-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwmesmfmd.ftn
6715 lines (6498 loc) · 232 KB
/
wmesmfmd.ftn
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
#include "w3macros.h"
!/
!/ ------------------------------------------------------------------- /
!/ Macros for ESMF logging
!/
#define FILENAME "wmesmfmd.ftn"
#define CONTEXT line=__LINE__,file=FILENAME,method=METHOD
#define PASSTHRU msg=ESMF_LOGERR_PASSTHRU,CONTEXT
!/
!/ ------------------------------------------------------------------- /
!/ Define real kind for data passed through ESMF interface
!/
#if defined(ESMF_R8)
#define ESMF_KIND_RX ESMF_KIND_R8
#define ESMF_TYPEKIND_RX ESMF_TYPEKIND_R8
#else
#define ESMF_KIND_RX ESMF_KIND_R4
#define ESMF_TYPEKIND_RX ESMF_TYPEKIND_R4
#endif
!/
!/ ------------------------------------------------------------------- /
!/ Macro for enabling using W3OUTG to calculate export fields
!/
#define USE_W3OUTG_FOR_EXPORT___disabled
!/
!/ ------------------------------------------------------------------- /
!/ Macros for enabling test output
!/
#define TEST_WMESMFMD___disabled
#define TEST_WMESMFMD_GETIMPORT___disabled
#define TEST_WMESMFMD_SETEXPORT___disabled
#define TEST_WMESMFMD_CREATEIMPGRID___disabled
#define TEST_WMESMFMD_CREATEEXPGRID___disabled
#define TEST_WMESMFMD_SETUPIMPBMSK___disabled
#define TEST_WMESMFMD_CHARNK___disabled
#define TEST_WMESMFMD_ROUGHL___disabled
#define TEST_WMESMFMD_BOTCUR___disabled
#define TEST_WMESMFMD_RADSTR2D___disabled
#define TEST_WMESMFMD_STOKES3D___disabled
!/
!/ ------------------------------------------------------------------- /
module WMESMFMD
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | T. J. Campbell, NRL |
!/ | A. J. van der Westhuysen |
!/ | FORTRAN 90 |
!/ | Last update : 09-Aug-2017 |
!/ +-----------------------------------+
!/
!/ 20-Jan-2017 : Origination. ( version 6.02 )
!/ 09-Aug-2017 : Add ocean forcing export fields ( version 6.03 )
!/ 28-Feb-2018 : Modifications for unstruc meshes ( version 6.06 )
!/
!/ Copyright 2009-2014 National Weather Service (NWS),
!/ National Oceanic and Atmospheric Administration. All rights
!/ reserved. WAVEWATCH III is a trademark of the NWS.
!/ No unauthorized use without permission.
!/
! 1. Purpose :
!
! National Unified Prediction Capability (NUOPC) based
! Earth System Modeling Framework (ESMF) interface module for
! multi-grid wave model.
!
! 2. Variables and types :
!
! All module variables and types are scoped private by default.
! The private module variables and types are not listed in this section.
!
! Name Type Scope Description
! ----------------------------------------------------------------
! ----------------------------------------------------------------
!
! 3. Subroutines and functions :
!
! All module subroutines and functions are scoped private by default.
!
! Name Type Scope Description
! -----------------------------------------------------------------
! SetServices Subr. Public Wave model ESMF Set Services
! -----------------------------------------------------------------
! InitializeP0 Subr. Private NUOPC/ESMF Initialize phase 0
! InitializeP1 Subr. Private NUOPC/ESMF Initialize phase 1
! InitializeP3 Subr. Private NUOPC/ESMF Initialize phase 3
! Finalize Subr. Private NUOPC/ESMF Finalize
! DataInitialize Subr. Private NUOPC/ESMF Data Initialize
! ModelAdvance Subr. Private NUOPC/ESMF Model Advance
! GetImport Subr. Private Get fields from import state
! SetExport Subr. Private Set fields from export state
! CreateImpGrid Subr. Private Create ESMF grid for import
! CreateExpGrid Subr. Private Create ESMF grid for export
! CreateImpMesh Subr. Private Create ESMF mesh for import
! CreateExpMesh Subr. Private Create ESMF mesh for export
! SetupImpBmsk Subr. Private Setup background blending mask
! BlendImpField Subr. Private Blend import field with background
! FieldFill Subr. Private Fill ESMF field
! FieldGather Subr. Private Gather ESMF field
! FieldIndex Func. Private Return field index
! PrintTimers Subr. Private Print wallclock timers
! CalcDecomp Subr. Private Calculate a 2D processor layout
! GetEnvValue Subr. Private Get value of env. variable
! GetZlevels Subr. Private Get z-levels from file for SDC
! CalcCharnk Subr. Private Calculate Charnock for export
! CalcRoughl Subr. Private Calculate roughness length for export
! CalcBotcur Subr. Private Calculate wave-bottom currents for export
! CalcRadstr2D Subr. Private Calculate 2D radiation stresses for export
! CalcStokes3D Subr. Private Calculate 3D Stokes drift current for export
!JQI20210927
! CalcWaveheight Subr. Private Get significant wave height for export
! CalcWavelength Subr. Private Get average wave length for export
! CalcWavedir Subr. Private Get average wave direction for export
!JQI20210927
! ----------------------------------------------------------------
!
! 4. Subroutines and functions used :
!
! See subroutine documentation.
!
! 5. Remarks :
!
! 6. Switches :
!
! See subroutine documentation.
!
! !/MPI Switch for enabling Message Passing Interface API
! !/SHRD Switch for shared memory architecture
! !/DIST Switch for distributed memory architecture
! !/ST3 WAM 4+ input and dissipation.
! !/ST4 Ardhuin et al. (2009, 2010)
!
! 7. Source code :
!
!/ ------------------------------------------------------------------- /
!/
!/ Use associated modules
!/
! --- ESMF Module
use ESMF
! --- NUOPC modules
use NUOPC
use NUOPC_Model, parent_SetServices => SetServices
! --- WW3 modules
use CONSTANTS
use WMINITMD, only: WMINIT, WMINITNML
use WMWAVEMD, only: WMWAVE
use WMFINLMD, only: WMFINL
use WMMDATMD
use W3GDATMD
use W3IDATMD
use W3ODATMD
use W3WDATMD
use W3ADATMD
use W3TIMEMD
use WMUPDTMD, only: WMUPD2
use W3UPDTMD, only: W3UINI
!/ST3 use W3SRC3MD, only: W3SPR3
!/ST4 use W3SRC4MD, only: W3SPR4
use W3IOGOMD, only: W3OUTG
!/
!/ Specify default data typing
!/
implicit none
!/
!/ Include MPI definitions
!/
!/MPI include "mpif.h"
!/
!/ Specify default accessibility
!/
private
save
!/
!/ Public module methods
!/
public SetServices
!/
!/ Private module parameters
!/
! --- Default Mask Convention for import/export fields
INTEGER, PARAMETER :: DEFAULT_MASK_WATER = 0
INTEGER, PARAMETER :: DEFAULT_MASK_LAND = 1
! --- Miscellaneous
integer, parameter :: stdo = 6
type(ESMF_VM) :: vm
integer :: lpet, npet
integer :: verbosity
logical :: realizeAllExport = .false.
integer :: maskValueWater = DEFAULT_MASK_WATER
integer :: maskValueLand = DEFAULT_MASK_LAND
integer :: nz ! Number of z-levels for SDC
real(4), allocatable :: zl(:) ! Array of z-levels for SDC
character(256) :: zlfile = 'none' ! File containing z-levels for SDC
character(ESMF_MAXSTR) :: msg
real(ESMF_KIND_RX) :: zeroValue
real(ESMF_KIND_RX) :: missingValue
!
! --- Timing
integer, parameter :: numwt=8
character(32) :: wtnam(numwt)
integer :: wtcnt(numwt)
real(8) :: wtime(numwt)
!
! --- Import fields
type(ESMF_ArraySpec) :: impArraySpec2D
type(ESMF_StaggerLoc) :: impStaggerLoc
type(ESMF_Index_Flag) :: impIndexFlag
type(ESMF_Grid) :: impGrid
integer :: impGridID
logical :: impGridIsLocal
integer, parameter :: impHaloWidth = 3
integer :: impHaloLWidth(2)
integer :: impHaloUWidth(2)
type(ESMF_RouteHandle) :: impHaloRH
type(ESMF_Field) :: impMask
logical :: noActiveImpFields
integer :: numImpFields
character(6), allocatable :: impFieldName(:)
character(128), allocatable :: impFieldStdName(:)
logical, allocatable :: impFieldInitRqrd(:)
logical, allocatable :: impFieldActive(:)
type(ESMF_Field), allocatable :: impField(:)
!
! --- Background import fields
character(10), allocatable :: mbgFieldName(:)
character(128), allocatable :: mbgFieldStdName(:)
logical, allocatable :: mbgFieldActive(:)
type(ESMF_Field), allocatable :: mbgField(:)
type(ESMF_Field), allocatable :: bmskField(:)
!
! --- Unstructured import meshes
type(ESMF_Mesh) :: impMesh
! integer :: impMeshID
! logical :: impMeshIsLocal
!
! --- Export fields
type(ESMF_ArraySpec) :: expArraySpec2D
type(ESMF_ArraySpec) :: expArraySpec3D
type(ESMF_StaggerLoc) :: expStaggerLoc
type(ESMF_Index_Flag) :: expIndexFlag
type(ESMF_Grid) :: expGrid
integer :: expGridID = 1
logical :: expGridIsLocal
integer, parameter :: expHaloWidth = 3
integer :: expHaloLWidth(2)
integer :: expHaloUWidth(2)
type(ESMF_RouteHandle) :: expHaloRH
type(ESMF_Field) :: expMask
logical :: noActiveExpFields
integer :: numExpFields
character(6), allocatable :: expFieldName(:)
character(128), allocatable :: expFieldStdName(:)
integer, allocatable :: expFieldDim(:)
logical, allocatable :: expFieldActive(:)
type(ESMF_Field), allocatable :: expField(:)
!
! --- Unstructured export meshes
type(ESMF_Mesh) :: expMesh
integer :: expMeshID
logical :: expMeshIsLocal
!
! --- Native field stuff
type(ESMF_ArraySpec) :: natArraySpec1D
type(ESMF_ArraySpec) :: natArraySpec2D
type(ESMF_ArraySpec) :: natArraySpec3D
type(ESMF_StaggerLoc) :: natStaggerLoc
type(ESMF_Index_Flag) :: natIndexFlag
type(ESMF_Grid) :: natGrid
integer :: natGridID
logical :: natGridIsLocal
type(ESMF_RouteHandle):: n2eRH
!/
!/ ------------------------------------------------------------------- /
contains
!/ ------------------------------------------------------------------- /
#undef METHOD
#define METHOD "SetServices"
subroutine SetServices ( gcomp, rc )
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | T. J. Campbell, NRL |
!/ | FORTRAN 90 |
!/ | Last update : 20-Jan-2017 |
!/ +-----------------------------------+
!/
!/ 20-Jan-2017 : Origination. ( version 6.02 )
!/
! 1. Purpose :
!
! Wave model ESMF set services.
!
! 2. Method :
!
! 3. Parameters :
!
! Parameter list
! ----------------------------------------------------------------
! gcomp Type I/O Gridded component
! rc Int. O Return code
! ----------------------------------------------------------------
!
! 4. Subroutines used :
!
! Name Type Module Description
! ----------------------------------------------------------------
! InitializeP0 Subr. WMESMFMD Wave model NUOPC/ESMF Initialize phase 0
! InitializeP1 Subr. WMESMFMD Wave model NUOPC/ESMF Initialize phase 1
! InitializeP3 Subr. WMESMFMD Wave model NUOPC/ESMF Initialize phase 3
! Finalize Subr. WMESMFMD Wave model NUOPC/ESMF Finalize
! DataInitialize Subr. WMESMFMD Wave model NUOPC/ESMF Data Initialize
! ModelAdvance Subr. WMESMFMD Wave model NUOPC/ESMF Model Advance
! ----------------------------------------------------------------
!
! 5. Called by :
!
! 6. Error messages :
!
! 7. Remarks :
!
! 8. Structure :
!
! 9. Switches :
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!/
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
type(ESMF_GridComp) :: gcomp
integer,intent(out) :: rc
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
!NONE
!
! -------------------------------------------------------------------- /
! Prep
!
rc = ESMF_SUCCESS
! --- Initialize wallclock timers
wtnam( 1) = 'InitializeP0'
wtnam( 2) = 'InitializeP1'
wtnam( 3) = 'InitializeP3'
wtnam( 4) = 'DataInitialize'
wtnam( 5) = 'ModelAdvance'
wtnam( 6) = 'Finalize'
wtnam( 7) = 'GetImport'
wtnam( 8) = 'SetExport'
wtcnt( :) = 0
wtime( :) = 0d0
!
! -------------------------------------------------------------------- /
! 1. NUOPC model component will register the generic methods
!
call NUOPC_CompDerive(gcomp, parent_SetServices, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
!
! -------------------------------------------------------------------- /
! 2. Set model entry points
!
! --- Initialize - phase 0 (requires use of ESMF method)
call ESMF_GridCompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
userRoutine=InitializeP0, phase=0, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! --- Set entry points for initialize methods
! >= IPDv03 supports satisfying inter-model data dependencies and
! the transfer of ESMF Grid & Mesh objects between Model and/or
! Mediator components during initialization
! IPDv03p1: advertise import & export fields
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p1"/), userRoutine=InitializeP1, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! IPDv03p2: unspecified by NUOPC -- not required
! IPDv03p3: realize import & export fields
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv03p3"/), userRoutine=InitializeP3, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! IPDv03p4: relevant for TransferActionGeomObject=="accept"
! IPDv03p5: relevant for TransferActionGeomObject=="accept"
! IPDv03p6: check compatibility of fields connected status
! IPDv03p7: handle field data initialization
!
! -------------------------------------------------------------------- /
! 3. Register specializing methods
!
! --- Model initialize export data method
call NUOPC_CompSpecialize(gcomp, specLabel=label_DataInitialize, &
specRoutine=DataInitialize, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! --- Model checkImport method (overriding default)
call ESMF_MethodRemove(gcomp, label_CheckImport, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
call NUOPC_CompSpecialize(gcomp, specLabel=label_CheckImport, &
specRoutine=NUOPC_NoOp, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! --- Model advance method
call NUOPC_CompSpecialize(gcomp, specLabel=label_Advance, &
specRoutine=ModelAdvance, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! --- Model finalize method
call NUOPC_CompSpecialize(gcomp, specLabel=label_Finalize, &
specRoutine=Finalize, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
!
! -------------------------------------------------------------------- /
! Post
!
rc = ESMF_SUCCESS
!/
!/ End of SetServices ------------------------------------------------ /
!/
end subroutine SetServices
!/ ------------------------------------------------------------------- /
#undef METHOD
#define METHOD "InitializeP0"
subroutine InitializeP0 ( gcomp, impState, expState, extClock, rc )
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | T. J. Campbell, NRL |
!/ | FORTRAN 90 |
!/ | Last update : 20-Jan-2017 |
!/ +-----------------------------------+
!/
!/ 20-Jan-2017 : Origination. ( version 6.02 )
!/
! 1. Purpose :
!
! Initialize wave model (phase 0)
! * Define the NUOPC Initialize Phase Mapping
!
! 2. Method :
!
! 3. Parameters :
!
! Parameter list
! ----------------------------------------------------------------
! gcomp Type I/O Gridded component
! impState Type I/O Import state
! expState Type I/O Export state
! extClock Type I External clock
! rc Int. O Return code
! ----------------------------------------------------------------
!
! 4. Subroutines used :
!
! Name Type Module Description
! ----------------------------------------------------------------
! NONE
! ----------------------------------------------------------------
!
! 5. Called by :
!
! 6. Error messages :
!
! 7. Remarks :
!
! 8. Structure :
!
! 9. Switches :
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!/
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: impState
type(ESMF_State) :: expState
type(ESMF_Clock) :: extClock
integer,intent(out) :: rc
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
character(ESMF_MAXSTR) :: cname
character(ESMF_MAXSTR) :: valueString
integer, parameter :: iwt=1
real(8) :: wstime, wftime
!
! -------------------------------------------------------------------- /
! Prep
!
rc = ESMF_SUCCESS
call ESMF_VMWtime(wstime)
call ESMF_GridCompGet(gcomp, name=cname, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
!
! -------------------------------------------------------------------- /
! Determine verbosity
!
call NUOPC_CompAttributeGet(gcomp, name='Verbosity', &
value=valueString, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
verbosity = ESMF_UtilString2Int( valueString, &
specialStringList=(/'high','max '/), &
specialValueList=(/ 255, 255/), rc=rc )
if (ESMF_LogFoundError(rc, PASSTHRU)) return
if (verbosity.gt.0) call ESMF_LogWrite(trim(cname)// &
': entered InitializeP0', ESMF_LOGMSG_INFO)
!
! -------------------------------------------------------------------- /
! Define initialization phases
! * switch to IPDv03 by filtering all other phaseMap entries
!
call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, &
acceptStringList=(/"IPDv03p"/), rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
!
! -------------------------------------------------------------------- /
! Post
!
rc = ESMF_SUCCESS
call ESMF_VMWtime(wftime)
wtime(iwt) = wtime(iwt) + wftime - wstime
wtcnt(iwt) = wtcnt(iwt) + 1
if (verbosity.gt.0) call ESMF_LogWrite(trim(cname)// &
': leaving InitializeP0', ESMF_LOGMSG_INFO)
!/
!/ End of InitializeP0 ----------------------------------------------- /
!/
end subroutine InitializeP0
!/ ------------------------------------------------------------------- /
#undef METHOD
#define METHOD "InitializeP1"
subroutine InitializeP1 ( gcomp, impState, expState, extClock, rc )
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | T. J. Campbell, NRL |
!/ | FORTRAN 90 |
!/ | Last update : 09-Aug-2017 |
!/ +-----------------------------------+
!/
!/ 20-Jan-2017 : Origination. ( version 6.02 )
!/ 09-Aug-2017 : Add ocean forcing export fields ( version 6.03 )
!/
! 1. Purpose :
!
! Initialize wave model (phase 1)
! * Advertise fields in import and export states.
!
! 2. Method :
!
! 3. Parameters :
!
! Parameter list
! ----------------------------------------------------------------
! gcomp Type I/O Gridded component
! impState Type I/O Import state
! expState Type I/O Export state
! extClock Type I External clock
! rc Int. O Return code
! ----------------------------------------------------------------
!
! 4. Subroutines used :
!
! Name Type Module Description
! ----------------------------------------------------------------
! WMINIT Subr. WMINITMD Wave model initialization
! WMINITNML Subr. WMINITMD Wave model initialization
! ----------------------------------------------------------------
!
! 5. Called by :
!
! 6. Error messages :
!
! 7. Remarks :
!
! 8. Structure :
!
! ----------------------------------------------------------------
! 1. Initialization necessary for driver
! a General I/O: (implicit in WMMDATMD)
! b MPI environment
! c Identifying output to "screen" unit
! 2. Initialization of all wave models / grids
! 3. Advertise import fields
! 4. Advertise export fields
! ----------------------------------------------------------------
!
! 9. Switches :
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!/
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: impState
type(ESMF_State) :: expState
type(ESMF_Clock) :: extClock
integer,intent(out) :: rc
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
character(ESMF_MAXSTR) :: cname
integer, parameter :: iwt=2
real(8) :: wstime, wftime
integer :: idsi, idso, idss, idst, idse
integer :: mpiComm = -99
logical :: configIsPresent
type(ESMF_Config) :: config
character(ESMF_MAXSTR) :: wrkdir = '.'
character(ESMF_MAXSTR) :: preamb = '.'
character(ESMF_MAXSTR) :: ifname = 'ww3_multi.inp'
logical :: lsep_ss = .false.
logical :: lsep_st = .false.
logical :: lsep_se = .false.
character(ESMF_MAXSTR) :: attstr
integer(ESMF_KIND_I4) :: yy,mm,dd,h,m,s
type(ESMF_Time) :: ttmp
type(ESMF_TimeInterval) :: tstep, etstep
integer :: i, j, n, istep, imod, jmod
integer, allocatable :: cplmap(:,:)
logical :: includeObg, includeAbg, includeIbg
!
! -------------------------------------------------------------------- /
! Prep
!
rc = ESMF_SUCCESS
call ESMF_VMWtime(wstime)
call ESMF_GridCompGet(gcomp, name=cname, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
if (verbosity.gt.0) call ESMF_LogWrite(trim(cname)// &
': entered InitializeP1', ESMF_LOGMSG_INFO)
!
! -------------------------------------------------------------------- /
! 1. Initialization necessary for driver
!
! 1.a Set global flag indicating that model is an ESMF Component
!
is_esmf_component = .true.
zeroValue = real(0,ESMF_KIND_RX)
missingValue = real(0,ESMF_KIND_RX)
!
!
! 1.b Get MPI environment from ESMF VM and set WW3 MPI related variables
!
call ESMF_GridCompGet(gcomp, vm=vm, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
call ESMF_VMGet(vm, petCount=npet, localPet=lpet, &
mpiCommunicator=mpiComm, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
nmproc = npet
improc = lpet + 1
nmpscr = 1
if ( improc .eq. nmpscr ) write (*,900)
!
! 1.c Get background model info
!
#if defined(COAMPS)
call ESMF_AttributeGet(gcomp, name="OcnBackground", &
value=attstr, defaultValue="none", &
convention="COAMPS", purpose="General", rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
includeObg = trim(attstr).eq."model"
call ESMF_AttributeGet(gcomp, name="AtmBackground", &
value=attstr, defaultValue="none", &
convention="COAMPS", purpose="General", rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
includeAbg = trim(attstr).eq."model"
call ESMF_AttributeGet(gcomp, name="IceBackground", &
value=attstr, defaultValue="none", &
convention="COAMPS", purpose="General", rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
includeIbg = trim(attstr).eq."model"
call ESMF_AttributeGet(gcomp, name="MissingValue", &
value=missingValue, defaultValue=real(0,ESMF_KIND_RX), &
convention="COAMPS", purpose="General", rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
#else
includeObg = .false.
includeAbg = .false.
includeIbg = .false.
#endif
!
! 1.d Config input
!
call ESMF_GridCompGet(gcomp, configIsPresent=configIsPresent, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
if (configIsPresent) then
call ESMF_GridCompGet(gcomp, config=config, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! working directory
call ESMF_ConfigGetAttribute(config, wrkdir, &
label=trim(cname)//'_work_dir:', default='.', rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! I/O options
call ESMF_ConfigGetAttribute(config, ifname, &
label=trim(cname)//'_input_file_name:', &
default='ww3_multi.inp', rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
call ESMF_ConfigGetAttribute(config, lsep_ss, &
label=trim(cname)//'_stdo_output_to_file:', default=.false., rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
call ESMF_ConfigGetAttribute(config, lsep_st, &
label=trim(cname)//'_test_output_to_file:', default=.false., rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
call ESMF_ConfigGetAttribute(config, lsep_se, &
label=trim(cname)//'_error_output_to_file:', default=.false., rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! export grid id
call ESMF_ConfigGetAttribute(config, expGridID, &
label=trim(cname)//'_export_grid_id:', default=1, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! realize all export flag
call ESMF_ConfigGetAttribute(config, realizeAllExport, &
label=trim(cname)//'_realize_all_export:', default=.false., rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! grid mask convention
call ESMF_ConfigGetAttribute(config, maskValueWater, &
label='mask_value_water:', default=DEFAULT_MASK_WATER, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
call ESMF_ConfigGetAttribute(config, maskValueLand, &
label='mask_value_land:', default=DEFAULT_MASK_LAND, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
! z-level file
call ESMF_ConfigGetAttribute(config, zlfile, &
label=trim(cname)//'_zlevel_exp_file:', default='none', rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
endif
! preamb = trim(wrkdir)//'/'
preamb = trim(preamb)//'/' !TODO: have separate paths for .inp, logs and data?
!
! 1.e Set internal start/stop time from external start/stop time
!
call ESMF_ClockGet(extClock, startTime=ttmp, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
call ESMF_TimeGet(ttmp, yy=yy,mm=mm,dd=dd,h=h,m=m,s=s, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
stime(1) = 10000*yy + 100*mm + dd
stime(2) = 10000*h + 100*m + s
call ESMF_ClockGet(extClock, stopTime=ttmp, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
call ESMF_TimeGet(ttmp, yy=yy,mm=mm,dd=dd,h=h,m=m,s=s, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
etime(1) = 10000*yy + 100*mm + dd
etime(2) = 10000*h + 100*m + s
!
! 1.f Identify available unit numbers
! Each ESMF_UtilIOUnitGet is followed by an OPEN statement for that
! unit so that subsequent ESMF_UtilIOUnitGet calls do not return the
! the same unit. After getting all the available unit numbers, close
! the units since they will be opened within WMINIT.
!
call ESMF_UtilIOUnitGet(idsi); open(unit=idsi, status='scratch');
call ESMF_UtilIOUnitGet(idso); open(unit=idso, status='scratch');
call ESMF_UtilIOUnitGet(idss); open(unit=idss, status='scratch');
call ESMF_UtilIOUnitGet(idst); open(unit=idst, status='scratch');
call ESMF_UtilIOUnitGet(idse); open(unit=idse, status='scratch');
close(idsi); close(idso); close(idss); close(idst); close(idse);
!
! -------------------------------------------------------------------- /
! 2. Initialization of all wave models / grids
!
! 2.a Call into WMINIT
!
if ( .not.lsep_ss ) idss = stdo
if ( .not.lsep_st ) idst = stdo
if ( .not.lsep_se ) idse = stdo
if ( trim(ifname).eq.'ww3_multi.nml' ) then
call wminitnml ( idsi, idso, idss, idst, idse, trim(ifname), &
mpicomm, preamb=preamb )
else
call wminit ( idsi, idso, idss, idst, idse, trim(ifname), &
mpicomm, preamb=preamb )
endif
!
! 2.b Check consistency between internal timestep and external
! timestep (coupling interval)
!
call ESMF_ClockGet(extClock, timeStep=etstep, rc=rc)
if (ESMF_LogFoundError(rc, PASSTHRU)) return
!
! 2.c Trap unsupported CPL input forcing settings
!
if ( any(inpmap.lt.0) ) then
if ( nrgrd.gt.1 ) then
if ( any(inpmap.eq.-999) ) then
write (msg,'(a)') 'CPL input forcing defined on a '// &
'native grid is not supported with multiple model grids'
if ( improc .eq. nmpscr ) write (idse,'(a)') trim(msg)
call ESMF_LogWrite(trim(msg), ESMF_LOGMSG_ERROR)
rc = ESMF_FAILURE
return
endif
endif
allocate (cplmap(nrgrd,jfirst:8), stat=rc)
if (ESMF_LogFoundAllocError(rc, PASSTHRU)) return
jmod = minval(inpmap)
cplmap = inpmap
where ( inpmap.lt.0 ) cplmap = jmod
if ( any(inpmap.ne.cplmap) ) then
write (msg,'(a)') 'All CPL input forcing must be '// &
'defined on the same grid'
if ( improc .eq. nmpscr ) write (idse,'(a)') trim(msg)
call ESMF_LogWrite(trim(msg), ESMF_LOGMSG_ERROR)
rc = ESMF_FAILURE
return
endif
deallocate (cplmap, stat=rc)
if (ESMF_LogFoundDeallocError(rc, PASSTHRU)) return
endif
!
! -------------------------------------------------------------------- /
! 3. Initialize import field list
!
istep_import: do istep = 1, 2
if ( istep.eq.2 ) then
allocate ( impFieldName(numImpFields), &
impFieldStdName(numImpFields), &
impFieldInitRqrd(numImpFields), &
impFieldActive(numImpFields), &
impField(numImpFields), &
stat=rc )
if (ESMF_LogFoundAllocError(rc, PASSTHRU)) return
allocate ( mbgFieldName(numImpFields), &
mbgFieldStdName(numImpFields), &
mbgFieldActive(numImpFields), &
mbgField(numImpFields), &
bmskField(numImpFields), &
stat=rc )
if (ESMF_LogFoundAllocError(rc, PASSTHRU)) return
impFieldActive(:) = .false.
endif
i = 0
i = i + 1
if ( istep.eq.2 ) then
j = 1
impFieldActive(i) = any(inpmap(:,j).lt.0)
impFieldName(i) = 'seahgt'
impFieldStdName(i) = 'sea_surface_height_above_sea_level'
impFieldInitRqrd(i) = .true.
mbgFieldActive(i) = impFieldActive(i).and.includeObg
endif
i = i + 1
if ( istep.eq.2 ) then
j = 2
impFieldActive(i) = any(inpmap(:,j).lt.0)
impFieldName(i) = 'uucurr'
impFieldStdName(i) = 'surface_eastward_sea_water_velocity'
impFieldInitRqrd(i) = .true.
mbgFieldActive(i) = impFieldActive(i).and.includeObg
endif
i = i + 1
if ( istep.eq.2 ) then
j = 2
impFieldActive(i) = any(inpmap(:,j).lt.0)
impFieldName(i) = 'vvcurr'
impFieldStdName(i) = 'surface_northward_sea_water_velocity'
impFieldInitRqrd(i) = .true.
mbgFieldActive(i) = impFieldActive(i).and.includeObg
endif
i = i + 1
if ( istep.eq.2 ) then
j = 3
impFieldActive(i) = any(inpmap(:,j).lt.0)
impFieldName(i) = 'uutrue'
impFieldStdName(i) = 'eastward_wind_at_10m_height'
impFieldInitRqrd(i) = .true.
mbgFieldActive(i) = impFieldActive(i).and.includeAbg
endif
i = i + 1
if ( istep.eq.2 ) then
j = 3
impFieldActive(i) = any(inpmap(:,j).lt.0)
impFieldName(i) = 'vvtrue'
impFieldStdName(i) = 'northward_wind_at_10m_height'
impFieldInitRqrd(i) = .true.
mbgFieldActive(i) = impFieldActive(i).and.includeAbg
endif
i = i + 1
if ( istep.eq.2 ) then
j = 4
impFieldActive(i) = any(inpmap(:,j).lt.0)
impFieldName(i) = 'seaice'
impFieldStdName(i) = 'sea_ice_concentration'
impFieldInitRqrd(i) = .true.
mbgFieldActive(i) = impFieldActive(i).and.includeIbg
endif
numImpFields = i
enddo istep_import
noActiveImpFields = all(.not.impFieldActive)
do i = 1,numImpFields
mbgFieldName(i) = 'mbg_'//trim(impFieldName(i))
mbgFieldStdName(i) = 'mbg_'//trim(impFieldStdName(i))
enddo
!
! -------------------------------------------------------------------- /
! 4. Initialize export field list
!
istep_export: do istep = 1, 2
if ( istep.eq.2 ) then
allocate ( expFieldName(numExpFields), &
expFieldStdName(numExpFields), &
expFieldDim(numExpFields), &
expFieldActive(numExpFields), &
expField(numExpFields), &
stat=rc )
if (ESMF_LogFoundAllocError(rc, PASSTHRU)) return
expFieldActive(:) = .false.
endif
i = 0
i = i + 1
if ( istep.eq.2 ) then
expFieldName(i) = 'charno'
expFieldStdName(i) = 'wave_induced_charnock_parameter'
expFieldDim(i) = 2
endif
i = i + 1
if ( istep.eq.2 ) then
expFieldName(i) = 'z0rlen'
expFieldStdName(i) = 'wave_z0_roughness_length'
expFieldDim(i) = 2
endif
i = i + 1
if ( istep.eq.2 ) then
expFieldName(i) = 'uscurr'
expFieldStdName(i) = 'eastward_stokes_drift_current'
expFieldDim(i) = 3
endif
i = i + 1
if ( istep.eq.2 ) then
expFieldName(i) = 'vscurr'
expFieldStdName(i) = 'northward_stokes_drift_current'
expFieldDim(i) = 3
endif
i = i + 1
if ( istep.eq.2 ) then
expFieldName(i) = 'wbcuru'
expFieldStdName(i) = 'eastward_wave_bottom_current'
expFieldDim(i) = 2
endif
i = i + 1
if ( istep.eq.2 ) then
expFieldName(i) = 'wbcurv'
expFieldStdName(i) = 'northward_wave_bottom_current'
expFieldDim(i) = 2
endif
i = i + 1
if ( istep.eq.2 ) then
expFieldName(i) = 'wbcurp'
expFieldStdName(i) = 'wave_bottom_current_period'
expFieldDim(i) = 2
endif
i = i + 1
if ( istep.eq.2 ) then
expFieldName(i) = 'wavsuu'
expFieldStdName(i) = 'eastward_wave_radiation_stress'
expFieldDim(i) = 2
endif