@@ -28,8 +28,16 @@ module model_grid
28
28
type (esmf_grid), public :: grid_mdl ! < ESMF grid object for the model grid.
29
29
type (esmf_field), public :: data_field_mdl ! < ESMF field object that holds the
30
30
! ! data interpolated to model grid.
31
+ type (esmf_field), public :: land_frac_field_mdl ! < ESMF field object that holds the
32
+ ! ! model land fraction. When running
33
+ ! ! with fractional grids, will be
34
+ ! ! between zero and one. For non-
35
+ ! ! fractional grids, will contain a
36
+ ! ! fill value.
31
37
type (esmf_field), public :: mask_field_mdl ! < ESMF field object that holds the
32
- ! ! model land mask.
38
+ ! ! model land mask. Equal to '1' if
39
+ ! ! point is partial or all land. Equal
40
+ ! ! to zero is point is all non-land.
33
41
type (esmf_field), public :: latitude_field_mdl ! < ESMF field object that holds the
34
42
! ! model grid latitude.
35
43
type (esmf_field), public :: longitude_field_mdl ! < ESMF field object that holds the
@@ -75,6 +83,7 @@ subroutine define_model_grid(localpet, npets)
75
83
76
84
real (esmf_kind_r4 ), allocatable :: latitude_one_tile(:,:)
77
85
real (esmf_kind_r4 ), allocatable :: longitude_one_tile(:,:)
86
+ real (esmf_kind_r4 ), allocatable :: land_frac_one_tile(:,:)
78
87
79
88
!- ----------------------------------------------------------------------
80
89
! Get the number of tiles from the mosaic file.
@@ -214,20 +223,31 @@ subroutine define_model_grid(localpet, npets)
214
223
if (ESMF_logFoundError(rcToCheck= rc,msg= ESMF_LOGERR_PASSTHRU,line= __LINE__,file= __FILE__)) &
215
224
call error_handler(" IN FieldGet" , rc)
216
225
226
+ print * ," - CALL FieldCreate FOR MODEL GRID LAND FRACTION."
227
+ land_frac_field_mdl = ESMF_FieldCreate(grid_mdl, &
228
+ typekind= ESMF_TYPEKIND_R4 , &
229
+ staggerloc= ESMF_STAGGERLOC_CENTER, &
230
+ name= " model grid land fraction" , &
231
+ rc= rc)
232
+ if (ESMF_logFoundError(rcToCheck= rc,msg= ESMF_LOGERR_PASSTHRU,line= __LINE__,file= __FILE__)) &
233
+ call error_handler(" IN FieldCreate" , rc)
234
+
217
235
if (localpet == 0 ) then
218
236
allocate (mask_mdl_one_tile(i_mdl,j_mdl))
237
+ allocate (land_frac_one_tile(i_mdl,j_mdl))
219
238
allocate (latitude_one_tile(i_mdl,j_mdl))
220
239
allocate (longitude_one_tile(i_mdl,j_mdl))
221
240
else
222
241
allocate (mask_mdl_one_tile(0 ,0 ))
242
+ allocate (land_frac_one_tile(0 ,0 ))
223
243
allocate (latitude_one_tile(0 ,0 ))
224
244
allocate (longitude_one_tile(0 ,0 ))
225
245
endif
226
246
227
247
do tile = 1 , num_tiles
228
248
if (localpet == 0 ) then
229
249
the_file = trim (orog_dir_mdl) // trim (orog_files_mdl(tile))
230
- call get_model_info(trim (the_file), mask_mdl_one_tile, &
250
+ call get_model_info(trim (the_file), mask_mdl_one_tile, land_frac_one_tile, &
231
251
latitude_one_tile, longitude_one_tile, i_mdl, j_mdl)
232
252
endif
233
253
@@ -236,6 +256,11 @@ subroutine define_model_grid(localpet, npets)
236
256
if (ESMF_logFoundError(rcToCheck= rc,msg= ESMF_LOGERR_PASSTHRU,line= __LINE__,file= __FILE__)) &
237
257
call error_handler(" IN FieldScatter" , rc)
238
258
259
+ print * ," - CALL FieldScatter FOR MODEL GRID LAND FRACTION. TILE IS: " , tile
260
+ call ESMF_FieldScatter(land_frac_field_mdl, land_frac_one_tile, rootpet= 0 , tile= tile, rc= rc)
261
+ if (ESMF_logFoundError(rcToCheck= rc,msg= ESMF_LOGERR_PASSTHRU,line= __LINE__,file= __FILE__)) &
262
+ call error_handler(" IN FieldScatter" , rc)
263
+
239
264
print * ," - CALL FieldScatter FOR MODEL LATITUDE. TILE IS: " , tile
240
265
call ESMF_FieldScatter(latitude_field_mdl, latitude_one_tile, rootpet= 0 , tile= tile, rc= rc)
241
266
if (ESMF_logFoundError(rcToCheck= rc,msg= ESMF_LOGERR_PASSTHRU,line= __LINE__,file= __FILE__)) &
@@ -282,7 +307,7 @@ end subroutine define_model_grid
282
307
! ! @param[in] idim i dimension of the model tile
283
308
! ! @param[in] jdim j dimension of the model tile
284
309
! ! @author George Gayno @date 2018
285
- subroutine get_model_info (orog_file , mask , lat2d , lon2d , idim , jdim )
310
+ subroutine get_model_info (orog_file , mask , land_frac , lat2d , lon2d , idim , jdim )
286
311
287
312
use esmf
288
313
use netcdf
@@ -297,6 +322,7 @@ subroutine get_model_info(orog_file, mask, lat2d, lon2d, idim, jdim)
297
322
298
323
real (esmf_kind_r4 ), intent (out ) :: lat2d(idim,jdim)
299
324
real (esmf_kind_r4 ), intent (out ) :: lon2d(idim,jdim)
325
+ real (esmf_kind_r4 ), intent (out ) :: land_frac(idim,jdim)
300
326
301
327
integer :: error, lat, lon, i, j
302
328
integer :: ncid, id_dim, id_var
@@ -330,11 +356,17 @@ subroutine get_model_info(orog_file, mask, lat2d, lon2d, idim, jdim)
330
356
allocate (dummy(idim,jdim))
331
357
332
358
!- ----------------------------------------------------------------------
333
- ! If the lake maker was used, there will be a 'lake_frac' record.
359
+ ! If the lake maker was used, we are running with a fractional
360
+ ! land/non-land grid and there will be a 'lake_frac' record.
334
361
! In that case, land/non-land is determined by 'land_frac'.
335
362
!
336
363
! If the lake maker was not used, use 'slmsk', which is defined
337
364
! as the nint(land_frac).
365
+ !
366
+ ! In summary, if 'mask' is one, the point is all land or
367
+ ! partial land and surface data will be mapped to it. Otherwise,
368
+ ! when 'mask' is zero, then the point is all non-land and
369
+ ! surface data will not be mapped to it.
338
370
!- ----------------------------------------------------------------------
339
371
340
372
error= nf90_inq_varid(ncid, ' lake_frac' , id_var)
@@ -345,16 +377,17 @@ subroutine get_model_info(orog_file, mask, lat2d, lon2d, idim, jdim)
345
377
error= nf90_get_var(ncid, id_var, dummy)
346
378
call netcdf_err(error, " READING SLMSK" )
347
379
mask = nint (dummy)
380
+ land_frac = - 999 .
348
381
else
349
382
print * ," - READ LAND FRACTION"
350
383
error= nf90_inq_varid(ncid, ' land_frac' , id_var)
351
384
call netcdf_err(error, " READING LAND_FRAC ID" )
352
- error= nf90_get_var(ncid, id_var, dummy )
385
+ error= nf90_get_var(ncid, id_var, land_frac )
353
386
call netcdf_err(error, " READING LAND_FRAC" )
354
387
mask = 0
355
388
do j = 1 , lat
356
389
do i = 1 , lon
357
- if (dummy (i,j) > 0.0 ) then
390
+ if (land_frac (i,j) > 0.0 ) then
358
391
mask(i,j) = 1
359
392
endif
360
393
enddo
@@ -398,6 +431,9 @@ subroutine model_grid_cleanup
398
431
print * ," - CALL FieldDestroy FOR MODEL GRID LAND MASK."
399
432
call ESMF_FieldDestroy(mask_field_mdl,rc= rc)
400
433
434
+ print * ," - CALL FieldDestroy FOR MODEL GRID LAND MASK."
435
+ call ESMF_FieldDestroy(land_frac_field_mdl,rc= rc)
436
+
401
437
print * ," - CALL FieldDestroy FOR MODEL GRID DATA FIELD."
402
438
call ESMF_FieldDestroy(data_field_mdl,rc= rc)
403
439
0 commit comments