Skip to content

Fix divide-by-zero in domain_def_clm for degenerate 1x1 domains#65

Merged
zhao7777 merged 1 commit intoHPSCTerrSys:tsmp-pdaf-patched-LAI_DAfrom
zhao7777:tsmp-pdaf-patched-LAI_DA
Apr 1, 2026
Merged

Fix divide-by-zero in domain_def_clm for degenerate 1x1 domains#65
zhao7777 merged 1 commit intoHPSCTerrSys:tsmp-pdaf-patched-LAI_DAfrom
zhao7777:tsmp-pdaf-patched-LAI_DA

Conversation

@zhao7777
Copy link
Copy Markdown
Collaborator

@zhao7777 zhao7777 commented Apr 1, 2026

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).

@zhao7777 zhao7777 merged commit e402449 into HPSCTerrSys:tsmp-pdaf-patched-LAI_DA Apr 1, 2026
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.

1 participant