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