using csv2gdx and gdxin

Problems with syntax of GAMS
Post Reply
BrianH
User
User
Posts: 2
Joined: 5 years ago

using csv2gdx and gdxin

Post by BrianH »

Hi everyone,

I'm new to GAMS, and this is my first post.

I'm trying to import data from a CSV file. I have these 2 lines of code in my ".gms" file (let's call them line 1 and line 2 respectively):

execute 'csv2gdx i.csv output=in_i.gdx index=1 values=1 useheader=y id=i';
$gdxin in_i.gdx

I get a lot of errors, but I'll focus on the top-most one (most of the errors are 502 and 510):

*** Error 510 in [my directory name]
Unable to pen gdx file for $GDXIN

I also noticed that if I run the 2 lines in different files, then there are no issues (run line 1 in one "gms" file and then run line 2 in the next "gms" file).

Can anyone help me to understand this issue? I tried inserting a -sleep- command between the 2 lines (thinking that the second line was being run before the first was complete), but that didn't help. Does GAMS not run the scripts from top to bottom?

best,

Brian
Fred
Posts: 372
Joined: 7 years ago

Re: using csv2gdx and gdxin

Post by Fred »

Brian,

GAMS is a two pass system with a compilation and an execution phase (see https://www.gams.com/latest/docs/UG_Gam ... ll_TwoPass).
Dollar control options like $gdxin are executed during the compilation phase.
Programs called via execute '...'; are executed during the execution phase (see https://www.gams.com/latest/docs/UG_Gam ... nalProgram).

Hence, you try to open the gdx file before it is created. You could call csv2gdx during compilation with $call

Code: Select all

$call csv2gdx i.csv output=in_i.gdx index=1 values=1 useheader=y id=i
I hope this helps!

Fred
BrianH
User
User
Posts: 2
Joined: 5 years ago

Re: using csv2gdx and gdxin

Post by BrianH »

That does help. Thanks, Fred.
Post Reply