22 subroutine get_grid_cell_area_sg_(component, tile, cellarea, domain)
23 character(len=*),
intent(in) :: component
24 integer ,
intent(in) :: tile
25 real(kind=fms_mos_kind_) ,
intent(inout) :: cellarea(:,:)
26 type(domain2d) ,
intent(in),
optional :: domain
30 real(kind=r8_kind),
allocatable :: glonb(:,:), glatb(:,:)
31 real(kind=r8_kind),
allocatable :: cellarea8(:,:)
33 call init_checks(
"get_grid_cell_area")
34 allocate(cellarea8(
size(cellarea,1),
size(cellarea,2)))
36 select case(grid_version)
37 case(version_geolon_t,version_x_t)
38 select case(trim(component))
40 call read_data(gridfileobj,
'AREA_LND_CELL', cellarea8)
42 call read_data(gridfileobj,
'AREA_'//trim(uppercase(component)),cellarea8)
44 call mpp_error(fatal, module_name//
'/get_grid_cell_area'//&
45 'Illegal component name "'//trim(component)//
'": must be one of ATM, LND, or OCN')
48 cellarea = real( cellarea8*4.0_r8_kind*pi*radius**2, fms_mos_kind_)
49 case(version_ocn_mosaic_file, version_gridfiles)
50 if (
present(domain))
then
51 call mpp_get_compute_domain(domain,xsize=nlon,ysize=nlat)
53 call get_grid_size(component,tile,nlon,nlat)
55 allocate(glonb(nlon+1,nlat+1),glatb(nlon+1,nlat+1))
56 call get_grid_cell_vertices(component, tile, glonb, glatb, domain)
57 if (great_circle_algorithm)
then
58 call calc_mosaic_grid_great_circle_area(glonb*pi/180.0_r8_kind, glatb*pi/180_r8_kind, cellarea8)
59 cellarea=real(cellarea8,fms_mos_kind_)
61 call calc_mosaic_grid_area(glonb*pi/180.0_r8_kind, glatb*pi/180_r8_kind, cellarea8)
62 cellarea=real(cellarea8,fms_mos_kind_)
64 deallocate(glonb,glatb)
69 end subroutine get_grid_cell_area_sg_
72 subroutine get_grid_comp_area_sg_(component,tile,area,domain)
73 character(len=*) :: component
74 integer,
intent(in) :: tile
75 real(kind=fms_mos_kind_),
intent(inout) :: area(:,:)
76 type(domain2d),
intent(in),
optional :: domain
78 integer :: n_xgrid_files
79 integer :: siz(2), nxgrid
81 integer,
allocatable :: i1(:), j1(:), i2(:), j2(:)
82 real(kind=r8_kind),
allocatable :: xgrid_area(:)
83 real(kind=r8_kind),
allocatable :: rmask(:,:)
84 character(len=MAX_NAME) :: &
88 character(len=FMS_PATH_LEN) :: &
91 character(len=4096) :: attvalue
92 character(len=MAX_NAME),
allocatable :: nest_tile_name(:)
93 integer :: is,ie,js,je
95 integer :: num_nest_tile, ntiles
97 integer :: found_xgrid_files
98 integer :: ibegin, iend, bsize, l
99 type(FmsNetcdfFile_t) :: tilefileobj, xgrid_fileobj
101 real(r8_kind),
allocatable :: area8(:,:)
103 call init_checks(
"get_grid_comp_area")
104 allocate(area8(
size(area,1),
size(area,2)))
106 select case (grid_version )
107 case(version_geolon_t,version_x_t)
108 select case(component)
110 call read_data(gridfileobj,
'AREA_ATM',area8)
112 allocate(rmask(
size(area8,1),
size(area8,2)))
113 call read_data(gridfileobj,
'AREA_OCN',area8)
114 call read_data(gridfileobj,
'wet', rmask)
115 area = real(area8*rmask, fms_mos_kind_)
118 call read_data(gridfileobj,
'AREA_LND',area8)
120 call mpp_error(fatal, module_name//
'/get_grid_comp_area'//&
121 'Illegal component name "'//trim(component)//
'": must be one of ATM, LND, or OCN')
123 case(version_ocn_mosaic_file, version_gridfiles)
124 select case (component)
127 call get_grid_cell_area(component,tile,area8)
128 area = real(area8, fms_mos_kind_)
131 xgrid_name =
'aXl_file'
132 call read_data(gridfileobj,
'lnd_mosaic', mosaic_name)
133 tile_name = trim(mosaic_name)//
'_tile'//char(tile+ichar(
'0'))
135 xgrid_name =
'aXo_file'
136 call read_data(gridfileobj,
'ocn_mosaic', mosaic_name)
137 tile_name = trim(mosaic_name)//
'_tile'//char(tile+ichar(
'0'))
139 call mpp_error(fatal, module_name//
'/get_grid_comp_area'//&
140 'Illegal component name "'//trim(component)//
'": must be one of ATM, LND, or OCN')
143 if(
present(domain))
then
144 call mpp_get_compute_domain(domain,is,ie,js,je)
147 call get_grid_size(component,tile,ie,je)
151 if (
size(area8,1)/=ie-is+1.or.
size(area8,2)/=je-js+1) &
152 call mpp_error(fatal, module_name//
'/get_grid_comp_area '//&
153 'size of the output argument "area" is not consistent with the domain')
156 call read_data(gridfileobj,
'atm_mosaic', mosaic_name)
157 call get_grid_ntiles(
'atm', ntiles)
158 allocate(nest_tile_name(ntiles))
161 tilefile = read_file_name(mosaic_fileobj(1),
'gridfiles', n)
162 call open_grid_file(tilefileobj, grid_dir//tilefile)
163 if (global_att_exists(tilefileobj,
"nest_grid"))
then
164 call get_global_attribute(tilefileobj,
"nest_grid", attvalue)
165 if(trim(attvalue) ==
"TRUE")
then
166 num_nest_tile = num_nest_tile + 1
167 nest_tile_name(num_nest_tile) = trim(mosaic_name)//
'_tile'//char(n+ichar(
'0'))
168 else if(trim(attvalue) .NE.
"FALSE")
then
169 call mpp_error(fatal,module_name//
'/get_grid_comp_area value of global attribute nest_grid in file'//&
170 trim(tilefile)//
' should be TRUE or FALSE')
173 call close_file(tilefileobj)
175 area8(:,:) = 0.0_r8_kind
176 if(variable_exists(gridfileobj,xgrid_name))
then
178 call get_variable_size(gridfileobj,xgrid_name,siz)
179 n_xgrid_files = siz(2)
180 found_xgrid_files = 0
182 do n = 1, n_xgrid_files
184 xgrid_file = read_file_name(gridfileobj,xgrid_name,n)
185 call open_grid_file(xgrid_fileobj, grid_dir//xgrid_file)
188 if(n_xgrid_files>1)
then
189 if(index(xgrid_file,trim(tile_name))==0) cycle
191 found_xgrid_files = found_xgrid_files + 1
194 do m = 1, num_nest_tile
195 if(index(xgrid_file, trim(nest_tile_name(m))) .NE. 0)
then
203 nxgrid = get_mosaic_xgrid_size(xgrid_fileobj)
204 if(nxgrid < bufsize)
then
205 allocate(i1(nxgrid), j1(nxgrid), i2(nxgrid), j2(nxgrid), xgrid_area(nxgrid))
207 allocate(i1(bufsize), j1(bufsize), i2(bufsize), j2(bufsize), xgrid_area(bufsize))
210 do l = 1,nxgrid,bufsize
211 bsize = min(bufsize, nxgrid-l+1)
212 iend = ibegin + bsize - 1
213 call get_mosaic_xgrid(xgrid_fileobj, i1(1:bsize), j1(1:bsize), i2(1:bsize), j2(1:bsize), &
214 xgrid_area(1:bsize), ibegin, iend)
218 if (i<is.or.i>ie) cycle
219 if (j<js.or.j>je) cycle
220 area8(i+i0,j+j0) = area8(i+i0,j+j0) + xgrid_area(m)
224 deallocate(i1, j1, i2, j2, xgrid_area)
225 call close_file(xgrid_fileobj)
227 if (found_xgrid_files == 0) &
228 call mpp_error(fatal,
'get_grid_comp_area no xgrid files were found for component '&
229 //trim(component)//
' (mosaic name is '//trim(mosaic_name)//
')')
232 deallocate(nest_tile_name)
235 area = real(area8*4.0_r8_kind*pi*radius**2, fms_mos_kind_)
239 end subroutine get_grid_comp_area_sg_
243 subroutine get_grid_cell_area_ug_(component, tile, cellarea, SG_domain, UG_domain)
244 character(len=*),
intent(in) :: component
245 integer ,
intent(in) :: tile
246 real(kind=fms_mos_kind_),
intent(inout) :: cellarea(:)
247 type(domain2d) ,
intent(in) :: SG_domain
248 type(domainUG) ,
intent(in) :: UG_domain
249 integer :: is, ie, js, je
250 real(kind=fms_mos_kind_),
allocatable :: sg_area(:,:)
252 call init_checks(
"get_grid_cell_area")
253 call mpp_get_compute_domain(sg_domain, is, ie, js, je)
254 allocate(sg_area(is:ie, js:je))
255 call get_grid_cell_area(component, tile, sg_area, sg_domain)
256 call mpp_pass_sg_to_ug(ug_domain, sg_area, cellarea)
258 end subroutine get_grid_cell_area_ug_
261 subroutine get_grid_comp_area_ug_(component, tile, area, SG_domain, UG_domain)
262 character(len=*),
intent(in) :: component
263 integer ,
intent(in) :: tile
264 real(kind=fms_mos_kind_),
intent(inout) :: area(:)
265 type(domain2d) ,
intent(in) :: SG_domain
266 type(domainUG) ,
intent(in) :: UG_domain
267 integer :: is, ie, js, je
268 real(kind=fms_mos_kind_),
allocatable :: sg_area(:,:)
270 call init_checks(
"get_grid_comp_area")
271 call mpp_get_compute_domain(sg_domain, is, ie, js, je)
272 allocate(sg_area(is:ie, js:je))
273 call get_grid_comp_area(component, tile, sg_area, sg_domain)
274 call mpp_pass_sg_to_ug(ug_domain, sg_area, area)
277 end subroutine get_grid_comp_area_ug_
281 subroutine get_grid_cell_vertices_1d_(component, tile, glonb, glatb)
282 character(len=*),
intent(in) :: component
283 integer,
intent(in) :: tile
284 real(kind=fms_mos_kind_),
intent(inout) :: glonb(:),glatb(:)
286 integer :: nlon, nlat
287 integer :: start(4), nread(4)
288 real(kind=fms_mos_kind_),
allocatable :: tmp(:,:), x_vert_t(:,:,:), y_vert_t(:,:,:)
289 character(len=FMS_PATH_LEN) :: tilefile
290 type(FmsNetcdfFile_t) :: tilefileobj
292 call init_checks(
"get_grid_cell_vertices")
293 call get_grid_size_for_one_tile(component, tile, nlon, nlat)
294 if (
size(glonb(:))/=nlon+1) &
295 call mpp_error (fatal, module_name//
'/get_grid_cell_vertices_1D '//&
296 'Size of argument "glonb" is not consistent with the grid size')
297 if (
size(glatb(:))/=nlat+1) &
298 call mpp_error (fatal, module_name//
'/get_grid_cell_vertices_1D '//&
299 'Size of argument "glatb" is not consistent with the grid size')
300 if(trim(component) .NE.
'ATM' .AND. component .NE.
'LND' .AND. component .NE.
'OCN')
then
301 call mpp_error(fatal, module_name//
'/get_grid_cell_vertices_1D '//&
302 'Illegal component name "'//trim(component)//
'": must be one of ATM, LND, or OCN')
305 select case(grid_version)
306 case(version_geolon_t)
307 select case(trim(component))
309 call read_data(gridfileobj,
'xb'//lowercase(component(1:1)), glonb)
310 call read_data(gridfileobj,
'yb'//lowercase(component(1:1)), glatb)
312 call read_data(gridfileobj,
"gridlon_vert_t", glonb)
313 call read_data(gridfileobj,
"gridlat_vert_t", glatb)
316 select case(trim(component))
318 call read_data(gridfileobj,
'xb'//lowercase(component(1:1)), glonb)
319 call read_data(gridfileobj,
'yb'//lowercase(component(1:1)), glatb)
321 allocate (x_vert_t(nlon,1,2), y_vert_t(1,nlat,2) )
323 nread(1) = nlon; nread(2) = 1; start(3) = 1
324 call read_data(gridfileobj,
"x_vert_T", x_vert_t(:,:,1), corner=start, edge_lengths=nread)
325 nread(1) = nlon; nread(2) = 1; start(3) = 2
326 call read_data(gridfileobj,
"x_vert_T", x_vert_t(:,:,2), corner=start, edge_lengths=nread)
328 nread(1) = 1; nread(2) = nlat; start(3) = 1
329 call read_data(gridfileobj,
"y_vert_T", y_vert_t(:,:,1), corner=start, edge_lengths=nread)
330 nread(1) = 1; nread(2) = nlat; start(3) = 4
331 call read_data(gridfileobj,
"y_vert_T", y_vert_t(:,:,2), corner=start, edge_lengths=nread)
332 glonb(1:nlon) = x_vert_t(1:nlon,1,1)
333 glonb(nlon+1) = x_vert_t(nlon,1,2)
334 glatb(1:nlat) = y_vert_t(1,1:nlat,1)
335 glatb(nlat+1) = y_vert_t(1,nlat,2)
336 deallocate(x_vert_t, y_vert_t)
338 case(version_ocn_mosaic_file, version_gridfiles)
340 tilefile = read_file_name(mosaic_fileobj(get_component_number(trim(component))),
'gridfiles',tile)
341 call open_grid_file(tilefileobj, grid_dir//tilefile)
345 allocate( tmp(2*nlon+1,1) )
346 call read_data(tilefileobj,
"x", tmp, corner=start, edge_lengths=nread)
347 glonb(1:nlon+1) = tmp(1:2*nlon+1:2,1)
349 allocate(tmp(1,2*nlat+1))
353 call read_data(tilefileobj,
"y", tmp, corner=start, edge_lengths=nread)
354 glatb(1:nlat+1) = tmp(1,1:2*nlat+1:2)
356 call close_file(tilefileobj)
358 end subroutine get_grid_cell_vertices_1d_
361 subroutine get_grid_cell_vertices_2d_(component, tile, lonb, latb, domain)
362 character(len=*),
intent(in) :: component
363 integer,
intent(in) :: tile
364 real(kind=fms_mos_kind_),
intent(inout) :: lonb(:,:),latb(:,:)
365 type(domain2d),
optional,
intent(in) :: domain
368 integer :: nlon, nlat
370 real(kind=fms_mos_kind_),
allocatable :: buffer(:), tmp(:,:), x_vert_t(:,:,:), y_vert_t(:,:,:)
371 integer :: is,ie,js,je
374 integer :: start(4), nread(4)
375 character(len=FMS_PATH_LEN) :: tilefile
376 type(FmsNetcdfFile_t) :: tilefileobj
378 call init_checks(
"get_grid_cell_vertices")
379 call get_grid_size_for_one_tile(component, tile, nlon, nlat)
381 if (
present(domain))
then
382 call mpp_get_compute_domain(domain,is,ie,js,je)
387 call mpp_error (note, module_name//
'/get_grid_cell_vertices '//&
388 'domain is not present, global data will be read')
390 i0 = -is+1; j0 = -js+1
393 if (
size(lonb,1)/=ie-is+2.or.
size(lonb,2)/=je-js+2) &
394 call mpp_error (fatal, module_name//
'/get_grid_cell_vertices '//&
395 'Size of argument "lonb" is not consistent with the domain size')
396 if (
size(latb,1)/=ie-is+2.or.
size(latb,2)/=je-js+2) &
397 call mpp_error (fatal, module_name//
'/get_grid_cell_vertices '//&
398 'Size of argument "latb" is not consistent with the domain size')
399 if(trim(component) .NE.
'ATM' .AND. component .NE.
'LND' .AND. component .NE.
'OCN')
then
400 call mpp_error(fatal, module_name//
'/get_grid_cell_vertices '//&
401 'Illegal component name "'//trim(component)//
'": must be one of ATM, LND, or OCN')
405 select case(grid_version)
406 case(version_geolon_t)
407 select case(component)
409 allocate(buffer(max(nlon,nlat)+1))
411 call read_data(gridfileobj,
'xb'//lowercase(component(1:1)), buffer(1:nlon+1))
414 lonb(i+i0,j+j0) = buffer(i)
417 call read_data(gridfileobj,
'yb'//lowercase(component(1:1)), buffer(1:nlat+1))
420 latb(i+i0,j+j0) = buffer(j)
425 if (
present(domain))
then
427 start(1) = is; start(2) = js
428 nread(1) = ie-is+2; nread(2) = je-js+2
429 call read_data(gridfileobj,
"geolon_vert_t", lonb, corner=start, edge_lengths=nread)
430 call read_data(gridfileobj,
"geolat_vert_t", latb, corner=start, edge_lengths=nread)
432 call read_data(gridfileobj,
"geolon_vert_t", lonb)
433 call read_data(gridfileobj,
"geolat_vert_t", latb)
437 select case(component)
439 allocate(buffer(max(nlon,nlat)+1))
441 call read_data(gridfileobj,
'xb'//lowercase(component(1:1)), buffer(1:nlon+1))
444 lonb(i+i0,j+j0) = buffer(i)
447 call read_data(gridfileobj,
'yb'//lowercase(component(1:1)), buffer(1:nlat+1))
450 latb(i+i0,j+j0) = buffer(j)
455 nlon=ie-is+1; nlat=je-js+1
456 allocate (x_vert_t(nlon,nlat,4), y_vert_t(nlon,nlat,4) )
457 call read_data(gridfileobj,
'x_vert_T', x_vert_t)
458 call read_data(gridfileobj,
'y_vert_T', y_vert_t)
459 lonb(1:nlon,1:nlat) = x_vert_t(1:nlon,1:nlat,1)
460 lonb(nlon+1,1:nlat) = x_vert_t(nlon,1:nlat,2)
461 lonb(1:nlon,nlat+1) = x_vert_t(1:nlon,nlat,4)
462 lonb(nlon+1,nlat+1) = x_vert_t(nlon,nlat,3)
463 latb(1:nlon,1:nlat) = y_vert_t(1:nlon,1:nlat,1)
464 latb(nlon+1,1:nlat) = y_vert_t(nlon,1:nlat,2)
465 latb(1:nlon,nlat+1) = y_vert_t(1:nlon,nlat,4)
466 latb(nlon+1,nlat+1) = y_vert_t(nlon,nlat,3)
467 deallocate(x_vert_t, y_vert_t)
469 case(version_ocn_mosaic_file, version_gridfiles)
471 tilefile = read_file_name(mosaic_fileobj(get_component_number(trim(component))),
'gridfiles',tile)
472 call open_grid_file(tilefileobj, grid_dir//tilefile)
473 if(
PRESENT(domain))
then
474 call mpp_get_global_domain(domain, xbegin=isg, ybegin=jsg)
476 start(1) = 2*(is-isg+1) - 1; nread(1) = 2*(ie-is)+3
477 start(2) = 2*(js-jsg+1) - 1; nread(2) = 2*(je-js)+3
478 allocate(tmp(nread(1), nread(2)) )
479 call read_data(tilefileobj,
"x", tmp, corner=start, edge_lengths=nread)
482 lonb(i,j) = tmp(2*i-1,2*j-1)
485 call read_data(tilefileobj,
"y", tmp, corner=start, edge_lengths=nread)
488 latb(i,j) = tmp(2*i-1,2*j-1)
492 allocate(tmp(2*nlon+1,2*nlat+1))
493 call read_data(tilefileobj,
"x", tmp)
496 lonb(i+i0,j+j0) = tmp(2*i-1,2*j-1)
499 call read_data(tilefileobj,
"y", tmp)
502 latb(i+i0,j+j0) = tmp(2*i-1,2*j-1)
507 call close_file(tilefileobj)
509 end subroutine get_grid_cell_vertices_2d_
513 subroutine get_grid_cell_vertices_ug_(component, tile, lonb, latb, SG_domain, UG_domain)
514 character(len=*),
intent(in) :: component
515 integer,
intent(in) :: tile
516 real(kind=fms_mos_kind_),
intent(inout) :: lonb(:,:),latb(:,:)
517 type(domain2d) ,
intent(in) :: SG_domain
518 type(domainUG) ,
intent(in) :: UG_domain
519 integer :: is, ie, js, je, i, j
520 real(kind=fms_mos_kind_),
allocatable :: sg_lonb(:,:), sg_latb(:,:), tmp(:,:,:)
522 call init_checks(
"get_grid_cell_vertices")
523 call mpp_get_compute_domain(sg_domain, is, ie, js, je)
524 allocate(sg_lonb(is:ie+1, js:je+1))
525 allocate(sg_latb(is:ie+1, js:je+1))
526 allocate(tmp(is:ie,js:je,4))
527 call get_grid_cell_vertices(component, tile, sg_lonb, sg_latb, sg_domain)
530 tmp(i,j,1) = sg_lonb(i,j)
531 tmp(i,j,2) = sg_lonb(i+1,j)
532 tmp(i,j,3) = sg_lonb(i+1,j+1)
533 tmp(i,j,4) = sg_lonb(i,j+1)
536 call mpp_pass_sg_to_ug(ug_domain, tmp, lonb)
539 tmp(i,j,1) = sg_latb(i,j)
540 tmp(i,j,2) = sg_latb(i+1,j)
541 tmp(i,j,3) = sg_latb(i+1,j+1)
542 tmp(i,j,4) = sg_latb(i,j+1)
545 call mpp_pass_sg_to_ug(ug_domain, tmp, latb)
548 deallocate(sg_lonb, sg_latb, tmp)
549 end subroutine get_grid_cell_vertices_ug_
552 subroutine get_grid_cell_centers_1d_(component, tile, glon, glat)
553 character(len=*),
intent(in) :: component
554 integer,
intent(in) :: tile
555 real(kind=fms_mos_kind_),
intent(inout) :: glon(:),glat(:)
557 integer :: nlon, nlat
558 integer :: start(4), nread(4)
559 real(kind=fms_mos_kind_),
allocatable :: tmp(:,:)
560 character(len=FMS_PATH_LEN) :: tilefile
561 type(FmsNetcdfFile_t) :: tilefileobj
563 call init_checks(
"get_grid_cell_centers")
564 call get_grid_size_for_one_tile(component, tile, nlon, nlat)
565 if (
size(glon(:))/=nlon) &
566 call mpp_error (fatal, module_name//
'/get_grid_cell_centers_1D '//&
567 'Size of argument "glon" is not consistent with the grid size')
568 if (
size(glat(:))/=nlat) &
569 call mpp_error (fatal, module_name//
'/get_grid_cell_centers_1D '//&
570 'Size of argument "glat" is not consistent with the grid size')
571 if(trim(component) .NE.
'ATM' .AND. component .NE.
'LND' .AND. component .NE.
'OCN')
then
572 call mpp_error(fatal, module_name//
'/get_grid_cell_centers_1D '//&
573 'Illegal component name "'//trim(component)//
'": must be one of ATM, LND, or OCN')
576 select case(grid_version)
577 case(version_geolon_t)
578 select case(trim(component))
580 call read_data(gridfileobj,
'xt'//lowercase(component(1:1)), glon)
581 call read_data(gridfileobj,
'yt'//lowercase(component(1:1)), glat)
583 call read_data(gridfileobj,
"gridlon_t", glon)
584 call read_data(gridfileobj,
"gridlat_t", glat)
587 select case(trim(component))
589 call read_data(gridfileobj,
'xt'//lowercase(component(1:1)), glon)
590 call read_data(gridfileobj,
'yt'//lowercase(component(1:1)), glat)
592 call read_data(gridfileobj,
"grid_x_T", glon)
593 call read_data(gridfileobj,
"grid_y_T", glat)
595 case(version_ocn_mosaic_file, version_gridfiles)
597 tilefile = read_file_name(mosaic_fileobj(get_component_number(trim(component))),
'gridfiles',tile)
598 call open_grid_file(tilefileobj, grid_dir//tilefile)
601 nread(1) = 2*nlon+1; start(2) = 2
602 allocate( tmp(2*nlon+1,1) )
603 call read_data(tilefileobj,
"x", tmp, corner=start, edge_lengths=nread)
604 glon(1:nlon) = tmp(2:2*nlon:2,1)
606 allocate(tmp(1, 2*nlat+1))
609 nread(2) = 2*nlat+1; start(1) = 2
610 call read_data(tilefileobj,
"y", tmp, corner=start, edge_lengths=nread)
611 glat(1:nlat) = tmp(1,2:2*nlat:2)
613 call close_file(tilefileobj)
615 end subroutine get_grid_cell_centers_1d_
618 subroutine get_grid_cell_centers_2d_(component, tile, lon, lat, domain)
619 character(len=*),
intent(in) :: component
620 integer,
intent(in) :: tile
621 real(kind=fms_mos_kind_),
intent(inout) :: lon(:,:),lat(:,:)
622 type(domain2d),
intent(in),
optional :: domain
624 integer :: nlon, nlat
626 real(kind=fms_mos_kind_),
allocatable :: buffer(:),tmp(:,:)
627 integer :: is,ie,js,je
630 integer :: start(4), nread(4)
631 character(len=FMS_PATH_LEN) :: tilefile
632 type(FmsNetcdfFile_t) :: tilefileobj
634 call init_checks(
"get_grid_cell_centers")
635 call get_grid_size_for_one_tile(component, tile, nlon, nlat)
636 if (
present(domain))
then
637 call mpp_get_compute_domain(domain,is,ie,js,je)
642 call mpp_error (note, module_name//
'/get_grid_cell_centers '//&
643 'domain is not present, global data will be read')
645 i0 = -is+1; j0 = -js+1
648 if (
size(lon,1)/=ie-is+1.or.
size(lon,2)/=je-js+1) &
649 call mpp_error (fatal, module_name//
'/get_grid_cell_centers '//&
650 'Size of array "lon" is not consistent with the domain size')
651 if (
size(lat,1)/=ie-is+1.or.
size(lat,2)/=je-js+1) &
652 call mpp_error (fatal, module_name//
'/get_grid_cell_centers '//&
653 'Size of array "lat" is not consistent with the domain size')
654 if(trim(component) .NE.
'ATM' .AND. component .NE.
'LND' .AND. component .NE.
'OCN')
then
655 call mpp_error(fatal, module_name//
'/get_grid_cell_vertices '//&
656 'Illegal component name "'//trim(component)//
'": must be one of ATM, LND, or OCN')
659 select case(grid_version)
660 case(version_geolon_t)
661 select case (trim(component))
663 allocate(buffer(max(nlon,nlat)))
665 call read_data(gridfileobj,
'xt'//lowercase(component(1:1)), buffer(1:nlon))
668 lon(i+i0,j+j0) = buffer(i)
671 call read_data(gridfileobj,
'yt'//lowercase(component(1:1)), buffer(1:nlat))
674 lat(i+i0,j+j0) = buffer(j)
679 call read_data(gridfileobj,
'geolon_t', lon)
680 call read_data(gridfileobj,
'geolat_t', lat)
683 select case(trim(component))
685 allocate(buffer(max(nlon,nlat)))
687 call read_data(gridfileobj,
'xt'//lowercase(component(1:1)), buffer(1:nlon))
690 lon(i+i0,j+j0) = buffer(i)
693 call read_data(gridfileobj,
'yt'//lowercase(component(1:1)), buffer(1:nlat))
696 lat(i+i0,j+j0) = buffer(j)
701 call read_data(gridfileobj,
'x_T', lon)
702 call read_data(gridfileobj,
'y_T', lat)
704 case(version_ocn_mosaic_file, version_gridfiles)
706 tilefile = read_file_name(mosaic_fileobj(get_component_number(trim(component))),
'gridfiles',tile)
707 call open_grid_file(tilefileobj, grid_dir//tilefile)
709 if(
PRESENT(domain))
then
710 call mpp_get_global_domain(domain, xbegin=isg, ybegin=jsg)
712 start(1) = 2*(is-isg+1) - 1; nread(1) = 2*(ie-is)+3
713 start(2) = 2*(js-jsg+1) - 1; nread(2) = 2*(je-js)+3
714 allocate(tmp(nread(1), nread(2)))
715 call read_data(tilefileobj,
"x", tmp, corner=start, edge_lengths=nread)
718 lon(i,j) = tmp(2*i,2*j)
721 call read_data(tilefileobj,
"y", tmp, corner=start, edge_lengths=nread)
724 lat(i,j) = tmp(2*i,2*j)
728 allocate(tmp(2*nlon+1,2*nlat+1))
729 call read_data(tilefileobj,
'x', tmp)
732 lon(i+i0,j+j0) = tmp(2*i,2*j)
735 call read_data(tilefileobj,
'y', tmp)
738 lat(i+i0,j+j0) = tmp(2*i,2*j)
743 call close_file(tilefileobj)
745 end subroutine get_grid_cell_centers_2d_
749 subroutine get_grid_cell_centers_ug_(component, tile, lon, lat, SG_domain, UG_domain)
750 character(len=*),
intent(in) :: component
751 integer,
intent(in) :: tile
752 real(kind=fms_mos_kind_),
intent(inout) :: lon(:),lat(:)
753 type(domain2d) ,
intent(in) :: SG_domain
754 type(domainUG) ,
intent(in) :: UG_domain
755 integer :: is, ie, js, je
756 real(kind=fms_mos_kind_),
allocatable :: sg_lon(:,:), sg_lat(:,:)
758 call init_checks(
"get_grid_cell_centers")
759 call mpp_get_compute_domain(sg_domain, is, ie, js, je)
760 allocate(sg_lon(is:ie, js:je))
761 allocate(sg_lat(is:ie, js:je))
762 call get_grid_cell_centers(component, tile, sg_lon, sg_lat, sg_domain)
763 call mpp_pass_sg_to_ug(ug_domain, sg_lon, lon)
764 call mpp_pass_sg_to_ug(ug_domain, sg_lat, lat)
765 deallocate(sg_lon, sg_lat)
766 end subroutine get_grid_cell_centers_ug_