Skip to content

Commit 7cc9803

Browse files
authored
fix: adds namelist flag use_center_grid_points to data_override to use the centroid grid points from the grid file instead of calculating them (#1566)
1 parent 33a87c6 commit 7cc9803

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

data_override/include/data_override.inc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,15 @@ logical :: reproduce_null_char_bug = .false.
138138
!! to reproduce the mpp_io bug where lat/lon_bnd were
139139
!! not read correctly if null characters are present in
140140
!! the netcdf file
141+
logical :: use_center_grid_points=.false. !< Flag indicating
142+
!! whether or not to use the centroid values of the
143+
!! supergrid from the grid file as opposed to calculating it
144+
!! by taking the average of the four corner points.
145+
!! This is only relevant to OCN and ICE grids.
141146
logical :: use_data_table_yaml = .false.
142147

143-
namelist /data_override_nml/ debug_data_override, grid_center_bug, reproduce_null_char_bug, use_data_table_yaml
148+
namelist /data_override_nml/ debug_data_override, grid_center_bug, reproduce_null_char_bug, use_data_table_yaml, &
149+
use_center_grid_points
144150

145151
public :: DATA_OVERRIDE_INIT_IMPL_, DATA_OVERRIDE_UNSET_ATM_, DATA_OVERRIDE_UNSET_OCN_, &
146152
& DATA_OVERRIDE_UNSET_LND_, DATA_OVERRIDE_UNSET_ICE_, DATA_OVERRIDE_0D_, &
@@ -340,7 +346,7 @@ end if
340346
call mpp_get_compute_domain( ocn_domain,is,ie,js,je)
341347
allocate(lon_local_ocn(is:ie,js:je), lat_local_ocn(is:ie,js:je))
342348
call get_grid_version_2(fileobj, 'ocn', ocn_domain, is, ie, js, je, lon_local_ocn, lat_local_ocn, &
343-
min_glo_lon_ocn, max_glo_lon_ocn )
349+
min_glo_lon_ocn, max_glo_lon_ocn, use_center_grid_points)
344350
endif
345351

346352
if (lnd_on .and. .not. allocated(lon_local_lnd) ) then
@@ -354,7 +360,7 @@ end if
354360
call mpp_get_compute_domain( ice_domain,is,ie,js,je)
355361
allocate(lon_local_ice(is:ie,js:je), lat_local_ice(is:ie,js:je))
356362
call get_grid_version_2(fileobj, 'ocn', ice_domain, is, ie, js, je, lon_local_ice, lat_local_ice, &
357-
min_glo_lon_ice, max_glo_lon_ice )
363+
min_glo_lon_ice, max_glo_lon_ice, use_center_grid_points )
358364
endif
359365
end if
360366
if(use_get_grid_version .EQ. 2) then

data_override/include/get_grid_version.inc

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ end subroutine GET_GRID_VERSION_1_
143143

144144
!> Get global lon and lat of three model (target) grids from mosaic.nc.
145145
!! Currently we assume the refinement ratio is 2 and there is one tile on each pe.
146-
subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lon, lat, min_lon, max_lon)
146+
subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lon, lat, min_lon, max_lon, &
147+
use_center_grid_points)
147148
integer, parameter :: lkind = FMS_GET_GRID_VERSION_KIND_
148149

149150
type(FmsNetcdfFile_t), intent(in) :: fileobj !< file object for grid file
@@ -152,6 +153,11 @@ subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lo
152153
integer, intent(in) :: isc, iec, jsc, jec
153154
real(lkind), dimension(isc:,jsc:), intent(out) :: lon, lat
154155
real(lkind), intent(out) :: min_lon, max_lon
156+
logical, optional, intent(in) :: use_center_grid_points !< Flag indicating whether or not to use the
157+
!! centroid values of the supergrid from the
158+
!! grid file as opposed to calcuating it by
159+
!! taking the average of the four corner points.
160+
!! This is only relevant to OCN and ICE grids.
155161

156162
integer :: i, j, siz(2)
157163
integer :: nlon, nlat ! size of global grid
@@ -164,6 +170,10 @@ subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lo
164170
logical :: open_solo_mosaic
165171
type(FmsNetcdfFile_t) :: mosaicfileobj, tilefileobj
166172
integer :: start(2), nread(2)
173+
logical :: use_center_grid_points_local
174+
175+
use_center_grid_points_local = .false.
176+
if (present(use_center_grid_points)) use_center_grid_points_local = use_center_grid_points
167177

168178
if(trim(mod_name) .NE. 'atm' .AND. trim(mod_name) .NE. 'ocn' .AND. &
169179
trim(mod_name) .NE. 'ice' .AND. trim(mod_name) .NE. 'lnd' ) call mpp_error(FATAL, &
@@ -215,20 +225,20 @@ subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lo
215225
call read_data( tilefileobj, 'y', tmpy, corner=start,edge_lengths=nread)
216226

217227
! copy data onto model grid
218-
if(trim(mod_name) == 'ocn' .OR. trim(mod_name) == 'ice') then
219-
do j = jsc, jec
220-
do i = isc, iec
221-
lon(i,j) = (tmpx(i*2-1,j*2-1)+tmpx(i*2+1,j*2-1)+tmpx(i*2+1,j*2+1)+tmpx(i*2-1,j*2+1))*0.25_lkind
222-
lat(i,j) = (tmpy(i*2-1,j*2-1)+tmpy(i*2+1,j*2-1)+tmpy(i*2+1,j*2+1)+tmpy(i*2-1,j*2+1))*0.25_lkind
223-
end do
224-
end do
228+
if(trim(mod_name) == 'atm' .OR. trim(mod_name) == 'lnd' .OR. use_center_grid_points_local) then
229+
do j = jsc, jec
230+
do i = isc, iec
231+
lon(i,j) = tmpx(i*2,j*2)
232+
lat(i,j) = tmpy(i*2,j*2)
233+
end do
234+
end do
225235
else
226-
do j = jsc, jec
227-
do i = isc, iec
228-
lon(i,j) = tmpx(i*2,j*2)
229-
lat(i,j) = tmpy(i*2,j*2)
230-
end do
231-
end do
236+
do j = jsc, jec
237+
do i = isc, iec
238+
lon(i,j) = (tmpx(i*2-1,j*2-1)+tmpx(i*2+1,j*2-1)+tmpx(i*2+1,j*2+1)+tmpx(i*2-1,j*2+1))*0.25_lkind
239+
lat(i,j) = (tmpy(i*2-1,j*2-1)+tmpy(i*2+1,j*2-1)+tmpy(i*2+1,j*2+1)+tmpy(i*2-1,j*2+1))*0.25_lkind
240+
end do
241+
end do
232242
endif
233243

234244
! convert to radian

0 commit comments

Comments
 (0)