-
Notifications
You must be signed in to change notification settings - Fork 7
/
GEOS_GcmGridComp.F90
2966 lines (2417 loc) · 114 KB
/
GEOS_GcmGridComp.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
! $Id: GEOS_GcmGridComp.F90,v 1.30.2.1.4.4.2.2.2.1.2.11.6.1.4.1.2.1.2.1.14.2 2019/12/18 20:23:25 ltakacs Exp $
#include "MAPL_Generic.h"
!=============================================================================
!BOP
! !MODULE: GEOS_GcmGridCompMod -- A Module to combine Agcm and Ogcm Gridded Components
! !INTERFACE:
module GEOS_GcmGridCompMod
! !USES:
use ESMF
use MAPL
use GEOS_dataatmGridCompMod, only: DATAATM_SetServices => SetServices
use GEOS_AgcmGridCompMod, only: AGCM_SetServices => SetServices
use GEOS_mkiauGridCompMod, only: AIAU_SetServices => SetServices
use DFI_GridCompMod, only: ADFI_SetServices => SetServices
use GEOS_OgcmGridCompMod, only: OGCM_SetServices => SetServices
use GEOS_WgcmGridCompMod, only: WGCM_SetServices => SetServices
use MAPL_HistoryGridCompMod, only: Hist_SetServices => SetServices
use MAPL_HistoryGridCompMod, only: HISTORY_ExchangeListWrap
use iso_fortran_env
implicit none
private
! !PUBLIC MEMBER FUNCTIONS:
public SetServices
integer :: NUM_ICE_CATEGORIES
integer :: NUM_ICE_LAYERS
integer, parameter :: NUM_SNOW_LAYERS=1
integer :: DO_CICE_THERMO
integer :: DO_OBIO
integer :: DO_DATASEA
integer :: DO_WAVES
integer :: DO_SEA_SPRAY
logical :: seaIceT_extData
logical :: DO_DATA_ATM4OCN
!=============================================================================
! !DESCRIPTION: This gridded component (GC) combines the Agcm GC,
! and Ogcm GC into a new composite Gcm GC.
!EOP
integer :: AGCM
integer :: OGCM
integer :: AIAU
integer :: ADFI
integer :: WGCM
integer :: hist
integer :: bypass_ogcm
integer :: k
character(len = 2) :: suffix
type T_GCM_STATE
private
type (MAPL_LocStreamXFORM) :: XFORM_A2O
type (MAPL_LocStreamXFORM) :: XFORM_O2A
type(ESMF_State) :: impSKIN ! Ocean thin layer
type(ESMF_State) :: expSKIN
type(ESMF_Alarm) :: alarmOcn
type(ESMF_Alarm) :: replayStartAlarm
type(ESMF_Alarm) :: replayStopAlarm
type(ESMF_Alarm) :: replayCycleAlarm
type(ESMF_Alarm) :: Regular_Replay09Alarm
type(ESMF_Alarm) :: replayMKIAUAlarm
type(ESMF_Alarm) :: replayShutoffAlarm
integer :: cordur
integer :: predur
integer :: rplfreq
integer :: rplreft
logical :: rplRegular
logical :: checkpointRequested = .false.
character(len=ESMF_MAXSTR) :: checkpointFilename = ''
character(len=ESMF_MAXSTR) :: checkpointFileType = ''
type(ESMF_GridComp) :: history_parent
logical :: run_history = .false.
! coupling to wave model
type(ESMF_State) :: SURF_EXP
type(ESMF_State) :: SURF_IMP
type(ESMF_State) :: TURB_EXP
type(ESMF_State) :: TURB_IMP
type(ESMF_State) :: OCN_EXP
type(ESMF_State) :: OCN_IMP
type(ESMF_State) :: WGCM_EXP
type(ESMF_State) :: WGCM_IMP
type(ESMF_RouteHandle), pointer :: rh_a2w => NULL()
type(ESMF_RouteHandle), pointer :: rh_w2a => NULL()
type(ESMF_RouteHandle), pointer :: rh_o2w => NULL()
type(ESMF_RouteHandle), pointer :: rh_w2o => NULL()
end type T_GCM_STATE
! Wrapper for extracting internal state
! -------------------------------------
type GCM_WRAP
type (T_GCM_STATE), pointer :: PTR => null()
end type GCM_WRAP
logical :: DUAL_OCEAN
contains
!BOP
! !IROUTINE: SetServices -- Sets ESMF services for this component
! !INTERFACE:
subroutine SetServices ( GC, RC )
! !ARGUMENTS:
type(ESMF_GridComp), intent(INOUT) :: GC ! gridded component
integer, intent(out) :: RC ! return code
! !DESCRIPTION: The SetServices for the PhysicsGcm GC needs to register its
! Initialize and Run. It uses the MAPL\_Generic construct for defining
! state specs and couplings among its children. In addition, it creates the
! children GCs (AGCM and OGCM) and runs their
! respective SetServices.
!EOP
!=============================================================================
!
! ErrLog Variables
character(len=ESMF_MAXSTR) :: IAm
integer :: STATUS
character(len=ESMF_MAXSTR) :: COMP_NAME
! Locals
type (T_GCM_STATE), pointer :: gcm_internal_state => null()
type (GCM_wrap) :: wrap
type (T_EXTDATA_STATE), pointer :: extdata_internal_state
type (EXTDATA_wrap) :: ExtDataWrap
type (MAPL_MetaComp), pointer :: MAPL
character(len=ESMF_MAXSTR) :: ReplayMode
character(len=ESMF_MAXSTR) :: CONVPAR_OPTION
character(len=ESMF_MAXSTR) :: AERO_PROVIDER
logical :: rplRegular
type (ESMF_Config) :: CF
integer :: heartbeat
integer :: ASSIMILATION_CYCLE
integer :: CORRECTOR_DURATION
integer :: MKIAU_FREQUENCY
integer :: MKIAU_REFERENCE_TIME
integer :: REPLAY_FILE_FREQUENCY
integer :: REPLAY_FILE_REFERENCE_TIME
integer :: iDUAL_OCEAN
!=============================================================================
! Begin...
! Get my name and set-up traceback handle
! ---------------------------------------
Iam = 'SetServices'
call ESMF_GridCompGet( GC, NAME=COMP_NAME, CONFIG=CF, RC=STATUS )
VERIFY_(STATUS)
Iam = trim(COMP_NAME) // Iam
! Register services for this component
! ------------------------------------
call MAPL_GridCompSetEntryPoint ( GC, ESMF_METHOD_INITIALIZE, Initialize, RC=STATUS )
VERIFY_(STATUS)
call MAPL_GridCompSetEntryPoint ( GC, ESMF_METHOD_RUN, Run, RC=STATUS )
VERIFY_(STATUS)
! Get my MAPL_Generic state
!--------------------------
call MAPL_GetObjectFromGC ( GC, MAPL, RC=STATUS)
VERIFY_(STATUS)
! Get constants from CF
! ---------------------
call MAPL_GetResource ( MAPL, DO_CICE_THERMO, Label="USE_CICE_Thermo:" , DEFAULT=0, _RC)
if (DO_CICE_THERMO /= 0) then
call ESMF_ConfigGetAttribute(CF, NUM_ICE_CATEGORIES, Label="CICE_N_ICE_CATEGORIES:" , _RC)
if (DO_CICE_THERMO == 1) then
call ESMF_ConfigGetAttribute(CF, NUM_ICE_LAYERS, Label="CICE_N_ICE_LAYERS:" , _RC)
endif
else
NUM_ICE_CATEGORIES = 1
NUM_ICE_LAYERS = 1
endif
call MAPL_GetResource ( MAPL, DO_OBIO, Label="USE_OCEANOBIOGEOCHEM:", DEFAULT=0, _RC)
call MAPL_GetResource ( MAPL, DO_DATA_ATM4OCN, Label="USE_DATA_ATM4OCN:", DEFAULT=.FALSE., _RC)
call MAPL_GetResource ( MAPL, DO_DATASEA, Label="USE_DATASEA:", DEFAULT=1, _RC)
call MAPL_GetResource ( MAPL, seaIceT_extData, Label="SEAICE_THICKNESS_EXT_DATA:", DEFAULT=.FALSE., _RC )
call MAPL_GetResource ( MAPL, DO_WAVES, Label="USE_WAVES:", DEFAULT=0, _RC)
call MAPL_GetResource ( MAPL, DO_SEA_SPRAY, Label="USE_SEA_SPRAY:", DEFAULT=0, _RC)
call MAPL_GetResource(MAPL, ReplayMode, 'REPLAY_MODE:', default="NoReplay", _RC )
! Default is not to do dual_ocean
call MAPL_GetResource(MAPL, iDUAL_OCEAN, 'DUAL_OCEAN:', default=0, _RC)
DUAL_OCEAN = iDUAL_OCEAN /= 0
if (DUAL_OCEAN) then
ASSERT_( adjustl(ReplayMode)=="Regular" )
endif
! Get/Set Default RUN Parameters used by Multiple Gridded Components
!-------------------------------------------------------------------
call MAPL_GetResource( MAPL, CONVPAR_OPTION, Label="CONVPAR_OPTION:", default="NULL", RC=STATUS)
VERIFY_(STATUS)
if( trim(CONVPAR_OPTION) == "NULL" ) then
CONVPAR_OPTION = "RAS"
call MAPL_ConfigSetAttribute( CF, CONVPAR_OPTION, Label="CONVPAR_OPTION:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting CONVPAR_OPTION to ',trim(CONVPAR_OPTION)
endif
call MAPL_GetResource( MAPL, AERO_PROVIDER, Label="AERO_PROVIDER:", default="NULL", RC=STATUS)
VERIFY_(STATUS)
if( trim(AERO_PROVIDER) == "NULL" ) then
AERO_PROVIDER = "GOCART.data"
call MAPL_ConfigSetAttribute( CF, AERO_PROVIDER, Label="AERO_PROVIDER:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting AERO_PROVIDER to ',trim(AERO_PROVIDER)
endif
! Create childrens gridded components and invoke their SetServices
! ----------------------------------------------------------------
if(DO_DATA_ATM4OCN) then
AGCM = MAPL_AddChild(GC, NAME='DATAATM', SS=DATAATM_SetServices, RC=STATUS)
VERIFY_(STATUS)
else
AGCM = MAPL_AddChild(GC, NAME='AGCM', SS=Agcm_SetServices, RC=STATUS)
VERIFY_(STATUS)
AIAU = MAPL_AddChild(GC, NAME='AIAU', SS=AIAU_SetServices, RC=STATUS)
VERIFY_(STATUS)
ADFI = MAPL_AddChild(GC, NAME='ADFI', SS=ADFI_SetServices, RC=STATUS)
VERIFY_(STATUS)
endif
OGCM = MAPL_AddChild(GC, NAME='OGCM', SS=Ogcm_SetServices, RC=STATUS)
VERIFY_(STATUS)
if (DO_WAVES /= 0) then
WGCM = MAPL_AddChild(GC, NAME='WGCM', SS=Wgcm_SetServices, RC=STATUS)
VERIFY_(STATUS)
end if
! Get RUN Parameters (MERRA-2 Defaults) and Initialize for use in other Components (e.g., AGCM_GridComp and MKIAU_GridComp)
!--------------------------------------------------------------------------------------------------------------------------
! Get HEARTBEAT
! -------------
call MAPL_GetResource( MAPL, heartbeat, Label="RUN_DT:", RC=STATUS)
VERIFY_(STATUS)
! Get ASSIMILATION_CYCLE Duration. If NOT_PRESENT, Initialize to MERRA-2 Default and Set Attribute.
!---------------------------------------------------------------------------------------------------
call MAPL_GetResource( MAPL, ASSIMILATION_CYCLE, Label="ASSIMILATION_CYCLE:", default=-999, RC=STATUS)
VERIFY_(STATUS)
if( ASSIMILATION_CYCLE .eq. -999 ) then
ASSIMILATION_CYCLE = 21600
call MAPL_ConfigSetAttribute( CF, ASSIMILATION_CYCLE, Label="ASSIMILATION_CYCLE:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting ASSIMILATION_CYCLE to ',ASSIMILATION_CYCLE
endif
! Get CORRECTOR_DURATION. If NOT_PRESENT, Initialize to MERRA-2 Default and Set Attribute.
! -----------------------------------------------------------------------------------------
call MAPL_GetResource( MAPL, CORRECTOR_DURATION, Label="CORRECTOR_DURATION:", default=-999, RC=STATUS)
VERIFY_(STATUS)
if( CORRECTOR_DURATION .eq. -999 ) then
CORRECTOR_DURATION = ASSIMILATION_CYCLE
call MAPL_ConfigSetAttribute( CF, CORRECTOR_DURATION, Label="CORRECTOR_DURATION:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting CORRECTOR_DURATION, to ',CORRECTOR_DURATION
endif
! Get REPLAY Frequency and Reference Time Associated with Forcing Files
! ---------------------------------------------------------------------
call MAPL_GetResource(MAPL,REPLAY_FILE_FREQUENCY, Label="REPLAY_FILE_FREQUENCY:", default=-999, rc=STATUS )
VERIFY_(STATUS)
call MAPL_GetResource(MAPL,REPLAY_FILE_REFERENCE_TIME, Label="REPLAY_FILE_REFERENCE_TIME:", default=-999, rc=STATUS )
VERIFY_(STATUS)
! Get MKIAU Frequency and Reference Time Associated with MKIAU Updates
! --------------------------------------------------------------------
call MAPL_GetResource(MAPL,MKIAU_FREQUENCY, Label="MKIAU_FREQUENCY:", default=-999, rc=STATUS )
VERIFY_(STATUS)
call MAPL_GetResource(MAPL,MKIAU_REFERENCE_TIME, Label="MKIAU_REFERENCE_TIME:", default=-999, rc=STATUS )
VERIFY_(STATUS)
! Set MKIAU_FREQUENCY and REPLAY_FILE_FREQUENCY Defaults
! ------------------------------------------------------
if( (MKIAU_FREQUENCY .eq. -999) .and. (REPLAY_FILE_FREQUENCY .eq. -999) ) then
REPLAY_FILE_FREQUENCY = CORRECTOR_DURATION
MKIAU_FREQUENCY = CORRECTOR_DURATION
call MAPL_ConfigSetAttribute( CF, MKIAU_FREQUENCY, Label="MKIAU_FREQUENCY:", RC=STATUS)
VERIFY_(STATUS)
call MAPL_ConfigSetAttribute( CF, REPLAY_FILE_FREQUENCY, Label="REPLAY_FILE_FREQUENCY:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting MKIAU_FREQUENCY, to ',MKIAU_FREQUENCY
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting REPLAY_FILE_FREQUENCY, to ',REPLAY_FILE_FREQUENCY
else if( MKIAU_FREQUENCY .eq. -999 ) then
MKIAU_FREQUENCY = REPLAY_FILE_FREQUENCY
call MAPL_ConfigSetAttribute( CF, MKIAU_FREQUENCY, Label="MKIAU_FREQUENCY:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting MKIAU_FREQUENCY, to ',MKIAU_FREQUENCY
else if( REPLAY_FILE_FREQUENCY .eq. -999 ) then
REPLAY_FILE_FREQUENCY = MKIAU_FREQUENCY
call MAPL_ConfigSetAttribute( CF, REPLAY_FILE_FREQUENCY, Label="REPLAY_FILE_FREQUENCY:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting REPLAY_FILE_FREQUENCY, to ',REPLAY_FILE_FREQUENCY
endif
! Set MKIAU_REFERENCE_TIME and REPLAY_FILE_REFERENCE_TIME Defaults
! ----------------------------------------------------------------
if( (MKIAU_REFERENCE_TIME .eq. -999) .and. (REPLAY_FILE_REFERENCE_TIME .eq. -999) ) then
REPLAY_FILE_REFERENCE_TIME = 000000
MKIAU_REFERENCE_TIME = 000000
call MAPL_ConfigSetAttribute( CF, MKIAU_REFERENCE_TIME, Label="MKIAU_REFERENCE_TIME:", RC=STATUS)
VERIFY_(STATUS)
call MAPL_ConfigSetAttribute( CF, REPLAY_FILE_REFERENCE_TIME, Label="REPLAY_FILE_REFERENCE_TIME:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting MKIAU_REFERENCE_TIME, to ',MKIAU_REFERENCE_TIME
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting REPLAY_FILE_REFERENCE_TIME, to ',REPLAY_FILE_REFERENCE_TIME
else if( MKIAU_REFERENCE_TIME .eq. -999 ) then
MKIAU_REFERENCE_TIME = REPLAY_FILE_REFERENCE_TIME
call MAPL_ConfigSetAttribute( CF, MKIAU_REFERENCE_TIME, Label="MKIAU_REFERENCE_TIME:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting MKIAU_REFERENCE_TIME, to ',MKIAU_REFERENCE_TIME
else if( REPLAY_FILE_REFERENCE_TIME .eq. -999 ) then
REPLAY_FILE_REFERENCE_TIME = MKIAU_REFERENCE_TIME
call MAPL_ConfigSetAttribute( CF, REPLAY_FILE_REFERENCE_TIME, Label="REPLAY_FILE_REFERENCE_TIME:", RC=STATUS)
VERIFY_(STATUS)
IF(MAPL_AM_I_ROOT()) PRINT *,'Setting REPLAY_FILE_REFERENCE_TIME, to ',REPLAY_FILE_REFERENCE_TIME
endif
! Get REPLAY Parameters
! ---------------------
call MAPL_GetResource(MAPL, ReplayMode, 'REPLAY_MODE:', default="NoReplay", RC=STATUS )
VERIFY_(STATUS)
! -------------------------------------------
! We need to know if we are doing "regular" replay
! if yes, then we are modifing MKIAU import specs
! to perform averaging of all MKIAU imports
if(adjustl(ReplayMode)=="Regular") then
rplRegular = .true.
else
rplRegular = .false.
endif
! Borrow exports from children
! Export for IAU and/or Analysis purposes
! ---------------------------------------
if(.not. DO_DATA_ATM4OCN) then
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'AK', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'BK', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'PS', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'DELP', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'TV', &
CHILD_ID = AGCM, &
RC = STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'U', &
CHILD_ID = AGCM, &
RC = STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'V', &
CHILD_ID = AGCM, &
RC = STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'PHIS', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'Q', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'QCTOT', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'QITOT', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'QLTOT', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'O3PPMV', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'U10N', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'V10N', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'SNOMAS', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'WET1', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'TSOIL1', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'LWI', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'TS', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'Z0', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'FRLAND', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'FRLANDICE',&
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'FRLAKE', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'FROCEAN', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddExportSpec ( GC, &
SHORT_NAME = 'FRACI', &
CHILD_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
endif
if(.not. DO_DATA_ATM4OCN) then
call MAPL_AddConnectivity ( GC, &
SHORT_NAME = (/'PHIS ','AK ','BK ','U ','V ','TV ','PS ','DELP ','O3PPMV', 'TS ','AREA '/), &
DST_ID = AIAU, &
SRC_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddConnectivity ( GC, &
SHORT_NAME = (/'DUDT ','DVDT ','DTDT ','DQVDT','DPEDT','DO3DT','DTSDT'/), &
DST_ID = AGCM, &
SRC_ID = AIAU, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddConnectivity ( GC, &
SRC_NAME = [character(len=13) :: 'Q ','PPBL','TROPP_BLENDED'], &
DST_NAME = [character(len=13) :: 'QV','PPBL','TROPP_BLENDED'], &
DST_ID = AIAU, &
SRC_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_AddConnectivity ( GC, &
SHORT_NAME = (/'U_DGRID','V_DGRID','PT ', &
'PE ','Q ','OX ' /), &
DST_ID = ADFI, &
SRC_ID = AGCM, &
RC=STATUS )
VERIFY_(STATUS)
endif
if (DO_CICE_THERMO == 2) then
call MAPL_AddConnectivity ( GC, &
SHORT_NAME = (/'SURFSTATE'/), &
DST_ID = AGCM, &
SRC_ID = OGCM, &
RC=STATUS )
VERIFY_(STATUS)
endif
! Next vars are explicitly connected through exchange grid transforms Run
!-------------------------------------------------------------------------
if (.not. seaIceT_extData) then
call MAPL_TerminateImport ( GC, &
SHORT_NAME = [character(len=7) :: &
'TAUXW ','TAUYW ','TAUXI ','TAUYI ', &
'OUSTAR3','PS ', &
'TI ','SI ' , &
'PENUVR ','PENUVF ','PENPAR ','PENPAF ', &
'DISCHRG', 'LWFLX', 'SHFLX', 'QFLUX', &
'DRNIR' , 'DFNIR', &
'SNOW', 'RAIN', 'PEN_OCN'], &
CHILD = OGCM, &
_RC)
else
call MAPL_TerminateImport ( GC, &
SHORT_NAME = [character(len=7) :: &
'TAUXW ','TAUYW ','TAUXI ','TAUYI ', &
'OUSTAR3','PS ', &
'PENUVR ','PENUVF ','PENPAR ','PENPAF ', &
'DISCHRG', 'LWFLX', 'SHFLX', 'QFLUX', &
'DRNIR' , 'DFNIR', &
'SNOW', 'RAIN', 'FRESH', 'FSALT', &
'FHOCN', 'PEN_OCN'], &
CHILD = OGCM, &
_RC)
endif
if (DO_CICE_THERMO <= 1) then
call MAPL_TerminateImport ( GC, &
SHORT_NAME = [character(len=5) :: &
'HI', 'FRESH', 'FSALT', 'FHOCN'], &
CHILD = OGCM, &
_RC)
endif
if (DO_CICE_THERMO == 1) then
call MAPL_TerminateImport ( GC, &
SHORT_NAME = (/ &
'FRACICE', 'VOLICE ', 'VOLSNO ', &
'ERGICE ', 'ERGSNO ', 'TAUAGE ', 'MPOND '/), &
CHILD = OGCM, &
_RC)
endif
if (DO_OBIO/=0) then
call OBIO_TerminateImports(DO_DATA_ATM4OCN, RC)
end if
if (DO_WAVES /= 0) then
! Terminate the imports of WGCM with the exception
! of the few that have to be sent to ExtData
call MAPL_TerminateImport(GC, &
SHORT_NAME = (/ &
'U10M ', 'V10M ', 'U10N ', 'V10N ', &
'RHOS ', 'TSKINW ', 'TS ', 'FRLAND ', &
'FROCEAN', 'FRACI ', 'PS ', 'Q10M ', &
'RH2M ', 'T10M ', 'LHFX ', 'SH ', &
'TW ', 'UW ', 'VW '/), &
CHILD=WGCM, &
RC=STATUS)
VERIFY_(STATUS)
end if
! Allocate this instance of the internal state and put it in wrapper.
! -------------------------------------------------------------------
allocate( gcm_internal_state, stat=status )
VERIFY_(STATUS)
wrap%ptr => gcm_internal_state
gcm_internal_state%rplRegular = rplRegular
gcm_internal_state%cordur = CORRECTOR_DURATION
gcm_internal_state%rplfreq = MKIAU_FREQUENCY
gcm_internal_state%rplreft = MKIAU_REFERENCE_TIME
! If doing regular replay make state to "borrow" gc and import to ExtData
! -----------------------------------------------------------------------
if (rplRegular) then
allocate( extdata_internal_state, stat=status)
VERIFY_(STATUS)
ExtDataWrap%ptr => extdata_internal_state
call ESMF_UserCompSetInternalState( GC, 'ExtData_state',ExtDataWrap,status)
VERIFY_(STATUS)
call history_setservice(_RC)
end if
! Save pointer to the wrapped internal state in the GC
! ----------------------------------------------------
call ESMF_UserCompSetInternalState ( GC, 'GCM_state',wrap,status )
VERIFY_(STATUS)
call MAPL_GenericSetServices ( GC, RC=STATUS )
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="INITIALIZE" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="RUN" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--OCEAN" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--ATMOSPHERE" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--REPLAY" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--A2O" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--O2A" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--A2W" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--W2A" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--O2W" ,RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerAdd(GC, name="--W2O" ,RC=STATUS)
VERIFY_(STATUS)
RETURN_(ESMF_SUCCESS)
contains
subroutine history_setservice(rc)
integer, intent(out), optional :: rc
integer :: status
type(ESMF_Config) :: hist_cf, gcm_cf
type(MAPL_MetaComp), pointer :: history_metaobj
type(StubComponent) :: stub_component
integer :: run_dt
character(len=ESMF_MAXSTR) :: replay_history
logical :: is_present
call ESMF_GridCompGet(gc,config=gcm_cf,_RC)
call ESMF_ConfigFindLabel(gcm_cf,"REPLAY_HISTORY_RC:",isPresent=is_present,_RC)
if (is_present) then
gcm_internal_state%run_history = .true.
call MAPL_GetResource(MAPL,replay_history,"REPLAY_HISTORY_RC:",_RC)
hist_cf = ESMF_ConfigCreate(_RC)
call ESMF_ConfigLoadFile(hist_cf,trim(replay_history),_RC)
call MAPL_GetResource(MAPL,run_dt,"RUN_DT:",_RC)
call MAPL_ConfigSetAttribute(hist_cf,value=run_dt,label="RUN_DT:",_RC)
call MAPL_ConfigSetAttribute(hist_cf,value=replay_history,label="HIST_CF:",_RC)
gcm_internal_state%history_parent = ESMF_GridCompCreate(name="History_GCM_parent",config=hist_cf,_RC)
history_metaobj => null()
call MAPL_InternalStateCreate(gcm_internal_state%history_parent,history_metaobj,_RC)
call MAPL_Set(history_metaobj,cf=hist_cf,name="History_GCM_parent",component=stub_component,_RC)
hist = MAPL_AddChild(history_metaobj,name="History_GCM",ss=hist_setservices,_RC)
end if
_RETURN(_SUCCESS)
end subroutine history_setservice
subroutine OBIO_TerminateImports(DO_DATA_ATM4OCN, RC)
logical, intent(IN ) :: DO_DATA_ATM4OCN
integer, optional, intent( OUT) :: RC
character(len=ESMF_MAXSTR), parameter :: IAm="OBIO_TerminateImports"
integer :: STATUS
integer :: k
call MAPL_TerminateImport ( GC, &
SHORT_NAME = [character(len=7) :: &
'CO2SC ','DUDP ','DUWT ','DUSD '],&
CHILD = OGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_TerminateImport ( GC, &
SHORT_NAME = (/'UU'/), &
CHILD = OGCM, &
RC=STATUS )
VERIFY_(STATUS)
call MAPL_TerminateImport ( GC, &
SHORT_NAME = (/'DRBAND', 'DFBAND'/), &
CHILD = OGCM, &
RC=STATUS )
VERIFY_(STATUS)
if(.not. DO_DATA_ATM4OCN) then
call MAPL_TerminateImport ( GC, &
SHORT_NAME = (/'BCDP', 'BCWT', 'OCDP', 'OCWT' /), &
CHILD = OGCM, &
RC=STATUS )
VERIFY_(STATUS)
end if
RETURN_(ESMF_SUCCESS)
end subroutine OBIO_TerminateImports
end subroutine SetServices
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! !IROUTINE: Initialize -- Initialize method for the composite Gcm Gridded Component
! !INTERFACE:
subroutine Initialize ( GC, IMPORT, EXPORT, CLOCK, RC )
! !ARGUMENTS:
type(ESMF_GridComp), intent(inout) :: GC ! Gridded component
type(ESMF_State), intent(inout) :: IMPORT ! Import state
type(ESMF_State), intent(inout) :: EXPORT ! Export state
type(ESMF_Clock), intent(inout) :: CLOCK ! The clock
integer, optional, intent( out) :: RC ! Error code
! !DESCRIPTION:
!EOP
! ErrLog Variables
character(len=ESMF_MAXSTR) :: IAm
integer :: STATUS
character(len=ESMF_MAXSTR) :: COMP_NAME
! Local derived type aliases
type(ESMF_Grid) :: agrid
type(ESMF_Grid) :: ogrid
type(MAPL_LocStream):: exchA
type(MAPL_LocStream):: exchO
type(MAPL_LocStream):: locstA
type(ESMF_DELayout) :: layout
type (ESMF_Config) :: CF
type (ESMF_VM) :: VM
type (MAPL_MetaComp), pointer :: MAPL => null()
type (MAPL_MetaComp), pointer :: CMAPL => null()
type (ESMF_GridComp), pointer :: GCS(:) => null()
type (ESMF_State), pointer :: GIM(:) => null()
type (ESMF_State), pointer :: GEX(:) => null()
character(len=ESMF_MAXSTR), pointer :: GCNAMES(:) => null()
character(len=ESMF_MAXSTR) :: skinname
character(len=ESMF_MAXSTR) :: tilingfile
character(len=ESMF_MAXSTR) :: tmpStr
character(len=ESMF_MAXSTR) :: ReplayMode
type (T_GCM_STATE), pointer :: gcm_internal_state => null()
type (GCM_wrap) :: wrap
type(ESMF_Calendar) :: cal
type(ESMF_Time) :: rep_StartTime
type(ESMF_Time) :: rep_RefTime
type(ESMF_Time) :: currTime
type(ESMF_Time) :: ringTime
type(ESMF_TimeInterval) :: CORRECTOR_DURATION
type(ESMF_TimeInterval) :: PREDICTOR_DURATION
type(ESMF_TimeInterval) :: MKIAU_FREQUENCY
type(ESMF_TimeInterval) :: Shutoff
type(ESMF_Alarm) :: replayStartAlarm
type(ESMF_Alarm) :: replayStopAlarm
type(ESMF_Alarm) :: replayCycleAlarm
type(ESMF_Alarm) :: Exact_Replay09Alarm
type(ESMF_Alarm) :: Regular_Replay09Alarm
type(ESMF_Alarm) :: replayMKIAUAlarm
type(ESMF_Alarm) :: replayShutoffAlarm
TYPE(ESMF_Alarm) :: PredictorIsActive
type(ESMF_Alarm) :: alarms(1)
type(ESMF_DistGrid) :: distGRID
integer :: i_CORRECTOR_DURATION
integer :: i_PREDICTOR_DURATION
integer :: i_MKIAU_FREQUENCY
integer :: MKIAU_REFERENCE_TIME
integer :: rplshut
integer :: rep_startdate(2)
integer :: rep_YY
integer :: rep_MM
integer :: rep_DD
integer :: rep_H
integer :: rep_M
integer :: rep_S
integer :: MKIAU_RingDate
integer :: MKIAU_RingTime
logical :: FileExists
!=============================================================================
! Begin...
! Get the target components name and set-up traceback handle.
! -----------------------------------------------------------
call ESMF_GridCompGet( GC, NAME=COMP_NAME, CONFIG=CF, RC=STATUS )
VERIFY_(STATUS)
Iam = trim(COMP_NAME) // "Initialize"
! Get my MAPL_Generic state
!--------------------------
call MAPL_GetObjectFromGC ( GC, MAPL, RC=STATUS)
VERIFY_(STATUS)
call MAPL_TimerOn(MAPL,"INITIALIZE")
call MAPL_TimerOn(MAPL,"TOTAL")
! Get my internal private state. This contains the transforms
! between the exchange grid and the atmos grid.
!-------------------------------------------------------------
call ESMF_UserCompGetInternalState(gc, 'GCM_state', wrap, status)
VERIFY_(STATUS)
gcm_internal_state => wrap%ptr
! Get children and their im/ex states from my generic state.
!----------------------------------------------------------
call MAPL_Get ( MAPL, GCS=GCS, GIM=GIM, GEX=GEX, GCNAMES=GCNAMES, RC=STATUS )
VERIFY_(STATUS)
! Create Atmospheric grid
!------------------------
call MAPL_GridCreate(GCS(AGCM), rc=status)
VERIFY_(STATUS)
! Create Waves grid
!------------------------
if (DO_WAVES /= 0) then
call MAPL_GridCreate(GCS(WGCM), rc=status)
VERIFY_(STATUS)
end if
! Create Ocean grid
!------------------
call MAPL_GridCreate(GCS(OGCM), rc=status)
VERIFY_(STATUS)
call ESMF_GridCompGet(GCS(OGCM), grid=ogrid, rc=status)
VERIFY_(STATUS)
call ESMF_GridCompGet(GCS(AGCM), grid=agrid, rc=status)
VERIFY_(STATUS)
call ESMF_GridGet(agrid, DistGrid=distgrid, rc=status)
VERIFY_(STATUS)
call ESMF_DistGridGet(distGRID, deLayout=layout, RC=STATUS)
VERIFY_(STATUS)
! Create exchange grids from tile file
!-------------------------------------
call MAPL_GetResource(MAPL, TILINGFILE, 'TILING_FILE:', &
default="tile.data", RC=STATUS)
VERIFY_(STATUS)
call MAPL_LocStreamCreate(exchA, LAYOUT=layout, FILENAME=TILINGFILE, &
NAME='MAIN_Atm', &
grid=agrid, RC=STATUS)
VERIFY_(STATUS)
call MAPL_LocStreamCreate(exchO, LAYOUT=layout, FILENAME=TILINGFILE, &
NAME='MAIN_Ocn', mask=(/ MAPL_OCEAN /), &
grid=ogrid, RC=STATUS)
VERIFY_(STATUS)
! ------------------------------------------------------
! Add default exchange grid to both Atm and Ocn
! ------------------------------------------------------
call MAPL_ExchangeGridSet(GCS(AGCM), exchA, rc=status)
VERIFY_(STATUS)
call MAPL_ExchangeGridSet(GCS(OGCM), exchO, rc=status)
VERIFY_(STATUS)
! Recursive setup of grids (should be disabled)
call ESMF_GridCompSet(GCS(AGCM), grid=agrid, rc=status)
VERIFY_(STATUS)
call ESMF_GridCompSet(GCS(OGCM), grid=ogrid, rc=status)
VERIFY_(STATUS)
if(.not. DO_DATA_ATM4OCN) then
call ESMF_GridCompSet(GCS(AIAU), grid=agrid, rc=status)
VERIFY_(STATUS)
call ESMF_GridCompSet(GCS(ADFI), grid=agrid, rc=status)
VERIFY_(STATUS)
endif
!ALT we need a grid for GCM - we put either the Agrid or the Ogrid
! depending of what exports are we propagating up
call ESMF_GridCompSet(GC, grid=agrid, rc=status)
VERIFY_(STATUS)
GCM_INTERNAL_STATE%checkpointRequested = .false.
call MAPL_GetResource(MAPL, ReplayMode, 'REPLAY_MODE:', default="NoReplay", RC=STATUS )
VERIFY_(STATUS)
! ALT replay: create alarms
! -------------------------
i_CORRECTOR_DURATION = gcm_internal_state%corDur
i_MKIAU_FREQUENCY = gcm_internal_state%rplfreq
MKIAU_REFERENCE_TIME = gcm_internal_state%rplreft
call MAPL_GetResource(MAPL, rplshut, Label="REPLAY_SHUTOFF:", default=-3600, rc=status)
VERIFY_(STATUS)
call ESMF_ClockGet(clock, currTime=currTime, calendar=cal, rc=status)
VERIFY_(STATUS)
call ESMF_TimeIntervalSet(CORRECTOR_DURATION, S=i_CORRECTOR_DURATION, rc=status)
VERIFY_(STATUS)
call ESMF_TimeIntervalSet(MKIAU_FREQUENCY, S=i_MKIAU_FREQUENCY, rc=status)
VERIFY_(STATUS)
call ESMF_TimeIntervalSet(Shutoff, S=abs(rplshut), rc=status)
VERIFY_(STATUS)
rep_StartTime = currTime
! UNPACK REPLAY_STARTTIME