From 2338fdd2062a0cafba88f9fed7ed198dd641ff46 Mon Sep 17 00:00:00 2001 From: Johannes Keller Date: Mon, 4 May 2026 10:50:13 +0200 Subject: [PATCH] Fix: correct longitude distance calculation for snapping radius The previous logic produced a wrong `deltax` whenever both model and observation longitudes exceeded 180 deg. Replaced with shortest-arc formula from LSTDA: compute the absolute difference and wrap it by subtracting from 360 if it exceeds 180. --- interface/framework/obs_SM_pdafomi.F90 | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/interface/framework/obs_SM_pdafomi.F90 b/interface/framework/obs_SM_pdafomi.F90 index 13ec0ebb..7cc57dc9 100644 --- a/interface/framework/obs_SM_pdafomi.F90 +++ b/interface/framework/obs_SM_pdafomi.F90 @@ -424,10 +424,9 @@ SUBROUTINE init_dim_obs_SM(step, dim_obs) if(newgridcell) then if(is_use_dr) then - if (lon(g)>180) then - deltax = abs(lon(g)-lon_obs(i)-360) - else - deltax = abs(lon(g)-lon_obs(i)) + deltax = abs(lon(g)-lon_obs(i)) + if (deltax > 180.0) then + deltax = 360.0 - deltax end if deltay = abs(lat(g)-lat_obs(i)) end if @@ -611,10 +610,9 @@ SUBROUTINE init_dim_obs_SM(step, dim_obs) if(newgridcell) then if(is_use_dr) then - if (lon(g)>180) then - deltax = abs(lon(g)-lon_obs(i)-360) - else - deltax = abs(lon(g)-lon_obs(i)) + deltax = abs(lon(g)-lon_obs(i)) + if (deltax > 180.0) then + deltax = 360.0 - deltax end if deltay = abs(lat(g)-lat_obs(i)) end if @@ -704,10 +702,9 @@ SUBROUTINE init_dim_obs_SM(step, dim_obs) if(newgridcell) then if(is_use_dr) then - if (lon(g)>180) then - deltax = abs(lon(g)-lon_obs(i)-360) - else - deltax = abs(lon(g)-lon_obs(i)) + deltax = abs(lon(g)-lon_obs(i)) + if (deltax > 180.0) then + deltax = 360.0 - deltax end if deltay = abs(lat(g)-lat_obs(i)) end if