gdxdump4.gms : GDXDUMP - Dumping special Values of Variable-Subfields from GDX

Description

A simple check to verify the results when dumping special values from a variable-
subfields to a CSV file using GDXDUMP and the CSVAllFields option. In addition,
the EpsOut, NaOut, pInfOut etc. options to customize the output string of special
values are checked.

Contributor: Jan-Erik Justkowiak, September 2018

  Check the results when dumping a variable with special values in the subfields


Small Model of Type : GAMS


Category : GAMS Test library


Main file : gdxdump4.gms

$title GDXDUMP - Dumping special Values of Variable-Subfields from GDX (GDXDUMP4,SEQ=786)

$onText
A simple check to verify the results when dumping special values from a variable-
subfields to a CSV file using GDXDUMP and the CSVAllFields option. In addition,
the EpsOut, NaOut, pInfOut etc. options to customize the output string of special
values are checked.

Contributor: Jan-Erik Justkowiak, September 2018
$offText

* Check the results when dumping a variable with special values in the subfields
$onEcho > testDefault.gms
Set
   dim1 / i1*i6 /
   dim2 / Eps, NA, '+Inf', '-Inf', Undf, 0 /;

Alias (dim2, dim3, dim4, dim5, dim6);

$onUndf
Variable x(*) /
   i1.l     EPS, i2.l     NA, i3.l     INF, i4.l     -INF, i5.l     UNDF, i6.l     0
   i1.m     EPS, i2.m     NA, i3.m     INF, i4.m     -INF, i5.m     UNDF, i6.m     0
   i1.lo    EPS, i2.lo    NA, i3.lo    INF, i4.lo    -INF, i5.lo    UNDF, i6.lo    0
   i1.up    EPS, i2.up    NA, i3.up    INF, i4.up    -INF, i5.up    UNDF, i6.up    0
   i1.scale EPS, i2.scale NA, i3.scale INF, i4.scale -INF, i5.scale UNDF, i6.scale 0
/;

$gdxOut varX.gdx
$unload x
$gdxOut

$call gdxdump varX.gdx format=csv symb=x CSVAllFields > dumpedX.csv
$ifE errorLevel<>0 $abort Error writing to dumpedX.csv!

* It's the best to read the CSV into a set, so we are sure not to miss something, e.g. zero's
$call csv2gdx dumpedX.csv output=dumpedX.gdx id=dumpedX index=1..lastCol useHeader=y trace=0
$ifE errorLevel<>0 $abort Error reading from dumpedX.csv!

* Expected results
Set dumpedX(*,*,*,*,*,*) /
   i1.Eps.Eps.Eps.Eps.Eps
   i2.NA.NA.NA.NA.NA
   i3.'+Inf'.'+Inf'.'+Inf'.'+Inf'.'+Inf'
   i4.'-Inf'.'-Inf'.'-Inf'.'-Inf'.'-Inf'
   i5.Undf.Undf.Undf.Undf.Undf
   i6.0.0.0.0.0
/;

$gdxOut controlData.gdx
$unload dim1 dim2 dim3 dim4 dim5 dim6 dumpedX
$gdxOut

* Check the results
$call gdxdiff controlData.gdx dumpedX.gdx > %system.nullfile%
$ifE errorLevel<>0 $abort Checking the results when dumping subfiels of a variable with special values failed!
$offEcho

$call gams testDefault.gms lo=%gams.lo%
$ifE errorLevel<>0 $abort Error running testDefault.gms
*-------------------------------------------------------------------------------


* Check the results when dumping a variable with special values in the subfields
* and change the string written of the special values by adding the EpsOut, NaOut etc. options
$onEcho > testNonDefault.gms
Set
   dim1 / i1*i6 /
   dim2 / Epsilon, 'Not Availible', 'Large Number', 'Small Number', 'Undefined', 'Zero' /;

Alias (dim2, dim3, dim4, dim5, dim6);

$call gdxdump varX.gdx format=csv symb=x CSVAllFields EpsOut=Epsilon NaOut="Not Availible" pInfOut="Large Number" mInfOut="Small Number" UndfOut=Undefined ZeroOut=Zero > dumpedXmod.csv
$ifE errorLevel<>0 $abort Error writing to dumpedXmod.csv!

* The identifier specified in the CSV2GDX call will be a parameter or set. Since
* the strings specified above will not be readable for CSV2GDX, we ommit the
* values specification and read the data as set using the index option
$call csv2gdx dumpedXmod.csv output=dumpedXmod.gdx id=dumpedXmod index=1..lastCol useHeader=y trace=0
$ifE errorLevel<>0 $abort Error reading from dumpedXmod.csv!

* To compare the results, we define the expected data also as a set
Set dumpedXmod(*,*,*,*,*,*) /
   i1.Epsilon.Epsilon.Epsilon.Epsilon.Epsilon
   i2."Not Availible"."Not Availible"."Not Availible"."Not Availible"."Not Availible"
   i3."Large Number"."Large Number"."Large Number"."Large Number"."Large Number"
   i4."Small Number"."Small Number"."Small Number"."Small Number"."Small Number"
   i5.Undefined.Undefined.Undefined.Undefined.Undefined
   i6.Zero.Zero.Zero.Zero.Zero
/;

$gdxOut controlData.gdx
$unload dim1 dim2 dim3 dim4 dim5 dim6 dumpedXmod
$gdxOut

* Check the results
$call gdxdiff controlData.gdx dumpedXmod.gdx > %system.nullfile%
$ifE errorLevel<>0 $abort Checking the results when dumping subfiels of a variable with special values failed!
$offEcho

$call gams testNonDefault.gms lo=%gams.lo%
$ifE errorLevel<>0 $abort Error running testNonDefault.gms
*-------------------------------------------------------------------------------