-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwwm_snl4_tsa.F90
4743 lines (4733 loc) · 204 KB
/
wwm_snl4_tsa.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
#include "wwm_functions.h"
!!
!! -----------------------------------------------------------------#
!! !
!! filename = "m0_sboltz_7r3_1_1e" in ~/msm/TSA/subrs7r3_99_m/ !
!! from "sbtsa-1-norm-Dec15-08.f-7r3" in same dir. !
!! for "w3snlxmd.ftn-NLX-7r3-TSA2-99-1-1e" !
!! used for both FBI and TSA !
!! Bash Toulany !
!! -----------------------------------------------------------------#
!!
!!op2
!!
!! Define nsep as the min # of bins that separates npk & npk2
!! and nbins as the min # of bins > npk or npk2
!! to guarantee 1 bin in equi. range
!! then nbins1 as the actual # of bins > npk or npk2
!!
!! nsep = 1
!! nbins = 1
!! nbins1 = nfs - npk (or = nrng - npk2)
!! if ( nbins1.gt.14 ) nbins1 = 14 !* to limit equi. range to 1.98*fp
!!
!!op2
!!
!! ------------------------------------------------------------------
!!
!!-
!a program sboltz
!!
MODULE W3SNLXMD
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | H. L. Tolman |
!/ | FORTRAN 90 |
!/ | Last update : 29-May-2009 |
!/ +-----------------------------------+
!/
!/ 20-Dec-2004 : Origination. ( version 3.06 )
!/ 23-Jun-2006 : Formatted for submitting code for ( version 3.09 )
!/ inclusion in WAVEWATCH III.
!/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
!/
!/ Copyright 2009 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.
!/
!!-=
!!
!! -----------------------------------------------------------------#
!! !
!! Generic shallow-water Boltzmann integral for !
!a "read-in" log-spaced E(f,theta) plus TSA estimate !
!b passed in from ww3 log-spaced action spectrum A(theta,k) !
!! !
!! This is a new program for wave-wave interactions (TSA or FBI) !
!! This is the time-stepping version. !
!! !
!! -----------------------------------------------------------------!
!! !
!! Nov. 2010; It was blended inside WAVEWATCH III ver. 3.14 !
!! by Bash Toulany !
!! -----------------------------------------------------------------!
!! !
!! March/April 2005 added two-scale analysis !
!! !
!! February/March 2004 - fiddled with by Redwing !
!! !
!! March 2003 version !
!! !
!! This is Resio version of the Boltzmann code as of March 2003. !
!! It should contain all changes/mods from Tracy's version. !
!! !
!! Computes over the full-circle, and includes fluxes. !
!! !
!! Runs best on Thursdays; !
!! usually doesn't work too well on Fridays !
!! !
!! !
!! S h a l l o w - W a t e r B o l t z m a n n C o d e !
!! !
!! !
!! -----------------------------------------------------------------!
!! !
!! The included file 'parfile_2.f' (below) contains just !
!! parameters that sets the dimensions nrng, nang, npts and NZZ !
!! for some arrays (below) !
!! !
!! parameters in 'parfile_2.f' are: !
!! nrng = 67 = maximum number of rings !
!! nang = 36 = maximum number of angles !
!! npts = 30 = maximum number of points around locus !
!! NZZ = 2278 = NZZ = (nrng*(nrng+1))/2 !
!! !
!a include 'parfile_2.f'
!! !
!! -----------------------------------------------------------------#
!!
!!------------------------------------------------------------------------------
!!--------------------------------------------------------------------72------80
!!==============================================================================
!!
!!+
!!
!! 1. Purpose :
!!
!! Dummy slot for nonlinear interaction source term.
!! This module can be used to include user-defined source term(s),
!! or to submit a source term to be included into the WAVEWATCH III
!! distribution. See section 5 for requirements for submissions.
!! Codes may be included in WAVEWATCH III as a standard option
!! with it's own dedicated compile switch, or as a version of this
!! module that can be plugged in by a user.
!!+
!! Here is being used as
!! Interface module for TSA type nonlinear interactions.
!! Based on Resio and Perrie (2008) and Perrie and Resio (2009)
!!
!! 2. Variables and types :
!!
!! Name Type Scope Description
!! ------------------------------------------------------------------
!! ------------------------------------------------------------------
!!
!! 3. Subroutines and functions :
!!
!! Name Type Scope Description
!! ------------------------------------------------------------------
!! W3SNLX Subr. Public Main interface for TSA subroutines.
!! Replaces main program "sboltz" in
!! "sbtsa-1-norm-Dec15-08.f" with
!! initialization done in subr. INSNLX
!! INSNLX Subr. Public Corresponding initialization routine.
!!
!!
!! TSA subroutines
!! ---------------
!! gridsetr Subr. Public Setup geometric integration grid
!! shlocr Subr. Public General locus solution
!! shloxr Subr. Public Locus solving routine - must converges
!! cplshr Subr. Public Computes Boltzmann coupling coeff.
!! ------
!! optsa Subr. Public Converts Cart. Energy density (f,theta)
!! to Polar Action density (k,theta)
!! then split it into large and small scale
!! snlr Subr. Public Computes dN(k,theta)/dt due to
!! ------ wave-wave inter.
!!
!! cgf fnc. Public Calculate group velocity "cgf" (m/s)
!! from frequency "f" (Hz), phase speed
!! "c" (m/s) and water depth "d" (m)
!! wkfnc fnc. Public Compute wave number "k" for given
!! ----- freq "f" (Hz) and water depth "d" (m)
!! ------------------------------------------------------------------
!!
!! 4. Subroutines and functions used :
!!
!! Name Type Module Description
!! ------------------------------------------------------------------
!! STRACE Subr. W3SERVMD Subroutine tracing.
!! ------------------------------------------------------------------
!!
!! 5. Remarks :
!
! WAVEWATCH III is designed as a highly plug-compatible code.
! Source term modules can be included as self-contained modules,
! with limited changes needed to the interface of routine calls
! in W3SRCE, and in the point postprocessing programs only.
! Codes submitted for inclusion in WAVEWATCH III should be
! self-contained in the way described below, and might be
! provided with distributions fully integrated in the data
! structure, or as an optional version of this module to be
! included by the user.
!
! Rules for preparing a module to be included in or distributed
! with WAVEWATCH III :
!
! - Fully document the code following the outline given in this
! file, and according to all other WAVEWATCH III routines.
! - Provide a file with necessary modifications to W3SRCE and
! all other routines that require modification.
! - Provide a test case with expected results.
! - It is strongly recommended that the programming style used
! in WAVEWATCH III is followed, in particular
! a) for readability, write as if in fixed FORTRAN format
! regarding column use, even though all files are F90
! free format.
! b) I prefer upper case programming for permanent code,
! as I use lower case in debugging and temporary code.
!
! This module needs to be self-contained in the following way.
!
! a) All saved variables connected with this source term need
! to be declared in the module header. Upon acceptance as
! permanent code, they will be converted to the WAVEWATCH III
! dynamic data structure.
! b) Provide a separate computation and initialization routine.
! In the submission, the initialization should be called
! from the computation routine upon the first call to the
! routine. Upon acceptance as permanent code, the
! initialization routine will be moved to a more appropriate
! location in the code (i.e., being absorbed in ww3_grid or
! being moved to W3IOGR).
!
! See notes in the file below where to add these elements.
!
!!
!! 6. Switches :
!!
!! !/S Enable subroutine tracing.
!!
!! 7. Source code :
!/
!/ ------------------------------------------------------------------- /
!/
! *****************************************
! *** Declare saved variables here ***
! *** public or private as appropriate ***
! *****************************************
!
!!
!! ------------------------------------------------------------------
!! ------------------------------------------------------------------
!!
!!
PUBLIC
!!
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!pub
!! Declare all gridsetr 11 returned arrays as PUBLIC arrays
integer, allocatable, dimension(:,:,:) :: kref2, kref4 !* /fr/
integer, allocatable, dimension(:,:,:) :: jref2, jref4 !* /fr/
real, allocatable, dimension(:,:,:) :: wtk2, wtk4 !* /fr/
real, allocatable, dimension(:,:,:) :: wta2, wta4 !* /fr/
real, allocatable, dimension(:,:,:) :: tfac2, tfac4 !* /fr/
real, allocatable, dimension(:,:,:) :: grad !* /dn/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!pub
!! Declare all shloxr/shlocr 5 returned arrays as PUBLIC arrays
real, allocatable, dimension(:) :: wk2x, wk2y !* /a/
real, allocatable, dimension(:) :: wk4x, wk4y, ds !* /a/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!pub
!! Declare the only cplshr 1 returned variable as PUBLIC
!xx real, allocatable :: csq
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!pub
!! Declare the optsa 2 returned arrays as PUBLIC arrays
real, allocatable, dimension(:,:) :: dens, dens2 !* /c/ /z/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!pub
!! Declare all snlr 4 returned arrays as PUBLIC arrays
!! tsa, diag used for -tsa
!! fbi, diag2 used for -fbi
real, allocatable, dimension(:,:) :: tsa, diag
real, allocatable, dimension(:,:) :: fbi, diag2
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
CONTAINS
!!
!!------------------------------------------------------------------------------
!!--------------------------------------------------------------------72------80
!!==============================================================================
!!
!!
!!
!!
!! ------------------------------------------------------------------
SUBROUTINE INSNLX
!/
!/ +-----------------------------------+
!/ | WAVEWATCH III NOAA/NCEP |
!/ | H. L. Tolman |
!/ | FORTRAN 90 |
!/ | Last update : 23-Jun-2006 |
!/ +-----------------------------------+
!/
!/ 20-Dec-2004 : Origination. ( version 3.06 )
!/ 23-Jun-2006 : Origination. ( version 3.09 )
!/
! 1. Purpose :
!
! Initialization for source term routine.
!
! 2. Method :
!
! 3. Parameters :
!
! Parameter list
! ----------------------------------------------------------------
! ----------------------------------------------------------------
!
! 4. Subroutines used :
!
! Name Type Module Description
! ----------------------------------------------------------------
! STRACE Subr. W3SERVMD Subroutine tracing.
! ----------------------------------------------------------------
!
! 5. Called by :
!
! Name Type Module Description
! ----------------------------------------------------------------
! W3SNLX Subr. W3SNLXMD Corresponding source term.
! ----------------------------------------------------------------
!
! 6. Error messages :
!
! None.
!
! 7. Remarks :
!
! 8. Structure :
!
! See source code.
!
! 9. Switches :
!
! !/S Enable subroutine tracing.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
#ifdef WW3_TSA
USE W3ODATMD, ONLY: NDSE
USE W3SERVMD, ONLY: EXTCDE
#endif
!/S USE W3SERVMD, ONLY: STRACE
!/
IMPLICIT NONE
!/
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
!/S INTEGER, SAVE :: IENT = 0
!/
!/ ------------------------------------------------------------------- /
!/
!/S CALL STRACE (IENT, 'INSNLX')
!
! 1. .... ----------------------------------------------------------- *
!
!/
!/ End of INSNLX ----------------------------------------------------- /
!/
END SUBROUTINE INSNLX
!!
!!------------------------------------------------------------------------------
!!==============================================================================
!!
!!
!!
!!
!! --------------------------------------------------------------- &
SUBROUTINE W3SNLX ( A, CG, WN, DEPTH, NZZ, S, D )
!! --------------------------------------------------------------- &
!!
!!
!! 1. Purpose :
!!
!! Interface module for TSA type nonlinear interactions.
!! Based on Resio and Perrie (2008) and Perrie and Resio (2009)
!!
!! 2. Method :
!!
!! 3. Parameters :
!!
!! Parameter list
!! ------------------------------------------------------------------
!! A R.A. I Action spectrum A(NTH,NK) as a function of
!! direction (rad) and wavenumber.
!! CG R.A. I Group velocities (dimension NK=nrng).
!! WN R.A. I Wavenumbers (dimension NK=nrng).
!! DEPTH Real I Water depth in meters.
!! NZZ Int. I NZZ = (NK*(NK+1))/2
!! S R.A. O Source term.
!! D R.A. O Diagonal term of derivative.
!! ------------------------------------------------------------------
!!
!! 4. Subroutines used :
!!
!! Name Type Module Description
!! ------------------------------------------------------------------
!! STRACE Subr. W3SERVMD Subroutine tracing.
!! ------------------------------------------------------------------
!!
!! 5. Called by :
!!
!! Name Type Module Description
!! ------------------------------------------------------------------
!! W3SRCE Subr. W3SRCEMD Source term integration.
!! W3EXPO Subr. N/A Point output post-processor.
!! GXEXPO Subr. N/A GrADS point output post-processor.
!! ------------------------------------------------------------------
!!
!! 6. Error messages :
!!
!! None.
!!
!! 7. Remarks :
!!
!! 8. Structure :
!!
!! See source code.
!!
!! 9. Switches :
!!
!! !/S Enable subroutine tracing.
!!
!!10. Source code :
!!
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!! ----------------------------------------------------------------72
!! ==================================================================
!!
!!
#ifdef WW3_TSA
!b USE CONSTANTS, ONLY: TPI, GRAV
USE CONSTANTS, ONLY: TPI
USE W3GDATMD, ONLY: NK, NTH, XFR, DTH, SIG, TH, ECOS, ESIN
!! dimension: SIG(0:NK+1),TH(NTH), ECOS(NSPEC+NTH), ESIN(NSPEC+NTH)
!!
USE W3SERVMD, ONLY: EXTCDE
#else
USE DATAPOOL, ONLY: &
& NK => NUMSIG, &
& NTH => NUMDIR, &
& TPI => PI2, &
& XFR => SFAC, &
& SIG => SPSIG, &
& DTH => DDIR, &
& TH => SPDIR, &
& ECOS => COSTH, &
& ESIN => SINTH, &
& rkind
#endif
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!! ------------------------------------------------------------------
!! ==================================================================
!!+=
!!
!!
IMPLICIT NONE
!!
!!+
!! Parameter list
!! --------------
INTEGER, INTENT(IN) :: NZZ
REAL, INTENT(IN) :: A(NTH,NK), CG(NK), WN(NK), DEPTH
REAL, INTENT(OUT) :: S(NTH,NK), D(NTH,NK)
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
LOGICAL, SAVE :: FIRST_TSA = .TRUE.
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!! ------------------------------------------------------------------
!!+=
!!
!! Local Parameters
!! ----------------
!b integer :: nrng, nang, npts, NZZ !* where in parfile_2.f
!b parameter ( nrng=67, nang=36, npts=30, NZZ=2278 )
!!
integer :: nrng, nang, npts
!!
!!-
!b Bash; for sbtsa run; NK, NTH & NZZ must be set here (below)
!b nrng, nang will be set later and
!b npts will be hardwired to 30 as it is not likely to change
!a integer :: NK, NTH
!a parameter ( NK = 67, NTH =36, NZZ=2278 )
!!
!b Bash; for ww3 run; NK, NTH are coming in via USE W3GDATMD and
!b NZZ is passed via the call (see above)
!b npts will be hardwired to 30 as it is not likely to change
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!-=
!!
!!-
!! Input variables (from Tape9 = densin)
!! where densin = test.out output from logspc-2d-plot-new.f
!!
!a integer :: npk0 !* read in from tape9
integer :: npk !* re-calculated npk
!a real :: fpk0 !* read in from tape9
real :: fpk !* re-calculated fpk
real :: dep !* get it from WW3 DEPTH
real :: dfrq !* get it from WW3 XFR
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
real :: ef2(NK,NTH) !* Cartesian Energy(f,theta)
!* get it from WW3 A(NTH,NK)
!! !* formely /enrgy/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!!
!! Local variables
!!
!! to avoid cross between ierr and IERR used in WW3 change ierr to ierr_gr
integer :: irng,iang, ierr_gr
!a integer :: ifr
!wrt
!wrt integer :: ipt, iz
!!
real :: twopi !* get it from WW3 TPI
!a real :: deg !* 360./twopi
!x real :: pi, pi2
!x real :: g, gsq !* get it from WW3 GRAV
!!
real :: f0 !* get it from WW3 oma(1)
real :: delfx !* multiplier for bandwidth
!! !* calc. from WW3 XFR
real :: ainc !* get it from WW3 DTH
!b real :: dwka !* store as an array
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!a real :: cgf !* real function
!a real :: wkfnc !* real function
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
real :: fac
real :: dwka(NK) !* k*dk*dtheta
real :: ef1(NK) !* 1D Energy
real :: e1max, e1sum, h1sig
!a real :: e2max
!!-=
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!!op2
integer :: npk2 !* bin# of second peak freq.
integer :: nsep !* # of bins that separates npk & npk2
integer :: nbins !* min # of bins > npk or npk2
!! !* to guarantee 1 bin in equi. range
integer :: nbins1 !* actual # of bins > npk or npk2
integer :: npeaks !* # of peaks (=0, 1, or 2)
integer :: nfs, nfs2 !* bin# of freq. separation
integer :: nfrq !* # of bin per freq. regime
real :: fpk2 !* second peak freq.
real :: e1max2 !* 1D energy at fpk2
real :: sumd1 !* sum dens+dens2 at nfs
real :: sumd2 !* sum dens+dens2 at nfs+1
real :: densat1 !* averaged dens at nfs
real :: densat2 !* averaged dens at nfs+1
real :: dens2sum !* dbl-sum dens2
real :: dens1sum !* dbl-sum dens
real :: dens2ov1 !* ratio of dens2sum/dens1sum
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!!+
!! Bash; Add to print
!prt real :: fbia1(NK,NTH), tsaa1(NK,NTH), afac1
!prt real :: fbia2(NK,NTH), tsaa2(NK,NTH), afac2
!prt real :: fbia3(NK,NTH), tsaa3(NK,NTH), afac3
!prt real :: fbia4(NK,NTH), tsaa4(NK,NTH), afac4
!prt real :: fbie1(NK,NTH), tsae1(NK,NTH), efac1
!prt real :: fbie2(NK,NTH), tsae2(NK,NTH), efac2
!prt real :: fbie3(NK,NTH), tsae3(NK,NTH), efac3
!prt real :: fbie4(NK,NTH), tsae4(NK,NTH), efac4
!!
!prt real :: fa1max, fa2max, fa3max, fa4max
!prt real :: fe1max, fe2max, fe3max, fe4max
!prt real :: ta1max, ta2max, ta3max, ta4max
!prt real :: te1max, te2max, te3max, te4max
!!
!prt real :: fa1sum, fa2sum, fa3sum, fa4sum
!prt real :: fe1sum, fe2sum, fe3sum, fe4sum
!prt real :: ta1sum, ta2sum, ta3sum, ta4sum
!prt real :: te1sum, te2sum, te3sum, te4sum
!!
!prt real :: deltaf !* df
!!+=
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!! ------------------::--------------------------------------------72
!! --------------------------------------------------------------- &
!! ==================================================================
!!
real :: wka(NK), oma(NK), frqa(NK) !* /b/
real :: angl(NTH), sinan(NTH), cosan(NTH) !* /b/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
real :: pha(NK) !* /c/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
real :: sumint(NK,NTH) !* /dn/
real :: cga(NK), cgnrng !* /dn/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!pub
!! Declare all gridsetr 11 returned arrays as PUBLIC (global) arrays
!pub integer :: kref2(30,NTH,NZZ), kref4(30,NTH,NZZ) !* /fr/
!pub integer :: jref2(30,NTH,NZZ), jref4(30,NTH,NZZ) !* /fr/
!pub real :: wtk2(30,NTH,NZZ), wtk4(30,NTH,NZZ) !* /fr/
!pub real :: wta2(30,NTH,NZZ), wta4(30,NTH,NZZ) !* /fr/
!pub real :: tfac2(30,NTH,NZZ), tfac4(30,NTH,NZZ) !* /fr/
!pub real :: grad(30,NTH,NZZ) !* /dn/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!pub
!pub real :: dens(NK,NTH) !* /c/
!pub real :: dens2(NK,NTH) !* /z/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
real :: sumintp(NK,NTH) !* /z/
real :: sumintx(NK,NTH), sumintsa(NK,NTH) !* /z/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!! for -tsa
!pub
!pub real :: tsa(NK,NTH), diag(NK,NTH)
!!
!! for -fbi
!pub
!pub real :: fbi(NK,NTH), diag2(NK,NTH)
!! ------------------::--------------------------------------------72
!! ##################################################################
!!------------------------------------------------------------------------------
!!==============================================================================
!!
!!
!!
!!-
!! Initial constants
!! -----------------
!!
nrng = NK
nang = NTH
npts = 30
!prt
!x pi = 3.141592654
!x pi2 = 1.570796327
!a twopi = 6.283185308 !* 2pi = 6.283,185,308 rad
!a deg = 360./twopi
!x g = 9.8
!x gsq = 96.04
!!
twopi = TPI !* twopi = 8.*atan(1.)
!x pi = twopi/2.
!x pi2 = pi/2.
!x g = GRAV
!x gsq = GRAV**2
!!-=
!! ------------------------------------------------------------------
!!
!!+
!! Initialization of the output arrays
!! before calling TSA subroutines.
!! -----------------------------------
do 12 iang=1,nang
do 11 irng=1,nrng
S(iang,irng) = 0.0
D(iang,irng) = 0.0
11 continue
12 continue
!!+=
!! ------------------------------------------------------------------
!! ==================================================================
!!
!!-
!!
!!-----------------------------------------------------------------------------#
!! !
!! dep = [m] depth of water !
!! dfrq = frequency multiplier for logarithmic frequency spacing = 1.05 !
!! npk = the magic number 14 ??? (as read from tape9) !
!! fpk = [Hz] peak frequency of initial frequency spectrum and !
!! a parameter of the solution grid !
!! !
!!-----------------------------------------------------------------------------#
!!
!! open & read spectral ef2(f,theta) Energy fit parameters (fit large-scale)
!! & separate ef2(f,theta) into large-scale (dens1) and small-scale (dens2)
!!
!! open & read in tape9 = e(f,theta)
!a open(9,file='densin',status='old')
!!
!a read (9,*) fpk0,dep,dfrq,npk0
!a do 110 irng=1,nrng
!a read(9,'(36e11.3)') (ef2(irng,iang), iang=1,nang)
!110 continue
!!
!a close(9)
!!-=
!!
dep = DEPTH
dfrq = XFR
!!
!! still have to find npk and fpk of the 1D Energy spectrum (see below)
!! --------------------------------------------------------------------------
!!
!!-
!! check input value of dfrq
if (dfrq .le. 1.) then
print *, ' dfrq </= 1; no longer supported '
print *, ' use geometric spacing - dfrq > 1 '
!a stop
#ifdef WW3_TSA
CALL EXTCDE ( 110 )
#endif
end if
!!-=
!!------------------------------------------------------------------------------
!!==============================================================================
!!
!!
!!-
!! open all output files
!a open(80, file='2d-energy.dat', status='unknown')
!a open(81, file='2d-Snl-e.dat', status='unknown')
!a open(84, file='2d-TSA-e.dat', status='unknown')
!a open(85, file='2d-energy-norm.dat',status='unknown')
!!
!a open(11, file='freq.dat', status='unknown')
!a open(12, file='direc.dat', status='unknown')
!a open(40, file='2D_Energy.dat', status='unknown')
!a open(41, file='2D_FBI_Snl.dat', status='unknown')
!a open(44, file='2D_TSA_Snl.dat', status='unknown')
!!
!! Bash; Add to print
!b open(16, file='dbl_sum.dat', status='unknown') !* use Tape6
!!-=
!!------------------------------------------------------------------------------
!!==============================================================================
!!
!!
!!-
!! Initialize frequency arrays and related parameters
!! --------------------------------------------------
!a f0 = fpk0 * (dfrq**(-(npk0-1))) !* npk=14 is magic - no more
delfx = 0.5 * (dfrq-1./dfrq) !* multiplier for bandwidth
!! !* needed for deltaf = delfx*frqa(irng)
!a do 115 irng=1,nrng !* on each computational ring:
!a frqa(irng) = f0 * (dfrq**(irng-1)) !* frequency f [Hz}
!a wka(irng) = wkfnc ( frqa(irng), dep ) !* wavenumber modulus k[rad/m]
!a oma(irng) = twopi * frqa(irng) !* frequency omega [rad/s]
!a cga(irng) = cgf ( frqa(irng), dep, oma(irng)/wka(irng) )
!! !* oma/wka = phase speed
!115 continue
!! --------------------------------------------------------------------------
!!
oma = SIG(1:NK)
frqa = oma / twopi
f0 = frqa(1)
!!
wka = WN(1:NK)
cga = CG(1:NK)
cgnrng = cga(nrng) !* group velocity, outer ring
!!-=
!!------------------------------------------------------------------------------
!!
!!
!!-
!! Initialize direction arrays and related parameters
!! --------------------------------------------------
!a ainc = twopi/nang !* angle increment (radians)
!a do 2 iang=1,nang
!a angl(iang) = (iang-1)*ainc !* angle array (radians)
!a cosan(iang) = cos(angl(iang)) !* array of cosine(angle)
!a sinan(iang) = sin(angl(iang)) !* array of sine(angle)
!a 2 continue
!! --------------------------------------------------------------------------
!!
ainc = DTH
angl = TH(1:NTH)
cosan = ECOS(1:NTH)
sinan = ESIN(1:NTH)
!!-=
!!------------------------------------------------------------------------------
!!==============================================================================
!!
!!
!! -----------------------------------------------------------------#
!! !
!! initialize array pha = k*dk*dtheta, the base area at a grid !
!! intersection for use in integration of 2-d density functions; !
!! dk at a given ring here is the spacing between adjacent cell !
!! centers, with edge points consistent with the geometric !
!! spacing of frequency rings !
!! !
!! -----------------------------------------------------------------#
!!
!!-
!! In the line below "wkfnc(frqa(1)/dfrq,dep)" is like wka(0)
dwka(1) = (wka(2) - wkfnc(frqa(1)/dfrq,dep)) / 2.
!! !* dk at ring 1
pha(1) = wka(1)*dwka(1)*ainc !* k*dk*dtheta at ring 1
!!
do 21 irng=2,nrng-1
dwka(irng) = (wka(irng+1)-wka(irng-1)) / 2. !* dk at irng
pha(irng) = wka(irng)*dwka(irng)*ainc !* k*dk*dtheta at irng
21 continue
!!
!! In the line below "wkfnc(dfrq*frqa(nrng),dep)" is like wka(nrng+1)
dwka(nrng) = (wkfnc(dfrq*frqa(nrng),dep) - wka(nrng-1)) / 2.
!! !* dk at nrng
pha(nrng) = wka(nrng)*dwka(nrng)*ainc !* k*dk*dtheta at nrng
!!-=
!!------------------------------------------------------------------------------
!!
!!-
!! -----------------------------------------------------------------#
!! Since this run is for a rectangular ocean with uniform depth |
!! call grid geometry subr "gridsetr" only once (from here) for |
!! all spectra at all grid points and for all the time steps. |
!! |
!!- We can also do cga and wka (both fnc of frqa and dep) once (here)|
!!- and since they are used in gridsetr we have to do them first. |
!!- However, for now ignore this option. |
!! -----------------------------------------------------------------#
!!
!!
IF ( FIRST_TSA ) THEN
!!
!pub
!! allocate all gridsetr 11 returned arrays declared above as PUBLIC
allocate(kref2(npts, nang, NZZ))
allocate(kref4(npts, nang, NZZ))
allocate(jref2(npts, nang, NZZ))
allocate(jref4(npts, nang, NZZ))
allocate(wtk2(npts, nang, NZZ))
allocate(wtk4(npts, nang, NZZ))
allocate(wta2(npts, nang, NZZ))
allocate(wta4(npts, nang, NZZ))
allocate(tfac2(npts, nang, NZZ))
allocate(tfac4(npts, nang, NZZ))
allocate(grad(npts, nang, NZZ))
!!
!pub
!! allocate all shloxr/shlocr 5 returned arrays as PUBLIC arrays
allocate(wk2x(npts))
allocate(wk2y(npts))
allocate(wk4x(npts))
allocate(wk4y(npts))
allocate(ds(npts))
!!
!pub
!! allocate the only cplshr 1 returned variable as PUBLIC
!xx can't declare as allocatable sibgle variable ?!
!xx allocate(csq)
!!
!pub
!! allocate the optsa 2 returned arrays as PUBLIC arrays
allocate(dens(nrng, nang))
allocate(dens2(nrng, nang))
!!
!pub
!! allocate all snlr 4 returned arrays as PUBLIC arrays
!! tsa, diag used for -tsa
!! fbi, diag2 used for -fbi
allocate(tsa(nrng, nang))
allocate(diag(nrng, nang))
allocate(fbi(nrng, nang))
allocate(diag2(nrng, nang))
!!
!pub
!!
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!! set up integration grid
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!!
!! --------------------------------------------------------------- &
!pub call gridsetr ( nrng,nang,npts,NZZ, dep,dfrq,ierr_gr, &
!pub frqa,wka, cgnrng, sinan,cosan, &
!pub kref2,kref4,jref2,jref4,wtk2,wtk4, &
!pub wta2,wta4,tfac2,tfac4,grad )
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
call gridsetr ( nrng,nang,npts,NZZ,dep,dfrq,ierr_gr, &
frqa,wka, cgnrng, sinan,cosan )
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!! ------------------------------------------------------------------
!!
!! wka, frqa, sinan,cosan, !* from /b/
!! grad, cgnrng, !* from /dn/
!! kref2,kref4,jref2,jref4,wtk2,wtk4, !* = /fr/
!! wta2,wta4,tfac2,tfac4 ) !* = /fr/
!! from /b/, /dn/, and /fr/
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!! ------------------------------------------------------------------
!! ==================================================================
!!
!!
if (ierr_gr .ne. 0) then
write(*,'('' error '',i10,'' from gridset; bail'')') ierr_gr
!a stop
#ifdef WW3_TSA
CALL EXTCDE ( 120 )
#endif
end if
!!
FIRST_TSA = .TRUE.
print *, ' Done calling gridsetr OK '
!!-=
!! ------------------------------------------------------------------
!! $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
!!
!!
!!
!!wrt Bash; Add test write output kref2()
!wrt open(103, file='kref2_at00.dat', status='unknown') !* Tape103
!wrt write(103,903) 'kref2(npts,NTH,NZZ)'
!wrt do 614 ipt =1,npts
!wrt do 613 iang=1,nang
!wrt write(103,904) ipt, iang
!wrt write(103,940) (kref2(ipt,iang,iz), iz=1,NZZ)
!613 continue
!614 continue
!wrt close(103)
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!!wrt Bash; Add test write output kref4()
!wrt open(104, file='kref4_at00.dat', status='unknown') !* Tape104
!wrt write(104,903) 'kref4(npts,NTH,NZZ)'
!wrt do 616 ipt =1,npts
!wrt do 615 iang=1,nang
!wrt write(104,904) ipt, iang
!wrt write(104,940) (kref4(ipt,iang,iz), iz=1,NZZ)
!615 continue
!616 continue
!wrt close(104)
!! == = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
!! == = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
!!
!!
!!wrt Bash; Add test write output jref2()
!wrt open(105, file='jref2_at00.dat', status='unknown') !* Tape105
!wrt write(105,903) 'jref2(npts,NTH,NZZ)'
!wrt do 618 ipt =1,npts
!wrt do 617 iang=1,nang
!wrt write(105,904) ipt, iang
!wrt write(105,940) (jref2(ipt,iang,iz), iz=1,NZZ)
!617 continue
!618 continue
!wrt close(105)
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!!wrt Bash; Add test write output jref4()
!wrt open(106, file='jref4_at00.dat', status='unknown') !* Tape106
!wrt write(106,903) 'jref4(npts,NTH,NZZ)'
!wrt do 620 ipt =1,npts
!wrt do 619 iang=1,nang
!wrt write(106,904) ipt, iang
!wrt write(106,940) (jref4(ipt,iang,iz), iz=1,NZZ)
!619 continue
!620 continue
!wrt close(106)
!! == = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
!! == = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
!!
!!
!!wrt Bash; Add test write output wtk2()
!wrt open(107, file='wtk2_at00.dat', status='unknown') !* Tape107
!wrt write(107,903) 'wtk2(npts,NTH,NZZ)'
!wrt do 622 ipt =1,npts
!wrt do 621 iang=1,nang
!wrt write(107,904) ipt, iang
!wrt write(107,950) (wtk2(ipt,iang,iz), iz=1,NZZ)
!621 continue
!622 continue
!wrt close(107)
!! -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
!!
!!wrt Bash; Add test write output wtk4()
!wrt open(108, file='wtk4_at00.dat', status='unknown') !* Tape108
!wrt write(108,903) 'wtk4(npts,NTH,NZZ)'
!wrt do 624 ipt =1,npts
!wrt do 623 iang=1,nang
!wrt write(108,904) ipt, iang
!wrt write(108,950) (wtk4(ipt,iang,iz), iz=1,NZZ)
!623 continue
!624 continue
!wrt close(108)
!! == = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
!! == = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
!!
!!
!!wrt Bash; Add test write output wta2()
!wrt open(109, file='wta2_at00.dat', status='unknown') !* Tape109
!wrt write(109,903) 'wta2(npts,NTH,NZZ)'
!wrt do 626 ipt =1,npts
!wrt do 625 iang=1,nang
!wrt write(109,904) ipt, iang