Monday, January 21, 2013

GAMS/GDX cannot read scalar from compressed GDX file

I encountered a problem when reading a scalar from a compressed GDX file:

GDXIN   C:\projects\ulrike - ifpri\gdx\spam.gdx
--- LOAD  cell5m = 2:cell5m
--- LOAD  rowcount = 1:rowcount
**** Problem reading symbol rowcount from gdx file
**** GDXmsg: Expected data marker (DATA) not found in GDX file

I did not really need the rowcount scalar so for me the workaround was: just skip reading this scalar.

It is amazing that this bug was not found earlier. I guess not many users are using compressed GDX files (the default is no compression) and of those few even fewer will ever store a scalar in such a file.

Some possible workarounds:

  • skip reading scalars
  • store scalars as a 1 dimensional parameter
  • store scalars in a separate uncompress gdx file
  • read scalars using gdxdump.

As said a possible workaround could be to use gdxdump for the scalars. This means instead of using:

$set gdxfile spam.gdx

set
cell5m;
scalar
rowcount;

* read from compressed GDX file

$gdxin %gdxfile%
$load cell5m  rowcount

we should implement something like:

$set gdxfile spam.gdx

set
cell5m;
scalar
rowcount;

* read from compressed GDX file
$gdxin %gdxfile%
$load cell5m

$call gdxdump %gdxfile% symb=rowcount output=rowcount.inc
$include rowcount.inc


display
rowcount;

No doubt this will be fixed in the next release.