Page 1 of 2

.inc files

Posted: Wed Sep 05, 2018 11:45 am
by ferrib
Hi there,

I am having trouble importing data using ".inc" files.

I am able to import data my parameters from an excel sheet. But it takes such a long time to process, and I have an old example where parameters were imported using .inc files so I decided to give it a try (this seemed faster for the parameters i was able to import, but correct me if not!).

For parameters which only contain one value or an array i managed to read the .inc file. But when I have columns I can't. I suppose this has to do with how data is formatted (i copied a table from excel and pasted it on the notepad file) - i get errors 170 (domain violation - dimension different) and 334 (i guess because of 170). I have also tried .csv files, but i did not manage to do it: anyway, would it be faster than from the excel file?

example of the data i need to input (couldn't attach, "invalid format"):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
d1 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480
d2 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490
d3 34 54 74 94 114 134 154 174 194 214 234 254 274 294 314 334 354 374 394 414 434 454 474 494
d4 38 58 78 98 118 138 158 178 198 218 238 258 278 298 318 338 358 378 398 418 438 458 478 498

Many thanks in advance.
F

Re: .inc files

Posted: Wed Sep 05, 2018 12:05 pm
by bussieck
The following works for me. Since you did not align the data (required for normal Table statement), you need to read under $ondelim. For this you need to add the 'd' in the header row:

Code: Select all

set i / 1*24 /, d / d1*d4 /;
$onecho > data.inc
d 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
d1 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380 400 420 440 460 480
d2 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490
d3 34 54 74 94 114 134 154 174 194 214 234 254 274 294 314 334 354 374 394 414 434 454 474 494
d4 38 58 78 98 118 138 158 178 198 218 238 258 278 298 318 338 358 378 398 418 438 458 478 498
$offecho
table data(d,i)
$ondelim
$include data.inc
$offdelim
;
-Michael

Re: .inc files

Posted: Wed Sep 05, 2018 12:50 pm
by ferrib
Michael,

Thanks so much for your quick feedback.

Understood the $ondelim and $offdelim, also the first "d". Additionally, I was only declaring the table as "parameter" (and not "table") - and that was working for importing data from the excel.

Re: .inc files

Posted: Wed Sep 05, 2018 2:12 pm
by bussieck
Not sure how you read data from Excel, but with gdxxrw (the best supported way) you get a GDX file and then it does not matter if you declare as parameter or table.

-Michael

Re: .inc files

Posted: Mon Sep 17, 2018 8:37 pm
by mahmoudabadi
Dear Ferrib
I agree with bussieck. If your data is in Excel sheet file, the best way is to use GDXXRW which is a very powerful command to read and write data from and on Excel sheet files.
I had many problems to use .inc files, but I am using the above command without any problem.
Regards, Abbas Mahmoudabadi

Re: .inc files

Posted: Tue Sep 18, 2018 12:58 pm
by ferrib
Hi there,

I tried GDXXRW but .inc is way faster. I was losing 1 minute to input the data via GDXXRW, but with .inc files it takes literally nothing.

Best regards

Re: .inc files

Posted: Wed Sep 19, 2018 7:54 am
by Renger
Hi
GDXXRW has the option "CheckDate": it checks before importing the data from an excel sheet if the sheet has been changed in the meantime. If not, it will skip the import and use the already available gdx file from the most recent import.
Cheers
Renger

Re: .inc files

Posted: Tue Oct 30, 2018 6:16 pm
by ferrib
Hi again,

Just ressurrecting this topic to see if any of you can provide an example with the CheckDate option. I can't make it work. Let's say my example for loading data is as follows, where should i place my "checkdate"?

Set d;
$call gdxxrw.exe i=input.xlsx set=d rng=Sheet1!c2 rdim=1 cdim=0
$gdxin input.gdx
$load d
$gdxin
display d;

Thanks in advance

Re: .inc files

Posted: Wed Oct 31, 2018 7:53 am
by Renger
Hi
It should be written at the end of the line and correctly spelled: not "checkdate" but CheckDate.
If this doesn't work, please send an excel sheet and the code that doesn't work.
Cheers
Renger

Re: .inc files

Posted: Wed Oct 31, 2018 10:48 am
by ferrib
Hi Renger,

Thanks for your help.

Attached the .xlsx file and the gams code.