GDX and GDXXRW Topic is solved

Problems with syntax of GAMS
Post Reply
edypark7
User
User
Posts: 1
Joined: 1 week ago

GDX and GDXXRW

Post by edypark7 » 1 week ago

I am having trouble reading a 3 dimensional matrix (data is binary) from Excel using the GDXXRW function. My code is as follows.

Code: Select all

Sets
  i RF /RF1*RF276/
  j AL /AL001*AL659/
  k SD /AE1, AE2/
  ;

Parameter
a(i,j,k)
*c(j,k) 
*b(i) 
;


$call GDXXRW GAMSGDX.xlsx para=a  rng=a(ijk)!a1:axs278 maxDupeErrors=4 rdim=1 cdim=2 trace=3
$GDXIN GDX Test.gdx
$LOAD a
$GDXIN

*display a;
Any thoughts would be appreciated.
GDX Test.gms
GAMS file with GDX code
(267 Bytes) Downloaded 1 time
GAMSGDX.xlsx
Sample data in Excel that needs to be read into GAMS GDX
(1 MiB) Downloaded 6 times
Last edited by edypark7 1 week ago, edited 1 time in total.

AndrewC
User
User
Posts: 4
Joined: 1 year ago

Re: GDX and GDXXRW

Post by AndrewC » 1 week ago

First just checking the basics, is gdxxrw in your path? If you open a command window and type gdxxrw does it recognise it? If not then this might be your issue.

Assuming it understands the call to gdxxrw, I made a slight adjustment to how the data is read in and it works for me, perhaps just copy what I did. Note that I didn't use all of your read options, but you can just add those back in. I'm not sure what the exact problem is, I just coded it the way I normally do and it seems to work that way.

Code: Select all

Sets
  i RF /RF1*RF276/
  j AL /AL001*AL659/
  k SD /AE1, AE2/
  ;

Parameter
a(i,j,k)
*c(j,k) 
*b(i) 
;

* Below the details about the parameter to read in and the data range has been moved to an external file "excel_dataRead.txt"
$call gdxxrw GAMSGDX.xlsx output=GDXTest.gdx @excel_dataRead.txt trace=3
$GDXIN GDXTest.gdx
$LOAD a
$GDXIN

display a;
Attached below is the file that specifies the parameter to read and the data range within the Excel workbook. You can add as many other sets/parameters to this .txt file as you want, e.g add reads for parameters b and c once you add them to the Excel workbook. Check out the gdxxrw documentation for various options and syntax when using a file to define the data during a gdxxrw read.

Cheers
excel_dataRead.txt
GDXXRW items to read and their Excel range definitions.
(102 Bytes) Downloaded 2 times

User avatar
Renger
Posts: 406
Joined: 3 years ago

Re: GDX and GDXXRW

Post by Renger » 1 week ago

Hi
I noticed that you include test.gdx, however, the gdx file that is saved according to your code is the name of the excel file with gdx as extension.
If you want to save the results in test.gdx you should add "o=test.gdx" to your gdxxrw command.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

Post Reply