Skip to content

Commit fca3bd5

Browse files
authored
Fix: correct longitude distance calculation for snapping radius (#79)
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. Found by: @visakhraja
1 parent f9a560a commit fca3bd5

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

interface/framework/obs_SM_pdafomi.F90

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,9 @@ SUBROUTINE init_dim_obs_SM(step, dim_obs)
424424
if(newgridcell) then
425425

426426
if(is_use_dr) then
427-
if (lon(g)>180) then
428-
deltax = abs(lon(g)-lon_obs(i)-360)
429-
else
430-
deltax = abs(lon(g)-lon_obs(i))
427+
deltax = abs(lon(g)-lon_obs(i))
428+
if (deltax > 180.0) then
429+
deltax = 360.0 - deltax
431430
end if
432431
deltay = abs(lat(g)-lat_obs(i))
433432
end if
@@ -611,10 +610,9 @@ SUBROUTINE init_dim_obs_SM(step, dim_obs)
611610
if(newgridcell) then
612611

613612
if(is_use_dr) then
614-
if (lon(g)>180) then
615-
deltax = abs(lon(g)-lon_obs(i)-360)
616-
else
617-
deltax = abs(lon(g)-lon_obs(i))
613+
deltax = abs(lon(g)-lon_obs(i))
614+
if (deltax > 180.0) then
615+
deltax = 360.0 - deltax
618616
end if
619617
deltay = abs(lat(g)-lat_obs(i))
620618
end if
@@ -704,10 +702,9 @@ SUBROUTINE init_dim_obs_SM(step, dim_obs)
704702
if(newgridcell) then
705703

706704
if(is_use_dr) then
707-
if (lon(g)>180) then
708-
deltax = abs(lon(g)-lon_obs(i)-360)
709-
else
710-
deltax = abs(lon(g)-lon_obs(i))
705+
deltax = abs(lon(g)-lon_obs(i))
706+
if (deltax > 180.0) then
707+
deltax = 360.0 - deltax
711708
end if
712709
deltay = abs(lat(g)-lat_obs(i))
713710
end if

0 commit comments

Comments
 (0)