Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect parsing of string that starts with "0Dxxxxx" #559

Closed
xldeltares opened this issue Jul 11, 2023 · 4 comments · Fixed by #626
Closed

Incorrect parsing of string that starts with "0Dxxxxx" #559

xldeltares opened this issue Jul 11, 2023 · 4 comments · Fixed by #626
Labels
priority: high type: bug Something isn't working

Comments

@xldeltares
Copy link
Collaborator

xldeltares commented Jul 11, 2023

Describe the bug
When reading a model that has storagenodes with id "0D05252", the string is parsed incorrectly as "0e05252"
A small test model is enclosed.
dflowfm.zip

To Reproduce
Steps to reproduce the behavior:

from hydrolib.core.dflowfm import FMModel
mdu = "FlowFM.mdu"
model = FMModel(mdu)
print(model.geometry.storagenodefile.storagenode[1].id)

The above steps returns: 0e05252

Expected behavior
The above steps should return" 0D05252

Screenshots
This can be verified in the nodeFile.ini:
image

Version info (please complete the following information):

  • OS: Windows
  • Version 0.5.2

Additional info
In my use case of Eindhoven, this is rather critical because there are more than 1000 nodes are parsed wrongly after reading. See below figure, the red nodes are parsed wrongly.
The wrongly parsed string will be written again but wont match the network node ID anymore, causing run to fail.
image

@priscavdsluis
Copy link
Contributor

priscavdsluis commented Aug 10, 2023

Another issue was reported via support: https://issuetracker.deltares.nl/browse/SOFTSUP-648

Source of bug:

for line in f:
    # Replace Fortran scientific notation for doubles
    # Match number d/D +/- number (e.g. 1d-05 or 1.23D+01 or 1.d-4)
    match = progline.match(line)
    if match:  # Only process value
        line = (
            match.group(1)
            + progfloat.sub(r"\1e\3", match.group(2))
            + str(match.group(3) or "")
        )
    else:  # Process full line
        line = progfloat.sub(r"\1e\3", line)
    parser.feed_line(line)

@tim-vd-aardweg
Copy link
Contributor

A side-effect of our fix is that you can now also set attributes that are floats using the Fortran scientific notation, e.g.:

from hydrolib.core.dflowfm import FMModel
mdu = "FlowFM.mdu"
model = FMModel(mdu)
model.geometry.storagenodefile.storagenode[1].area = "1d3")

@tim-vd-aardweg
Copy link
Contributor

@xldeltares Could you verify that this issue is fixed in branch: bug/559_Incorrect-parsing-of-string-starting-with-0D?

@xldeltares
Copy link
Collaborator Author

@tim-vd-aardwegAfter testing the reported bug in the example model enclosed, I confirm that the issues has been fixed in bug/559_Incorrect-parsing-of-string-starting-with-0D. Glad that this has been fixed and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high type: bug Something isn't working
Projects
Status: Done
5 participants