21 type(esmf_field
),
public :: alvsf_target_grid
22 type(esmf_field),
public :: alvwf_target_grid
23 type(esmf_field),
public :: alnsf_target_grid
24 type(esmf_field),
public :: alnwf_target_grid
25 type(esmf_field),
public :: facsf_target_grid
26 type(esmf_field),
public :: facwf_target_grid
27 type(esmf_field),
public :: max_veg_greenness_target_grid
28 type(esmf_field),
public :: min_veg_greenness_target_grid
29 type(esmf_field),
public :: mxsno_albedo_target_grid
30 type(esmf_field),
public :: slope_type_target_grid
31 type(esmf_field),
public :: soil_type_target_grid
32 type(esmf_field),
public :: substrate_temp_target_grid
33 type(esmf_field),
public :: veg_greenness_target_grid
34 type(esmf_field),
public :: veg_type_target_grid
50 num_tiles_target_grid, &
55 integer,
intent(in) :: localpet
57 integer :: error, tile, i, j
59 real(esmf_kind_r8),
allocatable :: data_one_tile(:,:)
60 real(esmf_kind_r8),
allocatable :: max_data_one_tile(:,:)
61 real(esmf_kind_r8),
allocatable :: min_data_one_tile(:,:)
64 allocate(data_one_tile(i_target,j_target))
66 allocate(data_one_tile(0,0))
75 do tile = 1, num_tiles_target_grid
76 if (localpet == 0)
then
79 print*,
"- CALL FieldScatter FOR TARGET GRID SLOPE TYPE."
80 call esmf_fieldscatter(slope_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
81 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
89 do tile = 1, num_tiles_target_grid
90 if (localpet == 0)
then
91 call
read_static_file(
'maximum_snow_albedo', i_target, j_target, tile, data_one_tile)
93 print*,
"- CALL FieldScatter FOR TARGET GRID MAXIMUM SNOW ALBEDO."
94 call esmf_fieldscatter(mxsno_albedo_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
95 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
103 do tile = 1, num_tiles_target_grid
104 if (localpet == 0)
then
107 print*,
"- CALL FieldScatter FOR TARGET GRID SOIL TYPE."
108 call esmf_fieldscatter(soil_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
109 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
117 do tile = 1, num_tiles_target_grid
118 if (localpet == 0)
then
119 call
read_static_file(
'vegetation_type', i_target, j_target, tile, data_one_tile)
121 print*,
"- CALL FieldScatter FOR TARGET GRID VEGETATION TYPE."
122 call esmf_fieldscatter(veg_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
123 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
131 if (localpet == 0)
then
132 allocate(max_data_one_tile(i_target,j_target))
133 allocate(min_data_one_tile(i_target,j_target))
135 allocate(max_data_one_tile(0,0))
136 allocate(min_data_one_tile(0,0))
139 do tile = 1, num_tiles_target_grid
140 if (localpet == 0)
then
141 call
read_static_file(
'vegetation_greenness', i_target, j_target, tile, data_one_tile, &
142 max_data_one_tile, min_data_one_tile)
144 print*,
"- CALL FieldScatter FOR TARGET GRID VEGETATION GREENNESS."
145 call esmf_fieldscatter(veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
146 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
148 print*,
"- CALL FieldScatter FOR TARGET GRID MAXIMUM VEGETATION GREENNESS."
149 call esmf_fieldscatter(max_veg_greenness_target_grid, max_data_one_tile, rootpet=0, tile=tile, rc=error)
150 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
152 print*,
"- CALL FieldScatter FOR TARGET GRID MINIMUM VEGETATION GREENNESS."
153 call esmf_fieldscatter(min_veg_greenness_target_grid, min_data_one_tile, rootpet=0, tile=tile, rc=error)
154 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
158 deallocate(max_data_one_tile, min_data_one_tile)
164 do tile = 1, num_tiles_target_grid
165 if (localpet == 0)
then
166 call
read_static_file(
'substrate_temperature', i_target, j_target, tile, data_one_tile)
168 print*,
"- CALL FieldScatter FOR TARGET GRID SUBSTRATE TEMPERATURE."
169 call esmf_fieldscatter(substrate_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
170 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
178 do tile = 1, num_tiles_target_grid
179 if (localpet == 0)
then
180 call
read_static_file(
'visible_black_sky_albedo', i_target, j_target, tile, data_one_tile)
182 print*,
"- CALL FieldScatter FOR TARGET GRID ALVSF."
183 call esmf_fieldscatter(alvsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
184 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
188 do tile = 1, num_tiles_target_grid
189 if (localpet == 0)
then
190 call
read_static_file(
'visible_white_sky_albedo', i_target, j_target, tile, data_one_tile)
192 print*,
"- CALL FieldScatter FOR TARGET GRID ALVWF."
193 call esmf_fieldscatter(alvwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
194 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
198 do tile = 1, num_tiles_target_grid
199 if (localpet == 0)
then
200 call
read_static_file(
'near_IR_black_sky_albedo', i_target, j_target, tile, data_one_tile)
202 print*,
"- CALL FieldScatter FOR TARGET GRID ALNSF."
203 call esmf_fieldscatter(alnsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
204 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
208 do tile = 1, num_tiles_target_grid
209 if (localpet == 0)
then
210 call
read_static_file(
'near_IR_white_sky_albedo', i_target, j_target, tile, data_one_tile)
212 print*,
"- CALL FieldScatter FOR TARGET GRID ALNWF."
213 call esmf_fieldscatter(alnwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
214 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
222 do tile = 1, num_tiles_target_grid
223 if (localpet == 0)
then
226 print*,
"- CALL FieldScatter FOR TARGET GRID FACSF."
227 call esmf_fieldscatter(facsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
228 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
230 if (localpet == 0)
then
233 if (data_one_tile(i,j) >= 0.0)
then
234 data_one_tile(i,j) = 1.0 - data_one_tile(i,j)
239 call esmf_fieldscatter(facwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error)
240 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
244 deallocate(data_one_tile)
261 data_one_tile, max_data_one_tile, &
266 use program_setup, only : fix_dir_target_grid, cres_target_grid, &
267 cycle_mon, cycle_day, cycle_hour
271 character(len=*),
intent(in) :: field
272 character(len=100) :: filename
273 character(len=500) :: the_file
275 integer,
intent(in) :: i_target, j_target, tile
277 real(esmf_kind_r8),
intent(out) :: data_one_tile(i_target,j_target)
278 real(esmf_kind_r8),
intent(out),
optional :: max_data_one_tile(i_target,j_target)
279 real(esmf_kind_r8),
intent(out),
optional :: min_data_one_tile(i_target,j_target)
281 integer :: bound1, bound2
282 integer :: error, ncid, id_var, n
283 integer :: i, j, id_time, num_times
284 integer :: idat(8), jdat(8)
285 integer,
allocatable :: days_since(:)
287 real(kind=4),
allocatable :: dummy(:,:,:)
288 real(esmf_kind_r8) :: num_days, num_days_rec1, rinc(5)
289 real(esmf_kind_r8) :: weight_rec1, weight_rec2
291 if (trim(field) ==
'facsf') filename =
"/" // trim(cres_target_grid) //
".facsf." // trim(tiles_target_grid(tile)) //
".nc"
292 if (trim(field) ==
'maximum_snow_albedo') filename =
"/" // trim(cres_target_grid) //
".maximum_snow_albedo." // trim(tiles_target_grid(tile)) //
".nc"
293 if (trim(field) ==
'slope_type') filename =
"/" // trim(cres_target_grid) //
".slope_type." // trim(tiles_target_grid(tile)) //
".nc"
294 if (trim(field) ==
'soil_type') filename =
"/" // trim(cres_target_grid) //
".soil_type." // trim(tiles_target_grid(tile)) //
".nc"
295 if (trim(field) ==
'substrate_temperature') filename =
"/" // trim(cres_target_grid) //
".substrate_temperature." // trim(tiles_target_grid(tile)) //
".nc"
296 if (trim(field) ==
'vegetation_greenness') filename =
"/" // trim(cres_target_grid) //
".vegetation_greenness." // trim(tiles_target_grid(tile)) //
".nc"
297 if (trim(field) ==
'vegetation_type') filename =
"/" // trim(cres_target_grid) //
".vegetation_type." // trim(tiles_target_grid(tile)) //
".nc"
298 if (trim(field) ==
'visible_black_sky_albedo') filename =
"/" // trim(cres_target_grid) //
".snowfree_albedo." // trim(tiles_target_grid(tile)) //
".nc"
299 if (trim(field) ==
'visible_white_sky_albedo') filename =
"/" // trim(cres_target_grid) //
".snowfree_albedo." // trim(tiles_target_grid(tile)) //
".nc"
300 if (trim(field) ==
'near_IR_black_sky_albedo') filename =
"/" // trim(cres_target_grid) //
".snowfree_albedo." // trim(tiles_target_grid(tile)) //
".nc"
301 if (trim(field) ==
'near_IR_white_sky_albedo') filename =
"/" // trim(cres_target_grid) //
".snowfree_albedo." // trim(tiles_target_grid(tile)) //
".nc"
303 the_file = trim(fix_dir_target_grid) // trim(filename)
305 print*,
'- OPEN FILE ',trim(the_file)
306 error=nf90_open(trim(the_file),nf90_nowrite,ncid)
307 call
netcdf_err(error,
'OPENING: '//trim(the_file) )
309 error=nf90_inq_dimid(ncid,
'time', id_time)
311 error=nf90_inquire_dimension(ncid, id_time, len=num_times)
312 call
netcdf_err(error,
'READING TIME DIMENSION')
313 print*,
'- FILE CONTAINS ', num_times,
' TIME RECORDS.'
315 allocate(dummy(i_target,j_target,num_times))
316 error=nf90_inq_varid(ncid, field, id_var)
318 error=nf90_get_var(ncid, id_var, dummy)
321 if (num_times > 1)
then
322 allocate (days_since(num_times))
323 error=nf90_inq_varid(ncid,
'time', id_time)
324 error=nf90_get_var(ncid, id_time, days_since)
325 print*,
'- TIME RECORDS (DAYS SINCE): ', days_since
336 call w3difdat(jdat,idat,1,rinc)
338 if (rinc(1) <= days_since(n))
exit
342 if (bound1 == 0) bound1 = num_times
343 if (bound2 == num_times+1) bound2 = 1
344 print*,
"- BOUNDING TIME RECORDS: ", bound1, bound2
345 if (bound2 /= 1)
then
346 num_days = float(days_since(bound2)) - float(days_since(bound1))
347 num_days_rec1 = rinc(1) - float(days_since(bound1))
348 weight_rec2 = num_days_rec1 / num_days
349 weight_rec1 = 1.0 - weight_rec2
350 print*,
"- BOUNDING WEIGHTS ", weight_rec1, weight_rec2
352 num_days = (float(days_since(bound2)) + 1.0) + (365.0 - float(days_since(bound1)) - 1.0)
353 if (rinc(1) >= days_since(bound1))
then
354 num_days_rec1 = rinc(1) - float(days_since(bound1))
356 num_days_rec1 = (365.0 - float(days_since(bound1))) + rinc(1)
358 weight_rec2 = num_days_rec1 / num_days
359 weight_rec1 = 1.0 - weight_rec2
360 print*,
"- BOUNDING WEIGHTS ", weight_rec1, weight_rec2
365 data_one_tile(i,j) = (weight_rec1*dummy(i,j,bound1)) + (weight_rec2*dummy(i,j,bound2))
369 deallocate(days_since)
373 data_one_tile = dummy(:,:,1)
377 if (trim(field) ==
'vegetation_greenness')
then
381 max_data_one_tile(i,j) = maxval(dummy(i,j,:))
382 min_data_one_tile(i,j) = minval(dummy(i,j,:))
390 error = nf90_close(ncid)
405 print*,
"- CALL FieldCreate FOR TARGET GRID SLOPE TYPE."
406 slope_type_target_grid = esmf_fieldcreate(target_grid, &
407 typekind=esmf_typekind_r8, &
408 staggerloc=esmf_staggerloc_center, rc=error)
409 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
412 print*,
"- CALL FieldCreate FOR TARGET GRID MAXIMUM SNOW ALBEDO."
413 mxsno_albedo_target_grid = esmf_fieldcreate(target_grid, &
414 typekind=esmf_typekind_r8, &
415 staggerloc=esmf_staggerloc_center, rc=error)
416 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
419 print*,
"- CALL FieldCreate FOR TARGET GRID SOIL TYPE."
420 soil_type_target_grid = esmf_fieldcreate(target_grid, &
421 typekind=esmf_typekind_r8, &
422 staggerloc=esmf_staggerloc_center, rc=error)
423 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
426 print*,
"- CALL FieldCreate FOR TARGET GRID VEGETATION TYPE."
427 veg_type_target_grid = esmf_fieldcreate(target_grid, &
428 typekind=esmf_typekind_r8, &
429 staggerloc=esmf_staggerloc_center, rc=error)
430 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
433 print*,
"- CALL FieldCreate FOR TARGET GRID VEGETATION GREENNESS."
434 veg_greenness_target_grid = esmf_fieldcreate(target_grid, &
435 typekind=esmf_typekind_r8, &
436 staggerloc=esmf_staggerloc_center, rc=error)
437 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
440 print*,
"- CALL FieldCreate FOR TARGET GRID MAXIMUM VEGETATION GREENNESS."
441 max_veg_greenness_target_grid = esmf_fieldcreate(target_grid, &
442 typekind=esmf_typekind_r8, &
443 staggerloc=esmf_staggerloc_center, rc=error)
444 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
447 print*,
"- CALL FieldCreate FOR TARGET GRID MINIMUM VEGETATION GREENNESS."
448 min_veg_greenness_target_grid = esmf_fieldcreate(target_grid, &
449 typekind=esmf_typekind_r8, &
450 staggerloc=esmf_staggerloc_center, rc=error)
451 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
454 print*,
"- CALL FieldCreate FOR TARGET GRID SUBSTRATE TEMPERATURE."
455 substrate_temp_target_grid = esmf_fieldcreate(target_grid, &
456 typekind=esmf_typekind_r8, &
457 staggerloc=esmf_staggerloc_center, rc=error)
458 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
461 print*,
"- CALL FieldCreate FOR ALVSF."
462 alvsf_target_grid = esmf_fieldcreate(target_grid, &
463 typekind=esmf_typekind_r8, &
464 staggerloc=esmf_staggerloc_center, rc=error)
465 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
468 print*,
"- CALL FieldCreate FOR ALVWF."
469 alvwf_target_grid = esmf_fieldcreate(target_grid, &
470 typekind=esmf_typekind_r8, &
471 staggerloc=esmf_staggerloc_center, rc=error)
472 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
475 print*,
"- CALL FieldCreate FOR ALNSF."
476 alnsf_target_grid = esmf_fieldcreate(target_grid, &
477 typekind=esmf_typekind_r8, &
478 staggerloc=esmf_staggerloc_center, rc=error)
479 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
482 print*,
"- CALL FieldCreate FOR ALNWF."
483 alnwf_target_grid = esmf_fieldcreate(target_grid, &
484 typekind=esmf_typekind_r8, &
485 staggerloc=esmf_staggerloc_center, rc=error)
486 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
489 print*,
"- CALL FieldCreate FOR TARGET GRID FACSF."
490 facsf_target_grid = esmf_fieldcreate(target_grid, &
491 typekind=esmf_typekind_r8, &
492 staggerloc=esmf_staggerloc_center, rc=error)
493 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
496 print*,
"- CALL FieldCreate FOR TARGET GRID FACWF."
497 facwf_target_grid = esmf_fieldcreate(target_grid, &
498 typekind=esmf_typekind_r8, &
499 staggerloc=esmf_staggerloc_center, rc=error)
500 if(esmf_logfounderror(rctocheck=error,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
514 print*,
"- DESTROY STATIC FIELDS."
516 call esmf_fielddestroy(alvsf_target_grid, rc=rc)
517 call esmf_fielddestroy(alvwf_target_grid, rc=rc)
518 call esmf_fielddestroy(alnsf_target_grid, rc=rc)
519 call esmf_fielddestroy(alnwf_target_grid, rc=rc)
520 call esmf_fielddestroy(facsf_target_grid, rc=rc)
521 call esmf_fielddestroy(facwf_target_grid, rc=rc)
522 call esmf_fielddestroy(max_veg_greenness_target_grid, rc=rc)
523 call esmf_fielddestroy(min_veg_greenness_target_grid, rc=rc)
524 call esmf_fielddestroy(mxsno_albedo_target_grid, rc=rc)
525 call esmf_fielddestroy(slope_type_target_grid, rc=rc)
526 call esmf_fielddestroy(soil_type_target_grid, rc=rc)
527 call esmf_fielddestroy(substrate_temp_target_grid, rc=rc)
528 call esmf_fielddestroy(veg_greenness_target_grid, rc=rc)
529 call esmf_fielddestroy(veg_type_target_grid, rc=rc)
subroutine, public get_static_fields(localpet)
Driver routine to read/time interpolate static/climo fields on the fv3 target grid.
subroutine, public create_static_fields
Create ESMF fields for static target grid data.
Sets up the ESMF grid objects for the input data grid and target FV3 grid.
subroutine, public cleanup_static_fields
Free up memory for fields in this module.
subroutine netcdf_err(err, string)
Error handler for netcdf.
subroutine error_handler(string, rc)
General error handler.
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data...
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.
Reads static surface climatological data for the target FV3 grid (such as soil type and vegetation ty...