WAVEWATCH III  beta 0.0.1
ww3_shel.F90
Go to the documentation of this file.
1 
5 !
6 #include "w3macros.h"
7 
8 !/ ------------------------------------------------------------------- /
15 !
16 PROGRAM w3shel
17  !/
18  !/ +-----------------------------------+
19  !/ | WAVEWATCH III NOAA/NCEP |
20  !/ | H. L. Tolman |
21  !/ | FORTRAN 90 |
22  !/ | Last update : 22-Mar-2021 |
23  !/ +-----------------------------------+
24  !/
25  !/ 19-Jan-1999 : Final FORTRAN 77 ( version 1.18 )
26  !/ 19-Jan-2000 : Upgrade to FORTRAN 90 ( version 2.00 )
27  !/ 08-Mar-2000 : Fix time managament bug. ( version 2.04 )
28  !/ 09-Jan-2001 : Fix FOUT allocation bug. ( version 2.05 )
29  !/ 24-Jan-2001 : Flat grid version. ( version 2.06 )
30  !/ 25-Jan-2002 : Data assimilation set up. ( version 2.17 )
31  !/ 08-May-2002 : Clean up for timers. ( version 2.21 )
32  !/ 26-Aug-2002 : Generalizing timer. ( version 2.22 )
33  !/ 26-Dec-2002 : Continuously moving grid. ( version 3.02 )
34  !/ 01-Aug-2003 : Continuously moving grid, input. ( version 3.03 )
35  !/ 07-Oct-2003 : Fixed NHMAX test. ( version 3.05 )
36  !/ 05-Jan-2005 : Multiple grid version. ( version 3.06 )
37  !/ 04-May-2005 : Change to MPI_COMM[_WAVE. ( version 3.07 )
38  !/ 26-Jun-2006 : Add wiring for output type 6. ( version 3.07 )
39  !/ 28-Jun-2006 : Adding file name preamble. ( version 3.09 )
40  !/ 28-Oct-2006 : Adding partitioning options. ( version 3.10 )
41  !/ 21-Jun-2007 : Dedicated output processes. ( version 3.11 )
42  !/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
43  !/ 30-Oct-2009 : Fix format statement 2945. ( version 3.14 )
44  !/ (T. J. Campbell, NRL)
45  !/ 30-Oct-2009 : Implement run-time grid selection. ( version 3.14 )
46  !/ (W. E. Rogers & T. J. Campbell, NRL)
47  !/ 13-Sep-2009 : Add coupling option ( version 3.14_SHOM )
48  !/ 30-Oct-2009 : Implement curvilinear grid type. ( version 3.14 )
49  !/ (W. E. Rogers & T. J. Campbell, NRL)
50  !/ 29-Oct-2010 : Implement unstructured grids ( version 3.14.4 )
51  !/ (A. Roland and F. Ardhuin)
52  !/ 23-Nov-2011 : Comments clean up ( version 4.04 )
53  !/ 06-Mar-2012 : Repairing test output. ( version 4.07 )
54  !/ 03-Sep-2012 : Output initialization time. ( version 4.10 )
55  !/ 27-Sep-2012 : Implement use of tidal constituents ( version 4.08 )
56  !/ 04-Feb-2014 : Switched clock to DATE_AND_TIME ( version 4.18 )
57  !/ (A. Chawla and Mark Szyszka)
58  !/ 23-Apr-2015 : Adding NCEP Coupler ( version 5.06 )
59  !/ (A. Chawla and Dmitry Sheinin)
60  !/ 24-Apr-2015 : Adding OASIS coupling calls ( version 5.07 )
61  !/ (M. Accensi & F. Ardhuin, IFREMER)
62  !/ 11-May-2015 : Checks dates for output types ( version 5.08 )
63  !/ 26-Mar-2018 : Sea-point only Wnd/Cur input. JGLi ( version 6.02 )
64  !/ 15-May-2018 : Update namelist ( version 6.05 )
65  !/ 06-Jun-2018 : Add PDLIB/MEMCHECK/NETCDF_QAD/DEBUGINIT ( version 6.04 )
66  !/ 14-Sep-2018 : Remove PALM implementation ( version 6.06 )
67  !/ 04-Oct-2019 : Inline Output implementation ( version 6.07 )
68  !/ (Roberto Padilla-Hernandez)
69  !/ 16-Jul-2020 : Variable coupling time step ( version 7.08 )
70  !/ 25-Sep-2020 : Oasis coupling at T+0 ( version 7.10 )
71  !/ 22-Mar-2021 : Add new coupling fields ( version 7.13 )
72  !/ 07-Jun-2021 : S_{nl} GKE NL5 (Q. Liu) ( version 7.13 )
73  !/ 02-Feb-2022 : Scalability local ( version 7.14 )
74  !/
75  !/ Copyright 2009-2012 National Weather Service (NWS),
76  !/ National Oceanic and Atmospheric Administration. All rights
77  !/ reserved. WAVEWATCH III is a trademark of the NWS.
78  !/ No unauthorized use without permission.
79  !/
80  ! 1. Purpose :
81  !
82  ! A generic shell for WAVEWATCH III, using preformatted
83  ! input fields.
84  !
85  ! 2. Method :
86  !
87  ! Driver for the actual wave model (W3WAVE).
88  !
89  ! Files : ww3_shel.inp Input commands for shell.
90  ! level.ww3 Water level fields (optional).
91  ! current.ww3 Current fields (optional).
92  ! wind.ww3 Wind fields (optional).
93  ! muddens.ww3 Mud parameter (optional)
94  ! mudthk.ww3 Mud parameter (optional)
95  ! mudvisc.ww3 Mud parameter (optional)
96  ! ice(n).ww3 Ice parameters (n=1 to 5) (optional)
97  ! ice.ww3 ice concentration fields (optional).
98  ! data0.ww3 Files with assimilation data (optional).
99  ! data1.ww3
100  ! data2.ww3
101  !
102  ! The file names of the input files are set in W3FLDO
103  !
104  ! 3. Parameters :
105  !
106  ! Local parameters.
107  ! ----------------------------------------------------------------
108  ! NHMAX I.P. Maximum number of homogeneous fields.
109  !
110  ! NDSI Int. General input unit number (shell only).
111  ! NDSS Int. Scratch file.
112  ! NDSO Int. General output unit number (shell only).
113  ! NDSE Int. Error output unit number (shell only).
114  ! NDST Int. Test output unit number (shell only).
115  ! NDSF I.A. Field files unit numbers (shell only).
116  ! FLH L.A. Flags for homogeneous fields.
117  ! FLAGSC L.A. Flags for coupling fields
118  ! FLAGSCI Log. Flags for ice ic1 ic5 coupling
119  ! NH I.A. Number of times for homogeneous fields.
120  ! THO I.A. Times of homogeneous fields.
121  ! TIME0 I.A. Starting time.
122  ! TIMEN I.A. Ending time.
123  ! ----------------------------------------------------------------
124  !
125  ! NDS, NTRACE, ..., see W3WAVE
126  !
127  ! 4. Subroutines used :
128  !
129  ! Name Type Module Description
130  ! ----------------------------------------------------------------
131  ! W3NMOD Subr. W3GDATMD Set nummber of data structures
132  ! W3SETG Subr. Id. Point to data structure.
133  ! W3NDAT Subr. W3WDATMD Set nummber of data structures
134  ! W3SETW Subr. Id. Point to data structure.
135  ! W3NMOD Subr. W3ADATMD Set nummber of data structures
136  ! W3NAUX Subr. Id. Point to data structure.
137  ! W3NOUT Subr. W3ODATMD Set nummber of data structures
138  ! W3SETO Subr. Id. Point to data structure.
139  ! W3NINP Subr. W3IDATMD Set nummber of data structures
140  ! W3SETI Subr. Id. Point to data structure.
141  !
142  ! NEXTLN Subr. W3SERVMD Skip to next input line.
143  ! STME21 Subr. W3TIMEMD Print date and time readable.
144  ! DSEC21 Func. Id. Difference between times.
145  ! TICK21 Subr. Id. Increment time.
146  !
147  ! W3FLDO Subr. W3FLDSMD Opens and checks input files.
148  ! W3FLDG Subr. Id. Reads from input files.
149  ! W3FLDD Subr. Id. Reads from data files.
150  ! W3FLDH Subr. Id. Udates homogeneous fields.
151  !
152  ! W3INIT Subr. W3INITMD Wave model initialization.
153  ! W3READFLGRD Subr. W3IOGOMD Reading output fields flags.
154  ! W3WAVE Subr. W3WAVEMD Wave model.
155  ! W3WDAS Subr. W3WDASMD Data assimilation interface.
156  !
157  ! MPI_INIT, MPI_COMM_SIZE, MPI_COMM_RANK, MPI_BARRIER,
158  ! MPI_FINALIZE
159  ! Subr. Standard MPI routines.
160  ! ----------------------------------------------------------------
161  !
162  ! 5. Called by :
163  !
164  ! None, stand-alone program.
165  !
166  ! 6. Error messages :
167  !
168  ! - Checks on I-O.
169  ! - Check on time interval.
170  !
171  ! 7. Remarks :
172  !
173  ! - A rigourous input check is made in W3INIT.
174  ! - See W3WDAS for documentation on the set-up of the data
175  ! assimilation.
176  ! - in "7.a.2 Check if update is needed"
177  ! Field is updated when compute time is past old input time, and
178  ! (in case of homogeneous input field), grabs field value at next
179  ! input time, which may in fact be far in the future from current
180  ! compute time. Example: user says
181  ! field=1 on 19680101 000000 and
182  ! field=100 on 20160101 000000
183  ! then on if 7.a.2 is reached on 19680101 010000, WW3 will set
184  ! field to 100.
185  !
186  ! 8. Structure :
187  !
188  ! ----------------------------------------------------------------
189  ! 0. Set up data structures. ( W3NMOD, etc. )
190  ! 1. I-O setup.
191  ! a For shell.
192  ! b For WAVEWATCH III.
193  ! c Local parameters.
194  ! 2. Define input fields
195  ! 3. Set time frame.
196  ! 4. Define output
197  ! a Loop over types, do
198  ! +--------------------------------------------------------+
199  ! | b Process standard line |
200  ! | c If type 1: fields of mean wave parameters |
201  ! | d If type 2: point output |
202  ! | e If type 3: track output |
203  ! | f If type 4: restart files |
204  ! | g If type 5: boundary output |
205  ! | h If type 6: separated wave fields |
206  ! | i If type 7: coupling fields |
207  ! +--------------------------------------------------------+
208  ! 5. Initialzations
209  ! a Wave model. ( W3INIT )
210  ! b Read homogeneous field data.
211  ! c Prepare input files. ( W3FLDO )
212  ! d Set field times.
213  ! 6. If no input fields required, run model in a single
214  ! sweep and exit. ( W3WAVE )
215  ! 7. Run model with input
216  ! Do until end time is reached
217  ! +--------------------------------------------------------+
218  ! | a Determine next time interval and input fields. |
219  ! | 1 Preparation |
220  ! | Loop over input fields |
221  ! | +------------------------------------------------------|
222  ! | | 2 Check if update is needed |
223  ! | | 3 Update time and fields ( W3FLDG ) |
224  ! | | ( W3FLDH ) |
225  ! | | 4 Update next ending time |
226  ! | +------------------------------------------------------|
227  ! | b Run wave model. ( W3WAVE ) |
228  ! | c If requested, data assimilation. ( W3WDAS ) |
229  ! | d Final output if needed. ( W3WAVE ) |
230  ! | e Check time |
231  ! +--------------------------------------------------------+
232  ! ----------------------------------------------------------------
233  !
234  ! 9. Switches :
235  !
236  ! !/SHRD Switch for shared / distributed memory architecture.
237  ! !/DIST Id.
238  ! !/MPI Id.
239  !
240  ! !/MGW Moving grid wind correction.
241  ! !/MGP Moving grid propagation correction.
242  !
243  ! !/T Enable test output.
244  ! !/O7 Echo input homogeneous fields.
245  !
246  ! !/NCO NCEP NCO modifications for operational implementation.
247  !
248  !
249  ! 10. Source code :
250  !
251  !/ ------------------------------------------------------------------- /
252 
253  use w3servmd, only : print_memcheck
254 #ifdef W3_PDLIB
255  USE constants, ONLY: lpdlib
256 #endif
257  USE w3gdatmd
258  USE w3wdatmd, ONLY: time, va, w3ndat, w3dimw, w3setw
259 #ifdef W3_OASIS
260  USE w3wdatmd, ONLY: time00, timeend
261 #endif
262 #ifdef W3_NL5
263  USE w3wdatmd, ONLY: qi5tbeg
264 #endif
265  USE w3adatmd, ONLY: w3naux, w3dima, w3seta
266  USE w3idatmd
267 #ifdef W3_OASIS
268  USE w3odatmd, ONLY: dtout, flout
269 #endif
270  USE w3odatmd, ONLY: w3nout, w3seto
271  USE w3odatmd, ONLY: naproc, iaproc, napout, naperr, nogrp, &
273  USE w3odatmd, ONLY: flogrr, flogr, ofiles
274  !/
275  USE w3fldsmd
276  USE w3initmd
277  USE w3wavemd
278  USE w3wdasmd
279  !/
280  USE w3iogrmd, ONLY: w3iogr
282  USE w3iorsmd, ONLY: oarst
283  USE w3iopomd
284  USE w3servmd, ONLY : nextln, extcde
285  USE w3timemd
286 
287 #ifdef W3_OASIS
288  USE w3oacpmd, ONLY: cpl_oasis_init, cpl_oasis_grid, &
291 #endif
292 #ifdef W3_OASOCM
293  USE w3ogcmmd, ONLY: snd_fields_to_ocean
294 #endif
295 #ifdef W3_OASACM
296  USE w3agcmmd, ONLY: snd_fields_to_atmos
297 #endif
298 #ifdef W3_OASICM
299  USE w3igcmmd, ONLY: snd_fields_to_ice
300 #endif
301 
302 #ifdef W3_TIDE
303  USE w3tidemd
304 #endif
305  !
306  USE w3nmlshelmd
307 
308 #ifdef W3_OMPG
309  USE omp_lib
310 #endif
311  IMPLICIT NONE
312  !
313 #ifdef W3_MPI
314  include "mpif.h"
315 #endif
316  !/
317  !/ ------------------------------------------------------------------- /
318  !/ Local PARAMETER statements
319  !/
320  INTEGER, PARAMETER :: nhmax = 200
321  !/
322  !/ ------------------------------------------------------------------- /
323  !/ Local parameters
324  !/
325  TYPE(nml_domain_t) :: nml_domain
326  TYPE(nml_input_t) :: nml_input
327  TYPE(nml_output_type_t) :: nml_output_type
328  TYPE(nml_output_date_t) :: nml_output_date
329  TYPE(nml_homog_count_t) :: nml_homog_count
330  TYPE(nml_homog_input_t), ALLOCATABLE :: nml_homog_input(:)
331  !
332  INTEGER :: ndsi, ndsi2, ndss, ndso, ndse, ndst, ndsl,&
333  ndsen, ierr, j, i, iloop, ipts, npts, &
334  ndtnew, mpi_comm = -99, &
335  flagtide, coupl_comm, ih, n_tot
336  INTEGER :: ndsf(-7:9), nds(15), ntrace(2), ndt(7:9), &
337  time0(2), timen(2), ttime(2), ttt(2), &
338  nh(-7:10), tho(2,-7:10,nhmax), rcld(7:9), &
339  nodata(7:9), odat(40), iprt(6) = 0, &
340  startdate(8), stopdate(8), ihh(-7:10)
341  !
342 #ifdef W3_OASIS
343  INTEGER :: oasised
344 #endif
345 #ifdef W3_COU
346  INTEGER :: ofl
347 #endif
348  INTEGER :: clkdt1(8), clkdt2(8), clkdt3(8)
349 #ifdef W3_MPI
350  INTEGER :: ierr_mpi
351 #endif
352  !
353  REAL :: factor, dttst, xx, yy, &
354  ha(nhmax,-7:10), hd(nhmax,-7:10), &
355  hs(nhmax,-7:10)
356  REAL :: clkfin, clkfel
357  REAL, ALLOCATABLE :: x(:), y(:), xxx(:,:), data0(:,:), &
358  data1(:,:), data2(:,:)
359  !
360  DOUBLE PRECISION :: startjulday, stopjulday
361  !
362  CHARACTER(LEN=1) :: comstr, flagtfc(-7:10)
363  CHARACTER(LEN=3) :: idstr(-7:10), idtst
364  CHARACTER(LEN=6) :: yesxno
365  CHARACTER(LEN=40) :: pn
366  CHARACTER(LEN=40), &
367  ALLOCATABLE :: pnames(:)
368  CHARACTER(LEN=13) :: idflds(-7:10)
369  CHARACTER(LEN=20) :: strng
370  CHARACTER(LEN=23) :: dtme21
371  CHARACTER(LEN=30) :: idotyp(8)
372  CHARACTER(LEN=80) :: line
373  CHARACTER(LEN=256) :: tmpline, test
374  CHARACTER(LEN=1024) :: fldin
375  CHARACTER(LEN=1024) :: fldrst=''
376  CHARACTER(LEN=80) :: linein
377  CHARACTER(LEN=8) :: words(7)=''
378 
379 #ifdef W3_COU
380  CHARACTER(LEN=30) :: ofile
381 #endif
382  !
383  LOGICAL :: fllstl, fllsti, fllstr, flflg, flhom, &
384  tflagi, prtfrm, flagsci, flgnml
385  LOGICAL :: flgrd(nogrp,ngrpp), flgd(nogrp), &
386  flgr2(nogrp,ngrpp), flg2(nogrp), &
387  flagstide(4), flh(-7:10), flgdas(3), &
388  fllst_all(-7:10)
389 #ifdef W3_MPI
390  LOGICAL :: flhybr = .false.
391 #endif
392 #ifdef W3_OMPH
393  INTEGER :: thrlev
394 #endif
395 #ifdef W3_OASIS
396  LOGICAL :: l_master
397  LOGICAL :: first_step = .true.
398 #endif
399  character(len=10) :: jchar
400  integer :: memunit
401  !
402  !/
403  !/ ------------------------------------------------------------------- /
404  !/
405  DATA idflds / 'ice param. 1 ' , 'ice param. 2 ' , &
406  'ice param. 3 ' , 'ice param. 4 ' , &
407  'ice param. 5 ' , &
408  'mud density ' , 'mud thkness ' , &
409  'mud viscos. ' , &
410  'water levels ' , 'currents ' , &
411  'winds ' , 'ice fields ' , &
412  'momentum ' , 'air density ' , &
413  'mean param. ' , '1D spectra ' , &
414  '2D spectra ' , 'moving grid ' /
415  DATA idotyp / 'Fields of mean wave parameters' , &
416  'Point output ' , &
417  'Track point output ' , &
418  'Restart files ' , &
419  'Nesting data ' , &
420  'Partitioned wave field data ' , &
421  'Fields for coupling ' , &
422  'Restart files second request '/
423  DATA idstr / 'IC1', 'IC2', 'IC3', 'IC4', 'IC5', 'MDN', 'MTH', &
424  'MVS', 'LEV', 'CUR', 'WND', 'ICE', 'TAU', 'RHO', &
425  'DT0', 'DT1', 'DT2', 'MOV' /
426  !
427  flgr2 = .false.
428  flagstide(:) = .false.
429  flh(:) = .false.
430  !
431 #ifdef W3_T
432  prtfrm = .true.
433 #endif
434  !
435  CALL date_and_time ( values=clkdt1 )
436  !
437  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
438  ! 0. Set up data structures
439  !
440 #ifdef W3_OASIS
441  oasised=1
442 #endif
443 #ifdef W3_PDLIB
444  lpdlib = .true.
445 #endif
446  !
447  CALL w3nmod ( 1, 6, 6 )
448  CALL w3ndat ( 6, 6 )
449  CALL w3naux ( 6, 6 )
450  CALL w3nout ( 6, 6 )
451  CALL w3ninp ( 6, 6 )
452  !
453  CALL w3setg ( 1, 6, 6 )
454  CALL w3setw ( 1, 6, 6 )
455  CALL w3seta ( 1, 6, 6 )
456  CALL w3seto ( 1, 6, 6 )
457  CALL w3seti ( 1, 6, 6 )
458 
459  memunit = 740+iaproc
460  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 1')
461  !
462 #ifdef W3_SHRD
463  naproc = 1
464  iaproc = 1
465 #endif
466  !
467 #ifdef W3_OMPH
468  flhybr = .true.
469 #endif
470 
471 #ifdef W3_OASIS
472  IF (oasised.EQ.1) THEN
473  CALL cpl_oasis_init(mpi_comm)
474  ELSE
475 #endif
476 #ifdef W3_OMPH
477  ! For hybrid MPI-OpenMP specify required thread level. JGLi06Sep2019
478  IF( flhybr ) THEN
479  CALL mpi_init_thread( mpi_thread_funneled, thrlev, ierr_mpi)
480  ELSE
481 #endif
482 #ifdef W3_MPI
483  CALL mpi_init ( ierr_mpi )
484 #endif
485 #ifdef W3_OMPH
486  ENDIF
487 #endif
488 
489 #ifdef W3_MPI
490  mpi_comm = mpi_comm_world
491 #endif
492 #ifdef W3_OASIS
493  END IF
494 #endif
495  !
496  !
497 #ifdef W3_MPI
498  CALL mpi_comm_size ( mpi_comm, naproc, ierr_mpi )
499 #endif
500 #ifdef W3_MPI
501  CALL mpi_comm_rank ( mpi_comm, iaproc, ierr_mpi )
502  iaproc = iaproc + 1
503 #endif
504  memunit = 740+iaproc
505  !
506 #ifdef W3_NCO
507  ! IF ( IAPROC .EQ. 1 ) CALL W3TAGB &
508  ! ('WAVEFCST',1998,0007,0050,'NP21 ')
509 #endif
510  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 2')
511  !
512  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
513  ! 1. IO set-up
514  ! 1.a For shell
515  !
516  ndsi = 10
517  ndss = 90
518  ndso = 6
519  ndse = 6
520  ndst = 6
521  ndsl = 50
522 #ifdef W3_COU
523  ndso = 333
524  ndse = 333
525  ndst = 333
526 #endif
527 
528 
529  ndsf(-7) = 1008
530  ndsf(-6) = 1009
531  ndsf(-5) = 1010
532  ndsf(-4) = 1011
533  ndsf(-3) = 1012
534  ndsf(-2) = 1013
535  ndsf(-1) = 1014
536  ndsf(0) = 1015
537 
538  ndsf(1) = 11
539  ndsf(2) = 12
540  ndsf(3) = 13
541  ndsf(4) = 14
542  ndsf(5) = 15
543  ndsf(6) = 16
544  ndsf(7) = 17
545  ndsf(8) = 18
546  ndsf(9) = 19
547  !
548 #ifdef W3_NCO
549  !
550  ! Redo according to NCO
551  !
552  ndsi = 11
553  ndss = 90
554  ndso = 6
555  ndse = ndso
556  ndst = ndso
557  ndsf(1) = 12
558  ndsf(2) = 13
559  ndsf(3) = 14
560  ndsf(4) = 15
561  ndsf(5) = 16
562  ndsf(6) = 17
563  ndsf(7) = 18
564  ndsf(8) = 19
565  ndsf(9) = 20
566 #endif
567  !
568  napout = 1
569  naperr = 1
570  !
571 #ifdef W3_COU
572  ofile = 'output.ww3'
573  ofl = len_trim(ofile)
574  j = len_trim(fnmpre)
575  IF ( iaproc .EQ. napout ) &
576  OPEN (333,file=fnmpre(:j)//ofile(:ofl),err=2008,iostat=ierr)
577 #endif
578 
579  IF ( iaproc .EQ. napout ) WRITE (ndso,900)
580  !
581  IF ( iaproc .EQ. naperr ) THEN
582  ndsen = ndse
583  ELSE
584  ndsen = -1
585  END IF
586 #ifdef W3_OMPH
587  IF ( iaproc .EQ. napout ) WRITE (ndso,905) &
588  mpi_thread_funneled, thrlev
589 #endif
590  !
591 #ifdef W3_OMPG
592  IF(iaproc .EQ. napout) THEN
593  WRITE(ndso, 906) omp_get_max_threads()
594  ENDIF
595 #endif
596 
597  !
598  ! 1.b For WAVEWATCH III (See W3INIT)
599  !
600  nds( 1) = 20
601  nds( 2) = 6
602  nds( 3) = 21
603  nds( 4) = 6
604  nds( 5) = 30
605  nds( 6) = 30
606  nds( 7) = 31
607  nds( 8) = 32
608  nds( 9) = 33
609  nds(10) = 35
610  nds(11) = 22
611  nds(12) = 23
612  nds(13) = 34
613  nds(14) = 36
614  nds(15) = 37
615 
616  !
617  ntrace(1) = nds(3)
618  ntrace(2) = 10
619  !
620 #ifdef W3_NCO
621  !
622  ! Redo according to NCO
623  !
624  nds( 1) = 51
625  nds( 2) = ndso
626  nds( 3) = ndso
627  nds( 4) = ndso
628  nds( 5) = 20
629  nds( 6) = 21
630  nds( 7) = 52
631  nds( 8) = 53
632  nds( 9) = 22
633  nds(10) = 71
634  nds(11) = 23
635  nds(12) = 54
636  nds(13) = 55
637  ntrace(1) = ndso
638 #endif
639  !
640 #ifdef W3_T
641  WRITE (ndst,9000) (nds(i),i=1,12)
642  WRITE (ndst,9001) (ntrace(i),i=1,2)
643 #endif
644  !
645  ! 1.c Local parameters
646  !
647  ! Default COMSTR to "$" (for when using nml input files)
648  comstr = "$"
649  !
650  ! inferred from context: these flags (FL) are to indicate that the last (LST)
651  ! field has been read from a file.
652  fllstl = .false. ! This is associated with J.EQ.1 (wlev)
653  fllsti = .false. ! This is associated with J.EQ.4 (ice)
654  fllstr = .false. ! This is associated with J.EQ.6 (rhoa)
655  fllst_all = .false. ! For all
656 
657  ! If using experimental mud or ice physics, additional lines will
658  ! be read in from ww3_shel.inp and applied, so JFIRST is changed from
659  ! its initialization setting "JFIRST=1" to some lower value.
660 #ifdef W3_IC1
661  jfirst=-7
662 #endif
663 #ifdef W3_IC2
664  jfirst=-7
665 #endif
666 #ifdef W3_IS2
667  jfirst=-7
668 #endif
669 #ifdef W3_IC3
670  jfirst=-7
671 #endif
672 #ifdef W3_BT8
673  jfirst=-7
674 #endif
675 #ifdef W3_BT9
676  jfirst=-7
677 #endif
678 #ifdef W3_IC4
679  jfirst=-7
680 #endif
681 #ifdef W3_IC5
682  jfirst=-7
683 #endif
684 
685  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 2a')
686  !
687  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
688  ! 2. Define input fields
689  !
690 
691  !
692  ! process ww3_prnc namelist
693  !
694  INQUIRE(file=trim(fnmpre)//"ww3_shel.nml", exist=flgnml)
695  IF (flgnml) THEN
696  ! Read namelist
697  CALL w3nmlshel (mpi_comm, ndsi, trim(fnmpre)//'ww3_shel.nml', &
698  nml_domain, nml_input, nml_output_type, &
699  nml_output_date, nml_homog_count, &
700  nml_homog_input, ierr)
701 
702  ! 2.1 forcing flags
703 
704  flh(-7:10)=.false.
705  flagtfc(-7)=trim(nml_input%FORCING%ICE_PARAM1)
706  flagtfc(-6)=trim(nml_input%FORCING%ICE_PARAM2)
707  flagtfc(-5)=trim(nml_input%FORCING%ICE_PARAM3)
708  flagtfc(-4)=trim(nml_input%FORCING%ICE_PARAM4)
709  flagtfc(-3)=trim(nml_input%FORCING%ICE_PARAM5)
710  flagtfc(-2)=trim(nml_input%FORCING%MUD_DENSITY)
711  flagtfc(-1)=trim(nml_input%FORCING%MUD_THICKNESS)
712  flagtfc(0)=trim(nml_input%FORCING%MUD_VISCOSITY)
713  flagtfc(1)=trim(nml_input%FORCING%WATER_LEVELS)
714  flagtfc(2)=trim(nml_input%FORCING%CURRENTS)
715  flagtfc(3)=trim(nml_input%FORCING%WINDS)
716  flagtfc(4)=trim(nml_input%FORCING%ICE_CONC)
717  flagtfc(5)=trim(nml_input%FORCING%ATM_MOMENTUM)
718  flagtfc(6)=trim(nml_input%FORCING%AIR_DENSITY)
719  flagtfc(7)=trim(nml_input%ASSIM%MEAN)
720  flagtfc(8)=trim(nml_input%ASSIM%SPEC1D)
721  flagtfc(9)=trim(nml_input%ASSIM%SPEC2D)
722 
723  IF (trim(nml_input%FORCING%ICE_PARAM1) .EQ. 'H') THEN
724  flagtfc(-7)='T'
725  flh(-7)=.true.
726  END IF
727  IF (trim(nml_input%FORCING%ICE_PARAM2) .EQ. 'H') THEN
728  flagtfc(-6)='T'
729  flh(-6)=.true.
730  END IF
731  IF (trim(nml_input%FORCING%ICE_PARAM3) .EQ. 'H') THEN
732  flagtfc(-5)='T'
733  flh(-5)=.true.
734  END IF
735  IF (trim(nml_input%FORCING%ICE_PARAM4) .EQ. 'H') THEN
736  flagtfc(-4)='T'
737  flh(-4)=.true.
738  END IF
739  IF (trim(nml_input%FORCING%ICE_PARAM5) .EQ. 'H') THEN
740  flagtfc(-3)='T'
741  flh(-3)=.true.
742  END IF
743  IF (trim(nml_input%FORCING%MUD_DENSITY) .EQ. 'H') THEN
744  flagtfc(-2)='T'
745  flh(-2)=.true.
746  END IF
747  IF (trim(nml_input%FORCING%MUD_THICKNESS) .EQ. 'H') THEN
748  flagtfc(-1)='T'
749  flh(-1)=.true.
750  END IF
751  IF (trim(nml_input%FORCING%MUD_VISCOSITY) .EQ. 'H') THEN
752  flagtfc(0)='T'
753  flh(0)=.true.
754  END IF
755  IF (trim(nml_input%FORCING%WATER_LEVELS) .EQ. 'H') THEN
756  flagtfc(1)='T'
757  flh(1)=.true.
758  END IF
759  IF (trim(nml_input%FORCING%CURRENTS) .EQ. 'H') THEN
760  flagtfc(2)='T'
761  flh(2)=.true.
762  END IF
763  IF (trim(nml_input%FORCING%WINDS) .EQ. 'H') THEN
764  flagtfc(3)='T'
765  flh(3)=.true.
766  END IF
767  IF (trim(nml_input%FORCING%ICE_CONC) .EQ. 'H') THEN
768  flagtfc(4)='T'
769  flh(4)=.true.
770  END IF
771  IF (trim(nml_input%FORCING%ATM_MOMENTUM) .EQ. 'H') THEN
772  flagtfc(5)='T'
773  flh(5)=.true.
774  END IF
775  IF (trim(nml_input%FORCING%AIR_DENSITY) .EQ. 'H') THEN
776  flagtfc(6)='T'
777  flh(6)=.true.
778  END IF
779 
780  IF ( iaproc .EQ. napout ) WRITE (ndso,920)
781  DO j=jfirst, 9
782  IF (flagtfc(j).EQ.'T') THEN
783  inflags1(j)=.true.
784  flagsc(j)=.false.
785  END IF
786  IF (flagtfc(j).EQ.'F') THEN
787  inflags1(j)=.false.
788  flagsc(j)=.false.
789  END IF
790  IF (flagtfc(j).EQ.'C') THEN
791  inflags1(j)=.true.
792  flagsc(j)=.true.
793  END IF
794  IF ( j .LE. 6 ) THEN
795  flh(j) = flh(j) .AND. inflags1(j)
796  END IF
797  IF ( inflags1(j) ) THEN
798  yesxno = 'YES/--'
799  ELSE
800  yesxno = '---/NO'
801  END IF
802  IF ( flh(j) ) THEN
803  strng = '(homogeneous field) '
804  ELSE IF ( flagsc(j) ) THEN
805  strng = '(coupling field) '
806  ELSE
807  strng = ' '
808  END IF
809  IF ( iaproc .EQ. napout ) WRITE (ndso,921) idflds(j), yesxno, strng
810  END DO
811 #ifdef W3_COU
812  IF (flagsc(1) .AND. inflags1(2) .AND. .NOT. flagsc(2)) GOTO 2102
813  IF (flagsc(2) .AND. inflags1(1) .AND. .NOT. flagsc(1)) GOTO 2102
814 #endif
815 
816  inflags1(10) = .false.
817 #ifdef W3_MGW
818  inflags1(10) = .true.
819 #endif
820 #ifdef W3_MGP
821  inflags1(10) = .true.
822 #endif
823 #ifdef W3_MGW
824  flh(10) = .true.
825 #endif
826 #ifdef W3_MGP
827  flh(10) = .true.
828 #endif
829  IF ( inflags1(10) .AND. iaproc.EQ.napout ) &
830  WRITE (ndso,921) idflds(10), 'YES/--', ' '
831  !
832  flflg = inflags1(-7) .OR. inflags1(-6) .OR. inflags1(-5) .OR. inflags1(-4) &
833  .OR. inflags1(-3) .OR. inflags1(-2) .OR. inflags1(-1) &
834  .OR. inflags1(0) .OR. inflags1(1) .OR. inflags1(2) &
835  .OR. inflags1(3) .OR. inflags1(4) .OR. inflags1(5) &
836  .OR. inflags1(6) .OR. inflags1(7) .OR. inflags1(8) &
837  .OR. inflags1(9)
838  flhom = flh(-7) .OR. flh(-6) .OR. flh(-5) .OR. flh(-4) &
839  .OR. flh(-3) .OR. flh(-2) .OR. flh(-1) .OR. flh(0) &
840  .OR. flh(1) .OR. flh(2) .OR. flh(3) .OR. flh(4) &
841  .OR. flh(5) .OR. flh(6) .OR. flh(10)
842  !
843  IF ( iaproc .EQ. napout ) WRITE (ndso,922)
844  !
845  ! INFLAGS2 is just "initial value of INFLAGS1", i.e. does *not* get
846  ! changed when model reads last record of ice.ww3
848 
849 #ifdef W3_T
850  WRITE (ndst,9020) flflg, inflags1, flhom, flh
851 #endif
852 
853 
854 
855  ! 2.2 Time setup
856 
857  READ(nml_domain%START,*) time0
858  CALL t2d(time0,startdate,ierr)
859  CALL d2j(startdate,startjulday,ierr)
860  READ(nml_domain%STOP,*) timen
861  CALL t2d(timen,stopdate,ierr)
862  CALL d2j(stopdate,stopjulday,ierr)
863 
864  ! 2.3 Domain setup
865 
866  iostyp = nml_domain%IOSTYP
867 
868 #ifdef W3_PDLIB
869  IF (iostyp .gt. 1) THEN
870  WRITE(*,*) 'IOSTYP not supported in domain decomposition mode'
871  CALL extcde ( 6666 )
872  ENDIF
873 #endif
874 
875  CALL w3iogr ( 'GRID', ndsf(7) )
876  IF ( flagll ) THEN
877  factor = 1.
878  ELSE
879  factor = 1.e-3
880  END IF
881 
882  ! 2.4 Output dates
883 
884  READ(nml_output_date%FIELD%START, *) odat(1), odat(2)
885  READ(nml_output_date%FIELD%STRIDE, *) odat(3)
886  READ(nml_output_date%FIELD%STOP, *) odat(4), odat(5)
887 
888  READ(nml_output_date%FIELD%OUTFFILE, *) ofiles(1)
889  ! OUTPTS(I)%OUTSTRIDE(1)=ODAT(3,I)
890 
891  READ(nml_output_date%POINT%START, *) odat(6), odat(7)
892  READ(nml_output_date%POINT%STRIDE, *) odat(8)
893  READ(nml_output_date%POINT%STOP, *) odat(9), odat(10)
894 
895  READ(nml_output_date%POINT%OUTFFILE, *) ofiles(2)
896  ! OUTPTS(I)%OUTSTRIDE(2)=ODAT(8,I)
897 
898  READ(nml_output_date%TRACK%START, *) odat(11), odat(12)
899  READ(nml_output_date%TRACK%STRIDE, *) odat(13)
900  READ(nml_output_date%TRACK%STOP, *) odat(14), odat(15)
901  READ(nml_output_date%RESTART%START, *) odat(16), odat(17)
902  READ(nml_output_date%RESTART%STRIDE, *) odat(18)
903  READ(nml_output_date%RESTART%STOP, *) odat(19), odat(20)
904  READ(nml_output_date%RESTART2%START, *) odat(36), odat(37)
905  READ(nml_output_date%RESTART2%STRIDE, *) odat(38)
906  READ(nml_output_date%RESTART2%STOP, *) odat(39), odat(40)
907  READ(nml_output_date%BOUNDARY%START, *) odat(21), odat(22)
908  READ(nml_output_date%BOUNDARY%STRIDE, *) odat(23)
909  READ(nml_output_date%BOUNDARY%STOP, *) odat(24), odat(25)
910  READ(nml_output_date%PARTITION%START, *) odat(26), odat(27)
911  READ(nml_output_date%PARTITION%STRIDE, *) odat(28)
912  READ(nml_output_date%PARTITION%STOP, *) odat(29), odat(30)
913  READ(nml_output_date%COUPLING%START, *) odat(31), odat(32)
914  READ(nml_output_date%COUPLING%STRIDE, *) odat(33)
915  READ(nml_output_date%COUPLING%STOP, *) odat(34), odat(35)
916 
917  ! set the time stride at 0 or more
918  odat(3) = max( 0 , odat(3) )
919  odat(8) = max( 0 , odat(8) )
920  odat(13) = max( 0 , odat(13) )
921  odat(18) = max( 0 , odat(18) )
922  odat(23) = max( 0 , odat(23) )
923  odat(28) = max( 0 , odat(28) )
924  odat(33) = max( 0 , odat(33) )
925  odat(38) = max( 0 , odat(38) )
926  !
927 #ifdef W3_COU
928  ! Test the validity of the coupling time step
929  IF (odat(33) == 0) THEN
930  IF ( iaproc .EQ. napout ) THEN
931  WRITE(ndso,1010) odat(33), int(dtmax)
932  END IF
933  odat(33) = int(dtmax)
934  ELSE IF (mod(odat(33),int(dtmax)) .NE. 0) THEN
935  GOTO 2009
936  END IF
937 #endif
938  !
939  ! 2.5 Output types
940 
941  npts = 0
942  notype = 6
943 #ifdef W3_COU
944  notype = 7
945 #endif
946  DO j = 1, notype
947  ! OUTPTS(I)%OFILES(J)=OFILES(J)
948  IF ( odat(5*(j-1)+3) .NE. 0 ) THEN
949 
950  ! Type 1: fields of mean wave parameters
951  IF ( j .EQ. 1 ) THEN
952  fldout = nml_output_type%FIELD%LIST
953  CALL w3flgrdflag ( ndso, ndso, ndse, fldout, flgd, &
954  flgrd, iaproc, napout, ierr )
955  IF ( ierr .NE. 0 ) GOTO 2222
956 
957 
958  ! Type 2: point output
959  ELSE IF ( j .EQ. 2 ) THEN
960  OPEN (ndsl, file=trim(fnmpre)//trim(nml_output_type%POINT%FILE), &
961  form='FORMATTED', status='OLD', err=2104, iostat=ierr)
962 
963  ! first loop to count the number of points
964  ! second loop to allocate the array and store the points
965  ipts = 0
966  DO iloop=1,2
967  rewind(ndsl)
968  !
969  IF ( iloop.EQ.2) THEN
970  npts = ipts
971  IF ( npts.GT.0 ) THEN
972  ALLOCATE ( x(npts), y(npts), pnames(npts) )
973  ipts = 0 ! reset counter to be reused for next do loop
974  ELSE
975  ALLOCATE ( x(1), y(1), pnames(1) )
976  GOTO 2054
977  END IF
978  END IF
979  !
980  DO
981  READ (ndsl,*,err=2004,iostat=ierr) tmpline
982  ! if end of file or stopstring, then exit
983  IF ( ierr.NE.0 .OR. index(tmpline,"STOPSTRING").NE.0 ) EXIT
984  ! leading blanks removed and placed on the right
985  test = adjustl( tmpline )
986  IF ( test(1:1).EQ.comstr .OR. len_trim(test).EQ.0 ) THEN
987  ! if comment or blank line, then skip
988  cycle
989  ELSE
990  ! otherwise, backup to beginning of line
991  backspace( ndsl, err=2004, iostat=ierr)
992  READ (ndsl,*,err=2004,iostat=ierr) xx, yy, pn
993  END IF
994  ipts = ipts + 1
995  IF ( iloop .EQ. 1 ) cycle
996  IF ( iloop .EQ. 2 ) THEN
997  x(ipts) = xx
998  y(ipts) = yy
999  pnames(ipts) = pn
1000  IF ( iaproc .EQ. napout ) THEN
1001  IF ( flagll ) THEN
1002  IF ( ipts .EQ. 1 ) THEN
1003  WRITE (ndso,2945) &
1004  factor*xx, factor*yy, pn
1005  ELSE
1006  WRITE (ndso,2946) ipts, &
1007  factor*xx, factor*yy, pn
1008  END IF
1009  ELSE
1010  IF ( ipts .EQ. 1 ) THEN
1011  WRITE (ndso,2955) &
1012  factor*xx, factor*yy, pn
1013  ELSE
1014  WRITE (ndso,2956) ipts, &
1015  factor*xx, factor*yy, pn
1016  END IF
1017  END IF
1018  END IF
1019  END IF ! ILOOP.EQ.2
1020  END DO ! end of file
1021  END DO ! ILOOP
1022  CLOSE(ndsl)
1023 
1024  ! Type 3: track output
1025  ELSE IF ( j .EQ. 3 ) THEN
1026  tflagi = nml_output_type%TRACK%FORMAT
1027  IF ( .NOT. tflagi ) nds(11) = -nds(11)
1028  IF ( iaproc .EQ. napout ) THEN
1029  IF ( .NOT. tflagi ) THEN
1030  WRITE (ndso,3945) 'input', 'UNFORMATTED'
1031  ELSE
1032  WRITE (ndso,3945) 'input', 'FORMATTED'
1033  END IF
1034  END IF
1035 
1036  ! Type 6: partitioning
1037  ELSE IF ( j .EQ. 6 ) THEN
1038  iprt(1) = nml_output_type%PARTITION%X0
1039  iprt(2) = nml_output_type%PARTITION%XN
1040  iprt(3) = nml_output_type%PARTITION%NX
1041  iprt(4) = nml_output_type%PARTITION%Y0
1042  iprt(5) = nml_output_type%PARTITION%YN
1043  iprt(6) = nml_output_type%PARTITION%NY
1044  prtfrm = nml_output_type%PARTITION%FORMAT
1045  !
1046  IF ( iaproc .EQ. napout ) THEN
1047  IF ( prtfrm ) THEN
1048  yesxno = 'YES/--'
1049  ELSE
1050  yesxno = '---/NO'
1051  END IF
1052  WRITE (ndso,6945) iprt, yesxno
1053  END IF
1054 
1055 #ifdef W3_COU
1056  ! Type 7: coupling
1057  ELSE IF ( j .EQ. 7 ) THEN
1058  fldout = nml_output_type%COUPLING%SENT
1059  CALL w3flgrdflag ( ndso, ndso, ndse, fldout, flg2, &
1060  flgr2, iaproc, napout, ierr )
1061  IF ( ierr .NE. 0 ) GOTO 2222
1062  fldin = nml_output_type%COUPLING%RECEIVED
1063  cplt0 = nml_output_type%COUPLING%COUPLET0
1064 #endif
1065 
1066  END IF ! J
1067  END IF ! ODAT
1068  END DO ! J
1069 
1070  ! Extra fields to be written in the restart
1071  fldrst = nml_output_type%RESTART%EXTRA
1072  CALL w3flgrdflag ( ndso, ndso, ndse, fldrst, flogr, &
1073  flogrr, iaproc, napout, ierr )
1074  IF ( ierr .NE. 0 ) GOTO 2222
1075 
1076  ! force minimal allocation to avoid memory seg fault
1077  IF ( .NOT.ALLOCATED(x) .AND. npts.EQ.0 ) ALLOCATE ( x(1), y(1), pnames(1) )
1078 
1079  ! 2.6 Homogeneous field data
1080 
1081  IF ( flhom ) THEN
1082  IF ( iaproc .EQ. napout ) WRITE (ndso,951) &
1083  'Homogeneous field data (and moving grid) ...'
1084 
1085  nh(-7) = nml_homog_count%N_IC1
1086  nh(-6) = nml_homog_count%N_IC2
1087  nh(-5) = nml_homog_count%N_IC3
1088  nh(-4) = nml_homog_count%N_IC4
1089  nh(-3) = nml_homog_count%N_IC5
1090  nh(-2) = nml_homog_count%N_MDN
1091  nh(-1) = nml_homog_count%N_MTH
1092  nh(0) = nml_homog_count%N_MVS
1093  nh(1) = nml_homog_count%N_LEV
1094  nh(2) = nml_homog_count%N_CUR
1095  nh(3) = nml_homog_count%N_WND
1096  nh(4) = nml_homog_count%N_ICE
1097  nh(5) = nml_homog_count%N_TAU
1098  nh(6) = nml_homog_count%N_RHO
1099  nh(10) = nml_homog_count%N_MOV
1100  !
1101  n_tot = nml_homog_count%N_TOT
1102  !
1103  DO j=jfirst,10
1104  IF ( nh(j) .GT. nhmax ) GOTO 2006
1105  END DO
1106 
1107 
1108  ! Store homogeneous fields
1109  IF ( n_tot .GT. 0 ) THEN
1110  ihh(:)=0
1111  DO ih=1,n_tot
1112  READ(nml_homog_input(ih)%NAME,*) idtst
1113  SELECT CASE (idtst)
1114  CASE ('IC1')
1115  j=-7
1116  CASE ('IC2')
1117  j=-6
1118  CASE ('IC3')
1119  j=-5
1120  CASE ('IC4')
1121  j=-4
1122  CASE ('IC5')
1123  j=-3
1124  CASE ('MDN')
1125  j=-2
1126  CASE ('MTH')
1127  j=-1
1128  CASE ('MVS')
1129  j=0
1130  CASE ('LEV')
1131  j=1
1132  CASE ('CUR')
1133  j=2
1134  CASE ('WND')
1135  j=3
1136  CASE ('ICE')
1137  j=4
1138  CASE ('TAU')
1139  j=5
1140  CASE ('RHO')
1141  j=6
1142  CASE ('MOV')
1143  j=10
1144  CASE DEFAULT
1145  GOTO 2062
1146  END SELECT
1147  ihh(j)=ihh(j)+1
1148  READ(nml_homog_input(ih)%DATE,*) tho(:,j,ihh(j))
1149  ha(ihh(j),j) = nml_homog_input(ih)%VALUE1
1150  hd(ihh(j),j) = nml_homog_input(ih)%VALUE2
1151  hs(ihh(j),j) = nml_homog_input(ih)%VALUE3
1152  END DO
1153  END IF
1154 
1155 #ifdef W3_O7
1156  DO j=jfirst, 10
1157  IF ( flh(j) .AND. iaproc.EQ.napout ) THEN
1158  WRITE (ndso,952) nh(j), idflds(j)
1159  DO i=1, nh(j)
1160  IF ( ( j .LE. 1 ) .OR. ( j .EQ. 4 ) .OR. &
1161  ( j .EQ. 6 ) ) THEN
1162  WRITE (ndso,953) i, tho(1,j,i), tho(2,j,i), &
1163  ha(i,j)
1164  ELSE IF ( ( j .EQ. 2 ) .OR. ( j .EQ. 5 ) .OR. &
1165  ( j .EQ. 10 ) ) THEN
1166  WRITE (ndso,953) i, tho(1,j,i), tho(2,j,i), &
1167  ha(i,j), hd(i,j)
1168  ELSE IF ( j .EQ. 3 ) THEN
1169  WRITE (ndso,953) i, tho(1,j,i), tho(2,j,i), &
1170  ha(i,j), hd(i,j), hs(i,j)
1171  END IF
1172  END DO
1173  END IF
1174  END DO
1175 #endif
1176  !
1177  IF ( ( flh(-7) .AND. (nh(-7).EQ.0) ) .OR. &
1178  ( flh(-6) .AND. (nh(-6).EQ.0) ) .OR. &
1179  ( flh(-5) .AND. (nh(-5).EQ.0) ) .OR. &
1180  ( flh(-4) .AND. (nh(-4).EQ.0) ) .OR. &
1181  ( flh(-3) .AND. (nh(-3).EQ.0) ) .OR. &
1182  ( flh(-2) .AND. (nh(-2).EQ.0) ) .OR. &
1183  ( flh(-1) .AND. (nh(-1).EQ.0) ) .OR. &
1184  ( flh(0) .AND. (nh(0).EQ.0) ) .OR. &
1185  ( flh(1) .AND. (nh(1).EQ.0) ) .OR. &
1186  ( flh(2) .AND. (nh(2).EQ.0) ) .OR. &
1187  ( flh(3) .AND. (nh(3).EQ.0) ) .OR. &
1188  ( flh(4) .AND. (nh(4).EQ.0) ) .OR. &
1189  ( flh(5) .AND. (nh(5).EQ.0) ) .OR. &
1190  ( flh(6) .AND. (nh(6).EQ.0) ) .OR. &
1191  ( flh(10) .AND. (nh(10).EQ.0) ) ) GOTO 2007
1192  !
1193  END IF ! FLHOM
1194 
1195 
1196  END IF ! FLGNML
1197 
1198 
1199 
1200  !
1201  ! process old ww3_shel.inp format
1202  !
1203  IF (.NOT. flgnml) THEN
1204 
1205  OPEN (ndsi,file=trim(fnmpre)//'ww3_shel.inp',status='OLD',iostat=ierr)
1206  rewind(ndsi)
1207  !AR: I changed the error handling for err=2002, see commit message ...
1208  READ (ndsi,'(A)') comstr
1209  IF (comstr.EQ.' ') comstr = '$'
1210  IF ( iaproc .EQ. napout ) WRITE (ndso,901) comstr
1211 
1212  ! 2.1 forcing flags
1213 
1214  flh(-7:10) = .false.
1215  DO j=jfirst, 9
1216  CALL nextln ( comstr , ndsi , ndsen )
1217  IF ( j .LE. 6 ) THEN
1218  READ (ndsi,*) flagtfc(j), flh(j)
1219  ELSE
1220  READ (ndsi,*) flagtfc(j)
1221  END IF
1222  END DO
1223 
1224  IF ( iaproc .EQ. napout ) WRITE (ndso,920)
1225  DO j=jfirst, 9
1226  IF (flagtfc(j).EQ.'T') THEN
1227  inflags1(j)=.true.
1228  flagsc(j)=.false.
1229  END IF
1230  IF (flagtfc(j).EQ.'F') THEN
1231  inflags1(j)=.false.
1232  flagsc(j)=.false.
1233  END IF
1234  IF (flagtfc(j).EQ.'C') THEN
1235  inflags1(j)=.true.
1236  flagsc(j)=.true.
1237  END IF
1238  IF ( j .LE. 6 ) THEN
1239  flh(j) = flh(j) .AND. inflags1(j)
1240  END IF
1241  IF ( inflags1(j) ) THEN
1242  yesxno = 'YES/--'
1243  ELSE
1244  yesxno = '---/NO'
1245  END IF
1246  IF ( flh(j) ) THEN
1247  strng = '(homogeneous field) '
1248  ELSE IF ( flagsc(j) ) THEN
1249  strng = '(coupling field) '
1250  ELSE
1251  strng = ' '
1252  END IF
1253  IF ( iaproc .EQ. napout ) WRITE (ndso,921) idflds(j), yesxno, strng
1254  END DO
1255 #ifdef W3_COU
1256  IF (flagsc(1) .AND. inflags1(2) .AND. .NOT. flagsc(2)) GOTO 2102
1257  IF (flagsc(2) .AND. inflags1(1) .AND. .NOT. flagsc(1)) GOTO 2102
1258 #endif
1259  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 2b')
1260  !
1261  inflags1(10) = .false.
1262 #ifdef W3_MGW
1263  inflags1(10) = .true.
1264 #endif
1265 #ifdef W3_MGP
1266  inflags1(10) = .true.
1267 #endif
1268 #ifdef W3_MGW
1269  flh(10) = .true.
1270 #endif
1271 #ifdef W3_MGP
1272  flh(10) = .true.
1273 #endif
1274  IF ( inflags1(10) .AND. iaproc.EQ.napout ) &
1275  WRITE (ndso,921) idflds(10), 'YES/--', ' '
1276  !
1277  flflg = inflags1(-7) .OR. inflags1(-6) .OR. inflags1(-5) .OR. inflags1(-4) &
1278  .OR. inflags1(-3) .OR. inflags1(-2) .OR. inflags1(-1) &
1279  .OR. inflags1(0) .OR. inflags1(1) .OR. inflags1(2) &
1280  .OR. inflags1(3) .OR. inflags1(4) .OR. inflags1(5) &
1281  .OR. inflags1(6) .OR. inflags1(7) .OR. inflags1(8) &
1282  .OR. inflags1(9)
1283  flhom = flh(-7) .OR. flh(-6) .OR. flh(-5) .OR. flh(-4) &
1284  .OR. flh(-3) .OR. flh(-2) .OR. flh(-1) .OR. flh(0) &
1285  .OR. flh(1) .OR. flh(2) .OR. flh(3) .OR. flh(4) &
1286  .OR. flh(5) .OR. flh(6) .OR. flh(10)
1287  !
1288  IF ( iaproc .EQ. napout ) WRITE (ndso,922)
1289  !
1290  ! INFLAGS2 is just "initial value of INFLAGS1", i.e. does *not* get
1291  ! changed when model reads last record of ice.ww3
1293 
1294 #ifdef W3_T
1295  WRITE (ndst,9020) flflg, inflags1, flhom, flh
1296 #endif
1297 
1298 
1299  ! 2.2 Time setup
1300 
1301  CALL nextln ( comstr , ndsi , ndsen )
1302  READ (ndsi,*) time0
1303  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 2c')
1304 
1305  CALL nextln ( comstr , ndsi , ndsen )
1306  READ (ndsi,*) timen
1307  !
1308  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 2d')
1309 
1310  ! 2.3 Domain setup
1311 
1312  CALL nextln ( comstr , ndsi , ndsen )
1313  READ (ndsi,*) iostyp
1314 #ifdef W3_PDLIB
1315  IF (iostyp .gt. 1) THEN
1316  WRITE(*,*) 'IOSTYP not supported in domain decomposition mode'
1317  CALL extcde ( 6666 )
1318  ENDIF
1319 #endif
1320  CALL w3iogr ( 'GRID', ndsf(7) )
1321  IF ( flagll ) THEN
1322  factor = 1.
1323  ELSE
1324  factor = 1.e-3
1325  END IF
1326 
1327 
1328  ! 2.4 Output dates
1329 
1330  npts = 0
1331  notype = 6
1332 #ifdef W3_COU
1333  notype = 7
1334 #endif
1335  DO j = 1, notype
1336  CALL nextln ( comstr , ndsi , ndsen )
1337  !
1338  ! CHECKPOINT
1339  IF(j .EQ. 4) THEN
1340  odat(38)=0
1341  words(1:7)=''
1342  READ (ndsi,'(A)') linein
1343  READ(linein,*,iostat=ierr) words
1344  READ(words( 1 ), * ) odat(16)
1345  READ(words( 2 ), * ) odat(17)
1346  READ(words( 3 ), * ) odat(18)
1347  READ(words( 4 ), * ) odat(19)
1348  READ(words( 5 ), * ) odat(20)
1349  IF (words(6) .EQ. 'T') THEN
1350  CALL nextln ( comstr , ndsi , ndsen )
1351  READ (ndsi,*,END=2001,ERR=2002)(ODAT(I),I=5*(8-1)+1,5*8)
1352  WRITE(*,*)(odat(i),i=5*(8-1)+1,5*8)
1353  END IF
1354  IF (words(7) .EQ. 'T') THEN
1355  CALL nextln ( comstr , ndsi , ndsen )
1356  READ (ndsi,'(A)',END=2001,ERR=2002) fldrst
1357  END IF
1358  CALL w3flgrdflag ( ndso, ndso, ndse, fldrst, flogr, &
1359  flogrr, iaproc, napout, ierr )
1360  IF ( ierr .NE. 0 ) GOTO 2222
1361  ELSE
1362  !
1363  !INLINE NEW VARIABLE TO READ IF PRESENT OFILES(J), IF NOT ==0
1364  ! READ (NDSI,*) (ODAT(I),I=5*(J-1)+1,5*J)
1365  ! READ (NDSI,*,IOSTAT=IERR) (ODAT(I),I=5*(J-1)+1,5*J),OFILES(J)
1366  IF(j .LE. 2) THEN
1367  words(1:6)=''
1368  ! READ (NDSI,*,END=2001,ERR=2002)(ODAT(I),I=5*(J-1)+1,5*J),OFILES(J)
1369  READ (ndsi,'(A)') linein
1370  READ(linein,*,iostat=ierr) words
1371  !
1372  IF(j .EQ. 1) THEN
1373  READ(words( 1 ), * ) odat(1)
1374  READ(words( 2 ), * ) odat(2)
1375  READ(words( 3 ), * ) odat(3)
1376  READ(words( 4 ), * ) odat(4)
1377  READ(words( 5 ), * ) odat(5)
1378  ELSE
1379  READ(words( 1 ), * ) odat(6)
1380  READ(words( 2 ), * ) odat(7)
1381  READ(words( 3 ), * ) odat(8)
1382  READ(words( 4 ), * ) odat(9)
1383  READ(words( 5 ), * ) odat(10)
1384  END IF
1385 
1386  IF (words(6) .NE. '0' .AND. words(6) .NE. '1') THEN
1387  ofiles(j)=0
1388  ELSE
1389  READ(words( 6 ), * ) ofiles(j)
1390  END IF
1391 
1392 
1393 #ifdef W3_COU
1394  ELSE IF(j .EQ. 7) THEN
1395  words(1:6)=''
1396  READ (ndsi,'(A)') linein
1397  READ(linein,*,iostat=ierr) words
1398 
1399  READ(words( 1 ), * ) odat(31)
1400  READ(words( 2 ), * ) odat(32)
1401  READ(words( 3 ), * ) odat(33)
1402  READ(words( 4 ), * ) odat(34)
1403  READ(words( 5 ), * ) odat(35)
1404 
1405  IF (words(6) .EQ. 'T') THEN
1406  cplt0 = .true.
1407  ELSE
1408  cplt0 = .false.
1409  END IF
1410 #endif
1411  ELSE
1412  ofiles(j)=0
1413  READ (ndsi,*,END=2001,ERR=2002)(ODAT(I),I=5*(J-1)+1,5*J)
1414  END IF
1415  ! WRITE(*,*) 'OFILES(J)= ', OFILES(J),J
1416  !
1417  odat(5*(j-1)+3) = max( 0 , odat(5*(j-1)+3) )
1418  !
1419  write(jchar, '(i0)') j
1420  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL NOTTYPE '//trim(jchar))
1421  !
1422  ! 2.5 Output types
1423 
1424  IF ( odat(5*(j-1)+3) .NE. 0 ) THEN
1425 
1426  ! Type 1: fields of mean wave parameters
1427  IF ( j .EQ. 1 ) THEN
1428  CALL w3readflgrd ( ndsi, ndso, 9, ndsen, comstr, flgd, &
1429  flgrd, iaproc, napout, ierr )
1430  IF ( ierr .NE. 0 ) GOTO 2222
1431 
1432 
1433 
1434  ! Type 2: point output
1435  ELSE IF ( j .EQ. 2 ) THEN
1436  DO iloop=1,2
1437  IF ( iloop .EQ. 1 ) THEN
1438  ndsi2 = ndsi
1439  IF ( iaproc .EQ. 1 ) OPEN &
1440  (ndss,file=trim(fnmpre)//'ww3_shel.scratch')
1441  ELSE
1442  ndsi2 = ndss
1443 #ifdef W3_MPI
1444  CALL mpi_barrier (mpi_comm,ierr_mpi)
1445 #endif
1446  OPEN (ndss,file=trim(fnmpre)//'ww3_shel.scratch')
1447  rewind(ndss)
1448  !
1449  IF ( .NOT.ALLOCATED(x) ) THEN
1450  IF ( npts.GT.0 ) THEN
1451  ALLOCATE ( x(npts), y(npts), pnames(npts) )
1452  ELSE
1453  ALLOCATE ( x(1), y(1), pnames(1) )
1454  GOTO 2054
1455  END IF
1456  END IF
1457  END IF
1458  !
1459  npts = 0
1460  DO
1461  CALL nextln ( comstr , ndsi , ndsen )
1462  READ (ndsi2,*) xx, yy, pn
1463  IF ( iloop.EQ.1 .AND. iaproc.EQ.1 ) THEN
1464  backspace(ndsi)
1465  READ (ndsi,'(A)') line
1466  WRITE (ndss,'(A)') line
1467  END IF
1468  IF ( index(pn,"STOPSTRING").NE.0 ) EXIT
1469  npts = npts + 1
1470  IF ( iloop .EQ. 1 ) cycle
1471  x(npts) = xx
1472  y(npts) = yy
1473  pnames(npts) = pn
1474  IF ( iaproc .EQ. napout ) THEN
1475  IF ( flagll ) THEN
1476  IF ( npts .EQ. 1 ) THEN
1477  WRITE (ndso,2945) &
1478  factor*xx, factor*yy, pn
1479  ELSE
1480  WRITE (ndso,2946) npts, &
1481  factor*xx, factor*yy, pn
1482  END IF
1483  ELSE
1484  IF ( npts .EQ. 1 ) THEN
1485  WRITE (ndso,2955) &
1486  factor*xx, factor*yy, pn
1487  ELSE
1488  WRITE (ndso,2956) npts, &
1489  factor*xx, factor*yy, pn
1490  END IF
1491  END IF
1492  END IF
1493  END DO
1494  !
1495  IF ( iaproc.EQ.1 .AND. iloop.EQ.1 ) CLOSE (ndss)
1496  END DO
1497  !
1498  IF ( npts.EQ.0 .AND. iaproc.EQ.napout ) &
1499  WRITE (ndso,2947)
1500  IF ( iaproc .EQ. 1 ) THEN
1501 #ifdef W3_MPI
1502  CALL mpi_barrier ( mpi_comm, ierr_mpi )
1503 #endif
1504  CLOSE (ndss,status='DELETE')
1505  ELSE
1506  CLOSE (ndss)
1507 #ifdef W3_MPI
1508  CALL mpi_barrier ( mpi_comm, ierr_mpi )
1509 #endif
1510  END IF
1511  !
1512 
1513 
1514  ! Type 3: track output
1515  ELSE IF ( j .EQ. 3 ) THEN
1516  CALL nextln ( comstr , ndsi , ndsen )
1517  READ (ndsi,*) tflagi
1518  !
1519  IF ( .NOT. tflagi ) nds(11) = -nds(11)
1520  IF ( iaproc .EQ. napout ) THEN
1521  IF ( .NOT. tflagi ) THEN
1522  WRITE (ndso,3945) 'input', 'UNFORMATTED'
1523  ELSE
1524  WRITE (ndso,3945) 'input', 'FORMATTED'
1525  END IF
1526  END IF
1527 
1528 
1529  ! Type 6: partitioning
1530  ELSE IF ( j .EQ. 6 ) THEN
1531  ! IPRT: IX0, IXN, IXS, IY0, IYN, IYS
1532  CALL nextln ( comstr , ndsi , ndsen )
1533  READ (ndsi,*) iprt, prtfrm
1534  !
1535  IF ( iaproc .EQ. napout ) THEN
1536  IF ( prtfrm ) THEN
1537  yesxno = 'YES/--'
1538  ELSE
1539  yesxno = '---/NO'
1540  END IF
1541  WRITE (ndso,6945) iprt, yesxno
1542  END IF
1543 
1544 
1545 #ifdef W3_COU
1546  ! Type 7: coupling
1547  ELSE IF ( j .EQ. 7 ) THEN
1548  CALL w3readflgrd ( ndsi, ndso, ndss, ndsen, comstr, flg2, &
1549  flgr2, iaproc, napout, ierr )
1550  IF ( ierr .NE. 0 ) GOTO 2222
1551  CALL nextln ( comstr , ndsi , ndsen )
1552  READ (ndsi,'(A)',END=2001,ERR=2002,IOSTAT=IERR) fldin
1553 #endif
1554 
1555  END IF ! J
1556  END IF ! ODAT
1557  END IF ! IF J=4
1558  END DO ! J
1559 
1560  ! force minimal allocation to avoid memory seg fault
1561  IF ( .NOT.ALLOCATED(x) .AND. npts.EQ.0 ) ALLOCATE ( x(1), y(1), pnames(1) )
1562 
1563  ! 2.6 Homogeneous field data
1564 
1565  IF ( flhom ) THEN
1566  IF ( iaproc .EQ. napout ) WRITE (ndso,951) &
1567  'Homogeneous field data (and moving grid) ...'
1568  nh = 0
1569  !
1570  ! Start of loop
1571  DO
1572  CALL nextln ( comstr , ndsi , ndsen )
1573  READ (ndsi,*) idtst
1574 
1575 
1576  ! Exit if illegal id
1577  IF ( idtst.NE.idstr(-7) .AND. idtst.NE.idstr(-6) .AND. &
1578  idtst.NE.idstr(-5) .AND. idtst.NE.idstr(-4) .AND. &
1579  idtst.NE.idstr(-3) .AND. idtst.NE.idstr(-2) .AND. &
1580  idtst.NE.idstr(-1) .AND. idtst.NE.idstr(0) .AND. &
1581  idtst.NE.idstr(1) .AND. idtst.NE.idstr(2) .AND. &
1582  idtst.NE.idstr(3) .AND. idtst.NE.idstr(4) .AND. &
1583  idtst.NE.idstr(5) .AND. idtst.NE.idstr(6) .AND. &
1584  idtst.NE.idstr(10) .AND. idtst.NE.'STP' ) GOTO 2005
1585 
1586  ! Stop conditions
1587  IF ( idtst .EQ. 'STP' ) THEN
1588  EXIT
1589  ELSE
1590  backspace( ndsi )
1591  END IF
1592 
1593  ! Store data
1594  DO j=lbound(idstr,1), 10
1595  IF ( idtst .EQ. idstr(j) ) THEN
1596  nh(j) = nh(j) + 1
1597  IF ( nh(j) .GT. nhmax ) GOTO 2006
1598  IF ( j .LE. 1 ) THEN ! water levels, etc. : get HA
1599  READ (ndsi,*) idtst, &
1600  tho(1,j,nh(j)), tho(2,j,nh(j)), &
1601  ha(nh(j),j)
1602  ELSE IF ( j .EQ. 2 ) THEN ! currents: get HA and HD
1603  READ (ndsi,*) idtst, &
1604  tho(1,j,nh(j)), tho(2,j,nh(j)), &
1605  ha(nh(j),j), hd(nh(j),j)
1606  ELSE IF ( j .EQ. 3 ) THEN ! wind: get HA HD and HS
1607  READ (ndsi,*) idtst, &
1608  tho(1,j,nh(j)), tho(2,j,nh(j)), &
1609  ha(nh(j),j), hd(nh(j),j), hs(nh(j),j)
1610  ELSE IF ( j .EQ. 4 ) THEN ! ice
1611  READ (ndsi,*) idtst, &
1612  tho(1,j,nh(j)), tho(2,j,nh(j)), &
1613  ha(nh(j),j)
1614  ELSE IF ( j .EQ. 5 ) THEN ! atmospheric momentum
1615  READ (ndsi,*) idtst, &
1616  tho(1,j,nh(j)), tho(2,j,nh(j)), &
1617  ha(nh(j),j), hd(nh(j),j)
1618  ELSE IF ( j .EQ. 6 ) THEN ! air density
1619  READ (ndsi,*) idtst, &
1620  tho(1,j,nh(j)), tho(2,j,nh(j)), &
1621  ha(nh(j),j)
1622  ELSE IF ( j .EQ. 10 ) THEN ! mov: HA and HD
1623  READ (ndsi,*) idtst, &
1624  tho(1,j,nh(j)), tho(2,j,nh(j)), &
1625  ha(nh(j),j), hd(nh(j),j)
1626  END IF
1627  END IF
1628  END DO
1629  END DO
1630  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 3')
1631  !
1632 #ifdef W3_O7
1633  DO j=jfirst, 10
1634  IF ( flh(j) .AND. iaproc.EQ.napout ) THEN
1635  WRITE (ndso,952) nh(j), idflds(j)
1636  DO i=1, nh(j)
1637  IF ( ( j .LE. 1 ) .OR. ( j .EQ. 4 ) .OR. &
1638  ( j .EQ. 6 ) ) THEN
1639  WRITE (ndso,953) i, tho(1,j,i), tho(2,j,i), &
1640  ha(i,j)
1641  ELSE IF ( ( j .EQ. 2 ) .OR. ( j .EQ. 5 ) .OR. &
1642  ( j .EQ. 10 ) ) THEN
1643  WRITE (ndso,953) i, tho(1,j,i), tho(2,j,i), &
1644  ha(i,j), hd(i,j)
1645  ELSE IF ( j .EQ. 3 ) THEN
1646  WRITE (ndso,953) i, tho(1,j,i), tho(2,j,i), &
1647  ha(i,j), hd(i,j), hs(i,j)
1648  END IF
1649  END DO
1650  END IF
1651  END DO
1652 #endif
1653  !
1654  !
1655  IF ( ( flh(-7) .AND. (nh(-7).EQ.0) ) .OR. &
1656  ( flh(-6) .AND. (nh(-6).EQ.0) ) .OR. &
1657  ( flh(-5) .AND. (nh(-5).EQ.0) ) .OR. &
1658  ( flh(-4) .AND. (nh(-4).EQ.0) ) .OR. &
1659  ( flh(-3) .AND. (nh(-3).EQ.0) ) .OR. &
1660  ( flh(-2) .AND. (nh(-2).EQ.0) ) .OR. &
1661  ( flh(-1) .AND. (nh(-1).EQ.0) ) .OR. &
1662  ( flh(0) .AND. (nh(0).EQ.0) ) .OR. &
1663  ( flh(1) .AND. (nh(1).EQ.0) ) .OR. &
1664  ( flh(2) .AND. (nh(2).EQ.0) ) .OR. &
1665  ( flh(3) .AND. (nh(3).EQ.0) ) .OR. &
1666  ( flh(4) .AND. (nh(4).EQ.0) ) .OR. &
1667  ( flh(5) .AND. (nh(5).EQ.0) ) .OR. &
1668  ( flh(6) .AND. (nh(6).EQ.0) ) .OR. &
1669  ( flh(10) .AND. (nh(10).EQ.0) ) ) GOTO 2007
1670  !
1671  END IF ! FLHOM
1672 
1673  END IF
1674 
1675 
1676 
1677 
1678 
1679  !
1680  ! ----------------
1681  !
1682 
1683  ! 2.1 input fields
1684 
1685  ! 2.1.a Opening field and data files
1686 
1687  IF ( iaproc .EQ. napout ) WRITE (ndso,950)
1688  IF ( flflg ) THEN
1689  IF ( iaproc .EQ. napout ) WRITE (ndso,951) &
1690  'Preparing input files ...'
1691  !
1692 
1693  DO j=jfirst, 6
1694  IF ( inflags1(j) .AND. .NOT. flagsc(j)) THEN
1695  IF ( flh(j) ) THEN
1696  IF ( iaproc .EQ. napout ) WRITE (ndso,954) idflds(j)
1697  ELSE
1698  flagtide = 0
1699  CALL w3fldo ('READ', idstr(j), ndsf(j), ndst, &
1700  ndsen, nx, ny, gtype, &
1701  ierr, fpre=trim(fnmpre), tideflagin=flagtide )
1702  IF ( ierr .NE. 0 ) GOTO 2222
1703 #ifdef W3_TIDE
1704  IF (flagtide.GT.0.AND.j.EQ.1) flagstide(1)=.true.
1705  IF (flagtide.GT.0.AND.j.EQ.2) flagstide(2)=.true.
1706 #endif
1707  IF ( iaproc .EQ. napout ) WRITE (ndso,955) idflds(j)
1708  END IF
1709  ELSE
1710  IF ( iaproc .EQ. napout ) WRITE (ndso,954) idflds(j)
1711  END IF
1712  END DO
1713  !
1714  DO j=7, 9
1715  IF ( inflags1(j) .AND. .NOT. flagsc(j)) THEN
1716  CALL w3fldo ('READ', idstr(j), ndsf(j), ndst, ndsen, &
1717  rcld(j), ny, nodata(j), &
1718  ierr, fpre=trim(fnmpre) )
1719  IF ( ierr .NE. 0 ) GOTO 2222
1720  IF ( iaproc .EQ. napout ) WRITE (ndso,956) idflds(j),&
1721  rcld(j), nodata(j)
1722  ELSE
1723  IF ( iaproc .EQ. napout ) WRITE (ndso,954) idflds(j)
1724  END IF
1725  END DO
1726  !
1727  END IF ! FLFLG
1728 
1729  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 4')
1730 
1731  ! 2.2 Time setup
1732 
1733  IF ( iaproc .EQ. napout ) WRITE (ndso,930)
1734  CALL stme21 ( time0 , dtme21 )
1735  IF ( iaproc .EQ. napout ) WRITE (ndso,931) dtme21
1736  time = time0
1737  CALL stme21 ( timen , dtme21 )
1738  IF ( iaproc .EQ. napout ) WRITE (ndso,932) dtme21
1739 #ifdef W3_OASIS
1740  time00 = time0
1741  timeend = timen
1742 #endif
1743 #ifdef W3_NL5
1744  qi5tbeg = time0
1745 #endif
1746  !
1747  dttst = dsec21( time0 , timen )
1748  IF ( dttst .LE. 0. ) GOTO 2003
1749 
1750 
1751  ! 2.3 Domain setup
1752 
1753  iostyp = max( 0 , min( 3 , iostyp ) )
1754 #ifdef W3_PDLIB
1755  IF (iostyp .gt. 1) THEN
1756  WRITE(*,*) 'IOSTYP not supported in domain decomposition mode'
1757  CALL extcde ( 6666 )
1758  ENDIF
1759 #endif
1760 
1761  IF ( iaproc .EQ. napout ) THEN
1762  IF ( iostyp .EQ. 0 ) THEN
1763  WRITE (ndso,940) 'No dedicated output process, ' // &
1764  'parallel file system required.'
1765  ELSE IF ( iostyp .EQ. 1 ) THEN
1766  WRITE (ndso,940) 'No dedicated output process, ' // &
1767  'any file system.'
1768  ELSE IF ( iostyp .EQ. 2 ) THEN
1769  WRITE (ndso,940) 'Single dedicated output process.'
1770  ELSE IF ( iostyp .EQ. 3 ) THEN
1771  WRITE (ndso,940) 'Multiple dedicated output processes.'
1772  ELSE
1773  WRITE (ndso,940) 'IOSTYP NOT RECOGNIZED'
1774  END IF
1775  END IF
1776 
1777 
1778  ! 2.4 Output dates
1779 
1780  DO j = 1, notype
1781  !
1782  IF ( odat(5*(j-1)+3) .NE. 0 ) THEN
1783  IF ( iaproc .EQ. napout ) WRITE (ndso,941) j, idotyp(j)
1784  ttime(1) = odat(5*(j-1)+1)
1785  ttime(2) = odat(5*(j-1)+2)
1786  CALL stme21 ( ttime , dtme21 )
1787  IF ( iaproc .EQ. napout ) WRITE (ndso,942) dtme21
1788  ttime(1) = odat(5*(j-1)+4)
1789  ttime(2) = odat(5*(j-1)+5)
1790  CALL stme21 ( ttime , dtme21 )
1791  IF ( iaproc .EQ. napout ) WRITE (ndso,943) dtme21
1792  ttime(1) = 0
1793  ttime(2) = 0
1794  dttst = real( odat(5*(j-1)+3) )
1795  CALL tick21 ( ttime , dttst )
1796  CALL stme21 ( ttime , dtme21 )
1797  IF ( ( odat(5*(j-1)+1) .NE. odat(5*(j-1)+4) .OR. &
1798  odat(5*(j-1)+2) .NE. odat(5*(j-1)+5) ) .AND. &
1799  iaproc .EQ. napout ) THEN
1800  IF ( dtme21(9:9) .NE. '0' ) THEN
1801  WRITE (ndso,1944) dtme21( 9:19)
1802  ELSE IF ( dtme21(10:10) .NE. '0' ) THEN
1803  WRITE (ndso,2944) dtme21(10:19)
1804  ELSE
1805  WRITE (ndso,3944) dtme21(12:19)
1806  END IF
1807  END IF
1808  END IF
1809  END DO
1810  !
1811  ! CHECKPOINT
1812  j=8
1813  IF (odat(38) .NE. 0) THEN
1814  IF ( iaproc .EQ. napout ) WRITE (ndso,941) j, idotyp(j)
1815  ttime(1) = odat(5*(j-1)+1)
1816  ttime(2) = odat(5*(j-1)+2)
1817  CALL stme21 ( ttime , dtme21 )
1818  IF ( iaproc .EQ. napout ) WRITE (ndso,942) dtme21
1819  ttime(1) = odat(5*(j-1)+4)
1820  ttime(2) = odat(5*(j-1)+5)
1821  CALL stme21 ( ttime , dtme21 )
1822  IF ( iaproc .EQ. napout ) WRITE (ndso,943) dtme21
1823  ttime(1) = 0
1824  ttime(2) = 0
1825  dttst = real( odat(5*(j-1)+3) )
1826  CALL tick21 ( ttime , dttst )
1827  CALL stme21 ( ttime , dtme21 )
1828  IF ( ( odat(5*(j-1)+1) .NE. odat(5*(j-1)+4) .OR. &
1829  odat(5*(j-1)+2) .NE. odat(5*(j-1)+5) ) .AND. &
1830  iaproc .EQ. napout ) THEN
1831  IF ( dtme21(9:9) .NE. '0' ) THEN
1832  WRITE (ndso,1944) dtme21( 9:19)
1833  ELSE IF ( dtme21(10:10) .NE. '0' ) THEN
1834  WRITE (ndso,2944) dtme21(10:19)
1835  ELSE
1836  WRITE (ndso,3944) dtme21(12:19)
1837  END IF
1838  END IF
1839  END IF
1840  !
1841  ! 2.5 Output types
1842 
1843 #ifdef W3_T
1844  WRITE (ndst,9040) odat
1845  WRITE (ndst,9041) flgrd
1846  WRITE (ndst,9042) iprt, prtfrm
1847 #endif
1848 
1849  !
1850  ! For outputs with non-zero time step, check dates :
1851  ! If output ends before run start OR output starts after run end,
1852  ! deactivate output cleanly with output time step = 0
1853  ! This is usefull for IOSTYP=3 (Multiple dedicated output processes)
1854  ! to avoid the definition of dedicated proc. for unused output.
1855  !
1856  DO j = 1, notype
1857  dttst = dsec21( time0 , odat(5*(j-1)+4:5*(j-1)+5) )
1858  IF ( dttst .LT. 0 ) THEN
1859  odat(5*(j-1)+3) = 0
1860  IF ( iaproc .EQ. napout ) WRITE (ndso,8945) trim(idotyp(j))
1861  CONTINUE
1862  END IF
1863  dttst = dsec21( odat(5*(j-1)+1:5*(j-1)+2), timen )
1864  IF ( dttst .LT. 0 ) THEN
1865  odat(5*(j-1)+3) = 0
1866  IF ( iaproc .EQ. napout ) WRITE (ndso,8945) trim(idotyp(j))
1867  CONTINUE
1868  END IF
1869  END DO
1870  !
1871  ! CHECKPOINT
1872  j = 8
1873  dttst = dsec21( time0 , odat(5*(j-1)+4:5*(j-1)+5) )
1874  IF ( dttst .LT. 0 ) THEN
1875  odat(5*(j-1)+3) = 0
1876  IF ( iaproc .EQ. napout ) WRITE (ndso,8945) trim(idotyp(j))
1877  CONTINUE
1878  END IF
1879  dttst = dsec21( odat(5*(j-1)+1:5*(j-1)+2), timen )
1880  IF ( dttst .LT. 0 ) THEN
1881  odat(5*(j-1)+3) = 0
1882  IF ( iaproc .EQ. napout ) WRITE (ndso,8945) trim(idotyp(j))
1883  CONTINUE
1884  END IF
1885  !
1886  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 5')
1887  !
1888  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1889  ! 5. Initializations
1890  !
1891 
1892  IF ( iaproc .EQ. napout ) WRITE (ndso,951) 'Wave model ...'
1893  !
1894 #ifdef W3_TIDE
1895  IF (flagstide(1).OR.flagstide(2)) THEN
1896  CALL vuf_set_parameters
1897  IF (flagstide(1)) CALL w3fldtide1 ( 'READ', ndsf(1), ndst, ndsen, nx, ny, idstr(1), ierr )
1898  IF (flagstide(2)) CALL w3fldtide1 ( 'READ', ndsf(2), ndst, ndsen, nx, ny, idstr(2), ierr )
1899  END IF
1900 #endif
1901  !
1902 #ifdef W3_COU
1903  ! Sent coupled fields must be written in the restart when coupling at T+0
1904  IF (cplt0) THEN
1905  DO j=1, nogrp
1906  flogr(j) = flogr(j) .OR. flg2(j)
1907  DO i=1, ngrpp
1908  flogrr(j,i) = flogrr(j,i) .OR. flgr2(j,i)
1909  END DO
1910  END DO
1911  ENDIF
1912 #endif
1913  !
1914  oarst = any(flogr)
1915  !
1916  CALL w3init ( 1, .false., 'ww3', nds, ntrace, odat, flgrd, flgr2, flgd, &
1917  flg2, npts, x, y, pnames, iprt, prtfrm, mpi_comm, &
1918  flagstidein=flagstide )
1919  !
1920  ! IF (MINVAL(VA) .LT. 0.) THEN
1921  ! WRITE(740+IAPROC,*) 'NEGATIVE ACTION SHELL 5', MINVAL(VA)
1922  ! CALL FLUSH(740+IAPROC)
1923  ! CALL EXTCDE(665)
1924  ! ENDIF
1925  ! IF (SUM(VA) .NE. SUM(VA)) THEN
1926  ! WRITE(740+IAPROC,*) 'NAN in ACTION SHEL1', SUM(VA)
1927  ! CALL FLUSH(740+IAPROC)
1928  ! CALL EXTCDE(666)
1929  ! ENDIF
1930 
1931  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 5')
1932  !
1933 #ifdef W3_TIDE
1934  IF (flagstide(1)) CALL w3fldtide2 ( 'READ', ndsf(1), ndst, ndsen, nx, ny, idstr(1), 1, ierr )
1935  IF (flagstide(2)) CALL w3fldtide2 ( 'READ', ndsf(2), ndst, ndsen, nx, ny, idstr(2), 1, ierr )
1936  ALLOCATE(v_arg(170,1),f_arg(170,1),u_arg(170,1)) ! to be removed later ...
1937 #endif
1938  !
1939  ALLOCATE ( xxx(nx,ny) )
1940  !
1941 
1942  !
1943 #ifdef W3_MPI
1944  CALL mpi_barrier ( mpi_comm, ierr_mpi )
1945 #endif
1946  !
1947  IF ( iaproc .EQ. napout ) THEN
1948  CALL date_and_time ( values=clkdt2 )
1949  END IF
1950  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1951  !
1952 #ifdef W3_OASIS
1953  ! Initialize L_MASTER, COUPL_COMM
1954  IF ( iaproc .EQ. 1) THEN
1955  l_master = .true.
1956  ELSE
1957  l_master = .false.
1958  ENDIF
1959  ! Estimate the weights for the spatial interpolation
1960  IF (dtout(7).NE.0) THEN
1961  CALL cpl_oasis_grid(l_master,mpi_comm)
1962  CALL cpl_oasis_define(ndso, fldin, fldout)
1963  END IF
1964 #endif
1965 
1966 
1967  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1968  ! 6. Model without input
1969  !
1970  ! IF (MINVAL(VA) .LT. 0.) THEN
1971  ! WRITE(740+IAPROC,*) 'NEGATIVE ACTION SHELL 6', MINVAL(VA)
1972  ! CALL FLUSH(740+IAPROC)
1973  ! CALL EXTCDE(665)
1974  ! ENDIF
1975  ! IF (SUM(VA) .NE. SUM(VA)) THEN
1976  ! WRITE(740+IAPROC,*) 'NAN in ACTION SHEL2', SUM(VA)
1977  ! CALL FLUSH(740+IAPROC)
1978  ! CALL EXTCDE(666)
1979  ! ENDIF
1980  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 6')
1981 
1982  IF ( .NOT. flflg ) THEN
1983  !
1984  IF ( iaproc .EQ. napout ) WRITE (ndso,960)
1985  CALL w3wave ( 1, odat, timen &
1986 #ifdef W3_OASIS
1987  , .true., .false., mpi_comm, timen &
1988 #endif
1989  )
1990  !
1991  GOTO 2222
1992  !
1993  END IF
1994  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1995  ! 7. Model with input
1996  !
1997  IF ( iaproc .EQ. napout ) WRITE (ndso,970)
1998  !
1999 
2000 #ifdef W3_OASIS
2001  ! Send coupling fields at the initial time step
2002  IF ( flout(7) .AND. cplt0 ) THEN
2003 #endif
2004 #ifdef W3_OASACM
2005  CALL snd_fields_to_atmos()
2006 #endif
2007 #ifdef W3_OASOCM
2008  CALL snd_fields_to_ocean()
2009 #endif
2010 #ifdef W3_OASICM
2011  CALL snd_fields_to_ice()
2012 #endif
2013 #ifdef W3_OASIS
2014  END IF
2015 #endif
2016 
2017 700 CONTINUE
2018  !
2019  !
2020  ! 7.a Determine next time interval and input fields
2021  ! 7.a.1 Preparation
2022  !
2023  ttime = timen
2024  !
2025  CALL stme21 ( time0 , dtme21 )
2026  IF ( iaproc .EQ. napout ) WRITE (ndso,971) dtme21
2027  !
2028 #ifdef W3_T
2029  WRITE (ndst,9070) '0-N', time0, ttime, &
2030  idstr(-7), inflags1(-7), ti1, &
2031  idstr(-6), inflags1(-6), ti2, &
2032  idstr(-5), inflags1(-5), ti3, &
2033  idstr(-4), inflags1(-4), ti4, &
2034  idstr(-3), inflags1(-3), ti5, &
2035  idstr(-2), inflags1(-2), tzn, &
2036  idstr(-1), inflags1(-1), ttn, &
2037  idstr(0), inflags1(0), tvn, &
2038  idstr(1), inflags1(1), tln, &
2039  idstr(2), inflags1(2), tc0, tcn, &
2040  idstr(3), inflags1(3), tw0, twn, &
2041  idstr(4), inflags1(4), tin, &
2042  idstr(5), inflags1(5), tu0, tun, &
2043  idstr(6), inflags1(6), tr0, trn, &
2044  idstr(7), inflags1(7), t0n, &
2045  idstr(8), inflags1(8), t1n, &
2046  idstr(9), inflags1(9), t2n, &
2047  idstr(10), inflags1(10), tg0, tgn
2048 #endif
2049  !
2050  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 7')
2051 
2052  DO j=jfirst,10
2053  !
2054  write(jchar, '(i0)') j
2055  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL UPDATE '//trim(jchar))
2056 
2057  IF ( inflags1(j) ) THEN
2058  !
2059  ! 7.a.2 Check if update is needed
2060  !
2061  IF (.NOT.flagsc(j)) THEN
2062  ttt(1) = tfn(1,j)
2063  ttt(2) = tfn(2,j)
2064  IF ( ttt(1) .EQ. -1 ) THEN
2065  dttst = 0.
2066  ELSE
2067  dttst = dsec21( time0 , ttt )
2068  END IF
2069 #ifdef W3_OASIS
2070  ELSE
2071  IF ( dtout(7).NE.0 ) THEN
2072  ! TFN not initialized at TIME=TIME00, using TIME instead
2073  IF(nint(dsec21(time00,time)) == 0) THEN
2074  id_oasis_time = 0
2075  dttst=0.
2076  ELSE
2077  id_oasis_time = nint(dsec21( time00 , tfn(:,j) ))
2078  IF ( mod(nint(dsec21(time00,time)), nint(dtout(7))) .EQ. 0 .AND. &
2079  dsec21(tfn(:,j), timeend) .GT. 0.0 ) dttst=0.
2080  ENDIF
2081  ENDIF
2082 #endif
2083  END IF
2084  !
2085 #ifdef W3_T
2086  WRITE (ndst,9071) idstr(j), dttst
2087 #endif
2088  !
2089  ! 7.a.3 Update time and fields / data
2090  !
2091  IF ( dttst .LE. 0. ) THEN
2092 
2093 #ifdef W3_TIDE
2094  IF ((fllevtide .AND.(j.EQ.1)).OR.(flcurtide.AND.(j.EQ.2))) THEN
2095  IF ( iaproc .EQ. napout ) WRITE (ndso,974) idflds(j)
2096  ELSE
2097 #endif
2098  IF ( iaproc .EQ. napout ) WRITE (ndso,972) idflds(j)
2099 #ifdef W3_TIDE
2100  END IF
2101 #endif
2102  !
2103  ! IC1 : (in context of IC3 & IC2, this is ice thickness)
2104  IF ( j .EQ. -7 ) THEN
2105  IF ( flh(j) ) THEN
2106  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2107  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2108  ttt, xxx, xxx, xxx, ti1, xxx, xxx, icep1, ierr)
2109  ELSE
2110 #ifdef W3_OASIS
2111  coupl_comm = mpi_comm
2112 #endif
2113 #ifdef W3_OASICM
2114  IF (flagsc(j)) flagsci = .true.
2115  IF (.NOT.flagsci) id_oasis_time = -1
2116 #endif
2117  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2118  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2119  ttt, xxx, xxx, xxx, ti1, xxx, xxx, icep1, &
2120  ierr, flagsc(j) &
2121 #ifdef W3_OASICM
2122  , coupl_comm &
2123 #endif
2124  )
2125  END IF
2126  IF ( ierr .LT. 0 ) fllst_all(j) = .true.
2127 
2128  ! IC2 : (in context of IC3, this is ice viscosity)
2129  ELSE IF ( j .EQ. -6 ) THEN
2130  IF ( flh(j) ) THEN
2131  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2132  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2133  ttt, xxx, xxx, xxx, ti2, xxx, xxx, icep2, ierr)
2134  ELSE
2135  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2136  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2137  ttt, xxx, xxx, xxx, ti2, xxx, xxx, icep2, &
2138  ierr, flagsc(j))
2139  END IF
2140  IF ( ierr .LT. 0 )fllst_all(j) = .true.
2141 
2142  ! IC3 : (in context of IC3, this is ice density)
2143  ELSE IF ( j .EQ. -5 ) THEN
2144  IF ( flh(j) ) THEN
2145  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2146  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2147  ttt, xxx, xxx, xxx, ti3, xxx, xxx, icep3, ierr)
2148  ELSE
2149  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2150  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2151  ttt, xxx, xxx, xxx, ti3, xxx, xxx, icep3, &
2152  ierr, flagsc(j))
2153  END IF
2154  IF ( ierr .LT. 0 )fllst_all(j) = .true.
2155 
2156  ! IC4 : (in context of IC3, this is ice modulus)
2157  ELSE IF ( j .EQ. -4 ) THEN
2158  IF ( flh(j) ) THEN
2159  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2160  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2161  ttt, xxx, xxx, xxx, ti4, xxx, xxx, icep4, ierr)
2162  ELSE
2163  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2164  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2165  ttt, xxx, xxx, xxx, ti4, xxx, xxx, icep4, &
2166  ierr, flagsc(j))
2167  END IF
2168  IF ( ierr .LT. 0 )fllst_all(j) = .true.
2169 
2170  ! IC5 : ice flow diam.
2171  ELSE IF ( j .EQ. -3 ) THEN
2172  IF ( flh(j) ) THEN
2173  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2174  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2175  ttt, xxx, xxx, xxx, ti5, xxx, xxx, icep5, ierr)
2176  ELSE
2177 #ifdef W3_OASIS
2178  coupl_comm = mpi_comm
2179 #endif
2180 #ifdef W3_OASICM
2181  IF (flagsc(j)) flagsci = .true.
2182  IF (.NOT.flagsci) id_oasis_time = -1
2183 #endif
2184  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2185  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2186  ttt, xxx, xxx, xxx, ti5, xxx, xxx, icep5, &
2187  ierr, flagsc(j) &
2188 #ifdef W3_OASICM
2189  , coupl_comm &
2190 #endif
2191  )
2192  END IF
2193  IF ( ierr .LT. 0 )fllst_all(j) = .true.
2194 
2195  ! MUD1 : mud density
2196  ELSE IF ( j .EQ. -2 ) THEN
2197  IF ( flh(j) ) THEN
2198  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2199  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2200  ttt, xxx, xxx, xxx, tzn, xxx, xxx, mudd, ierr)
2201  ELSE
2202  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2203  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2204  ttt, xxx, xxx, xxx, tzn, xxx, xxx, mudd, &
2205  ierr, flagsc(j))
2206  END IF
2207  IF ( ierr .LT. 0 )fllst_all(j) = .true.
2208 
2209  ! MUD2 : mud thickness
2210  ELSE IF ( j .EQ. -1 ) THEN
2211  IF ( flh(j) ) THEN
2212  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2213  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2214  ttt, xxx, xxx, xxx, ttn, xxx, xxx, mudt, ierr)
2215  ELSE
2216  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2217  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2218  ttt, xxx, xxx, xxx, ttn, xxx, xxx, mudt, &
2219  ierr, flagsc(j))
2220  END IF
2221  IF ( ierr .LT. 0 )fllst_all(j) = .true.
2222 
2223  ! MUD3 : mud viscosity
2224  ELSE IF ( j .EQ. 0 ) THEN
2225  IF ( flh(j) ) THEN
2226  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2227  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2228  ttt, xxx, xxx, xxx, tvn, xxx, xxx, mudv, ierr)
2229  ELSE
2230  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2231  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2232  ttt, xxx, xxx, xxx, tvn, xxx, xxx, mudv, &
2233  ierr, flagsc(j))
2234  END IF
2235  IF ( ierr .LT. 0 )fllst_all(j) = .true.
2236 
2237  ! LEV : water levels
2238  ELSE IF ( j .EQ. 1 ) THEN
2239  IF ( flh(j) ) THEN
2240  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2241  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2242  ttt, xxx, xxx, xxx, tln, xxx, xxx, wlev, ierr)
2243  ELSE
2244 #ifdef W3_TIDE
2245  IF ( fllevtide ) THEN
2246  ierr=0
2247  IF ( tln(1) .EQ. -1 ) THEN
2248  tln = time
2249  ELSE
2250  CALL tick21 ( tln, tide_dt )
2251  END IF
2252  ELSE
2253 #endif
2254 #ifdef W3_OASIS
2255  coupl_comm = mpi_comm
2256 #endif
2257 #ifdef W3_OASOCM
2258  IF (.NOT.flagsc(j)) id_oasis_time = -1
2259 #endif
2260  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2261  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2262  ttt, xxx, xxx, xxx, tln, xxx, xxx, wlev, &
2263  ierr, flagsc(j) &
2264 #ifdef W3_OASOCM
2265  , coupl_comm &
2266 #endif
2267  )
2268 #ifdef W3_TIDE
2269  END IF
2270 #endif
2271  END IF
2272  IF ( ierr .LT. 0 ) fllstl = .true.
2273  !could be: IF ( IERR .LT. 0 ) FLLST_ALL(J) = .TRUE.
2274 
2275  ! CUR : currents
2276  ELSE IF ( j .EQ. 2 ) THEN
2277  IF ( flh(j) ) THEN
2278  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2279  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2280  tc0, cx0, cy0, xxx, tcn, cxn, cyn, xxx, ierr)
2281  !
2282 #ifdef W3_SMC
2283  !!Li Reshape the CX0/N CY0/N space for sea-point only current.
2284  !!Li JGLi26Jun2018.
2285  ELSE IF( fswnd ) THEN
2286  CALL w3fldg ('READ', idstr(j), ndsf(j), ndst, &
2287  ndsen, nsea, 1, nsea, 1, time0, timen, tc0, &
2288  cx0, cy0, xxx, tcn, cxn, cyn, xxx, ierr)
2289  !!Li
2290 #endif
2291  ELSE
2292 #ifdef W3_TIDE
2293  IF ( flcurtide ) THEN
2294  ierr=0
2295  IF ( tcn(1) .EQ. -1 ) THEN
2296  tcn = time
2297  END IF
2298  tc0(:) = tcn(:)
2299  CALL tick21 ( tcn, tide_dt )
2300  ELSE
2301 #endif
2302 #ifdef W3_OASIS
2303  coupl_comm = mpi_comm
2304 #endif
2305 #ifdef W3_OASOCM
2306  IF (.NOT.flagsc(j)) id_oasis_time = -1
2307 #endif
2308  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2309  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2310  tc0, cx0, cy0, xxx, tcn, cxn, cyn, xxx, &
2311  ierr, flagsc(j) &
2312 #ifdef W3_OASOCM
2313  , coupl_comm &
2314 #endif
2315  )
2316 #ifdef W3_TIDE
2317  END IF
2318 #endif
2319  END IF
2320 
2321  ! WND : winds
2322  ELSE IF ( j .EQ. 3 ) THEN
2323  IF ( flh(j) ) THEN
2324  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2325  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2326  tw0, wx0, wy0, dt0, twn, wxn, wyn, dtn, ierr)
2327  !
2328 #ifdef W3_SMC
2329  !!Li Reshape the WX0/N WY0/N space for sea-point only wind.
2330  !!Li JGLi26Jun2018.
2331  ELSE IF( fswnd ) THEN
2332  CALL w3fldg ('READ', idstr(j), ndsf(j), ndst, &
2333  ndsen, nsea, 1, nsea, 1, time0, timen, tw0, &
2334  wx0, wy0, dt0, twn, wxn, wyn, dtn, ierr)
2335  !!Li
2336 #endif
2337  ELSE
2338 #ifdef W3_OASIS
2339  coupl_comm = mpi_comm
2340 #endif
2341 #ifdef W3_OASACM
2342  IF (.NOT.flagsc(j)) id_oasis_time = -1
2343 #endif
2344  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2345  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2346  tw0, wx0, wy0, dt0, twn, wxn, wyn, dtn, &
2347  ierr, flagsc(j) &
2348 #ifdef W3_OASACM
2349  , coupl_comm &
2350 #endif
2351  )
2352  END IF
2353 
2354  ! ICE : ice conc.
2355  ELSE IF ( j .EQ. 4 ) THEN
2356  IF ( flh(j) ) THEN
2357  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2358  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2359  ttt, xxx, xxx, xxx, tin, xxx, bergi, icei, ierr)
2360  ELSE
2361 #ifdef W3_OASIS
2362  coupl_comm = mpi_comm
2363 #endif
2364 #ifdef W3_OASICM
2365  IF (flagsc(j)) flagsci = .true.
2366  IF (.NOT.flagsci) id_oasis_time = -1
2367 #endif
2368  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2369  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2370  ttt, xxx, xxx, xxx, tin, xxx, bergi, icei, &
2371  ierr, flagsc(j) &
2372 #ifdef W3_OASICM
2373  , coupl_comm &
2374 #endif
2375  )
2376  IF ( ierr .LT. 0 ) fllsti = .true.
2377  !could be: IF ( IERR .LT. 0 ) FLLST_ALL(J) = .TRUE.
2378  END IF
2379 
2380  ! TAU : atmospheric momentum
2381  ELSE IF ( j .EQ. 5 ) THEN
2382  IF ( flh(j) ) THEN
2383  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2384  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2385  tu0, ux0, uy0, xxx, tun, uxn, uyn, xxx, ierr)
2386  !
2387 #ifdef W3_SMC
2388  !!Li Reshape the UX0/N UY0/N space for sea-point only current.
2389  !!Li JGLi26Jun2018.
2390  ELSE IF( fswnd ) THEN
2391  CALL w3fldg ('READ', idstr(j), ndsf(j), ndst, &
2392  ndsen, nsea, 1, nsea, 1, time0, timen, tu0, &
2393  ux0, uy0, xxx, tun, uxn, uyn, xxx, ierr)
2394  !!Li
2395 #endif
2396  ELSE
2397 #ifdef W3_OASIS
2398  coupl_comm = mpi_comm
2399 #endif
2400 #ifdef W3_OASACM
2401  IF (.NOT.flagsc(j)) id_oasis_time = -1
2402 #endif
2403  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2404  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2405  tu0, ux0, uy0, xxx, tun, uxn, uyn, xxx, &
2406  ierr, flagsc(j) &
2407 #ifdef W3_OASACM
2408  , coupl_comm &
2409 #endif
2410  )
2411  END IF
2412 
2413  ! RHO : air density
2414  ELSE IF ( j .EQ. 6 ) THEN
2415  IF ( flh(j) ) THEN
2416  CALL w3fldh (j, ndst, ndsen, nx, ny, nx, ny, &
2417  time0, timen, nh(j), nhmax, tho, ha, hd, hs,&
2418  tr0, xxx, xxx, rh0, trn, xxx, xxx, rhn, ierr)
2419 #ifdef W3_SMC
2420  !!Li Reshape the RH0/N space for sea-point only current.
2421  !!Li JGLi26Jun2018.
2422  ELSE IF( fswnd ) THEN
2423  CALL w3fldg ('READ', idstr(j), ndsf(j), ndst, &
2424  ndsen, nsea, 1, nsea, 1, time0, timen, tr0, &
2425  xxx, xxx, rh0, trn, xxx, xxx, rhn, ierr)
2426  !!Li
2427 #endif
2428  ELSE
2429 #ifdef W3_OASIS
2430  coupl_comm = mpi_comm
2431 #endif
2432 #ifdef W3_OASACM
2433  IF (.NOT.flagsc(j)) id_oasis_time = -1
2434 #endif
2435  CALL w3fldg ('READ', idstr(j), ndsf(j), &
2436  ndst, ndsen, nx, ny, nx, ny, time0, timen, &
2437  tr0, xxx, xxx, rh0, trn, xxx, xxx, rhn, &
2438  ierr, flagsc(j) &
2439 #ifdef W3_OASACM
2440  , coupl_comm &
2441 #endif
2442  )
2443  IF ( ierr .LT. 0 ) fllstr = .true.
2444  END IF
2445 
2446  ! Assim data
2447  ELSE IF ( j .EQ. 7 ) THEN
2448  CALL w3fldd ('SIZE', idstr(j), ndsf(j), ndst, &
2449  ndsen, time0, t0n, rcld(j), ndt(j), &
2450  ndtnew, data0, ierr )
2451  IF ( ierr .LT. 0 ) THEN
2452  inflags1(j) = .false.
2453  IF ( ALLOCATED(data0) ) DEALLOCATE(data0)
2454  ELSE
2455  ndt(j) = ndtnew
2456  IF ( ALLOCATED(data0) ) DEALLOCATE(data0)
2457  ALLOCATE ( data0(rcld(j),ndt(j)) )
2458  CALL w3fldd ('READ', idstr(j), ndsf(j), ndst, &
2459  ndsen, time0, t0n, rcld(j), ndt(j), &
2460  ndtnew, data0, ierr )
2461  END IF
2462 
2463  ! Assim data
2464  ELSE IF ( j .EQ. 8 ) THEN
2465  CALL w3fldd ('SIZE', idstr(j), ndsf(j), ndst, &
2466  ndsen, time0, t1n, rcld(j), ndt(j), &
2467  ndtnew, data1, ierr )
2468  IF ( ierr .LT. 0 ) THEN
2469  inflags1(j) = .false.
2470  IF ( ALLOCATED(data1) ) DEALLOCATE(data1)
2471  ELSE
2472  ndt(j) = ndtnew
2473  IF ( ALLOCATED(data1) ) DEALLOCATE(data1)
2474  ALLOCATE ( data1(rcld(j),ndt(j)) )
2475  CALL w3fldd ('READ', idstr(j), ndsf(j), ndst, &
2476  ndsen, time0, t1n, rcld(j), ndt(j), &
2477  ndtnew, data1, ierr )
2478  END IF
2479 
2480  ! Assim data
2481  ELSE IF ( j .EQ. 9 ) THEN
2482  CALL w3fldd ('SIZE', idstr(j), ndsf(j), ndst, &
2483  ndsen, time0, t2n, rcld(j), ndt(j), &
2484  ndtnew, data2, ierr )
2485  IF ( ierr .LT. 0 ) THEN
2486  inflags1(j) = .false.
2487  IF ( ALLOCATED(data2) ) DEALLOCATE(data2)
2488  ELSE
2489  ndt(j) = ndtnew
2490  IF ( ALLOCATED(data2) ) DEALLOCATE(data2)
2491  ALLOCATE ( data2(rcld(j),ndt(j)) )
2492  CALL w3fldd ('READ', idstr(j), ndsf(j), ndst, &
2493  ndsen, time0, t2n, rcld(j), ndt(j), &
2494  ndtnew, data2, ierr )
2495  END IF
2496 
2497  ! Track
2498  ELSE IF ( j .EQ. 10 ) THEN
2499  CALL w3fldm (4, ndst, ndsen, time0, timen, nh(4), &
2500  nhmax, tho, ha, hd, tg0, ga0, gd0, &
2501  tgn, gan, gdn, ierr)
2502  END IF
2503  !
2504  IF ( ierr.GT.0 ) GOTO 2222
2505  IF ( ierr.LT.0 .AND. iaproc.EQ.napout ) WRITE (ndso,973) idflds(j)
2506 
2507 
2508  END IF ! DTTST .LE. 0.
2509  !
2510  ! 7.a.4 Update next ending time
2511  !
2512  IF ( inflags1(j) ) THEN
2513  ttt = tfn(:,j)
2514  dttst = dsec21( ttt , ttime )
2515  IF ( dttst.GT.0. .AND. .NOT. &
2516  ( (fllstl .AND. j.EQ.1) .OR. &
2517  (fllst_all(j) .AND. j.EQ.-7) .OR. &
2518  (fllst_all(j) .AND. j.EQ.-6) .OR. &
2519  (fllst_all(j) .AND. j.EQ.-5) .OR. &
2520  (fllst_all(j) .AND. j.EQ.-4) .OR. &
2521  (fllst_all(j) .AND. j.EQ.-3) .OR. &
2522  (fllst_all(j) .AND. j.EQ.-2) .OR. &
2523  (fllst_all(j) .AND. j.EQ.-1) .OR. &
2524  (fllst_all(j) .AND. j.EQ.0 ) .OR. &
2525  (fllsti .AND. j.EQ.4) .OR. &
2526  (fllstr .AND. j.EQ.6) ) ) THEN
2527  ttime = ttt
2528  ! notes: if model has run out beyond field input, then this line should not
2529  ! be reached.
2530  END IF
2531  END IF
2532  !
2533  END IF ! INFLAGSC1(J)
2534  !
2535  END DO ! J=JFIRST,10
2536  !
2537  ! update the next assimilation data time
2538  !
2539 #ifdef W3_OASIS
2540  first_step = .false.
2541 #endif
2542 
2543  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 8')
2544 
2545  tdn = ttime
2546  CALL tick21 ( tdn, 1. )
2547  DO j=7, 9
2548  IF ( inflags1(j) ) THEN
2549  ttt = tfn(:,j)
2550  dttst = dsec21( ttt , tdn )
2551  IF ( dttst.GT.0. ) tdn = ttt
2552  END IF
2553  END DO
2554  !
2555 #ifdef W3_T
2556  WRITE (ndst,9072) '0-N', time0, ttime, &
2557  idstr(-7), inflags1(-7), ti1, &
2558  idstr(-6), inflags1(-6), ti2, &
2559  idstr(-5), inflags1(-5), ti3, &
2560  idstr(-4), inflags1(-4), ti4, &
2561  idstr(-3), inflags1(-3), ti5, &
2562  idstr(-2), inflags1(-2), tzn, &
2563  idstr(-1), inflags1(-1), ttn, &
2564  idstr(0), inflags1(0), tvn, &
2565  idstr(1), inflags1(1), tln, &
2566  idstr(2), inflags1(2), tc0, tcn, &
2567  idstr(3), inflags1(3), tw0, twn, &
2568  idstr(4), inflags1(4), tin, &
2569  idstr(5), inflags1(5), tu0, tun, &
2570  idstr(6), inflags1(6), tr0, trn, &
2571  idstr(7), inflags1(7), t0n, &
2572  idstr(8), inflags1(8), t1n, &
2573  idstr(9), inflags1(9), t2n, tdn, &
2574  idstr(10), inflags1(10), tg0, tgn
2575 #endif
2576  !
2577  IF ( iaproc .EQ. napout ) WRITE (ndso,*) ' '
2578  !
2579  ! 7.b Run the wave model for the given interval
2580  !
2581  time0 = ttime
2582  !
2583  CALL w3wave ( 1, odat, time0 &
2584 #ifdef W3_OASIS
2585  , .true., .false., mpi_comm, timen &
2586 #endif
2587  )
2588  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 9')
2589  !
2590  ! The following lines prevents us from trying to read past the end
2591  ! of the files. This feature existed in v3.14.
2592  ! "1" is for water levels
2593  ! "4" is for ice concentration:
2594  ! "6" is for air density:
2595  IF ( fllstl ) inflags1(1) = .false.
2596  IF ( fllsti ) inflags1(4) = .false.
2597  IF ( fllstr ) inflags1(6) = .false.
2598 
2599  ! We include something like this for mud and ice parameters also:
2600  DO j=-7,0
2601  IF (fllst_all(j))THEN
2602  inflags1(j)=.false.
2603  END IF
2604  END DO
2605 
2606  !
2607  ! 7.c Run data assimilation at ending time
2608  !
2609  dttst = dsec21( time , tdn )
2610  IF ( dttst .EQ. 0 ) THEN
2611  CALL stme21 ( time0 , dtme21 )
2612  IF ( iaproc .EQ. napout ) WRITE (ndso,975) dtme21
2613  !
2614  flgdas(1) = dsec21(time,t0n) .EQ. 0.
2615  flgdas(2) = dsec21(time,t1n) .EQ. 0.
2616  flgdas(3) = dsec21(time,t2n) .EQ. 0.
2617  !
2618  CALL w3wdas ( flgdas, rcld, ndt, data0, data1, data2 )
2619  !
2620  ! 7.d Call wave model again after data assimilation for output only
2621  !
2622  dttst = dsec21( time , timen )
2623 
2624  IF ( dttst .EQ. 0. ) THEN
2625  IF ( iaproc .EQ. napout ) WRITE (ndso,*) ' '
2626  CALL w3wave ( 1, odat, time0 &
2627 #ifdef W3_OASIS
2628  , .true., .false., mpi_comm, timen &
2629 #endif
2630  )
2631  END IF
2632  END IF
2633  !
2634  ! 7.e Check times
2635  !
2636  call print_memcheck(memunit, 'memcheck_____:'//' WW3_SHEL SECTION 10')
2637 
2638  dttst = dsec21( time0 , timen )
2639  IF ( dttst .GT. 0. ) GOTO 700
2640  !
2641  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2642  ! End of shel
2643  !
2644  GOTO 2222
2645  !
2646  ! Error escape locations
2647  !
2648 2000 CONTINUE
2649  IF ( iaproc .EQ. naperr ) WRITE (ndse,1000) ierr
2650  CALL extcde ( 1000 )
2651  !
2652 2001 CONTINUE
2653  IF ( iaproc .EQ. naperr ) WRITE (ndse,1001)
2654  CALL extcde ( 1001 )
2655  !
2656 2002 CONTINUE
2657  IF ( iaproc .EQ. naperr ) WRITE (ndse,1002) ierr
2658  CALL extcde ( 1002 )
2659  !
2660 2102 CONTINUE
2661  IF ( iaproc .EQ. naperr ) WRITE (ndse,1102)
2662  CALL extcde ( 1102 )
2663  !
2664 2003 CONTINUE
2665  IF ( iaproc .EQ. naperr ) WRITE (ndse,1003)
2666  CALL extcde ( 1003 )
2667  !
2668 2104 CONTINUE
2669  IF ( iaproc .EQ. naperr ) WRITE (ndse,1104) ierr
2670  CALL extcde ( 1104 )
2671  !
2672 2004 CONTINUE
2673  IF ( iaproc .EQ. naperr ) WRITE (ndse,1004) ierr
2674  CALL extcde ( 1004 )
2675  !
2676 2005 CONTINUE
2677  IF ( iaproc .EQ. naperr ) WRITE (ndse,1005) idtst
2678  CALL extcde ( 1005 )
2679  !
2680 2006 CONTINUE
2681  IF ( iaproc .EQ. naperr ) WRITE (ndse,1006) idtst, nh(j)
2682  CALL extcde ( 1006 )
2683  !
2684 2062 CONTINUE
2685  IF ( iaproc .EQ. naperr ) WRITE (ndse,1062) idtst
2686  CALL extcde ( 1062 )
2687  !
2688 2007 CONTINUE
2689  IF ( iaproc .EQ. naperr ) WRITE (ndse,1007)
2690  CALL extcde ( 1007 )
2691  !
2692 2008 CONTINUE
2693  IF ( iaproc .EQ. naperr ) WRITE (ndse,1008) ierr
2694  CALL extcde ( 1008 )
2695  !
2696 #ifdef W3_COU
2697 2009 CONTINUE
2698  IF ( iaproc .EQ. naperr ) WRITE (ndse,1009) odat(33), nint(dtmax)
2699  CALL extcde ( 1009 )
2700 #endif
2701  !
2702 2054 CONTINUE
2703  IF ( iaproc .EQ. naperr ) WRITE (ndse,1054)
2704  CALL extcde ( 1054 )
2705 2222 CONTINUE
2706  !
2707 #ifdef W3_MPI
2708  CALL mpi_barrier ( mpi_comm, ierr_mpi )
2709 #endif
2710  !
2711  IF ( iaproc .EQ. napout ) THEN
2712  CALL date_and_time ( values=clkdt3 )
2713  clkfin = max(tdiff( clkdt1,clkdt2 ), 0.)
2714  clkfel = max(tdiff( clkdt1,clkdt3 ), 0.)
2715  WRITE (ndso,997) clkfin
2716  WRITE (ndso,998) clkfel
2717  IF ( ndso .NE. nds(1) ) THEN
2718  WRITE (nds(1),997) clkfin
2719  WRITE (nds(1),998) clkfel
2720  END IF
2721  WRITE (ndso,999)
2722  END IF
2723  !
2724 #ifdef W3_NCO
2725  ! IF ( IAPROC .EQ. 1 ) CALL W3TAGE('WAVEFCST')
2726 #endif
2727 #ifdef W3_OASIS
2728  IF (oasised.EQ.1) THEN
2729  CALL cpl_oasis_finalize
2730  ELSE
2731 #endif
2732 #ifdef W3_MPI
2733  CALL mpi_finalize ( ierr_mpi )
2734 #endif
2735 #ifdef W3_OASIS
2736  END IF
2737 #endif
2738  !
2739  !
2740  ! Formats
2741  !
2742 900 FORMAT (/15x,' *** WAVEWATCH III Program shell *** '/ &
2743  15x,'==============================================='/)
2744 901 FORMAT ( ' Comment character is ''',a,''''/)
2745  !
2746 #ifdef W3_OMPH
2747 905 FORMAT ( ' Hybrid MPI/OMP thread support level:'/ &
2748  ' Requested: ', i2/ &
2749  ' Provided: ', i2/ )
2750 #endif
2751  !
2752 #ifdef W3_OMPG
2753 906 FORMAT ( ' OMP threading enabled. Number of threads: ', i3 / )
2754 #endif
2755 920 FORMAT (/' Input fields : '/ &
2756  ' --------------------------------------------------')
2757 921 FORMAT ( ' ',a,2x,a,2x,a)
2758 922 FORMAT ( ' ' )
2759  !
2760 930 FORMAT (/' Time interval : '/ &
2761  ' --------------------------------------------------')
2762 931 FORMAT ( ' Starting time : ',a)
2763 932 FORMAT ( ' Ending time : ',a/)
2764  !
2765 940 FORMAT (/' Output requests : '/ &
2766  ' --------------------------------------------------'/ &
2767  ' ',a)
2768 941 FORMAT (/' Type',i2,' : ',a/ &
2769  ' -----------------------------------------')
2770 942 FORMAT ( ' From : ',a)
2771 943 FORMAT ( ' To : ',a)
2772 1944 FORMAT ( ' Interval : ', 8x,a11/)
2773 2944 FORMAT ( ' Interval : ', 9x,a10/)
2774 3944 FORMAT ( ' Interval : ',11x,a8/)
2775 2945 FORMAT ( ' Point 1 : ',2f8.2,2x,a)
2776 2955 FORMAT ( ' Point 1 : ',2(f8.1,'E3'),2x,a)
2777 2946 FORMAT ( ' ',i6,' : ',2f8.2,2x,a)
2778 2956 FORMAT ( ' ',i6,' : ',2(f8.1,'E3'),2x,a)
2779 2947 FORMAT ( ' No points defined')
2780 3945 FORMAT ( ' The file with ',a,' data is ',a,'.')
2781 6945 FORMAT ( ' IX first,last,inc :',3i5/ &
2782  ' IY first,last,inc :',3i5/ &
2783  ' Formatted file : ',a)
2784 8945 FORMAT ( ' output dates out of run dates : ', a, &
2785  ' deactivated')
2786  !
2787 950 FORMAT (/' Initializations :'/ &
2788  ' --------------------------------------------------')
2789 951 FORMAT ( ' ',a)
2790 #ifdef W3_O7
2791 952 FORMAT ( ' ',i6,2x,a)
2792 953 FORMAT ( ' ',i6,i11.8,i7.6,3e12.4)
2793 #endif
2794 954 FORMAT ( ' ',a,': file not needed')
2795 955 FORMAT ( ' ',a,': file OK')
2796 956 FORMAT ( ' ',a,': file OK, recl =',i3, &
2797  ' undef = ',e10.3)
2798  !
2799 960 FORMAT (/' Running model without input fields'/ &
2800  ' --------------------------------------------------'/)
2801  !
2802 970 FORMAT (/' Running model with input fields'/ &
2803  ' --------------------------------------------------')
2804 971 FORMAT (/' Updating input at ',a)
2805 972 FORMAT ( ' Updating ',a)
2806 973 FORMAT ( ' Past last ',a)
2807 #ifdef W3_TIDE
2808 974 FORMAT ( ' Updating ',a,'using tidal constituents')
2809 #endif
2810 975 FORMAT (/' Data assimmilation at ',a)
2811  !
2812 997 FORMAT (/' Initialization time :',f10.2,' s')
2813 998 FORMAT ( ' Elapsed time :',f10.2,' s')
2814  !
2815 999 FORMAT(/' End of program '/ &
2816  ' ===================================='/ &
2817  ' WAVEWATCH III Program shell '/)
2818  !
2819 1000 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2820  ' ERROR IN OPENING INPUT FILE'/ &
2821  ' IOSTAT =',i5/)
2822  !
2823 1001 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2824  ' PREMATURE END OF INPUT FILE'/)
2825  !
2826 1002 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2827  ' ERROR IN READING FROM INPUT FILE'/ &
2828  ' IOSTAT =',i5/)
2829  !
2830 1102 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2831  ' LEVEL AND CURRENT ARE MIXING COUPLED AND FORCED'/&
2832  ' IT MUST BE FULLY COUPLED OR DISABLED '/)
2833  !
2834 1003 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2835  ' ILLEGAL TIME INTERVAL'/)
2836  !
2837 1104 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2838  ' ERROR IN OPENING POINT FILE'/ &
2839  ' IOSTAT =',i5/)
2840  !
2841 1004 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2842  ' ERROR IN READING FROM POINT FILE'/ &
2843  ' IOSTAT =',i5/)
2844  !
2845 1005 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2846  ' ILLEGAL ID STRING HOMOGENEOUS FIELD : ',a/)
2847  !
2848 1006 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2849  ' TOO MANY HOMOGENEOUS FIELDS : ',a,1x,i4/)
2850  !
2851 1062 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : ***'/ &
2852  ' HOMOGENEOUS NAME NOT RECOGNIZED : ', a/)
2853  !
2854 1007 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2855  ' INSUFFICIENT DATA FOR HOMOGENEOUS FIELDS'/)
2856  !
2857 1008 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2858  ' ERROR IN OPENING OUTPUT FILE'/ &
2859  ' IOSTAT =',i5/)
2860  !
2861 #ifdef W3_COU
2862 1009 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2863  ' COUPLING TIME STEP NOT MULTIPLE OF'/ &
2864  ' MODEL TIME STEP: ',i6, i6/)
2865 #endif
2866  !
2867 #ifdef W3_COU
2868 1010 FORMAT (/' *** WAVEWATCH III WARNING IN W3SHEL : *** '/ &
2869  ' COUPLING TIME STEP NOT DEFINED, '/ &
2870  ' IT WILL BE OVERRIDEN TO DEFAULT VALUE'/ &
2871  ' FROM ',i6, ' TO ',i6/)
2872 #endif
2873  !
2874 1054 FORMAT (/' *** WAVEWATCH III ERROR IN W3SHEL : *** '/ &
2875  ' POINT OUTPUT ACTIVATED BUT NO POINTS DEFINED'/)
2876  !
2877  !
2878 #ifdef W3_T
2879 9000 FORMAT ( ' TEST W3SHEL : UNIT NUMBERS :',12i4)
2880 9001 FORMAT ( ' TEST W3SHEL : SUBR. TRACING :',2i4)
2881 #endif
2882  !
2883 #ifdef W3_T
2884 9020 FORMAT ( ' TEST W3SHEL : FLAGS DEF / HOM : ',9l2,2x,9l2)
2885 #endif
2886  !
2887 #ifdef W3_T
2888 9040 FORMAT ( ' TEST W3SHEL : ODAT : ',i9.8,i7.6,i7,i9.8,i7.6, &
2889  4(/24x,i9.8,i7.6,i7,i9.8,i7.6) )
2890 9041 FORMAT ( ' TEST W3SHEL : FLGRD : ',20l2)
2891 9042 FORMAT ( ' TEST W3SHEL : IPR, PRFRM : ',6i6,1x,l1)
2892 #endif
2893  !
2894 #ifdef W3_T
2895 9070 FORMAT ( ' TEST W3SHEL : ',a,3x,2(i10.8,i7.6)/ &
2896  ' ',a,l3,17x,(i10.8,i7.6)/ &
2897  ' ',a,l3,17x,(i10.8,i7.6)/ &
2898  ' ',a,l3,17x,(i10.8,i7.6)/ &
2899  ' ',a,l3,17x,(i10.8,i7.6)/ &
2900  ' ',a,l3,17x,(i10.8,i7.6)/ &
2901  ' ',a,l3,17x,(i10.8,i7.6)/ &
2902  ' ',a,l3,17x,(i10.8,i7.6)/ &
2903  ' ',a,l3,17x,(i10.8,i7.6)/ &
2904  ' ',a,l3,17x,(i10.8,i7.6)/ &
2905  ' ',a,l3,2(i10.8,i7.6)/ &
2906  ' ',a,l3,2(i10.8,i7.6)/ &
2907  ' ',a,l3,17x,(i10.8,i7.6)/ &
2908  ' ',a,l3,2(i10.8,i7.6)/ &
2909  ' ',a,l3,2(i10.8,i7.6)/ &
2910  ' ',a,l3,17x,(i10.8,i7.6)/ &
2911  ' ',a,l3,17x,(i10.8,i7.6)/ &
2912  ' ',a,l3,17x,(i10.8,i7.6)/ &
2913  ' ',a,l3,2(i10.8,i7.6))
2914 9071 FORMAT ( ' TEST W3SHEL : ',a,', DTTST = ',e10.3)
2915 9072 FORMAT ( ' TEST W3SHEL : ',a,3x,2(i10.8,i7.6)/ &
2916  ' ',a,l3,17x,(i10.8,i7.6)/ &
2917  ' ',a,l3,17x,(i10.8,i7.6)/ &
2918  ' ',a,l3,17x,(i10.8,i7.6)/ &
2919  ' ',a,l3,17x,(i10.8,i7.6)/ &
2920  ' ',a,l3,17x,(i10.8,i7.6)/ &
2921  ' ',a,l3,17x,(i10.8,i7.6)/ &
2922  ' ',a,l3,17x,(i10.8,i7.6)/ &
2923  ' ',a,l3,17x,(i10.8,i7.6)/ &
2924  ' ',a,l3,17x,(i10.8,i7.6)/ &
2925  ' ',a,l3,2(i10.8,i7.6)/ &
2926  ' ',a,l3,2(i10.8,i7.6)/ &
2927  ' ',a,l3,17x,(i10.8,i7.6)/ &
2928  ' ',a,l3,2(i10.8,i7.6)/ &
2929  ' ',a,l3,2(i10.8,i7.6)/ &
2930  ' ',a,l3,17x,(i10.8,i7.6)/ &
2931  ' ',a,l3,17x,(i10.8,i7.6)/ &
2932  ' ',a,l3,17x,2(i10.8,i7.6)/ &
2933  ' ',a,l3,2(i10.8,i7.6))
2934 #endif
2935  !/
2936  !/ End of W3SHEL ----------------------------------------------------- /
2937  !/
2938 END PROGRAM w3shel
w3odatmd::iostyp
integer iostyp
Definition: w3odatmd.F90:321
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
w3agcmmd
Module used for coupling applications between atmospheric model and WW3 with OASIS3-MCT.
Definition: w3agcmmd.F90:23
w3idatmd::inflags1
logical, dimension(:), pointer inflags1
Definition: w3idatmd.F90:260
w3odatmd::notype
integer notype
Definition: w3odatmd.F90:327
w3adatmd
Define data structures to set up wave model auxiliary data for several models simultaneously.
Definition: w3adatmd.F90:26
w3timemd::t2d
subroutine t2d(TIME, DAT, IERR)
Definition: w3timemd.F90:1072
w3tidemd
Definition: w3tidemd.F90:3
w3wdasmd
Intended as the interface for externally supplied data assimilation software.
Definition: w3wdasmd.F90:37
w3wdatmd
Define data structures to set up wave model dynamic data for several models simultaneously.
Definition: w3wdatmd.F90:18
w3nmlshelmd
Definition: w3nmlshelmd.F90:3
w3idatmd::inflags2
logical, dimension(:), pointer inflags2
Definition: w3idatmd.F90:260
w3odatmd::dtout
real, dimension(:), pointer dtout
Definition: w3odatmd.F90:467
w3nmlshelmd::nml_output_type_t
Definition: w3nmlshelmd.F90:100
w3odatmd::iaproc
integer, pointer iaproc
Definition: w3odatmd.F90:457
w3odatmd::ngrpp
integer, parameter ngrpp
Definition: w3odatmd.F90:324
w3wdatmd::time
integer, dimension(:), pointer time
Definition: w3wdatmd.F90:172
w3odatmd::fnmpre
character(len=80) fnmpre
Definition: w3odatmd.F90:330
w3odatmd::ofiles
integer, dimension(:), pointer ofiles
Definition: w3odatmd.F90:466
w3oacpmd::cpl_oasis_finalize
subroutine, public cpl_oasis_finalize
Definition: w3oacpmd.F90:705
w3oacpmd::cpl_oasis_define
subroutine, public cpl_oasis_define(NDSO, RCV_STR, SND_STR)
Definition: w3oacpmd.F90:364
w3wdatmd::va
real, dimension(:,:), pointer va
Definition: w3wdatmd.F90:183
w3adatmd::w3dima
subroutine w3dima(IMOD, NDSE, NDST, D_ONLY)
Initialize an individual data grid at the proper dimensions.
Definition: w3adatmd.F90:846
w3igcmmd::snd_fields_to_ice
subroutine, public snd_fields_to_ice()
Send coupling fields to ice model.
Definition: w3igcmmd.F90:77
w3shel
program w3shel
A generic shell for WAVEWATCH III, using preformatted input fields.
Definition: ww3_shel.F90:16
w3gdatmd::w3setg
subroutine w3setg(IMOD, NDSE, NDST)
Definition: w3gdatmd.F90:2152
w3nmlshelmd::nml_input_t
Definition: w3nmlshelmd.F90:60
w3iorsmd::oarst
logical oarst
Definition: w3iorsmd.F90:68
w3adatmd::w3seta
subroutine w3seta(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3adatmd.F90:2645
w3timemd::d2j
subroutine d2j(DAT, JULIAN, IERR)
Definition: w3timemd.F90:1227
w3idatmd::jfirst
integer jfirst
Definition: w3idatmd.F90:162
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
w3wavemd
Contains wave model subroutine, w3wave.
Definition: w3wavemd.F90:13
w3agcmmd::snd_fields_to_atmos
subroutine, public snd_fields_to_atmos()
Send coupling fields to atmospheric model.
Definition: w3agcmmd.F90:89
constants::lpdlib
logical lpdlib
LPDLIB Logical for using the PDLIB library.
Definition: constants.F90:101
w3odatmd::flogrr
logical, dimension(:,:), pointer flogrr
Definition: w3odatmd.F90:478
w3nmlshelmd::nml_homog_input_t
Definition: w3nmlshelmd.F90:153
w3servmd
Definition: w3servmd.F90:3
w3wdatmd::w3setw
subroutine w3setw(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3wdatmd.F90:660
w3ogcmmd
Definition: w3ogcmmd.F90:3
w3odatmd::w3seto
subroutine w3seto(IMOD, NDSERR, NDSTST)
Definition: w3odatmd.F90:1523
w3nmlshelmd::nml_domain_t
Definition: w3nmlshelmd.F90:27
w3servmd::print_memcheck
subroutine print_memcheck(iun, msg)
Write memory statistics if requested.
Definition: w3servmd.F90:2033
w3idatmd::flagsc
logical, dimension(:), pointer flagsc
Definition: w3idatmd.F90:260
w3odatmd
Definition: w3odatmd.F90:3
w3oacpmd
Definition: w3oacpmd.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
w3idatmd::w3seti
subroutine w3seti(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3idatmd.F90:819
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
w3wdatmd::w3dimw
subroutine w3dimw(IMOD, NDSE, NDST, F_ONLY)
Initialize an individual data grid at the proper dimensions.
Definition: w3wdatmd.F90:343
w3igcmmd
Module used for coupling applications between ice model and WW3 with OASIS3-MCT.
Definition: w3igcmmd.F90:15
w3wdatmd::timeend
integer, dimension(:), pointer timeend
Definition: w3wdatmd.F90:176
w3wdatmd::qi5tbeg
integer, dimension(:), pointer qi5tbeg
Definition: w3wdatmd.F90:179
w3odatmd::flout
logical, dimension(:), pointer flout
Definition: w3odatmd.F90:468
w3iogomd
Gridded output of mean wave parameters.
Definition: w3iogomd.F90:15
w3oacpmd::cpl_oasis_grid
subroutine, public cpl_oasis_grid(LD_MASTER, ID_LCOMM)
Definition: w3oacpmd.F90:155
w3oacpmd::id_oasis_time
integer, public id_oasis_time
Definition: w3oacpmd.F90:78
w3idatmd
Define data structures to set up wave model input data for several models simultaneously.
Definition: w3idatmd.F90:16
w3gdatmd::w3nmod
subroutine w3nmod(NUMBER, NDSE, NDST, NAUX)
Definition: w3gdatmd.F90:1433
w3nmlshelmd::w3nmlshel
subroutine w3nmlshel(MPI_COMM, NDSI, INFILE, NML_DOMAIN, NML_INPUT, NML_OUTPUT_TYPE, NML_OUTPUT_DATE, NML_HOMOG_COUNT, NML_HOMOG_INPUT, IERR)
Definition: w3nmlshelmd.F90:174
w3odatmd::napout
integer, pointer napout
Definition: w3odatmd.F90:457
w3ogcmmd::snd_fields_to_ocean
subroutine, public snd_fields_to_ocean()
Definition: w3ogcmmd.F90:63
w3odatmd::idout
character(len=20), dimension(nogrp, ngrpp) idout
Definition: w3odatmd.F90:329
w3oacpmd::cplt0
logical, public cplt0
Definition: w3oacpmd.F90:80
w3nmlshelmd::nml_homog_count_t
Definition: w3nmlshelmd.F90:134
w3wdatmd::time00
integer, dimension(:), pointer time00
Definition: w3wdatmd.F90:175
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
constants
Define some much-used constants for global use (all defined as PARAMETER).
Definition: constants.F90:20
w3odatmd::nogrp
integer, parameter nogrp
Definition: w3odatmd.F90:323
w3gdatmd
Definition: w3gdatmd.F90:16
w3servmd::extcde
subroutine extcde(IEXIT, UNIT, MSG, FILE, LINE, COMM)
Definition: w3servmd.F90:736
w3odatmd::w3nout
subroutine w3nout(NDSERR, NDSTST)
Definition: w3odatmd.F90:561
w3oacpmd::cpl_oasis_init
subroutine, public cpl_oasis_init(ID_LCOMM)
Definition: w3oacpmd.F90:93
w3odatmd::flogr
logical, dimension(:), pointer flogr
Definition: w3odatmd.F90:478
w3timemd
Definition: w3timemd.F90:3
w3idatmd::w3ninp
subroutine w3ninp(NDSE, NDST)
Set up the number of grids to be used.
Definition: w3idatmd.F90:283
w3iorsmd
Read/write restart files.
Definition: w3iorsmd.F90:14
w3initmd
Contains module W3INITMD.
Definition: w3initmd.F90:14
w3iopomd
Process point output.
Definition: w3iopomd.F90:19
w3iogomd::fldout
character(len=1024) fldout
Definition: w3iogomd.F90:154
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
w3gdatmd::dtmax
real, pointer dtmax
Definition: w3gdatmd.F90:1183
w3nmlshelmd::nml_output_date_t
Definition: w3nmlshelmd.F90:121
w3fldsmd
Definition: w3fldsmd.F90:3
w3gdatmd::flagll
logical, pointer flagll
Definition: w3gdatmd.F90:1219