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