Page 1 of 1

several error messages when reading csv file

Posted: Wed Sep 05, 2018 7:31 pm
by LaurentFranckx
Dear all

I am trying to read the attached csv file with the following code:

Code: Select all

sets
year                             /1970*2040/  
cartype                          /gas,dies,gashybr,dieshybr,gashybr_cs,dieshybr_cs,gashybr_phev,dieshybr_phev,electric,fuelcellh2,h2ice,cng,lpg,motor/
sizeall                          /small, medium, big, all/
size(sizeall)                    /small, medium, big/
;

Table ProbasAllYears(CARTYPE,SIZE,YEAR)
$ondelim
$include C:\Usr\gams\PLANET\pttv_2018\output\ProbabasAllYearsFuelSize.csv
$offdelim

display   ProbasAllYears;
I get the following error messages, but I don't understand in what sense my file format does not comply with the requirements:

170 Domain violation for element
176 A row with the same name has been defined before in this table.
338 Unique element expected - symbol was not an element
and the following text will be skipped until a proper
symbol is found to recover. Remember that an UNQUOTED
element has to start with a letter or digit
followed by letters, digits, '+', '-' or '_'. The length
is limited to 31 characters. The following words are
reserved (starting symbols of a GAMS statement) and cannot
be used for UNQUOTED set elements:

ABORT, ACRONYM(S), ALIAS, BINARY, DISPLAY, ELSE
EQUATION(S), EXECUTE, FILE(S), FOR, FREE, IF, INTEGER, LOOP
MODEL(S), NEGATIVE, OPTION(S), PARAMETER(S)
POSITIVE, PROCEDURE(S), PUT, PUTCLEAR, PUTCLOSE, PUTHD
PUTPAGE, PUTTL, SCALAR(S), SEMICONT, SET(S), SOS1, SOS2
TABLE, VARIABLE(S), WHILE

QUOTED elements can contain any character. Single and
double quotes can be used (starting and ending quote have
to match).
455 Bad or missing delimiter while reading delimited data records

Re: several error messages when reading csv file

Posted: Thu Sep 06, 2018 10:57 am
by bussieck
Hi,

A GAMS table (with $ondelim) expects the last index as columns:

Code: Select all

table ProbasAllYears(CARTYPE,SIZE,YEAR)
$ondelim
cartype,size,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040
"dies","big",0.0507656349910645,0.0506888328163802,0.0435304882627481,0.0423379453305934,0.0420584395679741,0.0416762672708161,0.0409093846044358,0.0415426968837625,0.0412929266359249,0.0410590804354346,0.0408219105516127,0.040581151277351,0.0403365229023376,0.0400907028654152,0.0398405018371827,0.0395856196245794,0.039325746478762,0.0390605631336655,0.0388070750896296,0.038553960003693,0.0383012134129239,0.0380488310714533,0.0377968087711261,0.0375566842319094,0.0373167819472338,0.0370770980081705,0.0368376288076266,0.0365983709898335
"dies","medium",0.537902777656067,0.537593963635057,0.461541890853509...
...
$offdelim
;
...
You don't have a table, but a nice database format, so just read it as this by switching from table to parameter:

Code: Select all

Parameter ProbasAllYears(CARTYPE,SIZE,YEAR) /
$ondelim
$include C:\Users\bussieck\Downloads\ProbabasAllYearsFuelSize.csv
$offdelim
/;
-Michael

Re: several error messages when reading csv file

Posted: Fri Sep 07, 2018 1:26 pm
by LaurentFranckx
That solved it, thanks.