Skip to content

Commit 96e97c0

Browse files
authored
Fix!: Simplify argument lists of subroutines in get_grid_version_mod (#1514)
BREAKING CHANGE: removes compute indices from argument list from get_grid_version.
1 parent d94e3b3 commit 96e97c0

File tree

4 files changed

+32
-58
lines changed

4 files changed

+32
-58
lines changed

data_override/get_grid_version.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module get_grid_version_mod
2727
use platform_mod, only: r4_kind, r8_kind, FMS_PATH_LEN
2828
use mpp_mod, only : mpp_error,FATAL,NOTE, mpp_min, mpp_max
2929
use mpp_domains_mod, only : domain2d, operator(.NE.),operator(.EQ.)
30-
use mpp_domains_mod, only : mpp_get_global_domain, mpp_get_data_domain
30+
use mpp_domains_mod, only : mpp_get_compute_domain, mpp_get_global_domain
3131
use fms2_io_mod, only : FmsNetcdfDomainFile_t, FmsNetcdfFile_t, open_file, close_file, &
3232
variable_exists, read_data, get_variable_size, get_variable_num_dimensions
3333
use mosaic2_mod, only : get_mosaic_tile_grid

data_override/include/data_override.inc

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ subroutine DATA_OVERRIDE_INIT_IMPL_(Atm_domain_in, Ocean_domain_in, Ice_domain_i
173173
type(domainUG) , intent(in), optional :: Land_domainUG_in !> Land domain, unstructured grid
174174

175175
character(len=18), parameter :: grid_file = 'INPUT/grid_spec.nc'
176-
integer :: is,ie,js,je,use_get_grid_version
177-
integer :: i, iunit, io_status, ierr
176+
integer :: i, iunit, io_status, ierr, use_get_grid_version
178177
logical :: atm_on, ocn_on, lnd_on, ice_on, lndUG_on
179178
logical :: file_open
180179
type(FmsNetcdfFile_t) :: fileobj
@@ -309,58 +308,42 @@ end if
309308

310309
if(use_get_grid_version .EQ. 1) then
311310
if (atm_on .and. .not. allocated(lon_local_atm) ) then
312-
call mpp_get_compute_domain( atm_domain,is,ie,js,je)
313-
allocate(lon_local_atm(is:ie,js:je), lat_local_atm(is:ie,js:je))
314-
call get_grid_version_1(grid_file, 'atm', atm_domain, is, ie, js, je, lon_local_atm, lat_local_atm, &
311+
call get_grid_version_1(grid_file, 'atm', atm_domain, lon_local_atm, lat_local_atm, &
315312
min_glo_lon_atm, max_glo_lon_atm )
316313
endif
317314
if (ocn_on .and. .not. allocated(lon_local_ocn) ) then
318-
call mpp_get_compute_domain( ocn_domain,is,ie,js,je)
319-
allocate(lon_local_ocn(is:ie,js:je), lat_local_ocn(is:ie,js:je))
320-
call get_grid_version_1(grid_file, 'ocn', ocn_domain, is, ie, js, je, lon_local_ocn, lat_local_ocn, &
315+
call get_grid_version_1(grid_file, 'ocn', ocn_domain, lon_local_ocn, lat_local_ocn, &
321316
min_glo_lon_ocn, max_glo_lon_ocn )
322317
endif
323318

324319
if (lnd_on .and. .not. allocated(lon_local_lnd) ) then
325-
call mpp_get_compute_domain( lnd_domain,is,ie,js,je)
326-
allocate(lon_local_lnd(is:ie,js:je), lat_local_lnd(is:ie,js:je))
327-
call get_grid_version_1(grid_file, 'lnd', lnd_domain, is, ie, js, je, lon_local_lnd, lat_local_lnd, &
320+
call get_grid_version_1(grid_file, 'lnd', lnd_domain, lon_local_lnd, lat_local_lnd, &
328321
min_glo_lon_lnd, max_glo_lon_lnd )
329322
endif
330323

331324
if (ice_on .and. .not. allocated(lon_local_ice) ) then
332-
call mpp_get_compute_domain( ice_domain,is,ie,js,je)
333-
allocate(lon_local_ice(is:ie,js:je), lat_local_ice(is:ie,js:je))
334-
call get_grid_version_1(grid_file, 'ice', ice_domain, is, ie, js, je, lon_local_ice, lat_local_ice, &
325+
call get_grid_version_1(grid_file, 'ice', ice_domain, lon_local_ice, lat_local_ice, &
335326
min_glo_lon_ice, max_glo_lon_ice )
336327
endif
337328
else
338329
if (atm_on .and. .not. allocated(lon_local_atm) ) then
339-
call mpp_get_compute_domain(atm_domain,is,ie,js,je)
340-
allocate(lon_local_atm(is:ie,js:je), lat_local_atm(is:ie,js:je))
341-
call get_grid_version_2(fileobj, 'atm', atm_domain, is, ie, js, je, lon_local_atm, lat_local_atm, &
330+
call get_grid_version_2(fileobj, 'atm', atm_domain, lon_local_atm, lat_local_atm, &
342331
min_glo_lon_atm, max_glo_lon_atm )
343332
endif
344333

345334
if (ocn_on .and. .not. allocated(lon_local_ocn) ) then
346-
call mpp_get_compute_domain( ocn_domain,is,ie,js,je)
347-
allocate(lon_local_ocn(is:ie,js:je), lat_local_ocn(is:ie,js:je))
348-
call get_grid_version_2(fileobj, 'ocn', ocn_domain, is, ie, js, je, lon_local_ocn, lat_local_ocn, &
335+
call get_grid_version_2(fileobj, 'ocn', ocn_domain, lon_local_ocn, lat_local_ocn, &
349336
min_glo_lon_ocn, max_glo_lon_ocn, use_center_grid_points)
350337
endif
351338

352339
if (lnd_on .and. .not. allocated(lon_local_lnd) ) then
353-
call mpp_get_compute_domain( lnd_domain,is,ie,js,je)
354-
allocate(lon_local_lnd(is:ie,js:je), lat_local_lnd(is:ie,js:je))
355-
call get_grid_version_2(fileobj, 'lnd', lnd_domain, is, ie, js, je, lon_local_lnd, lat_local_lnd, &
340+
call get_grid_version_2(fileobj, 'lnd', lnd_domain, lon_local_lnd, lat_local_lnd, &
356341
min_glo_lon_lnd, max_glo_lon_lnd )
357342
endif
358343

359344
if (ice_on .and. .not. allocated(lon_local_ice) ) then
360-
call mpp_get_compute_domain( ice_domain,is,ie,js,je)
361-
allocate(lon_local_ice(is:ie,js:je), lat_local_ice(is:ie,js:je))
362-
call get_grid_version_2(fileobj, 'ocn', ice_domain, is, ie, js, je, lon_local_ice, lat_local_ice, &
363-
min_glo_lon_ice, max_glo_lon_ice, use_center_grid_points )
345+
call get_grid_version_2(fileobj, 'ocn', ice_domain, lon_local_ice, lat_local_ice, &
346+
min_glo_lon_ice, max_glo_lon_ice, use_center_grid_points)
364347
endif
365348
end if
366349
if(use_get_grid_version .EQ. 2) then

data_override/include/get_grid_version.inc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,23 @@
1818
!***********************************************************************
1919

2020
!> Get global lon and lat of three model (target) grids, with a given file name
21-
subroutine GET_GRID_VERSION_1_(grid_file, mod_name, domain, isc, iec, jsc, jec, lon, lat, min_lon, max_lon)
21+
subroutine GET_GRID_VERSION_1_(grid_file, mod_name, domain, lon, lat, min_lon, max_lon)
2222
integer, parameter :: lkind = FMS_GET_GRID_VERSION_KIND_
2323

2424
character(len=*), intent(in) :: grid_file !< name of grid file
2525
character(len=*), intent(in) :: mod_name !< module name
2626
type(domain2d), intent(in) :: domain !< 2D domain
27-
integer, intent(in) :: isc, iec, jsc, jec
28-
real(lkind), dimension(isc:,jsc:), intent(out) :: lon, lat
29-
real(lkind), intent(out) :: min_lon, max_lon
27+
real(lkind), intent(out), dimension(:,:), allocatable :: lon, lat
28+
real(lkind), intent(out) :: min_lon, max_lon
3029

3130
integer :: i, j, siz(4)
3231
integer :: nlon, nlat !< size of global lon and lat
3332
real(lkind), dimension(:,:,:), allocatable :: lon_vert, lat_vert !< of OCN grid vertices
3433
real(lkind), dimension(:), allocatable :: glon, glat !< lon and lat of 1-D grid of atm/lnd
3534
logical :: is_new_grid
3635
integer :: is, ie, js, je
37-
integer :: isd, ied, jsd, jed
3836
integer :: isg, ieg, jsg, jeg
37+
integer :: isc, iec, jsc, jec
3938
character(len=3) :: xname, yname
4039
integer :: start(2), nread(2)
4140
type(FmsNetcdfDomainFile_t) :: fileobj
@@ -45,8 +44,11 @@ subroutine GET_GRID_VERSION_1_(grid_file, mod_name, domain, isc, iec, jsc, jec,
4544
call mpp_error(FATAL, 'data_override_mod(get_grid_version_1): Error in opening file '//trim(grid_file))
4645
endif
4746

48-
call mpp_get_data_domain(domain, isd, ied, jsd, jed)
4947
call mpp_get_global_domain(domain, isg, ieg, jsg, jeg)
48+
call mpp_get_compute_domain(domain, isc, iec, jsc, jec)
49+
50+
allocate(lon(isc:iec, jsc:jec))
51+
allocate(lat(isc:iec, jsc:jec))
5052

5153
select case(mod_name)
5254
case('ocn', 'ice')
@@ -143,16 +145,14 @@ end subroutine GET_GRID_VERSION_1_
143145

144146
!> Get global lon and lat of three model (target) grids from mosaic.nc.
145147
!! 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, &
147-
use_center_grid_points)
148+
subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, lon, lat, min_lon, max_lon, use_center_grid_points)
148149
integer, parameter :: lkind = FMS_GET_GRID_VERSION_KIND_
149150

150151
type(FmsNetcdfFile_t), intent(in) :: fileobj !< file object for grid file
151152
character(len=*), intent(in) :: mod_name !< module name
152153
type(domain2d), intent(in) :: domain !< 2D domain
153-
integer, intent(in) :: isc, iec, jsc, jec
154-
real(lkind), dimension(isc:,jsc:), intent(out) :: lon, lat
155-
real(lkind), intent(out) :: min_lon, max_lon
154+
real(lkind), intent(out), dimension(:,:), allocatable :: lon, lat
155+
real(lkind), intent(out) :: min_lon, max_lon
156156
logical, optional, intent(in) :: use_center_grid_points !< Flag indicating whether or not to use the
157157
!! centroid values of the supergrid from the
158158
!! grid file as opposed to calcuating it by
@@ -162,8 +162,7 @@ subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lo
162162
integer :: i, j, siz(2)
163163
integer :: nlon, nlat ! size of global grid
164164
integer :: nlon_super, nlat_super ! size of global supergrid.
165-
integer :: isd, ied, jsd, jed
166-
integer :: isg, ieg, jsg, jeg
165+
integer :: isc, iec, jsc, jec
167166
integer :: isc2, iec2, jsc2, jec2
168167
character(len=FMS_PATH_LEN) :: solo_mosaic_file, grid_file
169168
real(lkind), allocatable :: tmpx(:,:), tmpy(:,:)
@@ -179,8 +178,10 @@ subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lo
179178
trim(mod_name) .NE. 'ice' .AND. trim(mod_name) .NE. 'lnd' ) call mpp_error(FATAL, &
180179
"data_override_mod: mod_name should be 'atm', 'ocn', 'ice' or 'lnd' ")
181180

182-
call mpp_get_data_domain(domain, isd, ied, jsd, jed)
183-
call mpp_get_global_domain(domain, isg, ieg, jsg, jeg)
181+
call mpp_get_compute_domain(domain, isc, iec, jsc, jec)
182+
183+
allocate(lon(isc:iec, jsc:jec))
184+
allocate(lat(isc:iec, jsc:jec))
184185

185186
! get the grid file to read
186187

@@ -189,7 +190,7 @@ subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lo
189190

190191
solo_mosaic_file = 'INPUT/'//trim(solo_mosaic_file)
191192
if(.not. open_file(mosaicfileobj, solo_mosaic_file, 'read')) then
192-
call mpp_error(FATAL, 'data_override_mod(get_grid_version_2: Error in opening solo mosaic file '// &
193+
call mpp_error(FATAL, 'data_override_mod(get_grid_version_2): Error in opening solo mosaic file '// &
193194
& trim(solo_mosaic_file))
194195
endif
195196
open_solo_mosaic=.true.
@@ -201,7 +202,7 @@ subroutine GET_GRID_VERSION_2_(fileobj, mod_name, domain, isc, iec, jsc, jec, lo
201202
call get_mosaic_tile_grid(grid_file, mosaicfileobj, domain)
202203

203204
if(.not. open_file(tilefileobj, grid_file, 'read')) then
204-
call mpp_error(FATAL, 'data_override_mod(get_grid_version_2: Error in opening tile file '//trim(grid_file))
205+
call mpp_error(FATAL, 'data_override_mod(get_grid_version_2): Error in opening tile file '//trim(grid_file))
205206
endif
206207

207208
call get_variable_size(tilefileobj, 'area', siz)

test_fms/data_override/test_get_grid_v1.F90

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ program test_get_grid_v1
3737

3838
integer, parameter :: lkind = DO_TEST_KIND_ !< r4_kind or r8_kind
3939
type(domain2d) :: Domain !< 2D domain
40-
integer :: is, ie, js, je !< Starting and ending compute domain indices
4140
integer :: nlon, nlat !< Number of lat, lon in grid
4241
real(lkind) :: min_lon, max_lon !< Maximum lat and lon
4342
real(lkind), dimension(:,:), allocatable :: lon, lat !< Lat and lon
@@ -83,25 +82,17 @@ program test_get_grid_v1
8382
!< Create a domain
8483
call mpp_define_domains( (/1,nlon,1,nlat/), (/1, 1/), Domain, name='Atm')
8584
call mpp_define_io_domain(Domain, (/1,1/))
86-
call mpp_get_compute_domain(Domain,is,ie,js,je)
8785

8886
!< Call "get_grid_version_1" on a "atm" grid
89-
allocate(lon(is:ie,js:je), lat(is:ie,js:je))
90-
call get_grid_version_1("grid_spec.nc", "atm", Domain, is, ie, js, je, lon, lat, &
91-
min_lon, max_lon)
87+
call get_grid_version_1("grid_spec.nc", "atm", Domain, lon, lat, min_lon, max_lon)
9288

9389
!< Error checking:
9490
if (lon(1,1) .ne. lon_in(1)*real(DEG_TO_RAD, lkind)) &
9591
& call mpp_error(FATAL,'test_get_grid_v1: lon is not the expected result')
9692
if (lat(1,1) .ne. lat_in(1)*real(DEG_TO_RAD, lkind)) &
9793
& call mpp_error(FATAL,'test_get_grid_v1: lat is not the expected result')
9894

99-
!< Try again with ocean
100-
lat = 0.
101-
lon = 0.
102-
103-
call get_grid_version_1("grid_spec.nc", "ocn", Domain, is, ie, js, je, lon, lat, &
104-
min_lon, max_lon)
95+
call get_grid_version_1("grid_spec.nc", "ocn", Domain, lon, lat, min_lon, max_lon)
10596

10697
!< Try again with ocean, "new_grid"
10798
allocate(lat_vert_in(1,1,4), lon_vert_in(1,1,4))
@@ -127,8 +118,7 @@ program test_get_grid_v1
127118
endif
128119
call mpp_sync()
129120

130-
call get_grid_version_1("grid_spec.nc", "ocn", Domain, is, ie, js, je, lon, lat, &
131-
min_lon, max_lon)
121+
call get_grid_version_1("grid_spec.nc", "ocn", Domain, lon, lat, min_lon, max_lon)
132122

133123
!< Error checking:
134124
if (lon(1,1) .ne. sum(lon_vert_in)/4._lkind * real(DEG_TO_RAD, lkind) ) then

0 commit comments

Comments
 (0)