Deltares / HYDROLIB-core

Core code around the I/O of the DHYDRO-suite
https://deltares.github.io/HYDROLIB-core/
MIT License
25 stars 4 forks source link

Multiline obs/crs files are not parsed correctly #485

Open veenstrajelmer opened 1 year ago

veenstrajelmer commented 1 year ago

There was a multiline method implemented in kernel+GUI with \ as a separator, to be used for obs/crs files and maybe others. This is an example snippet from the mdu:

ObsFile   = ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_1_kilometer_obs.xyn \ # Points file *.xyn with observation stations with rows x, y, station name
            ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_2_output_obs.xyn \
            ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_3_measurement_obs.xyn                                      
CrsFile   = ../../../geometry/cross_sections_v2b/rmm_vzm-j19_6-v2b_2_output_crs.pli \ # Polyline file *_crs.pli defining observation cross sections
            ../../../geometry/cross_sections_v2b/rmm_vzm-j19_6-v2b_3_measurement_crs.pli \
            ../../../geometry/cross_sections_v2b/rmm_vzm-j19_6-v2b_4_calibration_crs.pli 

hydrolib-core does not support this and raises the following:

ValidationError: 2 validation errors for FMModel
RMM_VZM_commented.mdu -> output -> crsFile -> 1
  File: `\\directory.intra\Project\` not found, skipped parsing. (type=value_error)
RMM_VZM_commented.mdu -> output -> crsFile -> 1
  File: `\\directory.intra\Project\` not found, skipped parsing. (type=value_error)

This happens for the \ at the end of the line, which makes sense to me and I wonder whether it should be supported or removed from kernel+gui instead. The latter makes more sense to me since I expect this is non-standard ini-formatting.

Additional information

OpenDA also crashes on this type of input

And a fun fact, the FM kernel crashes on too long space-delimited input (but only for crs, obs works fine):

ObsFile                             = ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_1_kilometer_obs.xyn  ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_2_output_obs.xyn                                        ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_3_measurement_obs.xyn                                      
CrsFile                             = ../../../geometry/cross_sections_v2b/rmm_vzm-j19_6-v2b_2_output_crs.pli  ../../../geometry/cross_sections_v2b/rmm_vzm-j19_6-v2b_3_measurement_crs.pli                                        ../../../geometry/cross_sections_v2b/rmm_vzm-j19_6-v2b_4_calibration_crs.pli 

Gives:

** ERROR  : Observation cross section file '../../../geometry/cross_sections_v2b/rmm_vzm-j19_6-v2b_4_calibrati' not found!
arthurvd commented 1 year ago

@veenstrajelmer : You're quite right, I can see that in the kernel code:

    character(len=1024):: md_obsfile       = ' ' !< File containing observation points  (e.g., *_obs.xyn, *_obs.ini)
    character(len=255) :: md_crsfile       = ' ' !< File containing cross sections (e.g., *_crs.pli, observation cross section *_crs.ini)   

Will fix it over there --> https://issuetracker.deltares.nl/browse/UNST-6813

veenstrajelmer commented 1 year ago

I have tested the behaviour when a file is given with multiline obs/crs files, but without \, so like this:

ObsFile                             = ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_1_kilometer_obs.xyn # Points file *.xyn with observation stations with rows x, y, station name
                                      ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_2_output_obs.xyn
                                      ../../../geometry/output_locations_v2b/rmm_vzm-j19_6-v2b_3_measurement_obs.xyn                                      

In this case, only the first filename is being read. I would expect a parsing error since the lines below should fail to read somewhere. Since they are not comments, I would say it should raise an error.