Skip to content

bug fix: out of bounds array indexing error #895

Merged
scrasmussen merged 1 commit into
NCAR:mainfrom
scrasmussen:fix/array-bounds-1
Jun 5, 2026
Merged

bug fix: out of bounds array indexing error #895
scrasmussen merged 1 commit into
NCAR:mainfrom
scrasmussen:fix/array-bounds-1

Conversation

@scrasmussen

Copy link
Copy Markdown
Member

TYPE: bug fix

KEYWORDS: array bounds, indexing error, debugging

SOURCE: Soren Rasmussen, NSF NCAR

DESCRIPTION OF CHANGES:

  • fixing out of bounds array indexing error
    • seems to be a copy-and-paste coding error. The variable index is the one being worked on, not trim(fileMeta%varNames(iTmp)) whose iTmp indexing variable isn't even being set in that do loop
  • compiled with flags -O0 -g -fbacktrace -fcheck=bounds -fsanitize=address -fno-omit-frame-pointer
  • before fixing the bug, running led to the following error (note I slightly modified the following message for clarity)
$ mpiexec -np 4 ./wrf_hydro
...
 Opening
At line 3368 of file src/Routing/module_NWM_io.F90
Fortran runtime error: Index '9' of dimension 1 of array 'filemeta%varnames' above upper bound of 1

Error termination. Backtrace:
#0  0x2e8e749 in __module_nwm_io_MOD_output_chrtout_grd_nwm
        at src/Routing/module_NWM_io.F90:3368
#1  0x2c98bb0 in __module_hydro_drv_MOD_hydro_out
        at src/HYDRO_drv/module_HYDRO_drv.F90:422
#2  0x2c49001 in __module_hydro_drv_MOD_hydro_ini
        at src/HYDRO_drv/module_HYDRO_drv.F90:1622
...

@rcabell

rcabell commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

This does seem to be producing legitimate value regressions in the Reach-Lakes case, @scrasmussen are you expecting this?

@rcabell rcabell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it would have been nice to have the message still have the variable name, I think this is a reasonable and safe approach

@scrasmussen

Copy link
Copy Markdown
Member Author

While it would have been nice to have the message still have the variable name, I think this is a reasonable and safe approach

It seems like the message doesn't have the variable name, since the other nwmCheck calls use a variable for the variable name, but at this point they switch to using the string index in the line iret = nf90_def_var(ftn,'index',nf90_int,(/dimId(2),dimId(3)/),varid=indexVarId) call.

Thanks for reviewing! I'll go ahead and merge it

@scrasmussen scrasmussen merged commit 82a1be8 into NCAR:main Jun 5, 2026
11 of 15 checks passed
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.

2 participants