CSVRead
Table of Contents
- Note
- This tool is part of the GAMS Tools Library. Please inspect the general information about GAMS Tools.
This tool writes data from a CSV file into a GAMS symbol. If the option gdxOut is specified, then the symbol is written to a GDX file. See the example below.
The tool utilizes the GAMS Connect agent CSVReader under the hood, therefore, many of its parameters are detailed in the agent's chapter as well.
Usage
Command line:
gamstool [data.]csvread csvFile id=symbolName gdxOut=fileOut.gdx
Compile time:
$callTool [data.]csvread csvFile id=symbolName [gdxOut=fileOut.gdx]
Execution time:
executeTool '[data.]csvread csvFile id=symbolName [gdxOut=fileOut.gdx]';
Where:
Argument Description csvFileCSV filename
The following named parameters are available:
Parameter Type Default Description acceptBadUelsboolean NSpecify if bad UELs are modified or result in an error return code. ( Yfor Yes,Nfor No)argsFilestring None Specify file to read in the parameters from. autoColstring None Generate automatic column names. autoRowstring None Generate automatic row labels. checkDateboolean NWrite gdx file only if CSV file is more recent than the GDX file. ( Yfor Yes,Nfor No)decimalSepstring periodSpecify a decimal separator. (period, comma) dimIdsstring None Specify the dimensions of the symbol separated by commas. If not specified, each dimension will be stored as Dim<X>in the GDX whengdxOutis provided.fieldSepstring commaSpecify a field separator. (comma, semicolon, tab) gdxOutstring None Name for the output GDX file. idstring None Name of the symbol. indexstring None Specify columns to use as the row labels. quotinginteger 0Control field quoting behavior. (0,1,2,3) See Connect agent CSVReaderoption quoting for more details.textstring None Specify columns to get the set element text from. thousandsSepstring None Specify a thousands separator. traceinteger 0Specify the trace level for debugging output. (0,1,2,3) See Connect agent CSVReaderoption trace for more details.useHeaderboolean NSpecify if header exists in the CSV file. ( Yfor Yes,Nfor No)valueDimboolean NAdds an extra dimension for values. ( Yfor Yes,Nfor No)valuesstring None Specify columns to get the values from.
Example
Set a, b;
Parameter c(a, b);
$onEcho > data.csv
a1,b1,10
a1,b2,20
a2,b1,30
a2,b2,40
$offEcho
$callTool data.csvread data.csv id=c index=1,2 values=3 dimIds=a,b
display a,b,c;
As the tool was executed during compile-time, the data was imported into symbol c in GAMS and the sets a and b were defined through c using the option dimIds.
Guidelines for CSV2GDX users
The parameters and the usage of this tool are similar to CSV2GDX. However, there are some differences between the two tools which are mentioned below.
- The colCount parameter is not required since the number of headers can now be inferred automatically from the CSV file.
- There is only one
valuesparameter, which can be used to specify the columns to get the values from. This parameter can accept both integer (a single column) as well as string (group of columns) as a valid assignment. - CSVRead cannot read from encrypted files.
- The option storeZero has been removed. Instead, zeroes will be stored as
0.0records.