- Note
- This tool is part of the GAMS Tools Library. Please inspect the general information about GAMS Tools.
This tool writes a symbol from a GDX file to a CSV file. If gdxIn is not specified, a symbol can be written directly from the GAMS database as well. See the example below.
This tool utilizes the GAMS Connect Projection agent to convert variables and equations to parameters and the CSVWriter agent to write the symbol to a CSV file. Therefore, many of its parameters are detailed in the agent's chapter as well. Further, it also utilizes GDXDUMP to handle different numerical formats.
Usage
Command line:
gamstool [data.]csvwrite gdxIn=fileIn.gdx id=symbolName file=fileOut.csv
Compile time:
$callTool [data.]csvwrite [gdxIn=fileIn.gdx] id=symbolName file=fileOut.csv
Execution time:
executeTool '[data.]csvwrite [gdxIn=fileIn.gdx] id=symbolName file=fileOut.csv';
The following named parameters are available:
Parameter Type Default Description allFieldsboolean NSpecify whether all the attributes (level, marginal, lower, upper, and scale) of a variable or an equation are written to the CSV. By default only the level will be written. ( Yfor Yes,Nfor No)decimalSepstring periodSpecify a decimal separator. (period, comma) dFormatstring normalSpecify the numerical format in the output file. (normal, hexponential, hexbytes) See Tool GDXDUMPoption dFormat for more details.fieldSepstring commaSpecify a field separator. (comma, semicolon, tab) filestring None Specify the name for the CSV file. If omitted and gdxIn is specified, the GDX file name will be used. gdxInstring None Specify the input GDX file. headerboolean YSpecify if the header will be written. ( Yfor Yes,Nfor No)idstring None Specify the name of the symbol in the GDX file or GAMS database. quotinginteger 0Control field quoting behavior. (0,1,2,3) See Connect agent CSVWriteroption quoting for more details.setHeaderstring None Specify a string that will be used as the header. skipTextboolean NSpecify if the set element text will be skipped. ( Yfor Yes,Nfor No)traceinteger 0Specify the trace level for debugging output. (0,1,2,3) See Connect agent CSVWriteroption trace for more details.unstackboolean NSpecify if the last dimension will be unstacked to the header row. ( Yfor Yes,Nfor No)
- Note
- If
dFormatis notnormal, the tool utilizesGDXDUMPin the background instead of theCSVWriter. SinceGDXDUMPdoes not allow to control the field quoting behavior, settingquotingwill have no effect. TheGDXDUMPquoting behavior corresponds toquoting=2.
Example
Set a /i1*i4/, b /j1*j2/;
Parameter c(a, b);
c(a,b)=UniformInt(1,10);
executeTool 'csvwrite id=c quoting=2 file=c_out.csv';
The above example generates the following CSV file named, c_out.csv.
"a","b","value" "i1","j1",2.0 "i1","j2",9.0 "i2","j1",6.0 "i2","j2",4.0 "i3","j1",3.0 "i3","j2",3.0 "i4","j1",4.0 "i4","j2",9.0
The tool exported symbol c to the CSV file during execution-time. Further, the following example shows how GDXDUMP is utilized in the background to store the same data but in hexponential numeric format using option dFormat.
Set a /i1*i4/, b /j1*j2/;
Parameter c(a, b);
c(a,b)=UniformInt(1,10);
executeTool 'csvwrite id=c file=c_out_exp.csv dFormat=hexponential';
The above example generates the following CSV file named, c_out_exp.csv.
"a","b","Val" "i1","j1",0x1.0p1 "i1","j2",0x1.2p3 "i2","j1",0x1.8p2 "i2","j2",0x1.0p2 "i3","j1",0x1.8p1 "i3","j2",0x1.8p1 "i4","j1",0x1.0p2 "i4","j2",0x1.2p3