GAMS Data Exchange API
GAMS Data Exchange API
GAMS Data Exchange API
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Page 8<br />
NrRecs : integer;<br />
UELS : TgdxUELIndex;<br />
Vals : TgdxValues;<br />
FDim : integer;<br />
N : integer;<br />
ErrMsg : shortstring;<br />
ErrNr : integer;<br />
acrname : shortstring;<br />
acrtext : shortstring;<br />
acrindx : integer;<br />
begin<br />
//Check the library<br />
if not gdxGetReadyX(ErrMsg)<br />
then<br />
begin<br />
WriteLn('Error loading GDX library, msg = ', ErrMsg);<br />
Halt(1);<br />
end;<br />
//Create GDX object and open file for writing<br />
gdxCreateX(PGX, ErrMsg);<br />
gdxOpenWriteEx(PGX, 'test.gdx', 'testing', 0, ErrNr);<br />
//register some unique elements<br />
gdxUELRegisterRawStart(PGX);<br />
for N := 1 to 5<br />
do gdxUELRegisterRaw(PGX, 'uel' + IntToStr(N));<br />
gdxUELRegisterDone(PGX);<br />
//write a parameter with two acronyms<br />
gdx<strong>Data</strong>WriteRawStart(PGX, 'symb1', 'text for symb1', 1, Ord(dt_par), 0);<br />
for N := 1 to 5<br />
do begin<br />
UELS[1] := N;<br />
if N in [2, 4]<br />
then<br />
Vals[vallevel] := gdxAcronymValue(PGX, N)<br />
else<br />
Vals[vallevel] := N;<br />
gdx<strong>Data</strong>WriteRaw(PGX, UELS, Vals);<br />
end;<br />
gdx<strong>Data</strong>WriteDone(PGX);<br />
//provide the names for the acronyms used<br />
for N := 1 to gdxAcronymCount(PGX)<br />
do begin<br />
gdxAcronymGetInfo(PGX, N, acrname, acrtext, acrindx);<br />
if acrindx = 2<br />
then<br />
gdxAcronymSetInfo(PGX, N, 'acro1', 'Some text for acro1', acrindx)<br />
else<br />
if acrindx = 4<br />
then<br />
gdxAcronymSetInfo(PGX, N, 'acro2', 'Some text for acro2', acrindx)<br />
end;<br />
//final check for errors before we close the file<br />
N := gdxClose(PGX);<br />
if N 0<br />
then<br />
begin<br />
gdxErrorStr(Nil, N, ErrMsg);<br />
WriteLn('Error writing file = ', ErrMsg);<br />
Halt(1);<br />
end;<br />
gdxFree(PGX);<br />
//open the file we just created<br />
gdxCreateX(PGX, ErrMsg);<br />
gdxOpenRead(PGX, 'test.gdx', ErrNr);<br />
if ErrNr 0<br />
GDX <strong>GAMS</strong> <strong>Data</strong> <strong>Exchange</strong> Dealing with<br />
acronyms<br />
<strong>GAMS</strong> <strong>Data</strong> <strong>Exchange</strong> <strong>API</strong><br />
1.3<br />
Page 8 2.4<br />
12/3/2012