Skip to content

optics_lib m_ice: short-wavelength branch search loop is a no-op ('continue' is not C continue), leading to out-of-bounds interpolation #161

Description

@duncanwp

Location: subsample_and_optics_example/optics/quickbeam_optics/optics_lib.F90, m_ice, line 542 (master 5eb05e5):

if (alam < cutice) then
   ! Region from 0.045 microns to 167.0 microns - no temperature depend
   do i=2,nwl
      if(alam < wl(i)) continue
   enddo
   x1  = log(wl(i-1))

In Fortran, continue is a no-op statement (not C's loop-continue), so this loop does nothing and always completes with i = nwl+1. The subsequent tabre(i) / wl(i) references then read one past the end of the nwl-sized arrays (silent out-of-bounds without -fcheck=bounds), and the interpolation uses the wrong bracket regardless.

The intended behaviour is clearly "find the first i with wl(i) > alam" (an exit instead of continue, or an infind-style search like the microwave branch below it).

Impact: latent for CloudSat use — at 94 GHz, alam = 3e5/94 ≈ 3191 um > cutice = 167 um, so only the temperature-dependent microwave branch executes. Any frequency above ~1.8 THz (or other reuse of m_ice at short wavelengths) would hit the broken branch.

Found while building a JAX translation of COSP (jax-cosp); its port implements the intended bracketing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions