Description
This example demonstrates how to read the parameters from an external text file. The file distance.csv from will be processed with CSVREAD while reading the options from an external file named howToRead.txt. This model is referenced in "Additional examples for extended use Example 8 - Reading the options from an external file" from the CSVREAD Documentation. Keywords: CSVREAD, data exchange, GAMS language features
Category : GAMS Data Utilities library
Main file : csv2gdx9.gms includes : csv2gdx9.gms
$title CSVREAD Example 9 - Reading Options from an external File (CSV2GDXE9,SEQ=118)
$onText
This example demonstrates how to read the parameters from an external text file.
The file distance.csv from will be processed with CSVREAD while reading the
options from an external file named howToRead.txt.
This model is referenced in "Additional examples for extended use Example 8 -
Reading the options from an external file" from the CSVREAD Documentation.
Keywords: CSVREAD, data exchange, GAMS language features
$offText
$onEcho > distance.csv
;new-york;chicago;topeka
seattle;2,5;1,7;1,8
san-diego;2,5;1,8;1,4
$offEcho
$onEcho > howToRead.txt
* These lines are interpreted as a comment
* This file specifies the options for reading distance.csv using CSVREAD
id = d
dimids = i,j
fieldSep = semiColon
decimalSep = comma
index = 1
useHeader = y
values = 2..lastCol
$offEcho
Set
i(*) 'canning plants'
j(*) 'markets';
Parameter d(i,j) 'distance in thousands of miles';
$callTool csvread distance.csv argsfile=howToRead.txt trace=0
$ifE errorLevel<>0 $abort Problems reading CSV file!
display i, j, d;