Description
This program tests the compile-time and execution-time usage of GAMS Tool CSVRead. The tool can write data from CSV directly to a GAMS symbol if the option -gdxout is not specified. Contributor: Vaibhavnath Jha, September 2024
Small Model of Type : GAMS
Category : GAMS Test library
Main file : csvread1.gms
$title 'Test GAMS Tool CSVRead' (csvread1,SEQ=965)
$onText
This program tests the compile-time and execution-time
usage of GAMS Tool CSVRead. The tool can write data from CSV
directly to a GAMS symbol if the option -gdxout is not specified.
Contributor: Vaibhavnath Jha, September 2024
$offText
$onEcho > data.csv
i,j,III,IV,V
a,d,1,4,7
b,e,2,5,8
c,f,3,6,9
$offEcho
Set i,j;
Parameter c(i,j);
* compile-time
$callTool.checkErrorLevel csvread data.csv id=c dimids=i,j index=1,2 values=lastCol useHeader=y
execute_unload 'out.gdx' c,i,j;
Set check_i /a,b,c/, check_j /d,e,f/;
Parameter check_c(i,j) /a.d 7, b.e 8, c.f 9/;
execute_unload 'check.gdx' check_c=c, check_i=i, check_j=j;
execute "gdxdiff out.gdx check.gdx > %system.NullFile%";
abort$errorlevel 'Unexpected data in c';
set attr /III, IV, V/;
Parameter d(i,j,attr);
* execution-time
executeTool.checkErrorLevel "csvread data.csv id=d index=1,2 values=3..lastCol useHeader=y";
execute_unload 'out.gdx' d;
parameter check_d /a.d.III 1, a.d.IV 4, a.d.V 7,
b.e.III 2, b.e.IV 5, b.e.V 8,
c.f.III 3, c.f.IV 6, c.f.V 9/;
execute_unload 'check.gdx' check_d=d;
execute "gdxdiff out.gdx check.gdx > %system.NullFile%";
abort$errorlevel 'Unexpected data in d';
$onEcho>data_1.csv
A,i1,i2,i3
a1,,,43
a2,,3.5,48
$offEcho
set a,b;
Parameter x(a,b);
*** CSVRead should not import unused UELs in the symbol.
$callTool CSVRead data_1.csv useHeader=yes id=x index=1 values=2..lastCol dimIds=a,b
abort$[card(b) <> 2] 'Dimension of second set must be 2';
execute_unload 'out.gdx' b;
Set check_b /i2,i3/;
execute_unload 'check.gdx' check_b=b;
execute "gdxdiff out.gdx check.gdx > %system.NullFile%";
abort$errorlevel 'Unexpected data in b, element >i1< must not be imported.';