Sets the grid metrics from a mosaic file.
170 type(dyn_horgrid_type),
intent(inout) :: G
171 type(param_file_type),
intent(in) :: param_file
173 real,
dimension(G%isd :G%ied ,G%jsd :G%jed ) :: tempH1, tempH2, tempH3, tempH4
174 real,
dimension(G%IsdB:G%IedB,G%JsdB:G%JedB) :: tempQ1, tempQ2, tempQ3, tempQ4
175 real,
dimension(G%IsdB:G%IedB,G%jsd :G%jed ) :: tempE1, tempE2
176 real,
dimension(G%isd :G%ied ,G%JsdB:G%JedB) :: tempN1, tempN2
179 real,
dimension(G%isd :G%ied ,G%jsd :G%jed ) :: dxT, dyT, areaT
180 real,
dimension(G%IsdB:G%IedB,G%jsd :G%jed ) :: dxCu, dyCu
181 real,
dimension(G%isd :G%ied ,G%JsdB:G%JedB) :: dxCv, dyCv
182 real,
dimension(G%IsdB:G%IedB,G%JsdB:G%JedB) :: dxBu, dyBu, areaBu
184 real,
dimension(2*G%isd-2:2*G%ied+1,2*G%jsd-2:2*G%jed+1) :: tmpT
185 real,
dimension(2*G%isd-3:2*G%ied+1,2*G%jsd-2:2*G%jed+1) :: tmpU
186 real,
dimension(2*G%isd-2:2*G%ied+1,2*G%jsd-3:2*G%jed+1) :: tmpV
187 real,
dimension(2*G%isd-3:2*G%ied+1,2*G%jsd-3:2*G%jed+1) :: tmpZ
188 real,
dimension(:,:),
allocatable :: tmpGlbl
189 character(len=200) :: filename, grid_file, inputdir
190 character(len=64) :: mdl =
"MOM_grid_init set_grid_metrics_from_mosaic"
191 integer :: err=0, ni, nj, global_indices(4)
192 type(MOM_domain_type) :: SGdom
194 integer :: i, j, i2, j2
196 integer,
dimension(:),
allocatable :: exni,exnj
197 integer :: start(4), nread(4)
199 call calltree_enter(
"set_grid_metrics_from_mosaic(), MOM_grid_initialize.F90")
201 call get_param(param_file, mdl,
"GRID_FILE", grid_file, &
202 "Name of the file from which to read horizontal grid data.", &
203 fail_if_missing=.true.)
204 call get_param(param_file, mdl,
"USE_TRIPOLAR_GEOLONB_BUG", lon_bug, &
205 "If true, use older code that incorrectly sets the longitude "//&
206 "in some points along the tripolar fold to be off by 360 degrees.", &
208 call get_param(param_file, mdl,
"INPUTDIR", inputdir, default=
".")
209 inputdir = slasher(inputdir)
210 filename = trim(adjustl(inputdir)) // trim(adjustl(grid_file))
211 call log_param(param_file, mdl,
"INPUTDIR/GRID_FILE", filename)
212 if (.not.file_exists(filename)) &
213 call mom_error(fatal,
" set_grid_metrics_from_mosaic: Unable to open "//&
217 dxcu(:,:) = 0.0 ; dycu(:,:) = 0.0
218 dxcv(:,:) = 0.0 ; dycv(:,:) = 0.0
219 dxbu(:,:) = 0.0 ; dybu(:,:) = 0.0 ; areabu(:,:) = 0.0
222 ni = 2*(g%iec-g%isc+1)
223 nj = 2*(g%jec-g%jsc+1)
226 npei = g%domain%layout(1) ; npej = g%domain%layout(2)
227 allocate(exni(npei)) ;
allocate(exnj(npej))
228 call mpp_get_domain_extents(g%domain%mpp_domain, exni, exnj)
229 allocate(sgdom%mpp_domain)
230 sgdom%nihalo = 2*g%domain%nihalo+1
231 sgdom%njhalo = 2*g%domain%njhalo+1
232 sgdom%niglobal = 2*g%domain%niglobal
233 sgdom%njglobal = 2*g%domain%njglobal
234 sgdom%layout(:) = g%domain%layout(:)
235 sgdom%io_layout(:) = g%domain%io_layout(:)
236 global_indices(1) = 1+sgdom%nihalo
237 global_indices(2) = sgdom%niglobal+sgdom%nihalo
238 global_indices(3) = 1+sgdom%njhalo
239 global_indices(4) = sgdom%njglobal+sgdom%njhalo
240 exni(:) = 2*exni(:) ; exnj(:) = 2*exnj(:)
241 if (
associated(g%domain%maskmap))
then
242 call mom_define_domain(global_indices, sgdom%layout, sgdom%mpp_domain, &
243 xflags=g%domain%X_FLAGS, yflags=g%domain%Y_FLAGS, &
244 xhalo=sgdom%nihalo, yhalo=sgdom%njhalo, &
245 xextent=exni,yextent=exnj, &
246 symmetry=.true., name=
"MOM_MOSAIC", maskmap=g%domain%maskmap)
248 call mom_define_domain(global_indices, sgdom%layout, sgdom%mpp_domain, &
249 xflags=g%domain%X_FLAGS, yflags=g%domain%Y_FLAGS, &
250 xhalo=sgdom%nihalo, yhalo=sgdom%njhalo, &
251 xextent=exni,yextent=exnj, &
252 symmetry=.true., name=
"MOM_MOSAIC")
255 call mom_define_io_domain(sgdom%mpp_domain, sgdom%io_layout)
261 call mom_read_data(filename,
'x', tmpz, sgdom, position=corner)
264 call pass_var(tmpz, sgdom, position=corner)
266 call pass_var(tmpz, sgdom, position=corner, inner_halo=0)
268 call extrapolate_metric(tmpz, 2*(g%jsc-g%jsd)+2, missing=999.)
269 do j=g%jsd,g%jed ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
270 g%geoLonT(i,j) = tmpz(i2-1,j2-1)
272 do j=g%JsdB,g%JedB ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
273 g%geoLonBu(i,j) = tmpz(i2,j2)
275 do j=g%jsd,g%jed ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
276 g%geoLonCu(i,j) = tmpz(i2,j2-1)
278 do j=g%JsdB,g%JedB ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
279 g%geoLonCv(i,j) = tmpz(i2-1,j2)
286 call mom_read_data(filename,
'y', tmpz, sgdom, position=corner)
288 call pass_var(tmpz, sgdom, position=corner)
289 call extrapolate_metric(tmpz, 2*(g%jsc-g%jsd)+2, missing=999.)
290 do j=g%jsd,g%jed ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
291 g%geoLatT(i,j) = tmpz(i2-1,j2-1)
293 do j=g%JsdB,g%JedB ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
294 g%geoLatBu(i,j) = tmpz(i2,j2)
296 do j=g%jsd,g%jed ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
297 g%geoLatCu(i,j) = tmpz(i2,j2-1)
299 do j=g%JsdB,g%JedB ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
300 g%geoLatCv(i,j) = tmpz(i2-1,j2)
304 tmpu(:,:) = 0. ; tmpv(:,:) = 0.
305 call mom_read_data(filename,
'dx',tmpv,sgdom,position=north_face)
306 call mom_read_data(filename,
'dy',tmpu,sgdom,position=east_face)
307 call pass_vector(tmpu, tmpv, sgdom, to_all+scalar_pair, cgrid_ne)
308 call extrapolate_metric(tmpv, 2*(g%jsc-g%jsd)+2, missing=0.)
309 call extrapolate_metric(tmpu, 2*(g%jsc-g%jsd)+2, missing=0.)
311 do j=g%jsd,g%jed ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
312 dxt(i,j) = tmpv(i2-1,j2-1) + tmpv(i2,j2-1)
313 dyt(i,j) = tmpu(i2-1,j2-1) + tmpu(i2-1,j2)
316 do j=g%jsd,g%jed ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
317 dxcu(i,j) = tmpv(i2,j2-1) + tmpv(i2+1,j2-1)
318 dycu(i,j) = tmpu(i2,j2-1) + tmpu(i2,j2)
321 do j=g%JsdB,g%JedB ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
322 dxcv(i,j) = tmpv(i2-1,j2) + tmpv(i2,j2)
323 dycv(i,j) = tmpu(i2-1,j2) + tmpu(i2-1,j2+1)
326 do j=g%JsdB,g%JedB ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
327 dxbu(i,j) = tmpv(i2,j2) + tmpv(i2+1,j2)
328 dybu(i,j) = tmpu(i2,j2) + tmpu(i2,j2+1)
333 call mom_read_data(filename,
'area', tmpt, sgdom)
334 call pass_var(tmpt, sgdom)
335 call extrapolate_metric(tmpt, 2*(g%jsc-g%jsd)+2, missing=0.)
337 do j=g%jsd,g%jed ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
338 areat(i,j) = (tmpt(i2-1,j2-1) + tmpt(i2,j2)) + &
339 (tmpt(i2-1,j2) + tmpt(i2,j2-1))
341 do j=g%JsdB,g%JedB ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
342 areabu(i,j) = (tmpt(i2,j2) + tmpt(i2+1,j2+1)) + &
343 (tmpt(i2,j2+1) + tmpt(i2+1,j2))
348 call mpp_deallocate_domain(sgdom%mpp_domain)
349 deallocate(sgdom%mpp_domain)
351 call pass_vector(dycu, dxcv, g%Domain, to_all+scalar_pair, cgrid_ne)
352 call pass_vector(dxcu, dycv, g%Domain, to_all+scalar_pair, cgrid_ne)
353 call pass_vector(dxbu, dybu, g%Domain, to_all+scalar_pair, bgrid_ne)
354 call pass_var(areat, g%Domain)
355 call pass_var(areabu, g%Domain, position=corner)
357 do i=g%isd,g%ied ;
do j=g%jsd,g%jed
358 g%dxT(i,j) = dxt(i,j) ; g%dyT(i,j) = dyt(i,j) ; g%areaT(i,j) = areat(i,j)
360 do i=g%IsdB,g%IedB ;
do j=g%jsd,g%jed
361 g%dxCu(i,j) = dxcu(i,j) ; g%dyCu(i,j) = dycu(i,j)
363 do i=g%isd,g%ied ;
do j=g%JsdB,g%JedB
364 g%dxCv(i,j) = dxcv(i,j) ; g%dyCv(i,j) = dycv(i,j)
366 do i=g%IsdB,g%IedB ;
do j=g%JsdB,g%JedB
367 g%dxBu(i,j) = dxbu(i,j) ; g%dyBu(i,j) = dybu(i,j) ; g%areaBu(i,j) = areabu(i,j)
372 start(:) = 1 ; nread(:) = 1
373 start(2) = 2 ; nread(1) = ni+1 ; nread(2) = 2
374 allocate( tmpglbl(ni+1,2) )
376 call read_data(filename,
"x", tmpglbl, start, nread, no_domain=.true.)
377 call broadcast(tmpglbl, 2*(ni+1), root_pe())
381 g%gridLonT(i) = tmpglbl(2*(i-g%isg)+2,2)
386 g%gridLonB(i) = tmpglbl(2*(i-g%isg)+3,1)
388 deallocate( tmpglbl )
390 allocate( tmpglbl(1, nj+1) )
391 start(:) = 1 ; nread(:) = 1
392 start(1) = int(ni/4)+1 ; nread(2) = nj+1
394 call read_data(filename,
"y", tmpglbl, start, nread, no_domain=.true.)
395 call broadcast(tmpglbl, nj+1, root_pe())
398 g%gridLatT(j) = tmpglbl(1,2*(j-g%jsg)+2)
401 g%gridLatB(j) = tmpglbl(1,2*(j-g%jsg)+3)
403 deallocate( tmpglbl )
405 call calltree_leave(
"set_grid_metrics_from_mosaic()")