forked from NOAA-EMC/WW3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
w3iogrmd.F90
1795 lines (1774 loc) · 62.4 KB
/
w3iogrmd.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 Reading/writing of model definition file.
!>
!> @author H. L. Tolman
!> @author F. Ardhuin
!> @date 15-Apr-2020
!>
#include "w3macros.h"
!/ ------------------------------------------------------------------- /
!>
!> @brief Reading/writing of model definition file.
!>
!> @details Arrays allocated here on read or ing ww3_grid on write.
!>
!> @author H. L. Tolman
!> @author F. Ardhuin
!> @date 15-Apr-2020
!>
MODULE W3IOGRMD
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | H. L. Tolman |
!/ ! F. Ardhuin !
!/ | FORTRAN 90 |
!/ | Last update : 15-Apr-2020 |
!/ +-----------------------------------+
!/
!/ For updates see W3IOGR documentation.
!/
! 1. Purpose :
!
! Reading/writing of model definition file .
!
! 2. Variables and types :
!
! Name Type Scope Description
! ----------------------------------------------------------------
! VERGRD C*10 Private Model definition file version number.
! IDSTR C*35 Private Model definition file ID string.
! ----------------------------------------------------------------
!
! 3. Subroutines and functions :
!
! Name Type Scope Description
! ----------------------------------------------------------------
! W3IOGR Subr. Public Read/write model definition file.
! ----------------------------------------------------------------
!
! 4. Subroutines and functions used :
!
! Name Type Module Description
! ----------------------------------------------------------------
! W3SETG Subr. W3GDATMD Point to data structure for spatial gr.
! W3DIMX Subr. Id. Set up arrays for spatial grid.
! W3DIMS Subr. Id. Set array dimensions for a spec. grid.
! W3SETO Subr. W3ODATMD Point to data structure for spatial gr.
! W3DMO5 Subr. Id. Set array dimensions.
! INPTAB Subr. W3SRC2MD Fill interpolation tables for
! dispersion relation.
! DISTAB Subr. W3DISPMD Input coefficient lookup table.
! INSNL1 Subr. W3SNL1MD Initialization of the DIA.
! INSNL2 Subr. W3SNL2MD Initialization of WRT.
! INSNL3 Subr. W3SNL3MD Initialization of GMD.
! INSNL5 Subr. W3SNL5MD Initialization of GKE.
! INSNLS Subr. W3SNLSMD Initialization of nonlinear `smoother'.
! STRACE Subr. W3SERVMD Subroutine tracing.
! EXTCDE Subr. W3SERVMD Abort program with exit code.
! ----------------------------------------------------------------
!
! 5. Remarks :
!
! - Arrays allocated here on read or ing ww3_grid on write.
!
! 6. Switches :
!
! See subroutine.
!
! 7. Source code :
!
!/ ------------------------------------------------------------------- /
! module default
implicit none
PUBLIC
!/
!/ Private parameter statements (ID strings)
!/
CHARACTER(LEN=10), PARAMETER, PRIVATE :: VERGRD = '2021-08-06'
CHARACTER(LEN=35), PARAMETER, PRIVATE :: &
IDSTR = 'WAVEWATCH III MODEL DEFINITION FILE'
!/
!/ Public variables
!/
!/
CONTAINS
!/ ------------------------------------------------------------------- /
!>
!> @brief Reading and writing of the model definition file.
!>
!> @details The file is opened within the routine, the name is pre-defined
!> and the unit number is given in the parameter list. The model
!> definition file is written using UNFORMATTED write statements.
!>
!> @param[in] INXOUT Test string for read/write.
!> @param[in] NDSM File unit number.
!> @param[in] IMOD Model number for W3GDAT etc.
!> @param[in] FEXT File extension to be used.
!>
!> @author H. L. Tolman
!> @author F. Ardhuin
!> @date 19-Oct-2020
SUBROUTINE W3IOGR ( INXOUT, NDSM, IMOD, FEXT )
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | H. L. Tolman |
!/ ! F. Ardhuin !
!/ | FORTRAN 90 |
!/ | Last update : 19-Oct-2020 |
!/ +-----------------------------------+
!/
!/ 14-Jan-1999 : Distributed FORTRAN 77 version. ( version 1.18 )
!/ 04-Feb-2000 : Upgrade to FORTRAN 90 ( version 2.00 )
!/ Major changes to logistics.
!/ 14-Feb-2000 : Exact-NL added. ( version 2.01 )
!/ 09-Jan-2001 : Flat grid option. ( version 2.06 )
!/ 02-Feb-2001 : Exact-NL version 3.0 ( version 2.07 )
!/ 27-Feb-2001 : Third propagation scheme added. ( version 2.08 )
!/ 16-Mar-2001 : Fourth propagation scheme added. ( version 2.09 )
!/ 29-Mar-2001 : Sub-grid islands added. ( version 2.10 )
!/ 11-Jan-2002 : Sub-grid ice added. ( version 2.15 )
!/ 09-May-2002 : Switch clean up. ( version 2.21 )
!/ 27-Aug-2002 : Exact-NL version 4.0 ( version 2.22 )
!/ 26-Nov-2002 : Adding first VDIA and MDIA. ( version 3.01 )
!/ 01-Aug-2003 : Adding moving grid GSE correction. ( version 3.03 )
!/ 08-Mar-2004 : Multiple grid version. ( version 3.06 )
!/ 04-May-2005 : Change to MPI_COMM_WAVE. ( version 3.07 )
!/ 24-Jun-2005 : Add MAPST2 processing. ( version 3.07 )
!/ 09-Nov-2005 : Remove soft boundary options. ( version 3.08 )
!/ 23-Jun-2006 : Add W3SLN1 parameters. ( version 3.09 )
!/ 27-Jun-2006 : Adding file name preamble. ( version 3.09 )
!/ 25-Jul-2006 : Reorder for 'GRID' option to read ( version 3.10 )
!/ spectral data also.
!/ 28-Oct-2006 : Add partitioning pars. ( version 3.10 )
!/ 26-Mar-2007 : Add partitioning pars. ( version 3.11 )
!/ 16-Apr-2006 : Add Miche limiter pars. ( version 3.11 )
!/ 25-Apr-2007 : Adding Battjes-Janssen Sdb. ( version 3.11 )
!/ 09-Oct-2007 : Adding WAM cycle 4+ Sin and Sds. ( version 3.13 )
!/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
!/ 30-Oct-2009 : Fix ndst arg in call to w3dmo5. ( version 3.14 )
!/ (T. J. Campbell, NRL)
!/ 30-Oct-2009 : Implement curvilinear grid type. ( version 3.14 )
!/ (W. E. Rogers & T. J. Campbell, NRL)
!/ 23-Dec-2009 : Addition of COU namelists ( version 3.14 )
!/ 31-Oct-2010 : Implement unstructured grids ( version 3.14 )
!/ (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)
!/ 12-Jun-2012 : Add /RTD option or rotated grid option.
!/ (Jian-Guo Li) ( version 4.06 )
!/ 13-Jul-2012 : Move GMD (SNL3) and nonlinear filter (SNLS)
!/ from 3.15 (HLT). ( version 4.08 )
!/ 12-Dec-2012 : Adding SMC grid. JG_Li ( version 4.08 )
!/ 19-Dec-2012 : Add NOSWLL to file. ( version 4.11 )
!/ 01-Jul-2013 : Document UQ / UNO switches in file ( version 4.12 )
!/ 10-Sep-2013 : Add IG1 parameters ( version 4.12 )
!/ 16-Sep-2013 : Add Arctic part in SMC grid. ( version 4.12 )
!/ 11-Nov-2013 : Make SMC and RTD grids compatible. ( version 4.13 )
!/ 06-Mar-2014 : Writes out a help message on error ( version 4.18 )
!/ 10-Mar-2014 : Add IC2 parameters ( version 5.01 )
!/ 29-May-2014 : Add IC3 parameters ( version 5.01 )
!/ 20-Aug-2016 : Add IOBPA ( version 5.12 )
!/ 08-Mar-2018 : Add FSWND for SMC grid. ( version 6.02 )
!/ 05-Jun-2018 : Add PDLIB/DEBUGINIT and implcit scheme parameters
!/ for unstructured grids ( version 6.04 )
!/ 27-Jul-2018 : Added PTMETH and PTFCUT parameters ( version 6.05 )
!/ (C. Bunney, UKMO)
!/ 18-Aug-2018 : S_{ice} IC5 (Q. Liu) ( version 6.06 )
!/ 26-Aug-2018 : UOST (Mentaschi et al. 2015, 2018) ( version 6.06 )
!/ 15-Apr-2020 : Adds optional opt-out for CFL on BC ( version 7.08 )
!/ 18-Jun-2020 : Adds 360-day calendar option ( version 7.08 )
!/ 19-Oct-2020 : Add AIRCMIN, AIRGB parameters ( version 7.08 )
!/ 07-07-2021 : S_{nl} GKE NL5 (Q. Liu) ( version 7.12 )
!/ 19-Jul-2021 : Momentum and air density support ( version 7.14 )
!/
!/ 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.
!/
! 1. Purpose :
!
! Reading and writing of the model definition file.
!
! 2. Method :
!
! The file is opened within the routine, the name is pre-defined
! and the unit number is given in the parameter list. The model
! definition file is written using UNFORMATTED write statements.
!
! 3. Parameters :
!
! Parameter list
! ----------------------------------------------------------------
! INXOUT C*(*) I Test string for read/write, valid are:
! 'READ', 'WRITE' and 'GRID'.
! NDSM Int. I File unit number.
! IMOD Int. I Model number for W3GDAT etc.
! FEXT C*(*) I File extension to be used.
! ----------------------------------------------------------------
!
! 4. Subroutines used :
!
! See above.
!
! 5. Called by :
!
! Name Type Module Description
! ----------------------------------------------------------------
! W3INIT Subr. W3INITMD Wave model initialization routine.
! ...... Prog. N/A All WAVEWATCH III aux programs and
! drivers.
! ----------------------------------------------------------------
!
! 6. Error messages :
!
! Tests on INXOUT, file status and on array dimensions.
!
! 7. Remarks :
!
! - The model definition file has the pre-defined name
! 'mod_def.FILEXT'.
!
! 8. Structure :
!
! See source code.
!
! 9. Switches :
!
! !/MPI MPI calls
!
! !/LNn Select source terms
! !/STn
! !/NLn
! !/BTn
! !/DBn
! !/TRn
! !/BSn
! !/XXn
!
! !/S Enable subroutine tracing.
! !/T Enable test output
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
use w3servmd, only : print_memcheck
USE CONSTANTS
USE W3GDATMD
#ifdef W3_MPI
USE W3ADATMD, ONLY: MPI_COMM_WAVE
#endif
USE W3ODATMD
#ifdef W3_ST2
USE W3SRC2MD, ONLY: INPTAB
#endif
#ifdef W3_ST3
USE W3SRC3MD, ONLY: INSIN3
#endif
#ifdef W3_ST4
USE W3SRC4MD, ONLY: INSIN4, TAUT, TAUHFT, TAUHFT2, &
DELU, DELTAUW, DELUST, &
DELALP, DELTAIL, &
DIKCUMUL
#endif
#ifdef W3_NL1
USE W3SNL1MD, ONLY: INSNL1
#endif
#ifdef W3_NL2
USE W3SNL2MD, ONLY: INSNL2
#endif
#ifdef W3_NL3
USE W3SNL3MD, ONLY: INSNL3
#endif
#ifdef W3_NL5
USE W3SNL5MD, ONLY: INSNL5
#endif
#ifdef W3_NLS
USE W3SNLSMD, ONLY: INSNLS
#endif
#ifdef W3_IS2
USE W3SIS2MD, ONLY: INSIS2
#endif
USE W3TIMEMD, ONLY: CALTYPE
USE W3SERVMD, ONLY: EXTCDE
#ifdef W3_S
USE W3SERVMD, ONLY: STRACE
#endif
USE W3DISPMD
#ifdef W3_UOST
USE W3UOSTMD, ONLY: UOST_INITGRID
#endif
!
#ifdef W3_MPI
INCLUDE "mpif.h"
#endif
!/
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
INTEGER, INTENT(IN) :: NDSM
INTEGER, INTENT(IN), OPTIONAL :: IMOD
CHARACTER, INTENT(IN) :: INXOUT*(*)
CHARACTER, INTENT(IN), OPTIONAL :: FEXT*(*)
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
INTEGER :: IGRD, IERR, I, J, MTH, MK, ISEA, IX, IY
INTEGER :: IEXT, IPRE
#ifdef W3_ST4
INTEGER :: IK, ITH, IK2, ITH2
#endif
INTEGER, ALLOCATABLE :: MAPTMP(:,:)
#ifdef W3_MPI
INTEGER :: IERR_MPI, IP
#endif
#ifdef W3_S
INTEGER, SAVE :: IENT = 0
#endif
#ifdef W3_T
INTEGER :: K
#endif
LOGICAL :: WRITE, FLTEST = .FALSE., TESTLL, &
FLSNL2 = .FALSE.
LOGICAL, SAVE :: FLINP = .FALSE. , FLDISP = .FALSE., &
FLIS = .FALSE.
CHARACTER(LEN=10) :: VERTST
CHARACTER(LEN=13) :: TEMPXT
CHARACTER(LEN=30) :: TNAME0, TNAME1, TNAME2, TNAME3, &
TNAME4, TNAME5, TNAME6, &
TNAMEP, TNAMEG, TNAMEF, TNAMEI
CHARACTER(LEN=30) :: FNAME0, FNAME1, FNAME2, FNAME3, &
FNAME4, FNAME5, FNAME6, &
FNAMEP, FNAMEG, FNAMEF, FNAMEI
CHARACTER(LEN=35) :: IDTST
CHARACTER(LEN=60) :: MESSAGE(5)
LOGICAL :: GLOBAL
REAL, ALLOCATABLE :: XGRD4(:,:), YGRD4(:,:)
integer :: memunit
!/
!/ ------------------------------------------------------------------- /
!/
memunit = 740+IAPROC
#ifdef W3_S
CALL STRACE (IENT, 'W3IOGR')
#endif
!
call print_memcheck(memunit, 'memcheck_____:'//' WIOGR SECTION 1')
MESSAGE =(/ ' MOD DEF FILE WAS GENERATED WITH A DIFFERENT ', &
' WW3 VERSION OR USING A DIFFERENT SWITCH FILE. ', &
' MAKE SURE WW3_GRID IS COMPILED WITH SAME SWITCH', &
' AS WW3_SHEL OR WW3_MULTI, RUN WW3_GRID AGAIN ', &
' AND THEN TRY AGAIN THE PROGRAM YOU JUST USED. '/)
!
TNAMEF = '------------------------------'
TNAME0 = '------------------------------'
TNAME1 = '------------------------------'
TNAME2 = '------------------------------'
TNAME3 = '------------------------------'
TNAME4 = '------------------------------'
TNAME5 = '------------------------------'
TNAME6 = '------------------------------'
TNAMEP = '------------------------------'
TNAMEG = '------------------------------'
TNAMEI = '------------------------------'
!
#ifdef W3_FLX1
TNAMEF = 'Wu (1980) '
#endif
#ifdef W3_FLX2
TNAMEF = 'Tolman and Chalikov (1996) '
#endif
#ifdef W3_FLX3
TNAMEF = 'T and C(1996) with cap on Cd '
#endif
#ifdef W3_FLX4
TNAMEF = 'Hwang (2011) with cap on Cd '
#endif
#ifdef W3_FLX5
TNAMEF = 'Direct use of stress '
#endif
#ifdef W3_LN0
TNAME0 = 'Not defined '
#endif
#ifdef W3_LN1
TNAME0 = 'Cavaleri and M.-R. (1982) '
#endif
#ifdef W3_ST0
TNAME1 = 'Not defined '
#endif
#ifdef W3_ST1
TNAME1 = 'WAM cycles 1 through 3 '
#endif
#ifdef W3_ST2
TNAME1 = 'Tolman and Chalikov (1996) '
#endif
#ifdef W3_ST3
TNAME1 = 'WAM cycle 4+ '
#endif
#ifdef W3_ST4
TNAME1 = 'Ardhuin et al. (2009+) '
#endif
#ifdef W3_ST6
TNAME1 = 'BYDB input and dissipation '
#endif
#ifdef W3_NL0
TNAME2 = 'Not defined '
#endif
#ifdef W3_NL1
TNAME2 = 'Discrete Interaction Approx. '
#endif
#ifdef W3_NL2
TNAME2 = 'Exact nonlinear interactions '
#endif
#ifdef W3_NL3
TNAME2 = 'Generalized Multiple DIA '
#endif
#ifdef W3_NL4
TNAME2 = 'Two Scaled Approximation '
#endif
#ifdef W3_NL5
TNAME2 = 'Generalized Kinetic Equation '
#endif
#ifdef W3_BT0
TNAME3 = 'Not defined '
#endif
#ifdef W3_BT1
TNAME3 = 'JONSWAP '
#endif
#ifdef W3_BT4
TNAME3 = 'SHOWEX '
#endif
#ifdef W3_BT8
TNAME3 = 'Muddy Bed (D & L) '
#endif
#ifdef W3_IC1
TNAMEI = 'Ice sink term (uniform k_i) '
#endif
#ifdef W3_IC2
TNAMEI = 'Ice sink term (Lui et al) '
#endif
#ifdef W3_IC3
TNAMEI = 'Ice sink term (Wang and Shen) '
#endif
#ifdef W3_IC4
TNAMEI = 'Ice sink term (empirical) '
#endif
#ifdef W3_IC5
TNAMEI = 'Ice sink term (eff. medium) '
#endif
#ifdef W3_DB0
TNAME4 = 'Not defined '
#endif
#ifdef W3_DB1
TNAME4 = 'Battjes and Janssen (1978) '
#endif
#ifdef W3_TR0
TNAME5 = 'Not defined '
#endif
#ifdef W3_BS0
TNAME6 = 'Not defined '
#endif
#ifdef W3_PR0
TNAMEP = 'No propagation '
#endif
#ifdef W3_PR1
TNAMEP = 'First order upstream '
#endif
#ifdef W3_UQ
TNAMEP = '3rd order UQ scheme '
#endif
#ifdef W3_UNO
TNAMEP = '2nd order UNO scheme '
#endif
#ifdef W3_PR0
TNAMEG = 'No GSE aleviation '
#endif
#ifdef W3_PR1
TNAMEG = 'No GSE aleviation (1up prop) '
#endif
#ifdef W3_PR2
TNAMEG = 'Diffusion operator '
#endif
#ifdef W3_PR3
TNAMEG = 'Averaging operator '
#endif
!
FNAMEF = TNAMEF
FNAME0 = TNAME0
FNAME1 = TNAME1
FNAME2 = TNAME2
FNAME3 = TNAME3
FNAME4 = TNAME4
FNAME5 = TNAME5
FNAME6 = TNAME6
FNAMEP = TNAMEP
FNAMEG = TNAMEG
FNAMEI = TNAMEI
!
#ifdef W3_T
FLTEST = .TRUE.
#endif
#ifdef W3_NL2
FLSNL2 = .TRUE.
#endif
!
! test input parameters ---------------------------------------------- *
!
IF ( PRESENT(IMOD) ) THEN
IGRD = IMOD
ELSE
IGRD = 1
END IF
!
IF ( PRESENT(FEXT) ) THEN
TEMPXT = FEXT
ELSE
TEMPXT = 'ww3'
END IF
!
IF (INXOUT.NE.'READ' .AND. INXOUT.NE.'WRITE' &
.AND. INXOUT.NE.'GRID') THEN
IF ( IAPROC .EQ. NAPERR ) WRITE (NDSE,900) INXOUT
CALL EXTCDE ( 1 )
END IF
!
WRITE = INXOUT .EQ. 'WRITE'
!
#ifdef W3_T
WRITE (NDST,9000) INXOUT, WRITE, NDSM, IGRD, TEMPXT
#endif
!
CALL W3SETO ( IGRD, NDSE, NDST )
CALL W3SETG ( IGRD, NDSE, NDST )
FILEXT = TEMPXT
call print_memcheck(memunit, 'memcheck_____:'//' WIOGR SECTION 2')
!
! open file ---------------------------------------------------------- *
!
IEXT = LEN_TRIM(FILEXT)
IPRE = LEN_TRIM(FNMPRE)
!
!AR: ADD DEBUGFLAG WRITE(*,*) 'FILE=', FNMPRE(:IPRE)//'mod_def.'//FILEXT(:IEXT)
IF ( WRITE ) THEN
OPEN (NDSM,FILE=FNMPRE(:IPRE)//'mod_def.'//FILEXT(:IEXT), &
form='UNFORMATTED', convert=file_endian,ERR=800,IOSTAT=IERR)
ELSE
OPEN (NDSM,FILE=FNMPRE(:IPRE)//'mod_def.'//FILEXT(:IEXT), &
form='UNFORMATTED', convert=file_endian,STATUS='OLD',ERR=800,IOSTAT=IERR)
ENDIF
!
REWIND ( NDSM )
!
! Dimensions and test information --------------------------------------
!
IF ( WRITE ) THEN
WRITE (NDSM) &
IDSTR, VERGRD, NX, NY, NSEA, NTH, NK, &
NBI, NFBPO, GNAME, FNAME0, FNAME1, FNAME2, FNAME3, &
FNAME4, FNAME5, FNAME6, FNAMEP, FNAMEG, &
FNAMEF, FNAMEI
!
#ifdef W3_SMC
WRITE (NDSM) NCel, NUFc, NVFc, NRLv, MRFct
WRITE (NDSM) NGLO, NARC, NBGL, NBAC, NBSMC
#endif
!
WRITE (NDSM) &
(NBO(I),I=0,NFBPO), (NBO2(I),I=0,NFBPO)
#ifdef W3_T
WRITE (NDST,9001) IDSTR, VERGRD, NX, NY, NSEA, NTH, NK, &
NBI, NFBPO, 9, GNAME, FNAME0, FNAME1, FNAME2, FNAME3, &
FNAME4, FNAME5, FNAME6, FNAMEP, FNAMEG, &
FNAMEF, FNAMEI
WRITE (NDST,9002) (NBO(I),I=0,NFBPO)
WRITE (NDST,9003) (NBO2(I),I=0,NFBPO)
#endif
ELSE
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
IDTST, VERTST, NX, NY, NSEA, MTH, MK, &
NBI, NFBPO, GNAME, FNAME0, FNAME1, FNAME2, FNAME3, &
FNAME4, FNAME5, FNAME6, FNAMEP, FNAMEG, &
FNAMEF, FNAMEI
!
#ifdef W3_SMC
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
NCel, NUFc, NVFc, NRLv, MRFct
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
NGLO, NARC, NBGL, NBAC, NBSMC
#endif
!
NK = MK
NTH = MTH
NK2 = NK + 2
NSPEC = NK * NTH
#ifdef W3_T
WRITE (NDST,9001) IDSTR, VERGRD, NX, NY, NSEA, NTH, NK, &
NBI, NFBPO, 9, GNAME, FNAME0, FNAME1, FNAME2, FNAME3, &
FNAME4, FNAME5, FNAME6, FNAMEP, FNAMEG, &
FNAMEF, FNAMEI
#endif
!
IF ( IDTST .NE. IDSTR ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,901) IDTST, IDSTR
CALL EXTCDE ( 10 )
END IF
IF ( VERTST .NE. VERGRD ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,902) VERTST, VERGRD
CALL EXTCDE ( 11 )
END IF
IF ( NFBPO .GT. 9 ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,904) NFBPO, 9
CALL EXTCDE ( 13 )
END IF
IF ( FNAME0 .NE. TNAME0 ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,905) 0, FILEXT(:IEXT), FNAME0, TNAME0, &
MESSAGE
CALL EXTCDE ( 14 )
END IF
IF ( FNAME1 .NE. TNAME1 ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,905) 1, FILEXT(:IEXT), FNAME1, TNAME1, &
MESSAGE
CALL EXTCDE ( 15 )
END IF
IF ( FNAME2 .NE. TNAME2 ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,905) 2, FILEXT(:IEXT), FNAME2, TNAME2, &
MESSAGE
CALL EXTCDE ( 16 )
END IF
IF ( FNAME3 .NE. TNAME3 ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,905) 3, FILEXT(:IEXT), FNAME3, TNAME3, &
MESSAGE
CALL EXTCDE ( 17 )
END IF
IF ( FNAMEI .NE. TNAMEI ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,905) 3, FILEXT(:IEXT), FNAMEI, TNAMEI, &
MESSAGE
CALL EXTCDE ( 17 )
END IF
IF ( FNAME4 .NE. TNAME4 ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,905) 4, FILEXT(:IEXT), FNAME4, TNAME4, &
MESSAGE
CALL EXTCDE ( 18 )
END IF
IF ( FNAME5 .NE. TNAME5 ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,905) 5, FILEXT(:IEXT), FNAME5, TNAME5, &
MESSAGE
CALL EXTCDE ( 19 )
END IF
IF ( FNAME6 .NE. TNAME6 ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,905) 6, FILEXT(:IEXT), FNAME6, TNAME6, &
MESSAGE
CALL EXTCDE ( 20 )
END IF
IF ( FNAMEP .NE. TNAMEP ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,906) FNAMEP, TNAMEP
CALL EXTCDE ( 22 )
END IF
IF ( FNAMEG .NE. TNAMEG ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,907) FNAMEG, TNAMEG, MESSAGE
CALL EXTCDE ( 22 )
END IF
IF ( FNAMEF .NE. TNAMEF ) THEN
IF ( IAPROC .EQ. NAPERR ) &
WRITE (NDSE,908) FILEXT(:IEXT), FNAMEF, TNAMEF, MESSAGE
CALL EXTCDE ( 24 )
END IF
!
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
(NBO(I),I=0,NFBPO), (NBO2(I),I=0,NFBPO)
#ifdef W3_T
WRITE (NDST,9002) (NBO(I),I=0,NFBPO)
WRITE (NDST,9003) (NBO2(I),I=0,NFBPO)
#endif
!
ENDIF
call print_memcheck(memunit, 'memcheck_____:'//' WIOGR SECTION 3')
!
! Parameters in modules --------------------------------------------- *
! Module W3GDAT GRID
!
ALLOCATE ( MAPTMP(NY,NX) )
!
IF ( WRITE ) THEN
MAPTMP = MAPSTA + 8*MAPST2
WRITE (NDSM) &
GTYPE, FLAGLL, ICLOSE
!
! Writes different kind of information depending on grid type
!
SELECT CASE ( GTYPE )
!!Li SMCTYPE shares info with RLGTYPE. JGLi12Oct2020
CASE ( RLGTYPE, SMCTYPE )
WRITE (NDSM) &
SX, SY, X0, Y0
CASE ( CLGTYPE )
WRITE (NDSM) &
REAL(XGRD), REAL(YGRD)
CASE (UNGTYPE)
WRITE (NDSM) &
FSN, FSPSI,FSFCT,FSNIMP,FSTOTALIMP,FSTOTALEXP, &
FSBCCFL, FSREFRACTION, FSFREQSHIFT, FSSOURCE, &
DO_CHANGE_WLV, SOLVERTHR_STP, CRIT_DEP_STP, &
NTRI,COUNTOT, COUNTRI, NNZ, &
B_JGS_TERMINATE_MAXITER, &
B_JGS_TERMINATE_DIFFERENCE, &
B_JGS_TERMINATE_NORM, &
B_JGS_LIMITER, &
B_JGS_BLOCK_GAUSS_SEIDEL, &
B_JGS_USE_JACOBI, &
B_JGS_MAXITER, &
B_JGS_PMIN, &
B_JGS_DIFF_THR, &
B_JGS_NORM_THR, &
B_JGS_NLEVEL, &
B_JGS_SOURCE_NONLINEAR
!Init COUNTCON and IOBDP to zero, it needs to be set somewhere or
!removed
COUNTCON=0
IOBDP=0
WRITE (NDSM) &
X0, Y0, SX, SY, DXYMAX, XGRD, YGRD, TRIGP, TRIA, &
LEN, IEN, ANGLE0, ANGLE, SI, MAXX, MAXY, &
DXYMAX, INDEX_CELL, CCON, COUNTCON, IE_CELL, &
POS_CELL, IOBP, IOBPA, IOBDP, IOBPD, IAA, JAA, POSI
END SELECT !GTYPE
!
WRITE (NDSM) &
ZB, MAPTMP, MAPFS, MAPSF, TRFLAG
!
#ifdef W3_SMC
IF( GTYPE .EQ. SMCTYPE ) THEN
WRITE (NDSM) NLvCel, NLvUFc, NLvVFc
WRITE (NDSM) IJKCel, IJKUFc, IJKVFc, ISMCBP
WRITE (NDSM) ICLBAC
WRITE (NDSM) ANGARC
WRITE (NDSM) CTRNX, CTRNY, CLATF
IF ( FLTEST ) THEN
WRITE (NDSE,"(' NRLv, MRFct and NBSMC values are',3I9)") NRLv, MRFct, NBSMC
WRITE (NDSE,"(' IJKCel, IJKUFc, IJKVFc Write for',3I9)") NCel, NUFc, NVFc
WRITE (NDSE,"(' CTRNXY transparency write for 2x', I9)") NCel
ENDIF
ENDIF
#endif
!
IF ( TRFLAG .NE. 0 ) WRITE (NDSM) TRNX, TRNY
WRITE (NDSM) &
DTCFL, DTCFLI, DTMAX, DTMIN, DMIN, CTMAX, &
FICE0, FICEN, FICEL, PFMOVE, FLDRY, FLCX, FLCY, FLCTH, &
FLCK, FLSOU, FLBPI, FLBPO, CLATS, CLATIS, CTHG0S, &
STEXU, STEYU, STEDU, IICEHMIN, IICEHINIT, IICEDISP, &
ICESCALES(1:4), CALTYPE, CMPRTRCK, IICEHFAC, IICEHDISP,&
IICEDDISP, IICEFDISP, BTBETA, &
AAIRCMIN, AAIRGB
WRITE(NDSM)GRIDSHIFT
#ifdef W3_SEC1
WRITE (NDSM) NITERSEC1
#endif
#ifdef W3_RTD
!! Add rotated Polat/lon and AnglD to mod_def JGLi12Jun2012
WRITE (NDSM) PoLat, PoLon, AnglD, FLAGUNR
#endif
!! WRITE(NDSM) &
!! COUG_2D, COUG_RAD3D, COUG_US3D
ELSE
call print_memcheck(memunit, 'memcheck_____:'//' WIOGR SECTION 4')
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
GTYPE, FLAGLL, ICLOSE
!!Li IF (.NOT.GINIT) CALL W3DIMX ( IGRD, NX, NY, NSEA, NDSE, NDST )
IF (.NOT.GINIT) CALL W3DIMX ( IGRD, NX, NY, NSEA, NDSE, NDST &
#ifdef W3_SMC
, NCel, NUFc, NVFc, NRLv, NBSMC &
, NARC, NBAC, NSPEC &
#endif
)
!
! Reads different kind of information depending on grid type
!
SELECT CASE ( GTYPE )
!!Li SMCTYPE shares info with RLGTYPE. JGLi12Oct2020
CASE ( RLGTYPE, SMCTYPE )
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
SX, SY, X0, Y0
DO IX=1,NX
XGRD(:,IX) = REAL(X0 + REAL(IX-1)*SX)
END DO
DO IY=1,NY
YGRD(IY,:) = REAL(Y0 + REAL(IY-1)*SY)
END DO
CASE ( CLGTYPE )
ALLOCATE(XGRD4(NY,NX),YGRD4(NY,NX)); XGRD4 = 0.; YGRD4 = 0.
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
XGRD4, YGRD4
XGRD = XGRD4
YGRD = YGRD4
DEALLOCATE(XGRD4, YGRD4)
!Set SX, SY, X0, Y0 to large values if curvilinear grid
X0 = HUGE(X0); Y0 = HUGE(Y0)
SX = HUGE(SX); SY = HUGE(SY)
CASE (UNGTYPE)
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
FSN, FSPSI,FSFCT,FSNIMP,FSTOTALIMP,FSTOTALEXP, &
FSBCCFL, FSREFRACTION, FSFREQSHIFT, FSSOURCE, &
DO_CHANGE_WLV, SOLVERTHR_STP, CRIT_DEP_STP, &
NTRI,COUNTOT, COUNTRI, NNZ, &
B_JGS_TERMINATE_MAXITER, &
B_JGS_TERMINATE_DIFFERENCE, &
B_JGS_TERMINATE_NORM, &
B_JGS_LIMITER, &
B_JGS_BLOCK_GAUSS_SEIDEL, &
B_JGS_USE_JACOBI, &
B_JGS_MAXITER, &
B_JGS_PMIN, &
B_JGS_DIFF_THR, &
B_JGS_NORM_THR, &
B_JGS_NLEVEL, &
B_JGS_SOURCE_NONLINEAR
IF (.NOT. GUGINIT) THEN
CALL W3DIMUG ( IGRD, NTRI, NX, COUNTOT, NNZ, NDSE, NDST )
END IF
call print_memcheck(memunit, 'memcheck_____:'//' WIOGR SECTION 5')
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
X0, Y0, SX, SY, DXYMAX, XGRD, YGRD, TRIGP, TRIA, &
LEN, IEN, ANGLE0, ANGLE, SI, MAXX, MAXY, &
DXYMAX, INDEX_CELL, CCON, COUNTCON, IE_CELL, &
POS_CELL, IOBP, IOBPA, IOBDP, IOBPD, IAA, JAA, POSI
call print_memcheck(memunit, 'memcheck_____:'//' WIOGR SECTION 6')
END SELECT !GTYPE
!
IF (GTYPE.NE.UNGTYPE) CALL W3GNTX ( IGRD, NDSE, NDST )
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
ZB, MAPTMP, MAPFS, MAPSF, TRFLAG
!
#ifdef W3_SMC
IF( GTYPE .EQ. SMCTYPE ) THEN
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
NLvCel, NLvUFc, NLvVFc
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
IJKCel, IJKUFc, IJKVFc, ISMCBP
DO J=lbound(IJKCel,2), ubound(IJKCel,2)
IJKCel3(J) = IJKCel(3,J)
IJKCel4(J) = IJKCel(4,J)
END DO
DO J=lbound(IJKVFc,2), ubound(IJKVFc,2)
IJKVFc5(J) = IJKVFc(5,J)
IJKVFc6(J) = IJKVFc(6,J)
END DO
DO J=lbound(IJKUFc,2), ubound(IJKUFc,2)
IJKUFc5(J) = IJKUFc(5,J)
IJKUFc6(J) = IJKUFc(6,J)
END DO
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
ICLBAC
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
ANGARC
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
CTRNX, CTRNY, CLATF
ENDIF
#endif
!
MAPSTA = MOD(MAPTMP+2,8) - 2
MAPST2 = (MAPTMP-MAPSTA) / 8
MAPSF(:,3) = MAPSF(:,2) + (MAPSF(:,1)-1)*NY
IF ( TRFLAG .NE. 0 ) THEN
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) TRNX, TRNY
END IF
#ifdef W3_UOST
! UOST (Unresolved Obstacles Source Term) is enabled.
! setting TRNX, TRNY to null values
TRNX = 1
TRNY = 1
#endif
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
DTCFL, DTCFLI, DTMAX, DTMIN, DMIN, CTMAX, &
FICE0, FICEN, FICEL, PFMOVE, FLDRY, FLCX, FLCY, &
FLCTH, FLCK, FLSOU, FLBPI, FLBPO, CLATS, CLATIS, &
CTHG0S, STEXU, STEYU, STEDU, IICEHMIN, IICEHINIT, &
IICEDISP, ICESCALES(1:4), CALTYPE, CMPRTRCK, IICEHFAC, &
IICEDDISP, IICEHDISP, IICEFDISP, BTBETA, &
AAIRCMIN, AAIRGB
READ(NDSM,END=801,ERR=802,IOSTAT=IERR)GRIDSHIFT
#ifdef W3_SEC1
READ (NDSM) NITERSEC1
#endif
!
#ifdef W3_RTD
!! Read rotated Polat/lon and AnglD from mod_def JGLi12Jun2012
READ (NDSM) PoLat, PoLon, AnglD, FLAGUNR
#endif
!
END IF
call print_memcheck(memunit, 'memcheck_____:'//' WIOGR SECTION 7')
!
#ifdef W3_T
WRITE (NDST,9010) GTYPE, FLAGLL, ICLOSE, SX, SY, X0, Y0, TRFLAG
WRITE (NDST,9011) 'MAPSTA'
DO IY=MIN(NY,20), 1, -1
WRITE (NDST,9012) (MAPSTA(IY,IX),IX=1,MIN(NX,30))
END DO
WRITE (NDST,9011) 'MAPST2'
DO IY=MIN(NY,20), 1, -1
WRITE (NDST,9012) (MAPST2(IY,IX),IX=1,MIN(NX,30))
END DO
WRITE (NDST,9011) 'MAPFS'
DO IY=MIN(NY,20), 1, -1
WRITE (NDST,9013) (MAPFS(IY,IX),IX=1,MIN(NX,12))
END DO
IF ( TRFLAG .NE. 0 ) THEN
WRITE (NDST,9011) 'TRNX'
DO IY=MIN(NY,20), 1, -1
WRITE (NDST,9014) (TRNX(IY,IX),IX=1,MIN(NX,12))
END DO
WRITE (NDST,9011) 'TRNY'
DO IY=MIN(NY,20), 1, -1
WRITE (NDST,9014) (TRNY(IY,IX),IX=1,MIN(NX,12))
END DO
END IF
#endif
!
DEALLOCATE ( MAPTMP )
!
#ifdef W3_T
WRITE (NDST,9015) DTCFL, DTCFLI, DTMAX, DTMIN, &
DMIN, CTMAX, FICE0, FICEN, FICEL, PFMOVE, &
STEXU, STEYU, STEDU
WRITE (NDST,9016) FLDRY, FLCX, FLCY, FLCTH, FLCK, &
FLSOU, FLBPI, FLBPO
WRITE (NDST,9017) (CLATS(ISEA),ISEA=1,1), &
(CLATIS(ISEA),ISEA=1,1), (CTHG0S(IY),ISEA=1,1)
#endif
!
! Spectral parameters ------------------------------------------------ *
! Module W3GDATMD SGRD
!
IF ( WRITE ) THEN
WRITE (NDSM) &
MAPWN, MAPTH, DTH, TH, ESIN, ECOS, ES2, ESC, EC2, &
XFR, FR1, SIG, SIG2, DSIP, DSII, DDEN, DDEN2, FTE, &
FTF, FTWN, FTTR, FTWL, FACTI1, FACTI2, FACHFA, FACHFE
ELSE
IF (.NOT.SINIT) CALL W3DIMS ( IGRD, NK, NTH, NDSE, NDST )
READ (NDSM,END=801,ERR=802,IOSTAT=IERR) &
MAPWN, MAPTH, DTH, TH, ESIN, ECOS, ES2, ESC, EC2, &
XFR, FR1, SIG, SIG2, DSIP, DSII, DDEN, DDEN2, FTE, &
FTF, FTWN, FTTR, FTWL, FACTI1, FACTI2, FACHFA, FACHFE
END IF
!
#ifdef W3_T
WRITE (NDST,9030) (MAPWN(I),I=1,8), (MAPTH(I),I=1,8), DTH*RADE, &
(TH(I)*RADE,I=1,4), (ESIN(I),I=1,4), (ECOS(I),I=1,4), &
XFR, SIG(1)*TPIINV, SIG(NK)*TPIINV, FTE, FTF, FTWN, FTTR, &
FTWL, FACTI1, FACTI2, FACHFA, FACHFE
#endif
!
! Langmuir mixing parameterization --------------
IF ( WRITE ) THEN
WRITE (NDSM) &
LMPENABLED, SDTAIL, HSLMODE
ELSE