chgres_cube  1.6.0
 All Data Structures Files Functions Variables
surface.F90
Go to the documentation of this file.
1 
5 
21  module surface
22 
23  use esmf
24 
25  implicit none
26 
27  private
28 
29  integer, parameter :: veg_type_landice_target = 15
30 
34 
35 ! surface fields (not including nst)
36  type(esmf_field), public :: canopy_mc_target_grid
37 
38  type(esmf_field), public :: f10m_target_grid
39 
41  type(esmf_field), public :: ffmm_target_grid
42 
44  type(esmf_field), public :: q2m_target_grid
45 
46  type(esmf_field), public :: seaice_depth_target_grid
47 
48  type(esmf_field), public :: seaice_fract_target_grid
49 
50  type(esmf_field), public :: seaice_skin_temp_target_grid
51 
52  type(esmf_field), public :: skin_temp_target_grid
53 
54  type(esmf_field), public :: srflag_target_grid
55 
56  type(esmf_field), public :: snow_liq_equiv_target_grid
57 
58  type(esmf_field), public :: snow_depth_target_grid
59 
60  type(esmf_field), public :: soil_temp_target_grid
61 
62  type(esmf_field), public :: soilm_liq_target_grid
63 
64  type(esmf_field), public :: soilm_tot_target_grid
65 
66  type(esmf_field), public :: t2m_target_grid
67 
68  type(esmf_field), public :: tprcp_target_grid
69 
70  type(esmf_field), public :: ustar_target_grid
71 
72  type(esmf_field), public :: z0_target_grid
73 
74  type(esmf_field), public :: lai_target_grid
75 
76 
77 ! nst fields
78  type(esmf_field), public :: c_d_target_grid
79 
80  type(esmf_field), public :: c_0_target_grid
81 
82  type(esmf_field), public :: d_conv_target_grid
83 
84  type(esmf_field), public :: dt_cool_target_grid
85 
86  type(esmf_field), public :: ifd_target_grid
87 
89  type(esmf_field), public :: qrain_target_grid
90 
91  type(esmf_field), public :: tref_target_grid
92 
93  type(esmf_field), public :: w_d_target_grid
94 
95  type(esmf_field), public :: w_0_target_grid
96 
97  type(esmf_field), public :: xs_target_grid
98 
100  type(esmf_field), public :: xt_target_grid
101 
103  type(esmf_field), public :: xu_target_grid
104 
106  type(esmf_field), public :: xv_target_grid
107 
109  type(esmf_field), public :: xz_target_grid
110 
111  type(esmf_field), public :: xtts_target_grid
112 
113  type(esmf_field), public :: xzts_target_grid
114 
115  type(esmf_field), public :: z_c_target_grid
116 
117  type(esmf_field), public :: zm_target_grid
118 
119 
120  type(esmf_field) :: soil_type_from_input_grid
121 
123  type(esmf_field) :: terrain_from_input_grid
124 
126  type(esmf_field) :: terrain_from_input_grid_land
127 
129 
130  real, parameter, private :: blim = 5.5
131 
132  real, parameter, private :: frz_h2o = 273.15
133 
134  real, parameter, private :: frz_ice = 271.21
135 
136  real, parameter, private :: grav = 9.81
137 
138  real, parameter, private :: hlice = 3.335E5
139 
140 
141  public :: surface_driver
142  public :: create_nst_esmf_fields
143  public :: interp
145  public :: cleanup_target_sfc_data
146  public :: nst_land_fill
147  public :: cleanup_target_nst_data
148 
149  contains
150 
156  subroutine surface_driver(localpet)
157 
158  use input_data, only : cleanup_input_sfc_data, &
162 
164  convert_nst
165 
166  use static_data, only : get_static_fields, &
168 
169  implicit none
170 
171  integer, intent(in) :: localpet
172 
173 !-----------------------------------------------------------------------
174 ! Compute soil-based parameters.
175 !-----------------------------------------------------------------------
176 
177  call calc_soil_params_driver(localpet)
178 
179 !-----------------------------------------------------------------------
180 ! Get static data (like vegetation type) on the target grid.
181 !-----------------------------------------------------------------------
182 
183  call get_static_fields(localpet)
184 
185 !-----------------------------------------------------------------------
186 ! Read surface data on input grid.
187 !-----------------------------------------------------------------------
188 
189  call read_input_sfc_data(localpet)
190 
191 !-----------------------------------------------------------------------
192 ! Read nst data on input grid.
193 !-----------------------------------------------------------------------
194 
195  if (convert_nst) call read_input_nst_data(localpet)
196 
197 !-----------------------------------------------------------------------
198 ! Create surface field objects for target grid.
199 !-----------------------------------------------------------------------
200 
202 
203 !-----------------------------------------------------------------------
204 ! Create nst field objects for target grid.
205 !-----------------------------------------------------------------------
206 
207  if (convert_nst) call create_nst_esmf_fields
208 
209 !-----------------------------------------------------------------------
210 ! Adjust soil levels of input grid !! not implemented yet
211 !-----------------------------------------------------------------------
212 
213  call adjust_soil_levels(localpet)
214 
215 !-----------------------------------------------------------------------
216 ! Horizontally interpolate fields.
217 !-----------------------------------------------------------------------
218 
219  call interp(localpet)
220 
221 !---------------------------------------------------------------------------------------------
222 ! Adjust soil/landice column temperatures for any change in elevation between
223 ! the
224 ! input and target grids.
225 !---------------------------------------------------------------------------------------------
226 
228 
229 !---------------------------------------------------------------------------------------------
230 ! Rescale soil moisture for changes in soil type between the input and target grids.
231 !---------------------------------------------------------------------------------------------
232 
234 
235 !---------------------------------------------------------------------------------------------
236 ! Compute liquid portion of total soil moisture.
237 !---------------------------------------------------------------------------------------------
238 
240 
241 !---------------------------------------------------------------------------------------------
242 ! Set z0 at land and sea ice.
243 !---------------------------------------------------------------------------------------------
244 
245  call roughness
246 
247 !---------------------------------------------------------------------------------------------
248 ! Perform some final qc checks.
249 !---------------------------------------------------------------------------------------------
250 
251  call qc_check
252 
253 !---------------------------------------------------------------------------------------------
254 ! Set flag values at land for nst fields.
255 !---------------------------------------------------------------------------------------------
256 
257  if (convert_nst) call nst_land_fill
258 
259 !---------------------------------------------------------------------------------------------
260 ! Free up memory.
261 !---------------------------------------------------------------------------------------------
262 
264 
265  if (convert_nst) call cleanup_input_nst_data
266 
267 !---------------------------------------------------------------------------------------------
268 ! Write data to file.
269 !---------------------------------------------------------------------------------------------
270 
271  call write_fv3_sfc_data_netcdf(localpet)
272 
273 !---------------------------------------------------------------------------------------------
274 ! Free up memory.
275 !---------------------------------------------------------------------------------------------
276 
277  if (convert_nst) call cleanup_target_nst_data
278 
280 
282 
283  return
284 
285  end subroutine surface_driver
286 
293  subroutine interp(localpet)
294 
295  use mpi
296  use esmf
297 
298  use input_data, only : canopy_mc_input_grid, &
299  f10m_input_grid, &
300  ffmm_input_grid, &
301  landsea_mask_input_grid, &
302  q2m_input_grid, &
303  seaice_depth_input_grid, &
304  seaice_fract_input_grid, &
305  seaice_skin_temp_input_grid, &
306  skin_temp_input_grid, &
307  snow_depth_input_grid, &
308  snow_liq_equiv_input_grid, &
309  soil_temp_input_grid, &
310  soil_type_input_grid, &
311  soilm_tot_input_grid, &
312  srflag_input_grid, &
313  t2m_input_grid, &
314  tprcp_input_grid, &
315  ustar_input_grid, &
316  veg_type_input_grid, &
317  z0_input_grid, &
318  c_d_input_grid, &
319  c_0_input_grid, &
320  d_conv_input_grid, &
321  dt_cool_input_grid, &
322  ifd_input_grid, &
323  qrain_input_grid, &
324  tref_input_grid, &
325  w_d_input_grid, &
326  w_0_input_grid, &
327  xs_input_grid, &
328  xt_input_grid, &
329  xu_input_grid, &
330  xv_input_grid, &
331  xz_input_grid, &
332  xtts_input_grid, &
333  xzts_input_grid, &
334  z_c_input_grid, &
335  zm_input_grid, terrain_input_grid, &
336  veg_type_landice_input, &
337  veg_greenness_input_grid, &
338  max_veg_greenness_input_grid, &
339  min_veg_greenness_input_grid, &
340  lai_input_grid
341 
342  use model_grid, only : input_grid, target_grid, &
343  i_target, j_target, &
344  lsoil_target, &
345  num_tiles_target_grid, &
346  landmask_target_grid, &
347  seamask_target_grid, &
348  latitude_target_grid
349 
350  use program_setup, only : convert_nst, &
351  vgtyp_from_climo, &
352  sotyp_from_climo, &
353  vgfrc_from_climo, &
354  minmax_vgfrc_from_climo, &
355  lai_from_climo, &
356  tg3_from_soil, &
357  external_model, &
358  input_type
359 
360  use static_data, only : veg_type_target_grid, &
361  soil_type_target_grid, &
362  veg_greenness_target_grid, &
363  substrate_temp_target_grid,&
364  min_veg_greenness_target_grid,&
365  max_veg_greenness_target_grid
366 
367  use search_util
368 
369  implicit none
370 
371  integer, intent(in) :: localpet
372 
373  integer :: l(1), u(1)
374  integer :: i, j, ij, rc, tile
375  integer :: clb_target(2), cub_target(2)
376  integer :: isrctermprocessing
377  integer(esmf_kind_i4), pointer :: unmapped_ptr(:)
378  integer(esmf_kind_i4), pointer :: mask_input_ptr(:,:)
379  integer(esmf_kind_i4), pointer :: mask_target_ptr(:,:)
380  integer(esmf_kind_i8), pointer :: landmask_target_ptr(:,:)
381  integer(esmf_kind_i8), allocatable :: mask_target_one_tile(:,:)
382  integer(esmf_kind_i8), allocatable :: water_target_one_tile(:,:)
383  integer(esmf_kind_i8), allocatable :: land_target_one_tile(:,:)
384  integer(esmf_kind_i8), pointer :: seamask_target_ptr(:,:)
385 
386  real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
387  real(esmf_kind_r8), allocatable :: data_one_tile2(:,:)
388  real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)
389  real(esmf_kind_r8), allocatable :: latitude_one_tile(:,:)
390  real(esmf_kind_r8), allocatable :: soil_type_target_grid_save(:,:)
391  real(esmf_kind_r8), pointer :: canopy_mc_target_ptr(:,:)
392  real(esmf_kind_r8), pointer :: c_d_target_ptr(:,:)
393  real(esmf_kind_r8), pointer :: c_0_target_ptr(:,:)
394  real(esmf_kind_r8), pointer :: d_conv_target_ptr(:,:)
395  real(esmf_kind_r8), pointer :: dt_cool_target_ptr(:,:)
396  real(esmf_kind_r8), pointer :: ifd_target_ptr(:,:)
397  real(esmf_kind_r8), pointer :: qrain_target_ptr(:,:)
398  real(esmf_kind_r8), pointer :: tref_target_ptr(:,:)
399  real(esmf_kind_r8), pointer :: w_d_target_ptr(:,:)
400  real(esmf_kind_r8), pointer :: w_0_target_ptr(:,:)
401  real(esmf_kind_r8), pointer :: xs_target_ptr(:,:)
402  real(esmf_kind_r8), pointer :: xt_target_ptr(:,:)
403  real(esmf_kind_r8), pointer :: xu_target_ptr(:,:)
404  real(esmf_kind_r8), pointer :: xv_target_ptr(:,:)
405  real(esmf_kind_r8), pointer :: xz_target_ptr(:,:)
406  real(esmf_kind_r8), pointer :: xtts_target_ptr(:,:)
407  real(esmf_kind_r8), pointer :: xzts_target_ptr(:,:)
408  real(esmf_kind_r8), pointer :: z_c_target_ptr(:,:)
409  real(esmf_kind_r8), pointer :: zm_target_ptr(:,:)
410  real(esmf_kind_r8), pointer :: seaice_depth_target_ptr(:,:)
411  real(esmf_kind_r8), pointer :: seaice_fract_target_ptr(:,:)
412  real(esmf_kind_r8), pointer :: seaice_skin_temp_target_ptr(:,:)
413  real(esmf_kind_r8), pointer :: skin_temp_target_ptr(:,:)
414  real(esmf_kind_r8), pointer :: snow_depth_target_ptr(:,:)
415  real(esmf_kind_r8), pointer :: snow_liq_equiv_target_ptr(:,:)
416  real(esmf_kind_r8), pointer :: soil_temp_target_ptr(:,:,:)
417  real(esmf_kind_r8), pointer :: soil_type_from_input_ptr(:,:)
418  real(esmf_kind_r8), pointer :: soil_type_target_ptr(:,:)
419  real(esmf_kind_r8), pointer :: soilm_tot_target_ptr(:,:,:)
420  real(esmf_kind_r8), pointer :: srflag_target_ptr(:,:)
421  real(esmf_kind_r8), pointer :: terrain_from_input_ptr(:,:)
422  real(esmf_kind_r8), pointer :: veg_type_target_ptr(:,:)
423  real(esmf_kind_r8), pointer :: z0_target_ptr(:,:)
424  real(esmf_kind_r8), pointer :: landmask_input_ptr(:,:)
425  real(esmf_kind_r8), pointer :: veg_type_input_ptr(:,:)
426  real(esmf_kind_r8), allocatable :: veg_type_target_one_tile(:,:)
427  real(esmf_kind_r8), pointer :: veg_greenness_target_ptr(:,:)
428  real(esmf_kind_r8), pointer :: min_veg_greenness_target_ptr(:,:)
429  real(esmf_kind_r8), pointer :: max_veg_greenness_target_ptr(:,:)
430  real(esmf_kind_r8), pointer :: lai_target_ptr(:,:)
431 
432  type(esmf_regridmethod_flag) :: method
433  type(esmf_routehandle) :: regrid_bl_no_mask
434  type(esmf_routehandle) :: regrid_all_land
435  type(esmf_routehandle) :: regrid_land
436  type(esmf_routehandle) :: regrid_landice
437  type(esmf_routehandle) :: regrid_nonland
438  type(esmf_routehandle) :: regrid_seaice
439  type(esmf_routehandle) :: regrid_water
440 
441 !-----------------------------------------------------------------------
442 ! Interpolate fieids that do not require 'masked' interpolation.
443 !-----------------------------------------------------------------------
444 
445  method=esmf_regridmethod_bilinear
446 
447  isrctermprocessing = 1
448 
449  print*,"- CALL FieldRegridStore FOR NON-MASKED BILINEAR INTERPOLATION."
450  call esmf_fieldregridstore(t2m_input_grid, &
451  t2m_target_grid, &
452  polemethod=esmf_polemethod_allavg, &
453  srctermprocessing=isrctermprocessing, &
454  routehandle=regrid_bl_no_mask, &
455  regridmethod=method, rc=rc)
456  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
457  call error_handler("IN FieldRegridStore", rc)
458 
459  print*,"- CALL Field_Regrid T2M."
460  call esmf_fieldregrid(t2m_input_grid, &
461  t2m_target_grid, &
462  routehandle=regrid_bl_no_mask, &
463  termorderflag=esmf_termorder_srcseq, rc=rc)
464  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
465  call error_handler("IN FieldRegrid", rc)
466 
467  print*,"- CALL Field_Regrid Q2M."
468  call esmf_fieldregrid(q2m_input_grid, &
469  q2m_target_grid, &
470  routehandle=regrid_bl_no_mask, &
471  termorderflag=esmf_termorder_srcseq, rc=rc)
472  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
473  call error_handler("IN FieldRegrid", rc)
474 
475  print*,"- CALL Field_Regrid TPRCP."
476  call esmf_fieldregrid(tprcp_input_grid, &
477  tprcp_target_grid, &
478  routehandle=regrid_bl_no_mask, &
479  termorderflag=esmf_termorder_srcseq, rc=rc)
480  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
481  call error_handler("IN FieldRegrid", rc)
482 
483  print*,"- CALL Field_Regrid F10M."
484  call esmf_fieldregrid(f10m_input_grid, &
485  f10m_target_grid, &
486  routehandle=regrid_bl_no_mask, &
487  termorderflag=esmf_termorder_srcseq, rc=rc)
488  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
489  call error_handler("IN FieldRegrid", rc)
490 
491  print*,"- CALL Field_Regrid FFMM."
492  call esmf_fieldregrid(ffmm_input_grid, &
493  ffmm_target_grid, &
494  routehandle=regrid_bl_no_mask, &
495  termorderflag=esmf_termorder_srcseq, rc=rc)
496  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
497  call error_handler("IN FieldRegrid", rc)
498 
499  print*,"- CALL Field_Regrid USTAR."
500  call esmf_fieldregrid(ustar_input_grid, &
501  ustar_target_grid, &
502  routehandle=regrid_bl_no_mask, &
503  termorderflag=esmf_termorder_srcseq, rc=rc)
504  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
505  call error_handler("IN FieldRegrid", rc)
506 
507  print*,"- CALL Field_Regrid SRFLAG."
508  call esmf_fieldregrid(srflag_input_grid, &
509  srflag_target_grid, &
510  routehandle=regrid_bl_no_mask, &
511  termorderflag=esmf_termorder_srcseq, rc=rc)
512  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
513  call error_handler("IN FieldRegrid", rc)
514 
515  print*,"- CALL FieldGet FOR SRFLAG."
516  call esmf_fieldget(srflag_target_grid, &
517  farrayptr=srflag_target_ptr, rc=rc)
518  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
519  call error_handler("IN FieldGet", rc)
520 
521 !-----------------------------------------------------------------------
522 ! This is a flag field. Using neighbor was expensive. So use
523 ! bilinear and 'nint'.
524 !-----------------------------------------------------------------------
525 
526  srflag_target_ptr = nint(srflag_target_ptr)
527 
528  print*,"- CALL FieldRegridRelease."
529  call esmf_fieldregridrelease(routehandle=regrid_bl_no_mask, rc=rc)
530  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
531  call error_handler("IN FieldRegridRelease", rc)
532 
533 !-----------------------------------------------------------------------
534 ! First, set the mask on the target and input grids.
535 !-----------------------------------------------------------------------
536 
537  print*,"- CALL GridAddItem FOR TARGET GRID."
538  call esmf_gridadditem(target_grid, &
539  itemflag=esmf_griditem_mask, &
540  staggerloc=esmf_staggerloc_center, rc=rc)
541  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
542  call error_handler("IN GridAddItem", rc)
543 
544  print*,"- CALL GridGetItem FOR TARGET GRID."
545  call esmf_gridgetitem(target_grid, &
546  itemflag=esmf_griditem_mask, &
547  farrayptr=mask_target_ptr, rc=rc)
548  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
549  call error_handler("IN GridGetItem", rc)
550 
551  print*,"- CALL FieldGet FOR TARGET GRID SEAMASK."
552  call esmf_fieldget(seamask_target_grid, &
553  computationallbound=clb_target, &
554  computationalubound=cub_target, &
555  farrayptr=seamask_target_ptr, rc=rc)
556  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
557  call error_handler("IN FieldGet", rc)
558 
559  print*,"- CALL FieldGet FOR TARGET GRID LANDMASK."
560  call esmf_fieldget(landmask_target_grid, &
561  farrayptr=landmask_target_ptr, rc=rc)
562  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
563  call error_handler("IN FieldGet", rc)
564 
565  print*,"- CALL GridAddItem FOR INPUT GRID SEAMASK."
566  call esmf_gridadditem(input_grid, &
567  itemflag=esmf_griditem_mask, &
568  staggerloc=esmf_staggerloc_center, rc=rc)
569  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
570  call error_handler("IN GridAddItem", rc)
571 
572  print*,"- CALL FieldGet FOR INPUT GRID LANDMASK."
573  call esmf_fieldget(landsea_mask_input_grid, &
574  farrayptr=landmask_input_ptr, rc=rc)
575  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
576  call error_handler("IN FieldGet", rc)
577 
578  print*,"- CALL GridGetItem FOR INPUT GRID LANDMASK."
579  call esmf_gridgetitem(input_grid, &
580  itemflag=esmf_griditem_mask, &
581  farrayptr=mask_input_ptr, rc=rc)
582  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
583  call error_handler("IN GridGetItem", rc)
584 
585  if (localpet == 0) then
586  allocate(data_one_tile(i_target,j_target))
587  allocate(data_one_tile_3d(i_target,j_target,lsoil_target))
588  allocate(mask_target_one_tile(i_target,j_target))
589  allocate(soil_type_target_grid_save(i_target,j_target))
590  else
591  allocate(data_one_tile(0,0))
592  allocate(data_one_tile_3d(0,0,0))
593  allocate(mask_target_one_tile(0,0))
594  allocate(soil_type_target_grid_save(0,0))
595  endif
596 
597  !-----------------------------------------------------------------------
598  ! Interpolate vegetation type to target grid if chosen in namelist and terrain
599  ! for use in replacing isolated bad terrain values
600  !-----------------------------------------------------------------------
601 
602  method=esmf_regridmethod_nearest_stod
603 
604  isrctermprocessing = 1
605 
606  mask_input_ptr = 0
607  where (nint(landmask_input_ptr) == 1) mask_input_ptr = 1
608 
609  mask_target_ptr = 0
610  where (landmask_target_ptr == 1) mask_target_ptr = 1
611 
612  print*,"- CALL FieldCreate FOR TERRAIN FROM INPUT GRID LAND."
613  terrain_from_input_grid_land = esmf_fieldcreate(target_grid, &
614  typekind=esmf_typekind_r8, &
615  staggerloc=esmf_staggerloc_center, rc=rc)
616  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
617  call error_handler("IN FieldCreate", rc)
618 
619  print*,"- CALL FieldRegridStore for land fields."
620  call esmf_fieldregridstore(terrain_input_grid, &
621  terrain_from_input_grid_land, &
622  srcmaskvalues=(/0/), &
623  dstmaskvalues=(/0/), &
624  polemethod=esmf_polemethod_none, &
625  srctermprocessing=isrctermprocessing, &
626  unmappedaction=esmf_unmappedaction_ignore, &
627  normtype=esmf_normtype_fracarea, &
628  routehandle=regrid_all_land, &
629  regridmethod=method, &
630  unmappeddstlist=unmapped_ptr, rc=rc)
631  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
632  call error_handler("IN FieldRegridStore", rc)
633 
634  print*,"- CALL Field_Regrid TERRAIN."
635  call esmf_fieldregrid(terrain_input_grid, &
636  terrain_from_input_grid_land, &
637  routehandle=regrid_all_land, &
638  termorderflag=esmf_termorder_srcseq, rc=rc)
639  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
640  call error_handler("IN FieldRegrid", rc)
641 
642  print*,"- CALL FieldGet FOR terrain from input grid at land."
643  call esmf_fieldget(terrain_from_input_grid_land, &
644  farrayptr=terrain_from_input_ptr, rc=rc)
645  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
646  call error_handler("IN FieldGet", rc)
647 
648  l = lbound(unmapped_ptr)
649  u = ubound(unmapped_ptr)
650 
651  do ij = l(1), u(1)
652  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
653  terrain_from_input_ptr(i,j) = -9999.9
654  enddo
655  nullify(terrain_from_input_ptr)
656 
657  do tile = 1, num_tiles_target_grid
658 
659  print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
660  call esmf_fieldgather(landmask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
661  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
662  call error_handler("IN FieldGather", rc)
663 
664  print*,"- CALL FieldGather FOR TERRAIN FROM INPUT GRID: ", tile
665  call esmf_fieldgather(terrain_from_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
666  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
667  call error_handler("IN FieldGather", rc)
668 
669  if (localpet == 0) then
670  allocate(land_target_one_tile(i_target,j_target))
671  land_target_one_tile = 0
672  where(mask_target_one_tile == 1) land_target_one_tile = 1
673  call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 7)
674  deallocate(land_target_one_tile)
675  endif
676 
677  print*,"- CALL FieldScatter FOR TERRAIN FROM INPUT GRID: ", tile
678  call esmf_fieldscatter(terrain_from_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
679  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
680  call error_handler("IN FieldScatter", rc)
681  enddo
682 
683  if(.not. vgtyp_from_climo) then
684 
685  print*,"- CALL FieldRegrid VEG TYPE."
686  call esmf_fieldregrid(veg_type_input_grid, &
687  veg_type_target_grid, &
688  routehandle=regrid_all_land, &
689  termorderflag=esmf_termorder_srcseq, rc=rc)
690  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
691  call error_handler("IN FieldRegrid", rc)
692 
693  print*,"- CALL FieldGet FOR TARGET grid veg type."
694  call esmf_fieldget(veg_type_target_grid, &
695  farrayptr=veg_type_target_ptr, rc=rc)
696  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
697  call error_handler("IN FieldGet", rc)
698 
699  l = lbound(unmapped_ptr)
700  u = ubound(unmapped_ptr)
701 
702  do ij = l(1), u(1)
703  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
704  veg_type_target_ptr(i,j) = -9999.9
705  enddo
706 
707  do tile = 1, num_tiles_target_grid
708  print*,"- CALL FieldGather FOR TARGET GRID VEG TYPE TILE: ", tile
709  call esmf_fieldgather(veg_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
710  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
711  call error_handler("IN FieldGather", rc)
712 
713  print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
714  call esmf_fieldgather(landmask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
715  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
716  call error_handler("IN FieldGather", rc)
717 
718  if (localpet == 0) then
719  allocate(land_target_one_tile(i_target,j_target))
720  land_target_one_tile = 0
721  where(mask_target_one_tile == 1) land_target_one_tile = 1
722  call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 225)
723  deallocate(land_target_one_tile)
724  endif
725 
726  print*,"- CALL FieldScatter FOR TARGET GRID VEG TYPE: ", tile
727  call esmf_fieldscatter(veg_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
728  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
729  call error_handler("IN FieldScatter", rc)
730  enddo
731  nullify(veg_type_target_ptr)
732  endif
733  print*,"- CALL FieldRegridRelease."
734  call esmf_fieldregridrelease(routehandle=regrid_all_land, rc=rc)
735  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
736  call error_handler("IN FieldRegridRelease", rc)
737 
738 !-----------------------------------------------------------------------
739 ! Next, determine the sea ice fraction on target grid.
740 ! Interpolate.
741 !-----------------------------------------------------------------------
742 
743  mask_input_ptr = 1
744  where (nint(landmask_input_ptr) == 1) mask_input_ptr = 0
745 
746  mask_target_ptr = seamask_target_ptr
747 
748  method=esmf_regridmethod_conserve
749 
750  isrctermprocessing = 1
751 
752  print*,"- CALL FieldRegridStore for sea ice fraction."
753  call esmf_fieldregridstore(seaice_fract_input_grid, &
754  seaice_fract_target_grid, &
755  srcmaskvalues=(/0/), &
756  dstmaskvalues=(/0/), &
757  polemethod=esmf_polemethod_none, &
758  srctermprocessing=isrctermprocessing, &
759  unmappedaction=esmf_unmappedaction_ignore, &
760  normtype=esmf_normtype_fracarea, &
761  routehandle=regrid_nonland, &
762  regridmethod=method, &
763  unmappeddstlist=unmapped_ptr, rc=rc)
764  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
765  call error_handler("IN FieldRegridStore", rc)
766 
767  print*,"- CALL Field_Regrid for sea ice fraction."
768  call esmf_fieldregrid(seaice_fract_input_grid, &
769  seaice_fract_target_grid, &
770  routehandle=regrid_nonland, &
771  termorderflag=esmf_termorder_srcseq, rc=rc)
772  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
773  call error_handler("IN FieldRegrid", rc)
774 
775  print*,"- CALL FieldGet FOR TARGET grid sea ice fraction."
776  call esmf_fieldget(seaice_fract_target_grid, &
777  farrayptr=seaice_fract_target_ptr, rc=rc)
778  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
779  call error_handler("IN FieldGet", rc)
780 
781  l = lbound(unmapped_ptr)
782  u = ubound(unmapped_ptr)
783 
784  do ij = l(1), u(1)
785  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
786  seaice_fract_target_ptr(i,j) = -9999.9 ! flag value for missing point
787  ! which will be replaced in routine
788  ! "search".
789  enddo
790 
791  if (localpet == 0) then
792  allocate(latitude_one_tile(i_target,j_target))
793  else
794  allocate(latitude_one_tile(0,0))
795  endif
796 
797  do tile = 1, num_tiles_target_grid
798 
799  print*,"- CALL FieldGather FOR TARGET GRID SEAICE FRACTION TILE: ", tile
800  call esmf_fieldgather(seaice_fract_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
801  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
802  call error_handler("IN FieldGather", rc)
803 
804  print*,"- CALL FieldGather FOR TARGET GRID MASK TILE: ", tile
805  call esmf_fieldgather(seamask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
806  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
807  call error_handler("IN FieldGather", rc)
808 
809  print*,"- CALL FieldGather FOR TARGET LATITUDE TILE: ", tile
810  call esmf_fieldgather(latitude_target_grid, latitude_one_tile, rootpet=0, tile=tile, rc=rc)
811  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
812  call error_handler("IN FieldGather", rc)
813 
814  if (localpet == 0) then
815  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 91, &
816  latitude=latitude_one_tile)
817  endif
818 
819  print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
820  call esmf_fieldgather(landmask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
821  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
822  call error_handler("IN FieldGather", rc)
823 
824 
825  if (localpet == 0) then
826  do j = 1, j_target
827  do i = 1, i_target
828  if (data_one_tile(i,j) > 1.0_esmf_kind_r8) then
829  data_one_tile(i,j) = 1.0_esmf_kind_r8
830  endif
831  if (data_one_tile(i,j) < 0.15_esmf_kind_r8) data_one_tile(i,j) = 0.0_esmf_kind_r8
832  if (data_one_tile(i,j) >= 0.15_esmf_kind_r8) mask_target_one_tile(i,j) = 2
833  enddo
834  enddo
835  endif
836 
837  print*,"- CALL FieldScatter FOR TARGET GRID SEAICE FRACTION TILE: ", tile
838  call esmf_fieldscatter(seaice_fract_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
839  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
840  call error_handler("IN FieldScatter", rc)
841 
842  print*,"- CALL FieldScatter FOR TARGET LANDMASK TILE: ", tile
843  call esmf_fieldscatter(landmask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
844  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
845  call error_handler("IN FieldScatter", rc)
846 
847  enddo
848 
849  deallocate(latitude_one_tile)
850 
851  print*,"- CALL FieldRegridRelease."
852  call esmf_fieldregridrelease(routehandle=regrid_nonland, rc=rc)
853  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
854  call error_handler("IN FieldRegridRelease", rc)
855 
856 !---------------------------------------------------------------------------------------------
857 ! Now interpolate other sea ice related fields. Since we know what points are ice on
858 ! the target grid, reset the target grid mask.
859 !---------------------------------------------------------------------------------------------
860 
861  mask_input_ptr = 0
862  where (nint(landmask_input_ptr) == 2) mask_input_ptr = 1
863 
864  print*,"- CALL FieldGet FOR TARGET land sea mask."
865  call esmf_fieldget(landmask_target_grid, &
866  farrayptr=landmask_target_ptr, rc=rc)
867  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
868  call error_handler("IN FieldGet", rc)
869 
870  mask_target_ptr = 0
871  do j = clb_target(2), cub_target(2)
872  do i = clb_target(1), cub_target(1)
873  if (landmask_target_ptr(i,j) == 2) mask_target_ptr(i,j) = 1
874  enddo
875  enddo
876 
877  method=esmf_regridmethod_nearest_stod
878  isrctermprocessing = 1
879 
880  print*,"- CALL FieldRegridStore for 3d seaice fields."
881  call esmf_fieldregridstore(soil_temp_input_grid, &
882  soil_temp_target_grid, &
883  srcmaskvalues=(/0/), &
884  dstmaskvalues=(/0/), &
885  polemethod=esmf_polemethod_none, &
886  srctermprocessing=isrctermprocessing, &
887  unmappedaction=esmf_unmappedaction_ignore, &
888  normtype=esmf_normtype_fracarea, &
889  routehandle=regrid_seaice, &
890  regridmethod=method, &
891  unmappeddstlist=unmapped_ptr, rc=rc)
892  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
893  call error_handler("IN FieldRegridStore", rc)
894 
895  print*,"- CALL Field_Regrid for soil temperature over seaice."
896  call esmf_fieldregrid(soil_temp_input_grid, &
897  soil_temp_target_grid, &
898  routehandle=regrid_seaice, &
899  termorderflag=esmf_termorder_srcseq, rc=rc)
900  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
901  call error_handler("IN FieldRegrid", rc)
902 
903  print*,"- CALL FieldGet FOR TARGET grid soil temperature over seaice."
904  call esmf_fieldget(soil_temp_target_grid, &
905  farrayptr=soil_temp_target_ptr, rc=rc)
906  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
907  call error_handler("IN FieldGet", rc)
908 
909  print*,"- CALL Field_Regrid for sea ice depth."
910  call esmf_fieldregrid(seaice_depth_input_grid, &
911  seaice_depth_target_grid, &
912  routehandle=regrid_seaice, &
913  termorderflag=esmf_termorder_srcseq, rc=rc)
914  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
915  call error_handler("IN FieldRegrid", rc)
916 
917  print*,"- CALL FieldGet FOR TARGET grid sea ice depth."
918  call esmf_fieldget(seaice_depth_target_grid, &
919  farrayptr=seaice_depth_target_ptr, rc=rc)
920  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
921  call error_handler("IN FieldGet", rc)
922 
923  print*,"- CALL Field_Regrid for snow depth."
924  call esmf_fieldregrid(snow_depth_input_grid, &
925  snow_depth_target_grid, &
926  routehandle=regrid_seaice, &
927  termorderflag=esmf_termorder_srcseq, rc=rc)
928  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
929  call error_handler("IN FieldRegrid", rc)
930 
931  print*,"- CALL FieldGet FOR TARGET grid snow depth."
932  call esmf_fieldget(snow_depth_target_grid, &
933  farrayptr=snow_depth_target_ptr, rc=rc)
934  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
935  call error_handler("IN FieldGet", rc)
936 
937  print*,"- CALL Field_Regrid for snow liq equiv."
938  call esmf_fieldregrid(snow_liq_equiv_input_grid, &
939  snow_liq_equiv_target_grid, &
940  routehandle=regrid_seaice, &
941  termorderflag=esmf_termorder_srcseq, rc=rc)
942  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
943  call error_handler("IN FieldRegrid", rc)
944 
945  print*,"- CALL FieldGet FOR TARGET grid snow liq equiv."
946  call esmf_fieldget(snow_liq_equiv_target_grid, &
947  farrayptr=snow_liq_equiv_target_ptr, rc=rc)
948  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
949  call error_handler("IN FieldGet", rc)
950 
951  print*,"- CALL Field_Regrid for sea ice skin temp."
952  call esmf_fieldregrid(seaice_skin_temp_input_grid, &
953  seaice_skin_temp_target_grid, &
954  routehandle=regrid_seaice, &
955  termorderflag=esmf_termorder_srcseq, rc=rc)
956  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
957  call error_handler("IN FieldRegrid", rc)
958 
959  print*,"- CALL FieldGet FOR TARGET grid sea ice skin temp."
960  call esmf_fieldget(seaice_skin_temp_target_grid, &
961  farrayptr=seaice_skin_temp_target_ptr, rc=rc)
962  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
963  call error_handler("IN FieldGet", rc)
964 
965  l = lbound(unmapped_ptr)
966  u = ubound(unmapped_ptr)
967 
968  do ij = l(1), u(1)
969  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
970  seaice_depth_target_ptr(i,j) = -9999.9
971  snow_depth_target_ptr(i,j) = -9999.9
972  snow_liq_equiv_target_ptr(i,j) = -9999.9
973  seaice_skin_temp_target_ptr(i,j) = -9999.9
974  soil_temp_target_ptr(i,j,:) = -9999.9
975  enddo
976 
977  do tile = 1, num_tiles_target_grid
978 
979  print*,"- CALL FieldGather FOR TARGET GRID SEAICE DEPTH TILE: ", tile
980  call esmf_fieldgather(seaice_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
981  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
982  call error_handler("IN FieldGather", rc)
983 
984  print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
985  call esmf_fieldgather(landmask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
986  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
987  call error_handler("IN FieldGather", rc)
988 
989  if (localpet == 0) then
990  ! I don't think is needed anymore with the more recent fixes to fill values in input_data
991  !if (count(landmask_target_ptr == 2) == 0) data_one_tile(:,:) =0.0_esmf_kind_r8
992 
993  where(mask_target_one_tile == 1) mask_target_one_tile = 0
994  where(mask_target_one_tile == 2) mask_target_one_tile = 1
995  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 92)
996  endif
997 
998  print*,"- CALL FieldScatter FOR TARGET GRID SEAICE DEPTH TILE: ", tile
999  call esmf_fieldscatter(seaice_depth_target_grid, data_one_tile, rootpet=0, tile=tile, 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  print*,"- CALL FieldGather FOR TARGET GRID SNOW DEPTH TILE: ", tile
1004  call esmf_fieldgather(snow_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1005  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1006  call error_handler("IN FieldGather", rc)
1007 
1008  if (localpet == 0) then
1009  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 66)
1010  endif
1011 
1012  print*,"- CALL FieldScatter FOR TARGET GRID SNOW DEPTH TILE: ", tile
1013  call esmf_fieldscatter(snow_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1014  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1015  call error_handler("IN FieldScatter", rc)
1016 
1017  print*,"- CALL FieldGather FOR TARGET GRID SNOW LIQ EQUIV TILE: ", tile
1018  call esmf_fieldgather(snow_liq_equiv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1019  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1020  call error_handler("IN FieldGather", rc)
1021 
1022  if (localpet == 0) then
1023  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 65)
1024  endif
1025 
1026  print*,"- CALL FieldScatter FOR TARGET GRID SNOW LIQ EQUIV TILE: ", tile
1027  call esmf_fieldscatter(snow_liq_equiv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1028  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1029  call error_handler("IN FieldScatter", rc)
1030 
1031  print*,"- CALL FieldGather FOR TARGET GRID SEAICE SKIN TEMP: ", tile
1032  call esmf_fieldgather(seaice_skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1033  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1034  call error_handler("IN FieldGather", rc)
1035 
1036  if (localpet == 0) then
1037  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 21)
1038  endif
1039 
1040  print*,"- CALL FieldScatter FOR TARGET GRID SEAICE SKIN TEMP: ", tile
1041  call esmf_fieldscatter(seaice_skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1042  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1043  call error_handler("IN FieldScatter", rc)
1044 
1045  print*,"- CALL FieldGather FOR TARGET GRID SEAICE COLUMN TEMP: ", tile
1046  call esmf_fieldgather(soil_temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
1047  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1048  call error_handler("IN FieldGather", rc)
1049 
1050  if (localpet == 0) then
1051  do j = 1, lsoil_target
1052  data_one_tile = data_one_tile_3d(:,:,j)
1053  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 21)
1054  data_one_tile_3d(:,:,j) = data_one_tile
1055  enddo
1056  endif
1057 
1058  print*,"- CALL FieldScatter FOR TARGET GRID SEAICE COLUMN TEMP: ", tile
1059  call esmf_fieldscatter(soil_temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
1060  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1061  call error_handler("IN FieldScatter", rc)
1062  enddo
1063 
1064  print*,"- CALL FieldRegridRelease."
1065  call esmf_fieldregridrelease(routehandle=regrid_seaice, rc=rc)
1066  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1067  call error_handler("IN FieldRegridRelease", rc)
1068 
1069 !---------------------------------------------------------------------------------------------
1070 ! Now interpolate water fields.
1071 !---------------------------------------------------------------------------------------------
1072 
1073  mask_input_ptr = 0
1074  where (nint(landmask_input_ptr) == 0) mask_input_ptr = 1
1075 
1076  mask_target_ptr = 0
1077  where (landmask_target_ptr == 0) mask_target_ptr = 1
1078 
1079  method=esmf_regridmethod_conserve
1080  isrctermprocessing = 1
1081 
1082  print*,"- CALL FieldRegridStore for water fields."
1083  call esmf_fieldregridstore(skin_temp_input_grid, &
1084  skin_temp_target_grid, &
1085  srcmaskvalues=(/0/), &
1086  dstmaskvalues=(/0/), &
1087  polemethod=esmf_polemethod_none, &
1088  srctermprocessing=isrctermprocessing, &
1089  unmappedaction=esmf_unmappedaction_ignore, &
1090  normtype=esmf_normtype_fracarea, &
1091  routehandle=regrid_water, &
1092  regridmethod=method, &
1093  unmappeddstlist=unmapped_ptr, rc=rc)
1094  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1095  call error_handler("IN FieldRegridStore", rc)
1096 
1097  print*,"- CALL Field_Regrid for skin temperature over water."
1098  call esmf_fieldregrid(skin_temp_input_grid, &
1099  skin_temp_target_grid, &
1100  routehandle=regrid_water, &
1101  termorderflag=esmf_termorder_srcseq, rc=rc)
1102  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1103  call error_handler("IN FieldRegrid", rc)
1104 
1105  print*,"- CALL FieldGet FOR TARGET skin temperature."
1106  call esmf_fieldget(skin_temp_target_grid, &
1107  farrayptr=skin_temp_target_ptr, rc=rc)
1108  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1109  call error_handler("IN FieldGet", rc)
1110 
1111  print*,"- CALL Field_Regrid for z0 over water."
1112  call esmf_fieldregrid(z0_input_grid, &
1113  z0_target_grid, &
1114  routehandle=regrid_water, &
1115  termorderflag=esmf_termorder_srcseq, rc=rc)
1116  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1117  call error_handler("IN FieldRegrid", rc)
1118 
1119  print*,"- CALL FieldGet FOR TARGET z0."
1120  call esmf_fieldget(z0_target_grid, &
1121  farrayptr=z0_target_ptr, rc=rc)
1122  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1123  call error_handler("IN FieldGet", rc)
1124 
1125  l = lbound(unmapped_ptr)
1126  u = ubound(unmapped_ptr)
1127 
1128  do ij = l(1), u(1)
1129  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
1130  skin_temp_target_ptr(i,j) = -9999.9
1131  z0_target_ptr(i,j) = -9999.9
1132  enddo
1133 
1134  if (convert_nst) then
1135 
1136  print*,"- CALL Field_Regrid for c_d over water."
1137  call esmf_fieldregrid(c_d_input_grid, &
1138  c_d_target_grid, &
1139  routehandle=regrid_water, &
1140  termorderflag=esmf_termorder_srcseq, rc=rc)
1141  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1142  call error_handler("IN FieldRegrid", rc)
1143 
1144  print*,"- CALL Field_Regrid for c_0 over water."
1145  call esmf_fieldregrid(c_0_input_grid, &
1146  c_0_target_grid, &
1147  routehandle=regrid_water, &
1148  termorderflag=esmf_termorder_srcseq, rc=rc)
1149  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1150  call error_handler("IN FieldRegrid", rc)
1151 
1152  print*,"- CALL Field_Regrid for d_conv over water."
1153  call esmf_fieldregrid(d_conv_input_grid, &
1154  d_conv_target_grid, &
1155  routehandle=regrid_water, &
1156  termorderflag=esmf_termorder_srcseq, rc=rc)
1157  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1158  call error_handler("IN FieldRegrid", rc)
1159 
1160  print*,"- CALL Field_Regrid for dt_cool over water."
1161  call esmf_fieldregrid(dt_cool_input_grid, &
1162  dt_cool_target_grid, &
1163  routehandle=regrid_water, &
1164  termorderflag=esmf_termorder_srcseq, rc=rc)
1165  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1166  call error_handler("IN FieldRegrid", rc)
1167 
1168  print*,"- CALL Field_Regrid for ifd over water."
1169  call esmf_fieldregrid(ifd_input_grid, &
1170  ifd_target_grid, &
1171  routehandle=regrid_water, &
1172  termorderflag=esmf_termorder_srcseq, rc=rc)
1173  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1174  call error_handler("IN FieldRegrid", rc)
1175 
1176  print*,"- CALL Field_Regrid for qrain over water."
1177  call esmf_fieldregrid(qrain_input_grid, &
1178  qrain_target_grid, &
1179  routehandle=regrid_water, &
1180  termorderflag=esmf_termorder_srcseq, rc=rc)
1181  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1182  call error_handler("IN FieldRegrid", rc)
1183 
1184  print*,"- CALL Field_Regrid for tref over water."
1185  call esmf_fieldregrid(tref_input_grid, &
1186  tref_target_grid, &
1187  routehandle=regrid_water, &
1188  termorderflag=esmf_termorder_srcseq, rc=rc)
1189  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1190  call error_handler("IN FieldRegrid", rc)
1191 
1192  print*,"- CALL Field_Regrid for w_d over water."
1193  call esmf_fieldregrid(w_d_input_grid, &
1194  w_d_target_grid, &
1195  routehandle=regrid_water, &
1196  termorderflag=esmf_termorder_srcseq, rc=rc)
1197  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1198  call error_handler("IN FieldRegrid", rc)
1199 
1200  print*,"- CALL Field_Regrid for w_0 over water."
1201  call esmf_fieldregrid(w_0_input_grid, &
1202  w_0_target_grid, &
1203  routehandle=regrid_water, &
1204  termorderflag=esmf_termorder_srcseq, rc=rc)
1205  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1206  call error_handler("IN FieldRegrid", rc)
1207 
1208  print*,"- CALL Field_Regrid for xs over water."
1209  call esmf_fieldregrid(xs_input_grid, &
1210  xs_target_grid, &
1211  routehandle=regrid_water, &
1212  termorderflag=esmf_termorder_srcseq, rc=rc)
1213  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1214  call error_handler("IN FieldRegrid", rc)
1215 
1216  print*,"- CALL Field_Regrid for xt over water."
1217  call esmf_fieldregrid(xt_input_grid, &
1218  xt_target_grid, &
1219  routehandle=regrid_water, &
1220  termorderflag=esmf_termorder_srcseq, rc=rc)
1221  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1222  call error_handler("IN FieldRegrid", rc)
1223 
1224  print*,"- CALL Field_Regrid for xu over water."
1225  call esmf_fieldregrid(xu_input_grid, &
1226  xu_target_grid, &
1227  routehandle=regrid_water, &
1228  termorderflag=esmf_termorder_srcseq, rc=rc)
1229  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1230  call error_handler("IN FieldRegrid", rc)
1231 
1232  print*,"- CALL Field_Regrid for xv over water."
1233  call esmf_fieldregrid(xv_input_grid, &
1234  xv_target_grid, &
1235  routehandle=regrid_water, &
1236  termorderflag=esmf_termorder_srcseq, rc=rc)
1237  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1238  call error_handler("IN FieldRegrid", rc)
1239 
1240  print*,"- CALL Field_Regrid for xz over water."
1241  call esmf_fieldregrid(xz_input_grid, &
1242  xz_target_grid, &
1243  routehandle=regrid_water, &
1244  termorderflag=esmf_termorder_srcseq, rc=rc)
1245  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1246  call error_handler("IN FieldRegrid", rc)
1247 
1248  print*,"- CALL Field_Regrid for xtts over water."
1249  call esmf_fieldregrid(xtts_input_grid, &
1250  xtts_target_grid, &
1251  routehandle=regrid_water, &
1252  termorderflag=esmf_termorder_srcseq, rc=rc)
1253  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1254  call error_handler("IN FieldRegrid", rc)
1255 
1256  print*,"- CALL Field_Regrid for xzts over water."
1257  call esmf_fieldregrid(xzts_input_grid, &
1258  xzts_target_grid, &
1259  routehandle=regrid_water, &
1260  termorderflag=esmf_termorder_srcseq, rc=rc)
1261  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1262  call error_handler("IN FieldRegrid", rc)
1263 
1264  print*,"- CALL Field_Regrid for z_c over water."
1265  call esmf_fieldregrid(z_c_input_grid, &
1266  z_c_target_grid, &
1267  routehandle=regrid_water, &
1268  termorderflag=esmf_termorder_srcseq, rc=rc)
1269  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1270  call error_handler("IN FieldRegrid", rc)
1271 
1272  print*,"- CALL Field_Regrid for zm over water."
1273  call esmf_fieldregrid(zm_input_grid, &
1274  zm_target_grid, &
1275  routehandle=regrid_water, &
1276  termorderflag=esmf_termorder_srcseq, rc=rc)
1277  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1278  call error_handler("IN FieldRegrid", rc)
1279 
1280 ! Tag unmapped points
1281 
1282  print*,"- CALL FieldGet FOR TARGET c_d."
1283  call esmf_fieldget(c_d_target_grid, &
1284  farrayptr=c_d_target_ptr, rc=rc)
1285  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1286  call error_handler("IN FieldGet", rc)
1287 
1288  print*,"- CALL FieldGet FOR TARGET c_0."
1289  call esmf_fieldget(c_0_target_grid, &
1290  farrayptr=c_0_target_ptr, rc=rc)
1291  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1292  call error_handler("IN FieldGet", rc)
1293 
1294  print*,"- CALL FieldGet FOR TARGET d_conv."
1295  call esmf_fieldget(d_conv_target_grid, &
1296  farrayptr=d_conv_target_ptr, rc=rc)
1297  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1298  call error_handler("IN FieldGet", rc)
1299 
1300  print*,"- CALL FieldGet FOR TARGET dt_cool."
1301  call esmf_fieldget(dt_cool_target_grid, &
1302  farrayptr=dt_cool_target_ptr, rc=rc)
1303  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1304  call error_handler("IN FieldGet", rc)
1305 
1306  print*,"- CALL FieldGet FOR TARGET ifd."
1307  call esmf_fieldget(ifd_target_grid, &
1308  farrayptr=ifd_target_ptr, rc=rc)
1309  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1310  call error_handler("IN FieldGet", rc)
1311 
1312  ifd_target_ptr = float(nint(ifd_target_ptr))
1313 
1314  print*,"- CALL FieldGet FOR TARGET qrain."
1315  call esmf_fieldget(qrain_target_grid, &
1316  farrayptr=qrain_target_ptr, rc=rc)
1317  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1318  call error_handler("IN FieldGet", rc)
1319 
1320  print*,"- CALL FieldGet FOR TARGET tref."
1321  call esmf_fieldget(tref_target_grid, &
1322  farrayptr=tref_target_ptr, rc=rc)
1323  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1324  call error_handler("IN FieldGet", rc)
1325 
1326  print*,"- CALL FieldGet FOR TARGET w_d."
1327  call esmf_fieldget(w_d_target_grid, &
1328  farrayptr=w_d_target_ptr, rc=rc)
1329  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1330  call error_handler("IN FieldGet", rc)
1331 
1332  print*,"- CALL FieldGet FOR TARGET w_0."
1333  call esmf_fieldget(w_0_target_grid, &
1334  farrayptr=w_0_target_ptr, rc=rc)
1335  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1336  call error_handler("IN FieldGet", rc)
1337 
1338  print*,"- CALL FieldGet FOR TARGET xs."
1339  call esmf_fieldget(xs_target_grid, &
1340  farrayptr=xs_target_ptr, rc=rc)
1341  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1342  call error_handler("IN FieldGet", rc)
1343 
1344  print*,"- CALL FieldGet FOR TARGET xt."
1345  call esmf_fieldget(xt_target_grid, &
1346  farrayptr=xt_target_ptr, rc=rc)
1347  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1348  call error_handler("IN FieldGet", rc)
1349 
1350  print*,"- CALL FieldGet FOR TARGET xu."
1351  call esmf_fieldget(xu_target_grid, &
1352  farrayptr=xu_target_ptr, rc=rc)
1353  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1354  call error_handler("IN FieldGet", rc)
1355 
1356  print*,"- CALL FieldGet FOR TARGET xv."
1357  call esmf_fieldget(xv_target_grid, &
1358  farrayptr=xv_target_ptr, rc=rc)
1359  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1360  call error_handler("IN FieldGet", rc)
1361 
1362  print*,"- CALL FieldGet FOR TARGET xz."
1363  call esmf_fieldget(xz_target_grid, &
1364  farrayptr=xz_target_ptr, rc=rc)
1365  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1366  call error_handler("IN FieldGet", rc)
1367 
1368  print*,"- CALL FieldGet FOR TARGET xtts."
1369  call esmf_fieldget(xtts_target_grid, &
1370  farrayptr=xtts_target_ptr, rc=rc)
1371  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1372  call error_handler("IN FieldGet", rc)
1373 
1374  print*,"- CALL FieldGet FOR TARGET xzts."
1375  call esmf_fieldget(xzts_target_grid, &
1376  farrayptr=xzts_target_ptr, rc=rc)
1377  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1378  call error_handler("IN FieldGet", rc)
1379 
1380  print*,"- CALL FieldGet FOR TARGET z_c."
1381  call esmf_fieldget(z_c_target_grid, &
1382  farrayptr=z_c_target_ptr, rc=rc)
1383  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1384  call error_handler("IN FieldGet", rc)
1385 
1386  print*,"- CALL FieldGet FOR TARGET zm."
1387  call esmf_fieldget(zm_target_grid, &
1388  farrayptr=zm_target_ptr, rc=rc)
1389  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1390  call error_handler("IN FieldGet", rc)
1391 
1392  do ij = l(1), u(1)
1393  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
1394  c_d_target_ptr(i,j) = -9999.9
1395  c_0_target_ptr(i,j) = -9999.9
1396  d_conv_target_ptr(i,j) = -9999.9
1397  dt_cool_target_ptr(i,j) = -9999.9
1398  ifd_target_ptr(i,j) = -9999.9
1399  qrain_target_ptr(i,j) = -9999.9
1400  tref_target_ptr(i,j) = -9999.9
1401  w_d_target_ptr(i,j) = -9999.9
1402  w_0_target_ptr(i,j) = -9999.9
1403  xs_target_ptr(i,j) = -9999.9
1404  xt_target_ptr(i,j) = -9999.9
1405  xu_target_ptr(i,j) = -9999.9
1406  xv_target_ptr(i,j) = -9999.9
1407  xz_target_ptr(i,j) = -9999.9
1408  xtts_target_ptr(i,j) = -9999.9
1409  xzts_target_ptr(i,j) = -9999.9
1410  z_c_target_ptr(i,j) = -9999.9
1411  zm_target_ptr(i,j) = -9999.9
1412  enddo
1413 
1414  endif
1415 
1416  if (localpet == 0) then
1417  allocate(latitude_one_tile(i_target,j_target))
1418  else
1419  allocate(latitude_one_tile(0,0))
1420  endif
1421 
1422  do tile = 1, num_tiles_target_grid
1423 
1424 ! skin temp
1425 
1426  print*,"- CALL FieldGather FOR TARGET GRID SKIN TEMPERATURE TILE: ", tile
1427  call esmf_fieldgather(skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1428  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1429  call error_handler("IN FieldGather", rc)
1430 
1431  print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
1432  call esmf_fieldgather(landmask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
1433  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1434  call error_handler("IN FieldGather", rc)
1435 
1436  print*,"- CALL FieldGather FOR TARGET LATITUDE TILE: ", tile
1437  call esmf_fieldgather(latitude_target_grid, latitude_one_tile, rootpet=0, tile=tile, rc=rc)
1438  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1439  call error_handler("IN FieldGather", rc)
1440 
1441  if (localpet == 0) then
1442  allocate(water_target_one_tile(i_target,j_target))
1443  water_target_one_tile = 0
1444  where(mask_target_one_tile == 0) water_target_one_tile = 1
1445  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 11, &
1446  latitude=latitude_one_tile)
1447  endif
1448 
1449  print*,"- CALL FieldScatter FOR TARGET GRID SKIN TEMP: ", tile
1450  call esmf_fieldscatter(skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1451  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1452  call error_handler("IN FieldScatter", rc)
1453 
1454 ! z0
1455 
1456  print*,"- CALL FieldGather FOR TARGET GRID Z0 TILE: ", tile
1457  call esmf_fieldgather(z0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1458  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1459  call error_handler("IN FieldGather", rc)
1460 
1461  if (localpet == 0) then
1462  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 83)
1463  endif
1464 
1465  print*,"- CALL FieldScatter FOR TARGET GRID Z0: ", tile
1466  call esmf_fieldscatter(z0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1467  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1468  call error_handler("IN FieldScatter", rc)
1469 
1470  if (convert_nst) then
1471 
1472 ! c_d
1473 
1474  print*,"- CALL FieldGather FOR TARGET GRID C_D TILE: ", tile
1475  call esmf_fieldgather(c_d_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1476  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1477  call error_handler("IN FieldGather", rc)
1478 
1479  if (localpet == 0) then
1480  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1481  endif
1482 
1483  print*,"- CALL FieldScatter FOR TARGET GRID C_D: ", tile
1484  call esmf_fieldscatter(c_d_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1485  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1486  call error_handler("IN FieldScatter", rc)
1487 
1488 ! c_0
1489 
1490  print*,"- CALL FieldGather FOR TARGET GRID C_0 TILE: ", tile
1491  call esmf_fieldgather(c_0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1492  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1493  call error_handler("IN FieldGather", rc)
1494 
1495  if (localpet == 0) then
1496  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1497  endif
1498 
1499  print*,"- CALL FieldScatter FOR TARGET GRID C_0: ", tile
1500  call esmf_fieldscatter(c_0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1501  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1502  call error_handler("IN FieldScatter", rc)
1503 
1504 ! d_conv
1505 
1506  print*,"- CALL FieldGather FOR TARGET GRID D_CONV TILE: ", tile
1507  call esmf_fieldgather(d_conv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1508  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1509  call error_handler("IN FieldGather", rc)
1510 
1511  if (localpet == 0) then
1512  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1513  endif
1514 
1515  print*,"- CALL FieldScatter FOR TARGET GRID D_CONV: ", tile
1516  call esmf_fieldscatter(d_conv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1517  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1518  call error_handler("IN FieldScatter", rc)
1519 
1520 ! dt_cool
1521 
1522  print*,"- CALL FieldGather FOR TARGET GRID DT_COOL TILE: ", tile
1523  call esmf_fieldgather(dt_cool_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1524  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1525  call error_handler("IN FieldGather", rc)
1526 
1527  if (localpet == 0) then
1528  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1529  endif
1530 
1531  print*,"- CALL FieldScatter FOR TARGET GRID DT_COOL: ", tile
1532  call esmf_fieldscatter(dt_cool_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1533  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1534  call error_handler("IN FieldScatter", rc)
1535 
1536 ! ifd
1537 
1538  print*,"- CALL FieldGather FOR TARGET GRID IFD TILE: ", tile
1539  call esmf_fieldgather(ifd_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1540  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1541  call error_handler("IN FieldGather", rc)
1542 
1543  if (localpet == 0) then
1544  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 1)
1545  endif
1546 
1547  print*,"- CALL FieldScatter FOR TARGET GRID IFD: ", tile
1548  call esmf_fieldscatter(ifd_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1549  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1550  call error_handler("IN FieldScatter", rc)
1551 
1552 ! qrain
1553 
1554  print*,"- CALL FieldGather FOR TARGET GRID QRAIN TILE: ", tile
1555  call esmf_fieldgather(qrain_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1556  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1557  call error_handler("IN FieldGather", rc)
1558 
1559  if (localpet == 0) then
1560  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1561  endif
1562 
1563  print*,"- CALL FieldScatter FOR TARGET GRID QRAIN: ", tile
1564  call esmf_fieldscatter(qrain_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1565  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1566  call error_handler("IN FieldScatter", rc)
1567 
1568 ! tref
1569 
1570  print*,"- CALL FieldGather FOR TARGET GRID TREF TILE: ", tile
1571  call esmf_fieldgather(tref_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1572  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1573  call error_handler("IN FieldGather", rc)
1574 
1575  if (localpet == 0) then
1576  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 11, &
1577  latitude=latitude_one_tile)
1578  endif
1579 
1580  print*,"- CALL FieldScatter FOR TARGET GRID TREF: ", tile
1581  call esmf_fieldscatter(tref_target_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 ! w_d
1586 
1587  print*,"- CALL FieldGather FOR TARGET GRID W_D TILE: ", tile
1588  call esmf_fieldgather(w_d_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1589  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1590  call error_handler("IN FieldGather", rc)
1591 
1592  if (localpet == 0) then
1593  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1594  endif
1595 
1596  print*,"- CALL FieldScatter FOR TARGET GRID W_D: ", tile
1597  call esmf_fieldscatter(w_d_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1598  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1599  call error_handler("IN FieldScatter", rc)
1600 
1601 ! w_0
1602 
1603  print*,"- CALL FieldGather FOR TARGET GRID W_0 TILE: ", tile
1604  call esmf_fieldgather(w_0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1605  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1606  call error_handler("IN FieldGather", rc)
1607 
1608  if (localpet == 0) then
1609  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1610  endif
1611 
1612  print*,"- CALL FieldScatter FOR TARGET GRID W_0: ", tile
1613  call esmf_fieldscatter(w_0_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1614  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1615  call error_handler("IN FieldScatter", rc)
1616 
1617 ! xs
1618 
1619  print*,"- CALL FieldGather FOR TARGET GRID XS TILE: ", tile
1620  call esmf_fieldgather(xs_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1621  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1622  call error_handler("IN FieldGather", rc)
1623 
1624  if (localpet == 0) then
1625  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1626  endif
1627 
1628  print*,"- CALL FieldScatter FOR TARGET GRID XS: ", tile
1629  call esmf_fieldscatter(xs_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1630  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1631  call error_handler("IN FieldScatter", rc)
1632 
1633 ! xt
1634 
1635  print*,"- CALL FieldGather FOR TARGET GRID XT TILE: ", tile
1636  call esmf_fieldgather(xt_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1637  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1638  call error_handler("IN FieldGather", rc)
1639 
1640  if (localpet == 0) then
1641  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1642  endif
1643 
1644  print*,"- CALL FieldScatter FOR TARGET GRID XT: ", tile
1645  call esmf_fieldscatter(xt_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1646  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1647  call error_handler("IN FieldScatter", rc)
1648 
1649 ! xu
1650 
1651  print*,"- CALL FieldGather FOR TARGET GRID XU TILE: ", tile
1652  call esmf_fieldgather(xu_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1653  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1654  call error_handler("IN FieldGather", rc)
1655 
1656  if (localpet == 0) then
1657  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1658  endif
1659 
1660  print*,"- CALL FieldScatter FOR TARGET GRID XU: ", tile
1661  call esmf_fieldscatter(xu_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1662  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1663  call error_handler("IN FieldScatter", rc)
1664 
1665 ! xv
1666 
1667  print*,"- CALL FieldGather FOR TARGET GRID XV TILE: ", tile
1668  call esmf_fieldgather(xv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1669  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1670  call error_handler("IN FieldGather", rc)
1671 
1672  if (localpet == 0) then
1673  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1674  endif
1675 
1676  print*,"- CALL FieldScatter FOR TARGET GRID XV: ", tile
1677  call esmf_fieldscatter(xv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1678  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1679  call error_handler("IN FieldScatter", rc)
1680 
1681 ! xz
1682 
1683  print*,"- CALL FieldGather FOR TARGET GRID XZ TILE: ", tile
1684  call esmf_fieldgather(xz_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1685  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1686  call error_handler("IN FieldGather", rc)
1687 
1688  if (localpet == 0) then
1689  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 30)
1690  endif
1691 
1692  print*,"- CALL FieldScatter FOR TARGET GRID XZ: ", tile
1693  call esmf_fieldscatter(xz_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1694  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1695  call error_handler("IN FieldScatter", rc)
1696 
1697 ! xtts
1698 
1699  print*,"- CALL FieldGather FOR TARGET GRID XTTS TILE: ", tile
1700  call esmf_fieldgather(xtts_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1701  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1702  call error_handler("IN FieldGather", rc)
1703 
1704  if (localpet == 0) then
1705  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1706  endif
1707 
1708  print*,"- CALL FieldScatter FOR TARGET GRID XTTS: ", tile
1709  call esmf_fieldscatter(xtts_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1710  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1711  call error_handler("IN FieldScatter", rc)
1712 
1713 ! xzts
1714 
1715  print*,"- CALL FieldGather FOR TARGET GRID XZTS TILE: ", tile
1716  call esmf_fieldgather(xzts_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1717  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1718  call error_handler("IN FieldGather", rc)
1719 
1720  if (localpet == 0) then
1721  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1722  endif
1723 
1724  print*,"- CALL FieldScatter FOR TARGET GRID XZTS: ", tile
1725  call esmf_fieldscatter(xzts_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1726  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1727  call error_handler("IN FieldScatter", rc)
1728 
1729 ! z_c
1730 
1731  print*,"- CALL FieldGather FOR TARGET GRID Z_C TILE: ", tile
1732  call esmf_fieldgather(z_c_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1733  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1734  call error_handler("IN FieldGather", rc)
1735 
1736  if (localpet == 0) then
1737  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1738  endif
1739 
1740  print*,"- CALL FieldScatter FOR TARGET GRID Z_C: ", tile
1741  call esmf_fieldscatter(z_c_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1742  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1743  call error_handler("IN FieldScatter", rc)
1744 
1745 ! zm
1746 
1747  print*,"- CALL FieldGather FOR TARGET GRID ZM TILE: ", tile
1748  call esmf_fieldgather(zm_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1749  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1750  call error_handler("IN FieldGather", rc)
1751 
1752  if (localpet == 0) then
1753  call search(data_one_tile, water_target_one_tile, i_target, j_target, tile, 0)
1754  endif
1755 
1756  print*,"- CALL FieldScatter FOR TARGET GRID ZM: ", tile
1757  call esmf_fieldscatter(zm_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1758  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1759  call error_handler("IN FieldScatter", rc)
1760 
1761  endif
1762 
1763  if (localpet == 0) deallocate(water_target_one_tile)
1764 
1765  enddo
1766 
1767  deallocate(latitude_one_tile)
1768 
1769  print*,"- CALL FieldRegridRelease."
1770  call esmf_fieldregridrelease(routehandle=regrid_water, rc=rc)
1771  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1772  call error_handler("IN FieldRegridRelease", rc)
1773 
1774 !---------------------------------------------------------------------------------------------
1775 ! Now interpolate "all land" to "all land". Here, "all land" means landice and non-land ice.
1776 !---------------------------------------------------------------------------------------------
1777 
1778  mask_input_ptr = 0
1779  where (nint(landmask_input_ptr) == 1) mask_input_ptr = 1
1780 
1781  mask_target_ptr = 0
1782  where (landmask_target_ptr == 1) mask_target_ptr = 1
1783 
1784  method=esmf_regridmethod_conserve
1785  isrctermprocessing = 1
1786 
1787  print*,"- CALL FieldRegridStore for land fields."
1788  call esmf_fieldregridstore(snow_depth_input_grid, &
1789  snow_depth_target_grid, &
1790  srcmaskvalues=(/0/), &
1791  dstmaskvalues=(/0/), &
1792  polemethod=esmf_polemethod_none, &
1793  srctermprocessing=isrctermprocessing, &
1794  unmappedaction=esmf_unmappedaction_ignore, &
1795  normtype=esmf_normtype_fracarea, &
1796  routehandle=regrid_all_land, &
1797  regridmethod=method, &
1798  unmappeddstlist=unmapped_ptr, rc=rc)
1799  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1800  call error_handler("IN FieldRegridStore", rc)
1801 
1802  print*,"- CALL Field_Regrid for snow depth over land."
1803  call esmf_fieldregrid(snow_depth_input_grid, &
1804  snow_depth_target_grid, &
1805  routehandle=regrid_all_land, &
1806  termorderflag=esmf_termorder_srcseq, &
1807  zeroregion=esmf_region_select, & ! flag needed so snow over sea
1808  ! ice is not zeroed out.
1809  rc=rc)
1810  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1811  call error_handler("IN FieldRegrid", rc)
1812 
1813  print*,"- CALL Field_Regrid for snow liq equiv over land."
1814  call esmf_fieldregrid(snow_liq_equiv_input_grid, &
1815  snow_liq_equiv_target_grid, &
1816  routehandle=regrid_all_land, &
1817  termorderflag=esmf_termorder_srcseq, &
1818  zeroregion=esmf_region_select, rc=rc)
1819  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1820  call error_handler("IN FieldRegrid", rc)
1821 
1822  print*,"- CALL Field_Regrid for canopy mc."
1823  call esmf_fieldregrid(canopy_mc_input_grid, &
1824  canopy_mc_target_grid, &
1825  routehandle=regrid_all_land, &
1826  termorderflag=esmf_termorder_srcseq, rc=rc)
1827  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1828  call error_handler("IN FieldRegrid", rc)
1829 
1830  print*,"- CALL FieldGet FOR TARGET snow depth."
1831  call esmf_fieldget(snow_depth_target_grid, &
1832  farrayptr=snow_depth_target_ptr, rc=rc)
1833  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1834  call error_handler("IN FieldGet", rc)
1835 
1836  print*,"- CALL FieldGet FOR TARGET snow liq equiv."
1837  call esmf_fieldget(snow_liq_equiv_target_grid, &
1838  farrayptr=snow_liq_equiv_target_ptr, rc=rc)
1839  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1840  call error_handler("IN FieldGet", rc)
1841 
1842  print*,"- CALL FieldGet FOR TARGET canopy moisture."
1843  call esmf_fieldget(canopy_mc_target_grid, &
1844  farrayptr=canopy_mc_target_ptr, rc=rc)
1845  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1846  call error_handler("IN FieldGet", rc)
1847 
1848  l = lbound(unmapped_ptr)
1849  u = ubound(unmapped_ptr)
1850 
1851  do ij = l(1), u(1)
1852  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
1853  snow_depth_target_ptr(i,j) = -9999.9
1854  snow_liq_equiv_target_ptr(i,j) = -9999.9
1855  canopy_mc_target_ptr(i,j) = -9999.9
1856  enddo
1857 
1858  do tile = 1, num_tiles_target_grid
1859 
1860  print*,"- CALL FieldGather FOR TARGET GRID SNOW DEPTH TILE: ", tile
1861  call esmf_fieldgather(snow_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1862  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1863  call error_handler("IN FieldGather", rc)
1864 
1865  print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
1866  call esmf_fieldgather(landmask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
1867  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1868  call error_handler("IN FieldGather", rc)
1869 
1870  if (localpet == 0) then
1871  allocate(land_target_one_tile(i_target,j_target))
1872  land_target_one_tile = 0
1873  where(mask_target_one_tile == 1) land_target_one_tile = 1
1874  call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 66)
1875  endif
1876 
1877  print*,"- CALL FieldScatter FOR TARGET GRID SNOW DEPTH: ", tile
1878  call esmf_fieldscatter(snow_depth_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1879  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1880  call error_handler("IN FieldScatter", rc)
1881 
1882  print*,"- CALL FieldGather FOR TARGET GRID SNOW LIQUID EQUIV: ", tile
1883  call esmf_fieldgather(snow_liq_equiv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1884  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1885  call error_handler("IN FieldGather", rc)
1886 
1887  if (localpet == 0) then
1888  call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 65)
1889  endif
1890 
1891  print*,"- CALL FieldScatter FOR TARGET GRID SNOW LIQUID EQUIV: ", tile
1892  call esmf_fieldscatter(snow_liq_equiv_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1893  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1894  call error_handler("IN FieldScatter", rc)
1895 
1896  print*,"- CALL FieldGather FOR TARGET GRID CANOPY MC: ", tile
1897  call esmf_fieldgather(canopy_mc_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1898  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1899  call error_handler("IN FieldGather", rc)
1900 
1901  if (localpet == 0) then
1902  call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 223)
1903  deallocate(land_target_one_tile)
1904  endif
1905 
1906  print*,"- CALL FieldScatter FOR TARGET GRID CANOPY MC: ", tile
1907  call esmf_fieldscatter(canopy_mc_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
1908  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1909  call error_handler("IN FieldScatter", rc)
1910 
1911  enddo
1912 
1913  print*,"- CALL FieldRegridRelease."
1914  call esmf_fieldregridrelease(routehandle=regrid_all_land, rc=rc)
1915  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1916  call error_handler("IN FieldRegridRelease", rc)
1917 
1918 !---------------------------------------------------------------------------------------------
1919 ! Now interpolate landice points to landice points.
1920 !---------------------------------------------------------------------------------------------
1921 
1922  print*,"- CALL FieldGet FOR INPUT GRID VEG TYPE."
1923  call esmf_fieldget(veg_type_input_grid, &
1924  farrayptr=veg_type_input_ptr, rc=rc)
1925  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1926  call error_handler("IN FieldGet", rc)
1927 
1928  print*,'land ice check ',veg_type_landice_input
1929 
1930  mask_input_ptr = 0
1931  where (nint(veg_type_input_ptr) == veg_type_landice_input) mask_input_ptr = 1
1932 
1933  print*,"- CALL FieldGet FOR TARGET GRID VEG TYPE."
1934  call esmf_fieldget(veg_type_target_grid, &
1935  farrayptr=veg_type_target_ptr, rc=rc)
1936  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1937  call error_handler("IN FieldGet", rc)
1938 
1939  mask_target_ptr = 0
1940  where (nint(veg_type_target_ptr) == veg_type_landice_target) mask_target_ptr = 1
1941 
1942  method=esmf_regridmethod_nearest_stod
1943  isrctermprocessing = 1
1944 
1945  print*,"- CALL FieldRegridStore for landice fields."
1946  call esmf_fieldregridstore(soil_temp_input_grid, &
1947  soil_temp_target_grid, &
1948  srcmaskvalues=(/0/), &
1949  dstmaskvalues=(/0/), &
1950  polemethod=esmf_polemethod_none, &
1951  srctermprocessing=isrctermprocessing, &
1952  unmappedaction=esmf_unmappedaction_ignore, &
1953  normtype=esmf_normtype_fracarea, &
1954  routehandle=regrid_landice, &
1955  regridmethod=method, &
1956  unmappeddstlist=unmapped_ptr, rc=rc)
1957  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1958  call error_handler("IN FieldRegridStore", rc)
1959 
1960  print*,"- CALL Field_Regrid for soil temperature over landice."
1961  call esmf_fieldregrid(soil_temp_input_grid, &
1962  soil_temp_target_grid, &
1963  routehandle=regrid_landice, &
1964  termorderflag=esmf_termorder_srcseq, &
1965  zeroregion=esmf_region_select, rc=rc)
1966  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1967  call error_handler("IN FieldRegrid", rc)
1968 
1969  print*,"- CALL Field_Regrid for skin temperature over landice."
1970  call esmf_fieldregrid(skin_temp_input_grid, &
1971  skin_temp_target_grid, &
1972  routehandle=regrid_landice, &
1973  termorderflag=esmf_termorder_srcseq, &
1974  zeroregion=esmf_region_select, rc=rc)
1975  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1976  call error_handler("IN FieldRegrid", rc)
1977 
1978  print*,"- CALL Field_Regrid for terrain over landice."
1979  call esmf_fieldregrid(terrain_input_grid, &
1980  terrain_from_input_grid, &
1981  routehandle=regrid_landice, &
1982  termorderflag=esmf_termorder_srcseq, &
1983  zeroregion=esmf_region_select, rc=rc)
1984  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1985  call error_handler("IN FieldRegrid", rc)
1986 
1987  print*,"- CALL FieldGet FOR TARGET grid column temperature over landice."
1988  call esmf_fieldget(soil_temp_target_grid, &
1989  farrayptr=soil_temp_target_ptr, rc=rc)
1990  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1991  call error_handler("IN FieldGet", rc)
1992 
1993  print*,"- CALL FieldGet FOR TARGET skin temperature."
1994  call esmf_fieldget(skin_temp_target_grid, &
1995  farrayptr=skin_temp_target_ptr, rc=rc)
1996  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
1997  call error_handler("IN FieldGet", rc)
1998 
1999  print*,"- CALL FieldGet FOR terrain from input grid."
2000  call esmf_fieldget(terrain_from_input_grid, &
2001  farrayptr=terrain_from_input_ptr, rc=rc)
2002  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2003  call error_handler("IN FieldGet", rc)
2004 
2005  if (.not. sotyp_from_climo) then
2006  print*,"- CALL FieldGather FOR SOIL TYPE TARGET GRID, TILE: ", tile
2007  call esmf_fieldgather(soil_type_target_grid,soil_type_target_grid_save,rootpet=0,tile=1, rc=rc)
2008  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2009  call error_handler("IN FieldGather", rc)
2010 
2011  print*,"- CALL Field_Regrid for soil type over landice."
2012  call esmf_fieldregrid(soil_type_input_grid, &
2013  soil_type_target_grid, &
2014  routehandle=regrid_landice, &
2015  termorderflag=esmf_termorder_srcseq, &
2016  rc=rc)
2017  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2018  call error_handler("IN FieldRegrid", rc)
2019 
2020  print*,"- CALL FieldGet FOR SOIL TYPE TARGET GRID."
2021  call esmf_fieldget(soil_type_target_grid, &
2022  farrayptr=soil_type_from_input_ptr, rc=rc)
2023  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2024  call error_handler("IN FieldGet", rc)
2025  endif
2026 
2027  l = lbound(unmapped_ptr)
2028  u = ubound(unmapped_ptr)
2029 
2030  do ij = l(1), u(1)
2031  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
2032  soil_temp_target_ptr(i,j,:) = -9999.9
2033  skin_temp_target_ptr(i,j) = -9999.9
2034  terrain_from_input_ptr(i,j) = -9999.9
2035  if (.not.sotyp_from_climo) soil_type_from_input_ptr(i,j) = -9999.9
2036  enddo
2037 
2038  if (localpet == 0) then
2039  allocate (veg_type_target_one_tile(i_target,j_target))
2040  allocate (land_target_one_tile(i_target,j_target))
2041  allocate (data_one_tile2(i_target,j_target))
2042  else
2043  allocate (veg_type_target_one_tile(0,0))
2044  allocate (land_target_one_tile(0,0))
2045  allocate (data_one_tile2(0,0))
2046  endif
2047 
2048  do tile = 1, num_tiles_target_grid
2049 
2050  print*,"- CALL FieldGather FOR TARGET GRID SKIN TEMP TILE: ", tile
2051  call esmf_fieldgather(skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2052  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2053  call error_handler("IN FieldGather", rc)
2054 
2055  print*,"- CALL FieldGather FOR TARGET VEG TYPE TILE: ", tile
2056  call esmf_fieldgather(veg_type_target_grid, veg_type_target_one_tile, rootpet=0, tile=tile, rc=rc)
2057  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2058  call error_handler("IN FieldGather", rc)
2059 
2060  if (localpet == 0) then
2061  land_target_one_tile = 0
2062  where(nint(veg_type_target_one_tile) == veg_type_landice_target) land_target_one_tile = 1
2063  call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 21)
2064  endif
2065 
2066  print*,"- CALL FieldScatter FOR TARGET GRID SKIN TEMP, TILE: ", tile
2067  call esmf_fieldscatter(skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2068  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2069  call error_handler("IN FieldScatter", rc)
2070 
2071  print*,"- CALL FieldGather FOR TERRAIN FROM INPUT GRID, TILE: ", tile
2072  call esmf_fieldgather(terrain_from_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2073  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2074  call error_handler("IN FieldGather", rc)
2075 
2076  print*,"- CALL FieldGather FOR TERRAIN FROM INPUT GRID LAND, TILE: ", tile
2077  call esmf_fieldgather(terrain_from_input_grid_land, data_one_tile2, rootpet=0, tile=tile, rc=rc)
2078  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2079  call error_handler("IN FieldGather", rc)
2080 
2081  if (localpet == 0) then
2082  call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 7, terrain_land=data_one_tile2)
2083  endif
2084 
2085  print*,"- CALL FieldScatter FOR TERRAIN FROM INPUT GRID, TILE: ", tile
2086  call esmf_fieldscatter(terrain_from_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2087  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2088  call error_handler("IN FieldScatter", rc)
2089 
2090  print*,"- CALL FieldGather FOR TARGET GRID LANDICE COLUMN TEMP: ", tile
2091  call esmf_fieldgather(soil_temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
2092  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2093  call error_handler("IN FieldGather", rc)
2094 
2095  if (localpet == 0) then
2096  do j = 1, lsoil_target
2097  data_one_tile = data_one_tile_3d(:,:,j)
2098  call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 21)
2099  data_one_tile_3d(:,:,j) = data_one_tile
2100  enddo
2101  endif
2102 
2103  print*,"- CALL FieldScatter FOR TARGET GRID SEAICE COLUMN TEMP: ", tile
2104  call esmf_fieldscatter(soil_temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
2105  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2106  call error_handler("IN FieldScatter", rc)
2107 
2108  if (.not. sotyp_from_climo) then
2109  print*,"- CALL FieldGather FOR SOIL TYPE TARGET GRID LAND, TILE: ",tile
2110  call esmf_fieldgather(soil_type_target_grid, data_one_tile,rootpet=0,tile=tile, rc=rc)
2111  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2112  call error_handler("IN FieldGather", rc)
2113 
2114  if (localpet == 0) then
2115  call search(data_one_tile, mask_target_one_tile, i_target, j_target,tile,231)
2116  endif
2117 
2118  print*,"- CALL FieldScatter FOR SOIL TYPE TARGET GRID, TILE: ", tile
2119  call esmf_fieldscatter(soil_type_target_grid,data_one_tile,rootpet=0,tile=tile,rc=rc)
2120  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2121  call error_handler("IN FieldScatter", rc)
2122  endif
2123 
2124  enddo
2125 
2126  deallocate (veg_type_target_one_tile)
2127  deallocate (land_target_one_tile)
2128 
2129  print*,"- CALL FieldRegridRelease."
2130  call esmf_fieldregridrelease(routehandle=regrid_landice, rc=rc)
2131  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2132  call error_handler("IN FieldRegridRelease", rc)
2133 
2134 !---------------------------------------------------------------------------------------------
2135 ! Now interpolate land (not including landice pts) to land (not including landice).
2136 !---------------------------------------------------------------------------------------------
2137 
2138  mask_input_ptr = 0
2139  where (nint(landmask_input_ptr) == 1) mask_input_ptr = 1
2140  where (nint(veg_type_input_ptr) == veg_type_landice_input) mask_input_ptr = 0
2141 
2142  mask_target_ptr = 0
2143  where (landmask_target_ptr == 1) mask_target_ptr = 1
2144  where (nint(veg_type_target_ptr) == veg_type_landice_target) mask_target_ptr = 0
2145 
2146  method=esmf_regridmethod_nearest_stod
2147  isrctermprocessing = 1
2148 
2149  print*,"- CALL FieldRegridStore for 3d land (but no land ice) fields."
2150  call esmf_fieldregridstore(soilm_tot_input_grid, &
2151  soilm_tot_target_grid, &
2152  srcmaskvalues=(/0/), &
2153  dstmaskvalues=(/0/), &
2154  polemethod=esmf_polemethod_none, &
2155  srctermprocessing=isrctermprocessing, &
2156  unmappedaction=esmf_unmappedaction_ignore, &
2157  normtype=esmf_normtype_fracarea, &
2158  routehandle=regrid_land, &
2159  regridmethod=method, &
2160  unmappeddstlist=unmapped_ptr, rc=rc)
2161  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2162  call error_handler("IN FieldRegridStore", rc)
2163 
2164  print*,"- CALL Field_Regrid for total soil moisture over land."
2165  call esmf_fieldregrid(soilm_tot_input_grid, &
2166  soilm_tot_target_grid, &
2167  routehandle=regrid_land, &
2168  termorderflag=esmf_termorder_srcseq, rc=rc)
2169  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2170  call error_handler("IN FieldRegrid", rc)
2171 
2172  print*,"- CALL Field_Regrid for soil temperature over land."
2173  call esmf_fieldregrid(soil_temp_input_grid, &
2174  soil_temp_target_grid, &
2175  routehandle=regrid_land, &
2176  termorderflag=esmf_termorder_srcseq, &
2177  zeroregion=esmf_region_select, rc=rc)
2178  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2179  call error_handler("IN FieldRegrid", rc)
2180 
2181  print*,"- CALL Field_Regrid for skin temperature over land."
2182  call esmf_fieldregrid(skin_temp_input_grid, &
2183  skin_temp_target_grid, &
2184  routehandle=regrid_land, &
2185  termorderflag=esmf_termorder_srcseq, &
2186  zeroregion=esmf_region_select, rc=rc)
2187  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2188  call error_handler("IN FieldRegrid", rc)
2189 
2190  print*,"- CALL Field_Regrid for terrain over land."
2191  call esmf_fieldregrid(terrain_input_grid, &
2192  terrain_from_input_grid, &
2193  routehandle=regrid_land, &
2194  termorderflag=esmf_termorder_srcseq, &
2195  zeroregion=esmf_region_select, rc=rc)
2196  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2197  call error_handler("IN FieldRegrid", rc)
2198 
2199  if (.not. sotyp_from_climo) then
2200  print*,"- CALL Field_Regrid for soil type over land."
2201  call esmf_fieldregrid(soil_type_input_grid, &
2202  soil_type_target_grid, &
2203  routehandle=regrid_land, &
2204  zeroregion=esmf_region_select, &
2205  termorderflag=esmf_termorder_srcseq, rc=rc)
2206  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2207  call error_handler("IN FieldRegrid", rc)
2208  endif
2209 
2210  print*,"- CALL Field_Regrid for soil type over land."
2211  call esmf_fieldregrid(soil_type_input_grid, &
2212  soil_type_from_input_grid, &
2213  routehandle=regrid_land, &
2214  termorderflag=esmf_termorder_srcseq, rc=rc)
2215  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2216  call error_handler("IN FieldRegrid", rc)
2217 
2218  if (.not. vgfrc_from_climo) then
2219  print*,"- CALL Field_Regrid for veg greenness over land."
2220  call esmf_fieldregrid(veg_greenness_input_grid, &
2221  veg_greenness_target_grid, &
2222  routehandle=regrid_land, &
2223  termorderflag=esmf_termorder_srcseq, rc=rc)
2224  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2225  call error_handler("IN FieldRegrid", rc)
2226  endif
2227 
2228  if (.not. minmax_vgfrc_from_climo) then
2229  print*,"- CALL Field_Regrid for max veg greenness over land."
2230  call esmf_fieldregrid(max_veg_greenness_input_grid, &
2231  max_veg_greenness_target_grid, &
2232  routehandle=regrid_land, &
2233  termorderflag=esmf_termorder_srcseq, rc=rc)
2234  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2235  call error_handler("IN FieldRegrid", rc)
2236 
2237  print*,"- CALL Field_Regrid for min veg greenness over land."
2238  call esmf_fieldregrid(min_veg_greenness_input_grid, &
2239  min_veg_greenness_target_grid, &
2240  routehandle=regrid_land, &
2241  termorderflag=esmf_termorder_srcseq, rc=rc)
2242  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2243  call error_handler("IN FieldRegrid", rc)
2244  endif
2245 
2246  if (.not. lai_from_climo) then
2247  print*,"- CALL Field_Regrid for leaf area index over land."
2248  call esmf_fieldregrid(lai_input_grid, &
2249  lai_target_grid, &
2250  routehandle=regrid_land, &
2251  termorderflag=esmf_termorder_srcseq, rc=rc)
2252  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2253  call error_handler("IN FieldRegrid", rc)
2254 
2255  endif
2256 
2257  print*,"- CALL FieldGet FOR TARGET grid total soil moisture over land."
2258  call esmf_fieldget(soilm_tot_target_grid, &
2259  farrayptr=soilm_tot_target_ptr, rc=rc)
2260  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2261  call error_handler("IN FieldGet", rc)
2262 
2263  print*,"- CALL FieldGet FOR TARGET grid soil temp over ice."
2264  call esmf_fieldget(soil_temp_target_grid, &
2265  farrayptr=soil_temp_target_ptr, rc=rc)
2266  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2267  call error_handler("IN FieldGet", rc)
2268 
2269  print*,"- CALL FieldGet FOR TARGET skin temperature."
2270  call esmf_fieldget(skin_temp_target_grid, &
2271  farrayptr=skin_temp_target_ptr, rc=rc)
2272  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2273  call error_handler("IN FieldGet", rc)
2274 
2275  print*,"- CALL FieldGet FOR terrain from input grid."
2276  call esmf_fieldget(terrain_from_input_grid, &
2277  farrayptr=terrain_from_input_ptr, rc=rc)
2278  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2279  call error_handler("IN FieldGet", rc)
2280 
2281  if (.not. sotyp_from_climo) then
2282  print*,"- CALL FieldGet FOR soil type target grid."
2283  call esmf_fieldget(soil_type_target_grid, &
2284  farrayptr=soil_type_target_ptr, rc=rc)
2285  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2286  call error_handler("IN FieldGet", rc)
2287  endif
2288 
2289  print*,"- CALL FieldGet FOR soil type from input grid."
2290  call esmf_fieldget(soil_type_from_input_grid, &
2291  farrayptr=soil_type_from_input_ptr, rc=rc)
2292  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2293  call error_handler("IN FieldGet", rc)
2294 
2295  if (.not. vgfrc_from_climo) then
2296  print*,"- CALL FieldGet FOR TARGET veg greenness."
2297  call esmf_fieldget(veg_greenness_target_grid, &
2298  farrayptr=veg_greenness_target_ptr, rc=rc)
2299  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2300  call error_handler("IN FieldGet", rc)
2301  endif
2302 
2303  if (.not. minmax_vgfrc_from_climo) then
2304  print*,"- CALL FieldGet FOR TARGET max veg greenness."
2305  call esmf_fieldget(max_veg_greenness_target_grid, &
2306  farrayptr=max_veg_greenness_target_ptr, rc=rc)
2307  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2308  call error_handler("IN FieldGet", rc)
2309 
2310  print*,"- CALL FieldGet FOR TARGET min veg greenness."
2311  call esmf_fieldget(min_veg_greenness_target_grid, &
2312  farrayptr=min_veg_greenness_target_ptr, rc=rc)
2313  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2314  call error_handler("IN FieldGet", rc)
2315  endif
2316 
2317  if (.not. lai_from_climo) then
2318  print*,"- CALL FieldGet FOR TARGET lai."
2319  call esmf_fieldget(lai_target_grid, &
2320  farrayptr=lai_target_ptr, rc=rc)
2321  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2322  call error_handler("IN FieldGet", rc)
2323  endif
2324 
2325  l = lbound(unmapped_ptr)
2326  u = ubound(unmapped_ptr)
2327  do ij = l(1), u(1)
2328  call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
2329  soilm_tot_target_ptr(i,j,:) = -9999.9
2330  soil_temp_target_ptr(i,j,:) = -9999.9
2331  skin_temp_target_ptr(i,j) = -9999.9
2332  terrain_from_input_ptr(i,j) = -9999.9
2333  if (.not. sotyp_from_climo) soil_type_target_ptr(i,j) = -9999.9
2334  soil_type_from_input_ptr(i,j) = -9999.9
2335  veg_greenness_target_ptr(i,j) = -9999.9
2336  max_veg_greenness_target_ptr(i,j) = -9999.9
2337  min_veg_greenness_target_ptr(i,j) = -9999.9
2338  lai_target_ptr(i,j) = -9999.9
2339  enddo
2340 
2341  if (localpet == 0) then
2342  allocate (veg_type_target_one_tile(i_target,j_target))
2343  else
2344  allocate (veg_type_target_one_tile(0,0))
2345  endif
2346 
2347  do tile = 1, num_tiles_target_grid
2348 
2349  print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
2350  call esmf_fieldgather(landmask_target_grid, mask_target_one_tile, rootpet=0, tile=tile, rc=rc)
2351  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2352  call error_handler("IN FieldGather", rc)
2353 
2354  print*,"- CALL FieldGather FOR TARGET VEG TYPE TILE: ", tile
2355  call esmf_fieldgather(veg_type_target_grid, veg_type_target_one_tile, rootpet=0, tile=tile, rc=rc)
2356  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2357  call error_handler("IN FieldGather", rc)
2358 
2359  print*,"- CALL FieldGather FOR TERRAIN FROM INPUT GRID, TILE: ", tile
2360  call esmf_fieldgather(terrain_from_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2361  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2362  call error_handler("IN FieldGather", rc)
2363 
2364  if (localpet == 0) then
2365  where(nint(veg_type_target_one_tile) == veg_type_landice_target) mask_target_one_tile = 0
2366  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 7)
2367  endif
2368 
2369  print*,"- CALL FieldScatter FOR TERRAIN FROM INPUT GRID, TILE: ", tile
2370  call esmf_fieldscatter(terrain_from_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2371  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2372  call error_handler("IN FieldScatter", rc)
2373 
2374  print*,"- CALL FieldGather FOR TARGET GRID SKIN TEMPERATURE, TILE: ", tile
2375  call esmf_fieldgather(skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2376  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2377  call error_handler("IN FieldGather", rc)
2378 
2379  if (localpet == 0) then
2380  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 85)
2381  endif
2382 
2383  print*,"- CALL FieldScatter FOR TARGET GRID SKIN TEMPERATURE, TILE: ", tile
2384  call esmf_fieldscatter(skin_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2385  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2386  call error_handler("IN FieldScatter", rc)
2387 
2388  print*,"- CALL FieldGather FOR SOIL TYPE FROM INPUT GRID, TILE: ", tile
2389  call esmf_fieldgather(soil_type_from_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2390  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2391  call error_handler("IN FieldGather", rc)
2392 
2393  print*,"- CALL FieldGather FOR SOIL TYPE TARGET GRID, TILE: ", tile
2394  call esmf_fieldgather(soil_type_target_grid, data_one_tile2, rootpet=0,tile=tile, rc=rc)
2395  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2396  call error_handler("IN FieldGather", rc)
2397 
2398 !---------------------------------------------------------------------------------------
2399 ! Some grib2 data does not have soil type. Set soil type interpolated from input
2400 ! grid to the target (model) grid soil type. This turns off the soil moisture
2401 ! rescaling.
2402 !---------------------------------------------------------------------------------------
2403 
2404  if (.not. sotyp_from_climo) then
2405  if (localpet==0) then
2406  call search(data_one_tile2, mask_target_one_tile, i_target, j_target, tile, 224,soilt_climo=soil_type_target_grid_save)
2407  endif
2408  else
2409  if (localpet == 0 .and. maxval(data_one_tile) > 0 .and. (trim(external_model) .ne. "GFS" .or. trim(input_type) .ne. "grib2")) then
2410  ! If soil type from the input grid has any non-zero points then soil type must exist for
2411  ! use
2412  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 224)
2413  elseif (localpet == 0) then
2414  data_one_tile = data_one_tile2
2415  endif
2416  endif
2417 
2418  if (.not. sotyp_from_climo) then
2419  print*,"- CALL FieldScatter FOR SOIL TYPE TARGET GRID, TILE: ", tile
2420  call esmf_fieldscatter(soil_type_target_grid, data_one_tile2, rootpet=0, tile=tile, rc=rc)
2421  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2422  call error_handler("IN FieldScatter", rc)
2423  endif
2424 
2425  print*,"- CALL FieldScatter FOR SOIL TYPE FROM INPUT GRID, TILE: ", tile
2426  call esmf_fieldscatter(soil_type_from_input_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2427  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2428  call error_handler("IN FieldScatter", rc)
2429 
2430  if (.not. vgfrc_from_climo) then
2431  print*,"- CALL FieldGather FOR TARGET GRID VEG GREENNESS, TILE: ", tile
2432  call esmf_fieldgather(veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2433  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2434  call error_handler("IN FieldGather", rc)
2435 
2436  if (localpet == 0 .and. maxval(data_one_tile) > 0.0) then
2437  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 226)
2438  endif
2439 
2440  print*,"- CALL FieldScatter FOR VEG GREENNESS TARGET GRID, TILE: ", tile
2441  call esmf_fieldscatter(veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=rc)
2442  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2443  call error_handler("IN FieldScatter", rc)
2444  endif
2445 
2446  if (.not. minmax_vgfrc_from_climo) then
2447  print*,"- CALL FieldGather FOR TARGET GRID MAX VEG GREENNESS, TILE: ", tile
2448  call esmf_fieldgather(max_veg_greenness_target_grid, data_one_tile, rootpet=0,tile=tile, rc=rc)
2449  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2450  call error_handler("IN FieldGather", rc)
2451 
2452  if (localpet == 0 .and. maxval(data_one_tile) > 0.0) then
2453  call search(data_one_tile, mask_target_one_tile, i_target, j_target,tile, 227)
2454  endif
2455 
2456  print*,"- CALL FieldScatter FOR MAX VEG GREENNESS TARGET GRID, TILE: ", tile
2457  call esmf_fieldscatter(max_veg_greenness_target_grid, data_one_tile, rootpet=0,tile=tile, rc=rc)
2458  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2459  call error_handler("IN FieldScatter", rc)
2460 
2461  print*,"- CALL FieldGather FOR TARGET GRID MIN VEG GREENNESS, TILE: ", tile
2462  call esmf_fieldgather(min_veg_greenness_target_grid, data_one_tile,rootpet=0,tile=tile, rc=rc)
2463  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2464  call error_handler("IN FieldGather", rc)
2465 
2466  if (localpet == 0 .and. maxval(data_one_tile) > 0.0) then
2467  call search(data_one_tile, mask_target_one_tile, i_target, j_target,tile,228)
2468  endif
2469 
2470 
2471  print*,"- CALL FieldScatter FOR MIN VEG GREENNESS TARGET GRID, TILE: ",tile
2472  call esmf_fieldscatter(min_veg_greenness_target_grid, data_one_tile,rootpet=0,tile=tile, rc=rc)
2473  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2474  call error_handler("IN FieldScatter", rc)
2475 
2476  endif
2477 
2478  if (.not. lai_from_climo) then
2479  print*,"- CALL FieldGather FOR TARGET GRID LEAF AREA INDEX, TILE: ", tile
2480  call esmf_fieldgather(lai_target_grid, data_one_tile, rootpet=0,tile=tile, rc=rc)
2481  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2482  call error_handler("IN FieldGather", rc)
2483 
2484  if (localpet == 0 .and. maxval(data_one_tile) > 0.0) then
2485  call search(data_one_tile, mask_target_one_tile, i_target, j_target,tile, 229)
2486  endif
2487 
2488  print*,"- CALL FieldScatter FOR LEAF AREA INDEX TARGET GRID, TILE: ", tile
2489  call esmf_fieldscatter(lai_target_grid, data_one_tile, rootpet=0,tile=tile, rc=rc)
2490  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
2491  call error_handler("IN FieldScatter", rc)
2492  endif
2493 
2494  print*,"- CALL FieldGather FOR TARGET GRID TOTAL SOIL MOISTURE, TILE: ", tile
2495  call esmf_fieldgather(soilm_tot_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
2496  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2497  call error_handler("IN FieldGather", rc)
2498 
2499  if (localpet == 0) then
2500  do j = 1, lsoil_target
2501  data_one_tile = data_one_tile_3d(:,:,j)
2502  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 86)
2503  data_one_tile_3d(:,:,j) = data_one_tile
2504  enddo
2505  endif
2506 
2507  print*,"- CALL FieldScatter FOR TARGET GRID TOTAL SOIL MOISTURE, TILE: ", tile
2508  call esmf_fieldscatter(soilm_tot_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
2509  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2510  call error_handler("IN FieldScatter", rc)
2511 
2512  print*,"- CALL FieldGather FOR TARGET GRID SOIL TEMPERATURE, TILE: ", tile
2513  call esmf_fieldgather(soil_temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
2514  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2515  call error_handler("IN FieldGather", rc)
2516 
2517  if (localpet == 0) then
2518  do j = 1, lsoil_target
2519  data_one_tile = data_one_tile_3d(:,:,j)
2520  call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 85)
2521  data_one_tile_3d(:,:,j) = data_one_tile
2522  enddo
2523  endif
2524 
2525  print*,"- CALL FieldScatter FOR TARGET GRID SOIL TEMPERATURE, TILE: ", tile
2526  call esmf_fieldscatter(soil_temp_target_grid, data_one_tile_3d, rootpet=0, tile=tile, rc=rc)
2527  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2528  call error_handler("IN FieldScatter", rc)
2529 
2530  if (tg3_from_soil) then
2531  print*,"- CALL FieldScatter FOR TARGET GRID SUBSTRATE TEMPERATURE, TILE: ", tile
2532  call esmf_fieldscatter(substrate_temp_target_grid, data_one_tile_3d(:,:,lsoil_target), rootpet=0, tile=tile, rc=rc)
2533  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2534  call error_handler("IN FieldScatter", rc)
2535  endif
2536 
2537  enddo
2538 
2539  print*,"- CALL FieldRegridRelease."
2540  call esmf_fieldregridrelease(routehandle=regrid_land, rc=rc)
2541  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2542  call error_handler("IN FieldRegridRelease", rc)
2543 
2544  deallocate(veg_type_target_one_tile)
2545 
2546  deallocate(data_one_tile, data_one_tile2)
2547  deallocate(data_one_tile_3d)
2548  deallocate(mask_target_one_tile)
2549 
2550  return
2551 
2552  end subroutine interp
2553 
2558 
2559  use esmf
2560 
2561  use model_grid, only : landmask_target_grid
2562 
2563  use program_setup, only : maxsmc_target, &
2564  bb_target, &
2565  satpsi_target
2566 
2567  use static_data, only : soil_type_target_grid, &
2568  veg_type_target_grid
2569 
2570  implicit none
2571 
2572  integer :: clb(3), cub(3), rc
2573  integer :: i, j, n, soil_type
2574 
2575  integer(esmf_kind_i8), pointer :: landmask_ptr(:,:)
2576 
2577  real :: bx, fk
2578  real(esmf_kind_r8), pointer :: soilm_liq_ptr(:,:,:)
2579  real(esmf_kind_r8), pointer :: soilm_tot_ptr(:,:,:)
2580  real(esmf_kind_r8), pointer :: soil_temp_ptr(:,:,:)
2581  real(esmf_kind_r8), pointer :: soil_type_ptr(:,:)
2582  real(esmf_kind_r8), pointer :: veg_type_ptr(:,:)
2583 
2584  print*,"- COMPUTE LIQUID PORTION OF TOTAL SOIL MOISTURE."
2585 
2586  print*,"- CALL FieldGet FOR TOTAL SOIL MOISTURE."
2587  call esmf_fieldget(soilm_tot_target_grid, &
2588  computationallbound=clb, &
2589  computationalubound=cub, &
2590  farrayptr=soilm_tot_ptr, rc=rc)
2591  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2592  call error_handler("IN FieldGet", rc)
2593 
2594  print*,"- CALL FieldGet FOR LIQUID SOIL MOISTURE."
2595  call esmf_fieldget(soilm_liq_target_grid, &
2596  farrayptr=soilm_liq_ptr, rc=rc)
2597  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2598  call error_handler("IN FieldGet", rc)
2599 
2600  print*,"- CALL FieldGet FOR SOIL TEMPERATURE."
2601  call esmf_fieldget(soil_temp_target_grid, &
2602  farrayptr=soil_temp_ptr, rc=rc)
2603  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2604  call error_handler("IN FieldGet", rc)
2605 
2606  print*,"- CALL FieldGet FOR VEGETATION TYPE."
2607  call esmf_fieldget(veg_type_target_grid, &
2608  farrayptr=veg_type_ptr, rc=rc)
2609  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2610  call error_handler("IN FieldGet", rc)
2611 
2612  print*,"- CALL FieldGet FOR SOIL TYPE."
2613  call esmf_fieldget(soil_type_target_grid, &
2614  farrayptr=soil_type_ptr, rc=rc)
2615  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2616  call error_handler("IN FieldGet", rc)
2617 
2618  print*,"- CALL FieldGet FOR LANDMASK."
2619  call esmf_fieldget(landmask_target_grid, &
2620  farrayptr=landmask_ptr, rc=rc)
2621  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2622  call error_handler("IN FieldGet", rc)
2623 
2624  do j = clb(2), cub(2)
2625  do i = clb(1), cub(1)
2626 
2627 !---------------------------------------------------------------------------------------------
2628 ! Check land points that are not permanent land ice.
2629 !---------------------------------------------------------------------------------------------
2630 
2631  if (landmask_ptr(i,j) == 1 .and. nint(veg_type_ptr(i,j)) /= veg_type_landice_target) then
2632 
2633  soil_type = nint(soil_type_ptr(i,j))
2634 
2635  do n = clb(3), cub(3)
2636 
2637  if (soil_temp_ptr(i,j,n) < (frz_h2o-0.0001)) then
2638 
2639  bx = bb_target(soil_type)
2640 
2641  if (bx .gt. blim) bx = blim
2642 
2643  fk=(((hlice/(grav*(-satpsi_target(soil_type))))* &
2644  ((soil_temp_ptr(i,j,n)-frz_h2o)/soil_temp_ptr(i,j,n)))** &
2645  (-1/bx))*maxsmc_target(soil_type)
2646 
2647  if (fk .lt. 0.02) fk = 0.02
2648 
2649  soilm_liq_ptr(i,j,n) = min( fk, soilm_tot_ptr(i,j,n) )
2650 
2651 !-----------------------------------------------------------------------
2652 ! now use iterative solution for liquid soil water content using
2653 ! FUNCTION FRH2O with the initial guess for SH2O from above explicit
2654 ! first guess.
2655 !-----------------------------------------------------------------------
2656 
2657  soilm_liq_ptr(i,j,n) = frh2o(soil_temp_ptr(i,j,n), &
2658  soilm_tot_ptr(i,j,n), soilm_liq_ptr(i,j,n), &
2659  maxsmc_target(soil_type),bb_target(soil_type), &
2660  satpsi_target(soil_type))
2661 
2662  else ! temp above freezing. all moisture is liquid
2663 
2664  soilm_liq_ptr(i,j,n) = soilm_tot_ptr(i,j,n)
2665 
2666  end if ! is soil layer below freezing?
2667 
2668  enddo ! soil layer
2669 
2670  end if ! is this point land?
2671 
2672  enddo
2673  enddo
2674 
2675  end subroutine calc_liq_soil_moisture
2676 
2701  FUNCTION frh2o (TKELV,SMC,SH2O,SMCMAX,BEXP,PSIS)
2702 
2703  use esmf
2704 
2705  IMPLICIT NONE
2706 
2707  INTEGER nlog
2708  INTEGER kcount
2709 
2710  REAL bexp
2711  REAL bx
2712  REAL denom
2713  REAL df
2714  REAL dswl
2715  REAL fk
2716  REAL frh2o
2717  REAL psis
2718  REAL(esmf_kind_r8) :: sh2o
2719  REAL(esmf_kind_r8) :: smc
2720  REAL smcmax
2721  REAL swl
2722  REAL swlk
2723  REAL(esmf_kind_r8) :: tkelv
2724 
2725  REAL, PARAMETER :: ck = 8.0
2726  REAL, PARAMETER :: error = 0.005
2727 
2728 ! ----------------------------------------------------------------------
2729 ! LIMITS ON PARAMETER B: B < 5.5 (use parameter BLIM)
2730 ! SIMULATIONS SHOWED IF B > 5.5 UNFROZEN WATER CONTENT IS
2731 ! NON-REALISTICALLY HIGH AT VERY LOW TEMPERATURES.
2732 ! ----------------------------------------------------------------------
2733 
2734  bx = bexp
2735  IF (bexp .GT. blim) bx = blim
2736 
2737 ! ----------------------------------------------------------------------
2738 ! INITIALIZING ITERATIONS COUNTER AND ITERATIVE SOLUTION FLAG.
2739 ! ----------------------------------------------------------------------
2740 
2741  nlog=0
2742  kcount=0
2743 
2744  IF (ck .NE. 0.0) THEN
2745 
2746 ! ----------------------------------------------------------------------
2747 ! OPTION 1: ITERATED SOLUTION FOR NONZERO CK
2748 ! IN KOREN ET AL, JGR, 1999, EQN 17
2749 ! ----------------------------------------------------------------------
2750 ! INITIAL GUESS FOR SWL (frozen content)
2751 ! ----------------------------------------------------------------------
2752 
2753  swl = smc-sh2o
2754 
2755 ! ----------------------------------------------------------------------
2756 ! KEEP WITHIN BOUNDS.
2757 ! ----------------------------------------------------------------------
2758 
2759  IF (swl .GT. (smc-0.02)) swl = smc-0.02
2760  IF (swl .LT. 0.) swl = 0.
2761 
2762 ! ----------------------------------------------------------------------
2763 ! START OF ITERATIONS
2764 ! ----------------------------------------------------------------------
2765 
2766  DO WHILE ( (nlog .LT. 10) .AND. (kcount .EQ. 0) )
2767 
2768  nlog = nlog+1
2769  df = log(( psis*grav/hlice ) * ( ( 1.+ck*swl )**2. ) * &
2770  ( smcmax/(smc-swl) )**bx) - log(-(tkelv-frz_h2o)/tkelv)
2771  denom = 2. * ck / ( 1.+ck*swl ) + bx / ( smc - swl )
2772  swlk = swl - df/denom
2773 
2774 ! ----------------------------------------------------------------------
2775 ! BOUNDS USEFUL FOR MATHEMATICAL SOLUTION.
2776 ! ----------------------------------------------------------------------
2777 
2778  IF (swlk .GT. (smc-0.02)) swlk = smc - 0.02
2779  IF (swlk .LT. 0.) swlk = 0.
2780 
2781 ! ----------------------------------------------------------------------
2782 ! MATHEMATICAL SOLUTION BOUNDS APPLIED.
2783 ! ----------------------------------------------------------------------
2784 
2785  dswl = abs(swlk-swl)
2786  swl = swlk
2787 
2788 ! ----------------------------------------------------------------------
2789 ! IF MORE THAN 10 ITERATIONS, USE EXPLICIT METHOD (CK=0 APPROX.)
2790 ! WHEN DSWL LESS OR EQ. ERROR, NO MORE ITERATIONS REQUIRED.
2791 ! ----------------------------------------------------------------------
2792 
2793  IF ( dswl .LE. error ) THEN
2794  kcount = kcount+1
2795  ENDIF
2796 
2797  END DO
2798 
2799 ! ----------------------------------------------------------------------
2800 ! END OF ITERATIONS
2801 ! ----------------------------------------------------------------------
2802 ! BOUNDS APPLIED WITHIN DO-BLOCK ARE VALID FOR PHYSICAL SOLUTION.
2803 ! ----------------------------------------------------------------------
2804 
2805  frh2o = smc - swl
2806 
2807 ! ----------------------------------------------------------------------
2808 ! END OPTION 1
2809 ! ----------------------------------------------------------------------
2810 
2811  ENDIF
2812 
2813 !-----------------------------------------------------------------------
2814 ! OPTION 2: EXPLICIT SOLUTION FOR FLERCHINGER EQ. i.e. CK=0
2815 ! IN KOREN ET AL., JGR, 1999, EQN 17
2816 ! APPLY PHYSICAL BOUNDS TO FLERCHINGER SOLUTION
2817 ! ----------------------------------------------------------------------
2818 
2819  IF (kcount .EQ. 0) THEN
2820 
2821  fk = (((hlice/(grav*(-psis)))* &
2822  ((tkelv-frz_h2o)/tkelv))**(-1/bx))*smcmax
2823 
2824  IF (fk .LT. 0.02) fk = 0.02
2825 
2826  frh2o = min(fk, smc)
2827 
2828  ENDIF
2829 
2830  RETURN
2831 
2832  END function frh2o
2833 
2840 
2841  use esmf
2842 
2843  use model_grid, only : landmask_target_grid
2844 
2845  use program_setup, only : drysmc_input, drysmc_target, &
2846  maxsmc_input, maxsmc_target, &
2847  refsmc_input, refsmc_target, &
2848  wltsmc_input, wltsmc_target
2849 
2850  use static_data, only : soil_type_target_grid, &
2851  veg_greenness_target_grid, &
2852  veg_type_target_grid
2853 
2854  implicit none
2855 
2856  integer :: clb(3), cub(3), i, j, k, rc
2857  integer :: soilt_input, soilt_target
2858  integer(esmf_kind_i8), pointer :: landmask_ptr(:,:)
2859 
2860  real(esmf_kind_r8), pointer :: soilm_tot_ptr(:,:,:)
2861  real(esmf_kind_r8), pointer :: soil_type_input_ptr(:,:)
2862  real(esmf_kind_r8), pointer :: soil_type_target_ptr(:,:)
2863  real(esmf_kind_r8), pointer :: veg_greenness_ptr(:,:)
2864  real(esmf_kind_r8), pointer :: veg_type_ptr(:,:)
2865  real :: f1, fn, smcdir, smctra
2866 
2867  print*,"- RESCALE SOIL MOISTURE FOR CHANGES IN SOIL TYPE."
2868 
2869  print*,"- CALL FieldGet FOR TOTAL SOIL MOISTURE."
2870  call esmf_fieldget(soilm_tot_target_grid, &
2871  computationallbound=clb, &
2872  computationalubound=cub, &
2873  farrayptr=soilm_tot_ptr, rc=rc)
2874  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2875  call error_handler("IN FieldGet", rc)
2876 
2877  print*,"- CALL FieldGet FOR LAND MASK."
2878  call esmf_fieldget(landmask_target_grid, &
2879  farrayptr=landmask_ptr, rc=rc)
2880  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2881  call error_handler("IN FieldGet", rc)
2882 
2883  print*,"- CALL FieldGet FOR VEGETATION TYPE."
2884  call esmf_fieldget(veg_type_target_grid, &
2885  farrayptr=veg_type_ptr, rc=rc)
2886  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2887  call error_handler("IN FieldGet", rc)
2888 
2889  print*,"- CALL FieldGet FOR VEGETATION GREENNESS."
2890  call esmf_fieldget(veg_greenness_target_grid, &
2891  farrayptr=veg_greenness_ptr, rc=rc)
2892  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2893  call error_handler("IN FieldGet", rc)
2894 
2895  print*,"- CALL FieldGet FOR TARGET GRID SOIL TYPE."
2896  call esmf_fieldget(soil_type_target_grid, &
2897  farrayptr=soil_type_target_ptr, rc=rc)
2898  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2899  call error_handler("IN FieldGet", rc)
2900 
2901  print*,"- CALL FieldGet FOR SOIL TYPE FROM INPUT GRID."
2902  call esmf_fieldget(soil_type_from_input_grid, &
2903  farrayptr=soil_type_input_ptr, rc=rc)
2904  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
2905  call error_handler("IN FieldGet", rc)
2906 
2907  do j = clb(2), cub(2)
2908  do i = clb(1), cub(1)
2909 
2910 !---------------------------------------------------------------------------------------------
2911 ! Check land points that are not permanent land ice.
2912 !---------------------------------------------------------------------------------------------
2913 
2914  if (landmask_ptr(i,j) == 1 .and. nint(veg_type_ptr(i,j)) /= veg_type_landice_target) then
2915 
2916  soilt_target = nint(soil_type_target_ptr(i,j))
2917  soilt_input = nint(soil_type_input_ptr(i,j))
2918 
2919 !---------------------------------------------------------------------------------------------
2920 ! Rescale soil moisture at points where the soil type between the input and output
2921 ! grids is different. Caution, this logic assumes the input and target grids use the same
2922 ! soil type dataset.
2923 !---------------------------------------------------------------------------------------------
2924 
2925  if (soilt_target /= soilt_input) then
2926 !---------------------------------------------------------------------------------------------
2927 ! Rescale top layer. First, determine direct evaporation part:
2928 !---------------------------------------------------------------------------------------------
2929 
2930  f1=(soilm_tot_ptr(i,j,1)-drysmc_input(soilt_input)) / &
2931  (maxsmc_input(soilt_input)-drysmc_input(soilt_input))
2932 
2933  smcdir=drysmc_target(soilt_target) + f1 * &
2934  (maxsmc_target(soilt_target) - drysmc_target(soilt_target))
2935 
2936 !---------------------------------------------------------------------------------------------
2937 ! Continue top layer rescale. Now determine transpiration part:
2938 !---------------------------------------------------------------------------------------------
2939 
2940  if (soilm_tot_ptr(i,j,1) < refsmc_input(soilt_input)) then
2941  f1=(soilm_tot_ptr(i,j,1) - wltsmc_input(soilt_input)) / &
2942  (refsmc_input(soilt_input) - wltsmc_input(soilt_input))
2943  smctra=wltsmc_target(soilt_target) + f1 * &
2944  (refsmc_target(soilt_target) - wltsmc_target(soilt_target))
2945  else
2946  f1=(soilm_tot_ptr(i,j,1) - refsmc_input(soilt_input)) / &
2947  (maxsmc_input(soilt_input) - refsmc_input(soilt_input))
2948  smctra=refsmc_target(soilt_target) + f1 * &
2949  (maxsmc_target(soilt_target) - refsmc_target(soilt_target))
2950  endif
2951 
2952 !---------------------------------------------------------------------------------------------
2953 ! Top layer is weighted by green vegetation fraction:
2954 !---------------------------------------------------------------------------------------------
2955 
2956  soilm_tot_ptr(i,j,1) = ((1.0 - veg_greenness_ptr(i,j)) * smcdir) + &
2957  (veg_greenness_ptr(i,j) * smctra)
2958 
2959 !---------------------------------------------------------------------------------------------
2960 ! Rescale bottom layers as follows:
2961 !
2962 ! - Rescale between wilting point and reference value when wilting < soil m < reference, or
2963 ! - Rescale between reference point and maximum value when reference < soil m < max.
2964 !---------------------------------------------------------------------------------------------
2965 
2966  do k = 2, cub(3)
2967  if (soilm_tot_ptr(i,j,k) < refsmc_input(soilt_input)) then
2968  fn = (soilm_tot_ptr(i,j,k) - wltsmc_input(soilt_input)) / &
2969  (refsmc_input(soilt_input) - wltsmc_input(soilt_input))
2970  soilm_tot_ptr(i,j,k) = wltsmc_target(soilt_target) + fn * &
2971  (refsmc_target(soilt_target) - wltsmc_target(soilt_target))
2972  else
2973  fn = (soilm_tot_ptr(i,j,k) - refsmc_input(soilt_input)) / &
2974  (maxsmc_input(soilt_input) - refsmc_input(soilt_input))
2975  soilm_tot_ptr(i,j,k) = refsmc_target(soilt_target) + fn * &
2976  (maxsmc_target(soilt_target) - refsmc_target(soilt_target))
2977  endif
2978  enddo
2979 
2980  endif ! is soil type different?
2981 
2982 !---------------------------------------------------------------------------------------------
2983 ! Range check all layers.
2984 !---------------------------------------------------------------------------------------------
2985 
2986  soilm_tot_ptr(i,j,1)=min(soilm_tot_ptr(i,j,1),maxsmc_target(soilt_target))
2987  soilm_tot_ptr(i,j,1)=max(drysmc_target(soilt_target),soilm_tot_ptr(i,j,1))
2988 
2989  do k = 2, cub(3)
2990  soilm_tot_ptr(i,j,k)=min(soilm_tot_ptr(i,j,k),maxsmc_target(soilt_target))
2991  soilm_tot_ptr(i,j,k)=max(wltsmc_target(soilt_target),soilm_tot_ptr(i,j,k))
2992  enddo
2993 
2994  endif ! is this a land point?
2995 
2996  enddo
2997  enddo
2998 
2999  return
3000 
3001  end subroutine rescale_soil_moisture
3002 
3008 
3009  use model_grid, only : landmask_target_grid, &
3010  terrain_target_grid
3011 
3012  use static_data, only : veg_type_target_grid
3013 
3014  implicit none
3015 
3016  integer :: clb(3), cub(3), i, j, k, rc
3017  integer(esmf_kind_i8), pointer :: landmask_ptr(:,:)
3018 
3019  real, parameter :: lapse_rate = 6.5e-03
3020  real :: terrain_diff
3021  real(esmf_kind_r8), pointer :: terrain_input_ptr(:,:)
3022  real(esmf_kind_r8), pointer :: terrain_target_ptr(:,:)
3023  real(esmf_kind_r8), pointer :: veg_type_target_ptr(:,:)
3024  real(esmf_kind_r8), pointer :: soil_temp_target_ptr(:,:,:)
3025 
3026  print*,"- CALL FieldGet FOR TARGET GRID LAND-SEA MASK."
3027  call esmf_fieldget(landmask_target_grid, &
3028  farrayptr=landmask_ptr, rc=rc)
3029  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3030  call error_handler("IN FieldGet", rc)
3031 
3032  print*,"- CALL FieldGet FOR TARGET GRID VEGETATION TYPE."
3033  call esmf_fieldget(veg_type_target_grid, &
3034  farrayptr=veg_type_target_ptr, rc=rc)
3035  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3036  call error_handler("IN FieldGet", rc)
3037 
3038  print*,"- CALL FieldGet FOR TARGET GRID TERRAIN."
3039  call esmf_fieldget(terrain_target_grid, &
3040  farrayptr=terrain_target_ptr, rc=rc)
3041  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3042  call error_handler("IN FieldGet", rc)
3043 
3044  print*,"- CALL FieldGet FOR TERRAIN INTERP TO TARGET GRID."
3045  call esmf_fieldget(terrain_from_input_grid, &
3046  farrayptr=terrain_input_ptr, rc=rc)
3047  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3048  call error_handler("IN FieldGet", rc)
3049 
3050  print*,"- CALL FieldGet FOR SOIL TEMP TARGET GRID."
3051  call esmf_fieldget(soil_temp_target_grid, &
3052  computationallbound=clb, &
3053  computationalubound=cub, &
3054  farrayptr=soil_temp_target_ptr, rc=rc)
3055  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3056  call error_handler("IN FieldGet", rc)
3057 
3058  do j = clb(2), cub(2)
3059  do i = clb(1), cub(1)
3060  if (landmask_ptr(i,j) == 1) then
3061  terrain_diff = abs(terrain_input_ptr(i,j) - terrain_target_ptr(i,j))
3062  if (terrain_diff > 100.0) then
3063  do k = clb(3), cub(3)
3064  soil_temp_target_ptr(i,j,k) = soil_temp_target_ptr(i,j,k) + &
3065  ((terrain_input_ptr(i,j) - terrain_target_ptr(i,j)) * lapse_rate)
3066  if (nint(veg_type_target_ptr(i,j)) == veg_type_landice_target) then
3067  soil_temp_target_ptr(i,j,k) = min(soil_temp_target_ptr(i,j,k), 273.16)
3068  endif
3069  enddo
3070  endif
3071  endif
3072  enddo
3073  enddo
3074 
3075  end subroutine adjust_soilt_for_terrain
3076 
3083  subroutine adjust_soil_levels(localpet)
3084  use model_grid, only : lsoil_target, i_input, j_input, input_grid
3085  use input_data, only : lsoil_input, soil_temp_input_grid, &
3086  soilm_liq_input_grid, soilm_tot_input_grid
3087  implicit none
3088  integer, intent(in) :: localpet
3089  character(len=1000) :: msg
3090  integer :: rc
3091  real(esmf_kind_r8) :: tmp(i_input,j_input), &
3092  data_one_tile(i_input,j_input,lsoil_input), &
3093  tmp3d(i_input,j_input,lsoil_target)
3094  if (lsoil_input == 9 .and. lsoil_target == 4) then
3095  print*, "CONVERTING FROM 9 INPUT SOIL LEVELS TO 4 TARGET SOIL LEVELS"
3096  call esmf_fieldgather(soil_temp_input_grid, data_one_tile, rootpet=0, tile=1, rc=rc)
3097  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3098  call error_handler("IN FieldGather", rc)
3099 
3100  call esmf_fielddestroy(soil_temp_input_grid,rc=rc)
3101  soil_temp_input_grid = esmf_fieldcreate(input_grid, &
3102  typekind=esmf_typekind_r8, &
3103  staggerloc=esmf_staggerloc_center, &
3104  ungriddedlbound=(/1/), &
3105  ungriddedubound=(/lsoil_target/), rc=rc)
3106 
3107  if(localpet==0)then
3108  tmp3d(:,:,1)= (data_one_tile(:,:,1) + data_one_tile(:,:,2))/2.0 * 0.1 + &
3109  (data_one_tile(:,:,2) + data_one_tile(:,:,3))/2.0 * 0.3 + &
3110  (data_one_tile(:,:,3) + data_one_tile(:,:,4))/2.0 * 0.6
3111  tmp = (data_one_tile(:,:,6) - data_one_tile(:,:,5)) / 30.0 * 10.0 + data_one_tile(:,:,5) !Linear approx. of 40 cm obs
3112  tmp3d(:,:,2)= (data_one_tile(:,:,4) + data_one_tile(:,:,5)) / 2.0 * 0.75 + &
3113  (data_one_tile(:,:,5) + tmp) / 2.0 * 0.25
3114  tmp3d(:,:,3)= (tmp + data_one_tile(:,:,6)) /2.0 * (1.0/3.0) + &
3115  (data_one_tile(:,:,6) + data_one_tile(:,:,7)) / 2.0 * (2.0/3.0)
3116  tmp = (data_one_tile(:,:,9) - data_one_tile(:,:,9)) / 140.0 * 40.0 + data_one_tile(:,:,8) !Linear approx of 200 cm obs
3117  tmp3d(:,:,4)= (data_one_tile(:,:,7) + data_one_tile(:,:,8)) / 2.0 * 0.6 + &
3118  (data_one_tile(:,:,8) + tmp) / 2.0 * 0.4
3119  endif
3120 
3121  call esmf_fieldscatter(soil_temp_input_grid, tmp3d, rootpet=0, rc=rc)
3122  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3123  call error_handler("IN FieldScatter", rc)
3124 
3125  call esmf_fieldgather(soilm_tot_input_grid, data_one_tile, rootpet=0, tile=1, rc=rc)
3126  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3127  call error_handler("IN FieldGather", rc)
3128 
3129  call esmf_fielddestroy(soilm_tot_input_grid,rc=rc)
3130  soilm_tot_input_grid = esmf_fieldcreate(input_grid, &
3131  typekind=esmf_typekind_r8, &
3132  staggerloc=esmf_staggerloc_center, &
3133  ungriddedlbound=(/1/), &
3134  ungriddedubound=(/lsoil_target/), rc=rc)
3135 
3136  if(localpet==0) then
3137  tmp3d(:,:,1)= (data_one_tile(:,:,1) + data_one_tile(:,:,2))/2.0 * 0.1 + &
3138  (data_one_tile(:,:,2) + data_one_tile(:,:,3))/2.0 * 0.3 + &
3139  (data_one_tile(:,:,3) + data_one_tile(:,:,4))/2.0 * 0.6
3140  tmp = (data_one_tile(:,:,6) - data_one_tile(:,:,5)) / 30.0 * 10.0 + data_one_tile(:,:,5) !Linear approx. of 40 cm obs
3141  tmp3d(:,:,2)= (data_one_tile(:,:,4) + data_one_tile(:,:,5)) / 2.0 * 0.75 + &
3142  (data_one_tile(:,:,5) + tmp) / 2.0 * 0.25
3143  tmp3d(:,:,3)= (tmp + data_one_tile(:,:,6)) /2.0 * (1.0/3.0) + &
3144  (data_one_tile(:,:,6) + data_one_tile(:,:,7)) / 2.0 * (2.0/3.0)
3145  tmp = (data_one_tile(:,:,9) - data_one_tile(:,:,9)) / 140.0 * 40.0 + data_one_tile(:,:,8) !Linear approx of 200 cm obs
3146  tmp3d(:,:,4)= (data_one_tile(:,:,7) + data_one_tile(:,:,8)) / 2.0 * 0.6 + &
3147  (data_one_tile(:,:,8) + tmp) / 2.0 * 0.4
3148  endif
3149 
3150  call esmf_fieldscatter(soilm_tot_input_grid, tmp3d, rootpet=0, rc=rc)
3151  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3152  call error_handler("IN FieldScatter", rc)
3153 
3154  call esmf_fieldgather(soilm_liq_input_grid, data_one_tile, rootpet=0, tile=1, rc=rc)
3155  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3156  call error_handler("IN FieldGather", rc)
3157 
3158  call esmf_fielddestroy(soilm_liq_input_grid,rc=rc)
3159  soilm_liq_input_grid = esmf_fieldcreate(input_grid, &
3160  typekind=esmf_typekind_r8, &
3161  staggerloc=esmf_staggerloc_center, &
3162  ungriddedlbound=(/1/), &
3163  ungriddedubound=(/lsoil_target/), rc=rc)
3164  if(localpet==0) then
3165  tmp3d(:,:,1)= (data_one_tile(:,:,1) + data_one_tile(:,:,2))/2.0 * 0.1 + &
3166  (data_one_tile(:,:,2) + data_one_tile(:,:,3))/2.0 * 0.3 + &
3167  (data_one_tile(:,:,3) + data_one_tile(:,:,4))/2.0 * 0.6
3168  tmp = (data_one_tile(:,:,6) - data_one_tile(:,:,5)) / 30.0 * 10.0 + data_one_tile(:,:,5) !Linear approx. of 40 cm obs
3169  tmp3d(:,:,2)= (data_one_tile(:,:,4) + data_one_tile(:,:,5)) / 2.0 * 0.75 + &
3170  (data_one_tile(:,:,5) + tmp) / 2.0 * 0.25
3171  tmp3d(:,:,3)= (tmp + data_one_tile(:,:,6)) /2.0 * (1.0/3.0) + &
3172  (data_one_tile(:,:,6) + data_one_tile(:,:,7)) / 2.0 * (2.0/3.0)
3173  tmp = (data_one_tile(:,:,9) - data_one_tile(:,:,9)) / 140.0 * 40.0 + data_one_tile(:,:,8) !Linear approx of 200 cm obs
3174  tmp3d(:,:,4)= (data_one_tile(:,:,7) + data_one_tile(:,:,8)) / 2.0 * 0.6 + &
3175  (data_one_tile(:,:,8) + tmp) / 2.0 * 0.4
3176  endif
3177 
3178  call esmf_fieldscatter(soilm_liq_input_grid, tmp3d, rootpet=0, rc=rc)
3179  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3180  call error_handler("IN FieldScatter", rc)
3181 
3182  elseif (lsoil_input /= lsoil_target) then
3183  rc = -1
3184 
3185  write(msg,'("NUMBER OF SOIL LEVELS IN INPUT (",I2,") and OUPUT &
3186  (",I2,") MUST EITHER BE EQUAL OR 9 AND 4, RESPECTIVELY")') &
3187  lsoil_input, lsoil_target
3188 
3189  call error_handler(trim(msg), rc)
3190  endif
3191 
3192  end subroutine adjust_soil_levels
3193 
3199  subroutine roughness
3200 
3201  use model_grid, only : landmask_target_grid
3202  use static_data, only : veg_type_target_grid
3203 
3204  implicit none
3205 
3206  integer :: clb(2), cub(2), i, j, rc
3207  integer(esmf_kind_i8), pointer :: landmask_ptr(:,:)
3208 
3209  real :: z0_igbp(20)
3210  real(esmf_kind_r8), pointer :: data_ptr(:,:)
3211  real(esmf_kind_r8), pointer :: veg_type_ptr(:,:)
3212 
3213  data z0_igbp /1.089, 2.653, 0.854, 0.826, 0.800, 0.050, &
3214  0.030, 0.856, 0.856, 0.150, 0.040, 0.130, &
3215  1.000, 0.250, 0.011, 0.011, 0.001, 0.076, &
3216  0.050, 0.030/
3217 
3218  print*,"- CALL FieldGet FOR TARGET GRID LAND-SEA MASK."
3219  call esmf_fieldget(landmask_target_grid, &
3220  computationallbound=clb, &
3221  computationalubound=cub, &
3222  farrayptr=landmask_ptr, rc=rc)
3223  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3224  call error_handler("IN FieldGet", rc)
3225 
3226  print*,"- CALL FieldGet FOR TARGET GRID VEGETATION TYPE."
3227  call esmf_fieldget(veg_type_target_grid, &
3228  farrayptr=veg_type_ptr, rc=rc)
3229  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3230  call error_handler("IN FieldGet", rc)
3231 
3232  print*,"- CALL FieldGet FOR TARGET GRID Z0."
3233  call esmf_fieldget(z0_target_grid, &
3234  farrayptr=data_ptr, rc=rc)
3235  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3236  call error_handler("IN FieldGet", rc)
3237 
3238  do j = clb(2), cub(2)
3239  do i = clb(1), cub(1)
3240  if (landmask_ptr(i,j) == 2) then
3241  data_ptr(i,j) = 1.0
3242  elseif (landmask_ptr(i,j) == 1) then
3243  data_ptr(i,j) = z0_igbp(nint(veg_type_ptr(i,j))) * 100.0
3244  endif
3245  enddo
3246  enddo
3247 
3248  end subroutine roughness
3249 
3253  subroutine qc_check
3254 
3255  use model_grid, only : landmask_target_grid
3256 
3257  use static_data, only : alvsf_target_grid, &
3258  alvwf_target_grid, &
3259  alnsf_target_grid, &
3260  alnwf_target_grid, &
3261  facsf_target_grid, &
3262  facwf_target_grid, &
3263  mxsno_albedo_target_grid, &
3264  max_veg_greenness_target_grid, &
3265  min_veg_greenness_target_grid, &
3266  slope_type_target_grid, &
3267  soil_type_target_grid, &
3268  substrate_temp_target_grid, &
3269  veg_greenness_target_grid, &
3270  veg_type_target_grid
3271 
3272  implicit none
3273 
3274  integer :: clb(2), cub(2), i, j, rc
3275  integer(esmf_kind_i8), pointer :: landmask_ptr(:,:)
3276 
3277  real(esmf_kind_r8), pointer :: data_ptr(:,:)
3278  real(esmf_kind_r8), pointer :: data3d_ptr(:,:,:)
3279  real(esmf_kind_r8), pointer :: soilmt_ptr(:,:,:)
3280  real(esmf_kind_r8), pointer :: soilml_ptr(:,:,:)
3281  real(esmf_kind_r8), pointer :: veg_greenness_ptr(:,:)
3282  real(esmf_kind_r8), pointer :: veg_type_ptr(:,:)
3283  real(esmf_kind_r8), pointer :: seaice_skint_ptr(:,:)
3284  real(esmf_kind_r8), pointer :: skint_ptr(:,:)
3285  real(esmf_kind_r8), pointer :: fice_ptr(:,:)
3286  real(esmf_kind_r8), pointer :: hice_ptr(:,:)
3287 
3288  print*,"- CALL FieldGet FOR TARGET GRID LAND-SEA MASK."
3289  call esmf_fieldget(landmask_target_grid, &
3290  computationallbound=clb, &
3291  computationalubound=cub, &
3292  farrayptr=landmask_ptr, rc=rc)
3293  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3294  call error_handler("IN FieldGet", rc)
3295 
3296  print*,"- SET NON-LAND FLAG FOR TARGET GRID SLOPE TYPE."
3297  call esmf_fieldget(slope_type_target_grid, &
3298  farrayptr=data_ptr, rc=rc)
3299  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3300  call error_handler("IN FieldGet", rc)
3301 
3302  do j = clb(2), cub(2)
3303  do i = clb(1), cub(1)
3304  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.0
3305  enddo
3306  enddo
3307 
3308  print*,"- SET NON-LAND FLAG FOR TARGET GRID SOIL TYPE."
3309  call esmf_fieldget(soil_type_target_grid, &
3310  farrayptr=data_ptr, rc=rc)
3311  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3312  call error_handler("IN FieldGet", rc)
3313 
3314  do j = clb(2), cub(2)
3315  do i = clb(1), cub(1)
3316  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.0
3317  enddo
3318  enddo
3319 
3320  print*,"- SET NON-LAND FLAG FOR TARGET GRID VEGETATION TYPE."
3321  call esmf_fieldget(veg_type_target_grid, &
3322  farrayptr=veg_type_ptr, rc=rc)
3323  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3324  call error_handler("IN FieldGet", rc)
3325 
3326  do j = clb(2), cub(2)
3327  do i = clb(1), cub(1)
3328  if (landmask_ptr(i,j) /= 1) veg_type_ptr(i,j) = 0.0
3329  enddo
3330  enddo
3331 
3332  print*,"- SET TARGET GRID ALVSF AT NON-LAND."
3333  call esmf_fieldget(alvsf_target_grid, &
3334  farrayptr=data_ptr, rc=rc)
3335  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3336  call error_handler("IN FieldGet", rc)
3337 
3338  do j = clb(2), cub(2)
3339  do i = clb(1), cub(1)
3340  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.06 ! gfs physics flag value
3341  enddo
3342  enddo
3343 
3344  print*,"- SET TARGET GRID ALVWF AT NON-LAND."
3345  call esmf_fieldget(alvwf_target_grid, &
3346  farrayptr=data_ptr, rc=rc)
3347  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3348  call error_handler("IN FieldGet", rc)
3349 
3350  do j = clb(2), cub(2)
3351  do i = clb(1), cub(1)
3352  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.06 ! gfs physics flag value
3353  enddo
3354  enddo
3355 
3356  print*,"- SET TARGET GRID ALNSF AT NON-LAND."
3357  call esmf_fieldget(alnsf_target_grid, &
3358  farrayptr=data_ptr, rc=rc)
3359  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3360  call error_handler("IN FieldGet", rc)
3361 
3362  do j = clb(2), cub(2)
3363  do i = clb(1), cub(1)
3364  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.06 ! gfs physics flag value
3365  enddo
3366  enddo
3367 
3368  print*,"- SET TARGET GRID ALNWF AT NON-LAND."
3369  call esmf_fieldget(alnwf_target_grid, &
3370  farrayptr=data_ptr, rc=rc)
3371  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3372  call error_handler("IN FieldGet", rc)
3373 
3374  do j = clb(2), cub(2)
3375  do i = clb(1), cub(1)
3376  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.06 ! gfs physics flag value
3377  enddo
3378  enddo
3379 
3380  print*,"- SET NON-LAND FLAG FOR TARGET GRID FACSF."
3381  call esmf_fieldget(facsf_target_grid, &
3382  farrayptr=data_ptr, rc=rc)
3383  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3384  call error_handler("IN FieldGet", rc)
3385 
3386  do j = clb(2), cub(2)
3387  do i = clb(1), cub(1)
3388  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.0
3389  enddo
3390  enddo
3391 
3392  print*,"- SET NON-LAND FLAG FOR TARGET GRID FACSF."
3393  call esmf_fieldget(facwf_target_grid, &
3394  farrayptr=data_ptr, rc=rc)
3395  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3396  call error_handler("IN FieldGet", rc)
3397 
3398  do j = clb(2), cub(2)
3399  do i = clb(1), cub(1)
3400  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.0
3401  enddo
3402  enddo
3403 
3404  print*,"- SET NON-LAND FLAG FOR TARGET GRID MAXIMUM GREENNESS."
3405  call esmf_fieldget(max_veg_greenness_target_grid, &
3406  farrayptr=data_ptr, rc=rc)
3407  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3408  call error_handler("IN FieldGet", rc)
3409 
3410  do j = clb(2), cub(2)
3411  do i = clb(1), cub(1)
3412  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.0
3413  enddo
3414  enddo
3415 
3416  print*,"- SET NON-LAND FLAG FOR TARGET GRID MINIMUM GREENNESS."
3417  call esmf_fieldget(min_veg_greenness_target_grid, &
3418  farrayptr=data_ptr, rc=rc)
3419  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3420  call error_handler("IN FieldGet", rc)
3421 
3422  do j = clb(2), cub(2)
3423  do i = clb(1), cub(1)
3424  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.0
3425  enddo
3426  enddo
3427 
3428  print*,"- SET NON-LAND FLAG FOR TARGET GRID VEGETATION GREENNESS."
3429  call esmf_fieldget(veg_greenness_target_grid, &
3430  farrayptr=veg_greenness_ptr, rc=rc)
3431  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3432  call error_handler("IN FieldGet", rc)
3433 
3434  do j = clb(2), cub(2)
3435  do i = clb(1), cub(1)
3436  if (landmask_ptr(i,j) /= 1) veg_greenness_ptr(i,j) = 0.0
3437  enddo
3438  enddo
3439 
3440  print*,"- SET NON-LAND FLAG FOR TARGET GRID MAX SNOW ALBEDO."
3441  call esmf_fieldget(mxsno_albedo_target_grid, &
3442  farrayptr=data_ptr, rc=rc)
3443  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3444  call error_handler("IN FieldGet", rc)
3445 
3446  do j = clb(2), cub(2)
3447  do i = clb(1), cub(1)
3448  if (landmask_ptr(i,j) /= 1) data_ptr(i,j) = 0.0
3449  enddo
3450  enddo
3451 
3452  print*,"- ZERO OUT TARGET GRID CANOPY MOISTURE CONTENT WHERE NO PLANTS."
3453  call esmf_fieldget(canopy_mc_target_grid, &
3454  farrayptr=data_ptr, rc=rc)
3455  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3456  call error_handler("IN FieldGet", rc)
3457 
3458  do j = clb(2), cub(2)
3459  do i = clb(1), cub(1)
3460  if (veg_greenness_ptr(i,j) <= 0.01) data_ptr(i,j) = 0.0
3461  enddo
3462  enddo
3463 
3464  print*,"- CALL FieldGet FOR TARGET GRID ICE SKIN TEMP."
3465  call esmf_fieldget(seaice_skin_temp_target_grid, &
3466  farrayptr=seaice_skint_ptr, rc=rc)
3467  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3468  call error_handler("IN FieldGet", rc)
3469 
3470  print*,"- SET TARGET GRID SKIN TEMP AT ICE POINTS."
3471  call esmf_fieldget(skin_temp_target_grid, &
3472  farrayptr=skint_ptr, rc=rc)
3473  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3474  call error_handler("IN FieldGet", rc)
3475 
3476  print*,"- CALL FieldGet FOR TARGET GRID SEA ICE FRACTION."
3477  call esmf_fieldget(seaice_fract_target_grid, &
3478  farrayptr=fice_ptr, rc=rc)
3479  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3480  call error_handler("IN FieldGet", rc)
3481 
3482  print*,"- SET TARGET GRID SEA ICE DEPTH TO ZERO AT NON-ICE POINTS."
3483  call esmf_fieldget(seaice_depth_target_grid, &
3484  farrayptr=hice_ptr, rc=rc)
3485  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3486  call error_handler("IN FieldGet", rc)
3487 
3488  do j = clb(2), cub(2)
3489  do i = clb(1), cub(1)
3490  if (fice_ptr(i,j) > 0.0) then
3491  skint_ptr(i,j) = (fice_ptr(i,j) * seaice_skint_ptr(i,j)) + &
3492  ( (1.0 - fice_ptr(i,j)) * frz_ice )
3493  else
3494  seaice_skint_ptr(i,j) = skint_ptr(i,j)
3495  hice_ptr(i,j) = 0.0
3496  endif
3497  enddo
3498  enddo
3499 
3500  print*,"- SET TARGET GRID SUBSTRATE TEMP AT ICE."
3501  call esmf_fieldget(substrate_temp_target_grid, &
3502  farrayptr=data_ptr, rc=rc)
3503  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3504  call error_handler("IN FieldGet", rc)
3505 
3506  do j = clb(2), cub(2)
3507  do i = clb(1), cub(1)
3508  if (landmask_ptr(i,j) == 2) then ! sea ice
3509  data_ptr(i,j) = frz_ice
3510  elseif (landmask_ptr(i,j) == 0) then ! open water flag value.
3511  data_ptr(i,j) = skint_ptr(i,j)
3512  endif
3513  enddo
3514  enddo
3515 
3516  print*,"- ZERO OUT TARGET GRID SNOW DEPTH AT OPEN WATER."
3517  call esmf_fieldget(snow_depth_target_grid, &
3518  farrayptr=data_ptr, rc=rc)
3519  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3520  call error_handler("IN FieldGet", rc)
3521 
3522  do j = clb(2), cub(2)
3523  do i = clb(1), cub(1)
3524  if (landmask_ptr(i,j) == 0) then ! open water
3525  data_ptr(i,j) = 0.0
3526  end if
3527  enddo
3528  enddo
3529 
3530  print*,"- ZERO OUT TARGET GRID SNOW LIQ AT OPEN WATER."
3531  call esmf_fieldget(snow_liq_equiv_target_grid, &
3532  farrayptr=data_ptr, rc=rc)
3533  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3534  call error_handler("IN FieldGet", rc)
3535 
3536  do j = clb(2), cub(2)
3537  do i = clb(1), cub(1)
3538  if (landmask_ptr(i,j) == 0) then ! open water
3539  data_ptr(i,j) = 0.0
3540  endif
3541  enddo
3542  enddo
3543 
3544  print*,"- SET NON-LAND FLAG VALUE FOR TARGET GRID TOTAL SOIL MOISTURE."
3545  call esmf_fieldget(soilm_tot_target_grid, &
3546  farrayptr=soilmt_ptr, rc=rc)
3547  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3548  call error_handler("IN FieldGet", rc)
3549 
3550  print*,"- SET NON-LAND FLAG VALUE FOR TARGET GRID LIQUID SOIL MOISTURE."
3551  call esmf_fieldget(soilm_liq_target_grid, &
3552  farrayptr=soilml_ptr, rc=rc)
3553  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3554  call error_handler("IN FieldGet", rc)
3555 
3556  do j = clb(2), cub(2)
3557  do i = clb(1), cub(1)
3558  if (landmask_ptr(i,j) == 2 .or. landmask_ptr(i,j) == 0 .or. &
3559  nint(veg_type_ptr(i,j)) == veg_type_landice_target) then
3560  soilmt_ptr(i,j,:) = 1.0
3561  soilml_ptr(i,j,:) = 1.0
3562  endif
3563  enddo
3564  enddo
3565 
3566  print*,"- SET OPEN WATER FLAG FOR TARGET GRID SOIL TEMPERATURE."
3567  call esmf_fieldget(soil_temp_target_grid, &
3568  farrayptr=data3d_ptr, rc=rc)
3569  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3570  call error_handler("IN FieldGet", rc)
3571 
3572  do j = clb(2), cub(2)
3573  do i = clb(1), cub(1)
3574  if (landmask_ptr(i,j) == 0) then
3575  data3d_ptr(i,j,:) = skint_ptr(i,j) ! open water flag value.
3576  endif
3577  enddo
3578  enddo
3579 
3580  return
3581 
3582  end subroutine qc_check
3583 
3588  subroutine nst_land_fill
3589 
3590  use model_grid, only : landmask_target_grid
3591 
3592  implicit none
3593 
3594  integer(esmf_kind_i8), pointer :: mask_ptr(:,:)
3595  integer :: rc,i
3596  integer, PARAMETER :: num_nst_fields_minus2 = 16
3597  integer, PARAMETER :: xz_fill = 30.0
3598  integer, PARAMETER :: nst_fill = 0.0
3599 
3600  real(esmf_kind_r8), pointer :: data_ptr(:,:)
3601  real(esmf_kind_r8), pointer :: skint_ptr(:,:)
3602 
3603  type(esmf_field) :: temp_field
3604  type(esmf_fieldbundle) :: nst_bundle
3605 
3606  print*,"- CALL FieldGet FOR TARGET GRID LANDMASK."
3607  call esmf_fieldget(landmask_target_grid, &
3608  farrayptr=mask_ptr, rc=rc)
3609  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3610  call error_handler("IN FieldGet", rc)
3611 
3612  nst_bundle = esmf_fieldbundlecreate(name="nst_bundle", rc=rc)
3613  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3614  call error_handler("IN FieldBundleCreate", rc)
3615 
3616  call esmf_fieldbundleadd(nst_bundle, (/c_d_target_grid,c_0_target_grid,d_conv_target_grid, &
3617  dt_cool_target_grid,ifd_target_grid,qrain_target_grid,&
3618  w_d_target_grid,w_0_target_grid,xs_target_grid,xt_target_grid,&
3619  xu_target_grid,xv_target_grid,xtts_target_grid,xzts_target_grid, &
3620  z_c_target_grid, zm_target_grid/), rc=rc)
3621  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3622  call error_handler("IN FieldBundleAdd", rc)
3623 
3624  print*,"- CALL FieldGet FOR TREF."
3625  call esmf_fieldget(tref_target_grid, &
3626  farrayptr=data_ptr, rc=rc)
3627  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3628  call error_handler("IN FieldGet", rc)
3629 
3630  print*,"- CALL FieldGet FOR SKIN T."
3631  call esmf_fieldget(skin_temp_target_grid, &
3632  farrayptr=skint_ptr, rc=rc)
3633  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3634  call error_handler("IN FieldGet", rc)
3635 
3636  where(mask_ptr /= 0) data_ptr = skint_ptr
3637 
3638 ! xz
3639 
3640  print*,"- CALL FieldGet FOR XZ."
3641  call esmf_fieldget(xz_target_grid, &
3642  farrayptr=data_ptr, rc=rc)
3643  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3644  call error_handler("IN FieldGet", rc)
3645 
3646  where(mask_ptr /= 0) data_ptr = xz_fill
3647 
3648  do i = 1,num_nst_fields_minus2
3649 
3650  call esmf_fieldbundleget(nst_bundle,i,temp_field,rc=rc)
3651  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3652  call error_handler("IN FieldBundleGet", rc)
3653 
3654  call esmf_fieldget(temp_field,farrayptr=data_ptr,rc=rc)
3655  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3656  call error_handler("IN FieldGet", rc)
3657 
3658  where(mask_ptr /= 0) data_ptr = nst_fill
3659 
3660  enddo
3661 
3662  call esmf_fieldbundledestroy(nst_bundle,rc=rc)
3663  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__))&
3664  call error_handler("IN FieldBundleDestroy", rc)
3665 
3666  end subroutine nst_land_fill
3667 
3672 
3673  use model_grid, only : target_grid, lsoil_target
3674 
3675  implicit none
3676 
3677  integer :: rc
3678 
3679  real(esmf_kind_r8), pointer :: target_ptr(:,:), target_ptr_3d(:,:,:)
3680  real :: init_val = -999.9
3681 
3682  print*,"- CALL FieldCreate FOR TARGET GRID T2M."
3683  t2m_target_grid = esmf_fieldcreate(target_grid, &
3684  typekind=esmf_typekind_r8, &
3685  staggerloc=esmf_staggerloc_center, rc=rc)
3686  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3687  call error_handler("IN FieldCreate", rc)
3688 
3689  print*,"- INITIALIZE TARGET grid t2m."
3690  call esmf_fieldget(t2m_target_grid, &
3691  farrayptr=target_ptr, rc=rc)
3692  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3693  call error_handler("IN FieldGet", rc)
3694 
3695  target_ptr = init_val
3696 
3697  print*,"- CALL FieldCreate FOR TARGET GRID Q2M."
3698  q2m_target_grid = esmf_fieldcreate(target_grid, &
3699  typekind=esmf_typekind_r8, &
3700  staggerloc=esmf_staggerloc_center, rc=rc)
3701  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3702  call error_handler("IN FieldCreate", rc)
3703 
3704  print*,"- INITIALIZE TARGET grid q2m."
3705  call esmf_fieldget(q2m_target_grid, &
3706  farrayptr=target_ptr, rc=rc)
3707  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3708  call error_handler("IN FieldGet", rc)
3709 
3710  target_ptr = init_val
3711 
3712  print*,"- CALL FieldCreate FOR TARGET GRID TPRCP."
3713  tprcp_target_grid = esmf_fieldcreate(target_grid, &
3714  typekind=esmf_typekind_r8, &
3715  staggerloc=esmf_staggerloc_center, rc=rc)
3716  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3717  call error_handler("IN FieldCreate", rc)
3718 
3719  print*,"- INITIALIZE TARGET grid tprcp."
3720  call esmf_fieldget(tprcp_target_grid, &
3721  farrayptr=target_ptr, rc=rc)
3722  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3723  call error_handler("IN FieldGet", rc)
3724 
3725  target_ptr = init_val
3726 
3727  print*,"- CALL FieldCreate FOR TARGET GRID F10M."
3728  f10m_target_grid = esmf_fieldcreate(target_grid, &
3729  typekind=esmf_typekind_r8, &
3730  staggerloc=esmf_staggerloc_center, rc=rc)
3731  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3732  call error_handler("IN FieldCreate", rc)
3733 
3734  print*,"- INITIALIZE TARGET grid f10m."
3735  call esmf_fieldget(f10m_target_grid, &
3736  farrayptr=target_ptr, rc=rc)
3737  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3738  call error_handler("IN FieldGet", rc)
3739 
3740  target_ptr = init_val
3741 
3742  print*,"- CALL FieldCreate FOR TARGET GRID FFMM."
3743  ffmm_target_grid = esmf_fieldcreate(target_grid, &
3744  typekind=esmf_typekind_r8, &
3745  staggerloc=esmf_staggerloc_center, rc=rc)
3746  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3747  call error_handler("IN FieldCreate", rc)
3748 
3749  print*,"- INITIALIZE TARGET grid ffmm."
3750  call esmf_fieldget(ffmm_target_grid, &
3751  farrayptr=target_ptr, rc=rc)
3752  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3753  call error_handler("IN FieldGet", rc)
3754 
3755  target_ptr = init_val
3756 
3757  print*,"- CALL FieldCreate FOR TARGET GRID USTAR."
3758  ustar_target_grid = esmf_fieldcreate(target_grid, &
3759  typekind=esmf_typekind_r8, &
3760  staggerloc=esmf_staggerloc_center, rc=rc)
3761  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3762  call error_handler("IN FieldCreate", rc)
3763 
3764  print*,"- INITIALIZE TARGET grid ustar."
3765  call esmf_fieldget(ustar_target_grid, &
3766  farrayptr=target_ptr, rc=rc)
3767  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3768  call error_handler("IN FieldGet", rc)
3769 
3770  target_ptr = init_val
3771 
3772  print*,"- CALL FieldCreate FOR TARGET GRID SNOW LIQ EQUIV."
3773  snow_liq_equiv_target_grid = esmf_fieldcreate(target_grid, &
3774  typekind=esmf_typekind_r8, &
3775  staggerloc=esmf_staggerloc_center, rc=rc)
3776  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3777  call error_handler("IN FieldCreate", rc)
3778 
3779  print*,"- INITIALIZE TARGET grid snow liq equiv."
3780  call esmf_fieldget(snow_liq_equiv_target_grid, &
3781  farrayptr=target_ptr, rc=rc)
3782  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3783  call error_handler("IN FieldGet", rc)
3784 
3785  target_ptr = init_val
3786 
3787  print*,"- CALL FieldCreate FOR TARGET GRID SNOW DEPTH."
3788  snow_depth_target_grid = esmf_fieldcreate(target_grid, &
3789  typekind=esmf_typekind_r8, &
3790  staggerloc=esmf_staggerloc_center, rc=rc)
3791  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3792  call error_handler("IN FieldCreate", rc)
3793 
3794  print*,"- INITIALIZE TARGET grid snow depth."
3795  call esmf_fieldget(snow_depth_target_grid, &
3796  farrayptr=target_ptr, rc=rc)
3797  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3798  call error_handler("IN FieldGet", rc)
3799 
3800  target_ptr = init_val
3801 
3802  print*,"- CALL FieldCreate FOR TARGET GRID SEA ICE FRACTION."
3803  seaice_fract_target_grid = esmf_fieldcreate(target_grid, &
3804  typekind=esmf_typekind_r8, &
3805  staggerloc=esmf_staggerloc_center, rc=rc)
3806  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3807  call error_handler("IN FieldCreate", rc)
3808 
3809  print*,"- INITIALIZE TARGET grid sea ice fraction."
3810  call esmf_fieldget(seaice_fract_target_grid, &
3811  farrayptr=target_ptr, rc=rc)
3812  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3813  call error_handler("IN FieldGet", rc)
3814 
3815  target_ptr = init_val
3816 
3817  print*,"- CALL FieldCreate FOR TARGET GRID SEA ICE DEPTH."
3818  seaice_depth_target_grid = esmf_fieldcreate(target_grid, &
3819  typekind=esmf_typekind_r8, &
3820  staggerloc=esmf_staggerloc_center, rc=rc)
3821  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3822  call error_handler("IN FieldCreate", rc)
3823 
3824  print*,"- INITIALIZE TARGET sea ice depth."
3825  call esmf_fieldget(seaice_depth_target_grid, &
3826  farrayptr=target_ptr, rc=rc)
3827  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3828  call error_handler("IN FieldGet", rc)
3829 
3830  target_ptr = init_val
3831 
3832  print*,"- CALL FieldCreate FOR TARGET GRID SEA ICE SKIN TEMP."
3833  seaice_skin_temp_target_grid = esmf_fieldcreate(target_grid, &
3834  typekind=esmf_typekind_r8, &
3835  staggerloc=esmf_staggerloc_center, rc=rc)
3836  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3837  call error_handler("IN FieldCreate", rc)
3838 
3839  print*,"- INITIALIZE TARGET sea ice skin temp."
3840  call esmf_fieldget(seaice_skin_temp_target_grid, &
3841  farrayptr=target_ptr, rc=rc)
3842  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3843  call error_handler("IN FieldGet", rc)
3844 
3845  target_ptr = init_val
3846 
3847  print*,"- CALL FieldCreate FOR TARGET GRID SRFLAG."
3848  srflag_target_grid = esmf_fieldcreate(target_grid, &
3849  typekind=esmf_typekind_r8, &
3850  staggerloc=esmf_staggerloc_center, rc=rc)
3851  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3852  call error_handler("IN FieldCreate", rc)
3853 
3854  print*,"- INITIALIZE TARGET srflag."
3855  call esmf_fieldget(srflag_target_grid, &
3856  farrayptr=target_ptr, rc=rc)
3857  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3858  call error_handler("IN FieldGet", rc)
3859 
3860  target_ptr = init_val
3861 
3862  print*,"- CALL FieldCreate FOR TARGET GRID SKIN TEMPERATURE."
3863  skin_temp_target_grid = esmf_fieldcreate(target_grid, &
3864  typekind=esmf_typekind_r8, &
3865  staggerloc=esmf_staggerloc_center, rc=rc)
3866  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3867  call error_handler("IN FieldCreate", rc)
3868 
3869  print*,"- INITIALIZE TARGET grid skin temp."
3870  call esmf_fieldget(skin_temp_target_grid, &
3871  farrayptr=target_ptr, rc=rc)
3872  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3873  call error_handler("IN FieldGet", rc)
3874 
3875  target_ptr = init_val
3876 
3877  print*,"- CALL FieldCreate FOR TARGET GRID CANOPY MOISTURE CONTENT."
3878  canopy_mc_target_grid = esmf_fieldcreate(target_grid, &
3879  typekind=esmf_typekind_r8, &
3880  staggerloc=esmf_staggerloc_center, rc=rc)
3881  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3882  call error_handler("IN FieldCreate", rc)
3883 
3884  print*,"- INITIALIZE TARGET grid canopy moisture."
3885  call esmf_fieldget(canopy_mc_target_grid, &
3886  farrayptr=target_ptr, rc=rc)
3887  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3888  call error_handler("IN FieldGet", rc)
3889 
3890  target_ptr = init_val
3891 
3892  print*,"- CALL FieldCreate FOR TARGET GRID LEAF AREA INDEX."
3893  lai_target_grid = esmf_fieldcreate(target_grid, &
3894  typekind=esmf_typekind_r8, &
3895  staggerloc=esmf_staggerloc_center, rc=rc)
3896  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3897  call error_handler("IN FieldCreate", rc)
3898 
3899  print*,"- INITIALIZE TARGET leaf area index."
3900  call esmf_fieldget(lai_target_grid, &
3901  farrayptr=target_ptr, rc=rc)
3902  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3903  call error_handler("IN FieldGet", rc)
3904 
3905  target_ptr = init_val
3906 
3907  print*,"- CALL FieldCreate FOR TARGET GRID Z0."
3908  z0_target_grid = esmf_fieldcreate(target_grid, &
3909  typekind=esmf_typekind_r8, &
3910  staggerloc=esmf_staggerloc_center, rc=rc)
3911  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3912  call error_handler("IN FieldCreate", rc)
3913 
3914  print*,"- INITIALIZE TARGET grid z0."
3915  call esmf_fieldget(z0_target_grid, &
3916  farrayptr=target_ptr, rc=rc)
3917  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3918  call error_handler("IN FieldGet", rc)
3919 
3920  target_ptr = init_val
3921 
3922  print*,"- CALL FieldCreate FOR INTERPOLATED TARGET GRID TERRAIN."
3923  terrain_from_input_grid = esmf_fieldcreate(target_grid, &
3924  typekind=esmf_typekind_r8, &
3925  staggerloc=esmf_staggerloc_center, rc=rc)
3926  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3927  call error_handler("IN FieldCreate", rc)
3928 
3929  print*,"- INITIALIZE TARGET grid interpolated terrain."
3930  call esmf_fieldget(terrain_from_input_grid, &
3931  farrayptr=target_ptr, rc=rc)
3932  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3933  call error_handler("IN FieldGet", rc)
3934 
3935  target_ptr = init_val
3936 
3937  print*,"- CALL FieldCreate FOR INTERPOLATED TARGET GRID SOIL TYPE."
3938  soil_type_from_input_grid = esmf_fieldcreate(target_grid, &
3939  typekind=esmf_typekind_r8, &
3940  staggerloc=esmf_staggerloc_center, rc=rc)
3941  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3942  call error_handler("IN FieldCreate", rc)
3943 
3944  print*,"- INITIALIZE TARGET grid soil type"
3945  call esmf_fieldget(soil_type_from_input_grid, &
3946  farrayptr=target_ptr, rc=rc)
3947  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3948  call error_handler("IN FieldGet", rc)
3949 
3950  target_ptr = init_val
3951 
3952  print*,"- CALL FieldCreate FOR TARGET GRID SOIL TEMPERATURE."
3953  soil_temp_target_grid = esmf_fieldcreate(target_grid, &
3954  typekind=esmf_typekind_r8, &
3955  staggerloc=esmf_staggerloc_center, &
3956  ungriddedlbound=(/1/), &
3957  ungriddedubound=(/lsoil_target/), rc=rc)
3958  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3959  call error_handler("IN FieldCreate", rc)
3960 
3961  print*,"- INITIALIZE TARGET grid soil temp"
3962  call esmf_fieldget(soil_temp_target_grid, &
3963  farrayptr=target_ptr_3d, rc=rc)
3964  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3965  call error_handler("IN FieldGet", rc)
3966 
3967  target_ptr_3d = init_val
3968 
3969  print*,"- CALL FieldCreate FOR TARGET GRID TOTAL SOIL MOISTURE."
3970  soilm_tot_target_grid = esmf_fieldcreate(target_grid, &
3971  typekind=esmf_typekind_r8, &
3972  staggerloc=esmf_staggerloc_center, &
3973  ungriddedlbound=(/1/), &
3974  ungriddedubound=(/lsoil_target/), rc=rc)
3975  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3976  call error_handler("IN FieldCreate", rc)
3977 
3978  print*,"- INITIALIZE TARGET grid soil moist"
3979  call esmf_fieldget(soilm_tot_target_grid, &
3980  farrayptr=target_ptr_3d, rc=rc)
3981  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3982  call error_handler("IN FieldGet", rc)
3983 
3984  target_ptr_3d = init_val
3985 
3986  print*,"- CALL FieldCreate FOR TARGET GRID LIQUID SOIL MOISTURE."
3987  soilm_liq_target_grid = esmf_fieldcreate(target_grid, &
3988  typekind=esmf_typekind_r8, &
3989  staggerloc=esmf_staggerloc_center, &
3990  ungriddedlbound=(/1/), &
3991  ungriddedubound=(/lsoil_target/), rc=rc)
3992  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3993  call error_handler("IN FieldCreate", rc)
3994 
3995  print*,"- INITIALIZE TARGET grid soil liq"
3996  call esmf_fieldget(soilm_liq_target_grid, &
3997  farrayptr=target_ptr_3d, rc=rc)
3998  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
3999  call error_handler("IN FieldGet", rc)
4000 
4001  target_ptr_3d = init_val
4002 
4003  end subroutine create_surface_esmf_fields
4004 
4009 
4010  use model_grid, only : target_grid
4011 
4012  implicit none
4013 
4014  integer :: rc
4015 
4016  print*,"- CALL FieldCreate FOR TARGET GRID C_D."
4017  c_d_target_grid = esmf_fieldcreate(target_grid, &
4018  typekind=esmf_typekind_r8, &
4019  name='c_d', &
4020  staggerloc=esmf_staggerloc_center, rc=rc)
4021  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4022  call error_handler("IN FieldCreate", rc)
4023 
4024  print*,"- CALL FieldCreate FOR TARGET GRID C_0."
4025  c_0_target_grid = esmf_fieldcreate(target_grid, &
4026  typekind=esmf_typekind_r8, &
4027  name='c_0', &
4028  staggerloc=esmf_staggerloc_center, rc=rc)
4029  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4030  call error_handler("IN FieldCreate", rc)
4031 
4032  print*,"- CALL FieldCreate FOR TARGET GRID D_CONV."
4033  d_conv_target_grid = esmf_fieldcreate(target_grid, &
4034  typekind=esmf_typekind_r8, &
4035  name='d_conv',&
4036  staggerloc=esmf_staggerloc_center, rc=rc)
4037  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4038  call error_handler("IN FieldCreate", rc)
4039 
4040  print*,"- CALL FieldCreate FOR TARGET GRID DT_COOL."
4041  dt_cool_target_grid = esmf_fieldcreate(target_grid, &
4042  typekind=esmf_typekind_r8, &
4043  name='dt_cool',&
4044  staggerloc=esmf_staggerloc_center, rc=rc)
4045  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4046  call error_handler("IN FieldCreate", rc)
4047 
4048  print*,"- CALL FieldCreate FOR TARGET GRID IFD."
4049  ifd_target_grid = esmf_fieldcreate(target_grid, &
4050  typekind=esmf_typekind_r8, &
4051  name='ifd',&
4052  staggerloc=esmf_staggerloc_center, rc=rc)
4053  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4054  call error_handler("IN FieldCreate", rc)
4055 
4056  print*,"- CALL FieldCreate FOR TARGET GRID QRAIN."
4057  qrain_target_grid = esmf_fieldcreate(target_grid, &
4058  typekind=esmf_typekind_r8, &
4059  name='qrain',&
4060  staggerloc=esmf_staggerloc_center, rc=rc)
4061  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4062  call error_handler("IN FieldCreate", rc)
4063 
4064  print*,"- CALL FieldCreate FOR TARGET GRID TREF."
4065  tref_target_grid = esmf_fieldcreate(target_grid, &
4066  typekind=esmf_typekind_r8, &
4067  name='tref',&
4068  staggerloc=esmf_staggerloc_center, rc=rc)
4069  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4070  call error_handler("IN FieldCreate", rc)
4071 
4072  print*,"- CALL FieldCreate FOR TARGET GRID W_D."
4073  w_d_target_grid = esmf_fieldcreate(target_grid, &
4074  typekind=esmf_typekind_r8, &
4075  name='w_d',&
4076  staggerloc=esmf_staggerloc_center, rc=rc)
4077  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4078  call error_handler("IN FieldCreate", rc)
4079 
4080  print*,"- CALL FieldCreate FOR TARGET GRID W_0."
4081  w_0_target_grid = esmf_fieldcreate(target_grid, &
4082  typekind=esmf_typekind_r8, &
4083  name='w_0',&
4084  staggerloc=esmf_staggerloc_center, rc=rc)
4085  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4086  call error_handler("IN FieldCreate", rc)
4087 
4088  print*,"- CALL FieldCreate FOR TARGET GRID XS."
4089  xs_target_grid = esmf_fieldcreate(target_grid, &
4090  typekind=esmf_typekind_r8, &
4091  name='xs',&
4092  staggerloc=esmf_staggerloc_center, rc=rc)
4093  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4094  call error_handler("IN FieldCreate", rc)
4095 
4096  print*,"- CALL FieldCreate FOR TARGET GRID XT."
4097  xt_target_grid = esmf_fieldcreate(target_grid, &
4098  typekind=esmf_typekind_r8, &
4099  name='xt',&
4100  staggerloc=esmf_staggerloc_center, rc=rc)
4101  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4102  call error_handler("IN FieldCreate", rc)
4103 
4104  print*,"- CALL FieldCreate FOR TARGET GRID XU."
4105  xu_target_grid = esmf_fieldcreate(target_grid, &
4106  typekind=esmf_typekind_r8, &
4107  name='xu',&
4108  staggerloc=esmf_staggerloc_center, rc=rc)
4109  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4110  call error_handler("IN FieldCreate", rc)
4111 
4112  print*,"- CALL FieldCreate FOR TARGET GRID XV."
4113  xv_target_grid = esmf_fieldcreate(target_grid, &
4114  typekind=esmf_typekind_r8, &
4115  name='xv',&
4116  staggerloc=esmf_staggerloc_center, rc=rc)
4117  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4118  call error_handler("IN FieldCreate", rc)
4119 
4120  print*,"- CALL FieldCreate FOR TARGET GRID XZ."
4121  xz_target_grid = esmf_fieldcreate(target_grid, &
4122  typekind=esmf_typekind_r8, &
4123  name='xz',&
4124  staggerloc=esmf_staggerloc_center, rc=rc)
4125  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4126  call error_handler("IN FieldCreate", rc)
4127 
4128  print*,"- CALL FieldCreate FOR TARGET GRID XTTS."
4129  xtts_target_grid = esmf_fieldcreate(target_grid, &
4130  typekind=esmf_typekind_r8, &
4131  name='xtts',&
4132  staggerloc=esmf_staggerloc_center, rc=rc)
4133  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4134  call error_handler("IN FieldCreate", rc)
4135 
4136  print*,"- CALL FieldCreate FOR TARGET GRID XZTS."
4137  xzts_target_grid = esmf_fieldcreate(target_grid, &
4138  typekind=esmf_typekind_r8, &
4139  name='xzts',&
4140  staggerloc=esmf_staggerloc_center, rc=rc)
4141  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4142  call error_handler("IN FieldCreate", rc)
4143 
4144  print*,"- CALL FieldCreate FOR TARGET GRID Z_C."
4145  z_c_target_grid = esmf_fieldcreate(target_grid, &
4146  typekind=esmf_typekind_r8, &
4147  name='z_c',&
4148  staggerloc=esmf_staggerloc_center, rc=rc)
4149  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4150  call error_handler("IN FieldCreate", rc)
4151 
4152  print*,"- CALL FieldCreate FOR TARGET GRID ZM."
4153  zm_target_grid = esmf_fieldcreate(target_grid, &
4154  typekind=esmf_typekind_r8, &
4155  name='zm',&
4156  staggerloc=esmf_staggerloc_center, rc=rc)
4157  if(esmf_logfounderror(rctocheck=rc,msg=esmf_logerr_passthru,line=__line__,file=__file__)) &
4158  call error_handler("IN FieldCreate", rc)
4159 
4160  end subroutine create_nst_esmf_fields
4161 
4170  subroutine ij_to_i_j(ij, itile, jtile, i, j)
4171 
4172  implicit none
4173 
4174  integer(esmf_kind_i4), intent(in) :: ij
4175  integer , intent(in) :: itile, jtile
4176 
4177  integer , intent(out) :: i, j
4178 
4179  integer :: tile_num
4180  integer :: pt_loc_this_tile
4181 
4182  tile_num = ((ij-1) / (itile*jtile)) ! tile number minus 1
4183  pt_loc_this_tile = ij - (tile_num * itile * jtile)
4184  ! "ij" location of point within tile.
4185 
4186  j = (pt_loc_this_tile - 1) / itile + 1
4187  i = mod(pt_loc_this_tile, itile)
4188 
4189  if (i==0) i = itile
4190 
4191  return
4192 
4193  end subroutine ij_to_i_j
4194 
4200 
4201  implicit none
4202 
4203  integer :: rc
4204 
4205  print*,"- DESTROY TARGET GRID SURFACE FIELDS."
4206 
4207  call esmf_fielddestroy(t2m_target_grid, rc=rc)
4208  call esmf_fielddestroy(q2m_target_grid, rc=rc)
4209  call esmf_fielddestroy(tprcp_target_grid, rc=rc)
4210  call esmf_fielddestroy(f10m_target_grid, rc=rc)
4211  call esmf_fielddestroy(ffmm_target_grid, rc=rc)
4212  call esmf_fielddestroy(ustar_target_grid, rc=rc)
4213  call esmf_fielddestroy(snow_liq_equiv_target_grid, rc=rc)
4214  call esmf_fielddestroy(snow_depth_target_grid, rc=rc)
4215  call esmf_fielddestroy(seaice_fract_target_grid, rc=rc)
4216  call esmf_fielddestroy(seaice_depth_target_grid, rc=rc)
4217  call esmf_fielddestroy(seaice_skin_temp_target_grid, rc=rc)
4218  call esmf_fielddestroy(srflag_target_grid, rc=rc)
4219  call esmf_fielddestroy(skin_temp_target_grid, rc=rc)
4220  call esmf_fielddestroy(canopy_mc_target_grid, rc=rc)
4221  call esmf_fielddestroy(lai_target_grid,rc=rc)
4222  call esmf_fielddestroy(z0_target_grid, rc=rc)
4223  call esmf_fielddestroy(terrain_from_input_grid, rc=rc)
4224  call esmf_fielddestroy(terrain_from_input_grid_land, rc=rc)
4225  call esmf_fielddestroy(soil_type_from_input_grid, rc=rc)
4226  call esmf_fielddestroy(soil_temp_target_grid, rc=rc)
4227  call esmf_fielddestroy(soilm_tot_target_grid, rc=rc)
4228  call esmf_fielddestroy(soilm_liq_target_grid, rc=rc)
4229 
4230  end subroutine cleanup_target_sfc_data
4231 
4237 
4238  implicit none
4239 
4240  integer :: rc
4241 
4242  print*,"- DESTROY TARGET GRID NST DATA."
4243 
4244  call esmf_fielddestroy(c_d_target_grid, rc=rc)
4245  call esmf_fielddestroy(c_0_target_grid, rc=rc)
4246  call esmf_fielddestroy(d_conv_target_grid, rc=rc)
4247  call esmf_fielddestroy(dt_cool_target_grid, rc=rc)
4248  call esmf_fielddestroy(ifd_target_grid, rc=rc)
4249  call esmf_fielddestroy(qrain_target_grid, rc=rc)
4250  call esmf_fielddestroy(tref_target_grid, rc=rc)
4251  call esmf_fielddestroy(w_d_target_grid, rc=rc)
4252  call esmf_fielddestroy(w_0_target_grid, rc=rc)
4253  call esmf_fielddestroy(xs_target_grid, rc=rc)
4254  call esmf_fielddestroy(xt_target_grid, rc=rc)
4255  call esmf_fielddestroy(xu_target_grid, rc=rc)
4256  call esmf_fielddestroy(xv_target_grid, rc=rc)
4257  call esmf_fielddestroy(xz_target_grid, rc=rc)
4258  call esmf_fielddestroy(xtts_target_grid, rc=rc)
4259  call esmf_fielddestroy(xzts_target_grid, rc=rc)
4260  call esmf_fielddestroy(z_c_target_grid, rc=rc)
4261  call esmf_fielddestroy(zm_target_grid, rc=rc)
4262 
4263  end subroutine cleanup_target_nst_data
4264 
4265  end module surface
subroutine, public cleanup_input_sfc_data
Free up memory associated with sfc data.
subroutine, public calc_soil_params_driver(localpet)
Driver routine to compute soil parameters for each soil type.
subroutine qc_check
Perform some quality control checks before output.
Definition: surface.F90:3253
subroutine write_fv3_sfc_data_netcdf(localpet)
Writes surface and nst data into a &#39;coldstart&#39; file (netcdf).
subroutine, public get_static_fields(localpet)
Driver routine to read/time interpolate static/climo fields on the fv3 target grid.
Definition: static_data.F90:47
subroutine, public interp(localpet)
Horizontally interpolate surface fields from input to target FV3 grid using esmf routines.
Definition: surface.F90:293
subroutine, public read_input_sfc_data(localpet)
Driver to read input grid surface data.
Definition: input_data.F90:381
Process surface and nst fields.
Definition: surface.F90:21
subroutine, public read_input_nst_data(localpet)
Driver to read input grid nst data.
Definition: input_data.F90:219
subroutine, public cleanup_target_sfc_data
Free up memory once the target grid surface fields are no longer needed.
Definition: surface.F90:4199
Sets up the ESMF grid objects for the input data grid and target FV3 grid.
Definition: model_grid.F90:9
subroutine, public cleanup_target_nst_data
Free up memory once the target grid nst fields are no longer needed.
Definition: surface.F90:4236
Read atmospheric, surface and nst data on the input grid.
Definition: input_data.F90:14
subroutine, public cleanup_static_fields
Free up memory for fields in this module.
Replace undefined values with a valid value.
Definition: search_util.F90:15
subroutine rescale_soil_moisture
Adjust soil moisture for changes in soil type between the input and target grids. ...
Definition: surface.F90:2839
subroutine adjust_soil_levels(localpet)
Adjust soil levels of the input grid if there is a mismatch between input and target grids...
Definition: surface.F90:3083
subroutine error_handler(string, rc)
General error handler.
Definition: utils.F90:9
subroutine, public create_nst_esmf_fields
Create ESMF fields for the target grid nst variables.
Definition: surface.F90:4008
This module contains code to read the setup namelist file, handle the varmap file for GRIB2 data...
real function frh2o(TKELV, SMC, SH2O, SMCMAX, BEXP, PSIS)
Calculate supercooled soil moisture.
Definition: surface.F90:2701
subroutine ij_to_i_j(ij, itile, jtile, i, j)
Convert 1d index to 2d indices.
Definition: surface.F90:4170
subroutine, public cleanup_input_nst_data
Free up memory associated with nst data.
subroutine adjust_soilt_for_terrain
Adjust soil temperature for changes in terrain height between the input and target grids...
Definition: surface.F90:3007
subroutine roughness
Set roughness length at land and sea ice.
Definition: surface.F90:3199
Reads static surface climatological data for the target FV3 grid (such as soil type and vegetation ty...
Definition: static_data.F90:13
subroutine, public search(field, mask, idim, jdim, tile, field_num, latitude, terrain_land, soilt_climo)
Replace undefined surface values.
Definition: search_util.F90:46
subroutine calc_liq_soil_moisture
Compute liquid portion of the total soil moisture.
Definition: surface.F90:2557
subroutine, public create_surface_esmf_fields
Create ESMF fields for the target grid surface variables.
Definition: surface.F90:3671
subroutine, public nst_land_fill
nst is not active at land or sea ice points.
Definition: surface.F90:3588
subroutine, public surface_driver(localpet)
Driver routine to process surface/nst data.
Definition: surface.F90:156