22.04.2013 Views

GAMS Data Exchange API

GAMS Data Exchange API

GAMS Data Exchange API

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Reading data using integers (Raw)<br />

Page 4<br />

then<br />

begin<br />

WriteLn('**** Could not find symbol X');<br />

halt;<br />

end;<br />

gdxSymbolInfo(PGX,SyNr,SyName,SyDim,SyTyp);<br />

if (SyDim 1) or (SyTyp Ord(dt_par))<br />

then<br />

begin<br />

WriteLn('**** X is not a one dimensional parameter');<br />

halt;<br />

end;<br />

if not gdx<strong>Data</strong>ReadStrStart(PGX,SyNr,NrRecs)<br />

then<br />

ReportGDXError(PGX);<br />

WriteLn('Parameter X has ',NrRecs,' records');<br />

while gdx<strong>Data</strong>ReadStr(PGX,IndxS,Values,N)<br />

do WriteLn('Record = ',IndxS[1],' ',Values[1]);<br />

if not gdx<strong>Data</strong>ReadDone(PGX)<br />

then<br />

ReportGDXError(PGX);<br />

In this example we find the symbol by its name, and before reading the data we verify that the symbol represents a one<br />

dimensional parameter.<br />

1.2.2 Reading data using integers (Raw)<br />

Reading data using integers in Raw mode does not require the registration of unique elements. The read routine returns an<br />

integer for which we can find the string representation.<br />

if not gdxFindSymbol(PGX,'x',SyNr)<br />

then<br />

begin<br />

WriteLn('**** Could not find symbol X');<br />

halt;<br />

end;<br />

gdxSymbolInfo(PGX,SyNr,SyName,SyDim,SyTyp);<br />

if (SyDim 1) or (SyTyp Ord(dt_par))<br />

then<br />

begin<br />

WriteLn('**** X is not a one dimensional parameter');<br />

halt;<br />

end;<br />

if not gdx<strong>Data</strong>ReadRawStart(PGX,SyNr,NrRecs)<br />

then<br />

ReportGDXError(PGX);<br />

WriteLn('Parameter X has ',NrRecs,' records');<br />

while gdx<strong>Data</strong>ReadRaw(PGX,IndxI,Values,N)<br />

do begin<br />

Write('Record = ',IndxI[1],' = ',Values[1]);<br />

gdxUMUelGet(PGX,IndxI[1],S,UsrMap);<br />

WriteLn(' with string = ',S);<br />

end;<br />

if not gdx<strong>Data</strong>ReadDone(PGX)<br />

then<br />

ReportGDXError(PGX);<br />

GDX <strong>GAMS</strong> <strong>Data</strong> <strong>Exchange</strong> Reading data<br />

from a GDX file<br />

<strong>GAMS</strong> <strong>Data</strong> <strong>Exchange</strong> <strong>API</strong><br />

1.2<br />

In this example we find the symbol by its name, and before reading the data we verify that the symbol represents a one<br />

dimensional parameter. When reading the data, we get a unique element as an integer. The integer value is used to get the<br />

Page 4 2.4<br />

12/3/2012

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!