17 use utilities,
only : error_handler, netcdf_err
56 integer,
intent(in) :: localpet
58 integer :: error, tile, i, j
60 real(esmf_kind_r8),
allocatable :: data_one_tile(:,:)
61 real(esmf_kind_r8),
allocatable :: max_data_one_tile(:,:)
62 real(esmf_kind_r8),
allocatable :: min_data_one_tile(:,:)
67 allocate(data_one_tile(0,0))
77 if (localpet == 0)
then 80 print*,
"- CALL FieldScatter FOR TARGET GRID SLOPE TYPE." 82 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
83 call error_handler(
"IN FieldScatter", error)
91 if (localpet == 0)
then 94 print*,
"- CALL FieldScatter FOR TARGET GRID MAXIMUM SNOW ALBEDO." 96 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
97 call error_handler(
"IN FieldScatter", error)
105 if (localpet == 0)
then 108 print*,
"- CALL FieldScatter FOR TARGET GRID SOIL TYPE." 110 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
111 call error_handler(
"IN FieldScatter", error)
119 if (localpet == 0)
then 122 print*,
"- CALL FieldScatter FOR TARGET GRID VEGETATION TYPE." 124 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
125 call error_handler(
"IN FieldScatter", error)
132 if (localpet == 0)
then 136 allocate(max_data_one_tile(0,0))
137 allocate(min_data_one_tile(0,0))
141 if (localpet == 0)
then 143 max_data_one_tile, min_data_one_tile)
145 print*,
"- CALL FieldScatter FOR TARGET GRID VEGETATION GREENNESS." 147 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
148 call error_handler(
"IN FieldScatter", error)
149 print*,
"- CALL FieldScatter FOR TARGET GRID MAXIMUM VEGETATION GREENNESS." 151 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
152 call error_handler(
"IN FieldScatter", error)
153 print*,
"- CALL FieldScatter FOR TARGET GRID MINIMUM VEGETATION GREENNESS." 155 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
156 call error_handler(
"IN FieldScatter", error)
159 deallocate(max_data_one_tile, min_data_one_tile)
166 if (localpet == 0)
then 169 print*,
"- CALL FieldScatter FOR TARGET GRID SUBSTRATE TEMPERATURE." 171 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
172 call error_handler(
"IN FieldScatter", error)
180 if (localpet == 0)
then 183 print*,
"- CALL FieldScatter FOR TARGET GRID ALVSF." 184 call esmf_fieldscatter(
alvsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
185 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
186 call error_handler(
"IN FieldScatter", error)
190 if (localpet == 0)
then 193 print*,
"- CALL FieldScatter FOR TARGET GRID ALVWF." 194 call esmf_fieldscatter(
alvwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
195 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
196 call error_handler(
"IN FieldScatter", error)
200 if (localpet == 0)
then 203 print*,
"- CALL FieldScatter FOR TARGET GRID ALNSF." 204 call esmf_fieldscatter(
alnsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
205 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
206 call error_handler(
"IN FieldScatter", error)
210 if (localpet == 0)
then 213 print*,
"- CALL FieldScatter FOR TARGET GRID ALNWF." 214 call esmf_fieldscatter(
alnwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
215 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
216 call error_handler(
"IN FieldScatter", error)
224 if (localpet == 0)
then 227 print*,
"- CALL FieldScatter FOR TARGET GRID FACSF." 228 call esmf_fieldscatter(
facsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
229 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
230 call error_handler(
"IN FieldScatter", error)
231 if (localpet == 0)
then 234 if (data_one_tile(i,j) >= 0.0)
then 235 data_one_tile(i,j) = 1.0 - data_one_tile(i,j)
240 call esmf_fieldscatter(
facwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
241 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
242 call error_handler(
"IN FieldScatter", error)
245 deallocate(data_one_tile)
262 data_one_tile, max_data_one_tile, &
272 character(len=*),
intent(in) :: field
273 character(len=100) :: filename
274 character(len=500) :: the_file
276 integer,
intent(in) :: i_target, j_target, tile
278 real(esmf_kind_r8),
intent(out) :: data_one_tile(i_target,j_target)
279 real(esmf_kind_r8),
intent(out),
optional :: max_data_one_tile(i_target,j_target)
280 real(esmf_kind_r8),
intent(out),
optional :: min_data_one_tile(i_target,j_target)
282 integer :: bound1, bound2
283 integer :: error, ncid, id_var, n
284 integer :: i, j, id_time, num_times
285 integer :: idat(8), jdat(8)
286 integer,
allocatable :: days_since(:)
288 real(kind=4),
allocatable :: dummy(:,:,:)
289 real(esmf_kind_r8) :: num_days, num_days_rec1, rinc(5)
290 real(esmf_kind_r8) :: weight_rec1, weight_rec2
306 print*,
'- OPEN FILE ',trim(the_file)
307 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
308 call netcdf_err(error,
'OPENING: '//trim(the_file) )
310 error=nf90_inq_dimid(ncid,
'time', id_time)
311 call netcdf_err(error,
'INQ TIME DIMENSION')
312 error=nf90_inquire_dimension(ncid, id_time, len=num_times)
313 call netcdf_err(error,
'READING TIME DIMENSION')
314 print*,
'- FILE CONTAINS ', num_times,
' TIME RECORDS.' 316 allocate(dummy(i_target,j_target,num_times))
317 error=nf90_inq_varid(ncid, field, id_var)
318 call netcdf_err(error,
'READING FIELD ID' )
319 error=nf90_get_var(ncid, id_var, dummy)
320 call netcdf_err(error,
'READING FIELD' )
322 if (num_times > 1)
then 323 allocate (days_since(num_times))
324 error=nf90_inq_varid(ncid,
'time', id_time)
325 error=nf90_get_var(ncid, id_time, days_since)
326 print*,
'- TIME RECORDS (DAYS SINCE): ', days_since
337 call w3difdat(jdat,idat,1,rinc)
339 if (rinc(1) <= days_since(n))
exit 343 if (bound1 == 0) bound1 = num_times
344 if (bound2 == num_times+1) bound2 = 1
345 print*,
"- BOUNDING TIME RECORDS: ", bound1, bound2
346 if (bound2 /= 1)
then 347 num_days = float(days_since(bound2)) - float(days_since(bound1))
348 num_days_rec1 = rinc(1) - float(days_since(bound1))
349 weight_rec2 = num_days_rec1 / num_days
350 weight_rec1 = 1.0 - weight_rec2
351 print*,
"- BOUNDING WEIGHTS ", weight_rec1, weight_rec2
353 num_days = (float(days_since(bound2)) + 1.0) + (365.0 - float(days_since(bound1)) - 1.0)
354 if (rinc(1) >= days_since(bound1))
then 355 num_days_rec1 = rinc(1) - float(days_since(bound1))
357 num_days_rec1 = (365.0 - float(days_since(bound1))) + rinc(1)
359 weight_rec2 = num_days_rec1 / num_days
360 weight_rec1 = 1.0 - weight_rec2
361 print*,
"- BOUNDING WEIGHTS ", weight_rec1, weight_rec2
366 data_one_tile(i,j) = (weight_rec1*dummy(i,j,bound1)) + (weight_rec2*dummy(i,j,bound2))
370 deallocate(days_since)
374 data_one_tile = dummy(:,:,1)
378 if (trim(field) ==
'vegetation_greenness')
then 382 max_data_one_tile(i,j) = maxval(dummy(i,j,:))
383 min_data_one_tile(i,j) = minval(dummy(i,j,:))
391 error = nf90_close(ncid)
406 print*,
"- CALL FieldCreate FOR TARGET GRID SLOPE TYPE." 408 typekind=esmf_typekind_r8, &
409 staggerloc=esmf_staggerloc_center, rc=error)
410 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
411 call error_handler(
"IN FieldCreate", error)
413 print*,
"- CALL FieldCreate FOR TARGET GRID MAXIMUM SNOW ALBEDO." 415 typekind=esmf_typekind_r8, &
416 staggerloc=esmf_staggerloc_center, rc=error)
417 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
418 call error_handler(
"IN FieldCreate", error)
420 print*,
"- CALL FieldCreate FOR TARGET GRID SOIL TYPE." 422 typekind=esmf_typekind_r8, &
423 staggerloc=esmf_staggerloc_center, rc=error)
424 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
425 call error_handler(
"IN FieldCreate", error)
427 print*,
"- CALL FieldCreate FOR TARGET GRID VEGETATION TYPE." 429 typekind=esmf_typekind_r8, &
430 staggerloc=esmf_staggerloc_center, rc=error)
431 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
432 call error_handler(
"IN FieldCreate", error)
434 print*,
"- CALL FieldCreate FOR TARGET GRID VEGETATION GREENNESS." 436 typekind=esmf_typekind_r8, &
437 staggerloc=esmf_staggerloc_center, rc=error)
438 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
439 call error_handler(
"IN FieldCreate", error)
441 print*,
"- CALL FieldCreate FOR TARGET GRID MAXIMUM VEGETATION GREENNESS." 443 typekind=esmf_typekind_r8, &
444 staggerloc=esmf_staggerloc_center, rc=error)
445 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
446 call error_handler(
"IN FieldCreate", error)
448 print*,
"- CALL FieldCreate FOR TARGET GRID MINIMUM VEGETATION GREENNESS." 450 typekind=esmf_typekind_r8, &
451 staggerloc=esmf_staggerloc_center, rc=error)
452 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
453 call error_handler(
"IN FieldCreate", error)
455 print*,
"- CALL FieldCreate FOR TARGET GRID SUBSTRATE TEMPERATURE." 457 typekind=esmf_typekind_r8, &
458 staggerloc=esmf_staggerloc_center, rc=error)
459 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
460 call error_handler(
"IN FieldCreate", error)
462 print*,
"- CALL FieldCreate FOR ALVSF." 464 typekind=esmf_typekind_r8, &
465 staggerloc=esmf_staggerloc_center, rc=error)
466 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
467 call error_handler(
"IN FieldCreate", error)
469 print*,
"- CALL FieldCreate FOR ALVWF." 471 typekind=esmf_typekind_r8, &
472 staggerloc=esmf_staggerloc_center, rc=error)
473 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
474 call error_handler(
"IN FieldCreate", error)
476 print*,
"- CALL FieldCreate FOR ALNSF." 478 typekind=esmf_typekind_r8, &
479 staggerloc=esmf_staggerloc_center, rc=error)
480 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
481 call error_handler(
"IN FieldCreate", error)
483 print*,
"- CALL FieldCreate FOR ALNWF." 485 typekind=esmf_typekind_r8, &
486 staggerloc=esmf_staggerloc_center, rc=error)
487 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
488 call error_handler(
"IN FieldCreate", error)
490 print*,
"- CALL FieldCreate FOR TARGET GRID FACSF." 492 typekind=esmf_typekind_r8, &
493 staggerloc=esmf_staggerloc_center, rc=error)
494 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
495 call error_handler(
"IN FieldCreate", error)
497 print*,
"- CALL FieldCreate FOR TARGET GRID FACWF." 499 typekind=esmf_typekind_r8, &
500 staggerloc=esmf_staggerloc_center, rc=error)
501 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
502 call error_handler(
"IN FieldCreate", error)
515 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.
character(len=6), public cres_target_grid
Target grid resolution, i.e., C768.
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.
type(esmf_grid), public target_grid
target grid esmf grid object.
type(esmf_field), public alnsf_target_grid
near ir black sky albedo
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
subroutine read_static_file(field, i_target, j_target, tile, data_one_tile, max_data_one_tile, min_data_one_tile)
Read static climatological data file.
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