$Ondelim and $Offdelim

Top  Previous  Next

CSV formatted entries files may be incorporated by using the command $Ondelim before beginning the entry and then $Offdelim afterwards.  Consider the following example (CSV1.gms):

 

SETS

   PLANT  PLANT LOCATIONS /NEWYORK,CHICAGO,LOSANGLS /

   MARKET DEMANDS  /MIAMI,HOUSTON, PORTLAND/

table datafrmCSV(plant,market)  data in CSV format

$Ondelim

dummy,MIAMI,HOUSTON,PORTLAND

NEWYORK,1300,1800,1100

CHICAGO,2200,1300,700

LOSANGLS,3700,2400,2500

$Offdelim

 

where the section in blue is in CSV form. In version 22.7 and later one can also drop the dummy entry but must maintain the comma as follows

table datafrmCSV2(plant,market)  data in CSV format

$Ondelim

,MIAMI,HOUSTON,PORTLAND

NEWYORK,1300,1800,1100

CHICAGO,2200,1300,700

LOSANGLS,3700,2400,2500

$Offdelim

 

One could equivalently use an include file as follows (CSV2.gms)

 

SETS

   PLANT  PLANT LOCATIONS /NEWYORK,CHICAGO,LOSANGLS /

   MARKET DEMANDS  /MIAMI,HOUSTON, PORTLAND/

table datafrmCSV(plant,market)  data in CSV format

$Ondelim

$Include Csvtoinc

$Offdelim

 

where the file csvtoinc.gms contains

 

dummy,MIAMI,HOUSTON,PORTLAND

NEWYORK,1300,1800,1100

CHICAGO,2200,1300,700

LOSANGLS,3700,2400,2500

 

where the dummy could be dropped but the comma must be maintained.

Notes:

We use $Ondelim before the CSV entry or included file and $Offdelim after to tell GAMS that the following entries are delimited.
A text item like the entry dummy above is included to use up the space over the set elements defining the table rows although as of version 22.7 this can be balk with just a comma.