CSVRead

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
csvFile CSV filename

The following named parameters are available:

Parameter Type Default Description
acceptBadUels boolean N Specify if bad UELs are modified or result in an error return code. (Y for Yes, N for No)
argsFile string None Specify file to read in the parameters from.
autoCol string None Generate automatic column names.
autoRow string None Generate automatic row labels.
checkDate boolean N Write gdx file only if CSV file is more recent than the GDX file. (Y for Yes, N for No)
decimalSep string period Specify a decimal separator. (period, comma)
dimIds string None Specify the dimensions of the symbol separated by commas. If not specified, each dimension will be stored as Dim<X> in the GDX when gdxOut is provided.
fieldSep string comma Specify a field separator. (comma, semicolon, tab)
gdxOut string None Name for the output GDX file
id string None Name of the symbol.
index string None Specify columns to use as the row labels.
quoting integer 0 Control field quoting behavior. (0,1,2,3) See Connect agent CSVReader option quoting for more details.
text string None Specify columns to get the set element text from.
thousandsSep string None Specify a thousands separator.
trace integer 0 Specify the trace level for debugging output
useHeader boolean N Specify if header exists in the CSV file (Y for Yes, N for No)
valueDim boolean N Adds an extra dimension for values. (Y for Yes, N for No)
values string 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.

  1. The colCount parameter is not required since the number of headers can now be inferred automatically from the CSV file.
  2. There is only one values parameter, 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.
  3. CSVRead cannot read from encrypted files.
  4. The option storeZero has been removed. Instead, zeroes will be stored as 0.0 records.