17 use utilities,
only : error_handler, netcdf_err
57 integer,
intent(in) :: localpet
59 integer :: error, tile, i, j
61 real(esmf_kind_r8),
allocatable :: data_one_tile(:,:)
62 real(esmf_kind_r8),
allocatable :: max_data_one_tile(:,:)
63 real(esmf_kind_r8),
allocatable :: min_data_one_tile(:,:)
64 real(esmf_kind_r8),
allocatable :: land_frac_target_tile(:,:)
69 allocate(data_one_tile(0,0))
70 allocate(land_frac_target_tile(0,0))
81 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
82 call error_handler(
"IN FieldGather", error)
83 if (localpet == 0)
then 86 print*,
"- CALL FieldScatter FOR TARGET GRID SLOPE TYPE." 88 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
89 call error_handler(
"IN FieldScatter", error)
98 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
99 call error_handler(
"IN FieldGather", error)
100 if (localpet == 0)
then 103 print*,
"- CALL FieldScatter FOR TARGET GRID MAXIMUM SNOW ALBEDO." 105 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
106 call error_handler(
"IN FieldScatter", error)
115 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
116 call error_handler(
"IN FieldGather", error)
117 if (localpet == 0)
then 120 print*,
"- CALL FieldScatter FOR TARGET GRID SOIL TYPE." 122 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
123 call error_handler(
"IN FieldScatter", error)
132 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
133 call error_handler(
"IN FieldGather", error)
134 if (localpet == 0)
then 137 print*,
"- CALL FieldScatter FOR TARGET GRID VEGETATION TYPE." 139 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
140 call error_handler(
"IN FieldScatter", error)
147 if (localpet == 0)
then 151 allocate(max_data_one_tile(0,0))
152 allocate(min_data_one_tile(0,0))
157 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
158 call error_handler(
"IN FieldGather", error)
159 if (localpet == 0)
then 161 land_frac_target_tile, max_data_one_tile, min_data_one_tile)
163 print*,
"- CALL FieldScatter FOR TARGET GRID VEGETATION GREENNESS." 165 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
166 call error_handler(
"IN FieldScatter", error)
167 print*,
"- CALL FieldScatter FOR TARGET GRID MAXIMUM VEGETATION GREENNESS." 169 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
170 call error_handler(
"IN FieldScatter", error)
171 print*,
"- CALL FieldScatter FOR TARGET GRID MINIMUM VEGETATION GREENNESS." 173 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
174 call error_handler(
"IN FieldScatter", error)
177 deallocate(max_data_one_tile, min_data_one_tile)
185 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
186 call error_handler(
"IN FieldGather", error)
187 if (localpet == 0)
then 190 print*,
"- CALL FieldScatter FOR TARGET GRID SUBSTRATE TEMPERATURE." 192 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
193 call error_handler(
"IN FieldScatter", error)
202 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
203 call error_handler(
"IN FieldGather", error)
204 if (localpet == 0)
then 207 print*,
"- CALL FieldScatter FOR TARGET GRID ALVSF." 208 call esmf_fieldscatter(
alvsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
209 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
210 call error_handler(
"IN FieldScatter", error)
215 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
216 call error_handler(
"IN FieldGather", error)
217 if (localpet == 0)
then 220 print*,
"- CALL FieldScatter FOR TARGET GRID ALVWF." 221 call esmf_fieldscatter(
alvwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
222 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
223 call error_handler(
"IN FieldScatter", error)
228 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
229 call error_handler(
"IN FieldGather", error)
230 if (localpet == 0)
then 233 print*,
"- CALL FieldScatter FOR TARGET GRID ALNSF." 234 call esmf_fieldscatter(
alnsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
235 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
236 call error_handler(
"IN FieldScatter", error)
241 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
242 call error_handler(
"IN FieldGather", error)
243 if (localpet == 0)
then 246 print*,
"- CALL FieldScatter FOR TARGET GRID ALNWF." 247 call esmf_fieldscatter(
alnwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
248 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
249 call error_handler(
"IN FieldScatter", error)
258 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
259 call error_handler(
"IN FieldGather", error)
260 if (localpet == 0)
then 263 print*,
"- CALL FieldScatter FOR TARGET GRID FACSF." 264 call esmf_fieldscatter(
facsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
265 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
266 call error_handler(
"IN FieldScatter", error)
267 if (localpet == 0)
then 270 if (data_one_tile(i,j) >= 0.0)
then 271 data_one_tile(i,j) = 1.0 - data_one_tile(i,j)
276 call esmf_fieldscatter(
facwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
277 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
278 call error_handler(
"IN FieldScatter", error)
281 deallocate(data_one_tile)
299 data_one_tile, land_frac, max_data_one_tile, &
309 character(len=*),
intent(in) :: field
310 character(len=100) :: filename
311 character(len=500) :: the_file, err_msg
313 integer,
intent(in) :: i_target, j_target, tile
315 real(esmf_kind_r8),
intent(in) :: land_frac(i_target,j_target)
316 real(esmf_kind_r8),
intent(out) :: data_one_tile(i_target,j_target)
317 real(esmf_kind_r8),
intent(out),
optional :: max_data_one_tile(i_target,j_target)
318 real(esmf_kind_r8),
intent(out),
optional :: min_data_one_tile(i_target,j_target)
320 integer :: bound1, bound2
321 integer :: error, ncid, id_var, n
322 integer :: i, j, id_time, num_times
323 integer :: idat(8), jdat(8)
324 integer,
allocatable :: days_since(:)
326 real(kind=4),
allocatable :: dummy(:,:,:)
327 real(esmf_kind_r8) :: num_days, num_days_rec1, rinc(5)
328 real(esmf_kind_r8) :: weight_rec1, weight_rec2
344 print*,
'- OPEN FILE ',trim(the_file)
345 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
346 call netcdf_err(error,
'OPENING: '//trim(the_file) )
348 error=nf90_inq_dimid(ncid,
'time', id_time)
349 call netcdf_err(error,
'INQ TIME DIMENSION')
350 error=nf90_inquire_dimension(ncid, id_time, len=num_times)
351 call netcdf_err(error,
'READING TIME DIMENSION')
352 print*,
'- FILE CONTAINS ', num_times,
' TIME RECORDS.' 354 allocate(dummy(i_target,j_target,num_times))
355 error=nf90_inq_varid(ncid, field, id_var)
356 call netcdf_err(error,
'READING FIELD ID' )
357 error=nf90_get_var(ncid, id_var, dummy)
358 call netcdf_err(error,
'READING FIELD' )
360 if (num_times > 1)
then 361 allocate (days_since(num_times))
362 error=nf90_inq_varid(ncid,
'time', id_time)
363 error=nf90_get_var(ncid, id_time, days_since)
364 print*,
'- TIME RECORDS (DAYS SINCE): ', days_since
375 call w3difdat(jdat,idat,1,rinc)
377 if (rinc(1) <= days_since(n))
exit 381 if (bound1 == 0) bound1 = num_times
382 if (bound2 == num_times+1) bound2 = 1
383 print*,
"- BOUNDING TIME RECORDS: ", bound1, bound2
384 if (bound2 /= 1)
then 385 num_days = float(days_since(bound2)) - float(days_since(bound1))
386 num_days_rec1 = rinc(1) - float(days_since(bound1))
387 weight_rec2 = num_days_rec1 / num_days
388 weight_rec1 = 1.0 - weight_rec2
389 print*,
"- BOUNDING WEIGHTS ", weight_rec1, weight_rec2
391 num_days = (float(days_since(bound2)) + 1.0) + (365.0 - float(days_since(bound1)) - 1.0)
392 if (rinc(1) >= days_since(bound1))
then 393 num_days_rec1 = rinc(1) - float(days_since(bound1))
395 num_days_rec1 = (365.0 - float(days_since(bound1))) + rinc(1)
397 weight_rec2 = num_days_rec1 / num_days
398 weight_rec1 = 1.0 - weight_rec2
399 print*,
"- BOUNDING WEIGHTS ", weight_rec1, weight_rec2
404 data_one_tile(i,j) = (weight_rec1*dummy(i,j,bound1)) + (weight_rec2*dummy(i,j,bound2))
408 deallocate(days_since)
414 if(land_frac(i,j) > 0.0 .and. dummy(i,j,1) == -999)
then 415 err_msg =
"Detected missing data point in " // trim(filename) //
". Static data may be outdated. Please use static data created with the latest UFS_UTILS release that supports fractional land coverage" 416 call error_handler(err_msg,-1)
418 data_one_tile(i,j) = dummy(i,j,1)
423 if (trim(field) ==
'vegetation_greenness')
then 427 max_data_one_tile(i,j) = maxval(dummy(i,j,:))
428 min_data_one_tile(i,j) = minval(dummy(i,j,:))
436 error = nf90_close(ncid)
451 print*,
"- CALL FieldCreate FOR TARGET GRID SLOPE TYPE." 453 typekind=esmf_typekind_r8, &
454 staggerloc=esmf_staggerloc_center, rc=error)
455 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
456 call error_handler(
"IN FieldCreate", error)
458 print*,
"- CALL FieldCreate FOR TARGET GRID MAXIMUM SNOW ALBEDO." 460 typekind=esmf_typekind_r8, &
461 staggerloc=esmf_staggerloc_center, rc=error)
462 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
463 call error_handler(
"IN FieldCreate", error)
465 print*,
"- CALL FieldCreate FOR TARGET GRID SOIL TYPE." 467 typekind=esmf_typekind_r8, &
468 staggerloc=esmf_staggerloc_center, rc=error)
469 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
470 call error_handler(
"IN FieldCreate", error)
472 print*,
"- CALL FieldCreate FOR TARGET GRID VEGETATION TYPE." 474 typekind=esmf_typekind_r8, &
475 staggerloc=esmf_staggerloc_center, rc=error)
476 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
477 call error_handler(
"IN FieldCreate", error)
479 print*,
"- CALL FieldCreate FOR TARGET GRID VEGETATION GREENNESS." 481 typekind=esmf_typekind_r8, &
482 staggerloc=esmf_staggerloc_center, rc=error)
483 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
484 call error_handler(
"IN FieldCreate", error)
486 print*,
"- CALL FieldCreate FOR TARGET GRID MAXIMUM VEGETATION GREENNESS." 488 typekind=esmf_typekind_r8, &
489 staggerloc=esmf_staggerloc_center, rc=error)
490 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
491 call error_handler(
"IN FieldCreate", error)
493 print*,
"- CALL FieldCreate FOR TARGET GRID MINIMUM VEGETATION GREENNESS." 495 typekind=esmf_typekind_r8, &
496 staggerloc=esmf_staggerloc_center, rc=error)
497 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
498 call error_handler(
"IN FieldCreate", error)
500 print*,
"- CALL FieldCreate FOR TARGET GRID SUBSTRATE TEMPERATURE." 502 typekind=esmf_typekind_r8, &
503 staggerloc=esmf_staggerloc_center, rc=error)
504 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
505 call error_handler(
"IN FieldCreate", error)
507 print*,
"- CALL FieldCreate FOR ALVSF." 509 typekind=esmf_typekind_r8, &
510 staggerloc=esmf_staggerloc_center, rc=error)
511 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
512 call error_handler(
"IN FieldCreate", error)
514 print*,
"- CALL FieldCreate FOR ALVWF." 516 typekind=esmf_typekind_r8, &
517 staggerloc=esmf_staggerloc_center, rc=error)
518 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
519 call error_handler(
"IN FieldCreate", error)
521 print*,
"- CALL FieldCreate FOR ALNSF." 523 typekind=esmf_typekind_r8, &
524 staggerloc=esmf_staggerloc_center, rc=error)
525 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
526 call error_handler(
"IN FieldCreate", error)
528 print*,
"- CALL FieldCreate FOR ALNWF." 530 typekind=esmf_typekind_r8, &
531 staggerloc=esmf_staggerloc_center, rc=error)
532 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
533 call error_handler(
"IN FieldCreate", error)
535 print*,
"- CALL FieldCreate FOR TARGET GRID FACSF." 537 typekind=esmf_typekind_r8, &
538 staggerloc=esmf_staggerloc_center, rc=error)
539 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
540 call error_handler(
"IN FieldCreate", error)
542 print*,
"- CALL FieldCreate FOR TARGET GRID FACWF." 544 typekind=esmf_typekind_r8, &
545 staggerloc=esmf_staggerloc_center, rc=error)
546 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
547 call error_handler(
"IN FieldCreate", error)
560 print*,
"- DESTROY STATIC FIELDS." integer, public j_target
j dimension of each global tile, or of a nest, target grid.
character(len=500), public fix_dir_target_grid
Directory containing target grid pre-computed fixed data (ex: soil type).
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data...
integer, public num_tiles_target_grid
Number of tiles, target grid.
subroutine, public create_static_fields
Create ESMF fields for static target grid data.
integer, public cycle_mon
Cycle month.
type(esmf_field), public land_frac_target_grid
land fraction, target grid
type(esmf_field), public min_veg_greenness_target_grid
minimum annual greenness fraction
type(esmf_field), public max_veg_greenness_target_grid
maximum annual greenness fraction
type(esmf_field), public mxsno_albedo_target_grid
maximum snow albedo
Sets up the ESMF grid objects for the input data grid and target FV3 grid.
type(esmf_field), public alvwf_target_grid
visible white sky albedo
integer, public i_target
i dimension of each global tile, or of a nest, target grid.
integer, public cycle_day
Cycle day.
character(len=15), public cres_target_grid
Target grid resolution, i.e., C768.
type(esmf_grid), public target_grid
target grid esmf grid object.
type(esmf_field), public alnsf_target_grid
near ir black sky albedo
subroutine read_static_file(field, i_target, j_target, tile, data_one_tile, land_frac, max_data_one_tile, min_data_one_tile)
Read static climatological data file.
subroutine, public cleanup_static_fields
Free up memory for fields in this module.
type(esmf_field), public alvsf_target_grid
visible black sky albedo
type(esmf_field), public slope_type_target_grid
slope type
Reads static surface climatological data for the target FV3 grid (such as soil type and vegetation ty...
type(esmf_field), public substrate_temp_target_grid
soil subtrate temperature
type(esmf_field), public veg_greenness_target_grid
vegetation greenness fraction
character(len=5), dimension(:), allocatable, public tiles_target_grid
Tile names of target grid.
type(esmf_field), public veg_type_target_grid
vegetation type
integer, public cycle_hour
Cycle hour.
type(esmf_field), public facwf_target_grid
fractional coverage for weak zenith angle dependent albedo
subroutine, public get_static_fields(localpet)
Driver routine to read/time interpolate static/climo fields on the fv3 target grid.
type(esmf_field), public alnwf_target_grid
near ir white sky albedo
type(esmf_field), public facsf_target_grid
fractional coverage for strong zenith angle dependent albedo
type(esmf_field), public soil_type_target_grid
soil type