WAVEWATCH III  beta 0.0.1
ww3_strt.F90
Go to the documentation of this file.
1 
5 !
6 #include "w3macros.h"
7 
8 !/ ------------------------------------------------------------------- /
37 PROGRAM w3strt
38  !/
39  !/ +-----------------------------------+
40  !/ | WAVEWATCH III NOAA/NCEP |
41  !/ | H. L. Tolman |
42  !/ | FORTRAN 90 |
43  !/ | Last update : 06-Jun-2018 |
44  !/ +-----------------------------------+
45  !/
46  !/ 15-Jan-1999 : Final FORTRAN 77 ( version 1.18 )
47  !/ 18-Jan-2000 : Upgrade to FORTRAN 90 ( version 2.00 )
48  !/ 11-Jan-2001 : Flat grid version ( version 2.06 )
49  !/ 11-Jun-2001 : Clean up. ( version 2.11 )
50  !/ 30-Apr-2002 : Updated W3IORS. ( version 2.20 )
51  !/ 13-Nov-2002 : Updated W3IORS. ( version 3.00 )
52  !/ 24-Dec-2004 : Multiple grid version. ( version 3.06 )
53  !/ 28-Jun-2006 : Adding file name preamble. ( version 3.09 )
54  !/ 08-May-2007 : Starting from calm as an option. ( version 3.11 )
55  !/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
56  !/ 30-Oct-2009 : Implement run-time grid selection. ( version 3.14 )
57  !/ (W. E. Rogers & T. J. Campbell, NRL)
58  !/ 30-Oct-2009 : Implement curvilinear grid type. ( version 3.14 )
59  !/ (W. E. Rogers & T. J. Campbell, NRL)
60  !/ 31-Oct-2010 : Implement unstructured grid ( version 3.14 )
61  !/ (A. Roland and F. Ardhuin)
62  !/ 05-Jul-2011 : Revert to X-Y gaussian shape ( version 4.01 )
63  !/ 06-Mar-2012 : Hardening output. ( version 4.07 )
64  !/ 06-Jun-2018 : Add DEBUGINIT/EXPORTWWM ( version 6.04 )
65  !/
66  !/
67  !/ Copyright 2009-2012 National Weather Service (NWS),
68  !/ National Oceanic and Atmospheric Administration. All rights
69  !/ reserved. WAVEWATCH III is a trademark of the NWS.
70  !/ No unauthorized use without permission.
71  !/
72  ! 1. Purpose :
73  !
74  ! Generation of initial conditions for a "cold start" of
75  ! WAVEWATCH III.
76  !
77  ! 2. Method :
78  !
79  ! General model information is obtained from the model definition
80  ! file using W3IOGR. The type of the initial field is read
81  ! from the input file WW3_strt.inp (NDSI). Three types of initial
82  ! conditions are available.
83  ! 1) Gaussian distribution in longitude, latitude and frequency,
84  ! cos power in directions. Can default to single spectral
85  ! bin.
86  ! 2) Predefined JONSWAP spectrum, Gaussian height distribution
87  ! in space.
88  ! 3) Fetch-limited JONSWAP spectrum based on the actual wind
89  ! speed. To avoid the need of reading a wind field, the
90  ! restart file is a "dummy", and the actual initial field
91  ! is constructed in the initialization routine W3INIT.
92  ! 4) User defined spectrum throughout the model.
93  ! 5) Starting from rest.
94  ! The initial conditions are written to the restart.WW3 using the
95  ! subroutine W3IORS. Note that the name of the restart file is set
96  ! in W3IORS.
97  !
98  ! 3. Parameters :
99  !
100  ! Local parameters.
101  ! ----------------------------------------------------------------
102  ! NDSI Int. Input unit number ("ww3_strt.inp").
103  ! ITYPE Int. Type of field (see section 2).
104  ! FP,SIP Real Peak frequency (Hz) and spread. \
105  ! XM,SIX Real Id. X (degr.). |
106  ! YM,SIY Real Id. Y (degr.). | ITYPE = 1
107  ! HMAX Real Maximum wave height. |
108  ! NCOS Real Cosine power in dir. distr. |
109  ! THM Real Mean direction (cart. degr.) / \
110  ! ALFA Real Energy level of PM spectrum. |
111  ! FP Real Peak frequency (Hz). | ITYPE = 2
112  ! GAMMA Real Peak enhancement factor |
113  ! SIGA/B Real Spread with GAMA. /
114  ! ----------------------------------------------------------------
115  !
116  ! 4. Subroutines used :
117  !
118  ! Name Type Module Description
119  ! ----------------------------------------------------------------
120  ! W3NMOD Subr. W3GDATMD Set number of model.
121  ! W3SETG Subr. Id. Point to selected model.
122  ! W3NDAT Subr. W3WDATMD Set number of model for wave data.
123  ! W3SETW Subr. Id. Point to selected model for wave data.
124  ! W3DIMW Subr. Id. Set array dims for wave data.
125  ! W3NAUX Subr. W3ADATMD Set number of model for aux data.
126  ! W3SETA Subr. Id. Point to selected model for aux data.
127  ! W3NOUT Subr. W3ODATMD Set number of model for output.
128  ! W3SETO Subr. Id. Point to selected model for output.
129  ! ITRACE Subr. W3SERVMD Subroutine tracing initialization.
130  ! STRACE Subr. Id. Subroutine tracing.
131  ! NEXTLN Subr. Id. Get next line from input filw
132  ! EXTCDE Subr. Id. Abort program as graceful as possible.
133  ! EJ5P Func. Id. Five parameter JONSWAP spectrum.
134  ! PRT1DS Subr. W3ARRYMD Print plot of 1-D spectrum.
135  ! PRT2DS Subr. Id. Print plot of 2-D spectrum.
136  ! PRTBLK Subr. Id. Print plot of array.
137  ! WAVNU1 Subr. W3DISPMD Solve dispersion relation.
138  ! W3IOGR Subr. W3IOGRMD Reading/writing model definition file.
139  ! W3IORS Subr. W3IORSMD Reading/writing restart files.
140  ! W3DIST Subr. W3GSRUMD Compute distance between two points.
141  ! MPI_xxx Subr. mpif.h Standard MPI routines.
142  ! ----------------------------------------------------------------
143  !
144  ! 5. Called by :
145  !
146  ! None, stand-alone program.
147  !
148  ! 6. Error messages :
149  !
150  ! 7. Remarks :
151  !
152  ! - While reading the restart file W3IORS will recognize the
153  ! need for checking the time, as the restart file contains
154  ! information on the origine of the file ("cold" or "hot").
155  ! - User input for x-wise gaussian spread control, SIX, is
156  ! now available again (option for SIX.NE.SIY available.)
157  ! If user desires a distribution that is circular in real
158  ! distances, user should input a negative number for SIX.
159  !
160  ! 8. Structure :
161  !
162  ! ----------------------------------------------------
163  ! 1.a Set up data structures.
164  ! ( W3NMOD , W3NDAT , W3NOUT
165  ! W3SETG , W3SETW , W3SETO )
166  ! b I-O setup.
167  ! b Print heading(s).
168  ! 2.a Read model defintion file with base model
169  ! data. ( W3IOGR )
170  ! b MPP initializations.
171  ! 3. Get field type from the input file.
172  ! 4. ITYPE = 1, Gaussian, cosine.
173  ! a Read parameters.
174  ! b Set-up 1-D spectrum.
175  ! c Set-up directional distribution.
176  ! d Normalize spectrum with Hmax.
177  ! e Distribute over grid.
178  ! 5. ITYPE = 2, pre-defined JONSWAP.
179  ! a Read parameters.
180  ! b Set-up 1-D spectrum.
181  ! c 2-D energy spectrum.
182  ! d Distribute over grid.
183  ! 6. ITYPE = 3, fetch limited JONSWAP.
184  ! 7. ITYPE = 4, user-defined spectrum.
185  ! a Read scale factor.
186  ! b Read and rescale spectrum.
187  ! c Distribute over grid.
188  ! 8. ITYPE = 5, start from calm conditions.
189  ! 9. Convert energy to action
190  ! 10. Write restart file. ( W3IORS )
191  ! ----------------------------------------------------
192  !
193  ! 9. Switches :
194  !
195  ! !/SHRD Switch for shared / distributed memory architecture.
196  ! !/DIST Id.
197  !
198  ! !/SHRD Switch for message passing method.
199  ! !/MPI Id.
200  !
201  ! !/S Enable subroutine tracing.
202  !
203  ! !/O4 Output normalized 1-D energy spectrum.
204  ! !/O5 Output normalized 2-D energy spectrum.
205  ! !/O6 Output normalized wave heights (not MPP adapted).
206  !
207  ! 10. Source code :
208  !
209  !/ ------------------------------------------------------------------- /
210  USE constants
211  !/
212  ! USE W3GDATMD, ONLY: W3NMOD, W3SETG
213  ! USE W3WDATMD, ONLY: W3NDAT, W3SETW, W3DIMW
214 #ifdef W3_NL1
215  USE w3adatmd, ONLY: w3naux, w3seta
216 #endif
217  USE w3odatmd, ONLY: w3nout, w3seto, flogrr
218  USE w3servmd, ONLY: itrace, nextln, ej5p, extcde
219 #ifdef W3_S
220  USE w3servmd, ONLY : strace
221 #endif
222 #ifdef W3_O4
223  USE w3arrymd, ONLY : prt1ds
224 #endif
225 #ifdef W3_O5
226  USE w3arrymd, ONLY : prt2ds
227 #endif
228 #ifdef W3_O6
229  USE w3arrymd, ONLY : prtblk
230 #endif
231  USE w3dispmd, ONLY : wavnu1
232  USE w3iogrmd, ONLY: w3iogr
233  USE w3iorsmd, ONLY: w3iors
234  USE w3gsrumd, ONLY: w3dist
235  !/
236  USE w3gdatmd
237  USE w3wdatmd
238  USE w3odatmd, ONLY: ndse, ndst, ndso, naproc, iaproc, &
240 #ifdef W3_WRST
241  USE w3idatmd, ONLY: w3ninp
242 #endif
243  !/
244  IMPLICIT NONE
245  !
246 #ifdef W3_MPI
247  include "mpif.h"
248 #endif
249  !/
250  !/ ------------------------------------------------------------------- /
251  !/ Local parameters
252  !/
253  INTEGER :: ndsi, ndsm, ndsr, ndstrc, ntrace, &
254  ndsen, ierr, itype, ncos, ikm, ik, &
255  ithm, ith, jsea, isea, ix, iy, j
256 #ifdef W3_MPI
257  INTEGER :: ierr_mpi
258 #endif
259 #ifdef W3_S
260  INTEGER, SAVE :: ient = 0
261 #endif
262 #ifdef W3_O6
263  INTEGER :: nsx, nsy
264  INTEGER, ALLOCATABLE :: mapo(:,:)
265 #endif
266  REAL :: fp, sip, thm, xm, six, ym, siy, hmax,&
267  chsip, frrel, etot, e1i, factor, x, &
268  y, rdsqr, alfa, gamma, siga, sigb, &
269  yln, fr, beta, frr, s, sumd, ang, &
270  arg, facs, depth, wn, cg, hpqmax
271  REAL, ALLOCATABLE :: e1(:), dd(:), e2(:,:), e21(:), finp(:,:)
272 #ifdef W3_O5
273  REAL, ALLOCATABLE :: e2out(:,:)
274 #endif
275 #ifdef W3_O6
276  REAL, ALLOCATABLE :: hsig(:,:)
277 #endif
278  CHARACTER :: comstr*1, inxout*4
279 #ifdef W3_EXPORTWWM
280  INTEGER :: ispec
281 #endif
282  LOGICAL :: flone,nosix
283  !/
284  !/ ------------------------------------------------------------------- /
285  !
286  ! 1.a Initialize data structure
287  !
288  CALL w3nmod ( 1, 6, 6 )
289  CALL w3setg ( 1, 6, 6 )
290  CALL w3ndat ( 6, 6 )
291  CALL w3setw ( 1, 6, 6 )
292 #ifdef W3_NL1
293  CALL w3naux ( 6, 6 )
294  CALL w3seta ( 1, 6, 6 )
295 #endif
296  CALL w3nout ( 6, 6 )
297  CALL w3seto ( 1, 6, 6 )
298 #ifdef W3_WRST
299  CALL w3ninp( 6, 6 )
300 #endif
301  !
302  ! 1.b IO set-up.
303  !
304  ndsi = 10
305  ndsm = 20
306  ndsr = 20
307  !
308  flogrr(:,:) = .false.
309  !
310  ndstrc = 6
311  ntrace = 10
312  CALL itrace ( ndstrc, ntrace )
313  !
314 #ifdef W3_S
315  CALL strace (ient, 'W3STRT')
316 #endif
317  !
318  ! 1.c MPP initializations
319  !
320 #ifdef W3_SHRD
321  naproc = 1
322  iaproc = 1
323 #endif
324  !
325 #ifdef W3_MPI
326  CALL mpi_init ( ierr_mpi )
327  CALL mpi_comm_size ( mpi_comm_world, naproc, ierr_mpi )
328  CALL mpi_comm_rank ( mpi_comm_world, iaproc, ierr_mpi )
329  iaproc = iaproc + 1
330 #endif
331  !
332  IF ( iaproc .EQ. naperr ) THEN
333  ndsen = ndse
334  ELSE
335  ndsen = -1
336  END IF
337  !
338  IF ( iaproc .EQ. napout ) WRITE (ndso,900)
339  !
340  j = len_trim(fnmpre)
341  OPEN (ndsi,file=fnmpre(:j)//'ww3_strt.inp',status='OLD', &
342  err=800,iostat=ierr)
343  rewind(ndsi)
344  READ (ndsi,'(A)',END=801,ERR=802) comstr
345  IF (comstr.EQ.' ') comstr = '$'
346  IF ( iaproc .EQ. napout ) WRITE (ndso,901) comstr
347  !
348  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
349  ! 2. Read model definition file and mpp initializations.
350  ! 2.a Reading file
351  !
352  CALL w3iogr ( 'READ', ndsm )
353  !
354  IF ( iaproc .EQ. napout ) WRITE (ndso,902) gname
355  !
356  ! 2.b MPP initializations
357  !
358 #ifdef W3_SHRD
359  nseal = nsea
360 #endif
361  !
362 #ifdef W3_DIST
363  nseal = 1 + (nsea-iaproc)/naproc
364  IF ( nsea .LT. naproc ) GOTO 803
365 #endif
366  !
367  CALL w3dimw ( 1, ndse, ndst )
368  ALLOCATE ( e1(nk), dd(nth), e2(nth,nk), e21(nspec), &
369  finp(nk,nth) )
370  !
371  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
372  ! 3. Read type from input file.
373  !
374  CALL nextln ( comstr , ndsi , ndsen )
375  READ (ndsi,*,END=801,ERR=802) itype
376  IF ( itype.LT.1 .OR. itype.GT.5 ) THEN
377  IF ( iaproc .EQ. naperr ) WRITE (ndse,1010) itype
378  CALL extcde ( 1 )
379  END IF
380  IF ( iaproc .EQ. napout ) WRITE (ndso,930) itype
381  !
382  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
383  ! 4. ITYPE = 1, Gaussian, cosine.
384  !
385  IF ( itype .EQ. 1 ) THEN
386  inxout = 'COLD'
387  !
388  ! 4.a Read parameters.
389  !
390  CALL nextln ( comstr , ndsi , ndsen )
391  READ (ndsi,*,END=801,ERR=802) &
392  fp, sip, thm, ncos, xm, six, ym, siy, hmax
393  fp = max( 0.5 * tpiinv * sig(1) , fp )
394  sip = max( 0. , sip )
395  DO
396  IF ( thm .LT. 0. ) THEN
397  thm = thm + 360.
398  ELSE
399  EXIT
400  END IF
401  END DO
402  thm = mod( thm , 360. )
403  ncos = max( 0 , 2*(ncos/2) )
404 
405  nosix=.false.
406  IF(six.LT.0.0)THEN
407  IF ( iaproc .EQ. napout ) WRITE (ndso,903)
408  nosix=.true.
409  END IF
410 
411  hpqmax=-999.0
412  DO jsea=1, nseal
413 #ifdef W3_DIST
414  isea = iaproc + (jsea-1)*naproc
415 #endif
416 #ifdef W3_SHRD
417  isea = jsea
418 #endif
419  ix = mapsf(isea,1)
420  iy = mapsf(isea,2)
421  IF(hpfac(iy,ix).GT.hpqmax)THEN
422  hpqmax=hpfac(iy,ix)
423  ENDIF
424  END DO
425  six = max(0.01*hpqmax,six)
426 
427  hpqmax=-999.0
428  DO jsea=1, nseal
429 #ifdef W3_DIST
430  isea = iaproc + (jsea-1)*naproc
431 #endif
432 #ifdef W3_SHRD
433  isea = jsea
434 #endif
435  ix = mapsf(isea,1)
436  iy = mapsf(isea,2)
437  IF(hqfac(iy,ix).GT.hpqmax)THEN
438  hpqmax=hqfac(iy,ix)
439  ENDIF
440  END DO
441  siy = max(0.01*hpqmax,siy)
442 
443  hmax = max( 0. , hmax )
444  !
445  IF ( iaproc .EQ. napout ) THEN
446  IF ( flagll ) THEN
447  factor = 1.
448  WRITE (ndso,940) fp, sip, thm, ncos, &
449  factor*xm, min(9999.99,factor*six), factor*ym, &
450  min(9999.99,factor*siy), hmax
451  ELSE
452  factor = 1.e-3
453  WRITE (ndso,941) fp, sip, thm, ncos, &
454  factor*xm, min(9999.99,factor*six), factor*ym, &
455  min(9999.99,factor*siy), hmax
456  END IF
457  END IF
458  !
459  fp = fp * tpi
460  sip = sip * tpi
461  thm = mod( 630. - thm , 360. ) * dera
462  !
463  ! 4.b Make 1-D spectrum.
464  !
465  chsip = 0.1 * dsip(1)
466  flone = sip .LT. chsip
467  ikm = nint( 1. + (log(fp)-log(fr1*tpi))/log(xfr) )
468  ikm = max( 1 , min( nk , ikm ) )
469  !
470  DO ik=1, nk
471  IF ( flone ) THEN
472  IF (ik.EQ.ikm) THEN
473  e1(ik) = 1.
474  ELSE
475  e1(ik) = 0.
476  END IF
477  ELSE
478  frrel = (sig(ik)-fp)/sip
479  IF (abs(frrel).LT.10) THEN
480  e1(ik) = exp( -0.125 * frrel**2 )
481  ELSE
482  e1(ik) = 0.
483  END IF
484  END IF
485  END DO
486  !
487 #ifdef W3_O4
488  IF ( iaproc .EQ. napout ) CALL prt1ds &
489  (ndso, nk, e1, sig(1:), ' ', 10, 0., &
490  'Unscaled 1-D', ' ', 'TEST E(f)')
491 #endif
492  !
493  ! 4.c Make directional distribution.
494  !
495  flone = ncos .GT. 20
496  ithm = 1 + nint( thm / dth )
497  DO ith=1, nth
498  IF (flone) THEN
499  IF ( ith .EQ. ithm ) THEN
500  dd(ith) = 1.
501  ELSE
502  dd(ith) = 0.
503  END IF
504  ELSE
505  dd(ith) = max( cos(th(ith)-thm) , 0. )**ncos
506  END IF
507  END DO
508  !
509  ! 4.d 2-D energy spectrum.
510  !
511  etot = 0.
512  DO ik=1, nk
513  e1i = 0.
514  DO ith=1, nth
515  e2(ith,ik) = e1(ik) * dd(ith)
516  e1i = e1i + e2(ith,ik)
517  END DO
518  etot = etot + e1i * dsip(ik)
519  END DO
520  etot = etot * dth
521  factor = hmax**2 / ( 16. * etot )
522  !
523  e2 = factor * e2
524  !
525 #ifdef W3_O5
526  ALLOCATE ( e2out(nk,nth) )
527  DO ith=1, nth
528  DO ik=1, nk
529  e2out(ik,ith) = tpi * e2(ith,ik)
530  END DO
531  END DO
532 #endif
533  !
534 #ifdef W3_O5
535  IF ( iaproc .EQ. napout ) CALL prt2ds &
536  ( ndso, nk, nk, nth, e2out, sig(1:), ' ', dera*tpi, &
537  0., 0.0001, 'Energy', 'm2s', 'TEST 2-D')
538  DEALLOCATE ( e2out )
539 #endif
540  !
541  ! 4.e Distribute over grid.
542  !
543 
544  DO ik=1, nk
545  e21(1+(ik-1)*nth:ik*nth) = e2(:,ik)
546  END DO
547  !
548  DO jsea=1, nseal
549  !
550 #ifdef W3_DIST
551  isea = iaproc + (jsea-1)*naproc
552 #endif
553 #ifdef W3_SHRD
554  isea = jsea
555 #endif
556  IF (gtype .EQ. ungtype) THEN
557  ix = mapsf(isea,1)
558  x = xgrd(1,ix)
559  y = ygrd(1,ix)
560  ELSE
561  ix = mapsf(isea,1)
562  iy = mapsf(isea,2)
563  x = xgrd(iy,ix)
564  y = ygrd(iy,ix)
565  ENDIF
566  IF(nosix)THEN
567  rdsqr =(w3dist(flagll,x,y,xm,ym)/siy)**2
568  ELSE
569  rdsqr =((x-xm)/six)**2 + ((y-ym)/siy)**2
570  ENDIF
571  IF ( rdsqr .GT. 40. ) THEN
572  factor = 0.
573  ELSE
574  factor = exp( -0.5 * rdsqr )
575  END IF
576  !
577 #ifdef W3_EXPORTWWM
578  factor = 1.
579 #endif
580  va(:,jsea) = factor * e21
581  !
582 
583  !
584  END DO
585  !
586  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
587  ! 5. ITYPE = 2, pre-defined JONSWAP.
588  !
589  ELSE IF ( itype .EQ. 2 ) THEN
590  inxout = 'COLD'
591  !
592  ! 5.a Read parameters.
593  !
594  CALL nextln ( comstr , ndsi , ndsen )
595  READ (ndsi,*,END=801,ERR=802) &
596  alfa, fp, thm, gamma, siga, sigb, xm, six, ym, siy
597  !
598  IF (alfa.LE.0.) alfa = 0.0081
599  IF (fp .LE.0.) fp = 0.10
600  IF (siga.LE.0.) siga = 0.07
601  IF (sigb.LE.0.) sigb = 0.09
602  fp = max( 0.5 * tpiinv * sig(1) , fp )
603  fp = min( tpiinv * sig(nk) , fp )
604 
605  nosix=.false.
606  IF(six.LT.0.0)THEN
607  IF ( iaproc .EQ. napout ) WRITE (ndso,903)
608  nosix=.true.
609  END IF
610 
611  hpqmax=-999.0
612  DO jsea=1, nseal
613 #ifdef W3_DIST
614  isea = iaproc + (jsea-1)*naproc
615 #endif
616 #ifdef W3_SHRD
617  isea = jsea
618 #endif
619  ix = mapsf(isea,1)
620  iy = mapsf(isea,2)
621  IF(hpfac(iy,ix).GT.hpqmax)THEN
622  hpqmax=hpfac(iy,ix)
623  ENDIF
624  END DO
625  six = max(0.01*hpqmax,six)
626 
627  hpqmax=-999.0
628  DO jsea=1, nseal
629 #ifdef W3_DIST
630  isea = iaproc + (jsea-1)*naproc
631 #endif
632 #ifdef W3_SHRD
633  isea = jsea
634 #endif
635  ix = mapsf(isea,1)
636  iy = mapsf(isea,2)
637  IF(hqfac(iy,ix).GT.hpqmax)THEN
638  hpqmax=hqfac(iy,ix)
639  ENDIF
640  END DO
641  siy = max(0.01*hpqmax,siy)
642 
643  DO
644  IF ( thm .LT. 0. ) THEN
645  thm = thm + 360.
646  ELSE
647  EXIT
648  END IF
649  END DO
650  thm = mod( thm , 360. )
651  gamma = max(gamma,1.)
652  yln = log(gamma)
653  !
654  IF ( iaproc .EQ. napout ) THEN
655  IF ( flagll ) THEN
656  factor = 1.
657  WRITE (ndso,950) alfa, fp, thm, gamma, siga, sigb, &
658  factor*xm, factor*six, factor*ym, factor*siy
659  ELSE
660  factor = 1.e-3
661  WRITE (ndso,951) alfa, fp, thm, gamma, siga, sigb, &
662  factor*xm, factor*six, factor*ym, factor*siy
663  END IF
664  END IF
665  thm = mod( 630. - thm , 360. ) * dera
666  !
667  ! 5.b Make 1-D spectrum.
668  !
669  DO ik=1, nk
670  fr = sig(ik) * tpiinv
671  e1(ik) = ej5p(fr, alfa, fp, yln, siga, sigb )
672  END DO
673  !
674 #ifdef W3_O4
675  IF ( iaproc .EQ. napout ) CALL prt1ds &
676  (ndso, nk, e1, sig(1:), ' ', 18, 0., &
677  'E(f)', ' ', 'TEST 1-D')
678 #endif
679  !
680  ! 5.c 2-D energy spectrum.
681  ! Factor 2pi to go to E(sigma,theta)
682  !
683  DO ik = 1,nk
684  fr = sig(ik) * tpiinv
685  IF (fr.LT.fp) THEN
686  beta = 4.06
687  ELSE
688  beta = -2.34
689  END IF
690  frr = min( 2.5 , fr/fp )
691  s = 9.77 * frr**beta
692  sumd = 0.
693  DO ith = 1,nth
694  ang = cos( 0.5 * ( thm - th(ith) ) )**2
695  dd(ith) = 0.
696  IF(ang.GT.1.e-20) THEN
697  arg = s * log(ang)
698  IF(arg.GT.-170) dd(ith) = exp(arg)
699  END IF
700  sumd = sumd + dd(ith)
701  END DO
702  factor = 1. / (tpi*sumd*dth)
703  DO ith = 1,nth
704  e2(ith,ik) = factor * e1(ik) * dd(ith)
705  END DO
706  END DO
707  !
708 #ifdef W3_O5
709  ALLOCATE ( e2out(nk,nth) )
710  DO ith=1, nth
711  DO ik=1, nk
712  e2out(ik,ith) = tpi * e2(ith,ik)
713  END DO
714  END DO
715 #endif
716  !
717 #ifdef W3_O5
718  IF ( iaproc .EQ. napout ) CALL prt2ds &
719  (ndso, nk, nk, nth, e2out, sig(1:), ' ', 1., &
720  0., 0.0001, 'E(f,theta)', 'm2s', 'TEST 2-D')
721  DEALLOCATE ( e2out )
722 #endif
723  !
724  ! 5.d Distribute over grid.
725  !
726 
727  DO ik=1, nk
728  e21(1+(ik-1)*nth:ik*nth) = e2(:,ik)
729  END DO
730  !
731  !
732  DO jsea=1, nseal
733  !
734 #ifdef W3_DIST
735  isea = iaproc + (jsea-1)*naproc
736 #endif
737 #ifdef W3_SHRD
738  isea = jsea
739 #endif
740  IF (gtype .EQ. ungtype) THEN
741  ix = mapsf(isea,1)
742  x = xgrd(1,ix)
743  y = ygrd(1,ix)
744  ELSE
745  ix = mapsf(isea,1)
746  iy = mapsf(isea,2)
747  x = xgrd(iy,ix)
748  y = ygrd(iy,ix)
749  ENDIF
750  IF(nosix)THEN
751  rdsqr =(w3dist(flagll,x,y,xm,ym)/siy)**2
752  ELSE
753  rdsqr =((x-xm)/six)**2 + ((y-ym)/siy)**2
754  ENDIF
755  IF ( rdsqr .GT. 40. ) THEN
756  factor = 0.
757  ELSE
758  factor = exp( -0.5 * rdsqr )
759  END IF
760  !
761  va(:,jsea) = factor * e21
762  !
763  END DO
764  !
765  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
766  ! 6. ITYPE = 3, fetch limited JONSWAP.
767  !
768  ELSE IF ( itype .EQ. 3 ) THEN
769  inxout = 'WIND'
770  IF ( iaproc .EQ. napout ) WRITE (ndso,960)
771  !
772  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
773  ! 7. ITYPE = 4, User defined.
774  !
775  ELSE IF ( itype .EQ. 4 ) THEN
776  inxout = 'COLD'
777  !
778  ! 7.a Read parameters.
779  !
780  CALL nextln ( comstr , ndsi , ndsen )
781  READ (ndsi,*,END=801,ERR=802) facs
782  IF ( facs .LE. 0. ) facs = 1.
783  IF ( iaproc .EQ. napout ) WRITE (ndso,970) facs
784  !
785  ! 7.b Read and rescale spectrum.
786  !
787  CALL nextln ( comstr , ndsi , ndsen )
788  READ (ndsi,*,END=801,ERR=802) &
789  ((finp(ik,ith),ik=1,nk),ith=1,nth)
790  !
791  finp = finp * facs / tpi
792  !
793 #ifdef W3_O5
794  IF ( iaproc .EQ. napout ) CALL prt2ds &
795  (ndso, nk, nk, nth, finp, sig(1:), ' ', tpi, &
796  0., 0.0001, 'Energy', 'm2s', 'TEST 2-D')
797 #endif
798  !
799  ! 7.c Distribute over grid.
800  !
801  DO jsea=1, nseal
802  !
803 #ifdef W3_DIST
804  isea = iaproc + (jsea-1)*naproc
805 #endif
806 #ifdef W3_SHRD
807  isea = jsea
808 #endif
809  DO ik=1, nk
810  DO ith=1, nth
811  va(ith+(ik-1)*nth,jsea) = finp(ik,ith)
812  END DO
813  END DO
814  END DO
815  !
816  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
817  ! 8. ITYPE = 5, fetch limited JONSWAP.
818  !
819  ELSE
820  inxout = 'CALM'
821  IF ( iaproc .EQ. napout ) WRITE (ndso,980)
822  !
823  END IF
824  !
825  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
826  ! 9. Convert E(sigma) to N(k)
827  !
828  IF ( itype.NE.3 .AND. itype.NE.5 ) THEN
829  IF ( iaproc .EQ. napout ) WRITE (ndso,990)
830  !
831 #ifdef W3_O6
832  ALLOCATE ( hsig(nx,ny) )
833  hsig = 0.
834 #endif
835  !
836  DO jsea=1, nseal
837 #ifdef W3_DIST
838  isea = iaproc + (jsea-1)*naproc
839 #endif
840 #ifdef W3_SHRD
841  isea = jsea
842 #endif
843  depth = max( dmin , -zb(isea) )
844 #ifdef W3_O6
845  etot = 0.
846 #endif
847  DO ik=1, nk
848  CALL wavnu1 ( sig(ik), depth, wn, cg )
849 #ifdef W3_O6
850  e1i = 0.
851 #endif
852  DO ith=1, nth
853 #ifdef W3_O6
854  e1i = e1i + va(ith+(ik-1)*nth,jsea)
855 #endif
856  va(ith+(ik-1)*nth,jsea) = va(ith+(ik-1)*nth,jsea) * &
857  cg / sig(ik)
858  END DO
859 #ifdef W3_O6
860  etot = etot + e1i*dsip(ik)
861 #endif
862  END DO
863 #ifdef W3_O6
864  ix = mapsf(isea,1)
865  iy = mapsf(isea,2)
866  hsig(ix,iy) = 4. * sqrt( etot * dth )
867 #endif
868 #ifdef W3_EXPORTWWM
869  IF (jsea .eq. 1) THEN
870  DO ith=1,nth
871  DO ik=1,nk
872  ispec = ith + nth * (ik-1)
873  WRITE(10003) ith, ik, va(ispec,jsea)
874  END DO
875  END DO
876  WRITE(740+iaproc,*) 'FINAL : sum(VA)=', sum(va(:,jsea))
877  END IF
878 #endif
879  END DO
880  !
881 #ifdef W3_O6
882  ALLOCATE ( mapo(nx,ny) )
883  DO ix=1, nx
884  DO iy=1, ny
885  mapo(ix,iy) = mapsta(iy,ix)
886  END DO
887  END DO
888 #endif
889  !
890 #ifdef W3_MPI
891  IF ( naproc .EQ. 1 ) THEN
892 #endif
893 #ifdef W3_O6
894  nsx = 1 + nx/35
895  nsy = 1 + ny/35
896  IF ( iaproc .EQ. napout ) CALL prtblk &
897  (ndso, nx, ny, nx, hsig, mapo, 0, 0., &
898  1, nx, nsx, 1, ny, nsy, 'Hs', 'm')
899 #endif
900 #ifdef W3_MPI
901  END IF
902 #endif
903  !
904  END IF
905  !
906  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
907  !10. Write restart file.
908  !
909  IF ( iaproc .EQ. napout ) WRITE (ndso,995)
910  CALL w3iors ( inxout, ndsr, sig(nk) )
911  !
912  GOTO 888
913  !
914  ! Escape locations read errors :
915  !
916 800 CONTINUE
917  IF ( iaproc .EQ. naperr ) WRITE (ndse,1000) ierr
918  CALL extcde ( 10 )
919  !
920 801 CONTINUE
921  IF ( iaproc .EQ. naperr ) WRITE (ndse,1001)
922  CALL extcde ( 11 )
923  !
924 802 CONTINUE
925  IF ( iaproc .EQ. naperr ) WRITE (ndse,1002) ierr
926  CALL extcde ( 12 )
927  !
928 #ifdef W3_DIST
929 803 CONTINUE
930  IF ( iaproc .EQ. naperr ) WRITE (ndse,1003) nsea, naproc
931  CALL extcde ( 13 )
932 #endif
933  !
934 888 CONTINUE
935  IF ( iaproc .EQ. napout ) WRITE (ndso,999)
936 #ifdef W3_MPI
937  CALL mpi_finalize ( ierr_mpi )
938 #endif
939  !
940  ! Formats
941  !
942 900 FORMAT (/15x,' *** WAVEWATCH III Initial conditions *** '/ &
943  15x,'==============================================='/)
944 901 FORMAT ( ' Comment character is ''',a,''''/)
945 902 FORMAT ( ' Grid name : ',a/)
946 903 FORMAT ( ' Negative SIX was provided by user. '/ &
947  ' WW3 will create a gaussian distribution '/ &
948  ' that is circular in real space. ')
949  !
950 930 FORMAT (/' Initial field ITYPE =',i2/ &
951  ' --------------------------------------------------')
952  !
953 940 FORMAT ( ' Gaussian / cosine power spectrum '// &
954  ' Peak frequency and spread (Hz) :',2x,2f8.4/ &
955  ' Mean direction (Naut., degr.) :',f7.1/ &
956  ' Cosine power of dir. distribution :',i5/ &
957  ' Mean longitude and spread (degr.) :',2f8.2/ &
958  ' Mean latitude and spread (degr.) :',2f8.2/ &
959  ' Maximum wave height :',f8.2/)
960  !
961 950 FORMAT ( ' JONSWAP spectrum'// &
962  ' alfa (-) : ',f12.5/ &
963  ' Peak frequecy (Hz) : ',f11.4/ &
964  ' Mean direction (Naut.,deg.) : ',f 8.1/ &
965  ' gamma (-) : ',f 9.2/ &
966  ' sigma-A (-) : ',f11.4/ &
967  ' sigma-B (-) : ',f11.4/ &
968  ' Mean longitude and spread (degr.) : ',2f9.2/ &
969  ' Mean latitude and spread (degr.) : ',2f9.2)
970 941 FORMAT ( ' Gaussian / cosine power spectrum '// &
971  ' Peak frequency and spread (Hz) :',2x,2f8.4/ &
972  ' Mean direction (Naut., degr.) :',f7.1/ &
973  ' Cosine power of dir. distribution :',i5/ &
974  ' Mean X and spread (km) :',2f8.2/ &
975  ' Mean Y and spread (km) :',2f8.2/ &
976  ' Maximum wave height :',f8.2/)
977  !
978 951 FORMAT ( ' JONSWAP spectrum'// &
979  ' alfa (-) : ',f12.5/ &
980  ' Peak frequecy (Hz) : ',f11.4/ &
981  ' Mean direction (Naut.,deg.) : ',f 8.1/ &
982  ' gamma (-) : ',f 9.2/ &
983  ' sigma-A (-) : ',f11.4/ &
984  ' sigma-B (-) : ',f11.4/ &
985  ' Mean X and spread (km) : ',2f9.2/ &
986  ' Mean Y and spread (km) : ',2f9.2)
987  !
988 960 FORMAT ( ' Fetch-limited JONSWAP spectra based on local '/ &
989  ' wind speed (fetch related to grid increment).')
990  !
991 970 FORMAT ( ' User-defined energy spectrum F(f,theta).'// &
992  ' Scale factor (-) : ',e12.4/)
993  !
994 980 FORMAT ( ' Starting from calm conditions (Hs = 0)')
995  !
996 990 FORMAT (/' Converting energy to action ... ')
997 995 FORMAT (/' Writing restart file ... '/)
998  !
999 999 FORMAT (/' End of program '/ &
1000  ' ========================================='/ &
1001  ' WAVEWATCH III Initial conditions '/)
1002  !
1003 1000 FORMAT (/' *** WAVEWATCH III ERROR IN W3STRT : '/ &
1004  ' ERROR IN OPENING INPUT FILE'/ &
1005  ' IOSTAT =',i5/)
1006  !
1007 1001 FORMAT (/' *** WAVEWATCH III ERROR IN W3STRT : '/ &
1008  ' PREMATURE END OF INPUT FILE'/)
1009  !
1010 1002 FORMAT (/' *** WAVEWATCH III ERROR IN W3STRT : '/ &
1011  ' ERROR IN READING FROM INPUT FILE'/ &
1012  ' IOSTAT =',i5/)
1013  !
1014 1010 FORMAT (/' *** WAVEWATCH III ERROR IN W3STRT : '/ &
1015  ' ILLEGAL TYPE, ITYPE =',i4/)
1016  !
1017 #ifdef W3_DIST
1018 1003 FORMAT (/' *** WAVEWATCH III ERROR IN W3STRT : '/ &
1019  ' NUMBER OF SEA POINTS LESS THAN NUMBER OF PROC.'/ &
1020  ' NSEA, NAPROC =',2i8/)
1021 #endif
1022  !/
1023  !/ End of W3STRT ----------------------------------------------------- /
1024  !/
1025 END PROGRAM w3strt
w3servmd::nextln
subroutine nextln(CHCKC, NDSI, NDSE)
Definition: w3servmd.F90:222
include
cmake src_list cmake include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_switches.cmake) check_switches("$
Definition: CMakeLists.txt:15
w3servmd::ej5p
real function ej5p(F, ALFA, FP, YLN, SIGA, SIGB)
Definition: w3servmd.F90:407
w3adatmd
Define data structures to set up wave model auxiliary data for several models simultaneously.
Definition: w3adatmd.F90:26
constants::dera
real, parameter dera
DERA Conversion factor from degrees to radians.
Definition: constants.F90:77
w3wdatmd
Define data structures to set up wave model dynamic data for several models simultaneously.
Definition: w3wdatmd.F90:18
w3iorsmd::w3iors
subroutine w3iors(INXOUT, NDSR, DUMFPI, IMOD, FLRSTRT)
Reads/writes restart files.
Definition: w3iorsmd.F90:113
w3gsrumd
Definition: w3gsrumd.F90:17
w3odatmd::iaproc
integer, pointer iaproc
Definition: w3odatmd.F90:457
w3odatmd::fnmpre
character(len=80) fnmpre
Definition: w3odatmd.F90:330
w3gdatmd::w3setg
subroutine w3setg(IMOD, NDSE, NDST)
Definition: w3gdatmd.F90:2152
w3odatmd::ndse
integer, pointer ndse
Definition: w3odatmd.F90:456
w3adatmd::w3seta
subroutine w3seta(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3adatmd.F90:2645
w3wdatmd::w3ndat
subroutine w3ndat(NDSE, NDST)
Set up the number of grids to be used.
Definition: w3wdatmd.F90:210
w3odatmd::naperr
integer, pointer naperr
Definition: w3odatmd.F90:457
w3odatmd::flogrr
logical, dimension(:,:), pointer flogrr
Definition: w3odatmd.F90:478
w3servmd
Definition: w3servmd.F90:3
w3wdatmd::w3setw
subroutine w3setw(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3wdatmd.F90:660
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
w3odatmd
Definition: w3odatmd.F90:3
w3adatmd::w3naux
subroutine w3naux(NDSE, NDST)
Set up the number of grids to be used.
Definition: w3adatmd.F90:704
w3odatmd::naproc
integer, pointer naproc
Definition: w3odatmd.F90:457
w3iogrmd::w3iogr
subroutine w3iogr(INXOUT, NDSM, IMOD, FEXT ifdef W3_ASCII
Reading and writing of the model definition file.
Definition: w3iogrmd.F90:117
file
file(STRINGS ${CMAKE_BINARY_DIR}/switch switch_strings) separate_arguments(switches UNIX_COMMAND $
Definition: CMakeLists.txt:3
w3iogrmd
Reading/writing of model definition file.
Definition: w3iogrmd.F90:20
w3arrymd::prt1ds
subroutine prt1ds(NDS, NFR, E, FR, UFR, NLINES, FTOPI, PRVAR, PRUNIT, PNTNME)
Definition: w3arrymd.F90:1366
constants::tpi
real, parameter tpi
TPI 2*Pi.
Definition: constants.F90:72
w3servmd::strace
subroutine strace(IENT, SNAME)
Definition: w3servmd.F90:148
w3idatmd
Define data structures to set up wave model input data for several models simultaneously.
Definition: w3idatmd.F90:16
w3odatmd::ndso
integer, pointer ndso
Definition: w3odatmd.F90:456
w3gdatmd::w3nmod
subroutine w3nmod(NUMBER, NDSE, NDST, NAUX)
Definition: w3gdatmd.F90:1433
w3arrymd
Definition: w3arrymd.F90:3
w3odatmd::napout
integer, pointer napout
Definition: w3odatmd.F90:457
w3odatmd::ndst
integer, pointer ndst
Definition: w3odatmd.F90:456
constants
Define some much-used constants for global use (all defined as PARAMETER).
Definition: constants.F90:20
w3gdatmd
Definition: w3gdatmd.F90:16
w3dispmd::wavnu1
subroutine wavnu1(SI, H, K, CG)
Definition: w3dispmd.F90:85
w3servmd::extcde
subroutine extcde(IEXIT, UNIT, MSG, FILE, LINE, COMM)
Definition: w3servmd.F90:736
w3odatmd::w3nout
subroutine w3nout(NDSERR, NDSTST)
Definition: w3odatmd.F90:561
w3arrymd::prt2ds
subroutine prt2ds(NDS, NFR0, NFR, NTH, E, FR, UFR, FACSP, FSC, RRCUT, PRVAR, PRUNIT, PNTNME)
Definition: w3arrymd.F90:1943
w3strt
program w3strt
Generation of initial conditions for a "cold start" of WAVEWATCH III.
Definition: ww3_strt.F90:37
w3servmd::itrace
subroutine itrace(NDS, NMAX)
Definition: w3servmd.F90:91
w3idatmd::w3ninp
subroutine w3ninp(NDSE, NDST)
Set up the number of grids to be used.
Definition: w3idatmd.F90:283
w3dispmd
Definition: w3dispmd.F90:3
w3arrymd::prtblk
subroutine prtblk(NDS, NX, NY, MX, F, MAP, MAP0, FSC, IX1, IX2, IX3, IY1, IY2, IY3, PRVAR, PRUNIT)
Definition: w3arrymd.F90:1112
w3iorsmd
Read/write restart files.
Definition: w3iorsmd.F90:14