WAVEWATCH III  beta 0.0.1
w3iogomd.F90
Go to the documentation of this file.
1 
6 
7 #include "w3macros.h"
8 
14 !/ ------------------------------------------------------------------- /
15 MODULE w3iogomd
16  !/
17  !/ +-----------------------------------+
18  !/ | WAVEWATCH III NOAA/NCEP |
19  !/ | H. L. Tolman |
20  !/ | FORTRAN 90 |
21  !/ | Last update : 02-Mar-2024 |
22  !/ +-----------------------------------+
23  !/
24  !/ 04-Jan-2001 : Origination. ( version 2.00 )
25  !/ 23-Apr-2002 : Clean up. ( version 2.19 )
26  !/ 29-Apr-2002 : Add output parameters 17-18. ( version 2.20 )
27  !/ 30-May-2002 : Switch clean up. ( version 2.21 )
28  !/ 13-Nov-2002 : Add stress vector. ( version 3.00 )
29  !/ 25-Oct-2004 : Multiple grid version. ( version 3.06 )
30  !/ 27-Jun-2005 : Adding MAPST2. ( version 3.07 )
31  !/ 21-Jul-2005 : Adding output fields 19-21. ( version 3.07 )
32  !/ 23-Apr-2006 : Filter for directional spread. ( version 3.09 )
33  !/ 27-Jun-2006 : Adding file name preamble. ( version 3.09 )
34  !/ 05-Jul-2006 : Consolidate stress arrays. ( version 3.09 )
35  !/ 02-Apr-2007 : Adding partitioned output. ( version 3.11 )
36  !/ Adding user slots for outputs.
37  !/ 08-Oct-2007 : Adding ST3 source term option. ( version 3.13 )
38  !/ ( F. Ardhuin )
39  !/ 05-Mar-2008 : Added NEC sxf90 compiler directives
40  !/ (Chris Bunney, UK Met Office) ( version 3.13 )
41  !/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
42  !/ 13-Sep-2009 : Add coupling option ( version 3.14 )
43  !/ 10-Mar-2009 : Add second order pressure ( version 3.14 )
44  !/ 15-Sep-2010 : Adding ST4 source term option. ( version 3.14 )
45  !/ 30-Oct-2009 : Implement curvilinear grid type. ( version 3.14 )
46  !/ (W. E. Rogers & T. J. Campbell, NRL)
47  !/ 05-Feb-2011 : Implement unstructured grid ( version 3.14.3 )
48  !/ (A. Roland and F. Ardhuin)
49  !/ 12-Jun-2012 : Add /RTD option or rotated grid option.
50  !/ (Jian-Guo Li) ( version 4.06 )
51  !/ 25-Dec-2012 : New output structure and smaller ( version 4.11 )
52  !/ memory footprint.
53  !/ 15-Apr-2013 : New subroutine to read param. names ( version 4.11 )
54  !/ 21-Aug-2013 : Bug correction in W3IOGO: UBR, ABR ( version 4.11 )
55  !/ 11-Nov-2013 : SMC and rotated grid incorporated in the main
56  !/ trunk ( version 4.13 )
57  !/ 31-Jan-2014 : Bug fix warning output (Tolman). ( version 4.18 )
58  !/ 10-Feb-2014 : Bug correction for US3D: div. by df ( version 4.18 )
59  !/ 30-Apr-2014 : Add th2m and sth2m calculation ( version 5.01 )
60  !/ 27-May-2014 : Switch to OMPG switch. ( version 5.02 )
61  !/ 27-Aug-2015 : Add ICEF,ICEH as output fields ( version 5.10 )
62  !/ 01-Mar-2018 : Removed RTD code (now used in post ( version 6.02 )
63  !/ processing code)
64  !/ 05-Jun-2018 : Add DEBUGSTP/SETUP ( version 6.04 )
65  !/ 22-Aug-2018 : Add WBT output parameter ( version 6.06 )
66  !/ 25-Sep-2019 : Corrected th2m and sth2m ( version 6.07 )
67  !/ calculations. (J Dykes, NRL)
68  !/ 04-Oct-2019 : Optional one file per output stride ( version 7.00 )
69  !/ (Roberto Padilla-Hernandez & J.H. Alves)
70  !/ 03-Nov-2020 : Factored out NAME matching into ( version 7.12 )
71  !/ seperate subroutine. (C. Bunney)
72  !/ 15-Jan-2021 : Added TP output based on exsiting ( version 7.12 )
73  !/ FP internal field. (C. Bunney)
74  !/ 22-Mar-2021 : Add extra coupling fields as output ( version 7.13 )
75  !/ 21-Jul-2022 : Correct FP0 calc for peak energy in ( version 7.14 )
76  !/ min/max freq band (B. Pouliot, CMC)
77  !/ 02-Mar-2024 : Add skweness and EM bias varaible ( version 7.xx )
78  !/
79  !/ Copyright 2009-2024 National Weather Service (NWS),
80  !/ National Oceanic and Atmospheric Administration. All rights
81  !/ reserved. WAVEWATCH III is a trademark of the NWS.
82  !/ No unauthorized use without permission.
83  !/
84  ! 1. Purpose :
85  !
86  ! Gridded output of mean wave parameters.
87  !
88  ! 2. Variables and types :
89  !
90  ! Name Type Scope Description
91  ! ----------------------------------------------------------------
92  ! VEROGR C*10 Private Gridded output file version number.
93  ! IDSTR C*30 Private Gridded output file ID string.
94  ! ----------------------------------------------------------------
95  !
96  ! 3. Subroutines and functions :
97  !
98  ! Name Type Scope Description
99  ! ----------------------------------------------------------------
100  ! W3OUTG Subr. Public Calculate mean parameters.
101  ! W3IOGO Subr. Public IO to raw gridded fields file.
102  ! ----------------------------------------------------------------
103  !
104  ! 4. Subroutines and functions used :
105  !
106  ! Name Type Module Description
107  ! ----------------------------------------------------------------
108  ! W3SETO Subr. W3ODATMD Point to data structure.
109  ! W3SETG Subr. W3GDATMD Point to data structure.
110  ! W3SETW Subr. W3WDATMD Point to data structure.
111  ! W3SETA Subr. W3ADATMD Point to data structure.
112  ! W3XETA Subr. W3ADATMD Point to data structure.
113  ! W3DIMW Subr. W3WDATMD Allocate data structure.
114  ! W3DIMA Subr. W3ADATMD Allocate data structure.
115  ! STRACE Subr. W3SERVMD Subroutine tracing. ( !/S )
116  ! EXTCDE Subr. W3SERVMD Program abort with exit code.
117  ! ----------------------------------------------------------------
118  !
119  ! 5. Remarks :
120  !
121  ! - The different output fields are not folded in with this module
122  ! due to the different requirements for a element '0' in some of
123  ! the fields.
124  !
125  ! 6. Switches :
126  !
127  ! !/SHRD Switch for shared / distributed memory architecture.
128  ! !/DIST Id.
129  !
130  ! !/OMPG OpenMP compiler directive for loop splitting.
131  !
132  ! !/O8 Filter for low wave heights ( HSMIN )
133  ! !/O9 Negative wave height alowed, other mean parameters will
134  ! not be correct.
135  !
136  ! !/ST0 No source terms.
137  ! !/ST1 Source term set 1 (WAM equiv.)
138  ! !/ST2 Source term set 2 (Tolman and Chalikov)
139  ! !/ST3 Source term set 3 (WAM 4+)
140  ! !/ST4 Source term set 4 (Ardhuin et al. 2009, 2010)
141  ! !/ST6 Source term set 6 (BYDRZ)
142  !
143  ! !/S Enable subroutine tracing.
144  ! !/T Test output.
145  !
146  ! 7. Source code :
147  !
148  !/ ------------------------------------------------------------------- /
149 #ifdef W3_S
150  USE w3servmd, ONLY : strace
151 #endif
152  !/
153  PUBLIC
154  CHARACTER(LEN=1024) :: fldout
155  !/
156  !/ Private parameter statements (ID strings)
157  !/
158  CHARACTER(LEN=10), PARAMETER, PRIVATE :: verogr = '2019-10-04'
159  CHARACTER(LEN=30), PARAMETER, PRIVATE :: &
160  idstr = 'WAVEWATCH III GRID OUTPUT FILE'
161  !/
162 CONTAINS
163  !/ ------------------------------------------------------------------- /
177  SUBROUTINE w3flgrdupdt ( NDSO, NDSEN, FLGRD, FLGR2, FLGD, FLG2 )
178  !/
179  !/ +-----------------------------------+
180  !/ | WAVEWATCH III NOAA/NCEP |
181  !/ | F. Ardhuin |
182  !/ | FORTRAN 90 |
183  !/ | Last update : 15-Apr-2013 |
184  !/ +-----------------------------------+
185  !/
186  !/ 15-Apr-2013 : Origination. ( version 4.10 )
187  !/
188  ! 1. Purpose :
189  !
190  ! Updates the flags for output parameters based on the mod_def file
191  ! this is to prevent the allocation of big 3D arrays when not requested
192  !
193  ! 3. Parameters :
194  !
195  ! Parameter list
196  ! ----------------------------------------------------------------
197  ! NDSO Int. I Output file logical unit number
198  ! NDSEN R.A. I Error output file logical unit number
199  ! FLGD,FLG2 L.A. O 1D array of flags for groups
200  ! FLGRD L.A. O 2D array of flags
201  ! FLGR2 L.A. O 2D array of flags
202  ! ----------------------------------------------------------------
203  !
204  !
205  ! 4. Subroutines used :
206  !
207  ! None
208  !
209  ! 5. Called by :
210  !
211  ! Name Type Module Description
212  ! ----------------------------------------------------------------
213  ! W3INIT Subr. N/A
214  ! ----------------------------------------------------------------
215  !
216  ! 6. Error messages :
217  !
218  ! None.
219  !
220  ! 8. Structure :
221  !
222  ! See source code.
223  !
224  ! 9. Switches :
225  !
226  ! !/S Enable subroutine tracing.
227  ! !/T Test output.
228  !
229  ! 10. Source code :
230  !
231  !/ ------------------------------------------------------------------- /
232  USE constants
233  USE w3gdatmd, ONLY: e3df, p2msf, us3df, usspf
234  USE w3odatmd, ONLY: nogrp, ngrpp
235 #ifdef W3_S
236  USE w3servmd, ONLY: strace
237 #endif
238  !
239  IMPLICIT NONE
240  !/
241  !/ ------------------------------------------------------------------- /
242  !/ Parameter list
243  !/
244  INTEGER, INTENT(IN) :: NDSO, NDSEN
245  LOGICAL, INTENT(INOUT) :: FLGRD(NOGRP,NGRPP), FLGD(NOGRP), &
246  FLGR2(NOGRP,NGRPP), FLG2(NOGRP)
247  !/
248  !/ ------------------------------------------------------------------- /
249  !/ Local parameters
250  !/
251  INTEGER :: I
252  CHARACTER(LEN=10) :: VARNAME1(5),VARNAME2(5)
253 #ifdef W3_S
254  INTEGER, SAVE :: IENT = 0
255 #endif
256  !/
257  !/ ------------------------------------------------------------------- /
258  !/
259 #ifdef W3_S
260  CALL strace (ient, 'W3FLGRDUPDT')
261 #endif
262  !
263  varname1(1) = 'EF'; varname2(1) = 'E3D'
264  varname1(2) = 'TH1M'; varname2(2) = 'TH1MF'
265  varname1(3) = 'STH1M'; varname2(3) = 'STH1MF'
266  varname1(4) = 'TH2M'; varname2(4) = 'TH2MF'
267  varname1(5) = 'STH2M'; varname2(5) = 'STH2MF'
268 
269  DO i=1,5
270  IF (e3df(1,i).LE.0.OR.e3df(3,i).LT.e3df(2,i)) THEN
271  IF (flgrd(3,i).OR.flgr2(3,i)) THEN
272  WRITE(ndsen,1008) varname1(i),varname2(i)
273  END IF
274  flgrd(3,i)=.false.
275  flgr2(3,i)=.false.
276  END IF
277  END DO
278  IF (us3df(1).LE.0.OR.us3df(3).LT.us3df(2)) THEN
279  IF (flgrd(6,8).OR.flgr2(6,8)) THEN
280  WRITE(ndsen,1008) 'USF','US3D'
281  END IF
282  flgrd(6,8)=.false.
283  flgr2(6,8)=.false.
284  END IF
285  IF (usspf(1).LE.0.OR.usspf(2).LE.0) THEN
286  IF (flgrd(6,12).OR.flgr2(6,12)) THEN
287  WRITE(ndsen,1008) 'USP','USSP'
288  END IF
289  flgrd(6,12)=.false.
290  flgr2(6,12)=.false.
291  END IF
292  IF (p2msf(1).LE.0.OR.p2msf(3).LT.p2msf(2)) THEN
293  IF (flgrd(6,9).OR.flgr2(6,9)) THEN
294  WRITE(ndsen,1008) 'P2L','P2SF'
295  END IF
296  flgrd(6,9)=.false.
297  flgr2(6,9)=.false.
298  END IF
299  !
300  flgd(3) = .false.
301  flg2(3) = .false.
302  IF(any(flgrd(3,:))) flgd(3)=.true.
303  IF(any(flgr2(3,:))) flg2(3)=.true.
304  flgd(6) = .false.
305  flg2(6) = .false.
306  IF(any(flgrd(6,:))) flgd(6)=.true.
307  IF(any(flgr2(6,:))) flg2(6)=.true.
308  !
309  RETURN
310  !
311 1008 FORMAT (/' *** WAVEWATCH III WARNING : '/ &
312  ' PARAMETER ',a,' not allowed: need to set', &
313  ' parameter ',a,' in OUTS namelist (in ww3_grid.inp)' &
314  ' with proper bounds' )
315  !
316  END SUBROUTINE w3flgrdupdt
317  !/ ------------------------------------------------------------------- /
334  SUBROUTINE w3readflgrd ( NDSI , NDSO, NDSS, NDSEN, COMSTR, &
335  FLG1D, FLG2D, IAPROC, NAPOUT, IERR)
336  !/
337  !/ +-----------------------------------+
338  !/ | WAVEWATCH III NOAA/NCEP |
339  !/ | F. Ardhuin |
340  !/ | FORTRAN 90 |
341  !/ | Last update : 25-Sep-2020 |
342  !/ +-----------------------------------+
343  !/
344  !/ 15-Apr-2013 : Origination. ( version 4.10 )
345  !/ 31-Jan-2014 : Bug fix warning output (Tolman). ( version 4.18 )
346  !/ 30-Apr-2014 : Add th2m and sth2m calculation ( version 5.01 )
347  !/ 25-Sep-2020 : Calculate FLG1D for any processor ( version 7.10 )
348  !/ 03-Nov-2020 : Factored out NAME matching into ( version 7.12 )
349  !/ seperate subroutine (C. Bunney)
350  !/
351  ! 1. Purpose :
352  !
353  ! Fills in FLG1D and FLG2D arrays from ASCII input file
354  !
355  ! 3. Parameters :
356  !
357  ! Parameter list
358  ! ----------------------------------------------------------------
359  ! NDSI Int. I Input file logical unit number
360  ! NDSO Int. I Output file logical unit number
361  ! NDSS Int. I Screen file logical unit number
362  ! NDSEN R.A. I Error output file logical unit number
363  ! COMSTR Char I Comment string, usually '$'
364  ! FLG1D L.A. O 1D array of flags for groups
365  ! FLG2D L.A. O 2D array of flags
366  ! IAPROC Int. I index of current processor
367  ! NAPOUT Int. I index of processor for output (screen)
368  ! IERR Int. O Error message number
369  ! ----------------------------------------------------------------
370  !
371  !
372  ! 4. Subroutines used :
373  !
374  ! None
375  !
376  ! 5. Called by :
377  !
378  ! Name Type Module Description
379  ! ----------------------------------------------------------------
380  ! WW3_SHEL Prog. N/A Actual wave model program
381  ! WW3_OUTF Prog. N/A Output postprocessor.
382  ! WW3_OUNF Prog. N/A NetCDF output postprocessor.
383  ! ----------------------------------------------------------------
384  !
385  ! 6. Error messages :
386  !
387  ! None.
388  !
389  ! 8. Structure :
390  !
391  ! See source code.
392  !
393  ! 9. Switches :
394  !
395  ! !/S Enable subroutine tracing.
396  ! !/T Test output.
397  !
398  ! 10. Source code :
399  !
400  !/ ------------------------------------------------------------------- /
401  USE constants
402  USE w3gdatmd, ONLY: us3df, usspf
403  USE w3odatmd, ONLY: nogrp, ngrpp, noge, idout
404  USE w3servmd, ONLY: nextln, strsplit, str_to_upper
405 #ifdef W3_S
406  USE w3servmd, ONLY: strace
407 #endif
408  !
409  IMPLICIT NONE
410  !/
411  !/ ------------------------------------------------------------------- /
412  !/ Parameter list
413  !/
414  INTEGER, INTENT(IN) :: NDSI, NDSO, NDSS, NDSEN, IAPROC, NAPOUT
415  INTEGER, INTENT(OUT) :: IERR
416  CHARACTER(LEN=1) :: COMSTR
417  LOGICAL, INTENT(OUT) :: FLG2D(NOGRP,NGRPP), FLG1D(NOGRP)
418  CHARACTER(LEN=100) :: OUT_NAMES(100), TESTSTR
419  !/
420  !/ ------------------------------------------------------------------- /
421  !/ Local parameters
422  !/
423  INTEGER :: IFI, IFJ, IOUT
424 #ifdef W3_S
425  INTEGER, SAVE :: IENT = 0
426 #endif
427  CHARACTER(LEN=1) :: AFLG
428  LOGICAL :: FLT, NAMES
429  !/
430  !/ ------------------------------------------------------------------- /
431  !/
432 #ifdef W3_S
433  CALL strace (ient, 'W3READFLGRD')
434 #endif
435  !
436  !
437  ! 1. Initialize flags -------------------------------------- *
438  !
439  ierr=0
440  flg2d(:,:)=.false. ! Initialize FLG2D
441  flg1d(:)=.false. ! Initialize FLOG
442  names =.false.
443  !
444  DO ifi=1,nogrp ! Loop over field output groups
445  !
446  CALL nextln ( comstr , ndsi , ndsen )
447  READ (ndsi,*,END=2001,ERR=2002) aflg
448  IF (aflg.EQ.'T') THEN
449  flg1d(ifi)=.true.
450  ELSE IF (aflg.EQ.'F') THEN
451  flg1d(ifi)=.false.
452  ELSE IF (aflg.EQ.'N') THEN
453  names=.true.
454  EXIT
455  ELSE
456  ierr=1
457  GOTO 2005
458  END IF
459  IF ( flg1d(ifi) ) THEN ! Skip if group not requested
460  CALL nextln ( comstr , ndsi , ndsen )
461  READ (ndsi,'(A)',END=2001,ERR=2006,IOSTAT=IERR) &
462  fldout
463  out_names(:)=''
464  CALL strsplit(fldout,out_names)
465  ifj=0
466  DO WHILE (len_trim(out_names(ifj+1)).NE.0)
467  ifj=ifj+1
468  IF ( out_names(ifj) .EQ. 'T' ) &
469  flg2d(ifi,ifj)=.true.
470  ENDDO
471  IF ( iaproc .EQ. napout .AND. ifj .LT. noge(ifi) ) WRITE(ndsen,1007) ifi
472  ENDIF
473  END DO
474  !
475  IF (names) THEN
476  !
477  ! 2. Reads and splits list of output field names
478  !
479  CALL nextln ( comstr , ndsi , ndsen )
480  READ (ndsi,'(A)',END=2001,ERR=2003,IOSTAT=IERR) fldout
481  out_names(:)=''
482  CALL strsplit(fldout,out_names)
483  iout=0
484  DO WHILE (len_trim(out_names(iout+1)).NE.0)
485  CALL str_to_upper(out_names(iout+1))
486  !
487  ! 2. Matches names with expected ...
488  !
489  teststr=out_names(iout+1)
490  CALL w3fldtoij(teststr, ifi, ifj, iaproc, napout, ndsen)
491 
492  IF(ifi .NE. -1) THEN
493  flg2d(ifi, ifj) = .true.
494  ENDIF
495  !
496  iout=iout+1
497  !
498  END DO
499  !
500  END IF
501  !
502  flt = .true.
503  DO ifi=1, nogrp
504  IF ( iaproc .EQ. napout ) THEN
505  DO ifj=1, ngrpp
506  IF ( flg2d(ifi,ifj) ) THEN
507  IF ( flt ) THEN
508  WRITE (ndso,1945) idout(ifi,ifj)
509  flt = .false.
510  ELSE
511  WRITE (ndso,1946) idout(ifi,ifj)
512  END IF
513  END IF
514  END DO
515  END IF
516  IF(any(flg2d(ifi,:))) flg1d(ifi)=.true. !Update FLG1D
517  END DO
518  IF ( iaproc .EQ. napout ) THEN
519  IF ( flt ) WRITE (ndso,1945) 'no fields defined'
520  END IF
521  !
522  RETURN
523  !
524 2001 CONTINUE
525  IF ( iaproc .EQ. napout ) WRITE (ndsen,1001)
526  RETURN
527 2002 CONTINUE
528  IF ( iaproc .EQ. napout ) WRITE (ndsen, 1002) ifi, ierr
529  RETURN
530 2003 CONTINUE
531  IF ( iaproc .EQ. napout ) WRITE (ndsen, 1003) ierr
532  RETURN
533  !2004 CONTINUE ! replaced by warning in code ....
534 2005 CONTINUE
535  IF ( iaproc .EQ. napout ) WRITE (ndsen, 1005) aflg
536  RETURN
537 2006 CONTINUE
538  IF ( iaproc .EQ. napout ) WRITE (ndsen, 1006) ifi,ierr
539  RETURN
540  !
541 1945 FORMAT ( ' Fields : ',a)
542 1946 FORMAT ( ' ',a)
543  !
544 1001 FORMAT (/' *** WAVEWATCH III ERROR : '/ &
545  ' PREMATURE END OF INPUT FILE'/)
546  !
547 1002 FORMAT (/' *** WAVEWATCH III ERROR : '/ &
548  ' ERROR IN READING OUTPUT FIELDS GROUP FLAGS ', &
549  i2, /, ' IOSTAT =',i5/)
550  !
551 1003 FORMAT (/' *** WAVEWATCH III ERROR : '/ &
552  ' ERROR READING OUTPUT FIELD NAMES FROM INPUT FILE'/&
553  ' IOSTAT =',i5/)
554  !
555 1005 FORMAT (/' *** WAVEWATCH III ERROR : '/ &
556  ' WAS EXPECTING "T" "F" or "N", but found "',a,'".'/)
557  !
558 1006 FORMAT (/' *** WAVEWATCH III ERROR : '/ &
559  ' ERROR IN READING OUTPUT FIELDS FLAGS FOR GROUP ', &
560  i2, /, ' IOSTAT =',i5/)
561  !
562 1007 FORMAT (/' *** WAVEWATCH III WARNING : '/ &
563  ' NUMBER OF REQUESTED OUTPUT FIELD FLAGS IN GROUP ',&
564  i2, /,' LESS THAN AVAILABLE, CHECK DOCS FOR MORE OPTIONS')
565  !
566  END SUBROUTINE w3readflgrd
567 
568  !/ ------------------------------------------------------------------- /
584  SUBROUTINE w3flgrdflag ( NDSO, NDSS, NDSEN, FLDOUT, &
585  FLG1D, FLG2D, IAPROC, NAPOUT, IERR)
586  !/
587  !/ +-----------------------------------+
588  !/ | WAVEWATCH III NOAA/NCEP |
589  !/ | F. Ardhuin |
590  !/ | FORTRAN 90 |
591  !/ | Last update : 25-Sep-2020 |
592  !/ +-----------------------------------+
593  !/
594  !/ 15-Apr-2013 : Origination. ( version 4.10 )
595  !/ 31-Jan-2014 : Bug fix warning output (Tolman). ( version 4.18 )
596  !/ 30-Apr-2014 : Add th2m and sth2m calculation ( version 5.01 )
597  !/ 17-Feb-2016 : New version for namelist use ( version 5.11 )
598  !/ 25-Sep-2020 : Calculate FLG1D for any processor ( version 7.10 )
599  !/ 03-Nov-2020 : Factored out NAME matching into ( version 7.12 )
600  !/ seperate subroutine (C. Bunney)
601  !/
602  ! 1. Purpose :
603  !
604  ! Fills in FLG1D and FLG2D arrays from ASCII input file
605  !
606  ! 3. Parameters :
607  !
608  ! Parameter list
609  ! ----------------------------------------------------------------
610  ! NDSO Int. I Output file logical unit number
611  ! NDSS Int. I Screen file logical unit number
612  ! NDSEN R.A. I Error output file logical unit number
613  ! FLDOUT Cha. I List of field names
614  ! FLG1D L.A. O 1D array of flags for groups
615  ! FLG2D L.A. O 2D array of flags
616  ! IAPROC Int. I index of current processor
617  ! NAPOUT Int. I index of processor for output (screen)
618  ! IERR Int. O Error message number
619  ! ----------------------------------------------------------------
620  !
621  !
622  ! 4. Subroutines used :
623  !
624  ! None
625  !
626  ! 5. Called by :
627  !
628  ! Name Type Module Description
629  ! ----------------------------------------------------------------
630  ! WW3_SHEL Prog. N/A Actual wave model program
631  ! WW3_OUTF Prog. N/A Output postprocessor.
632  ! WW3_OUNF Prog. N/A NetCDF output postprocessor.
633  ! ----------------------------------------------------------------
634  !
635  ! 6. Error messages :
636  !
637  ! None.
638  !
639  ! 8. Structure :
640  !
641  ! See source code.
642  !
643  ! 9. Switches :
644  !
645  ! !/S Enable subroutine tracing.
646  ! !/T Test output.
647  !
648  ! 10. Source code :
649  !
650  !/ ------------------------------------------------------------------- /
651  USE constants
652  USE w3odatmd, ONLY: nogrp, ngrpp, idout
653  USE w3servmd, ONLY: strsplit, str_to_upper
654  USE w3gdatmd, ONLY: us3df, usspf
655 #ifdef W3_S
656  USE w3servmd, ONLY: strace
657 #endif
658  !
659  IMPLICIT NONE
660  !/
661  !/ ------------------------------------------------------------------- /
662  !/ Parameter list
663  !/
664  INTEGER, INTENT(IN) :: NDSO, NDSS, NDSEN, IAPROC, NAPOUT
665  CHARACTER(1024), INTENT(IN) :: FLDOUT
666  INTEGER, INTENT(OUT) :: IERR
667  LOGICAL, INTENT(OUT) :: FLG2D(NOGRP,NGRPP), FLG1D(NOGRP)
668  CHARACTER(LEN=100) :: OUT_NAMES(100), TESTSTR
669  !/
670  !/ ------------------------------------------------------------------- /
671  !/ Local parameters
672  !/
673  INTEGER :: I, IFI, IFJ, IOUT
674 #ifdef W3_S
675  INTEGER, SAVE :: IENT = 0
676 #endif
677  LOGICAL :: FLT
678  !/
679  !/ ------------------------------------------------------------------- /
680  !/
681 #ifdef W3_S
682  CALL strace (ient, 'W3FLGRDFLAG')
683 #endif
684  !
685  !
686  ! 1. Initialize flags -------------------------------------- *
687  !
688  ierr=0
689  flg2d(:,:)=.false. ! Initialize FLG2D
690  flg1d(:)=.false. ! Initialize FLOG
691  !
692  ! 2. Splits list of output field names
693  !
694  out_names(:)=''
695  CALL strsplit(fldout,out_names)
696  iout=0
697  DO WHILE (len_trim(out_names(iout+1)).NE.0)
698  CALL str_to_upper(out_names(iout+1))
699  !
700  ! 2. Matches names with expected ...
701  !
702  teststr=out_names(iout+1)
703  CALL w3fldtoij(teststr, ifi, ifj, iaproc, napout, ndsen)
704 
705  IF(ifi .NE. -1) THEN
706  flg2d(ifi, ifj) = .true.
707  ENDIF
708  !
709  iout=iout+1
710  !
711  END DO
712  !
713  flt = .true.
714  DO ifi=1, nogrp
715  IF ( iaproc .EQ. napout ) THEN
716  DO ifj=1, ngrpp
717  IF ( flg2d(ifi,ifj) ) THEN
718  IF ( flt ) THEN
719  WRITE (ndso,1945) idout(ifi,ifj)
720  flt = .false.
721  ELSE
722  WRITE (ndso,1946) idout(ifi,ifj)
723  END IF
724  END IF
725  END DO
726  ENDIF
727  IF(any(flg2d(ifi,:))) flg1d(ifi)=.true. !Update FLG1D
728  END DO
729  IF ( iaproc .EQ. napout ) THEN
730  IF ( flt ) WRITE (ndso,1945) 'no fields defined'
731  ENDIF
732  !
733  RETURN
734  !
735 1945 FORMAT ( ' Fields : ',a)
736 1946 FORMAT ( ' ',a)
737  !
738  ! 1004 FORMAT (/' *** WAVEWATCH III WARNING : '/ &
739  ! ' REQUESTED OUTPUT FIELD ',A,' WAS NOT RECOGNIZED.'/)
740  !!
741  ! 1008 FORMAT (/' *** WAVEWATCH III WARNING : '/ &
742  ! ' PARAMETER ',A,' not allowed: need to set', &
743  ! ' parameter ',A,' in OUTS namelist (in ww3_grid.inp)')
744  !
745  END SUBROUTINE w3flgrdflag
746 
747  !/ ------------------------------------------------------------------- /
760  SUBROUTINE w3fldtoij(FLD, I, J, IAPROC, NAPOUT, NDSEN)
761  !/
762  !/ +-----------------------------------+
763  !/ | WAVEWATCH III NOAA/NCEP |
764  !/ | C. Bunney |
765  !/ | FORTRAN 90 |
766  !/ | Last update : 22-Mar-2021 |
767  !/ +-----------------------------------+
768  !/
769  !/ 03-Nov-2020 : Origination. ( version 7.12 )
770  !/ 22-Mar-2021 : Add extra coupling fields as output ( version 7.13 )
771  !
772  ! 1. Purpose :
773  !
774  ! Returns the group/field (I/J) indices for a named output field.
775  !
776  ! 3. Parameters :
777  !
778  ! Parameter list
779  ! ----------------------------------------------------------------
780  ! FLD Cha. I Field names
781  ! I Int. O Output group number (IFI)
782  ! J Int. O Output field number (IFJ)
783  ! IAPROC Int. I index of current processor
784  ! NAPOUT Int. I index of processor for output (screen)
785  ! NDSEN R.A. I Error output file logical unit number
786  ! ----------------------------------------------------------------
787  !
788  !/ ------------------------------------------------------------------- /
789  USE w3gdatmd, ONLY: us3df, usspf
790  IMPLICIT NONE
791  !/
792  !/ ------------------------------------------------------------------- /
793  !/ Local parameters
794  !/
795  CHARACTER(LEN=*), INTENT(IN) :: FLD
796  INTEGER, INTENT(IN) :: IAPROC, NAPOUT, NDSEN
797  INTEGER, INTENT(OUT) :: I, J
798 
799  i = -1
800  j = -1
801 
802  SELECT CASE(trim(fld(1:6)))
803  !
804  ! Group 1
805  !
806  CASE('DPT')
807  i = 1
808  j = 1
809  CASE('CUR')
810  i = 1
811  j = 2
812  CASE('WND')
813  i = 1
814  j = 3
815  CASE('AST')
816  i = 1
817  j = 4
818  CASE('WLV')
819  i = 1
820  j = 5
821  CASE('ICE')
822  i = 1
823  j = 6
824  CASE('IBG')
825  i = 1
826  j = 7
827  CASE('TAU')
828  i = 1
829  j = 8
830  CASE('RHO')
831  i = 1
832  j = 9
833 #ifdef W3_BT4
834  CASE('D50')
835  i = 1
836  j = 10
837 #endif
838 #ifdef W3_IS2
839  CASE('IC1')
840  i = 1
841  j = 11
842  CASE('IC5')
843  i = 1
844  j = 12
845 #endif
846  ! Group 2
847  !
848 #ifdef W3_OASACM
849  CASE('AHS')
850  i = 2
851  j = 1
852 #endif
853 #ifdef W3_OASOCM
854  CASE('OHS')
855  i = 2
856  j = 1
857 #endif
858  CASE('HS')
859  i = 2
860  j = 1
861  CASE('LM')
862  i = 2
863  j = 2
864  CASE('T02')
865  i = 2
866  j = 3
867  CASE('T0M1')
868  i = 2
869  j = 4
870  CASE('T01')
871  i = 2
872  j = 5
873  CASE('FP')
874  i = 2
875  j = 6
876  CASE('DIR')
877  i = 2
878  j = 7
879  CASE('SPR')
880  i = 2
881  j = 8
882  CASE('DP')
883  i = 2
884  j = 9
885  CASE('HIG')
886  i = 2
887  j = 10
888  CASE('MXE')
889  i = 2
890  j = 11
891  CASE('MXES')
892  i = 2
893  j = 12
894  CASE('MXH')
895  i = 2
896  j = 13
897  CASE('MXHC')
898  i = 2
899  j = 14
900  CASE('SDMH')
901  i = 2
902  j = 15
903  CASE('SDMHC')
904  i = 2
905  j = 16
906  CASE('WBT')
907  i = 2
908  j = 17
909  CASE('TP') ! Uses FP0 internally, as per FP
910  i = 2
911  j = 18
912  CASE('WNM')
913  i = 2
914  j = 19
915 #ifdef W3_OASOCM
916  CASE('THM')
917  i = 2
918  j = 20
919 #endif
920  !
921  ! Group 3
922  !
923  CASE('EF')
924  i = 3
925  j = 1
926  CASE('TH1M')
927  i = 3
928  j = 2
929  CASE('STH1M')
930  i = 3
931  j = 3
932  CASE('TH2M')
933  i = 3
934  j = 4
935  CASE('STH2M')
936  i = 3
937  j = 5
938  CASE('WN')
939  i = 3
940  j = 6
941  !
942  ! Group 4
943  !
944  CASE('PHS')
945  i = 4
946  j = 1
947  CASE('PTP')
948  i = 4
949  j = 2
950  CASE('PLP')
951  i = 4
952  j = 3
953  CASE('PDIR')
954  i = 4
955  j = 4
956  CASE('PSPR')
957  i = 4
958  j = 5
959  CASE('PWS')
960  i = 4
961  j = 6
962  CASE('PDP')
963  i = 4
964  j = 7
965  CASE('PQP')
966  i = 4
967  j = 8
968  CASE('PPE')
969  i = 4
970  j = 9
971  CASE('PGW')
972  i = 4
973  j = 10
974  CASE('PSW')
975  i = 4
976  j = 11
977  CASE('PTM10')
978  i = 4
979  j = 12
980  CASE('PT01')
981  i = 4
982  j = 13
983  CASE('PT02')
984  i = 4
985  j = 14
986  CASE('PEP')
987  i = 4
988  j = 15
989  CASE('TWS')
990  i = 4
991  j = 16
992  CASE('PNR')
993  i = 4
994  j = 17
995  !
996  ! Group 5
997  !
998  CASE('UST')
999  i = 5
1000  j = 1
1001 #ifdef W3_OASACM
1002  CASE('ACHA')
1003  i = 5
1004  j = 2
1005 #endif
1006 #ifdef W3_OASOCM
1007  CASE('OCHA')
1008  i = 5
1009  j = 2
1010 #endif
1011  CASE('CHA')
1012  i = 5
1013  j = 2
1014  CASE('CGE')
1015  i = 5
1016  j = 3
1017  CASE('FAW')
1018  i = 5
1019  j = 4
1020  CASE('TAW')
1021  i = 5
1022  j = 5
1023  CASE('TWA')
1024  i = 5
1025  j = 6
1026  CASE('WCC')
1027  i = 5
1028  j = 7
1029  CASE('WCF')
1030  i = 5
1031  j = 8
1032  CASE('WCH')
1033  i = 5
1034  j = 9
1035  CASE('WCM')
1036  i = 5
1037  j = 10
1038  CASE('FWS')
1039  i = 5
1040  j = 11
1041  !
1042  ! Group 6
1043  !
1044  CASE('SXY')
1045  i = 6
1046  j = 1
1047  CASE('TWO')
1048  i = 6
1049  j = 2
1050  CASE('BHD')
1051  i = 6
1052  j = 3
1053  CASE('FOC')
1054  i = 6
1055  j = 4
1056  CASE('TUS')
1057  i = 6
1058  j = 5
1059  CASE('USS')
1060  i = 6
1061  j = 6
1062  CASE('P2S')
1063  i = 6
1064  j = 7
1065  CASE('USF')
1066  IF (us3df(1).GE.1) THEN
1067  i = 6
1068  j = 8
1069  ELSE
1070  IF ( iaproc .EQ. napout ) WRITE(ndsen,1008) 'USF','US3D'
1071  END IF
1072  CASE('P2L')
1073  i = 6
1074  j = 9
1075  CASE('TWI')
1076  i = 6
1077  j = 10
1078  CASE('FIC')
1079  i = 6
1080  j = 11
1081  CASE('USP')
1082  IF (usspf(1).GE.1) THEN
1083  i = 6
1084  j = 12
1085  ELSE
1086  IF ( iaproc .EQ. napout ) WRITE(ndsen,1008) 'USP','USSP'
1087  END IF
1088  CASE('TOC')
1089  i = 6
1090  j = 13
1091  !
1092  ! Group 7
1093  !
1094  CASE('ABR')
1095  i = 7
1096  j = 1
1097  CASE('UBR')
1098  i = 7
1099  j = 2
1100  CASE('BED')
1101  i = 7
1102  j = 3
1103  CASE('FBB')
1104  i = 7
1105  j = 4
1106  CASE('TBB')
1107  i = 7
1108  j = 5
1109  !
1110  ! Group 8
1111  !
1112  CASE('MSS')
1113  i = 8
1114  j = 1
1115  CASE('MSC')
1116  i = 8
1117  j = 2
1118  CASE('MSD')
1119  i = 8
1120  j = 3
1121  CASE('MCD')
1122  i = 8
1123  j = 4
1124  CASE('QP')
1125  i = 8
1126  j = 5
1127  CASE('QKK')
1128  i = 8
1129  j = 6
1130  CASE('SKW')
1131  i = 8
1132  j = 7
1133  CASE('EMB')
1134  i = 8
1135  j = 8
1136  CASE('EMC')
1137  i = 8
1138  j = 9
1139  !
1140  ! Group 9
1141  !
1142  CASE('DTD')
1143  i = 9
1144  j = 1
1145  CASE('FC')
1146  i = 9
1147  j = 2
1148  CASE('CFX')
1149  i = 9
1150  j = 3
1151  CASE('CFD')
1152  i = 9
1153  j = 4
1154  CASE('CFK')
1155  i = 9
1156  j = 5
1157  !
1158  ! Group 10
1159  !
1160  CASE('U1')
1161  i = 10
1162  j = 1
1163  CASE('U2')
1164  i = 10
1165  j = 1
1166  ! Not found:
1167 #ifdef W3_COU
1168  CASE('DRY')
1169 #endif
1170  CASE('UNSET')
1171  CASE DEFAULT
1172  i = -1
1173  j = -1
1174  IF ( iaproc .EQ. napout ) WRITE (ndsen,1004) trim(fld)
1175  END SELECT
1176 
1177 1004 FORMAT (/' *** WAVEWATCH III WARNING : '/ &
1178  ' REQUESTED OUTPUT FIELD ',a,' WAS NOT RECOGNIZED.'/)
1179  !
1180 1008 FORMAT (/' *** WAVEWATCH III WARNING : '/ &
1181  ' PARAMETER ',a,' not allowed: need to set', &
1182  ' parameter ',a,' in OUTS namelist (in ww3_grid.inp)')
1183  !
1184  END SUBROUTINE w3fldtoij
1185 
1186  !/ ------------------------------------------------------------------- /
1197  SUBROUTINE w3outg ( A, FLPART, FLOUTG, FLOUTG2 )
1198  !/
1199  !/ +-----------------------------------+
1200  !/ | WAVEWATCH III NOAA/NCEP |
1201  !/ | H. L. Tolman |
1202  !/ | FORTRAN 90 |
1203  !/ | Last update : 10-Apr-2015 |
1204  !/ +-----------------------------------+
1205  !/
1206  !/ 10-Dec-1998 : Distributed FORTRAN 77 version. ( version 1.18 )
1207  !/ 04-Jan-2000 : Upgrade to FORTRAN 90 ( version 2.00 )
1208  !/ Major changes to logistics.
1209  !/ 09-May-2002 : Switch clean up. ( version 2.21 )
1210  !/ 19-Oct-2004 : Multiple grid version. ( version 3.06 )
1211  !/ 21-Jul-2005 : Adding output fields 19-21. ( version 3.07 )
1212  !/ 23-Apr-2006 : Filter for directional spread. ( version 3.09 )
1213  !/ 02-Apr-2007 : Adding partitioned output. ( version 3.11 )
1214  !/ Adding user slots for outputs.
1215  !/ 08-Oct-2007 : Adding ST3 source term option. ( version 3.13 )
1216  !/ ( F. Ardhuin )
1217  !/ 05-Mar-2008 : Added NEC sxf90 compiler directives
1218  !/ (Chris Bunney, UK Met Office) ( version 3.13 )
1219  !/ 25-Dec-2012 : New output structure and smaller ( version 4.11 )
1220  !/ memory footprint.
1221  !/ 10-Feb-2014 : Bug correction for US3D: div. by df ( version 4.18 )
1222  !/ 30-Apr-2014 : Add th2m and sth2m calculation ( version 5.01 )
1223  !/ 27-May-2014 : Switch to OMPG switch. ( version 5.02 )
1224  !/ 10-Apr-2015 : Remove unused variables ( version 5.08 )
1225  !/ 10-Jan-2017 : Separate Stokes drift calculation ( version 6.01 )
1226  !/ 01-Mar-2018 : Removed RTD code (now used in post ( version 6.02 )
1227  !/ processing code)
1228  !/ 22-Aug-2018 : Add WBT parameter ( version 6.06 )
1229  !/ 25-Sep-2019 : Corrected th2m and sth2m ( version 6.07 )
1230  !/ calculations. (J Dykes, NRL)
1231  !/
1232  ! 1. Purpose :
1233  !
1234  ! Fill necessary arrays with gridded data for output.
1235  !
1236  ! 3. Parameters :
1237  !
1238  ! Parameter list
1239  ! ----------------------------------------------------------------
1240  ! A R.A. I Input spectra. Left in par list to change
1241  ! shape.
1242  ! FLPART Log. I Flag for filling fields with part. data.
1243  ! FLOUTG Log. I Flag for file field output
1244  ! FLOUTG2 Log. I Flag for coupling field output
1245  ! ----------------------------------------------------------------
1246  !
1247  ! Locally saved parameters
1248  ! ----------------------------------------------------------------
1249  ! HSMIN Real Filter level in Hs for calculation of mean
1250  ! wave parameters.
1251  ! ----------------------------------------------------------------
1252  !
1253  ! 4. Subroutines used :
1254  !
1255  ! See module documentation.
1256  !
1257  ! 5. Called by :
1258  !
1259  ! Name Type Module Description
1260  ! ----------------------------------------------------------------
1261  ! W3WAVE Subr. W3WAVEMD Actual wave model routine.
1262  ! ----------------------------------------------------------------
1263  !
1264  ! 6. Error messages :
1265  !
1266  ! None.
1267  !
1268  ! 8. Structure :
1269  !
1270  ! See source code.
1271  !
1272  ! 9. Switches :
1273  !
1274  ! !/SHRD Switch for shared / distributed memory architecture.
1275  ! !/DIST Id.
1276  !
1277  ! !/OMPG OpenMP compiler directive for loop splitting.
1278  !
1279  ! !/O8 Filter for low wave heights ( HSMIN )
1280  ! !/O9 Negative wave height alowed, other mean parameters will
1281  ! not be correct.
1282  !
1283  ! !/ST0 No source terms.
1284  ! !/ST1 Source term set 1 (WAM equiv.)
1285  ! !/ST2 Source term set 2 (Tolman and Chalikov)
1286  ! !/ST3 Source term set 3 (WAM 4+)
1287  ! !/ST6 Source term set 6 (BYDRZ)
1288  !
1289  ! !/S Enable subroutine tracing.
1290  ! !/T Test output.
1291  !
1292  ! 10. Source code :
1293  !
1294  !/ ------------------------------------------------------------------- /
1295  USE constants
1296  USE w3gdatmd
1297  USE w3wdatmd, ONLY: ust, fpis
1298  USE w3adatmd, ONLY: cg, wn, dw
1299  USE w3adatmd, ONLY: hs, wlm, t02, t0m1, t01, fp0, &
1300  thm, ths, thp0
1301  USE w3adatmd, ONLY: aba, abd, uba, ubd, fcut, sxx, &
1302  syy, sxy, phs, ptp, plp, pdir, psi, pws, &
1303  pwst, pnr, usero, tusx, tusy, prms, tpms, &
1304  ussx, ussy, mssx, mssy, mssd, mscx, mscy, &
1305  mscd, charn, &
1306  bhd, cge, p2sms, us3d, ef, th1m, sth1m, &
1307  th2m, sth2m, hsig, stmaxe, stmaxd, &
1308  hcmaxe, hmaxe, hcmaxd, hmaxd, ussp, qp, pqp,&
1309  pthp0, ppe, pgw, psw, ptm1, pt1, pt2, pep, &
1310  wbt, qkk
1311  USE w3odatmd, ONLY: ndst, undef, iaproc, naproc, napfld, &
1313  nogrp, ngrpp
1314  USE w3adatmd, ONLY: nsealm
1315 #ifdef W3_S
1316  USE w3servmd, ONLY: strace
1317 #endif
1318  !
1319  USE w3parall, ONLY : init_get_isea
1320  IMPLICIT NONE
1321  !/
1322  !/ ------------------------------------------------------------------- /
1323  !/ Parameter list
1324  !/
1325  REAL, INTENT(IN) :: A(NTH,NK,0:NSEAL)
1326  LOGICAL, INTENT(IN) :: FLPART, FLOUTG, FLOUTG2
1327  !/
1328  !/ ------------------------------------------------------------------- /
1329  !/ Local parameters
1330  !/
1331  INTEGER :: IK, ITH, JSEA, ISEA, IX, IY, &
1332  IKP0(NSEAL), NKH(NSEAL), &
1333  I, J, LKMS, HKMS, ITL
1334 #ifdef W3_S
1335  INTEGER, SAVE :: IENT = 0
1336 #endif
1337  REAL :: FXPMC, FACTOR, FACTOR2, EBAND, FKD, &
1338  AABS, UABS, &
1339  XL, XH, XL2, XH2, EL, EH, DENOM, KD, &
1340  M1, M2, MA, MB, MC, STEX, STEY, STED
1341  REAL :: ET(NSEAL), EWN(NSEAL), ETR(NSEAL), &
1342  ETX(NSEAL), ETY(NSEAL), AB(NSEAL), &
1343  ETXX(NSEAL), ETYY(NSEAL), ETXY(NSEAL),&
1344  ABX(NSEAL), ABY(NSEAL),ET02(NSEAL), &
1345  EBD(NK,NSEAL), EC(NSEAL), &
1346  ABR(NSEAL), UBR(NSEAL), UBS(NSEAL), &
1347  ABX2(NSEAL), ABY2(NSEAL), &
1348  AB2X(NSEAL), AB2Y(NSEAL), &
1349  ABST(NSEAL), ABXX(NSEAL), &
1350  ABYY(NSEAL), ABXY(NSEAL), &
1351  ABYX(NSEAL), EET1(NSEAL), &
1352  ETUSCX(NSEAL), ETUSCY(NSEAL), &
1353  ETMSSL(NSEAL), ETMSSCL(NSEAL), &
1354  ETTPMM(NSEAL), ETF(NSEAL), &
1355  ET1(NSEAL), ABX2M(NSEAL), &
1356  ABY2M(NSEAL), ABXM(NSEAL), &
1357  ABYM(NSEAL), ABXYM(NSEAL), &
1358  MSSXM(NSEAL), MSSYM(NSEAL), &
1359  MSSXTM(NSEAL), MSSYTM(NSEAL), &
1360  MSSXYM(NSEAL), THMP(NSEAL), &
1361  T02P(NSEAL), NV(NSEAL), NS(NSEAL), &
1362  NB(NSEAL), MODE(NSEAL), &
1363  MU(NSEAL), NI(NSEAL), STMAXEL(NSEAL),&
1364  PHI(21,NSEAL),PHIST(NSEAL), &
1365  EBC(NK,NSEAL), ABP(NSEAL), &
1366  STMAXDL(NSEAL), TLPHI(NSEAL), &
1367  WL02X(NSEAL), WL02Y(NSEAL), &
1368  ALPXT(NSEAL), ALPYT(NSEAL), &
1369  ALPXY(NSEAL), SCREST(NSEAL), &
1370  QK1(NSEAL), QK2(NSEAL)
1371  REAL USSCO, FT1
1372  REAL, SAVE :: HSMIN = 0.01
1373  LOGICAL :: FLOLOC(NOGRP,NGRPP)
1374  !/
1375  !/ ------------------------------------------------------------------- /
1376  !/
1377 #ifdef W3_S
1378  CALL strace (ient, 'W3OUTG')
1379 #endif
1380  DO i=1,nogrp
1381  DO j=1,ngrpp
1382  floloc(i,j) = &
1383  ((floutg.AND.flogrd(i,j)).OR.(floutg2.AND.flogr2(i,j)))
1384  END DO
1385  END DO
1386  !
1387  fxpmc = 0.66 * grav / 28.
1388  hsmin = hsmin
1389  ft1 = 0.3333 * sig(nk)**2 * dth * sig(nk)
1390  !
1391  ! 1. Initialize storage arrays -------------------------------------- *
1392  !
1393  et = 0.
1394  et02 = 0.
1395  ewn = 0.
1396  etr = 0.
1397  et1 = 0.
1398  eet1 = 0.
1399  etx = 0.
1400  ety = 0.
1401  etxx = 0.
1402  etyy = 0.
1403  etxy = 0.
1404  abr = 0.
1405  aba = 0.
1406  abd = 0.
1407  ubr = 0.
1408  uba = 0.
1409  ubd = 0.
1410  ubs = 0.
1411  sxx = 0.
1412  syy = 0.
1413  sxy = 0.
1414  ussx = 0.
1415  ussy = 0.
1416  tusx = 0.
1417  tusy = 0.
1418  mssx = 0.
1419  mssy = 0.
1420  mssd = 0.
1421  mscx = 0.
1422  mscy = 0.
1423  mscd = 0.
1424  prms = 0.
1425  tpms = 0.
1426  etuscy = 0.
1427  etuscy = 0.
1428  etmssl = 0.
1429  etmsscl= 0.
1430  ettpmm = 0.
1431  ebd = 0.
1432  ec = 0.
1433  etf = 0.
1434  ebc = 0.
1435  bhd = 0.
1436  mssxm = 0.
1437  mssym = 0.
1438  mssxtm = 0.
1439  mssytm = 0.
1440  mssxym = 0.
1441  phi = 0.
1442  phist = 0.
1443  tlphi = 0.
1444  stmaxel = 0.
1445  stmaxdl = 0.
1446  qk2 = 0.
1447  !
1448  hs = undef
1449  wlm = undef
1450  t0m1 = undef
1451  t01 = undef
1452  t02 = undef
1453  fp0 = undef
1454  thm = undef
1455  ths = undef
1456  thp0 = undef
1457  hsig = undef
1458  wl02x = undef
1459  wl02y = undef
1460  alpxy = undef
1461  alpxt = undef
1462  alpyt = undef
1463  qkk = undef
1464  thmp = undef
1465  t02p = undef
1466  screst = undef
1467  nv = undef
1468  ns = undef
1469  nb = undef
1470  mu = undef
1471  ni = undef
1472  mode = undef
1473  stmaxe = undef
1474  stmaxd = undef
1475  hcmaxe = undef
1476  hmaxe = undef
1477  hcmaxd = undef
1478  hmaxd = undef
1479  qp = undef
1480  wbt = undef
1481  !
1482  ! 2. Integral over discrete part of spectrum ------------------------ *
1483  !
1484  DO ik=1, nk
1485  !
1486  ! 2.a Initialize energy in band
1487  !
1488  ab = 0.
1489  abx = 0.
1490  aby = 0.
1491  abx2 = 0.
1492  aby2 = 0.
1493  ab2x = 0.
1494  ab2y = 0.
1495  abxx = 0.
1496  abyy = 0.
1497  abxy = 0.
1498  abyx = 0.
1499  abst = 0.
1500  qk1 = 0.
1501  !
1502  ! 2.b Integrate energy in band
1503  !
1504  DO ith=1, nth
1505  !
1506 #ifdef W3_OMPG
1507  !$OMP PARALLEL DO PRIVATE(JSEA,ISEA,FACTOR)
1508 #endif
1509  !
1510  DO jsea=1, nseal
1511  nkh(jsea) = min( nk , &
1512  int(facti2+facti1*log(max(1.e-7,fcut(jsea)))) )
1513  ab(jsea) = ab(jsea) + a(ith,ik,jsea)
1514  abx(jsea) = abx(jsea) + a(ith,ik,jsea)*ecos(ith)
1515  aby(jsea) = aby(jsea) + a(ith,ik,jsea)*esin(ith)
1516  ! These are the integrals with cos^2 and sin^2
1517  abx2(jsea) = abx2(jsea) + a(ith,ik,jsea)*ec2(ith)
1518  aby2(jsea) = aby2(jsea) + a(ith,ik,jsea)*es2(ith)
1519  ! Using trig identities to represent cos2theta and sin2theta.
1520  ab2x(jsea) = ab2x(jsea) + a(ith,ik,jsea)*(2*ec2(ith) - 1)
1521  ab2y(jsea) = ab2y(jsea) + a(ith,ik,jsea)*(2*esc(ith))
1522  abyx(jsea) = abyx(jsea) + a(ith,ik,jsea)*esc(ith)
1523  IF (ith.LE.nth/2) THEN
1524  abst(jsea) = abst(jsea) + &
1525  a(ith,ik,jsea)*a(ith+nth/2,ik,jsea)
1526  qk1(jsea) = qk1(jsea) + (a(ith,ik,jsea)+a(ith+nth/2,ik,jsea))**2
1527  END IF
1528  CALL init_get_isea(isea, jsea)
1529  factor = max( 0.5 , cg(ik,isea)/sig(ik)*wn(ik,isea) )
1530  abxx(jsea) = abxx(jsea) + ((1.+ec2(ith))*factor-0.5) * &
1531  a(ith,ik,jsea)
1532  abyy(jsea) = abyy(jsea) + ((1.+es2(ith))*factor-0.5) * &
1533  a(ith,ik,jsea)
1534  abxy(jsea) = abxy(jsea) + esc(ith)*factor * a(ith,ik,jsea)
1535  END DO
1536  !
1537 #ifdef W3_OMPG
1538  !$OMP END PARALLEL DO
1539 #endif
1540  !
1541  END DO
1542  !
1543  ! 2.c Finalize integration over band and update mean arrays
1544  !
1545  !
1546 #ifdef W3_OMPG
1547  !$OMP PARALLEL DO PRIVATE(JSEA,ISEA,FACTOR,FACTOR2,MA,MC,MB,KD,FKD,USSCO,M1,M2)
1548 #endif
1549  !
1550  DO jsea=1, nseal
1551  CALL init_get_isea(isea, jsea)
1552  factor = dden(ik) / cg(ik,isea)
1553  ebd(ik,jsea) = ab(jsea) * factor ! this is E(f)*df
1554  et(jsea) = et(jsea) + ebd(ik,jsea)
1555 #ifdef W3_IG1
1556  IF (ik.EQ.nint(igpars(5))) hsig(jsea) = 4*sqrt(et(jsea))
1557 #endif
1558  etf(jsea) = etf(jsea) + ebd(ik,jsea) * cg(ik,isea)
1559  ewn(jsea) = ewn(jsea) + ebd(ik,jsea) / wn(ik,isea)
1560  etr(jsea) = etr(jsea) + ebd(ik,jsea) / sig(ik)
1561  et1(jsea) = et1(jsea) + ebd(ik,jsea) * sig(ik)
1562  ! EET1(JSEA) = EET1(JSEA)+ EBD(IK,JSEA)**2 * SIG(IK)
1563  eet1(jsea) = eet1(jsea)+ ebd(ik,jsea)**2 * sig(ik)/dsii(ik)
1564  et02(jsea) = et02(jsea)+ ebd(ik,jsea) * sig(ik)**2
1565  etx(jsea) = etx(jsea) + abx(jsea) * factor
1566  ety(jsea) = ety(jsea) + aby(jsea) * factor
1567  tusx(jsea) = tusx(jsea) + abx(jsea)*factor &
1568  *grav*wn(ik,isea)/sig(ik)
1569  tusy(jsea) = tusy(jsea) + aby(jsea)*factor &
1570  *grav*wn(ik,isea)/sig(ik)
1571  etxx(jsea) = etxx(jsea) + abx2(jsea) * factor* wn(ik,isea)**2
1572  ! NB: QK1 (JSEA) = QK1(JSEA) + A(ITH,IK,JSEA)**2
1573  qk2(jsea) = qk2(jsea) + qk1(jsea) * factor* sig(ik) /wn(ik,isea)
1574  etyy(jsea) = etyy(jsea) + aby2(jsea) * factor* wn(ik,isea)**2
1575  etxy(jsea) = etxy(jsea) + abyx(jsea) * factor* wn(ik,isea)**2
1576  IF (sig(ik)*0.5*(1+xfr).LT.0.4*tpi) THEN
1577  etmssl(jsea) = etmssl(jsea) + ab(jsea)*factor &
1578  *wn(ik,isea)**2
1579  ELSE
1580  IF (sig(max(ik-1,1))*0.5*(1+xfr).LT.0.4*tpi) THEN
1581  etmssl(jsea) = etmssl(jsea) + ab(jsea)*factor &
1582  *(sig(ik)*0.5*(1+1/xfr)-(0.4*tpi))/dsii(ik) &
1583  *wn(ik,isea)**2
1584  factor2 = sig(ik)**5/(grav**2)/dsii(ik)
1585  etmsscl(jsea) = ab(jsea)*factor*factor2
1586  END IF
1587  END IF
1588  !
1589  ubs(jsea) = ubs(jsea) + ab(jsea) * sig(ik)**2
1590  !
1591  ! 2nd order equivalent surface pressure spectral density at K=0
1592  ! this is used for microseismic or microbarom sources
1593  ! Finite water depth corrections (Ardhuin & Herbers 2013) are not
1594  ! included here.
1595  !
1596  factor2 = dth*2/(tpi**2) &
1597  * sig(ik) &
1598  * (tpi*sig(ik)/cg(ik,isea))**2 & ! Jacobian^2 to get E(f,th) from A(k,th)
1599  * abst(jsea)
1600  !
1601  ! Integration over seismic radian frequency : *2*dsigma
1602  !
1603  prms(jsea) = prms(jsea) + factor2 * 2 * dsii(ik)
1604  IF ( floloc(6, 9).AND.(ik.GE.p2msf(2).AND.ik.LE.p2msf(3))) &
1605  p2sms(jsea,ik) = factor2 * 2 * tpi
1606  IF (factor2 .GT. ettpmm(jsea)) THEN
1607  ettpmm(jsea) = factor2
1608  tpms(jsea) = tpi/sig(ik)
1609  END IF
1610 
1611  !
1612  ! Directional moments in the last freq. band
1613  !
1614  IF (ik.EQ.nk) THEN
1615  factor2 = sig(ik)**5/(grav**2)/dsii(ik)
1616  etuscx(jsea) = abx(jsea)*factor*factor2
1617  etuscy(jsea) = aby(jsea)*factor*factor2
1618  !
1619  ! NB: the slope PDF is proportional to ell1=ETYY*EC2-2*ETXY*ECS+ETYY*ES2 = A*EC2-2*B*ECS+C*ES2
1620  ! This is an ellipse equation with axis direction given by dir=0.5*ATAN2(-2.*ETXY,ETYY-ETXX)
1621  !
1622  ma = abx2(jsea) * factor * factor2
1623  mc = aby2(jsea) * factor * factor2
1624  mb = abyx(jsea) * factor * factor2
1625  !
1626  ! Old definitions: MSCX(JSEA) = ABX2(JSEA) * FACTOR * FACTOR2
1627  ! MSCY(JSEA) = ABY2(JSEA) * FACTOR * FACTOR2
1628  mscd(jsea)=0.5*atan2(2*mb,ma-mc)
1629 
1630  mscx(jsea)= ma*cos(mscd(jsea))**2 &
1631  +2*mb*sin(mscd(jsea))*cos(mscd(jsea))+ma*sin(mscd(jsea))**2
1632  mscy(jsea)= mc*cos(mscd(jsea))**2 &
1633  -2*mb*sin(mscd(jsea))*cos(mscd(jsea))+ma*sin(mscd(jsea))**2
1634  END IF
1635  !
1636  ! Deep water limits
1637  !
1638  kd = max( 0.001 , wn(ik,isea) * dw(isea) )
1639  IF ( kd .LT. 6. ) THEN
1640  fkd = factor / sinh(kd)**2
1641  abr(jsea) = abr(jsea) + ab(jsea) * fkd
1642  aba(jsea) = aba(jsea) + abx(jsea) * fkd
1643  abd(jsea) = abd(jsea) + aby(jsea) * fkd
1644  ubr(jsea) = ubr(jsea) + ab(jsea) * sig(ik)**2 * fkd
1645  uba(jsea) = uba(jsea) + abx(jsea) * sig(ik)**2 * fkd
1646  ubd(jsea) = ubd(jsea) + aby(jsea) * sig(ik)**2 * fkd
1647  ussco=fkd*sig(ik)*wn(ik,isea)*cosh(2.*kd)
1648  bhd(jsea) = bhd(jsea) + &
1649  grav*wn(ik,isea) * ebd(ik,jsea) / (sinh(2.*kd))
1650  ELSE
1651  ussco=factor*sig(ik)*2.*wn(ik,isea)
1652  END IF
1653  !
1654  abxx(jsea) = max( 0. , abxx(jsea) ) * factor
1655  abyy(jsea) = max( 0. , abyy(jsea) ) * factor
1656  abxy(jsea) = abxy(jsea) * factor
1657  sxx(jsea) = sxx(jsea) + abxx(jsea)
1658  syy(jsea) = syy(jsea) + abyy(jsea)
1659  sxy(jsea) = sxy(jsea) + abxy(jsea)
1660  ebd(ik,jsea) = ebd(ik,jsea) / dsii(ik)
1661  !
1662  IF ( floloc( 3, 1).AND.(ik.GE.e3df(2,1).AND.ik.LE.e3df(3,1))) &
1663  ef(jsea,ik) = ebd(ik,jsea) * tpi
1664  !
1665  ussx(jsea) = ussx(jsea) + abx(jsea)*ussco
1666  ussy(jsea) = ussy(jsea) + aby(jsea)*ussco
1667  !
1668  ! Fills the 3D Stokes drift spectrum array
1669  ! ! The US3D Stokes drift specrum array is now calculated in a
1670  ! subroutine and called at the end of this subroutine
1671  ! IF ( FLOLOC( 6, 8).AND.(IK.GE.US3DF(2).AND.IK.LE.US3DF(3) )) THEN
1672  ! US3D(JSEA,IK) = ABX(JSEA)*USSCO/(DSII(IK)*TPIINV)
1673  ! US3D(JSEA,NK+IK) = ABY(JSEA)*USSCO/(DSII(IK)*TPIINV)
1674  ! END IF
1675  IF ( floloc( 3, 2).AND.(ik.GE.e3df(2,2).AND.ik.LE.e3df(3,2))) &
1676  th1m(jsea,ik)= mod( 630. - rade*atan2(aby(jsea),abx(jsea)) , 360. )
1677  m1 = sqrt(abx(jsea)**2+aby(jsea)**2)/max(1e-20,ab(jsea))
1678  IF ( floloc( 3, 3).AND.(ik.GE.e3df(2,3).AND.ik.LE.e3df(3,3))) &
1679  sth1m(jsea,ik)= sqrt(abs(2.*(1-m1)))*rade
1680  IF ( floloc( 3, 4).AND.(ik.GE.e3df(2,4).AND.ik.LE.e3df(3,4))) &
1681  th2m(jsea,ik)= mod( 270. - rade*0.5*atan2(aby2(jsea),ab2x(jsea)) , 180. )
1682  m2 = sqrt(ab2x(jsea)**2+ab2y(jsea)**2)/max(1e-20,ab(jsea))
1683  IF ( floloc( 3, 5).AND.(ik.GE.e3df(2,5).AND.ik.LE.e3df(3,5))) &
1684  sth2m(jsea,ik)= sqrt(abs(0.5*(1-m2)))*rade
1685  END DO
1686  !
1687 #ifdef W3_OMPG
1688  !$OMP END PARALLEL DO
1689 #endif
1690  !
1691  END DO
1692  !
1693  ! Start of Space-Time Extremes Section
1694  IF ( ( stexu .GT. 0. .AND. steyu .GT. 0. ) &
1695  .OR. ( stedu .GT. 0. ) ) THEN
1696  ! Space-Time extremes
1697  ! (for references:
1698  ! - Krogstad et al, OMAE 2004
1699  ! - Baxevani and Rychlik, OE 2006
1700  ! - Adler and Taylor, 2007
1701  ! - Fedele, JPO 2012
1702  ! - Fedele et al, OM 2013
1703  ! - Benetazzo et al, JPO 2015)
1704  !
1705  ! Compute spectral parameters wrt the mean wave direction
1706  ! (no tail contribution - Prognostic)
1707  DO jsea=1, nseal
1708  CALL init_get_isea(isea, jsea)
1709  ix = mapsf(isea,1)
1710  iy = mapsf(isea,2)
1711  IF ( mapsta(iy,ix) .GT. 0 ) THEN
1712  IF ( abs(etx(jsea))+abs(ety(jsea)) .GT. 1.e-7 ) THEN
1713  thmp(jsea) = atan2(ety(jsea),etx(jsea))
1714  END IF
1715  END IF
1716  END DO
1717  !
1718  DO ik=1, nk
1719  !
1720  abx2m = 0.
1721  aby2m = 0.
1722  abxm = 0.
1723  abym = 0.
1724  abxym = 0.
1725  !
1726  DO ith=1, nth
1727  !
1728 #ifdef W3_OMPG
1729  !$OMP PARALLEL DO PRIVATE(JSEA)
1730 #endif
1731  !
1732  DO jsea=1, nseal
1733  abx2m(jsea) = abx2m(jsea) + a(ith,ik,jsea)* &
1734  (ecos(ith)*cos(thmp(jsea))+esin(ith)*sin(thmp(jsea)))**2
1735  aby2m(jsea) = aby2m(jsea) + a(ith,ik,jsea)* &
1736  (esin(ith)*cos(thmp(jsea))-ecos(ith)*sin(thmp(jsea)))**2
1737  abxm(jsea) = abxm(jsea) + a(ith,ik,jsea)* &
1738  (ecos(ith)*cos(thmp(jsea))+esin(ith)*sin(thmp(jsea)))
1739  abym(jsea) = abym(jsea) + a(ith,ik,jsea)* &
1740  (esin(ith)*cos(thmp(jsea))-ecos(ith)*sin(thmp(jsea)))
1741  abxym(jsea) = abxym(jsea) + a(ith,ik,jsea)* &
1742  (ecos(ith)*cos(thmp(jsea))+esin(ith)*sin(thmp(jsea)))* &
1743  (esin(ith)*cos(thmp(jsea))-ecos(ith)*sin(thmp(jsea)))
1744  END DO
1745  !
1746 #ifdef W3_OMPG
1747  !$OMP END PARALLEL DO
1748 #endif
1749  !
1750  END DO
1751  !
1752 #ifdef W3_OMPG
1753  !$OMP PARALLEL DO PRIVATE(JSEA,ISEA,FACTOR)
1754 #endif
1755  !
1756  DO jsea=1, nseal
1757  CALL init_get_isea(isea, jsea)
1758  factor = dden(ik) / cg(ik,isea)
1759  mssxm(jsea) = mssxm(jsea) + abx2m(jsea)*factor* &
1760  wn(ik,isea)**2
1761  mssym(jsea) = mssym(jsea) + aby2m(jsea)*factor* &
1762  wn(ik,isea)**2
1763  mssxtm(jsea) = mssxtm(jsea) + abxm(jsea)*factor*wn(ik,isea)* &
1764  sig(ik)
1765  mssytm(jsea) = mssytm(jsea) + abym(jsea)*factor*wn(ik,isea)* &
1766  sig(ik)
1767  mssxym(jsea) = mssxym(jsea) + abxym(jsea)*factor* &
1768  wn(ik,isea)**2
1769  END DO
1770  !
1771 #ifdef W3_OMPG
1772  !$OMP END PARALLEL DO
1773 #endif
1774  !
1775  END DO
1776 
1777 #ifdef W3_OMPG
1778  !$OMP PARALLEL DO PRIVATE(JSEA,STEX,STEY,STED,ITL,IK)
1779 #endif
1780  !
1781  DO jsea=1, nseal
1782  !
1783  ! Mean wave period (no tail contribution - Prognostic)
1784  IF ( et02(jsea) .GT. 1.e-7 ) THEN
1785  t02p(jsea) = tpi * sqrt(et(jsea) / et02(jsea) )
1786  END IF
1787  !
1788  ! Mean wavelength and mean crest length (02) for space-time extremes
1789  IF ( mssxm(jsea) .GT. 1.e-7 ) THEN
1790  wl02x(jsea) = tpi * sqrt(et(jsea) / mssxm(jsea))
1791  END IF
1792  IF ( mssym(jsea) .GT. 1.e-7 ) THEN
1793  wl02y(jsea) = tpi * sqrt(et(jsea) / mssym(jsea))
1794  END IF
1795  !
1796  ! Irregularity parameters for space-time extremes
1797  IF ((mssxm(jsea) .GT. 1.e-7) .AND. (et02(jsea) .GT. 1.e-7)) THEN
1798  alpxt(jsea) = mssxtm(jsea) / (sqrt(mssxm(jsea) * et02(jsea)))
1799  ENDIF
1800  IF ((mssym(jsea) .GT. 1.e-7) .AND. (et02(jsea) .GT. 1.e-7)) THEN
1801  alpyt(jsea) = mssytm(jsea) / (sqrt(mssym(jsea) * et02(jsea)))
1802  ENDIF
1803  IF ((mssxm(jsea) .GT. 1.e-7) .AND. (mssym(jsea) .GT. 1.e-7)) THEN
1804  alpxy(jsea) = mssxym(jsea) / (sqrt(mssxm(jsea) * mssym(jsea)))
1805  ENDIF
1806  !
1807  ! Short-crestedness parameter
1808  IF (mssxm(jsea) .GT. 1.e-7) THEN
1809  screst(jsea) = sqrt(mssym(jsea)/mssxm(jsea))
1810  END IF
1811  !
1812  ! Space domain size (user-defined or default)
1813  IF ( stexu .GT. 0 .AND. steyu .GT. 0 ) THEN
1814  stex = stexu
1815  stey = steyu
1816  ELSE
1817  stex = 0.
1818  stey = 0.
1819  END IF
1820  !
1821  ! Time domain size (user-defined or default)
1822  IF ( stedu .GT. 0 ) THEN
1823  sted = stedu
1824  ELSE
1825  sted = 0.
1826  END IF
1827  !
1828  ! Average numbers of waves in the space-time domain (Volume+Sides+Borders)
1829  IF ((wl02x(jsea) .GT. 1.e-7) .AND. (wl02y(jsea) .GT. 1.e-7) &
1830  .AND. (t02p(jsea) .GT. 1.e-7)) THEN
1831  nv(jsea) = tpi*(stex*stey*sted)/ &
1832  (wl02x(jsea)*wl02y(jsea)*t02p(jsea)) * &
1833  sqrt(1-alpxt(jsea)**2-alpyt(jsea)**2 - &
1834  alpxy(jsea)**2+2*alpxt(jsea)*alpyt(jsea)*alpxy(jsea))
1835  ns(jsea) = sqrt(tpi)*((stex*sted)/(wl02x(jsea)*t02p(jsea)) * &
1836  sqrt(1-alpxt(jsea)**2) + &
1837  (stey*sted)/(wl02y(jsea)*t02p(jsea)) * &
1838  sqrt(1-alpyt(jsea)**2) + &
1839  (stex*stey)/(wl02x(jsea)*wl02y(jsea)) * &
1840  sqrt(1-alpxy(jsea)**2))
1841  nb(jsea) = stex/wl02x(jsea) + stey/wl02y(jsea) + &
1842  sted/t02p(jsea)
1843  END IF
1844  !
1845  ! Integral measure of wave steepness (Fedele & Tayfun, 2009) MU, as a
1846  ! function of the spectral width parameter NI (Longuet-Higgins, 1985)
1847  IF (et1(jsea) .GT. 1.e-7) THEN
1848  ni(jsea) = sqrt(et(jsea)*et02(jsea)/et1(jsea)**2 - 1)
1849  ENDIF
1850  IF (et(jsea) .GT. 1.e-7) THEN
1851  mu(jsea) = et1(jsea)**2/grav * (et(jsea))**(-1.5) * &
1852  (1-ni(jsea)+ni(jsea)**2)
1853  ENDIF
1854  !
1855  ! Mode of the Adler&Taylor distribution
1856  ! (normalized on the standard deviation = Hs/4)
1857  ! Time extremes
1858  IF ((stex .EQ. 0) .AND. (stey .EQ. 0)) THEN
1859  mode(jsea) = sqrt(2.*log(nb(jsea)))
1860  ! Space extremes (strictly for STEX*STEY >> WL02X*WL02Y)
1861  ELSEIF (sted .EQ. 0) THEN
1862  mode(jsea) = sqrt(2.*log(ns(jsea))+log(2.*log(ns(jsea))+ &
1863  log(2.*log(ns(jsea)))))
1864  ! Space-time extremes (strictly for STEX*STEY >> WL02X*WL02Y)
1865  ELSEIF ((wl02x(jsea) .GT. 1.e-7) .AND. (wl02y(jsea) .GT. 1.e-7) &
1866  .AND. (t02p(jsea) .GT. 1.e-7)) THEN
1867  mode(jsea) = sqrt(2.*log(nv(jsea))+2.*log(2.*log(nv(jsea))+ &
1868  2.*log(2.*log(nv(jsea)))))
1869  ENDIF
1870  !
1871  ! Expected maximum sea surface elevation in the ST domain - nonlinear
1872  ! (in meters, Hs/4=SQRT(ET(JSEA)))
1873  stmaxe(jsea) = sqrt(et(jsea)) * &
1874  ( mode(jsea)+0.5*mu(jsea)*mode(jsea)**2 + &
1875  0.5772*(1+mu(jsea)*mode(jsea)) / &
1876  (mode(jsea)-(2*nv(jsea)*mode(jsea)+ns(jsea)) / &
1877  (nv(jsea)*mode(jsea)**2+ns(jsea)*mode(jsea)+nb(jsea))) )
1878  !
1879  ! Standard deviation of the maximum sea surface elevation in ST domain
1880  ! - nonlinear (in meters, Hs/4=SQRT(ET(JSEA)))
1881  stmaxd(jsea) = sqrt(et(jsea)) * &
1882  ( pi*(1+mu(jsea)*mode(jsea))/sqrt(6.) / &
1883  (mode(jsea)-(2*nv(jsea)*mode(jsea)+ns(jsea)) / &
1884  (nv(jsea)*mode(jsea)**2+ns(jsea)*mode(jsea)+nb(jsea))) )
1885  !
1886  ! Autocovariance (time) function (normalized on the maximum, i.e. total
1887  ! variance)
1888  IF (t02p(jsea) .GT. 1.e-7) THEN
1889  tlphi(jsea) = 0.3*t02p(jsea)
1890  DO itl = 1, 21
1891  DO ik = 1, nk-3, 4
1892  phi(itl,jsea) = phi(itl,jsea) + &
1893  (xfr**3*ebd(ik+3,jsea)*cos(xfr**3*sig(ik)*tlphi(jsea))+ &
1894  xfr**2*ebd(ik+2,jsea)*cos(xfr**2*sig(ik)*tlphi(jsea))+ &
1895  xfr*ebd(ik+1,jsea)*cos(xfr*sig(ik)*tlphi(jsea)) + &
1896  ebd(ik,jsea)*cos(sig(ik)*tlphi(jsea)))*dsii(ik)
1897  ENDDO
1898  tlphi(jsea) = tlphi(jsea) + t02p(jsea)/20.
1899  ENDDO
1900  phi(:,jsea) = phi(:,jsea)/et(jsea)
1901  !
1902  ! First minimum of the autocovariance function (absolute value)
1903  phist(jsea) = abs(minval(phi(:,jsea),1))
1904  ENDIF
1905  !
1906  ! Wave height of the wave with the maximum expected crest height
1907  ! and corresponding standard deviation
1908  ! (according to Boccotti Quasi-Determinism theory - linear)
1909  stmaxel(jsea) = sqrt(et(jsea)) * ( mode(jsea)+0.5772 / &
1910  (mode(jsea)-(2*nv(jsea)*mode(jsea)+ns(jsea)) / &
1911  (nv(jsea)*mode(jsea)**2+ns(jsea)*mode(jsea)+nb(jsea))) )
1912  stmaxdl(jsea) = sqrt(et(jsea)) * &
1913  ( pi/sqrt(6.) / &
1914  (mode(jsea)-(2*nv(jsea)*mode(jsea)+ns(jsea)) / &
1915  (nv(jsea)*mode(jsea)**2+ns(jsea)*mode(jsea)+nb(jsea))) )
1916  hcmaxe(jsea) = stmaxel(jsea)*(1+phist(jsea))
1917  hcmaxd(jsea) = stmaxdl(jsea)*(1+phist(jsea))
1918  ! Maximum expected wave height and corresponding standard deviation
1919  ! (according to Boccotti Quasi-Determinism theory - linear)
1920  hmaxe(jsea) = stmaxel(jsea)*sqrt(2*(1+phist(jsea)))
1921  hmaxd(jsea) = stmaxdl(jsea)*sqrt(2*(1+phist(jsea)))
1922  ENDDO
1923  !
1924 #ifdef W3_OMPG
1925  !$OMP END PARALLEL DO
1926 #endif
1927  !
1928 
1929  ! End of Space-Time Extremes Section
1930  ENDIF
1931  !
1932  ! 3. Finalize computation of mean parameters ------------------------ *
1933  !
1934 #ifdef W3_OMPG
1935  !$OMP PARALLEL DO PRIVATE(JSEA,ISEA,EBAND)
1936 #endif
1937  !
1938  DO jsea=1, nseal
1939  CALL init_get_isea(isea, jsea)
1940  !
1941  ! 3.a Directional mss parameters
1942  ! NB: the slope PDF is proportional to ell1=ETYY*EC2-2*ETXY*ECS+ETXX*ES2 = C*EC2-2*B*ECS+A*ES2
1943  ! This is an ellipse equation with axis direction given by dir=0.5*ATAN2(2.*ETXY,ETXX-ETYY)
1944  ! From matlab script: t0=0.5*(atan2(2.*B,A-C));
1945  ! From matlab script: A2=A.*cos(t0).^2+2.*B.*sin(t0).*cos(t0)+A.*cos(t0).^2+C.*sin(t0)^2;
1946  ! From matlab script: C2=C.*cos(t0)^2-2.*B.*sin(t0).*cos(t0)+A.*sin(t0).^2;
1947  mssd(jsea)=0.5*(atan2(2*etxy(jsea),etxx(jsea)-etyy(jsea)))
1948  mssx(jsea) = etxx(jsea)*cos(mssd(jsea))**2 &
1949  +2*etxy(jsea)*sin(mssd(jsea))*cos(mssd(jsea))+etyy(jsea)*sin(mssd(jsea))**2
1950  mssy(jsea) = etyy(jsea)*cos(mssd(jsea))**2 &
1951  -2*etxy(jsea)*sin(mssd(jsea))*cos(mssd(jsea))+etxx(jsea)*sin(mssd(jsea))**2
1952  !
1953  ! 3.b Add tail
1954  ! ( DTH * SIG absorbed in FTxx )
1955 
1956  eband = ab(jsea) / cg(nk,isea) ! EBAND is E(sigma)/sigma for the last frequency band
1957  et(jsea) = et(jsea) + fte * eband
1958  ewn(jsea) = ewn(jsea) + ftwl * eband
1959  etf(jsea) = etf(jsea) + grav * fttr * eband ! this is the integral of CgE in deep water
1960  etr(jsea) = etr(jsea) + fttr * eband
1961  et1(jsea) = et1(jsea) + ft1 * eband
1962  ! EET1(JSEA)= EET1(JSEA) + FT1 * EBAND**2 : this was not correct. Actually tail may not be needed for Qp.
1963  et02(jsea)= et02(jsea)+ eband* 0.5 * sig(nk)**4 * dth
1964  etx(jsea) = etx(jsea) + fte * abx(jsea) / cg(nk,isea)
1965  ety(jsea) = ety(jsea) + fte * aby(jsea) / cg(nk,isea)
1966  sxx(jsea) = sxx(jsea) + fte * abxx(jsea) / cg(nk,isea)
1967  syy(jsea) = syy(jsea) + fte * abyy(jsea) / cg(nk,isea)
1968  sxy(jsea) = sxy(jsea) + fte * abxy(jsea) / cg(nk,isea)
1969  !
1970  ! Tail for surface stokes drift is commented out: very sensitive to tail power
1971  !
1972  ! USSX(JSEA) = USSX(JSEA) + 2*GRAV*ETUSCX(JSEA)/SIG(NK)
1973  ! USSY(JSEA) = USSY(JSEA) + 2*GRAV*ETUSCY(JSEA)/SIG(NK)
1974  ubs(jsea) = ubs(jsea) + ftwl * eband/grav
1975  END DO
1976  !
1977 #ifdef W3_OMPG
1978  !$OMP END PARALLEL DO
1979 #endif
1980  !
1981  sxx = sxx * dwat * grav
1982  syy = syy * dwat * grav
1983  sxy = sxy * dwat * grav
1984  !
1985 #ifdef W3_OMPG
1986  !$OMP PARALLEL DO PRIVATE(JSEA,ISEA,IX,IY)
1987 #endif
1988  !
1989  DO jsea=1, nseal
1990  CALL init_get_isea(isea, jsea)
1991  ix = mapsf(isea,1)
1992  iy = mapsf(isea,2)
1993  IF ( mapsta(iy,ix) .GT. 0 ) THEN
1994 #ifdef W3_O9
1995  IF ( et(jsea) .GE. 0. ) THEN
1996 #endif
1997  hs(jsea) = 4. * sqrt( et(jsea) )
1998 #ifdef W3_O9
1999  ELSE
2000  hs(jsea) = - 4. * sqrt( -et(jsea) )
2001  END IF
2002 #endif
2003  IF ( et(jsea) .GT. 1.e-7 ) THEN
2004  qp(jsea) = ( 2. / et(jsea)**2 ) * eet1(jsea)
2005  wlm(jsea) = ewn(jsea) / et(jsea) * tpi
2006  t0m1(jsea) = etr(jsea) / et(jsea) * tpi
2007  ths(jsea) = rade * sqrt( max( 0. , 2. * ( 1. - sqrt( &
2008  max(0.,(etx(jsea)**2+ety(jsea)**2)/et(jsea)**2) ) ) ) )
2009  IF ( ths(jsea) .LT. 0.01*rade*dth ) ths(jsea) = 0.
2010  ! NB: QK1 (JSEA) = QK1(JSEA) + A(ITH,IK,JSEA)**2
2011  ! QK2 (JSEA) = QK2 (JSEA) + QK1(JSEA) * FACTOR* SIG(IK) /WN(IK,ISEA)
2012  qkk(jsea) = sqrt(0.5*qk2(jsea))/et(jsea)
2013  ELSE
2014  wlm(jsea) = 0.
2015  t0m1(jsea) = tpi / sig(nk)
2016  ths(jsea) = 0.
2017  END IF
2018  IF ( abs(etx(jsea))+abs(ety(jsea)) .GT. 1.e-7 ) THEN
2019  thm(jsea) = atan2(ety(jsea),etx(jsea))
2020  ELSE
2021  thm(jsea) = 0.
2022  END IF
2023  abr(jsea) = sqrt( 2. * max( 0. , abr(jsea) ) )
2024  IF ( abr(jsea) .GE. 1.e-7 ) THEN
2025  abd(jsea) = atan2(abd(jsea),aba(jsea))
2026  ELSE
2027  abd(jsea) = 0.
2028  ENDIF
2029  aba(jsea) = abr(jsea)
2030  ubr(jsea) = sqrt( 2. * max( 0. , ubr(jsea) ) )
2031  IF ( ubr(jsea) .GE. 1.e-7 ) THEN
2032  ubd(jsea) = atan2(ubd(jsea),uba(jsea))
2033  ELSE
2034  ubd(jsea) = 0.
2035  ENDIF
2036  uba(jsea) = ubr(jsea)
2037  cge(jsea) = dwat*grav*etf(jsea)
2038  IF ( et02(jsea) .GT. 1.e-7 .AND. et(jsea) .GT. 0 ) THEN
2039  t02(jsea) = tpi * sqrt(et(jsea) / et02(jsea) )
2040  t01(jsea) = tpi * et(jsea) / et1(jsea)
2041  ELSE
2042  t02(jsea) = tpi / sig(nk)
2043  t01(jsea)= t02(jsea)
2044  ENDIF
2045  !
2046  ! Add here USERO(JSEA,1) ...
2047  !
2048  END IF
2049  END DO
2050  !
2051 #ifdef W3_OMPG
2052  !$OMP END PARALLEL DO
2053 #endif
2054  !
2055  ! 3.b Clean-up small values if !/O8 switch selected
2056  !
2057 #ifdef W3_O8
2058  DO jsea=1, nseal
2059  IF ( hs(jsea).LE.hsmin .AND. hs(jsea).NE.undef) THEN
2060  wlm(jsea) = undef
2061  t02(jsea) = undef
2062  t0m1(jsea) = undef
2063  thm(jsea) = undef
2064  ths(jsea) = undef
2065  END IF
2066  END DO
2067 #endif
2068  !
2069  ! 4. Peak frequencies and directions -------------------------------- *
2070  ! 4.a Initialize
2071  !
2072 #ifdef W3_OMPG
2073  !$OMP PARALLEL DO PRIVATE(JSEA)
2074 #endif
2075  !
2076  DO jsea=1, nseal
2077  ec(jsea) = ebd(nk,jsea)
2078  fp0(jsea) = undef
2079  ikp0(jsea) = nk
2080  thp0(jsea) = undef
2081  END DO
2082  !
2083 #ifdef W3_OMPG
2084  !$OMP END PARALLEL DO
2085 #endif
2086  !
2087  ! 4.b Discrete peak frequencies
2088  !
2089  DO ik=nk-1, 1, -1
2090  !
2091 #ifdef W3_OMPG
2092  !$OMP PARALLEL DO PRIVATE(JSEA)
2093 #endif
2094  !
2095  DO jsea=1, nseal
2096  IF ( ec(jsea) .LT. ebd(ik,jsea) ) THEN
2097  ec(jsea) = ebd(ik,jsea)
2098  ikp0(jsea) = ik
2099  END IF
2100  END DO
2101  !
2102 #ifdef W3_OMPG
2103  !$OMP END PARALLEL DO
2104 #endif
2105  !
2106  END DO
2107  !
2108 #ifdef W3_OMPG
2109  !$OMP PARALLEL DO PRIVATE(JSEA)
2110 #endif
2111  !
2112  DO jsea=1, nseal
2113  IF ( ikp0(jsea) .NE. nk ) fp0(jsea) = sig(ikp0(jsea)) * tpiinv
2114  END DO
2115  !
2116 #ifdef W3_OMPG
2117  !$OMP END PARALLEL DO
2118 #endif
2119  !
2120  ! 4.c Continuous peak frequencies
2121  !
2122  xl = 1./xfr - 1.
2123  xh = xfr - 1.
2124  xl2 = xl**2
2125  xh2 = xh**2
2126  !
2127 #ifdef W3_OMPG
2128  !$OMP PARALLEL DO PRIVATE(JSEA,EL,EH,DENOM)
2129 #endif
2130  !
2131  DO jsea=1, nseal
2132  IF ( ikp0(jsea) .NE. nk ) THEN
2133  IF ( ikp0(jsea) .EQ. 1 ) THEN
2134  el = - ebd(ikp0(jsea), jsea)
2135  ELSE
2136  el = ebd(ikp0(jsea)-1, jsea) - ebd(ikp0(jsea), jsea)
2137  END IF
2138 
2139  eh = ebd(ikp0(jsea)+1, jsea) - ebd(ikp0(jsea), jsea)
2140 
2141  denom = xl*eh - xh*el
2142  fp0(jsea) = fp0(jsea) * ( 1. + 0.5 * ( xl2*eh - xh2*el ) &
2143  / sign( max(abs(denom),1.e-15) , denom ) )
2144  END IF
2145  END DO
2146  !
2147 #ifdef W3_OMPG
2148  !$OMP END PARALLEL DO
2149 #endif
2150  !
2151  ! 4.d Peak directions
2152  !
2153 #ifdef W3_OMPG
2154  !$OMP PARALLEL DO PRIVATE(JSEA)
2155 #endif
2156  !
2157  DO jsea=1, nseal
2158  etx(jsea) = 0.
2159  ety(jsea) = 0.
2160  END DO
2161  !
2162 #ifdef W3_OMPG
2163  !$OMP END PARALLEL DO
2164 #endif
2165  !
2166  DO ith=1, nth
2167  !
2168 #ifdef W3_OMPG
2169  !$OMP PARALLEL DO PRIVATE(JSEA)
2170 #endif
2171  !
2172  DO jsea=1, nseal
2173  IF ( ikp0(jsea) .NE. nk ) THEN
2174  etx(jsea) = etx(jsea) + a(ith,ikp0(jsea),jsea)*ecos(ith)
2175  ety(jsea) = ety(jsea) + a(ith,ikp0(jsea),jsea)*esin(ith)
2176  END IF
2177  END DO
2178  !
2179 #ifdef W3_OMPG
2180  !$OMP END PARALLEL DO
2181 #endif
2182  !
2183  END DO
2184  !
2185 #ifdef W3_OMPG
2186  !$OMP PARALLEL DO PRIVATE(JSEA)
2187 #endif
2188  !
2189  DO jsea=1, nseal
2190  IF ( abs(etx(jsea))+abs(ety(jsea)) .GT. 1.e-7 .AND. &
2191  fp0(jsea).NE.undef ) &
2192  thp0(jsea) = atan2(ety(jsea),etx(jsea))
2193  etx(jsea) = 0.
2194  ety(jsea) = 0.
2195  END DO
2196  !
2197 #ifdef W3_OMPG
2198  !$OMP END PARALLEL DO
2199  !$OMP PARALLEL DO PRIVATE(JSEA,ISEA,IX,IY)
2200 #endif
2201  !
2202  DO jsea =1, nseal
2203  CALL init_get_isea(isea, jsea)
2204  ix = mapsf(isea,1)
2205  iy = mapsf(isea,2)
2206  IF ( mapsta(iy,ix) .LE. 0 ) THEN
2207  fp0(jsea) = undef
2208  thp0(jsea) = undef
2209  END IF
2210  END DO
2211  !
2212 #ifdef W3_OMPG
2213  !$OMP END PARALLEL DO
2214 #endif
2215  !
2216  ! 5. Test output (local to MPP only)
2217  !
2218 #ifdef W3_T
2219  WRITE (ndst,9050)
2220  DO jsea =1, nseal
2221  CALL init_get_isea(isea, jsea)
2222  ix = mapsf(isea,1)
2223  iy = mapsf(isea,2)
2224  IF ( hs(jsea) .EQ. undef ) THEN
2225  WRITE (ndst,9051) isea, ix, iy
2226  ELSE IF ( wlm(jsea) .EQ. undef ) THEN
2227  WRITE (ndst,9052) isea, ix, iy, hs(jsea)
2228  ELSE IF ( fp0(jsea) .EQ. undef ) THEN
2229  WRITE (ndst,9053) isea, ix, iy, hs(jsea), wlm(jsea), &
2230  t0m1(jsea), rade*thm(jsea), ths(jsea)
2231  ELSE
2232  WRITE (ndst,9054) isea, ix, iy, hs(jsea), wlm(jsea), &
2233  t0m1(jsea), rade*thm(jsea), ths(jsea), fp0(jsea),&
2234  thp0(jsea)
2235  END IF
2236  END DO
2237 #endif
2238  !
2239  ! 6. Fill arrays wth partitioned data
2240  !
2241  IF ( flpart ) THEN
2242  !
2243  ! 6.a Initializations
2244  !
2245  phs = undef
2246  ptp = undef
2247  plp = undef
2248  pdir = undef
2249  psi = undef
2250  pws = undef
2251  pwst = undef
2252  pnr = undef
2253  pthp0 = undef
2254  pqp = undef
2255  ppe = undef
2256  pgw = undef
2257  psw = undef
2258  ptm1 = undef
2259  pt1 = undef
2260  pt2 = undef
2261  pep = undef
2262  !
2263  ! 6.b Loop over local sea points
2264  !
2265 #ifdef W3_OMPG
2266  !$OMP PARALLEL DO PRIVATE(ISEA,JSEA,IX,IY,I,J)
2267 #endif
2268  !
2269  DO jsea=1, nseal
2270  CALL init_get_isea(isea, jsea)
2271  ix = mapsf(isea,1)
2272  iy = mapsf(isea,2)
2273  !
2274  IF ( mapsta(iy,ix).GT.0 ) THEN
2275  i = icprt(jsea,2)
2276  pnr(jsea) = max( 0. , real(icprt(jsea,1)-1) )
2277  IF ( icprt(jsea,1).GE.1 ) pwst(jsea) = dtprt(6,i)
2278  END IF
2279  !
2280  IF ( mapsta(iy,ix).GT.0 .AND. icprt(jsea,1).GT.1 ) THEN
2281  i = icprt(jsea,2) + 1
2282  IF ( dtprt(6,i) .GE. wscut ) THEN
2283  phs(jsea,0) = dtprt(1,i)
2284  ptp(jsea,0) = dtprt(2,i)
2285  plp(jsea,0) = dtprt(3,i)
2286  ! (PDIR is already in degrees nautical - convert back to
2287  ! Cartesian in radians to maintain internal convention)
2288  IF(dtprt(4,i) .NE. undef) THEN
2289  pdir(jsea,0) = (270. - dtprt(4,i)) * dera
2290  ENDIF
2291  psi(jsea,0) = dtprt(5,i)
2292  pws(jsea,0) = dtprt(6,i)
2293  ! (PTHP0 is already in degrees nautical - convert back to
2294  ! Cartesian in radians to maintain internal convention)
2295  IF(dtprt(7,i) .NE. undef) THEN
2296  pthp0(jsea,0) = (270. - dtprt(7,i)) * dera
2297  ENDIF
2298  psw(jsea,0) = dtprt(8,i)
2299  ppe(jsea,0) = dtprt(9,i)
2300  pqp(jsea,0) = dtprt(10,i)
2301  pgw(jsea,0) = dtprt(11,i)
2302  ptm1(jsea,0) = dtprt(12,i)
2303  pt1(jsea,0) = dtprt(13,i)
2304  pt2(jsea,0) = dtprt(14,i)
2305  pep(jsea,0) = dtprt(15,i)
2306  i = i + 1
2307  END IF
2308  DO j=1, noswll
2309  IF ( i .GT. icprt(jsea,2)+icprt(jsea,1)-1 ) EXIT
2310  phs(jsea,j) = dtprt(1,i)
2311  ptp(jsea,j) = dtprt(2,i)
2312  plp(jsea,j) = dtprt(3,i)
2313  ! (PDIR is already in degrees nautical - convert back to
2314  ! Cartesian in radians to maintain internal convention)
2315  IF(dtprt(4,i) .NE. undef) THEN
2316  pdir(jsea,j) = (270. - dtprt(4,i)) * dera
2317  ENDIF
2318  psi(jsea,j) = dtprt(5,i)
2319  pws(jsea,j) = dtprt(6,i)
2320  ! (PTHP0 is already in degrees nautical - convert back to
2321  ! Cartesian in radians to maintain internal convention)
2322  IF(dtprt(7,i) .NE. undef) THEN
2323  pthp0(jsea,j) = (270. - dtprt(7,i)) * dera
2324  ENDIF
2325  psw(jsea,j) = dtprt(8,i)
2326  ppe(jsea,j) = dtprt(9,i)
2327  pqp(jsea,j) = dtprt(10,i)
2328  pgw(jsea,j) = dtprt(11,i)
2329  ptm1(jsea,j) = dtprt(12,i)
2330  pt1(jsea,j) = dtprt(13,i)
2331  pt2(jsea,j) = dtprt(14,i)
2332  pep(jsea,j) = dtprt(15,i)
2333  i = i + 1
2334  END DO
2335  END IF
2336  !
2337  END DO
2338  !
2339 #ifdef W3_OMPG
2340  !$OMP END PARALLEL DO
2341 #endif
2342  !
2343 
2344  END IF
2345 
2346  IF (floloc( 6, 8)) THEN
2347  CALL calc_u3stokes(a,1)
2348  END IF
2349  !
2350  IF (floloc( 6, 12)) THEN
2351  CALL calc_u3stokes(a,2)
2352  ENDIF
2353  !
2354  IF (floloc( 8, 7).OR.floloc( 8, 8).OR.floloc( 8, 9)) THEN
2355  CALL skewness(a)
2356  END IF
2357 
2358  !
2359  ! Dominant wave breaking probability
2360  !
2361  IF (floloc(2, 17)) CALL calc_wbt(a)
2362  !
2363  RETURN
2364  !
2365  ! Formats
2366  !
2367 #ifdef W3_T
2368 9050 FORMAT (' TEST W3OUTG : ISEA, IX, IY, HS, L, Tm, THm, THs', &
2369  ', FP0, THP0')
2370 9051 FORMAT (2x,i8,2i8)
2371 9052 FORMAT (2x,i8,2i8,f6.2)
2372 9053 FORMAT (2x,i8,2i8,f6.2,f7.1,f6.2,2f6.1)
2373 9054 FORMAT (2x,i8,2i8,f6.2,f7.1,f6.2,2f6.1,f6.3,f6.0)
2374 #endif
2375 
2376  !/
2377  !/ End of W3OUTG ----------------------------------------------------- /
2378  !/
2379  END SUBROUTINE w3outg
2380  !/ ------------------------------------------------------------------- /
2381  !/
2394  SUBROUTINE w3iogo ( INXOUT, NDSOG, IOTST, IMOD &
2395 #ifdef W3_ASCII
2396  ,NDSOA &
2397 #endif
2398  )
2399  !/
2400  !/ +-----------------------------------+
2401  !/ | WAVEWATCH III NOAA/NCEP |
2402  !/ | H. L. Tolman |
2403  !/ | FORTRAN 90 |
2404  !/ | Last update : 22-Mar-2021 |
2405  !/ +-----------------------------------+
2406  !/
2407  !/ 17-Mar-1999 : Distributed FORTRAN 77 version. ( version 1.18 )
2408  !/ 04-Jan-2000 : Upgrade to FORTRAN 90 ( version 2.00 )
2409  !/ Major changes to logistics.
2410  !/ 24-Jan-2001 : Flat grid version (formats only) ( version 2.06 )
2411  !/ 23-Apr-2002 : Clean up ( version 2.19 )
2412  !/ 29-Apr-2002 : Add output types 17-18. ( version 2.20 )
2413  !/ 13-Nov-2002 : Add stress vector. ( version 3.00 )
2414  !/ 25-Oct-2004 : Multiple grid version. ( version 3.06 )
2415  !/ 27-Jun-2005 : Adding MAPST2. ( version 3.07 )
2416  !/ 21-Jul-2005 : Adding output fields 19-21. ( version 3.07 )
2417  !/ 27-Jun-2006 : Adding file name preamble. ( version 3.09 )
2418  !/ 05-Jul-2006 : Consolidate stress arrays. ( version 3.09 )
2419  !/ 02-Apr-2007 : Adding partitioned output. ( version 3.11 )
2420  !/ Adding user slots for outputs.
2421  !/ 30-Oct-2009 : Implement curvilinear grid type. ( version 3.14 )
2422  !/ (W. E. Rogers & T. J. Campbell, NRL)
2423  !/ 31-Oct-2010 : Implement unstructured grids ( version 3.14 )
2424  !/ (A. Roland and F. Ardhuin)
2425  !/ 05-Feb-2011 : Renumbering of output fields ( version 3.14 )
2426  !/ (F. Ardhuin)
2427  !/ 25-Dec-2012 : New output structure and smaller ( version 4.11 )
2428  !/ memory footprint.
2429  !/ 21-Aug-2013 : Added missing cos,sin for UBA, ABA ( version 4.11 )
2430  !/ 27-Nov-2013 : Management of coupling output ( version 4.18 )
2431  !/ 01-Mar-2018 : Removed RTD code (now used in post ( version 6.02 )
2432  !/ processing code)
2433  !/ 25-Aug-2018 : Add WBT parameter ( version 6.06 )
2434  !/ 22-Mar-2021 : Add extra coupling fields as output ( version 7.13 )
2435  !/ 07-Mar-2024 : Add Skewness parameters ( version 7.13 )
2436  !/
2437  ! 1. Purpose :
2438  !
2439  ! Read/write gridded output.
2440  !
2441  ! 2. Method :
2442  !
2443  ! Fields in file are determined by flags in FLOGRD in W3ODATMD.
2444  !
2445  ! 3. Parameters :
2446  !
2447  ! Parameter list
2448  ! ----------------------------------------------------------------
2449  ! INXOUT C*(*) I Test string for read/write, valid are:
2450  ! 'READ' and 'WRITE'.
2451  ! NDSOG Int. I File unit number.
2452  ! IOTST Int. O Test indictor for reading.
2453  ! 0 : Fields read.
2454  ! -1 : Past end of file.
2455  ! IMOD Int. I Model number for W3GDAT etc.
2456  ! ----------------------------------------------------------------
2457  !
2458  ! 4. Subroutines used :
2459  !
2460  ! See module documentation above.
2461  !
2462  ! 5. Called by :
2463  !
2464  ! Name Type Module Description
2465  ! ----------------------------------------------------------------
2466  ! W3WAVE Subr. W3WAVEMD Actual wave model routine.
2467  ! WW3_OUTF Prog. N/A Ouput postprocessor.
2468  ! WW3_GRIB Prog. N/A Ouput postprocessor.
2469  ! GX_OUTF Prog. N/A Ouput postprocessor.
2470  ! ----------------------------------------------------------------
2471  !
2472  ! 6. Error messages :
2473  !
2474  ! Tests on INXOUT, file status and on array dimensions.
2475  !
2476  ! 7. Remarks :
2477  !
2478  ! - MAPSTA is dumped as it contains information on the ice edge.
2479  ! Dynamic ice edges require MAPSTA to be dumped every time step.
2480  ! - The output file has the pre-defined name 'out_grd.FILEXT'.
2481  ! - The current components CX and CY are written to out_grd as
2482  ! components, but converted to magnitude and direction in most
2483  ! gridded and point output post-processors (except gx_outf).
2484  ! - All written direction are in degrees, nautical convention,
2485  ! but in reading, all is convered back to radians and cartesian
2486  ! conventions.
2487  ! - Before writing, wind and current directions are converted,
2488  ! wave directions are already in correct convention (see W3OUTG).
2489  ! - In MPP version of model data is supposed to be gatherd at the
2490  ! correct processor before the routine is called.
2491  ! - In MPP version routine is called by only one process, therefore
2492  ! no test on process for error messages is needed.
2493  !
2494  ! 8. Structure :
2495  !
2496  ! See source code.
2497  !
2498  ! 9. Switches :
2499  !
2500  ! !/ST1 First source term package (WAM3).
2501  ! !/ST2 Second source term package (TC96).
2502  ! !/S Enable subroutine tracing.
2503  ! !/T Test output.
2504  !
2505  ! 10. Source code :
2506  !
2507  !/ ------------------------------------------------------------------- /
2508  USE constants
2509  USE w3gdatmd
2510  !/
2511  USE w3wdatmd, ONLY: w3setw, w3dimw
2512  USE w3adatmd, ONLY: w3seta, w3dima, w3xeta
2513  USE w3odatmd, ONLY: w3seto
2514  !/
2515  USE w3wdatmd, ONLY: time, dinit, wlv, ice, icef, iceh, berg, &
2516  ust, ustdir, asf, rhoair
2517  USE w3adatmd, ONLY: ainit, dw, ua, ud, as, cx, cy, wn, &
2518  taua, tauadir
2519  USE w3adatmd, ONLY: hs, wlm, t02, t0m1, t01, fp0, thm, ths, thp0,&
2520  wbt, wnmean
2521  USE w3adatmd, ONLY: dtdyn, fcut, aba, abd, uba, ubd, sxx, syy, sxy,&
2522  phs, ptp, plp, pdir, psi, pws, pwst, pnr, &
2523  pthp0, pqp, ppe, pgw, psw, ptm1, pt1, pt2, &
2524  pep, usero, tauox, tauoy, tauwix, tauwiy, &
2525  phiaw, phioc, tusx, tusy, prms, tpms, &
2526  ussx, ussy, mssx, mssy, mssd, mscx, mscy, &
2527  mscd, qp, tauwnx, tauwny, charn, tws, bhd, &
2530  th1m, sth1m, th2m, sth2m, hsig, phice, tauice,&
2533  !/
2534  USE w3odatmd, ONLY: nogrp, ngrpp, idout, undef, ndst, ndse, &
2535  flogrd, ipass => ipass1, write => write1, &
2536  fnmpre, noswll, noextr
2537  !/
2538  USE w3servmd, ONLY: extcde
2539  USE w3odatmd, only : iaproc
2540  USE w3odatmd, ONLY : ofiles
2541 #ifdef W3_SETUP
2542  USE w3wdatmd, ONLY: zeta_setup
2543 #endif
2544 #ifdef W3_S
2545  USE w3servmd, ONLY: strace
2546 #endif
2547  !
2548  IMPLICIT NONE
2549  !/
2550  !/ ------------------------------------------------------------------- /
2551  !/ Parameter list
2552  !/
2553  INTEGER, INTENT(INOUT) :: IOTST
2554  INTEGER, INTENT(IN) :: NDSOG
2555  INTEGER, INTENT(IN), OPTIONAL :: IMOD
2556  CHARACTER, INTENT(IN) :: INXOUT*(*)
2557  CHARACTER(LEN=15) :: TIMETAG
2558 #ifdef W3_ASCII
2559  INTEGER, INTENT(IN), OPTIONAL :: NDSOA
2560 #endif
2561  !/
2562  !/ ------------------------------------------------------------------- /
2563  !/ Local parameters
2564  !/
2565  INTEGER :: IGRD, IERR, I, J, IX, IY, MOGRP, &
2566  MGRPP, ISEA, MOSWLL, IK, IFI, IFJ &
2567  ,IFILOUT
2568  INTEGER, ALLOCATABLE :: MAPTMP(:,:)
2569 #ifdef W3_S
2570  INTEGER, SAVE :: IENT = 0
2571 #endif
2572  REAL :: AUX1(NSEA), AUX2(NSEA), &
2573  AUX3(NSEA), AUX4(NSEA)
2574 #ifdef W3_SMC
2575  REAL :: UDARC
2576 #endif
2577  CHARACTER(LEN=30) :: IDTST, TNAME
2578  CHARACTER(LEN=10) :: VERTST
2579  !/
2580  !/ ------------------------------------------------------------------- /
2581  !/
2582 #ifdef W3_S
2583  CALL strace (ient, 'W3IOGO')
2584 #endif
2585  !
2586  ! test input parameters ---------------------------------------------- *
2587  !
2588  IF ( PRESENT(imod) ) THEN
2589  igrd = imod
2590  ELSE
2591  igrd = 1
2592  END IF
2593  !
2594  CALL w3seto ( igrd, ndse, ndst )
2595  CALL w3setg ( igrd, ndse, ndst )
2596  CALL w3seta ( igrd, ndse, ndst )
2597 #ifdef W3_MPI
2598  CALL w3xeta ( igrd, ndse, ndst )
2599 #endif
2600  CALL w3setw ( igrd, ndse, ndst )
2601  !
2602  ipass = ipass + 1
2603  iotst = 0
2604  !
2605  IF (inxout.NE.'READ' .AND. inxout.NE.'WRITE' ) THEN
2606  WRITE (ndse,900) inxout
2607  CALL extcde ( 1 )
2608  END IF
2609  !
2610  IF ( ipass.EQ.1 .AND. ofiles(1) .EQ. 0) THEN
2611  WRITE = inxout.EQ.'WRITE'
2612  ELSE
2613  IF ( WRITE .AND. inxout.EQ.'READ' ) THEN
2614  WRITE (ndse,901) inxout
2615  CALL extcde ( 2 )
2616  END IF
2617  END IF
2618  !
2619 #ifdef W3_T
2620  WRITE (ndst,9000) ipass, inxout, WRITE, ndsog, igrd, filext
2621 #endif
2622  !
2623  !
2624  ! open file ---------------------------------------------------------- *
2625  ! ( IPASS = 1 )
2626  !
2627  IF ( ipass.EQ.1 .AND. ofiles(1) .EQ. 0) THEN
2628  i = len_trim(filext)
2629  j = len_trim(fnmpre)
2630  !
2631 #ifdef W3_T
2632  WRITE (ndst,9001) fnmpre(:j)//'out_grd.'//filext(:i)
2633 #endif
2634  IF ( WRITE ) THEN
2635  OPEN (ndsog,file=fnmpre(:j)//'out_grd.'//filext(:i), &
2636  form ='UNFORMATTED', convert=file_endian,err=800,iostat=ierr)
2637 #ifdef W3_ASCII
2638  OPEN (ndsoa,file=fnmpre(:j)//'out_grd.'//filext(:i)//'.txt', &
2639  form ='FORMATTED',err=800,iostat=ierr)
2640 #endif
2641  ELSE
2642  OPEN (ndsog,file=fnmpre(:j)//'out_grd.'//filext(:i), &
2643  form='UNFORMATTED', convert=file_endian,err=800,iostat=ierr,status='OLD')
2644  END IF
2645  !
2646  rewind( ndsog )
2647  !
2648  ! test info --------------------------------------------------------- *
2649  ! ( IPASS = 1 )
2650  !
2651  IF ( WRITE ) THEN
2652  WRITE (ndsog) &
2653  idstr, verogr, gname, nogrp, ngrpp, nsea, nx, ny, &
2654  undef, noswll
2655 #ifdef W3_ASCII
2656  WRITE (ndsoa,*) &
2657  'IDSTR, VEROGR, GNAME, NOGRP, NGRPP, NSEA, NX, NY, &
2658  UNDEF, NOSWLL:', &
2659  idstr, verogr, gname, nogrp, ngrpp, nsea, nx, ny, &
2660  undef, noswll
2661 #endif
2662  ELSE
2663  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
2664  idtst, vertst, tname, mogrp, mgrpp, nsea, nx, ny, &
2665  undef, moswll
2666  !
2667  IF ( idtst .NE. idstr ) THEN
2668  WRITE (ndse,902) idtst, idstr
2669  CALL extcde ( 20 )
2670  END IF
2671  IF ( vertst .NE. verogr ) THEN
2672  WRITE (ndse,903) vertst, verogr
2673  CALL extcde ( 21 )
2674  END IF
2675  IF ( nogrp .NE. mogrp .OR. ngrpp .NE. mgrpp ) THEN
2676  WRITE (ndse,904) mogrp, mgrpp, nogrp, ngrpp
2677  CALL extcde ( 22 )
2678  END IF
2679  IF ( tname .NE. gname ) THEN
2680  WRITE (ndse,905) tname, gname
2681  END IF
2682  IF ( noswll .NE. moswll ) THEN
2683  WRITE (ndse,906) moswll, noswll
2684  CALL extcde ( 24 )
2685  END IF
2686  !
2687  END IF
2688  !
2689 #ifdef W3_T
2690  WRITE (ndst,9002) idstr, verogr, gname, nsea, nx, ny, &
2691  undef
2692 #endif
2693  !
2694  END IF
2695  !
2696  ! IN CASE OF GENERATION OF A NEW FILE OUTPUT EVERY DELTA OUTPUT
2697  ! open file ---------------------------------------------------------- *
2698  ! ( IPASS = 1 )
2699  !
2700  IF ( ipass.GE.1 .AND. ofiles(1) .EQ. 1) THEN
2701  WRITE = inxout.EQ.'WRITE'
2702  ELSE
2703  IF ( WRITE .AND. inxout.EQ.'READ' ) THEN
2704  WRITE (ndse,901) inxout
2705  CALL extcde ( 2 )
2706  END IF
2707  END IF
2708 
2709  !
2710  IF ( ipass.GE.1 .AND. ofiles(1) .EQ. 1) THEN
2711  i = len_trim(filext)
2712  j = len_trim(fnmpre)
2713  !
2714  ! Create TIMETAG for file name using YYYYMMDD.HHMMS prefix
2715  WRITE(timetag,"(i8.8,'.'i6.6)")time(1),time(2)
2716 #ifdef W3_T
2717  WRITE (ndst,9001) fnmpre(:j)//timetag//'.out_grd.'//filext(:i)
2718 #endif
2719  IF ( WRITE ) THEN
2720  OPEN (ndsog,file=fnmpre(:j)//timetag//'.out_grd.' &
2721  //filext(:i),form='UNFORMATTED', convert=file_endian,err=800,iostat=ierr)
2722 #ifdef W3_ASCII
2723  OPEN (ndsoa,file=fnmpre(:j)//timetag//'.out_grd.' &
2724  //filext(:i)//'.txt',form='FORMATTED',err=800,iostat=ierr)
2725 #endif
2726  ELSE
2727  OPEN (ndsog,file=fnmpre(:j)//'out_grd.'//filext(:i), &
2728  form='UNFORMATTED', convert=file_endian,err=800,iostat=ierr,status='OLD')
2729  END IF
2730  !
2731  rewind( ndsog )
2732  !
2733  ! test info --------------------------------------------------------- *
2734  ! ( IPASS >= 1 & OFILES(1) = 1)
2735  !
2736  IF ( WRITE ) THEN
2737  WRITE (ndsog) &
2738  idstr, verogr, gname, nogrp, ngrpp, nsea, nx, ny, &
2739  undef, noswll
2740 #ifdef W3_ASCII
2741  WRITE (ndsoa,*) &
2742  'IDSTR, VEROGR, GNAME, NOGRP, NGRPP, NSEA, NX, NY, &
2743  UNDEF, NOSWLL:', &
2744  idstr, verogr, gname, nogrp, ngrpp, nsea, nx, ny, &
2745  undef, noswll
2746 #endif
2747  ELSE
2748  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
2749  idtst, vertst, tname, mogrp, mgrpp, nsea, nx, ny, &
2750  undef, moswll
2751  !
2752  IF ( idtst .NE. idstr ) THEN
2753  WRITE (ndse,902) idtst, idstr
2754  CALL extcde ( 20 )
2755  END IF
2756  IF ( vertst .NE. verogr ) THEN
2757  WRITE (ndse,903) vertst, verogr
2758  CALL extcde ( 21 )
2759  END IF
2760  IF ( nogrp .NE. mogrp .OR. ngrpp .NE. mgrpp ) THEN
2761  WRITE (ndse,904) mogrp, mgrpp, nogrp, ngrpp
2762  CALL extcde ( 22 )
2763  END IF
2764  IF ( tname .NE. gname ) THEN
2765  WRITE (ndse,905) tname, gname
2766  END IF
2767  IF ( noswll .NE. moswll ) THEN
2768  WRITE (ndse,906) moswll, noswll
2769  CALL extcde ( 24 )
2770  END IF
2771  !
2772  END IF
2773  !
2774 #ifdef W3_T
2775  WRITE (ndst,9002) idstr, verogr, gname, nsea, nx, ny, &
2776  undef
2777 #endif
2778  !
2779  END IF
2780  !
2781  ! TIME and flags ----------------------------------------------------- *
2782  !
2783  IF ( WRITE ) THEN
2784  WRITE (ndsog) time, flogrd
2785 #ifdef W3_ASCII
2786  WRITE (ndsoa,*) 'TIME, FLOGRD:', &
2787  time, flogrd
2788 #endif
2789  ELSE
2790  READ (ndsog,END=803,ERR=802,IOSTAT=IERR) TIME, flogrd
2791  END IF
2792  !
2793 #ifdef W3_T
2794  WRITE (ndst,9003) time, flogrd
2795 #endif
2796  !
2797  ! MAPSTA ------------------------------------------------------------- *
2798  !
2799  ALLOCATE ( maptmp(ny,nx) )
2800  IF ( WRITE ) THEN
2801  maptmp = mapsta + 8*mapst2
2802  WRITE (ndsog) &
2803  ((maptmp(iy,ix),ix=1,nx),iy=1,ny)
2804 #ifdef W3_ASCII
2805  WRITE (ndsoa,*) 'MAPSTA:', &
2806  ((maptmp(iy,ix),ix=1,nx),iy=1,ny)
2807 #endif
2808  ELSE
2809  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
2810  ((maptmp(iy,ix),ix=1,nx),iy=1,ny)
2811  mapsta = mod(maptmp+2,8) - 2
2812  mapst2 = (maptmp-mapsta) / 8
2813  END IF
2814  DEALLOCATE ( maptmp )
2815  !
2816  ! Fields ---------------------------------------------- *
2817  !
2818  ! Initialization ---------------------------------------------- *
2819  !
2820  IF ( WRITE ) THEN
2821  DO isea=1, nsea
2822  IF ( mapsta(mapsf(isea,2),mapsf(isea,1)) .LT. 0 ) THEN
2823  !
2824  IF ( flogrd( 2, 2) ) wlm(isea) = undef
2825  IF ( flogrd( 2, 3) ) t02(isea) = undef
2826  IF ( flogrd( 2, 4) ) t0m1(isea) = undef
2827  IF ( flogrd( 2, 5) ) t01(isea) = undef
2828  IF ( flogrd( 2, 6) .OR. flogrd( 2,18) ) &
2829  fp0(isea) = undef ! FP or TP
2830  IF ( flogrd( 2, 7) ) thm(isea) = undef
2831  IF ( flogrd( 2, 8) ) ths(isea) = undef
2832  IF ( flogrd( 2, 9) ) thp0(isea) = undef
2833  ust(isea) = undef
2834  ustdir(isea) = undef
2835  IF ( flogrd( 2,10) ) hsig(isea) = undef
2836  IF ( flogrd( 2,11) ) stmaxe(isea) = undef
2837  IF ( flogrd( 2,12) ) stmaxd(isea) = undef
2838  IF ( flogrd( 2,13) ) hmaxe(isea) = undef
2839  IF ( flogrd( 2,14) ) hcmaxe(isea) = undef
2840  IF ( flogrd( 2,15) ) hmaxd(isea) = undef
2841  IF ( flogrd( 2,16) ) hcmaxd(isea) = undef
2842  IF ( flogrd( 2,17) ) wbt(isea) = undef
2843  IF ( flogrd( 2,19) ) wnmean(isea) = undef
2844  !
2845  IF ( flogrd( 3, 1) ) ef(isea,:) = undef
2846  IF ( flogrd( 3, 2) ) th1m(isea,:) = undef
2847  IF ( flogrd( 3, 3) ) sth1m(isea,:) = undef
2848  IF ( flogrd( 3, 4) ) th2m(isea,:) = undef
2849  IF ( flogrd( 3, 5) ) sth2m(isea,:) = undef
2850  !
2851  IF ( flogrd( 4, 1) ) phs(isea,:) = undef
2852  IF ( flogrd( 4, 2) ) ptp(isea,:) = undef
2853  IF ( flogrd( 4, 3) ) plp(isea,:) = undef
2854  IF ( flogrd( 4, 4) ) pdir(isea,:) = undef
2855  IF ( flogrd( 4, 5) ) psi(isea,:) = undef
2856  IF ( flogrd( 4, 6) ) pws(isea,:) = undef
2857  IF ( flogrd( 4, 7) ) pthp0(isea,:) = undef
2858  IF ( flogrd( 4, 8) ) pqp(isea,:) = undef
2859  IF ( flogrd( 4, 9) ) ppe(isea,:) = undef
2860  IF ( flogrd( 4,10) ) pgw(isea,:) = undef
2861  IF ( flogrd( 4,11) ) psw(isea,:) = undef
2862  IF ( flogrd( 4,12) ) ptm1(isea,:) = undef
2863  IF ( flogrd( 4,13) ) pt1(isea,:) = undef
2864  IF ( flogrd( 4,14) ) pt2(isea,:) = undef
2865  IF ( flogrd( 4,15) ) pep(isea,:) = undef
2866  IF ( flogrd( 4,16) ) pwst(isea ) = undef
2867  IF ( flogrd( 4,17) ) pnr(isea ) = undef
2868  !
2869  IF ( flogrd( 5, 2) ) charn(isea) = undef
2870  IF ( flogrd( 5, 3) ) cge(isea) = undef
2871  IF ( flogrd( 5, 4) ) phiaw(isea) = undef
2872  IF ( flogrd( 5, 5) ) THEN
2873  tauwix(isea) = undef
2874  tauwiy(isea) = undef
2875  END IF
2876  IF ( flogrd( 5, 6) ) THEN
2877  tauwnx(isea) = undef
2878  tauwny(isea) = undef
2879  END IF
2880  IF ( flogrd( 5, 7) ) whitecap(isea,1) = undef
2881  IF ( flogrd( 5, 8) ) whitecap(isea,2) = undef
2882  IF ( flogrd( 5, 9) ) whitecap(isea,3) = undef
2883  IF ( flogrd( 5,10) ) whitecap(isea,4) = undef
2884  !
2885  IF ( flogrd( 6, 1) ) THEN
2886  sxx(isea) = undef
2887  syy(isea) = undef
2888  sxy(isea) = undef
2889  END IF
2890  IF ( flogrd( 6, 2) ) THEN
2891  tauox(isea) = undef
2892  tauoy(isea) = undef
2893  END IF
2894  IF ( flogrd( 6, 3) ) bhd(isea) = undef
2895  IF ( flogrd( 6, 4) ) phioc(isea) = undef
2896  IF ( flogrd( 6, 5) ) THEN
2897  tusx(isea) = undef
2898  tusy(isea) = undef
2899  END IF
2900  IF ( flogrd( 6, 6) ) THEN
2901  ussx(isea) = undef
2902  ussy(isea) = undef
2903  END IF
2904  IF ( flogrd( 6, 7) ) THEN
2905  prms(isea) = undef
2906  tpms(isea) = undef
2907  END IF
2908  IF ( flogrd( 6, 8) ) us3d(isea,:) = undef
2909  IF ( flogrd( 6, 9) ) p2sms(isea,:) = undef
2910  IF ( flogrd( 6, 10) ) tauice(isea,:) = undef
2911  IF ( flogrd( 6, 11) ) phice(isea) = undef
2912  IF ( flogrd( 6, 12) ) ussp(isea,:) = undef
2913  IF ( flogrd( 6, 13) ) THEN
2914  tauocx(isea) = undef
2915  tauocy(isea) = undef
2916  END IF
2917  !
2918  IF ( flogrd( 7, 1) ) THEN
2919  aba(isea) = undef
2920  abd(isea) = undef
2921  END IF
2922  IF ( flogrd( 7, 2) ) THEN
2923  uba(isea) = undef
2924  ubd(isea) = undef
2925  END IF
2926  IF ( flogrd( 7, 3) ) bedforms(isea,:) = undef
2927  IF ( flogrd( 7, 4) ) phibbl(isea) = undef
2928  IF ( flogrd( 7, 5) ) taubbl(isea,:) = undef
2929  !
2930  IF ( flogrd( 8, 1) ) THEN
2931  mssx(isea) = undef
2932  mssy(isea) = undef
2933  END IF
2934  IF ( flogrd( 8, 2) ) THEN
2935  mscx(isea) = undef
2936  mscy(isea) = undef
2937  END IF
2938  IF ( flogrd( 8, 3) ) mssd(isea) = undef
2939  IF ( flogrd( 8, 4) ) mscd(isea) = undef
2940  IF ( flogrd( 8, 5) ) qp(isea) = undef
2941  IF ( flogrd( 8, 6) ) qkk(isea) = undef
2942  IF ( flogrd( 8, 7) ) skew(isea) = undef
2943  IF ( flogrd( 8, 8) ) embia1(isea) = undef
2944  IF ( flogrd( 8, 9) ) embia2(isea) = undef
2945  !
2946  IF ( flogrd( 9, 1) ) dtdyn(isea) = undef
2947  IF ( flogrd( 9, 2) ) fcut(isea) = undef
2948  IF ( flogrd( 9, 3) ) cflxymax(isea) = undef
2949  IF ( flogrd( 9, 4) ) cflthmax(isea) = undef
2950  IF ( flogrd( 9, 5) ) cflkmax(isea) = undef
2951  !
2952  END IF
2953  !
2954  IF ( mapsta(mapsf(isea,2),mapsf(isea,1)) .EQ. 2 ) THEN
2955  !
2956  IF ( flogrd( 5, 4) ) phiaw(isea) = undef
2957  IF ( flogrd( 5, 5) ) THEN
2958  tauwix(isea) = undef
2959  tauwiy(isea) = undef
2960  END IF
2961  IF ( flogrd( 5, 6) ) THEN
2962  tauwnx(isea) = undef
2963  tauwny(isea) = undef
2964  END IF
2965  IF ( flogrd( 5, 7) ) whitecap(isea,1) = undef
2966  IF ( flogrd( 5, 8) ) whitecap(isea,2) = undef
2967  IF ( flogrd( 5, 9) ) whitecap(isea,3) = undef
2968  IF ( flogrd( 5,10) ) whitecap(isea,4) = undef
2969  !
2970  IF ( flogrd( 6, 2) )THEN
2971  tauox(isea) = undef
2972  tauoy(isea) = undef
2973  END IF
2974  IF ( flogrd( 6, 4) ) phioc(isea) = undef
2975  !
2976  IF ( flogrd( 7, 3) ) bedforms(isea,:) = undef
2977  IF ( flogrd( 7, 4) ) phibbl(isea) = undef
2978  IF ( flogrd( 7, 5) ) taubbl(isea,:) = undef
2979  !
2980  END IF
2981  !
2982  END DO
2983  !
2984  ELSE
2985  IF (.NOT.dinit) CALL w3dimw ( igrd, ndse, ndst, .true. )
2986  IF (.NOT.ainit) CALL w3dima ( igrd, ndse, ndst, .true. )
2987  END IF
2988  !
2989  ! Actual output ---------------------------------------------- *
2990  DO ifi=1, nogrp
2991  DO ifj=1, ngrpp
2992 
2993  IF ( flogrd(ifi,ifj) ) THEN
2994  !
2995 #ifdef W3_T
2996  WRITE (ndst,9010) flogrd(ifi,ifj), idout(ifi,ifj)
2997 #endif
2998  !
2999  IF ( WRITE ) THEN
3000  !
3001  ! Section 1)
3002  !
3003  IF ( ifi .EQ. 1 .AND. ifj .EQ. 1 ) THEN
3004  WRITE ( ndsog ) dw(1:nsea)
3005 #ifdef W3_ASCII
3006  WRITE ( ndsoa,* ) 'DW:', dw(1:nsea)
3007 #endif
3008  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 2 ) THEN
3009  WRITE ( ndsog ) cx(1:nsea)
3010 #ifdef W3_ASCII
3011  WRITE ( ndsoa,* ) 'CX:', cx(1:nsea)
3012 #endif
3013  WRITE ( ndsog ) cy(1:nsea)
3014 #ifdef W3_ASCII
3015  WRITE ( ndsoa,* ) 'CY:', cy(1:nsea)
3016 #endif
3017  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 3 ) THEN
3018  DO isea=1, nsea
3019 #ifdef W3_SMC
3020  !!Li Rotate map-east wind in Arctic part back to local east. JGLi02Feb2016
3021  IF( arctc .AND. (isea .GT. nglo) ) THEN
3022  udarc = ud(isea) - angarc(isea - nglo)*dera
3023  ud(isea) = mod(tpi + udarc, tpi)
3024  ENDIF
3025 #endif
3026  IF (ua(isea) .NE.undef) THEN
3027  aux1(isea) = ua(isea)*cos(ud(isea))
3028  aux2(isea) = ua(isea)*sin(ud(isea))
3029  ELSE
3030  aux1(isea) = undef
3031  aux2(isea) = undef
3032  END IF
3033  END DO
3034  WRITE ( ndsog ) aux1
3035 #ifdef W3_ASCII
3036  WRITE ( ndsoa,* ) 'AUX1 (UA*cos(UD)):', aux1
3037 #endif
3038  WRITE ( ndsog ) aux2
3039 #ifdef W3_ASCII
3040  WRITE ( ndsoa,* ) 'AUX2 (UA*sin(UD)):', aux2
3041 #endif
3042  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 4 ) THEN
3043  WRITE ( ndsog ) as(1:nsea)
3044 #ifdef W3_ASCII
3045  WRITE ( ndsoa,* ) 'AS:', as(1:nsea)
3046 #endif
3047  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 5 ) THEN
3048  WRITE ( ndsog ) wlv(1:nsea)
3049 #ifdef W3_ASCII
3050  WRITE ( ndsoa,* ) 'WLV:', wlv(1:nsea)
3051 #endif
3052  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 6 ) THEN
3053  WRITE ( ndsog ) ice(1:nsea)
3054 #ifdef W3_ASCII
3055  WRITE ( ndsoa,* ) 'ICE:', ice(1:nsea)
3056 #endif
3057  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 7 ) THEN
3058  WRITE ( ndsog ) berg(1:nsea)
3059 #ifdef W3_ASCII
3060  WRITE ( ndsoa,* ) 'BERG:', berg(1:nsea)
3061 #endif
3062  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 8 ) THEN
3063  DO isea=1, nsea
3064 #ifdef W3_SMC
3065  !!Li Rotate map-east momentum in Arctic part back to local east. JGLi02Feb2016
3066  IF( arctc .AND. (isea .GT. nglo) ) THEN
3067  udarc = tauadir(isea) - angarc(isea - nglo)*dera
3068  tauadir(isea) = mod(tpi + udarc, tpi)
3069  ENDIF
3070 #endif
3071  IF (taua(isea) .NE.undef) THEN
3072  aux1(isea) = taua(isea)*cos(tauadir(isea))
3073  aux2(isea) = taua(isea)*sin(tauadir(isea))
3074  ELSE
3075  aux1(isea) = undef
3076  aux2(isea) = undef
3077  END IF
3078  END DO
3079  WRITE ( ndsog ) aux1
3080 #ifdef W3_ASCII
3081  WRITE ( ndsoa,* ) 'AUX1 (TAUA*cos(TAUADIR)):', aux1
3082 #endif
3083  WRITE ( ndsog ) aux2
3084 #ifdef W3_ASCII
3085  WRITE ( ndsoa,* ) 'AUX2 (TAUA*sin(TAUADIR)):', aux2
3086 #endif
3087  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 9 ) THEN
3088  WRITE ( ndsog ) rhoair(1:nsea)
3089 #ifdef W3_ASCII
3090  WRITE ( ndsoa,* ) 'RHOAIR:', rhoair(1:nsea)
3091 #endif
3092 #ifdef W3_BT4
3093  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 10 ) THEN
3094  WRITE ( ndsog ) sed_d50(1:nsea)
3095 #ifdef W3_ASCII
3096  WRITE ( ndsoa,* ) 'SED_D50:', sed_d50(1:nsea)
3097 #endif
3098 #endif
3099 #ifdef W3_IS2
3100  ELSE IF (ifi .EQ. 1 .AND. ifj .EQ. 11 ) THEN
3101  WRITE (ndsog ) iceh(1:nsea)
3102 #ifdef W3_ASCII
3103  WRITE (ndsoa,* ) 'ICEH:', iceh(1:nsea)
3104 #endif
3105  ELSE IF (ifi .EQ. 1 .AND. ifj .EQ. 12 ) THEN
3106  WRITE (ndsog ) icef(1:nsea)
3107 #ifdef W3_ASCII
3108  WRITE (ndsoa,* ) 'ICEF:', icef(1:nsea)
3109 #endif
3110 #endif
3111 #ifdef W3_SETUP
3112  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 13 ) THEN
3113  WRITE ( ndsog ) zeta_setup(1:nsea)
3114 #ifdef W3_ASCII
3115  WRITE ( ndsoa,* ) 'ZETA_SETUP:', zeta_setup(1:nsea)
3116 #endif
3117 #endif
3118 
3119  !
3120  ! Section 2)
3121  !
3122  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 1 ) THEN
3123  WRITE ( ndsog ) hs(1:nsea)
3124 #ifdef W3_ASCII
3125  WRITE ( ndsoa,* ) 'HS:', hs(1:nsea)
3126 #endif
3127  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 2 ) THEN
3128  WRITE ( ndsog ) wlm(1:nsea)
3129 #ifdef W3_ASCII
3130  WRITE ( ndsoa,* ) 'WLM:', wlm(1:nsea)
3131 #endif
3132  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 3 ) THEN
3133  WRITE ( ndsog ) t02(1:nsea)
3134 #ifdef W3_ASCII
3135  WRITE ( ndsoa,* ) 'T02:', t02(1:nsea)
3136 #endif
3137  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 4 ) THEN
3138  WRITE ( ndsog ) t0m1(1:nsea)
3139 #ifdef W3_ASCII
3140  WRITE ( ndsoa,* ) 'T0M1:', t0m1(1:nsea)
3141 #endif
3142  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 5 ) THEN
3143  WRITE ( ndsog ) t01(1:nsea)
3144 #ifdef W3_ASCII
3145  WRITE ( ndsoa,* ) 'T01:', t01(1:nsea)
3146 #endif
3147  ELSE IF ( (ifi .EQ. 2 .AND. ifj .EQ. 6) .OR. &
3148  (ifi .EQ. 2 .AND. ifj .EQ. 18) ) THEN
3149  ! Note: TP output is derived from FP field.
3150  WRITE ( ndsog ) fp0(1:nsea)
3151 #ifdef W3_ASCII
3152  WRITE ( ndsoa,* ) 'FP0:', fp0(1:nsea)
3153 #endif
3154  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 7 ) THEN
3155  WRITE ( ndsog ) thm(1:nsea)
3156 #ifdef W3_ASCII
3157  WRITE ( ndsoa,* ) 'THM:', thm(1:nsea)
3158 #endif
3159  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 8 ) THEN
3160  WRITE ( ndsog ) ths(1:nsea)
3161 #ifdef W3_ASCII
3162  WRITE ( ndsoa,* ) 'THS:', ths(1:nsea)
3163 #endif
3164  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 9 ) THEN
3165  WRITE ( ndsog ) thp0(1:nsea)
3166 #ifdef W3_ASCII
3167  WRITE ( ndsoa,* ) 'THP0:', thp0(1:nsea)
3168 #endif
3169  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 10 ) THEN
3170  WRITE ( ndsog ) hsig(1:nsea)
3171 #ifdef W3_ASCII
3172  WRITE ( ndsoa,* ) 'HSIG:', hsig(1:nsea)
3173 #endif
3174  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 11 ) THEN
3175  WRITE ( ndsog ) stmaxe(1:nsea)
3176 #ifdef W3_ASCII
3177  WRITE ( ndsoa,* ) 'STMAXE:', stmaxe(1:nsea)
3178 #endif
3179  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 12 ) THEN
3180  WRITE ( ndsog ) stmaxd(1:nsea)
3181 #ifdef W3_ASCII
3182  WRITE ( ndsoa,* ) 'STMAXD:', stmaxd(1:nsea)
3183 #endif
3184  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 13 ) THEN
3185  WRITE ( ndsog ) hmaxe(1:nsea)
3186 #ifdef W3_ASCII
3187  WRITE ( ndsoa,* ) 'HMAXE:', hmaxe(1:nsea)
3188 #endif
3189  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 14 ) THEN
3190  WRITE ( ndsog ) hcmaxe(1:nsea)
3191 #ifdef W3_ASCII
3192  WRITE ( ndsoa,* ) 'HCMAXE:', hcmaxe(1:nsea)
3193 #endif
3194  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 15 ) THEN
3195  WRITE ( ndsog ) hmaxd(1:nsea)
3196 #ifdef W3_ASCII
3197  WRITE ( ndsoa,* ) 'HMAXD:', hmaxd(1:nsea)
3198 #endif
3199  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 16 ) THEN
3200  WRITE ( ndsog ) hcmaxd(1:nsea)
3201 #ifdef W3_ASCII
3202  WRITE ( ndsoa,* ) 'HCMAXD:', hcmaxd(1:nsea)
3203 #endif
3204  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 17 ) THEN
3205  WRITE ( ndsog ) wbt(1:nsea)
3206 #ifdef W3_ASCII
3207  WRITE ( ndsoa,* ) 'WBT:', wbt(1:nsea)
3208 #endif
3209  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 19 ) THEN
3210  WRITE ( ndsog ) wnmean(1:nsea)
3211 #ifdef W3_ASCII
3212  WRITE ( ndsoa,* ) 'WNMEAN:', wnmean(1:nsea)
3213 #endif
3214  !
3215  ! Section 3)
3216  !
3217  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 1 ) THEN
3218  WRITE ( ndsog ) ef(1:nsea,e3df(2,1):e3df(3,1))
3219 #ifdef W3_ASCII
3220  WRITE ( ndsoa,* ) 'EF:', ef(1:nsea,e3df(2,1):e3df(3,1))
3221 #endif
3222  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 2 ) THEN
3223  WRITE ( ndsog ) th1m(1:nsea,e3df(2,2):e3df(3,2))
3224 #ifdef W3_ASCII
3225  WRITE ( ndsoa,* ) 'TH1M:', th1m(1:nsea,e3df(2,2):e3df(3,2))
3226 #endif
3227  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 3 ) THEN
3228  WRITE ( ndsog ) sth1m(1:nsea,e3df(2,3):e3df(3,3))
3229 #ifdef W3_ASCII
3230  WRITE ( ndsoa,* ) 'STH1M:', sth1m(1:nsea,e3df(2,3):e3df(3,3))
3231 #endif
3232  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 4 ) THEN
3233  WRITE ( ndsog ) th2m(1:nsea,e3df(2,4):e3df(3,4))
3234 #ifdef W3_ASCII
3235  WRITE ( ndsoa,* ) 'TH2M:', th2m(1:nsea,e3df(2,4):e3df(3,4))
3236 #endif
3237  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 5 ) THEN
3238  WRITE ( ndsog ) sth2m(1:nsea,e3df(2,5):e3df(3,5))
3239 #ifdef W3_ASCII
3240  WRITE ( ndsoa,* ) 'STH2M:', sth2m(1:nsea,e3df(2,5):e3df(3,5))
3241 #endif
3242  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 6) THEN
3243  WRITE ( ndsog ) wn(1:nk,1:nsea)
3244 #ifdef W3_ASCII
3245  WRITE ( ndsoa,* ) 'WN:', wn(1:nk,1:nsea)
3246 #endif
3247  !
3248  ! Section 4)
3249  !
3250  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 1 ) THEN
3251  WRITE ( ndsog ) phs(1:nsea,0:noswll)
3252 #ifdef W3_ASCII
3253  WRITE ( ndsoa,* ) 'PHS:', phs(1:nsea,0:noswll)
3254 #endif
3255  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 2 ) THEN
3256  WRITE ( ndsog ) ptp(1:nsea,0:noswll)
3257 #ifdef W3_ASCII
3258  WRITE ( ndsoa,* ) 'PTP:', ptp(1:nsea,0:noswll)
3259 #endif
3260  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 3 ) THEN
3261  WRITE ( ndsog ) plp(1:nsea,0:noswll)
3262 #ifdef W3_ASCII
3263  WRITE ( ndsoa,* ) 'PLP:', plp(1:nsea,0:noswll)
3264 #endif
3265  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 4 ) THEN
3266  WRITE ( ndsog ) pdir(1:nsea,0:noswll)
3267 #ifdef W3_ASCII
3268  WRITE ( ndsoa,* ) 'PDIR:', pdir(1:nsea,0:noswll)
3269 #endif
3270  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 5 ) THEN
3271  WRITE ( ndsog ) psi(1:nsea,0:noswll)
3272 #ifdef W3_ASCII
3273  WRITE ( ndsoa,* ) 'PSI:', psi(1:nsea,0:noswll)
3274 #endif
3275  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 6 ) THEN
3276  WRITE ( ndsog ) pws(1:nsea,0:noswll)
3277 #ifdef W3_ASCII
3278  WRITE ( ndsoa,* ) 'PWS:', pws(1:nsea,0:noswll)
3279 #endif
3280  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 7 ) THEN
3281  WRITE ( ndsog ) pthp0(1:nsea,0:noswll)
3282 #ifdef W3_ASCII
3283  WRITE ( ndsoa,* ) 'PTHP0:', pthp0(1:nsea,0:noswll)
3284 #endif
3285  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 8 ) THEN
3286  WRITE ( ndsog ) pqp(1:nsea,0:noswll)
3287 #ifdef W3_ASCII
3288  WRITE ( ndsoa,* ) 'PQP:', pqp(1:nsea,0:noswll)
3289 #endif
3290  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 9 ) THEN
3291  WRITE ( ndsog ) ppe(1:nsea,0:noswll)
3292 #ifdef W3_ASCII
3293  WRITE ( ndsoa,* ) 'PPE:', ppe(1:nsea,0:noswll)
3294 #endif
3295  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 10 ) THEN
3296  WRITE ( ndsog ) pgw(1:nsea,0:noswll)
3297 #ifdef W3_ASCII
3298  WRITE ( ndsoa,* ) 'PGW:', pgw(1:nsea,0:noswll)
3299 #endif
3300  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 11 ) THEN
3301  WRITE ( ndsog ) psw(1:nsea,0:noswll)
3302 #ifdef W3_ASCII
3303  WRITE ( ndsoa,* ) 'PSW:', psw(1:nsea,0:noswll)
3304 #endif
3305  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 12 ) THEN
3306  WRITE ( ndsog ) ptm1(1:nsea,0:noswll)
3307 #ifdef W3_ASCII
3308  WRITE ( ndsoa,* ) 'PTM1:', ptm1(1:nsea,0:noswll)
3309 #endif
3310  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 13 ) THEN
3311  WRITE ( ndsog ) pt1(1:nsea,0:noswll)
3312 #ifdef W3_ASCII
3313  WRITE ( ndsoa,* ) 'PT1:', pt1(1:nsea,0:noswll)
3314 #endif
3315  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 14 ) THEN
3316  WRITE ( ndsog ) pt2(1:nsea,0:noswll)
3317 #ifdef W3_ASCII
3318  WRITE ( ndsoa,* ) 'PT2:', pt2(1:nsea,0:noswll)
3319 #endif
3320  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 15 ) THEN
3321  WRITE ( ndsog ) pep(1:nsea,0:noswll)
3322 #ifdef W3_ASCII
3323  WRITE ( ndsoa,* ) 'PEP:', pep(1:nsea,0:noswll)
3324 #endif
3325  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 16 ) THEN
3326  WRITE ( ndsog ) pwst(1:nsea)
3327 #ifdef W3_ASCII
3328  WRITE ( ndsoa,* ) 'PWST:', pwst(1:nsea)
3329 #endif
3330  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 17 ) THEN
3331  WRITE ( ndsog ) pnr(1:nsea)
3332 #ifdef W3_ASCII
3333  WRITE ( ndsoa,* ) 'PNR:', pnr(1:nsea)
3334 #endif
3335  !
3336  ! Section 5)
3337  !
3338  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 1 ) THEN
3339  DO isea=1, nsea
3340  ix = mapsf(isea,1)
3341  iy = mapsf(isea,2)
3342  IF ( mapsta(iy,ix) .EQ. 1 ) THEN
3343  aux1(isea) = ust(isea) * asf(isea) * &
3344  cos(ustdir(isea))
3345  aux2(isea) = ust(isea) * asf(isea) * &
3346  sin(ustdir(isea))
3347  ELSE
3348  aux1(isea) = undef
3349  aux2(isea) = undef
3350  END IF
3351  END DO
3352  WRITE ( ndsog ) aux1
3353 #ifdef W3_ASCII
3354  WRITE ( ndsoa,* ) 'AUX1 (UST*ASF*cos(USTDIR)):', aux1
3355 #endif
3356  WRITE ( ndsog ) aux2
3357 #ifdef W3_ASCII
3358  WRITE ( ndsoa,* ) 'AUX2 (UST*ASF*sin(USTDIR)):', aux2
3359 #endif
3360  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 2 ) THEN
3361  WRITE ( ndsog ) charn(1:nsea)
3362 #ifdef W3_ASCII
3363  WRITE ( ndsoa,* ) 'CHARN:', charn(1:nsea)
3364 #endif
3365  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 3 ) THEN
3366  WRITE ( ndsog ) cge(1:nsea)
3367 #ifdef W3_ASCII
3368  WRITE ( ndsoa,* ) 'CGE:', cge(1:nsea)
3369 #endif
3370  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 4 ) THEN
3371  WRITE ( ndsog ) phiaw(1:nsea)
3372 #ifdef W3_ASCII
3373  WRITE ( ndsoa,* ) 'PHIAW:', phiaw(1:nsea)
3374 #endif
3375  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 5 ) THEN
3376  WRITE ( ndsog ) tauwix(1:nsea)
3377 #ifdef W3_ASCII
3378  WRITE ( ndsoa,* ) 'TAUWIX:', tauwix(1:nsea)
3379 #endif
3380  WRITE ( ndsog ) tauwiy(1:nsea)
3381 #ifdef W3_ASCII
3382  WRITE ( ndsoa,* ) 'TAUWIY:', tauwiy(1:nsea)
3383 #endif
3384  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 6 ) THEN
3385  WRITE ( ndsog ) tauwnx(1:nsea)
3386 #ifdef W3_ASCII
3387  WRITE ( ndsoa,* ) 'TAUWNX:', tauwnx(1:nsea)
3388 #endif
3389  WRITE ( ndsog ) tauwny(1:nsea)
3390 #ifdef W3_ASCII
3391  WRITE ( ndsoa,* ) 'TAUWNY:', tauwny(1:nsea)
3392 #endif
3393  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 7 ) THEN
3394  WRITE ( ndsog ) whitecap(1:nsea,1)
3395 #ifdef W3_ASCII
3396  WRITE ( ndsoa,* ) 'WHITECAP(1):', whitecap(1:nsea,1)
3397 #endif
3398  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 8 ) THEN
3399  WRITE ( ndsog ) whitecap(1:nsea,2)
3400 #ifdef W3_ASCII
3401  WRITE ( ndsoa,* ) 'WHITECAP(2):', whitecap(1:nsea,2)
3402 #endif
3403  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 9 ) THEN
3404  WRITE ( ndsog ) whitecap(1:nsea,3)
3405 #ifdef W3_ASCII
3406  WRITE ( ndsoa,* ) 'WHITECAP(3):', whitecap(1:nsea,3)
3407 #endif
3408  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 10 ) THEN
3409  WRITE ( ndsog ) whitecap(1:nsea,4)
3410 #ifdef W3_ASCII
3411  WRITE ( ndsoa,* ) 'WHITECAP(4):', whitecap(1:nsea,4)
3412 #endif
3413  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 11 ) THEN
3414  WRITE ( ndsog ) tws(1:nsea)
3415 #ifdef W3_ASCII
3416  WRITE ( ndsoa,* ) 'TWS:', tws(1:nsea)
3417 #endif
3418  !
3419  ! Section 6)
3420  !
3421  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 1 ) THEN
3422  WRITE ( ndsog ) sxx(1:nsea)
3423 #ifdef W3_ASCII
3424  WRITE ( ndsoa,* ) 'SXX:', sxx(1:nsea)
3425 #endif
3426  WRITE ( ndsog ) syy(1:nsea)
3427 #ifdef W3_ASCII
3428  WRITE ( ndsoa,* ) 'SYY:', syy(1:nsea)
3429 #endif
3430  WRITE ( ndsog ) sxy(1:nsea)
3431 #ifdef W3_ASCII
3432  WRITE ( ndsoa,* ) 'SXY:', sxy(1:nsea)
3433 #endif
3434  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 2 ) THEN
3435  WRITE ( ndsog ) tauox(1:nsea)
3436 #ifdef W3_ASCII
3437  WRITE ( ndsoa,* ) 'TAUOX:', tauox(1:nsea)
3438 #endif
3439  WRITE ( ndsog ) tauoy(1:nsea)
3440 #ifdef W3_ASCII
3441  WRITE ( ndsoa,* ) 'TAUOY:', tauoy(1:nsea)
3442 #endif
3443  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 3 ) THEN
3444  WRITE ( ndsog ) bhd(1:nsea)
3445 #ifdef W3_ASCII
3446  WRITE ( ndsoa,* ) 'BHD:', bhd(1:nsea)
3447 #endif
3448  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 4 ) THEN
3449  WRITE ( ndsog ) phioc(1:nsea)
3450 #ifdef W3_ASCII
3451  WRITE ( ndsoa,* ) 'PHIOC:', phioc(1:nsea)
3452 #endif
3453  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 5 ) THEN
3454  WRITE ( ndsog ) tusx(1:nsea)
3455 #ifdef W3_ASCII
3456  WRITE ( ndsoa,* ) 'TUSX:', tusx(1:nsea)
3457 #endif
3458  WRITE ( ndsog ) tusy(1:nsea)
3459 #ifdef W3_ASCII
3460  WRITE ( ndsoa,* ) 'TUSY:', tusy(1:nsea)
3461 #endif
3462  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 6 ) THEN
3463  WRITE ( ndsog ) ussx(1:nsea)
3464 #ifdef W3_ASCII
3465  WRITE ( ndsoa,* ) 'USSX:', ussx(1:nsea)
3466 #endif
3467  WRITE ( ndsog ) ussy(1:nsea)
3468 #ifdef W3_ASCII
3469  WRITE ( ndsoa,* ) 'USSY:', ussy(1:nsea)
3470 #endif
3471  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 7 ) THEN
3472  WRITE ( ndsog ) prms(1:nsea)
3473 #ifdef W3_ASCII
3474  WRITE ( ndsoa,* ) 'PRMS:', prms(1:nsea)
3475 #endif
3476  WRITE ( ndsog ) tpms(1:nsea)
3477 #ifdef W3_ASCII
3478  WRITE ( ndsoa,* ) 'TPMS:', tpms(1:nsea)
3479 #endif
3480  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 8 ) THEN
3481  WRITE ( ndsog ) us3d(1:nsea, us3df(2):us3df(3))
3482 #ifdef W3_ASCII
3483  WRITE ( ndsoa,* ) 'US3D:', us3d(1:nsea, us3df(2):us3df(3))
3484 #endif
3485  WRITE ( ndsog ) us3d(1:nsea,nk+us3df(2):nk+us3df(3))
3486 #ifdef W3_ASCII
3487  WRITE ( ndsoa,* ) 'US3D+NK:', us3d(1:nsea,nk+us3df(2):nk+us3df(3))
3488 #endif
3489  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 9 ) THEN
3490  WRITE ( ndsog ) p2sms(1:nsea,p2msf(2):p2msf(3))
3491 #ifdef W3_ASCII
3492  WRITE ( ndsoa,* ) 'P2SMS:', p2sms(1:nsea,p2msf(2):p2msf(3))
3493 #endif
3494  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 10 ) THEN
3495  WRITE ( ndsog ) tauice(1:nsea,1)
3496 #ifdef W3_ASCII
3497  WRITE ( ndsoa,* ) 'TAUICE(1):', tauice(1:nsea,1)
3498 #endif
3499  WRITE ( ndsog ) tauice(1:nsea,2)
3500 #ifdef W3_ASCII
3501  WRITE ( ndsoa,* ) 'TAUICE(2):', tauice(1:nsea,2)
3502 #endif
3503  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 11 ) THEN
3504  WRITE ( ndsog ) phice(1:nsea)
3505 #ifdef W3_ASCII
3506  WRITE ( ndsoa,* ) 'PHICE:', phice(1:nsea)
3507 #endif
3508  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 12 ) THEN
3509  WRITE ( ndsog ) ussp(1:nsea, 1:usspf(2))
3510 #ifdef W3_ASCII
3511  WRITE ( ndsoa,* ) 'USSP:', ussp(1:nsea, 1:usspf(2))
3512 #endif
3513  WRITE ( ndsog ) ussp(1:nsea,nk+1:nk+usspf(2))
3514 #ifdef W3_ASCII
3515  WRITE ( ndsoa,* ) 'USSP:', ussp(1:nsea,nk+1:nk+usspf(2))
3516 #endif
3517  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 13 ) THEN
3518  WRITE ( ndsog ) tauocx(1:nsea)
3519 #ifdef W3_ASCII
3520  WRITE ( ndsoa,* ) 'TAUOCX:', tauocx(1:nsea)
3521 #endif
3522  WRITE ( ndsog ) tauocy(1:nsea)
3523 #ifdef W3_ASCII
3524  WRITE ( ndsoa,* ) 'TAUOCY:', tauocy(1:nsea)
3525 #endif
3526  !
3527  ! Section 7)
3528  !
3529  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 1 ) THEN
3530  DO isea=1, nsea
3531  IF ( aba(isea) .NE. undef ) THEN
3532  aux1(isea) = aba(isea)*cos(abd(isea))
3533  aux2(isea) = aba(isea)*sin(abd(isea))
3534  ELSE
3535  aux1(isea) = undef
3536  aux2(isea) = undef
3537  END IF
3538  END DO
3539  WRITE ( ndsog ) aux1
3540 #ifdef W3_ASCII
3541  WRITE ( ndsoa,* ) 'AUX1 (ABA*cos(ABD)):', aux1
3542 #endif
3543  WRITE ( ndsog ) aux2
3544 #ifdef W3_ASCII
3545  WRITE ( ndsoa,* ) 'AUX2 (ABA*sin(ABD)):', aux2
3546 #endif
3547  !WRITE ( NDSOG ) ABA(1:NSEA)
3548  !WRITE ( NDSOG ) ABD(1:NSEA)
3549  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 2 ) THEN
3550  DO isea=1, nsea
3551  IF ( uba(isea) .NE. undef ) THEN
3552  aux1(isea) = uba(isea)*cos(ubd(isea))
3553  aux2(isea) = uba(isea)*sin(ubd(isea))
3554  ELSE
3555  aux1(isea) = undef
3556  aux2(isea) = undef
3557  END IF
3558  END DO
3559  WRITE ( ndsog ) aux1
3560 #ifdef W3_ASCII
3561  WRITE ( ndsoa,* ) 'AUX1 (UBA*cos(UBD)):', aux1
3562 #endif
3563  WRITE ( ndsog ) aux2
3564 #ifdef W3_ASCII
3565  WRITE ( ndsoa,* ) 'AUX2 (UBA*sin(UBD)):', aux2
3566 #endif
3567  ! WRITE ( NDSOG ) UBA(1:NSEA)
3568  ! WRITE ( NDSOG ) UBD(1:NSEA)
3569  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 3 ) THEN
3570  WRITE ( ndsog ) bedforms(1:nsea,1)
3571 #ifdef W3_ASCII
3572  WRITE ( ndsoa,* ) 'BEDFORMS(1):', bedforms(1:nsea,1)
3573 #endif
3574  WRITE ( ndsog ) bedforms(1:nsea,2)
3575 #ifdef W3_ASCII
3576  WRITE ( ndsoa,* ) 'BEDFORMS(2):', bedforms(1:nsea,2)
3577 #endif
3578  WRITE ( ndsog ) bedforms(1:nsea,3)
3579 #ifdef W3_ASCII
3580  WRITE ( ndsoa,* ) 'BEDFORMS(3):', bedforms(1:nsea,3)
3581 #endif
3582  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 4 ) THEN
3583  WRITE ( ndsog ) phibbl(1:nsea)
3584 #ifdef W3_ASCII
3585  WRITE ( ndsoa,* ) 'PHIBBL:', phibbl(1:nsea)
3586 #endif
3587  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 5 ) THEN
3588  WRITE ( ndsog ) taubbl(1:nsea,1)
3589 #ifdef W3_ASCII
3590  WRITE ( ndsoa,* ) 'TAUBBL(1):', taubbl(1:nsea,1)
3591 #endif
3592  WRITE ( ndsog ) taubbl(1:nsea,2)
3593 #ifdef W3_ASCII
3594  WRITE ( ndsoa,* ) 'TAUBBL(2):', taubbl(1:nsea,2)
3595 #endif
3596  !
3597  ! Section 8)
3598  !Skewness
3599  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 1 ) THEN
3600  WRITE ( ndsog ) mssx(1:nsea)
3601 #ifdef W3_ASCII
3602  WRITE ( ndsoa,* ) 'MSSX:', mssx(1:nsea)
3603 #endif
3604  WRITE ( ndsog ) mssy(1:nsea)
3605 #ifdef W3_ASCII
3606  WRITE ( ndsoa,* ) 'MSSY:', mssy(1:nsea)
3607 #endif
3608  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 2 ) THEN
3609  WRITE ( ndsog ) mscx(1:nsea)
3610 #ifdef W3_ASCII
3611  WRITE ( ndsoa,* ) 'MSCX:', mscx(1:nsea)
3612 #endif
3613  WRITE ( ndsog ) mscy(1:nsea)
3614 #ifdef W3_ASCII
3615  WRITE ( ndsoa,* ) 'MSCY:', mscy(1:nsea)
3616 #endif
3617  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 3 ) THEN
3618  WRITE ( ndsog ) mssd(1:nsea)
3619 #ifdef W3_ASCII
3620  WRITE ( ndsoa,* ) 'MSSD:', mssd(1:nsea)
3621 #endif
3622  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 4 ) THEN
3623  WRITE ( ndsog ) mscd(1:nsea)
3624 #ifdef W3_ASCII
3625  WRITE ( ndsoa,* ) 'MSCD:', mscd(1:nsea)
3626 #endif
3627  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 5 ) THEN
3628  WRITE ( ndsog ) qp(1:nsea)
3629 #ifdef W3_ASCII
3630  WRITE ( ndsoa,* ) 'QP:', qp(1:nsea)
3631 #endif
3632  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 6 ) THEN
3633  WRITE ( ndsog ) qkk(1:nsea)
3634 #ifdef W3_ASCII
3635  WRITE ( ndsoa,* ) 'QKK:', qkk(1:nsea)
3636 #endif
3637  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 7 ) THEN
3638  WRITE ( ndsog ) skew(1:nsea)
3639 #ifdef W3_ASCII
3640  WRITE ( ndsoa,* ) 'SKW:', skew(1:nsea)
3641 #endif
3642  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 8 ) THEN
3643  WRITE ( ndsog ) embia1(1:nsea)
3644 #ifdef W3_ASCII
3645  WRITE ( ndsoa,* ) 'EMB:', embia1(1:nsea)
3646 #endif
3647  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 9 ) THEN
3648  WRITE ( ndsog ) embia2(1:nsea)
3649 #ifdef W3_ASCII
3650  WRITE ( ndsoa,* ) 'EMC:', embia2(1:nsea)
3651 #endif
3652  !
3653  ! Section 9)
3654  !
3655  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 1 ) THEN
3656  WRITE ( ndsog ) dtdyn(1:nsea)
3657 #ifdef W3_ASCII
3658  WRITE ( ndsoa,* ) 'DTDYN:', dtdyn(1:nsea)
3659 #endif
3660  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 2 ) THEN
3661  WRITE ( ndsog ) fcut(1:nsea)
3662 #ifdef W3_ASCII
3663  WRITE ( ndsoa,* ) 'FCUT:', fcut(1:nsea)
3664 #endif
3665  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 3 ) THEN
3666  WRITE ( ndsog ) cflxymax(1:nsea)
3667 #ifdef W3_ASCII
3668  WRITE ( ndsoa,* ) 'CFLXYMAX:', cflxymax(1:nsea)
3669 #endif
3670  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 4 ) THEN
3671  WRITE ( ndsog ) cflthmax(1:nsea)
3672 #ifdef W3_ASCII
3673  WRITE ( ndsoa,* ) 'CFLTHMAX:', cflthmax(1:nsea)
3674 #endif
3675  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 5 ) THEN
3676  WRITE ( ndsog ) cflkmax(1:nsea)
3677 #ifdef W3_ASCII
3678  WRITE ( ndsoa,* ) 'CFLMAX:', cflkmax(1:nsea)
3679 #endif
3680  !
3681  ! Section 10)
3682  !
3683  ELSE IF ( ifi .EQ. 10 ) THEN
3684  WRITE ( ndsog ) usero(1:nsea,ifj)
3685 #ifdef W3_ASCII
3686  WRITE ( ndsoa,* ) 'USER0:', usero(1:nsea,ifj)
3687 #endif
3688  !
3689  END IF
3690  !
3691  ELSE
3692  !
3693  ! Start of reading ......
3694  !
3695  ! Section 1)
3696  !
3697  IF ( ifi .EQ. 1 .AND. ifj .EQ. 1 ) THEN
3698  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) DW(1:NSEA)
3699  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 2 ) THEN
3700  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) CX(1:NSEA)
3701  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) CY(1:NSEA)
3702  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 3 ) THEN
3703  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) UA(1:NSEA)
3704  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) UD(1:NSEA)
3705  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 4 ) THEN
3706  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) AS(1:NSEA)
3707  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 5 ) THEN
3708  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) WLV(1:NSEA)
3709  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 6 ) THEN
3710  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) ICE(1:NSEA)
3711  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 7 ) THEN
3712  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) BERG(1:NSEA)
3713  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 8 ) THEN
3714  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) TAUA(1:NSEA)
3715  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) TAUADIR(1:NSEA)
3716  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 9 ) THEN
3717  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) RHOAIR(1:NSEA)
3718 #ifdef W3_BT4
3719  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 10 ) THEN
3720  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) SED_D50(1:NSEA)
3721 #endif
3722 #ifdef W3_IS2
3723  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 11 ) THEN
3724  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) ICEH(1:NSEA)
3725  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 12 ) THEN
3726  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) ICEF(1:NSEA)
3727 #endif
3728 #ifdef W3_SETUP
3729  ELSE IF ( ifi .EQ. 1 .AND. ifj .EQ. 13 ) THEN
3730  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) ZETA_SETUP(1:NSEA)
3731 #endif
3732  !
3733  ! Section 2)
3734  !
3735  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 1 ) THEN
3736  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) HS(1:NSEA)
3737  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 2 ) THEN
3738  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) WLM(1:NSEA)
3739  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 3 ) THEN
3740  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) T02(1:NSEA)
3741  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 4 ) THEN
3742  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) T0M1(1:NSEA)
3743  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 5 ) THEN
3744  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) T01(1:NSEA)
3745  ELSE IF ( (ifi .EQ. 2 .AND. ifj .EQ. 6) .OR. &
3746  (ifi .EQ. 2 .AND. ifj .EQ. 18) ) THEN
3747  ! Note: TP output is derived from FP field.
3748  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) FP0(1:NSEA)
3749  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 7 ) THEN
3750  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) THM(1:NSEA)
3751  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 8 ) THEN
3752  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) THS(1:NSEA)
3753  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 9 ) THEN
3754  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3755  thp0(1:nsea)
3756  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 10 ) THEN
3757  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3758  hsig(1:nsea)
3759  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 11 ) THEN
3760  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3761  stmaxe(1:nsea)
3762  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 12 ) THEN
3763  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3764  stmaxd(1:nsea)
3765  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 13 ) THEN
3766  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3767  hmaxe(1:nsea)
3768  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 14 ) THEN
3769  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3770  hcmaxe(1:nsea)
3771  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 15 ) THEN
3772  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3773  hmaxd(1:nsea)
3774  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 16 ) THEN
3775  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3776  hcmaxd(1:nsea)
3777  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 17 ) THEN
3778  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) WBT(1:NSEA)
3779  ELSE IF ( ifi .EQ. 2 .AND. ifj .EQ. 19 ) THEN
3780  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3781  wnmean(1:nsea)
3782  !
3783  ! Section 3)
3784  !
3785  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 1 ) THEN
3786  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3787  ef(1:nsea,e3df(2,1):e3df(3,1))
3788  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 2 ) THEN
3789  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3790  th1m(1:nsea,e3df(2,2):e3df(3,2))
3791  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 3 ) THEN
3792  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3793  sth1m(1:nsea,e3df(2,3):e3df(3,3))
3794  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 4 ) THEN
3795  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3796  th2m(1:nsea,e3df(2,4):e3df(3,4))
3797  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 5 ) THEN
3798  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3799  sth2m(1:nsea,e3df(2,5):e3df(3,5))
3800  ELSE IF ( ifi .EQ. 3 .AND. ifj .EQ. 6) THEN
3801  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3802  wn(1:nk,1:nsea)
3803  !
3804  ! Section 4)
3805  !
3806  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 1 ) THEN
3807  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3808  phs(1:nsea,0:noswll)
3809  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 2 ) THEN
3810  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3811  ptp(1:nsea,0:noswll)
3812  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 3 ) THEN
3813  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3814  plp(1:nsea,0:noswll)
3815  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 4 ) THEN
3816  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3817  pdir(1:nsea,0:noswll)
3818  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 5 ) THEN
3819  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3820  psi(1:nsea,0:noswll)
3821  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 6 ) THEN
3822  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3823  pws(1:nsea,0:noswll)
3824  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 7 ) THEN
3825  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3826  pthp0(1:nsea,0:noswll)
3827  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 8 ) THEN
3828  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3829  pqp(1:nsea,0:noswll)
3830  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 9 ) THEN
3831  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3832  ppe(1:nsea,0:noswll)
3833  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 10 ) THEN
3834  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3835  pgw(1:nsea,0:noswll)
3836  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 11 ) THEN
3837  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3838  psw(1:nsea,0:noswll)
3839  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 12 ) THEN
3840  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3841  ptm1(1:nsea,0:noswll)
3842  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 13 ) THEN
3843  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3844  pt1(1:nsea,0:noswll)
3845  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 14 ) THEN
3846  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3847  pt2(1:nsea,0:noswll)
3848  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 15 ) THEN
3849  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3850  pep(1:nsea,0:noswll)
3851  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 16) THEN
3852  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3853  pwst(1:nsea)
3854  ELSE IF ( ifi .EQ. 4 .AND. ifj .EQ. 17) THEN
3855  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) PNR(1:NSEA)
3856  !
3857  ! Section 5)
3858  !
3859  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 1 ) THEN
3860  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3861  ust(1:nsea)
3862  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3863  ustdir(1:nsea)
3864  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 2 ) THEN
3865  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3866  charn(1:nsea)
3867  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 3 ) THEN
3868  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) CGE(1:NSEA)
3869  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 4 ) THEN
3870  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3871  phiaw(1:nsea)
3872  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 5 ) THEN
3873  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3874  tauwix(1:nsea)
3875  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3876  tauwiy(1:nsea)
3877  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 6 ) THEN
3878  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3879  tauwnx(1:nsea)
3880  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3881  tauwny(1:nsea)
3882  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 7 ) THEN
3883  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3884  whitecap(1:nsea,1)
3885  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 8 ) THEN
3886  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3887  whitecap(1:nsea,2)
3888  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 9 ) THEN
3889  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3890  whitecap(1:nsea,3)
3891  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 10 ) THEN
3892  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3893  whitecap(1:nsea,4)
3894  ELSE IF ( ifi .EQ. 5 .AND. ifj .EQ. 11 ) THEN
3895  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3896  tws(1:nsea)
3897  !
3898  ! Section 6)
3899  !
3900  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 1 ) THEN
3901  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) SXX(1:NSEA)
3902  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) SYY(1:NSEA)
3903  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) SXY(1:NSEA)
3904  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 2 ) THEN
3905  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3906  tauox(1:nsea)
3907  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3908  tauoy(1:nsea)
3909  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 3 ) THEN
3910  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3911  bhd(1:nsea)
3912  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 4 ) THEN
3913  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3914  phioc(1:nsea)
3915  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 5 ) THEN
3916  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3917  tusx(1:nsea)
3918  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3919  tusy(1:nsea)
3920  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 6 ) THEN
3921  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3922  ussx(1:nsea)
3923  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3924  ussy(1:nsea)
3925  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 7 ) THEN
3926  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3927  prms(1:nsea)
3928  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3929  tpms(1:nsea)
3930  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 8 ) THEN
3931  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3932  us3d(1:nsea,us3df(2):us3df(3))
3933  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3934  us3d(1:nsea,nk+us3df(2):nk+us3df(3))
3935  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 9 ) THEN
3936  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3937  p2sms(1:nsea,p2msf(2):p2msf(3))
3938  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 10 ) THEN
3939  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3940  tauice(1:nsea,1)
3941  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3942  tauice(1:nsea,2)
3943  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 11 ) THEN
3944  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3945  phice(1:nsea)
3946  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 12 ) THEN
3947  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3948  ussp(1:nsea,1:usspf(2))
3949  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3950  ussp(1:nsea,nk+1:nk+usspf(2))
3951  ELSE IF ( ifi .EQ. 6 .AND. ifj .EQ. 13 ) THEN
3952  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3953  tauocx(1:nsea)
3954  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3955  tauocy(1:nsea)
3956 
3957  !
3958  ! Section 7)
3959  !
3960  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 1 ) THEN
3961  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) ABA(1:NSEA)
3962  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) ABD(1:NSEA)
3963  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 2 ) THEN
3964  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) UBA(1:NSEA)
3965  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) UBD(1:NSEA)
3966  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 3 ) THEN
3967  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3968  bedforms(1:nsea,1)
3969  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3970  bedforms(1:nsea,2)
3971  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3972  bedforms(1:nsea,3)
3973  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 4 ) THEN
3974  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3975  phibbl(1:nsea)
3976  ELSE IF ( ifi .EQ. 7 .AND. ifj .EQ. 5 ) THEN
3977  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3978  taubbl(1:nsea,1)
3979  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3980  taubbl(1:nsea,2)
3981  !
3982  ! Section 8)
3983  !
3984  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 1 ) THEN
3985  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3986  mssx(1:nsea)
3987  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3988  mssy(1:nsea)
3989  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 2 ) THEN
3990  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3991  mscx(1:nsea)
3992  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3993  mscy(1:nsea)
3994  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 3 ) THEN
3995  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3996  mssd(1:nsea)
3997  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 4 ) THEN
3998  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
3999  mscd(1:nsea)
4000  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 5 ) THEN
4001  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) QP(1:NSEA)
4002  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 6 ) THEN
4003  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) QKK(1:NSEA)
4004  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 7 ) THEN
4005  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) SKEW(1:NSEA)
4006  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 8 ) THEN
4007  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) EMBIA1(1:NSEA)
4008  ELSE IF ( ifi .EQ. 8 .AND. ifj .EQ. 9 ) THEN
4009  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) EMBIA2(1:NSEA)
4010  !
4011  ! Section 9)
4012  !
4013  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 1 ) THEN
4014  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
4015  dtdyn(1:nsea)
4016  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 2 ) THEN
4017  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
4018  fcut(1:nsea)
4019  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 3 ) THEN
4020  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
4021  cflxymax(1:nsea)
4022  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 4 ) THEN
4023  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
4024  cflthmax(1:nsea)
4025  ELSE IF ( ifi .EQ. 9 .AND. ifj .EQ. 5 ) THEN
4026  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
4027  cflkmax(1:nsea)
4028  !
4029  ! Section 10)
4030  !
4031  ELSE IF ( ifi .EQ. 10 ) THEN
4032  READ (ndsog,END=801,ERR=802,IOSTAT=IERR) &
4033  usero(1:nsea,ifj)
4034  END IF
4035  !
4036  ! End of test on WRITE/READ:
4037  !
4038  END IF
4039  !
4040  ! End of test on FLOGRD(IFI,IFJ):
4041  !
4042  END IF
4043  !
4044  ! End of IFI and IFJ loops
4045  !
4046  END DO
4047  END DO
4048  !
4049  ! Flush the buffers for write
4050  !
4051  IF ( WRITE ) CALL flush ( ndsog )
4052  !
4053  IF(ofiles(1) .EQ. 1) CLOSE(ndsog)
4054  !
4055 #ifdef W3_MPI
4056  CALL w3seta ( igrd, ndse, ndst )
4057 #endif
4058  !
4059  RETURN
4060  !
4061  ! Escape locations read errors
4062  !
4063 800 CONTINUE
4064  WRITE (ndse,1000) ierr
4065  CALL extcde ( 41 )
4066  !
4067 801 CONTINUE
4068  WRITE (ndse,1001)
4069  CALL extcde ( 42 )
4070  !
4071 802 CONTINUE
4072  WRITE (ndse,1002) ierr
4073  CALL extcde ( 43 )
4074  !
4075 803 CONTINUE
4076  iotst = -1
4077 #ifdef W3_T
4078  WRITE (ndst,9020)
4079 #endif
4080  RETURN
4081  !
4082  ! Formats
4083  !
4084 900 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO :'/ &
4085  ' ILEGAL INXOUT VALUE: ',a/)
4086 901 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO :'/ &
4087  ' MIXED READ/WRITE, LAST REQUEST: ',a/)
4088 902 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO :'/ &
4089  ' ILEGAL IDSTR, READ : ',a/ &
4090  ' CHECK : ',a/)
4091 903 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO :'/ &
4092  ' ILEGAL VEROGR, READ : ',a/ &
4093  ' CHECK : ',a/)
4094 904 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO :'/ &
4095  ' DIFFERENT NUMBER OF FIELDS, FILE :',i8,i8/ &
4096  ' PROGRAM :',i8,i8/)
4097 905 FORMAT (/' *** WAVEWATCH III WARNING IN W3IOGO :'/ &
4098  ' ILEGAL GNAME, READ : ',a/ &
4099  ' CHECK : ',a/)
4100 906 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO :'/ &
4101  ' ILEGAL NOSWLL, READ : ',i4/ &
4102  ' CHECK : ',i4/)
4103  !
4104  ! 999 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO :'/ &
4105  ! ' PLEASE UPDATE FIELDS !!! '/)
4106  !
4107 1000 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO : '/ &
4108  ' ERROR IN OPENING FILE'/ &
4109  ' IOSTAT =',i5/)
4110 1001 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO : '/ &
4111  ' PREMATURE END OF FILE'/)
4112 1002 FORMAT (/' *** WAVEWATCH III ERROR IN W3IOGO : '/ &
4113  ' ERROR IN READING FROM FILE'/ &
4114  ' IOSTAT =',i5/)
4115  !
4116 #ifdef W3_T
4117 9000 FORMAT (' TEST W3IOGO : IPASS =',i4,' INXOUT = ',a, &
4118  ' WRITE = ',l1,' UNIT =',i3/ &
4119  ' IGRD =',i3,' FEXT = ',a)
4120 9001 FORMAT (' TEST W3IOGO : OPENING NEW FILE [',a,']')
4121 9002 FORMAT (' TEST W3IOGO : TEST PARAMETERS:'/ &
4122  ' IDSTR : ',a/ &
4123  ' VEROGR : ',a/ &
4124  ' GNAME : ',a/ &
4125  ' NSEA :',i6/ &
4126  ' NX,NY : ',i9,i12/ &
4127  ' UNDEF : ',f8.2)
4128 9003 FORMAT (' TEST W3IOGO : TIME :',i9.8,i7.6/ &
4129  ' FLAGS :',20l2,1x,20l2/ &
4130  ' ',20l2,2x,20l2/ &
4131  ' ',20l2,2x,20l2/ &
4132  ' ',20l2,2x,20l2/ &
4133  ' ',20l2,2x,20l2)
4134 9010 FORMAT (' TEST W3IOGO : PROC = ',l1,' FOR ',a)
4135 9020 FORMAT (' TEST W3IOGO : END OF FILE REACHED')
4136 #endif
4137  !/
4138  !/ End of W3IOGO ----------------------------------------------------- /
4139  !/
4140  END SUBROUTINE w3iogo
4141  !/
4142  !/ ------------------------------------------------------------------- /
4155  SUBROUTINE calc_u3stokes ( A , USS_SWITCH )
4156  !/
4157  !/ +-----------------------------------+
4158  !/ | WAVEWATCH III NOAA/NCEP |
4159  !/ | H. L. Tolman |
4160  !/ | FORTRAN 90 |
4161  !/ | Last update : 10-Jan-2017 |
4162  !/ +-----------------------------------+
4163  !/
4164  !/ 10-Jan-2017 : Separate Stokes drift calculation ( version 6.01 )
4165  !/
4166  ! 1. Purpose :
4167  !
4168  ! This code is built for the purpose of outputting Stokes drift
4169  ! related parameters that can be utilized to obtain full
4170  ! Stokes drift profiles external to the wave model.
4171  !
4172  ! Option 1: USS_SWITCH == 1
4173  ! This method is for outputing the Stokes drift frequency
4174  ! spectrum for spectral frequency bands as defined by the
4175  ! WW3 computation spectral frequency grid.
4176  ! Output Quantity: Stokes drift frequency spectrum [m/s/Hz]
4177  ! X and Y componenets.
4178  !
4179  ! Option 2: USS_SWITCH == 2
4180  ! This method is for outputing the surface Stokes drift
4181  ! for a specified frequency partition/band of the
4182  ! wave spectrum. These partitions do not need to be
4183  ! matched to WW3's computation spectral frequency grid,
4184  ! and will rather sum the contributions of the WW3 bands
4185  ! into the output partition. The partitions are defined
4186  ! in the ww3_grid.inp namelist section.
4187  ! Output Quantity: Stokes drift surface velocity [m/s]
4188  ! X and Y components
4189  ! For each partition (up to 25).
4190  !
4191  ! 3. Parameters :
4192  !
4193  ! Parameter list
4194  ! ----------------------------------------------------------------
4195  ! A R.A. I Input spectra. Left in par list to change
4196  ! shape.
4197  ! USS_SWITCH I I Switch if computing US3D (spectral) or USSP
4198  ! (partitions)
4199  ! ----------------------------------------------------------------
4200  !
4201  !
4202  ! 4. Subroutines used :
4203  !
4204  ! See module documentation.
4205  !
4206  ! 5. Called by :
4207  !
4208  ! Name Type Module Description
4209  ! ----------------------------------------------------------------
4210  ! W3WAVE Subr. W3WAVEMD Actual wave model routine.
4211  ! ----------------------------------------------------------------
4212  !
4213  ! 6. Error messages :
4214  !
4215  ! None.
4216  !
4217  ! 8. Structure :
4218  !
4219  ! See source code.
4220  !
4221  ! 9. Switches :
4222  !
4223  ! !/SHRD Switch for shared / distributed memory architecture.
4224  ! !/DIST Id.
4225  !
4226  ! !/OMPG OpenMP compiler directive for loop splitting.
4227  !
4228  ! !/S Enable subroutine tracing.
4229  ! !/T Test output.
4230  !
4231  ! 10. Source code :
4232  !
4233  !/ ------------------------------------------------------------------- /
4234  USE constants, ONLY: tpiinv, grav, tpi
4235  USE w3gdatmd, ONLY: dden, dsii, xfr, sig, nk, nth, nseal, &
4237  USE w3adatmd, ONLY: cg, wn, dw
4238  USE w3adatmd, ONLY: ussx, ussy, us3d, ussp
4239  USE w3odatmd, ONLY: iaproc, naproc
4240  USE w3parall, ONLY: init_get_isea
4241 #ifdef W3_S
4242  USE w3servmd, ONLY: strace
4243 #endif
4244  !
4245  IMPLICIT NONE
4246  !/
4247  !/ ------------------------------------------------------------------- /
4248  !/ Parameter list
4249  !/
4250  REAL, INTENT(IN) :: A(NTH,NK,0:NSEAL)
4251  INTEGER, INTENT(IN) :: USS_SWITCH
4252  !/
4253  !/ ------------------------------------------------------------------- /
4254  !/ Local parameters
4255  !/
4256  INTEGER :: IK, ITH, ISEA, JSEA
4257  INTEGER :: IKST, IKFI, IB
4258 #ifdef W3_S
4259  INTEGER, SAVE :: IENT = 0
4260 #endif
4261  REAL :: FACTOR, FKD,KD
4262  REAL :: ABX(NSEAL), ABY(NSEAL), USSCO
4263  REAL :: MINDIFF
4264  INTEGER :: Spc2Bnd(NK)
4265  !/
4266  !/ ------------------------------------------------------------------- /
4267  !/
4268 #ifdef W3_S
4269  CALL strace (ient, 'CALC_U3STOKES')
4270 #endif
4271  !
4272  ! 1. Initialize storage arrays -------------------------------------- *
4273  !
4274  ! 2. Integral over discrete part of spectrum ------------------------ *
4275  !
4276  !Two options ----------------------------------------------------|
4277  ! USS_SWITCH == 1 -> Old option, Stokes drift integrated in same |
4278  ! wavenumber bands as model integrates. |
4279  ! USS_SWITCH == 2 -> New option, Stokes drift integrated in a |
4280  ! defined number (NP) of user specified |
4281  ! partitions, where NP and the frequency |
4282  ! ranges for each partition can be user |
4283  ! defined at run-time. |
4284  !----------------------------------------------------------------|
4285 
4286  if (uss_switch==1) then
4287  ikst=us3df(2)!Start at US3DF(2)
4288  ikfi=us3df(3)!End at US3DF(3)
4289  ELSEif (uss_switch==2) then
4290  ikst=1 ! Start at 1
4291  ikfi=nk ! End at NK
4292  ENDIF
4293 
4294  ! Initialize US3D/USSP
4295  IF (uss_switch.eq.1) then
4296  us3d(:,:)=0.0
4297  ELSEIF (uss_switch.eq.2) then
4298  ussp(:,:)=0.0
4299  ENDIF
4300  DO ik=ikst,ikfi !1, NK
4301  !
4302  ! 2.a Initialize energy in band
4303  !
4304  abx = 0.
4305  aby = 0.
4306  !
4307  ! 2.b Integrate energy in band
4308  !
4309  DO ith=1, nth
4310  !
4311 #ifdef W3_OMPG
4312  !$OMP PARALLEL DO PRIVATE(JSEA)
4313 #endif
4314  !
4315  DO jsea=1, nseal
4316  abx(jsea) = abx(jsea) + a(ith,ik,jsea)*ecos(ith)
4317  aby(jsea) = aby(jsea) + a(ith,ik,jsea)*esin(ith)
4318  END DO
4319  !
4320 #ifdef W3_OMPG
4321  !$OMP END PARALLEL DO
4322 #endif
4323  !
4324  END DO
4325  !
4326  ! 2.c Finalize integration over band and update mean arrays
4327  !
4328  !
4329 #ifdef W3_OMPG
4330  !$OMP PARALLEL DO PRIVATE(JSEA,ISEA,FACTOR,KD,FKD,USSCO,MINDIFF,IB)
4331 #endif
4332  !
4333  DO jsea=1, nseal
4334  CALL init_get_isea(isea, jsea)
4335  factor = dden(ik) / cg(ik,isea)
4336  !
4337  ! Deep water limits
4338  !
4339  kd = max( 0.001 , wn(ik,isea) * dw(isea) )
4340  IF ( kd .LT. 6. ) THEN
4341  fkd = factor / sinh(kd)**2
4342  ussco=fkd*sig(ik)*wn(ik,isea)*cosh(2.*kd)
4343  ELSE
4344  ussco=factor*sig(ik)*2.*wn(ik,isea)
4345  END IF
4346  !
4347  !
4348  !USSX(JSEA) = USSX(JSEA) + ABX(JSEA)*USSCO
4349  !USSY(JSEA) = USSY(JSEA) + ABY(JSEA)*USSCO
4350  !
4351  ! Fills the 3D Stokes drift spectrum array or surface Stokes partitions
4352  !
4353  IF (uss_switch==1) THEN
4354  !Old method fills into WW3 bands
4355  IF (ik.GE.us3df(2).and.ik.LE.us3df(3)) then
4356  us3d(jsea,ik) = abx(jsea)*ussco/(dsii(ik)*tpiinv)
4357  us3d(jsea,nk+ik) = aby(jsea)*ussco/(dsii(ik)*tpiinv)
4358  ENDIF
4359  ELSEIF (uss_switch==2) THEN
4360  ! Match each spectral component to the nearest partition
4361  mindiff=1.e8
4362  spc2bnd(ik) = 1
4363  mindiff=abs(ussp_wn(1)-wn(ik,isea))
4364  DO ib=2,usspf(2)
4365  IF (mindiff .gt. abs(ussp_wn(ib)-wn(ik,isea))) then
4366  spc2bnd(ik) = ib
4367  mindiff = abs(ussp_wn(ib)-wn(ik,isea))
4368  ENDIF
4369  ENDDO
4370  !Put spectral energey into whichever band central wavenumber fits in
4371  ussp(jsea,spc2bnd(ik)) = ussp(jsea,spc2bnd(ik)) + abx(jsea)*ussco
4372  ussp(jsea,nk+spc2bnd(ik)) = ussp(jsea,nk+spc2bnd(ik)) + aby(jsea)*ussco
4373  ENDIF
4374  END DO
4375 #ifdef W3_OMPG
4376  !$OMP END PARALLEL DO
4377 #endif
4378  END DO
4379  !
4380  RETURN
4381  !
4382  !/ End of CALC_U3STOKES
4383  !----------------------------------------------------- /
4384  !/
4385  END SUBROUTINE calc_u3stokes
4386  !/
4387  !/ ------------------------------------------------------------------- /
4411  SUBROUTINE calc_wbt (A)
4412  !/
4413  !/ +-----------------------------------+
4414  !/ | WAVEWATCH III NOAA/NCEP |
4415  !/ | Q. Liu |
4416  !/ | FORTRAN 90 |
4417  !/ | Last update : 24-Aug-2018 |
4418  !/ +-----------------------------------+
4419  !/
4420  !/ 24-Aug-2018 : Origination. ( version 6.06 )
4421  !/
4422  ! 1. Purpose :
4423  !
4424  ! Estimate the dominant wave breaking probability b_T based on
4425  ! the empirical parameterization proposed by Babanin et al. (2001).
4426  ! From their Fig. 12, we have
4427  !
4428  ! b_T = 85.1 * [(εp - 0.055) * (1 + H_s/d)]^2.33,
4429  !
4430  ! where ε is the significant steepness of the spectral peak, H_s is
4431  ! the significant wave height, d is the water depth.
4432  !
4433  ! For more details, please see
4434  ! Banner et al. 2000: JPO, 30, 3145 - 3160.
4435  ! Babanin et al. 2001: JGR, 106(C6), 11569 - 11676.
4436  !
4437  ! 2. Method :
4438  !
4439  ! 3. Parameters :
4440  !
4441  ! Parameter list
4442  ! ----------------------------------------------------------------
4443  ! A R.A. I Input wave action spectra N(j, θ, k)
4444  ! ----------------------------------------------------------------
4445  !
4446  ! 4. Subroutines used :
4447  !
4448  ! 5. Called by :
4449  !
4450  ! Name Type Module Description
4451  ! ----------------------------------------------------------------
4452  ! W3OUTG Subr. Public Calculate mean parameters.
4453  ! ----------------------------------------------------------------
4454  !
4455  ! 6. Error messages :
4456  !
4457  ! None.
4458  !
4459  ! 8. Structure :
4460  !
4461  ! See source code.
4462  !
4463  ! 9. Switches :
4464  !
4465  ! !/S Enable subroutine tracing.
4466  ! !/T Test output.
4467  !
4468  ! 10. Source code :
4469  !
4470  !/ ------------------------------------------------------------------- /
4471  USE w3dispmd, ONLY: wavnu1
4472  USE w3adatmd, ONLY: u10, u10d, wbt
4473  USE w3adatmd, ONLY: cg, wn, dw
4474  USE w3gdatmd, ONLY: nk, nth, nseal, sig, esin, ecos, dth, dsii, &
4475  fte, xfr, mapsf, mapsta, dmin
4476  USE w3gdatmd, ONLY: btbeta
4477  USE w3parall, ONLY: init_get_isea
4478 #ifdef W3_S
4479  USE w3servmd, ONLY: strace
4480 #endif
4481  !
4482  IMPLICIT NONE
4483  !
4484  !/ ------------------------------------------------------------------- /
4485  !/ Parameter list
4486  !/
4487  REAL, INTENT(IN) :: A (NTH, NK, 0:NSEAL)
4488  !/
4489  !/ ------------------------------------------------------------------- /
4490  !/ Local parameters
4491  !/
4492 #ifdef W3_S
4493  INTEGER, SAVE :: IENT = 0
4494 #endif
4495  !
4496  INTEGER :: FPOPT = 0
4497  !
4498  INTEGER :: IK, ITH, ISEA, JSEA, IKM, IKL, IKH, IX, IY
4499  REAL :: TDPT, TU10, TUDIR, SINU, COSU, TC, TFORCE
4500  REAL :: ESIG(NK) ! E(σ)
4501  REAL :: FACTOR, ET, HS, ETP, HSP, SIGP, KP, &
4502  CGP, WSTP
4503  REAL :: XL, XH, XL2, XH2, EL, EH, DENOM
4504  REAL :: TWBT
4505  !/
4506  !/ ------------------------------------------------------------------- /
4507  !/
4508 #ifdef W3_S
4509  CALL strace (ient, 'CALC_WBT')
4510 #endif
4511  !
4512  DO jsea = 1, nseal
4513  ! JSEA 2 ISEA
4514  CALL init_get_isea(isea, jsea)
4515  !
4516  ! check the status of this grid point [escape if this point is excluded]
4517  !
4518  ix = mapsf(isea,1)
4519  iy = mapsf(isea,2)
4520  IF ( mapsta(iy,ix) .LE. 0 ) cycle
4521  !
4522  ! Wind info. is required to select wind sea partition from the wave
4523  ! spectrum. Two wind velocities are availabe:
4524  ! - U10 & U10D (w3adatmd)
4525  ! - UST & USTDIR (w3wdatmd)
4526  ! * U10D & USTDIR are not really the same when swell are present.
4527  !
4528  ! Following Janssen et al. (1989) and Bidlot (2001), spectral components
4529  ! are considered to be subject to local wind forcing when
4530  !
4531  ! c / [U cos(θ - φ)] < β,
4532  !
4533  ! where c is the phase velocity c = σ/k, φ is the wind direction, U is
4534  ! the wind speed U10, (sometimes approximated by U10≅ 28 * ust), β is
4535  ! the constant forcing parameter with β∈ [1.0, 2.0]. By default, we use
4536  ! β = 1.2(Bidlot 2001).
4537  !
4538  tdpt = max(dw(isea), dmin) ! water depth d
4539  tu10 = u10(isea) ! wind velocity U10
4540  tudir = u10d(isea) ! wind direction φ (rad)
4541  sinu = sin(tudir) ! sinφ
4542  cosu = cos(tudir) ! cosφ
4543  !
4544  esig = 0. ! E(σ)
4545  et = 0. ! ΣE(σ)δσ
4546  etp = 0. ! ΣE(σ)δσ at peak only
4547  !
4548  DO ik = 1, nk
4549  tc = sig(ik) / wn(ik, isea) ! phase velocity c=σ/k
4550  factor = sig(ik) / cg(ik, isea) ! σ / cg
4551  factor = factor * dth ! σ / cg * δθ
4552  !
4553  DO ith = 1, nth
4554  tforce = tc - tu10 * (cosu*ecos(ith)+sinu*esin(ith)) &
4555  * btbeta
4556 
4557  IF (tforce .LT. 0.) THEN ! wind sea component
4558  esig(ik) = esig(ik) + a(ith, ik, jsea) * factor
4559  ENDIF
4560  ENDDO ! ITH
4561  !
4562  ENDDO ! IK
4563  !
4564  ! ESIG is E(σ) of the wind sea after filtration of any background swell.
4565  ! Now we need to get Hs & σp for the wind sea spectrum.
4566  ! FTE = 0.25 * SIG(NK) * DTH * SIG(NK) [ww3_grid.ftn]
4567  !
4568  et = sum(esig * dsii)
4569  et = et + esig(nk) * fte / (dth * sig(nk)) ! FTE: add tail
4570  hs = 4. * sqrt(max(0., et)) ! Hs
4571  !
4572  ! Get σp from E(σ)
4573  !
4574  ! Here we have tried three different ways to calculate FP:
4575  !
4576  ! FPOPT = 0: fp defined by Young (1999, p. 239)
4577  ! FPOPT = 1: parabolic fit around the discrete peak frequency, as used
4578  ! by ww3_outp
4579  ! FPOPT = 2: discrete peak frequency
4580  !
4581  ! When the discrete peak frequency is used:
4582  ! * For XFR = 1.1, the **discrete** peak region [0.7σp, 1.3σp] will be
4583  ! {0.75, 0.83, 0.91, 1., 1.1, 1.21, 1.33}σp,
4584  ! * and for XFR = 1.07, the **discrete** peak region becomes
4585  ! {0.71, 0.76, 0.82, 0.87, 0.93, 1., 1.07, 1.14, 1.23, 1.31}σp.
4586  !
4587  ! Thus, a good approximation to the range [0.7σp, 1.3σp] is guranteed
4588  ! by each XFR. I however found using the discrete peak frequency yielded
4589  ! step-wise results. According to my test, the smoothest results were
4590  ! obtained with FPOPT = 0. For simplicity, the δσ values (DSII) are
4591  ! not modified.
4592  !
4593  ikm = maxloc(esig, 1) ! index for σp
4594  !
4595  IF (fpopt .EQ. 0) THEN
4596  ! FP defined in Ian's book
4597  sigp = sum(esig**4. * sig(1:nk) * dsii) / &
4598  max(1e-10, sum(esig**4. * dsii))
4599  !
4600  ELSE IF (fpopt .EQ. 1) THEN
4601  ! Parabolic fit around the discrete peak (ww3_outp.ftn)
4602  xl = 1./xfr - 1.
4603  xh = xfr - 1.
4604  xl2 = xl**2.
4605  xh2 = xh**2.
4606  ikl = max( 1 , ikm-1 )
4607  ikh = min( nk , ikm+1 )
4608  el = esig(ikl) - esig(ikm)
4609  eh = esig(ikh) - esig(ikm)
4610  denom = xl*eh - xh*el
4611  sigp = sig(ikm) * (1. + 0.5 * ( xl2*eh - xh2*el) &
4612  / sign(max(abs(denom), 1.e-15), denom)) ! σp
4613  !
4614  ELSE IF (fpopt .EQ. 2) THEN
4615  ! Discrete peak (Give stepwise results, not used by default)
4616  sigp = sig(ikm)
4617  ENDIF
4618  !
4619  ! kp from σp (linear dispersion)
4620  !
4621  ! N(k, θ) at first step is zero → σp=0 → floating divided by zero error
4622  IF (sigp < 1e-6) sigp = sig(nk) ! Hsp & b_T will be still 0.
4623  !
4624  CALL wavnu1 (sigp, tdpt, kp, cgp)
4625  !
4626  ! { /1.3σp }1/2
4627  ! peak wave height Hp = 4 { | E(σ) dσ }
4628  ! { /0.7σp }
4629  !
4630  DO ik = 1, nk
4631  IF ( (sig(ik) >= 0.7 * sigp) .AND. &
4632  (sig(ik) <= 1.3 * sigp) ) THEN
4633  etp = etp + esig(ik) * dsii(ik)
4634  ENDIF
4635  ENDDO ! IK
4636  hsp = 4. * sqrt(max(0., etp))
4637  !
4638  ! significant steepness of the peak region εp
4639  !
4640  wstp = 0.5 * kp * hsp
4641  !
4642  ! Dominant wave breaking b_T
4643  !
4644  twbt = 85.1 * (max(0.0, wstp - 0.055) * (1 + hs/tdpt))**2.33
4645  wbt(jsea) = min(1.0, twbt)
4646  !
4647  ENDDO ! JSEA
4648  !/
4649  !/ End of CALC_WBT -------------------------------------------------- /
4650  !/
4651  END SUBROUTINE calc_wbt
4652  !/ ------------------------------------------------------------------- /
4653  !/
4666  SUBROUTINE secondhh(NKHF,FAC0,FAC1,FAC2,FAC3)
4667 !----------------------------------------------------------------
4668 
4669 !**** *SECONDHH* - COMPUTATION OF SECOND ORDER HARMONICS AND
4670 ! RELEVANT TABLES FOR THE ALTIMETER CORRECTIONS.
4671 
4672 ! P.A.E.M. JANSSEN
4673 
4674 ! PURPOSE.
4675 ! ---------
4676 
4677 ! COMPUTE SECOND HARMONICS
4678 
4679 !** INTERFACE.
4680 ! ----------
4681 
4682 ! *CALL* *SECONDHH*
4683 
4684 ! METHOD.
4685 ! -------
4686 
4687 ! SEE REFERENCE.
4688 
4689 ! EXTERNALS.
4690 ! ----------
4691 
4692 ! VMIN_D
4693 ! VPLUS_D
4694 
4695 ! REFERENCES.
4696 ! -----------
4697 
4698 ! V E ZAKHAROV(1967)
4699 
4700 !-------------------------------------------------------------------
4701 
4702 !-------------------------------------------------------------------
4703 USE constants, ONLY: grav, tpi
4704 USE w3gdatmd, ONLY: nk, nth, xfr, sig, th, dth, ecos, esin
4705  IMPLICIT NONE
4706  ! REAL(KIND=4) :: VMIN_D,VPLUS_D
4707 
4708 
4709 
4710  INTEGER, INTENT(IN) :: NKHF
4711  REAL(KIND=4), dimension(nth,nth,nkhf,nkhf), INTENT(OUT) :: fac0, fac1, fac2, fac3
4712  REAL(KIND=4), parameter :: fratio = 1.1
4713 
4714 
4715  INTEGER :: M, K1, M1, K2, M2
4716 
4717  REAL(KIND=4), parameter :: del1=1.0e-8
4718  REAL(KIND=4), parameter :: zconst = 0.0281349
4719 
4720  !REAL(KIND=4) :: VMIN_D, VPLUS_D
4721  REAL(KIND=4) :: co1
4722  REAL(KIND=4) :: xk1, xk1sq, xk2, xk2sq, xk3
4723  REAL(KIND=4) :: cosdiff
4724  REAL(KIND=4) :: x12, x13, x32, om1, om2, om3, f1, f2, f3
4725  REAL(KIND=4) :: vm, vp
4726  REAL(KIND=4) :: delom1, delom2
4727  REAL(KIND=4) :: delom321, delom312
4728  REAL(KIND=4) :: c22, s22
4729 
4730  REAL(KIND=4), dimension(nth,nth,nkhf,nkhf) :: b
4731  REAL(KIND=4), dimension(:), ALLOCATABLE:: fak, sighf, dfimhf
4732 
4733 
4734 
4735 
4736 !-----------------------------------------------------------------------
4737 
4738 
4739 
4740 
4741 !* 1. INITIALISE RELEVANT QUANTITIES.
4742 
4743  ALLOCATE(fak(nkhf))
4744  ALLOCATE(sighf(nkhf))
4745  ALLOCATE(dfimhf(nkhf))
4746 
4747  sighf(1) = sig(1)
4748  DO m=2,nkhf
4749  sighf(m) = xfr*sighf(m-1)
4750  ENDDO
4751 
4752  DO m=1,nkhf
4753  fak(m) = (sighf(m))**2/grav
4754  ENDDO
4755 
4756  co1 = 0.5*(xfr-1.)*dth
4757  dfimhf(1) = co1*sighf(1)
4758  DO m=2,nkhf-1
4759  dfimhf(m)=co1*(sighf(m)+sighf(m-1))
4760  ENDDO
4761  dfimhf(nkhf)=co1*sighf(nkhf-1)
4762 
4763  DO m2=1,nkhf
4764  xk2 = fak(m2)
4765  xk2sq = fak(m2)**2
4766  DO m1=1,nkhf
4767  xk1 = fak(m1)
4768  xk1sq = fak(m1)**2
4769  DO k1=1,nth
4770  DO k2=1,nth
4771  cosdiff = cos(th(k1)-th(k2))
4772  x12 = xk1*xk2*cosdiff
4773  xk3 = xk1sq + xk2sq +2.0*x12 +del1
4774  xk3 = sqrt(xk3)
4775  x13 = xk1sq+x12
4776  x32 = x12+xk2sq
4777  om1 = sqrt(grav*xk1)
4778  om2 = sqrt(grav*xk2)
4779  om3 = sqrt(grav*xk3)
4780  f1 = sqrt(xk1/(2.0*om1))
4781  f2 = sqrt(xk2/(2.0*om2))
4782  f3 = sqrt(xk3/(2.0*om3))
4783  vm = tpi*vmin_d(xk3,xk1,xk2,x13,x32,x12,om3,om1,om2)
4784  vp = tpi*vplus_d(-xk3,xk1,xk2,-x13,-x32,x12,om3,om1,om2)
4785  delom1 = om3-om1-om2+del1
4786  delom2 = om3+om1+om2+del1
4787  fac0(k1,k2,m1,m2) = -f3/(f1*f2)*(vm/(delom1)+ &
4788  & vp/(delom2))
4789  ENDDO
4790  ENDDO
4791  ENDDO
4792  ENDDO
4793 
4794  DO m2=1,nkhf
4795  xk2 = fak(m2)
4796  xk2sq = fak(m2)**2
4797  DO m1=1,nkhf
4798  xk1 = fak(m1)
4799  xk1sq = fak(m1)**2
4800  DO k1=1,nth
4801  DO k2=1,nth
4802  cosdiff = cos(th(k1)-th(k2))
4803  x12 = xk1*xk2*cosdiff
4804  xk3 = xk1sq + xk2sq - 2.*x12 + del1
4805  xk3 = sqrt(xk3)
4806  x13 = xk1sq-x12
4807  x32 = x12-xk2sq
4808  om1 = sqrt(grav*xk1)
4809  om2 = sqrt(grav*xk2)
4810  om3 = sqrt(grav*xk3)+del1
4811  f1 = sqrt(xk1/(2.0*om1))
4812  f2 = sqrt(xk2/(2.0*om2))
4813  f3 = sqrt(abs(xk3)/(2.0*om3))
4814  vm = tpi*vmin_d(xk1,xk3,xk2,x13,x12,x32,om1,om3,om2)
4815  vp = tpi*vmin_d(xk2,-xk3,xk1,-x32,x12,-x13,om2,om3,om1)
4816  delom321 = om3+om2-om1+del1
4817  delom312 = om3+om1-om2+del1
4818  b(k1,k2,m1,m2) = -f3/(f1*f2)*(vm/(delom321)+ &
4819  & vp/(delom312))
4820  ENDDO
4821  ENDDO
4822  ENDDO
4823  ENDDO
4824 
4825  DO m2=1,nkhf
4826  xk2sq = fak(m2)**2
4827  DO m1=1,nkhf
4828  xk1sq = fak(m1)**2
4829  DO k2=1,nth
4830  DO k1=1,nth
4831  c22 = fac0(k1,k2,m1,m2)+b(k1,k2,m1,m2)
4832  s22 = b(k1,k2,m1,m2)-fac0(k1,k2,m1,m2)
4833  fac1(k1,k2,m1,m2) = &
4834  & (xk1sq*ecos(k1)**2 + xk2sq*ecos(k2)**2)*c22 &
4835  & -fak(m1)*fak(m2)*ecos(k1)*ecos(k2)*s22
4836  fac2(k1,k2,m1,m2) = &
4837  & (xk1sq*esin(k1)**2 + xk2sq*esin(k2)**2)*c22 &
4838  & -fak(m1)*fak(m2)*esin(k1)*esin(k2)*s22
4839  fac3(k1,k2,m1,m2) = &
4840  & (xk1sq*esin(k1)*ecos(k1) + &
4841  & xk2sq*esin(k2)*ecos(k2))*c22 &
4842  & -fak(m1)*fak(m2)*ecos(k1)*esin(k2)*s22
4843  fac0(k1,k2,m1,m2) = c22
4844  ENDDO
4845  ENDDO
4846  ENDDO
4847  ENDDO
4848 
4849 
4850  CONTAINS
4851 
4852 !-----------------------------------------------------------------------
4853 
4854  REAL(KIND=4) function vmin_d(xi,xj,xk,xij,xik,xjk,xoi,xoj,xok)
4856 ! PETER JANSSEN
4857 
4858 ! PURPOSE.
4859 ! --------
4860 
4861 ! GIVES NONLINEAR TRANSFER COEFFICIENT FOR THREE
4862 ! WAVE INTERACTIONS OF DEEP-WATER WAVES IN THE
4863 ! IDEAL CASE OF NO CURRENT. (CF.ZAKHAROV)
4864 
4865 ! INTERFACE.
4866 ! ----------
4867 ! *VMIN_D(XI,XJ,XK)*
4868 ! *XI* - WAVE NUMBER
4869 ! *XJ* - WAVE NUMBER
4870 ! *XK* - WAVE NUMBER
4871 ! METHOD.
4872 ! -------
4873 ! NONE
4874 
4875 ! EXTERNALS.
4876 ! ----------
4877 ! NONE.
4878 
4879 
4880 !*** 1. DETERMINE NONLINEAR TRANSFER.
4881 ! --------------------------------
4882  IMPLICIT NONE
4883  REAL, INTENT(IN) :: xi, xj, xk, xij, xik, xjk, xoi, xoj, xok
4884  REAL :: ri, rj, rk, oi, oj, ok, sqijk, sqikj, sqjki
4885 
4886  ri=abs(xi)+del1
4887  rj=abs(xj)+del1
4888  rk=abs(xk)+del1
4889  oi=xoi+del1
4890  oj=xoj+del1
4891  ok=xok+del1
4892  sqijk=sqrt(oi*oj*rk/(ok*ri*rj))
4893  sqikj=sqrt(oi*ok*rj/(oj*ri*rk))
4894  sqjki=sqrt(oj*ok*ri/(oi*rj*rk))
4895  vmin_d=zconst*( (xij-ri*rj)*sqijk + (xik-ri*rk)*sqikj &
4896  & + (xjk+rj*rk)*sqjki )
4897 
4898  END FUNCTION vmin_d
4899 
4900 !-----------------------------------------------------------------------
4901 
4902  REAL(kind=4) function vplus_d(xi,xj,xk,xij,xik,xjk,xoi,xoj,xok)
4904 !*** *VPLUS_D* DETERMINES THE NONLINEAR TRANSFER COEFFICIENT FOR THREE
4905 ! WAVE INTERACTIONS OF DEEP-WATER WAVES.
4906 
4907 ! PETER JANSSEN
4908 
4909 ! PURPOSE.
4910 ! --------
4911 
4912 ! GIVES NONLINEAR TRANSFER COEFFICIENT FOR THREE
4913 ! WAVE INTERACTIONS OF GRAVITY-CAPILLARY WAVES IN THE
4914 ! IDEAL CASE OF NO CURRENT. (CF.ZAKHAROV)
4915 
4916 ! INTERFACE.
4917 ! ----------
4918 ! *VPLUS_D(XI,XJ,XK)*
4919 ! *XI* - WAVE NUMBER
4920 ! *XJ* - WAVE NUMBER
4921 ! *XK* - WAVE NUMBER
4922 ! METHOD.
4923 ! -------
4924 ! NONE
4925 
4926 ! EXTERNALS.
4927 ! ----------
4928 ! NONE.
4929 
4930 
4931 
4932 !*** 1. DETERMINE NONLINEAR TRANSFER.
4933 ! --------------------------------
4934 
4935  IMPLICIT NONE
4936  REAL, INTENT(IN) :: xi, xj, xk, xij, xik, xjk, xoi, xoj, xok
4937  REAL :: ri, rj, rk, oi, oj, ok, sqijk, sqikj, sqjki
4938 
4939  ri=abs(xi)+del1
4940  rj=abs(xj)+del1
4941  rk=abs(xk)+del1
4942  oi=xoi+del1
4943  oj=xoj+del1
4944  ok=xok+del1
4945  sqijk=sqrt(oi*oj*rk/(ok*ri*rj))
4946  sqikj=sqrt(oi*ok*rj/(oj*ri*rk))
4947  sqjki=sqrt(oj*ok*ri/(oi*rj*rk))
4948  vplus_d=zconst*( (xij+ri*rj)*sqijk + (xik+ri*rk)*sqikj &
4949  & + (xjk+rj*rk)*sqjki )
4950 
4951  END FUNCTION vplus_d
4952 ! -----------------------------------------------------------------
4953 
4954  END SUBROUTINE secondhh
4955  !/ ------------------------------------------------------------------- /
4956  !/
4974  SUBROUTINE skewness(A)
4976 !--------------------------------------------------------------------
4977 
4978 !*****SKEWNESS** COMPUTES PARAMETERS OF THE NEARLY-GAUSSIAN
4979 ! DISTRIBUTION OF OCEAN WAVES AT A FIXED GRID POINT.
4980 
4981 ! P.JANSSEN JULY 1997
4982 
4983 ! PURPOSE
4984 ! -------
4985 ! DETERMINES SKEWNESS PARAMETERS IN ORDER TO OBTAIN
4986 ! CORRECTION ON ALTIMETER WAVE HEIGHT.
4987 
4988 ! INTERFACE
4989 ! ---------
4990 ! *CALL* *SKEWNESS(IU06,F1,NCOLL,XKAPPA1,DELH_ALT)*
4991 
4992 
4993 
4994 ! METHOD
4995 ! ------
4996 ! EVALUATE DEVIATIONS FROM GAUSSIANITY FOLLOWING THE WORK
4997 ! OF SROKOSZ AND LONGUET-HIGGINS. FOR SECOND ORDER
4998 ! CORRECTIONS TO SURFACE ELEVATION THE APPROACH OF
4999 ! ZAKHAROV HAS BEEN USED.
5000 
5001 ! EXTERNALS
5002 ! ---------
5003 ! NONE
5004 
5005 ! REFERENCES
5006 ! ----------
5007 ! M.A. SROKOSZ, J.G.R.,91,995-1006(1986)
5008 ! V.E. ZAKHAROV, HAMILTONIAN APPROACH(1967)
5009 !--------------------------------------------------------------------
5010 
5011 
5012 
5013 !--------------------------------------------------------------------
5014 ! *TH* REAL DIRECTIONS IN RADIANS.
5015 USE constants, ONLY: grav, tpi, tpiinv
5016 USE w3gdatmd, ONLY: nk, nth, xfr, sig, dth, ecos, esin, nseal
5017 USE w3parall, ONLY: init_get_isea
5018 USE w3adatmd, ONLY: cg, skew, embia1, embia2
5019 
5020 
5021  IMPLICIT NONE
5022 
5023  REAL, INTENT(IN) :: A(NTH,NK,0:NSEAL)
5024 
5025  INTEGER :: NKHF
5026  REAL(KIND=4), dimension(:,:,:,:) , ALLOCATABLE:: fac0,fac1,fac2,fac3
5027 
5028  INTEGER :: M, K, M1, K1, M2, K2, I, J
5029  INTEGER :: MSTART, JSEA
5030 
5031  REAL(KIND=4) :: conx, delta
5032  REAL(KIND=4) :: fh, delf, xk1
5033  REAL(KIND=4) :: xpi, xpj, xpk, xn, xfac, co1
5034  REAL(KIND=4), dimension(:,:), ALLOCATABLE :: f2
5035  REAL(KIND=4), dimension(0:3,0:2,0:2) :: xmu, xlambda
5036  REAL(KIND=4), dimension(:) , ALLOCATABLE:: sighf, dfimhf, fak
5037 
5038 ! ----------------------------------------------------------------------
5039 
5040  nkhf=nk+13 ! same offset as in ECWAM
5041 
5042  ALLOCATE(fac0(nth,nth,nkhf,nkhf))
5043  ALLOCATE(fac1(nth,nth,nkhf,nkhf))
5044  ALLOCATE(fac2(nth,nth,nkhf,nkhf))
5045  ALLOCATE(fac3(nth,nth,nkhf,nkhf))
5046 
5047  CALL secondhh(nkhf,fac0,fac1,fac2,fac3)
5048 
5049  ALLOCATE(f2(nth,nkhf))
5050  ALLOCATE(sighf(nkhf), dfimhf(nkhf), fak(nkhf))
5051 
5052 ! 1. COMPUTATION OF FREQUENCY-DIRECTION INCREMENT
5053 ! -----------------------------------------------
5054 
5055  mstart = 1
5056 
5057 
5058 #ifdef W3_OMPG
5059  !$OMP PARALLEL DO PRIVATE(JSEA)
5060 #endif
5061  DO jsea=1, nseal
5062  xmu(:,:,:) = 0.0
5063  DO k=1,nth
5064  DO m=1,nk
5065  conx = tpiinv / sig(m) * cg(m,jsea)
5066  f2(k,m)=a(k,m,jsea)/ conx
5067  END DO
5068  END DO
5069 
5070  sighf(1) = sig(1)
5071  DO m=2,nkhf
5072  sighf(m) = xfr*sighf(m-1)
5073  ENDDO
5074 
5075  co1 = 0.5*(xfr-1.)*dth*tpiinv
5076  dfimhf(1) = co1*sighf(1) ! this is DF*DTH
5077  DO m=2,nkhf-1
5078  dfimhf(m)=co1*(sighf(m)+sighf(m-1))
5079  ENDDO
5080  dfimhf(nkhf)=co1*sighf(nkhf-1)
5081 
5082  DO m=1,nkhf
5083  fak(m) = (sighf(m))**2/grav
5084  ENDDO
5085 
5086 ! Deals with the tail ...
5087  DO m=nk+1,nkhf
5088  fh=(sighf(nk)/sighf(m))**5
5089  DO k=1,nth
5090  f2(k,m)=f2(k,nk)*fh
5091  ENDDO
5092  ENDDO
5093 
5094 ! 2. COMPUTATION OF THE SKEWNESS COEFFICIENTS
5095 ! --------------------------------------------
5096 
5097  DO m1=mstart,nkhf
5098  DO m2=mstart,nkhf
5099  DO k1=1,nth
5100  DO k2=1,nth
5101  delf = dfimhf(m1)*dfimhf(m2)*f2( k1,m1)*f2(k2,m2)
5102  xmu(3,0,0) = xmu(3,0,0)+3.0*fac0(k1,k2,m1,m2)*delf
5103  xmu(1,2,0) = xmu(1,2,0)+fac1(k1,k2,m1,m2)*delf
5104  xmu(1,0,2) = xmu(1,0,2)+fac2(k1,k2,m1,m2)*delf
5105  xmu(1,1,1) = xmu(1,1,1)+fac3(k1,k2,m1,m2)*delf
5106  ENDDO
5107  ENDDO
5108  ENDDO
5109  ENDDO
5110 
5111  DO k1=1,nth
5112  DO m1=mstart,nkhf
5113  xk1 = fak(m1)**2
5114  delf = dfimhf(m1)*f2(k1,m1)
5115  xmu(2,0,0) = xmu(2,0,0) + delf
5116  xmu(0,2,0) = xmu(0,2,0) + xk1*ecos(k1)**2*delf
5117  xmu(0,0,2) = xmu(0,0,2) + xk1*esin(k1)**2*delf
5118  xmu(0,1,1) = xmu(0,1,1) + xk1*ecos(k1)*esin(k1)*delf
5119  ENDDO
5120  ENDDO
5121 
5122 
5123 ! 3. COMPUTATION OF THE NORMALISED SKEWNESS COEFFICIENTS
5124 ! ------------------------------------------------------
5125 
5126  DO i=0,3
5127  xpi = 0.5*float(i)
5128  DO j=0,2
5129  xpj = 0.5*float(j)
5130  DO k=0,2
5131  xpk = 0.5*float(k)
5132  xn = xmu(2,0,0)**xpi*xmu(0,2,0)**xpj*xmu(0,0,2)**xpk ! denom in Srokosz eq. 11
5133  IF (xn .NE. 0) THEN
5134  xlambda(i,j,k) = xmu(i,j,k)/xn
5135  ELSE
5136  xlambda(i,j,k) = 0
5137  END IF
5138  END DO
5139  END DO
5140  END DO
5141  IF ( xmu(2,0,0) .GT. 1.e-7 ) THEN
5142  skew(jsea)=xlambda(3,0,0)
5143  delta = ( xlambda(1,2,0) + xlambda(1,0,2) &
5144  - 2.0*xlambda(0,1,1)*xlambda(1,1,1) )/ &
5145  (1.0 - xlambda(0,1,1)**2) ! this is called gamma eq. 20
5146  embia1(jsea)=-0.125*delta ! EM Bias coefficient
5147  embia2(jsea)=-0.125*xlambda(3,0,0)/3.0 ! tracker bias (least squares only)
5148  END IF
5149  END DO ! end of loop on JSEA
5150  !
5151 #ifdef W3_OMPG
5152  !$OMP END PARALLEL DO
5153 #endif
5154 
5155  DEALLOCATE(fac0,fac1,fac2,fac3)
5156  DEALLOCATE(f2,sighf,dfimhf,fak)
5157 
5158 
5159  END SUBROUTINE skewness
5160 
5161 END MODULE w3iogomd
w3adatmd::pt2
real, dimension(:,:), pointer pt2
Definition: w3adatmd.F90:597
w3adatmd::psw
real, dimension(:,:), pointer psw
Definition: w3adatmd.F90:597
w3gdatmd::nk
integer, pointer nk
Definition: w3gdatmd.F90:1230
w3adatmd::hcmaxe
real, dimension(:), pointer hcmaxe
Definition: w3adatmd.F90:587
w3gdatmd::esc
real, dimension(:), pointer esc
Definition: w3gdatmd.F90:1234
w3gdatmd::nseal
integer, pointer nseal
Definition: w3gdatmd.F90:1097
constants::pi
real, parameter pi
PI Value of Pi.
Definition: constants.F90:71
w3servmd::nextln
subroutine nextln(CHCKC, NDSI, NDSE)
Definition: w3servmd.F90:222
w3iogomd::skewness
subroutine skewness(A)
Determines skewness paramters in order to obtain correction on altimeter wave height.
Definition: w3iogomd.F90:4975
w3adatmd::phice
real, dimension(:), pointer phice
Definition: w3adatmd.F90:607
w3adatmd::th2m
real, dimension(:,:), pointer th2m
Definition: w3adatmd.F90:594
w3wdatmd::iceh
real, dimension(:), pointer iceh
Definition: w3wdatmd.F90:183
w3adatmd::charn
real, dimension(:), pointer charn
Definition: w3adatmd.F90:603
w3adatmd::dtdyn
real, dimension(:), pointer dtdyn
Definition: w3adatmd.F90:620
w3wdatmd::fpis
real, dimension(:), pointer fpis
Definition: w3wdatmd.F90:183
w3gdatmd::dth
real, pointer dth
Definition: w3gdatmd.F90:1232
w3adatmd::nsealm
integer, pointer nsealm
Definition: w3adatmd.F90:686
w3adatmd::as
real, dimension(:), pointer as
Definition: w3adatmd.F90:584
w3adatmd
Define data structures to set up wave model auxiliary data for several models simultaneously.
Definition: w3adatmd.F90:26
w3adatmd::hcmaxd
real, dimension(:), pointer hcmaxd
Definition: w3adatmd.F90:587
w3adatmd::sth1m
real, dimension(:,:), pointer sth1m
Definition: w3adatmd.F90:594
w3adatmd::ussy
real, dimension(:), pointer ussy
Definition: w3adatmd.F90:607
w3adatmd::pep
real, dimension(:,:), pointer pep
Definition: w3adatmd.F90:597
w3adatmd::mscd
real, dimension(:), pointer mscd
Definition: w3adatmd.F90:617
constants::dera
real, parameter dera
DERA Conversion factor from degrees to radians.
Definition: constants.F90:77
w3adatmd::abd
real, dimension(:), pointer abd
Definition: w3adatmd.F90:614
w3gdatmd::dmin
real, pointer dmin
Definition: w3gdatmd.F90:1183
w3wdatmd
Define data structures to set up wave model dynamic data for several models simultaneously.
Definition: w3wdatmd.F90:18
w3gdatmd::p2msf
integer, dimension(:), pointer p2msf
Definition: w3gdatmd.F90:1098
w3adatmd::stmaxe
real, dimension(:), pointer stmaxe
Definition: w3adatmd.F90:587
w3adatmd::tauice
real, dimension(:,:), pointer tauice
Definition: w3adatmd.F90:607
w3adatmd::t02
real, dimension(:), pointer t02
Definition: w3adatmd.F90:587
w3adatmd::us3d
real, dimension(:,:), pointer us3d
Definition: w3adatmd.F90:612
w3adatmd::cflxymax
real, dimension(:), pointer cflxymax
Definition: w3adatmd.F90:620
w3odatmd::dtprt
real, dimension(:,:), pointer dtprt
Definition: w3odatmd.F90:553
w3gdatmd::ftwl
real, pointer ftwl
Definition: w3gdatmd.F90:1232
w3adatmd::cg
real, dimension(:,:), pointer cg
Definition: w3adatmd.F90:575
w3adatmd::tws
real, dimension(:), pointer tws
Definition: w3adatmd.F90:603
w3adatmd::tusx
real, dimension(:), pointer tusx
Definition: w3adatmd.F90:607
w3adatmd::fcut
real, dimension(:), pointer fcut
Definition: w3adatmd.F90:620
w3odatmd::flogr2
logical, dimension(:,:), pointer flogr2
Definition: w3odatmd.F90:478
w3adatmd::tusy
real, dimension(:), pointer tusy
Definition: w3adatmd.F90:607
w3adatmd::ptp
real, dimension(:,:), pointer ptp
Definition: w3adatmd.F90:597
w3adatmd::dw
real, dimension(:), pointer dw
Definition: w3adatmd.F90:584
w3adatmd::u10d
real, dimension(:), pointer u10d
Definition: w3adatmd.F90:584
w3gdatmd::sig
real, dimension(:), pointer sig
Definition: w3gdatmd.F90:1234
w3wdatmd::icef
real, dimension(:), pointer icef
Definition: w3wdatmd.F90:183
w3adatmd::th1m
real, dimension(:,:), pointer th1m
Definition: w3adatmd.F90:594
w3adatmd::t01
real, dimension(:), pointer t01
Definition: w3adatmd.F90:587
w3adatmd::cge
real, dimension(:), pointer cge
Definition: w3adatmd.F90:603
w3wdatmd::wlv
real, dimension(:), pointer wlv
Definition: w3wdatmd.F90:183
w3odatmd::iaproc
integer, pointer iaproc
Definition: w3odatmd.F90:457
w3odatmd::ngrpp
integer, parameter ngrpp
Definition: w3odatmd.F90:324
w3adatmd::pdir
real, dimension(:,:), pointer pdir
Definition: w3adatmd.F90:597
w3wdatmd::time
integer, dimension(:), pointer time
Definition: w3wdatmd.F90:172
w3adatmd::thp0
real, dimension(:), pointer thp0
Definition: w3adatmd.F90:587
w3adatmd::tauocy
real, dimension(:), pointer tauocy
Definition: w3adatmd.F90:607
w3gdatmd::ecos
real, dimension(:), pointer ecos
Definition: w3gdatmd.F90:1234
constants::rade
real, parameter rade
RADE Conversion factor from radians to degrees.
Definition: constants.F90:76
w3adatmd::phs
real, dimension(:,:), pointer phs
Definition: w3adatmd.F90:597
w3adatmd::hs
real, dimension(:), pointer hs
Definition: w3adatmd.F90:587
w3gdatmd::gname
character(len=30), pointer gname
Definition: w3gdatmd.F90:1223
w3gdatmd::ny
integer, pointer ny
Definition: w3gdatmd.F90:1097
w3adatmd::uba
real, dimension(:), pointer uba
Definition: w3adatmd.F90:614
w3odatmd::fnmpre
character(len=80) fnmpre
Definition: w3odatmd.F90:330
w3servmd::strsplit
subroutine strsplit(STRING, TAB)
Definition: w3servmd.F90:1440
w3odatmd::ofiles
integer, dimension(:), pointer ofiles
Definition: w3odatmd.F90:466
w3adatmd::pqp
real, dimension(:,:), pointer pqp
Definition: w3adatmd.F90:597
vmin_d
real(kind=4) function vmin_d(XI, XJ, XK, XIJ, XIK, XJK, XOI, XOJ, XOK)
Definition: w3iogomd.F90:4855
w3adatmd::tauwix
real, dimension(:), pointer tauwix
Definition: w3adatmd.F90:603
w3adatmd::w3dima
subroutine w3dima(IMOD, NDSE, NDST, D_ONLY)
Initialize an individual data grid at the proper dimensions.
Definition: w3adatmd.F90:846
w3gdatmd::th
real, dimension(:), pointer th
Definition: w3gdatmd.F90:1234
w3adatmd::pthp0
real, dimension(:,:), pointer pthp0
Definition: w3adatmd.F90:597
w3gdatmd::ussp_wn
real, dimension(:), pointer ussp_wn
Definition: w3gdatmd.F90:1099
w3gdatmd::w3setg
subroutine w3setg(IMOD, NDSE, NDST)
Definition: w3gdatmd.F90:2152
w3iogomd::calc_wbt
subroutine calc_wbt(A)
Estimate the dominant wave breaking probability b_T.
Definition: w3iogomd.F90:4412
w3adatmd::w3xeta
subroutine w3xeta(IMOD, NDSE, NDST)
Reduced version of W3SETA to point to expended output arrays.
Definition: w3adatmd.F90:3118
w3adatmd::tauwiy
real, dimension(:), pointer tauwiy
Definition: w3adatmd.F90:603
w3adatmd::taubbl
real, dimension(:,:), pointer taubbl
Definition: w3adatmd.F90:614
w3odatmd::ndse
integer, pointer ndse
Definition: w3odatmd.F90:456
w3iogomd::secondhh
subroutine secondhh(NKHF, FAC0, FAC1, FAC2, FAC3)
Computation of second order harmonics and relevant tables for the altimeter corrections.
Definition: w3iogomd.F90:4667
w3adatmd::ainit
logical, pointer ainit
Definition: w3adatmd.F90:688
w3adatmd::ef
real, dimension(:,:), pointer ef
Definition: w3adatmd.F90:594
w3wdatmd::berg
real, dimension(:), pointer berg
Definition: w3wdatmd.F90:183
w3gdatmd::es2
real, dimension(:), pointer es2
Definition: w3gdatmd.F90:1234
w3adatmd::w3seta
subroutine w3seta(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3adatmd.F90:2645
w3adatmd::tauwny
real, dimension(:), pointer tauwny
Definition: w3adatmd.F90:603
w3gdatmd::esin
real, dimension(:), pointer esin
Definition: w3gdatmd.F90:1234
w3adatmd::phiaw
real, dimension(:), pointer phiaw
Definition: w3adatmd.F90:603
w3adatmd::pws
real, dimension(:,:), pointer pws
Definition: w3adatmd.F90:597
w3adatmd::plp
real, dimension(:,:), pointer plp
Definition: w3adatmd.F90:597
w3adatmd::phibbl
real, dimension(:), pointer phibbl
Definition: w3adatmd.F90:614
w3adatmd::cflthmax
real, dimension(:), pointer cflthmax
Definition: w3adatmd.F90:620
w3adatmd::skew
real, dimension(:), pointer skew
Definition: w3adatmd.F90:617
w3adatmd::psi
real, dimension(:,:), pointer psi
Definition: w3adatmd.F90:597
w3adatmd::sth2m
real, dimension(:,:), pointer sth2m
Definition: w3adatmd.F90:594
w3adatmd::tpms
real, dimension(:), pointer tpms
Definition: w3adatmd.F90:607
w3servmd
Definition: w3servmd.F90:3
w3adatmd::embia1
real, dimension(:), pointer embia1
Definition: w3adatmd.F90:617
w3odatmd::flogrd
logical, dimension(:,:), pointer flogrd
Definition: w3odatmd.F90:478
w3adatmd::ths
real, dimension(:), pointer ths
Definition: w3adatmd.F90:587
w3gdatmd::dsii
real, dimension(:), pointer dsii
Definition: w3gdatmd.F90:1234
w3adatmd::bedforms
real, dimension(:,:), pointer bedforms
Definition: w3adatmd.F90:614
w3adatmd::ud
real, dimension(:), pointer ud
Definition: w3adatmd.F90:584
w3adatmd::hmaxd
real, dimension(:), pointer hmaxd
Definition: w3adatmd.F90:587
w3adatmd::pwst
real, dimension(:), pointer pwst
Definition: w3adatmd.F90:597
w3wdatmd::w3setw
subroutine w3setw(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3wdatmd.F90:660
w3adatmd::qkk
real, dimension(:), pointer qkk
Definition: w3adatmd.F90:617
w3odatmd::noge
integer, dimension(nogrp) noge
Definition: w3odatmd.F90:326
constants::tpiinv
real, parameter tpiinv
TPIINV Inverse of 2*Pi.
Definition: constants.F90:74
w3odatmd::w3seto
subroutine w3seto(IMOD, NDSERR, NDSTST)
Definition: w3odatmd.F90:1523
w3adatmd::sxy
real, dimension(:), pointer sxy
Definition: w3adatmd.F90:607
w3adatmd::tauwnx
real, dimension(:), pointer tauwnx
Definition: w3adatmd.F90:603
w3gdatmd::nth
integer, pointer nth
Definition: w3gdatmd.F90:1230
w3gdatmd::fttr
real, pointer fttr
Definition: w3gdatmd.F90:1232
w3odatmd
Definition: w3odatmd.F90:3
w3adatmd::wbt
real, dimension(:), pointer wbt
Definition: w3adatmd.F90:587
w3adatmd::bhd
real, dimension(:), pointer bhd
Definition: w3adatmd.F90:607
w3adatmd::cy
real, dimension(:), pointer cy
Definition: w3adatmd.F90:584
w3adatmd::pnr
real, dimension(:), pointer pnr
Definition: w3adatmd.F90:597
w3adatmd::taua
real, dimension(:), pointer taua
Definition: w3adatmd.F90:584
w3adatmd::hmaxe
real, dimension(:), pointer hmaxe
Definition: w3adatmd.F90:587
w3odatmd::write1
logical, pointer write1
Definition: w3odatmd.F90:478
w3adatmd::pt1
real, dimension(:,:), pointer pt1
Definition: w3adatmd.F90:597
constants::dwat
real, parameter dwat
DWAT Density of water (kg/m3).
Definition: constants.F90:62
w3adatmd::wlm
real, dimension(:), pointer wlm
Definition: w3adatmd.F90:587
w3gdatmd::mapsf
integer, dimension(:,:), pointer mapsf
Definition: w3gdatmd.F90:1163
w3odatmd::naproc
integer, pointer naproc
Definition: w3odatmd.F90:457
w3gdatmd::btbeta
real, pointer btbeta
Definition: w3gdatmd.F90:1183
w3gdatmd::us3df
integer, dimension(:), pointer us3df
Definition: w3gdatmd.F90:1098
w3adatmd::wnmean
real, dimension(:), pointer wnmean
Definition: w3adatmd.F90:587
w3adatmd::cflkmax
real, dimension(:), pointer cflkmax
Definition: w3adatmd.F90:620
w3iogomd::w3iogo
subroutine w3iogo(INXOUT, NDSOG, IOTST, IMOD ifdef W3_ASCII
Read/write gridded output.
Definition: w3iogomd.F90:2396
w3adatmd::phioc
real, dimension(:), pointer phioc
Definition: w3adatmd.F90:607
file
file(STRINGS ${CMAKE_BINARY_DIR}/switch switch_strings) separate_arguments(switches UNIX_COMMAND $
Definition: CMakeLists.txt:3
w3odatmd::ipass1
integer, pointer ipass1
Definition: w3odatmd.F90:473
vplus_d
real(kind=4) function vplus_d(XI, XJ, XK, XIJ, XIK, XJK, XOI, XOJ, XOK)
Definition: w3iogomd.F90:4903
w3adatmd::wn
real, dimension(:,:), pointer wn
Definition: w3adatmd.F90:575
w3wdatmd::w3dimw
subroutine w3dimw(IMOD, NDSE, NDST, F_ONLY)
Initialize an individual data grid at the proper dimensions.
Definition: w3wdatmd.F90:343
w3adatmd::u10
real, dimension(:), pointer u10
Definition: w3adatmd.F90:584
w3iogomd::calc_u3stokes
subroutine calc_u3stokes(A, USS_SWITCH)
Output Stokes drift related parameters.
Definition: w3iogomd.F90:4156
w3gdatmd::stexu
real, pointer stexu
Definition: w3gdatmd.F90:1183
w3iogomd::w3fldtoij
subroutine w3fldtoij(FLD, I, J, IAPROC, NAPOUT, NDSEN)
Returns the group/field (I/J) indices for a named output field.
Definition: w3iogomd.F90:761
w3servmd::str_to_upper
subroutine str_to_upper(STR)
Definition: w3servmd.F90:1500
w3adatmd::qp
real, dimension(:), pointer qp
Definition: w3adatmd.F90:587
constants::tpi
real, parameter tpi
TPI 2*Pi.
Definition: constants.F90:72
w3iogomd
Gridded output of mean wave parameters.
Definition: w3iogomd.F90:15
w3adatmd::stmaxd
real, dimension(:), pointer stmaxd
Definition: w3adatmd.F90:587
w3servmd::strace
subroutine strace(IENT, SNAME)
Definition: w3servmd.F90:148
w3gdatmd::facti2
real, pointer facti2
Definition: w3gdatmd.F90:1232
w3wdatmd::zeta_setup
real, dimension(:), pointer zeta_setup
Definition: w3wdatmd.F90:187
w3wdatmd::ice
real, dimension(:), pointer ice
Definition: w3wdatmd.F90:183
w3gdatmd::xfr
real, pointer xfr
Definition: w3gdatmd.F90:1232
w3adatmd::whitecap
real, dimension(:,:), pointer whitecap
Definition: w3adatmd.F90:603
w3gdatmd::fte
real, pointer fte
Definition: w3gdatmd.F90:1232
w3gdatmd::stedu
real, pointer stedu
Definition: w3gdatmd.F90:1183
w3adatmd::tauox
real, dimension(:), pointer tauox
Definition: w3adatmd.F90:607
w3iogomd::w3flgrdupdt
subroutine w3flgrdupdt(NDSO, NDSEN, FLGRD, FLGR2, FLGD, FLG2)
Updates the flags for output parameters based on the mod_def file this is to prevent the allocation o...
Definition: w3iogomd.F90:178
w3odatmd::noextr
integer, parameter noextr
Definition: w3odatmd.F90:328
w3adatmd::p2sms
real, dimension(:,:), pointer p2sms
Definition: w3adatmd.F90:612
w3odatmd::idout
character(len=20), dimension(nogrp, ngrpp) idout
Definition: w3odatmd.F90:329
w3adatmd::prms
real, dimension(:), pointer prms
Definition: w3adatmd.F90:607
w3odatmd::napfld
integer, pointer napfld
Definition: w3odatmd.F90:457
w3adatmd::usero
real, dimension(:,:), pointer usero
Definition: w3adatmd.F90:623
w3iogomd::w3readflgrd
subroutine w3readflgrd(NDSI, NDSO, NDSS, NDSEN, COMSTR, FLG1D, FLG2D, IAPROC, NAPOUT, IERR)
Fills in FLG1D and FLG2D arrays from ASCII input file.
Definition: w3iogomd.F90:336
w3adatmd::mssy
real, dimension(:), pointer mssy
Definition: w3adatmd.F90:617
w3odatmd::ndst
integer, pointer ndst
Definition: w3odatmd.F90:456
w3wdatmd::ust
real, dimension(:), pointer ust
Definition: w3wdatmd.F90:183
constants
Define some much-used constants for global use (all defined as PARAMETER).
Definition: constants.F90:20
w3adatmd::ua
real, dimension(:), pointer ua
Definition: w3adatmd.F90:584
w3adatmd::tauoy
real, dimension(:), pointer tauoy
Definition: w3adatmd.F90:607
w3odatmd::nogrp
integer, parameter nogrp
Definition: w3odatmd.F90:323
w3gdatmd::dden
real, dimension(:), pointer dden
Definition: w3gdatmd.F90:1234
w3adatmd::fp0
real, dimension(:), pointer fp0
Definition: w3adatmd.F90:587
w3gdatmd
Definition: w3gdatmd.F90:16
w3adatmd::hsig
real, dimension(:), pointer hsig
Definition: w3adatmd.F90:587
w3dispmd::wavnu1
subroutine wavnu1(SI, H, K, CG)
Definition: w3dispmd.F90:85
w3adatmd::ussx
real, dimension(:), pointer ussx
Definition: w3adatmd.F90:607
w3gdatmd::igpars
real, dimension(:), pointer igpars
Definition: w3gdatmd.F90:1142
w3adatmd::embia2
real, dimension(:), pointer embia2
Definition: w3adatmd.F90:617
w3adatmd::mssx
real, dimension(:), pointer mssx
Definition: w3adatmd.F90:617
w3gdatmd::steyu
real, pointer steyu
Definition: w3gdatmd.F90:1183
constants::file_endian
character(*), parameter file_endian
FILE_ENDIAN Filled by preprocessor with 'big_endian', 'little_endian', or 'native'.
Definition: constants.F90:86
w3adatmd::tauadir
real, dimension(:), pointer tauadir
Definition: w3adatmd.F90:584
w3servmd::extcde
subroutine extcde(IEXIT, UNIT, MSG, FILE, LINE, COMM)
Definition: w3servmd.F90:736
w3adatmd::mscy
real, dimension(:), pointer mscy
Definition: w3adatmd.F90:617
w3wdatmd::rhoair
real, dimension(:), pointer rhoair
Definition: w3wdatmd.F90:183
w3wdatmd::ustdir
real, dimension(:), pointer ustdir
Definition: w3wdatmd.F90:183
w3iogomd::w3outg
subroutine w3outg(A, FLPART, FLOUTG, FLOUTG2)
Fill necessary arrays with gridded data for output.
Definition: w3iogomd.F90:1198
w3odatmd::icprt
integer, dimension(:,:), pointer icprt
Definition: w3odatmd.F90:551
w3adatmd::ptm1
real, dimension(:,:), pointer ptm1
Definition: w3adatmd.F90:597
w3odatmd::noswll
integer, pointer noswll
Definition: w3odatmd.F90:460
w3gdatmd::facti1
real, pointer facti1
Definition: w3gdatmd.F90:1232
w3adatmd::thm
real, dimension(:), pointer thm
Definition: w3adatmd.F90:587
w3adatmd::mscx
real, dimension(:), pointer mscx
Definition: w3adatmd.F90:617
w3adatmd::ppe
real, dimension(:,:), pointer ppe
Definition: w3adatmd.F90:597
w3adatmd::cx
real, dimension(:), pointer cx
Definition: w3adatmd.F90:584
w3gdatmd::nx
integer, pointer nx
Definition: w3gdatmd.F90:1097
w3adatmd::pgw
real, dimension(:,:), pointer pgw
Definition: w3adatmd.F90:597
constants::undef
real undef
UNDEF Value for undefined variable in output.
Definition: constants.F90:84
w3adatmd::ussp
real, dimension(:,:), pointer ussp
Definition: w3adatmd.F90:612
w3parall
Parallel routines for implicit solver.
Definition: w3parall.F90:22
w3gdatmd::ec2
real, dimension(:), pointer ec2
Definition: w3gdatmd.F90:1234
w3dispmd
Definition: w3dispmd.F90:3
w3gdatmd::usspf
integer, dimension(:), pointer usspf
Definition: w3gdatmd.F90:1098
w3adatmd::mssd
real, dimension(:), pointer mssd
Definition: w3adatmd.F90:617
w3gdatmd::e3df
integer, dimension(:,:), pointer e3df
Definition: w3gdatmd.F90:1098
w3adatmd::t0m1
real, dimension(:), pointer t0m1
Definition: w3adatmd.F90:587
w3gdatmd::mapsta
integer, dimension(:,:), pointer mapsta
Definition: w3gdatmd.F90:1163
constants::grav
real, parameter grav
GRAV Acc.
Definition: constants.F90:61
w3adatmd::tauocx
real, dimension(:), pointer tauocx
Definition: w3adatmd.F90:607
w3odatmd::wscut
real, pointer wscut
Definition: w3odatmd.F90:553
w3parall::init_get_isea
subroutine init_get_isea(ISEA, JSEA)
Set ISEA for all schemes.
Definition: w3parall.F90:1398
w3adatmd::aba
real, dimension(:), pointer aba
Definition: w3adatmd.F90:614
w3adatmd::syy
real, dimension(:), pointer syy
Definition: w3adatmd.F90:607
w3iogomd::fldout
character(len=1024) fldout
Definition: w3iogomd.F90:154
w3adatmd::ubd
real, dimension(:), pointer ubd
Definition: w3adatmd.F90:614
w3iogomd::w3flgrdflag
subroutine w3flgrdflag(NDSO, NDSS, NDSEN, FLDOUT, FLG1D, FLG2D, IAPROC, NAPOUT, IERR)
Fills in FLG1D and FLG2D arrays from ASCII input file.
Definition: w3iogomd.F90:586
w3adatmd::sxx
real, dimension(:), pointer sxx
Definition: w3adatmd.F90:607
w3wdatmd::dinit
logical, pointer dinit
Definition: w3wdatmd.F90:195
w3wdatmd::asf
real, dimension(:), pointer asf
Definition: w3wdatmd.F90:183
w3gdatmd::filext
character(len=13), pointer filext
Definition: w3gdatmd.F90:1224