Skip to content

fix: Fix SAVE gotcha with read_snow17_parameters#55

Merged
aaraney merged 1 commit intoNOAA-OWP:masterfrom
robertbartel:b/fix_multi_cat_param_loading/main
Jun 24, 2025
Merged

fix: Fix SAVE gotcha with read_snow17_parameters#55
aaraney merged 1 commit intoNOAA-OWP:masterfrom
robertbartel:b/fix_multi_cat_param_loading/main

Conversation

@robertbartel
Copy link
Copy Markdown

Fixing bug in read_snow17_parameters subroutine. The overall result of this bug is that it is not currently possible to use this with ngen whenever more than one catchment formulation uses this as a BMI module.

Bug Description

For the read_snow17_parameters subroutine, the local ios variable is used by each read to get the next line of the given parameter file. A test of ios is used to determine when all lines of the parameter file have been read.

The problem is that the value of ios is being initialized as part of its declaration. As noted here and elsewhere, initializing at declaration implies the SAVE attribute is applied to the variable. The effect is that ios retains its value between calls.

Thus, ios is only properly set the first time the subroutine is run. In the second run, the test of whether the file has been completely read yields a false positive immediately, before any lines and parameter values have been read. That, in turn, leads to an error condition and a stop.

Changes

The declaration of ios is changed to not include initialization, and then a subsequent assignment statement is used to properly initialize its expected value for the start of read_snow17_parameters.

Testing

Local testing has been performed to ensure the read_snow17_parameters now completes without stopping execution.

Fixing bug in read_snow17_parameters subroutine due to local variable
being initialized at declaration, leading to values carried over from
previous invocations of the subroutine, and from that causing the
loading of the SECOND catchment's config param file to fail to load and
cause the execution to be stopped.
@andywood
Copy link
Copy Markdown
Contributor

Great fix, Robert. I think this was discussed pretty well in #44 -- maybe your fix can close this issue? (and definitely refer to it).

@andywood
Copy link
Copy Markdown
Contributor

btw great to see snow17 getting some attention. we do want to have it as a standard/base option in nextgen.

@robertbartel
Copy link
Copy Markdown
Author

Hmm ... yes, this addresses the same bug described in #44. However, I see there is also #47, which would also address #44 and then do a little bit more.

Given this bug is breaking the module's compatibility with NextGen, it may make more sense to merge this PR (a more minimal solution) first and return to #47 at some point later. But regardless, one of them needs to be fully approved and merged to fix the issue.

@robertbartel
Copy link
Copy Markdown
Author

Also, FWIW, there is a very similar issue and fix in Sac-SMA, in PR NOAA-OWP/sac-sma#16.

@andywood
Copy link
Copy Markdown
Contributor

Definitely ... the two codes came from the same source, which was run in a different use case, and inherited some inconsistencies with the nextgen driver. I'm glad this is getting resolved now.

@andywood
Copy link
Copy Markdown
Contributor

I don't have time to fully review it now (as in run test it myself), but I can at least concur that these changes are needed.

@aaraney aaraney self-requested a review June 24, 2025 18:34
@aaraney aaraney merged commit fef3388 into NOAA-OWP:master Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants