27 use mpp_mod,
only : mpp_root_pe,
mpp_error, uppercase, lowercase, fatal, note
28 use constants_mod,
only : pi, radius
29 use fms2_io_mod,
only : get_global_attribute,
read_data, global_att_exists, &
32 use fms_string_utils_mod,
only:
string
73 module procedure get_grid_cell_vertices_1d_r4
74 module procedure get_grid_cell_vertices_1d_r8
75 module procedure get_grid_cell_vertices_2d_r4
76 module procedure get_grid_cell_vertices_2d_r8
77 module procedure get_grid_cell_vertices_ug_r4
78 module procedure get_grid_cell_vertices_ug_r8
84 module procedure get_grid_cell_centers_1d_r4
85 module procedure get_grid_cell_centers_1d_r8
86 module procedure get_grid_cell_centers_2d_r4
87 module procedure get_grid_cell_centers_2d_r8
88 module procedure get_grid_cell_centers_ug_r4
89 module procedure get_grid_cell_centers_ug_r8
95 module procedure get_grid_cell_area_sg_r4
96 module procedure get_grid_cell_area_sg_r8
97 module procedure get_grid_cell_area_ug_r4
98 module procedure get_grid_cell_area_ug_r8
104 module procedure get_grid_comp_area_sg_r4
105 module procedure get_grid_comp_area_sg_r8
106 module procedure get_grid_comp_area_ug_r4
107 module procedure get_grid_comp_area_ug_r8
113 character(len=*),
parameter :: &
114 module_name =
'grid2_mod'
117 #include<file_version.h>
119 character(len=*),
parameter :: &
120 grid_dir =
'INPUT/', & !< root directory for all grid files
123 integer,
parameter :: &
124 max_name = 256, & !< max length of the variable names
136 logical :: great_circle_algorithm = .false.
137 logical :: module_is_initialized = .false.
138 logical :: grid_spec_exists = .true.
139 type(fmsnetcdffile_t) :: gridfileobj
140 type(fmsnetcdffile_t),
dimension(3) :: mosaic_fileobj
146 if (module_is_initialized)
return
148 module_is_initialized = .true.
149 grid_spec_exists = .false.
157 module_is_initialized = .true.
162 if (grid_spec_exists)
then
171 character(len=128) :: attvalue
175 if (.not. grid_spec_exists)
return
176 if (global_att_exists(gridfileobj,
"great_circle_algorithm"))
then
177 call get_global_attribute(gridfileobj,
"great_circle_algorithm", attvalue)
178 if(trim(attvalue) ==
"TRUE")
then
180 else if(trim(attvalue) .NE.
"FALSE")
then
182 '/get_great_circle_algorithm value of global attribute "great_circle_algorthm" in file'// &
183 trim(
grid_file)//
' should be TRUE or FALSE')
190 type(fmsnetcdffile_t),
intent(out) :: myfileobj
191 character(len=*),
intent(in) :: myfilename
192 if(.not.
open_file(myfileobj, myfilename,
'read'))
then
193 call mpp_error(fatal,
'grid2_mod(open_grid_file):Error in opening file '//trim(myfilename))
199 type(fmsnetcdffile_t),
intent(out) :: mymosaicfileobj
200 character(len=3),
intent(in) :: component
202 character(len=FMS_PATH_LEN) :: mosaicfilename
203 if (.not. grid_spec_exists)
then
204 call mpp_error(fatal,
'grid2_mod(open_mosaic_file): grid_spec does not exist')
206 call read_data(gridfileobj,trim(lowercase(component))//
'_mosaic_file', mosaicfilename)
213 type(fmsnetcdffile_t),
intent(in) :: thisfileobj
214 character(len=*),
intent(in) :: filevar
215 integer,
intent(in) :: level
216 integer,
dimension(2) :: file_list_size
218 character(len=FMS_PATH_LEN),
dimension(:),
allocatable :: file_names
220 call get_variable_size(thisfileobj, filevar, file_list_size)
221 allocate(file_names(file_list_size(2)))
222 call read_data(thisfileobj, filevar, file_names)
224 deallocate(file_names)
230 type(fmsnetcdffile_t),
intent(in) :: fileobj
234 if(variable_exists(fileobj,
'geolon_t'))
then
236 else if(variable_exists(fileobj,
'x_T'))
then
238 else if(variable_exists(fileobj,
'ocn_mosaic_file') )
then
240 else if(variable_exists(fileobj,
'gridfiles') )
then
243 call mpp_error(fatal, module_name//
'/get_grid_version Can''t determine the version of the grid spec:'// &
244 &
' none of "x_T", "geolon_t", or "ocn_mosaic_file" exist in file "'//trim(
grid_file)//
'"')
251 if (.not. grid_spec_exists)
then
252 call mpp_error(fatal,
'grid2_mod(assign_component_mosaics): grid_spec does not exist')
254 mosaic_fileobj(1) = gridfileobj
255 mosaic_fileobj(2) = gridfileobj
256 mosaic_fileobj(3) = gridfileobj
261 if (.not. grid_spec_exists)
then
262 call mpp_error(fatal,
'grid2_mod(open_component_mosaics): grid_spec does not exist')
264 if (variable_exists(gridfileobj,
'atm_mosaic_file'))
call open_mosaic_file(mosaic_fileobj(1),
'atm')
265 if (variable_exists(gridfileobj,
'ocn_mosaic_file'))
call open_mosaic_file(mosaic_fileobj(2),
'ocn')
266 if (variable_exists(gridfileobj,
'lnd_mosaic_file'))
call open_mosaic_file(mosaic_fileobj(3),
'lnd')
271 if (.not. grid_spec_exists)
then
272 call mpp_error(fatal,
'grid2_mod(close_component_mosaics): grid_spec does not exist')
274 if (variable_exists(gridfileobj,
'atm_mosaic_file'))
call close_file(mosaic_fileobj(1))
275 if (variable_exists(gridfileobj,
'ocn_mosaic_file'))
call close_file(mosaic_fileobj(2))
276 if (variable_exists(gridfileobj,
'lnd_mosaic_file'))
call close_file(mosaic_fileobj(3))
282 character(len=*),
intent(in) :: component
284 select case(lowercase(component))
296 character(len=*) :: component
297 integer,
intent(out) :: ntiles
309 character(len=*) :: component
310 integer,
intent(inout) :: nx(:),ny(:)
314 character(len=MAX_NAME) :: varname1
316 varname1 =
'AREA_'//trim(uppercase(component))
320 if (.not. grid_spec_exists)
then
321 call mpp_error(fatal,
'grid2_mod(get_grid_size_for_all_tiles): grid_spec does not exist')
323 call get_variable_size(gridfileobj, varname1, siz)
324 nx(1) = siz(1); ny(1)=siz(2)
332 character(len=*) :: component
333 integer,
intent(in) :: tile
334 integer,
intent(inout) :: nx,ny
337 integer,
allocatable :: nnx(:), nny(:)
341 if(tile>0.and.tile<=ntiles)
then
342 allocate(nnx(ntiles),nny(ntiles))
344 nx = nnx(tile); ny = nny(tile)
348 'requested tile index '//trim(
string(tile))//
' is out of bounds (1:'//trim(
string(ntiles))//
')')
355 character(len=*) ,
intent(in) :: component
356 type(
domain2d) ,
intent(inout) :: domain
357 integer ,
intent(in) :: layout(2)
358 integer,
optional,
intent(in) :: halo
359 logical,
optional,
intent(in) :: maskmap(:,:,:)
365 integer :: ng, pe_pos, npes
366 integer,
allocatable :: nlon(:), nlat(:), global_indices(:,:)
367 integer,
allocatable :: pe_start(:), pe_end(:), layout_2d(:,:)
368 integer,
allocatable :: tile1(:),tile2(:)
369 integer,
allocatable :: is1(:),ie1(:),js1(:),je1(:)
370 integer,
allocatable :: is2(:),ie2(:),js2(:),je2(:)
373 allocate(nlon(ntiles), nlat(ntiles))
374 allocate(global_indices(4,ntiles))
375 allocate(pe_start(ntiles),pe_end(ntiles))
376 allocate(layout_2d(2,ntiles))
379 pe_pos = mpp_root_pe()
381 global_indices(:,n) = (/ 1, nlon(n), 1, nlat(n) /)
382 layout_2d(:,n) = layout
383 if(
present(maskmap))
then
384 npes = count(maskmap(:,:,n))
386 npes = layout(1)*layout(2)
389 pe_end(n) = pe_pos + npes - 1
390 pe_pos = pe_end(n) + 1
395 allocate(tile1(ncontacts),tile2(ncontacts))
396 allocate(is1(ncontacts),ie1(ncontacts),js1(ncontacts),je1(ncontacts))
397 allocate(is2(ncontacts),ie2(ncontacts),js2(ncontacts),je2(ncontacts))
399 is1, ie1, js1, je1, is2, ie2, js2, je2)
402 if(
present(halo)) ng = halo
405 ntiles, ncontacts, tile1, tile2, &
406 is1, ie1, js1, je1, &
407 is2, ie2, js2, je2, &
408 pe_start=pe_start, pe_end=pe_end, symmetry=.true., &
409 shalo = ng, nhalo = ng, whalo = ng, ehalo = ng, &
411 name = trim(component)//
'Cubic-Sphere Grid' )
413 deallocate(nlon,nlat,global_indices,pe_start,pe_end,layout_2d)
414 deallocate(tile1,tile2)
415 deallocate(is1,ie1,js1,je1)
416 deallocate(is2,ie2,js2,je2)
419 #include "grid2_r4.fh"
420 #include "grid2_r8.fh"
Close a netcdf or domain file opened with open_file or open_virtual_file.
Opens a given netcdf or domain file.
Read data from a defined field in a file.
character(:) function, allocatable, public string(v, fmt)
Converts a number or a Boolean value to a string.
integer grid_version
Value to indicate what type of grid file is being read, based on which variables are present.
integer, parameter version_gridfiles
indicates gridfiles variable is present in grid_file
subroutine, public grid_end
Shutdown the grid2 module.
subroutine, public grid_init
Initialize the grid2 module.
subroutine open_mosaic_file(mymosaicfileobj, component)
Open a mosaic file.
integer function get_component_number(component)
Get the component number of a model component (atm, lnd, ocn)
integer, parameter version_ocn_mosaic_file
indicates ocn_mosaic_file variable is present in grid_file
integer, parameter version_geolon_t
indicates gelon_t variable is present in grid_file
character(len=fms_path_len) function read_file_name(thisfileobj, filevar, level)
Read a tile file name from a netcdf file.
subroutine open_component_mosaics
Open the component mosaic files for atm, lnd, and ocn.
subroutine, public get_grid_ntiles(component, ntiles)
returns number of tiles for a given component
subroutine assign_component_mosaics
Assign the component mosaic files if grid_spec is Version 3.
character(len= *), parameter grid_dir
root directory for all grid files
integer, parameter version_x_t
indicates x_t variable is present in grid_file
subroutine open_grid_file(myfileobj, myfilename)
Open a grid file.
subroutine close_component_mosaics
Close the component mosaic files for atm, lnd, and ocn.
integer, parameter bufsize
This is used to control memory usage in get_grid_comp_area We may change this to a namelist variable ...
subroutine get_grid_size_for_one_tile(component, tile, nx, ny)
returns size of the grid for one of the tiles
integer, parameter max_name
max length of the variable names
character(len= *), parameter grid_file
name of the grid spec file
integer function get_grid_version(fileobj)
Get the grid version from a file object.
subroutine, public define_cube_mosaic(component, domain, layout, halo, maskmap)
given a model component, a layout, and (optionally) a halo size, returns a domain for current process...
logical function, public get_great_circle_algorithm()
Determine if we are using the great circle algorithm.
subroutine get_grid_size_for_all_tiles(component, nx, ny)
returns size of the grid for each of the tiles
Finds area of a grid cell.
Gets arrays of global grid cell boundaries for given model component and mosaic tile number.
Gets the area of a given component per grid cell.
Gets the size of the grid for one or all tiles.
integer function, public get_mosaic_xgrid_size(fileobj)
return exchange grid size of mosaic xgrid file.
subroutine, public get_mosaic_contact(fileobj, tile1, tile2, istart1, iend1, jstart1, jend1, istart2, iend2, jstart2, jend2)
Get contact information from mosaic_file Example usage: call get_mosaic_contact(mosaic_file,...
integer function, public get_mosaic_ntiles(fileobj)
Get number of tiles in the mosaic_file.
integer function, public get_mosaic_ncontacts(fileobj)
Get number of contacts in the mosaic_file.
subroutine, public get_mosaic_grid_sizes(fileobj, nx, ny)
Get grid size of each tile from mosaic_file.
subroutine mpp_define_mosaic(global_indices, layout, domain, num_tile, num_contact, tile1, tile2, istart1, iend1, jstart1, jend1, istart2, iend2, jstart2, jend2, pe_start, pe_end, pelist, whalo, ehalo, shalo, nhalo, xextent, yextent, maskmap, name, memory_size, symmetry, xflags, yflags, tile_id)
Defines a domain for mosaic tile grids.
These routines retrieve the axis specifications associated with the compute domains....
These routines retrieve the axis specifications associated with the global domains....
Passes data from a structured grid to an unstructured grid Example usage:
The domain2D type contains all the necessary information to define the global, compute and data domai...
Domain information for managing data on unstructured grids.