Rutherford's CSV put: Gams2csv

Top  Previous  Next

GAMS users do not have to do put file programming to move data in CSV format.  Rather they can use a libinclude routine called Gams2csv developed by Rutherford and associates at the University of Colorado.  That program and a write-up is available at http://www.mpsge.org/gams2csv/gams2csv.htm.

Gams2csv is invoked as follows:

 

FILE localname /externalname/;

PUT localname;

$LIBInclude gams2csv  [row domain [column domain] ] item[.suffix] [item[.suffix] ...]

 

The material in brackets [ ] is optional
Before the program can be used a file and initial put command are required as explained in the Output via Put Commands chapter.
The gams2csv.gms file must have been obtained from the Rutherford web page  and installed into the place where libinclude files are read from.  This location is generally the inclib subdirectory of the GAMS system directory (as discussed in the Including External Files chapter).
Data from a parameter, variable or equation may be output. When a variable or equation is used, an attribute must be identified such as .L, or .M.
The routine may be used within a loop or if block only if it is first initialized with a blank invocation ($LIBInclude gams2csv).
All items written in a single libinclude must be of the same dimension.  To write items of different dimensions or domains, use multiple libincludes of the routine.
When row and column domains are specified they can cause less than the full set to be entered into the CSV file.  The domain must be the set defining the item or a subset thereof.
One can control whether zeros are written to the CSV file through the global environment variable "zeros" using the syntax

 

 $setglobal zeros yes

 

One can specify a prefix to be attached to every line using the syntax

 

 $setglobal prefix text

Example:

(ruthercsv.gms)

put 'x without domain' /;

$libinclude gams2csv x

put / 'x with lesser domain for i' //;

$libinclude gams2csv lessi x

put / 'y without domain' //;

$libinclude gams2csv y

put / 'y with lesser domain for i and j' //;

$libinclude gams2csv lessi,lessj k y

put / 'z without domain' //;

$libinclude gams2csv z

put / 'z with lesser domain for j and k' //;

$libinclude gams2csv i,lessj,lessk z

 

which yields the output

 

x without domain

"x","A one-dimensional vector."

,"i1",1.7174713200000E-01

,"i2",8.4326670800000E-01

x with lesser domain for i

"x","A one-dimensional vector."

,"i1",1.7174713200000E-01

y without domain

"y","A three dimensional array written with column headers"

,,,"k1","k2","k3"

,"i1","j1",3.0113790400000E-01,2.9221211700000E-01,2.2405286700000E-01

,"i1","j2",3.4983050400000E-01,8.5627034700000E-01,6.7113723000000E-02

,"i1","j3",5.0021066900000E-01,9.9811762700000E-01,5.7873337800000E-01

,"i2","j1",9.9113303900000E-01,7.6225046700000E-01,1.3069248300000E-01

,"i2","j2",6.3971875900000E-01,1.5951786400000E-01,2.5008053300000E-01

,"i2","j3",6.6892860900000E-01,4.3535638100000E-01,3.5970026600000E-01

y with lesser domain for i and j

"y","A three dimensional array written with column headers"

,,,"k1","k2","k3"

,"i1","j1",3.0113790400000E-01,2.9221211700000E-01,2.2405286700000E-01

z without domain

"z","A three dimensional array written in list form"

,,,"k1","k2","k3"

,"i1","j1",3.0113790400000E-01,2.9221211700000E-01,2.2405286700000E-01

,"i1","j2",3.4983050400000E-01,8.5627034700000E-01,6.7113723000000E-02

,"i1","j3",5.0021066900000E-01,9.9811762700000E-01,5.7873337800000E-01

,"i2","j1",9.9113303900000E-01,7.6225046700000E-01,1.3069248300000E-01

,"i2","j2",6.3971875900000E-01,1.5951786400000E-01,2.5008053300000E-01

,"i2","j3",6.6892860900000E-01,4.3535638100000E-01,3.5970026600000E-01

z with lesser domain for j and k

"z","A three dimensional array written in list form"

,"i1","j1","k2",2.9221211700000E-01

,"i2","j1","k2",7.6225046700000E-01

,"i3","j1","k2",0.0000000000000E+00