Merging GDX files

Problems with syntax of GAMS
Post Reply
pitters
User
User
Posts: 14
Joined: 2 years ago

Merging GDX files

Post by pitters »

Hi!
Im having trouble merging two gdx files (or parameters).

Let's say (as a toy problem) I have a set "t" and the parameter t_par(t), which im uploading from two diferent excel sheets
test.xlsx
(9.28 KiB) Downloaded 188 times
set and params gdx files
t.gdx
(483 Bytes) Downloaded 169 times
t_par_a.gdx
(500 Bytes) Downloaded 168 times
t_par_b.gdx
(501 Bytes) Downloaded 173 times
The first call is to "t_par_a", the second call is to get "t_par_b", then I want to merge them both into a single file called "t_par.gdx"
________________________________________________________________

Code: Select all

SETS
t /t1*t10/
;

PARAMETERS
t_par_a(t)
t_par_b(t)
;

$CALL GDXXRW.EXE    i=test.xlsx     o=rep\t_par_a     par=t_par_a     rng=par1!a2     Rdim=1
$CALL GDXXRW.EXE    i=test.xlsx     o=rep\t_par_b     par=t_par_b     rng=par2!a2     Rdim=1

execute_unload 'rep\t.gdx' t

$GDXIN rep\t_par_a.gdx
$LOAD t_par_a
$GDXIN
;
$GDXIN rep\t_par_b.gdx
$LOAD t_par_b
$GDXIN
;

gdxmerge t_par_a t_par_b (o=t_par.gdx);    <--- this is giving error
FIXED: CORRECT WAY "$call gdxmerge rep\t_par_a.gdx rep\t_par_b.gdx output=t_par". Thanks abhosekar
________________________________________________________________

Im looking https://www.gams.com/latest/docs/T_GDXMERGE.html, but I may be doing something wrong or It could be a better
Last edited by pitters 2 years ago, edited 3 times in total.
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Merging GDX files

Post by abhosekar »

Saying that you get an error is not useful. What is the error that you get?

1. Are you using $call gdxmerge or just gdxmerge? You have to use $call gdxmerge while using it from GAMS. Check examples here https://www.gams.com/latest/docs/T_GDXM ... GE_EXAMPLE
2. You generate gdx files in rep\ directory. Assuming you are running the command from GAMS, you should also have rep\gdxfilename in the GDXMERGE command.
3. It is useful for other users to help you if you attach two gdx files that you are trying to merge instead of attaching an excel file.

- Atharv
pitters
User
User
Posts: 14
Joined: 2 years ago

Re: Merging GDX files

Post by pitters »

Thanks abhosekar, I edited the post and added the gdx files for other users.
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Merging GDX files

Post by abhosekar »

Okay, gdxmerge merges the contents of two gdx files. There is no way for gdxmerge to know that you want to merge t_par_a and t_par_b into t_par.

I would suggest doing it in gams.

Code: Select all

set t/t1*t10/;
parameter t_par,t_par_a, t_par_b;

$gdxin t_par_a
$load t_par_a
$gdxin

$gdxin t_par_b
$load t_par_b
$gdxin

t_par(t)$t_par_a(t) = t_par_a(t);
t_par(t)$t_par_b(t) = t_par_b(t);
execute_unload "merged_gdx1" t_par
- Atharv
Post Reply