From 7cc98033e94ab533d4cedb2ae1a1c568e743fc9f Mon Sep 17 00:00:00 2001 From: uramirez8707 <49168881+uramirez8707@users.noreply.github.com> Date: Fri, 2 Aug 2024 13:24:53 -0400 Subject: [PATCH] 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) --- data_override/include/data_override.inc | 12 +++++-- data_override/include/get_grid_version.inc | 38 ++++++++++++++-------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/data_override/include/data_override.inc b/data_override/include/data_override.inc index 6de2f41b66..e79ee5d042 100644 --- a/data_override/include/data_override.inc +++ b/data_override/include/data_override.inc @@ -138,9 +138,15 @@ logical :: reproduce_null_char_bug = .false. !! to reproduce the mpp_io bug where lat/lon_bnd were !! not read correctly if null characters are present in !! the netcdf file +logical :: use_center_grid_points=.false. !< Flag indicating + !! whether or not to use the centroid values of the + !! supergrid from the grid file as opposed to calculating it + !! by taking the average of the four corner points. + !! This is only relevant to OCN and ICE grids. logical :: use_data_table_yaml = .false. -namelist /data_override_nml/ debug_data_override, grid_center_bug, reproduce_null_char_bug, use_data_table_yaml +namelist /data_override_nml/ debug_data_override, grid_center_bug, reproduce_null_char_bug, use_data_table_yaml, & + use_center_grid_points public :: DATA_OVERRIDE_INIT_IMPL_, DATA_OVERRIDE_UNSET_ATM_, DATA_OVERRIDE_UNSET_OCN_, & & DATA_OVERRIDE_UNSET_LND_, DATA_OVERRIDE_UNSET_ICE_, DATA_OVERRIDE_0D_, & @@ -340,7 +346,7 @@ end if call mpp_get_compute_domain( ocn_domain,is,ie,js,je) allocate(lon_local_ocn(is:ie,js:je), lat_local_ocn(is:ie,js:je)) call get_grid_version_2(fileobj, 'ocn', ocn_domain, is, ie, js, je, lon_local_ocn, lat_local_ocn, & - min_glo_lon_ocn, max_glo_lon_ocn ) + min_glo_lon_ocn, max_glo_lon_ocn, use_center_grid_points) endif if (lnd_on .and. .not. allocated(lon_local_lnd) ) then @@ -354,7 +360,7 @@ end if call mpp_get_compute_domain( ice_domain,is,ie,js,je) allocate(lon_local_ice(is:ie,js:je), lat_local_ice(is:ie,js:je)) call get_grid_version_2(fileobj, 'ocn', ice_domain, is, ie, js, je, lon_local_ice, lat_local_ice, & - min_glo_lon_ice, max_glo_lon_ice ) + min_glo_lon_ice, max_glo_lon_ice, use_center_grid_points ) endif end if if(use_get_grid_version .EQ. 2) then diff --git a/data_override/include/get_grid_version.inc b/data_override/include/get_grid_version.inc index fd65588e46..7690bbf685 100644 --- a/data_override/include/get_grid_version.inc +++ b/data_override/include/get_grid_version.inc @@ -143,7 +143,8 @@ end subroutine GET_GRID_VERSION_1_ !> Get global lon and lat of three model (target) grids from mosaic.nc. !! Currently we assume the refinement ratio is 2 and there is one tile on each pe. -subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lon, lat, min_lon, max_lon) +subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lon, lat, min_lon, max_lon, & + use_center_grid_points) integer, parameter :: lkind = FMS_GET_GRID_VERSION_KIND_ 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 integer, intent(in) :: isc, iec, jsc, jec real(lkind), dimension(isc:,jsc:), intent(out) :: lon, lat real(lkind), intent(out) :: min_lon, max_lon + logical, optional, intent(in) :: use_center_grid_points !< Flag indicating whether or not to use the + !! centroid values of the supergrid from the + !! grid file as opposed to calcuating it by + !! taking the average of the four corner points. + !! This is only relevant to OCN and ICE grids. integer :: i, j, siz(2) 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 logical :: open_solo_mosaic type(FmsNetcdfFile_t) :: mosaicfileobj, tilefileobj integer :: start(2), nread(2) + logical :: use_center_grid_points_local + + use_center_grid_points_local = .false. + if (present(use_center_grid_points)) use_center_grid_points_local = use_center_grid_points if(trim(mod_name) .NE. 'atm' .AND. trim(mod_name) .NE. 'ocn' .AND. & 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 call read_data( tilefileobj, 'y', tmpy, corner=start,edge_lengths=nread) ! copy data onto model grid - if(trim(mod_name) == 'ocn' .OR. trim(mod_name) == 'ice') then - do j = jsc, jec - do i = isc, iec - 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 - 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 - end do - end do + if(trim(mod_name) == 'atm' .OR. trim(mod_name) == 'lnd' .OR. use_center_grid_points_local) then + do j = jsc, jec + do i = isc, iec + lon(i,j) = tmpx(i*2,j*2) + lat(i,j) = tmpy(i*2,j*2) + end do + end do else - do j = jsc, jec - do i = isc, iec - lon(i,j) = tmpx(i*2,j*2) - lat(i,j) = tmpy(i*2,j*2) - end do - end do + do j = jsc, jec + do i = isc, iec + 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 + 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 + end do + end do endif ! convert to radian