-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw3wavemd.F90
3759 lines (3665 loc) · 122 KB
/
w3wavemd.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!> @file
!> @brief Contains MODULE W3WAVEMD.
!>
!> @author H. L. Tolman @date 22-Mar-2021
!>
#include "w3macros.h"
!/ ------------------------------------------------------------------- /
!>
!> @brief Contains wave model subroutine, w3wave.
!>
!> @author H. L. Tolman @date 22-Mar-2021
!>
MODULE W3WAVEMD
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | H. L. Tolman |
!/ | FORTRAN 90 |
!/ | Last update : 13-Sep-2022 |
!/ +-----------------------------------+
!/
!/ 04-Feb-2000 : Origination. ( version 2.00 )
!/ For upgrades see subroutines.
!/ 14-Feb-2000 : Exact-NL added. ( version 2.01 )
!/ 05-Jan-2001 : Bug fix to allow model to run ( version 2.05 )
!/ without output.
!/ 24-Jan-2001 : Flat grid version. ( version 2.06 )
!/ 09-Feb-2001 : Third propagation scheme added. ( version 2.08 )
!/ 23-Feb-2001 : Check for barrier after source
!/ terms added ( W3NMIN ). ( delayed version 2.07 )
!/ 16-Mar-2001 : Fourth propagation scheme added. ( version 2.09 )
!/ 30-Mar-2001 : Sub-grid obstacles added. ( version 2.10 )
!/ 23-May-2001 : Clean up and bug fixes. ( version 2.11 )
!/ 10-Dec-2001 : Sub-grid obstacles for UQ schemes. ( version 2.14 )
!/ 11-Jan-2002 : Sub-grid ice. ( version 2.15 )
!/ 24-Jan-2002 : Zero time step dor data ass. ( version 2.17 )
!/ 18-Feb-2002 : Point output diagnostics added. ( version 2.18 )
!/ 30-Apr-2002 : Add field output types 17-18. ( version 2.20 )
!/ 09-May-2002 : Switch clean up. ( version 2.21 )
!/ 13-Nov-2002 : Add stress vector. ( version 3.00 )
!/ 26-Dec-2002 : Moving grid version. ( version 3.02 )
!/ 01-Aug-2003 : Moving grid GSE correction. ( version 3.03 )
!/ 20-Aug-2003 : Output server options added. ( version 3.04 )
!/ 07-Oct-2003 : Output options for NN training. ( version 3.05 )
!/ 29-Dec-2004 : Multiple grid version. ( version 3.06 )
!/ W3INIT, W3MPII-O and WWVER moved to w3initmd.ftn
!/ 04-Feb-2005 : Add STAMP to par list of W3WAVE. ( version 3.07 )
!/ 04-May-2005 : Change to MPI_COMM_WAVE. ( version 3.07 )
!/ 28-Jun-2005 : Adding map recalc for W3ULEV call. ( version 3.07 )
!/ 07-Sep-2005 : Updated boundary conditions. ( version 3.08 )
!/ Fix NRQSG1/2 = 0 array bound issue.
!/ 13-Jun-2006 : Split STORE in G/SSTORE ( version 3.09 )
!/ 26-Jun-2006 : Add output type 6. ( version 3.09 )
!/ 04-Jul-2006 : Consolidate stress arrays. ( version 3.09 )
!/ 18-Oct-2006 : Partitioned spectral data output. ( version 3.10 )
!/ 02-Feb-2007 : Add FLAGST test. ( version 3.10 )
!/ 02-Apr-2007 : Add partitioned field data. ( version 3.11 )
!/ 07-May-2007 : Bug fix SKIP_O treatment. ( version 3.11 )
!/ 17-May-2007 : Adding NTPROC/NAPROC separation. ( version 3.11 )
!/ 08-Oct-2007 : Adding AS CX-Y to W3SRCE par. list. ( version 3.13 )
!/ 22-Feb-2008 : Initialize VGX-Y properly. ( version 3.13 )
!/ 10-Apr-2008 : Bug fix writing log file (MPI). ( version 3.13 )
!/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
!/ 30-Oct-2009 : Implement run-time grid selection. ( version 3.14 )
!/ (W. E. Rogers & T. J. Campbell, NRL)
!/ 30-Oct-2009 : Implement curvilinear grid type. ( version 3.14 )
!/ (W. E. Rogers & T. J. Campbell, NRL)
!/ 29-Mar-2010 : Adding coupling, ice in W3SRCE. ( version 3.14_SHOM )
!/ 16-May-2010 : Adding transparencies in W3SCRE ( version 3.14_SHOM )
!/ 23-Jun-2011 : Movable bed bottom friction BT4 ( version 4.04 )
!/ 03-Nov-2011 : Shoreline reflection on unst. grids ( version 4.04 )
!/ 02-Jul-2011 : Update for PALM coupling ( version 4.07 )
!/ 06-Mar-2012 : Initializing ITEST as needed. ( version 4.07 )
!/ 02-Jul-2012 : Update for PALM coupling ( version 4.07 )
!/ 02-Sep-2012 : Clean up of open BC for UG grids ( version 4.08 )
!/ 03-Sep-2012 : Fix format 902. ( version 4.10 )
!/ 07-Dec-2012 : Wrap W3SRCE with TMPn to limit WARN ( version 4.OF )
!/ 10-Dec-2012 : Modify field output MPI for new ( version 4.OF )
!/ structure and smaller memory footprint.
!/ 12-Dec-2012 : Adding SMC grid. JG_Li ( version 4.08 )
!/ 26-Dec-2012 : Move FIELD init. to W3GATH. ( version 4.OF )
!/ 16-Sep-2013 : Add Arctic part for SMC grid. ( version 4.11 )
!/ 11-Nov-2013 : SMC and rotated grid incorporated in the main
!/ trunk ( version 4.13 )
!/ 14-Nov-2013 : Remove orphaned work arrays. ( version 4.13 )
!/ 27-Nov-2013 : Fixes for OpenMP versions. ( version 4.15 )
!/ 23-May-2014 : Adding ice fluxes to W3SRCE ( version 5.01 )
!/ 27-May-2014 : Move to OMPG/X switch. ( version 5.02 )
!/ 24-Apr-2015 : Adding OASIS coupling calls ( version 5.07 )
!/ (M. Accensi & F. Ardhuin, IFREMER)
!/ 27-Aug-2015 : Update for ICEH, ICEF ( version 5.08 )
!/ 14-Sep-2018 : Remove PALM implementation ( version 6.06 )
!/ 15-Sep-2020 : Bugfix FIELD allocation. Remove ( version 7.11 )
!/ defunct OMPX switches.
!/ 22-Mar-2021 : Update TAUA, RHOA ( version 7.13 )
!/ 06-May-2021 : Use ARCTC and SMCTYPE options. JGLi ( version 7.13 )
!/ 19-Jul-2021 : Momentum and air density support ( version 7.14 )
!/ 11-Nov-2021 : Remove XYB since it is obsolete ( version 7.xx )
!/ 13-Sep-2022 : Add OMP for W3NMIN loops. Hide
!/ W3NMIN in W3_DEBUGRUN for scaling. ( version 7.xx )
!/
!/ 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 :
!
! 2. Variables and types :
!
! 3. Subroutines and functions :
!
! Name Type Scope Description
! ----------------------------------------------------------------
! W3WAVE Subr. Public Actual wave model.
! W3GATH Subr. Public Data transpose before propagation.
! W3SCAT Subr. Public Data transpose after propagation.
! W3NMIN Subr. Public Calculate minimum number of sea
! points per processor.
! ----------------------------------------------------------------
!
! 4. Subroutines and functions used :
!
! Name Type Module Description
! ----------------------------------------------------------------
! W3SETx Subr. W3xDATMD Point to data structure.
!
! W3UCUR Subr. W3UPDTMD Interpolate current fields in time.
! W3UWND Subr. W3UPDTMD Interpolate wind fields in time.
! W3UINI Subr. W3UPDTMD Update initial conditions if init.
! with initial wind conditions.
! W3UBPT Subr. W3UPDTMD Update boundary points.
! W3UICE Subr. W3UPDTMD Update ice coverage.
! W3ULEV Subr. W3UPDTMD Transform the wavenumber grid.
! W3DDXY Subr. W3UPDTMD Calculate dirivatives of the depth.
! W3DCXY Subr. W3UPDTMD Calculate dirivatives of the current.
!
! W3MAPn Subr. W3PROnMD Preparation for ropagation schemes.
! W3XYPn Subr. W3PROnMD Longitude-latitude ("XY") propagation.
! W3KTPn Subr. W3PROnMD Intra-spectral ("k-theta") propagation.
!
! W3SRCE Subr. W3SRCEMD Source term integration and calculation.
!
! W3IOGR Subr. W3IOGRMD Reading/writing model definition file.
! W3OUTG Subr. W3IOGOMD Generate gridded output fields.
! W3IOGO Subr. W3IOGOMD Read/write gridded output.
! W3IOPE Subr. W3IOPOMD Extract point output.
! W3IOPO Subr. W3IOPOMD Read/write point output.
! W3IOTR Subr. W3IOTRMD Process spectral output along tracks.
! W3IORS Subr. W3IORSMD Read/write restart files.
! W3IOBC Subr. W3IOBCMD Read/write boundary conditions.
! W3CPRT Subr. W3IOSFMD Partition spectra.
! W3IOSF Subr. Id. Write partitioned spectral data.
!
! STRACE Subr. W3SERVMD Subroutine tracing.
! WWTIME Subr. Id. System time in readable format.
! EXTCDE Subr. Id. Program abort.
!
! TICK21 Subr. W3TIMEMD Advance the clock.
! DSEC21 Func. Id. Difference between times.
! STME21 Subr. Id. Time in readable format.
!
! MPI_BARRIER, MPI_STARTALL, MPI_WAITALL
! Subr. Basic MPI routines.
! ----------------------------------------------------------------
!
! 5. Remarks : Call to W3NMIN hidden behind W3_DEBUGRUN. This call
! currently only serves to warn when one or more procs
! have no active seapoints. It has been hid as this
! dramatically increases runtime performance.
!
! 6. Switches :
!
! !/SHRD Switch for shared / distributed memory architecture.
! !/DIST Id.
! !/MPI Id.
! !/OMPG Id.
!
! !/PR1 First order propagation schemes.
! !/PR2 ULTIMATE QUICKEST scheme.
! !/PR3 Averaged ULTIMATE QUICKEST scheme.
! !/SMC UNO2 scheme on SMC grid.
!
! !/S Enable subroutine tracing.
! !/T Test output.
! !/MPIT Test output for MPI specific code.
!
! 7. Source code :
!
!/ ------------------------------------------------------------------- /
use w3servmd, only : print_memcheck
#ifdef W3_MPI
USE W3ADATMD, ONLY: MPIBUF
#endif
!module default
implicit none
!
PUBLIC
!/
CONTAINS
!/ ------------------------------------------------------------------- /
!>
!> @brief Run WAVEWATCH III for a given time interval.
!>
!> @details Currents are updated before winds as currents are used in wind
!> and USTAR processing.
!>
!> Ice and water levels can be updated only once per call.
!>
!> If ice or water level time are undefined, the update
!> takes place asap, otherwise around the "half-way point"
!> between the old and new times.
!>
!> To increase accuracy, the calculation of the intra-spectral
!> propagation is performed in two parts around the spatial propagation.
!>
!> @param[in] IMOD Model number.
!> @param[in] TEND Ending time of integration.
!> @param[in] STAMP Write time stamp (optional, defaults to T).
!> @param[in] NO_OUT Skip output (optional, defaults to F).
!> @param[in] ODAT
!> @param[in] ID_LCOMM Present only when using W3_OASIS.
!> @param[in] TIMEN Present only when using W3_OASIS.
!>
!> @author H. L. Tolman @date 22-Mar-2021
!>
SUBROUTINE W3WAVE ( IMOD, ODAT, TEND, STAMP, NO_OUT &
#ifdef W3_OASIS
,ID_LCOMM, TIMEN &
#endif
)
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | H. L. Tolman |
!/ | FORTRAN 90 |
!/ | Last update : 22-Mar-2021 |
!/ +-----------------------------------+
!/
!/ 17-Mar-1999 : Distributed FORTRAN 77 version. ( version 1.18 )
!/ 04-Feb-2000 : Upgrade to FORTRAN 90 ( version 2.00 )
!/ Major changes to logistics.
!/ 05-Jan-2001 : Bug fix to allow model to run ( version 2.05 )
!/ without output.
!/ 24-Jan-2001 : Flat grid version. ( version 2.06 )
!/ 09-Feb-2001 : Third propagation scheme added. ( version 2.08 )
!/ 23-Feb-2001 : Check for barrier after source
!/ terms added ( W3NMIN ). ( delayed version 2.07 )
!/ 16-Mar-2001 : Fourth propagation scheme added. ( version 2.09 )
!/ 30-Mar-2001 : Sub-grid obstacles added. ( version 2.10 )
!/ 23-May-2001 : Barrier added for dry run, changed ( version 2.10 )
!/ declaration of FLIWND.
!/ 10-Dec-2001 : Sub-grid obstacles for UQ schemes. ( version 2.14 )
!/ 11-Jan-2002 : Sub-grid ice. ( version 2.15 )
!/ 24-Jan-2002 : Zero time step dor data ass. ( version 2.17 )
!/ 09-May-2002 : Switch clean up. ( version 2.21 )
!/ 13-Nov-2002 : Add stress vector. ( version 3.00 )
!/ 26-Dec-2002 : Moving grid version. ( version 3.02 )
!/ 01-Aug-2003 : Moving grid GSE correction. ( version 3.03 )
!/ 07-Oct-2003 : Output options for NN training. ( version 3.05 )
!/ 29-Dec-2004 : Multiple grid version. ( version 3.06 )
!/ 04-Feb-2005 : Add STAMP to par list. ( version 3.07 )
!/ 04-May-2005 : Change to MPI_COMM_WAVE. ( version 3.07 )
!/ 28-Jun-2005 : Adding map recalc for W3ULEV call. ( version 3.07 )
!/ 07-Sep-2005 : Updated boundary conditions. ( version 3.08 )
!/ 26-Jun-2006 : Add output type 6. ( version 3.09 )
!/ 04-Jul-2006 : Consolidate stress arrays. ( version 3.09 )
!/ 18-Oct-2006 : Partitioned spectral data output. ( version 3.10 )
!/ 02-Feb-2007 : Add FLAGST test. ( version 3.10 )
!/ 02-Apr-2007 : Add partitioned field data. ( version 3.11 )
!/ Improve MPI_WAITALL call tests/allocations.
!/ 07-May-2007 : Bug fix SKIP_O treatment. ( version 3.11 )
!/ 17-May-2007 : Adding NTPROC/NAPROC separation. ( version 3.11 )
!/ 08-Oct-2007 : Adding AS CX-Y to W3SRCE par. list. ( version 3.13 )
!/ 22-Feb-2008 : Initialize VGX-Y properly. ( version 3.13 )
!/ 10-Apr-2008 : Bug fix writing log file (MPI). ( version 3.13 )
!/ 30-Oct-2009 : Implement run-time grid selection. ( version 3.14 )
!/ (W. E. Rogers & T. J. Campbell, NRL)
!/ 30-Oct-2009 : Implement curvilinear grid type. ( version 3.14 )
!/ (W. E. Rogers & T. J. Campbell, NRL)
!/ 31-Mar-2010 : Add reflections ( version 3.14.4 )
!/ 29-Oct-2010 : Implement unstructured grids ( version 3.14.4 )
!/ (A. Roland and F. Ardhuin)
!/ 06-Mar-2011 : Output of max. CFL (F.Ardhuin) ( version 3.14.4 )
!/ 05-Apr-2011 : Implement iteration for DTMAX <1s ( version 3.14.4 )
!/ 02-Jul-2012 : Update for PALM coupling ( version 4.07 )
!/ 02-Sep-2012 : Clean up of open BC for UG grids ( version 4.08 )
!/ 03-Sep-2012 : Fix format 902. ( version 4.10 )
!/ 10-Dec-2012 : Modify field output MPI for new ( version 4.OF )
!/ structure and smaller memory footprint.
!/ 16-Nov-2013 : Allows reflection on curvi. grids ( version 4.13 )
!/ 27-Nov-2013 : Fixes for OpenMP versions. ( version 4.15 )
!/ 23-May-2014 : Adding ice fluxes to W3SRCE ( version 5.01 )
!/ 27-May-2014 : Move to OMPG/X switch. ( version 5.02 )
!/ 24-Apr-2015 : Adding OASIS coupling calls ( version 5.07 )
!/ (M. Accensi & F. Ardhuin, IFREMER)
!/ 27-Aug-2015 : Update for ICEH, ICEF ( version 5.10 )
!/ 31-Mar-2016 : Current option for smc grid. ( version 5.18 )
!/ 06-Jun-2018 : Add PDLIB/MEMCHECK/SETUP/NETCDF_QAD/TIMING
!/ OASIS/DEBUGINIT/DEBUGSRC/DEBUGRUN/DEBUGCOH
!/ DEBUGIOBP/DEBUGIOBC ( version 6.04 )
!/ 14-Sep-2018 : Remove PALM implementation ( version 6.06 )
!/ 25-Sep-2020 : Oasis coupling at T+0 ( version 7.10 )
!/ 22-Mar-2021 : Update TAUA, RHOA ( version 7.13 )
!/ 06-May-2021 : Use ARCTC and SMCTYPE options. JGLi ( version 7.13 )
!/
! 1. Purpose :
!
! Run WAVEWATCH III for a given time interval.
!
! 3. Parameters :
!
! Parameter list
! ----------------------------------------------------------------
! IMOD Int. I Model number.
! TEND I.A. I Ending time of integration.
! STAMP Log. I WRITE(*,*)time stamp (optional, defaults to T).
! NO_OUT Log. I Skip output (optional, defaults to F).
! Skip at ending time only!
! ----------------------------------------------------------------
!
! Local parameters : Flags
! ----------------------------------------------------------------
! FLOUTG Log. Flag for running W3OUTG.
! FLPART Log. Flag for running W3CPRT.
! FLZERO Log. Flag for zero time interval.
! FLAG0 Log. Flag for processors without tasks.
! ----------------------------------------------------------------
!
! 4. Subroutines used :
!
! See module documentation.
!
! 5. Called by :
!
! Any program shell or integrated model which uses WAVEWATCH III.
!
! 6. Error messages :
!
! 7. Remarks :
!
! - Currents are updated before winds as currents are used in wind
! and USTAR processing.
! - Ice and water levels can be updated only once per call.
! - If ice or water level time are undefined, the update
! takes place asap, otherwise around the "half-way point"
! betweem the old and new times.
! - To increase accuracy, the calculation of the intra-spectral
! propagation is performed in two parts around the spatial propagation.
!
! 8. Structure :
!
! -----------------------------------------------------------
! 0. Initializations
! a Point to data structures
! b Subroutine tracing
! c Local parameter initialization
! d Test output
! 1. Check the consistency of the input.
! a Ending time versus initial time.
! b Water level time.
! c Current time interval.
! d Wind time interval.
! e Ice time.
! 2. Determine next time from ending and output
! time and get corresponding time step.
! 3. Loop over time steps (see below).
! 4. Perform output to file if requested.
! a Check if time is output time.
! b Processing and MPP preparations. ( W3CPRT, W3OUTG )
! c Reset next output time.
! -------------- loop over output types ------------------
! d Perform output. ( W3IOxx )
! e Update next output time.
! -------------------- end loop --------------------------
! 5. Update log file.
! 6. If time is not ending time, branch back to 2.
! -----------------------------------------------------------
!
! Section 3.
! ----------------------------------------------------------
! 3.1 Interpolate winds and currents. ( W3UCUR, W3DCXY )
! ( W3UWND )
! ( W3UINI )
! 3.2 Update boundary conditions. ( W3IOBC, W3UBPT )
! 3.3 Update ice coverage (if new ice map). ( W3UICE )
! 3.4 Transform grid (if new water level). ( W3ULEV )
! 3.5 Update maps and dirivatives. ( W3MAPn, W3DDXY )
! ( W3NMIN, W3UTRN )
! Update grid advection vector.
! 3.6 Perform propagation
! a Preparations.
! b Intra spectral part 1. ( W3KTPn )
! c Longitude-latitude ( W3GATH, W3XYPn W3SCAT )
! b Intra spectral part 2. ( W3KTPn )
! 3.7 Calculate and integrate source terms. ( W3SRCE )
! 3.8 Update global time step.
! ----------------------------------------------------------
!
! 9. Switches :
!
! See module documentation.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
USE CONSTANTS
!/
USE W3GDATMD
USE W3WDATMD
USE W3ADATMD
USE W3IDATMD
USE W3ODATMD
!/
USE W3UPDTMD
USE W3SRCEMD
#ifdef W3_PR1
USE W3PRO1MD
#endif
#ifdef W3_PR2
USE W3PRO2MD
#endif
#ifdef W3_PR3
USE W3PRO3MD
#endif
#ifdef W3_SMC
USE W3PSMCMD
#endif
!
#ifdef W3_PR1
USE W3PROFSMD
#endif
#ifdef W3_PR2
USE W3PROFSMD
#endif
#ifdef W3_PR3
USE W3PROFSMD
#endif
!/
USE W3TRIAMD
USE W3IOGRMD
USE W3IOGOMD
USE W3IOPOMD
USE W3IOTRMD
USE W3IORSMD
USE W3IOBCMD
USE W3IOSFMD
#ifdef W3_PDLIB
USE PDLIB_W3PROFSMD, only : APPLY_BOUNDARY_CONDITION_VA
USE PDLIB_W3PROFSMD, only : PDLIB_W3XYPUG, PDLIB_W3XYPUG_BLOCK_IMPLICIT, PDLIB_W3XYPUG_BLOCK_EXPLICIT
USE PDLIB_W3PROFSMD, only : ALL_VA_INTEGRAL_PRINT, ALL_VAOLD_INTEGRAL_PRINT, ALL_FIELD_INTEGRAL_PRINT
USE W3PARALL, only : PDLIB_NSEAL, PDLIB_NSEALM
USE yowNodepool, only: npa, iplg, np
#endif
!/
USE W3SERVMD
USE W3TIMEMD
#ifdef W3_IC3
USE W3SIC3MD
#endif
#ifdef W3_IS2
USE W3SIS2MD
#endif
#ifdef W3_UOST
USE W3UOSTMD, ONLY: UOST_SETGRID
#endif
USE W3PARALL, ONLY : INIT_GET_ISEA
#ifdef W3_SETUP
USE W3WAVSET, only : WAVE_SETUP_COMPUTATION
#endif
#ifdef W3_OASIS
USE W3OACPMD, ONLY: ID_OASIS_TIME, CPLT0
#endif
#ifdef W3_OASOCM
USE W3OGCMMD, ONLY: SND_FIELDS_TO_OCEAN
#endif
#ifdef W3_OASACM
USE W3AGCMMD, ONLY: SND_FIELDS_TO_ATMOS
#endif
#ifdef W3_OASICM
USE W3IGCMMD, ONLY: SND_FIELDS_TO_ICE
#endif
#ifdef W3_PDLIB
USE PDLIB_FIELD_VEC, only : DO_OUTPUT_EXCHANGES
USE PDLIB_W3PROFSMD, ONLY: ASPAR_JAC, ASPAR_DIAG_ALL, B_JAC
USE W3PARALL, only : LSLOC
#endif
#ifdef W3_TIMINGS
USE W3PARALL, only : PRINT_MY_TIME
#endif
use wav_restart_mod , only : write_restart
use w3iogoncmd_pio , only : w3iogonc_pio
use w3iogoncdmd , only : w3iogoncd
use w3odatmd , only : histwr, rstwr, use_historync, use_restartnc, user_restfname
use w3timemd , only : set_user_timestring
!
#ifdef W3_MPI
INCLUDE "mpif.h"
#endif
!/
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
INTEGER, INTENT(IN) :: IMOD, TEND(2),ODAT(35)
LOGICAL, INTENT(IN), OPTIONAL :: STAMP, NO_OUT
#ifdef W3_OASIS
INTEGER, INTENT(IN), OPTIONAL :: ID_LCOMM
INTEGER, INTENT(IN), OPTIONAL :: TIMEN(2)
#endif
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters :
!/
#ifdef W3_S
INTEGER, SAVE :: IENT = 0
#endif
INTEGER :: IP
INTEGER :: TCALC(2), IT, IT0, NT, ITEST, &
ITLOC, ITLOCH, NTLOC, ISEA, JSEA, &
IX, IY, ISPEC, J, TOUT(2), TLST(2), &
REFLED(6), IK, ITH, IS, NKCFL
INTEGER :: ISP, IP_glob
INTEGER :: TTEST(2),DTTEST
REAL :: ICEDAVE
!
LOGICAL :: SBSED
LOGICAL :: CPLWRTFLG
#ifdef W3_SEC1
INTEGER :: ISEC1
#endif
INTEGER :: JJ, NDSOFLG
#ifdef W3_MPI
INTEGER :: IERR_MPI, NRQMAX
INTEGER, ALLOCATABLE :: STATCO(:,:), STATIO(:,:)
#endif
INTEGER :: IXrel
REAL :: DTTST, DTTST1, DTTST2, DTTST3, &
DTL0, DTI0, DTR0, DTI10, DTI50, &
DTGA, DTG, DTGpre, DTRES, &
FAC, VGX, VGY, FACK, FACTH, &
FACX, XXX, REFLEC(4), &
DELX, DELY, DELA, DEPTH, D50, PSIC
REAL :: VSioDummy(NSPEC), VDioDummy(NSPEC), VAoldDummy(NSPEC)
LOGICAL :: SHAVETOTioDummy
#ifdef W3_SEC1
REAL :: DTGTEMP
#endif
!
REAL, ALLOCATABLE :: FIELD(:)
REAL :: TMP1(4), TMP2(3), TMP3(2), TMP4(2)
#ifdef W3_IC3
REAL, ALLOCATABLE :: WN_I(:)
#endif
#ifdef W3_REFRX
REAL, ALLOCATABLE :: CIK(:)
#endif
!
! Orphaned arrays from old data structure
!
REAL, ALLOCATABLE :: TAUWX(:), TAUWY(:)
!
LOGICAL :: FLACT, FLZERO, FLFRST, FLMAP, TSTAMP,&
SKIP_O, FLAG_O, FLDDIR, READBC, &
FLAG0 = .FALSE., FLOUTG, FLPFLD, &
FLPART, LOCAL, FLOUTG2
!
#ifdef W3_MPI
LOGICAL :: FLGMPI(0:8)
#endif
#ifdef W3_IC3
REAL :: FIXEDVISC,FIXEDDENS,FIXEDELAS
REAL :: USE_CHENG, USE_CGICE, HICE
#endif
LOGICAL :: UGDTUPDATE ! true if time step should be updated for UG schemes
CHARACTER(LEN=8) :: STTIME
CHARACTER(LEN=21) :: IDACT
CHARACTER(LEN=16) :: OUTID
CHARACTER(LEN=23) :: IDTIME
INTEGER eIOBP
INTEGER ITH_F
#ifdef W3_PDLIB
REAL :: VS_SPEC(NSPEC)
REAL :: VD_SPEC(NSPEC)
#endif
!
CHARACTER(LEN=30) :: FOUTNAME
!
#ifdef W3_T
REAL :: INDSORT(NSEA), DTCFL1(NSEA)
#endif
!/
#ifdef W3_SMC
!Li Temperature spectra for Arctic boundary update.
REAL, ALLOCATABLE :: BACSPEC(:)
REAL :: BACANGL
#endif
! locally defined flags
#ifdef W3_SBS
logical, parameter :: w3_sbs_flag = .true.
#else
logical, parameter :: w3_sbs_flag = .false.
#endif
#ifdef W3_CESMCOUPLED
logical, parameter :: w3_cesmcoupled_flag = .true.
#else
logical, parameter :: w3_cesmcoupled_flag = .false.
#endif
integer :: memunit
logical :: do_gridded_output
logical :: do_point_output
logical :: do_track_output
logical :: do_restart_output
logical :: do_sf_output
logical :: do_coupler_output
logical :: do_wavefield_separation_output
logical :: do_startall
logical :: do_w3outg
character(len=16) :: user_timestring !YYYY-MM-DD-SSSSS
character(len=256) :: fname
! debug
integer :: i
!/ ------------------------------------------------------------------- /
! 0. Initializations
!
XXX = undef
memunit = 40000+iaproc
! 0.a Set pointers to data structure
!
#ifdef W3_COU
SCREEN = 333
#endif
!
IF ( IOUTP .NE. IMOD ) CALL W3SETO ( IMOD, NDSE, NDST )
IF ( IGRID .NE. IMOD ) CALL W3SETG ( IMOD, NDSE, NDST )
IF ( IWDATA .NE. IMOD ) CALL W3SETW ( IMOD, NDSE, NDST )
IF ( IADATA .NE. IMOD ) CALL W3SETA ( IMOD, NDSE, NDST )
IF ( IIDATA .NE. IMOD ) CALL W3SETI ( IMOD, NDSE, NDST )
#ifdef W3_UOST
CALL UOST_SETGRID(IMOD)
#endif
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "W3WAVEMD, step 1", 1)
#endif
!
ALLOCATE(TAUWX(NSEAL), TAUWY(NSEAL))
#ifdef W3_REFRX
ALLOCATE(CIK(NSEAL))
#endif
!
IF ( PRESENT(STAMP) ) THEN
TSTAMP = STAMP
ELSE
TSTAMP = .TRUE.
END IF
!
IF ( PRESENT(NO_OUT) ) THEN
SKIP_O = NO_OUT
ELSE
SKIP_O = .FALSE.
END IF
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "W3WAVEMD, step 2", 1)
#endif
!
! 0.b Subroutine tracing
!
#ifdef W3_S
CALL STRACE (IENT, 'W3WAVE')
#endif
!
!
! 0.c Local parameter initialization
!
IPASS = IPASS + 1
IDACT = ' '
OUTID = ' '
FLACT = ITIME .EQ. 0
FLMAP = ITIME .EQ. 0
FLDDIR = ITIME .EQ. 0 .AND. ( FLCTH .OR. FSREFRACTION .OR. FLCK .OR. FSFREQSHIFT )
!
FLPFLD = .FALSE.
DO J=1,NOGE(4)
FLPFLD = FLPFLD .OR. FLOGRD(4,J) .OR. FLOGR2(4,J)
END DO
!
IF ( IAPROC .EQ. NAPLOG ) BACKSPACE ( NDSO )
!
IF ( FLCOLD ) THEN
DTDYN = 0.
FCUT = SIG(NK) * TPIINV
END IF
!
IF( GTYPE .EQ. SMCTYPE ) THEN
J = 1
#ifdef W3_SMC
!!Li Use sea point only field for SMC grid.
ALLOCATE ( FIELD(NCel) )
#endif
ELSE
ALLOCATE ( FIELD(1-NY:NY*(NX+2)) )
ENDIF
!
LOCAL = IAPROC .LE. NAPROC
UGDTUPDATE = .FALSE.
IF (FLAGLL) THEN
FACX = 1./(DERA * RADIUS)
ELSE
FACX = 1.
END IF
!
SBSED = .FALSE.
if (w3_sbs_flag) then
NDSOFLG = 99
SBSED = .TRUE.
end if
!
TAUWX = 0.
TAUWY = 0.
!
! 0.d Test output
!
#ifdef W3_T
WRITE (NDST,9000) IMOD, trim(FILEXT), TEND
#endif
!
! 1. Check the consistency of the input ----------------------------- /
! 1.a Ending time versus initial time
!
DTTST = DSEC21 ( TIME , TEND )
FLZERO = DTTST .EQ. 0.
#ifdef W3_T
WRITE (NDST,9010) DTTST, FLZERO
#endif
IF ( DTTST .LT. 0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1000)
CALL EXTCDE ( 1 )
END IF
!
! 1.b Water level time
!
IF ( FLLEV ) THEN
IF ( TLEV(1) .GE. 0. ) THEN
DTL0 = DSEC21 ( TLEV , TLN )
ELSE
DTL0 = 1.
END IF
#ifdef W3_T
WRITE (NDST,9011) DTL0
#endif
IF ( DTL0 .LT. 0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1001)
CALL EXTCDE ( 2 )
END IF
ELSE
DTL0 = 0.
END IF
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "W3WAVEMD, step 4", 1)
#endif
!
! 1.c Current interval
!
IF ( FLCUR ) THEN
DTTST1 = DSEC21 ( TC0 , TCN )
DTTST2 = DSEC21 ( TC0 , TIME )
DTTST3 = DSEC21 ( TEND , TCN )
#ifdef W3_T
WRITE (NDST,9012) DTTST1, DTTST2, DTTST3
#endif
IF ( DTTST1.LT.0. .OR. DTTST2.LT.0. .OR. DTTST3.LT.0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1002)
CALL EXTCDE ( 3 )
END IF
IF ( DTTST2.EQ.0..AND. ITIME.EQ.0 ) THEN
IDACT(7:7) = 'F'
TOFRST = TIME
END IF
END IF
!
! 1.d Wind interval
!
IF ( FLWIND ) THEN
DTTST1 = DSEC21 ( TW0 , TWN )
DTTST2 = DSEC21 ( TW0 , TIME )
DTTST3 = DSEC21 ( TEND , TWN )
#ifdef W3_T
WRITE (NDST,9013) DTTST1, DTTST2, DTTST3
#endif
IF ( DTTST1.LT.0. .OR. DTTST2.LT.0. .OR. DTTST3.LT.0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1003)
CALL EXTCDE ( 4 )
END IF
IF ( DTTST2.EQ.0..AND. ITIME.EQ.0 ) THEN
IDACT(3:3) = 'F'
TOFRST = TIME
END IF
END IF
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "W3WAVEMD, step 5", 1)
#endif
!
! 1.e Ice concentration interval
!
IF ( FLICE ) THEN
IF ( TICE(1) .GE. 0 ) THEN
DTI0 = DSEC21 ( TICE , TIN )
ELSE
DTI0 = 1.
END IF
#ifdef W3_T
WRITE (NDST,9014) DTI0
#endif
IF ( DTI0 .LT. 0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1004)
CALL EXTCDE ( 5 )
END IF
ELSE
DTI0 = 0.
END IF
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "W3WAVEMD, step 6", 1)
#endif
!
! 1.f Momentum interval
!
IF ( FLTAUA ) THEN
DTTST1 = DSEC21 ( TU0 , TUN )
DTTST2 = DSEC21 ( TU0 , TIME )
DTTST3 = DSEC21 ( TEND , TUN )
#ifdef W3_T
WRITE (NDST,9017) DTTST1, DTTST2, DTTST3
#endif
IF ( DTTST1.LT.0. .OR. DTTST2.LT.0. .OR. DTTST3.LT.0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1007)
CALL EXTCDE ( 3 )
END IF
IF ( DTTST2.EQ.0..AND. ITIME.EQ.0 ) THEN
IDACT(9:9) = 'F'
TOFRST = TIME
END IF
END IF
!
! 1.g Air density time
!
IF ( FLRHOA ) THEN
DTTST1 = DSEC21 ( TR0 , TRN )
DTTST2 = DSEC21 ( TR0 , TIME )
DTTST3 = DSEC21 ( TEND , TRN )
#ifdef W3_T
WRITE (NDST,9018) DTTST1, DTTST2, DTTST3
#endif
IF ( DTTST1.LT.0. .OR. DTTST2.LT.0. .OR. DTTST3.LT.0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1008)
CALL EXTCDE ( 2 )
END IF
IF ( DTTST2.EQ.0..AND. ITIME.EQ.0 ) THEN
IDACT(11:11) = 'F'
TOFRST = TIME
END IF
END IF
!
! 1.e Ice thickness interval
!
IF ( FLIC1 ) THEN
IF ( TIC1(1) .GE. 0 ) THEN
DTI10 = DSEC21 ( TIC1 , TI1 )
ELSE
DTI10 = 1.
END IF
#ifdef W3_T
WRITE (NDST,9015) DTI10
#endif
IF ( DTI10 .LT. 0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1005)
CALL EXTCDE ( 5 )
END IF
ELSE
DTI10 = 0.
END IF
!
! 1.e Ice floe interval
!
#ifdef W3_IS2
IF ( FLIC5 ) THEN
IF ( TIC5(1) .GE. 0 ) THEN
DTI50 = DSEC21 ( TIC5 , TI5 )
ELSE
DTI50 = 1.
END IF
#ifdef W3_T
WRITE (NDST,9016) DTI50
#endif
IF ( DTI50 .LT. 0. ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,1006)
CALL EXTCDE ( 5 )
END IF
ELSE
DTI50 = 0.
END IF
#endif
!
! 2. Determine next time from ending and output --------------------- /
! time and get corresponding time step.
!
FLFRST = .TRUE.
DO
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("First entry in the TIME LOOP")
#endif
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "W3WAVEMD, step 6.1", 1)
#endif
!
!
! 2.a Pre-calculate table for IC3 ------------------------------------ /
#ifdef W3_IC3
USE_CHENG=IC3PARS(9)
IF( USE_CHENG==1.0 )THEN
FIXEDVISC=IC3PARS(14)
FIXEDDENS=IC3PARS(15)
FIXEDELAS=IC3PARS(16)
IF ( (FIXEDVISC.LT.0.0).OR.(FIXEDDENS.LT.0.0) .OR. (FIXEDELAS.LT.0.0) ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE(NDSE,*)'Cheng method requires stationary', &
' and uniform rheology from namelist.'
CALL EXTCDE(2)
END IF
IF (CALLEDIC3TABLE==0) THEN
CALL IC3TABLE_CHENG(FIXEDVISC,FIXEDDENS,FIXEDELAS)
CALLEDIC3TABLE = 1
ENDIF
ENDIF
#endif
! 2.b Update group velocity and wavenumber from ice parameters ------- /
! from W3SIC3MD module. ------------------------------------------ /
! Note: "IF FLFRST" can be added for efficiency, but testing req'd
JSEA=1 ! no switch (intentional)
#ifdef W3_IC3
USE_CGICE=IC3PARS(12)
IF ( USE_CGICE==1.0 ) THEN
IF ( IAPROC .EQ. NAPERR ) WRITE(SCREEN,920)
#endif
#ifdef W3_IC3
DO JSEA=1,NSEAL
#endif
#ifdef W3_DIST
ISEA = IAPROC + (JSEA-1)*NAPROC
#endif
#ifdef W3_SHRD
ISEA = JSEA
#endif
#ifdef W3_IC3
ALLOCATE(WN_I(SIZE(WN(:,ISEA))))
WN_I(:) = 0.
DEPTH = MAX( DMIN , DW(ISEA) )
IX = MAPSF(ISEA,1)
IY = MAPSF(ISEA,2)
#endif
! 2.b.1 Using Cheng method: requires stationary/uniform rheology.
! However, ice thickness may be input by either method
#ifdef W3_IC3
IF ( USE_CHENG==1.0 ) THEN
IF (FLIC1) THEN
HICE=ICEP1(IX,IY)
ELSEIF (IC3PARS(13).GE.0.0)THEN
HICE=IC3PARS(13)
ELSE
IF ( IAPROC .EQ. NAPERR ) then
WRITE(NDSE,*)'ICE THICKNESS NOT AVAILABLE FOR CG CALC'
end if
CALL EXTCDE(2)
ENDIF
IF (HICE > 0.0) THEN ! non-zero ice
CALL W3IC3WNCG_CHENG(WN(:,ISEA),WN_I(:), CG(:,ISEA),HICE,FIXEDVISC, &
FIXEDDENS, FIXEDELAS, DEPTH)
END IF ! non-zero ice
#endif
#ifdef W3_IC3
ELSE ! not using Cheng method
#endif
! 2.b.2 If not using Cheng method: require FLIC1 to FLIC4 (not strictly
! necesssary, but makes code simpler)
#ifdef W3_IC3