-
Notifications
You must be signed in to change notification settings - Fork 548
/
w3initmd.F90
6218 lines (6183 loc) · 190 KB
/
w3initmd.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 W3INITMD.
!>
!> @author H. L. Tolman @date 22-Mar-2021
!>
#include "w3macros.h"
!>
!> @brief Contains module W3INITMD.
!>
!> @author H. L. Tolman @date 22-Mar-2021
!>
!/ ------------------------------------------------------------------- /
MODULE W3INITMD
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | H. L. Tolman |
!/ | FORTRAN 90 |
!/ | Last update : 22-Mar-2021 |
!/ +-----------------------------------+
!/
!/ 28-Dec-2004 : Origination (out of W3WAVEMD). ( version 3.06 )
!/ Multiple grid version.
!/ 03-Jan-2005 : Add US2x to MPI communication. ( version 3.06 )
!/ 04-Jan-2005 : Add grid output flags to W3INIT. ( version 3.06 )
!/ 07-Feb-2005 : Combined vs. separate test output. ( version 3.07 )
!/ 04-May-2005 : Change to MPI_COMM_WAVE. ( version 3.07 )
!/ 21-Jul-2005 : Add output fields. ( version 3.07 )
!/ 09-Nov-2005 : Drying out of points added. ( version 3.08 )
!/ 13-Jun-2006 : Splitting STORE in G/SSTORE. ( version 3.09 )
!/ 26-Jun-2006 : adding wiring for output type 6. ( version 3.09 )
!/ 27-Jun-2006 : Adding file name preamble. ( version 3.09 )
!/ 04-Jul-2006 : Consolidate stress arrays. ( version 3.09 )
!/ 02-Aug-2006 : Adding W3MPIP. ( version 3.10 )
!/ 02-Nov-2006 : Adding partitioning options. ( version 3.10 )
!/ 11-Jan-2007 : Updating IAPPRO computation. ( version 3.10 )
!/ 02-Apr-2007 : Add partitioned field data. ( version 3.11 )
!/ Add user-defined field data.
!/ 01-May-2007 : Move O7a output to W3IOPP. ( version 3.11 )
!/ 08-May-2007 : Starting from calm as an option. ( version 3.11 )
!/ 17-May-2007 : Adding NTPROC/NAPROC separation. ( version 3.11 )
!/ 21-Jun-2007 : Dedicated output processes. ( version 3.11 )
!/ 29-Feb-2008 : Add NEC compiler directives. ( version 3.13 )
!/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
!/ 23-Jul-2009 : Implement unstructured grids ( 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)
!/ 06-Dec-2010 : Change from GLOBAL (logical) to ICLOSE (integer) to
!/ specify index closure for a grid. ( version 3.14 )
!/ (T. J. Campbell, NRL)
!/ 02-Sep.2012 : Set up for > 999 test files. ( version 4.10 )
!/ Reset UST initialization.
!/ 03-Sep-2012 : Switch test file on/off (TSTOUT) ( version 4.10 )
!/ 03-Sep-2012 : Clean up of UG grids ( version 4.08 )
!/ 30-Sep-2012 : Implemetation of tidal constituents ( version 4.09 )
!/ 07-Dec-2012 : Initialize UST non-zero. ( version 4.11 )
!/ 12-Dec-2012 : Changes for SMC grid. JG_Li ( version 4.11 )
!/ 26-Dec-2012 : Modify field output MPI for new ( version 4.11 )
!/ structure and smaller memory footprint.
!/ 02-Jul-2013 : Bug fix MPI_FLOAT -> MPI_REAL. ( version 4.11 )
!/ 10-Oct-2013 : CG and WN values at DMIN for ISEA=0 ( version 4.12 )
!/ 14-Nov-2013 : Remove UST(DIR) initialization. ( version 4.13 )
!/ 15-Dec-2013 : Adds fluxes to ice ( version 5.01 )
!/ 01-May-2017 : Adds directional MSS parameters ( version 6.04 )
!/ 05-Jun-2018 : Adds PDLIB/MEMCHECK/DEBUG ( version 6.04 )
!/ 21-Aug-2018 : Add WBT parameter ( version 6.06 )
!/ 26-Aug-2018 : UOST (Mentaschi et al. 2015, 2018) ( version 6.06 )
!/ 25-Sep-2020 : Extra fields for coupling restart ( version 7.10 )
!/ 22-Mar-2021 : Extra coupling fields ( version 7.13 )
!/ 22-Jun-2021 : GKE NL5 (Q. Liu) ( version 7.13 )
!/
!/ Copyright 2009-2013 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.
!/
!/ Note: Changes in version numbers not logged above.
!/
! 1. Purpose :
!
! 2. Variables and types :
!
! Name Type Scope Description
! ----------------------------------------------------------------
! CRITOS R.P. Public Critical percentage of resources used
! for output to trigger warning.
! WWVER C*10 Public Model version number.
! SWITCHES C*256 Public switches taken from bin/switch
! ----------------------------------------------------------------
!
! 3. Subroutines and functions :
!
! Name Type Scope Description
! ----------------------------------------------------------------
! W3INIT Subr. Public Wave model initialization.
! W3MPII Subr. Public Initialize MPI data transpose.
! W3MPIO Subr. Public Initialize MPI output gathering.
! W3MPIP Subr. Public Initialize MPI point output gathering.
! ----------------------------------------------------------------
!
! 4. Subroutines and functions used :
!
! See subroutine documentation.
!
! 5. Remarks :
!
! 6. Switches :
!
! !/SHRD Switch for shared / distributed memory architecture.
! !/DIST Id.
! !/MPI Id.
!
! !/S Enable subroutine tracing.
! !/Tn Enable test output.
! !/MPIT Enable test output (MPI).
!
! 7. Source code :
!
!/ ------------------------------------------------------------------- /
! module default
implicit none
PUBLIC
!/
REAL, PARAMETER :: CRITOS = 15.
CHARACTER(LEN=10), PARAMETER :: WWVER = '7.14 '
CHARACTER(LEN=512), PARAMETER :: SWITCHES = &
__WW3_SWITCHES__
!/
CONTAINS
!/ ------------------------------------------------------------------- /
!>
!> @brief Initialize WAVEWATCH III.
!>
!> @details Initialize data structure and wave fields from data files.
!> Initialize grid from local and instantaneous data.
!>
!> @param[in] IMOD Model number.
!> @param[in] IsMulti
!> @param[in] FEXT Extension of data files.
!> @param[in] MDS Array with dataset numbers saved as NDS in W3ODATMD.
!> @param[in] MTRACE Array with subroutine tracing information.
!> @param[in] ODAT Output data, five parameters per output type.
!> @param[inout] FLGRD Flags for gridded output.
!> @param[inout] FLGR2 Flags for coupling output.
!> @param[inout] FLGD
!> @param[inout] FLG2
!> @param[in] NPT Number of output points.
!> @param[inout] XPT Coordinates of output points.
!> @param[inout] YPT Coordinates of output points.
!> @param[in] PNAMES Output point names.
!> @param[in] IPRT Partitioning grid info.
!> @param[inout] PRTFRM Partitioning format flag.
!> @param[in] MPI_COMM MPI communicator to be used for model.
!> @param[in] FLAGSTIDEIN
!>
!> @author H. L. Tolman @date 03-Sep-2012
!>
SUBROUTINE W3INIT ( IMOD, IsMulti, FEXT, MDS, MTRACE, ODAT, FLGRD, FLGR2, FLGD, &
FLG2, NPT, XPT, YPT, PNAMES, IPRT, PRTFRM, MPI_COMM, FLAGSTIDEIN)
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | H. L. Tolman |
!/ | FORTRAN 90 |
!/ | Last update : 03-Sep-2012 |
!/ +-----------------------------------+
!/
!/ 17-Mar-1999 : Distributed FORTRAN 77 version. ( version 1.18 )
!/ 13-Jan-2000 : Upgrade to FORTRAN 90 ( version 2.00 )
!/ Major changes to logistics.
!/ 14-Feb-2000 : Exact-NL added. ( version 2.01 )
!/ 24-Jan-2001 : Flat grid version. ( version 2.06 )
!/ 24-Jan-2002 : Zero time step for data ass. ( version 2.17 )
!/ 18-Feb-2002 : Point output diagnostics added. ( version 2.18 )
!/ 13-Nov-2002 : Add stress vector. ( version 3.00 )
!/ 20-Aug-2003 : Output server options added. ( version 3.04 )
!/ 28-Dec-2004 : Multiple grid version. ( version 3.06 )
!/ Taken out of W3WAVE.
!/ 04-Jan-2005 : Add grid output flags to par list. ( version 3.06 )
!/ 07-Feb-2005 : Combined vs. separate test output. ( version 3.07 )
!/ 04-May-2005 : Change to MPI_COMM_WAVE. ( version 3.07 )
!/ 09-Nov-2005 : Drying out of points added. ( version 3.08 )
!/ 26-Jun-2006 : adding wiring for output type 6. ( version 3.09 )
!/ 27-Jun-2006 : Adding file name preamble. ( version 3.09 )
!/ 02-Aug-2006 : Adding W3MPIP. ( version 3.10 )
!/ 02-Nov-2006 : Adding partitioning options. ( version 3.10 )
!/ 11-Jan-2007 : Updating IAPPRO computation. ( version 3.10 )
!/ 01-May-2007 : Move O7a output to W3IOPP. ( version 3.11 )
!/ 08-May-2007 : Starting from calm as an option. ( version 3.11 )
!/ 17-May-2007 : Adding NTPROC/NAPROC separation. ( version 3.11 )
!/ 21-Jun-2007 : Dedicated output processes. ( version 3.11
!/ 13-Sep-2009 : Add coupling option ( 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-Oct-2010 : Implement unstructured grids ( version 3.14.1 )
!/ (A. Roland and F. Ardhuin)
!/ 06-Dec-2010 : Change from GLOBAL (logical) to ICLOSE (integer) to
!/ specify index closure for a grid. ( version 3.14 )
!/ (T. J. Campbell, NRL)
!/ 02-Sep.2012 : Set up for > 999 test files. ( version 4.10 )
!/ 03-Sep-2012 : Switch test file on/off (TSTOUT) ( version 4.10 )
!/ 03-Sep-2012 : Clean up of UG grids ( version 4.08 )
!/
! 1. Purpose :
!
! Initialize WAVEWATCH III.
!
! 2. Method :
!
! Initialize data structure and wave fields from data files.
! Initialize grid from local and instantaneous data.
!
! 3. Parameters :
!
! Parameter list
! ----------------------------------------------------------------
! IMOD Int. I Model number.
! FEXT Char I Extension of data files.
! MDS I.A. I Array with dataset numbers (see below),
! saved as NDS in W3ODATMD.
! 1: General output unit number ("log file").
! 2: Error output unit number.
! 3: Test output unit number.
! 4: "screen", i.e., direct output location,
! can be the screen or the output file of
! the shell.
! 5: Model definition file unit number.
! 6: Restart file unit number.
! 7: Grid output file unit number.
! 8: Point output file unit number.
! 9: Input boundary data file unit number.
! 10: Output boundary data file unit number
! (first).
! 11: Track information file unit number.
! 12: Track output file unit number.
! MTRACE I.A. I Array with subroutine tracing information.
! 1: Output unit number for trace.
! 2: Maximum number of trace prints.
! ODAT I.A. I Output data, five parameters per output type
! 1-5 Data for OTYPE = 1; gridded fields.
! 1 YYYMMDD for first output.
! 2 HHMMSS for first output.
! 3 Output interval in seconds.
! 4 YYYMMDD for last output.
! 5 HHMMSS for last output.
! 6-10 Id. for OTYPE = 2; point output.
! 11-15 Id. for OTYPE = 3; track point output.
! 16-20 Id. for OTYPE = 4; restart files.
! 21-25 Id. for OTYPE = 5; boundary data.
! 31-35 Id. for OTYPE = 7; coupling data.
! 36-40 Id. for OTYPE = 8; second restart file
! FLGRD L.A. I Flags for gridded output.
! FLGR2 L.A. I Flags for coupling output.
! NPT Int. I Number of output points
! X/YPT R.A. I Coordinates of output points.
! PNAMES C.A. I Output point names.
! IPRT I.A. I Partitioning grid info.
! PRTFRM I.A. I Partitioning format flag.
! MPI_COMM Int. I MPI communicator to be used for model.
! ----------------------------------------------------------------
!
! 4. Subroutines used :
!
! Name Type Module Description
! ----------------------------------------------------------------
! W3SETG Subr. W3GDATMD Point to data structure.
! W3SETW Subr. W3WDATMD Point to data structure.
! W3DIMW Subr. Id. Set array sizes in data structure.
! W3SETA Subr. W3ADATMD Point to data structure.
! W3DIMA Subr. Id. Set array sizes in data structure.
! W3SETI Subr. W3IDATMD Point to data structure.
! W3DIMI Subr. Id. Set array sizes in data structure.
! W3SETO Subr. W3ODATMD Point to data structure.
! W3DMO5 Subr. Id. Set array sizes in data structure.
! ITRACE Subr. W3SERVMD Subroutine tracing initialization.
! STRACE Subr. Id. Subroutine tracing.
! EXTCDE Subr. Id. Program abort.
! WWDATE Subr. Id. System date.
! WWTIME Subr. Id. System time.
! DSEC21 Func. W3TIMEMD Compute time difference.
! TICK21 Func. Id. Advance the clock.
! STME21 Func. Id. Print the time readable.
! PRTBLK Func. W3ARRYMD Print plot of array.
! W3IOGR Subr. W3IOGRMD Read/write model definition file.
! W3IORS Subr. W3IORSMD Read/write restart file.
! W3IOPP Subr. W3IOPOMD Preprocess point output.
! CALL MPI_COMM_SIZE, CALL MPI_COMM_RANK
! Subr. mpif.h Standard MPI routines.
! ----------------------------------------------------------------
!
! 5. Called by :
!
! Any program shell or integrated model which uses WAVEWATCH III.
!
! 6. Error messages :
!
! On opening of log file only. Other error messages are generated
! by W3IOGR and W3IORS.
!
! 7. Remarks :
!
! - The log file is called 'log.FEXT', where FEXT is passed to
! the routine.
! - The test output file is called 'test.FEXT' in shared memory
! version or testNNN.FEXT in distributed memory version.
! - A water level and ice coverage are transferred with the
! restart file. To assure consistency within the model, the
! water level and ice coverage are re-evaluated at the 0th
! time step in the actual wave model routine.
! - When running regtests in cases where disk is non-local
! (i.e. NFS used), there can be a huge improvment in compute
! time by using /var/tmp/ for log files.
! See commented line at "OPEN (MDS(1),FILE=..."
!
! 8. Structure :
!
! ----------------------------------------------------
! 1. Set-up of idata structures and I/O.
! a Point to proper data structures.
! b Number of processors and processor number.
! c Open files.
! d Dataset unit numbers
! e Subroutine tracing
! f Initial and test outputs
! 2. Model definition.
! a Read model definition file ( W3IOGR )
! b Save MAPSTA.
! c MPP preparation
! 3. Model initialization.
! a Read restart file. ( W3IORS )
! b Compare grid and restart MAPSTA.
! c Initialize with winds if requested (set flag).
! d Initialize calm conditions if requested.
! e Preparations for prop. scheme.
! 4. Set-up output times.
! a Unpack ODAT.
! b Check if output available.
! c Get first time per output and overall.
! d Prepare point output ( W3IOPP )
! 5. Define wavenumber grid.
! a Calculate depth.
! b Fill wavenumber and group velocity arrays.
! 6. Initialize arrays.
! 7. Write info to log file.
! 8. Final MPI set up ( W3MPII , W3MPIO , W3MPIP )
! ----------------------------------------------------
!
! 9. Switches :
!
! !/SHRD Switch for shared / distributed memory architecture.
! !/DIST Id.
! !/MPI Id.
!
! !/S Enable subroutine tracing.
! !/Tn Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
use w3servmd, only : print_memcheck
USE CONSTANTS
!/
USE W3GDATMD, ONLY: W3SETG, RSTYPE
USE W3WDATMD, ONLY: W3SETW, W3DIMW
USE W3ADATMD, ONLY: W3SETA, W3DIMA
USE W3IDATMD, ONLY: W3SETI, W3DIMI
USE W3ODATMD, ONLY: W3SETO, W3DMO5
USE W3IOGOMD, ONLY: W3FLGRDUPDT
USE W3IOGRMD, ONLY: W3IOGR
USE W3IORSMD, ONLY: W3IORS
USE W3IOPOMD, ONLY: W3IOPP
USE W3SERVMD, ONLY: ITRACE, EXTCDE, WWDATE, WWTIME
#ifdef W3_S
USE W3SERVMD, ONLY: STRACE
#endif
USE W3TIMEMD, ONLY: DSEC21, TICK21, STME21
USE W3ARRYMD, ONLY: PRTBLK
!/
USE W3GDATMD, ONLY: NX, NY, NSEA, NSEAL, MAPSTA, MAPST2, MAPFS, &
MAPSF, FLAGLL, &
ICLOSE, ZB, TRNX, TRNY, DMIN, DTCFL, DTMAX, &
FLCK, NK, NTH, NSPEC, SIG, GNAME
#ifdef W3_PDLIB
USE W3GDATMD, ONLY : FLCTH, B_JGS_BLOCK_GAUSS_SEIDEL, B_JGS_USE_JACOBI
#endif
USE W3WDATMD, ONLY: TIME, TLEV, TICE, TRHO, WLV, UST, USTDIR, VA
USE W3ODATMD, ONLY: NDSO, NDSE, NDST, SCREEN, NDS, NTPROC, &
NAPROC, IAPROC, NAPLOG, NAPOUT, NAPERR, &
NAPFLD, NAPPNT, NAPTRK, NAPRST, NAPBPT, &
NAPPRT, TOFRST, DTOUT, TONEXT, TOLAST, &
FLOUT, FLOGRD, FLBPO, NOPTS, PTNME, &
PTLOC, IPTINT, PTIFAC, UNDEF, IDOUT, FLBPI, &
OUTPTS, FNMPRE, IX0, IXN, IXS, IY0, IYN, &
IYS, FLFORM, IOSTYP, UNIPTS, UPPROC, NOTYPE,&
FLOGR2, NOGRP, NGRPP, FLOGD, FLOG2
#ifdef W3_NL5
USE W3ODATMD, ONLY: TOSNL5
#endif
USE W3ADATMD, ONLY: NSEALM, IAPPRO, FLCOLD, FLIWND, DW, CG, WN, &
UA, UD, U10, U10D, AS
#ifdef W3_MPI
USE W3ADATMD, ONLY: MPI_COMM_WAVE, MPI_COMM_WCMP
#endif
USE W3IDATMD, ONLY: FLLEV, FLCUR, FLWIND, FLICE, FLTAUA, FLRHOA,&
FLMDN, FLMTH, FLMVS, FLIC1, FLIC2, FLIC3, &
FLIC4, FLIC5
USE W3DISPMD, ONLY: WAVNU1, WAVNU3
USE W3PARALL, ONLY: SET_UP_NSEAL_NSEALM
#ifdef W3_PDLIB
USE W3PARALL, ONLY: SYNCHRONIZE_IPGL_ETC_ARRAY, ISEA_TO_JSEA
use yowNodepool, only: npa
use yowRankModule, only : rank
#endif
USE W3GDATMD, ONLY: GTYPE, UNGTYPE
#ifdef W3_PDLIB
USE PDLIB_W3PROFSMD, ONLY : PDLIB_MAPSTA_INIT, SET_IOBDP_PDLIB, PDLIB_IOBP_INIT, SET_IOBPA_PDLIB
USE PDLIB_W3PROFSMD, ONLY : BLOCK_SOLVER_INIT, BLOCK_SOLVER_EXPLICIT_INIT, PDLIB_INIT, DEALLOCATE_PDLIB_GLOBAL
use yowDatapool, only: istatus
#endif
#ifdef W3_SETUP
USE W3WAVSET, ONLY : PREPARATION_FD_SCHEME
USE W3WDATMD, ONLY: ZETA_SETUP
USE W3GDATMD, ONLY : DO_CHANGE_WLV
#endif
USE W3TRIAMD, ONLY: NVECTRI, AREA_SI, COORDMAX, SPATIAL_GRID
USE W3GDATMD, ONLY: FSN,FSPSI,FSFCT,FSNIMP, FSTOTALIMP, FSTOTALEXP, XGRD, YGRD
USE W3GDATMD, ONLY: FSREFRACTION, FSFREQSHIFT
USE W3PARALL, ONLY: INIT_GET_JSEA_ISPROC, INIT_GET_ISEA
#ifdef W3_TIMINGS
USE W3PARALL, ONLY: PRINT_MY_TIME
#endif
#if defined W3_PDLIB && defined W3_DEBUGCOH
USE PDLIB_W3PROFSMD, ONLY: ALL_VA_INTEGRAL_PRINT, TEST_MPI_STATUS
#endif
#if defined W3_PDLIB && defined W3_DEBUGINIT
USE PDLIB_W3PROFSMD, ONLY: PRINT_WN_STATISTIC
#endif
#ifdef W3_UOST
USE W3UOSTMD, ONLY: UOST_SETGRID
#endif
!/
#ifdef W3_MPI
INCLUDE "mpif.h"
#endif
!/
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
INTEGER, INTENT(IN) :: IMOD, MDS(13), MTRACE(2), &
ODAT(40),NPT, IPRT(6),&
MPI_COMM
LOGICAL, INTENT(IN) :: IsMulti
REAL, INTENT(INOUT) :: XPT(NPT), YPT(NPT)
LOGICAL, INTENT(INOUT) :: FLGRD(NOGRP,NGRPP), FLGD(NOGRP),&
FLGR2(NOGRP,NGRPP), FLG2(NOGRP),&
PRTFRM
CHARACTER, INTENT(IN) :: FEXT*(*)
CHARACTER(LEN=40), INTENT(IN) :: PNAMES(NPT)
LOGICAL, INTENT(IN), OPTIONAL :: FLAGSTIDEIN(4)
INTEGER :: NSEALout, NSEALMout
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
integer :: IRANK, I, ISTAT
INTEGER :: IE, IFL, IFT, IERR, NTTOT, NTLOC, &
NTTARG, IK, IP, ITH, IX, IY, &
J, J0, TOUT(2), TLST(2), ISEA, IS, &
K, I1, I2, JSEA, NTTMAX
#ifdef W3_DIST
INTEGER :: ISTEP, ISP, IW
#endif
#ifdef W3_MPI
INTEGER :: IERR_MPI, BGROUP, LGROUP
#endif
#ifdef W3_S
INTEGER, SAVE :: IENT = 0
#endif
#ifdef W3_T
INTEGER :: NX0, NXN
INTEGER, ALLOCATABLE :: MAPOUT(:,:)
#endif
#ifdef W3_MPI
INTEGER, ALLOCATABLE :: TMPRNK(:)
#endif
INTEGER, ALLOCATABLE :: NT(:), MAPTST(:,:)
#ifdef W3_T
INTEGER, SAVE :: NXS = 49
#endif
REAL :: DTTST, DEPTH, FRACOS
REAL :: FACTOR
REAL :: WLVeff
#ifdef W3_T
REAL, ALLOCATABLE :: XOUT(:,:)
#endif
LOGICAL :: OPENED
CHARACTER(LEN=8) :: STTIME
CHARACTER(LEN=10) :: STDATE
INTEGER :: ISPROC
#ifdef W3_DIST
CHARACTER(LEN=12) :: FORMAT
#endif
CHARACTER(LEN=23) :: DTME21
CHARACTER(LEN=30) :: LFILE, TFILE
#ifdef W3_PDLIB
INTEGER :: IScal(1), IPROC
#endif
integer :: memunit
!/
!/ ------------------------------------------------------------------- /
!
! 1. Set-up of data structures and I/O ----------------------------- /
! 1.a Point to proper data structures.
CALL W3SETO ( IMOD, MDS(2), MDS(3) )
memunit = 10000+IAPROC
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 1a')
CALL W3SETG ( IMOD, MDS(2), MDS(3) )
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 1b')
CALL W3SETW ( IMOD, MDS(2), MDS(3) )
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 1c')
CALL W3SETA ( IMOD, MDS(2), MDS(3) )
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 1d')
CALL W3SETI ( IMOD, MDS(2), MDS(3) )
#ifdef W3_UOST
CALL UOST_SETGRID(IMOD)
#endif
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("Case 2")
#endif
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 1e')
!
!
! 1.b Number of processors and processor number.
! Overwrite some initializations from W3ODATMD.
!
! *******************************************************
! *** NOTE : OUTPUT PROCESSOR ASSIGNMENT NEEDS TO BE ***
! *** CONSISTENT WITH ASSIGNMENT IN WMINIT. ***
! *******************************************************
!
#ifdef W3_SHRD
NTPROC = 1
NAPROC = 1
IAPROC = 1
IOSTYP = 1
#endif
!
#ifdef W3_MPI
MPI_COMM_WAVE = MPI_COMM
CALL MPI_COMM_SIZE ( MPI_COMM_WAVE, NTPROC, IERR_MPI )
NAPROC = NTPROC
CALL MPI_COMM_RANK ( MPI_COMM_WAVE, IAPROC, IERR_MPI )
IAPROC = IAPROC + 1
#endif
memunit = 10000+IAPROC
!
IF ( IOSTYP .LE. 1 ) THEN
!
NAPFLD = MAX(1,NAPROC-1)
NAPPNT = MAX(1,NAPROC-2)
NAPTRK = MAX(1,NAPROC-5)
NAPRST = NAPROC
NAPBPT = MAX(1,NAPROC-3)
NAPPRT = MAX(1,NAPROC-4)
!
ELSE
!
NAPPNT = NAPROC
IF ( UNIPTS .AND. UPPROC ) NAPROC = MAX(1,NTPROC - 1)
NAPFLD = NAPROC
NAPRST = NAPROC
NAPBPT = NAPROC
NAPTRK = NAPROC
NAPPRT = NAPROC
!
IF ( IOSTYP .EQ. 2 ) THEN
NAPROC = MAX(1,NAPROC-1)
ELSE IF ( IOSTYP .EQ. 3 ) THEN
!
! For field or coupling output
!
IF ( ODAT( 3).GT.0 .OR. ODAT(33).GT.0 ) THEN
NAPFLD = NAPROC
NAPROC = MAX(1,NAPROC-1)
END IF
IF ( ODAT(13).GT.0 ) THEN
NAPTRK = NAPROC
NAPROC = MAX(1,NAPROC-1)
END IF
IF ( ODAT(28).GT.0 ) THEN
NAPPRT = NAPROC
NAPROC = MAX(1,NAPROC-1)
END IF
IF ( ODAT( 8).GT.0 ) NAPPNT = NAPROC
IF ( ODAT(18).GT.0 ) NAPRST = NAPROC
IF ( ODAT(23).GT.0 ) NAPBPT = NAPROC
IF ( ( ODAT( 8).GT.0 .OR. ODAT(18).GT.0 .OR. &
ODAT(23).GT.0 ) ) NAPROC = MAX(1,NAPROC-1)
END IF
END IF
!
FRACOS = 100. * REAL(NTPROC-NAPROC) / REAL(NTPROC)
IF ( FRACOS.GT.CRITOS .AND. IAPROC.EQ.NAPERR ) WRITE (NDSE,8002) FRACOS
!
#ifdef W3_MPI
IF ( NAPROC .EQ. NTPROC ) THEN
MPI_COMM_WCMP = MPI_COMM_WAVE
ELSE
CALL MPI_COMM_GROUP ( MPI_COMM_WAVE, BGROUP, IERR_MPI )
ALLOCATE ( TMPRNK(NAPROC) )
DO J=1, NAPROC
TMPRNK(J) = J - 1
END DO
CALL MPI_GROUP_INCL ( BGROUP, NAPROC, TMPRNK, LGROUP, IERR_MPI )
CALL MPI_COMM_CREATE ( MPI_COMM_WAVE, LGROUP, MPI_COMM_WCMP, IERR_MPI )
CALL MPI_GROUP_FREE ( LGROUP, IERR_MPI )
CALL MPI_GROUP_FREE ( BGROUP, IERR_MPI )
DEALLOCATE ( TMPRNK )
END IF
#endif
!
LPDLIB = .FALSE.
#ifdef W3_PDLIB
LPDLIB = .TRUE.
#endif
IF (FSTOTALIMP .and. .NOT. LPDLIB) THEN
WRITE(NDSE,*) 'IMPTOTAL is selected'
WRITE(NDSE,*) 'But PDLIB is not'
CALL FLUSH(NDSE)
STOP
ELSE IF (FSTOTALEXP .and. .NOT. LPDLIB) THEN
WRITE(NDSE,*) 'EXPTOTAL is selected'
WRITE(NDSE,*) 'But PDLIB is not'
CALL FLUSH(NDSE)
STOP
END IF
#ifdef W3_PDLIB
IF (B_JGS_BLOCK_GAUSS_SEIDEL .AND. .NOT. B_JGS_USE_JACOBI) THEN
WRITE(NDSE,*) 'B_JGS_BLOCK_GAUSS_SEIDEL is used but the Jacobi solver is not choosen'
WRITE(NDSE,*) 'Please set JGS_USE_JACOBI .eqv. .true.'
CALL FLUSH(NDSE)
STOP
ENDIF
#endif
!
! 1.c Open files without unpacking MDS ,,,
!
IE = LEN_TRIM(FEXT)
LFILE = 'log.' // FEXT(:IE)
IFL = LEN_TRIM(LFILE)
#ifdef W3_SHRD
TFILE = 'test.' // FEXT(:IE)
#endif
#ifdef W3_DIST
IW = 1 + INT ( LOG10 ( REAL(NAPROC) + 0.5 ) )
IW = MAX ( 3 , MIN ( 9 , IW ) )
WRITE (FORMAT,'(A5,I1.1,A1,I1.1,A4)') &
'(A4,I', IW, '.', IW, ',2A)'
WRITE (TFILE,FORMAT) 'test', &
OUTPTS(IMOD)%IAPROC, '.', FEXT(:IE)
#endif
IFT = LEN_TRIM(TFILE)
J = LEN_TRIM(FNMPRE)
!
#ifndef W3_CESMCOUPLED
IF ( OUTPTS(IMOD)%IAPROC .EQ. OUTPTS(IMOD)%NAPLOG ) &
OPEN (MDS(1),FILE=FNMPRE(:J)//LFILE(:IFL),ERR=888,IOSTAT=IERR)
#endif
!
IF ( MDS(3).NE.MDS(1) .AND. MDS(3).NE.MDS(4) .AND. TSTOUT ) THEN
INQUIRE (MDS(3),OPENED=OPENED)
IF ( .NOT. OPENED ) OPEN (MDS(3),FILE=FNMPRE(:J)//TFILE(:IFT), ERR=889, &
IOSTAT=IERR)
END IF
!
! 1.d Dataset unit numbers
!
NDS = MDS
NDSO = NDS(1)
NDSE = NDS(2)
NDST = NDS(3)
SCREEN = NDS(4)
!
! 1.e Subroutine tracing
!
CALL ITRACE ( MTRACE(1), MTRACE(2) )
!
! 1.f Initial and test outputs
!
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2')
!
IF ( IAPROC .EQ. NAPLOG ) THEN
CALL WWDATE ( STDATE )
CALL WWTIME ( STTIME )
WRITE (NDSO,900) WWVER, STDATE, STTIME
END IF
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2a')
!
#ifdef W3_S
CALL STRACE (IENT, 'W3INIT')
#endif
#ifdef W3_T
WRITE(NDST,9000) IMOD, FEXT(:IE)
WRITE (NDST,9001) NTPROC, NAPROC, IAPROC, NAPLOG, NAPOUT, &
NAPERR, NAPFLD, NAPPNT, NAPTRK, NAPRST, NAPBPT, NAPPRT
WRITE (NDST,9002) NDSO, NDSE, NDST, SCREEN
WRITE (NDST,9003) LFILE(:IFL), TFILE(:IFT)
#endif
!
! 2. Model definition ---------------------------------------------- /
! 2.a Read model definition file
!
CALL W3IOGR ( 'READ', NDS(5), IMOD, FEXT )
IF (GTYPE .eq. UNGTYPE) THEN
CALL SPATIAL_GRID
CALL NVECTRI
CALL COORDMAX
#ifdef W3_PDLIB
IF(.false.) THEN
#endif
CALL AREA_SI(1)
#ifdef W3_PDLIB
ENDIF
#endif
ENDIF
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2b')
#ifdef W3_PDLIB
IF (GTYPE .ne. UNGTYPE) THEN
#endif
#ifdef W3_SETUP
CALL PREPARATION_FD_SCHEME(IMOD)
#endif
#ifdef W3_PDLIB
ELSE
#endif
#ifdef W3_PDLIB
CALL PDLIB_INIT(IMOD)
#endif
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2c')
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("After PDLIB_INIT")
#endif
#ifdef W3_PDLIB
CALL SYNCHRONIZE_IPGL_ETC_ARRAY(IMOD, IsMulti)
#endif
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2cc')
#ifdef W3_PDLIB
END IF
#endif
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2d')
! Update of output parameter flags based on mod_def parameters (for 3D arrays)
CALL W3FLGRDUPDT ( NDSO, NDSE, FLGRD, FLGR2, FLGD, FLG2 )
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("After W3FLGRDUPDT")
#endif
IF ( FLAGLL ) THEN
FACTOR = 1.
ELSE
FACTOR = 1.E-3
END IF
IF ( IAPROC .EQ. NAPLOG ) WRITE (NDSO,920)
!
! 2.b Save MAPSTA
!
ALLOCATE ( MAPTST(NY,NX) )
MAPTST = MAPSTA
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2e')
!
!
! 2.c MPP preparation
! 2.c.1 Set simple counters and variables
!
CALL SET_UP_NSEAL_NSEALM(NSEALout, NSEALMout)
NSEAL = NSEALout
NSEALM = NSEALMout
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2f')
#ifdef W3_DIST
IF ( NSEA .LT. NAPROC ) GOTO 820
IF (LPDLIB .eqv. .FALSE.) THEN
IF ( NSPEC .LT. NAPROC ) GOTO 821
END IF
#endif
#ifdef W3_PDLIB
IF ((IAPROC .LE. NAPROC).and.(GTYPE .eq. UNGTYPE)) THEN
CALL BLOCK_SOLVER_INIT(IMOD)
CALL PDLIB_IOBP_INIT(IMOD)
CALL SET_IOBPA_PDLIB
IF (FSTOTALEXP) THEN
CALL BLOCK_SOLVER_EXPLICIT_INIT()
ENDIF
ENDIF
#endif
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("After BLOCK_SOLVER_INIT")
#endif
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2g')
!
!
! 2.c.2 Allocate arrays
!
IF ( IAPROC .LE. NAPROC ) THEN
CALL W3DIMW ( IMOD, NDSE, NDST )
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2h')
ELSE
CALL W3DIMW ( IMOD, NDSE, NDST, .FALSE. )
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2i')
END IF
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("After W3DIMW")
#endif
CALL W3DIMA ( IMOD, NDSE, NDST )
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 2j')
CALL W3DIMI ( IMOD, NDSE, NDST , FLAGSTIDEIN )
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("After W3DIMI")
#endif
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 3')
!
! 2.c.3 Calculated expected number of prop. calls per processor
!
NTTOT = 0
DO IK=1, NK
NTLOC = 1 + INT(DTMAX/(DTCFL*SIG(IK)/SIG(1))-0.001)
NTTOT = NTTOT + NTLOC*NTH
END DO
NTTARG = 1 + (NTTOT-1)/NAPROC
NTTARG = NTTARG + INT(DTMAX/(DTCFL*SIG(NK)/SIG(1))-0.001)
NTTMAX = NTTARG + 5
!
! 2.c.4 Initialize IAPPRO
!
IAPPRO = 1
ALLOCATE ( NT(NSPEC) )
NT = NTTOT
#ifdef W3_DIST
IF (LPDLIB .eqv. .FALSE.) THEN
!
DO
!
! 2.c.5 First sweep filling IAPPRO
!
DO IP=1, NAPROC
ISTEP = IP
ISP = 0
NT(IP) = 0
DO J=1, 1+NSPEC/NAPROC
ISP = ISP + ISTEP
IF ( MOD(J,2) .EQ. 1 ) THEN
ISTEP = 2*(NAPROC-IP) + 1
ELSE
ISTEP = 2*IP - 1
END IF
IF ( ISP .LE. NSPEC ) THEN
IK = 1 + (ISP-1)/NTH
NTLOC = 1 + INT(DTMAX/(DTCFL*SIG(IK)/SIG(1))-0.001)
IF ( NT(IP)+NTLOC .LE. NTTARG ) THEN
IAPPRO(ISP) = IP
NT(IP) = NT(IP) + NTLOC
ELSE
IAPPRO(ISP) = -1
END IF
END IF
END DO
END DO
!
! 2.c.6 Second sweep filling IAPPRO
!
DO IP=1, NAPROC
IF ( NT(IP) .LT. NTTARG ) THEN
DO ISP=1, NSPEC
IF ( IAPPRO(ISP) .EQ. -1 ) THEN
IK = 1 + (ISP-1)/NTH
NTLOC = 1 + INT(DTMAX/(DTCFL*SIG(IK)/SIG(1))-0.001)
IF ( NT(IP)+NTLOC .LE. NTTARG ) THEN
IAPPRO(ISP) = IP
NT(IP) = NT(IP) + NTLOC
END IF
END IF
END DO
END IF
END DO
!
! 2.c.7 Check if all served
!
IF ( MINVAL(IAPPRO(1:NSPEC)) .GT. 0 ) THEN
EXIT
ELSE
NTTARG = NTTARG + 1
IF ( NTTARG .GE. NTTMAX ) EXIT
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,8028)
END IF
!
END DO
END IF
#endif
!
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("After Case 14")
#endif
! 2.c.8 Test output
!
#ifdef W3_T
WRITE (NDST,9020)
DO IP=1, NAPROC
WRITE (NDST,9021) IP, NT(IP), NTTARG
END DO
!
WRITE (NDST,9025)
DO IK=NK, 1, -1
WRITE (NDST,9026) IK, (IAPPRO(ITH+(IK-1)*NTH),ITH=1,MIN(24,NTH))
IF ( NTH .GT. 24 ) WRITE (NDST,9027) (IAPPRO(ITH+(IK-1)*NTH),ITH=25,NTH)
END DO
#endif
!
! 2.c.9 Test if any spectral points are left out
!
#ifdef W3_DIST
IF (LPDLIB .eqv. .FALSE.) THEN
DO ISP=1, NSPEC
IF ( IAPPRO(ISP) .EQ. -1. ) GOTO 829
END DO
END IF
#endif
DEALLOCATE ( NT )
!
! 3. Model initialization ------------------------------------------- /
! 3.a Read restart file
!
VA(:,:) = 0.
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "Before W3IORS call", 1)
#endif
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("Before W3IORS")
#endif
CALL W3IORS ( 'READ', NDS(6), SIG(NK), IMOD)
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("After W3IORS")
#endif
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 3a')
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "After W3IORS call", 1)
#endif
FLCOLD = RSTYPE.LE.1 .OR. RSTYPE.EQ.4
IF ( IAPROC .EQ. NAPLOG ) THEN
IF (RSTYPE.EQ.0) THEN
WRITE (NDSO,930) 'cold start (idealized).'
ELSE IF ( RSTYPE .EQ. 1 ) THEN
WRITE (NDSO,930) 'cold start (wind).'
ELSE IF ( RSTYPE .EQ. 4 ) THEN
WRITE (NDSO,930) 'cold start (calm).'
ELSE
WRITE (NDSO,930) 'full restart.'
END IF
END IF
#ifdef W3_DEBUGCOH
CALL ALL_VA_INTEGRAL_PRINT(IMOD, "W3INIT, step 4.2", 1)
#endif
#ifdef W3_TIMINGS
CALL PRINT_MY_TIME("After restart inits")
#endif
!
! 3.b Compare MAPSTA from grid and restart
!
DO IX=1, NX
DO IY=1, NY
IF ( ABS(MAPSTA(IY,IX)).EQ.2 .OR. &
ABS(MAPTST(IY,IX)).EQ.2 ) THEN
MAPSTA(IY,IX) = SIGN ( MAPTST(IY,IX) , MAPSTA(IY,IX) )
END IF
END DO
END DO
call print_memcheck(memunit, 'memcheck_____:'//' WW3_INIT SECTION 3b')