-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwanSpectPart.ftn
1477 lines (1461 loc) · 42.8 KB
/
SwanSpectPart.ftn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! Contents of this file
!
! W3ODATMD Parameters required for partitioning model output
! SWPARTMD Spectral partitioning according to the watershed method
! includes the subroutines :
! SWPART (interface to watershed routines)
! PTSORT (sort discretized image)
! PTNGHB (define nearest neighbours)
! PT_FLD (incremental flooding algorithm)
! FIFO_ADD, FIFO_EMPTY, FIFO_FIRST (queue management)
! PTMEAN (compute mean parameters)
!
MODULE W3ODATMD
!
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmers: The SWAN team |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
!
! 0. Authors
!
! 41.62: Andre van der Westhuysen, from code by H.L. Tolman
!
! 1. Updates
!
! 41.62, Nov. 15: New module
!
! 2. Purpose
!
! This module considers the parameters required for partitioned model output
! (from the WAVEWATCH III codes w3odatmd.ftn and ww3_grid.ftn)
!
! 3. Method
!
! MODULE construct
!
! 4. Modules used
!
! ---
!
IMPLICIT NONE
!
! 5. Argument variables
!
! ---
!
! 6. Parameter variables
!
! ---
!
! 7. Local variables
!
! Elements of OUT6 are aliased to pointers with the same
! name. These pointers are defined as :
!
! Name Type Scope Description
! ----------------------------------------------------------------
! IHMAX Int. Public Number of discrete spectral levels.
! HSPMIN Real Public Minimum significant height per part.
! WSMULT Real Public Multiplier for wind sea boundary.
! WSCUT Real Public Cut-off wind factor for wind seas.
! FLCOMB Log. Public Flag for combining wind seas.
! ----------------------------------------------------------------
!
PUBLIC
INTEGER :: IHMAX
REAL :: HSPMIN, WSMULT, WSCUT
LOGICAL :: FLCOMB
! These hardcoded values (from ww3_grid.ftn) can be made
! user-defined with the OUTPUT command
PARAMETER (IHMAX=100, HSPMIN=0.05, WSMULT=1.7, 41.62
& WSCUT=0.333, FLCOMB=.FALSE.)
!
! 8. Subroutines and functions used
!
! ---
!
! 9. Subroutines and functions calling
!
! ---
!
! 10. Error messages
!
! ---
!
! 11. Remarks
!
! ---
!
! 12. Structure
!
! ---
!
! 13. Source text
!
! CONTAINS
END MODULE W3ODATMD
MODULE SWPARTMD
!
USE W3ODATMD, ONLY: IHMAX, HSPMIN, WSMULT 41.62
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmers: The SWAN team |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
!
! 0. Authors
!
! 41.62: Andre van der Westhuysen, based on code by Barbara Tracy
! and H.L. Tolman, with contributions by M. Szyszka
!
! 1. Updates
!
! 41.62, Nov. 15: New module
!
! 2. Purpose
!
! Spectral partitioning according to the watershed method
!
! 3. Method
!
! MODULE construct
!
! 4. Modules used
!
! ---
!
IMPLICIT NONE
!
! 5. Argument variables
!
! ---
!
! 6. Parameter variables
!
! ---
!
! 7. Local variables
!
! Name Type Scope Description
! ----------------------------------------------------------------
! MK, MTH Int. Private Dimensions of stored neighour array
! NEIGH I.A. Private Nearest Neighbor array
! ----------------------------------------------------------------
! Note: IHMAX, HSPMIN, WSMULT, WSCUT and FLCOMB used from W3ODATMD
!
PUBLIC
!
INTEGER, PRIVATE :: MK = -1, MTH = -1
INTEGER, ALLOCATABLE, PRIVATE :: NEIGH(:,:)
!
! 8. Subroutines and functions used
!
! ---
!
! 9. Subroutines and functions calling
!
! SWOEXA : Compute wave partitions
!
! 10. Error messages
!
! ---
!
! 11. Remarks
!
! ---
!
! 12. Structure
!
! ---
!
! 13. Source text
!
CONTAINS
!***********************************************************************
! *
SUBROUTINE SWPART ( SPEC, UABS, UDIR, DEPTH, WN, SPCSIG, SPCDIR,
& NP, XP, DIMXP )
! *
!***********************************************************************
!
USE W3ODATMD, ONLY: WSCUT, FLCOMB 41.62
USE SWCOMM3 , ONLY: MSC, MDC 41.62
USE OCPCOMM4, ONLY: PRINTF 41.62
!
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmers: The SWAN team |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
!
! 0. Authors
!
! 41.62: Andre van der Westhuysen, based on code by Barbara Tracy
! and H.L. Tolman, with contributions by M. Szyszka
!
! 1. Updates
!
! 41.62, Nov. 15: New subroutine
!
! 2. Purpose
!
! Interface to watershed partitioning routines
!
! 3. Method
!
! Watershed Algorithm of Vincent and Soille, 1991, implemented by
! Barbara Tracy (USACE/ERDC) for NOAA/NCEP
!
! 4. Modules used
!
! ---
!
IMPLICIT NONE
!
! 5. Argument variables
!
! SPEC R.A. I 2D spectrum E(f,theta)
! UABS Real I Wind speed
! UDIR Real I Wind direction (Cartesian) 41.62
! DEPTH Real I Water depth
! WN R.A. I Wavenumbers for each frequency
! SPCDIR REAL I Spectral directions 41.62
! SPCSIG REAL I Spectral frequencies 41.62
! NP Int. O Number of partitions
! -1 : Spectrum without minumum energy
! 0 : Spectrum with minumum energy
! but no partitions
! XP R.A. O Parameters describing partitions
! Entry '0' contains entire spectrum
! DIMXP Int. I Second dimension of XP
INTEGER, INTENT(OUT) :: NP
INTEGER, INTENT(IN) :: DIMXP
REAL, INTENT(IN) :: SPEC(MSC,MDC), WN(MSC), UABS,
& UDIR, DEPTH
REAL, INTENT(OUT) :: XP(7,0:DIMXP)
REAL, INTENT(IN) :: SPCDIR(MDC,6) 41.62
REAL, INTENT(IN) :: SPCSIG(MSC) 41.62
!
! 6. Parameter variables
!
! ---
!
! 7. Local variables
INTEGER :: IENT, ITH, IMI(MSC*MDC), IMD(MSC*MDC),
& IMO(MSC*MDC), IND(MSC*MDC), NP_MAX,
& IP, IT(1), INDEX(DIMXP), NWS,
& IPW, IPT, ISP
INTEGER :: PMAP(DIMXP)
REAL :: ZP(MSC*MDC), ZMIN, ZMAX, Z(MSC*MDC),
& FACT, WSMAX, HSMAX
REAL :: TP(7,DIMXP) 41.62 extended from TP(6,1:DIMXP)
!
! 8. Subroutines and functions used
!
! ---
!
! 9. Subroutines and functions calling
!
! SWOEXA : Process partition output
!
! 10. Error messages
!
! ---
!
! 11. Remarks
!
! To achieve minimum storage but guaranteed storage of all
! partitions DIMXP = ((MSC+1)/2) * ((MDC-1)/2)
!
! 12. Structure
!
! ---
!
! 13. Source text
!
!/ ------------------------------------------------------------------- /
! 0. Initializations
!
SAVE IENT
DATA IENT /0/
CALL STRACE (IENT, 'SWPART')
!
NP = 0
XP = 0.
!
! -------------------------------------------------------------------- /
! 1. Process input spectrum
! 1.a 2-D to 1-D spectrum
!
DO ITH=1, MDC
ZP(1+(ITH-1)*MSC:ITH*MSC) = SPEC(:,ITH)
END DO
!
! 1.b Invert spectrum and 'digitize'
!
ZMIN = MINVAL ( ZP )
ZMAX = MAXVAL ( ZP )
IF ( ZMAX-ZMIN .LT. 1.E-9 ) RETURN
!
Z = ZMAX - ZP
!
FACT = REAL(IHMAX-1) / ( ZMAX - ZMIN )
IMI = MAX ( 1 , MIN ( IHMAX , NINT ( 1. + Z*FACT ) ) )
!
! 1.c Sort digitized image
!
CALL PTSORT ( IMI, IND, IHMAX )
!
! -------------------------------------------------------------------- /
! 2. Perform partitioning
! 2.a Update nearest neighbor info as needed
!
CALL PTNGHB
!
! 2.b Incremental flooding
!
CALL PT_FLD ( IMI, IND, IMO, ZP, NP_MAX )
!
! 2.c Compute parameters per partition
! NP and NX initialized inside routine
!
CALL PTMEAN ( NP_MAX, IMO, ZP, DEPTH, UABS, UDIR, WN,
& SPCSIG, SPCDIR, NP, XP, DIMXP, PMAP ) 41.62
!
! -------------------------------------------------------------------- /
! 3. Sort and recombine wind seas as needed
! 3.a Sort by wind sea fraction
!
IF ( NP .LE. 1 ) RETURN
!
TP(:,1:NP) = XP(:,1:NP)
XP(:,1:NP) = 0.
INDEX(1:NP) = 0
NWS = 0
!
DO IP=1, NP
IT = MAXLOC(TP(6,1:NP))
INDEX(IP) = IT(1)
XP(:,IP) = TP(:,INDEX(IP))
IF ( TP(6,IT(1)) .GE. WSCUT ) NWS = NWS + 1
TP(6,IT(1)) = -1.
END DO
!
! 3.b Combine wind seas as needed and resort
!
IF ( NWS.GT.1 .AND. FLCOMB ) THEN
IPW = PMAP(INDEX(1))
DO IP=2, NWS
IPT = PMAP(INDEX(IP))
DO ISP=1, MSC*MDC
IF ( IMO(ISP) .EQ. IPT ) IMO(ISP) = IPW
END DO
END DO
!
CALL PTMEAN ( NP_MAX, IMO, ZP, DEPTH, UABS, UDIR, WN,
& SPCSIG, SPCDIR, NP, XP, DIMXP, PMAP ) 41.62
IF ( NP .LE. 1 ) RETURN
!
TP(:,1:NP) = XP(:,1:NP)
XP(:,1:NP) = 0.
INDEX(1:NP) = 0
NWS = 0
!
DO IP=1, NP
IT = MAXLOC(TP(6,1:NP))
INDEX(IP) = IT(1)
XP(:,IP) = TP(:,INDEX(IP))
IF ( TP(6,IT(1)) .GE. WSCUT ) NWS = NWS + 1
TP(6,IT(1)) = -1.
END DO
!
END IF
!
! 3.c Sort remaining fields by wave height
!
NWS = MIN ( 1 , NWS )
!
TP(:,1:NP) = XP(:,1:NP)
XP(:,1:NP) = 0.
!
IF ( NWS .GT. 0 ) THEN
XP(:,1) = TP(:,1)
TP(1,1) = -1.
NWS = 1
END IF
!
DO IP=NWS+1, NP
IT = MAXLOC(TP(1,1:NP))
XP(:,IP) = TP(:,IT(1))
TP(1,IT(1)) = -1.
END DO
!> IF (ALLOCATED(NEIGH )) DEALLOCATE(NEIGH ) 41.62
!
! -------------------------------------------------------------------- /
! 4. End of routine
!
RETURN
!
! end of subroutine SWPART
END SUBROUTINE SWPART
!***********************************************************************
! *
SUBROUTINE PTSORT ( IMI, IND, IHMAX )
! *
!***********************************************************************
!
USE SWCOMM3, ONLY: MSC, MDC 41.62
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmers: The SWAN team |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
!
! 0. Authors
!
! 41.62: Andre van der Westhuysen, based on code by Barbara Tracy
! and H.L. Tolman
!
! 1. Updates
!
! 41.62, Nov. 15: New subroutine
!
! 2. Purpose
!
! This subroutine sorts the image data in ascending order
! This sort original to F.T. Tracy (2006)
!
! 3. Method
!
! ---
!
! 4. Modules used
!
! ---
!
IMPLICIT NONE
!
! 5. Argument variables
!
! IMI I.A. I Input discretized spectrum
! IND I.A. O Sorted data
! IHMAX Int. I Number of integer levels
!
INTEGER, INTENT(IN) :: IHMAX, IMI(MSC*MDC)
INTEGER, INTENT(OUT) :: IND(MSC*MDC)
!
! 6. Parameter variables
!
! ---
!
! 7. Local variables
!
INTEGER :: I, IN, IV
INTEGER :: NUMV(IHMAX), IADDR(IHMAX),
& IORDER(MSC*MDC)
!
! 8. Subroutines and functions used
!
! ---
!
! 9. Subroutines and functions calling
!
! SWPART
!
! 10. Error messages
!
! ---
!
! 11. Remarks
!
! ---
!
! 12. Structure
!
! ---
!
! 13. Source text
!
! -------------------------------------------------------------------- /
! a. Occurences per height
!
NUMV = 0
DO I=1, MSC*MDC
NUMV(IMI(I)) = NUMV(IMI(I)) + 1
END DO
!
! -------------------------------------------------------------------- /
! b. Starting address per height
!
IADDR(1) = 1
DO I=1, IHMAX-1
IADDR(I+1) = IADDR(I) + NUMV(I)
END DO
!
! -------------------------------------------------------------------- /
! c. Order points
!
DO I=1, MSC*MDC
IV = IMI(I)
IN = IADDR(IV)
IORDER(I) = IN
IADDR(IV) = IN + 1
END DO
!
! -------------------------------------------------------------------- /
! d. Sort points
!
DO I=1, MSC*MDC
IND(IORDER(I)) = I
END DO
!
RETURN
! end of subroutine PTSORT
END SUBROUTINE PTSORT
!***********************************************************************
! *
SUBROUTINE PTNGHB
! *
!***********************************************************************
!
USE SWCOMM3, ONLY: MSC, MDC 41.62
USE OCPCOMM4, ONLY: PRINTF 41.62
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmers: The SWAN team |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
!
! 0. Authors
!
! 41.62: Andre van der Westhuysen, based on code by Barbara Tracy
! and H.L. Tolman
!
! 1. Updates
!
! 41.62, Nov. 15: New subroutine
!
! 2. Purpose
!
! This subroutine computes the nearest neighbors for each grid
! point. Wrapping of directional distribution (0 to 360) is taken
! care of using the nearest neighbor system
!
! 3. Method
!
! ---
!
! 4. Modules used
!
! ---
!
IMPLICIT NONE
!
! 5. Argument variables
!
! IMI I.A. I Input discretized spectrum
! IMD I.A. O Sorted data
! IHMAX Int. I Number of integer levels
!
! INTEGER, INTENT(IN) :: IHMAX, IMI(MSC*MDC)
! INTEGER, INTENT(IN) :: IMD(MSC*MDC)
!
! 6. Parameter variables
!
! ---
!
! 7. Local variables
!
INTEGER :: IENT, N, J, I, K
!
! 8. Subroutines and functions used
!
! ---
!
! 9. Subroutines and functions calling
!
! SWPART
!
! 10. Error messages
!
! ---
!
! 11. Remarks
!
! ---
!
! 12. Structure
!
! ---
!
! 13. Source text
!
SAVE IENT
DATA IENT /0/
CALL STRACE (IENT, 'PTNGHB')
! -------------------------------------------------------------------- /
! a. Check on need of processing
!
IF ( MK.EQ.MSC .AND. MTH.EQ.MDC ) RETURN
!
IF ( MK.GT.0 ) DEALLOCATE ( NEIGH )
ALLOCATE ( NEIGH(9,MSC*MDC) )
MK = MSC
MTH = MDC
!
! -------------------------------------------------------------------- /
! b. Build map
!
NEIGH = 0
!
! ... Base loop
!
DO N = 1, MSC*MDC
!
J = (N-1) / MSC + 1
I = N - (J-1) * MSC
K = 0
!
! ... Point at the left(1)
!
IF ( I .NE. 1 ) THEN
K = K + 1
NEIGH(K, N) = N - 1
END IF
!
! ... Point at the right (2)
!
IF ( I .NE. MSC ) THEN
K = K + 1
NEIGH(K, N) = N + 1
END IF
!
! ... Point at the bottom(3)
!
IF ( J .NE. 1 ) THEN
K = K + 1
NEIGH(K, N) = N - MSC
END IF
!
! ... ADD Point at bottom_wrap to top
!
IF ( J .EQ. 1 ) THEN
K = K + 1
NEIGH(K,N) = MSC*MDC - (MSC-I)
END IF
!
! ... Point at the top(4)
!
IF ( J .NE. MDC ) THEN
K = K + 1
NEIGH(K, N) = N + MSC
END IF
!
! ... ADD Point to top_wrap to bottom
!
IF ( J .EQ. MDC ) THEN
K = K + 1
NEIGH(K,N) = N - (MDC-1) * MSC
END IF
!
! ... Point at the bottom, left(5)
!
IF ( (I.NE.1) .AND. (J.NE.1) ) THEN
K = K + 1
NEIGH(K, N) = N - MSC - 1
END IF
!
! ... Point at the bottom, left with wrap.
!
IF ( (I.NE.1) .AND. (J.EQ.1) ) THEN
K = K + 1
NEIGH(K,N) = N - 1 + MSC * (MDC-1)
END IF
!
! ... Point at the bottom, right(6)
!
IF ( (I.NE.MSC) .AND. (J.NE.1) ) THEN
K = K + 1
NEIGH(K, N) = N - MSC + 1
END IF
!
! ... Point at the bottom, right with wrap
!
IF ( (I.NE.MSC) .AND. (J.EQ.1) ) THEN
K = K + 1
NEIGH(K,N) = N + 1 + MSC * (MDC - 1)
END IF
!
! ... Point at the top, left(7)
!
IF ( (I.NE.1) .AND. (J.NE.MDC) ) THEN
K = K + 1
NEIGH(K, N) = N + MSC - 1
END IF
!
! ... Point at the top, left with wrap
!
IF ( (I.NE.1) .AND. (J.EQ.MDC) ) THEN
K = K + 1
NEIGH(K,N) = N - 1 - (MSC) * (MDC-1)
END IF
!
! ... Point at the top, right(8)
!
IF ( (I.NE.MSC) .AND. (J.NE.MDC) ) THEN
K = K + 1
NEIGH(K, N) = N + MSC + 1
END IF
!
! ... Point at top, right with wrap
!
IF ( (I.NE.MSC) .AND. (J.EQ.MDC) ) THEN
K = K + 1
NEIGH(K,N) = N + 1 - (MSC) * (MDC-1)
END IF
!
NEIGH(9,N) = K
!
END DO
!
RETURN
! end of subroutine PTNGHB
END SUBROUTINE PTNGHB
!***********************************************************************
! *
SUBROUTINE PT_FLD ( IMI, IND, IMO, ZP, NPART )
! *
!***********************************************************************
!
USE SWCOMM3, ONLY: MSC, MDC 41.62
!
!
! --|-----------------------------------------------------------|--
! | Delft University of Technology |
! | Faculty of Civil Engineering and Geosciences |
! | Environmental Fluid Mechanics Section |
! | P.O. Box 5048, 2600 GA Delft, The Netherlands |
! | |
! | Programmers: The SWAN team |
! --|-----------------------------------------------------------|--
!
!
! SWAN (Simulating WAves Nearshore); a third generation wave model
! Copyright (C) 1993-2024 Delft University of Technology
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
!
! 0. Authors
!
! 41.62: Andre van der Westhuysen, based on code by H.L. Tolman
!
! 1. Updates
!
! 41.62, Nov. 15: New subroutine
!
! 2. Purpose
!
! This subroutine does incremental flooding of the image to
! determine the watershed image
!
! 3. Method
!
! ---
!
! 4. Modules used
!
! ---
!
IMPLICIT NONE
!
! 5. Argument variables
!
! IMI I.A. I Input discretized spectrum
! IND I.A. I Sorted addresses
! IMO I.A. O Output partitioned spectrum
! ZP R.A. I Spectral array
! NPART Int. O Number of partitions found
!
INTEGER, INTENT(IN) :: IMI(MSC*MDC), IND(MSC*MDC)
INTEGER, INTENT(OUT) :: IMO(MSC*MDC), NPART
REAL, INTENT(IN) :: ZP(MSC*MDC)
!
! 6. Parameter variables
!
! ---
!
! 7. Local variables
!
INTEGER :: IENT, MASK, INIT, IWSHED, IMD(MSC*MDC),
& IC_LABEL, IFICT_PIXEL, M, IH, MSAVE,
& IP, I, IPP, IC_DIST, IEMPTY, IPPP,
& JL, JN, IPT, J
INTEGER :: IQ(MSC*MDC), IQ_START, IQ_END
REAL :: ZPMAX, EP1, DIFF
!
! 8. Subroutines and functions used
!
! ---
!
! 9. Subroutines and functions calling
!
! SWPART
!
! 10. Error messages
!
! ---
!
! 11. Remarks
!
! ---
!
! 12. Structure
!
! ---
!
! 13. Source text
!
SAVE IENT
DATA IENT /0/
CALL STRACE (IENT, 'PT_FLD')
! -------------------------------------------------------------------- /
! 0. Initializations
!
MASK = -2
INIT = -1
IWSHED = 0
IMO = INIT
IC_LABEL = 0
IMD = 0
IFICT_PIXEL = -100
!
IQ_START = 1
IQ_END = 1
!
ZPMAX = MAXVAL ( ZP )
!
! -------------------------------------------------------------------- /
! 1. Loop over levels
!
M = 1
!
DO IH=1, IHMAX
MSAVE = M
!
! 1.a Pixels at level IH
!
DO
IP = IND(M)
IF ( IMI(IP) .NE. IH ) EXIT
!
! Flag the point, if it stays flagge, it is a separate minimum
!
IMO(IP) = MASK
!
! Consider neighbors
! If there is neighbor, set distance and add to queue
!
DO I=1, NEIGH(9,IP)
IPP = NEIGH(I,IP)
IF ( (IMO(IPP).GT.0) .OR. (IMO(IPP).EQ.IWSHED) ) THEN
IMD(IP) = 1
CALL FIFO_ADD (IP)
EXIT