Q:Whenever I try to use $ondelim
and $offdelim
to include a csv file containing a multi-dimensional (dimension >2) table I get into trouble (error 445).
Find below an example which illustrates how to do this. The trick is to delay the use of $ondelim
, so GAMS can figure out what the structures is of the table (dimensions of the rows and columns).
Set n 'scenario set' /s0*s1100/ i 'project set' /i1*i3/ para 'parameter set' /resv, ip, wresv, decay/ ph 'phase set' /ph1, ph2, ph3/ ; Table scen(n, i, para, ph) 'all data are logged and in csv format' i1.resv.ph1 i1.ip.ph1 i2.resv.ph1 i2.ip.ph1 i3.resv.ph1 i3.ip.ph1 $onDelim $include scenpv.csv $offDelim option scen:6:3:1; display scen;
scenpv.csv
s1, 4.484497, 5.590780, 9.565448, -2.776771, 2.017210, 0.403969 s2, 4.039559, 7.829553, 1.965880, 4.383472, 0.832007, 5.789936 s3, 2.557665, 2.588679, 18.390045, 1.562361, -1.775599, -1.249638 s4, 7.979709, 8.760805, -0.482130, 7.159645, 13.708082, 1.417433 s5, 0.696502, 4.404599, 0.503611, 0.834050, 11.337872, 10.814183 s6, 18.435462, 2.077279, 5.328744, 0.618193, 6.188519, 3.306824 s7, 3.306904, 0.556912, 19.002177, 7.614140, 13.621738, 1.301998 s8, 10.388623, 8.810147, 11.926869, -1.214278, 20.940576, 7.139113 s9, 7.147472, 10.465706, 14.562816, 11.444166, -1.436094, -2.144297 s10, 1.728924, 1.424648, 3.307312, 9.400273, 4.361133, 1.460645
---- 23 PARAMETER scen all data are logged and in csv format ph1 s1 .i1.resv 4.484497 s1 .i1.ip 5.590780 s1 .i2.resv 9.565448 s1 .i2.ip -2.776771 s1 .i3.resv 2.017210 s1 .i3.ip 0.403969 s2 .i1.resv 4.039559 s2 .i1.ip 7.829553 s2 .i2.resv 1.965880 s2 .i2.ip 4.383472 s2 .i3.resv 0.832007 s2 .i3.ip 5.789936 s3 .i1.resv 2.557665 s3 .i1.ip 2.588679 s3 .i2.resv 18.390045 s3 .i2.ip 1.562361 s3 .i3.resv -1.775599 s3 .i3.ip -1.249638 s4 .i1.resv 7.979709 s4 .i1.ip 8.760805 s4 .i2.resv -0.482130 s4 .i2.ip 7.159645 s4 .i3.resv 13.708082 s4 .i3.ip 1.417433 s5 .i1.resv 0.696502 s5 .i1.ip 4.404599 s5 .i2.resv 0.503611 s5 .i2.ip 0.834050 s5 .i3.resv 11.337872 s5 .i3.ip 10.814183 s6 .i1.resv 18.435462 s6 .i1.ip 2.077279 s6 .i2.resv 5.328744 s6 .i2.ip 0.618193 s6 .i3.resv 6.188519 s6 .i3.ip 3.306824 s7 .i1.resv 3.306904 s7 .i1.ip 0.556912 s7 .i2.resv 19.002177 s7 .i2.ip 7.614140 s7 .i3.resv 13.621738 s7 .i3.ip 1.301998 s8 .i1.resv 10.388623 s8 .i1.ip 8.810147 s8 .i2.resv 11.926869 s8 .i2.ip -1.214278 s8 .i3.resv 20.940576 s8 .i3.ip 7.139113 s9 .i1.resv 7.147472 s9 .i1.ip 10.465706 s9 .i2.resv 14.562816 s9 .i2.ip 11.444166 s9 .i3.resv -1.436094 s9 .i3.ip -2.144297 s10.i1.resv 1.728924 s10.i1.ip 1.424648 s10.i2.resv 3.307312 s10.i2.ip 9.400273 s10.i3.resv 4.361133 s10.i3.ip 1.460645
Below is an example of importing a 3 dimensional table.
Set s /s1/ r /r1*r7/ a /a1*a35/ ; $onecho > data.csv ,,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35 s1,r1,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0 s1,r2,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0 s1,r3,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0 s1,r4,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0 s1,r5,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0 s1,r6,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0 s1,r7,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100,0,0,0,0,0,0,100 $offecho Table csvtable(s,r,a) 3 dimensional table $onDelim $include data.csv $offDelim display csvtable;