chgres_cube 1.14.0
Loading...
Searching...
No Matches
sfc_input_data.F90
Go to the documentation of this file.
1module sfc_input_data
5
15 use esmf
16 use netcdf
17#ifdef CHGRES_ALL
18 use nemsio_module
19#endif
20
27 input_type, &
35
36 use model_grid, only : input_grid, &
40
41 use utilities, only : error_handler, &
42 netcdf_err, &
43 handle_grib_error, &
44 to_upper, &
45 check_soilt, &
46 check_cnwat
47
48! Fields associated with the land-surface model.
49
50 integer, public :: veg_type_landice_input = 15
53 real :: icet_default = 265.0
55 type(esmf_field), public :: canopy_mc_input_grid
56 type(esmf_field), public :: f10m_input_grid
57 type(esmf_field), public :: ffmm_input_grid
59 type(esmf_field), public :: landsea_mask_input_grid
61 type(esmf_field), public :: q2m_input_grid
62 type(esmf_field), public :: seaice_depth_input_grid
63 type(esmf_field), public :: seaice_fract_input_grid
64 type(esmf_field), public :: seaice_skin_temp_input_grid
65 type(esmf_field), public :: skin_temp_input_grid
66 type(esmf_field), public :: snow_depth_input_grid
67 type(esmf_field), public :: snow_liq_equiv_input_grid
68 type(esmf_field), public :: soil_temp_input_grid
69 type(esmf_field), public :: soil_type_input_grid
70 type(esmf_field), public :: soilm_liq_input_grid
71 type(esmf_field), public :: soilm_tot_input_grid
72 type(esmf_field), public :: srflag_input_grid
73 type(esmf_field), public :: t2m_input_grid
74 type(esmf_field), public :: tprcp_input_grid
75 type(esmf_field), public :: ustar_input_grid
76 type(esmf_field), public :: veg_type_input_grid
77 type(esmf_field), public :: z0_input_grid
78 type(esmf_field), public :: veg_greenness_input_grid
79 type(esmf_field), public :: lai_input_grid
80 type(esmf_field), public :: max_veg_greenness_input_grid
81 type(esmf_field), public :: min_veg_greenness_input_grid
82
83 integer, public :: lsoil_input=4
85
86 public :: read_input_sfc_data
87 public :: cleanup_input_sfc_data
88 public :: init_sfc_esmf_fields
89
90 contains
91
96 subroutine read_input_sfc_data(localpet)
97
98 implicit none
99
100 integer, intent(in) :: localpet
101
102 call init_sfc_esmf_fields()
103
104!-------------------------------------------------------------------------------
105! Read the tiled 'warm' restart files.
106!-------------------------------------------------------------------------------
107
108 if (trim(input_type) == "restart") then
109
110 call read_input_sfc_restart_file(localpet)
111
112!-------------------------------------------------------------------------------
113! Read the tiled or gaussian history files in netcdf format.
114!-------------------------------------------------------------------------------
115
116 elseif (trim(input_type) == "history" .or. trim(input_type) == &
117 "gaussian_netcdf") then
118
119 call read_input_sfc_netcdf_file(localpet)
120
121!-------------------------------------------------------------------------------
122! Read the gaussian history files in nemsio format.
123!-------------------------------------------------------------------------------
124
125#ifdef CHGRES_ALL
126 elseif (trim(input_type) == "gaussian_nemsio") then
127
128 call read_input_sfc_gaussian_nemsio_file(localpet)
129
130!-------------------------------------------------------------------------------
131! Read the spectral gfs gaussian history files in nemsio format.
132!-------------------------------------------------------------------------------
133
134 elseif (trim(input_type) == "gfs_gaussian_nemsio") then
135
136 call read_input_sfc_gfs_gaussian_nemsio_file(localpet)
137
138!-------------------------------------------------------------------------------
139! Read the spectral gfs gaussian history files in sfcio format.
140!-------------------------------------------------------------------------------
141
142 elseif (trim(input_type) == "gfs_sigio") then
143
144 call read_input_sfc_gfs_sfcio_file(localpet)
145
146#endif
147!-------------------------------------------------------------------------------
148! Read fv3gfs surface data in grib2 format.
149!-------------------------------------------------------------------------------
150
151 elseif (trim(input_type) == "grib2") then
152
153 call read_input_sfc_grib2_file(localpet)
154
155 endif
156
157 end subroutine read_input_sfc_data
158
159#ifdef CHGRES_ALL
160
167 subroutine read_input_sfc_gfs_sfcio_file(localpet)
168
169 use sfcio_module
170
171 implicit none
172
173 integer, intent(in) :: localpet
174
175 character(len=300) :: the_file
176
177 integer(sfcio_intkind) :: iret
178 integer :: rc
179
180 real(esmf_kind_r8), allocatable :: dummy2d(:,:)
181 real(esmf_kind_r8), allocatable :: dummy3d(:,:,:)
182
183 type(sfcio_head) :: sfchead
184 type(sfcio_dbta) :: sfcdata
185
186 the_file = trim(data_dir_input_grid) // "/" // trim(sfc_files_input_grid(1))
187
188 print*,"- READ SURFACE DATA IN SFCIO FORMAT."
189 print*,"- OPEN AND READ: ",trim(the_file)
190 call sfcio_sropen(23, trim(the_file), iret)
191 if (iret /= 0) then
192 rc=iret
193 call error_handler("OPENING FILE", rc)
194 endif
195
196 call sfcio_srhead(23, sfchead, iret)
197 if (iret /= 0) then
198 rc=iret
199 call error_handler("READING HEADER", rc)
200 endif
201
202 if (localpet == 0) then
203 call sfcio_aldbta(sfchead, sfcdata, iret)
204 if (iret /= 0) then
205 rc=iret
206 call error_handler("ALLOCATING DATA.", rc)
207 endif
208 call sfcio_srdbta(23, sfchead, sfcdata, iret)
209 if (iret /= 0) then
210 rc=iret
211 call error_handler("READING DATA.", rc)
212 endif
213 allocate(dummy2d(i_input,j_input))
214 allocate(dummy3d(i_input,j_input,lsoil_input))
215 else
216 allocate(dummy2d(0,0))
217 allocate(dummy3d(0,0,0))
218 endif
219
220 if (localpet == 0) dummy2d = sfcdata%slmsk
221
222 print*,"- CALL FieldScatter FOR INPUT LANDSEA MASK."
223 call esmf_fieldscatter(landsea_mask_input_grid, dummy2d, rootpet=0, rc=rc)
224 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
225 call error_handler("IN FieldScatter", rc)
226
227 if (localpet == 0) dummy2d = sfcdata%zorl
228
229 print*,"- CALL FieldScatter FOR INPUT Z0."
230 call esmf_fieldscatter(z0_input_grid, dummy2d, rootpet=0, rc=rc)
231 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
232 call error_handler("IN FieldScatter", rc)
233
234 if (localpet == 0) dummy2d = nint(sfcdata%vtype)
235
236 print*,"- CALL FieldScatter FOR INPUT VEG TYPE."
237 call esmf_fieldscatter(veg_type_input_grid, dummy2d, rootpet=0, rc=rc)
238 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
239 call error_handler("IN FieldScatter", rc)
240
241! Prior to July, 2017, gfs used zobler soil types. '13' indicates permanent land ice.
242 veg_type_landice_input = 13
243
244 if (localpet == 0) dummy2d = sfcdata%canopy
245
246 print*,"- CALL FieldScatter FOR INPUT CANOPY MC."
247 call esmf_fieldscatter(canopy_mc_input_grid, dummy2d, rootpet=0, rc=rc)
248 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
249 call error_handler("IN FieldScatter", rc)
250
251 if (localpet == 0) dummy2d = sfcdata%fice
252
253 print*,"- CALL FieldScatter FOR INPUT ICE FRACTION."
254 call esmf_fieldscatter(seaice_fract_input_grid, dummy2d, rootpet=0, rc=rc)
255 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
256 call error_handler("IN FieldScatter", rc)
257
258 if (localpet == 0) dummy2d = sfcdata%hice
259
260 print*,"- CALL FieldScatter FOR INPUT ICE DEPTH."
261 call esmf_fieldscatter(seaice_depth_input_grid, dummy2d, rootpet=0, rc=rc)
262 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
263 call error_handler("IN FieldScatter", rc)
264
265 if (localpet == 0) dummy2d = sfcdata%tisfc
266
267 print*,"- CALL FieldScatter FOR INPUT ICE SKIN TEMP."
268 call esmf_fieldscatter(seaice_skin_temp_input_grid, dummy2d, rootpet=0, rc=rc)
269 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
270 call error_handler("IN FieldScatter", rc)
271
272 if (localpet == 0) dummy2d = sfcdata%snwdph ! mm (expected by program)
273
274 print*,"- CALL FieldScatter FOR INPUT SNOW DEPTH."
275 call esmf_fieldscatter(snow_depth_input_grid, dummy2d, rootpet=0, rc=rc)
276 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
277 call error_handler("IN FieldScatter", rc)
278
279 if (localpet == 0) dummy2d = sfcdata%sheleg
280
281 print*,"- CALL FieldScatter FOR INPUT SNOW LIQUID EQUIV."
282 call esmf_fieldscatter(snow_liq_equiv_input_grid, dummy2d, rootpet=0, rc=rc)
283 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
284 call error_handler("IN FieldScatter", rc)
285
286 if (localpet == 0) dummy2d = sfcdata%t2m
287
288 print*,"- CALL FieldScatter FOR INPUT T2M."
289 call esmf_fieldscatter(t2m_input_grid, dummy2d, rootpet=0, rc=rc)
290 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
291 call error_handler("IN FieldScatter", rc)
292
293 if (localpet == 0) dummy2d = sfcdata%q2m
294
295 print*,"- CALL FieldScatter FOR INPUT Q2M."
296 call esmf_fieldscatter(q2m_input_grid, dummy2d, rootpet=0, rc=rc)
297 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
298 call error_handler("IN FieldScatter", rc)
299
300 if (localpet == 0) dummy2d = sfcdata%tprcp
301
302 print*,"- CALL FieldScatter FOR INPUT TPRCP."
303 call esmf_fieldscatter(tprcp_input_grid, dummy2d, rootpet=0, rc=rc)
304 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
305 call error_handler("IN FieldScatter", rc)
306
307 if (localpet == 0) dummy2d = sfcdata%f10m
308
309 print*,"- CALL FieldScatter FOR INPUT F10M."
310 call esmf_fieldscatter(f10m_input_grid, dummy2d, rootpet=0, rc=rc)
311 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
312 call error_handler("IN FieldScatter", rc)
313
314 if (localpet == 0) dummy2d = sfcdata%uustar
315
316 print*,"- CALL FieldScatter FOR INPUT USTAR."
317 call esmf_fieldscatter(ustar_input_grid, dummy2d, rootpet=0, rc=rc)
318 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
319 call error_handler("IN FieldScatter", rc)
320
321 if (localpet == 0) dummy2d = sfcdata%ffmm
322
323 print*,"- CALL FieldScatter FOR INPUT FFMM."
324 call esmf_fieldscatter(ffmm_input_grid, dummy2d, rootpet=0, rc=rc)
325 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
326 call error_handler("IN FieldScatter", rc)
327
328 if (localpet == 0) dummy2d = sfcdata%srflag
329
330 print*,"- CALL FieldScatter FOR INPUT SRFLAG."
331 call esmf_fieldscatter(srflag_input_grid, dummy2d, rootpet=0, rc=rc)
332 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
333 call error_handler("IN FieldScatter", rc)
334
335 if (localpet == 0) dummy2d = sfcdata%tsea
336
337 print*,"- CALL FieldScatter FOR INPUT SKIN TEMP."
338 call esmf_fieldscatter(skin_temp_input_grid, dummy2d, rootpet=0, rc=rc)
339 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
340 call error_handler("IN FieldScatter", rc)
341
342 if (localpet == 0) dummy2d = nint(sfcdata%stype)
343
344 print*,"- CALL FieldScatter FOR INPUT SOIL TYPE."
345 call esmf_fieldscatter(soil_type_input_grid, dummy2d, rootpet=0, rc=rc)
346 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
347 call error_handler("IN FieldScatter", rc)
348
349 if (localpet == 0) dummy2d = sfcdata%orog
350
351 print*,"- CALL FieldScatter FOR INPUT TERRAIN."
352 call esmf_fieldscatter(terrain_input_grid, dummy2d, rootpet=0, rc=rc)
353 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
354 call error_handler("IN FieldScatter", rc)
355
356 if (localpet == 0) dummy3d = sfcdata%slc
357
358 print*,"- CALL FieldScatter FOR INPUT LIQUID SOIL MOISTURE."
359 call esmf_fieldscatter(soilm_liq_input_grid, dummy3d, rootpet=0, rc=rc)
360 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
361 call error_handler("IN FieldScatter", rc)
362
363 if (localpet == 0) dummy3d = sfcdata%smc
364
365 print*,"- CALL FieldScatter FOR INPUT TOTAL SOIL MOISTURE."
366 call esmf_fieldscatter(soilm_tot_input_grid, dummy3d, rootpet=0, rc=rc)
367 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
368 call error_handler("IN FieldScatter", rc)
369
370 if (localpet == 0) dummy3d = sfcdata%stc
371
372 print*,"- CALL FieldScatter FOR INPUT SOIL TEMPERATURE."
373 call esmf_fieldscatter(soil_temp_input_grid, dummy3d, rootpet=0, rc=rc)
374 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
375 call error_handler("IN FieldScatter", rc)
376
377 deallocate(dummy2d, dummy3d)
378 call sfcio_axdbta(sfcdata, iret)
379
380 call sfcio_sclose(23, iret)
381
382 end subroutine read_input_sfc_gfs_sfcio_file
383#endif
384
385#ifdef CHGRES_ALL
386
393 subroutine read_input_sfc_gfs_gaussian_nemsio_file(localpet)
394
395 implicit none
396
397 integer, intent(in) :: localpet
398
399 character(len=300) :: the_file
400
401 integer :: rc
402
403 real(nemsio_realkind), allocatable :: dummy(:)
404 real(esmf_kind_r8), allocatable :: dummy2d(:,:)
405 real(esmf_kind_r8), allocatable :: dummy3d(:,:,:)
406
407 type(nemsio_gfile) :: gfile
408
409 the_file = trim(data_dir_input_grid) // "/" // trim(sfc_files_input_grid(1))
410
411 if (localpet == 0) then
412 allocate(dummy3d(i_input,j_input,lsoil_input))
413 allocate(dummy2d(i_input,j_input))
414 allocate(dummy(i_input*j_input))
415 print*,"- OPEN FILE ", trim(the_file)
416 call nemsio_open(gfile, the_file, "read", iret=rc)
417 if (rc /= 0) call error_handler("OPENING FILE.", rc)
418 else
419 allocate(dummy3d(0,0,0))
420 allocate(dummy2d(0,0))
421 allocate(dummy(0))
422 endif
423
424 if (localpet == 0) then
425 print*,"- READ TERRAIN."
426 call nemsio_readrecv(gfile, "orog", "sfc", 1, dummy, 0, iret=rc)
427 if (rc /= 0) call error_handler("READING TERRAIN.", rc)
428 dummy2d = reshape(dummy, (/i_input,j_input/))
429 print*,'orog ',maxval(dummy2d),minval(dummy2d)
430 endif
431
432 print*,"- CALL FieldScatter FOR INPUT TERRAIN."
433 call esmf_fieldscatter(terrain_input_grid, dummy2d, rootpet=0, rc=rc)
434 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
435 call error_handler("IN FieldScatter", rc)
436
437 if (localpet == 0) then
438 print*,"- READ LANDSEA MASK."
439 call nemsio_readrecv(gfile, "land", "sfc", 1, dummy, 0, iret=rc)
440 if (rc /= 0) call error_handler("READING LANDSEA MASK.", rc)
441 dummy2d = reshape(dummy, (/i_input,j_input/))
442 print*,'landmask ',maxval(dummy2d),minval(dummy2d)
443 endif
444
445 print*,"- CALL FieldScatter FOR INPUT LANDSEA MASK."
446 call esmf_fieldscatter(landsea_mask_input_grid, dummy2d, rootpet=0, rc=rc)
447 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
448 call error_handler("IN FieldScatter", rc)
449
450 if (localpet == 0) then
451 print*,"- READ SEAICE FRACTION."
452 call nemsio_readrecv(gfile, "icec", "sfc", 1, dummy, 0, iret=rc)
453 if (rc /= 0) call error_handler("READING SEAICE FRACTION.", rc)
454 dummy2d = reshape(dummy, (/i_input,j_input/))
455 print*,'icec ',maxval(dummy2d),minval(dummy2d)
456 endif
457
458 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE FRACTION."
459 call esmf_fieldscatter(seaice_fract_input_grid, dummy2d, rootpet=0, rc=rc)
460 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
461 call error_handler("IN FieldScatter", rc)
462
463 if (localpet == 0) then
464 print*,"- READ SEAICE DEPTH."
465 call nemsio_readrecv(gfile, "icetk", "sfc", 1, dummy, 0, iret=rc)
466 if (rc /= 0) call error_handler("READING SEAICE DEPTH.", rc)
467 dummy2d = reshape(dummy, (/i_input,j_input/))
468 print*,'icetk ',maxval(dummy2d),minval(dummy2d)
469 endif
470
471 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE DEPTH."
472 call esmf_fieldscatter(seaice_depth_input_grid, dummy2d, rootpet=0, rc=rc)
473 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
474 call error_handler("IN FieldScatter", rc)
475
476 if (localpet == 0) then
477 print*,"- READ SEAICE SKIN TEMPERATURE."
478 call nemsio_readrecv(gfile, "tisfc", "sfc", 1, dummy, 0, iret=rc)
479 if (rc /= 0) call error_handler("READING SEAICE SKIN TEMP.", rc)
480 dummy2d = reshape(dummy, (/i_input,j_input/))
481 print*,'ti ',maxval(dummy2d),minval(dummy2d)
482 endif
483
484 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE SKIN TEMPERATURE."
485 call esmf_fieldscatter(seaice_skin_temp_input_grid, dummy2d, rootpet=0, rc=rc)
486 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
487 call error_handler("IN FieldScatter", rc)
488
489 if (localpet == 0) then
490 print*,"- READ SNOW LIQUID EQUIVALENT."
491 call nemsio_readrecv(gfile, "weasd", "sfc", 1, dummy, 0, iret=rc)
492 if (rc /= 0) call error_handler("READING SNOW LIQUID EQUIVALENT.", rc)
493 dummy2d = reshape(dummy, (/i_input,j_input/))
494 print*,'weasd ',maxval(dummy2d),minval(dummy2d)
495 endif
496
497 print*,"- CALL FieldScatter FOR INPUT GRID SNOW LIQUID EQUIVALENT."
498 call esmf_fieldscatter(snow_liq_equiv_input_grid, dummy2d, rootpet=0, rc=rc)
499 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
500 call error_handler("IN FieldScatter", rc)
501
502 if (localpet == 0) then
503 print*,"- READ SNOW DEPTH."
504 call nemsio_readrecv(gfile, "snod", "sfc", 1, dummy, 0, iret=rc)
505 if (rc /= 0) call error_handler("READING SNOW DEPTH.", rc)
506 dummy2d = reshape(dummy, (/i_input,j_input/))
507 print*,'snod ',maxval(dummy2d),minval(dummy2d)
508 endif
509
510 print*,"- CALL FieldScatter FOR INPUT GRID SNOW DEPTH."
511 call esmf_fieldscatter(snow_depth_input_grid, dummy2d, rootpet=0, rc=rc)
512 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
513 call error_handler("IN FieldScatter", rc)
514
515 if (localpet == 0) then
516 print*,"- READ VEG TYPE."
517 call nemsio_readrecv(gfile, "vtype", "sfc", 1, dummy, 0, iret=rc)
518 if (rc /= 0) call error_handler("READING VEG TYPE", rc)
519 dummy2d = reshape(dummy, (/i_input,j_input/))
520 print*,'vtype ',maxval(dummy2d),minval(dummy2d)
521 endif
522
523 print*,"- CALL FieldScatter FOR INPUT GRID VEG TYPE."
524 call esmf_fieldscatter(veg_type_input_grid, dummy2d, rootpet=0, rc=rc)
525 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
526 call error_handler("IN FieldScatter", rc)
527
528 if (localpet == 0) then
529 print*,"- READ SOIL TYPE."
530 call nemsio_readrecv(gfile, "sotyp", "sfc", 1, dummy, 0, iret=rc)
531 if (rc /= 0) call error_handler("READING SOIL TYPE.", rc)
532 dummy2d = reshape(dummy, (/i_input,j_input/))
533 print*,'sotype ',maxval(dummy2d),minval(dummy2d)
534 endif
535
536 print*,"- CALL FieldScatter FOR INPUT GRID SOIL TYPE."
537 call esmf_fieldscatter(soil_type_input_grid, dummy2d, rootpet=0, rc=rc)
538 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
539 call error_handler("IN FieldScatter", rc)
540
541 if (localpet == 0) then
542 print*,"- READ T2M."
543 call nemsio_readrecv(gfile, "tmp", "2 m above gnd", 1, dummy, 0, iret=rc)
544 if (rc /= 0) call error_handler("READING T2M.", rc)
545 dummy2d = reshape(dummy, (/i_input,j_input/))
546 print*,'t2m ',maxval(dummy2d),minval(dummy2d)
547 endif
548
549 print*,"- CALL FieldScatter FOR INPUT GRID T2M."
550 call esmf_fieldscatter(t2m_input_grid, dummy2d, rootpet=0, rc=rc)
551 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
552 call error_handler("IN FieldScatter", rc)
553
554 if (localpet == 0) then
555 print*,"- READ Q2M."
556 call nemsio_readrecv(gfile, "spfh", "2 m above gnd", 1, dummy, 0, iret=rc)
557 if (rc /= 0) call error_handler("READING Q2M.", rc)
558 dummy2d = reshape(dummy, (/i_input,j_input/))
559 print*,'q2m ',maxval(dummy2d),minval(dummy2d)
560 endif
561
562 print*,"- CALL FieldScatter FOR INPUT GRID Q2M."
563 call esmf_fieldscatter(q2m_input_grid, dummy2d, rootpet=0, rc=rc)
564 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
565 call error_handler("IN FieldScatter", rc)
566
567 if (localpet == 0) then
568 print*,"- READ TPRCP."
569 call nemsio_readrecv(gfile, "tprcp", "sfc", 1, dummy, 0, iret=rc)
570 if (rc /= 0) call error_handler("READING TPRCP.", rc)
571 dummy2d = reshape(dummy, (/i_input,j_input/))
572 print*,'tprcp ',maxval(dummy2d),minval(dummy2d)
573 endif
574
575 print*,"- CALL FieldScatter FOR INPUT GRID TPRCP."
576 call esmf_fieldscatter(tprcp_input_grid, dummy2d, rootpet=0, rc=rc)
577 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
578 call error_handler("IN FieldScatter", rc)
579
580 if (localpet == 0) then
581 print*,"- READ FFMM."
582 call nemsio_readrecv(gfile, "ffmm", "sfc", 1, dummy, 0, iret=rc)
583 if (rc /= 0) call error_handler("READING FFMM.", rc)
584 dummy2d = reshape(dummy, (/i_input,j_input/))
585 print*,'ffmm ',maxval(dummy2d),minval(dummy2d)
586 endif
587
588 print*,"- CALL FieldScatter FOR INPUT GRID FFMM"
589 call esmf_fieldscatter(ffmm_input_grid, dummy2d, rootpet=0, rc=rc)
590 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
591 call error_handler("IN FieldScatter", rc)
592
593 if (localpet == 0) then
594 print*,"- READ USTAR."
595 call nemsio_readrecv(gfile, "fricv", "sfc", 1, dummy, 0, iret=rc)
596 if (rc /= 0) call error_handler("READING USTAR.", rc)
597 dummy2d = reshape(dummy, (/i_input,j_input/))
598 print*,'fricv ',maxval(dummy2d),minval(dummy2d)
599 endif
600
601 print*,"- CALL FieldScatter FOR INPUT GRID USTAR"
602 call esmf_fieldscatter(ustar_input_grid, dummy2d, rootpet=0, rc=rc)
603 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
604 call error_handler("IN FieldScatter", rc)
605
606 if (localpet == 0) dummy2d = 0.0
607 print*,"- CALL FieldScatter FOR INPUT GRID SRFLAG"
608 call esmf_fieldscatter(srflag_input_grid, dummy2d, rootpet=0, rc=rc)
609 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
610 call error_handler("IN FieldScatter", rc)
611
612 if (localpet == 0) then
613 print*,"- READ SKIN TEMPERATURE."
614 call nemsio_readrecv(gfile, "tmp", "sfc", 1, dummy, 0, iret=rc)
615 if (rc /= 0) call error_handler("READING SKIN TEMPERATURE.", rc)
616 dummy2d = reshape(dummy, (/i_input,j_input/))
617 print*,'tmp ',maxval(dummy2d),minval(dummy2d)
618 endif
619
620 print*,"- CALL FieldScatter FOR INPUT GRID SKIN TEMPERATURE"
621 call esmf_fieldscatter(skin_temp_input_grid, dummy2d, rootpet=0, rc=rc)
622 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
623 call error_handler("IN FieldScatter", rc)
624
625 if (localpet == 0) then
626 print*,"- READ F10M."
627 call nemsio_readrecv(gfile, "f10m", "10 m above gnd", 1, dummy, 0, iret=rc)
628 if (rc /= 0) call error_handler("READING F10M.", rc)
629 dummy2d = reshape(dummy, (/i_input,j_input/))
630 print*,'f10m ',maxval(dummy2d),minval(dummy2d)
631 endif
632
633 print*,"- CALL FieldScatter FOR INPUT GRID F10M."
634 call esmf_fieldscatter(f10m_input_grid, dummy2d, rootpet=0, rc=rc)
635 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
636 call error_handler("IN FieldScatter", rc)
637
638 if (localpet == 0) then
639 print*,"- READ CANOPY MOISTURE CONTENT."
640 call nemsio_readrecv(gfile, "cnwat", "sfc", 1, dummy, 0, iret=rc)
641 if (rc /= 0) call error_handler("READING CANOPY MOISTURE CONTENT.", rc)
642 dummy2d = reshape(dummy, (/i_input,j_input/))
643 print*,'cnwat ',maxval(dummy2d),minval(dummy2d)
644 endif
645
646 print*,"- CALL FieldScatter FOR INPUT GRID CANOPY MOISTURE CONTENT."
647 call esmf_fieldscatter(canopy_mc_input_grid, dummy2d, rootpet=0, rc=rc)
648 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
649 call error_handler("IN FieldScatter", rc)
650
651 if (localpet == 0) then
652 print*,"- READ Z0."
653 call nemsio_readrecv(gfile, "sfcr", "sfc", 1, dummy, 0, iret=rc)
654 if (rc /= 0) call error_handler("READING Z0.", rc)
655 dummy2d = reshape(dummy, (/i_input,j_input/))
656 print*,'sfcr ',maxval(dummy2d),minval(dummy2d)
657 endif
658
659 print*,"- CALL FieldScatter FOR INPUT GRID Z0."
660 call esmf_fieldscatter(z0_input_grid, dummy2d, rootpet=0, rc=rc)
661 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
662 call error_handler("IN FieldScatter", rc)
663
664 deallocate(dummy2d)
665
666 if (localpet == 0) then
667 print*,"- READ LIQUID SOIL MOISTURE."
668 call nemsio_readrecv(gfile, "slc", "soil layer", 1, dummy, 0, iret=rc)
669 if (rc /= 0) call error_handler("READING LAYER 1 LIQUID SOIL MOIST.", rc)
670 dummy3d(:,:,1) = reshape(dummy, (/i_input,j_input/))
671 call nemsio_readrecv(gfile, "slc", "soil layer", 2, dummy, 0, iret=rc)
672 if (rc /= 0) call error_handler("READING LAYER 2 LIQUID SOIL MOIST.", rc)
673 dummy3d(:,:,2) = reshape(dummy, (/i_input,j_input/))
674 call nemsio_readrecv(gfile, "slc", "soil layer", 3, dummy, 0, iret=rc)
675 if (rc /= 0) call error_handler("READING LAYER 3 LIQUID SOIL MOIST.", rc)
676 dummy3d(:,:,3) = reshape(dummy, (/i_input,j_input/))
677 call nemsio_readrecv(gfile, "slc", "soil layer", 4, dummy, 0, iret=rc)
678 if (rc /= 0) call error_handler("READING LAYER 4 LIQUID SOIL MOIST.", rc)
679 dummy3d(:,:,4) = reshape(dummy, (/i_input,j_input/))
680 print*,'slc ',maxval(dummy3d),minval(dummy3d)
681 endif
682
683 print*,"- CALL FieldScatter FOR INPUT LIQUID SOIL MOISTURE."
684 call esmf_fieldscatter(soilm_liq_input_grid, dummy3d, rootpet=0, rc=rc)
685 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
686 call error_handler("IN FieldScatter", rc)
687
688 if (localpet == 0) then
689 print*,"- READ TOTAL SOIL MOISTURE."
690 call nemsio_readrecv(gfile, "smc", "soil layer", 1, dummy, 0, iret=rc)
691 if (rc /= 0) call error_handler("READING LAYER 1 TOTAL SOIL MOIST.", rc)
692 dummy3d(:,:,1) = reshape(dummy, (/i_input,j_input/))
693 call nemsio_readrecv(gfile, "smc", "soil layer", 2, dummy, 0, iret=rc)
694 if (rc /= 0) call error_handler("READING LAYER 2 TOTAL SOIL MOIST.", rc)
695 dummy3d(:,:,2) = reshape(dummy, (/i_input,j_input/))
696 call nemsio_readrecv(gfile, "smc", "soil layer", 3, dummy, 0, iret=rc)
697 if (rc /= 0) call error_handler("READING LAYER 3 TOTAL SOIL MOIST.", rc)
698 dummy3d(:,:,3) = reshape(dummy, (/i_input,j_input/))
699 call nemsio_readrecv(gfile, "smc", "soil layer", 4, dummy, 0, iret=rc)
700 if (rc /= 0) call error_handler("READING LAYER 4 TOTAL SOIL MOIST.", rc)
701 dummy3d(:,:,4) = reshape(dummy, (/i_input,j_input/))
702 print*,'smc ',maxval(dummy3d),minval(dummy3d)
703 endif
704
705 print*,"- CALL FieldScatter FOR INPUT TOTAL SOIL MOISTURE."
706 call esmf_fieldscatter(soilm_tot_input_grid, dummy3d, rootpet=0, rc=rc)
707 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
708 call error_handler("IN FieldScatter", rc)
709
710 if (localpet == 0) then
711 print*,"- READ SOIL TEMPERATURE."
712 call nemsio_readrecv(gfile, "stc", "soil layer", 1, dummy, 0, iret=rc)
713 if (rc /= 0) call error_handler("READING LAYER 1 SOIL TEMP.", rc)
714 dummy3d(:,:,1) = reshape(dummy, (/i_input,j_input/))
715 call nemsio_readrecv(gfile, "stc", "soil layer", 2, dummy, 0, iret=rc)
716 if (rc /= 0) call error_handler("READING LAYER 2 SOIL TEMP.", rc)
717 dummy3d(:,:,2) = reshape(dummy, (/i_input,j_input/))
718 call nemsio_readrecv(gfile, "stc", "soil layer", 3, dummy, 0, iret=rc)
719 if (rc /= 0) call error_handler("READING LAYER 3 SOIL TEMP.", rc)
720 dummy3d(:,:,3) = reshape(dummy, (/i_input,j_input/))
721 call nemsio_readrecv(gfile, "stc", "soil layer", 4, dummy, 0, iret=rc)
722 if (rc /= 0) call error_handler("READING LAYER 4 SOIL TEMP.", rc)
723 dummy3d(:,:,4) = reshape(dummy, (/i_input,j_input/))
724 print*,'stc ',maxval(dummy3d),minval(dummy3d)
725 endif
726
727 print*,"- CALL FieldScatter FOR INPUT SOIL TEMPERATURE."
728 call esmf_fieldscatter(soil_temp_input_grid, dummy3d, rootpet=0, rc=rc)
729 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
730 call error_handler("IN FieldScatter", rc)
731
732 deallocate(dummy3d, dummy)
733
734 if (localpet == 0) call nemsio_close(gfile)
735
736 end subroutine read_input_sfc_gfs_gaussian_nemsio_file
737#endif
738
739#ifdef CHGRES_ALL
740
744 subroutine read_input_sfc_gaussian_nemsio_file(localpet)
745
746 implicit none
747
748 integer, intent(in) :: localpet
749
750 character(len=250) :: the_file
751
752 integer :: rc
753
754 real(nemsio_realkind), allocatable :: dummy(:)
755 real(esmf_kind_r8), allocatable :: dummy2d(:,:)
756 real(esmf_kind_r8), allocatable :: dummy3d(:,:,:)
757
758 type(nemsio_gfile) :: gfile
759
760 the_file = trim(data_dir_input_grid) // "/" // trim(sfc_files_input_grid(1))
761
762 if (localpet == 0) then
763 allocate(dummy3d(i_input,j_input,lsoil_input))
764 allocate(dummy2d(i_input,j_input))
765 allocate(dummy(i_input*j_input))
766 print*,"- OPEN FILE ", trim(the_file)
767 call nemsio_open(gfile, the_file, "read", iret=rc)
768 if (rc /= 0) call error_handler("OPENING FILE.", rc)
769 else
770 allocate(dummy3d(0,0,0))
771 allocate(dummy2d(0,0))
772 allocate(dummy(0))
773 endif
774
775 if (localpet == 0) then
776 print*,"- READ TERRAIN."
777 call nemsio_readrecv(gfile, "orog", "sfc", 1, dummy, 0, iret=rc)
778 if (rc /= 0) call error_handler("READING TERRAIN.", rc)
779 dummy2d = reshape(dummy, (/i_input,j_input/))
780 print*,'orog ',maxval(dummy2d),minval(dummy2d)
781 endif
782
783 print*,"- CALL FieldScatter FOR INPUT TERRAIN."
784 call esmf_fieldscatter(terrain_input_grid, dummy2d, rootpet=0, rc=rc)
785 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
786 call error_handler("IN FieldScatter", rc)
787
788 if (localpet == 0) then
789 print*,"- READ LANDSEA MASK."
790 call nemsio_readrecv(gfile, "land", "sfc", 1, dummy, 0, iret=rc)
791 if (rc /= 0) call error_handler("READING LANDSEA MASK.", rc)
792 dummy2d = reshape(dummy, (/i_input,j_input/))
793 print*,'landmask ',maxval(dummy2d),minval(dummy2d)
794 endif
795
796 print*,"- CALL FieldScatter FOR INPUT LANDSEA MASK."
797 call esmf_fieldscatter(landsea_mask_input_grid, dummy2d, rootpet=0, rc=rc)
798 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
799 call error_handler("IN FieldScatter", rc)
800
801 if (localpet == 0) then
802 print*,"- READ SEAICE FRACTION."
803 call nemsio_readrecv(gfile, "icec", "sfc", 1, dummy, 0, iret=rc)
804 if (rc /= 0) call error_handler("READING SEAICE FRACTION.", rc)
805 dummy2d = reshape(dummy, (/i_input,j_input/))
806 print*,'icec ',maxval(dummy2d),minval(dummy2d)
807 endif
808
809 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE FRACTION."
810 call esmf_fieldscatter(seaice_fract_input_grid, dummy2d, rootpet=0, rc=rc)
811 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
812 call error_handler("IN FieldScatter", rc)
813
814 if (localpet == 0) then
815 print*,"- READ SEAICE DEPTH."
816 call nemsio_readrecv(gfile, "icetk", "sfc", 1, dummy, 0, iret=rc)
817 if (rc /= 0) call error_handler("READING SEAICE DEPTH.", rc)
818 dummy2d = reshape(dummy, (/i_input,j_input/))
819 print*,'icetk ',maxval(dummy2d),minval(dummy2d)
820 endif
821
822 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE DEPTH."
823 call esmf_fieldscatter(seaice_depth_input_grid, dummy2d, rootpet=0, rc=rc)
824 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
825 call error_handler("IN FieldScatter", rc)
826
827 if (localpet == 0) then
828 print*,"- READ SEAICE SKIN TEMPERATURE."
829 call nemsio_readrecv(gfile, "ti", "sfc", 1, dummy, 0, iret=rc)
830 if (rc /= 0) call error_handler("READING SEAICE SKIN TEMP.", rc)
831 dummy2d = reshape(dummy, (/i_input,j_input/))
832 print*,'ti ',maxval(dummy2d),minval(dummy2d)
833 endif
834
835 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE SKIN TEMPERATURE."
836 call esmf_fieldscatter(seaice_skin_temp_input_grid, dummy2d, rootpet=0, rc=rc)
837 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
838 call error_handler("IN FieldScatter", rc)
839
840 if (localpet == 0) then
841 print*,"- READ SNOW LIQUID EQUIVALENT."
842 call nemsio_readrecv(gfile, "weasd", "sfc", 1, dummy, 0, iret=rc)
843 if (rc /= 0) call error_handler("READING SNOW LIQUID EQUIVALENT.", rc)
844 dummy2d = reshape(dummy, (/i_input,j_input/))
845 print*,'weasd ',maxval(dummy2d),minval(dummy2d)
846 endif
847
848 print*,"- CALL FieldScatter FOR INPUT GRID SNOW LIQUID EQUIVALENT."
849 call esmf_fieldscatter(snow_liq_equiv_input_grid, dummy2d, rootpet=0, rc=rc)
850 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
851 call error_handler("IN FieldScatter", rc)
852
853 if (localpet == 0) then
854 print*,"- READ SNOW DEPTH."
855 call nemsio_readrecv(gfile, "snod", "sfc", 1, dummy, 0, iret=rc)
856 if (rc /= 0) call error_handler("READING SNOW DEPTH.", rc)
857 dummy2d = reshape(dummy, (/i_input,j_input/)) * 1000.0_8
858 print*,'snod ',maxval(dummy2d),minval(dummy2d)
859 endif
860
861 print*,"- CALL FieldScatter FOR INPUT GRID SNOW DEPTH."
862 call esmf_fieldscatter(snow_depth_input_grid, dummy2d, rootpet=0, rc=rc)
863 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
864 call error_handler("IN FieldScatter", rc)
865
866 if (localpet == 0) then
867 print*,"- READ VEG TYPE."
868 call nemsio_readrecv(gfile, "vtype", "sfc", 1, dummy, 0, iret=rc)
869 if (rc /= 0) call error_handler("READING VEG TYPE", rc)
870 dummy2d = reshape(dummy, (/i_input,j_input/))
871 print*,'vtype ',maxval(dummy2d),minval(dummy2d)
872 endif
873
874 print*,"- CALL FieldScatter FOR INPUT GRID VEG TYPE."
875 call esmf_fieldscatter(veg_type_input_grid, dummy2d, rootpet=0, rc=rc)
876 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
877 call error_handler("IN FieldScatter", rc)
878
879 if (localpet == 0) then
880 print*,"- READ SOIL TYPE."
881 call nemsio_readrecv(gfile, "sotyp", "sfc", 1, dummy, 0, iret=rc)
882 if (rc /= 0) call error_handler("READING SOIL TYPE.", rc)
883 dummy2d = reshape(dummy, (/i_input,j_input/))
884 print*,'sotype ',maxval(dummy2d),minval(dummy2d)
885 endif
886
887 print*,"- CALL FieldScatter FOR INPUT GRID SOIL TYPE."
888 call esmf_fieldscatter(soil_type_input_grid, dummy2d, rootpet=0, rc=rc)
889 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
890 call error_handler("IN FieldScatter", rc)
891
892 if (localpet == 0) then
893 print*,"- READ T2M."
894 call nemsio_readrecv(gfile, "tmp", "2 m above gnd", 1, dummy, 0, iret=rc)
895 if (rc /= 0) call error_handler("READING T2M.", rc)
896 dummy2d = reshape(dummy, (/i_input,j_input/))
897 print*,'t2m ',maxval(dummy2d),minval(dummy2d)
898 endif
899
900 print*,"- CALL FieldScatter FOR INPUT GRID T2M."
901 call esmf_fieldscatter(t2m_input_grid, dummy2d, rootpet=0, rc=rc)
902 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
903 call error_handler("IN FieldScatter", rc)
904
905 if (localpet == 0) then
906 print*,"- READ Q2M."
907 call nemsio_readrecv(gfile, "spfh", "2 m above gnd", 1, dummy, 0, iret=rc)
908 if (rc /= 0) call error_handler("READING Q2M.", rc)
909 dummy2d = reshape(dummy, (/i_input,j_input/))
910 print*,'q2m ',maxval(dummy2d),minval(dummy2d)
911 endif
912
913 print*,"- CALL FieldScatter FOR INPUT GRID Q2M."
914 call esmf_fieldscatter(q2m_input_grid, dummy2d, rootpet=0, rc=rc)
915 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
916 call error_handler("IN FieldScatter", rc)
917
918 if (localpet == 0) then
919 print*,"- READ TPRCP."
920 call nemsio_readrecv(gfile, "tprcp", "sfc", 1, dummy, 0, iret=rc)
921 if (rc /= 0) call error_handler("READING TPRCP.", rc)
922 dummy2d = reshape(dummy, (/i_input,j_input/))
923 print*,'tprcp ',maxval(dummy2d),minval(dummy2d)
924 endif
925
926 print*,"- CALL FieldScatter FOR INPUT GRID TPRCP."
927 call esmf_fieldscatter(tprcp_input_grid, dummy2d, rootpet=0, rc=rc)
928 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
929 call error_handler("IN FieldScatter", rc)
930
931 if (localpet == 0) then
932 print*,"- READ FFMM."
933 call nemsio_readrecv(gfile, "ffmm", "sfc", 1, dummy, 0, iret=rc)
934 if (rc /= 0) call error_handler("READING FFMM.", rc)
935 dummy2d = reshape(dummy, (/i_input,j_input/))
936 print*,'ffmm ',maxval(dummy2d),minval(dummy2d)
937 endif
938
939 print*,"- CALL FieldScatter FOR INPUT GRID FFMM"
940 call esmf_fieldscatter(ffmm_input_grid, dummy2d, rootpet=0, rc=rc)
941 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
942 call error_handler("IN FieldScatter", rc)
943
944 if (localpet == 0) then
945 print*,"- READ USTAR."
946 call nemsio_readrecv(gfile, "fricv", "sfc", 1, dummy, 0, iret=rc)
947 if (rc /= 0) call error_handler("READING USTAR.", rc)
948 dummy2d = reshape(dummy, (/i_input,j_input/))
949 print*,'fricv ',maxval(dummy2d),minval(dummy2d)
950 endif
951
952 print*,"- CALL FieldScatter FOR INPUT GRID USTAR"
953 call esmf_fieldscatter(ustar_input_grid, dummy2d, rootpet=0, rc=rc)
954 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
955 call error_handler("IN FieldScatter", rc)
956
957 if (localpet == 0) dummy2d = 0.0
958 print*,"- CALL FieldScatter FOR INPUT GRID SRFLAG"
959 call esmf_fieldscatter(srflag_input_grid, dummy2d, rootpet=0, rc=rc)
960 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
961 call error_handler("IN FieldScatter", rc)
962
963 if (localpet == 0) then
964 print*,"- READ SKIN TEMPERATURE."
965 call nemsio_readrecv(gfile, "tmp", "sfc", 1, dummy, 0, iret=rc)
966 if (rc /= 0) call error_handler("READING SKIN TEMPERATURE.", rc)
967 dummy2d = reshape(dummy, (/i_input,j_input/))
968 print*,'tmp ',maxval(dummy2d),minval(dummy2d)
969 endif
970
971 print*,"- CALL FieldScatter FOR INPUT GRID SKIN TEMPERATURE"
972 call esmf_fieldscatter(skin_temp_input_grid, dummy2d, rootpet=0, rc=rc)
973 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
974 call error_handler("IN FieldScatter", rc)
975
976 if (localpet == 0) then
977 print*,"- READ F10M."
978 call nemsio_readrecv(gfile, "f10m", "10 m above gnd", 1, dummy, 0, iret=rc)
979 if (rc /= 0) call error_handler("READING F10M.", rc)
980 dummy2d = reshape(dummy, (/i_input,j_input/))
981 print*,'f10m ',maxval(dummy2d),minval(dummy2d)
982 endif
983
984 print*,"- CALL FieldScatter FOR INPUT GRID F10M."
985 call esmf_fieldscatter(f10m_input_grid, dummy2d, rootpet=0, rc=rc)
986 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
987 call error_handler("IN FieldScatter", rc)
988
989 if (localpet == 0) then
990 print*,"- READ CANOPY MOISTURE CONTENT."
991 call nemsio_readrecv(gfile, "cnwat", "sfc", 1, dummy, 0, iret=rc)
992 if (rc /= 0) call error_handler("READING CANOPY MOISTURE CONTENT.", rc)
993 dummy2d = reshape(dummy, (/i_input,j_input/))
994 print*,'cnwat ',maxval(dummy2d),minval(dummy2d)
995 endif
996
997 print*,"- CALL FieldScatter FOR INPUT GRID CANOPY MOISTURE CONTENT."
998 call esmf_fieldscatter(canopy_mc_input_grid, dummy2d, rootpet=0, rc=rc)
999 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1000 call error_handler("IN FieldScatter", rc)
1001
1002 if (localpet == 0) then
1003 print*,"- READ Z0."
1004 call nemsio_readrecv(gfile, "sfcr", "sfc", 1, dummy, 0, iret=rc)
1005 if (rc /= 0) call error_handler("READING Z0.", rc)
1006 dummy2d = reshape(dummy, (/i_input,j_input/)) * 100.0_8 ! convert to cm
1007 print*,'sfcr ',maxval(dummy2d),minval(dummy2d)
1008 endif
1009
1010 print*,"- CALL FieldScatter FOR INPUT GRID Z0."
1011 call esmf_fieldscatter(z0_input_grid, dummy2d, rootpet=0, rc=rc)
1012 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1013 call error_handler("IN FieldScatter", rc)
1014
1015 deallocate(dummy2d)
1016
1017 if (localpet == 0) then
1018 print*,"- READ LIQUID SOIL MOISTURE."
1019 call nemsio_readrecv(gfile, "soill", "0-10 cm down", 1, dummy, 0, iret=rc)
1020 if (rc /= 0) call error_handler("READING LAYER 1 LIQUID SOIL MOIST.", rc)
1021 dummy3d(:,:,1) = reshape(dummy, (/i_input,j_input/))
1022 call nemsio_readrecv(gfile, "soill", "10-40 cm down", 1, dummy, 0, iret=rc)
1023 if (rc /= 0) call error_handler("READING LAYER 2 LIQUID SOIL MOIST.", rc)
1024 dummy3d(:,:,2) = reshape(dummy, (/i_input,j_input/))
1025 call nemsio_readrecv(gfile, "soill", "40-100 cm down", 1, dummy, 0, iret=rc)
1026 if (rc /= 0) call error_handler("READING LAYER 3 LIQUID SOIL MOIST.", rc)
1027 dummy3d(:,:,3) = reshape(dummy, (/i_input,j_input/))
1028 call nemsio_readrecv(gfile, "soill", "100-200 cm down", 1, dummy, 0, iret=rc)
1029 if (rc /= 0) call error_handler("READING LAYER 4 LIQUID SOIL MOIST.", rc)
1030 dummy3d(:,:,4) = reshape(dummy, (/i_input,j_input/))
1031 print*,'soill ',maxval(dummy3d),minval(dummy3d)
1032 endif
1033
1034 print*,"- CALL FieldScatter FOR INPUT LIQUID SOIL MOISTURE."
1035 call esmf_fieldscatter(soilm_liq_input_grid, dummy3d, rootpet=0, rc=rc)
1036 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1037 call error_handler("IN FieldScatter", rc)
1038
1039 if (localpet == 0) then
1040 print*,"- READ TOTAL SOIL MOISTURE."
1041 call nemsio_readrecv(gfile, "soilw", "0-10 cm down", 1, dummy, 0, iret=rc)
1042 if (rc /= 0) call error_handler("READING LAYER 1 TOTAL SOIL MOIST.", rc)
1043 dummy3d(:,:,1) = reshape(dummy, (/i_input,j_input/))
1044 call nemsio_readrecv(gfile, "soilw", "10-40 cm down", 1, dummy, 0, iret=rc)
1045 if (rc /= 0) call error_handler("READING LAYER 2 TOTAL SOIL MOIST.", rc)
1046 dummy3d(:,:,2) = reshape(dummy, (/i_input,j_input/))
1047 call nemsio_readrecv(gfile, "soilw", "40-100 cm down", 1, dummy, 0, iret=rc)
1048 if (rc /= 0) call error_handler("READING LAYER 3 TOTAL SOIL MOIST.", rc)
1049 dummy3d(:,:,3) = reshape(dummy, (/i_input,j_input/))
1050 call nemsio_readrecv(gfile, "soilw", "100-200 cm down", 1, dummy, 0, iret=rc)
1051 if (rc /= 0) call error_handler("READING LAYER 4 TOTAL SOIL MOIST.", rc)
1052 dummy3d(:,:,4) = reshape(dummy, (/i_input,j_input/))
1053 print*,'soilm ',maxval(dummy3d),minval(dummy3d)
1054 endif
1055
1056 print*,"- CALL FieldScatter FOR INPUT TOTAL SOIL MOISTURE."
1057 call esmf_fieldscatter(soilm_tot_input_grid, dummy3d, rootpet=0, rc=rc)
1058 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1059 call error_handler("IN FieldScatter", rc)
1060
1061 if (localpet == 0) then
1062 print*,"- READ SOIL TEMPERATURE."
1063 call nemsio_readrecv(gfile, "tmp", "0-10 cm down", 1, dummy, 0, iret=rc)
1064 if (rc /= 0) call error_handler("READING LAYER 1 SOIL TEMP.", rc)
1065 dummy3d(:,:,1) = reshape(dummy, (/i_input,j_input/))
1066 call nemsio_readrecv(gfile, "tmp", "10-40 cm down", 1, dummy, 0, iret=rc)
1067 if (rc /= 0) call error_handler("READING LAYER 2 SOIL TEMP.", rc)
1068 dummy3d(:,:,2) = reshape(dummy, (/i_input,j_input/))
1069 call nemsio_readrecv(gfile, "tmp", "40-100 cm down", 1, dummy, 0, iret=rc)
1070 if (rc /= 0) call error_handler("READING LAYER 3 SOIL TEMP.", rc)
1071 dummy3d(:,:,3) = reshape(dummy, (/i_input,j_input/))
1072 call nemsio_readrecv(gfile, "tmp", "100-200 cm down", 1, dummy, 0, iret=rc)
1073 if (rc /= 0) call error_handler("READING LAYER 4 SOIL TEMP.", rc)
1074 dummy3d(:,:,4) = reshape(dummy, (/i_input,j_input/))
1075 print*,'soilt ',maxval(dummy3d),minval(dummy3d)
1076 endif
1077
1078 print*,"- CALL FieldScatter FOR INPUT SOIL TEMPERATURE."
1079 call esmf_fieldscatter(soil_temp_input_grid, dummy3d, rootpet=0, rc=rc)
1080 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1081 call error_handler("IN FieldScatter", rc)
1082
1083 deallocate(dummy3d, dummy)
1084
1085 if (localpet == 0) call nemsio_close(gfile)
1086
1087 end subroutine read_input_sfc_gaussian_nemsio_file
1088#endif
1089
1094 subroutine read_input_sfc_restart_file(localpet)
1095
1096 implicit none
1097
1098 integer, intent(in) :: localpet
1099
1100 character(len=500) :: tilefile
1101
1102 integer :: error, rc
1103 integer :: id_dim, idim_input, jdim_input
1104 integer :: ncid, tile, id_var, id_var1, id_var2, idum(2)
1105
1106 real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
1107 real(esmf_kind_r8), allocatable :: land_frac_one_tile(:,:), vtype_one_tile(:,:)
1108 real(esmf_kind_r4), allocatable :: slmsk_orog_one_tile(:,:)
1109 real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)
1110
1111 type(esmf_vm) :: vm
1112 logical :: condition1_met, condition2_met
1113!------------------------------------------------------------------------------------------
1114! Get i/j dimensions and number of soil layers from first surface file.
1115! Do dimensions match those from the orography file?
1116! Do land/sea masks (i.e., ocean res. and orog version) match those from the orography file?
1117!------------------------------------------------------------------------------------------
1118
1119 print*,"- CALL VMGetGlobal"
1120 call esmf_vmgetglobal(vm, rc=rc)
1121 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1122 call error_handler("IN VMGetGlobal", rc)
1123
1124 tilefile = trim(data_dir_input_grid) // "/" // trim(sfc_files_input_grid(1))
1125
1126 if (localpet == 0) then
1127 print*,"- READ GRID DIMENSIONS FROM: ", trim(tilefile)
1128 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
1129 call netcdf_err(error, 'opening: '//trim(tilefile) )
1130
1131 error=nf90_inq_dimid(ncid, 'xaxis_1', id_dim)
1132 call netcdf_err(error, 'reading xaxis_1 id' )
1133 error=nf90_inquire_dimension(ncid,id_dim,len=idum(1))
1134 call netcdf_err(error, 'reading xaxis_1 value' )
1135
1136 error=nf90_inq_dimid(ncid, 'yaxis_1', id_dim)
1137 call netcdf_err(error, 'reading yaxis_1 id' )
1138 error=nf90_inquire_dimension(ncid,id_dim,len=idum(2))
1139 call netcdf_err(error, 'reading yaxis_1 value' )
1140
1141 error = nf90_close(ncid)
1142 endif
1143
1144 call esmf_vmbroadcast(vm, idum, 2, 0, rc=rc)
1145 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1146 call error_handler("IN VMBroadcast", rc)
1147
1148 idim_input=idum(1)
1149 jdim_input=idum(2)
1150
1151 if (idim_input /= i_input .or. jdim_input /= j_input) then
1152 call error_handler("DIMENSION MISMATCH BETWEEN SFC AND OROG FILES.", 1)
1153 endif
1154
1155 if (localpet == 0) then
1156 allocate(data_one_tile(idim_input,jdim_input))
1157 allocate(land_frac_one_tile(idim_input,jdim_input))
1158 allocate(slmsk_orog_one_tile(idim_input,jdim_input))
1159 allocate(vtype_one_tile(idim_input,jdim_input))
1160 allocate(data_one_tile_3d(idim_input,jdim_input,lsoil_input))
1161 else
1162 allocate(data_one_tile(0,0))
1163 allocate(land_frac_one_tile(0,0))
1164 allocate(slmsk_orog_one_tile(0,0))
1165 allocate(vtype_one_tile(0,0))
1166 allocate(data_one_tile_3d(0,0,0))
1167 endif
1168
1169 terrain_loop: do tile = 1, num_tiles_input_grid
1170
1171 if (localpet == 0) then
1172 tilefile = trim(orog_dir_input_grid) // trim(orog_files_input_grid(tile))
1173 print*,'- OPEN OROGRAPHY FILE: ', trim(tilefile)
1174 error=nf90_open(tilefile,nf90_nowrite,ncid)
1175 call netcdf_err(error, 'OPENING OROGRAPHY FILE' )
1176 error=nf90_inq_varid(ncid, 'orog_raw', id_var)
1177 call netcdf_err(error, 'READING OROG RECORD ID' )
1178 error=nf90_inq_varid(ncid, 'land_frac', id_var1)
1179 call netcdf_err(error, 'READING OROG LAND_FRAC ID' )
1180 error=nf90_inq_varid(ncid, 'slmsk', id_var2)
1181 call netcdf_err(error, 'READING OROG SLMSK ID' )
1182 error=nf90_get_var(ncid, id_var, data_one_tile)
1183 call netcdf_err(error, 'READING OROG RECORD' )
1184 error=nf90_get_var(ncid, id_var1, land_frac_one_tile)
1185 call netcdf_err(error, 'READING OROG LAND_FRAC' )
1186 error=nf90_get_var(ncid, id_var2, slmsk_orog_one_tile)
1187 call netcdf_err(error, 'READING OROG SLMSK' )
1188 print*,'terrain check ',tile, maxval(data_one_tile)
1189 error=nf90_close(ncid)
1190
1191 ! A consistent non-fractional grid, will meet condition1
1192 ! A consistent fractional grid, will meet condition2
1193 call read_fv3_grid_data_netcdf('vtype', tile, idim_input, jdim_input, &
1194 lsoil_input, sfcdata=vtype_one_tile)
1195
1196 condition1_met = all(((nint(vtype_one_tile) > 0) .and. (nint(slmsk_orog_one_tile) == 1)) .or. ((nint(vtype_one_tile) <= 0) .and. (nint(slmsk_orog_one_tile) == 0)))
1197 condition2_met = all(((land_frac_one_tile > 0.) .and. (nint(vtype_one_tile) > 0)) .or. ((land_frac_one_tile == 0.) .and. (nint(vtype_one_tile)<= 0)))
1198
1199 if (condition1_met) then
1200 print*,'[Non-fractional grid]: mask check ',tile,': consistent!'
1201 endif
1202 if (condition2_met) then
1203 print*,'[Fractional grid]: mask check ',tile,': consistent!'
1204 endif
1205
1206 if ((.not. condition1_met) .and. (.not. condition2_met)) then
1207 call error_handler("INCONSISTENT LAND/SEA MASK BETWEEN RESTART AND OROG FILES.", 10)
1208 endif
1209
1210 endif
1211
1212 print*,"- CALL FieldScatter FOR INPUT TERRAIN."
1213 call esmf_fieldscatter(terrain_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1214 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1215 call error_handler("IN FieldScatter", rc)
1216
1217 enddo terrain_loop
1218
1219 tile_loop : do tile = 1, num_tiles_input_grid
1220
1221! liquid soil moisture
1222
1223 if (localpet == 0) then
1224 call read_fv3_grid_data_netcdf('slc', tile, idim_input, jdim_input, &
1225 lsoil_input, sfcdata_3d=data_one_tile_3d)
1226 endif
1227
1228 print*,"- CALL FieldScatter FOR INPUT LIQUID SOIL MOISTURE."
1229 call esmf_fieldscatter(soilm_liq_input_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
1230 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1231 call error_handler("IN FieldScatter", rc)
1232
1233 if (localpet == 0) then
1234 call read_fv3_grid_data_netcdf('smc', tile, idim_input, jdim_input, &
1235 lsoil_input, sfcdata_3d=data_one_tile_3d)
1236 endif
1237
1238 print*,"- CALL FieldScatter FOR INPUT TOTAL SOIL MOISTURE."
1239 call esmf_fieldscatter(soilm_tot_input_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
1240 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1241 call error_handler("IN FieldScatter", rc)
1242
1243 if (localpet == 0) then
1244 call read_fv3_grid_data_netcdf('stc', tile, idim_input, jdim_input, &
1245 lsoil_input, sfcdata_3d=data_one_tile_3d)
1246 endif
1247
1248 print*,"- CALL FieldScatter FOR INPUT SOIL TEMPERATURE."
1249 call esmf_fieldscatter(soil_temp_input_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
1250 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1251 call error_handler("IN FieldScatter", rc)
1252
1253! land mask
1254
1255 if (localpet == 0) then
1256 call read_fv3_grid_data_netcdf('slmsk', tile, idim_input, jdim_input, &
1257 lsoil_input, sfcdata=data_one_tile)
1258 endif
1259
1260 print*,"- CALL FieldScatter FOR INPUT LANDSEA MASK."
1261 call esmf_fieldscatter(landsea_mask_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1262 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1263 call error_handler("IN FieldScatter", rc)
1264
1265! sea ice fraction
1266
1267 if (localpet == 0) then
1268 call read_fv3_grid_data_netcdf('fice', tile, idim_input, jdim_input, &
1269 lsoil_input, sfcdata=data_one_tile)
1270 endif
1271
1272 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE FRACTION."
1273 call esmf_fieldscatter(seaice_fract_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1274 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1275 call error_handler("IN FieldScatter", rc)
1276
1277! sea ice depth
1278
1279 if (localpet == 0) then
1280 call read_fv3_grid_data_netcdf('hice', tile, idim_input, jdim_input, &
1281 lsoil_input, sfcdata=data_one_tile)
1282 endif
1283
1284 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE DEPTH."
1285 call esmf_fieldscatter(seaice_depth_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1286 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1287 call error_handler("IN FieldScatter", rc)
1288
1289! sea ice skin temperature
1290
1291 if (localpet == 0) then
1292 call read_fv3_grid_data_netcdf('tisfc', tile, idim_input, jdim_input, &
1293 lsoil_input, sfcdata=data_one_tile)
1294 endif
1295
1296 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE SKIN TEMPERATURE."
1297 call esmf_fieldscatter(seaice_skin_temp_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1298 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1299 call error_handler("IN FieldScatter", rc)
1300
1301! liquid equivalent snow depth
1302
1303 if (localpet == 0) then
1304 call read_fv3_grid_data_netcdf('sheleg', tile, idim_input, jdim_input, &
1305 lsoil_input, sfcdata=data_one_tile)
1306 endif
1307
1308 print*,"- CALL FieldScatter FOR INPUT GRID SNOW LIQUID EQUIVALENT."
1309 call esmf_fieldscatter(snow_liq_equiv_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1310 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1311 call error_handler("IN FieldScatter", rc)
1312
1313! physical snow depth
1314
1315 if (localpet == 0) then
1316 call read_fv3_grid_data_netcdf('snwdph', tile, idim_input, jdim_input, &
1317 lsoil_input, sfcdata=data_one_tile)
1318 data_one_tile = data_one_tile
1319 endif
1320
1321 print*,"- CALL FieldScatter FOR INPUT GRID SNOW DEPTH."
1322 call esmf_fieldscatter(snow_depth_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1323 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1324 call error_handler("IN FieldScatter", rc)
1325
1326! Vegetation type
1327
1328 if (localpet == 0) then
1329 call read_fv3_grid_data_netcdf('vtype', tile, idim_input, jdim_input, &
1330 lsoil_input, sfcdata=data_one_tile)
1331 endif
1332
1333 print*,"- CALL FieldScatter FOR INPUT GRID VEG TYPE."
1334 call esmf_fieldscatter(veg_type_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1335 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1336 call error_handler("IN FieldScatter", rc)
1337
1338! Soil type
1339
1340 if (localpet == 0) then
1341 call read_fv3_grid_data_netcdf('stype', tile, idim_input, jdim_input, &
1342 lsoil_input, sfcdata=data_one_tile)
1343 endif
1344
1345 print*,"- CALL FieldScatter FOR INPUT GRID SOIL TYPE."
1346 call esmf_fieldscatter(soil_type_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1347 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1348 call error_handler("IN FieldScatter", rc)
1349
1350! Two-meter temperature
1351
1352 if (localpet == 0) then
1353 call read_fv3_grid_data_netcdf('t2m', tile, idim_input, jdim_input, &
1354 lsoil_input, sfcdata=data_one_tile)
1355 endif
1356
1357 print*,"- CALL FieldScatter FOR INPUT GRID T2M."
1358 call esmf_fieldscatter(t2m_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1359 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1360 call error_handler("IN FieldScatter", rc)
1361
1362! Two-meter q
1363
1364 if (localpet == 0) then
1365 call read_fv3_grid_data_netcdf('q2m', tile, idim_input, jdim_input, &
1366 lsoil_input, sfcdata=data_one_tile)
1367 endif
1368
1369 print*,"- CALL FieldScatter FOR INPUT GRID Q2M."
1370 call esmf_fieldscatter(q2m_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1371 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1372 call error_handler("IN FieldScatter", rc)
1373
1374 if (localpet == 0) then
1375 call read_fv3_grid_data_netcdf('tprcp', tile, idim_input, jdim_input, &
1376 lsoil_input, sfcdata=data_one_tile)
1377 endif
1378
1379 print*,"- CALL FieldScatter FOR INPUT GRID TPRCP."
1380 call esmf_fieldscatter(tprcp_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1381 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1382 call error_handler("IN FieldScatter", rc)
1383
1384 if (localpet == 0) then
1385 call read_fv3_grid_data_netcdf('f10m', tile, idim_input, jdim_input, &
1386 lsoil_input, sfcdata=data_one_tile)
1387 endif
1388
1389 print*,"- CALL FieldScatter FOR INPUT GRID F10M"
1390 call esmf_fieldscatter(f10m_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1391 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1392 call error_handler("IN FieldScatter", rc)
1393
1394 if (localpet == 0) then
1395 call read_fv3_grid_data_netcdf('ffmm', tile, idim_input, jdim_input, &
1396 lsoil_input, sfcdata=data_one_tile)
1397 endif
1398
1399 print*,"- CALL FieldScatter FOR INPUT GRID FFMM"
1400 call esmf_fieldscatter(ffmm_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1401 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1402 call error_handler("IN FieldScatter", rc)
1403
1404 if (localpet == 0) then
1405 call read_fv3_grid_data_netcdf('uustar', tile, idim_input, jdim_input, &
1406 lsoil_input, sfcdata=data_one_tile)
1407 endif
1408
1409 print*,"- CALL FieldScatter FOR INPUT GRID USTAR"
1410 call esmf_fieldscatter(ustar_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1411 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1412 call error_handler("IN FieldScatter", rc)
1413
1414 if (localpet == 0) then
1415 call read_fv3_grid_data_netcdf('srflag', tile, idim_input, jdim_input, &
1416 lsoil_input, sfcdata=data_one_tile)
1417 endif
1418
1419 print*,"- CALL FieldScatter FOR INPUT GRID SRFLAG"
1420 call esmf_fieldscatter(srflag_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1421 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1422 call error_handler("IN FieldScatter", rc)
1423
1424 if (localpet == 0) then
1425 call read_fv3_grid_data_netcdf('tsea', tile, idim_input, jdim_input, &
1426 lsoil_input, sfcdata=data_one_tile)
1427 endif
1428
1429 print*,"- CALL FieldScatter FOR INPUT GRID SKIN TEMPERATURE"
1430 call esmf_fieldscatter(skin_temp_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1431 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1432 call error_handler("IN FieldScatter", rc)
1433
1434 if (localpet == 0) then
1435 call read_fv3_grid_data_netcdf('canopy', tile, idim_input, jdim_input, &
1436 lsoil_input, sfcdata=data_one_tile)
1437 endif
1438
1439 print*,"- CALL FieldScatter FOR INPUT GRID CANOPY MOISTURE CONTENT."
1440 call esmf_fieldscatter(canopy_mc_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1441 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1442 call error_handler("IN FieldScatter", rc)
1443
1444 if (localpet == 0) then
1445 call read_fv3_grid_data_netcdf('zorl', tile, idim_input, jdim_input, &
1446 lsoil_input, sfcdata=data_one_tile)
1447 endif
1448
1449 print*,"- CALL FieldScatter FOR INPUT GRID Z0."
1450 call esmf_fieldscatter(z0_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1451 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1452 call error_handler("IN FieldScatter", rc)
1453
1454 enddo tile_loop
1455
1456 deallocate(data_one_tile, data_one_tile_3d)
1457 deallocate(vtype_one_tile, land_frac_one_tile, slmsk_orog_one_tile)
1458
1459 end subroutine read_input_sfc_restart_file
1460
1466 subroutine read_input_sfc_netcdf_file(localpet)
1467
1468 implicit none
1469
1470 integer, intent(in) :: localpet
1471
1472 character(len=500) :: tilefile
1473
1474 integer :: error, id_var
1475 integer :: id_dim, idim_input, jdim_input
1476 integer :: ncid, rc, tile, idum(2)
1477
1478 real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
1479 real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)
1480
1481 type(esmf_vm) :: vm
1482
1483!---------------------------------------------------------------------------
1484! Get i/j dimensions and number of soil layers from first surface file.
1485! Do dimensions match those from the orography file?
1486!---------------------------------------------------------------------------
1487
1488 print*,"- CALL VMGetGlobal"
1489 call esmf_vmgetglobal(vm, rc=rc)
1490 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1491 call error_handler("IN VMGetGlobal", rc)
1492
1493 tilefile = trim(data_dir_input_grid) // "/" // trim(sfc_files_input_grid(1))
1494
1495 if (localpet == 0) then
1496 print*,"- READ GRID DIMENSIONS FROM: ", trim(tilefile)
1497 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
1498 call netcdf_err(error, 'opening: '//trim(tilefile) )
1499
1500 error=nf90_inq_dimid(ncid, 'grid_xt', id_dim)
1501 call netcdf_err(error, 'reading grid_xt id' )
1502 error=nf90_inquire_dimension(ncid,id_dim,len=idum(1))
1503 call netcdf_err(error, 'reading grid_xt value' )
1504
1505 error=nf90_inq_dimid(ncid, 'grid_yt', id_dim)
1506 call netcdf_err(error, 'reading grid_yt id' )
1507 error=nf90_inquire_dimension(ncid,id_dim,len=idum(2))
1508 call netcdf_err(error, 'reading grid_yt value' )
1509
1510 error = nf90_close(ncid)
1511 endif
1512
1513 call esmf_vmbroadcast(vm, idum, 2, 0, rc=rc)
1514 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1515 call error_handler("IN VMBroadcast", rc)
1516
1517 idim_input=idum(1)
1518 jdim_input=idum(2)
1519
1520 if (idim_input /= i_input .or. jdim_input /= j_input) then
1521 call error_handler("DIMENSION MISMATCH BETWEEN SFC AND OROG FILES.", 3)
1522 endif
1523
1524 if (localpet == 0) then
1525 allocate(data_one_tile(idim_input,jdim_input))
1526 allocate(data_one_tile_3d(idim_input,jdim_input,lsoil_input))
1527 else
1528 allocate(data_one_tile(0,0))
1529 allocate(data_one_tile_3d(0,0,0))
1530 endif
1531
1532 terrain_loop: do tile = 1, num_tiles_input_grid
1533
1534 if (trim(input_type) == "gaussian_netcdf") then
1535 if (localpet == 0) then
1536 call read_fv3_grid_data_netcdf('orog', tile, idim_input, jdim_input, &
1537 lsoil_input, sfcdata=data_one_tile)
1538 endif
1539
1540 else
1541
1542 if (localpet == 0) then
1543 tilefile = trim(orog_dir_input_grid) // trim(orog_files_input_grid(tile))
1544 print*,'- OPEN OROGRAPHY FILE: ', trim(tilefile)
1545 error=nf90_open(tilefile,nf90_nowrite,ncid)
1546 call netcdf_err(error, 'OPENING OROGRAPHY FILE.' )
1547 error=nf90_inq_varid(ncid, 'orog_raw', id_var)
1548 call netcdf_err(error, 'READING OROGRAPHY RECORD ID.' )
1549 error=nf90_get_var(ncid, id_var, data_one_tile)
1550 call netcdf_err(error, 'READING OROGRAPHY RECORD.' )
1551 print*,'terrain check history ',tile, maxval(data_one_tile)
1552 error=nf90_close(ncid)
1553 endif
1554
1555 endif
1556
1557 print*,"- CALL FieldScatter FOR INPUT TERRAIN."
1558 call esmf_fieldscatter(terrain_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1559 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1560 call error_handler("IN FieldScatter", rc)
1561
1562 enddo terrain_loop
1563
1564 tile_loop : do tile = 1, num_tiles_input_grid
1565
1566! liquid soil moisture
1567
1568 if (localpet == 0) then
1569 call read_fv3_grid_data_netcdf('soill1', tile, idim_input, jdim_input, &
1570 lsoil_input, sfcdata=data_one_tile)
1571 data_one_tile_3d(:,:,1) = data_one_tile
1572 call read_fv3_grid_data_netcdf('soill2', tile, idim_input, jdim_input, &
1573 lsoil_input, sfcdata=data_one_tile)
1574 data_one_tile_3d(:,:,2) = data_one_tile
1575 call read_fv3_grid_data_netcdf('soill3', tile, idim_input, jdim_input, &
1576 lsoil_input, sfcdata=data_one_tile)
1577 data_one_tile_3d(:,:,3) = data_one_tile
1578 call read_fv3_grid_data_netcdf('soill4', tile, idim_input, jdim_input, &
1579 lsoil_input, sfcdata=data_one_tile)
1580 data_one_tile_3d(:,:,4) = data_one_tile
1581 endif
1582
1583 print*,"- CALL FieldScatter FOR INPUT LIQUID SOIL MOISTURE."
1584 call esmf_fieldscatter(soilm_liq_input_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
1585 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1586 call error_handler("IN FieldScatter", rc)
1587
1588! total soil moisture
1589
1590 if (localpet == 0) then
1591 call read_fv3_grid_data_netcdf('soilw1', tile, idim_input, jdim_input, &
1592 lsoil_input, sfcdata=data_one_tile)
1593 data_one_tile_3d(:,:,1) = data_one_tile
1594 call read_fv3_grid_data_netcdf('soilw2', tile, idim_input, jdim_input, &
1595 lsoil_input, sfcdata=data_one_tile)
1596 data_one_tile_3d(:,:,2) = data_one_tile
1597 call read_fv3_grid_data_netcdf('soilw3', tile, idim_input, jdim_input, &
1598 lsoil_input, sfcdata=data_one_tile)
1599 data_one_tile_3d(:,:,3) = data_one_tile
1600 call read_fv3_grid_data_netcdf('soilw4', tile, idim_input, jdim_input, &
1601 lsoil_input, sfcdata=data_one_tile)
1602 data_one_tile_3d(:,:,4) = data_one_tile
1603 endif
1604
1605 print*,"- CALL FieldScatter FOR INPUT TOTAL SOIL MOISTURE."
1606 call esmf_fieldscatter(soilm_tot_input_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
1607 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1608 call error_handler("IN FieldScatter", rc)
1609
1610! soil tempeature (ice temp at land ice points)
1611
1612 if (localpet == 0) then
1613 call read_fv3_grid_data_netcdf('soilt1', tile, idim_input, jdim_input, &
1614 lsoil_input, sfcdata=data_one_tile)
1615 data_one_tile_3d(:,:,1) = data_one_tile
1616 call read_fv3_grid_data_netcdf('soilt2', tile, idim_input, jdim_input, &
1617 lsoil_input, sfcdata=data_one_tile)
1618 data_one_tile_3d(:,:,2) = data_one_tile
1619 call read_fv3_grid_data_netcdf('soilt3', tile, idim_input, jdim_input, &
1620 lsoil_input, sfcdata=data_one_tile)
1621 data_one_tile_3d(:,:,3) = data_one_tile
1622 call read_fv3_grid_data_netcdf('soilt4', tile, idim_input, jdim_input, &
1623 lsoil_input, sfcdata=data_one_tile)
1624 data_one_tile_3d(:,:,4) = data_one_tile
1625 endif
1626
1627 print*,"- CALL FieldScatter FOR INPUT SOIL TEMPERATURE."
1628 call esmf_fieldscatter(soil_temp_input_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
1629 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1630 call error_handler("IN FieldScatter", rc)
1631
1632! land mask
1633
1634 if (localpet == 0) then
1635 call read_fv3_grid_data_netcdf('land', tile, idim_input, jdim_input, &
1636 lsoil_input, sfcdata=data_one_tile)
1637 endif
1638
1639 print*,"- CALL FieldScatter FOR INPUT LANDSEA MASK."
1640 call esmf_fieldscatter(landsea_mask_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1641 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1642 call error_handler("IN FieldScatter", rc)
1643
1644! sea ice fraction
1645
1646 if (localpet == 0) then
1647 call read_fv3_grid_data_netcdf('icec', tile, idim_input, jdim_input, &
1648 lsoil_input, sfcdata=data_one_tile)
1649 endif
1650
1651 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE FRACTION."
1652 call esmf_fieldscatter(seaice_fract_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1653 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1654 call error_handler("IN FieldScatter", rc)
1655
1656! sea ice depth
1657
1658 if (localpet == 0) then
1659 call read_fv3_grid_data_netcdf('icetk', tile, idim_input, jdim_input, &
1660 lsoil_input, sfcdata=data_one_tile)
1661 endif
1662
1663 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE DEPTH."
1664 call esmf_fieldscatter(seaice_depth_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1665 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1666 call error_handler("IN FieldScatter", rc)
1667
1668! sea ice skin temperature
1669
1670 if (localpet == 0) then
1671 call read_fv3_grid_data_netcdf('tisfc', tile, idim_input, jdim_input, &
1672 lsoil_input, sfcdata=data_one_tile)
1673 endif
1674
1675 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE SKIN TEMPERATURE."
1676 call esmf_fieldscatter(seaice_skin_temp_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1677 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1678 call error_handler("IN FieldScatter", rc)
1679
1680! liquid equivalent snow depth
1681
1682 if (localpet == 0) then
1683 call read_fv3_grid_data_netcdf('weasd', tile, idim_input, jdim_input, &
1684 lsoil_input, sfcdata=data_one_tile)
1685 endif
1686
1687 print*,"- CALL FieldScatter FOR INPUT GRID SNOW LIQUID EQUIVALENT."
1688 call esmf_fieldscatter(snow_liq_equiv_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1689 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1690 call error_handler("IN FieldScatter", rc)
1691
1692! physical snow depth
1693
1694 if (localpet == 0) then
1695 call read_fv3_grid_data_netcdf('snod', tile, idim_input, jdim_input, &
1696 lsoil_input, sfcdata=data_one_tile)
1697 data_one_tile = data_one_tile * 1000.0 ! convert from meters to mm.
1698 endif
1699
1700 print*,"- CALL FieldScatter FOR INPUT GRID SNOW DEPTH."
1701 call esmf_fieldscatter(snow_depth_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1702 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1703 call error_handler("IN FieldScatter", rc)
1704
1705! Vegetation type
1706
1707 if (localpet == 0) then
1708 call read_fv3_grid_data_netcdf('vtype', tile, idim_input, jdim_input, &
1709 lsoil_input, sfcdata=data_one_tile)
1710 endif
1711
1712 print*,"- CALL FieldScatter FOR INPUT GRID VEG TYPE."
1713 call esmf_fieldscatter(veg_type_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1714 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1715 call error_handler("IN FieldScatter", rc)
1716
1717! Soil type
1718
1719 if (localpet == 0) then
1720 call read_fv3_grid_data_netcdf('sotyp', tile, idim_input, jdim_input, &
1721 lsoil_input, sfcdata=data_one_tile)
1722 endif
1723
1724 print*,"- CALL FieldScatter FOR INPUT GRID SOIL TYPE."
1725 call esmf_fieldscatter(soil_type_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1726 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1727 call error_handler("IN FieldScatter", rc)
1728
1729! Two-meter temperature
1730
1731 if (localpet == 0) then
1732 call read_fv3_grid_data_netcdf('tmp2m', tile, idim_input, jdim_input, &
1733 lsoil_input, sfcdata=data_one_tile)
1734 endif
1735
1736 print*,"- CALL FieldScatter FOR INPUT GRID T2M."
1737 call esmf_fieldscatter(t2m_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1738 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1739 call error_handler("IN FieldScatter", rc)
1740
1741! Two-meter q
1742
1743 if (localpet == 0) then
1744 call read_fv3_grid_data_netcdf('spfh2m', tile, idim_input, jdim_input, &
1745 lsoil_input, sfcdata=data_one_tile)
1746 endif
1747
1748 print*,"- CALL FieldScatter FOR INPUT GRID Q2M."
1749 call esmf_fieldscatter(q2m_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1750 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1751 call error_handler("IN FieldScatter", rc)
1752
1753 if (localpet == 0) then
1754 call read_fv3_grid_data_netcdf('tprcp', tile, idim_input, jdim_input, &
1755 lsoil_input, sfcdata=data_one_tile)
1756 endif
1757
1758 print*,"- CALL FieldScatter FOR INPUT GRID TPRCP."
1759 call esmf_fieldscatter(tprcp_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1760 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1761 call error_handler("IN FieldScatter", rc)
1762
1763 if (localpet == 0) then
1764 call read_fv3_grid_data_netcdf('f10m', tile, idim_input, jdim_input, &
1765 lsoil_input, sfcdata=data_one_tile)
1766 endif
1767
1768 print*,"- CALL FieldScatter FOR INPUT GRID F10M"
1769 call esmf_fieldscatter(f10m_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1770 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1771 call error_handler("IN FieldScatter", rc)
1772
1773 if (localpet == 0) then
1774 call read_fv3_grid_data_netcdf('ffmm', tile, idim_input, jdim_input, &
1775 lsoil_input, sfcdata=data_one_tile)
1776 endif
1777
1778 print*,"- CALL FieldScatter FOR INPUT GRID FFMM"
1779 call esmf_fieldscatter(ffmm_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1780 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1781 call error_handler("IN FieldScatter", rc)
1782
1783 if (localpet == 0) then
1784 call read_fv3_grid_data_netcdf('fricv', tile, idim_input, jdim_input, &
1785 lsoil_input, sfcdata=data_one_tile)
1786 endif
1787
1788 print*,"- CALL FieldScatter FOR INPUT GRID USTAR"
1789 call esmf_fieldscatter(ustar_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1790 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1791 call error_handler("IN FieldScatter", rc)
1792
1793 if (localpet == 0) then
1794! call read_fv3_grid_data_netcdf('srflag', tile, idim_input, jdim_input, &
1795! lsoil_input, sfcdata=data_one_tile)
1796 data_one_tile = 0.0
1797 endif
1798
1799 print*,"- CALL FieldScatter FOR INPUT GRID SRFLAG"
1800 call esmf_fieldscatter(srflag_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1801 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1802 call error_handler("IN FieldScatter", rc)
1803
1804 if (localpet == 0) then
1805 call read_fv3_grid_data_netcdf('tmpsfc', tile, idim_input, jdim_input, &
1806 lsoil_input, sfcdata=data_one_tile)
1807 endif
1808
1809 print*,"- CALL FieldScatter FOR INPUT GRID SKIN TEMPERATURE"
1810 call esmf_fieldscatter(skin_temp_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1811 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1812 call error_handler("IN FieldScatter", rc)
1813
1814 if (localpet == 0) then
1815 call read_fv3_grid_data_netcdf('cnwat', tile, idim_input, jdim_input, &
1816 lsoil_input, sfcdata=data_one_tile)
1817 endif
1818
1819 print*,"- CALL FieldScatter FOR INPUT GRID CANOPY MOISTURE CONTENT."
1820 call esmf_fieldscatter(canopy_mc_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1821 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1822 call error_handler("IN FieldScatter", rc)
1823
1824 if (localpet == 0) then
1825 call read_fv3_grid_data_netcdf('sfcr', tile, idim_input, jdim_input, &
1826 lsoil_input, sfcdata=data_one_tile)
1827 endif
1828
1829 print*,"- CALL FieldScatter FOR INPUT GRID Z0."
1830 call esmf_fieldscatter(z0_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1831 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1832 call error_handler("IN FieldScatter", rc)
1833
1834 enddo tile_loop
1835
1836 deallocate(data_one_tile, data_one_tile_3d)
1837
1838 end subroutine read_input_sfc_netcdf_file
1839
1844 subroutine read_input_sfc_grib2_file(localpet)
1845
1846 use mpi_f08
1847 use grib_mod
1849 use model_grid, only : input_grid_type
1850 use search_util
1851
1852 implicit none
1853
1854 integer, intent(in) :: localpet
1855
1856 character(len=250) :: the_file
1857 character(len=250) :: geo_file
1858 character(len=200) :: err_msg
1859 character(len=20) :: vname, vname_file, slev
1860 character(len=50) :: method
1861
1862 integer :: rc, varnum, iret, i, j,k
1863 integer :: ncid2d, varid, varsize
1864 integer :: lugb, lugi
1865 integer :: jdisc, jgdtn, jpdtn, pdt_num
1866 integer :: jids(200), jgdt(200), jpdt(200)
1867
1868 logical :: rap_latlon, unpack
1869
1870 real(esmf_kind_r4) :: value
1871 real(esmf_kind_r4), allocatable :: dummy2d(:,:)
1872 real(esmf_kind_r8), allocatable :: icec_save(:,:)
1873 real(esmf_kind_r4), allocatable :: dummy1d(:)
1874 real(esmf_kind_r8), allocatable :: dummy2d_8(:,:),dummy2d_82(:,:),tsk_save(:,:)
1875 real(esmf_kind_r8), allocatable :: dummy3d(:,:,:), dummy3d_stype(:,:,:)
1876 integer(esmf_kind_i4), allocatable :: slmsk_save(:,:)
1877 integer(esmf_kind_i8), allocatable :: dummy2d_i(:,:)
1878
1879 type(gribfield) :: gfld
1880
1881 rap_latlon = trim(to_upper(external_model))=="RAP" .and. trim(input_grid_type) == "rotated_latlon"
1882
1883 the_file = trim(data_dir_input_grid) // "/" // trim(grib2_file_input_grid)
1884 geo_file = trim(geogrid_file_input_grid)
1885
1886 print*,"- READ SFC DATA FROM GRIB2 FILE: ", trim(the_file)
1887
1888! Determine the number of soil layers in file.
1889
1890 if (localpet == 0) then
1891
1892 lugb=12
1893 call baopenr(lugb,the_file,rc)
1894 if (rc /= 0) call error_handler("ERROR OPENING GRIB2 FILE.", rc)
1895
1896 j = 0 ! search at beginning of file
1897 lugi = 0 ! no grib index file
1898 jdisc = -1 ! search for any discipline
1899 jpdtn = -1 ! search for any product definition template number
1900 jgdtn = -1 ! search for any grid definition template number
1901 jids = -9999 ! array of values in identification section, set to wildcard
1902 jgdt = -9999 ! array of values in grid definition template, set to wildcard
1903 jpdt = -9999 ! array of values in product definition template, set to wildcard
1904 unpack = .false. ! unpack data
1905
1906 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
1907 unpack, k, gfld, rc)
1908
1909 if (rc == 0) then
1910 if (gfld%idsect(1) == 7 .and. gfld%idsect(2) == 2) then
1911 print*,'- THIS IS NCEP GEFS DATA.'
1912 pdt_num = 1
1913 else
1914 pdt_num = 0
1915 endif
1916 else
1917 if (rc /= 0) call error_handler("ERROR READING GRIB2 FILE.", rc)
1918 endif
1919
1920 j = 0
1921 lsoil_input = 0
1922
1923 do
1924
1925 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
1926 unpack, k, gfld, rc)
1927
1928 if (rc /= 0) exit
1929
1930 if (gfld%discipline == 2) then ! discipline - land products
1931 if (gfld%ipdtnum == pdt_num) then ! prod template number - analysis or forecast at single level.
1932 if (gfld%ipdtmpl(1) == 0 .and. gfld%ipdtmpl(2) == 2) then ! soil temp
1933 ! Sect4/octs 10 and 11
1934 if (gfld%ipdtmpl(10) == 106 .and. gfld%ipdtmpl(13) == 106) then ! Sect4/octs 23/29.
1935 ! Layer below ground.
1936 lsoil_input = lsoil_input + 1
1937 endif
1938 endif
1939 endif
1940 endif
1941
1942 j = k
1943
1944 enddo
1945
1946 print*, "- FILE HAS ", lsoil_input, " SOIL LEVELS."
1947 if (lsoil_input == 0) call error_handler("COUNTING SOIL LEVELS.", rc)
1948
1949 endif ! localpet == 0
1950
1951 call mpi_barrier(mpi_comm_world, rc)
1952 call mpi_bcast(lsoil_input,1,mpi_integer,0,mpi_comm_world,rc)
1953
1954 ! We need to recreate the soil fields if we have something other than 4 levels
1955
1956 if (lsoil_input /= 4) then
1957
1958 call esmf_fielddestroy(soil_temp_input_grid, rc=rc)
1959 call esmf_fielddestroy(soilm_tot_input_grid, rc=rc)
1960 call esmf_fielddestroy(soilm_liq_input_grid, rc=rc)
1961
1962 print*,"- CALL FieldCreate FOR INPUT SOIL TEMPERATURE."
1963 soil_temp_input_grid = esmf_fieldcreate(input_grid, &
1964 typekind=esmf_typekind_r8, &
1965 staggerloc=esmf_staggerloc_center, &
1966 ungriddedlbound=(/1/), &
1967 ungriddedubound=(/lsoil_input/), rc=rc)
1968 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1969 call error_handler("IN FieldCreate", rc)
1970
1971 print*,"- CALL FieldCreate FOR INPUT TOTAL SOIL MOISTURE."
1972 soilm_tot_input_grid = esmf_fieldcreate(input_grid, &
1973 typekind=esmf_typekind_r8, &
1974 staggerloc=esmf_staggerloc_center, &
1975 ungriddedlbound=(/1/), &
1976 ungriddedubound=(/lsoil_input/), rc=rc)
1977 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1978 call error_handler("IN FieldCreate", rc)
1979
1980 print*,"- CALL FieldCreate FOR INPUT LIQUID SOIL MOISTURE."
1981 soilm_liq_input_grid = esmf_fieldcreate(input_grid, &
1982 typekind=esmf_typekind_r8, &
1983 staggerloc=esmf_staggerloc_center, &
1984 ungriddedlbound=(/1/), &
1985 ungriddedubound=(/lsoil_input/), rc=rc)
1986 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1987 call error_handler("IN FieldCreate", rc)
1988
1989 endif
1990
1991 if (localpet == 0) then
1992 allocate(dummy2d(i_input,j_input))
1993 allocate(slmsk_save(i_input,j_input))
1994 allocate(tsk_save(i_input,j_input))
1995 allocate(icec_save(i_input,j_input))
1996 allocate(dummy2d_8(i_input,j_input))
1997 allocate(dummy2d_82(i_input,j_input))
1998 allocate(dummy3d(i_input,j_input,lsoil_input))
1999 else
2000 allocate(dummy3d(0,0,0))
2001 allocate(dummy2d_8(0,0))
2002 allocate(dummy2d_82(0,0))
2003 allocate(dummy2d(0,0))
2004 allocate(slmsk_save(0,0))
2005 endif
2006
2007 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008 ! These variables are always in grib files, or are required, so no need to check for them
2009 ! in the varmap table. If they can't be found in the input file, then stop the program.
2010 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2011
2012 if (localpet == 0) then
2013
2014 print*,"- READ TERRAIN."
2015
2016 j = 0
2017 jdisc = 0 ! Search for discipline 0 - meteorological products
2018 jpdt = -9999 ! array of values in product definition template, set to wildcard.
2019 jpdtn = pdt_num ! search for product definition template number 0 - anl or fcst.
2020 jpdt(1) = 3 ! Sec4/oct 10 - param cat - mass field
2021 jpdt(2) = 5 ! Sec4/oct 11 - param number - geopotential height
2022 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2023 unpack=.true.
2024 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2025 unpack, k, gfld, rc)
2026 if (rc /= 0) call error_handler("READING TERRAIN.", rc)
2027
2028 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2029! print*,'orog ', maxval(dummy2d_8),minval(dummy2d_8)
2030
2031 endif
2032
2033 print*,"- CALL FieldScatter FOR INPUT TERRAIN."
2034 call esmf_fieldscatter(terrain_input_grid, dummy2d_8, rootpet=0, rc=rc)
2035 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2036 call error_handler("IN FieldScatter", rc)
2037
2038 if (localpet == 0) then
2039
2040 print*,"- READ SEAICE FRACTION."
2041
2042 jdisc = 10 ! Search for discipline - ocean products
2043 j = 0 ! Search at beginning of file.
2044 jpdtn = pdt_num ! Search for product def template number 0 - anl or fcst.
2045 jpdt = -9999 ! Array of values in Sec 4 product definition template;
2046 ! Initialize to wildcard.
2047 jpdt(1) = 2 ! Sec4/oct 10 - parameter category - ice
2048 jpdt(2) = 0 ! Sec4/oct 11 - parameter number - ice cover
2049 unpack=.true.
2050 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2051 unpack, k, gfld, rc)
2052 if (rc /= 0) call error_handler("READING SEAICE FRACTION.", rc)
2053
2054 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2055! print*,'icec ', maxval(dummy2d_8),minval(dummy2d_8)
2056
2057 icec_save = dummy2d_8
2058
2059 endif
2060
2061 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE FRACTION."
2062 call esmf_fieldscatter(seaice_fract_input_grid, dummy2d_8 ,rootpet=0, rc=rc)
2063 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2064 call error_handler("IN FieldScatter", rc)
2065
2066!----------------------------------------------------------------------------------
2067! GFS v14 and v15.2 grib data has two land masks. LANDN is created by
2068! nearest neighbor interpolation. LAND is created by bilinear interpolation.
2069! LANDN matches the bitmap. So use it first. For other GFS versions or other models,
2070! use LAND. Mask in grib file is '1' (land), '0' (not land). Add sea/lake ice category
2071! '2' based on ice concentration.
2072!----------------------------------------------------------------------------------
2073
2074 if (localpet == 0) then
2075
2076 print*,"- READ LANDSEA MASK."
2077
2078 jdisc = 2 ! Search for discipline - land products
2079 j = 0 ! Search at beginning of file.
2080 jpdtn = pdt_num ! Search for product definition template number 0 - anl or fcst.
2081 jpdt = -9999 ! Initialize array of values in product definition template - Sec 4.
2082 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - veg/biomass
2083 jpdt(2) = 218 ! Sec4/oct 11 - parameter number - land nearest neighbor
2084 unpack=.true.
2085 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2086 unpack, k, gfld, rc)
2087
2088 if (rc == 0) then
2089
2090 print*,'landnn ', maxval(gfld%fld),minval(gfld%fld)
2091
2092 else
2093
2094 jdisc = 2 ! Search for discipline - land products
2095 j = 0 ! Search at beginning of file.
2096 jpdtn = pdt_num ! Search for product def template number 0 - anl or fcst.
2097 jpdt = -9999 ! Initialize array of values in product definition template - Sec 4.
2098 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - veg/biomass
2099 jpdt(2) = 0 ! Sec4/oct 11 - parameter number - land cover (fraction)
2100 unpack=.true.
2101 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2102 unpack, k, gfld, rc)
2103 if (rc /= 0) call error_handler("READING LANDSEA MASK.", rc)
2104
2105! print*,'land ', maxval(gfld%fld),minval(gfld%fld)
2106
2107 endif
2108
2109 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2110
2111 do j = 1, j_input
2112 do i = 1, i_input
2113 if(dummy2d_8(i,j) < 0.5_esmf_kind_r8) dummy2d_8(i,j)=0.0
2114 if(icec_save(i,j) > 0.15_esmf_kind_r8) then
2115 dummy2d_8(i,j) = 2.0_esmf_kind_r8
2116 endif
2117 enddo
2118 enddo
2119
2120 slmsk_save = nint(dummy2d_8)
2121
2122 deallocate(icec_save)
2123
2124 endif ! read land mask
2125
2126 print*,"- CALL FieldScatter FOR INPUT LANDSEA MASK."
2127 call esmf_fieldscatter(landsea_mask_input_grid, dummy2d_8 ,rootpet=0, rc=rc)
2128 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2129 call error_handler("IN FieldScatter", rc)
2130
2131 if (localpet == 0) then
2132
2133 print*,"- READ SEAICE SKIN TEMPERATURE."
2134
2135 jdisc = 0 ! Search for discipline - meteorological products
2136 j = 0 ! Search at beginning of file.
2137 jpdtn = pdt_num ! Search for product definition template number 0 - anl or fcst.
2138 jpdt = -9999 ! Initialize array of values in product definition template - Sec4
2139 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - temperature
2140 jpdt(2) = 0 ! Sec4/oct 11 - parameter number - temperature
2141 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2142 unpack=.true.
2143 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2144 unpack, k, gfld, rc)
2145 if (rc /= 0) call error_handler("READING SEAICE SKIN TEMP.", rc)
2146
2147! print*,'ti ',maxval(gfld%fld),minval(gfld%fld)
2148
2149 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2150
2151 endif
2152
2153 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE SKIN TEMPERATURE."
2154 call esmf_fieldscatter(seaice_skin_temp_input_grid, dummy2d_8 ,rootpet=0, rc=rc)
2155 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2156 call error_handler("IN FieldScatter", rc)
2157
2158!----------------------------------------------------------------------------------
2159! Read snow fields. Zero out at non-land points and undefined points (points
2160! removed using the bitmap). Program expects depth and liquid equivalent
2161! in mm.
2162!----------------------------------------------------------------------------------
2163
2164 if (localpet == 0) then
2165
2166 print*,"- READ SNOW LIQUID EQUIVALENT."
2167
2168 jdisc = 0 ! Search for discipline - meteorological products
2169 j = 0 ! Search at beginning of file.
2170 jpdtn = pdt_num ! Search for the product definition template number.
2171 jpdt = -9999 ! Initialize array of values in product definition template - Sec4
2172 jpdt(1) = 1 ! Sec4/oct 10 - parameter category - moisture
2173 jpdt(2) = 13 ! Sec4/oct 11 - parameter number - liquid equiv snow depth
2174 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2175 unpack=.true.
2176
2177 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2178 unpack, k, gfld, rc)
2179 if (rc /= 0) call error_handler("READING SNOW LIQUID EQUIVALENT.", rc)
2180
2181! print*,'weasd ', maxval(gfld%fld),minval(gfld%fld)
2182
2183 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2184
2185 do j = 1, j_input
2186 do i = 1, i_input
2187 if(slmsk_save(i,j) == 0) dummy2d_8(i,j) = 0.0
2188 enddo
2189 enddo
2190
2191 endif
2192
2193 print*,"- CALL FieldScatter FOR INPUT GRID SNOW LIQUID EQUIVALENT."
2194 call esmf_fieldscatter(snow_liq_equiv_input_grid, dummy2d_8 ,rootpet=0, rc=rc)
2195 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2196 call error_handler("IN FieldScatter", rc)
2197
2198 if (localpet == 0) then
2199
2200 print*,"- READ SNOW DEPTH."
2201
2202 jdisc = 0 ! Search for discipline - meteorological products
2203 j = 0 ! Search at beginning of file.
2204 jpdtn = pdt_num ! Search for the product definition template number.
2205 jpdt = -9999 ! Initialize array of values in product definition template - Sec4
2206 jpdt(1) = 1 ! Sec4/oct 10 - parameter category - moisture
2207 jpdt(2) = 11 ! Sec4/oct 11 - parameter number - snow depth
2208 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2209 unpack=.true.
2210
2211 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2212 unpack, k, gfld, rc)
2213
2214 if (rc /= 0) then
2215 call error_handler("READING SNOW DEPTH.", rc)
2216 else
2217 gfld%fld = gfld%fld * 1000.0
2218! print*,'snod ', maxval(gfld%fld),minval(gfld%fld)
2219 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2220 endif
2221
2222 do j = 1, j_input
2223 do i = 1, i_input
2224 if(slmsk_save(i,j) == 0) dummy2d_8(i,j) = 0.0
2225 enddo
2226 enddo
2227
2228 endif
2229
2230 print*,"- CALL FieldScatter FOR INPUT GRID SNOW DEPTH."
2231 call esmf_fieldscatter(snow_depth_input_grid,dummy2d_8,rootpet=0, rc=rc)
2232 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2233 call error_handler("IN FieldScatter", rc)
2234
2235 if (localpet == 0) then
2236
2237 print*,"- READ T2M."
2238
2239 jdisc = 0 ! Search for discipline - meteorological products
2240 j = 0 ! Search at beginning of file.
2241 jpdtn = pdt_num ! Search for the product definition template number.
2242 jpdt = -9999 ! Initialize array of values in product definition template - Sec4
2243 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - temperature
2244 jpdt(2) = 0 ! Sec4/oct 11 - parameter number - temperature
2245 jpdt(10) = 103 ! Sec4/oct 23 - type of level - height above ground surface
2246 jpdt(12) = 2 ! Sec4/octs 25-28 - 2 meters above ground.
2247 unpack=.true.
2248
2249 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2250 unpack, k, gfld, rc)
2251
2252 if (rc /= 0) call error_handler("READING T2M.", rc)
2253! print*,'t2m ', maxval(gfld%fld),minval(gfld%fld)
2254
2255 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2256
2257 endif
2258
2259 print*,"- CALL FieldScatter FOR INPUT GRID T2M."
2260 call esmf_fieldscatter(t2m_input_grid, dummy2d_8, rootpet=0,rc=rc)
2261 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2262 call error_handler("IN FieldScatter", rc)
2263
2264 if (localpet == 0) then
2265
2266 print*,"- READ Q2M."
2267
2268 jdisc = 0 ! Search for discipline - meteorological products
2269 j = 0 ! Search at beginning of file.
2270 jpdtn = pdt_num ! Search for the product definition template number.
2271 jpdt = -9999 ! Initialize array of values in product definition template - Sec4
2272 jpdt(1) = 1 ! Sec4/oct 10 - parameter category - moisture
2273 jpdt(2) = 0 ! Sec4/oct 11 - parameter number - specific humidity
2274 jpdt(10) = 103 ! Sec4/oct 23 - type of level - height above ground surface
2275 jpdt(12) = 2 ! Sec4/octs 25-28 - 2 meters above ground.
2276 unpack=.true.
2277
2278 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2279 unpack, k, gfld, rc)
2280 if (rc /=0) call error_handler("READING Q2M.", rc)
2281
2282! print*,'q2m ',maxval(gfld%fld),minval(gfld%fld)
2283
2284 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2285
2286 endif
2287
2288 print*,"- CALL FieldScatter FOR INPUT GRID Q2M."
2289 call esmf_fieldscatter(q2m_input_grid,dummy2d_8, rootpet=0,rc=rc)
2290 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2291 call error_handler("IN FieldScatter", rc)
2292
2293 if (localpet == 0) then
2294
2295 print*,"- READ SKIN TEMPERATURE."
2296
2297 jdisc = 0 ! Search for discipline - meteorological products
2298 j = 0 ! Search at beginning of file.
2299 jpdtn = pdt_num ! Search for the product definition template number.
2300 jpdt = -9999 ! Initialize array of values in product definition template - Sec4
2301 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - temperature
2302 jpdt(2) = 0 ! Sec4/oct 11 - parameter number - temperature
2303 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2304 unpack=.true.
2305
2306 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2307 unpack, k, gfld, rc)
2308
2309 if (rc /= 0 ) call error_handler("READING SKIN TEMPERATURE.", rc)
2310! print*,'skint ', maxval(gfld%fld),minval(gfld%fld)
2311
2312 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2313
2314 tsk_save(:,:) = dummy2d_8
2315
2316 do j = 1, j_input
2317 do i = 1, i_input
2318 if(slmsk_save(i,j) == 0 .and. dummy2d_8(i,j) < 271.2) then
2319! print*,'too cool SST ',i,j,dummy2d_8(i,j)
2320 dummy2d_8(i,j) = 271.2
2321 endif
2322 if(slmsk_save(i,j) == 0 .and. dummy2d_8(i,j) > 310.) then
2323! print*,'too hot SST ',i,j,dummy2d_8(i,j)
2324 dummy2d_8(i,j) = 310.0
2325 endif
2326 enddo
2327 enddo
2328
2329 endif
2330
2331 print*,"- CALL FieldScatter FOR INPUT GRID SKIN TEMPERATURE"
2332 call esmf_fieldscatter(skin_temp_input_grid,dummy2d_8,rootpet=0, rc=rc)
2333 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2334 call error_handler("IN FieldScatter", rc)
2335
2336! srflag not in files. Set to zero.
2337
2338 if (localpet == 0) dummy2d_8 = 0.0
2339
2340 print*,"- CALL FieldScatter FOR INPUT GRID SRFLAG"
2341 call esmf_fieldscatter(srflag_input_grid,dummy2d_8, rootpet=0,rc=rc)
2342 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2343 call error_handler("IN FieldScatter", rc)
2344
2345 if (localpet == 0) then
2346
2347 print*,"- READ SOIL TYPE."
2348
2349 jdisc = 2 ! Search for discipline - land products
2350 j = 0 ! Search at beginning of file
2351 jpdtn = pdt_num ! Search for the product definition template number.
2352 jpdt = -9999 ! Initialize array of values in product definition template - Sec4
2353 jpdt(1) = 3 ! Sec4/oct 10 - parameter category - soil products
2354 jpdt(2) = 0 ! Sec4/oct 11 - parameter number - soil type
2355 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2356 unpack=.true.
2357
2358 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2359 unpack, k, gfld, rc)
2360
2361 if (rc == 0 ) then
2362! print*,'soil type ', maxval(gfld%fld),minval(gfld%fld)
2363 dummy2d = reshape(real(gfld%fld,kind=esmf_kind_r4) , (/i_input,j_input/))
2364
2365 endif
2366
2367 if (rc /= 0 .and. (trim(to_upper(external_model))=="HRRR" .or. rap_latlon) .and. geo_file .ne. "NULL") then
2368 ! Some HRRR and RAP files don't have dominant soil type in the output, but the geogrid files
2369 ! do, so this gives users the option to provide the geogrid file and use input soil
2370 ! type
2371 print*, "OPEN GEOGRID FILE ", trim(geo_file)
2372 rc = nf90_open(geo_file,nf90_nowrite,ncid2d)
2373 call netcdf_err(rc,"READING GEOGRID FILE")
2374
2375 print*, "INQURE ABOUT DIM IDS"
2376 rc = nf90_inq_dimid(ncid2d,"west_east",varid)
2377 call netcdf_err(rc,"READING west_east DIMENSION FROM GEOGRID FILE")
2378
2379 rc = nf90_inquire_dimension(ncid2d,varid,len=varsize)
2380 call netcdf_err(rc,"READING west_east DIMENSION SIZE")
2381 if (varsize .ne. i_input) call error_handler ("GEOGRID FILE GRID SIZE DIFFERS FROM INPUT DATA.", -1)
2382
2383 print*, "INQUIRE ABOUT SOIL TYPE FROM GEOGRID FILE"
2384 rc = nf90_inq_varid(ncid2d,"SCT_DOM",varid)
2385 call netcdf_err(rc,"FINDING SCT_DOM IN GEOGRID FILE")
2386
2387 print*, "READ SOIL TYPE FROM GEOGRID FILE "
2388 rc = nf90_get_var(ncid2d,varid,dummy2d)
2389 call netcdf_err(rc,"READING SCT_DOM FROM FILE")
2390
2391 print*, "INQUIRE ABOUT SOIL TYPE FRACTIONS FROM GEOGRID FILE"
2392 rc = nf90_inq_varid(ncid2d,"SOILCTOP",varid)
2393 call netcdf_err(rc,"FINDING SOILCTOP IN GEOGRID FILE")
2394
2395 allocate(dummy3d_stype(i_input,j_input,16))
2396 print*, "READ SOIL TYPE FRACTIONS FROM GEOGRID FILE "
2397 rc = nf90_get_var(ncid2d,varid,dummy3d_stype)
2398 call netcdf_err(rc,"READING SCT_DOM FROM FILE")
2399
2400 print*, "CLOSE GEOGRID FILE "
2401 iret = nf90_close(ncid2d)
2402
2403 ! There's an issue with the geogrid file containing soil type water at land points.
2404 ! This correction replaces the soil type at these points with the soil type with
2405 ! the next highest fractional coverage.
2406 allocate(dummy1d(16))
2407 do j = 1, j_input
2408 do i = 1, i_input
2409 if(dummy2d(i,j) == 14.0_esmf_kind_r4 .and. slmsk_save(i,j) == 1) then
2410 dummy1d(:) = real(dummy3d_stype(i,j,:),kind=esmf_kind_r4)
2411 dummy1d(14) = 0.0_esmf_kind_r4
2412 dummy2d(i,j) = real(maxloc(dummy1d, 1),esmf_kind_r4)
2413 endif
2414 enddo
2415 enddo
2416 deallocate(dummy1d)
2417 deallocate(dummy3d_stype)
2418 endif ! failed
2419
2420 if ((rc /= 0 .and. trim(to_upper(external_model)) /= "HRRR" .and. .not. rap_latlon) &
2421 .or. (rc /= 0 .and. (trim(to_upper(external_model)) == "HRRR" .or. rap_latlon))) then
2422 if (.not. sotyp_from_climo) then
2423 call error_handler("COULD NOT FIND SOIL TYPE IN FILE. PLEASE SET SOTYP_FROM_CLIMO=.TRUE. . EXITING", rc)
2424 else
2425 vname = "sotyp"
2426 slev = "surface"
2427 call get_var_cond(vname,this_miss_var_method=method, this_miss_var_value=value, &
2428 loc=varnum)
2429 call handle_grib_error(vname, slev ,method,value,varnum,read_from_input,rc, var= dummy2d)
2430 if (rc == 1) then ! missing_var_method == skip or no entry in varmap table
2431 print*, "WARNING: "//trim(vname)//" NOT AVAILABLE IN FILE. WILL NOT "//&
2432 "SCALE SOIL MOISTURE FOR DIFFERENCES IN SOIL TYPE. "
2433 dummy2d(:,:) = -99999.0_esmf_kind_r4
2434 endif
2435 endif
2436 endif
2437
2438 ! In the event that the soil type on the input grid still contains mismatches between
2439 ! soil type and landmask, this correction is a last-ditch effort to replace these points
2440 ! with soil type from a nearby land point.
2441
2442 if (.not. sotyp_from_climo) then
2443 do j = 1, j_input
2444 do i = 1, i_input
2445 if(dummy2d(i,j) == 14.0_esmf_kind_r4 .and. slmsk_save(i,j) == 1) dummy2d(i,j) = -99999.9_esmf_kind_r4
2446 enddo
2447 enddo
2448
2449 allocate(dummy2d_i(i_input,j_input))
2450 dummy2d_8 = real(dummy2d,esmf_kind_r8)
2451 dummy2d_i(:,:) = 0
2452 where(slmsk_save == 1) dummy2d_i = 1
2453
2454 call search(dummy2d_8,dummy2d_i,i_input,j_input,1,230)
2455 deallocate(dummy2d_i)
2456 else
2457 dummy2d_8=real(dummy2d,esmf_kind_r8)
2458 endif
2459
2460 print*,'sotype ',maxval(dummy2d_8),minval(dummy2d_8)
2461
2462 endif ! read of soil type
2463
2464 print*,"- CALL FieldScatter FOR INPUT GRID SOIL TYPE."
2465 call esmf_fieldscatter(soil_type_input_grid,dummy2d_8, rootpet=0, rc=rc)
2466 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2467 call error_handler("IN FieldScatter", rc)
2468
2469 deallocate(dummy2d)
2470
2471 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2472 ! Begin variables whose presence in grib2 files varies, but no climatological
2473 ! data is available, so we have to account for values in the varmap table
2474 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2475
2476 if (.not. vgfrc_from_climo) then
2477
2478 if (localpet == 0) then
2479
2480 print*,"- READ VEG FRACTION."
2481
2482 jdisc = 2 ! Search for discipline - land products
2483 j = 0 ! Search at beginning of file.
2484 jpdtn = pdt_num ! Search for the product definition template number.
2485 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2486 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - veg/biomass
2487 jpdt(2) = 4 ! Sec4/oct 11 - parameter number - vegetation
2488 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2489 unpack=.true.
2490
2491 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2492 unpack, k, gfld, rc)
2493
2494 if (rc /= 0 )then
2495 err_msg="COULD NOT FIND VEGETATION FRACTION IN FILE. PLEASE SET VGFRC_FROM_CLIMO=.TRUE."
2496 call error_handler(err_msg, rc)
2497 else
2498 if (maxval(gfld%fld) > 2.0) gfld%fld = gfld%fld / 100.0
2499! print*,'vfrac ', maxval(gfld%fld),minval(gfld%fld)
2500 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2501
2502 endif
2503
2504 endif ! localpet 0
2505
2506 print*,"- CALL FieldScatter FOR INPUT GRID VEG GREENNESS."
2507 call esmf_fieldscatter(veg_greenness_input_grid,dummy2d_8, rootpet=0, rc=rc)
2508 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2509 call error_handler("IN FieldScatter", rc)
2510
2511 endif
2512
2513 if (.not. minmax_vgfrc_from_climo) then
2514
2515 if (localpet == 0) then
2516
2517 print*,"- READ MIN VEG FRACTION."
2518
2519 jdisc = 2 ! Search for discipline - land products
2520 j = 1105 ! grib2 file does not distinguish between the various veg
2521 ! fractions. Need to search using record number.
2522 jpdtn = pdt_num ! Search for the product definition template number.
2523 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2524 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - veg/biomass
2525 jpdt(2) = 4 ! Sec4/oct 11 - parameter number - vegetation
2526 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2527 unpack=.true.
2528
2529 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2530 unpack, k, gfld, rc)
2531
2532 if (rc /= 0) then
2533 j = 1101 ! Have to search by record number.
2534 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2535 unpack, k, gfld, rc)
2536 if (rc /= 0) then
2537 j = 1151 ! Have to search by record number.
2538 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2539 unpack, k, gfld, rc)
2540 err_msg="COULD NOT FIND MIN VEGETATION FRACTION IN FILE. SET MINMAX_VGFRC_FROM_CLIMO=.TRUE."
2541 if (rc/=0) call error_handler(err_msg, rc)
2542 endif
2543 endif
2544
2545 if (maxval(gfld%fld) > 2.0) gfld%fld = gfld%fld / 100.0
2546 print*,'vfrac min ', maxval(gfld%fld),minval(gfld%fld)
2547 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2548
2549 endif ! localpet == 0
2550
2551 print*,"- CALL FieldScatter FOR INPUT GRID MIN VEG GREENNESS."
2552 call esmf_fieldscatter(min_veg_greenness_input_grid,dummy2d_8, rootpet=0, rc=rc)
2553 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2554 call error_handler("IN FieldScatter", rc)
2555
2556 if (localpet == 0) then
2557
2558 print*,"- READ MAX VEG FRACTION."
2559
2560 jdisc = 2 ! Search for discipline - land products
2561 j = 1106 ! Have to search by record number.
2562 jpdtn = pdt_num ! Search for the product definition template number.
2563 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2564 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - veg/biomass
2565 jpdt(2) = 4 ! Sec4/oct 11 - parameter number - vegetation
2566 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2567 unpack=.true.
2568
2569 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2570 unpack, k, gfld, rc)
2571 if (rc /= 0) then
2572 j = 1102 ! Have to search by record number.
2573 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2574 unpack, k, gfld, rc)
2575 if (rc /= 0) then
2576 j = 1152 ! Have to search by record number.
2577 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2578 unpack, k, gfld, rc)
2579 err_msg="COULD NOT FIND MAX VEGETATION FRACTION IN FILE. SET MINMAX_VGFRC_FROM_CLIMO=.TRUE."
2580 if (rc <= 0) call error_handler(err_msg, rc)
2581 endif
2582 endif
2583
2584 if (maxval(gfld%fld) > 2.0) gfld%fld = gfld%fld / 100.0
2585! print*,'vfrac max ', maxval(gfld%fld),minval(gfld%fld)
2586 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2587
2588 endif !localpet==0
2589
2590 print*,"- CALL FieldScatter FOR INPUT GRID MAX VEG GREENNESS."
2591 call esmf_fieldscatter(max_veg_greenness_input_grid,dummy2d_8,rootpet=0, rc=rc)
2592 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2593 call error_handler("IN FieldScatter", rc)
2594
2595 endif !minmax_vgfrc_from_climo
2596
2597 if (.not. lai_from_climo) then
2598
2599 if (localpet == 0) then
2600
2601 print*,"- READ LAI."
2602
2603 jdisc = 0 ! Search for discipline - meteorological products
2604 j = 0 ! Search at beginning of file.
2605 jpdtn = pdt_num ! Search for the product definition template number.
2606 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2607 jpdt(1) = 7 ! Sec4/oct 10 - parameter category - thermo stability indices
2608 jpdt(2) = 198 ! Sec4/oct 11 - parameter number - leaf area index
2609 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2610 unpack=.true.
2611
2612 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2613 unpack, k, gfld, rc)
2614
2615 err_msg="COULD NOT FIND LAI IN FILE. SET LAI_FROM_CLIMO=.TRUE."
2616 if (rc /= 0) call error_handler(err_msg, rc)
2617
2618! print*,'lai ', maxval(gfld%fld),minval(gfld%fld)
2619 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2620
2621 endif !localpet==0
2622
2623 print*,"- CALL FieldScatter FOR INPUT GRID LAI."
2624 call esmf_fieldscatter(lai_input_grid,dummy2d_8,rootpet=0, rc=rc)
2625 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2626 call error_handler("IN FieldScatter", rc)
2627
2628 endif ! lai
2629
2630 if (localpet == 0) then
2631
2632 print*,"- READ SEAICE DEPTH."
2633 vname="hice"
2634 slev=":surface:"
2635 call get_var_cond(vname,this_miss_var_method=method,this_miss_var_value=value, &
2636 loc=varnum)
2637
2638 jdisc = 10 ! Search for discipline - ocean products
2639 j = 0 ! Search at beginning of file.
2640 jpdtn = pdt_num ! Search for the product definition template number.
2641 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2642 jpdt(1) = 2 ! Sec4/oct 10 - parameter category - ice
2643 jpdt(2) = 1 ! Sec4/oct 11 - parameter number - thickness
2644 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2645 unpack=.true.
2646
2647 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2648 unpack, k, gfld, rc)
2649
2650 if (rc /= 0 ) then
2651 call handle_grib_error(vname, slev ,method,value,varnum,read_from_input,rc,var8=dummy2d_8)
2652 if (rc==1) then ! missing_var_method == skip or no entry in varmap table
2653 print*, "WARNING: "//trim(vname)//" NOT AVAILABLE IN FILE. THIS FIELD WILL BE"//&
2654 " REPLACED WITH CLIMO. SET A FILL "// &
2655 "VALUE IN THE VARMAP TABLE IF THIS IS NOT DESIRABLE."
2656 dummy2d_8(:,:) = 0.0
2657 endif
2658 else
2659! print*,'hice ', maxval(gfld%fld),minval(gfld%fld)
2660 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2661 endif
2662
2663 endif
2664
2665 print*,"- CALL FieldScatter FOR INPUT GRID SEAICE DEPTH."
2666 call esmf_fieldscatter(seaice_depth_input_grid,dummy2d_8, rootpet=0, rc=rc)
2667 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2668 call error_handler("IN FieldScatter", rc)
2669
2670 if (localpet == 0) then
2671
2672 print*,"- READ TPRCP."
2673 vname="tprcp"
2674 slev=":surface:"
2675 call get_var_cond(vname,this_miss_var_method=method,this_miss_var_value=value, &
2676 loc=varnum)
2677
2678! No test data contained this field. So could not test with g2 library.
2679 rc = 1
2680 if (rc /= 0) then
2681 call handle_grib_error(vname, slev ,method,value,varnum,read_from_input,rc, var8=dummy2d_8)
2682 if (rc==1) then ! missing_var_method == skip or no entry in varmap table
2683 print*, "WARNING: "//trim(vname)//" NOT AVAILABLE IN FILE. THIS FIELD WILL NOT"//&
2684 " BE WRITTEN TO THE INPUT FILE. SET A FILL "// &
2685 "VALUE IN THE VARMAP TABLE IF THIS IS NOT DESIRABLE."
2686 dummy2d_8 = 0.0
2687 endif
2688 endif
2689 print*,'tprcp ',maxval(dummy2d_8),minval(dummy2d_8)
2690
2691 endif ! tprcp
2692
2693 print*,"- CALL FieldScatter FOR INPUT GRID TPRCP."
2694 call esmf_fieldscatter(tprcp_input_grid,dummy2d_8, rootpet=0, rc=rc)
2695 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2696 call error_handler("IN FieldScatter", rc)
2697
2698 if (localpet == 0) then
2699
2700 print*,"- READ FFMM."
2701 vname="ffmm"
2702 slev=":surface:"
2703 call get_var_cond(vname,this_miss_var_method=method,this_miss_var_value=value, &
2704 loc=varnum)
2705
2706! No sample data contained this field, so could not test g2lib.
2707 rc = 1
2708 if (rc /= 0) then
2709 call handle_grib_error(vname, slev ,method,value,varnum,read_from_input,rc, var8=dummy2d_8)
2710 if (rc==1) then ! missing_var_method == skip or no entry in varmap table
2711 print*, "WARNING: "//trim(vname)//" NOT AVAILABLE IN FILE. THIS FIELD WILL NOT"//&
2712 " BE WRITTEN TO THE INPUT FILE. SET A FILL "// &
2713 "VALUE IN THE VARMAP TABLE IF THIS IS NOT DESIRABLE."
2714 dummy2d_8(:,:) = 0.0
2715 endif
2716 endif
2717 print*,'ffmm ',maxval(dummy2d_8),minval(dummy2d_8)
2718
2719 endif ! ffmm
2720
2721 print*,"- CALL FieldScatter FOR INPUT GRID FFMM"
2722 call esmf_fieldscatter(ffmm_input_grid,dummy2d_8, rootpet=0, rc=rc)
2723 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2724 call error_handler("IN FieldScatter", rc)
2725
2726 if (localpet == 0) then
2727
2728 print*,"- READ USTAR."
2729 vname="fricv"
2730 slev=":surface:"
2731 call get_var_cond(vname,this_miss_var_method=method,this_miss_var_value=value, &
2732 loc=varnum)
2733
2734 jdisc = 0 ! Search for discipline - meteorological products
2735 j = 0 ! Search at beginning of file.
2736 jpdtn = pdt_num ! Search for the product definition template number.
2737 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2738 jpdt(1) = 2 ! Sec4/oct 10 - parameter category - momentum
2739 jpdt(2) = 30 ! Sec4/oct 11 - parameter number - friction velocity
2740 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2741 unpack=.true.
2742
2743 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2744 unpack, k, gfld, rc)
2745 if (rc /= 0) then
2746 jpdt(2) = 197 ! oct 11 - param number - friction vel.
2747 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2748 unpack, k, gfld, rc)
2749 endif
2750
2751 if (rc == 0) then
2752! print*,'fricv ', maxval(gfld%fld),minval(gfld%fld)
2753 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2754 else
2755 call handle_grib_error(vname, slev ,method,value,varnum,read_from_input,rc, var8=dummy2d_8)
2756 if (rc==1) then ! missing_var_method == skip or no entry in varmap table
2757 print*, "WARNING: "//trim(vname)//" NOT AVAILABLE IN FILE. THIS FIELD WILL "//&
2758 "REPLACED WITH CLIMO. SET A FILL "// &
2759 "VALUE IN THE VARMAP TABLE IF THIS IS NOT DESIRABLE."
2760 dummy2d_8(:,:) = 0.0
2761 endif
2762 endif
2763
2764 endif ! ustar
2765
2766 print*,"- CALL FieldScatter FOR INPUT GRID USTAR"
2767 call esmf_fieldscatter(ustar_input_grid,dummy2d_8, rootpet=0, rc=rc)
2768 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2769 call error_handler("IN FieldScatter", rc)
2770
2771 if (localpet == 0) then
2772
2773 print*,"- READ F10M."
2774 vname="f10m"
2775 slev=":10 m above ground:"
2776 call get_var_cond(vname,this_miss_var_method=method,this_miss_var_value=value, &
2777 loc=varnum)
2778
2779 rc = -1 ! None of the test cases have this record. Can't test with g2lib.
2780 if (rc /= 0) then
2781 call handle_grib_error(vname, slev ,method,value,varnum,read_from_input,rc, var8=dummy2d_8)
2782 if (rc==1) then ! missing_var_method == skip or no entry in varmap table
2783 print*, "WARNING: "//trim(vname)//" NOT AVAILABLE IN FILE. THIS FIELD WILL NOT"//&
2784 " BE WRITTEN TO THE INPUT FILE. SET A FILL "// &
2785 "VALUE IN THE VARMAP TABLE IF THIS IS NOT DESIRABLE."
2786 dummy2d_8(:,:) = 0.0
2787 endif
2788 endif
2789 print*,'f10m ',maxval(dummy2d_8),minval(dummy2d_8)
2790
2791 endif
2792
2793 print*,"- CALL FieldScatter FOR INPUT GRID F10M."
2794 call esmf_fieldscatter(f10m_input_grid,dummy2d_8, rootpet=0, rc=rc)
2795 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2796 call error_handler("IN FieldScatter", rc)
2797
2798 if (localpet == 0) then
2799
2800 print*,"- READ CANOPY MOISTURE CONTENT."
2801 vname="cnwat"
2802 slev=":surface:"
2803 call get_var_cond(vname,this_miss_var_method=method,this_miss_var_value=value, &
2804 loc=varnum)
2805
2806 jdisc = 2 ! Search for discipline - land products
2807 j = 0 ! Search from beginning of file
2808 jpdtn = pdt_num ! Search for the product definition template number.
2809 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2810 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - veg/biomass
2811 jpdt(2) = 13 ! Sec4/oct 11 - parameter number - canopy water
2812 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2813 unpack=.true.
2814
2815 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2816 unpack, k, gfld, rc)
2817
2818 if (rc /= 0 ) then
2819 jpdt(2) = 196 ! Sec4/oct 11 - param number - canopy water
2820 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2821 unpack, k, gfld, rc)
2822 endif
2823
2824 if (rc == 0 ) then
2825 print*,'cnwat ', maxval(gfld%fld),minval(gfld%fld)
2826 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2827 call check_cnwat(dummy2d_8,i_input,j_input)
2828 else
2829 call handle_grib_error(vname, slev ,method,value,varnum,read_from_input,rc, var8=dummy2d_8)
2830 if (rc==1) then ! missing_var_method == skip or no entry in varmap table
2831 print*, "WARNING: "//trim(vname)//" NOT AVAILABLE IN FILE. THIS FIELD WILL"//&
2832 " REPLACED WITH CLIMO. SET A FILL "// &
2833 "VALUE IN THE VARMAP TABLE IF THIS IS NOT DESIRABLE."
2834 dummy2d_8 = 0.0
2835 endif
2836 endif
2837
2838 endif
2839
2840 print*,"- CALL FieldScatter FOR INPUT GRID CANOPY MOISTURE CONTENT."
2841 call esmf_fieldscatter(canopy_mc_input_grid,dummy2d_8, rootpet=0, rc=rc)
2842 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2843 call error_handler("IN FieldScatter", rc)
2844
2845 if (localpet == 0) then
2846
2847 print*,"- READ Z0."
2848 vname="sfcr"
2849 slev=":surface:"
2850 call get_var_cond(vname,this_miss_var_method=method,this_miss_var_value=value, &
2851 loc=varnum)
2852
2853 jdisc = 2 ! Search for discipline - land products
2854 j = 0 ! Search from beginning of file.
2855 jpdtn = pdt_num ! Search for the product definition template number.
2856 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2857 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - veg/biomass
2858 jpdt(2) = 1 ! Sec4/oct 11 - parameter number - surface roughness
2859 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2860 unpack=.true.
2861
2862 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2863 unpack, k, gfld, rc)
2864
2865 if (rc /= 0 ) then
2866 call handle_grib_error(vname, slev ,method,value,varnum,read_from_input,rc, var8= dummy2d_8)
2867 if (rc==1) then ! missing_var_method == skip or no entry in varmap table
2868 print*, "WARNING: "//trim(vname)//" NOT AVAILABLE IN FILE. THIS FIELD WILL BE"//&
2869 " REPLACED WITH CLIMO. SET A FILL "// &
2870 "VALUE IN THE VARMAP TABLE IF THIS IS NOT DESIRABLE."
2871 dummy2d_8(:,:) = 0.0
2872 endif
2873 else
2874 gfld%fld = gfld%fld * 10.0 ! Grib files have z0 (m), but fv3 expects z0(cm)
2875! print*,'sfcr ', maxval(gfld%fld),minval(gfld%fld)
2876 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2877 endif
2878
2879 endif
2880
2881 print*,"- CALL FieldScatter FOR INPUT GRID Z0."
2882 call esmf_fieldscatter(z0_input_grid,dummy2d_8, rootpet=0, rc=rc)
2883 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2884 call error_handler("IN FieldScatter", rc)
2885
2886 if (localpet == 0) then
2887 print*,"- READ LIQUID SOIL MOISTURE."
2888 vname = "soill"
2889 vname_file = ":SOILL:"
2890 call read_grib_soil(vname,vname_file,lugb, pdt_num,dummy3d) !!! NEED TO HANDLE
2891 !!! SOIL LEVELS
2892 endif
2893
2894 print*,"- CALL FieldScatter FOR INPUT LIQUID SOIL MOISTURE."
2895 call esmf_fieldscatter(soilm_liq_input_grid, dummy3d, rootpet=0, rc=rc)
2896 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2897 call error_handler("IN FieldScatter", rc)
2898
2899 if (localpet == 0) then
2900 print*,"- READ TOTAL SOIL MOISTURE."
2901 vname = "soilw"
2902 vname_file = "var2_2_1_" ! the var number instead
2903 call read_grib_soil(vname,vname_file,lugb, pdt_num,dummy3d)
2904 endif
2905
2906 print*,"- CALL FieldScatter FOR INPUT TOTAL SOIL MOISTURE."
2907 call esmf_fieldscatter(soilm_tot_input_grid, dummy3d, rootpet=0, rc=rc)
2908 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2909 call error_handler("IN FieldScatter", rc)
2910
2911!----------------------------------------------------------------------------------------
2912! Vegetation type is not available in some files. However, it is needed to identify
2913! permanent land ice points. At land ice, the total soil moisture is a flag value of
2914! '1'. Use this flag as a temporary solution.
2915!----------------------------------------------------------------------------------------
2916
2917 print*, "- CALL FieldGather for INPUT SOIL TYPE."
2918 call esmf_fieldgather(soil_type_input_grid, dummy2d_82, rootpet=0, tile=1, rc=rc)
2919 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2920 call error_handler("IN FieldGather", rc)
2921
2922 if (localpet == 0) then
2923
2924 print*,"- READ VEG TYPE."
2925
2926 jdisc = 2 ! Search for discipline - land products
2927 j = 0 ! Search from beginning of file.
2928 jpdtn = pdt_num ! Search for the product definition template number.
2929 jpdt = -9999 ! Initialize array of values in product definition template Sec4.
2930 jpdt(1) = 0 ! Sec4/oct 10 - parameter category - veg/biomass
2931 jpdt(2) = 198 ! Sec4/oct 11 - parameter number - vegetation type
2932 jpdt(10) = 1 ! Sec4/oct 23 - type of level - ground surface
2933 unpack=.true.
2934
2935 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
2936 unpack, k, gfld, rc)
2937
2938 if (rc /= 0 ) then
2939 if (.not. vgtyp_from_climo) then
2940 call error_handler("COULD NOT FIND VEGETATION TYPE IN FILE. PLEASE SET VGTYP_FROM_CLIMO=.TRUE. . EXITING", rc)
2941 else ! Set input veg type at land ice from soil moisture flag (1.0).
2942 do j = 1, j_input
2943 do i = 1, i_input
2944 dummy2d_8(i,j) = 0.0
2945 if(slmsk_save(i,j) == 1 .and. dummy3d(i,j,1) > 0.99) & ! land ice indicated by
2946 ! soil moisture flag of '1'.
2947 dummy2d_8(i,j) = real(veg_type_landice_input,esmf_kind_r8)
2948 enddo
2949 enddo
2950 endif
2951 else ! found vtype in file.
2952 dummy2d_8 = reshape(gfld%fld , (/i_input,j_input/))
2953 endif
2954
2955 if (trim(external_model) .ne. "GFS") then
2956 do j = 1, j_input
2957 do i = 1,i_input
2958 if (dummy2d_8(i,j) == 15.0_esmf_kind_r8 .and. slmsk_save(i,j) == 1) then
2959 if (dummy3d(i,j,1) < 0.6) then
2960 dummy2d_8(i,j) = real(veg_type_landice_input,esmf_kind_r8)
2961 elseif (dummy3d(i,j,1) > 0.99) then
2962 slmsk_save(i,j) = 0
2963 dummy2d_8(i,j) = 0.0_esmf_kind_r8
2964 dummy2d_82(i,j) = 0.0_esmf_kind_r8
2965 endif
2966 elseif (dummy2d_8(i,j) == 17.0_esmf_kind_r8 .and. slmsk_save(i,j)==0) then
2967 dummy2d_8(i,j) = 0.0_esmf_kind_r8
2968 endif
2969 enddo
2970 enddo
2971 endif
2972
2973! print*,'vgtyp ',maxval(dummy2d_8),minval(dummy2d_8)
2974
2975 endif ! read veg type
2976
2977 print*,"- CALL FieldScatter FOR INPUT VEG TYPE."
2978 call esmf_fieldscatter(veg_type_input_grid, dummy2d_8, rootpet=0, rc=rc)
2979 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2980 call error_handler("IN FieldScatter", rc)
2981
2982 print*,"- CALL FieldScatter FOR INPUT SOIL TYPE."
2983 call esmf_fieldscatter(soil_type_input_grid, dummy2d_82, rootpet=0, rc=rc)
2984 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2985 call error_handler("IN FieldScatter", rc)
2986
2987 deallocate(dummy2d_82)
2988
2989 print*,"- CALL FieldScatter FOR INPUT LANDSEA MASK."
2990 call esmf_fieldscatter(landsea_mask_input_grid,real(slmsk_save,esmf_kind_r8),rootpet=0, rc=rc)
2991 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2992 call error_handler("IN FieldScatter", rc)
2993
2994!---------------------------------------------------------------------------------
2995! At open water (slmsk==0), the soil temperature array is not used and set
2996! to the filler value of SST. At lake/sea ice points (slmsk=2), the soil
2997! temperature array holds ice column temperature. This field is not available
2998! in the grib data, so set to a default value.
2999!---------------------------------------------------------------------------------
3000
3001 if (localpet == 0) then
3002 print*,"- READ SOIL TEMPERATURE."
3003 vname = "soilt"
3004 vname_file = ":TSOIL:"
3005 call read_grib_soil(vname,vname_file,lugb,pdt_num,dummy3d)
3006 call check_soilt(dummy3d,slmsk_save,tsk_save,icet_default,i_input,j_input,lsoil_input)
3007 deallocate(tsk_save)
3008 endif
3009
3010 deallocate(slmsk_save)
3011
3012 print*,"- CALL FieldScatter FOR INPUT SOIL TEMPERATURE."
3013 call esmf_fieldscatter(soil_temp_input_grid, dummy3d, rootpet=0, rc=rc)
3014 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3015 call error_handler("IN FieldScatter", rc)
3016
3017 deallocate(dummy3d)
3018 deallocate(dummy2d_8)
3019
3020 if (localpet == 0) call baclose(lugb, rc)
3021
3022 end subroutine read_input_sfc_grib2_file
3023
3027 subroutine init_sfc_esmf_fields
3028
3029 implicit none
3030
3031 integer :: rc
3032
3033 print*,"- CALL FieldCreate FOR INPUT GRID LANDSEA MASK."
3034 landsea_mask_input_grid = esmf_fieldcreate(input_grid, &
3035 typekind=esmf_typekind_r8, &
3036 staggerloc=esmf_staggerloc_center, rc=rc)
3037 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3038 call error_handler("IN FieldCreate", rc)
3039
3040 print*,"- CALL FieldCreate FOR INPUT GRID Z0."
3041 z0_input_grid = esmf_fieldcreate(input_grid, &
3042 typekind=esmf_typekind_r8, &
3043 staggerloc=esmf_staggerloc_center, rc=rc)
3044 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3045 call error_handler("IN FieldCreate", rc)
3046
3047 print*,"- CALL FieldCreate FOR INPUT GRID VEGETATION TYPE."
3048 veg_type_input_grid = esmf_fieldcreate(input_grid, &
3049 typekind=esmf_typekind_r8, &
3050 staggerloc=esmf_staggerloc_center, rc=rc)
3051 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3052 call error_handler("IN FieldCreate", rc)
3053
3054 print*,"- CALL FieldCreate FOR INPUT GRID CANOPY MOISTURE CONTENT."
3055 canopy_mc_input_grid = esmf_fieldcreate(input_grid, &
3056 typekind=esmf_typekind_r8, &
3057 staggerloc=esmf_staggerloc_center, rc=rc)
3058 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3059 call error_handler("IN FieldCreate", rc)
3060
3061 print*,"- CALL FieldCreate FOR INPUT GRID SEAICE FRACTION."
3062 seaice_fract_input_grid = esmf_fieldcreate(input_grid, &
3063 typekind=esmf_typekind_r8, &
3064 staggerloc=esmf_staggerloc_center, rc=rc)
3065 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3066 call error_handler("IN FieldCreate", rc)
3067
3068 print*,"- CALL FieldCreate FOR INPUT GRID SEAICE DEPTH."
3069 seaice_depth_input_grid = esmf_fieldcreate(input_grid, &
3070 typekind=esmf_typekind_r8, &
3071 staggerloc=esmf_staggerloc_center, rc=rc)
3072 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3073 call error_handler("IN FieldCreate", rc)
3074
3075 print*,"- CALL FieldCreate FOR INPUT GRID SEAICE SKIN TEMPERATURE."
3076 seaice_skin_temp_input_grid = esmf_fieldcreate(input_grid, &
3077 typekind=esmf_typekind_r8, &
3078 staggerloc=esmf_staggerloc_center, rc=rc)
3079 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3080 call error_handler("IN FieldCreate", rc)
3081
3082 print*,"- CALL FieldCreate FOR INPUT GRID SNOW DEPTH."
3083 snow_depth_input_grid = esmf_fieldcreate(input_grid, &
3084 typekind=esmf_typekind_r8, &
3085 staggerloc=esmf_staggerloc_center, rc=rc)
3086 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3087 call error_handler("IN FieldCreate", rc)
3088
3089 print*,"- CALL FieldCreate FOR INPUT GRID SNOW LIQUID EQUIVALENT."
3090 snow_liq_equiv_input_grid = esmf_fieldcreate(input_grid, &
3091 typekind=esmf_typekind_r8, &
3092 staggerloc=esmf_staggerloc_center, rc=rc)
3093 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3094 call error_handler("IN FieldCreate", rc)
3095
3096 print*,"- CALL FieldCreate FOR INPUT GRID T2M."
3097 t2m_input_grid = esmf_fieldcreate(input_grid, &
3098 typekind=esmf_typekind_r8, &
3099 staggerloc=esmf_staggerloc_center, rc=rc)
3100 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3101 call error_handler("IN FieldCreate", rc)
3102
3103 print*,"- CALL FieldCreate FOR INPUT GRID Q2M."
3104 q2m_input_grid = esmf_fieldcreate(input_grid, &
3105 typekind=esmf_typekind_r8, &
3106 staggerloc=esmf_staggerloc_center, rc=rc)
3107 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3108 call error_handler("IN FieldCreate", rc)
3109
3110 print*,"- CALL FieldCreate FOR INPUT GRID TPRCP."
3111 tprcp_input_grid = esmf_fieldcreate(input_grid, &
3112 typekind=esmf_typekind_r8, &
3113 staggerloc=esmf_staggerloc_center, rc=rc)
3114 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3115 call error_handler("IN FieldCreate", rc)
3116
3117 print*,"- CALL FieldCreate FOR INPUT GRID F10M."
3118 f10m_input_grid = esmf_fieldcreate(input_grid, &
3119 typekind=esmf_typekind_r8, &
3120 staggerloc=esmf_staggerloc_center, rc=rc)
3121 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3122 call error_handler("IN FieldCreate", rc)
3123
3124 print*,"- CALL FieldCreate FOR INPUT GRID USTAR."
3125 ustar_input_grid = esmf_fieldcreate(input_grid, &
3126 typekind=esmf_typekind_r8, &
3127 staggerloc=esmf_staggerloc_center, rc=rc)
3128 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3129 call error_handler("IN FieldCreate", rc)
3130
3131 print*,"- CALL FieldCreate FOR INPUT GRID FFMM."
3132 ffmm_input_grid = esmf_fieldcreate(input_grid, &
3133 typekind=esmf_typekind_r8, &
3134 staggerloc=esmf_staggerloc_center, rc=rc)
3135 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3136 call error_handler("IN FieldCreate", rc)
3137
3138 print*,"- CALL FieldCreate FOR INPUT GRID SRFLAG."
3139 srflag_input_grid = esmf_fieldcreate(input_grid, &
3140 typekind=esmf_typekind_r8, &
3141 staggerloc=esmf_staggerloc_center, rc=rc)
3142 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3143 call error_handler("IN FieldCreate", rc)
3144
3145 print*,"- CALL FieldCreate FOR INPUT SKIN TEMPERATURE."
3146 skin_temp_input_grid = esmf_fieldcreate(input_grid, &
3147 typekind=esmf_typekind_r8, &
3148 staggerloc=esmf_staggerloc_center, rc=rc)
3149 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3150 call error_handler("IN FieldCreate", rc)
3151
3152 print*,"- CALL FieldCreate FOR INPUT SOIL TYPE."
3153 soil_type_input_grid = esmf_fieldcreate(input_grid, &
3154 typekind=esmf_typekind_r8, &
3155 staggerloc=esmf_staggerloc_center, rc=rc)
3156 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3157 call error_handler("IN FieldCreate", rc)
3158
3159 print*,"- CALL FieldCreate FOR INPUT TERRAIN."
3160 terrain_input_grid = esmf_fieldcreate(input_grid, &
3161 typekind=esmf_typekind_r8, &
3162 staggerloc=esmf_staggerloc_center, rc=rc)
3163 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3164 call error_handler("IN FieldCreate", rc)
3165
3166 print*,"- CALL FieldCreate FOR INPUT SOIL TEMPERATURE."
3167 soil_temp_input_grid = esmf_fieldcreate(input_grid, &
3168 typekind=esmf_typekind_r8, &
3169 staggerloc=esmf_staggerloc_center, &
3170 ungriddedlbound=(/1/), &
3171 ungriddedubound=(/lsoil_input/), rc=rc)
3172 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3173 call error_handler("IN FieldCreate", rc)
3174
3175 print*,"- CALL FieldCreate FOR INPUT TOTAL SOIL MOISTURE."
3176 soilm_tot_input_grid = esmf_fieldcreate(input_grid, &
3177 typekind=esmf_typekind_r8, &
3178 staggerloc=esmf_staggerloc_center, &
3179 ungriddedlbound=(/1/), &
3180 ungriddedubound=(/lsoil_input/), rc=rc)
3181 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3182 call error_handler("IN FieldCreate", rc)
3183
3184 print*,"- CALL FieldCreate FOR INPUT LIQUID SOIL MOISTURE."
3185 soilm_liq_input_grid = esmf_fieldcreate(input_grid, &
3186 typekind=esmf_typekind_r8, &
3187 staggerloc=esmf_staggerloc_center, &
3188 ungriddedlbound=(/1/), &
3189 ungriddedubound=(/lsoil_input/), rc=rc)
3190 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3191 call error_handler("IN FieldCreate", rc)
3192
3193
3194
3195 if (.not. vgfrc_from_climo) then
3196 print*,"- CALL FieldCreate FOR INPUT VEGETATION GREENNESS."
3197 veg_greenness_input_grid = esmf_fieldcreate(input_grid, &
3198 typekind=esmf_typekind_r8, &
3199 staggerloc=esmf_staggerloc_center, rc=rc)
3200 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3201 call error_handler("IN FieldCreate", rc)
3202 endif
3203
3204 if (.not. minmax_vgfrc_from_climo) then
3205 print*,"- CALL FieldCreate FOR INPUT MIN VEGETATION GREENNESS."
3206 min_veg_greenness_input_grid = esmf_fieldcreate(input_grid, &
3207 typekind=esmf_typekind_r8, &
3208 staggerloc=esmf_staggerloc_center, rc=rc)
3209 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3210 call error_handler("IN FieldCreate", rc)
3211
3212 print*,"- CALL FieldCreate FOR INPUT MAX VEGETATION GREENNESS."
3213 max_veg_greenness_input_grid = esmf_fieldcreate(input_grid, &
3214 typekind=esmf_typekind_r8, &
3215 staggerloc=esmf_staggerloc_center, rc=rc)
3216 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3217 call error_handler("IN FieldCreate", rc)
3218 endif
3219
3220 if (.not. lai_from_climo) then
3221 print*,"- CALL FieldCreate FOR INPUT LEAF AREA INDEX."
3222 lai_input_grid = esmf_fieldcreate(input_grid, &
3223 typekind=esmf_typekind_r8, &
3224 staggerloc=esmf_staggerloc_center, rc=rc)
3225 if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3226 call error_handler("IN FieldCreate", rc)
3227 endif
3228 end subroutine init_sfc_esmf_fields
3229
3240 SUBROUTINE read_fv3_grid_data_netcdf(FIELD,TILE_NUM,IMO,JMO,LMO, &
3241 SFCDATA, SFCDATA_3D)
3242
3243 IMPLICIT NONE
3244
3245 CHARACTER(LEN=*),INTENT(IN) :: FIELD
3246
3247 INTEGER, INTENT(IN) :: IMO, JMO, LMO, TILE_NUM
3248
3249 REAL(ESMF_KIND_R8), INTENT(OUT), OPTIONAL :: SFCDATA(IMO,JMO)
3250 REAL(ESMF_KIND_R8), INTENT(OUT), OPTIONAL :: SFCDATA_3D(IMO,JMO,LMO)
3251
3252 CHARACTER(LEN=256) :: TILEFILE
3253
3254 INTEGER :: ERROR, NCID, ID_VAR
3255
3256 tilefile = trim(data_dir_input_grid) // "/" // trim(sfc_files_input_grid(tile_num))
3257
3258 print*,'WILL READ ',trim(field), ' FROM: ', trim(tilefile)
3259
3260 error=nf90_open(trim(tilefile),nf90_nowrite,ncid)
3261 CALL netcdf_err(error, 'OPENING: '//trim(tilefile) )
3262
3263 error=nf90_inq_varid(ncid, field, id_var)
3264 CALL netcdf_err(error, 'READING FIELD ID' )
3265
3266 IF (PRESENT(sfcdata_3d)) THEN
3267 error=nf90_get_var(ncid, id_var, sfcdata_3d)
3268 CALL netcdf_err(error, 'READING FIELD' )
3269 ELSE
3270 error=nf90_get_var(ncid, id_var, sfcdata)
3271 CALL netcdf_err(error, 'READING FIELD' )
3272 ENDIF
3273
3274 error = nf90_close(ncid)
3275
3276 END SUBROUTINE read_fv3_grid_data_netcdf
3277
3286 subroutine read_grib_soil(vname, vname_file, lugb, pdt_num, dummy3d)
3287
3288 use grib_mod
3289
3290 implicit none
3291
3292 character(len=20), intent(in) :: vname,vname_file
3293
3294 integer, intent(in) :: lugb, pdt_num
3295
3296 real(esmf_kind_r8), intent(inout) :: dummy3d(:,:,:)
3297
3298 character(len=50) :: slevs(lsoil_input)
3299 character(len=50) :: method
3300
3301 integer :: varnum, i, j, k, rc, rc2
3302 integer :: jdisc, jgdtn, jpdtn, lugi
3303 integer :: jids(200), jgdt(200), jpdt(200)
3304 integer :: iscale1, iscale2
3305
3306 logical :: unpack
3307
3308 real(esmf_kind_r4), allocatable :: dummy2d(:,:)
3309 real(esmf_kind_r4) :: value
3310
3311 type(gribfield) :: gfld
3312
3313 allocate(dummy2d(i_input,j_input))
3314
3315 if(lsoil_input == 4) then
3316 slevs = (/character(24)::':0-0.1 m below ground:', ':0.1-0.4 m below ground:', &
3317 ':0.4-1 m below ground:', ':1-2 m below ground:'/)
3318 elseif(lsoil_input == 9) then
3319 slevs = (/character(26)::':0-0 m below ground',':0.01-0.01 m below ground:',':0.04-0.04 m below ground:', &
3320 ':0.1-0.1 m below ground:',':0.3-0.3 m below ground:',':0.6-0.6 m below ground:', &
3321 ':1-1 m below ground:',':1.6-1.6 m below ground:',':3-3 m below ground:'/)
3322 else
3323 rc = -1
3324 call error_handler("reading soil levels. File must have 4 or 9 soil levels.", rc)
3325 endif
3326
3327 call get_var_cond(vname,this_miss_var_method=method,this_miss_var_value=value, &
3328 loc=varnum)
3329
3330 lugi = 0 ! unit number for index file
3331 jdisc = 2 ! search for discipline - land products
3332 j = 0 ! search at beginning of file.
3333 jpdt = -9999 ! array of values in product definition template 4.n
3334 jids = -9999 ! array of values in identification section, set to wildcard
3335 jgdt = -9999 ! array of values in grid definition template 3.m
3336 jgdtn = -1 ! search for any grid definition number.
3337 jpdtn = pdt_num ! Search for the product definition template number.
3338 jpdt(1) = 0 ! Section 4/Octet 10 - parameter category - veg/biomass
3339 if (trim(vname) == 'soilt') jpdt(2) = 2 ! Section 4/Octet 11 - parameter number - soil temp
3340 if (trim(vname) == 'soilw') jpdt(2) = 192 ! Section 4/Octet 11 - parameter number - total soilm
3341 if (trim(vname) == 'soill') then
3342 jpdt(1) = 3 ! Section 4/Octet 10 - soil products
3343 jpdt(2) = 192 ! Section 4/Octet 11 - parameter number - liquid soilm
3344 endif
3345 jpdt(10) = 106 ! Section 4/Octet 23 - depth below ground
3346 jpdt(13) = 106 ! Section 4/Octet 29 - depth below ground
3347 unpack=.true.
3348
3349 do i = 1,lsoil_input
3350
3351 call getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
3352 unpack, k, gfld, rc2)
3353
3354 if (rc2 /= 0) then ! record not found.
3355 call handle_grib_error(vname_file, slevs(i),method,value,varnum,read_from_input,rc,var=dummy2d)
3356 if (rc==1 .and. trim(vname) /= "soill") then
3357 ! missing_var_method == skip or no entry in varmap table
3358 call error_handler("READING IN "//trim(vname)//". SET A FILL "// &
3359 "VALUE IN THE VARMAP TABLE IF THIS ERROR IS NOT DESIRABLE.",rc)
3360 elseif (rc==1) then
3361 dummy3d(:,:,:) = 0.0_esmf_kind_r8
3362 return
3363 endif
3364 endif
3365
3366 if (rc2 == 0) then ! record found.
3367 iscale1 = 10 ** gfld%ipdtmpl(11)
3368 iscale2 = 10 ** gfld%ipdtmpl(14)
3369! print*,'getgb2 top of soil layer in m ', float(gfld%ipdtmpl(12))/float(iscale1)
3370! print*,'getgb2 bot of soil layer in m ', float(gfld%ipdtmpl(15))/float(iscale2)
3371 dummy2d = reshape(real(gfld%fld,kind=esmf_kind_r4), (/i_input,j_input/) )
3372 endif
3373
3374 j = k
3375
3376 dummy3d(:,:,i) = real(dummy2d,esmf_kind_r8)
3377
3378 enddo
3379
3380 deallocate(dummy2d)
3381
3382 end subroutine read_grib_soil
3383
3387 subroutine cleanup_input_sfc_data
3388
3389 implicit none
3390
3391 integer :: rc
3392
3393 print*,"- CALL FieldDestroy FOR INPUT GRID FIELDS."
3394
3395 call esmf_fielddestroy(canopy_mc_input_grid, rc=rc)
3396 call esmf_fielddestroy(f10m_input_grid, rc=rc)
3397 call esmf_fielddestroy(ffmm_input_grid, rc=rc)
3398 if (.not. convert_nst) then
3399 call esmf_fielddestroy(landsea_mask_input_grid, rc=rc)
3400 endif
3401 call esmf_fielddestroy(q2m_input_grid, rc=rc)
3402 call esmf_fielddestroy(seaice_depth_input_grid, rc=rc)
3403 call esmf_fielddestroy(seaice_fract_input_grid, rc=rc)
3404 call esmf_fielddestroy(seaice_skin_temp_input_grid, rc=rc)
3405 call esmf_fielddestroy(skin_temp_input_grid, rc=rc)
3406 call esmf_fielddestroy(snow_depth_input_grid, rc=rc)
3407 call esmf_fielddestroy(snow_liq_equiv_input_grid, rc=rc)
3408 call esmf_fielddestroy(soil_temp_input_grid, rc=rc)
3409 call esmf_fielddestroy(soil_type_input_grid, rc=rc)
3410 call esmf_fielddestroy(soilm_liq_input_grid, rc=rc)
3411 call esmf_fielddestroy(soilm_tot_input_grid, rc=rc)
3412 call esmf_fielddestroy(srflag_input_grid, rc=rc)
3413 call esmf_fielddestroy(t2m_input_grid, rc=rc)
3414 call esmf_fielddestroy(tprcp_input_grid, rc=rc)
3415 call esmf_fielddestroy(ustar_input_grid, rc=rc)
3416 call esmf_fielddestroy(veg_type_input_grid, rc=rc)
3417 call esmf_fielddestroy(z0_input_grid, rc=rc)
3418 call esmf_fielddestroy(terrain_input_grid, rc=rc)
3419 if (.not. vgfrc_from_climo) then
3420 call esmf_fielddestroy(veg_greenness_input_grid, rc=rc)
3421 endif
3422 if (.not. minmax_vgfrc_from_climo) then
3423 call esmf_fielddestroy(min_veg_greenness_input_grid, rc=rc)
3424 call esmf_fielddestroy(max_veg_greenness_input_grid, rc=rc)
3425 endif
3426 if (.not. lai_from_climo) then
3427 call esmf_fielddestroy(lai_input_grid, rc=rc)
3428 endif
3429
3430 end subroutine cleanup_input_sfc_data
3431
3432 end module sfc_input_data
Read atmospheric data on the input grid.
type(esmf_field), public terrain_input_grid
terrain height
Sets up the ESMF grid objects for the input data grid and target FV3 grid.
Definition model_grid.F90:9
type(esmf_grid), public input_grid
input grid esmf grid object
integer, public i_input
i-dimension of input grid (or of each global tile)
character(len=50), public input_grid_type
map projection of input grid
integer, public num_tiles_input_grid
Number of tiles, input grid.
integer, public j_input
j-dimension of input grid (or of each global tile)
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data,...
character(len=500), public geogrid_file_input_grid
Name of "geogrid" file, which contains static surface fields on the input grid.
character(len=500), dimension(6), public sfc_files_input_grid
File names containing input surface data.
character(len=500), public orog_dir_input_grid
Directory containing the input grid orography files.
logical, dimension(:), allocatable, public read_from_input
When false, variable was not read from GRIB2 input file.
character(len=500), public grib2_file_input_grid
REQUIRED.
character(len=500), dimension(6), public orog_files_input_grid
Input grid orography files.
logical, public lai_from_climo
If false, interpolate leaf area index from the input data to the target grid instead of using data fr...
logical, public vgfrc_from_climo
If false, interpolate vegetation fraction from the input data to the target grid instead of using dat...
subroutine, public get_var_cond(var_name, this_miss_var_method, this_miss_var_value, this_field_var_name, loc)
Search the variable mapping table to find conditions for handling missing variables.
character(len=500), public data_dir_input_grid
Directory containing input atm or sfc files.
logical, public sotyp_from_climo
If false, interpolate soil type from the input data to the target grid instead of using data from sta...
logical, public vgtyp_from_climo
If false, interpolate vegetation type from the input data to the target grid instead of using data fr...
character(len=25), public input_type
Input data type:
character(len=20), public external_model
The model that the input data is derived from.
logical, public convert_nst
Convert nst data when true.
logical, public minmax_vgfrc_from_climo
If false, interpolate min/max vegetation fraction from the input data to the target grid instead of u...
Replace undefined values with a valid value.
subroutine, public search(field, mask, idim, jdim, tile, field_num, latitude, terrain_land, soilt_climo)
Replace undefined surface values.