femiguez / apsimx

R package for APSIM-X
https://femiguez.github.io/apsimx-docs/
49 stars 20 forks source link

.apsimx file cannot be opened after editing clock - "Error reading file (...) --> Could not convert string to DateTime: 30/12/2014." #164

Closed LenLon closed 4 weeks ago

LenLon commented 1 month ago

When I edit the clock using edit_apsimx, the edited simulation file can then not be opened by the GUI anymore, giving the following error:

Error reading file \WestAfrica_C4Maize.apsimx --> Could not convert string to DateTime: 30/12/2014. Path 'Children[1].Children[0].End', line 26, position 29.

Opening the .apsimx file itself in notepad, the start and end dates look just fine:

image

femiguez commented 1 month ago

@LenLon APSIM expects dates in this format.

ex.dir <- auto_detect_apsimx_examples()
inspect_apsimx("Maize", ex.dir)
# Start: 1990-01-01T00:00:00 
# End: 2000-12-31T00:00:00 

I'm planning to create a function 'check_apsimx' that will catch many of these issues before attempting to run the model. Stay tuned... :)

LenLon commented 1 month ago

Ah thank you, that fixed it.

For posterity, here is the as.Date() command that creates dates in this format in R:

> start_date <- format(as.Date("2020-12-31"), "%Y-%m-%dT%H:%M:%S")
> start_date
[1] "2020-12-31T00:00:00"
femiguez commented 4 weeks ago

@LenLon If you are interested in early testing, I just pushed some changes. There is a function 'check_apsimx' that will test things such as the date format. I'm closing this issue, but please open a new one if you need it.