csv2gdx4.gms : CSV2GDX - Reading special Values

Description

CSV2GDX is tested on data with special values (NA,Undf,Inf,Eps,True,False,None,
Null,N/A), empty fields, quoted values and quoted UELs. Furthermore, the
storeZero option is checked.

Contributor Jan-Erik Justkowiak, March 2018


Small Model of Type : GAMS


Category : GAMS Test library


Main file : csv2gdx4.gms

$title CSV2GDX - Reading special Values (CSV2GDX4,SEQ=748)

$onText
CSV2GDX is tested on data with special values (NA,Undf,Inf,Eps,True,False,None,
Null,N/A), empty fields, quoted values and quoted UELs. Furthermore, the
storeZero option is checked.

Contributor Jan-Erik Justkowiak, March 2018
$offText

$onEcho > specialValues.csv
one,two,three,four,five,six
red,red,,Undef,'3.3',red
red,red,"4.4",5.5,Eps,green
"red",'green',7.7e+02,8.8°,-Inf,blue
blue,blue,"10%",0,NA,"'purple'"
green,blue,"Eps","NA","Undef",purple
green,blue,"0","","  ",'green'
brown,blue,true,false,N/A,'green'
black,red,None,Null,"True",blue
black,red,"False","None","Null",green
black,red,"N/A",'true','false',yellow
black,red,'None','Null','N/A',brown
$offEcho

$call csv2gdx specialValues.csv id=A_SZ index=1,2,6 values=3..5 useHeader=Y storeZero=Y trace=0
$ifE errorLevel<>0 $abort Problems reading data with CSV2GDX (storeZero enabled)!

* defining the control data
Set
   dim1 / red, blue, green, brown, black /
   dim2 / red, "'green'", blue /
   dim3 / red, green, blue, "'purple'", purple, "'green'", yellow, brown /
   dim4 / three, four, five /;

* to check the results when storeZero is enabled
$onUNDF
Parameter A_SZ
/
   red.red.red.four Undf
   red.red.red.five Undf
   red.red.green.three 4.4
   red.red.green.four 5.5
   red.red.green.five Eps
   red."'green'".blue.three 770
   red."'green'".blue.four Undf
   red."'green'".blue.five -Inf
   blue.blue."'purple'".three Undf
   blue.blue."'purple'".four Eps
   blue.blue."'purple'".five NA
   green.blue.purple.three Eps
   green.blue.purple.four  NA
   green.blue.purple.five  Undf
   green.blue."'green'".three Eps
   brown.blue."'green'".three 1
   brown.blue."'green'".four  Eps
   brown.blue."'green'".five  NA
   black.red.blue.three   Eps
   black.red.blue.four    Eps
   black.red.blue.five    1
   black.red.green.three  Eps
   black.red.green.four   Eps
   black.red.green.five   Eps
   black.red.yellow.three NA
   black.red.yellow.four  Undf
   black.red.yellow.five  Undf
   black.red.brown.three  Undf
   black.red.brown.four   Undf
   black.red.brown.five   Undf
/;

$gdxOut check_SZ.gdx
$unLoad dim1 dim2 dim3 dim4 A_SZ
$gdxOut

$call gdxdiff specialValues.gdx check_SZ.gdx > %system.nullfile%
$ifE errorLevel<>0 $abort Data is not correct after reading special values with storeZero enabled!
*-------------------------------------------------------------------------------

* to check the results when storeZero is disabled (default)
$call csv2gdx specialValues.csv id=A index=1,2,6 values=3..5 useHeader=Y trace=0
$ifE errorLevel<>0 $abort Problems reading data with CSV2GDX (storeZero disabled)!

Parameter A
/
   red.red.red.four Undf
   red.red.red.five Undf
   red.red.green.three 4.4
   red.red.green.four 5.5
   red.red.green.five Eps
   red."'green'".blue.three 770
   red."'green'".blue.four Undf
   red."'green'".blue.five -Inf
   blue.blue."'purple'".three Undf
   blue.blue."'purple'".four 0
   blue.blue."'purple'".five NA
   green.blue.purple.three Eps
   green.blue.purple.four  NA
   green.blue.purple.five  Undf
   green.blue."'green'".three 0
   brown.blue."'green'".three 1
   brown.blue."'green'".four  0
   brown.blue."'green'".five  NA
   black.red.blue.three   0
   black.red.blue.four    0
   black.red.blue.five    1
   black.red.green.three  0
   black.red.green.four   0
   black.red.green.five   0
   black.red.yellow.three NA
   black.red.yellow.four  Undf
   black.red.yellow.five  Undf
   black.red.brown.three  Undf
   black.red.brown.four   Undf
   black.red.brown.five   Undf
/;

$gdxOut check.gdx
$unLoad dim1 dim2 dim3 dim4 A
$gdxOut

$call gdxdiff specialValues.gdx check.gdx > %system.nullfile%
$ifE errorLevel<>0 $abort Data is not correct after reading special values with storeZero disabled!
*-------------------------------------------------------------------------------