## put command

Problems with syntax of GAMS
s0r0n
User Posts: 7
Joined: 8 months ago

### put command

Hello!

My program in GAMS is working, but some results are not what I was expecting. I need to check some of my equations line by line, to see what value each variable has in every iteration. So I need a report in excel, which I know will be done with the put command. What I want to see for example is this :

Code: Select all

``````Net9(i,f,t)\$(Ainc(i,f)=1) .. K(i,t) =e= sum(j\$(Ainc(j,f)=-1),K(j,t)) + 2*((R(f)/Zbase)*(P_line(f,t)/Sbase) +
(X(f)/Zbase)*(Q_line(f,t)/Sbase));``````
• -------k(i) - k(j) -- P() ---Q()
iter1: 5 ----4 -----202 ---150
iter2: 7 ----2 -----420 ---340 ....
Would appreciate some help with this.

Renger
Posts: 266
Joined: 2 years ago

### Re: put command

Hi

Why use the put command to write to Excel. The best tool for doing this is gdxxrw:

Code: Select all

``````Net9(i,f,t)\$(Ainc(i,f)=1) .. K(i,t) =e= sum(j\$(Ainc(j,f)=-1),K(j,t)) + 2*((R(f)/Zbase)*(P_line(f,t)/Sbase) +
(X(f)/Zbase)*(Q_line(f,t)/Sbase));

parameter eq_net9(*,i,f,t);
loop(f,
eq_net9("K", i,f,t) = K.L(i,t);
eq_net9("Ksum", i,f,t) = sum(j\$(Ainc(j,f)=-1),K.L(j,t));
etc...
);
Execute_Unload "results.gdx", eq_net9;
execute 'gdxxrw results.gdx par=eq_net9 rng=eq_net9!a1
``````
Cheers
Renger

s0r0n
User Posts: 7
Joined: 8 months ago

### Re: put command

Thank you very much! It works that way, however it's not very easy to read, since all the values of K are printed first, then sumK, Pline etc.. Thus can't check each equation. Ideally what I want to see is :

---------------------K()-------sumK()---------P_line()-------- Q_line()
eq_net9(1,1,1)--k(1,1)----sumK(1,1)---P_line(1,1)----Q_line(1,1)
eq_net9(2,1,1)--k(2,1)----sumK(2,1)---P_line(2,1)----Q_line(2,1)
...

Renger
Posts: 266
Joined: 2 years ago

### Re: put command

just redefine the parameter as

Code: Select all

``````eq_net9(i,f,t, *)
``````
and adjust the export command as follows:

Code: Select all

``execute 'gdxxrw results.gdx par=eq_net9 rng=eq_net9!a1 Rdim=3 Cdim=1``
This will correct the order and you will have the output according to equations.
CHeers
Renger

s0r0n
User Posts: 7
Joined: 8 months ago

### Re: put command

Thank you again. It's getting better and better every time How come it works correctly since you used only the f argument inside the loop? Also how can you put labels for the sets as well?

Renger
Posts: 266
Joined: 2 years ago

### Re: put command

Hi
I only use the f loop because you use K(i,t) in an equation with the additional index f. i and t are on both sides of the assignment but f is missing on the right:

Code: Select all

``````loop(f,
eq_net9("K", i,f,t) = K.L(i,t);``````
);
If K was also defined over f, you don't have to use a loop to assign values and this would do the job:

Code: Select all

``eq_net9("K", i,f,t) = K.L(i,f,t);``
You can't easily export the labels, however, you can define your sets more explicitly. For example:

Code: Select all

``i /Sector1*Sector12/, j /Iter1*Iter24/ ``
instead of

Code: Select all

``i /1*12/, j /1*24/ ``
.

You will than have "Sector1" , "Iter1", etc. instead of 1, 1 in your excel table.

CHeers
Renger