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