NCAR / obs2ioda

Converter developed by @jamiebresch to transform conventional and remote sensing observations in different formats to the IODA format needed in JEDI
4 stars 4 forks source link

Fix Out-of-Bounds Error and Streamline Logic for Setting Observation Error Subroutine in ncio_mod.f90 #18

Closed amstokely closed 2 days ago

amstokely commented 5 days ago

Problem

The original code in ncio_mod.f90 encountered an out-of-bounds error with bounds checking enabled, primarily due to the following reasons:

  1. 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.
  2. 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

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.

amstokely commented 2 days ago

Thank you so much for fixing it @amstokely

You got it!!!