NCAR / DART

Data Assimilation Research Testbed
https://dart.ucar.edu/
Apache License 2.0
184 stars 139 forks source link

set_location followed by get_location does not necessarily return the same value #621

Open hkershaw-brown opened 6 months ago

hkershaw-brown commented 6 months ago

This was a Jira issue DART-12

see example program below:

program bitwise_creep

use types_mod,    only : r8
use location_mod, only : location_type, VERTISLEVEL, set_location, get_location
use utilities_mod, only : initialize_utilities

implicit none

real(r8) :: lon, lat, lev
real(r8) :: lon_lat_lev(3)
type(location_type) :: location
integer :: i

call initialize_utilities()

lon = -91.868560791015625_r8
lat =  16.901844024658203_r8
lev = 1.0_r8

! dart expects longitude [0,360]
do while (lon <   0.0_r8)
   lon = lon + 360.0_r8
end do
do while (lon > 360.0_r8)
   lon = lon - 360.0_r8
end do

do i = 1, 10
print*, 'lon, lat', lon, lat

location = set_location(lon, lat, lev, VERTISLEVEL)
lon_lat_lev = get_location(location)

print*, 'lon, lat', lon_lat_lev(1), lon_lat_lev(2)
enddo

end program bitwise_creep
hkershaw@cisl-fisher work (main) $ ./bitwise-creep 

 --------------------------------------
 Starting ... at YYYY MM DD HH MM SS = 
                 2024  1 12 10  9  1
 --------------------------------------

  set_nml_output Echo NML values to log file only
 lon, lat   268.13143920898438        16.901844024658203     
  location_mod: using code with optimized cutoffs
  location_mod: Including vertical separation when computing distances:
  location_mod:        # pascals ~ 1 horiz radian:     6666666.70000
  location_mod:         # meters ~ 1 horiz radian:     5000000.00000
  location_mod:   # model levels ~ 1 horiz radian:        2666.70000
  location_mod:  # scale heights ~ 1 horiz radian:          10.00000
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203     
 lon, lat   268.13143920898438        16.901844024658203     
 lon, lat   268.13143920898443        16.901844024658203