Sets the grid metrics from a mosaic file.
168 type(dyn_horgrid_type),
intent(inout) :: g
169 type(param_file_type),
intent(in) :: param_file
170 type(unit_scale_type),
optional,
intent(in) :: us
172 real,
dimension(G%isd :G%ied ,G%jsd :G%jed ) :: temph1, temph2, temph3, temph4
173 real,
dimension(G%IsdB:G%IedB,G%JsdB:G%JedB) :: tempq1, tempq2, tempq3, tempq4
174 real,
dimension(G%IsdB:G%IedB,G%jsd :G%jed ) :: tempe1, tempe2
175 real,
dimension(G%isd :G%ied ,G%JsdB:G%JedB) :: tempn1, tempn2
178 real,
dimension(G%isd :G%ied ,G%jsd :G%jed ) :: dxt, dyt, areat
179 real,
dimension(G%IsdB:G%IedB,G%jsd :G%jed ) :: dxcu, dycu
180 real,
dimension(G%isd :G%ied ,G%JsdB:G%JedB) :: dxcv, dycv
181 real,
dimension(G%IsdB:G%IedB,G%JsdB:G%JedB) :: dxbu, dybu, areabu
183 real,
dimension(2*G%isd-2:2*G%ied+1,2*G%jsd-2:2*G%jed+1) :: tmpt
184 real,
dimension(2*G%isd-3:2*G%ied+1,2*G%jsd-2:2*G%jed+1) :: tmpu
185 real,
dimension(2*G%isd-2:2*G%ied+1,2*G%jsd-3:2*G%jed+1) :: tmpv
186 real,
dimension(2*G%isd-3:2*G%ied+1,2*G%jsd-3:2*G%jed+1) :: tmpz
187 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 m_to_l = 1.0 ;
if (
present(us)) m_to_l = us%m_to_L
202 call get_param(param_file, mdl,
"GRID_FILE", grid_file, &
203 "Name of the file from which to read horizontal grid data.", &
204 fail_if_missing=.true.)
205 call get_param(param_file, mdl,
"USE_TRIPOLAR_GEOLONB_BUG", lon_bug, &
206 "If true, use older code that incorrectly sets the longitude "//&
207 "in some points along the tripolar fold to be off by 360 degrees.", &
209 call get_param(param_file, mdl,
"INPUTDIR", inputdir, default=
".")
210 inputdir = slasher(inputdir)
211 filename = trim(adjustl(inputdir)) // trim(adjustl(grid_file))
212 call log_param(param_file, mdl,
"INPUTDIR/GRID_FILE", filename)
213 if (.not.file_exists(filename)) &
214 call mom_error(fatal,
" set_grid_metrics_from_mosaic: Unable to open "//&
218 dxcu(:,:) = 0.0 ; dycu(:,:) = 0.0
219 dxcv(:,:) = 0.0 ; dycv(:,:) = 0.0
220 dxbu(:,:) = 0.0 ; dybu(:,:) = 0.0 ; areabu(:,:) = 0.0
223 ni = 2*(g%iec-g%isc+1)
224 nj = 2*(g%jec-g%jsc+1)
227 npei = g%domain%layout(1) ; npej = g%domain%layout(2)
228 allocate(exni(npei)) ;
allocate(exnj(npej))
229 call mpp_get_domain_extents(g%domain%mpp_domain, exni, exnj)
230 allocate(sgdom%mpp_domain)
231 sgdom%nihalo = 2*g%domain%nihalo+1
232 sgdom%njhalo = 2*g%domain%njhalo+1
233 sgdom%niglobal = 2*g%domain%niglobal
234 sgdom%njglobal = 2*g%domain%njglobal
235 sgdom%layout(:) = g%domain%layout(:)
236 sgdom%io_layout(:) = g%domain%io_layout(:)
237 global_indices(1) = 1+sgdom%nihalo
238 global_indices(2) = sgdom%niglobal+sgdom%nihalo
239 global_indices(3) = 1+sgdom%njhalo
240 global_indices(4) = sgdom%njglobal+sgdom%njhalo
241 exni(:) = 2*exni(:) ; exnj(:) = 2*exnj(:)
242 if (
associated(g%domain%maskmap))
then 243 call mom_define_domain(global_indices, sgdom%layout, sgdom%mpp_domain, &
244 xflags=g%domain%X_FLAGS, yflags=g%domain%Y_FLAGS, &
245 xhalo=sgdom%nihalo, yhalo=sgdom%njhalo, &
246 xextent=exni,yextent=exnj, &
247 symmetry=.true., name=
"MOM_MOSAIC", maskmap=g%domain%maskmap)
249 call mom_define_domain(global_indices, sgdom%layout, sgdom%mpp_domain, &
250 xflags=g%domain%X_FLAGS, yflags=g%domain%Y_FLAGS, &
251 xhalo=sgdom%nihalo, yhalo=sgdom%njhalo, &
252 xextent=exni,yextent=exnj, &
253 symmetry=.true., name=
"MOM_MOSAIC")
256 call mom_define_io_domain(sgdom%mpp_domain, sgdom%io_layout)
262 call mom_read_data(filename,
'x', tmpz, sgdom, position=corner)
265 call pass_var(tmpz, sgdom, position=corner)
267 call pass_var(tmpz, sgdom, position=corner, inner_halo=0)
269 call extrapolate_metric(tmpz, 2*(g%jsc-g%jsd)+2, missing=999.)
270 do j=g%jsd,g%jed ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
271 g%geoLonT(i,j) = tmpz(i2-1,j2-1)
273 do j=g%JsdB,g%JedB ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
274 g%geoLonBu(i,j) = tmpz(i2,j2)
276 do j=g%jsd,g%jed ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
277 g%geoLonCu(i,j) = tmpz(i2,j2-1)
279 do j=g%JsdB,g%JedB ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
280 g%geoLonCv(i,j) = tmpz(i2-1,j2)
287 call mom_read_data(filename,
'y', tmpz, sgdom, position=corner)
289 call pass_var(tmpz, sgdom, position=corner)
290 call extrapolate_metric(tmpz, 2*(g%jsc-g%jsd)+2, missing=999.)
291 do j=g%jsd,g%jed ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
292 g%geoLatT(i,j) = tmpz(i2-1,j2-1)
294 do j=g%JsdB,g%JedB ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
295 g%geoLatBu(i,j) = tmpz(i2,j2)
297 do j=g%jsd,g%jed ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
298 g%geoLatCu(i,j) = tmpz(i2,j2-1)
300 do j=g%JsdB,g%JedB ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
301 g%geoLatCv(i,j) = tmpz(i2-1,j2)
305 tmpu(:,:) = 0. ; tmpv(:,:) = 0.
306 call mom_read_data(filename,
'dx',tmpv,sgdom,position=north_face)
307 call mom_read_data(filename,
'dy',tmpu,sgdom,position=east_face)
308 call pass_vector(tmpu, tmpv, sgdom, to_all+scalar_pair, cgrid_ne)
309 call extrapolate_metric(tmpv, 2*(g%jsc-g%jsd)+2, missing=0.)
310 call extrapolate_metric(tmpu, 2*(g%jsc-g%jsd)+2, missing=0.)
312 do j=g%jsd,g%jed ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
313 dxt(i,j) = tmpv(i2-1,j2-1) + tmpv(i2,j2-1)
314 dyt(i,j) = tmpu(i2-1,j2-1) + tmpu(i2-1,j2)
317 do j=g%jsd,g%jed ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
318 dxcu(i,j) = tmpv(i2,j2-1) + tmpv(i2+1,j2-1)
319 dycu(i,j) = tmpu(i2,j2-1) + tmpu(i2,j2)
322 do j=g%JsdB,g%JedB ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
323 dxcv(i,j) = tmpv(i2-1,j2) + tmpv(i2,j2)
324 dycv(i,j) = tmpu(i2-1,j2) + tmpu(i2-1,j2+1)
327 do j=g%JsdB,g%JedB ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
328 dxbu(i,j) = tmpv(i2,j2) + tmpv(i2+1,j2)
329 dybu(i,j) = tmpu(i2,j2) + tmpu(i2,j2+1)
334 call mom_read_data(filename,
'area', tmpt, sgdom)
335 call pass_var(tmpt, sgdom)
336 call extrapolate_metric(tmpt, 2*(g%jsc-g%jsd)+2, missing=0.)
338 do j=g%jsd,g%jed ;
do i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
339 areat(i,j) = (tmpt(i2-1,j2-1) + tmpt(i2,j2)) + &
340 (tmpt(i2-1,j2) + tmpt(i2,j2-1))
342 do j=g%JsdB,g%JedB ;
do i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
343 areabu(i,j) = (tmpt(i2,j2) + tmpt(i2+1,j2+1)) + &
344 (tmpt(i2,j2+1) + tmpt(i2+1,j2))
349 call mpp_deallocate_domain(sgdom%mpp_domain)
350 deallocate(sgdom%mpp_domain)
352 call pass_vector(dycu, dxcv, g%Domain, to_all+scalar_pair, cgrid_ne)
353 call pass_vector(dxcu, dycv, g%Domain, to_all+scalar_pair, cgrid_ne)
354 call pass_vector(dxbu, dybu, g%Domain, to_all+scalar_pair, bgrid_ne)
355 call pass_var(areat, g%Domain)
356 call pass_var(areabu, g%Domain, position=corner)
358 do i=g%isd,g%ied ;
do j=g%jsd,g%jed
359 g%dxT(i,j) = m_to_l*dxt(i,j) ; g%dyT(i,j) = m_to_l*dyt(i,j) ; g%areaT(i,j) = m_to_l**2*areat(i,j)
361 do i=g%IsdB,g%IedB ;
do j=g%jsd,g%jed
362 g%dxCu(i,j) = m_to_l*dxcu(i,j) ; g%dyCu(i,j) = m_to_l*dycu(i,j)
364 do i=g%isd,g%ied ;
do j=g%JsdB,g%JedB
365 g%dxCv(i,j) = m_to_l*dxcv(i,j) ; g%dyCv(i,j) = m_to_l*dycv(i,j)
367 do i=g%IsdB,g%IedB ;
do j=g%JsdB,g%JedB
368 g%dxBu(i,j) = m_to_l*dxbu(i,j) ; g%dyBu(i,j) = m_to_l*dybu(i,j) ; g%areaBu(i,j) = m_to_l**2*areabu(i,j)
373 start(:) = 1 ; nread(:) = 1
374 start(2) = 2 ; nread(1) = ni+1 ; nread(2) = 2
375 allocate( tmpglbl(ni+1,2) )
377 call read_data(filename,
"x", tmpglbl, start, nread, no_domain=.true.)
378 call broadcast(tmpglbl, 2*(ni+1), root_pe())
382 g%gridLonT(i) = tmpglbl(2*(i-g%isg)+2,2)
387 g%gridLonB(i) = tmpglbl(2*(i-g%isg)+3,1)
389 deallocate( tmpglbl )
391 allocate( tmpglbl(1, nj+1) )
392 start(:) = 1 ; nread(:) = 1
393 start(1) = int(ni/4)+1 ; nread(2) = nj+1
395 call read_data(filename,
"y", tmpglbl, start, nread, no_domain=.true.)
396 call broadcast(tmpglbl, nj+1, root_pe())
399 g%gridLatT(j) = tmpglbl(1,2*(j-g%jsg)+2)
402 g%gridLatB(j) = tmpglbl(1,2*(j-g%jsg)+3)
404 deallocate( tmpglbl )
406 call calltree_leave(
"set_grid_metrics_from_mosaic()")