-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmed.F90
2592 lines (2226 loc) · 122 KB
/
med.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
module MED
!-----------------------------------------------------------------------------
! Mediator Initialization
!
! Note on time management:
! Each time loop has its own associated clock object. NUOPC manages
! these clock objects, i.e. their creation and destruction, as well as
! startTime, endTime, timeStep adjustments during the execution. The
! outer most time loop of the run sequence is a special case. It uses
! the driver clock itself. If a single outer most loop is defined in
! the run sequence provided by freeFormat, this loop becomes the driver
! loop level directly. Therefore, setting the timeStep or runDuration
! for the outer most time loop results in modifying the driver clock
! itself. However, for cases with cocnatenated loops on the upper level
! of the run sequence in freeFormat, a single outer loop is added
! automatically during ingestion, and the driver clock is used for this
! loop instead.
!-----------------------------------------------------------------------------
use ESMF , only : ESMF_VMLogMemInfo
use NUOPC_Model , only : SetVM
use med_kind_mod , only : CX=>SHR_KIND_CX, CS=>SHR_KIND_CS, CL=>SHR_KIND_CL, R8=>SHR_KIND_R8
use med_constants_mod , only : dbug_flag => med_constants_dbug_flag
use med_constants_mod , only : spval_init => med_constants_spval_init
use med_constants_mod , only : spval => med_constants_spval
use med_constants_mod , only : czero => med_constants_czero
use med_utils_mod , only : chkerr => med_utils_ChkErr
use med_methods_mod , only : Field_GeomPrint => med_methods_Field_GeomPrint
use med_methods_mod , only : State_GeomPrint => med_methods_State_GeomPrint
use med_methods_mod , only : State_reset => med_methods_State_reset
use med_methods_mod , only : State_getNumFields => med_methods_State_getNumFields
use med_methods_mod , only : State_GetScalar => med_methods_State_GetScalar
use med_methods_mod , only : FB_Init => med_methods_FB_init
use med_methods_mod , only : FB_Init_pointer => med_methods_FB_Init_pointer
use med_methods_mod , only : FB_Reset => med_methods_FB_Reset
use med_methods_mod , only : FB_diagnose => med_methods_FB_diagnose
use med_methods_mod , only : FB_getFieldN => med_methods_FB_getFieldN
use med_methods_mod , only : clock_timeprint => med_methods_clock_timeprint
use med_utils_mod , only : memcheck => med_memcheck
use med_time_mod , only : med_time_alarmInit
use med_internalstate_mod , only : InternalState, med_internalstate_init, med_internalstate_coupling
use med_internalstate_mod , only : med_internalstate_defaultmasks, logunit, maintask
use med_internalstate_mod , only : ncomps, compname
use med_internalstate_mod , only : compmed, compatm, compocn, compice, complnd, comprof, compwav, compglc
use med_internalstate_mod , only : coupling_mode, aoflux_code, aoflux_ccpp_suite
use esmFlds , only : med_fldList_GetocnalbfldList, med_fldList_type
use esmFlds , only : med_fldList_GetNumFlds, med_fldList_GetFldNames, med_fldList_GetFldInfo
use esmFlds , only : med_fldList_Document_Mapping, med_fldList_Document_Merging
use esmFlds , only : med_fldList_GetfldListFr, med_fldList_GetfldListTo, med_fldList_Realize
use esmFldsExchange_ufs_mod , only : esmFldsExchange_ufs
use esmFldsExchange_cesm_mod , only : esmFldsExchange_cesm
use esmFldsExchange_hafs_mod , only : esmFldsExchange_hafs
use med_phases_profile_mod , only : med_phases_profile_finalize
implicit none
private
public SetServices
public SetVM
private InitializeP0
private AdvertiseFields ! advertise fields
private RealizeFieldsWithTransferProvided ! realize connected Fields with transfer action "provide"
private ModifyDecompofMesh ! optionally modify the decomp/distr of transferred Grid/Mesh
private RealizeFieldsWithTransferAccept ! realize all Fields with transfer action "accept"
private DataInitialize ! finish initialization and resolve data dependencies
private SetRunClock
private med_meshinfo_create
private med_grid_write
private med_write_dststatus
private med_finalize
character(len=*), parameter :: u_FILE_u = &
__FILE__
logical :: profile_memory = .false.
logical, allocatable :: compDone(:) ! component done flag
!-----------------------------------------------------------------------------
contains
!-----------------------------------------------------------------------------
subroutine SetServices(gcomp, rc)
use ESMF , only: ESMF_SUCCESS, ESMF_GridCompSetEntryPoint
use ESMF , only: ESMF_METHOD_INITIALIZE, ESMF_METHOD_RUN
use ESMF , only: ESMF_GridComp, ESMF_MethodRemove
use NUOPC , only: NUOPC_CompDerive, NUOPC_CompSetEntryPoint, NUOPC_CompSpecialize, NUOPC_NoOP
use NUOPC_Mediator , only: mediator_routine_SS => SetServices
use NUOPC_Mediator , only: mediator_routine_Run => routine_Run
use NUOPC_Mediator , only: mediator_label_DataInitialize => label_DataInitialize
use NUOPC_Mediator , only: mediator_label_Advance => label_Advance
use NUOPC_Mediator , only: mediator_label_CheckImport => label_CheckImport
use NUOPC_Mediator , only: mediator_label_TimestampExport => label_TimestampExport
use NUOPC_Mediator , only: mediator_label_SetRunClock => label_SetRunClock
use NUOPC_Mediator , only: mediator_label_Finalize => label_Finalize
use med_phases_history_mod , only: med_phases_history_write
use med_phases_restart_mod , only: med_phases_restart_write
use med_phases_prep_atm_mod , only: med_phases_prep_atm
use med_phases_prep_ice_mod , only: med_phases_prep_ice
use med_phases_prep_lnd_mod , only: med_phases_prep_lnd
use med_phases_prep_wav_mod , only: med_phases_prep_wav_accum
use med_phases_prep_wav_mod , only: med_phases_prep_wav_avg
use med_phases_prep_glc_mod , only: med_phases_prep_glc
use med_phases_prep_rof_mod , only: med_phases_prep_rof
use med_phases_prep_ocn_mod , only: med_phases_prep_ocn_accum
use med_phases_prep_ocn_mod , only: med_phases_prep_ocn_avg
use med_phases_post_atm_mod , only: med_phases_post_atm
use med_phases_post_ice_mod , only: med_phases_post_ice
use med_phases_post_lnd_mod , only: med_phases_post_lnd
use med_phases_post_glc_mod , only: med_phases_post_glc
use med_phases_post_ocn_mod , only: med_phases_post_ocn
use med_phases_post_rof_mod , only: med_phases_post_rof
use med_phases_post_wav_mod , only: med_phases_post_wav
use med_phases_ocnalb_mod , only: med_phases_ocnalb_run
use med_phases_aofluxes_mod , only: med_phases_aofluxes_run
use med_diag_mod , only: med_phases_diag_accum, med_phases_diag_print
use med_diag_mod , only: med_phases_diag_atm
use med_diag_mod , only: med_phases_diag_lnd
use med_diag_mod , only: med_phases_diag_rof
use med_diag_mod , only: med_phases_diag_glc
use med_diag_mod , only: med_phases_diag_ocn
use med_diag_mod , only: med_phases_diag_ice_ice2med, med_phases_diag_ice_med2ice
use med_fraction_mod , only: med_fraction_init, med_fraction_set
use med_phases_profile_mod , only: med_phases_profile
#ifdef CDEPS_INLINE
use med_phases_cdeps_mod , only: med_phases_cdeps_run
#endif
! input/output variables
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
! local variables
character(len=*), parameter :: subname = '('//__FILE__//':SetServices)'
!-----------------------------------------------------------
rc = ESMF_SUCCESS
if (profile_memory) call ESMF_VMLogMemInfo("Entering "//trim(subname))
!------------------
! the NUOPC model component mediator_routine_SS will register the generic methods
!------------------
call NUOPC_CompDerive(gcomp, mediator_routine_SS, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! set entry point for methods that require specific implementation
! Provide InitializeP0 to switch from default IPDv00 to IPDv03
!------------------
call ESMF_GridCompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
InitializeP0, phase=0, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! IPDv03p1: advertise Fields
!------------------
! Mediator advertises its import and export Fields and sets the TransferOfferGeomObject Attribute.
! The TransferOfferGeomObject is a String value indicating a component's
! intention to transfer the underlying Grid or Mesh on which an advertised Field object is defined.
! The valid values are: [will provide, can provide, cannot provide]
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p1"/), userRoutine=AdvertiseFields, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! IPDv03p3: realize connected Fields with transfer action "provide"
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p3"/), userRoutine=RealizeFieldsWithTransferProvided, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! IPDv03p4: optionally modify the decomp/distr of transferred Grid/Mesh
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p4"/), userRoutine=ModifyDecompofMesh, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! IPDv03p5: realize all Fields with transfer action "accept"
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p5"/), userRoutine=RealizeFieldsWithTransferAccept, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! attach specializing method for DataInitialize
!------------------
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_DataInitialize, &
specRoutine=DataInitialize, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! setup mediator history phases for all output variables
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_history_write"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_history_write", specRoutine=med_phases_history_write, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! setup mediator restart phase
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_restart_write"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_restart_write", specRoutine=med_phases_restart_write, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_restart_write", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! setup mediator profile phase
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_profile"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_profile", specRoutine=med_phases_profile, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_profile", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! prep and post routines for atm
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_atm"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_atm", specRoutine=med_phases_prep_atm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_post_atm"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_post_atm", specRoutine=med_phases_post_atm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! prep and post routines for ocn
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_ocn_accum"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_ocn_accum", specRoutine=med_phases_prep_ocn_accum, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_prep_ocn_accum", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_ocn_avg"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_ocn_avg", specRoutine=med_phases_prep_ocn_avg, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_post_ocn"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_post_ocn", specRoutine=med_phases_post_ocn, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! prep and post routines for ice
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_ice"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_ice", specRoutine=med_phases_prep_ice, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! note that med_fraction_set is now called from post_ice
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_post_ice"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_post_ice", specRoutine=med_phases_post_ice, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! prep/post routines for lnd
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_lnd"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_lnd", specRoutine=med_phases_prep_lnd, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_post_lnd"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_post_lnd", specRoutine=med_phases_post_lnd, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! prep/post routines for rof
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_rof"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_rof", specRoutine=med_phases_prep_rof, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! post routine for rof (mapping to lnd, ocn, ice)
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_post_rof"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_post_rof", specRoutine=med_phases_post_rof, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! prep/post routines for wav
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_wav_accum"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_wav_accum", specRoutine=med_phases_prep_wav_accum, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_prep_wav_accum", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_wav_avg"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_wav_avg", specRoutine=med_phases_prep_wav_avg, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_post_wav"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_post_wav", specRoutine=med_phases_post_wav, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! prep/post routines for glc
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_glc"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_prep_glc", specRoutine=med_phases_prep_glc, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! post routine for glc (mapping to lnd, ocn, ice)
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_post_glc"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_post_glc", specRoutine=med_phases_post_glc, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! phase routine for ocean albedo computation
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_ocnalb_run"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_ocnalb_run", specRoutine=med_phases_ocnalb_run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! phase routine for ocn/atm flux computation
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_aofluxes_run"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_aofluxes_run", specRoutine=med_phases_aofluxes_run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! phase routine for updating fractions
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_fraction_set"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_fraction_set", specRoutine=med_fraction_set, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_fraction_set", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! phase routines for budget diagnostics
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_atm"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaselabel="med_phases_diag_atm", specRoutine=med_phases_diag_atm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_atm", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_lnd"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaselabel="med_phases_diag_lnd", specRoutine=med_phases_diag_lnd, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_lnd", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_rof"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaselabel="med_phases_diag_rof", specRoutine=med_phases_diag_rof, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_rof", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_ocn"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaselabel="med_phases_diag_ocn", specRoutine=med_phases_diag_ocn, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_ocn", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_glc"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaselabel="med_phases_diag_glc", specRoutine=med_phases_diag_glc, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_glc", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_ice_ice2med"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaselabel="med_phases_diag_ice_ice2med", specRoutine=med_phases_diag_ice_ice2med, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_ice_ice2med", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_ice_med2ice"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaselabel="med_phases_diag_ice_med2ice", specRoutine=med_phases_diag_ice_med2ice, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_ice_med2ice", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_accum"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaselabel="med_phases_diag_accum", specRoutine=med_phases_diag_accum, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_accum", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_diag_print"/), userRoutine=mediator_routine_Run, rc=rc)
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_diag_print", specRoutine=med_phases_diag_print, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_diag_print", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
#ifdef CDEPS_INLINE
!------------------
! phase routine for cdeps inline capability
!------------------
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_cdeps_run"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_cdeps_run", specRoutine=med_phases_cdeps_run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
#endif
!------------------
! attach specializing method(s)
! -> NUOPC specializes by default --->>> first need to remove the default
!------------------
call ESMF_MethodRemove(gcomp, mediator_label_CheckImport, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_CheckImport, specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! attach specializing method(s)
! -> NUOPC specializes by default --->>> first need to remove the default
!------------------
! This is called every time you enter a mediator phase
call ESMF_MethodRemove(gcomp, mediator_label_SetRunClock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_SetRunClock, specRoutine=SetRunClock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! attach specializing method(s)
! -> NUOPC specializes by default --->>> first need to remove the default
!------------------
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Finalize, &
specRoutine=med_finalize, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (profile_memory) call ESMF_VMLogMemInfo("Leaving "//trim(subname))
end subroutine SetServices
!-----------------------------------------------------------------------------
subroutine InitializeP0(gcomp, importState, exportState, clock, rc)
use ESMF , only : ESMF_GridComp, ESMF_State, ESMF_Clock, ESMF_VM, ESMF_SUCCESS
use ESMF , only : ESMF_GridCompGet, ESMF_VMGet, ESMF_AttributeGet, ESMF_AttributeSet
use ESMF , only : ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_METHOD_INITIALIZE
use NUOPC , only : NUOPC_CompFilterPhaseMap, NUOPC_CompAttributeGet
use med_internalstate_mod, only : maintask, logunit, diagunit
#ifdef CESMCOUPLED
use nuopc_shr_methods, only : set_component_logging
use shr_log_mod, only : shr_log_unit
#endif
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! local variables
type(ESMF_VM) :: vm
character(len=CL) :: cvalue
integer :: localPet
integer :: i
logical :: isPresent, isSet
character(len=CX) :: msgString
character(len=CX) :: diro
character(len=CX) :: logfile
character(len=CX) :: diagfile
character(len=*), parameter :: subname = '('//__FILE__//':InitializeP0)'
!-----------------------------------------------------------
rc = ESMF_SUCCESS
call ESMF_LogWrite(trim(subname)//": called", ESMF_LOGMSG_INFO)
if (profile_memory) call ESMF_VMLogMemInfo("Entering "//trim(subname))
call ESMF_GridCompGet(gcomp, vm=vm, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_VMGet(vm, localPet=localPet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
maintask = .false.
if (localPet == 0) maintask=.true.
! Determine mediator logunit
if (maintask) then
call NUOPC_CompAttributeGet(gcomp, name="diro", value=diro, isPresent=isPresent, isSet=isSet, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (.not. isPresent .and. .not. isSet) then
diro = './'
end if
call NUOPC_CompAttributeGet(gcomp, name="logfile", value=logfile, isPresent=isPresent, isSet=isSet, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (.not. isPresent .and. .not. isSet) then
logfile = 'mediator.log'
end if
#ifdef CESMCOUPLED
call set_component_logging(gcomp, maintask, logunit, shr_log_unit, rc)
#else
open(newunit=logunit,file=trim(diro)//"/"//trim(logfile))
#endif
call NUOPC_CompAttributeGet(gcomp, name="do_budgets", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
if (trim(cvalue) .eq. '.true.') then
i = index(logfile, '.log')
diagfile = "diags"//logfile(i:)
open(newunit=diagunit, file=trim(diro)//"/"//trim(diagfile))
endif
end if
else
logUnit = 6
endif
! Obtain verbosity level
call ESMF_AttributeGet(gcomp, name="Verbosity", value=cvalue, defaultValue="max", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (maintask) then
write(logunit,'(a)')trim(subname)//": Mediator verbosity is set to "//trim(cvalue)
end if
! Obtain profiling level
call NUOPC_CompAttributeGet(gcomp, name="Profiling", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
if (maintask) then
write(logunit,'(a)') trim(subname)//": Mediator profiling is set to "//trim(cvalue)
end if
end if
! Obtain dbug_flag setting if present; otherwise use default value in med_constants
call NUOPC_CompAttributeGet(gcomp, name='dbug_flag', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) dbug_flag
end if
write(msgString,'(A,i6)') trim(subname)//': Mediator dbug_flag is ',dbug_flag
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO)
! Switch to IPDv03 by filtering all other phaseMap entries
call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, acceptStringList=(/"IPDv03p"/), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (profile_memory) call ESMF_VMLogMemInfo("Leaving "//trim(subname))
call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)
end subroutine InitializeP0
!-----------------------------------------------------------------------
subroutine AdvertiseFields(gcomp, importState, exportState, clock, rc)
! Mediator advertises its import and export Fields and sets the
! TransferOfferGeomObject Attribute.
use ESMF , only : ESMF_GridComp, ESMF_State, ESMF_Clock, ESMF_SUCCESS, ESMF_LogFoundAllocError
use ESMF , only : ESMF_StateIsCreated
use ESMF , only : ESMF_LogMsg_Info, ESMF_LogWrite
use ESMF , only : ESMF_END_ABORT, ESMF_Finalize, ESMF_MAXSTR
use NUOPC , only : NUOPC_AddNamespace, NUOPC_Advertise, NUOPC_AddNestedState
use NUOPC , only : NUOPC_CompAttributeGet, NUOPC_CompAttributeSet, NUOPC_CompAttributeAdd
use esmFlds, only : med_fldlist_init1, med_fld_GetFldInfo, med_fldList_entry_type
use med_phases_history_mod, only : med_phases_history_init
use med_methods_mod , only : mediator_checkfornans
! input/output variables
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! local variables
character(len=CS) :: stdname, shortname
integer :: ncomp, ns
logical :: isPresent, isSet
character(len=CS) :: transferOffer
character(len=CS) :: cvalue
character(len=8) :: cnum
type(InternalState) :: is_local
type(med_fldlist_type), pointer :: fldListFr, fldListTo
type(med_fldList_entry_type), pointer :: fld
integer :: stat
character(len=*), parameter :: subname = '('//__FILE__//':AdvertiseFields)'
!-----------------------------------------------------------
call ESMF_LogWrite(trim(subname)//": called", ESMF_LOGMSG_INFO)
rc = ESMF_SUCCESS
if (profile_memory) call ESMF_VMLogMemInfo("Entering "//trim(subname))
!------------------
! Allocate memory for the internal state
!------------------
allocate(is_local%wrap, stat=stat)
if (ESMF_LogFoundAllocError(statusToCheck=stat, &
msg="Allocation of the internal state memory failed.", line=__LINE__, file=u_FILE_u)) then
return ! bail out
end if
call ESMF_GridCompSetInternalState(gcomp, is_local, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call med_internalstate_init(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! Allocate memory for history module variables
!------------------
call med_phases_history_init()
!------------------
! add a namespace (i.e. nested state) for each import and export component state in the mediator's InternalState
!------------------
! Namespaces are implemented via nested states. This creates a nested state inside of
! state. The nested state is returned as nestedState. nestedStateName will be used to name the
! newly created nested state.
call NUOPC_AddNamespace(importState, namespace="ATM", nestedStateName="AtmImp", &
nestedState=is_local%wrap%NStateImp(compatm), rc=rc)
call NUOPC_AddNamespace(exportState, namespace="ATM", nestedStateName="AtmExp", &
nestedState=is_local%wrap%NStateExp(compatm), rc=rc)
call NUOPC_AddNamespace(importState, namespace="OCN", nestedStateName="OcnImp", &
nestedState=is_local%wrap%NStateImp(compocn), rc=rc)
call NUOPC_AddNamespace(exportState, namespace="OCN", nestedStateName="OcnExp", &
nestedState=is_local%wrap%NStateExp(compocn), rc=rc)
call NUOPC_AddNamespace(importState, namespace="ICE", nestedStateName="IceImp", &
nestedState=is_local%wrap%NStateImp(compice), rc=rc)
call NUOPC_AddNamespace(exportState, namespace="ICE", nestedStateName="IceExp", &
nestedState=is_local%wrap%NStateExp(compice), rc=rc)
call NUOPC_AddNamespace(importState, namespace="LND", nestedStateName="LndImp", &
nestedState=is_local%wrap%NStateImp(complnd), rc=rc)
call NUOPC_AddNamespace(exportState, namespace="LND", nestedStateName="LndExp", &
nestedState=is_local%wrap%NStateExp(complnd), rc=rc)
call NUOPC_AddNamespace(importState, namespace="ROF", nestedStateName="RofImp", &
nestedState=is_local%wrap%NStateImp(comprof), rc=rc)
call NUOPC_AddNamespace(exportState, namespace="ROF", nestedStateName="RofExp", &
nestedState=is_local%wrap%NStateExp(comprof), rc=rc)
call NUOPC_AddNamespace(importState, namespace="WAV", nestedStateName="WavImp", &
nestedState=is_local%wrap%NStateImp(compwav), rc=rc)
call NUOPC_AddNamespace(exportState, namespace="WAV", nestedStateName="WavExp", &
nestedState=is_local%wrap%NStateExp(compwav), rc=rc)
! Only create nested states for active land-ice sheets
do ns = 1,is_local%wrap%num_icesheets
write(cnum,'(i0)') ns
call NUOPC_AddNestedState(importState, CplSet="GLC"//trim(cnum), &
nestedState=is_local%wrap%NStateImp(compglc(ns)), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_AddNestedState(exportState, CplSet="GLC"//trim(cnum), &
nestedState=is_local%wrap%NStateExp(compglc(ns)), rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end do
! Determine aoflux grid
call NUOPC_CompAttributeGet(gcomp, name='aoflux_grid', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (.not. isPresent .and. .not. isSet) then
cvalue = 'ogrid'
end if
is_local%wrap%aoflux_grid = trim(cvalue)
! Determine aoflux scheme that will be used to compute atmosphere-ocean fluxes [cesm|ccpp]
! TODO: If ccpp is not available it will be always run in cesm mode independent from aoflux_code option
call NUOPC_CompAttributeGet(gcomp, name='aoflux_code', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (.not. isPresent .and. .not. isSet) then
cvalue = 'cesm'
end if
aoflux_code = trim(cvalue)
if (maintask) then
write(logunit,*) '========================================================'
write(logunit,'(a)')trim(subname)//' Mediator aoflux scheme is '//trim(aoflux_code)
write(logunit,*) '========================================================'
end if
! Determine CCPP suite if aoflux scheme set to 'ccpp'
if (trim(aoflux_code) == 'ccpp') then
call NUOPC_CompAttributeGet(gcomp, name='aoflux_ccpp_suite', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (.not. isPresent .and. .not. isSet) then
call ESMF_LogWrite("aoflux_ccpp_suite need to be provided when aoflux_code is set to 'ccpp'", ESMF_LOGMSG_INFO)
call ESMF_Finalize(endflag=ESMF_END_ABORT)
end if
aoflux_ccpp_suite = trim(cvalue)
if (maintask) then
write(logunit,*) '========================================================'
write(logunit,'(a)')trim(subname)//' Mediator aoflux CCPP suite is '//trim(aoflux_ccpp_suite)
write(logunit,*) '========================================================'
end if
end if
!------------------
! Initialize mediator flds
!------------------
call NUOPC_CompAttributeGet(gcomp, name='coupling_mode', value=coupling_mode, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite('coupling_mode = '// trim(coupling_mode), ESMF_LOGMSG_INFO)
if (maintask) then
write(logunit,*) '========================================================'
write(logunit,'(a)')trim(subname)//' Mediator Coupling Mode is '//trim(coupling_mode)
write(logunit,*) '========================================================'
write(logunit,*)
end if
! Initialize memory for fldlistTo and fldlistFr - this is need for the calls below for the
! advertise phase
call med_fldlist_init1(ncomps)
if (trim(coupling_mode) == 'cesm') then
call esmFldsExchange_cesm(gcomp, phase='advertise', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else if (coupling_mode(1:3) == 'ufs') then
call esmFldsExchange_ufs(gcomp, phase='advertise', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else if (coupling_mode(1:4) == 'hafs') then
call esmFldsExchange_hafs(gcomp, phase='advertise', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else
call ESMF_LogWrite(trim(coupling_mode)//' is not a valid coupling_mode', ESMF_LOGMSG_INFO)
call ESMF_Finalize(endflag=ESMF_END_ABORT)
end if
! Set default masking for mapping
call med_internalstate_defaultmasks(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
!------------------
! Determine component present indices
!------------------
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldName", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
is_local%wrap%flds_scalar_name = trim(cvalue)
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldCount", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue, *) is_local%wrap%flds_scalar_num
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNX", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) is_local%wrap%flds_scalar_index_nx
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNY", value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) is_local%wrap%flds_scalar_index_ny
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxGridNTile", value=cvalue, &
isPresent=isPresent, isSet=isSet,rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) is_local%wrap%flds_scalar_index_ntile
else
is_local%wrap%flds_scalar_index_ntile = 0
end if
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxNextSwCday", value=cvalue, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) is_local%wrap%flds_scalar_index_nextsw_cday
else
is_local%wrap%flds_scalar_index_nextsw_cday = 0
end if
call NUOPC_CompAttributeGet(gcomp, name="ScalarFieldIdxPrecipFactor", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) is_local%wrap%flds_scalar_index_precip_factor
else
is_local%wrap%flds_scalar_index_precip_factor = 0
end if
!------------------
! Advertise import/export mediator field names
!------------------
do ncomp = 1,ncomps
if (ncomp /= compmed) then
if (maintask) write(logunit,*)
fldListFr => med_fldList_GetFldListFr(ncomp)
fld => fldListFr%fields
do while(associated(fld))
call med_fld_GetFldInfo(fld, stdname=stdname, shortname=shortname)
if (maintask) then
write(logunit,'(a)') trim(subname)//':Fr_'//trim(compname(ncomp))//': '//trim(shortname)
end if
if (trim(shortname) == is_local%wrap%flds_scalar_name) then
transferOffer = 'will provide'
else
transferOffer = 'cannot provide'
end if
call NUOPC_Advertise(is_local%wrap%NStateImp(ncomp), &
standardName=stdname, shortname=shortname, name=shortname, &
TransferOfferGeomObject=transferOffer, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite(subname//':Fr_'//trim(compname(ncomp))//': '//trim(shortname), ESMF_LOGMSG_INFO)
fld => fld%next
end do
fldListTo => med_fldList_GetFldListTo(ncomp)
fld => fldListTo%fields
do while(associated(fld))
call med_fld_GetFldInfo(fld, stdname=stdname, shortname=shortname, rc=rc)
if (maintask) then
write(logunit,'(a)') trim(subname)//':To_'//trim(compname(ncomp))//': '//trim(shortname)
end if
if (trim(shortname) == is_local%wrap%flds_scalar_name) then
transferOffer = 'will provide'
else
transferOffer = 'cannot provide'
end if
call NUOPC_Advertise(is_local%wrap%NStateExp(ncomp), &
standardName=stdname, shortname=shortname, name=shortname, &
TransferOfferGeomObject=transferOffer, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite(subname//':To_'//trim(compname(ncomp))//': '//trim(shortname), ESMF_LOGMSG_INFO)
fld => fld%next
end do
end if
end do ! end of ncomps loop
! Should mediator check for NaNs?
call NUOPC_CompAttributeGet(gcomp, name="check_for_nans", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if(isPresent .and. isSet) then
read(cvalue, *) mediator_checkfornans
else
mediator_checkfornans = .false.
endif
if(maintask) then
write(logunit,*) ' check_for_nans is ',mediator_checkfornans
if(mediator_checkfornans) then
write(logunit,*) ' Fields will be checked for NaN values when passed from mediator to component'
else
write(logunit,*) ' Fields will NOT be checked for NaN values when passed from mediator to component'
endif
endif
! Should target component use all data for first time step?
do ncomp = 1,ncomps
if (ncomp /= compmed) then
call NUOPC_CompAttributeGet(gcomp, name=trim(compname(ncomp))//"_use_data_first_import", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue, *) is_local%wrap%med_data_force_first(ncomp)
else
is_local%wrap%med_data_force_first(ncomp) = .false.
endif
if (maintask) then
write(logunit,*) trim(compname(ncomp))//'_use_data_first_import is ', is_local%wrap%med_data_force_first(ncomp)
endif
end if
end do
if (profile_memory) call ESMF_VMLogMemInfo("Leaving "//trim(subname))
call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)
end subroutine AdvertiseFields
!-----------------------------------------------------------------------------
subroutine RealizeFieldsWithTransferProvided(gcomp, importState, exportState, clock, rc)
! Realize connected Fields with transfer action "provide"
use ESMF , only : ESMF_GridComp, ESMF_State, ESMF_Clock, ESMF_VM, ESMF_SUCCESS
use ESMF , only : ESMF_LogWrite, ESMF_LOGMSG_INFO, ESMF_TimeInterval
use ESMF , only : ESMF_VMGet, ESMF_StateIsCreated, ESMF_GridCompGet
use ESMF , only : ESMF_StateSet, ESMF_StateIntent_Import, ESMF_StateIntent_Export
use ESMF , only : ESMF_StateIntent_Flag
! Input/output variables
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc