GAMS Data Exchange API
GAMS Data Exchange API
GAMS Data Exchange API
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Writing data using integers (Mapped)<br />
Page 2<br />
Before writing data using a string based interface we can register strings for the unique elements, but this step is optional. The<br />
only reason to register the strings beforehand is to enter the strings in a given order which may have advantages later in the<br />
modelling stage.<br />
if not gdx<strong>Data</strong>WriteStrStart(PGX,'Demand','Demand data',1,Ord(dt_par),0)<br />
then<br />
ReportGDXError(PGX);<br />
IndxS[1] := 'New-York';<br />
Values[1] := 324.0;<br />
gdx<strong>Data</strong>WriteStr(PGX,IndxS,Values);<br />
IndxS[1] := 'Chicago';<br />
Values[1] := 299.0;<br />
gdx<strong>Data</strong>WriteStr(PGX,IndxS,Values);<br />
if not gdx<strong>Data</strong>WriteDone(PGX)<br />
then<br />
ReportGDXError(PGX);<br />
In this example we write two records for a parameter that has a dimension of one.<br />
1.1.2 Writing data using integers (Raw)<br />
The Raw interface is suitable when we want to manage our own list of unique elements, and use an integer based index. The<br />
Raw interface assumes that the integers assigned to the strings range from one to the number of strings registered.<br />
Before we can write data using the Raw interface, we have to register the strings for the unique elements. The GDX routines will<br />
assign an integer to the string that increases by one for every string registered.<br />
if not gdxUELRegisterRawStart(PGX)<br />
then<br />
ReportGDXError(PGX);<br />
gdxUELRegisterRaw(PGX,'New-York');<br />
gdxUELRegisterRaw(PGX,'Chicago');<br />
if not gdxUELRegisterDone(PGX)<br />
then<br />
ReportGDXError(PGX);<br />
if not gdx<strong>Data</strong>WriteRawStart(PGX,'Demand','Demand data',1,Ord(dt_par),0)<br />
then<br />
ReportGDXError(PGX);<br />
IndxI[1] := 1;<br />
Values[1] := 324.0;<br />
gdx<strong>Data</strong>WriteRaw(PGX,IndxI,Values);<br />
IndxI[1] := 2;<br />
Values[1] := 299.0;<br />
gdx<strong>Data</strong>WriteRaw(PGX,IndxS,Values);<br />
if not gdx<strong>Data</strong>WriteDone(PGX)<br />
then<br />
ReportGDXError(PGX);<br />
1.1.3 Writing data using integers (Mapped)<br />
GDX <strong>GAMS</strong> <strong>Data</strong> <strong>Exchange</strong> Writing data to<br />
a GDX file<br />
<strong>GAMS</strong> <strong>Data</strong> <strong>Exchange</strong> <strong>API</strong><br />
1.1<br />
The Mapped interface is suitable when we want to manage our own list of unique elements, and use an integer based index. The<br />
mapped interface lets us select our own mapping between strings for the unique elements and their integer equivalent. The<br />
integers assigned to the unique elements should be greater equal one, and be unique for each element.<br />
Page 2 2.4<br />
12/3/2012