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