The original code in ncio_mod.f90 encountered an out-of-bounds error with bounds checking enabled, primarily due to the following reasons:
Out-of-Bounds Access: The code attempted to access geoinst_list(ityp) where ityp often exceeded the bounds of geoinst_list, causing a runtime error when bounds checking was enabled in gfortran.
Convoluted Logic: The condition for selecting the set_obserr subroutine relied on checking if geoinst_list(ityp) equaled "ahi_himawari8". However, this was indirect and unreliable, as the true condition of interest was whether write_opt == write_nc_radiance_geo.
Solution
The logic was refactored to directly check if (write_opt == write_nc_radiance_geo), ensuring the proper subroutine (set_ahi_obserr or set_brit_obserr) is selected based on this condition alone. This simplifies the code and avoids the risk of accessing out-of-bounds elements in geoinst_list.
Summary of Code Changes
Replaced if (geoinst_list(ityp) == "ahi_himawari8") with if (write_opt == write_nc_radiance_geo).
This new condition directly matches the intended condition for setting observation errors without risking out-of-bounds access.
Impact
This fix resolves the bounds error when using bounds-checking compilers like gfortran, improves code readability, and aligns the logic more closely with the intended conditions for setting observation errors.
Problem
The original code in
ncio_mod.f90
encountered an out-of-bounds error with bounds checking enabled, primarily due to the following reasons:geoinst_list(ityp)
whereityp
often exceeded the bounds ofgeoinst_list
, causing a runtime error when bounds checking was enabled in gfortran.set_obserr
subroutine relied on checking ifgeoinst_list(ityp)
equaled"ahi_himawari8"
. However, this was indirect and unreliable, as the true condition of interest was whetherwrite_opt == write_nc_radiance_geo
.Solution
The logic was refactored to directly check
if (write_opt == write_nc_radiance_geo)
, ensuring the proper subroutine (set_ahi_obserr
orset_brit_obserr
) is selected based on this condition alone. This simplifies the code and avoids the risk of accessing out-of-bounds elements ingeoinst_list
.Summary of Code Changes
if (geoinst_list(ityp) == "ahi_himawari8")
withif (write_opt == write_nc_radiance_geo)
.Impact
This fix resolves the bounds error when using bounds-checking compilers like gfortran, improves code readability, and aligns the logic more closely with the intended conditions for setting observation errors.