-
Notifications
You must be signed in to change notification settings - Fork 158
/
module_fcst_grid_comp.F90
1687 lines (1432 loc) · 77.1 KB
/
module_fcst_grid_comp.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
#define ESMF_ERR_ABORT(rc) \
if (rc /= ESMF_SUCCESS) write(0,*) 'rc=',rc,__FILE__,__LINE__; if(ESMF_LogFoundError(rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!-----------------------------------------------------------------------
!
module module_fcst_grid_comp
!
!-----------------------------------------------------------------------
!*** Forecast gridded component.
!-----------------------------------------------------------------------
!***
!*** HISTORY
!***
! Apr 2017: J. Wang - initial code for forecast grid component
!
!---------------------------------------------------------------------------------
!
use mpi_f08
use esmf
use nuopc
use time_manager_mod, only: time_type, set_calendar_type, set_time, &
set_date, month_name, &
operator(+), operator(-), operator (<), &
operator (>), operator (/=), operator (/), &
operator (==), operator (*), &
THIRTY_DAY_MONTHS, JULIAN, GREGORIAN, &
NOLEAP, NO_CALENDAR, &
date_to_string, get_date, get_time
use atmos_model_mod, only: atmos_model_init, atmos_model_end, &
get_atmos_model_ungridded_dim, &
update_atmos_model_dynamics, &
update_atmos_radiation_physics, &
update_atmos_model_state, &
atmos_data_type, atmos_model_restart, &
atmos_model_exchange_phase_1, &
atmos_model_exchange_phase_2, &
addLsmask2grid, atmos_model_get_nth_domain_info
use GFS_typedefs, only: kind_phys, kind_sngl_prec
use constants_mod, only: constants_init
use fms_mod, only: error_mesg, fms_init, fms_end, &
write_version_number, uppercase
use mpp_mod, only: mpp_init, mpp_pe, mpp_npes, mpp_root_pe, mpp_set_current_pelist, &
mpp_error, FATAL, WARNING, NOTE
use mpp_mod, only: mpp_clock_id, mpp_clock_begin
use mpp_domains_mod, only: mpp_get_compute_domains, domain2D
use sat_vapor_pres_mod, only: sat_vapor_pres_init
use diag_manager_mod, only: diag_manager_init, diag_manager_end, &
diag_manager_set_time_end
use data_override_mod, only: data_override_init
use fv_nggps_diags_mod, only: fv_dyn_bundle_setup
use fv3atm_history_io_mod, only: fv_phys_bundle_setup
use fv3atm_restart_io_mod, only: fv_phy_restart_bundle_setup, fv_sfc_restart_bundle_setup
use fv_ufs_restart_io_mod, only: fv_core_restart_bundle_setup, &
fv_srf_wnd_restart_bundle_setup, &
fv_tracer_restart_bundle_setup
use fms2_io_mod, only: FmsNetcdfFile_t, open_file, close_file, variable_exists, read_data
use atmosphere_mod, only: atmosphere_control_data
use module_fv3_io_def, only: num_pes_fcst, num_files, filename_base, &
nbdlphys, iau_offset
use module_fv3_config, only: dt_atmos, fcst_mpi_comm, fcst_ntasks, &
quilting, quilting_restart, &
calendar, cpl_grid_id, &
cplprint_flag
use get_stochy_pattern_mod, only: write_stoch_restart_atm
use module_cplfields, only: nExportFields, exportFields, exportFieldsInfo, &
nImportFields, importFields, importFieldsInfo
use module_cplfields, only: realizeConnectedCplFields
use atmos_model_mod, only: setup_exportdata
use CCPP_data, only: GFS_control
!
!-----------------------------------------------------------------------
!
implicit none
!
!-----------------------------------------------------------------------
!
private
!
!---- model defined-types ----
type(atmos_data_type), save :: Atmos
type(ESMF_GridComp),dimension(:),allocatable :: fcstGridComp
integer :: ngrids, mygrid
integer :: n_atmsteps
!----- coupled model data -----
integer :: calendar_type = -99
integer :: date_init(6)
integer :: numLevels = 0
integer :: numSoilLayers = 0
integer :: numTracers = 0
integer :: frestart(999)
integer :: mype
!
!-----------------------------------------------------------------------
!
public SetServices
!
contains
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine SetServices(fcst_comp, rc)
!
type(ESMF_GridComp) :: fcst_comp
integer, intent(out) :: rc
rc = ESMF_SUCCESS
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_INITIALIZE, &
userRoutine=fcst_initialize, phase=1, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_INITIALIZE, &
userRoutine=fcst_advertise, phase=2, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_INITIALIZE, &
userRoutine=fcst_realize, phase=3, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_RUN, &
userRoutine=fcst_run_phase_1, phase=1, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_RUN, &
userRoutine=fcst_run_phase_2, phase=2, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!
call ESMF_GridCompSetEntryPoint(fcst_comp, ESMF_METHOD_FINALIZE, &
userRoutine=fcst_finalize, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end subroutine SetServices
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine SetServicesNest(nest, rc)
!
type(ESMF_GridComp) :: nest
integer, intent(out) :: rc
character(len=80) :: name
type(ESMF_Grid) :: grid
type(ESMF_Info) :: info
integer :: layout(2), tilesize
integer :: tl, nx, ny
integer,dimension(2,6):: decomptile !define delayout for the 6 cubed-sphere tiles
integer,dimension(2) :: regdecomp !define delayout for the nest grid
type(ESMF_Decomp_Flag):: decompflagPTile(2,6)
type(ESMF_TypeKind_Flag) :: grid_typekind
character(3) :: myGridStr
type(ESMF_DistGrid) :: distgrid
type(ESMF_Array) :: array
rc = ESMF_SUCCESS
call ESMF_GridCompSetEntryPoint(nest, ESMF_METHOD_INITIALIZE, userRoutine=init_dyn_fb, phase=1, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompSetEntryPoint(nest, ESMF_METHOD_INITIALIZE, userRoutine=init_phys_fb, phase=2, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompSetEntryPoint(nest, ESMF_METHOD_INITIALIZE, userRoutine=init_advertise, phase=3, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompSetEntryPoint(nest, ESMF_METHOD_INITIALIZE, userRoutine=init_realize, phase=4, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridCompGet(nest, name=name, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_InfoGetFromHost(nest, info=info, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_InfoGet(info, key="layout", values=layout, rc=rc); ESMF_ERR_ABORT(rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (kind_phys == kind_sngl_prec) then
grid_typekind = ESMF_TYPEKIND_R4
else
grid_typekind = ESMF_TYPEKIND_R8
endif
if (trim(name)=="global") then
! global domain
call ESMF_InfoGet(info, key="tilesize", value=tilesize, rc=rc); ESMF_ERR_ABORT(rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
do tl=1,6
decomptile(1,tl) = layout(1)
decomptile(2,tl) = layout(2)
decompflagPTile(:,tl) = (/ESMF_DECOMP_SYMMEDGEMAX,ESMF_DECOMP_SYMMEDGEMAX/)
enddo
grid = ESMF_GridCreateCubedSphere(tileSize=tilesize, &
coordSys=ESMF_COORDSYS_SPH_RAD, &
coordTypeKind=grid_typekind, &
regDecompPTile=decomptile, &
decompflagPTile=decompflagPTile, &
name="fcst_grid", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
else
! nest domain
call ESMF_InfoGet(info, key="nx", value=nx, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_InfoGet(info, key="ny", value=ny, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
grid = ESMF_GridCreateNoPeriDim(regDecomp=(/layout(1),layout(2)/), &
minIndex=(/1,1/), &
maxIndex=(/nx,ny/), &
gridAlign=(/-1,-1/), &
coordSys=ESMF_COORDSYS_SPH_RAD, &
coordTypeKind=grid_typekind, &
decompflag=(/ESMF_DECOMP_SYMMEDGEMAX,ESMF_DECOMP_SYMMEDGEMAX/), &
name="fcst_grid", &
indexflag=ESMF_INDEX_DELOCAL, &
rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
endif
! - Create coordinate arrays around allocations held within Atmos data structure and set in Grid
call ESMF_GridGet(grid, staggerloc=ESMF_STAGGERLOC_CENTER, distgrid=distgrid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
array = ESMF_ArrayCreate(distgrid, farray=Atmos%lon, indexflag=ESMF_INDEX_DELOCAL, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridSetCoord(grid, coordDim=1, staggerLoc=ESMF_STAGGERLOC_CENTER, array=array, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
array = ESMF_ArrayCreate(distgrid, farray=Atmos%lat, indexflag=ESMF_INDEX_DELOCAL, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridSetCoord(grid, coordDim=2, staggerLoc=ESMF_STAGGERLOC_CENTER, array=array, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridGet(grid, staggerloc=ESMF_STAGGERLOC_CORNER, distgrid=distgrid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
array = ESMF_ArrayCreate(distgrid, farray=Atmos%lon_bnd, indexflag=ESMF_INDEX_DELOCAL, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridSetCoord(grid, coordDim=1, staggerLoc=ESMF_STAGGERLOC_CORNER, array=array, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
array = ESMF_ArrayCreate(distgrid, farray=Atmos%lat_bnd, indexflag=ESMF_INDEX_DELOCAL, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridSetCoord(grid, coordDim=2, staggerLoc=ESMF_STAGGERLOC_CORNER, array=array, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!TODO: Consider aligning mask treatment with coordinates... especially if it requires updates for moving
call addLsmask2grid(grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! - Add Attributes used by output
call ESMF_AttributeAdd(grid, convention="NetCDF", purpose="FV3", &
attrList=(/"ESMF:gridded_dim_labels"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(grid, convention="NetCDF", purpose="FV3", &
name="ESMF:gridded_dim_labels", valueList=(/"grid_xt", "grid_yt"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!test to write out vtk file:
! if( cplprint_flag ) then
! call ESMF_GridWriteVTK(grid, staggerloc=ESMF_STAGGERLOC_CENTER, &
! filename='fv3cap_fv3Grid', rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! endif
!
! Write grid to netcdf file
if( cplprint_flag ) then
write (myGridStr,"(I0)") mygrid
if (trim(name)=="global") then
call wrt_fcst_grid(grid, "diagnostic_FV3_fcstGrid"//trim(mygridStr)//".tile*.nc", &
regridArea=.TRUE., rc=rc)
else
call wrt_fcst_grid(grid, "diagnostic_FV3_fcstGrid"//trim(mygridStr)//".nc", &
regridArea=.TRUE., rc=rc)
end if
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
endif
! - Hold on to the grid by GridComp
call ESMF_GridCompSet(nest, grid=grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end subroutine SetServicesNest
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine init_dyn_fb(nest, importState, exportState, clock, rc)
!
type(ESMF_GridComp) :: nest
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
type(ESMF_Grid) :: grid
integer :: itemCount, i
character(len=ESMF_MAXSTR), allocatable :: itemNameList(:)
character(len=ESMF_MAXSTR) :: fb_name
type(ESMF_FieldBundle), allocatable :: fbList(:)
type(ESMF_FieldBundle) :: fcstFB
call ESMF_GridCompGet(nest, grid=grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateGet(importState, itemCount=itemCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
allocate(itemNameList(itemCount), fbList(itemCount))
call ESMF_StateGet(importState, itemNameList=itemNameList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
do i=1, itemCount
call ESMF_StateGet(importState, itemName=itemNameList(i), fieldbundle=fcstFB, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
fbList(i) = ESMF_FieldBundleCreate(name=itemNameList(i), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeCopy(fcstFB, fbList(i), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateAdd(exportState, (/fbList(i)/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
enddo
! get the name of the first field bundle and based on that determine if it's a history or restart bundles
call ESMF_FieldBundleGet(fbList(1), name=fb_name, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (fb_name(1:19) == 'restart_fv_core.res') then
call fv_core_restart_bundle_setup(fbList(1), grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
else if (fb_name(1:22) == 'restart_fv_srf_wnd.res') then
call fv_srf_wnd_restart_bundle_setup(fbList(1), grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
else if (fb_name(1:21) == 'restart_fv_tracer.res') then
call fv_tracer_restart_bundle_setup(fbList(1), grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
else
do i=1, itemCount
call fv_dyn_bundle_setup(Atmos%axes, fbList(i), grid, quilting=.true., rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end do
endif
end subroutine init_dyn_fb
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine init_phys_fb(nest, importState, exportState, clock, rc)
!
type(ESMF_GridComp) :: nest
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
type(ESMF_Grid) :: grid
integer :: itemCount, i
character(len=ESMF_MAXSTR), allocatable :: itemNameList(:)
character(len=ESMF_MAXSTR) :: fb_name
type(ESMF_FieldBundle), allocatable :: fbList(:)
type(ESMF_FieldBundle) :: fcstFB
call ESMF_GridCompGet(nest, grid=grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateGet(importState, itemCount=itemCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
allocate(itemNameList(itemCount), fbList(itemCount))
call ESMF_StateGet(importState, itemNameList=itemNameList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
do i=1, itemCount
call ESMF_StateGet(importState, itemName=itemNameList(i), fieldbundle=fcstFB, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
fbList(i) = ESMF_FieldBundleCreate(name=itemNameList(i), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeCopy(fcstFB, fbList(i), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_StateAdd(exportState, (/fbList(i)/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
enddo
! get the name of the first field bundle and based on that determine if it's a history or restart bundles
call ESMF_FieldBundleGet(fbList(1), name=fb_name, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (fb_name(1:16) == 'restart_phy_data') then
call fv_phy_restart_bundle_setup(fbList(1), grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
elseif (fb_name(1:16) == 'restart_sfc_data') then
call fv_sfc_restart_bundle_setup(fbList(1), grid, GFS_control, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
else
call fv_phys_bundle_setup(Atmos%diag, Atmos%axes, fbList, grid, quilting=.true., nbdlphys=itemCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
endif
end subroutine init_phys_fb
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine init_advertise(nest, importState, exportState, clock, rc)
!
type(ESMF_GridComp) :: nest
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
!
!*** local variables
!
integer :: i
rc = ESMF_SUCCESS
!
! importable fields:
do i = 1, size(importFieldsInfo)
call NUOPC_Advertise(importState, &
StandardName=trim(importFieldsInfo(i)%name), &
SharePolicyField='share', rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end do
! exportable fields:
do i = 1, size(exportFieldsInfo)
call NUOPC_Advertise(exportState, &
StandardName=trim(exportFieldsInfo(i)%name), &
SharePolicyField='share', rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end do
!
!-----------------------------------------------------------------------
!
end subroutine init_advertise
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine init_realize(nest, importState, exportState, clock, rc)
!
use module_cplscalars, only : flds_scalar_name, flds_scalar_num, &
flds_scalar_index_nx, flds_scalar_index_ny, &
flds_scalar_index_ntile
use module_cplscalars, only : State_SetScalar
type(ESMF_GridComp) :: nest
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer,intent(out) :: rc
!
!*** local variables
!
real(ESMF_KIND_R8) :: scalardim(3)
type(ESMF_Grid) :: grid
scalardim = 0.0
! cpl_scalars for export state
scalardim(1) = real(Atmos%mlon,8)
scalardim(2) = real(Atmos%mlat,8)
scalardim(3) = 1.0
if (.not. Atmos%regional)scalardim(3) = 6.0
rc = ESMF_SUCCESS
! access this domain grid
call ESMF_GridCompGet(nest, grid=grid, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! -- realize connected fields in exportState
call realizeConnectedCplFields(exportState, grid, &
numLevels, numSoilLayers, numTracers, &
exportFieldsInfo, 'FV3 Export', exportFields, 0.0_ESMF_KIND_R8, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (flds_scalar_num > 0) then
! Set the scalar data into the exportstate
call State_SetScalar(scalardim(1), flds_scalar_index_nx, exportState, flds_scalar_name, flds_scalar_num, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call State_SetScalar(scalardim(2), flds_scalar_index_ny, exportState, flds_scalar_name, flds_scalar_num, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call State_SetScalar(scalardim(3), flds_scalar_index_ntile, exportState, flds_scalar_name, flds_scalar_num, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end if
! -- initialize export fields if applicable
call setup_exportdata(rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! -- realize connected fields in importState
call realizeConnectedCplFields(importState, grid, &
numLevels, numSoilLayers, numTracers, &
importFieldsInfo, 'FV3 Import', importFields, 9.99e20_ESMF_KIND_R8, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
!
!-----------------------------------------------------------------------
!
end subroutine init_realize
!
!-----------------------------------------------------------------------
!#######################################################################
!-----------------------------------------------------------------------
!
subroutine fcst_initialize(fcst_comp, importState, exportState, clock, rc)
!
!-----------------------------------------------------------------------
!*** INITIALIZE THE FORECAST GRIDDED COMPONENT.
!-----------------------------------------------------------------------
!
type(esmf_GridComp) :: fcst_comp
type(ESMF_State) :: importState, exportState
type(esmf_Clock) :: clock
integer,intent(out) :: rc
!
!*** local variables
!
integer :: i, j
!
type(ESMF_VM) :: VM
type(ESMF_Time) :: CurrTime, StartTime, StopTime
type(ESMF_Config) :: cf
integer,dimension(6) :: date, date_end
!
integer :: initClock, unit, total_inttime
integer :: stat
character(4) dateSY
character(2) dateSM,dateSD,dateSH,dateSN,dateSS
character(len=esmf_maxstr) name_FB, name_FB1
character(len=80) :: dateS
character(256) :: gridfile
character(8) :: bundle_grid
real(kind=8) :: mpi_wtime, timeis
type(ESMF_DELayout) :: delayout
type(ESMF_DistGrid) :: distgrid
integer :: jsc, jec, isc, iec, nlev
type(domain2D) :: domain
integer :: n, fcstNpes, tmpvar, k
logical :: freq_restart, fexist
integer, allocatable, dimension(:) :: isl, iel, jsl, jel
integer, allocatable, dimension(:,:,:) :: deBlockList
integer, allocatable, dimension(:) :: petListNest
integer :: globalTileLayout(2)
integer :: nestRootPet, peListSize(1)
integer, allocatable :: petMap(:)
integer :: layout(2), nx, ny
integer, pointer :: pelist(:) => null()
logical :: top_parent_is_global
logical :: history_file_on_native_grid
integer :: num_restart_interval, restart_starttime
real,dimension(:),allocatable :: restart_interval
integer :: urc
type(ESMF_State) :: tempState
type(ESMF_Info) :: info
type(time_type) :: Time_init, Time, Time_step, Time_end, &
Time_restart, Time_step_restart
type(time_type) :: iautime
integer :: io_unit, calendar_type_res, date_res(6), date_init_res(6)
integer,allocatable :: grid_number_on_all_pets(:)
logical,allocatable :: is_moving_on_all_pets(:), is_moving(:)
character(len=7) :: nest_suffix
type(FmsNetcdfFile_t) :: fileobj
!
!-----------------------------------------------------------------------
!***********************************************************************
!-----------------------------------------------------------------------
!
timeis = mpi_wtime()
rc = ESMF_SUCCESS
!
call ESMF_VMGetCurrent(vm=vm,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_VMGet(vm=vm, localPet=mype, mpiCommunicator=fcst_mpi_comm%mpi_val, &
petCount=fcst_ntasks, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (mype == 0) write(*,*)'in fcst comp init, fcst_ntasks=',fcst_ntasks
CF = ESMF_ConfigCreate(rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_ConfigLoadFile(config=CF ,filename='model_configure' ,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
num_restart_interval = ESMF_ConfigGetLen(config=CF, label ='restart_interval:',rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (mype == 0) print *,'af ufs config,num_restart_interval=',num_restart_interval
if (num_restart_interval<=0) num_restart_interval = 1
allocate(restart_interval(num_restart_interval))
restart_interval = 0
call ESMF_ConfigGetAttribute(CF,valueList=restart_interval,label='restart_interval:', &
count=num_restart_interval, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (mype == 0) print *,'af ufs config,restart_interval=',restart_interval
!
call fms_init(fcst_mpi_comm%mpi_val)
call mpp_init()
initClock = mpp_clock_id( 'Initialization' )
call mpp_clock_begin (initClock) !nesting problem
call constants_init
call sat_vapor_pres_init
select case( uppercase(trim(calendar)) )
case( 'JULIAN' )
calendar_type = JULIAN
case( 'GREGORIAN' )
calendar_type = GREGORIAN
case( 'NOLEAP' )
calendar_type = NOLEAP
case( 'THIRTY_DAY' )
calendar_type = THIRTY_DAY_MONTHS
case( 'NO_CALENDAR' )
calendar_type = NO_CALENDAR
case default
call mpp_error ( FATAL, 'fcst_initialize: calendar must be one of '// &
'JULIAN|GREGORIAN|NOLEAP|THIRTY_DAY|NO_CALENDAR.' )
end select
call set_calendar_type (calendar_type)
!
!-----------------------------------------------------------------------
!*** set atmos time
!-----------------------------------------------------------------------
!
call ESMF_ClockGet(clock, CurrTime=CurrTime, StartTime=StartTime, &
StopTime=StopTime, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
date_init = 0
call ESMF_TimeGet (StartTime, &
YY=date_init(1), MM=date_init(2), DD=date_init(3), &
H=date_init(4), M =date_init(5), S =date_init(6), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
Time_init = set_date (date_init(1), date_init(2), date_init(3), &
date_init(4), date_init(5), date_init(6))
if (mype == 0) write(*,'(A,6I5)') 'StartTime=',date_init
date=0
call ESMF_TimeGet (CurrTime, &
YY=date(1), MM=date(2), DD=date(3), &
H=date(4), M =date(5), S =date(6), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
Time = set_date (date(1), date(2), date(3), &
date(4), date(5), date(6))
if (mype == 0) write(*,'(A,6I5)') 'CurrTime =',date
date_end=0
call ESMF_TimeGet (StopTime, &
YY=date_end(1), MM=date_end(2), DD=date_end(3), &
H=date_end(4), M =date_end(5), S =date_end(6), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
Time_end = set_date (date_end(1), date_end(2), date_end(3), &
date_end(4), date_end(5), date_end(6))
if (mype == 0) write(*,'(A,6I5)') 'StopTime =',date_end
!------------------------------------------------------------------------
! If this is a restarted run ('INPUT/coupler.res' file exists),
! compare date and date_init to the values in 'coupler.res'
if (mype == 0) then
inquire(FILE='INPUT/coupler.res', EXIST=fexist)
if (fexist) then ! file exists, this is a restart run
open(newunit=io_unit, file='INPUT/coupler.res', status='old', action='read', err=998)
read (io_unit,*,err=999) calendar_type_res
read (io_unit,*) date_init_res
read (io_unit,*) date_res
close(io_unit)
if(date_res(1) == 0 .and. date_init_res(1) /= 0) date_res = date_init_res
if(mype == 0) write(*,'(A,6(I4))') 'INPUT/coupler.res: date_init=',date_init_res
if(mype == 0) write(*,'(A,6(I4))') 'INPUT/coupler.res: date =',date_res
if (calendar_type /= calendar_type_res) then
write(0,'(A)') 'fcst_initialize ERROR: calendar_type /= calendar_type_res'
write(0,'(A,6(I4))')' calendar_type = ', calendar_type
write(0,'(A,6(I4))')' calendar_type_res = ', calendar_type_res
call ESMF_Finalize(endflag=ESMF_END_ABORT)
endif
if (.not. ALL(date_init.EQ.date_init_res)) then
write(0,'(A)') 'fcst_initialize ERROR: date_init /= date_init_res'
write(0,'(A,6(I4))')' date_init = ', date_init
write(0,'(A,6(I4))')' date_init_res = ', date_init_res
call ESMF_Finalize(endflag=ESMF_END_ABORT)
endif
if (.not. ALL(date.EQ.date_res)) then
write(0,'(A)') 'fcst_initialize ERROR: date /= date_res'
write(0,'(A,6(I4))')' date = ', date
write(0,'(A,6(I4))')' date_res = ', date_res
call ESMF_Finalize(endflag=ESMF_END_ABORT)
endif
999 continue
998 continue
endif ! fexist
endif ! mype == 0
call diag_manager_init (TIME_INIT=date)
call diag_manager_set_time_end(Time_end)
!
Time_step = set_time (dt_atmos,0)
if (mype == 0) write(*,*)'time_init=', date_init,'time=',date,'time_end=',date_end,'dt_atmos=',dt_atmos
! set up forecast time array that controls when to write out restart files
frestart = 0
call get_time(Time_end - Time_init, total_inttime)
! set iau offset time
Atmos%iau_offset = iau_offset
if(iau_offset > 0 ) then
iautime = set_time(iau_offset * 3600, 0)
endif
! if the second item is -1, the first number is frequency
freq_restart = .false.
if(num_restart_interval == 2) then
if(restart_interval(2)== -1) freq_restart = .true.
endif
if(freq_restart) then
if(restart_interval(1) >= 0) then
tmpvar = restart_interval(1) * 3600
Time_step_restart = set_time (tmpvar, 0)
if(iau_offset > 0 ) then
Time_restart = Time_init + iautime + Time_step_restart
frestart(1) = tmpvar + iau_offset *3600
else
Time_restart = Time_init + Time_step_restart
frestart(1) = tmpvar
endif
if(restart_interval(1) > 0) then
i = 2
do while ( Time_restart < Time_end )
frestart(i) = frestart(i-1) + tmpvar
Time_restart = Time_restart + Time_step_restart
i = i + 1
enddo
endif
endif
! otherwise it is an array with forecast time at which the restart files will be written out
else if(num_restart_interval >= 1) then
if(num_restart_interval == 1 .and. restart_interval(1) == 0 ) then
frestart(1) = total_inttime
else
if(iau_offset > 0 ) then
restart_starttime = iau_offset *3600
else
restart_starttime = 0
endif
do i=1,num_restart_interval
frestart(i) = restart_interval(i) * 3600. + restart_starttime
enddo
endif
endif
! if to write out restart at the end of forecast
if (mype == 0) print *,'frestart=',frestart(1:10)/3600, 'total_inttime=',total_inttime
!------ initialize component models ------
call atmos_model_init (Atmos, Time_init, Time, Time_step)
!
inquire(FILE='data_table', EXIST=fexist)
if (fexist) then
call data_override_init()
endif
!-----------------------------------------------------------------------
!---- open and close dummy file in restart dir to check if dir exists --
if (mpp_pe() == 0 ) then
open( newunit=unit, file='RESTART/file', iostat=stat )
if (stat == 0) then
close(unit, status='delete')
else
call mpp_error ( FATAL, 'fcst_initialize: RESTART subdirectory does not exist in the run directory' )
endif
endif
!
!-----------------------------------------------------------------------
!*** create grid for output fields, using FV3 parameters
!-----------------------------------------------------------------------
!
call mpp_error(NOTE, 'before create fcst grid')
gridfile = "grid_spec.nc" ! default
if (open_file(fileobj, "INPUT/grid_spec.nc", "read")) then
if (variable_exists(fileobj, "atm_mosaic_file")) then
call read_data(fileobj, "atm_mosaic_file", gridfile)
endif
call close_file(fileobj)
endif
ngrids = Atmos%ngrids
mygrid = Atmos%mygrid
allocate(grid_number_on_all_pets(fcst_ntasks), is_moving_on_all_pets(fcst_ntasks))
call mpi_allgather(mygrid, 1, MPI_INTEGER, &
grid_number_on_all_pets, 1, MPI_INTEGER, &
fcst_mpi_comm, rc)
call mpi_allgather(Atmos%is_moving_nest, 1, MPI_LOGICAL, &
is_moving_on_all_pets, 1, MPI_LOGICAL, &
fcst_mpi_comm, rc)
allocate(is_moving(ngrids))
do n=1, fcst_ntasks
is_moving(grid_number_on_all_pets(n)) = is_moving_on_all_pets(n)
enddo
deallocate(grid_number_on_all_pets, is_moving_on_all_pets)
call ESMF_InfoGetFromHost(exportState, info=info, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="is_moving", values=is_moving, rc=rc); ESMF_ERR_ABORT(rc)
deallocate(is_moving)
allocate (fcstGridComp(ngrids))
do n=1,ngrids
pelist => null()
call atmos_model_get_nth_domain_info(n, layout, nx, ny, pelist)
call ESMF_VMBroadcast(vm, bcstData=layout, count=2, rootPet=pelist(1), rc=rc); ESMF_ERR_ABORT(rc)
if (n==1) then
! on grid==1 (top level parent) determine if the domain is global or regional
top_parent_is_global = .true.
if(mygrid==1) then
if (Atmos%regional) top_parent_is_global = .false.
endif
call mpi_bcast(top_parent_is_global, 1, MPI_LOGICAL, 0, fcst_mpi_comm, rc)
endif
if (n==1 .and. top_parent_is_global) then
fcstGridComp(n) = ESMF_GridCompCreate(name="global", petList=pelist, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoGetFromHost(fcstGridComp(n), info=info, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="layout", values=layout, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="tilesize", value=Atmos%mlon, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_GridCompSetServices(fcstGridComp(n), SetServicesNest, userrc=urc, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (ESMF_LogFoundError(rcToCheck=urc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__, rcToReturn=rc)) return
else
allocate(petListNest(layout(1)*layout(2)))
k=pelist(1)
do j=1,layout(2)
do i=1,layout(1)
petListNest(k-pelist(1)+1) = k
k = k + 1
end do
end do
fcstGridComp(n) = ESMF_GridCompCreate(name="nest", petList=petListNest, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoGetFromHost(fcstGridComp(n), info=info, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="layout", values=layout, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="nx", value=nx, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_InfoSet(info, key="ny", value=ny, rc=rc); ESMF_ERR_ABORT(rc)
call ESMF_GridCompSetServices(fcstGridComp(n), SetServicesNest, userrc=urc, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
if (ESMF_LogFoundError(rcToCheck=urc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__, rcToReturn=rc)) return
deallocate(petListNest)
end if
end do
! Add gridfile Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/"gridfile"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="gridfile", value=trim(gridfile), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! Add total number of domains(grids) Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/"ngrids"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="ngrids", value=ngrids, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! Add top_parent_is_global Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/"top_parent_is_global"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="top_parent_is_global", value=top_parent_is_global, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! Add time Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/ "time ", &
"time:long_name ", &
"time:units ", &
"time:cartesian_axis", &
"time:calendar_type ", &
"time:calendar " /), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time", value=real(0,ESMF_KIND_R8), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
write(dateSY,'(I4.4)')date_init(1)
write(dateSM,'(I2.2)')date_init(2)
write(dateSD,'(I2.2)')date_init(3)
write(dateSH,'(I2.2)')date_init(4)
write(dateSN,'(I2.2)')date_init(5)
write(dateSS,'(I2.2)')date_init(6)
dateS="hours since "//dateSY//'-'//dateSM//'-'//dateSD//' '//dateSH//':'// &
dateSN//":"//dateSS
if (mype == 0) write(*,*)'dateS=',trim(dateS),'date_init=',date_init
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:units", value=trim(dateS), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:long_name", value="time", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:cartesian_axis", value="T", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:calendar_type", value=uppercase(trim(calendar)), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_AttributeSet(exportState, convention="NetCDF", purpose="FV3", &
name="time:calendar", value=uppercase(trim(calendar)), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! Add time_iso Attribute to the exportState
call ESMF_AttributeAdd(exportState, convention="NetCDF", purpose="FV3", &
attrList=(/ "time_iso ", &
"time_iso:long_name ", &
"time_iso:description " /), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return