22.04.2013 Views

GAMS Data Exchange API

GAMS Data Exchange API

GAMS Data Exchange API

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 2: C program<br />

Page 14<br />

begin<br />

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

Halt(1);<br />

end;<br />

GDXSymbolInfo(PGX,VarNr,VarName,Dim,VarTyp);<br />

if (Dim 2) or (VarTyp gms_dt_var)<br />

then<br />

begin<br />

WriteLn('**** X is not a two dimensional variable');<br />

Halt(1);<br />

end;<br />

if GDX<strong>Data</strong>ReadStrStart(PGX,VarNr,NrRecs) = 0<br />

then<br />

ReportGDXError(PGX);<br />

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

while GDX<strong>Data</strong>ReadStr(PGX,Indx,Values,N) 0<br />

do begin<br />

if Values[vallevel] = 0.0 //skip level = 0.0 is default<br />

then<br />

continue;<br />

for D := 1 to Dim<br />

do begin<br />

Write(Indx[D]);<br />

if D < Dim<br />

then<br />

Write('.');<br />

end;<br />

WriteLn(' = ',Values[vallevel]:7:2);<br />

end;<br />

WriteLn('All solution values shown');<br />

GDX<strong>Data</strong>ReadDone(PGX);<br />

end;<br />

ErrNr := GDXClose(PGX);<br />

if ErrNr 0<br />

then<br />

ReportIOError(ErrNr);<br />

end.<br />

1.6.2 Example 2: C program<br />

This is a simplified version of the gdxdump program written in C<br />

/*<br />

Use this command to compile the example:<br />

cl gdxdumpc.c ../../gmstest/apifiles/C/api/gdxcc.c ../../gmstest/apifiles/C/api/gclgms.c -<br />

I../../gmstest/apifiles/C/api/<br />

*/<br />

#include <br />

#include <br />

#include "gdxcc.h"<br />

#include "gclgms.h"<br />

char *val2str(gdxHandle_t Tptr, double val, char *s) {<br />

int sv;<br />

if (gdxAcronymName(Tptr, val, s)) {<br />

return s;<br />

} else {<br />

gdxMapValue(Tptr, val, &sv);<br />

if (sv_normal != sv)<br />

sprintf(s,"%s", gmsSVText[sv]);<br />

else<br />

sprintf(s,"%g", val);<br />

GDX <strong>GAMS</strong> <strong>Data</strong> <strong>Exchange</strong> Example<br />

programs<br />

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

1.6<br />

Page 14 2.4<br />

12/3/2012

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

Saved successfully!

Ooh no, something went wrong!