Merging GDX files

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 KB)
set and params gdx files
t.gdx (483 Bytes)
t_par_b.gdx (501 Bytes)
t_par_a.gdx (500 Bytes)
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”


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

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_GDXMERGE.html#GDXMERGE_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

Thanks abhosekar, I edited the post and added the gdx files for other users.

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.

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