Fix divide-by-zero in domain_def_clm for degenerate 1x1 domains#65
Merged
zhao7777 merged 1 commit intoHPSCTerrSys:tsmp-pdaf-patched-LAI_DAfrom Apr 1, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug: TSMP-PDAF crashes during CLM observation setup with a floating-point exception (divide by zero) in domain_def_clm (enkf_clm_mod_5.F90), e.g. when calling init_dim_obs_pdaf → domain_def_clm, see: #64
Cause: For a single land grid cell (1×1 domain), minlon == maxlon and minlat == maxlat after shifting by +180° / +90°, so (maxlon - minlon) and (maxlat - minlat) are zero. The code then maps observation lon/lat to grid indices by dividing by those spans. When observation coordinates differ slightly from the grid (e.g. float32 in NetCDF vs. double lonc/latc), the first branch can still be taken and divide by zero.
Fix: Compute longitudinal and latitudinal spans in real(r8) and treat the domain as degenerate when span ≤ 1.0e-6 (same units as lon+180 / lat+90).