forked from ufs-community/UFS_UTILS
-
Notifications
You must be signed in to change notification settings - Fork 2
/
surface.F90
3731 lines (3028 loc) · 162 KB
/
surface.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!> @file
!! @brief Process land, sea/lake ice, open water/Near Sea Surface
!! Temperature (NSST) fields.
!! @author George Gayno NCEP/EMC
!> Process surface and nst fields. Interpolates fields from the input
!! to target grids. Adjusts soil temperature according to differences
!! in input and target grid terrain. Rescales soil moisture for soil
!! type differences between input and target grid. Computes frozen
!! portion of total soil moisture.
!!
!! Assumes the input land data are Noah LSM-based, and the fv3 run
!! will use the Noah LSM. NSST fields are not available when using
!! GRIB2 input data.
!!
!! Public variables are defined below. "target" indicates field
!! associated with the target grid. "input" indicates field associated
!! with the input grid.
!!
!! @author George Gayno NCEP/EMC
module surface
use esmf
use surface_target_data, only : canopy_mc_target_grid, t2m_target_grid, &
q2m_target_grid, tprcp_target_grid, &
f10m_target_grid, seaice_fract_target_grid, &
ffmm_target_grid, ustar_target_grid, &
srflag_target_grid, soil_temp_target_grid, &
seaice_depth_target_grid, snow_liq_equiv_target_grid, &
seaice_skin_temp_target_grid, skin_temp_target_grid, &
snow_depth_target_grid, &
c_d_target_grid, c_0_target_grid, &
d_conv_target_grid, dt_cool_target_grid, &
ifd_target_grid, qrain_target_grid, &
tref_target_grid, w_d_target_grid, &
w_0_target_grid, xs_target_grid, &
xt_target_grid, xu_target_grid, &
xv_target_grid, xz_target_grid, &
xtts_target_grid, xzts_target_grid, &
z_c_target_grid, zm_target_grid, &
soilm_tot_target_grid, lai_target_grid, &
soilm_liq_target_grid, ice_temp_target_grid, &
snow_depth_at_ice_target_grid, &
z0_water_target_grid, &
z0_ice_target_grid, sst_target_grid, &
snow_liq_equiv_at_ice_target_grid
use write_data, only : write_fv3_sfc_data_netcdf
use utilities, only : error_handler
implicit none
private
integer, parameter :: veg_type_landice_target = 15
!< Vegetation type category that
!< defines permanent land ice points.
!< The Noah LSM land ice physics
!< are applied at these points.
type(esmf_field) :: soil_type_from_input_grid
!< soil type interpolated from
!< input grid
type(esmf_field) :: terrain_from_input_grid
!< terrain height interpolated
!< from input grid
type(esmf_field) :: terrain_from_input_grid_land
!< terrain height interpolated
!< from input grid at all land points
real, parameter, private :: blim = 5.5
!< soil 'b' parameter limit
real, parameter, private :: frz_h2o = 273.15
!< melting pt water
real, parameter, private :: frz_ice = 271.21
!< melting pt sea ice
real, parameter, private :: grav = 9.81
!< gravity
real, parameter, private :: hlice = 3.335E5
!< latent heat of fusion
real(esmf_kind_r8), parameter, private :: missing = -1.e20_esmf_kind_r8
!< flag for non-active points.
type realptr_2d
real(esmf_kind_r8), pointer :: p(:,:)
!< array of 2d pointers
end type realptr_2d
!< pointer to hold array of 2d pointers
type realptr_3d
real(esmf_kind_r8), pointer :: p(:,:,:)
!< array of 3d pointers
end type realptr_3d
!< pointer to hold array of 3d pointers
public :: surface_driver
public :: create_nst_esmf_fields
public :: interp
public :: create_surface_esmf_fields
public :: nst_land_fill
public :: regrid_many
public :: search_many
contains
!> Driver routine to process surface/nst data
!!
!! @param[in] localpet ESMF local persistent execution thread
!!
!! @author George Gayno NCEP/EMC
subroutine surface_driver(localpet)
use sfc_input_data, only : cleanup_input_sfc_data, &
read_input_sfc_data
use nst_input_data, only : cleanup_input_nst_data, &
read_input_nst_data
use program_setup, only : calc_soil_params_driver, &
convert_nst
use static_data, only : get_static_fields, &
cleanup_static_fields
use surface_target_data, only : cleanup_target_nst_data
use utilities, only : error_handler
implicit none
integer, intent(in) :: localpet
!-----------------------------------------------------------------------
! Compute soil-based parameters.
!-----------------------------------------------------------------------
call calc_soil_params_driver(localpet)
!-----------------------------------------------------------------------
! Get static data (like vegetation type) on the target grid.
!-----------------------------------------------------------------------
call get_static_fields(localpet)
!-----------------------------------------------------------------------
! Read surface data on input grid.
!-----------------------------------------------------------------------
call read_input_sfc_data(localpet)
!-----------------------------------------------------------------------
! Read nst data on input grid.
!-----------------------------------------------------------------------
if (convert_nst) call read_input_nst_data(localpet)
!-----------------------------------------------------------------------
! Create surface field objects for target grid.
!-----------------------------------------------------------------------
call create_surface_esmf_fields
!-----------------------------------------------------------------------
! Create nst field objects for target grid.
!-----------------------------------------------------------------------
if (convert_nst) call create_nst_esmf_fields
!-----------------------------------------------------------------------
! Adjust soil levels of input grid !! not implemented yet
!-----------------------------------------------------------------------
call adjust_soil_levels(localpet)
!-----------------------------------------------------------------------
! Horizontally interpolate fields.
!-----------------------------------------------------------------------
call interp(localpet)
!---------------------------------------------------------------------------------------------
! Adjust soil/landice column temperatures for any change in elevation between the
! input and target grids.
!---------------------------------------------------------------------------------------------
call adjust_soilt_for_terrain
!---------------------------------------------------------------------------------------------
! Rescale soil moisture for changes in soil type between the input and target grids.
!---------------------------------------------------------------------------------------------
call rescale_soil_moisture
!---------------------------------------------------------------------------------------------
! Compute liquid portion of total soil moisture.
!---------------------------------------------------------------------------------------------
call calc_liq_soil_moisture
!---------------------------------------------------------------------------------------------
! Set z0 at water and sea ice.
!---------------------------------------------------------------------------------------------
call roughness
!---------------------------------------------------------------------------------------------
! Perform some final qc checks.
!---------------------------------------------------------------------------------------------
call qc_check
!---------------------------------------------------------------------------------------------
! Set flag values at land for nst fields.
!---------------------------------------------------------------------------------------------
if (convert_nst) call nst_land_fill
!---------------------------------------------------------------------------------------------
! Free up memory.
!---------------------------------------------------------------------------------------------
call cleanup_input_sfc_data
if (convert_nst) call cleanup_input_nst_data
!---------------------------------------------------------------------------------------------
! Update land mask for ice.
!---------------------------------------------------------------------------------------------
call update_landmask
!---------------------------------------------------------------------------------------------
! Write data to file.
!---------------------------------------------------------------------------------------------
call write_fv3_sfc_data_netcdf(localpet)
!---------------------------------------------------------------------------------------------
! Free up memory.
!---------------------------------------------------------------------------------------------
if (convert_nst) call cleanup_target_nst_data
call cleanup_all_target_sfc_data
call cleanup_static_fields
return
end subroutine surface_driver
!> Horizontally interpolate surface fields from input to target FV3
!> grid using esmf routines.
!!
!! @param[in] localpet ESMF local persistent execution thread
!!
!! @author George Gayno NOAA/EMC
subroutine interp(localpet)
use mpi_f08
use esmf
use sfc_input_data, only : canopy_mc_input_grid, &
f10m_input_grid, &
ffmm_input_grid, &
landsea_mask_input_grid, &
q2m_input_grid, &
seaice_depth_input_grid, &
seaice_fract_input_grid, &
seaice_skin_temp_input_grid, &
skin_temp_input_grid, &
snow_depth_input_grid, &
snow_liq_equiv_input_grid, &
soil_temp_input_grid, &
soil_type_input_grid, &
soilm_tot_input_grid, &
srflag_input_grid, &
t2m_input_grid, &
tprcp_input_grid, &
ustar_input_grid, &
veg_type_input_grid, &
z0_input_grid, &
veg_type_landice_input, &
veg_greenness_input_grid, &
max_veg_greenness_input_grid, &
min_veg_greenness_input_grid, &
lai_input_grid
use nst_input_data, only : c_d_input_grid, &
c_0_input_grid, &
d_conv_input_grid, &
dt_cool_input_grid, &
ifd_input_grid, &
qrain_input_grid, &
tref_input_grid, &
w_d_input_grid, &
w_0_input_grid, &
xs_input_grid, &
xt_input_grid, &
xu_input_grid, &
xv_input_grid, &
xz_input_grid, &
xtts_input_grid, &
xzts_input_grid, &
z_c_input_grid, &
zm_input_grid
use atm_input_data, only : terrain_input_grid
use model_grid, only : input_grid, target_grid, &
i_target, j_target, &
lsoil_target, &
num_tiles_target_grid, &
landmask_target_grid, &
seamask_target_grid, &
latitude_target_grid
use program_setup, only : convert_nst, &
vgtyp_from_climo, &
sotyp_from_climo, &
vgfrc_from_climo, &
minmax_vgfrc_from_climo, &
lai_from_climo, &
tg3_from_soil
use static_data, only : veg_type_target_grid, &
soil_type_target_grid, &
veg_greenness_target_grid, &
substrate_temp_target_grid,&
min_veg_greenness_target_grid,&
max_veg_greenness_target_grid
use search_util
implicit none
integer, intent(in) :: localpet
integer :: l(1), u(1)
integer :: i, j, ij, rc, tile
integer :: clb_target(2), cub_target(2)
integer :: isrctermprocessing
integer :: num_fields
integer :: vgfrc_ind, mmvg_ind, lai_ind
integer, allocatable :: search_nums(:)
integer(esmf_kind_i4), pointer :: unmapped_ptr(:)
integer(esmf_kind_i4), pointer :: mask_input_ptr(:,:)
integer(esmf_kind_i4), pointer :: mask_target_ptr(:,:)
integer(esmf_kind_i8), pointer :: landmask_target_ptr(:,:)
integer(esmf_kind_i8), allocatable :: mask_target_one_tile(:,:)
integer(esmf_kind_i8), allocatable :: water_target_one_tile(:,:)
integer(esmf_kind_i8), allocatable :: land_target_one_tile(:,:)
integer(esmf_kind_i8), pointer :: seamask_target_ptr(:,:)
real(esmf_kind_r8), allocatable :: data_one_tile(:,:)
real(esmf_kind_r8), allocatable :: data_one_tile2(:,:)
real(esmf_kind_r8), allocatable :: data_one_tile_3d(:,:,:)
real(esmf_kind_r8), allocatable :: latitude_one_tile(:,:)
real(esmf_kind_r8), allocatable :: fice_target_one_tile(:,:)
real(esmf_kind_r8), pointer :: seaice_fract_target_ptr(:,:)
real(esmf_kind_r8), pointer :: srflag_target_ptr(:,:)
real(esmf_kind_r8), pointer :: terrain_from_input_ptr(:,:)
real(esmf_kind_r8), pointer :: veg_type_target_ptr(:,:)
real(esmf_kind_r8), pointer :: soil_type_target_ptr(:,:)
real(esmf_kind_r8), pointer :: landmask_input_ptr(:,:)
real(esmf_kind_r8), pointer :: veg_type_input_ptr(:,:)
real(esmf_kind_r8), allocatable :: veg_type_target_one_tile(:,:)
real(esmf_kind_r8) :: ice_lim
type(esmf_regridmethod_flag) :: method
type(esmf_routehandle) :: regrid_bl_no_mask
type(esmf_routehandle) :: regrid_all_land
type(esmf_routehandle) :: regrid_land
type(esmf_routehandle) :: regrid_landice
type(esmf_routehandle) :: regrid_nonland
type(esmf_routehandle) :: regrid_seaice
type(esmf_routehandle) :: regrid_water
type(esmf_fieldbundle) :: bundle_all_target, bundle_all_input
type(esmf_fieldbundle) :: bundle_seaice_target, bundle_seaice_input
type(esmf_fieldbundle) :: bundle_water_target, bundle_water_input
type(esmf_fieldbundle) :: bundle_allland_target, bundle_allland_input
type(esmf_fieldbundle) :: bundle_landice_target, bundle_landice_input
type(esmf_fieldbundle) :: bundle_nolandice_target, bundle_nolandice_input
logical, allocatable :: dozero(:)
!-----------------------------------------------------------------------
! Interpolate fieids that do not require 'masked' interpolation.
!-----------------------------------------------------------------------
method=ESMF_REGRIDMETHOD_BILINEAR
isrctermprocessing = 1
print*,"- CALL FieldRegridStore FOR NON-MASKED BILINEAR INTERPOLATION."
call ESMF_FieldRegridStore(t2m_input_grid, &
t2m_target_grid, &
polemethod=ESMF_POLEMETHOD_ALLAVG, &
srctermprocessing=isrctermprocessing, &
routehandle=regrid_bl_no_mask, &
regridmethod=method, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridStore", rc)
bundle_all_target = ESMF_FieldBundleCreate(name="all points target", rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleCreate", rc)
bundle_all_input = ESMF_FieldBundleCreate(name="all points input", rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleCreate", rc)
call ESMF_FieldBundleAdd(bundle_all_target, (/t2m_target_grid,q2m_target_grid,tprcp_target_grid, &
f10m_target_grid,ffmm_target_grid,ustar_target_grid,srflag_target_grid/), &
rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleAdd", rc)
call ESMF_FieldBundleAdd(bundle_all_input, (/t2m_input_grid,q2m_input_grid,tprcp_input_grid, &
f10m_input_grid,ffmm_input_grid,ustar_input_grid,srflag_input_grid/), &
rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleAdd", rc)
call ESMF_FieldBundleGet(bundle_all_target,fieldCount=num_fields,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleGet", rc)
allocate(dozero(num_fields))
dozero(:) = .True.
call regrid_many(bundle_all_input,bundle_all_target,num_fields,regrid_bl_no_mask,dozero)
deallocate(dozero)
call ESMF_FieldBundleDestroy(bundle_all_target,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleDestroy", rc)
call ESMF_FieldBundleDestroy(bundle_all_input,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleDestroy", rc)
print*,"- CALL FieldGet FOR SRFLAG."
call ESMF_FieldGet(srflag_target_grid, &
farrayPtr=srflag_target_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGet", rc)
!-----------------------------------------------------------------------
! This is a flag field. Using neighbor was expensive. So use
! bilinear and 'nint'.
!-----------------------------------------------------------------------
srflag_target_ptr = nint(srflag_target_ptr)
print*,"- CALL FieldRegridRelease."
call ESMF_FieldRegridRelease(routehandle=regrid_bl_no_mask, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridRelease", rc)
!-----------------------------------------------------------------------
! First, set the mask on the target and input grids.
!-----------------------------------------------------------------------
print*,"- CALL GridAddItem FOR TARGET GRID."
call ESMF_GridAddItem(target_grid, &
itemflag=ESMF_GRIDITEM_MASK, &
staggerloc=ESMF_STAGGERLOC_CENTER, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN GridAddItem", rc)
print*,"- CALL GridGetItem FOR TARGET GRID."
call ESMF_GridGetItem(target_grid, &
itemflag=ESMF_GRIDITEM_MASK, &
farrayPtr=mask_target_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN GridGetItem", rc)
print*,"- CALL FieldGet FOR TARGET GRID SEAMASK."
call ESMF_FieldGet(seamask_target_grid, &
computationalLBound=clb_target, &
computationalUBound=cub_target, &
farrayPtr=seamask_target_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGet", rc)
print*,"- CALL FieldGet FOR TARGET GRID LANDMASK."
call ESMF_FieldGet(landmask_target_grid, &
farrayPtr=landmask_target_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGet", rc)
print*,"- CALL GridAddItem FOR INPUT GRID SEAMASK."
call ESMF_GridAddItem(input_grid, &
itemflag=ESMF_GRIDITEM_MASK, &
staggerloc=ESMF_STAGGERLOC_CENTER, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN GridAddItem", rc)
print*,"- CALL FieldGet FOR INPUT GRID LANDMASK."
call ESMF_FieldGet(landsea_mask_input_grid, &
farrayPtr=landmask_input_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGet", rc)
print*,"- CALL GridGetItem FOR INPUT GRID LANDMASK."
call ESMF_GridGetItem(input_grid, &
itemflag=ESMF_GRIDITEM_MASK, &
farrayPtr=mask_input_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN GridGetItem", rc)
if (localpet == 0) then
allocate(data_one_tile(i_target,j_target))
allocate(data_one_tile_3d(i_target,j_target,lsoil_target))
allocate(mask_target_one_tile(i_target,j_target))
else
allocate(data_one_tile(0,0))
allocate(data_one_tile_3d(0,0,0))
allocate(mask_target_one_tile(0,0))
endif
!-----------------------------------------------------------------------
! Interpolate vegetation type to target grid if chosen in namelist and terrain
! for use in replacing isolated bad terrain values
!-----------------------------------------------------------------------
method=ESMF_REGRIDMETHOD_NEAREST_STOD
isrctermprocessing = 1
mask_input_ptr = 0
where (nint(landmask_input_ptr) == 1) mask_input_ptr = 1
mask_target_ptr = 0
where (landmask_target_ptr == 1) mask_target_ptr = 1 ! some or all land.
print*,"- CALL FieldCreate FOR TERRAIN FROM INPUT GRID LAND."
terrain_from_input_grid_land = ESMF_FieldCreate(target_grid, &
typekind=ESMF_TYPEKIND_R8, &
staggerloc=ESMF_STAGGERLOC_CENTER, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldCreate", rc)
print*,"- CALL FieldRegridStore for land fields."
call ESMF_FieldRegridStore(terrain_input_grid, &
terrain_from_input_grid_land, &
srcmaskvalues=(/0/), &
dstmaskvalues=(/0/), &
polemethod=ESMF_POLEMETHOD_NONE, &
srctermprocessing=isrctermprocessing, &
unmappedaction=ESMF_UNMAPPEDACTION_IGNORE, &
normtype=ESMF_NORMTYPE_FRACAREA, &
routehandle=regrid_all_land, &
regridmethod=method, &
unmappedDstList=unmapped_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridStore", rc)
print*,"- CALL Field_Regrid TERRAIN."
call ESMF_FieldRegrid(terrain_input_grid, &
terrain_from_input_grid_land, &
routehandle=regrid_all_land, &
termorderflag=ESMF_TERMORDER_SRCSEQ, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegrid", rc)
print*,"- CALL FieldGet FOR terrain from input grid at land."
call ESMF_FieldGet(terrain_from_input_grid_land, &
farrayPtr=terrain_from_input_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGet", rc)
l = lbound(unmapped_ptr)
u = ubound(unmapped_ptr)
do ij = l(1), u(1)
call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
terrain_from_input_ptr(i,j) = -9999.9
enddo
nullify(terrain_from_input_ptr)
do tile = 1, num_tiles_target_grid
print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
call ESMF_FieldGather(landmask_target_grid, mask_target_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGather", rc)
print*,"- CALL FieldGather FOR TERRAIN FROM INPUT GRID: ", tile
call ESMF_FieldGather(terrain_from_input_grid, data_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGather", rc)
if (localpet == 0) then
allocate(land_target_one_tile(i_target,j_target))
land_target_one_tile = 0
where(mask_target_one_tile == 1) land_target_one_tile = 1
call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 7)
deallocate(land_target_one_tile)
endif
print*,"- CALL FieldScatter FOR TERRAIN FROM INPUT GRID: ", tile
call ESMF_FieldScatter(terrain_from_input_grid, data_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldScatter", rc)
enddo
if(.not. vgtyp_from_climo) then
print*,"- CALL FieldRegrid VEG TYPE."
call ESMF_FieldRegrid(veg_type_input_grid, &
veg_type_target_grid, &
routehandle=regrid_all_land, &
termorderflag=ESMF_TERMORDER_SRCSEQ, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegrid", rc)
print*,"- CALL FieldGet FOR TARGET grid veg type."
call ESMF_FieldGet(veg_type_target_grid, &
farrayPtr=veg_type_target_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGet", rc)
l = lbound(unmapped_ptr)
u = ubound(unmapped_ptr)
do ij = l(1), u(1)
call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
veg_type_target_ptr(i,j) = -9999.9
enddo
do tile = 1, num_tiles_target_grid
print*,"- CALL FieldGather FOR TARGET GRID VEG TYPE TILE: ", tile
call ESMF_FieldGather(veg_type_target_grid, data_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGather", rc)
print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
call ESMF_FieldGather(landmask_target_grid, mask_target_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGather", rc)
if (localpet == 0) then
allocate(land_target_one_tile(i_target,j_target))
land_target_one_tile = 0
where(mask_target_one_tile == 1) land_target_one_tile = 1
call search(data_one_tile, land_target_one_tile, i_target, j_target, tile, 225)
deallocate(land_target_one_tile)
endif
print*,"- CALL FieldScatter FOR TARGET GRID VEG TYPE: ", tile
call ESMF_FieldScatter(veg_type_target_grid, data_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldScatter", rc)
enddo
nullify(veg_type_target_ptr)
endif
print*,"- CALL FieldRegridRelease."
call ESMF_FieldRegridRelease(routehandle=regrid_all_land, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridRelease", rc)
!-----------------------------------------------------------------------
! Next, determine the sea ice fraction on the fractional target grid.
! For fractional grids, the ice fraction is not scaled for the
! fraction of non-land. So if a point is 50% land and non-land,
! an ice frac of 100% means the entire non-land portion is ice covered.
!-----------------------------------------------------------------------
mask_input_ptr = 1
where (nint(landmask_input_ptr) == 1) mask_input_ptr = 0
!-----------------------------------------------------------------------
! Map to grid points that are partial or all non-land. That is
! indicated where seamask_target is '1'.
!-----------------------------------------------------------------------
mask_target_ptr = int(seamask_target_ptr,kind=esmf_kind_i4)
method=ESMF_REGRIDMETHOD_CONSERVE
isrctermprocessing = 1
print*,"- CALL FieldRegridStore for sea ice fraction."
call ESMF_FieldRegridStore(seaice_fract_input_grid, &
seaice_fract_target_grid, &
srcmaskvalues=(/0/), &
dstmaskvalues=(/0/), &
polemethod=ESMF_POLEMETHOD_NONE, &
srctermprocessing=isrctermprocessing, &
unmappedaction=ESMF_UNMAPPEDACTION_IGNORE, &
normtype=ESMF_NORMTYPE_FRACAREA, &
routehandle=regrid_nonland, &
regridmethod=method, &
unmappedDstList=unmapped_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridStore", rc)
print*,"- CALL Field_Regrid for sea ice fraction."
call ESMF_FieldRegrid(seaice_fract_input_grid, &
seaice_fract_target_grid, &
routehandle=regrid_nonland, &
termorderflag=ESMF_TERMORDER_SRCSEQ, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegrid", rc)
print*,"- CALL FieldGet FOR TARGET grid sea ice fraction."
call ESMF_FieldGet(seaice_fract_target_grid, &
farrayPtr=seaice_fract_target_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGet", rc)
l = lbound(unmapped_ptr)
u = ubound(unmapped_ptr)
do ij = l(1), u(1)
call ij_to_i_j(unmapped_ptr(ij), i_target, j_target, i, j)
seaice_fract_target_ptr(i,j) = -9999.9 ! flag value for missing point
! which will be replaced in routine
! "search".
enddo
if (localpet == 0) then
allocate(latitude_one_tile(i_target,j_target))
else
allocate(latitude_one_tile(0,0))
endif
do tile = 1, num_tiles_target_grid
print*,"- CALL FieldGather FOR TARGET GRID SEAICE FRACTION TILE: ", tile
call ESMF_FieldGather(seaice_fract_target_grid, data_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGather", rc)
print*,"- CALL FieldGather FOR TARGET GRID MASK TILE: ", tile
call ESMF_FieldGather(seamask_target_grid, mask_target_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGather", rc)
print*,"- CALL FieldGather FOR TARGET LATITUDE TILE: ", tile
call ESMF_FieldGather(latitude_target_grid, latitude_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGather", rc)
if (localpet == 0) then
call search(data_one_tile, mask_target_one_tile, i_target, j_target, tile, 91, &
latitude=latitude_one_tile)
endif
!------------------------------------------------------------------------------
! To reduce the potenitally large number of target grid points with a very
! small amount of open water, set any point with ice between 95-100% to 100%.
!------------------------------------------------------------------------------
ice_lim = 0.95_esmf_kind_r8
if (localpet == 0) then
do j = 1, j_target
do i = 1, i_target
if (data_one_tile(i,j) > ice_lim) then
data_one_tile(i,j) = 1.0_esmf_kind_r8
endif
if (data_one_tile(i,j) < 0.15_esmf_kind_r8) data_one_tile(i,j) = 0.0_esmf_kind_r8
enddo
enddo
endif
print*,"- CALL FieldScatter FOR TARGET GRID SEAICE FRACTION TILE: ", tile
call ESMF_FieldScatter(seaice_fract_target_grid, data_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldScatter", rc)
enddo
deallocate(latitude_one_tile)
print*,"- CALL FieldRegridRelease."
call ESMF_FieldRegridRelease(routehandle=regrid_nonland, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridRelease", rc)
!---------------------------------------------------------------------------------------------
! Now interpolate other sea ice related fields. Since we know what points are ice on
! the target grid, reset the target grid mask.
!---------------------------------------------------------------------------------------------
mask_input_ptr = 0
where (nint(landmask_input_ptr) == 2) mask_input_ptr = 1
mask_target_ptr = 0
do j = clb_target(2), cub_target(2)
do i = clb_target(1), cub_target(1)
if (seaice_fract_target_ptr(i,j) > 0.0) mask_target_ptr(i,j) = 1
enddo
enddo
method=ESMF_REGRIDMETHOD_NEAREST_STOD
isrctermprocessing = 1
print*,"- CALL FieldRegridStore for 3d seaice fields."
call ESMF_FieldRegridStore(soil_temp_input_grid, &
ice_temp_target_grid, &
srcmaskvalues=(/0/), &
dstmaskvalues=(/0/), &
polemethod=ESMF_POLEMETHOD_NONE, &
srctermprocessing=isrctermprocessing, &
unmappedaction=ESMF_UNMAPPEDACTION_IGNORE, &
normtype=ESMF_NORMTYPE_FRACAREA, &
routehandle=regrid_seaice, &
regridmethod=method, &
unmappedDstList=unmapped_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridStore", rc)
bundle_seaice_target = ESMF_FieldBundleCreate(name="sea ice target", rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleCreate", rc)
bundle_seaice_input = ESMF_FieldBundleCreate(name="sea ice input", rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleCreate", rc)
call ESMF_FieldBundleAdd(bundle_seaice_target, (/seaice_depth_target_grid, snow_depth_at_ice_target_grid, &
snow_liq_equiv_at_ice_target_grid, seaice_skin_temp_target_grid, &
ice_temp_target_grid/), rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleAdd", rc)
call ESMF_FieldBundleAdd(bundle_seaice_input, (/seaice_depth_input_grid, snow_depth_input_grid, &
snow_liq_equiv_input_grid, seaice_skin_temp_input_grid, &
soil_temp_input_grid/), rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleAdd", rc)
call ESMF_FieldBundleGet(bundle_seaice_target,fieldCount=num_fields,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleGet", rc)
allocate(search_nums(num_fields))
allocate(dozero(num_fields))
search_nums = (/92,66,65,21,21/)
dozero(:) = .True.
l = lbound(unmapped_ptr)
u = ubound(unmapped_ptr)
call regrid_many(bundle_seaice_input,bundle_seaice_target,num_fields,regrid_seaice,dozero, &
unmapped_ptr=unmapped_ptr )
deallocate(dozero)
call ESMF_FieldBundleDestroy(bundle_seaice_input,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleDestroy", rc)
if (localpet == 0) then
allocate(fice_target_one_tile(i_target,j_target))
else
allocate(fice_target_one_tile(0,0))
endif
do tile = 1, num_tiles_target_grid
print*,"- CALL FieldGather FOR TARGET LANDMASK TILE: ", tile
call ESMF_FieldGather(seaice_fract_target_grid, fice_target_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldGather", rc)
if (localpet == 0) then
mask_target_one_tile = 0
where(fice_target_one_tile > 0.0) mask_target_one_tile = 1
call search_many(num_fields,bundle_seaice_target,tile, search_nums,localpet, &
mask=mask_target_one_tile)
else
call search_many(num_fields,bundle_seaice_target, tile,search_nums,localpet)
endif
enddo
deallocate(search_nums)
call ESMF_FieldBundleDestroy(bundle_seaice_target,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))&
call error_handler("IN FieldBundleDestroy", rc)
print*,"- CALL FieldRegridRelease."
call ESMF_FieldRegridRelease(routehandle=regrid_seaice, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridRelease", rc)
!---------------------------------------------------------------------------------------------
! Now interpolate open water fields.
!---------------------------------------------------------------------------------------------
mask_input_ptr = 0
where (nint(landmask_input_ptr) == 0) mask_input_ptr = 1
!---------------------------------------------------------------------------------------------
! Set target mask - want points with at least some open water.
!---------------------------------------------------------------------------------------------
mask_target_ptr = 0
where (seamask_target_ptr == 1) mask_target_ptr = 1 ! some or all non-land.
where (seaice_fract_target_ptr == 1.0_esmf_kind_r8) mask_target_ptr = 0 ! all ice.
method=ESMF_REGRIDMETHOD_CONSERVE
isrctermprocessing = 1
print*,"- CALL FieldRegridStore for water fields."
call ESMF_FieldRegridStore(skin_temp_input_grid, &
sst_target_grid, &
srcmaskvalues=(/0/), &
dstmaskvalues=(/0/), &
polemethod=ESMF_POLEMETHOD_NONE, &
srctermprocessing=isrctermprocessing, &
unmappedaction=ESMF_UNMAPPEDACTION_IGNORE, &
normtype=ESMF_NORMTYPE_FRACAREA, &
routehandle=regrid_water, &
regridmethod=method, &
unmappedDstList=unmapped_ptr, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldRegridStore", rc)
bundle_water_target = ESMF_FieldBundleCreate(name="water target", rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleCreate", rc)
bundle_water_input = ESMF_FieldBundleCreate(name="water input", rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleCreate", rc)
call ESMF_FieldBundleAdd(bundle_water_target, (/sst_target_grid, z0_water_target_grid/), rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleAdd", rc)
call ESMF_FieldBundleAdd(bundle_water_input, (/skin_temp_input_grid, z0_input_grid/), rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleAdd", rc)
if (convert_nst) then
call ESMF_FieldBundleAdd(bundle_water_target, (/c_d_target_grid,c_0_target_grid,d_conv_target_grid, &
dt_cool_target_grid,ifd_target_grid,qrain_target_grid,tref_target_grid, &
w_d_target_grid,w_0_target_grid,xs_target_grid,xt_target_grid,xu_target_grid, &
xv_target_grid,xz_target_grid,xtts_target_grid,xzts_target_grid, &
z_c_target_grid,zm_target_grid/), rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleAdd", rc)
call ESMF_FieldBundleAdd(bundle_water_input, (/c_d_input_grid,c_0_input_grid,d_conv_input_grid, &
dt_cool_input_grid,ifd_input_grid,qrain_input_grid,tref_input_grid, &
w_d_input_grid,w_0_input_grid,xs_input_grid,xt_input_grid,xu_input_grid, &
xv_input_grid,xz_input_grid,xtts_input_grid,xzts_input_grid, &
z_c_input_grid,zm_input_grid/), rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleAdd", rc)
call ESMF_FieldBundleGet(bundle_water_target,fieldCount=num_fields,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleGet", rc)
allocate(search_nums(num_fields))
allocate(dozero(num_fields))
search_nums(:)=(/11,83,0,0,0,0,1,0,11,0,0,0,0,0,0,30,0,0,0,0/)
dozero(:) = .True.
else
call ESMF_FieldBundleGet(bundle_water_target,fieldCount=num_fields,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleGet", rc)
allocate(search_nums(num_fields))
allocate(dozero(num_fields))
search_nums(:)=(/11,83/)
dozero(:) = .True.
endif
call regrid_many(bundle_water_input,bundle_water_target,num_fields,regrid_water,dozero, &
unmapped_ptr=unmapped_ptr, resetifd=.True.)
deallocate(dozero)
call ESMF_FieldBundleDestroy(bundle_water_input,rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &
call error_handler("IN FieldBundleDestroy", rc)
if (localpet == 0) then
allocate(latitude_one_tile(i_target,j_target))
else
allocate(latitude_one_tile(0,0))
endif
do tile = 1, num_tiles_target_grid
print*,"- CALL FieldGather FOR TARGET SEAMASK TILE: ", tile
call ESMF_FieldGather(seamask_target_grid, mask_target_one_tile, rootPet=0, tile=tile, rc=rc)
if(ESMF_logFoundError(rcToCheck=rc,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) &