WAVEWATCH III  beta 0.0.1
wminitmd.F90
Go to the documentation of this file.
1 
6 
7 #include "w3macros.h"
8 !/ ------------------------------------------------------------------- /
18 MODULE wminitmd
19  !/
20  !/ +-----------------------------------+
21  !/ | WAVEWATCH III NOAA/NCEP |
22  !/ | H. L. Tolman |
23  !/ | FORTRAN 90 |
24  !/ | Last update : 22-Mar-2021 |
25  !/ +-----------------------------------+
26  !/
27  !/ 13-Jun-2005 : Origination. ( version 3.07 )
28  !/ See subroutine for update log.
29  !/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
30  !/ 30-Oct-2009 : Implement run-time grid selection. ( version 3.14 )
31  !/ (W. E. Rogers & T. J. Campbell, NRL)
32  !/ 16-Aug-2010 : Adding NTRMAX to unify NTRACE. ( version 3.14 )
33  !/ 06-Dec-2010 : Change from GLOBAL (logical) to ICLOSE (integer) to
34  !/ specify index closure for a grid. ( version 3.14 )
35  !/ (T. J. Campbell, NRL)
36  !/ 05-Sep-2011 : Distribute HQFAC anf HPFAC to idle processors for
37  !/ use in WMGRIDMD. ( version 4.05 )
38  !/ 07-Mar-2012 : Adding TNAMES to avoid read warn. ( version 4.07 )
39  !/ Adjust allocation INPMAP and IDINP.
40  !/ 12-Mar-2012 : Fixing format 9061. ( version 3.14 )
41  !/ Use MPI_COMM_NULL for checks instead of fixed '-1'.
42  !/ 28-Jul-2012 : Initialize FLGR2 properly. ( version 4.08 )
43  !/ Tom Durrant's fix, but moved to allocation.
44  !/ 28-Nov-2012 : Bug fix: Distribute to idle processors the grid data
45  !/ required for regridding. ( version 4.08 )
46  !/ (T. J. Campbell, NRL)
47  !/ 02-Sep-2012 : Set up for > 999 test files. ( version 4.10 )
48  !/ Set up output for > 999 procs.
49  !/ 03-Sep-2012 : Output of initilization time. ( version 4.10 )
50  !/ Switch test file on/off (TSTOUT)
51  !/ 18-Dec-2013 : Adding error checking for FLAGLL ( version 4.16 )
52  !/ 28-Jan-2014 : Add memory hwm to profiling. ( version 5.00 )
53  !/ 04-Feb-2014 : Switched clock to DATE_AND_TIME ( version 4.18 )
54  !/ (A. Chawla and Mark Szyszka)
55  !/ 27-May-2014 : Bug fix prf file name. ( version 5.02 )
56  !/ 20-Jan-2017 : Update to new W3GSRUMD APIs ( version 6.02 )
57  !/ 20-Jan-2017 : Modify input forcing flags to support coupler input.
58  !/ Add ESMF override for STIME & ETIME ( version 6.02 )
59  !/ (T. J. Campbell, NRL)
60  !/ 15-May-2018 : Update namelist ( version 6.05 )
61  !/ 22-Mar-2021 : Add momentum and air density input ( version 7.13 )
62  !/
63  !/ Copyright 2009-2014 National Weather Service (NWS),
64  !/ National Oceanic and Atmospheric Administration. All rights
65  !/ reserved. WAVEWATCH III is a trademark of the NWS.
66  !/ No unauthorized use without permission.
67  !/
68  ! 1. Purpose :
69  !
70  ! Initialization of the multi-grid wave model. As a preparation
71  ! for coupled modeling, all initialization, including the
72  ! processing of the input file has ben included in the routine.
73  !
74  ! 2. Variables and types :
75  !
76  ! Name Type Scope Description
77  ! ----------------------------------------------------------------
78  ! NTRMAX Int. Local Maximum number of subroutine trace
79  ! printouts (NTRACE in subr. ITRACE).
80  ! ----------------------------------------------------------------
81  !
82  ! 3. Subroutines and functions :
83  !
84  ! Name Type Scope Description
85  ! ----------------------------------------------------------------
86  ! WMINIT Subr. Public Wave model initialization.
87  ! ----------------------------------------------------------------
88  !
89  ! 4. Subroutines and functions used :
90  !
91  ! See subroutine documentation.
92  !
93  ! 5. Remarks :
94  !
95  ! 6. Switches :
96  !
97  ! See subroutine documentation.
98  !
99  ! 7. Source code :
100  !
101  !/ ------------------------------------------------------------------- /
102  PUBLIC
103  !/
104 
108  INTEGER, PRIVATE :: NTRMAX = 1000
109 
110 
111  !/
112 CONTAINS
113  !/ ------------------------------------------------------------------- /
129  SUBROUTINE wminit ( IDSI, IDSO, IDSS, IDST, IDSE, IFNAME, &
130  MPI_COMM, PREAMB )
131  !/
132  !/ +-----------------------------------+
133  !/ | WAVEWATCH III NOAA/NCEP |
134  !/ | H. L. Tolman |
135  !/ | FORTRAN 90 |
136  !/ | Last update : 22-Mar-2021 |
137  !/ +-----------------------------------+
138  !/
139  !/ 13-Jun-2005 : Origination. ( version 3.07 )
140  !/ 28-Dec-2005 : Add static nesting. ( version 3.08 )
141  !/ 25-May-2006 : Add overlapping grids. ( version 3.09 )
142  !/ 26-Jun-2006 : Add output type 6. ( version 3.09 )
143  !/ 29-Jun-2006 : Adding file name preamble. ( version 3.09 )
144  !/ 09-Aug-2006 : Unified point output added. ( version 3.10 )
145  !/ 14-Oct-2006 : Adding separate input grids. ( version 3.10 )
146  !/ 03-Nov-2006 : Adding wave field separation. ( version 3.10 )
147  !/ 02-Feb-2007 : Adding FLAGST initialization. ( version 3.10 )
148  !/ 21-Jun-2007 : Dedicated output processes. ( version 3.11 )
149  !/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
150  !/ 30-Oct-2009 : Implement run-time grid selection. ( version 3.14 )
151  !/ (W. E. Rogers & T. J. Campbell, NRL)
152  !/ 16-Aug-2010 : Adding NTRMAX to unify NTRACE. ( version 3.14.5 )
153  !/ 21-Sep-2010 : Adding coupling output ( version 3.14-Ifremer)
154  !/ 06-Dec-2010 : Change from GLOBAL (logical) to ICLOSE (integer) to
155  !/ specify index closure for a grid. ( version 3.14 )
156  !/ (T. J. Campbell, NRL)
157  !/ 28-Jul-2012 : Initialize FLGR2 properly. ( version 4.08 )
158  !/ Tom Durant's fix, but moved to allocation.
159  !/ 28-Nov-2012 : Bug fix: Distribute to idle processors the grid data
160  !/ required for regridding. ( version 4.08 )
161  !/ (T. J. Campbell, NRL)
162  !/ 02-Sep-2012 : Set up for > 999 test files. ( version 4.10 )
163  !/ Set up output for > 999 procs.
164  !/ 03-Sep-2012 : Output of initilization time. ( version 4.10 )
165  !/ Switch test file on/off (TSTOUT)
166  !/ 28-Nov-2012 : Bug fix: Distribute to idle processors the grid data
167  !/ required for regridding. ( version 4.08 )
168  !/ (T. J. Campbell, NRL)
169  !/ 15-Apr-2013 : Changes the reading of output fields( version 4.10 )
170  !/ (F. Ardhuin)
171  !/ 28-Jan-2014 : Add memory hwm to profiling. ( version 5.00 )
172  !/ 27-May-2014 : Bug fix prf file name. ( version 5.02 )
173  !/ 17-Sep-2014 : Read mod_def before inp file ( version 5.03 )
174  !/ 20-Jan-2017 : Update to new W3GSRUMD APIs ( version 6.02 )
175  !/ 20-Jan-2017 : Modify input forcing flags to support coupler input.
176  !/ Add ESMF override for STIME & ETIME ( version 6.02 )
177  !/ (T. J. Campbell, NRL)
178  !/ 28-Oct-2020 : Add SMCTYPE for SMC sub-grid. JGLi ( version 7.13 )
179  !/ 22-Mar-2021 : Add momentum and air density input ( version 7.13 )
180  !/
181  ! 1. Purpose :
182  !
183  ! Initialize multi-grid version of WAVEWATCH III.
184  !
185  ! 2. Method :
186  !
187  ! 3. Parameters :
188  !
189  ! Parameter list
190  ! ----------------------------------------------------------------
191  ! IDSI Int. I Unit number for input file.
192  ! IDSO Int. I Unit number for output file.
193  ! IDSS Int. I Unit number for "screen" output. Switch off
194  ! by setting equal to IDSO.
195  ! IDST Int. I Unit number for test output.
196  ! IDSE Int. I Unit number for error output.
197  ! IFNAME Char I File name for input file.
198  ! MPI_COMM Int. I MPI communicator to be used.
199  ! PREAMB Char I File name preamble (optional).
200  ! ----------------------------------------------------------------
201  !
202  ! 4. Subroutines used :
203  !
204  ! Name Type Module Description
205  ! ----------------------------------------------------------------
206  ! W3NMOD Subr. W3GDATMD Data structure initialization.
207  ! W3DIMX Subr. Id. Set grid arrays.
208  ! W3DIMS Subr. Id. Set grid arrays.
209  ! W3SETG Subr. Id. Point to grid/model.
210  ! W3NDAT Subr. W3WDATMD Data structure initialization.
211  ! W3SETW Subr. Id. Point to grid/model.
212  ! W3NAUX Subr. W3ADATMD Data structure initialization.
213  ! W3SETA Subr. Id. Point to grid/model.
214  ! W3NOUT Subr. W3ODATMD Data structure initialization.
215  ! W3SETO Subr. Id. Point to grid/model.
216  ! W3NINP Subr. W3IDATMD Data structure initialization.
217  ! W3SETI Subr. Id. Point to grid/model.
218  ! W3DIMI Subr. Id. Allocate grid/model.
219  ! WMNDAT Subr. WMMDATMD Data structure initialization.
220  ! WMSETM Subr. Id. Point to grid/model.
221  ! WMDIMD Subr. Id. Allocate array space.
222  ! W3FLDO Subr. W3FLDSMD Open input data file.
223  ! W3IOGR Subr. W3IOGRMD Reading of model definition file.
224  ! W3INIT Subr. W3INITMD Model intiailization.
225  ! WMGLOW Subr. WMGRIDMD Lower rank grid dependencies.
226  ! WMGEQL Subr. Id. Same rank grid dependencies.
227  ! WMGHGH Subr. Id. Higher rank grid dependencies.
228  ! RESPEC Subr. Id. Spectral conversion flags.
229  ! WMIOBS Subr. WMINIOMD Stage boundary data.
230  ! WMIOBG Subr. Id. Gather boundary data.
231  ! WMIOBF Subr. Id. Finalize staging in WMIOBS.
232  ! WMUINI Subr. WMUNITMD Initialize dynamic unit assignment,
233  ! WMUDMP Subr. Id. Dump dynamic unit data,
234  ! WMUSET Subr. Id. Set unit number data.
235  ! WMUGET Subr. Id. Get a unit number.
236  ! WMUINQ Subr. Id. Update unit number info.
237  ! WMIOPP Subr. WMIOPOMD Initialize unified point output.
238  ! ITRACE Subr. W3SERVMD Initialize subroutine tracing.
239  ! STRACE Subr. Id. Subroutine tracing.
240  ! EXTCDE Subr. Id. Program abort.
241  ! WWDATE Subr. Id. System date.
242  ! WWTIME Subr. Id. System time.
243  ! NEXTLN Subr. Id. Find next input line in file.
244  ! PRINIT Subr. Id. Profiling routine ( !/MPRF )
245  ! PRTIME Subr. Id. Profiling routine ( !/MPRF )
246  ! STME21 Subr. W3TIMEMD Convert time to string.
247  ! DSEC21 Func. Id. Difference between times.
248  ! TICK21 Subr. Id. Advance the clock.
249  ! W3READFLGRD Subr. W3IOGOMD Reads flags or namelist for output fields
250  !
251  ! MPI_COMM_SIZE, CALL MPI_COMM_RANK, MPI_BARRIER, MPI_COMM_GROUP,
252  ! MPI_GROUP_INCLUDE, MPI_COMM_CREATE, MPI_GROUP_FREE, MPI_BCAST
253  ! Subr. mpif.h Standard MPI routines.
254  ! ----------------------------------------------------------------
255  !
256  ! 5. Called by :
257  !
258  ! Name Type Module Description
259  ! ----------------------------------------------------------------
260  ! W3MLTI Prog. N/A Multi-grid model driver.
261  ! .... Any coupled model.
262  ! ----------------------------------------------------------------
263  !
264  ! 6. Error messages :
265  !
266  ! See formats 1000 and following, or escape locations 2000 and
267  ! following.
268  !
269  ! 7. Remarks :
270  !
271  ! - When running regtests in cases where disk is non-local
272  ! (i.e. NFS used), there can be a huge improvment in compute
273  ! time by using /var/tmp/ for log files.
274  ! See commented line at "OPEN (MDSO,FILE=..."
275  !
276  ! - IDFLDS dimensioning is hardwired as IDFLDS(-7:9) where lowest possible
277  ! value of JFIRST is JFIRST=-7
278  !
279  ! 8. Structure :
280  !
281  ! --------------------------------------------------------------
282  ! 1. Multi-grid model intializations
283  ! a Unit numbers
284  ! b Subroutine tracing ( ITRACE )
285  ! c Input file
286  ! d Log and test files
287  ! e Initial and test output
288  ! 2. Set-up of data structures and I/O
289  ! a Get number of grids
290  ! b Set up data structures
291  ! ( W3NMOD, W3NDAT, W3NAUX, W3NOUT, W3NINP, WMNDAT )
292  ! c Set up I/O for individual models
293  ! 3. Get individual grid information
294  ! a Read data
295  ! b Assign input file numbers.
296  ! c Set rank and group data
297  ! d Unified point output file. ( W3IOGR )
298  ! e Output
299  ! 4. Model run time information and settings
300  ! 5. Output requests
301  ! a Loop over types for unified output
302  ! ---------------------------------------------------
303  ! b Process standard line
304  ! c Type 1: fields of mean wave parameters
305  ! d Type 2: point output
306  ! e Type 3: track output
307  ! f Type 4: restart files (no additional data)
308  ! g Type 5: nesting data (no additional data)
309  ! h Type 6: wave field data (dummy for now)
310  ! i Set all grids to unified output
311  ! ---------------------------------------------------
312  ! j Endless loop for correcting output per grid
313  ! ---------------------------------------------------
314  ! Test grid name and output number
315  ! k Process standard line
316  ! l Type 1: fields of mean wave parameters
317  ! m Type 2: point output
318  ! n Type 3: track output
319  ! o Type 6: partitioning output
320  ! p Type 7: coupling output
321  ! ---------------------------------------------------
322  ! 6. Read moving grid data
323  ! 7. Work load distribution
324  ! a Initialize arrays
325  ! b Set communicators and ALLPRC array
326  ! c Set MODMAP and LOADMP arrays
327  ! d Warnings
328  ! 8. Actual initializations
329  ! a Loop over models for per-model initialization
330  ! 1 Wave model ( W3INIT )
331  ! 2 Data files ( W3FLDO )
332  ! 3 Grid status indicator and model times
333  ! 3 Grid data for processors that are NOT used.
334  ! 5 Test output
335  ! b Input data files.
336  ! c Inter model initialization
337  ! 1 Set spectral conversion flags ( WMRSPC )
338  ! 2 Prepare unified point output ( WMIOPO )
339  ! 3 Relation to lower ranked grids
340  ! ( WMGLOW, WMIOBS, WMIOBG, WMIOBF )
341  ! 4 Relation to same ranked grids ( WMGEQL )
342  ! 5 Relation to higher ranked grids ( WMGHGH )
343  ! 6 Output
344  ! --------------------------------------------------------------
345  !
346  ! 9. Switches :
347  !
348  ! !/SHRD Switch for shared / distributed memory architecture.
349  ! !/DIST Id.
350  ! !/MPI Id.
351  !
352  ! !/MGW Moving grid wind correction.
353  ! !/MGP Moving grid propagation correction.
354  !
355  ! !/O10 Enable output identifying start and end of routine
356  !
357  ! !/S Enable subroutine tracing.
358  ! !/T Enable test output.
359  ! !/MPRF Profiling.
360  !
361  ! 10. Source code :
362  !
363  !/ ------------------------------------------------------------------- /
364  USE constants
365  !/
366  USE w3gdatmd, ONLY: w3nmod, w3dimx, w3dims, w3setg
367  USE w3wdatmd, ONLY: w3ndat, w3setw
368  USE w3adatmd, ONLY: w3naux, w3seta
369  USE w3odatmd, ONLY: w3nout, w3seto
370  USE w3idatmd, ONLY: w3ninp, w3seti, w3dimi
371  USE wmmdatmd, ONLY: wmndat, wmsetm, wmdimd
372  !
373  USE w3fldsmd, ONLY: w3fldo
374  USE w3iogomd, ONLY: w3readflgrd
375  USE w3iogrmd, ONLY: w3iogr
376  USE w3initmd, ONLY: w3init
377  USE wmgridmd, ONLY: wmrspc, wmglow, wmgeql, wmghgh, wmsmceql
378  USE wminiomd, ONLY: wmiobs, wmiobg, wmiobf
379  USE wmiopomd, ONLY: wmiopp
380  !/
381  USE w3servmd, ONLY: itrace, extcde, wwdate, wwtime, nextln
382 #ifdef W3_S
383  USE w3servmd, ONLY: strace
384 #endif
385 #ifdef W3_MPRF
386  USE w3timemd, ONLY: prinit, prtime
387 #endif
388  USE w3timemd, ONLY: stme21, dsec21, tick21, tdiff
389  USE wmunitmd, ONLY: wmuini, wmudmp, wmuset, wmuget, wmuinq
390  !/
391  USE w3gdatmd, ONLY: gtype, nx, ny, filext, nsea, flagst, grids
392 #ifdef W3_SMC
393  USE w3gdatmd, ONLY: ncel, nufc, nvfc, nrlv, nbsmc
394  USE w3gdatmd, ONLY: narc, nbac, nspec, smctype
395 #endif
396 #ifdef W3_MPI
397  USE w3gdatmd, ONLY: flagll, iclose, gsu, x0, y0, sx, sy, &
398  xgrd, ygrd, dxdp, dxdq, dydp, dydq, &
399  hqfac, hpfac, mapsta, mapst2, &
400  gridshift, nseal, nk, nth, xfr, fr1, &
401  th, dtmax, dtcfl
402  USE w3gsrumd
403 #endif
404  USE w3wdatmd, ONLY: time
405  USE w3adatmd, ONLY: wadats
406  USE w3idatmd, ONLY: inflags1, inflags2, inputs, iinit, &
407  jfirst
408  USE w3odatmd, ONLY: nogrp, ngrpp, flout, tonext, flbpi, &
409  flbpo, nfbpo, nbi, nds, iaproc, &
410  napfld, nappnt, naptrk, napbpt, &
413  tolast, notype
414  USE wmmdatmd, ONLY: mdsi, mdso, mdss, mdst, mdse, mdsf, mdsup, &
415  improc, nmproc, nmpscr, nmperr, &
417  tmv, amv, dmv, nrgrd, nrinp, nrgrp, grank, &
422  USE wmmdatmd, ONLY: clkdt1, clkdt2, clkfin
423 #ifdef W3_MPI
424  USE wmmdatmd, ONLY: mpi_comm_mwave, mpi_comm_grd, &
426 #endif
427 #ifdef W3_MPRF
428  USE wmmdatmd, ONLY: mdsp
429 #endif
430 #ifdef W3_ASCII
431  USE wmmdatmd, ONLY: mdsupa
432 #endif
433  USE w3initmd, ONLY: wwver
434  USE w3odatmd, ONLY: ofiles
435  !
436  !/
437  IMPLICIT NONE
438  !
439 #ifdef W3_MPI
440  include "mpif.h"
441 #endif
442  !/
443  !/ ------------------------------------------------------------------- /
444  !/ Parameter list
445  !/
446  INTEGER, INTENT(IN) :: IDSI, IDSO, IDSS, IDST, IDSE, &
447  MPI_COMM
448  CHARACTER*(*), INTENT(IN) :: IFNAME
449  CHARACTER*(*), INTENT(IN), OPTIONAL :: PREAMB
450  !/
451  !/ ------------------------------------------------------------------- /
452  !/ Local parameters
453  !/
454  INTEGER :: MDSE2, IERR, I, J, NMOVE, TTIME(2), &
455  ILOOP, MDSI2, SCRATCH, RNKMIN, &
456  RNKMAX, RNKTMP, GRPMIN, GRPMAX, II, &
457  NDSREC, NDSFND, NPTS, JJ, IP1, IPN, &
458  MPI_COMM_LOC, NMPSC2, JJJ, TOUT(2), &
459  TLST(2), NCPROC, NPOUTT, NAPLOC, &
460  NAPRES, NAPADD, NAPBCT, IFI, IFJ, IW,&
461  IFT
462  INTEGER :: STMPT(2), ETMPT(2)
463 #ifdef W3_MPI
464  INTEGER :: IERR_MPI, BGROUP, LGROUP, IROOT
465 #endif
466 #ifdef W3_S
467  INTEGER, SAVE :: IENT = 0
468 #endif
469  INTEGER, ALLOCATABLE :: MDS(:,:), NTRACE(:,:), ODAT(:,:), &
470  TMPRNK(:), TMPGRP(:), NINGRP(:), &
471  TMOVE(:,:), LOADMP(:,:), IPRT(:,:), &
472  NDPOUT(:), OUTFF(:,:)
473  REAL :: DTTST, XX, YY
474 
475 #ifdef W3_MPRF
476  REAL :: PRFT0, PRFTN
477  REAL(KIND=8) :: get_memory
478 #endif
479  REAL, ALLOCATABLE :: X(:), Y(:), AMOVE(:), DMOVE(:), &
480  RP1(:), RPN(:)
481  LOGICAL :: FLT, TFLAGI, TFLAGS(-7:14), PSHARE
482  LOGICAL, ALLOCATABLE :: FLGRD(:,:,:), FLRBPI(:), BCDTMP(:), &
483  USEINP(:), LPRT(:), FLGR2(:,:,:), &
484  FLGD(:,:), FLG2(:,:), FLG2D(:,:), &
485  FLG1D(:), CPLINP(:)
486  CHARACTER(LEN=1) :: COMSTR
487  CHARACTER(LEN=3) :: IDSTR(9), IDTST
488  CHARACTER(LEN=5) :: STOUT, OUTSTR(6)
489  CHARACTER(LEN=6) :: ACTION(11), YESXX, XXXNO
490  CHARACTER(LEN=8) :: LFILE, STTIME
491 #ifdef W3_SHRD
492  CHARACTER(LEN=9) :: TFILE
493 #endif
494  CHARACTER(LEN=13) :: STDATE, MN, TNAMES(9)
495  CHARACTER(LEN=40) :: PN
496  CHARACTER(LEN=13), &
497  ALLOCATABLE :: INAMES(:,:), MNAMES(:)
498  CHARACTER(LEN=40), &
499  ALLOCATABLE :: PNAMES(:)
500  CHARACTER(LEN=12) :: FORMAT
501 #ifdef W3_DIST
502  CHARACTER(LEN=18) :: TFILE
503 #endif
504 #ifdef W3_MPRF
505  CHARACTER(LEN=18) :: PFILE
506 #endif
507 
508  CHARACTER(LEN=13) :: IDFLDS(-7:9)
509  CHARACTER(LEN=23) :: DTME21
510  CHARACTER(LEN=30) :: IDOTYP(8)
511  CHARACTER(LEN=80) :: TNAME
512  CHARACTER(LEN=80) :: LINE
513  CHARACTER(LEN=80) :: LINEIN
514  CHARACTER(LEN=8) :: WORDS(6)
515 
516  TYPE ot2tpe
517  INTEGER :: NPTS
518  REAL, POINTER :: X(:), Y(:)
519  CHARACTER(LEN=40), POINTER :: PNAMES(:)
520  END TYPE ot2tpe
521  !
522  TYPE(ot2tpe), ALLOCATABLE :: OT2(:)
523  !/
524  !/ ------------------------------------------------------------------- /
525  !/
526 
527  DATA idflds / 'ice param. 1 ' , 'ice param. 2 ' , &
528  'ice param. 3 ' , 'ice param. 4 ' , &
529  'ice param. 5 ' , &
530  'mud density ' , 'mud thkness ' , &
531  'mud viscos. ' , &
532  'water levels ' , 'currents ' , &
533  'winds ' , 'ice fields ' , &
534  'momentum ' , 'air density ' , &
535  'mean param. ' , '1D spectra ' , &
536  '2D spectra ' /
537  !
538  DATA idotyp / 'Fields of mean wave parameters' , &
539  'Point output ' , &
540  'Track point output ' , &
541  'Restart files ' , &
542  'Nesting data ' , &
543  'Separated wave field data ' , &
544  'Fields for coupling ' , &
545  'Restart files second request '/
546  !
547  DATA idstr / 'LEV', 'CUR', 'WND', 'ICE', 'TAU', 'RHO', &
548  'DT0', 'DT1', 'DT2' /
549  !
550  DATA yesxx / 'YES/--' /
551  DATA xxxno / '---/NO' /
552  !
553 #ifdef W3_MPRF
554  CALL prinit
555  CALL prtime ( prft0 )
556 #endif
557  !
558  CALL date_and_time ( values=clkdt1 )
559  !
560  mpi_comm_loc = mpi_comm
561 #ifdef W3_MPI
562  mpi_comm_mwave = mpi_comm
563  CALL mpi_comm_size ( mpi_comm_mwave, nmproc, ierr_mpi )
564  CALL mpi_comm_rank ( mpi_comm_mwave, improc, ierr_mpi )
565  improc = improc + 1
566 #endif
567  !
568  IF ( PRESENT(preamb) ) fnmpre = preamb
569  !/
570  !/ ------------------------------------------------------------------- /
571  ! 1. Multi-grid model intializations
572  ! 1.a Unit numbers
573  ! Initialize dynamic assignment, errors and test to stdout
574  !
575  CALL wmuini ( 6, 6 )
576  !
577  ! ... Identify reserved unit numbers
578  !
579  CALL wmuset ( 6,6, 5, .true., 'SYS', 'stdin', 'Standart input' )
580  CALL wmuset ( 6,6, 6, .true., 'SYS', 'stdout','Standart output')
581  !
582 #ifdef W3_NL2
583  CALL wmuset (6,6,103, .true., 'FIX', desc='Reserved SNL2' )
584  CALL wmuset (6,6,104, .true., 'FIX', desc='Reserved SNL2' )
585  CALL wmuset (6,6,105, .true., 'FIX', desc='Reserved SNL2' )
586  CALL wmuset (6,6,106, .true., 'FIX', desc='Reserved SNL2' )
587  CALL wmuset (6,6,107, .true., 'FIX', desc='Reserved SNL2' )
588  CALL wmuset (6,6,108, .true., 'FIX', desc='Reserved SNL2' )
589  CALL wmuset (6,6,109, .true., 'FIX', desc='Reserved SNL2' )
590  CALL wmuset (6,6,110, .true., 'FIX', desc='Reserved SNL2' )
591  CALL wmuset (6,6,111, .true., 'FIX', desc='Reserved SNL2' )
592  CALL wmuset (6,6,112, .true., 'FIX', desc='Reserved SNL2' )
593  CALL wmuset (6,6,113, .true., 'FIX', desc='Reserved SNL2' )
594  CALL wmuset (6,6,114, .true., 'FIX', desc='Reserved SNL2' )
595  CALL wmuset (6,6,117, .true., 'FIX', desc='Reserved SNL2' )
596 #endif
597  !
598  ! ... Unit numbers from parameter list
599  ! Dynamic scripture updated per file
600  !
601  mdsi = idsi
602  mdso = idso
603  mdss = idss
604  mdst = idst
605  mdse = idse
606  !
607  IF ( improc .EQ. nmperr ) THEN
608  mdse2 = mdse
609  ELSE
610  mdse2 = -1
611  END IF
612  !
613  ! 1.b Subroutine tracing
614  !
615  CALL itrace ( mdst, ntrmax )
616  !
617 #ifdef W3_O10
618  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,900)
619 #endif
620  !
621  ! 1.c Input file
622  !
623  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
624  WRITE (mdss,910) ifname, mdsi
625  !
626  OPEN (mdsi,file=trim(fnmpre)//ifname,status='OLD',err=2000, &
627  iostat=ierr)
628  rewind(mdsi)
629  READ (mdsi,'(A)',END=2001,ERR=2002) comstr
630  IF (comstr.EQ.' ') comstr = '$'
631  CALL wmuset ( mdss, mdss, mdsi, .true., 'INP', &
632  trim(fnmpre)//ifname, 'Model control input file')
633  !
634  ! 1.d Log and test files
635  !
636  lfile = 'log.mww3'
637  iw = 1 + int( log10( real(nmproc) + 0.5 ) )
638  iw = max( 3 , min( 9 , iw ) )
639  WRITE (FORMAT,'(A5,I1.1,A1,I1.1,A4)') '(A4,I',iw,'.',iw,',A5)'
640 #ifdef W3_SHRD
641  tfile = 'test.mww3'
642 #endif
643 #ifdef W3_DIST
644  WRITE (tfile,format) 'test', improc, '.mww3'
645 #endif
646 #ifdef W3_MPRF
647  WRITE (pfile,format) 'prf.', improc, '.mww3'
648 #endif
649  !
650  IF ( improc .EQ. nmplog ) THEN
651  OPEN (mdso,file=trim(fnmpre)//lfile,err=2010,iostat=ierr)
652  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
653  WRITE (mdss,911) lfile, mdso
654  CALL wmuset ( mdss, mdss, mdso, .true., 'OUT', &
655  trim(fnmpre)//lfile, 'Log file')
656  ELSE
657  CALL wmuset ( mdss, mdss, mdso, .true., 'XXX', &
658  'Log file on other processors')
659  END IF
660  !
661  IF ( mdst.NE.mdso .AND. mdst.NE.mdss .AND. tstout ) THEN
662  ift = len_trim(tfile)
663  OPEN (mdst,file=trim(fnmpre)//tfile(:ift),err=2011,iostat=ierr)
664  CALL wmuset ( mdss, mdst, mdst, .true., 'OUT', &
665  trim(fnmpre)//tfile(:ift), 'Test output file')
666  END IF
667  !
668 #ifdef W3_MPRF
669  ift = len_trim(pfile)
670  CALL wmuget ( mdss, mdst, mdsp, 'OUT' )
671  CALL wmuset ( mdss, mdst, mdsp, .true., 'OUT', &
672  trim(fnmpre)//pfile(:ift), 'Profiling file')
673  OPEN (mdsp,file=trim(fnmpre)//pfile(:ift),err=2011,iostat=ierr)
674 #endif
675  !
676  ! 1.e Initial and test output
677  !
678 #ifdef W3_S
679  CALL strace (ient, 'WMINIT')
680 #endif
681  !
682  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,912) comstr
683  !
684  IF ( improc .EQ. nmplog ) THEN
685  CALL wwdate ( stdate )
686  CALL wwtime ( sttime )
687  WRITE (mdso,901) wwver, stdate, sttime
688  END IF
689  !
690 #ifdef W3_T
691  WRITE(mdst,9000) idsi, idso, idss, idst, idse, ifname
692 #endif
693  !
694  ! 2. Set-up of data structures and I/O ----------------------------- /
695  ! 2.a Get number of grids
696  ! Note: grid for consolidated point output always generated.
697  ! Processor set as in W3INIT to minimize communication in WMIOPO
698  !
699  CALL nextln ( comstr , mdsi , mdse2 )
700  READ (mdsi,*,END=2001,ERR=2002) NRGRD, NRINP, UNIPTS, &
701  iostyp, upproc, pshare
702  iostyp = max( 0 , min( 3 , iostyp ) )
703  !
704  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
705  WRITE (mdss,920) nrgrd
706  IF ( nrinp .EQ. 0 ) THEN
707  WRITE (mdss,921)
708  ELSE
709  WRITE (mdss,922) nrinp
710  END IF
711  IF ( unipts ) THEN
712  WRITE (mdss,923) yesxx
713  ELSE
714  WRITE (mdss,923) xxxno
715  END IF
716  WRITE (mdss,1923) iostyp
717  IF ( unipts ) THEN
718  IF ( upproc ) THEN
719  WRITE (mdss,2923) yesxx
720  ELSE
721  WRITE (mdss,2923) xxxno
722  END IF
723  END IF
724  IF ( iostyp.GT.1 .AND. pshare ) THEN
725  WRITE (mdss,3923) yesxx
726  ELSE IF ( iostyp.GT. 1 ) THEN
727  WRITE (mdss,3923) xxxno
728  END IF
729  END IF
730  !
731  IF ( nrgrd .LT. 1 ) GOTO 2020
732  IF ( nrinp .LT. 0 ) GOTO 2021
733  IF ( nrinp.EQ.0 .AND. .NOT.unipts ) nrinp = -1
734  !
735  ! 2.b Set up data structures
736  !
737  CALL w3nmod ( nrgrd, mdse2, mdst, nrinp )
738  CALL w3ndat ( mdse2, mdst )
739  CALL w3naux ( mdse2, mdst )
740  CALL w3nout ( mdse2, mdst )
741  CALL w3ninp ( mdse2, mdst )
742  CALL wmndat ( mdse2, mdst )
743  !
744  ! 2.c Set up I/O for individual models (initial)
745  !
746  ALLOCATE ( mds(15,nrgrd), ntrace(2,nrgrd), odat(40,0:nrgrd), &
747  flgrd(nogrp,ngrpp,nrgrd), ot2(0:nrgrd), flgd(nogrp,nrgrd), &
748  mdsf(-nrinp:nrgrd,jfirst:9), iprt(6,nrgrd), lprt(nrgrd), &
749  flgr2(nogrp,ngrpp,nrgrd),flg2d(nogrp,ngrpp), flg1d(nogrp), &
750  flg2(nogrp,nrgrd),outff(7,0:nrgrd))
751  !
752  mds = -1
753  mdsf = -1
754  flgr2 = .false.
755  flg2 = .false.
756  lprt = .false.
757  iprt = 0
758  !
759  ! ... Fixed and recycleable unit numbers.
760  !
761  CALL wmuget ( mdse, mdst, ndsrec, 'INP' )
762  CALL wmuset ( mdse, mdst, ndsrec, .true., 'I/O', name='...', &
763  desc='Recyclable I/O (mod_def etc.)' )
764  CALL wmuget ( mdse, mdst, scratch, 'SCR' )
765  CALL wmuset ( mdse, mdst, scratch, .true., desc='Scratch file', &
766  name=trim(fnmpre)//'ww3_multi.scratch' )
767  !
768  IF(mdst.EQ.ndsrec)THEN
769  IF ( improc .EQ. nmperr ) &
770  WRITE(mdse,'(A,I8)')'RECYCLABLE UNIT NUMBERS AND '&
771  //'TEST OUTPUT UNIT NUMBER ARE THE SAME : ',mdst
772  CALL extcde ( 15 )
773  ENDIF
774 
775  DO i=1, nrgrd
776  mds( 2,i) = 6
777  mds( 3,i) = mdst
778  mds( 4,i) = 6
779  mds( 5,i) = ndsrec
780  mds( 6,i) = ndsrec
781  ntrace( 1,i) = mdst
782  ntrace( 2,i) = ntrmax
783  END DO
784  !
785 #ifdef W3_T
786  WRITE (mdst,9020) 'INITIAL'
787  DO i=1, nrgrd
788  WRITE (mdst,9021) i, mds(:,i), ntrace(:,i)
789  END DO
790 #endif
791  !
792  ! 3. Get individual grid information -------------------------------- /
793  !
794  ! Version 3.07: For now we simply read the input data flags,
795  ! skip the homogeneous option. Later on, we want
796  ! to have the options to use input from common
797  ! sources, and from communication rather than
798  ! files.
799  !
800  ALLOCATE ( inames(2*nrgrd,jfirst:9), mnames(-nrinp:2*nrgrd), &
801  tmprnk(2*nrgrd), tmpgrp(2*nrgrd), ningrp(2*nrgrd), &
802  rp1(2*nrgrd), rpn(2*nrgrd), bcdtmp(nrgrd+1:2*nrgrd) )
803  ALLOCATE ( grank(nrgrd), grgrp(nrgrd), useinp(nrinp) )
804  ALLOCATE ( cplinp(nrinp) )
805  grank = -1
806  grgrp = -1
807  useinp = .false.
808  cplinp = .false.
809  !
810  ! 3.a Read data
811  !
812 #ifdef W3_T
813  WRITE (mdst,9030)
814 #endif
815  !
816  ! 3.a.1 Input grids
817  !
818  DO i=1, nrinp
819  !
820  CALL nextln ( comstr , mdsi , mdse2 )
821  CALL w3seti ( -i, mdse, mdst )
822  inflags1 = .false.
823  READ (mdsi,*,END=2001,ERR=2002) MNAMES(-I), INFLAGS1(JFIRST:9)
824  !
825  END DO
826  !
827  ! 3.a.2 Unified point output grid.
828  !
829  IF ( unipts ) THEN
830  !
831  CALL w3seti ( 0, mdse, mdst )
832  CALL w3seto ( 0, mdse, mdst )
833  inflags1 = .false.
834  ndst = mdst
835  ndse = mdse
836  !
837  CALL nextln ( comstr , mdsi , mdse2 )
838  READ (mdsi,*,END=2001,ERR=2002) MNAMES(0)
839  !
840  IF ( iostyp .LE. 1 ) THEN
841  nmpupt = max(1,nmproc-2)
842  ELSE
843  nmpupt = nmproc
844  END IF
845  !
846  END IF
847  !
848  ! 3.a.3 Read wave grids
849  !
850  DO i=nrgrd+1, 2*nrgrd
851  CALL nextln ( comstr , mdsi , mdse2 )
852  READ (mdsi,*,END=2001,ERR=2002) MNAMES(I), TNAMES(:), &
853  tmprnk(i), tmpgrp(i), rp1(i), rpn(i), bcdtmp(i)
854  inames(i,:) = tnames(:)
855  rp1(i) = max( 0. , min( 1. , rp1(i) ) )
856  rpn(i) = max( rp1(i) , min( 1. , rpn(i) ) )
857  END DO
858  !
859  ! 3.a.4 Sort wave grids
860  !
861  rnktmp = minval( tmprnk(nrgrd+1:2*nrgrd) )
862  i = 0
863  !
864  DO
865  DO j=nrgrd+1, 2*nrgrd
866  IF ( tmprnk(j) .EQ. rnktmp ) THEN
867  i = i + 1
868  CALL w3seti ( i, mdse, mdst )
869  inflags1 = .false.
870 #ifdef W3_MGW
871  inflags1(10) = .true.
872 #endif
873 #ifdef W3_MGP
874  inflags1(10) = .true.
875 #endif
876  inames(i,:)= inames(j,:)
877  mnames(i) = mnames(j)
878  tmprnk(i) = tmprnk(j)
879  tmpgrp(i) = tmpgrp(j)
880  rp1(i) = rp1(j)
881  rpn(i) = rpn(j)
882  bcdump(i) = bcdtmp(j)
883 #ifdef W3_T
884  WRITE (mdst,9031) i, mnames(i), inflags1, tmprnk(i), &
885  tmpgrp(i), rp1(i), rpn(i)
886 #endif
887  END IF
888  END DO
889  IF ( i .EQ. nrgrd ) EXIT
890  rnktmp = rnktmp + 1
891  END DO
892  !
893  ! 3.a.5 Set input flags
894  !
895  ALLOCATE ( inpmap(nrgrd,jfirst:10), idinp(-nrinp:nrgrd,jfirst:10) )
896  inpmap = 0
897  idinp = '---'
898  !
899  DO i=1, nrgrd
900  CALL w3seti ( i, mdse, mdst )
901  DO j=jfirst, 9
902  IF ( inames(i,j) .EQ. 'native' ) THEN
903  ! *** forcing input from file & defined on the native grid ***
904  inflags1(j) = .true.
905  ELSE
906  inflags1(j) = .false.
907  IF ( inames(i,j)(1:4) .EQ. 'CPL:' ) THEN
908  IF ( inames(i,j)(5:) .EQ. 'native' ) THEN
909  ! *** forcing input from CPL & defined on the native grid ***
910  inflags1(j) = .true.
911  inpmap(i,j) = -999
912  ELSE
913  ! *** forcing input from CPL & defined on an input grid ***
914  DO jj=1, nrinp
915  IF ( mnames(-jj) .EQ. inames(i,j)(5:) ) THEN
916  inpmap(i,j) = -jj
917  EXIT
918  END IF
919  END DO
920  IF ( inpmap(i,j) .EQ. 0 ) GOTO 2030
921  IF ( .NOT. inputs(inpmap(i,j))%INFLAGS1(j) ) GOTO 2031
922  useinp(-inpmap(i,j)) = .true.
923  cplinp(-inpmap(i,j)) = .true.
924  END IF
925  ELSE IF ( inames(i,j) .NE. 'no' ) THEN
926  ! *** forcing input from file & defined on an input grid ***
927  DO jj=1, nrinp
928  IF ( mnames(-jj) .EQ. inames(i,j) ) THEN
929  inpmap(i,j) = jj
930  inflags2(j) = .true.
931  EXIT
932  END IF
933  END DO
934  IF ( inpmap(i,j) .EQ. 0 ) GOTO 2030
935  IF ( .NOT. inputs(-inpmap(i,j))%INFLAGS1(j) ) GOTO 2031
936  useinp(inpmap(i,j)) = .true.
937  END IF
938  END IF
939  ! INFLAGS2 is initial value of INFLAGS1. Unlike INFLAGS1,
940  ! it does not change during the simulation
941  IF(.NOT. inflags2(j)) inflags2(j)=inflags1(j)
942  END DO ! DO J=JFIRST, 9
943  END DO ! DO I=1, NRGRD
944  !
945  DO i=1, nrinp
946  IF ( .NOT.useinp(i) .AND. &
947  mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
948  ii = len_trim(mnames(-i))
949  WRITE (mdse,1032) mnames(-i)(1:ii)
950  END IF
951  END DO
952  !
953  ! 3.b Assign input file unit numbers
954  !
955  DO i=-nrinp, nrgrd
956  IF ( i .EQ. 0 ) cycle
957  CALL w3seti ( i, mdse, mdst )
958  DO j=jfirst, 9
959  IF ( i .GE. 1 ) THEN
960  IF ( inpmap(i,j) .LT. 0 ) cycle
961  END IF
962  IF ( inflags1(j) ) THEN
963  CALL wmuget ( mdse, mdst, ndsfnd, 'INP' )
964  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
965  desc='Input data file' )
966  mdsf(i,j) = ndsfnd
967  END IF
968  END DO
969  END DO
970  !
971 #ifdef W3_T
972  WRITE (mdst,9022)
973  DO i=-nrinp, nrgrd
974  IF ( i .EQ. 0 ) cycle
975  WRITE (mdst,9021) i, mdsf(i,jfirst:9)
976  END DO
977 #endif
978  !
979  ! 3.c Set rank and group data
980  !
981 #ifdef W3_T
982  WRITE (mdst,9032)
983 #endif
984  !
985  rnkmax = maxval( tmprnk(1:nrgrd) ) + 1
986  rnktmp = 0
987  !
988  DO
989  rnkmin = minval( tmprnk(1:nrgrd) )
990  IF ( rnkmin .EQ. rnkmax ) EXIT
991  rnktmp = rnktmp + 1
992  DO i=1, nrgrd
993  IF ( tmprnk(i) .EQ. rnkmin ) THEN
994  grank(i) = rnktmp
995  tmprnk(i) = rnkmax
996  END IF
997  END DO
998  END DO
999  !
1000 #ifdef W3_T
1001  DO i=1, nrgrd
1002  WRITE (mdst,9033) i, mnames(i), grank(i)
1003  END DO
1004 #endif
1005  !
1006  rnkmax = rnktmp
1007  grpmax = maxval( tmpgrp(1:nrgrd) ) + 1
1008  nrgrp = 0
1009  ningrp = 0
1010  !
1011  DO rnktmp=1, rnkmax
1012  DO
1013  grpmin = grpmax
1014  DO i=1, nrgrd
1015  IF ( grank(i) .EQ. rnktmp ) &
1016  grpmin = min( grpmin , tmpgrp(i) )
1017  END DO
1018  IF ( grpmin .EQ. grpmax ) EXIT
1019  nrgrp = nrgrp + 1
1020  DO i=1, nrgrd
1021  IF ( grank(i).EQ.rnktmp .AND. grpmin.EQ.tmpgrp(i) ) THEN
1022  grgrp(i) = nrgrp
1023  tmpgrp(i) = grpmax
1024  ningrp(nrgrp) = ningrp(nrgrp) + 1
1025  END IF
1026  END DO
1027  END DO
1028  END DO
1029  !
1030 #ifdef W3_T
1031  WRITE (mdst,9034) nrgrp
1032  DO i=1, nrgrd
1033  WRITE (mdst,9033) i, mnames(i), grgrp(i)
1034  END DO
1035  WRITE (mdst,9035) ningrp(1:nrgrp)
1036 #endif
1037  !
1038  ALLOCATE ( ingrp(nrgrp,0:maxval(ningrp(:nrgrp))) )
1039  DEALLOCATE ( tmprnk, tmpgrp, ningrp, bcdtmp )
1040  ingrp = 0
1041  !
1042  DO i=1, nrgrd
1043  ingrp(grgrp(i),0) = ingrp(grgrp(i),0) + 1
1044  ingrp(grgrp(i),ingrp(grgrp(i),0)) = i
1045  END DO
1046  !
1047 #ifdef W3_T
1048  WRITE (mdst,9036)
1049  DO j=1, nrgrp
1050  WRITE (mdst,9037) j, ingrp(j,:ingrp(j,0))
1051  END DO
1052 #endif
1053  !
1054  !
1055  ! 3.d Unified point output
1056  !
1057 #ifdef W3_MPRF
1058  CALL prtime ( prftn )
1059  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8.b'
1060  prft0 = prftn
1061 #endif
1062  !
1063  IF ( unipts ) THEN
1064  !
1065  j = len_trim(mnames(0))
1066  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1067  WRITE (mdss,986) mnames(0)(1:j)
1068  WRITE (mdss,987)
1069  END IF
1070  !
1071  CALL w3iogr ( 'GRID', ndsrec, 0, mnames(0)(1:j) )
1072  !
1073  END IF
1074  !
1075  ! 3.e Output
1076  !
1077  IF ( nrinp .GT. 0 ) THEN
1078  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,924)
1079  IF ( nmplog .EQ. improc ) WRITE (mdso,924)
1080  DO i=1, nrinp
1081  IF ( .NOT. useinp(i) ) cycle
1082  CALL w3seti ( -i, mdse, mdst )
1083  action(1:6) = '--- '
1084  DO j=jfirst, 6
1085  IF ( inflags1(j) ) action(j) = ' X '
1086  END DO
1087  action(7:9) = '- '
1088  IF ( inflags1(7) ) action(7) = '1 '
1089  IF ( inflags1(8) ) action(8) = '2 '
1090  IF ( inflags1(9) ) action(9) = '3 '
1091  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1092  WRITE (mdss,925) i, mnames(-i), action(jfirst:9)
1093  IF ( nmplog .EQ. improc ) &
1094  WRITE (mdso,925) i, mnames(-i), action(jfirst:9)
1095  END DO
1096  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,926)
1097  IF ( nmplog .EQ. improc ) WRITE (mdso,926)
1098  END IF
1099  !
1100  IF ( unipts ) THEN
1101  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,927)
1102  IF ( nmplog .EQ. improc ) WRITE (mdso,927)
1103  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1104  WRITE (mdss,928) mnames(0)
1105  IF ( nmplog .EQ. improc ) &
1106  WRITE (mdso,928) mnames(0)
1107  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,929)
1108  IF ( nmplog .EQ. improc ) WRITE (mdso,929)
1109  END IF
1110  !
1111  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,930)
1112  IF ( nmplog .EQ. improc ) WRITE (mdso,930)
1113  DO i=1, nrgrd
1114  CALL w3seti ( i, mdse, mdst )
1115  action(1:6) = '--- '
1116  DO j=jfirst, 6
1117  IF ( inflags1(j) .AND. inpmap(i,j) .EQ. 0 ) THEN
1118  action(j) = 'native'
1119  ELSE IF ( inflags1(j) .AND. inpmap(i,j) .EQ. -999 ) THEN
1120  action(j) = 'native'
1121  ELSE IF ( inpmap(i,j) .GT. 0 ) THEN
1122  action(j) = mnames(-inpmap(i,j))
1123  ELSE IF ( inpmap(i,j) .LT. 0 ) THEN
1124  action(j) = mnames( inpmap(i,j))
1125  END IF
1126  END DO
1127  action(7:11) = '- '
1128  IF ( inflags1(7) ) action(7) = '1 '
1129  IF ( inflags1(8) ) action(8) = '2 '
1130  IF ( inflags1(9) ) action(9) = '3 '
1131  IF ( inflags1(10) ) THEN
1132  action(10) = 'yes '
1133  ELSE
1134  action(10) = 'no '
1135  END IF
1136  IF ( bcdump(i) ) action(11) = 'y '
1137  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1138  WRITE (mdss,931) i, mnames(i), action(1:10), grank(i), &
1139  grgrp(i), action(11)
1140  IF ( nmplog .EQ. improc ) &
1141  WRITE (mdso,931) i, mnames(i), action(1:10), grank(i), &
1142  grgrp(i), action(11)
1143  END DO
1144  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,932)
1145  IF ( nmplog .EQ. improc ) WRITE (mdso,932)
1146  !
1147  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1148  WRITE (mdss,933) 'Group information'
1149  IF ( nmplog .EQ. improc ) &
1150  WRITE (mdso,933) 'Group information'
1151  DO j=1, nrgrp
1152  WRITE (line(1:6),'(1X,I3,2X)') j
1153  jjj = 6
1154  DO jj=1, ingrp(j,0)
1155  IF ( jjj .GT. 60 ) THEN
1156  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1157  WRITE (mdss,934) line(1:jjj)
1158  IF ( nmplog .EQ. improc ) WRITE (mdso,934) line(1:jjj)
1159  line(1:6) = ' '
1160  jjj = 6
1161  END IF
1162  WRITE (line(jjj+1:jjj+3),'(I3)') ingrp(j,jj)
1163  !
1164  line(jjj+4:jjj+5) = ' ('
1165  WRITE (line(jjj+6:jjj+11),'(F6.4)') rp1(ingrp(j,jj))
1166  line(jjj+12:jjj+12) = '-'
1167  WRITE (line(jjj+13:jjj+18),'(F6.4)') rpn(ingrp(j,jj))
1168  line(jjj+19:jjj+19) = ')'
1169  jjj = jjj + 19
1170  !
1171  END DO
1172  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1173  WRITE (mdss,934) line(1:jjj)
1174  IF ( nmplog .EQ. improc ) WRITE (mdso,934) line(1:jjj)
1175  END DO
1176  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,935)
1177  IF ( nmplog .EQ. improc ) WRITE (mdso,935)
1178  !
1179  ! 4. Model run time information etc. -------------------------------- /
1180  !
1181  ! Version 3.07: Same for all grids, diversify later ....
1182  ! If invoked as ESMF Component, then STIME and ETIME are set
1183  ! in WMESMFMD from the external clock.
1184  !
1185  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,940)
1186  !
1187  CALL nextln ( comstr , mdsi , mdse2 )
1188  IF (is_esmf_component) THEN
1189  READ (mdsi,*,END=2001,ERR=2002) STMPT, etmpt
1190  ELSE
1191  READ (mdsi,*,END=2001,ERR=2002) STIME, etime
1192  END IF
1193  !
1194  CALL stme21 ( stime , dtme21 )
1195  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,941) dtme21
1196  CALL stme21 ( etime , dtme21 )
1197  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,942) dtme21
1198  !
1199  DO i=1, nrgrd
1200  CALL w3setw ( i, mdse, mdst )
1201  time = stime
1202  END DO
1203  !
1204  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,943)
1205  !
1206  CALL nextln ( comstr , mdsi , mdse2 )
1207  READ (mdsi,*,END=2001,ERR=2002) FLGHG1, flghg2
1208  flghg2 = flghg1 .AND. flghg2
1209  !
1210  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1211  IF ( flghg1 ) THEN
1212  WRITE (mdss,944) yesxx
1213  ELSE
1214  WRITE (mdss,944) xxxno
1215  END IF
1216  IF ( flghg2 ) THEN
1217  WRITE (mdss,945) yesxx
1218  ELSE
1219  WRITE (mdss,945) xxxno
1220  END IF
1221  END IF
1222  !
1223  ! 5. Output requests ------------------------------------------------ /
1224  !
1225  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,950)
1226  npts = 0
1227  !
1228  ! 5.a Loop over types for unified output
1229  !
1230  notype = 6
1231  DO j=1, notype
1232  !
1233  ! 5.b Process standard line
1234  !
1235  CALL nextln ( comstr , mdsi , mdse2 )
1236  !
1237  IF(j .LE. 2) THEN
1238  words(1:6)=''
1239  READ (mdsi,'(A)') linein
1240  READ(linein,*,iostat=ierr) words
1241  !
1242  IF(j .LE. 1) THEN
1243  READ(words( 1 ), * ) odat(1,1)
1244  READ(words( 2 ), * ) odat(2,1)
1245  READ(words( 3 ), * ) odat(3,1)
1246  READ(words( 4 ), * ) odat(4,1)
1247  READ(words( 5 ), * ) odat(5,1)
1248  ELSE
1249  READ(words( 1 ), * ) odat(6,1)
1250  READ(words( 2 ), * ) odat(7,1)
1251  READ(words( 3 ), * ) odat(8,1)
1252  READ(words( 4 ), * ) odat(9,1)
1253  READ(words( 5 ), * ) odat(10,1)
1254  END IF
1255 
1256  IF (words(6) .NE. '0' .AND. words(6) .NE. '1') THEN
1257  outff(j,1)=0
1258  ELSE
1259  READ(words( 6 ), * ) outff(j,1)
1260  ! print*,' Number of data: ', 6
1261  END IF
1262  ! CHECKPOINT
1263  ELSE IF(j .EQ. 4) THEN
1264  words(1:6)=''
1265  READ (mdsi,'(A)') linein
1266  READ(linein,*,iostat=ierr) words
1267  !
1268  READ(words( 1 ), * ) odat(16,1)
1269  READ(words( 2 ), * ) odat(17,1)
1270  READ(words( 3 ), * ) odat(18,1)
1271  READ(words( 4 ), * ) odat(19,1)
1272  READ(words( 5 ), * ) odat(20,1)
1273  IF (words(6) .EQ. 'T') THEN
1274  CALL nextln ( comstr , mdsi , mdse2 )
1275  READ (mdsi,*,END=2001,ERR=2002)(ODAT(I,1),I=5*(8-1)+1,5*8)
1276  ELSE
1277  odat(5*(8-1)+1,1)=0
1278  odat(5*(8-1)+2,1)=0
1279  odat(5*(8-1)+3,1)=0
1280  odat(5*(8-1)+4,1)=0
1281  odat(5*8,1)=0
1282  END IF
1283  ELSE
1284  READ (mdsi,*,END=2001,ERR=2002)(ODAT(I,1),I=5*(J-1)+1,5*J)
1285  outff(j,1) = 0
1286  END IF
1287  !
1288  outpts(1)%OFILES(j)=outff(j,1)
1289  !
1290  !
1291  odat(5*(j-1)+3,1) = max( 0 , odat(5*(j-1)+3,1) )
1292  !
1293  IF ( odat(5*(j-1)+3,1) .NE. 0 ) THEN
1294  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1295  WRITE (mdss,951) j, idotyp(j)
1296  ttime(1) = odat(5*(j-1)+1,1)
1297  ttime(2) = odat(5*(j-1)+2,1)
1298  CALL stme21 ( ttime , dtme21 )
1299  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1300  WRITE (mdss,952) dtme21
1301  ttime(1) = odat(5*(j-1)+4,1)
1302  ttime(2) = odat(5*(j-1)+5,1)
1303  CALL stme21 ( ttime , dtme21 )
1304  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1305  WRITE (mdss,953) dtme21
1306  ttime(1) = 0
1307  ttime(2) = 0
1308  dttst = real( odat(5*(j-1)+3,1) )
1309  CALL tick21 ( ttime , dttst )
1310  CALL stme21 ( ttime , dtme21 )
1311  IF ( ( odat(5*(j-1)+1,1) .NE. odat(5*(j-1)+4,1) .OR. &
1312  odat(5*(j-1)+2,1) .NE. odat(5*(j-1)+5,1) ) .AND. &
1313  mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1314  DO i=1, 18
1315  IF ( dtme21(i:i).NE.'0' .AND. &
1316  dtme21(i:i).NE.'/' .AND. &
1317  dtme21(i:i).NE.' ' .AND. &
1318  dtme21(i:i).NE.':' ) EXIT
1319  dtme21(i:i) = ' '
1320  END DO
1321  WRITE (mdss,954) dtme21(1:19)
1322 
1323  END IF
1324  IF ( j .EQ. 1 ) THEN
1325  !
1326  ! 5.c Type 1: fields of mean wave parameters
1327  !
1328  flgrd(:,:,:)=.false. ! Initialize FLGRD
1329  CALL w3readflgrd ( mdsi, mdss, mdso, mdse2, comstr, flg1d, &
1330  flg2d, improc, nmpscr, ierr )
1331  flgrd(:,:,1)=flg2d
1332  flgd(:,1) =flg1d
1333  !
1334  ELSE IF ( j .EQ. 2 ) THEN
1335  !
1336  ! 5.d Type 2: point output
1337  !
1338  DO iloop=1, 2
1339  IF ( iloop .EQ. 1 ) THEN
1340  mdsi2 = mdsi
1341  IF ( improc .EQ. 1 ) OPEN &
1342  (scratch,file=trim(fnmpre)//'ww3_multi.scratch')
1343  ELSE
1344  mdsi2 = scratch
1345 #ifdef W3_MPI
1346  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
1347 #endif
1348  OPEN &
1349  (scratch,file=trim(fnmpre)//'ww3_multi.scratch')
1350  rewind(scratch)
1351  IF (npts.GT.0) THEN
1352  ALLOCATE ( x(npts), y(npts), pnames(npts) )
1353  ELSE
1354  GOTO 2054
1355  END IF
1356  END IF
1357  !
1358  npts = 0
1359  DO
1360  CALL nextln ( comstr , mdsi2 , mdse2 )
1361  READ (mdsi2,*,END=2001,ERR=2002) XX, YY, pn
1362  !
1363  IF ( iloop.EQ.1 .AND. improc.EQ.1 ) THEN
1364  backspace(mdsi)
1365  READ (mdsi,'(A)') line
1366  WRITE (scratch,'(A)') line
1367  END IF
1368  !
1369  IF ( pn .EQ. 'STOPSTRING' ) EXIT
1370  !
1371  npts = npts + 1
1372  IF ( iloop .EQ. 1 ) cycle
1373  !
1374  x(npts) = xx
1375  y(npts) = yy
1376  pnames(npts) = pn
1377  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1378  IF ( npts .EQ. 1 ) THEN
1379  WRITE (mdss,957) xx, yy, pn
1380  ELSE
1381  WRITE (mdss,958) npts, xx, yy, pn
1382  END IF
1383  END IF
1384  !
1385  END DO
1386  !
1387  IF ( improc.EQ.1 .AND. iloop.EQ.1 ) CLOSE (scratch)
1388  END DO
1389  !
1390  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc .AND. &
1391  npts.EQ.0 ) WRITE (mdss,959)
1392  IF ( improc .EQ. 1 ) THEN
1393 #ifdef W3_MPI
1394  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
1395 #endif
1396  CLOSE (scratch,status='DELETE')
1397  ELSE
1398  CLOSE (scratch)
1399 #ifdef W3_MPI
1400  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
1401 #endif
1402  END IF
1403  !
1404  ELSE IF ( j .EQ. 3 ) THEN
1405  !
1406  ! 5.e Type 3: track output
1407  !
1408  CALL nextln ( comstr , mdsi , mdse2 )
1409  READ (mdsi,*,END=2001,ERR=2002) tflagi
1410  IF ( .NOT. tflagi ) mds(11,:) = -mds(11,:)
1411  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1412  IF ( .NOT. tflagi ) THEN
1413  WRITE (mdss,960) 'input', 'UNFORMATTED'
1414  ELSE
1415  WRITE (mdss,960) 'input', 'FORMATTED'
1416  END IF
1417  END IF
1418  !
1419  ELSE IF ( j .EQ. 4 ) THEN
1420  !
1421  ! 5.f Type 4: restart files (no additional data)
1422  !
1423  ELSE IF ( j .EQ. 5 ) THEN
1424  !
1425  ! 5.g Type 5: nesting data (no additional data)
1426  !
1427  ELSE IF ( j .EQ. 6 ) THEN
1428  !
1429  ! 5.h Type 6: partitioned wave field data
1430  !
1431  CALL nextln ( comstr , mdsi , mdse2 )
1432  READ (mdsi,*,END=2001,ERR=2002) IPRT(:,1), LPRT(1)
1433  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1434  WRITE (mdss,961) iprt(:,1)
1435  IF ( .NOT. lprt(1) ) THEN
1436  WRITE (mdss,960) 'output', 'UNFORMATTED'
1437  ELSE
1438  WRITE (mdss,960) 'output', 'FORMATTED'
1439  END IF
1440  END IF
1441  !
1442  ! ... End of output type selecttion ELSE IF
1443  !
1444  END IF
1445  !
1446  ! ... End of IF in 5.b
1447  !
1448  END IF
1449  !
1450  ! ... End of loop in 5.a
1451  !
1452  END DO
1453  !xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1454  ! Checkpoint
1455  j=8
1456  IF ( odat(5*(j-1)+3,1) .NE. 0 ) THEN
1457  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1458  WRITE (mdss,951) j, idotyp(j)
1459  ttime(1) = odat(5*(j-1)+1,1)
1460  ttime(2) = odat(5*(j-1)+2,1)
1461  CALL stme21 ( ttime , dtme21 )
1462  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1463  WRITE (mdss,952) dtme21
1464  ttime(1) = odat(5*(j-1)+4,1)
1465  ttime(2) = odat(5*(j-1)+5,1)
1466  CALL stme21 ( ttime , dtme21 )
1467  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1468  WRITE (mdss,953) dtme21
1469  ttime(1) = 0
1470  ttime(2) = 0
1471  dttst = real( odat(5*(j-1)+3,1) )
1472  CALL tick21 ( ttime , dttst )
1473  CALL stme21 ( ttime , dtme21 )
1474  IF ( ( odat(5*(j-1)+1,1) .NE. odat(5*(j-1)+4,1) .OR. &
1475  odat(5*(j-1)+2,1) .NE. odat(5*(j-1)+5,1) ) .AND. &
1476  mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1477  DO i=1, 18
1478  IF ( dtme21(i:i).NE.'0' .AND. &
1479  dtme21(i:i).NE.'/' .AND. &
1480  dtme21(i:i).NE.' ' .AND. &
1481  dtme21(i:i).NE.':' ) EXIT
1482  dtme21(i:i) = ' '
1483  END DO
1484  WRITE (mdss,954) dtme21(1:19)
1485  END IF
1486  END IF
1487  !xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1488  !
1489  ! 5.i Set all grids to unified output
1490  !
1491  IF ( unipts ) THEN
1492  odat(6:10,0) = odat(6:10,1)
1493  odat( 8 , 1) = 0
1494  outpts(1)%OFILES(1) = outff(1,1)
1495  END IF
1496  !
1497  DO i=2, nrgrd
1498  odat(:,i) = odat(:,1)
1499  outff(:,i) = outff(:,1)
1500  outpts(i)%OFILES(:)=outff(:,1)
1501  flgd(:,i) = flgd(:,1)
1502  flgrd(:,:,i) = flgrd(:,:,1)
1503  flg2(:,i) = flg2(:,1)
1504  flgr2(:,:,i) = flgr2(:,:,1)
1505  iprt(:,i) = iprt(:,1)
1506  lprt(i) = lprt(1)
1507  END DO
1508  !
1509  IF ( npts.EQ.0 .OR. odat(8,0).EQ.0 ) unipts = .false.
1510  IF ( unipts ) THEN
1511  IF ( ( npts.EQ.0 .OR. odat(8,0).EQ.0 ) .AND. &
1512  improc.EQ.nmperr ) WRITE (mdse,1050)
1513  IF ( npts.EQ.0 .OR. odat(8,0).EQ.0 ) unipts = .false.
1514  ot2(0)%NPTS = npts
1515  ALLOCATE (ot2(0)%X(npts),ot2(0)%Y(npts),ot2(0)%PNAMES(npts))
1516  ot2(0)%X = x
1517  ot2(0)%Y = y
1518  ot2(0)%PNAMES = pnames
1519  DO i=1, nrgrd
1520  ot2(i)%NPTS = 0
1521  ALLOCATE (ot2(i)%X(1),ot2(i)%Y(1),ot2(i)%PNAMES(1))
1522  END DO
1523  ELSE
1524  DO i=1, nrgrd
1525  ot2(i)%NPTS = npts
1526  IF ( npts .EQ. 0 ) THEN
1527  ALLOCATE (ot2(i)%X(1),ot2(i)%Y(1),ot2(i)%PNAMES(1))
1528  ELSE
1529  ALLOCATE (ot2(i)%X(npts),ot2(i)%Y(npts), &
1530  ot2(i)%PNAMES(npts))
1531  ot2(i)%X = x
1532  ot2(i)%Y = y
1533  ot2(i)%PNAMES = pnames
1534  END IF
1535  END DO
1536  END IF
1537  !
1538  ! 5.j Endless loop for correcting output per grid
1539  !
1540  DO
1541  CALL nextln ( comstr , mdsi , mdse2 )
1542  READ (mdsi,*,END=2001,ERR=2002) MN, j
1543  !
1544  ! 5.j.1 Bail out loop for output type 0
1545  !
1546  IF ( j .EQ. 0 ) EXIT
1547  !
1548  ! 5.j.2 Find the grid number
1549  !
1550  ii = len_trim(mn)
1551  DO i=1, nrgrd
1552  IF ( mn(:ii) .EQ. mnames(i)(1:ii) ) EXIT
1553  END DO
1554  !
1555  IF ( i .GT. nrgrd ) GOTO 2051
1556  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1557  WRITE (mdss,962) mn(1:ii), i
1558  !
1559  ! 5.j.3 Check the output type
1560  !
1561  IF ( j.LT.0 .OR. j.GT. notype ) GOTO 2052
1562  IF ( j.EQ.2 .AND. unipts ) GOTO 2053
1563  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1564  WRITE (mdss,951) j, idotyp(j)
1565  !
1566  ! 5.k Process standard line
1567  !
1568  CALL nextln ( comstr , mdsi , mdse2 )
1569  IF(j .LE. 2) THEN
1570  outff(j,i)=0
1571  words(1:6) =''
1572  READ (mdsi,'(A)') linein
1573  READ(linein,*,iostat=ierr) words
1574  IF(j .EQ. 1) THEN
1575  READ(words( 1 ), * ) odat(1,i)
1576  READ(words( 2 ), * ) odat(2,i)
1577  READ(words( 3 ), * ) odat(3,i)
1578  READ(words( 4 ), * ) odat(4,i)
1579  READ(words( 5 ), * ) odat(5,i)
1580  ELSE
1581  READ(words( 1 ), * ) odat(6,i)
1582  READ(words( 2 ), * ) odat(7,i)
1583  READ(words( 3 ), * ) odat(8,i)
1584  READ(words( 4 ), * ) odat(9,i)
1585  READ(words( 5 ), * ) odat(10,i)
1586  END IF
1587  IF (words(6) .NE. '0' .AND. words(6) .NE. '1') THEN
1588  outff(j,i)=0
1589  ELSE
1590  READ(words( 6 ), * ) outff(j,i)
1591  END IF
1592  !
1593  ELSE
1594  READ (mdsi,*,END=2001,ERR=2002)(ODAT(II,I),II=5*(J-1)+1,5*J)
1595  outff(j,i) = 0
1596  END IF
1597  !
1598  outpts(i)%OFILES(j)=outff(j,i)
1599  !
1600  odat(5*(j-1)+3,i) = max( 0 , odat(5*(j-1)+3,i) )
1601  !
1602  IF ( odat(5*(j-1)+3,i) .NE. 0 ) THEN
1603  ttime(1) = odat(5*(j-1)+1,i)
1604  ttime(2) = odat(5*(j-1)+2,i)
1605  CALL stme21 ( ttime , dtme21 )
1606  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1607  WRITE (mdss,952) dtme21
1608  ttime(1) = odat(5*(j-1)+4,i)
1609  ttime(2) = odat(5*(j-1)+5,i)
1610  CALL stme21 ( ttime , dtme21 )
1611  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1612  WRITE (mdss,953) dtme21
1613  ttime(1) = 0
1614  ttime(2) = 0
1615  dttst = real( odat(5*(j-1)+3,i) )
1616  CALL tick21 ( ttime , dttst )
1617  CALL stme21 ( ttime , dtme21 )
1618  IF ( ( odat(5*(j-1)+1,i) .NE. odat(5*(j-1)+4,i) .OR. &
1619  odat(5*(j-1)+2,i) .NE. odat(5*(j-1)+5,i) ) .AND. &
1620  mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1621  DO ii=1, 18
1622  IF ( dtme21(ii:ii).NE.'0' .AND. &
1623  dtme21(ii:ii).NE.'/' .AND. &
1624  dtme21(ii:ii).NE.' ' .AND. &
1625  dtme21(ii:ii).NE.':' ) EXIT
1626  dtme21(ii:ii) = ' '
1627  END DO
1628  WRITE (mdss,954) dtme21(1:19)
1629  END IF
1630  !
1631  IF ( j .EQ. 1 ) THEN
1632  !
1633  ! 5.l Type 1: fields of mean wave parameters
1634  !
1635  CALL w3readflgrd ( mdsi, mdss, mdso, mdse2, comstr, &
1636  flg1d, flg2d, improc, nmpscr, ierr )
1637  flgd(:,i) = flg1d
1638  flgrd(:,:,i) = flg2d
1639  !
1640  ELSE IF ( j .EQ. 2 ) THEN
1641  !
1642  ! 5.m Type 2: point output
1643  !
1644  DO iloop=1, 2
1645  IF ( iloop .EQ. 1 ) THEN
1646  mdsi2 = mdsi
1647  IF ( improc .EQ. 1 ) OPEN &
1648  (scratch,file=trim(fnmpre)//'ww3_multi.scratch')
1649  ELSE
1650  mdsi2 = scratch
1651 #ifdef W3_MPI
1652  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
1653 #endif
1654  OPEN &
1655  (scratch,file=trim(fnmpre)//'ww3_multi.scratch')
1656  rewind(scratch)
1657  DEALLOCATE ( ot2(i)%X, ot2(i)%Y, ot2(i)%PNAMES )
1658  ALLOCATE ( ot2(i)%X(ot2(i)%NPTS), &
1659  ot2(i)%Y(ot2(i)%NPTS), &
1660  ot2(i)%PNAMES(ot2(i)%NPTS) )
1661  END IF
1662  !
1663  ot2(i)%NPTS = 0
1664  DO
1665  CALL nextln ( comstr , mdsi2 , mdse2 )
1666  READ (mdsi2,*,END=2001,ERR=2002) XX, YY, pn
1667  !
1668  IF ( iloop.EQ.1 .AND. improc.EQ.1 ) THEN
1669  backspace(mdsi)
1670  READ (mdsi,'(A)') line
1671  WRITE (scratch,'(A)') line
1672  END IF
1673  !
1674  IF ( pn .EQ. 'STOPSTRING' ) EXIT
1675  !
1676  ot2(i)%NPTS = ot2(i)%NPTS + 1
1677  IF ( iloop .EQ. 1 ) cycle
1678  !
1679  ot2(i)%X(ot2(i)%NPTS) = xx
1680  ot2(i)%Y(ot2(i)%NPTS) = yy
1681  ot2(i)%PNAMES(ot2(i)%NPTS) = pn
1682  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1683  IF ( ot2(i)%NPTS .EQ. 1 ) THEN
1684  WRITE (mdss,957) xx, yy, pn
1685  ELSE
1686  WRITE (mdss,958) ot2(i)%NPTS, xx, yy, pn
1687  END IF
1688  END IF
1689  !
1690  END DO
1691  !
1692  IF ( improc.EQ.1 .AND. iloop.EQ.1 ) CLOSE (scratch)
1693  END DO
1694  !
1695  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc .AND. &
1696  ot2(i)%NPTS.EQ.0 ) WRITE (mdss,959)
1697  IF ( improc .EQ. 1 ) THEN
1698 #ifdef W3_MPI
1699  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
1700 #endif
1701  CLOSE (scratch,status='DELETE')
1702  ELSE
1703  CLOSE (scratch)
1704 #ifdef W3_MPI
1705  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
1706 #endif
1707  END IF
1708  !
1709  ELSE IF ( j .EQ. 3 ) THEN
1710  !
1711  ! 5.n Type 3: track output
1712  !
1713  CALL nextln ( comstr , mdsi , mdse2 )
1714  READ (mdsi,*,END=2001,ERR=2002) tflagi
1715  IF ( tflagi ) THEN
1716  mds(11,i) = abs(mds(11,i))
1717  ELSE
1718  mds(11,i) = -abs(mds(11,i))
1719  END IF
1720  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1721  IF ( .NOT. tflagi ) THEN
1722  WRITE (mdss,960) 'input', 'UNFORMATTED'
1723  ELSE
1724  WRITE (mdss,960) 'input', 'FORMATTED'
1725  END IF
1726  END IF
1727  !
1728  ELSE IF ( j .EQ. 6 ) THEN
1729  !
1730  ! 5.o Type 6: partitioned wave field data
1731  !
1732  CALL nextln ( comstr , mdsi , mdse2 )
1733  READ (mdsi,*,END=2001,ERR=2002) IPRT(:,I), LPRT(I)
1734  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1735  WRITE (mdss,961) iprt(:,i)
1736  IF ( .NOT. lprt(i) ) THEN
1737  WRITE (mdss,960) 'output', 'UNFORMATTED'
1738  ELSE
1739  WRITE (mdss,960) 'output', 'FORMATTED'
1740  END IF
1741  END IF
1742  !
1743  END IF
1744  ELSE IF ( j .EQ. 7 ) THEN
1745  !
1746  ! 5.p Type 7: coupling fields
1747  !
1748  CALL w3readflgrd ( mdsi, mdss, mdso, mdse2, comstr, &
1749  flg1d, flg2d, improc, nmpscr, ierr )
1750  flg2(:,i) = flg1d
1751  flgr2(:,:,i) = flg2d
1752  !
1753  ELSE
1754  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,963)
1755  END IF
1756  !
1757  ! ... End of loop in 5.j
1758  !
1759  END DO
1760  !
1761 #ifdef W3_T
1762  DO i=1, nrgrd
1763  WRITE (mdst,9050) i
1764  WRITE (mdst,9051) odat(:,i)
1765  WRITE (mdst,9051) outff(:,i)
1766  WRITE (mdst,9052) flgrd(:,:,i)
1767  END DO
1768 #endif
1769  !
1770  ! 6. Read moving grid data ------------------------------------------ /
1771  !
1772  ! Only a single set of data are provided to be applied to all
1773  ! the grids, because this is only intended for test cases.
1774  ! For true implementations, the jumping grid will be used.
1775  !
1776  IF ( inflags1(10) ) THEN
1777  !
1778  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1779  WRITE (mdss,965)
1780  WRITE (mdss,966) 'Continuous grid movement data'
1781  END IF
1782  !
1783 #ifdef W3_MPI
1784  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
1785 #endif
1786  DO iloop=1, 2
1787  IF ( iloop .EQ. 1 ) THEN
1788  mdsi2 = mdsi
1789  IF ( improc .EQ. 1 ) &
1790  OPEN (scratch,file=trim(fnmpre)//'ww3_shel.scratch')
1791  ELSE
1792  mdsi2 = scratch
1793 #ifdef W3_MPI
1794  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
1795 #endif
1796  OPEN (scratch,file=trim(fnmpre)//'ww3_shel.scratch')
1797  rewind(scratch)
1798  ALLOCATE ( tmove(2,nmove), amove(nmove), dmove(nmove) )
1799  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1800  WRITE (mdss,967) nmove, 'MOV'
1801  END IF
1802  !
1803  nmove = 0
1804  DO
1805  CALL nextln ( comstr , mdsi2 , mdse2 )
1806  READ (mdsi2,*,END=2001,ERR=2002) idtst
1807  !
1808  IF ( iloop.EQ.1 .AND. improc.EQ.1 ) THEN
1809  backspace(mdsi)
1810  READ (mdsi,'(A)') line
1811  WRITE (scratch,'(A)') line
1812  END IF
1813  !
1814  IF ( idtst .EQ. 'STP' ) EXIT
1815  IF ( idtst .NE. 'MOV' ) cycle
1816  !
1817  nmove = nmove + 1
1818  IF ( iloop .EQ. 1 ) cycle
1819  !
1820  backspace(mdsi2)
1821  READ (mdsi2,*,END=2001,ERR=2002) IDTST, TTIME, XX, yy
1822  tmove(:,nmove) = ttime
1823  amove(nmove) = xx
1824  dmove(nmove) = yy
1825  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1826  WRITE (mdss,968) nmove, tmove(:,nmove), &
1827  amove(nmove), dmove(nmove)
1828  !
1829  END DO
1830  !
1831  IF ( improc.EQ.1 .AND. iloop.EQ.1 ) CLOSE (scratch)
1832  END DO
1833  !
1834  IF ( improc .EQ. 1 ) THEN
1835 #ifdef W3_MPI
1836  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
1837 #endif
1838  CLOSE (scratch,status='DELETE')
1839  ELSE
1840  CLOSE (scratch)
1841 #ifdef W3_MPI
1842  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
1843 #endif
1844  END IF
1845  !
1846 #ifdef W3_T
1847  WRITE (mdst,9060)
1848  DO i=1, nmove
1849  WRITE (mdst,9061) i, tmove(:,i), amove(i), dmove(i)
1850  END DO
1851 #endif
1852  !
1853  IF ( nmove .EQ. 0 ) GOTO 2060
1854  !
1855  nmvmax = nmove
1856  DO i=1, nrgrd
1857  CALL w3setg ( i, mdse, mdst )
1858  CALL wmsetm ( i, mdse, mdst )
1859  nmv = nmove
1860  CALL wmdimd ( i, mdse, mdst, 0 )
1861  DO ii=1, nmv
1862  tmv(:,4,ii) = tmove(:,ii)
1863  amv(ii,4) = amove(ii)
1864  dmv(ii,4) = dmove(ii)
1865  END DO
1866  END DO
1867  !
1868  END IF
1869  !
1870  ! 7. Work load distribution ----------------------------------------- /
1871  ! 7.a Initialize arrays
1872  !
1873  ! *******************************************************
1874  ! *** NOTE : OUTPUT PROCESSOR ASSIGNMENT NEEDS TO BE ***
1875  ! *** CONSISTENT WITH ASSIGNMENT IN W3INIT. ***
1876  ! *******************************************************
1877  !
1878  ALLOCATE ( allprc(nmproc,nrgrd) , modmap(nmproc,nrgrp) , &
1879  loadmp(nmproc,nrgrp) )
1880  !
1881  allprc = 0
1882  modmap = 0
1883  loadmp = 0
1884  !
1885  ! 7.b Determine number of output processors
1886  !
1887  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,970)
1888  !
1889  ncproc = nmproc
1890  upproc = upproc .AND. unipts .AND. iostyp.GT.1
1891  !
1892  ! 7.b.1 Unified point output
1893  !
1894  IF ( unipts ) THEN
1895  IF ( nmproc.GE.10 .AND. upproc ) THEN
1896  ncproc = nmproc - 1
1897  ELSE
1898  IF ( upproc .AND. mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1899  WRITE (mdss,971) 'Separate process for point' // &
1900  ' output disabled.'
1901  upproc = .false.
1902  END IF
1903  IF ( nmpupt .EQ. improc ) THEN
1904  ii = len_trim(mnames(0))
1905  CALL wmuget ( mdss, mdst, mdsup, 'OUT' )
1906  CALL wmuset ( mdss, mdst, mdsup, .true., 'OUT', &
1907  trim(fnmpre)//'out_pnt.'//mnames(0)(1:ii), &
1908  'Unified point output')
1909 #ifdef W3_ASCII
1910  CALL wmuget ( mdss, mdst, mdsupa, 'OUA' )
1911  CALL wmuset ( mdss, mdst, mdsupa, .true., 'OUA', &
1912  trim(fnmpre)//'out_pnt.'//mnames(0)(1:ii)//'.txt', &
1913  'Unified point output ascii')
1914 #endif
1915  END IF
1916  END IF
1917  !
1918  IF ( upproc .AND. mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1919  WRITE (mdss,972) nmpupt
1920  !
1921  ! 7.b.2 Other output
1922  !
1923  ALLOCATE ( ndpout(nrgrd) )
1924  ndpout = 0
1925  !
1926  IF ( iostyp .GT. 1 ) THEN
1927  DO i=1, nrgrd
1928  IF ( odat( 3,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
1929  IF ( odat(13,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
1930  IF ( odat(28,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
1931  IF ( odat( 8,i) .GT. 0 .OR. odat(18,i) .GT. 0 .OR. &
1932  odat(23,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
1933  IF ( iostyp .EQ. 2 ) ndpout(i) = min( 1 , ndpout(i) )
1934  END DO
1935  END IF
1936  !
1937  ! ..... Reduce IOSTYP if not enough resources to run IOSTYP = 3
1938  !
1939  IF ( iostyp.EQ.3 .AND. &
1940  ( ( .NOT.pshare .AND. 4*sum(ndpout).GT.ncproc ) &
1941  .OR.( pshare .AND. 4*maxval(ndpout).GT.ncproc ) ) ) THEN
1942  DO i=1, nrgrd
1943  ndpout(i) = min( 1 , ndpout(i) )
1944  END DO
1945  iostyp = 2
1946  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1947  WRITE (mdss,971) 'Separate processes for output' // &
1948  ' types disabled.'
1949  END IF
1950  !
1951  ! ..... Force sharing of output processes if not enough resources
1952  !
1953  IF ( iostyp.GT.1 .AND. .NOT.pshare .AND. &
1954  4*sum(ndpout).GT.ncproc ) THEN
1955  pshare = .true.
1956  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1957  WRITE (mdss,971) 'Grids sharing output processes.'
1958  END IF
1959  !
1960  ! ..... Disable output processes if not enough resources
1961  !
1962  IF ( iostyp.GT.1 .AND. 4*maxval(ndpout).GT.ncproc ) THEN
1963  ndpout = 0
1964  iostyp = 1
1965  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
1966  WRITE (mdss,971) 'Separate processes for output' // &
1967  ' disabled.'
1968  END IF
1969  !
1970  ! ..... Number of output processes (except for unified point output)
1971  !
1972  npoutt = 0
1973  IF ( iostyp .GT. 1 ) THEN
1974  IF ( pshare ) THEN
1975  npoutt = maxval(ndpout)
1976  ELSE
1977  npoutt = sum(ndpout)
1978  END IF
1979  END IF
1980  ncproc = ncproc - npoutt
1981  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
1982  IF ( npoutt .EQ. 0 ) THEN
1983  WRITE (mdss,971) 'No (other) dedicated output processes.'
1984  ELSE
1985  WRITE (mdss,973) ncproc+1, ncproc+npoutt, npoutt
1986  END IF
1987  END IF
1988  !
1989  ! 7.c Set communicators and ALLPRC array
1990  !
1991 #ifdef W3_T
1992  WRITE (mdst,9070)
1993 #endif
1994  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,974)
1995  IF ( nmplog.EQ.improc ) WRITE (mdso,1974)
1996  !
1997 #ifdef W3_MPI
1998  CALL mpi_comm_group ( mpi_comm_mwave, bgroup, ierr_mpi )
1999 #endif
2000  ALLOCATE ( tmprnk(nmproc) )
2001  napres = ncproc
2002  !
2003  DO i=1, nrgrd
2004  !
2005  ip1 = max( 1 , min( ncproc , 1+nint(real(ncproc)*rp1(i)) ) )
2006  ipn = max( ip1 , min( ncproc , nint(real(ncproc)*rpn(i)) ) )
2007  outstr = '-----'
2008  !
2009  CALL wmsetm ( i, mdse, mdst )
2010  naploc = 1 + ipn - ip1
2011  napadd = naploc
2012 #ifdef W3_MPI
2013  croot = ip1
2014  fbcast = naploc .NE. ncproc
2015  fbcast = naploc .NE. ncproc .OR. &
2016  ( iostyp.GT.1 .AND. .NOT.pshare )
2017 #endif
2018  DO j=ip1, ipn
2019  tmprnk(1+j-ip1) = j - 1
2020  END DO
2021  !
2022  IF ( iostyp .GT. 1 ) THEN
2023  IF ( pshare ) napres = ncproc
2024  DO j=1, ndpout(i)
2025  napadd = napadd + 1
2026  tmprnk(napadd) = napres
2027  napres = napres + 1
2028  END DO
2029  END IF
2030  !
2031  IF ( upproc ) THEN
2032  napadd = napadd + 1
2033  tmprnk(napadd) = nmproc - 1
2034  END IF
2035  !
2036 #ifdef W3_MPI
2037  CALL mpi_group_incl ( bgroup, napadd, tmprnk, lgroup, &
2038  ierr_mpi )
2039  CALL mpi_comm_create ( mpi_comm_mwave, lgroup, &
2040  mpi_comm_grd, ierr_mpi )
2041  CALL mpi_group_free ( lgroup, ierr_mpi )
2042 #endif
2043  !
2044  DO ii=ip1, ipn
2045  allprc(ii,i) = 1 + ii - ip1
2046  END DO
2047  ii = ii - ip1
2048  !
2049  IF ( pshare .OR. i.EQ.1 ) THEN
2050  napadd = ncproc
2051  ELSE
2052  napadd = ncproc + sum(ndpout(1:i-1))
2053  END IF
2054  IF ( iostyp .GT. 1 ) THEN
2055  DO j=1, ndpout(i)
2056  napadd = napadd + 1
2057  ii = ii + 1
2058  allprc(napadd,i) = ii
2059  END DO
2060  END IF
2061  !
2062  IF ( upproc ) THEN
2063  ii = ii + 1
2064  allprc(nmproc,i) = ii
2065  END IF
2066  !
2067 #ifdef W3_T
2068  WRITE (mdst,9071) i, allprc(:,i)
2069 #endif
2070  !
2071  ! ... output
2072  !
2073  !
2074  IF ( iostyp .LE. 1 ) THEN
2075  !
2076  IF ( odat( 3,i) .GT. 0 ) THEN
2077  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-1))+1
2078  outstr(1) = stout
2079  END IF
2080  IF ( odat( 8,i) .GT. 0 .OR. unipts ) THEN
2081  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-2))+1
2082  outstr(2) = stout
2083  END IF
2084  IF ( odat(13,i) .GT. 0 ) THEN
2085  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-5))+1
2086  outstr(3) = stout
2087  END IF
2088  IF ( odat(18,i) .GT. 0 ) THEN
2089  WRITE (stout,'(I5.5)') tmprnk(naploc)+1
2090  outstr(4) = stout
2091  END IF
2092  IF ( odat(23,i) .GT. 0 ) THEN
2093  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-3))+1
2094  outstr(5) = stout
2095  END IF
2096  IF ( odat(28,i) .GT. 0 ) THEN
2097  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-4))+1
2098  outstr(6) = stout
2099  END IF
2100  !
2101  ELSE
2102  !
2103  IF ( unipts ) THEN
2104  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
2105  outstr(2) = stout
2106  IF ( upproc ) ii = ii - 1
2107  END IF
2108  !
2109  IF ( iostyp .EQ. 2 ) THEN
2110  !
2111  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
2112  IF ( odat( 3,i) .GT. 0 ) outstr(1) = stout
2113  IF ( odat( 8,i) .GT. 0 .OR. &
2114  ( unipts .AND. .NOT.upproc ) ) &
2115  outstr(2) = stout
2116  IF ( odat(13,i) .GT. 0 ) outstr(3) = stout
2117  IF ( odat(18,i) .GT. 0 ) outstr(4) = stout
2118  IF ( odat(23,i) .GT. 0 ) outstr(5) = stout
2119  IF ( odat(28,i) .GT. 0 ) outstr(6) = stout
2120  !
2121  ELSE IF ( iostyp .EQ. 3 ) THEN
2122  !
2123  IF ( odat( 3,i).GT.0 ) THEN
2124  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
2125  outstr(1) = stout
2126  ii = ii - 1
2127  END IF
2128  IF ( odat(13,i).GT.0 ) THEN
2129  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
2130  outstr(3) = stout
2131  ii = ii - 1
2132  END IF
2133  IF ( odat(28,i).GT.0 ) THEN
2134  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
2135  outstr(6) = stout
2136  ii = ii - 1
2137  END IF
2138  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
2139  IF ( odat( 8,i) .GT. 0 ) outstr(2) = stout
2140  IF ( odat(18,i) .GT. 0 ) outstr(4) = stout
2141  IF ( odat(23,i) .GT. 0 ) outstr(5) = stout
2142  !
2143  END IF
2144  !
2145  END IF
2146  !
2147  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
2148  WRITE (mdss,975) mnames(i), ip1, ipn, outstr
2149  IF ( nmplog .EQ. improc ) &
2150  WRITE (mdso,1975)mnames(i), ip1, ipn, outstr
2151  !
2152 #ifdef W3_MPI
2153  IF ( fbcast ) THEN
2154  tmprnk(1) = ip1 - 1
2155  napbct = 1
2156  DO j=1, nmproc
2157  IF ( allprc(j,i) .EQ. 0 ) THEN
2158  napbct = napbct + 1
2159  tmprnk(napbct) = j - 1
2160  END IF
2161  END DO
2162  CALL mpi_group_incl ( bgroup, napbct, tmprnk, &
2163  lgroup, ierr_mpi )
2164  CALL mpi_comm_create ( mpi_comm_mwave, lgroup, &
2165  mpi_comm_bct, ierr_mpi )
2166  CALL mpi_group_free ( lgroup, ierr_mpi )
2167  END IF
2168 #endif
2169  !
2170  END DO
2171  !
2172  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
2173  WRITE (mdss,976)
2174  IF ( unipts ) WRITE (mdss,977) nmpupt
2175  WRITE (mdss,*)
2176  END IF
2177  !
2178  IF ( nmplog .EQ. improc ) THEN
2179  WRITE (mdso,1976)
2180  IF ( unipts ) WRITE (mdso,1977) nmpupt
2181  WRITE (mdso,*)
2182  END IF
2183  !
2184  DEALLOCATE ( tmprnk, ndpout )
2185  !
2186  ! 7.d Set MODMAP and LOADMP arrays
2187  !
2188  DO jj=1, nrgrp
2189  DO ii=1, ingrp(jj,0)
2190  i = ingrp(jj,ii)
2191  DO j=1, nmproc
2192  IF ( allprc(j,i) .NE. 0 ) THEN
2193  loadmp(j,jj) = loadmp(j,jj) + 1
2194  IF ( loadmp(j,jj) .EQ. 1 ) THEN
2195  modmap(j,jj) = i
2196  ELSE
2197  modmap(j,jj) = -1
2198  END IF
2199  END IF
2200  END DO
2201  END DO
2202  END DO
2203  !
2204 #ifdef W3_T
2205  WRITE (mdst,8042)
2206  DO j=1, nrgrp
2207  WRITE (mdst,8044) j, modmap(:,j)
2208  END DO
2209  WRITE (mdst,8043)
2210  DO j=1, nrgrp
2211  WRITE (mdst,8044) j, loadmp(:,j)
2212  END DO
2213 #endif
2214  !
2215  ! 7.e Warnings
2216  !
2217  IF ( nmproc .GT. 1 ) THEN
2218  DO i=1, nrgrp
2219  ip1 = minval( loadmp(:ncproc,i) )
2220  ipn = maxval( loadmp(:ncproc,i) )
2221  IF ( ip1.NE.ipn .AND. improc.EQ.nmperr ) &
2222  WRITE (mdse,1040) i, ip1, ipn
2223  END DO
2224  END IF
2225  !
2226  DEALLOCATE ( rp1, rpn, loadmp )
2227  !
2228  ! 7.f Reset NMPSCR to first processor of first rank 1 grid
2229  !
2230 #ifdef W3_MPI
2231  CALL wmsetm ( ingrp(1,1), mdse, mdst )
2232  nmpscr = croot
2233 #endif
2234  !
2235 #ifdef W3_MPI
2236  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
2237 #endif
2238  !
2239  ! 8. Actual initializations ----------------------------------------- /
2240  !
2241 #ifdef W3_MPRF
2242  CALL prtime ( prftn )
2243  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8'
2244  prft0 = prftn
2245 #endif
2246  !
2247  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,980)
2248  ALLOCATE ( tsync(2,0:nrgrd), tmax(2,nrgrd), toutp(2,0:nrgrd), &
2249  tdata(2,nrgrd), grstat(nrgrd), dtres(nrgrd) )
2250  !
2251  tsync(1,:) = -1
2252  tsync(2,:) = 0
2253  tmax(1,:) = -1
2254  tmax(2,:) = 0
2255  toutp(1,:) = -1
2256  toutp(2,:) = 0
2257  tdata(1,:) = -1
2258  tdata(2,:) = 0
2259  grstat = 99
2260  !
2261  ! 8.a Loop over models for per-model initialization
2262  !
2263 #ifdef W3_T
2264  WRITE (mdst,9080)
2265 #endif
2266 #ifdef W3_MPRF
2267  CALL prtime ( prftn )
2268  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8.a'
2269  prft0 = prftn
2270 #endif
2271  !
2272  DO i=1, nrgrd
2273  j = len_trim(mnames(i))
2274  DO nmpsc2=1, nmproc
2275  IF ( allprc(nmpsc2,i) .EQ. 1 ) EXIT
2276  END DO
2277  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
2278  WRITE (mdss,981) i, mnames(i)(1:j)
2279  !
2280 #ifdef W3_MPI
2281  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
2282 #endif
2283  !
2284  ! 8.a.1 Wave model initialization (NOTE: sets all grid pointers)
2285  ! ..... Initial output file hook up
2286  !
2287  CALL wmsetm ( i, mdse, mdst )
2288 #ifdef W3_MPI
2289  mpi_comm_loc = mpi_comm_grd
2290  IF ( mpi_comm_loc .EQ. mpi_comm_null ) cycle
2291 #endif
2292  !
2293  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT' )
2294  CALL wmuset ( mdse, mdst, ndsfnd, .true., desc='Log file' )
2295  mds( 1,i) = ndsfnd
2296  !
2297  ! ... this one overwrites the combined setting MDS( 3,I) = MDST above
2298  !
2299  ! CALL WMUGET ( MDSE, MDST, NDSFND, 'OUT' )
2300  ! CALL WMUSET ( MDSE, MDST, NDSFND, .TRUE., DESC='Test output' )
2301  ! MDS( 3,I) = NDSFND
2302  !
2303  DO j=1, 6
2304  IF ( j.EQ.4 .OR. j.EQ.5 ) cycle
2305  IF ( odat(5*(j-1)+3,i) .GT. 0 ) THEN
2306  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT' )
2307  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
2308  desc='Raw output file' )
2309  SELECT CASE (j)
2310  CASE (1)
2311  mds(7,i) = ndsfnd
2312 #ifdef W3_ASCII
2313  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT' )
2314  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
2315  desc='ASCII output file' )
2316  mds(14,i) = ndsfnd ! ASCII
2317 #endif
2318  CASE (2)
2319  mds(8,i) = ndsfnd
2320 #ifdef W3_ASCII
2321  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT' )
2322  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
2323  desc='ASCII output file' )
2324  mds(15,i) = ndsfnd ! ASCII
2325 #endif
2326  CASE (3)
2327  mds(12,i) = ndsfnd
2328  CALL wmuget ( mdse, mdst, ndsfnd, 'INP' )
2329  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
2330  desc='Input data file' )
2331  mds(11,i) = ndsfnd
2332  CASE (6)
2333  mds(13,i) = ndsfnd
2334  END SELECT
2335  END IF
2336  END DO
2337  !
2338  CALL wmuget ( mdse, mdst, ndsfnd, 'INP' )
2339  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
2340  desc='Input data file' )
2341  mds(9,i) = ndsfnd
2342  !
2343  IF ( odat(5*(5-1)+3,i) .GT. 0 ) THEN
2344  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT', 9 )
2345  mds(10,i) = ndsfnd
2346  DO ii=0, 8
2347  CALL wmuset ( mdse, mdst, ndsfnd+ii, .true., &
2348  desc='Raw output file' )
2349  END DO
2350  END IF
2351  !
2352  ! ..... Model initialization
2353  !
2354  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) WRITE (mdss,982)
2355 
2356  CALL w3init ( i, .true., mnames(i), mds(:,i), ntrace(:,i), &
2357  odat(:,i), &
2358  flgrd(:,:,i),flgr2(:,:,i),flgd(:,i),flg2(:,i), &
2359  ot2(i)%NPTS, ot2(i)%X, ot2(i)%Y, ot2(i)%PNAMES, &
2360  iprt(:,i), lprt(i), mpi_comm_loc)
2361  !
2362  ! ..... Finalize I/O file hook up
2363  !
2364  ii = len_trim(filext)
2365  jj = len_trim(fnmpre)
2366  CALL wmuinq ( mdse, mdst, mds(1,i) )
2367  IF ( mds(3,i) .NE. mdst ) CALL wmuinq ( mdse, mdst, mds(3,i) )
2368  !
2369  IF ( mds(7,i) .NE. -1 ) THEN
2370  IF ( iaproc .EQ. napfld ) THEN
2371  tname = trim(fnmpre)//'out_grd.' // filext(:ii)
2372  CALL wmuset ( mdse,mdst, mds(7,i), .true., name=tname )
2373  ELSE
2374  CALL wmuset ( mdse,mdst, mds(7,i), .false. )
2375  mds(7,i) = -1
2376  END IF
2377  END IF
2378  !
2379  IF ( mds(8,i) .NE. -1 ) THEN
2380  IF ( iaproc .EQ. nappnt ) THEN
2381  tname = trim(fnmpre)//'out_pnt.' // filext(:ii)
2382  CALL wmuset ( mdse,mdst, mds(8,i), .true., name=tname )
2383  ELSE
2384  CALL wmuset ( mdse,mdst, mds(8,i), .false. )
2385  mds(8,i) = -1
2386  END IF
2387  END IF
2388  !
2389  IF ( mds(9,i) .NE. -1 ) THEN
2390  IF ( flbpi ) THEN
2391  tname = trim(fnmpre)//'nest.' // filext(:ii)
2392  CALL wmuset ( mdse, mdst, mds(9,i), .true., name=tname )
2393  ELSE
2394  CALL wmuset ( mdse, mdst, mds(9,i), .false. )
2395  mds(9,i) = -1
2396  END IF
2397  END IF
2398  !
2399  IF ( mds(10,i) .NE. -1 ) THEN
2400  IF ( flbpo .AND. iaproc.EQ.napbpt ) THEN
2401  tname = trim(fnmpre)//'nestN.' // filext(:ii)
2402  DO j=0, nfbpo-1
2403  WRITE (tname(jj+5:jj+5),'(I1)') j + 1
2404  CALL wmuset ( mdse, mdst, mds(10,i)+j, .true., &
2405  name=tname )
2406  END DO
2407  DO j=nfbpo, 8
2408  CALL wmuset ( mdse,mdst, mds(10,i)+j, .false. )
2409  END DO
2410  ELSE
2411  DO j=0, 8
2412  CALL wmuset ( mdse,mdst, mds(10,i)+j, .false. )
2413  END DO
2414  mds(10,i) = -1
2415  END IF
2416  END IF
2417  !
2418  IF ( mds(11,i) .NE. -1 ) THEN
2419  tname = trim(fnmpre)//'track_i.' // filext(:ii)
2420  CALL wmuset ( mdse,mdst, mds(11,i), .true., name=tname )
2421  END IF
2422  !
2423  IF ( mds(12,i) .NE. -1 ) THEN
2424  IF ( iaproc .EQ. naptrk ) THEN
2425  tname = trim(fnmpre)//'track_o.' // filext(:ii)
2426  CALL wmuset ( mdse,mdst, mds(12,i), .true., name=tname )
2427  ELSE
2428  CALL wmuset ( mdse,mdst, mds(12,i), .false. )
2429  mds(12,i) = -1
2430  END IF
2431  END IF
2432  !
2433  IF ( mds(13,i) .NE. -1 ) THEN
2434  IF ( iaproc .EQ. napprt ) THEN
2435  tname = trim(fnmpre)//'partition.' // filext(:ii)
2436  CALL wmuset ( mdse,mdst, mds(13,i), .true., name=tname )
2437  ELSE
2438  CALL wmuset ( mdse,mdst, mds(13,i), .false. )
2439  mds(13,i) = -1
2440  END IF
2441  END IF
2442  !
2443 #ifdef W3_ASCII
2444  IF ( mds(14,i) .NE. -1 ) THEN ! Grid output (ASCII)
2445  IF ( iaproc .EQ. napfld ) THEN
2446  tname = trim(fnmpre)//'out_grd.' // filext(:ii) // '.txt'
2447  CALL wmuset ( mdse,mdst, mds(14,i), .true., name=tname )
2448  ELSE
2449  CALL wmuset ( mdse,mdst, mds(14,i), .false. )
2450  mds(14,i) = -1
2451  END IF
2452  END IF
2453  !
2454  IF ( mds(15,i) .NE. -1 ) THEN ! Point output (ASCII)
2455  IF ( iaproc .EQ. nappnt ) THEN
2456  tname = trim(fnmpre)//'out_pnt.' // filext(:ii) // '.txt'
2457  CALL wmuset ( mdse,mdst, mds(15,i), .true., name=tname )
2458  ELSE
2459  CALL wmuset ( mdse,mdst, mds(15,i), .false. )
2460  mds(15,i) = -1
2461  END IF
2462  END IF
2463 #endif
2464 !
2465 #ifdef W3_T
2466  WRITE (mdst,9081) i, time
2467 #endif
2468  !
2469  ! 8.a.2 Data file initialization (forcing)
2470  !
2471  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) WRITE (mdss,983)
2472  CALL w3seti ( i, mdse, mdst )
2473  !
2474  !!Li Stop modifying GTYPE from input forcing file. JGLi08Apr2021.
2475  jjj = gtype
2476  !
2477  ! ..... regular input files
2478  !
2479  DO j=jfirst, 6
2480  IF ( inflags1(j) ) THEN
2481  idinp(i,j) = idstr(j)
2482  IF ( inpmap(i,j) .LT. 0 ) cycle
2483  CALL w3fldo ('READ', idinp(i,j), mdsf(i,j), mdst, mdse2,&
2484  !!Li NX, NY, GTYPE, IERR, MNAMES(I), &
2485  nx, ny, jjj, ierr, mnames(i), &
2486  trim(fnmpre) )
2487  IF ( ierr .NE. 0 ) GOTO 2080
2488  !
2489  !!Li Print a warning message when GTYPE not matching forcing field one.
2490  IF ( (jjj .NE. gtype) .AND. (improc .EQ. nmpsc2) ) &
2491  WRITE (mdse, *) ' *** Warning: grid', i, ' GTYPE=', &
2492  gtype, ' not matching field', j, ' grid type', jjj
2493  !
2494  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
2495  WRITE (mdss,985) idflds(j)
2496  ELSE
2497  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
2498  WRITE (mdss,984) idflds(j)
2499  END IF
2500  END DO
2501  !
2502  ! ..... assimilation data files
2503  !
2504  ! version 3.07: Data assimilation part ignored for now ....
2505  !
2506  ! ..... finalize file info data base
2507  !
2508  DO j=jfirst, 9
2509  IF ( mdsf(i,j) .NE. -1 ) CALL wmuinq ( mdse, mdst, mdsf(i,j) )
2510  END DO
2511  !
2512  ! ..... Adjust input flags for other than native or CPL input,
2513  ! and initialize input arrays one set at a time as needed.
2514  !
2515  IF ( SIZE(inflags1) .NE. SIZE(tflags) ) THEN
2516  WRITE (mdse,'(/2A)') ' *** ERROR WMINIT: ', &
2517  .NE.'SIZE(INFLAGS1)SIZE(TFLAGS) ***'
2518  CALL extcde ( 999 )
2519  END IF
2520  IF ( SIZE(inflags2) .NE. SIZE(tflags) ) THEN
2521  WRITE (mdse,'(/2A)') ' *** ERROR WMINIT: ', &
2522  .NE.'SIZE(INFLAGS2)SIZE(TFLAGS) ***'
2523  CALL extcde ( 999 )
2524  END IF
2525 
2526  tflags = inflags1
2527  !
2528  DO j=jfirst, 9
2529  IF ( inpmap(i,j) .NE. 0 ) THEN
2530  !
2531  tflags(j) = .true.
2532  inflags1 = .false.
2533  inflags1(j) = .true.
2534  iinit = .false.
2535  CALL w3dimi ( i, mdse, mdst )
2536  !
2537  IF ( j.EQ.2 ) ALLOCATE ( wadats(i)%CA0(nsea) , &
2538  wadats(i)%CAI(nsea) , &
2539  wadats(i)%CD0(nsea) , &
2540  wadats(i)%CDI(nsea) )
2541  !
2542  IF ( j.EQ.3 ) ALLOCATE ( wadats(i)%UA0(nsea) , &
2543  wadats(i)%UAI(nsea) , &
2544  wadats(i)%UD0(nsea) , &
2545  wadats(i)%UDI(nsea) , &
2546  wadats(i)%AS0(nsea) , &
2547  wadats(i)%ASI(nsea) )
2548  !
2549  IF ( j.EQ.5 ) ALLOCATE ( wadats(i)%MA0(nsea) , &
2550  wadats(i)%MAI(nsea) , &
2551  wadats(i)%MD0(nsea) , &
2552  wadats(i)%MDI(nsea) )
2553  !
2554  IF ( j.EQ.6 ) ALLOCATE ( wadats(i)%RA0(nsea) , &
2555  wadats(i)%RAI(nsea) )
2556  !
2557  END IF ! IF ( INPMAP(I,J) .NE. 0 ) THEN
2558  END DO ! DO J=JFIRST, 9
2559  !
2560  inflags1 = tflags
2561  CALL w3seti ( i, mdse, mdst )
2562  CALL w3seta ( i, mdse, mdst )
2563  !
2564  ! 8.a.3 Status indicator and model times
2565  !
2566  DO j=1, notype
2567  IF ( flout(j) ) THEN
2568  IF ( toutp(1,i) .EQ. -1 ) THEN
2569  toutp(:,i) = tonext(:,j)
2570  ELSE
2571  dttst = dsec21( toutp(:,i), tonext(:,j) )
2572  IF ( dttst .LT. 0. ) toutp(:,i) = tonext(:,j)
2573  ENDIF
2574  END IF
2575  END DO
2576  !
2577  ! CHECKPOINT
2578  j=8
2579  IF ( flout(j) ) THEN
2580  IF ( toutp(1,i) .EQ. -1 ) THEN
2581  toutp(:,i) = tonext(:,j)
2582  ELSE
2583  dttst = dsec21( toutp(:,i), tonext(:,j) )
2584  IF ( dttst .LT. 0. ) toutp(:,i) = tonext(:,j)
2585  ENDIF
2586  END IF
2587  !
2588  !
2589  grstat(i) = 0
2590  tsync(:,i) = time(:)
2591  !
2592 #ifdef W3_SMC
2593  ! Check GTYPE values after initialization
2594  IF ( improc .EQ. nmperr ) WRITE(mdse,*) "GRID IMPROC GTYPE", &
2595  i, improc, grids(i)%GTYPE
2596 #endif
2597  !
2598 #ifdef W3_T
2599  WRITE (mdst,9082) grstat(i), toutp(:,i), tsync(:,i)
2600 #endif
2601  !
2602  END DO !! 8.a I-NRGRD loop
2603  !
2604 #ifdef W3_MPI
2605  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
2606  DO i=1, nrgrd
2607  CALL wmsetm ( i, mdse, mdst )
2608  CALL w3setg ( i, mdse, mdst )
2609  CALL w3seto ( i, mdse, mdst )
2610  IF ( fbcast .AND. mpi_comm_bct.NE.mpi_comm_null ) THEN
2611  CALL mpi_bcast ( toutp(1,i), 2, mpi_integer, 0, &
2612  mpi_comm_bct, ierr_mpi )
2613  CALL mpi_bcast ( tsync(1,i), 2, mpi_integer, 0, &
2614  mpi_comm_bct, ierr_mpi )
2615  CALL mpi_bcast ( grstat(i), 1, mpi_integer, 0, &
2616  mpi_comm_bct, ierr_mpi )
2617 #endif
2618  !
2619  ! 8.a.4 Grid sizes etc. for processors that are not used.
2620  !
2621 #ifdef W3_MPI
2622  CALL mpi_bcast ( flagll,1, mpi_logical, 0, &
2623  mpi_comm_bct, ierr_mpi )
2624  CALL mpi_bcast ( gtype, 1, mpi_integer, 0, &
2625  mpi_comm_bct, ierr_mpi )
2626  CALL mpi_bcast ( iclose,1, mpi_integer, 0, &
2627  mpi_comm_bct, ierr_mpi )
2628  CALL mpi_bcast ( nx , 1, mpi_integer, 0, &
2629  mpi_comm_bct, ierr_mpi )
2630  CALL mpi_bcast ( ny , 1, mpi_integer, 0, &
2631  mpi_comm_bct, ierr_mpi )
2632  CALL mpi_bcast ( x0 , 1, mpi_real , 0, &
2633  mpi_comm_bct, ierr_mpi )
2634  CALL mpi_bcast ( sx , 1, mpi_real , 0, &
2635  mpi_comm_bct, ierr_mpi )
2636  CALL mpi_bcast ( y0 , 1, mpi_real , 0, &
2637  mpi_comm_bct, ierr_mpi )
2638  CALL mpi_bcast ( sy , 1, mpi_real , 0, &
2639  mpi_comm_bct, ierr_mpi )
2640  CALL mpi_bcast ( nsea , 1, mpi_integer, 0, &
2641  mpi_comm_bct, ierr_mpi )
2642  CALL mpi_bcast ( nseal, 1, mpi_integer, 0, &
2643  mpi_comm_bct, ierr_mpi )
2644  CALL mpi_bcast ( dtmax, 1, mpi_real, 0, &
2645  mpi_comm_bct, ierr_mpi )
2646  CALL mpi_bcast ( dtcfl, 1, mpi_real, 0, &
2647  mpi_comm_bct, ierr_mpi )
2648  CALL mpi_bcast ( filext, 10, mpi_character, 0, &
2649  mpi_comm_bct, ierr_mpi )
2650  IF ( mpi_comm_grd .EQ. mpi_comm_null ) &
2651  CALL w3dimx ( i, nx, ny, nsea, mdse, mdst &
2652 #endif
2653 #ifdef W3_SMC
2654  !! SMC grid related variables are not needed beyond MPI_COMM_GRD
2655  !! so all dimensions are minimised to 1. JGLi29Mar2021
2656 #endif
2657 #ifdef W3_MPI
2658 #ifdef W3_SMC
2659  !!Li , NCel, NUFc, NVFc, NRLv, NBSMC &
2660  !!Li , NARC, NBAC, NSPEC &
2661  , 1, 1, 1, 1, 1, 1, 1, 1 &
2662 #endif
2663  )
2664  CALL mpi_bcast ( hqfac, nx*ny, mpi_real, 0, &
2665  mpi_comm_bct, ierr_mpi )
2666  CALL mpi_bcast ( hpfac, nx*ny, mpi_real, 0, &
2667  mpi_comm_bct, ierr_mpi )
2668  CALL mpi_bcast ( xgrd, nx*ny, mpi_double_precision, 0, &
2669  mpi_comm_bct, ierr_mpi )
2670  CALL mpi_bcast ( ygrd, nx*ny, mpi_double_precision, 0, &
2671  mpi_comm_bct, ierr_mpi )
2672  IF ( mpi_comm_grd .EQ. mpi_comm_null ) &
2673  gsu = w3gsuc( .false., flagll, iclose, &
2674  xgrd, ygrd )
2675  CALL mpi_bcast ( dxdp, nx*ny, mpi_real, 0, &
2676  mpi_comm_bct, ierr_mpi )
2677  CALL mpi_bcast ( dxdq, nx*ny, mpi_real, 0, &
2678  mpi_comm_bct, ierr_mpi )
2679  CALL mpi_bcast ( dydp, nx*ny, mpi_real, 0, &
2680  mpi_comm_bct, ierr_mpi )
2681  CALL mpi_bcast ( dydq, nx*ny, mpi_real, 0, &
2682  mpi_comm_bct, ierr_mpi )
2683  CALL mpi_bcast ( mapsta, nx*ny, mpi_integer, 0, &
2684  mpi_comm_bct, ierr_mpi )
2685  CALL mpi_bcast ( mapst2, nx*ny, mpi_integer, 0, &
2686  mpi_comm_bct, ierr_mpi )
2687  CALL mpi_bcast ( gridshift, 1, mpi_double_precision, 0, &
2688  mpi_comm_bct, ierr_mpi )
2689 #endif
2690  !
2691 #ifdef W3_MPI
2692  CALL mpi_bcast ( nk , 1, mpi_integer, 0, &
2693  mpi_comm_bct, ierr_mpi )
2694  CALL mpi_bcast ( nth , 1, mpi_integer, 0, &
2695  mpi_comm_bct, ierr_mpi )
2696  CALL mpi_bcast ( xfr , 1, mpi_real , 0, &
2697  mpi_comm_bct, ierr_mpi )
2698  CALL mpi_bcast ( fr1 , 1, mpi_real , 0, &
2699  mpi_comm_bct, ierr_mpi )
2700  IF ( mpi_comm_grd .EQ. mpi_comm_null ) &
2701  CALL w3dims ( i, nk, nth, mdse, mdst )
2702  CALL mpi_bcast ( th , nth, mpi_real , 0, &
2703  mpi_comm_bct, ierr_mpi )
2704 #endif
2705  !
2706 #ifdef W3_MPI
2707  CALL mpi_bcast ( naproc,1, mpi_integer, 0, &
2708  mpi_comm_bct, ierr_mpi )
2709  CALL mpi_bcast ( nappnt,1, mpi_integer, 0, &
2710  mpi_comm_bct, ierr_mpi )
2711  CALL mpi_bcast ( nbi , 1, mpi_integer, 0, &
2712  mpi_comm_bct, ierr_mpi )
2713 #endif
2714  !
2715 #ifdef W3_MPI
2716  CALL mpi_bcast ( flout, 8, mpi_logical, 0, &
2717  mpi_comm_bct, ierr_mpi )
2718  CALL mpi_bcast ( dtout , 8, mpi_real, 0, &
2719  mpi_comm_bct, ierr_mpi )
2720  CALL mpi_bcast ( tonext,16, mpi_integer, 0, &
2721  mpi_comm_bct, ierr_mpi )
2722  CALL mpi_bcast ( tolast,16, mpi_integer, 0, &
2723  mpi_comm_bct, ierr_mpi )
2724 #endif
2725  !
2726 #ifdef W3_MPI
2727  END IF
2728  END DO
2729  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
2730 #endif
2731  !
2732  DO i=1, nrgrd
2733  IF ( allprc(improc,i) .EQ. 0 ) THEN
2734  CALL w3seto ( i, mdse, mdst )
2735  iaproc = -1
2736  END IF
2737  END DO
2738  !
2739  ! 8.a.5 Test output
2740  !
2741 #ifdef W3_T
2742  WRITE (mdst,9020) 'AFTER SETUP'
2743  DO i=1, nrgrd
2744  WRITE (mdst,9021) i, mds(:,i), ntrace(:,i)
2745  END DO
2746 #endif
2747  !
2748  ! 8.a.6 Check for coordinate system
2749  !
2750  DO i=1, nrgrd-1
2751  IF ( grids(i)%FLAGLL .NEQV. grids(i+1)%FLAGLL ) GOTO 2070
2752  END DO
2753  !
2754  ! 8.b Input files
2755  !
2756 #ifdef W3_MPRF
2757  CALL prtime ( prftn )
2758  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8.c'
2759  prft0 = prftn
2760 #endif
2761  !
2762  DO i=1, nrinp
2763  !
2764  IF ( .NOT. useinp(i) ) cycle
2765  !
2766  j = len_trim(mnames(-i))
2767  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) THEN
2768  WRITE (mdss,988) i, mnames(-i)(1:j)
2769  WRITE (mdss,987)
2770  END IF
2771  !
2772  CALL w3iogr ( 'GRID', ndsrec, -i, mnames(-i)(1:j) )
2773  CALL w3dimi ( -i, mdse, mdst )
2774  !
2775  IF ( cplinp(i) ) cycle
2776  !
2777  DO j=jfirst, 6
2778  IF ( inflags1(j) ) THEN
2779  idinp(-i,j) = idstr(j)
2780  CALL w3fldo ('READ', idinp(-i,j), mdsf(-i,j), mdst, &
2781  mdse2, nx, ny, gtype, ierr, &
2782  mnames(-i), trim(fnmpre) )
2783  IF ( ierr .NE. 0 ) GOTO 2080
2784  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
2785  WRITE (mdss,985) idflds(j)
2786  ELSE
2787  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
2788  WRITE (mdss,984) idflds(j)
2789  END IF
2790  END DO
2791  !
2792  ! Skipping assimilation input files for now.
2793  !
2794  DO j=jfirst, 9
2795  IF ( mdsf(-i,j) .NE. -1 ) CALL wmuinq &
2796  ( mdse, mdst, mdsf(-i,j) )
2797  END DO
2798  !
2799  END DO
2800  !
2801  DO i=1, nrgrd
2802  DO j=jfirst, 9
2803  IF ( inpmap(i,j).LT.0 .AND. inpmap(i,j).NE.-999) idinp(i,j) = idinp( inpmap(i,j),j)
2804  !IF ( INPMAP(I,J) .LT. 0 ) IDINP(I,J) = IDINP( INPMAP(I,J),J)
2805  IF ( inpmap(i,j) .GT. 0 ) idinp(i,j) = idinp(-inpmap(i,j),j)
2806  END DO
2807  END DO
2808  !
2809  DEALLOCATE ( useinp )
2810  DEALLOCATE ( cplinp )
2811  !
2812  ! 8.c Inter model initialization
2813  !
2814 #ifdef W3_MPRF
2815  CALL prtime ( prftn )
2816  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8.d'
2817  prft0 = prftn
2818 #endif
2819 
2820  ! 8.c.1 Spectral conversion flags and source term flags
2821  !
2822  CALL wmrspc
2823  !
2824  DO i=1, nrgrd
2825  CALL w3setg ( i, mdse, mdst )
2826  flagst = .true.
2827  END DO
2828  !
2829  ! 8.c.2 Relation to lower ranked grids
2830  ! Includes update of unit numbers, and bound. data initialization.
2831  !
2832  ALLOCATE ( flrbpi(nrgrd) )
2833  CALL wmglow ( flrbpi )
2834  !
2835  ! ..... At this point the grid-search-utility (GSU) object for grids
2836  ! that do not belong to this processor is no longer needed.
2837  !
2838 #ifdef W3_MPI
2839  DO i=1, nrgrd
2840  CALL wmsetm ( i, mdse, mdst )
2841  CALL w3setg ( i, mdse, mdst )
2842 #endif
2843  ! the next line (with the W3GSUD call) removed Jan 8 2013.
2844  ! ...ref: personal communication,
2845  ! ...email from Rogers to Alves, Campbell, Tolman, Chawla Dec 13 2012.
2846  ! REMOVED !/MPI IF ( MPI_COMM_GRD .EQ. MPI_COMM_NULL ) CALL W3GSUD( GSU )
2847 #ifdef W3_MPI
2848  END DO
2849 #endif
2850  !
2851  ! ..... Unit numbers
2852  !
2853 
2854  DO i=1, nrgrd
2855  !
2856  CALL w3setg ( i, mdse, mdst )
2857  CALL w3seto ( i, mdse, mdst )
2858  !
2859  IF ( bcdump(i) .AND. flrbpi(i) ) THEN
2860  IF ( improc .EQ. nmperr ) WRITE (mdse,1080) i
2861  IF ( improc .EQ. nmplog ) WRITE (mdso,1082) i
2862  bcdump(i) = .false.
2863  END IF
2864  !
2865  IF ( bcdump(i) .AND. nbi.EQ.0 ) THEN
2866  IF ( improc .EQ. nmperr ) WRITE (mdse,1081) i
2867  IF ( improc .EQ. nmplog ) WRITE (mdso,1082) i
2868  bcdump(i) = .false.
2869  END IF
2870  !
2871 #ifdef W3_SHRD
2872  IF ( .NOT. flrbpi(i) .AND. flbpi ) THEN
2873 #endif
2874 #ifdef W3_MPI
2875  IF ( .NOT. flrbpi(i) .AND. flbpi .AND. &
2876  mpi_comm_grd .NE. mpi_comm_null) THEN
2877 #endif
2878  CALL wmuset ( mdse, mdst, nds(9), .false. )
2879  IF ( bcdump(i) .AND. iaproc.EQ.napbpt ) THEN
2880  j = len_trim(filext)
2881  tname(1:5) = 'nest.'
2882  tname(6:5+j) = filext(1:j)
2883  j = j + 5
2884  CALL wmuget ( mdse, mdst, nds(9), 'OUT' )
2885  CALL wmuset ( mdse, mdst, nds(9), .true., &
2886  name=trim(fnmpre)//tname(1:j), &
2887  desc='Output data file (nest dump)' )
2888  mds(9,i) = ndsfnd
2889  ELSE
2890  nds(9) = -1
2891  END IF
2892 #ifdef W3_MPI
2893  END IF
2894 #endif
2895 #ifdef W3_SHRD
2896  END IF
2897 #endif
2898  !
2899  END DO
2900  !
2901  ! ..... Data initialization
2902  !
2903  DO i=1, nrgrd
2904 #ifdef W3_MPI
2905  CALL wmsetm ( i, mdse, mdst )
2906  IF ( mpi_comm_grd .NE. mpi_comm_null ) CALL wmiobs ( i )
2907 #endif
2908 #ifdef W3_SHRD
2909  CALL wmiobs ( i )
2910 #endif
2911  END DO
2912  !
2913  DO i=1, nrgrd
2914 #ifdef W3_MPI
2915  CALL wmsetm ( i, mdse, mdst )
2916  IF ( mpi_comm_grd .NE. mpi_comm_null ) CALL wmiobg ( i )
2917 #endif
2918 #ifdef W3_SHRD
2919  CALL wmiobg ( i )
2920 #endif
2921  END DO
2922  !
2923 #ifdef W3_MPI
2924  DO i=1, nrgrd
2925  CALL wmsetm ( i, mdse, mdst )
2926  IF ( mpi_comm_grd .NE. mpi_comm_null ) CALL wmiobf ( i )
2927  END DO
2928 #endif
2929  !
2930  ! 8.c.3 Relation to same ranked grids
2931  !
2932 #ifdef W3_SMC
2933  !! Check whether there is a SMC grid group. JGLi12Apr2021
2934  ngrpsmc = 0
2935  DO jj=1, nrgrp
2936  j = 0
2937  DO ii=1, ingrp(jj,0)
2938  i = ingrp(jj,ii)
2939  IF( grids(i)%GTYPE .EQ. smctype ) j = j + 1
2940  ENDDO
2941  IF( j .GT. 1 ) ngrpsmc = jj
2942  ENDDO
2943  IF( improc.EQ.nmperr ) WRITE (mdse,*) " NGRPSMC =", ngrpsmc
2944 
2945  !! Equal ranked SMC grid group uses its own sub. JGLi12Apr2021
2946  IF( ngrpsmc .GT. 0 ) THEN
2947  CALL wmsmceql
2948  ELSE
2949 #endif
2950  !
2951  CALL wmgeql
2952  !
2953 #ifdef W3_SMC
2954  ENDIF
2955 #endif
2956  !
2957  ! 8.c.4 Relation to higher ranked grids
2958  !
2959  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) WRITE (mdss,938) &
2960  'Computing relation to higher ranked grids'
2961  CALL wmghgh
2962  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) WRITE (mdss,938) &
2963  'Finished computing relation to higher ranked grids'
2964  !
2965  ! 8.c.5 Unified point output
2966  !
2967  IF ( unipts ) THEN
2968  !
2969  outpts(0)%TONEXT(1,2) = odat( 6,0)
2970  outpts(0)%TONEXT(2,2) = odat( 7,0)
2971  outpts(0)%DTOUT ( 2) = real( odat( 8,0) )
2972  outpts(0)%TOLAST(1,2) = odat( 9,0)
2973  outpts(0)%TOLAST(2,2) = odat(10,0)
2974  outpts(0)%OFILES(1) = outff(1,1)
2975  outpts(0)%OFILES(2) = outff(2,1)
2976  !
2977  tout = outpts(0)%TONEXT(:,2)
2978  tlst = outpts(0)%TOLAST(:,2)
2979  !
2980  DO
2981  dttst = dsec21( stime , tout )
2982  IF ( dttst .LT. 0 ) THEN
2983  CALL tick21 ( tout, outpts(0)%DTOUT(2) )
2984  ELSE
2985  EXIT
2986  END IF
2987  END DO
2988  !
2989  outpts(0)%TONEXT(:,2) = tout
2990  !
2991  dttst = dsec21( tout , tlst )
2992  IF ( dttst .LT. 0. ) THEN
2993  unipts = .false.
2994  ELSE
2995  CALL wmiopp ( ot2(0)%NPTS, ot2(0)%X, ot2(0)%Y, &
2996  ot2(0)%PNAMES )
2997  END IF
2998  !
2999 #ifdef W3_MPI
3000  DO i=1, nrgrd
3001  CALL wmsetm ( i, mdse, mdst )
3002  CALL w3setg ( i, mdse, mdst )
3003  CALL w3seto ( i, mdse, mdst )
3004  IF ( fbcast .AND. mpi_comm_bct.NE.mpi_comm_null ) THEN
3005  CALL mpi_bcast ( nopts, 1, mpi_integer, 0, &
3006  mpi_comm_bct, ierr_mpi )
3007  END IF
3008  END DO
3009 #endif
3010  !
3011  END IF
3012  !
3013  ! 8.c.6 Output
3014  !
3015  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3016  WRITE (mdss,938) 'Additional group information'
3017  !
3018  IF ( maxval(grdlow(:,0)) .GT. 0 ) THEN
3019  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3020  WRITE (mdss,933) 'Lower rank grid dependence'
3021  IF ( nmplog .EQ. improc ) &
3022  WRITE (mdso,933) 'Lower rank grid dependence'
3023  DO i=1, nrgrd
3024  WRITE (line(1:6),'(1X,I3,2X)') i
3025  jjj = 6
3026  IF ( grdlow(i,0) .NE. 0 ) THEN
3027  DO j=1, grdlow(i,0)
3028  WRITE (line(jjj+1:jjj+3),'(I3)') grdlow(i,j)
3029  jjj = jjj + 3
3030  END DO
3031  ELSE IF ( flrbpi(i) ) THEN
3032  jjj = 21
3033  line(7:jjj) = ' Data from file'
3034  ELSE
3035  jjj = 22
3036  line(7:jjj) = ' No dependencies'
3037  END IF
3038  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3039  WRITE(mdss,934) line(1:jjj)
3040  IF ( nmplog .EQ. improc ) WRITE(mdso,934) line(1:jjj)
3041  END DO
3042  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,935)
3043  IF ( nmplog .EQ. improc ) WRITE (mdso,935)
3044  ELSE
3045  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3046  WRITE (mdss,937) 'No lower rank grid dependencies'
3047  IF ( nmplog .EQ. improc ) &
3048  WRITE (mdso,937) 'No lower rank grid dependencies'
3049  END IF
3050  DEALLOCATE ( flrbpi )
3051  !
3052  IF ( maxval(grdeql(:,0)) .GT. 0 ) THEN
3053  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3054  WRITE (mdss,933) 'Same rank grid dependence'
3055  IF ( nmplog .EQ. improc ) &
3056  WRITE (mdso,933) 'Same rank grid dependence'
3057  DO i=1, nrgrd
3058  WRITE (line(1:6),'(1X,I3,2X)') i
3059  jjj = 6
3060  IF ( grdeql(i,0) .NE. 0 ) THEN
3061  DO j=1, grdeql(i,0)
3062  WRITE (line(jjj+1:jjj+3),'(I3)') grdeql(i,j)
3063  jjj = jjj + 3
3064  END DO
3065  ELSE
3066  jjj = 22
3067  line(7:jjj) = ' No dependencies'
3068  END IF
3069  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3070  WRITE(mdss,934) line(1:jjj)
3071  IF ( nmplog .EQ. improc ) WRITE(mdso,934) line(1:jjj)
3072  END DO
3073  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,935)
3074  IF ( nmplog .EQ. improc ) WRITE (mdso,935)
3075  ELSE
3076  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3077  WRITE (mdss,937) 'No same rank grid dependencies'
3078  IF ( nmplog .EQ. improc ) &
3079  WRITE (mdso,937) 'No same rank grid dependencies'
3080  END IF
3081  !
3082  IF ( maxval(grdhgh(:,0)) .GT. 0 ) THEN
3083  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3084  WRITE (mdss,933) 'Higher rank grid dependence'
3085  IF ( nmplog .EQ. improc ) &
3086  WRITE (mdso,933) 'Higher rank grid dependence'
3087  DO i=1, nrgrd
3088  WRITE (line(1:6),'(1X,I3,2X)') i
3089  jjj = 6
3090  IF ( grdhgh(i,0) .NE. 0 ) THEN
3091  DO j=1, grdhgh(i,0)
3092  WRITE (line(jjj+1:jjj+3),'(I3)') grdhgh(i,j)
3093  jjj = jjj + 3
3094  END DO
3095  ELSE
3096  jjj = 22
3097  line(7:jjj) = ' No dependencies'
3098  END IF
3099  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3100  WRITE(mdss,934) line(1:jjj)
3101  IF ( nmplog .EQ. improc ) WRITE(mdso,934) line(1:jjj)
3102  END DO
3103  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,935)
3104  IF ( nmplog .EQ. improc ) WRITE (mdso,935)
3105  ELSE
3106  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
3107  WRITE (mdss,937) 'No higher rank grid dependencies'
3108  IF ( nmplog .EQ. improc ) &
3109  WRITE (mdso,937) 'No higher rank grid dependencies'
3110  END IF
3111  !
3112 #ifdef W3_T
3113  WRITE (mdst,9083)
3114  DO i=-nrinp, nrgrd
3115  WRITE (mdst,9084) i, idinp(i,:)
3116  END DO
3117 #endif
3118  !
3119  ! Test output of connected units (always)
3120  !
3121  CALL wmuset ( mdse, mdst, scratch, .false. )
3122  IF ( tstout ) CALL wmudmp ( mdst, 0 )
3123  !
3124  DEALLOCATE ( mds, ntrace, odat, flgrd, flgr2, flgd, flg2, inames,&
3125  mnames &
3126  ,outff )
3127  !
3128 #ifdef W3_MPI
3129  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
3130 #endif
3131  !
3132  CALL date_and_time ( values=clkdt2 )
3133  clkfin = tdiff( clkdt1,clkdt2 )
3134  !
3135 #ifdef W3_MPRF
3136  CALL prtime ( prftn )
3137  WRITE (mdsp,990) prft0, prftn, get_memory(), 'END'
3138 #endif
3139  !
3140  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,998)
3141 #ifdef W3_O10
3142  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,999)
3143 #endif
3144  !
3145  RETURN
3146  !
3147  ! Escape locations read errors :
3148  !
3149 2000 CONTINUE
3150  IF ( improc .EQ. nmperr ) WRITE (mdse,1000) ifname, ierr
3151  CALL extcde ( 2000 )
3152  RETURN
3153  !
3154 2001 CONTINUE
3155  IF ( improc .EQ. nmperr ) WRITE (mdse,1001)
3156  CALL extcde ( 2001 )
3157  RETURN
3158  !
3159 2002 CONTINUE
3160  IF ( improc .EQ. nmperr ) WRITE (mdse,1002) ierr
3161  CALL extcde ( 2002 )
3162  RETURN
3163  !
3164 2010 CONTINUE
3165  IF ( improc .EQ. nmperr ) WRITE (mdse,1010) ierr
3166  CALL extcde ( 2010 )
3167  RETURN
3168  !
3169 2011 CONTINUE
3170  ! === no process number filtering for test file !!! ===
3171  WRITE (mdse,1011) ierr
3172  CALL extcde ( 2011 )
3173  RETURN
3174  !
3175 2020 CONTINUE
3176  IF ( improc .EQ. nmperr ) WRITE (mdse,1020)
3177  CALL extcde ( 2020 )
3178  RETURN
3179  !
3180 2021 CONTINUE
3181  IF ( improc .EQ. nmperr ) WRITE (mdse,1021)
3182  CALL extcde ( 2021 )
3183  RETURN
3184  !
3185 2030 CONTINUE
3186  IF ( improc .EQ. nmperr ) WRITE (mdse,1030) mnames(i), inames(i,j)
3187  CALL extcde ( 2030 )
3188  RETURN
3189  !
3190 2031 CONTINUE
3191  IF ( improc .EQ. nmperr ) WRITE (mdse,1031) inames(i,j), j
3192  CALL extcde ( 2031 )
3193  RETURN
3194  !
3195  !2050 CONTINUE
3196  ! IF ( IMPROC .EQ. NMPERR ) WRITE (MDSE,1040)
3197  ! CALL EXTCDE ( 2050 )
3198  ! RETURN
3199  !
3200 2051 CONTINUE
3201  IF ( improc .EQ. nmperr ) WRITE (mdse,1051) mn(:ii)
3202  CALL extcde ( 2051 )
3203  RETURN
3204  !
3205 2052 CONTINUE
3206  IF ( improc .EQ. nmperr ) WRITE (mdse,1052) j
3207  CALL extcde ( 2052 )
3208  RETURN
3209  !
3210 2053 CONTINUE
3211  IF ( improc .EQ. nmperr ) WRITE (mdse,1053)
3212  CALL extcde ( 2053 )
3213  RETURN
3214  !
3215 2054 CONTINUE
3216  IF ( improc .EQ. nmperr ) WRITE (mdse,1054)
3217  CALL extcde ( 2054 )
3218  RETURN
3219  !
3220 2060 CONTINUE
3221  IF ( improc .EQ. nmperr ) WRITE (mdse,1060)
3222  CALL extcde ( 2060 )
3223  RETURN
3224  !
3225 2070 CONTINUE
3226  IF ( improc .EQ. nmperr ) WRITE (mdse,1070)
3227  CALL extcde ( 2070 )
3228  RETURN
3229  !
3230 2080 CONTINUE
3231  CALL extcde ( 2080 )
3232  RETURN
3233  !
3234  ! Formats
3235  !
3236 900 FORMAT ( ' ========== STARTING MWW3 INITIALIZATION (WMINIT) =', &
3237  '============================'/)
3238 901 FORMAT ( ' WAVEWATCH III log file ', &
3239  ' version ',a/ &
3240  ' ==================================', &
3241  '==================================='/ &
3242  ' multi-grid model driver ', &
3243  'date : ',a10/50x,'time : ',a8)
3244  !
3245 910 FORMAT ( ' Opening input file ',a,' (unit number',i3,')')
3246 911 FORMAT ( ' Opening output file ',a,' (unit number',i3,')')
3247 912 FORMAT (/' Comment character : ''',a,'''')
3248  !
3249 920 FORMAT (/' Number of grids :',i3)
3250 921 FORMAT ( ' No input data grids.')
3251 922 FORMAT ( ' Input data grids :',i3)
3252 923 FORMAT ( ' Single point output file : ',a)
3253 1923 FORMAT (/' Output server type :',i3)
3254 2923 FORMAT ( ' Single point output proc : ',a)
3255 3923 FORMAT ( ' Grids share output procs : ',a)
3256  !
3257 924 FORMAT (/' Input grid information : '/ &
3258  ' nr extension lev. cur. wind ice tau', &
3259  ' rho data'/ &
3260  ' ----------------------------------------------', &
3261  '--------------')
3262 925 FORMAT (1x,i3,1x,a10,6(1x,a6),3(1x,a1))
3263 926 FORMAT ( ' ----------------------------------------------', &
3264  '--------------')
3265  !
3266 927 FORMAT (/' Grid for point output : '/ &
3267  ' nr extension '/ ' ---------------')
3268 928 FORMAT (5x,a10)
3269 929 FORMAT ( ' ---------------')
3270  !
3271 930 FORMAT (/' Wave grid information : '/ &
3272  ' nr extension lev. cur. wind ice tau', &
3273  ' rho data move1 rnk grp dmp'/ &
3274  ' ----------------------------------------------', &
3275  '-----------------------------------')
3276 931 FORMAT (1x,i3,1x,a10,6(1x,a6),3(1x,a1),2x,a4,2i4,3x,a1)
3277 932 FORMAT ( ' -----------------------------------------------', &
3278  '-----------------------------------'/)
3279 933 FORMAT ( ' ',a,' : '/ &
3280  ' nr grids (part of comm.)'/ &
3281  ' -----------------------------------------------', &
3282  '---------------------')
3283 934 FORMAT (a)
3284 935 FORMAT ( ' -----------------------------------------------', &
3285  '---------------------'/)
3286 936 FORMAT (/' ',a,' : '/ &
3287  ' nr Depends on '/ &
3288  ' -----------------------------------------------', &
3289  '---------------------')
3290 937 FORMAT ( ' ',a/)
3291 938 FORMAT (/' ',a/)
3292  !
3293 940 FORMAT (/' Time interval : '/ &
3294  ' --------------------------------------------------')
3295 941 FORMAT ( ' Starting time : ',a)
3296 942 FORMAT ( ' Ending time : ',a/)
3297 943 FORMAT (/' Model settings : '/ &
3298  ' --------------------------------------------------')
3299 944 FORMAT ( ' Masking computation in nesting : ',a)
3300 945 FORMAT ( ' Masking output in nesting : ',a/)
3301  !
3302 950 FORMAT (/' Output requests : (ALL GRIDS) '/ &
3303  ' ==================================================')
3304 951 FORMAT (/' Type',i2,' : ',a/ &
3305  ' -----------------------------------------')
3306 952 FORMAT ( ' From : ',a)
3307 953 FORMAT ( ' To : ',a)
3308 954 FORMAT ( ' Interval : ',a/)
3309 955 FORMAT ( ' Fields : ',a)
3310 956 FORMAT ( ' ',a)
3311 957 FORMAT ( ' Point 1 : ',2e14.6,2x,a)
3312 958 FORMAT ( ' ',i6,' : ',2e14.6,2x,a)
3313 959 FORMAT ( ' No points defined')
3314 960 FORMAT ( ' The file with ',a,' data is ',a,'.')
3315 961 FORMAT ( ' IX fls : ',3i6/ &
3316  ' IY fls : ',3i6)
3317 962 FORMAT (/' Output request for model ',a,' (nr',i3,') '/ &
3318  ' ==================================================')
3319 963 FORMAT ( ' Output disabled')
3320  !
3321 965 FORMAT (/' Grid movement data (!/MGP, !/MGW): '/ &
3322  ' --------------------------------------------------')
3323 966 FORMAT ( ' ',a)
3324 967 FORMAT ( ' ',i6,2x,a)
3325 968 FORMAT ( ' ',i6,i11.8,i7.6,2f8.2)
3326  !
3327 970 FORMAT(//' Assigning resources : '/ &
3328  ' --------------------------------------------------')
3329 971 FORMAT ( ' ',a)
3330 972 FORMAT ( ' Process ',i5.5,' reserved for all point output.')
3331 973 FORMAT ( ' Processes ',i5.5,' through ',i5.5,' [',i3,']', &
3332  ' reserved for output.')
3333 974 FORMAT (/ &
3334  5x,' grid comp. grd pnt trk rst bpt prt'/ &
3335  5x,' ------------------------------------------------------', &
3336  '-------------')
3337 975 FORMAT (5x,' ',a10,2x,i5.5,'-',i5.5,6(2x,a5))
3338 976 FORMAT(5x,' -------------------------------------------------', &
3339  '------------------')
3340 977 FORMAT (5x,' Unified point output at ',i5.5)
3341 1974 FORMAT (' Resource assignement (processes) : '/ &
3342  ' grid comp. grd pnt trk rst bpt prt'/ &
3343  ' ------------------------------------------------------', &
3344  '-------------')
3345 1975 FORMAT (' ',a10,2x,i5.5,'-',i5.5,6(2x,a5))
3346 1976 FORMAT (' ---------------------------------------------------', &
3347  '----------------')
3348 1977 FORMAT (' Unified point output at ',i5.5)
3349  !
3350 980 FORMAT(//' Initializations :'/ &
3351  ' --------------------------------------------------')
3352 981 FORMAT ( ' Model number',i3,' [',a,']')
3353 982 FORMAT ( ' Initializing wave model ...')
3354 983 FORMAT ( ' Initializing model input ...')
3355 984 FORMAT ( ' ',a,': file not needed')
3356 985 FORMAT ( ' ',a,': file OK')
3357 986 FORMAT ( ' Unified point output [',a,']')
3358 987 FORMAT ( ' Initializing grids ...')
3359 988 FORMAT ( ' Input data grid',i3,' [',a,']')
3360  !
3361 #ifdef W3_MPRF
3362 990 FORMAT (1x,3f12.3,' WMINIT',1x,a)
3363 #endif
3364  !
3365 998 FORMAT ( ' Running the model :'/ &
3366  ' --------------------------------------------------'/)
3367 999 FORMAT ( ' ========== END OF MWW3 INITIALIZATION (WMINIT) ===', &
3368  '============================'/)
3369  !
3370 1000 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3371  ' ERROR IN OPENING INPUT FILE ',a/ &
3372  ' IOSTAT =',i5/)
3373  !
3374 1001 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3375  ' PREMATURE END OF INPUT FILE'/)
3376  !
3377 1002 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3378  ' ERROR IN READING FROM INPUT FILE'/ &
3379  ' IOSTAT =',i5/)
3380 1010 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3381  ' ERROR IN OPENING LOG FILE'/ &
3382  ' IOSTAT =',i5/)
3383 1011 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3384  ' ERROR IN OPENING TEST FILE'/ &
3385  ' IOSTAT =',i5/)
3386 1020 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3387  ' ILLEGAL NUMBER OF GRIDS ( < 1 ) '/)
3388 1021 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3389  ' ILLEGAL NUMBER OF INPUT GRIDS ( < 0 ) '/)
3390 1030 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3391  ' INPUT GRID NAME NOT FOUND '/ &
3392  ' WAVE GRID : ',a/ &
3393  ' INPUT NAME : ',a/)
3394 1031 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : *** '/ &
3395  ' REQUESTED INPUT TYPE NOT FOUND IN INPUT GRID '/ &
3396  ' INPUT GRID : ',a/ &
3397  ' INPUT TYPE : ',i8/)
3398 1032 FORMAT (/' *** WAVEWATCH III WARNING IN WMINIT : *** '/ &
3399  ' INPUT GRID ',a,' NOT USED '/)
3400 1040 FORMAT ( ' *** WAVEWATCH III WARNING IN W3MLTI : ***'/ &
3401  ' POSSIBLE LOAD IMBALANCE GROUP',i3,' :',2i6/)
3402  !1040 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
3403  ! ' ILLEGAL TIME INTERVAL'/)
3404 1050 FORMAT (/' *** WAVEWATCH III WARNING IN W3MLTI : ***'/ &
3405  ' UNIFIED POINT OUTPUT BUT NO OUTPUT'/ &
3406  ' UNIFIED POINT OUTPUT DISABLED'/)
3407 1051 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
3408  ' ILLEGAL MODEL ID [',a,']'/)
3409 1052 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
3410  ' ILLEGAL OUTPUT TYPE',i10/)
3411 1053 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
3412  ' OUTPUT POINTS FOR INDIVIDUAL GRIDS CANNOT BE DEFINED'/ &
3413  ' WHEN UNIFIED POINT OUTPUT IS REQUESTED'/)
3414 1054 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
3415  ' POINT OUTPUT ACTIVATED, BUT NO POINTS DEFINED'/)
3416 1060 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
3417  ' NO MOVING GRID DATA PRESENT'/)
3418 1070 FORMAT (/' *** WAVEWATCH III ERROR IN WMINIT : ***'/ &
3419  ' ALL GRIDS ARE NOT USING THE SAME COORDINATE SYSTEM'/)
3420 1080 FORMAT (/' *** BOUNDARY DATA READ, WILL NOT DUMP, GRID :',i4, &
3421  ' ***')
3422 1081 FORMAT (/' *** NO BOUNDARY DATA TO DUMP, GRID :',i4,' ***')
3423 1082 FORMAT ( ' No boundary data dump for grid',i3/)
3424  !
3425 #ifdef W3_T
3426 9000 FORMAT ( ' TEST WMINIT : UNIT NUMBERS : ',5i6/ &
3427  ' INPUT FILE NAME : ',a)
3428 #endif
3429  !
3430 #ifdef W3_T
3431 9020 FORMAT ( ' TEST WMINIT : UNIT NUMBERS FOR GRIDS (',a,')'/ &
3432  15x,'GRID MDS(1-15)',43x,'NTRACE')
3433 9021 FORMAT (14x,16i4)
3434 9022 FORMAT ( ' TEST WMINIT : UNIT NUMBERS FOR INTPUT FILES'/ &
3435  15x,'GRID MDSF(JFIRST-9)')
3436 9030 FORMAT ( ' TEST WMINIT : FILE EXTENSIONS, INPUT FLAGS,', &
3437  ' RANK AND GROUP, PROC RANGE')
3438 9031 FORMAT ( ' ',i3,1x,a,20l2,2i4,2f6.2)
3439 9032 FORMAT ( ' TEST WMINIT : PROCESSED RANK NUMBERS')
3440 9033 FORMAT ( ' ',i3,1x,a,1x,i4)
3441 9034 FORMAT ( ' TEST WMINIT : NUMBER OF GROUPS :',i4)
3442 9035 FORMAT ( ' TEST WMINIT : SIZE OF GROUPS :',20i3)
3443 9036 FORMAT ( ' TEST WMINIT : GROUP SIZE AND COMPONENTS :')
3444 9037 FORMAT ( ' ',2i3,':',20i3)
3445 #endif
3446  !
3447 #ifdef W3_T
3448 9050 FORMAT ( ' TEST WMINIT : GRID NUMBER',i3,' =================')
3449 9051 FORMAT ( ' TEST WMINIT : ODAT : ',i9.8,i7.6,i7,i9.8,i7.6, &
3450  5(/24x,i9.8,i7.6,i7,i9.8,i7.6) )
3451 9052 FORMAT ( ' TEST WMINIT : FLGRD : ',5(5l2,1x)/24x,5(5l2,1x))
3452 #endif
3453  !
3454 #ifdef W3_T
3455 9060 FORMAT ( ' TEST WMINIT : GRID MOVEMENT DATA')
3456 9061 FORMAT ( ' ',i8.8,i7,1x,2f8.2)
3457 #endif
3458  !
3459 #ifdef W3_T
3460 9070 FORMAT ( ' TEST WMINIT : ALLPRC ')
3461 9071 FORMAT ( ' ',i3,' : ',250i3)
3462 8042 FORMAT ( ' TEST WMINIT : MODMAP ')
3463 8043 FORMAT ( ' TEST WMINIT : LOADMP ')
3464 8044 FORMAT ( ' ',i3,' : ',250i2)
3465 #endif
3466  !
3467 #ifdef W3_T
3468 9080 FORMAT ( ' TEST WMINIT : MODEL INITIALIZATION')
3469 9081 FORMAT ( ' MODEL AND TIME :',i4,i10.8,i8.6)
3470 9082 FORMAT ( ' STATUS AND TIMES :',i4,3(i10.8,i8.6))
3471 9083 FORMAT ( ' TEST WMINIT : IDINP AFTER INITIALIZATION :')
3472 9084 FORMAT ( ' ',i4,17(2x,a3))
3473 #endif
3474  !/
3475  !/ End of WMINIT ----------------------------------------------------- /
3476  !/
3477  END SUBROUTINE wminit
3478 
3479 
3480 
3481 
3482 
3483 
3484  !/ ------------------------------------------------------------------- /
3500  SUBROUTINE wminitnml ( IDSI, IDSO, IDSS, IDST, IDSE, IFNAME, &
3501  MPI_COMM, PREAMB )
3502  !/
3503  !/ +-----------------------------------+
3504  !/ | WAVEWATCH III NOAA/NCEP |
3505  !/ | H. L. Tolman |
3506  !/ | FORTRAN 90 |
3507  !/ | Last update : 22-Mar-2021 |
3508  !/ +-----------------------------------+
3509  !/
3510  !/ 13-Jun-2005 : Origination. ( version 3.07 )
3511  !/ 28-Dec-2005 : Add static nesting. ( version 3.08 )
3512  !/ 25-May-2006 : Add overlapping grids. ( version 3.09 )
3513  !/ 26-Jun-2006 : Add output type 6. ( version 3.09 )
3514  !/ 29-Jun-2006 : Adding file name preamble. ( version 3.09 )
3515  !/ 09-Aug-2006 : Unified point output added. ( version 3.10 )
3516  !/ 14-Oct-2006 : Adding separate input grids. ( version 3.10 )
3517  !/ 03-Nov-2006 : Adding wave field separation. ( version 3.10 )
3518  !/ 02-Feb-2007 : Adding FLAGST initialization. ( version 3.10 )
3519  !/ 21-Jun-2007 : Dedicated output processes. ( version 3.11 )
3520  !/ 29-May-2009 : Preparing distribution version. ( version 3.14 )
3521  !/ 30-Oct-2009 : Implement run-time grid selection. ( version 3.14 )
3522  !/ (W. E. Rogers & T. J. Campbell, NRL)
3523  !/ 16-Aug-2010 : Adding NTRMAX to unify NTRACE. ( version 3.14.5 )
3524  !/ 21-Sep-2010 : Adding coupling output ( version 3.14-Ifremer)
3525  !/ 06-Dec-2010 : Change from GLOBAL (logical) to ICLOSE (integer) to
3526  !/ specify index closure for a grid. ( version 3.14 )
3527  !/ (T. J. Campbell, NRL)
3528  !/ 28-Jul-2012 : Initialize FLGR2 properly. ( version 4.08 )
3529  !/ Tom Durant's fix, but moved to allocation.
3530  !/ 28-Nov-2012 : Bug fix: Distribute to idle processors the grid data
3531  !/ required for regridding. ( version 4.08 )
3532  !/ (T. J. Campbell, NRL)
3533  !/ 02-Sep-2012 : Set up for > 999 test files. ( version 4.10 )
3534  !/ Set up output for > 999 procs.
3535  !/ 03-Sep-2012 : Output of initilization time. ( version 4.10 )
3536  !/ Switch test file on/off (TSTOUT)
3537  !/ 28-Nov-2012 : Bug fix: Distribute to idle processors the grid data
3538  !/ required for regridding. ( version 4.08 )
3539  !/ (T. J. Campbell, NRL)
3540  !/ 15-Apr-2013 : Changes the reading of output fields( version 4.10 )
3541  !/ (F. Ardhuin)
3542  !/ 28-Jan-2014 : Add memory hwm to profiling. ( version 5.00 )
3543  !/ 27-May-2014 : Bug fix prf file name. ( version 5.02 )
3544  !/ 17-Sep-2014 : Read mod_def before inp file ( version 5.03 )
3545  !/ 17-Feb-2016 : New version from namelist use ( version 5.11 )
3546  !/ 20-Jan-2017 : Update to new W3GSRUMD APIs ( version 6.02 )
3547  !/ 20-Jan-2017 : Modify input forcing flags to support coupler input.
3548  !/ Add ESMF override for STIME & ETIME ( version 6.02 )
3549  !/ (T. J. Campbell, NRL)
3550  !/ 15-May-2018 : Update namelist ( version 6.05 )
3551  !/ 28-Oct-2020 : Add SMCTYPE for SMC sub-grid. JGLi ( version 7.13 )
3552  !/ 22-Mar-2021 : Add momentum and air density input ( version 7.13 )
3553  !/
3554  ! 1. Purpose :
3555  !
3556  ! Initialize multi-grid version of WAVEWATCH III.
3557  !
3558  ! 2. Method :
3559  !
3560  ! 3. Parameters :
3561  !
3562  ! Parameter list
3563  ! ----------------------------------------------------------------
3564  ! IDSI Int. I Unit number for input file.
3565  ! IDSO Int. I Unit number for output file.
3566  ! IDSS Int. I Unit number for "screen" output. Switch off
3567  ! by setting equal to IDSO.
3568  ! IDST Int. I Unit number for test output.
3569  ! IDSE Int. I Unit number for error output.
3570  ! IFNAME Char I File name for input file.
3571  ! MPI_COMM Int. I MPI communicator to be used.
3572  ! PREAMB Char I File name preamble (optional).
3573  ! ----------------------------------------------------------------
3574  !
3575  ! 4. Subroutines used :
3576  !
3577  ! Name Type Module Description
3578  ! ----------------------------------------------------------------
3579  ! W3NMOD Subr. W3GDATMD Data structure initialization.
3580  ! W3DIMX Subr. Id. Set grid arrays.
3581  ! W3DIMS Subr. Id. Set grid arrays.
3582  ! W3SETG Subr. Id. Point to grid/model.
3583  ! W3NDAT Subr. W3WDATMD Data structure initialization.
3584  ! W3SETW Subr. Id. Point to grid/model.
3585  ! W3NAUX Subr. W3ADATMD Data structure initialization.
3586  ! W3SETA Subr. Id. Point to grid/model.
3587  ! W3NOUT Subr. W3ODATMD Data structure initialization.
3588  ! W3SETO Subr. Id. Point to grid/model.
3589  ! W3NINP Subr. W3IDATMD Data structure initialization.
3590  ! W3SETI Subr. Id. Point to grid/model.
3591  ! W3DIMI Subr. Id. Allocate grid/model.
3592  ! WMNDAT Subr. WMMDATMD Data structure initialization.
3593  ! WMSETM Subr. Id. Point to grid/model.
3594  ! WMDIMD Subr. Id. Allocate array space.
3595  ! W3FLDO Subr. W3FLDSMD Open input data file.
3596  ! W3IOGR Subr. W3IOGRMD Reading of model definition file.
3597  ! W3INIT Subr. W3INITMD Model intiailization.
3598  ! WMGLOW Subr. WMGRIDMD Lower rank grid dependencies.
3599  ! WMGEQL Subr. Id. Same rank grid dependencies.
3600  ! WMGHGH Subr. Id. Higher rank grid dependencies.
3601  ! RESPEC Subr. Id. Spectral conversion flags.
3602  ! WMIOBS Subr. WMINIOMD Stage boundary data.
3603  ! WMIOBG Subr. Id. Gather boundary data.
3604  ! WMIOBF Subr. Id. Finalize staging in WMIOBS.
3605  ! WMUINI Subr. WMUNITMD Initialize dynamic unit assignment,
3606  ! WMUDMP Subr. Id. Dump dynamic unit data,
3607  ! WMUSET Subr. Id. Set unit number data.
3608  ! WMUGET Subr. Id. Get a unit number.
3609  ! WMUINQ Subr. Id. Update unit number info.
3610  ! WMIOPP Subr. WMIOPOMD Initialize unified point output.
3611  ! ITRACE Subr. W3SERVMD Initialize subroutine tracing.
3612  ! STRACE Subr. Id. Subroutine tracing.
3613  ! EXTCDE Subr. Id. Program abort.
3614  ! WWDATE Subr. Id. System date.
3615  ! WWTIME Subr. Id. System time.
3616  ! PRINIT Subr. Id. Profiling routine ( !/MPRF )
3617  ! PRTIME Subr. Id. Profiling routine ( !/MPRF )
3618  ! STME21 Subr. W3TIMEMD Convert time to string.
3619  ! DSEC21 Func. Id. Difference between times.
3620  ! TICK21 Subr. Id. Advance the clock.
3621  ! W3READFLGRD Subr. W3IOGOMD Reads flags or namelist for output fields
3622  !
3623  ! MPI_COMM_SIZE, CALL MPI_COMM_RANK, MPI_BARRIER, MPI_COMM_GROUP,
3624  ! MPI_GROUP_INCLUDE, MPI_COMM_CREATE, MPI_GROUP_FREE, MPI_BCAST
3625  ! Subr. mpif.h Standard MPI routines.
3626  ! ----------------------------------------------------------------
3627  !
3628  ! 5. Called by :
3629  !
3630  ! Name Type Module Description
3631  ! ----------------------------------------------------------------
3632  ! W3MLTI Prog. N/A Multi-grid model driver.
3633  ! .... Any coupled model.
3634  ! ----------------------------------------------------------------
3635  !
3636  ! 6. Error messages :
3637  !
3638  ! See formats 1000 and following, or escape locations 2000 and
3639  ! following.
3640  !
3641  ! 7. Remarks :
3642  !
3643  ! - When running regtests in cases where disk is non-local
3644  ! (i.e. NFS used), there can be a huge improvment in compute
3645  ! time by using /var/tmp/ for log files.
3646  ! See commented line at "OPEN (MDSO,FILE=..."
3647  !
3648  ! - IDFLDS dimensioning is hardwired as IDFLDS(-7:9) where lowest possible
3649  ! value of JFIRST is JFIRST=-7
3650  !
3651  ! 8. Structure :
3652  !
3653  ! --------------------------------------------------------------
3654  ! 1. Multi-grid model intializations
3655  ! a Unit numbers
3656  ! b Subroutine tracing ( ITRACE )
3657  ! c Input file
3658  ! d Log and test files
3659  ! e Initial and test output
3660  ! 2. Set-up of data structures and I/O
3661  ! a Get number of grids
3662  ! b Set up data structures
3663  ! ( W3NMOD, W3NDAT, W3NAUX, W3NOUT, W3NINP, WMNDAT )
3664  ! c Set up I/O for individual models
3665  ! 3. Get individual grid information
3666  ! a Read data
3667  ! b Assign input file numbers.
3668  ! c Set rank and group data
3669  ! d Unified point output file. ( W3IOGR )
3670  ! e Output
3671  ! 4. Model run time information and settings
3672  ! 5. Output requests
3673  ! a Loop over types for unified output
3674  ! ---------------------------------------------------
3675  ! b Process standard line
3676  ! c Type 1: fields of mean wave parameters
3677  ! d Type 2: point output
3678  ! e Type 3: track output
3679  ! f Type 4: restart files (no additional data)
3680  ! g Type 5: nesting data (no additional data)
3681  ! h Type 6: wave field data (dummy for now)
3682  ! i Set all grids to unified output
3683  ! ---------------------------------------------------
3684  ! j Endless loop for correcting output per grid
3685  ! ---------------------------------------------------
3686  ! Test grid name and output number
3687  ! k Process standard line
3688  ! l Type 1: fields of mean wave parameters
3689  ! m Type 2: point output
3690  ! n Type 3: track output
3691  ! o Type 6: partitioning output
3692  ! p Type 7: coupling output
3693  ! ---------------------------------------------------
3694  ! 6. Read moving grid data
3695  ! 7. Work load distribution
3696  ! a Initialize arrays
3697  ! b Set communicators and ALLPRC array
3698  ! c Set MODMAP and LOADMP arrays
3699  ! d Warnings
3700  ! 8. Actual initializations
3701  ! a Loop over models for per-model initialization
3702  ! 1 Wave model ( W3INIT )
3703  ! 2 Data files ( W3FLDO )
3704  ! 3 Grid status indicator and model times
3705  ! 3 Grid data for processors that are NOT used.
3706  ! 5 Test output
3707  ! b Input data files.
3708  ! c Inter model initialization
3709  ! 1 Set spectral conversion flags ( WMRSPC )
3710  ! 2 Prepare unified point output ( WMIOPO )
3711  ! 3 Relation to lower ranked grids
3712  ! ( WMGLOW, WMIOBS, WMIOBG, WMIOBF )
3713  ! 4 Relation to same ranked grids ( WMGEQL )
3714  ! 5 Relation to higher ranked grids ( WMGHGH )
3715  ! 6 Output
3716  ! --------------------------------------------------------------
3717  !
3718  ! 9. Switches :
3719  !
3720  ! !/SHRD Switch for shared / distributed memory architecture.
3721  ! !/DIST Id.
3722  ! !/MPI Id.
3723  !
3724  ! !/MGW Moving grid wind correction.
3725  ! !/MGP Moving grid propagation correction.
3726  !
3727  ! !/O10 Enable output identifying start and end of routine
3728  !
3729  ! !/S Enable subroutine tracing.
3730  ! !/T Enable test output.
3731  ! !/MPRF Profiling.
3732  !
3733  ! 10. Source code :
3734  !
3735  !/ ------------------------------------------------------------------- /
3736  USE constants
3737  !/
3738  USE w3gdatmd, ONLY: w3nmod, w3dimx, w3dims, w3setg
3739  USE w3wdatmd, ONLY: w3ndat, w3setw
3740  USE w3adatmd, ONLY: w3naux, w3seta
3741  USE w3odatmd, ONLY: w3nout, w3seto
3742  USE w3odatmd, ONLY: ofiles
3743  USE w3idatmd, ONLY: w3ninp, w3seti, w3dimi
3744  USE wmmdatmd, ONLY: wmndat, wmsetm, wmdimd
3745  !
3746  USE w3fldsmd, ONLY: w3fldo
3747  USE w3iogomd, ONLY: w3readflgrd, w3flgrdflag
3748  USE w3iogrmd, ONLY: w3iogr
3749  USE w3initmd, ONLY: w3init
3750  USE wmgridmd, ONLY: wmrspc, wmglow, wmgeql, wmghgh, wmsmceql
3751  USE wminiomd, ONLY: wmiobs, wmiobg, wmiobf
3752  USE wmiopomd, ONLY: wmiopp
3753  !/
3754  USE w3servmd, ONLY: itrace, extcde, nextln, wwdate, wwtime
3755 #ifdef W3_S
3756  USE w3servmd, ONLY: strace
3757 #endif
3758 #ifdef W3_MPRF
3759  USE w3timemd, ONLY: prinit, prtime
3760 #endif
3761  USE w3timemd, ONLY: stme21, dsec21, tick21, tdiff
3762  USE wmunitmd, ONLY: wmuini, wmudmp, wmuset, wmuget, wmuinq
3763  !/
3764  USE w3gdatmd, ONLY: gtype, nx, ny, filext, nsea, flagst, grids
3765 #ifdef W3_SMC
3766  USE w3gdatmd, ONLY: ncel, nufc, nvfc, nrlv, nbsmc
3767  USE w3gdatmd, ONLY: narc, nbac, nspec, smctype
3768 #endif
3769 #ifdef W3_MPI
3770  USE w3gdatmd, ONLY: flagll, iclose, gsu, x0, y0, sx, sy, &
3771  xgrd, ygrd, dxdp, dxdq, dydp, dydq, &
3772  hqfac, hpfac, mapsta, mapst2, &
3773  gridshift, nseal, nk, nth, xfr, fr1, &
3774  th, dtmax, dtcfl
3775  USE w3gsrumd
3776 #endif
3777  USE w3wdatmd, ONLY: time
3778  USE w3adatmd, ONLY: wadats
3779  USE w3idatmd, ONLY: inflags1, inflags2, inputs, iinit, &
3780  jfirst
3781  USE w3odatmd, ONLY: nogrp, ngrpp, flout, tonext, flbpi, &
3782  flbpo, nfbpo, nbi, nds, iaproc, &
3783  napfld, nappnt, naptrk, napbpt, &
3785  nopts, iostyp, unipts, upproc, dtout, &
3786  tolast, notype
3787  USE wmmdatmd, ONLY: mdsi, mdso, mdss, mdst, mdse, mdsf, mdsup, &
3788  improc, nmproc, nmpscr, nmperr, &
3789  nmplog, nmpupt, stime, etime, nmv, nmvmax, &
3790  tmv, amv, dmv, nrgrd, nrinp, nrgrp, grank, &
3791  grgrp, ingrp, grdhgh, grdeql, grdlow, &
3792  allprc, modmap, tsync, tmax, toutp, tdata, &
3794  inpmap, idinp, ngrpsmc
3795  USE wmmdatmd, ONLY: clkdt1, clkdt2, clkfin
3796 #ifdef W3_MPI
3797  USE wmmdatmd, ONLY: mpi_comm_mwave, mpi_comm_grd, &
3799 #endif
3800 #ifdef W3_MPRF
3801  USE wmmdatmd, ONLY: mdsp
3802 #endif
3803 #ifdef W3_ASCII
3804  USE wmmdatmd, ONLY: mdsupa
3805 #endif
3806  USE w3initmd, ONLY: wwver
3807  USE w3nmlmultimd
3808  !/
3809  IMPLICIT NONE
3810  !
3811 #ifdef W3_MPI
3812  include "mpif.h"
3813 #endif
3814  !/
3815  !/ ------------------------------------------------------------------- /
3816  !/ Parameter list
3817  !/
3818  INTEGER, INTENT(IN) :: IDSI, IDSO, IDSS, IDST, IDSE, &
3819  MPI_COMM
3820  CHARACTER*(*), INTENT(IN) :: IFNAME
3821  CHARACTER*(*), INTENT(IN), OPTIONAL :: PREAMB
3822  !/
3823  !/ ------------------------------------------------------------------- /
3824  !/ Local parameters
3825  !/
3826  TYPE(nml_domain_t) :: NML_DOMAIN
3827  TYPE(nml_input_grid_t), ALLOCATABLE :: NML_INPUT_GRID(:)
3828  TYPE(nml_model_grid_t), ALLOCATABLE :: NML_MODEL_GRID(:)
3829  TYPE(nml_output_type_t), ALLOCATABLE :: NML_OUTPUT_TYPE(:)
3830  TYPE(nml_output_date_t), ALLOCATABLE :: NML_OUTPUT_DATE(:)
3831  TYPE(nml_homog_count_t) :: NML_HOMOG_COUNT
3832  TYPE(nml_homog_input_t), ALLOCATABLE :: NML_HOMOG_INPUT(:)
3833  !
3834  TYPE ot2tpe
3835  INTEGER :: NPTS
3836  REAL, POINTER :: X(:), Y(:)
3837  CHARACTER(LEN=40), POINTER :: PNAMES(:)
3838  END TYPE ot2tpe
3839  !
3840  TYPE(ot2tpe), ALLOCATABLE :: OT2(:)
3841  !
3842  INTEGER :: MDSE2, IERR, I,J,K, N_MOV, N_TOT, &
3843  SCRATCH, RNKMIN, RNKMAX, RNKTMP, &
3844  GRPMIN, GRPMAX, II, NDSREC, NDSFND, &
3845  NPTS, JJ, IP1, IPN, MPI_COMM_LOC, &
3846  NMPSC2, JJJ, NCPROC, NPOUTT, NAPLOC, &
3847  NAPRES, NAPADD, NAPBCT, IFI, IFJ, IW, &
3848  IFT, ILOOP
3849  !
3850  INTEGER :: TTIME(2), TOUT(2), STMPT(2), ETMPT(2),&
3851  TLST(2)
3852 #ifdef W3_MPI
3853  INTEGER :: IERR_MPI, BGROUP, LGROUP, IROOT
3854 #endif
3855 #ifdef W3_S
3856  INTEGER, SAVE :: IENT = 0
3857 #endif
3858  !
3859  INTEGER, ALLOCATABLE :: MDS(:,:), NTRACE(:,:), ODAT(:,:), &
3860  TMPRNK(:), TMPGRP(:), NINGRP(:), &
3861  TMOVE(:,:), LOADMP(:,:), IPRT(:,:), &
3862  NDPOUT(:) &
3863  ,OUTFF(:,:)
3864  !
3865  REAL :: DTTST, XX, YY
3866 #ifdef W3_MPRF
3867  REAL :: PRFT0, PRFTN
3868  REAL(KIND=8) :: get_memory
3869 #endif
3870  !
3871  REAL, ALLOCATABLE :: X(:), Y(:), AMOVE(:), DMOVE(:), &
3872  RP1(:), RPN(:)
3873  !
3874  LOGICAL :: FLT, TFLAGI, TFLAGS(-7:14), PSHARE
3875  LOGICAL, ALLOCATABLE :: FLGRD(:,:,:), FLRBPI(:), BCDTMP(:), &
3876  USEINP(:), LPRT(:), FLGR2(:,:,:), &
3877  FLGD(:,:), FLG2(:,:), FLG2D(:,:), &
3878  FLG1D(:), CPLINP(:)
3879  !
3880  CHARACTER(LEN=1) :: COMSTR
3881  CHARACTER(LEN=256) :: TMPLINE, TEST
3882  CHARACTER(LEN=3) :: IDSTR(-7:9), IDTST
3883  CHARACTER(LEN=5) :: STOUT, OUTSTR(6)
3884  CHARACTER(LEN=6) :: YESXX, XXXNO
3885  CHARACTER(LEN=6), &
3886  ALLOCATABLE :: ACTION(:)
3887  CHARACTER(LEN=8) :: LFILE, STTIME
3888 #ifdef W3_SHRD
3889  CHARACTER(LEN=9) :: TFILE
3890 #endif
3891  CHARACTER(LEN=13) :: STDATE, MN, TNAMES(9)
3892  CHARACTER(LEN=40) :: PN
3893  CHARACTER(LEN=13), &
3894  ALLOCATABLE :: INAMES(:,:), MNAMES(:)
3895  CHARACTER(LEN=40), &
3896  ALLOCATABLE :: PNAMES(:)
3897  CHARACTER(LEN=12) :: FORMAT
3898 #ifdef W3_DIST
3899  CHARACTER(LEN=18) :: TFILE
3900 #endif
3901 #ifdef W3_MPRF
3902  CHARACTER(LEN=18) :: PFILE
3903 #endif
3904  CHARACTER(LEN=13) :: IDFLDS(-7:9)
3905  CHARACTER(LEN=23) :: DTME21
3906  CHARACTER(LEN=30) :: IDOTYP(8)
3907  CHARACTER(LEN=80) :: TNAME, LINE
3908  CHARACTER(LEN=1024) :: FLDOUT
3909  !
3910 
3911  !/
3912  !/ ------------------------------------------------------------------- /
3913  !/
3914 
3915  DATA idflds / 'ice param. 1 ' , 'ice param. 2 ' , &
3916  'ice param. 3 ' , 'ice param. 4 ' , &
3917  'ice param. 5 ' , &
3918  'mud density ' , 'mud thkness ' , &
3919  'mud viscos. ' , &
3920  'water levels ' , 'currents ' , &
3921  'winds ' , 'ice fields ' , &
3922  'momentum ' , 'air density ' , &
3923  'mean param. ' , '1D spectra ' , &
3924  '2D spectra ' /
3925  !
3926  DATA idotyp / 'Fields of mean wave parameters' , &
3927  'Point output ' , &
3928  'Track point output ' , &
3929  'Restart files ' , &
3930  'Nesting data ' , &
3931  'Separated wave field data ' , &
3932  'Fields for coupling ' , &
3933  'Restart files second request '/
3934  !
3935  DATA idstr / 'IC1', 'IC2', 'IC3', 'IC4', 'IC5', &
3936  'MDN', 'MTH', 'MVS', 'LEV', 'CUR', &
3937  'WND', 'ICE', 'TAU', 'RHO', 'DT0', &
3938  'DT1', 'DT2' /
3939  !
3940  DATA yesxx / 'YES/--' /
3941  DATA xxxno / '---/NO' /
3942  !
3943 #ifdef W3_MPRF
3944  CALL prinit
3945  CALL prtime ( prft0 )
3946 #endif
3947  !
3948  CALL date_and_time ( values=clkdt1 )
3949  !
3950  mpi_comm_loc = mpi_comm
3951 #ifdef W3_MPI
3952  mpi_comm_mwave = mpi_comm
3953  CALL mpi_comm_size ( mpi_comm_mwave, nmproc, ierr_mpi )
3954  CALL mpi_comm_rank ( mpi_comm_mwave, improc, ierr_mpi )
3955  improc = improc + 1
3956 #endif
3957  !
3958  IF ( PRESENT(preamb) ) fnmpre = preamb
3959  !/
3960  !/ ------------------------------------------------------------------- /
3961  ! 1. Multi-grid model intializations
3962  ! 1.a Unit numbers
3963  ! Initialize dynamic assignment, errors and test to stdout
3964  !
3965  CALL wmuini ( 6, 6 )
3966  !
3967  ! ... Identify reserved unit numbers
3968  !
3969  CALL wmuset ( 6,6, 5, .true., 'SYS', 'stdin', 'Standart input' )
3970  CALL wmuset ( 6,6, 6, .true., 'SYS', 'stdout','Standart output')
3971  !
3972 #ifdef W3_NL2
3973  CALL wmuset (6,6,103, .true., 'FIX', desc='Reserved SNL2' )
3974  CALL wmuset (6,6,104, .true., 'FIX', desc='Reserved SNL2' )
3975  CALL wmuset (6,6,105, .true., 'FIX', desc='Reserved SNL2' )
3976  CALL wmuset (6,6,106, .true., 'FIX', desc='Reserved SNL2' )
3977  CALL wmuset (6,6,107, .true., 'FIX', desc='Reserved SNL2' )
3978  CALL wmuset (6,6,108, .true., 'FIX', desc='Reserved SNL2' )
3979  CALL wmuset (6,6,109, .true., 'FIX', desc='Reserved SNL2' )
3980  CALL wmuset (6,6,110, .true., 'FIX', desc='Reserved SNL2' )
3981  CALL wmuset (6,6,111, .true., 'FIX', desc='Reserved SNL2' )
3982  CALL wmuset (6,6,112, .true., 'FIX', desc='Reserved SNL2' )
3983  CALL wmuset (6,6,113, .true., 'FIX', desc='Reserved SNL2' )
3984  CALL wmuset (6,6,114, .true., 'FIX', desc='Reserved SNL2' )
3985  CALL wmuset (6,6,117, .true., 'FIX', desc='Reserved SNL2' )
3986 #endif
3987  !
3988  ! ... Unit numbers from parameter list
3989  ! Dynamic scripture updated per file
3990  !
3991  mdsi = idsi
3992  mdso = idso
3993  mdss = idss
3994  mdst = idst
3995  mdse = idse
3996  !
3997  comstr = '$'
3998  !
3999  IF ( improc .EQ. nmperr ) THEN
4000  mdse2 = mdse
4001  ELSE
4002  mdse2 = -1
4003  END IF
4004  !
4005  ! 1.b Subroutine tracing
4006  !
4007  CALL itrace ( mdst, ntrmax )
4008  !
4009 #ifdef W3_O10
4010  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,900)
4011 #endif
4012  !
4013  ! 1.c Input file
4014  !
4015  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4016  WRITE (mdss,910) ifname, mdsi
4017  !
4018  ! process ww3_multi namelist input
4019  CALL w3nmlmultidef (mpi_comm, mdsi, trim(fnmpre)//ifname, nml_domain, ierr)
4020  ALLOCATE(nml_input_grid(nml_domain%NRINP))
4021  ALLOCATE(nml_model_grid(nml_domain%NRGRD))
4022  ALLOCATE(nml_output_type(nml_domain%NRGRD))
4023  ALLOCATE(nml_output_date(nml_domain%NRGRD))
4024  !
4025  CALL w3nmlmulticonf (mpi_comm, mdsi, trim(fnmpre)//ifname, &
4026  nml_domain, nml_input_grid, nml_model_grid, nml_output_type, &
4027  nml_output_date, nml_homog_count, nml_homog_input, ierr)
4028  IF (ierr.NE.0) THEN
4029  WRITE (*,'(2A)') 'ERROR: error occured while processing ', ifname
4030  CALL exit (ierr)
4031  END IF
4032 
4033 
4034  CALL wmuset ( mdss, mdss, mdsi, .true., 'INP', &
4035  trim(fnmpre)//ifname, 'Model control input file')
4036  !
4037  ! 1.d Log and test files
4038  !
4039  lfile = 'log.mww3'
4040  iw = 1 + int( log10( real(nmproc) + 0.5 ) )
4041  iw = max( 3 , min( 9 , iw ) )
4042  WRITE (FORMAT,'(A5,I1.1,A1,I1.1,A4)') '(A4,I',iw,'.',iw,',A5)'
4043 #ifdef W3_SHRD
4044  tfile = 'test.mww3'
4045 #endif
4046 #ifdef W3_DIST
4047  WRITE (tfile,format) 'test', improc, '.mww3'
4048 #endif
4049 #ifdef W3_MPRF
4050  WRITE (pfile,format) 'prf.', improc, '.mww3'
4051 #endif
4052  !
4053  IF ( improc .EQ. nmplog ) THEN
4054  OPEN (mdso,file=trim(fnmpre)//lfile,err=2010,iostat=ierr)
4055  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4056  WRITE (mdss,911) lfile, mdso
4057  CALL wmuset ( mdss, mdss, mdso, .true., 'OUT', &
4058  trim(fnmpre)//lfile, 'Log file')
4059  ELSE
4060  CALL wmuset ( mdss, mdss, mdso, .true., 'XXX', &
4061  'Log file on other processors')
4062  END IF
4063  !
4064  IF ( mdst.NE.mdso .AND. mdst.NE.mdss .AND. tstout ) THEN
4065  ift = len_trim(tfile)
4066  OPEN (mdst,file=trim(fnmpre)//tfile(:ift),err=2011,iostat=ierr)
4067  CALL wmuset ( mdss, mdst, mdst, .true., 'OUT', &
4068  trim(fnmpre)//tfile(:ift), 'Test output file')
4069  END IF
4070  !
4071 #ifdef W3_MPRF
4072  ift = len_trim(pfile)
4073  CALL wmuget ( mdss, mdst, mdsp, 'OUT' )
4074  CALL wmuset ( mdss, mdst, mdsp, .true., 'OUT', &
4075  trim(fnmpre)//pfile(:ift), 'Profiling file')
4076  OPEN (mdsp,file=trim(fnmpre)//pfile(:ift),err=2011,iostat=ierr)
4077 #endif
4078  !
4079  ! 1.e Initial and test output
4080  !
4081 #ifdef W3_S
4082  CALL strace (ient, 'WMINITNML')
4083 #endif
4084  !
4085  IF ( improc .EQ. nmplog ) THEN
4086  CALL wwdate ( stdate )
4087  CALL wwtime ( sttime )
4088  WRITE (mdso,901) wwver, stdate, sttime
4089  END IF
4090  !
4091 #ifdef W3_T
4092  WRITE(mdst,9000) idsi, idso, idss, idst, idse, ifname
4093 #endif
4094  !
4095  ! 2. Set-up of data structures and I/O ----------------------------- /
4096  ! 2.a Get number of grids
4097  ! Note: grid for consolidated point output always generated.
4098  ! Processor set as in W3INIT to minimize communication in WMIOPO
4099  !
4100  nrinp = nml_domain%NRINP
4101  nrgrd = nml_domain%NRGRD
4102  unipts = nml_domain%UNIPTS
4103  iostyp = nml_domain%IOSTYP
4104  upproc = nml_domain%UPPROC
4105  pshare = nml_domain%PSHARE
4106 
4107  iostyp = max( 0 , min( 3 , iostyp ) )
4108  !
4109  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4110  WRITE (mdss,920) nrgrd
4111  IF ( nrinp .EQ. 0 ) THEN
4112  WRITE (mdss,921)
4113  ELSE
4114  WRITE (mdss,922) nrinp
4115  END IF
4116  IF ( unipts ) THEN
4117  WRITE (mdss,923) yesxx
4118  ELSE
4119  WRITE (mdss,923) xxxno
4120  END IF
4121  WRITE (mdss,1923) iostyp
4122  IF ( unipts ) THEN
4123  IF ( upproc ) THEN
4124  WRITE (mdss,2923) yesxx
4125  ELSE
4126  WRITE (mdss,2923) xxxno
4127  END IF
4128  END IF
4129  IF ( iostyp.GT.1 .AND. pshare ) THEN
4130  WRITE (mdss,3923) yesxx
4131  ELSE IF ( iostyp.GT. 1 ) THEN
4132  WRITE (mdss,3923) xxxno
4133  END IF
4134  END IF
4135  !
4136  IF ( nrgrd .LT. 1 ) GOTO 2020
4137  IF ( nrinp .LT. 0 ) GOTO 2021
4138  IF ( nrinp.EQ.0 .AND. .NOT.unipts ) nrinp = -1
4139  !
4140  ! 2.b Set up data structures
4141  !
4142  CALL w3nmod ( nrgrd, mdse2, mdst, nrinp )
4143  CALL w3ndat ( mdse2, mdst )
4144  CALL w3naux ( mdse2, mdst )
4145  CALL w3nout ( mdse2, mdst )
4146  CALL w3ninp ( mdse2, mdst )
4147  CALL wmndat ( mdse2, mdst )
4148  !
4149  ! 2.c Set up I/O for individual models (initial)
4150  !
4151  ALLOCATE ( mds(15,nrgrd), ntrace(2,nrgrd), odat(40,0:nrgrd), &
4152  flgrd(nogrp,ngrpp,nrgrd), ot2(0:nrgrd), flgd(nogrp,nrgrd), &
4153  mdsf(-nrinp:nrgrd,jfirst:9), iprt(6,nrgrd), lprt(nrgrd), &
4154  flgr2(nogrp,ngrpp,nrgrd),flg2d(nogrp,ngrpp), flg1d(nogrp), &
4155  flg2(nogrp,nrgrd),outff(7,0:nrgrd))
4156  !
4157  mds = -1
4158  mdsf = -1
4159  flgr2 = .false.
4160  flg2 = .false.
4161  lprt = .false.
4162  iprt = 0
4163  !
4164  ! ... Fixed and recycleable unit numbers.
4165  !
4166  CALL wmuget ( mdse, mdst, ndsrec, 'INP' )
4167  CALL wmuset ( mdse, mdst, ndsrec, .true., 'I/O', name='...', &
4168  desc='Recyclable I/O (mod_def etc.)' )
4169  CALL wmuget ( mdse, mdst, scratch, 'SCR' )
4170  CALL wmuset ( mdse, mdst, scratch, .true., desc='Scratch file', &
4171  name=trim(fnmpre)//'ww3_multi.scratch' )
4172  !
4173  IF(mdst.EQ.ndsrec)THEN
4174  IF ( improc .EQ. nmperr ) &
4175  WRITE(mdse,'(A,I8)')'RECYCLABLE UNIT NUMBERS AND '&
4176  //'TEST OUTPUT UNIT NUMBER ARE THE SAME : ',mdst
4177  CALL extcde ( 15 )
4178  ENDIF
4179 
4180  DO i=1, nrgrd
4181  mds( 2,i) = 6
4182  mds( 3,i) = mdst
4183  mds( 4,i) = 6
4184  mds( 5,i) = ndsrec
4185  mds( 6,i) = ndsrec
4186  ntrace( 1,i) = mdst
4187  ntrace( 2,i) = ntrmax
4188  END DO
4189  !
4190 #ifdef W3_T
4191  WRITE (mdst,9020) 'INITIAL'
4192  DO i=1, nrgrd
4193  WRITE (mdst,9021) i, mds(:,i), ntrace(:,i)
4194  END DO
4195 #endif
4196  !
4197  ! 3. Get individual grid information -------------------------------- /
4198  !
4199  ! Version 3.07: For now we simply read the input data flags,
4200  ! skip the homogeneous option. Later on, we want
4201  ! to have the options to use input from common
4202  ! sources, and from communication rather than
4203  ! files.
4204  !
4205  ALLOCATE ( inames(2*nrgrd,-7:9), mnames(-nrinp:2*nrgrd), &
4206  tmprnk(2*nrgrd), tmpgrp(2*nrgrd), ningrp(2*nrgrd), &
4207  rp1(2*nrgrd), rpn(2*nrgrd), bcdtmp(nrgrd+1:2*nrgrd) )
4208  ALLOCATE ( grank(nrgrd), grgrp(nrgrd), useinp(nrinp) )
4209  ALLOCATE ( cplinp(nrinp) )
4210  grank = -1
4211  grgrp = -1
4212  useinp = .false.
4213  cplinp = .false.
4214  !
4215  ! 3.a Read data
4216  !
4217 #ifdef W3_T
4218  WRITE (mdst,9030)
4219 #endif
4220  !
4221  ! 3.a.1 Input grids
4222  !
4223  DO i=1, nrinp
4224  !
4225  CALL w3seti ( -i, mdse, mdst )
4226  inflags1 = .false.
4227  mnames(-i) = nml_input_grid(i)%NAME
4228  inflags1(-7) = nml_input_grid(i)%FORCING%ICE_PARAM1
4229  inflags1(-6) = nml_input_grid(i)%FORCING%ICE_PARAM2
4230  inflags1(-5) = nml_input_grid(i)%FORCING%ICE_PARAM3
4231  inflags1(-4) = nml_input_grid(i)%FORCING%ICE_PARAM4
4232  inflags1(-3) = nml_input_grid(i)%FORCING%ICE_PARAM5
4233  inflags1(-2) = nml_input_grid(i)%FORCING%MUD_DENSITY
4234  inflags1(-1) = nml_input_grid(i)%FORCING%MUD_THICKNESS
4235  inflags1(0) = nml_input_grid(i)%FORCING%MUD_VISCOSITY
4236  inflags1(1) = nml_input_grid(i)%FORCING%WATER_LEVELS
4237  inflags1(2) = nml_input_grid(i)%FORCING%CURRENTS
4238  inflags1(3) = nml_input_grid(i)%FORCING%WINDS
4239  inflags1(4) = nml_input_grid(i)%FORCING%ICE_CONC
4240  inflags1(5) = nml_input_grid(i)%FORCING%ATM_MOMENTUM
4241  inflags1(6) = nml_input_grid(i)%FORCING%AIR_DENSITY
4242  inflags1(7) = nml_input_grid(i)%ASSIM%MEAN
4243  inflags1(8) = nml_input_grid(i)%ASSIM%SPEC1D
4244  inflags1(9) = nml_input_grid(i)%ASSIM%SPEC2D
4245  END DO
4246  !
4247  ! 3.a.2 Unified point output grid.
4248  !
4249  IF ( unipts ) THEN
4250  !
4251  CALL w3seti ( 0, mdse, mdst )
4252  CALL w3seto ( 0, mdse, mdst )
4253  inflags1 = .false.
4254  ndst = mdst
4255  ndse = mdse
4256  !
4257  mnames(0) = nml_output_type(1)%POINT%NAME
4258  !
4259  IF ( iostyp .LE. 1 ) THEN
4260  nmpupt = max(1,nmproc-2)
4261  ELSE
4262  nmpupt = nmproc
4263  END IF
4264  !
4265  END IF
4266  !
4267  ! 3.a.3 Read wave grids
4268  !
4269  DO i=1,nrgrd
4270  mnames(nrgrd+i) = nml_model_grid(i)%NAME
4271  inames(nrgrd+i,-7) = nml_model_grid(i)%FORCING%ICE_PARAM1
4272  inames(nrgrd+i,-6) = nml_model_grid(i)%FORCING%ICE_PARAM2
4273  inames(nrgrd+i,-5) = nml_model_grid(i)%FORCING%ICE_PARAM3
4274  inames(nrgrd+i,-4) = nml_model_grid(i)%FORCING%ICE_PARAM4
4275  inames(nrgrd+i,-3) = nml_model_grid(i)%FORCING%ICE_PARAM5
4276  inames(nrgrd+i,-2) = nml_model_grid(i)%FORCING%MUD_DENSITY
4277  inames(nrgrd+i,-1) = nml_model_grid(i)%FORCING%MUD_THICKNESS
4278  inames(nrgrd+i,0) = nml_model_grid(i)%FORCING%MUD_VISCOSITY
4279  inames(nrgrd+i,1) = nml_model_grid(i)%FORCING%WATER_LEVELS
4280  inames(nrgrd+i,2) = nml_model_grid(i)%FORCING%CURRENTS
4281  inames(nrgrd+i,3) = nml_model_grid(i)%FORCING%WINDS
4282  inames(nrgrd+i,4) = nml_model_grid(i)%FORCING%ICE_CONC
4283  inames(nrgrd+i,5) = nml_model_grid(i)%FORCING%ATM_MOMENTUM
4284  inames(nrgrd+i,6) = nml_model_grid(i)%FORCING%AIR_DENSITY
4285  inames(nrgrd+i,7) = nml_model_grid(i)%ASSIM%MEAN
4286  inames(nrgrd+i,8) = nml_model_grid(i)%ASSIM%SPEC1D
4287  inames(nrgrd+i,9) = nml_model_grid(i)%ASSIM%SPEC2D
4288  tmprnk(nrgrd+i) = nml_model_grid(i)%RESOURCE%RANK_ID
4289  tmpgrp(nrgrd+i) = nml_model_grid(i)%RESOURCE%GROUP_ID
4290  rp1(nrgrd+i) = nml_model_grid(i)%RESOURCE%COMM_FRAC(1)
4291  rpn(nrgrd+i) = nml_model_grid(i)%RESOURCE%COMM_FRAC(2)
4292  bcdtmp(nrgrd+i) = nml_model_grid(i)%RESOURCE%BOUND_FLAG
4293  !
4294  rp1(nrgrd+i) = max( 0. , min( 1. , rp1(nrgrd+i) ) )
4295  rpn(nrgrd+i) = max( rp1(nrgrd+i) , min( 1. , rpn(nrgrd+i) ) )
4296  END DO
4297  !
4298  ! 3.a.4 Sort wave grids
4299  !
4300  rnktmp = minval( tmprnk(nrgrd+1:2*nrgrd) )
4301  i = 0
4302  !
4303  DO
4304  DO j=nrgrd+1, 2*nrgrd
4305  IF ( tmprnk(j) .EQ. rnktmp ) THEN
4306  i = i + 1
4307  CALL w3seti ( i, mdse, mdst )
4308  inflags1 = .false.
4309 #ifdef W3_MGW
4310  inflags1(10) = .true.
4311 #endif
4312 #ifdef W3_MGP
4313  inflags1(10) = .true.
4314 #endif
4315  inames(i,:)= inames(j,:)
4316  mnames(i) = mnames(j)
4317  tmprnk(i) = tmprnk(j)
4318  tmpgrp(i) = tmpgrp(j)
4319  rp1(i) = rp1(j)
4320  rpn(i) = rpn(j)
4321  bcdump(i) = bcdtmp(j)
4322 #ifdef W3_T
4323  WRITE (mdst,9031) i, mnames(i), inflags1, tmprnk(i), &
4324  tmpgrp(i), rp1(i), rpn(i)
4325 #endif
4326  END IF
4327  END DO
4328  IF ( i .EQ. nrgrd ) EXIT
4329  rnktmp = rnktmp + 1
4330  END DO
4331  !
4332  ! 3.a.5 Set input flags
4333  !
4334  ALLOCATE ( inpmap(nrgrd,jfirst:10), idinp(-nrinp:nrgrd,jfirst:10) )
4335  inpmap = 0
4336  idinp = '---'
4337  !
4338  DO i=1, nrgrd
4339  CALL w3seti ( i, mdse, mdst )
4340  DO j=jfirst, 9
4341  IF ( inames(i,j) .EQ. 'native' ) THEN
4342  ! *** forcing input from file & defined on the native grid ***
4343  inflags1(j) = .true.
4344  ELSE
4345  inflags1(j) = .false.
4346  IF ( inames(i,j)(1:4) .EQ. 'CPL:' ) THEN
4347  IF ( inames(i,j)(5:) .EQ. 'native' ) THEN
4348  ! *** forcing input from CPL & defined on the native grid ***
4349  inflags1(j) = .true.
4350  inpmap(i,j) = -999
4351  ELSE
4352  ! *** forcing input from CPL & defined on an input grid ***
4353  DO jj=1, nrinp
4354  IF ( mnames(-jj) .EQ. inames(i,j)(5:) ) THEN
4355  inpmap(i,j) = -jj
4356  EXIT
4357  END IF
4358  END DO
4359  IF ( inpmap(i,j) .EQ. 0 ) GOTO 2030
4360  IF ( .NOT. inputs(inpmap(i,j))%INFLAGS1(j) ) GOTO 2031
4361  useinp(-inpmap(i,j)) = .true.
4362  cplinp(-inpmap(i,j)) = .true.
4363  END IF
4364  ELSE IF ( inames(i,j) .NE. 'no' ) THEN
4365  ! *** forcing input from file & defined on an input grid ***
4366  DO jj=1, nrinp
4367  IF ( mnames(-jj) .EQ. inames(i,j) ) THEN
4368  inpmap(i,j) = jj
4369  inflags2(j) = .true.
4370  EXIT
4371  END IF
4372  END DO
4373  IF ( inpmap(i,j) .EQ. 0 ) GOTO 2030
4374  IF ( .NOT. inputs(-inpmap(i,j))%INFLAGS1(j) ) GOTO 2031
4375  useinp(inpmap(i,j)) = .true.
4376  END IF
4377  END IF
4378  ! INFLAGS2 is initial value of INFLAGS1. Unlike INFLAGS1,
4379  ! it does not change during the simulation
4380  IF(.NOT. inflags2(j)) inflags2(j)=inflags1(j)
4381  END DO ! DO J=JFIRST, 9
4382  END DO ! DO I=1, NRGRD
4383  !
4384  DO i=1, nrinp
4385  IF ( .NOT.useinp(i) .AND. &
4386  mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4387  ii = len_trim(mnames(-i))
4388  WRITE (mdse,1032) mnames(-i)(1:ii)
4389  END IF
4390  END DO
4391  !
4392  ! 3.b Assign input file unit numbers
4393  !
4394  DO i=-nrinp, nrgrd
4395  IF ( i .EQ. 0 ) cycle
4396  CALL w3seti ( i, mdse, mdst )
4397  DO j=jfirst, 9
4398  IF ( i .GE. 1 ) THEN
4399  IF ( inpmap(i,j) .LT. 0 ) cycle
4400  END IF
4401  IF ( inflags1(j) ) THEN
4402  CALL wmuget ( mdse, mdst, ndsfnd, 'INP' )
4403  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
4404  desc='Input data file' )
4405  mdsf(i,j) = ndsfnd
4406  END IF
4407  END DO
4408  END DO
4409  !
4410 #ifdef W3_T
4411  WRITE (mdst,9022)
4412  DO i=-nrinp, nrgrd
4413  IF ( i .EQ. 0 ) cycle
4414  WRITE (mdst,9021) i, mdsf(i,jfirst:9)
4415  END DO
4416 #endif
4417  !
4418  ! 3.c Set rank and group data
4419  !
4420 #ifdef W3_T
4421  WRITE (mdst,9032)
4422 #endif
4423  !
4424  rnkmax = maxval( tmprnk(1:nrgrd) ) + 1
4425  rnktmp = 0
4426  !
4427  DO
4428  rnkmin = minval( tmprnk(1:nrgrd) )
4429  IF ( rnkmin .EQ. rnkmax ) EXIT
4430  rnktmp = rnktmp + 1
4431  DO i=1, nrgrd
4432  IF ( tmprnk(i) .EQ. rnkmin ) THEN
4433  grank(i) = rnktmp
4434  tmprnk(i) = rnkmax
4435  END IF
4436  END DO
4437  END DO
4438  !
4439 #ifdef W3_T
4440  DO i=1, nrgrd
4441  WRITE (mdst,9033) i, mnames(i), grank(i)
4442  END DO
4443 #endif
4444  !
4445  rnkmax = rnktmp
4446  grpmax = maxval( tmpgrp(1:nrgrd) ) + 1
4447  nrgrp = 0
4448  ningrp = 0
4449  !
4450  DO rnktmp=1, rnkmax
4451  DO
4452  grpmin = grpmax
4453  DO i=1, nrgrd
4454  IF ( grank(i) .EQ. rnktmp ) &
4455  grpmin = min( grpmin , tmpgrp(i) )
4456  END DO
4457  IF ( grpmin .EQ. grpmax ) EXIT
4458  nrgrp = nrgrp + 1
4459  DO i=1, nrgrd
4460  IF ( grank(i).EQ.rnktmp .AND. grpmin.EQ.tmpgrp(i) ) THEN
4461  grgrp(i) = nrgrp
4462  tmpgrp(i) = grpmax
4463  ningrp(nrgrp) = ningrp(nrgrp) + 1
4464  END IF
4465  END DO
4466  END DO
4467  END DO
4468  !
4469 #ifdef W3_T
4470  WRITE (mdst,9034) nrgrp
4471  DO i=1, nrgrd
4472  WRITE (mdst,9033) i, mnames(i), grgrp(i)
4473  END DO
4474  WRITE (mdst,9035) ningrp(1:nrgrp)
4475 #endif
4476  !
4477  ALLOCATE ( action(jfirst:11) )
4478  ALLOCATE ( ingrp(nrgrp,0:maxval(ningrp(:nrgrp))) )
4479  DEALLOCATE ( tmprnk, tmpgrp, ningrp, bcdtmp )
4480  ingrp = 0
4481  !
4482  DO i=1, nrgrd
4483  ingrp(grgrp(i),0) = ingrp(grgrp(i),0) + 1
4484  ingrp(grgrp(i),ingrp(grgrp(i),0)) = i
4485  END DO
4486  !
4487 #ifdef W3_T
4488  WRITE (mdst,9036)
4489  DO j=1, nrgrp
4490  WRITE (mdst,9037) j, ingrp(j,:ingrp(j,0))
4491  END DO
4492 #endif
4493  !
4494  !
4495  ! 3.d Unified point output
4496  !
4497 #ifdef W3_MPRF
4498  CALL prtime ( prftn )
4499  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8.b'
4500  prft0 = prftn
4501 #endif
4502  !
4503  IF ( unipts ) THEN
4504  !
4505  j = len_trim(mnames(0))
4506  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4507  WRITE (mdss,986) mnames(0)(1:j)
4508  WRITE (mdss,987)
4509  END IF
4510  !
4511  CALL w3iogr ( 'GRID', ndsrec, 0, mnames(0)(1:j) )
4512  !
4513  END IF
4514  !
4515  ! 3.e Output
4516  !
4517  IF ( nrinp .GT. 0 ) THEN
4518  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,924)
4519  IF ( nmplog .EQ. improc ) WRITE (mdso,924)
4520  DO i=1, nrinp
4521  IF ( .NOT. useinp(i) ) cycle
4522  CALL w3seti ( -i, mdse, mdst )
4523  action(1:6) = '--- '
4524  DO j=jfirst, 6
4525  IF ( inflags1(j) ) action(j) = ' X '
4526  END DO
4527  action(7:9) = '- '
4528  IF ( inflags1(7) ) action(7) = '1 '
4529  IF ( inflags1(8) ) action(8) = '2 '
4530  IF ( inflags1(9) ) action(9) = '3 '
4531  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4532  WRITE (mdss,925) i, mnames(-i), action(jfirst:9)
4533  IF ( nmplog .EQ. improc ) &
4534  WRITE (mdso,925) i, mnames(-i), action(jfirst:9)
4535  END DO
4536  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,926)
4537  IF ( nmplog .EQ. improc ) WRITE (mdso,926)
4538  END IF
4539  !
4540  IF ( unipts ) THEN
4541  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,927)
4542  IF ( nmplog .EQ. improc ) WRITE (mdso,927)
4543  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4544  WRITE (mdss,928) mnames(0)
4545  IF ( nmplog .EQ. improc ) &
4546  WRITE (mdso,928) mnames(0)
4547  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,929)
4548  IF ( nmplog .EQ. improc ) WRITE (mdso,929)
4549  END IF
4550  !
4551  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,930)
4552  IF ( nmplog .EQ. improc ) WRITE (mdso,930)
4553  DO i=1, nrgrd
4554  CALL w3seti ( i, mdse, mdst )
4555  action(1:6) = '--- '
4556  DO j=jfirst, 6
4557  IF ( inflags1(j) .AND. inpmap(i,j) .EQ. 0 ) THEN
4558  action(j) = 'native'
4559  ELSE IF ( inflags1(j) .AND. inpmap(i,j) .EQ. -999 ) THEN
4560  action(j) = 'native'
4561  ELSE IF ( inpmap(i,j) .GT. 0 ) THEN
4562  action(j) = mnames(-inpmap(i,j))
4563  ELSE IF ( inpmap(i,j) .LT. 0 ) THEN
4564  action(j) = mnames( inpmap(i,j))
4565  END IF
4566  END DO
4567  action(7:11) = '- '
4568  IF ( inflags1(7) ) action(7) = '1 '
4569  IF ( inflags1(8) ) action(8) = '2 '
4570  IF ( inflags1(9) ) action(9) = '3 '
4571  IF ( inflags1(10) ) THEN
4572  action(10) = 'yes '
4573  ELSE
4574  action(10) = 'no '
4575  END IF
4576  IF ( bcdump(i) ) action(11) = 'y '
4577  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4578  WRITE (mdss,931) i, mnames(i), action(1:10), grank(i), &
4579  grgrp(i), action(11)
4580  IF ( nmplog .EQ. improc ) &
4581  WRITE (mdso,931) i, mnames(i), action(1:10), grank(i), &
4582  grgrp(i), action(11)
4583  END DO
4584  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,932)
4585  IF ( nmplog .EQ. improc ) WRITE (mdso,932)
4586  !
4587  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4588  WRITE (mdss,933) 'Group information'
4589  IF ( nmplog .EQ. improc ) &
4590  WRITE (mdso,933) 'Group information'
4591  DO j=1, nrgrp
4592  WRITE (line(1:6),'(1X,I3,2X)') j
4593  jjj = 6
4594  DO jj=1, ingrp(j,0)
4595  IF ( jjj .GT. 60 ) THEN
4596  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4597  WRITE (mdss,934) line(1:jjj)
4598  IF ( nmplog .EQ. improc ) WRITE (mdso,934) line(1:jjj)
4599  line(1:6) = ' '
4600  jjj = 6
4601  END IF
4602  WRITE (line(jjj+1:jjj+3),'(I3)') ingrp(j,jj)
4603  !
4604  line(jjj+4:jjj+5) = ' ('
4605  WRITE (line(jjj+6:jjj+11),'(F6.4)') rp1(ingrp(j,jj))
4606  line(jjj+12:jjj+12) = '-'
4607  WRITE (line(jjj+13:jjj+18),'(F6.4)') rpn(ingrp(j,jj))
4608  line(jjj+19:jjj+19) = ')'
4609  jjj = jjj + 19
4610  !
4611  END DO
4612  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4613  WRITE (mdss,934) line(1:jjj)
4614  IF ( nmplog .EQ. improc ) WRITE (mdso,934) line(1:jjj)
4615  END DO
4616  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,935)
4617  IF ( nmplog .EQ. improc ) WRITE (mdso,935)
4618  !
4619  ! 4. Model run time information etc. -------------------------------- /
4620  !
4621  ! Version 3.07: Same for all grids, diversify later ....
4622  ! If invoked as ESMF Component, then STIME and ETIME are set
4623  ! in WMESMFMD from the external clock.
4624  !
4625  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,940)
4626  !
4627  IF (is_esmf_component) THEN
4628  READ(nml_domain%START, *) stmpt
4629  READ(nml_domain%STOP, *) etmpt
4630  ELSE
4631  READ(nml_domain%START, *) stime
4632  READ(nml_domain%STOP, *) etime
4633  END IF
4634  CALL stme21 ( stime , dtme21 )
4635  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,941) dtme21
4636  CALL stme21 ( etime , dtme21 )
4637  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,942) dtme21
4638  !
4639  DO i=1, nrgrd
4640  CALL w3setw ( i, mdse, mdst )
4641  time = stime
4642  END DO
4643  !
4644  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,943)
4645  !
4646  flghg1 = nml_domain%FLGHG1
4647  flghg2 = nml_domain%FLGHG2
4648  flghg2 = flghg1 .AND. flghg2
4649  !
4650  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4651  IF ( flghg1 ) THEN
4652  WRITE (mdss,944) yesxx
4653  ELSE
4654  WRITE (mdss,944) xxxno
4655  END IF
4656  IF ( flghg2 ) THEN
4657  WRITE (mdss,945) yesxx
4658  ELSE
4659  WRITE (mdss,945) xxxno
4660  END IF
4661  END IF
4662  !
4663  ! 5. Output requests ------------------------------------------------ /
4664  !
4665  ot2(:)%NPTS = 0
4666  iloop = 0
4667  !
4668  ! 5.a Loop over types
4669  !
4670  DO i=1, nrgrd
4671  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,950) trim(mnames(nrgrd+i))
4672  notype = 8
4673  ! OTYPE 1
4674  READ(nml_output_date(i)%FIELD%START, *) odat(1,i), odat(2,i)
4675  READ(nml_output_date(i)%FIELD%STRIDE, *) odat(3,i)
4676  READ(nml_output_date(i)%FIELD%STOP, *) odat(4,i), odat(5,i)
4677  READ(nml_output_date(i)%FIELD%OUTFFILE, *) outff(1,i)
4678  ! OTYPE 2
4679  READ(nml_output_date(i)%POINT%START, *) odat(6,i), odat(7,i)
4680  READ(nml_output_date(i)%POINT%STRIDE, *) odat(8,i)
4681  READ(nml_output_date(i)%POINT%STOP, *) odat(9,i), odat(10,i)
4682  READ(nml_output_date(i)%POINT%OUTFFILE, *) outff(2,i)
4683  ! OTYPE 3
4684  READ(nml_output_date(i)%TRACK%START, *) odat(11,i), odat(12,i)
4685  READ(nml_output_date(i)%TRACK%STRIDE, *) odat(13,i)
4686  READ(nml_output_date(i)%TRACK%STOP, *) odat(14,i), odat(15,i)
4687  ! OTYPE 4
4688  READ(nml_output_date(i)%RESTART%START, *) odat(16,i), odat(17,i)
4689  READ(nml_output_date(i)%RESTART%STRIDE, *) odat(18,i)
4690  READ(nml_output_date(i)%RESTART%STOP, *) odat(19,i), odat(20,i)
4691  !OTYPE 5
4692  READ(nml_output_date(i)%BOUNDARY%START, *) odat(21,i), odat(22,i)
4693  READ(nml_output_date(i)%BOUNDARY%STRIDE, *) odat(23,i)
4694  READ(nml_output_date(i)%BOUNDARY%STOP, *) odat(24,i), odat(25,i)
4695  !OTYPE 6
4696  READ(nml_output_date(i)%PARTITION%START, *) odat(26,i), odat(27,i)
4697  READ(nml_output_date(i)%PARTITION%STRIDE, *) odat(28,i)
4698  READ(nml_output_date(i)%PARTITION%STOP, *) odat(29,i), odat(30,i)
4699  !OTYPE 7
4700  ! for coupling but not implemented yet
4701  !OTYPE 8
4702  READ(nml_output_date(i)%RESTART2%START, *) odat(36,i), odat(37,i)
4703  READ(nml_output_date(i)%RESTART2%STRIDE, *) odat(38,i)
4704  READ(nml_output_date(i)%RESTART2%STOP, *) odat(39,i), odat(40,i)
4705 
4706  ! set the time stride at 0 or more
4707  odat(3,i) = max( 0 , odat(3,i) )
4708  odat(8,i) = max( 0 , odat(8,i) )
4709  odat(13,i) = max( 0 , odat(13,i) )
4710  odat(18,i) = max( 0 , odat(18,i) )
4711  odat(23,i) = max( 0 , odat(23,i) )
4712  odat(28,i) = max( 0 , odat(28,i) )
4713  odat(38,i) = max( 0 , odat(38,i) )
4714 
4715  ! define the time of the output point grid (index 0) as the &
4716  ! time of the first grid which should be the larger one by convention
4717  odat(6:10,0) = odat(6:10,1)
4718 
4719  ! allocate pointers to minimum value if no output point
4720  IF ( odat(8,i) .EQ. 0 ) THEN
4721  ALLOCATE ( ot2(i)%X(1), ot2(i)%Y(1), ot2(i)%PNAMES(1) )
4722  END IF
4723 
4724 
4725  DO j=1, notype
4726  !
4727  ! 5.b Process standard line
4728  !
4729  outpts(i)%OFILES(j)=outff(j,i)
4730  IF ( odat(5*(j-1)+3,i) .NE. 0 ) THEN
4731  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4732  WRITE (mdss,951) j, idotyp(j)
4733  ttime(1) = odat(5*(j-1)+1,i)
4734  ttime(2) = odat(5*(j-1)+2,i)
4735  CALL stme21 ( ttime , dtme21 )
4736  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4737  WRITE (mdss,952) dtme21
4738  ttime(1) = odat(5*(j-1)+4,i)
4739  ttime(2) = odat(5*(j-1)+5,i)
4740  CALL stme21 ( ttime , dtme21 )
4741  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4742  WRITE (mdss,953) dtme21
4743  ttime(1) = 0
4744  ttime(2) = 0
4745  dttst = real( odat(5*(j-1)+3,i) )
4746  CALL tick21 ( ttime , dttst )
4747  CALL stme21 ( ttime , dtme21 )
4748  IF ( ( odat(5*(j-1)+1,i) .NE. odat(5*(j-1)+4,i) .OR. &
4749  odat(5*(j-1)+2,i) .NE. odat(5*(j-1)+5,i) ) .AND. &
4750  mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4751  DO ii=1, 18
4752  IF ( dtme21(ii:ii).NE.'0' .AND. &
4753  dtme21(ii:ii).NE.'/' .AND. &
4754  dtme21(ii:ii).NE.' ' .AND. &
4755  dtme21(ii:ii).NE.':' ) EXIT
4756  dtme21(ii:ii) = ' '
4757  END DO
4758  WRITE (mdss,954) dtme21(1:19)
4759  END IF
4760  !
4761  IF ( j .EQ. 1 ) THEN
4762  !
4763  ! 5.c Type 1: fields of mean wave parameters
4764  !
4765  flgrd(:,:,i)=.false. ! Initialize FLGRD
4766  fldout = nml_output_type(i)%FIELD%LIST
4767  CALL w3flgrdflag ( mdss, mdso, mdse2, fldout, flg1d, &
4768  flg2d, improc, nmpscr, ierr )
4769  flgrd(:,:,i)=flg2d
4770  flgd(:,i) =flg1d
4771  !
4772  ELSE IF ( j .EQ. 2 ) THEN
4773  !
4774  ! 5.d Type 2: point output
4775  !
4776  ! if the output is 0, the output is disabled
4777  IF (unipts) THEN
4778  IF ( odat(8,0).EQ.0 .AND. improc.EQ.nmperr ) WRITE (mdse,1050)
4779  IF ( odat(8,0).EQ.0 ) unipts = .false.
4780  END IF
4781 
4782  ! if the point file is not set
4783  IF ( trim(nml_output_type(i)%POINT%FILE).EQ.'unset' ) THEN
4784  ! and if output also disabled, cycle to the next output type J
4785  IF ( odat(8,i).EQ.0 ) THEN
4786  ALLOCATE ( ot2(i)%X(1), ot2(i)%Y(1), ot2(i)%PNAMES(1) )
4787  cycle
4788  ! and if output still enabled, stop
4789  ELSE
4790  GOTO 2055
4791  END IF
4792  END IF
4793 
4794  ! if the unified point is already defined, cycle to the next output type J
4795  IF ( unipts .AND. iloop.NE.0 ) cycle
4796  !
4797  IF ( unipts .AND. i.GE.2 ) THEN
4798  DO k=1,i-1
4799  IF ( nml_output_type(k)%POINT%FILE.NE.nml_output_type(i)%POINT%FILE ) GOTO 2053
4800  END DO
4801  END IF
4802  OPEN (mdsi, file=trim(fnmpre)//trim(nml_output_type(i)%POINT%FILE), &
4803  form='FORMATTED', status='OLD', err=2104, iostat=ierr)
4804 
4805  ! first loop to count the number of points
4806  ! second loop to allocate the array and store the points
4807  ot2(i)%NPTS = 0
4808  DO iloop=1,2
4809  rewind(mdsi)
4810  !
4811  IF ( iloop.EQ.2) THEN
4812  IF ( ot2(i)%NPTS.GT.0 ) THEN
4813  ALLOCATE ( ot2(i)%X(ot2(i)%NPTS), &
4814  ot2(i)%Y(ot2(i)%NPTS), &
4815  ot2(i)%PNAMES(ot2(i)%NPTS) )
4816  ot2(i)%NPTS = 0 ! reset it to use it as a counter for loop 2
4817  ELSE
4818  ALLOCATE ( ot2(i)%X(1), ot2(i)%Y(1), ot2(i)%PNAMES(1) )
4819  GOTO 2054
4820  END IF
4821  END IF
4822  !
4823  DO
4824  READ (mdsi,*,err=2004,iostat=ierr) tmpline
4825  ! if end of file or stopstring, then exit
4826  IF ( ierr.NE.0 .OR. index(tmpline,"STOPSTRING").NE.0 ) EXIT
4827  ! leading blanks removed and placed on the right
4828  test = adjustl( tmpline )
4829  IF ( test(1:1).EQ.comstr .OR. len_trim(test).EQ.0 ) THEN
4830  ! if comment or blank line, then skip
4831  cycle
4832  ELSE
4833  ! otherwise, backup to beginning of line
4834  backspace( mdsi, err=2004, iostat=ierr)
4835  READ (mdsi,*,err=2004,iostat=ierr) xx, yy, pn
4836  ENDIF
4837  ot2(i)%NPTS = ot2(i)%NPTS + 1
4838  IF ( iloop .EQ. 1 ) cycle
4839  IF ( iloop .EQ. 2 ) THEN
4840  ot2(i)%X(ot2(i)%NPTS) = xx
4841  ot2(i)%Y(ot2(i)%NPTS) = yy
4842  ot2(i)%PNAMES(ot2(i)%NPTS) = pn
4843  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4844  IF ( ot2(i)%NPTS .EQ. 1 ) THEN
4845  WRITE (mdss,957) xx, yy, pn
4846  ELSE
4847  WRITE (mdss,958) ot2(i)%NPTS, xx, yy, pn
4848  END IF
4849  END IF
4850  END IF ! ILOOP.EQ.2
4851  END DO ! end of file
4852  END DO ! ILOOP
4853  CLOSE(mdsi)
4854  !
4855  IF ( unipts .AND. ot2(0)%NPTS.EQ.0 .AND. ot2(i)%NPTS.GT.0 ) THEN
4856  ! copy points to point grid number 0
4857  ot2(0)%NPTS = ot2(i)%NPTS
4858  ALLOCATE (ot2(0)%X(ot2(0)%NPTS), ot2(0)%Y(ot2(0)%NPTS), ot2(0)%PNAMES(ot2(0)%NPTS))
4859  ot2(0)%X(:) = ot2(i)%X(:)
4860  ot2(0)%Y(:) = ot2(i)%Y(:)
4861  ot2(0)%PNAMES(:) = ot2(i)%PNAMES(:)
4862  ! define all the other grids to empty output point
4863  DO k=1, nrgrd
4864  ot2(k)%NPTS = 0
4865  ALLOCATE (ot2(k)%X(1),ot2(k)%Y(1),ot2(k)%PNAMES(1))
4866  END DO
4867  END IF
4868  !
4869  ELSE IF ( j .EQ. 3 ) THEN
4870  !
4871  ! 5.e Type 3: track output
4872  !
4873  tflagi = nml_output_type(i)%TRACK%FORMAT
4874  IF ( tflagi ) THEN
4875  mds(11,i) = abs(mds(11,i))
4876  ELSE
4877  mds(11,i) = -abs(mds(11,i))
4878  END IF
4879  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4880  IF ( .NOT. tflagi ) THEN
4881  WRITE (mdss,960) 'input', 'UNFORMATTED'
4882  ELSE
4883  WRITE (mdss,960) 'input', 'FORMATTED'
4884  END IF
4885  END IF
4886  !
4887  ELSE IF ( j .EQ. 4 ) THEN
4888  !
4889  ! 5.f Type 4: restart files (no additional data)
4890  !
4891  ELSE IF ( j .EQ. 5 ) THEN
4892  !
4893  ! 5.g Type 5: nesting data (no additional data)
4894  !
4895  ELSE IF ( j .EQ. 6 ) THEN
4896  !
4897  ! 5.h Type 6: partitioned wave field data
4898  !
4899  iprt(1,i) = nml_output_type(i)%PARTITION%X0
4900  iprt(2,i) = nml_output_type(i)%PARTITION%XN
4901  iprt(3,i) = nml_output_type(i)%PARTITION%NX
4902  iprt(4,i) = nml_output_type(i)%PARTITION%Y0
4903  iprt(5,i) = nml_output_type(i)%PARTITION%YN
4904  iprt(6,i) = nml_output_type(i)%PARTITION%NY
4905  lprt(i) = nml_output_type(i)%PARTITION%FORMAT
4906  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4907  WRITE (mdss,961) iprt(:,i)
4908  IF ( .NOT. lprt(i) ) THEN
4909  WRITE (mdss,960) 'output', 'UNFORMATTED'
4910  ELSE
4911  WRITE (mdss,960) 'output', 'FORMATTED'
4912  END IF
4913  END IF
4914  !
4915  ! ... End of output type selecttion ELSE IF
4916  !
4917  ELSE IF ( j .EQ. 8 ) THEN
4918  !
4919  ! 5.i Type 8: checkpoint files (no additional data)
4920  !
4921  END IF
4922  !
4923  ! ... End of IF in 5.b
4924  !
4925  END IF
4926  !
4927  ! ... End of loop J on NOTYPE in 5.a
4928  !
4929  END DO
4930  !
4931  ! ... End of loop I on NRGRD in 5.a
4932  !
4933  END DO
4934  !
4935 #ifdef W3_T
4936  DO i=1, nrgrd
4937  WRITE (mdst,9050) i
4938  WRITE (mdst,9053) odat(:,i)
4939  WRITE (mdst,9052) flgrd(:,:,i)
4940  END DO
4941 #endif
4942  !
4943  ! 6. Read moving grid data ------------------------------------------ /
4944  !
4945  ! Only a single set of data are provided to be applied to all
4946  ! the grids, because this is only intended for test cases.
4947  ! For true implementations, the jumping grid will be used.
4948  !
4949  IF ( inflags1(10) ) THEN
4950  !
4951  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
4952  WRITE (mdss,965)
4953  WRITE (mdss,966) 'Continuous grid movement data'
4954  END IF
4955  !
4956  n_mov = nml_homog_count%N_MOV
4957  n_tot = nml_homog_count%N_TOT
4958 
4959  IF ( n_mov .EQ. 0 ) GOTO 2060
4960  IF ( n_mov .GT. 99 ) GOTO 2061
4961 
4962  ALLOCATE ( tmove(2,n_mov), amove(n_mov), dmove(n_mov) )
4963  !
4964  DO i=1,n_tot
4965  READ(nml_homog_input(i)%NAME,*) idtst
4966  SELECT CASE (idtst)
4967  CASE ('MOV')
4968  READ(nml_homog_input(i)%DATE,*) tmove(:,i)
4969  amove(i) = nml_homog_input(i)%VALUE1
4970  dmove(i) = nml_homog_input(i)%VALUE2
4971  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
4972  WRITE (mdss,968) i, tmove(:,i), amove(i), dmove(i)
4973  CASE DEFAULT
4974  GOTO 2062
4975  END SELECT
4976  END DO
4977  !
4978  nmvmax = n_mov
4979  DO i=1, nrgrd
4980  CALL w3setg ( i, mdse, mdst )
4981  CALL wmsetm ( i, mdse, mdst )
4982  nmv = n_mov
4983  CALL wmdimd ( i, mdse, mdst, 0 )
4984  DO ii=1, nmv
4985  tmv(:,4,ii) = tmove(:,ii)
4986  amv(ii,4) = amove(ii)
4987  dmv(ii,4) = dmove(ii)
4988  END DO
4989  END DO
4990  !
4991  END IF
4992  !
4993  ! 7. Work load distribution ----------------------------------------- /
4994  ! 7.a Initialize arrays
4995  !
4996  ! *******************************************************
4997  ! *** NOTE : OUTPUT PROCESSOR ASSIGNMENT NEEDS TO BE ***
4998  ! *** CONSISTENT WITH ASSIGNMENT IN W3INIT. ***
4999  ! *******************************************************
5000  !
5001  ALLOCATE ( allprc(nmproc,nrgrd) , modmap(nmproc,nrgrp) , &
5002  loadmp(nmproc,nrgrp) )
5003  !
5004  allprc = 0
5005  modmap = 0
5006  loadmp = 0
5007  !
5008  ! 7.b Determine number of output processors
5009  !
5010  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,970)
5011  !
5012  ncproc = nmproc
5013  upproc = upproc .AND. unipts .AND. iostyp.GT.1
5014  !
5015  ! 7.b.1 Unified point output
5016  !
5017  IF ( unipts ) THEN
5018  IF ( nmproc.GE.10 .AND. upproc ) THEN
5019  ncproc = nmproc - 1
5020  ELSE
5021  IF ( upproc .AND. mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
5022  WRITE (mdss,971) 'Separate process for point' // &
5023  ' output disabled.'
5024  upproc = .false.
5025  END IF
5026  IF ( nmpupt .EQ. improc ) THEN
5027  ii = len_trim(mnames(0))
5028  CALL wmuget ( mdss, mdst, mdsup, 'OUT' )
5029  CALL wmuset ( mdss, mdst, mdsup, .true., 'OUT', &
5030  trim(fnmpre)//'out_pnt.'//mnames(0)(1:ii), &
5031  'Unified point output')
5032 #ifdef W3_ASCII
5033  CALL wmuget ( mdss, mdst, mdsupa, 'OUA' )
5034  CALL wmuset ( mdss, mdst, mdsupa, .true., 'OUA', &
5035  trim(fnmpre)//'out_pnt.'//mnames(0)(1:ii)//'.txt', &
5036  'Unified point output ascii')
5037 #endif
5038  END IF
5039  END IF
5040  !
5041  IF ( upproc .AND. mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
5042  WRITE (mdss,972) nmpupt
5043  !
5044  ! 7.b.2 Other output
5045  !
5046  ALLOCATE ( ndpout(nrgrd) )
5047  ndpout = 0
5048  !
5049  IF ( iostyp .GT. 1 ) THEN
5050  DO i=1, nrgrd
5051  ! FIELD
5052  IF ( odat( 3,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
5053  ! TRACK
5054  IF ( odat(13,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
5055  ! PARTITION
5056  IF ( odat(28,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
5057  ! POINT .OR. RESTART .OR. BOUNDARY
5058  IF ( odat( 8,i) .GT. 0 .OR. odat(18,i) .GT. 0 .OR. &
5059  odat(23,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
5060  ! RESTART2
5061  IF ( odat(38,i) .GT. 0 ) ndpout(i) = ndpout(i) + 1
5062  IF ( iostyp .EQ. 2 ) ndpout(i) = min( 1 , ndpout(i) )
5063  END DO
5064  END IF
5065  !
5066  ! ..... Reduce IOSTYP if not enough resources to run IOSTYP = 3
5067  !
5068  IF ( iostyp.EQ.3 .AND. &
5069  ( ( .NOT.pshare .AND. 4*sum(ndpout).GT.ncproc ) &
5070  .OR.( pshare .AND. 4*maxval(ndpout).GT.ncproc ) ) ) THEN
5071  DO i=1, nrgrd
5072  ndpout(i) = min( 1 , ndpout(i) )
5073  END DO
5074  iostyp = 2
5075  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
5076  WRITE (mdss,971) 'Separate processes for output' // &
5077  ' types disabled.'
5078  END IF
5079  !
5080  ! ..... Force sharing of output processes if not enough resources
5081  !
5082  IF ( iostyp.GT.1 .AND. .NOT.pshare .AND. &
5083  4*sum(ndpout).GT.ncproc ) THEN
5084  pshare = .true.
5085  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
5086  WRITE (mdss,971) 'Grids sharing output processes.'
5087  END IF
5088  !
5089  ! ..... Disable output processes if not enough resources
5090  !
5091  IF ( iostyp.GT.1 .AND. 4*maxval(ndpout).GT.ncproc ) THEN
5092  ndpout = 0
5093  iostyp = 1
5094  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
5095  WRITE (mdss,971) 'Separate processes for output' // &
5096  ' disabled.'
5097  END IF
5098  !
5099  ! ..... Number of output processes (except for unified point output)
5100  !
5101  npoutt = 0
5102  IF ( iostyp .GT. 1 ) THEN
5103  IF ( pshare ) THEN
5104  npoutt = maxval(ndpout)
5105  ELSE
5106  npoutt = sum(ndpout)
5107  END IF
5108  END IF
5109  ncproc = ncproc - npoutt
5110  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
5111  IF ( npoutt .EQ. 0 ) THEN
5112  WRITE (mdss,971) 'No (other) dedicated output processes.'
5113  ELSE
5114  WRITE (mdss,973) ncproc+1, ncproc+npoutt, npoutt
5115  END IF
5116  END IF
5117  !
5118  ! 7.c Set communicators and ALLPRC array
5119  !
5120 #ifdef W3_T
5121  WRITE (mdst,9070)
5122 #endif
5123  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,974)
5124  IF ( nmplog.EQ.improc ) WRITE (mdso,1974)
5125  !
5126 #ifdef W3_MPI
5127  CALL mpi_comm_group ( mpi_comm_mwave, bgroup, ierr_mpi )
5128 #endif
5129  ALLOCATE ( tmprnk(nmproc) )
5130  napres = ncproc
5131  !
5132  DO i=1, nrgrd
5133  !
5134  ip1 = max( 1 , min( ncproc , 1+nint(real(ncproc)*rp1(i)) ) )
5135  ipn = max( ip1 , min( ncproc , nint(real(ncproc)*rpn(i)) ) )
5136  outstr = '-----'
5137  !
5138  CALL wmsetm ( i, mdse, mdst )
5139  naploc = 1 + ipn - ip1
5140  napadd = naploc
5141 #ifdef W3_MPI
5142  croot = ip1
5143  fbcast = naploc .NE. ncproc
5144  fbcast = naploc .NE. ncproc .OR. &
5145  ( iostyp.GT.1 .AND. .NOT.pshare )
5146 #endif
5147  DO j=ip1, ipn
5148  tmprnk(1+j-ip1) = j - 1
5149  END DO
5150  !
5151  IF ( iostyp .GT. 1 ) THEN
5152  IF ( pshare ) napres = ncproc
5153  DO j=1, ndpout(i)
5154  napadd = napadd + 1
5155  tmprnk(napadd) = napres
5156  napres = napres + 1
5157  END DO
5158  END IF
5159  !
5160  IF ( upproc ) THEN
5161  napadd = napadd + 1
5162  tmprnk(napadd) = nmproc - 1
5163  END IF
5164  !
5165 #ifdef W3_MPI
5166  CALL mpi_group_incl ( bgroup, napadd, tmprnk, lgroup, &
5167  ierr_mpi )
5168  CALL mpi_comm_create ( mpi_comm_mwave, lgroup, &
5169  mpi_comm_grd, ierr_mpi )
5170  CALL mpi_group_free ( lgroup, ierr_mpi )
5171 #endif
5172  !
5173  DO ii=ip1, ipn
5174  allprc(ii,i) = 1 + ii - ip1
5175  END DO
5176  ii = ii - ip1
5177  !
5178  IF ( pshare .OR. i.EQ.1 ) THEN
5179  napadd = ncproc
5180  ELSE
5181  napadd = ncproc + sum(ndpout(1:i-1))
5182  END IF
5183  IF ( iostyp .GT. 1 ) THEN
5184  DO j=1, ndpout(i)
5185  napadd = napadd + 1
5186  ii = ii + 1
5187  allprc(napadd,i) = ii
5188  END DO
5189  END IF
5190  !
5191  IF ( upproc ) THEN
5192  ii = ii + 1
5193  allprc(nmproc,i) = ii
5194  END IF
5195  !
5196 #ifdef W3_T
5197  WRITE (mdst,9071) i, allprc(:,i)
5198 #endif
5199  !
5200  ! ... output
5201  !
5202  !
5203  IF ( iostyp .LE. 1 ) THEN
5204  !
5205  IF ( odat( 3,i) .GT. 0 ) THEN
5206  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-1))+1
5207  outstr(1) = stout
5208  END IF
5209  IF ( odat( 8,i) .GT. 0 .OR. unipts ) THEN
5210  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-2))+1
5211  outstr(2) = stout
5212  END IF
5213  IF ( odat(13,i) .GT. 0 ) THEN
5214  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-5))+1
5215  outstr(3) = stout
5216  END IF
5217  IF ( odat(18,i) .GT. 0 ) THEN
5218  WRITE (stout,'(I5.5)') tmprnk(naploc)+1
5219  outstr(4) = stout
5220  END IF
5221  IF ( odat(23,i) .GT. 0 ) THEN
5222  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-3))+1
5223  outstr(5) = stout
5224  END IF
5225  IF ( odat(28,i) .GT. 0 ) THEN
5226  WRITE (stout,'(I5.5)') tmprnk(max(1,naploc-4))+1
5227  outstr(6) = stout
5228  END IF
5229  !
5230  ELSE
5231  !
5232  ! set last proc for point and disable point for the grid
5233  IF ( unipts ) THEN
5234  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
5235  outstr(2) = stout
5236  odat(8,i) = 0
5237  IF ( upproc ) ii = ii - 1
5238  END IF
5239  !
5240  IF ( iostyp .EQ. 2 ) THEN
5241  !
5242  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
5243  IF ( odat( 3,i) .GT. 0 ) outstr(1) = stout
5244  IF ( odat( 8,i) .GT. 0 .OR. &
5245  ( unipts .AND. .NOT.upproc ) ) &
5246  outstr(2) = stout
5247  IF ( odat(13,i) .GT. 0 ) outstr(3) = stout
5248  IF ( odat(18,i) .GT. 0 ) outstr(4) = stout
5249  IF ( odat(23,i) .GT. 0 ) outstr(5) = stout
5250  IF ( odat(28,i) .GT. 0 ) outstr(6) = stout
5251  !
5252  ELSE IF ( iostyp .EQ. 3 ) THEN
5253  !
5254  IF ( odat( 3,i).GT.0 ) THEN
5255  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
5256  outstr(1) = stout
5257  ii = ii - 1
5258  END IF
5259  IF ( odat(13,i).GT.0 ) THEN
5260  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
5261  outstr(3) = stout
5262  ii = ii - 1
5263  END IF
5264  IF ( odat(28,i).GT.0 ) THEN
5265  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
5266  outstr(6) = stout
5267  ii = ii - 1
5268  END IF
5269  WRITE (stout,'(I5.5)') tmprnk(ii) + 1
5270  IF ( odat( 8,i) .GT. 0 ) outstr(2) = stout
5271  IF ( odat(18,i) .GT. 0 ) outstr(4) = stout
5272  IF ( odat(23,i) .GT. 0 ) outstr(5) = stout
5273  !
5274  END IF
5275  !
5276  END IF
5277  !
5278  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
5279  WRITE (mdss,975) mnames(i), ip1, ipn, outstr
5280  IF ( nmplog .EQ. improc ) &
5281  WRITE (mdso,1975)mnames(i), ip1, ipn, outstr
5282  !
5283 #ifdef W3_MPI
5284  IF ( fbcast ) THEN
5285  tmprnk(1) = ip1 - 1
5286  napbct = 1
5287  DO j=1, nmproc
5288  IF ( allprc(j,i) .EQ. 0 ) THEN
5289  napbct = napbct + 1
5290  tmprnk(napbct) = j - 1
5291  END IF
5292  END DO
5293  CALL mpi_group_incl ( bgroup, napbct, tmprnk, &
5294  lgroup, ierr_mpi )
5295  CALL mpi_comm_create ( mpi_comm_mwave, lgroup, &
5296  mpi_comm_bct, ierr_mpi )
5297  CALL mpi_group_free ( lgroup, ierr_mpi )
5298  END IF
5299 #endif
5300  !
5301  END DO
5302  !
5303  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) THEN
5304  WRITE (mdss,976)
5305  IF ( unipts ) WRITE (mdss,977) nmpupt
5306  WRITE (mdss,*)
5307  END IF
5308  !
5309  IF ( nmplog .EQ. improc ) THEN
5310  WRITE (mdso,1976)
5311  IF ( unipts ) WRITE (mdso,1977) nmpupt
5312  WRITE (mdso,*)
5313  END IF
5314  !
5315  DEALLOCATE ( tmprnk, ndpout )
5316  !
5317  ! 7.d Set MODMAP and LOADMP arrays
5318  !
5319  DO jj=1, nrgrp
5320  DO ii=1, ingrp(jj,0)
5321  i = ingrp(jj,ii)
5322  DO j=1, nmproc
5323  IF ( allprc(j,i) .NE. 0 ) THEN
5324  loadmp(j,jj) = loadmp(j,jj) + 1
5325  IF ( loadmp(j,jj) .EQ. 1 ) THEN
5326  modmap(j,jj) = i
5327  ELSE
5328  modmap(j,jj) = -1
5329  END IF
5330  END IF
5331  END DO
5332  END DO
5333  END DO
5334  !
5335 #ifdef W3_T
5336  WRITE (mdst,8042)
5337  DO j=1, nrgrp
5338  WRITE (mdst,8044) j, modmap(:,j)
5339  END DO
5340  WRITE (mdst,8043)
5341  DO j=1, nrgrp
5342  WRITE (mdst,8044) j, loadmp(:,j)
5343  END DO
5344 #endif
5345  !
5346  ! 7.e Warnings
5347  !
5348  IF ( nmproc .GT. 1 ) THEN
5349  DO i=1, nrgrp
5350  ip1 = minval( loadmp(:ncproc,i) )
5351  ipn = maxval( loadmp(:ncproc,i) )
5352  IF ( ip1.NE.ipn .AND. improc.EQ.nmperr ) &
5353  WRITE (mdse,1040) i, ip1, ipn
5354  END DO
5355  END IF
5356  !
5357  DEALLOCATE ( rp1, rpn, loadmp )
5358  !
5359  ! 7.f Reset NMPSCR to first processor of first rank 1 grid
5360  !
5361 #ifdef W3_MPI
5362  CALL wmsetm ( ingrp(1,1), mdse, mdst )
5363  nmpscr = croot
5364 #endif
5365  !
5366 #ifdef W3_MPI
5367  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
5368 #endif
5369  !
5370  ! 8. Actual initializations ----------------------------------------- /
5371  !
5372 #ifdef W3_MPRF
5373  CALL prtime ( prftn )
5374  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8'
5375  prft0 = prftn
5376 #endif
5377  !
5378  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,980)
5379  ALLOCATE ( tsync(2,0:nrgrd), tmax(2,nrgrd), toutp(2,0:nrgrd), &
5380  tdata(2,nrgrd), grstat(nrgrd), dtres(nrgrd) )
5381  !
5382  tsync(1,:) = -1
5383  tsync(2,:) = 0
5384  tmax(1,:) = -1
5385  tmax(2,:) = 0
5386  toutp(1,:) = -1
5387  toutp(2,:) = 0
5388  tdata(1,:) = -1
5389  tdata(2,:) = 0
5390  grstat = 99
5391  !
5392  ! 8.a Loop over models for per-model initialization
5393  !
5394 #ifdef W3_T
5395  WRITE (mdst,9080)
5396 #endif
5397 #ifdef W3_MPRF
5398  CALL prtime ( prftn )
5399  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8.a'
5400  prft0 = prftn
5401 #endif
5402  !
5403  DO i=1, nrgrd
5404  j = len_trim(mnames(i))
5405  DO nmpsc2=1, nmproc
5406  IF ( allprc(nmpsc2,i) .EQ. 1 ) EXIT
5407  END DO
5408  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
5409  WRITE (mdss,981) i, mnames(i)(1:j)
5410  !
5411 #ifdef W3_MPI
5412  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
5413 #endif
5414  !
5415  ! 8.a.1 Wave model initialization (NOTE: sets all grid pointers)
5416  ! ..... Initial output file hook up
5417  !
5418  CALL wmsetm ( i, mdse, mdst )
5419 #ifdef W3_MPI
5420  mpi_comm_loc = mpi_comm_grd
5421  IF ( mpi_comm_loc .EQ. mpi_comm_null ) cycle
5422 #endif
5423  !
5424  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT' )
5425  CALL wmuset ( mdse, mdst, ndsfnd, .true., desc='Log file' )
5426  mds( 1,i) = ndsfnd
5427  !
5428  ! ... this one overwrites the combined setting MDS( 3,I) = MDST above
5429  !
5430  ! CALL WMUGET ( MDSE, MDST, NDSFND, 'OUT' )
5431  ! CALL WMUSET ( MDSE, MDST, NDSFND, .TRUE., DESC='Test output' )
5432  ! MDS( 3,I) = NDSFND
5433  !
5434  DO j=1, 6
5435  IF ( j.EQ.4 .OR. j.EQ.5 ) cycle
5436  IF ( odat(5*(j-1)+3,i) .GT. 0 ) THEN
5437  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT' )
5438  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
5439  desc='Raw output file' )
5440  SELECT CASE (j)
5441  CASE (1)
5442  mds(7,i) = ndsfnd
5443 #ifdef W3_ASCII
5444  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT' )
5445  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
5446  desc='ASCII output file' )
5447  mds(14,i) = ndsfnd ! ASCII
5448 #endif
5449  CASE (2)
5450  mds(8,i) = ndsfnd
5451 #ifdef W3_ASCII
5452  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT' )
5453  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
5454  desc='ASCII output file' )
5455  mds(15,i) = ndsfnd ! ASCII
5456 #endif
5457  CASE (3)
5458  mds(12,i) = ndsfnd
5459  CALL wmuget ( mdse, mdst, ndsfnd, 'INP' )
5460  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
5461  desc='Input data file' )
5462  mds(11,i) = ndsfnd
5463  CASE (6)
5464  mds(13,i) = ndsfnd
5465  END SELECT
5466  END IF
5467  END DO
5468  !
5469  CALL wmuget ( mdse, mdst, ndsfnd, 'INP' )
5470  CALL wmuset ( mdse, mdst, ndsfnd, .true., &
5471  desc='Input data file' )
5472  mds(9,i) = ndsfnd
5473  !
5474  IF ( odat(5*(5-1)+3,i) .GT. 0 ) THEN
5475  CALL wmuget ( mdse, mdst, ndsfnd, 'OUT', 9 )
5476  mds(10,i) = ndsfnd
5477  DO ii=0, 8
5478  CALL wmuset ( mdse, mdst, ndsfnd+ii, .true., &
5479  desc='Raw output file' )
5480  END DO
5481  END IF
5482  !
5483  ! ..... Model initialization
5484  !
5485  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) WRITE (mdss,982)
5486 
5487  CALL w3init ( i, .true., mnames(i), mds(:,i), ntrace(:,i), &
5488  odat(:,i), &
5489  flgrd(:,:,i),flgr2(:,:,i),flgd(:,i),flg2(:,i), &
5490  ot2(i)%NPTS, ot2(i)%X, ot2(i)%Y, ot2(i)%PNAMES, &
5491  iprt(:,i), lprt(i), mpi_comm_loc)
5492  !
5493  ! ..... Finalize I/O file hook up
5494  !
5495  ii = len_trim(filext)
5496  jj = len_trim(fnmpre)
5497  CALL wmuinq ( mdse, mdst, mds(1,i) )
5498  IF ( mds(3,i) .NE. mdst ) CALL wmuinq ( mdse, mdst, mds(3,i) )
5499  !
5500  IF ( mds(7,i) .NE. -1 ) THEN
5501  IF ( iaproc .EQ. napfld ) THEN
5502  tname = trim(fnmpre)//'out_grd.' // filext(:ii)
5503  CALL wmuset ( mdse,mdst, mds(7,i), .true., name=tname )
5504  ELSE
5505  CALL wmuset ( mdse,mdst, mds(7,i), .false. )
5506  mds(7,i) = -1
5507  END IF
5508  END IF
5509  !
5510  IF ( mds(8,i) .NE. -1 ) THEN
5511  IF ( iaproc .EQ. nappnt ) THEN
5512  tname = trim(fnmpre)//'out_pnt.' // filext(:ii)
5513  CALL wmuset ( mdse,mdst, mds(8,i), .true., name=tname )
5514  ELSE
5515  CALL wmuset ( mdse,mdst, mds(8,i), .false. )
5516  mds(8,i) = -1
5517  END IF
5518  END IF
5519  !
5520  IF ( mds(9,i) .NE. -1 ) THEN
5521  IF ( flbpi ) THEN
5522  tname = trim(fnmpre)//'nest.' // filext(:ii)
5523  CALL wmuset ( mdse, mdst, mds(9,i), .true., name=tname )
5524  ELSE
5525  CALL wmuset ( mdse, mdst, mds(9,i), .false. )
5526  mds(9,i) = -1
5527  END IF
5528  END IF
5529  !
5530  IF ( mds(10,i) .NE. -1 ) THEN
5531  IF ( flbpo .AND. iaproc.EQ.napbpt ) THEN
5532  tname = trim(fnmpre)//'nestN.' // filext(:ii)
5533  DO j=0, nfbpo-1
5534  WRITE (tname(jj+5:jj+5),'(I1)') j + 1
5535  CALL wmuset ( mdse, mdst, mds(10,i)+j, .true., &
5536  name=tname )
5537  END DO
5538  DO j=nfbpo, 8
5539  CALL wmuset ( mdse,mdst, mds(10,i)+j, .false. )
5540  END DO
5541  ELSE
5542  DO j=0, 8
5543  CALL wmuset ( mdse,mdst, mds(10,i)+j, .false. )
5544  END DO
5545  mds(10,i) = -1
5546  END IF
5547  END IF
5548  !
5549  IF ( mds(11,i) .NE. -1 ) THEN
5550  tname = trim(fnmpre)//'track_i.' // filext(:ii)
5551  CALL wmuset ( mdse,mdst, mds(11,i), .true., name=tname )
5552  END IF
5553  !
5554  IF ( mds(12,i) .NE. -1 ) THEN
5555  IF ( iaproc .EQ. naptrk ) THEN
5556  tname = trim(fnmpre)//'track_o.' // filext(:ii)
5557  CALL wmuset ( mdse,mdst, mds(12,i), .true., name=tname )
5558  ELSE
5559  CALL wmuset ( mdse,mdst, mds(12,i), .false. )
5560  mds(12,i) = -1
5561  END IF
5562  END IF
5563  !
5564  IF ( mds(13,i) .NE. -1 ) THEN
5565  IF ( iaproc .EQ. napprt ) THEN
5566  tname = trim(fnmpre)//'partition.' // filext(:ii)
5567  CALL wmuset ( mdse,mdst, mds(13,i), .true., name=tname )
5568  ELSE
5569  CALL wmuset ( mdse,mdst, mds(13,i), .false. )
5570  mds(13,i) = -1
5571  END IF
5572  END IF
5573  !
5574 #ifdef W3_ASCII
5575  IF ( mds(14,i) .NE. -1 ) THEN ! Grid output (ASCII)
5576  IF ( iaproc .EQ. napfld ) THEN
5577  tname = trim(fnmpre)//'out_grd.' // filext(:ii) // '.txt'
5578  CALL wmuset ( mdse,mdst, mds(14,i), .true., name=tname )
5579  ELSE
5580  CALL wmuset ( mdse,mdst, mds(14,i), .false. )
5581  mds(14,i) = -1
5582  END IF
5583  END IF
5584  !
5585  IF ( mds(15,i) .NE. -1 ) THEN ! Point output (ASCII)
5586  IF ( iaproc .EQ. nappnt ) THEN
5587  tname = trim(fnmpre)//'out_pnt.' // filext(:ii) // '.txt'
5588  CALL wmuset ( mdse,mdst, mds(15,i), .true., name=tname )
5589  ELSE
5590  CALL wmuset ( mdse,mdst, mds(15,i), .false. )
5591  mds(15,i) = -1
5592  END IF
5593  END IF
5594 #endif
5595 !
5596 #ifdef W3_T
5597  WRITE (mdst,9081) i, time
5598 #endif
5599  !
5600  ! 8.a.2 Data file initialization (forcing)
5601  !
5602  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) WRITE (mdss,983)
5603  CALL w3seti ( i, mdse, mdst )
5604  !
5605  !!Li Stop modifying GTYPE from input forcing file. JGLi08Apr2021.
5606  jjj = gtype
5607  !
5608  ! ..... regular input files
5609  !
5610  DO j=jfirst, 6
5611  IF ( inflags1(j) ) THEN
5612  idinp(i,j) = idstr(j)
5613  IF ( inpmap(i,j) .LT. 0 ) cycle
5614  CALL w3fldo ('READ', idinp(i,j), mdsf(i,j), mdst, mdse2,&
5615  !!Li NX, NY, GTYPE, IERR, MNAMES(I), &
5616  nx, ny, jjj, ierr, mnames(i), &
5617  trim(fnmpre) )
5618  IF ( ierr .NE. 0 ) GOTO 2080
5619  !
5620  !!Li Print a warning message when GTYPE not matching forcing field one.
5621  IF ( (jjj .NE. gtype) .AND. (improc .EQ. nmpsc2) ) &
5622  WRITE (mdse, *) ' *** Warning: grid', i, ' GTYPE=', &
5623  gtype, ' not matching field', j, ' grid type', jjj
5624  !
5625  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
5626  WRITE (mdss,985) idflds(j)
5627  ELSE
5628  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
5629  WRITE (mdss,984) idflds(j)
5630  END IF
5631  END DO
5632  !
5633  ! ..... assimilation data files
5634  !
5635  ! version 3.07: Data assimilation part ignored for now ....
5636  !
5637  ! ..... finalize file info data base
5638  !
5639  DO j=jfirst, 9
5640  IF ( mdsf(i,j) .NE. -1 ) CALL wmuinq ( mdse, mdst, mdsf(i,j) )
5641  END DO
5642  !
5643  ! ..... Adjust input flags for other than native or CPL input,
5644  ! and initialize input arrays one set at a time as needed.
5645  !
5646  IF ( SIZE(inflags1) .NE. SIZE(tflags) ) THEN
5647  WRITE (mdse,'(/2A)') ' *** ERROR WMINITNML: ', &
5648  .NE.'SIZE(INFLAGS1)SIZE(TFLAGS) ***'
5649  CALL extcde ( 999 )
5650  END IF
5651  IF ( SIZE(inflags2) .NE. SIZE(tflags) ) THEN
5652  WRITE (mdse,'(/2A)') ' *** ERROR WMINITNML: ', &
5653  .NE.'SIZE(INFLAGS2)SIZE(TFLAGS) ***'
5654  CALL extcde ( 999 )
5655  END IF
5656 
5657  tflags = inflags1
5658  !
5659  DO j=jfirst, 9
5660  IF ( inpmap(i,j) .NE. 0 ) THEN
5661  !
5662  tflags(j) = .true.
5663  inflags1 = .false.
5664  inflags1(j) = .true.
5665  iinit = .false.
5666  CALL w3dimi ( i, mdse, mdst )
5667  !
5668  IF ( j.EQ.2 ) ALLOCATE ( wadats(i)%CA0(nsea) , &
5669  wadats(i)%CAI(nsea) , &
5670  wadats(i)%CD0(nsea) , &
5671  wadats(i)%CDI(nsea) )
5672  !
5673  IF ( j.EQ.3 ) ALLOCATE ( wadats(i)%UA0(nsea) , &
5674  wadats(i)%UAI(nsea) , &
5675  wadats(i)%UD0(nsea) , &
5676  wadats(i)%UDI(nsea) , &
5677  wadats(i)%AS0(nsea) , &
5678  wadats(i)%ASI(nsea) )
5679  !
5680  IF ( j.EQ.5 ) ALLOCATE ( wadats(i)%MA0(nsea) , &
5681  wadats(i)%MAI(nsea) , &
5682  wadats(i)%MD0(nsea) , &
5683  wadats(i)%MDI(nsea) )
5684  !
5685  IF ( j.EQ.6 ) ALLOCATE ( wadats(i)%RA0(nsea) , &
5686  wadats(i)%RAI(nsea) )
5687  !
5688  END IF ! IF ( INPMAP(I,J) .NE. 0 ) THEN
5689  END DO ! DO J=JFIRST, 9
5690  !
5691  inflags1 = tflags
5692  CALL w3seti ( i, mdse, mdst )
5693  CALL w3seta ( i, mdse, mdst )
5694  !
5695  ! 8.a.3 Status indicator and model times
5696  !
5697  DO j=1, notype
5698  IF ( flout(j) ) THEN
5699  IF ( toutp(1,i) .EQ. -1 ) THEN
5700  toutp(:,i) = tonext(:,j)
5701  ELSE
5702  dttst = dsec21( toutp(:,i), tonext(:,j) )
5703  IF ( dttst .LT. 0. ) toutp(:,i) = tonext(:,j)
5704  ENDIF
5705  END IF
5706  END DO
5707  !
5708  grstat(i) = 0
5709  tsync(:,i) = time(:)
5710  !
5711 #ifdef W3_SMC
5712  ! Check GTYPE values after initialization
5713  IF ( improc .EQ. nmperr ) WRITE(mdse,*) "GRID IMPROC GTYPE", &
5714  i, improc, grids(i)%GTYPE
5715 #endif
5716  !
5717 #ifdef W3_T
5718  WRITE (mdst,9082) grstat(i), toutp(:,i), tsync(:,i)
5719 #endif
5720  !
5721  END DO !! 8.a I-NRGRD loop
5722  !
5723 #ifdef W3_MPI
5724  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
5725  DO i=1, nrgrd
5726  CALL wmsetm ( i, mdse, mdst )
5727  CALL w3setg ( i, mdse, mdst )
5728  CALL w3seto ( i, mdse, mdst )
5729  IF ( fbcast .AND. mpi_comm_bct.NE.mpi_comm_null ) THEN
5730  CALL mpi_bcast ( toutp(1,i), 2, mpi_integer, 0, &
5731  mpi_comm_bct, ierr_mpi )
5732  CALL mpi_bcast ( tsync(1,i), 2, mpi_integer, 0, &
5733  mpi_comm_bct, ierr_mpi )
5734  CALL mpi_bcast ( grstat(i), 1, mpi_integer, 0, &
5735  mpi_comm_bct, ierr_mpi )
5736 #endif
5737  !
5738  ! 8.a.4 Grid sizes etc. for processors that are not used.
5739  !
5740 #ifdef W3_MPI
5741  CALL mpi_bcast ( flagll,1, mpi_logical, 0, &
5742  mpi_comm_bct, ierr_mpi )
5743  CALL mpi_bcast ( gtype, 1, mpi_integer, 0, &
5744  mpi_comm_bct, ierr_mpi )
5745  CALL mpi_bcast ( iclose,1, mpi_integer, 0, &
5746  mpi_comm_bct, ierr_mpi )
5747  CALL mpi_bcast ( nx , 1, mpi_integer, 0, &
5748  mpi_comm_bct, ierr_mpi )
5749  CALL mpi_bcast ( ny , 1, mpi_integer, 0, &
5750  mpi_comm_bct, ierr_mpi )
5751  CALL mpi_bcast ( x0 , 1, mpi_real , 0, &
5752  mpi_comm_bct, ierr_mpi )
5753  CALL mpi_bcast ( sx , 1, mpi_real , 0, &
5754  mpi_comm_bct, ierr_mpi )
5755  CALL mpi_bcast ( y0 , 1, mpi_real , 0, &
5756  mpi_comm_bct, ierr_mpi )
5757  CALL mpi_bcast ( sy , 1, mpi_real , 0, &
5758  mpi_comm_bct, ierr_mpi )
5759  CALL mpi_bcast ( nsea , 1, mpi_integer, 0, &
5760  mpi_comm_bct, ierr_mpi )
5761  CALL mpi_bcast ( nseal, 1, mpi_integer, 0, &
5762  mpi_comm_bct, ierr_mpi )
5763  CALL mpi_bcast ( dtmax, 1, mpi_real, 0, &
5764  mpi_comm_bct, ierr_mpi )
5765  CALL mpi_bcast ( dtcfl, 1, mpi_real, 0, &
5766  mpi_comm_bct, ierr_mpi )
5767  CALL mpi_bcast ( filext, 10, mpi_character, 0, &
5768  mpi_comm_bct, ierr_mpi )
5769  IF ( mpi_comm_grd .EQ. mpi_comm_null ) &
5770  CALL w3dimx ( i, nx, ny, nsea, mdse, mdst &
5771 #endif
5772 #ifdef W3_SMC
5773  !! SMC grid related variables are not needed beyond MPI_COMM_GRD
5774  !! so all dimensions are minimised to 1. JGLi29Mar2021
5775 #endif
5776 #ifdef W3_MPI
5777 #ifdef W3_SMC
5778  !!Li , NCel, NUFc, NVFc, NRLv, NBSMC &
5779  !!Li , NARC, NBAC, NSPEC &
5780  , 1, 1, 1, 1, 1, 1, 1, 1 &
5781 #endif
5782  )
5783  CALL mpi_bcast ( hqfac, nx*ny, mpi_real, 0, &
5784  mpi_comm_bct, ierr_mpi )
5785  CALL mpi_bcast ( hpfac, nx*ny, mpi_real, 0, &
5786  mpi_comm_bct, ierr_mpi )
5787  CALL mpi_bcast ( xgrd, nx*ny, mpi_double_precision, 0, &
5788  mpi_comm_bct, ierr_mpi )
5789  CALL mpi_bcast ( ygrd, nx*ny, mpi_double_precision, 0, &
5790  mpi_comm_bct, ierr_mpi )
5791  IF ( mpi_comm_grd .EQ. mpi_comm_null ) &
5792  gsu = w3gsuc( .false., flagll, iclose, &
5793  xgrd, ygrd )
5794  CALL mpi_bcast ( dxdp, nx*ny, mpi_real, 0, &
5795  mpi_comm_bct, ierr_mpi )
5796  CALL mpi_bcast ( dxdq, nx*ny, mpi_real, 0, &
5797  mpi_comm_bct, ierr_mpi )
5798  CALL mpi_bcast ( dydp, nx*ny, mpi_real, 0, &
5799  mpi_comm_bct, ierr_mpi )
5800  CALL mpi_bcast ( dydq, nx*ny, mpi_real, 0, &
5801  mpi_comm_bct, ierr_mpi )
5802  CALL mpi_bcast ( mapsta, nx*ny, mpi_integer, 0, &
5803  mpi_comm_bct, ierr_mpi )
5804  CALL mpi_bcast ( mapst2, nx*ny, mpi_integer, 0, &
5805  mpi_comm_bct, ierr_mpi )
5806  CALL mpi_bcast ( gridshift, 1, mpi_double_precision, 0, &
5807  mpi_comm_bct, ierr_mpi )
5808 #endif
5809  !
5810 #ifdef W3_MPI
5811  CALL mpi_bcast ( nk , 1, mpi_integer, 0, &
5812  mpi_comm_bct, ierr_mpi )
5813  CALL mpi_bcast ( nth , 1, mpi_integer, 0, &
5814  mpi_comm_bct, ierr_mpi )
5815  CALL mpi_bcast ( xfr , 1, mpi_real , 0, &
5816  mpi_comm_bct, ierr_mpi )
5817  CALL mpi_bcast ( fr1 , 1, mpi_real , 0, &
5818  mpi_comm_bct, ierr_mpi )
5819  IF ( mpi_comm_grd .EQ. mpi_comm_null ) &
5820  CALL w3dims ( i, nk, nth, mdse, mdst )
5821  CALL mpi_bcast ( th , nth, mpi_real , 0, &
5822  mpi_comm_bct, ierr_mpi )
5823 #endif
5824  !
5825 #ifdef W3_MPI
5826  CALL mpi_bcast ( naproc,1, mpi_integer, 0, &
5827  mpi_comm_bct, ierr_mpi )
5828  CALL mpi_bcast ( nappnt,1, mpi_integer, 0, &
5829  mpi_comm_bct, ierr_mpi )
5830  CALL mpi_bcast ( nbi , 1, mpi_integer, 0, &
5831  mpi_comm_bct, ierr_mpi )
5832 #endif
5833  !
5834 #ifdef W3_MPI
5835  CALL mpi_bcast ( flout, 8, mpi_logical, 0, &
5836  mpi_comm_bct, ierr_mpi )
5837  CALL mpi_bcast ( dtout , 8, mpi_real, 0, &
5838  mpi_comm_bct, ierr_mpi )
5839  CALL mpi_bcast ( tonext,16, mpi_integer, 0, &
5840  mpi_comm_bct, ierr_mpi )
5841  CALL mpi_bcast ( tolast,16, mpi_integer, 0, &
5842  mpi_comm_bct, ierr_mpi )
5843 #endif
5844  !
5845 #ifdef W3_MPI
5846  END IF
5847  END DO
5848  CALL mpi_barrier (mpi_comm_mwave,ierr_mpi)
5849 #endif
5850  !
5851  DO i=1, nrgrd
5852  IF ( allprc(improc,i) .EQ. 0 ) THEN
5853  CALL w3seto ( i, mdse, mdst )
5854  iaproc = -1
5855  END IF
5856  END DO
5857  !
5858  ! 8.a.5 Test output
5859  !
5860 #ifdef W3_T
5861  WRITE (mdst,9020) 'AFTER SETUP'
5862  DO i=1, nrgrd
5863  WRITE (mdst,9021) i, mds(:,i), ntrace(:,i)
5864  END DO
5865 #endif
5866  !
5867  ! 8.a.6 Check for coordinate system
5868  !
5869  DO i=1, nrgrd-1
5870  IF ( grids(i)%FLAGLL .NEQV. grids(i+1)%FLAGLL ) GOTO 2070
5871  END DO
5872  !
5873  ! 8.b Input files
5874  !
5875 #ifdef W3_MPRF
5876  CALL prtime ( prftn )
5877  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8.c'
5878  prft0 = prftn
5879 #endif
5880  !
5881  DO i=1, nrinp
5882  !
5883  IF ( .NOT. useinp(i) ) cycle
5884  !
5885  j = len_trim(mnames(-i))
5886  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) THEN
5887  WRITE (mdss,988) i, mnames(-i)(1:j)
5888  WRITE (mdss,987)
5889  END IF
5890  !
5891  CALL w3iogr ( 'GRID', ndsrec, -i, mnames(-i)(1:j) )
5892  CALL w3dimi ( -i, mdse, mdst )
5893  !
5894  IF ( cplinp(i) ) cycle
5895  !
5896  DO j=jfirst, 6
5897  IF ( inflags1(j) ) THEN
5898  idinp(-i,j) = idstr(j)
5899  CALL w3fldo ('READ', idinp(-i,j), mdsf(-i,j), mdst, &
5900  mdse2, nx, ny, gtype, ierr, &
5901  mnames(-i), trim(fnmpre) )
5902  IF ( ierr .NE. 0 ) GOTO 2080
5903  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
5904  WRITE (mdss,985) idflds(j)
5905  ELSE
5906  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) &
5907  WRITE (mdss,984) idflds(j)
5908  END IF
5909  END DO
5910  !
5911  ! Skipping assimilation input files for now.
5912  !
5913  DO j=jfirst, 9
5914  IF ( mdsf(-i,j) .NE. -1 ) CALL wmuinq &
5915  ( mdse, mdst, mdsf(-i,j) )
5916  END DO
5917  !
5918  END DO
5919  !
5920  DO i=1, nrgrd
5921  DO j=jfirst, 9
5922  IF ( inpmap(i,j).LT.0 .AND. inpmap(i,j).NE.-999) idinp(i,j) = idinp( inpmap(i,j),j)
5923  !IF ( INPMAP(I,J) .LT. 0 ) IDINP(I,J) = IDINP( INPMAP(I,J),J)
5924  IF ( inpmap(i,j) .GT. 0 ) idinp(i,j) = idinp(-inpmap(i,j),j)
5925  END DO
5926  END DO
5927  !
5928  DEALLOCATE ( useinp )
5929  DEALLOCATE ( cplinp )
5930  !
5931  ! 8.c Inter model initialization
5932  !
5933 #ifdef W3_MPRF
5934  CALL prtime ( prftn )
5935  WRITE (mdsp,990) prft0, prftn, get_memory(), 'START Sec. 8.d'
5936  prft0 = prftn
5937 #endif
5938 
5939  ! 8.c.1 Spectral conversion flags and source term flags
5940  !
5941  CALL wmrspc
5942  !
5943  DO i=1, nrgrd
5944  CALL w3setg ( i, mdse, mdst )
5945  flagst = .true.
5946  END DO
5947  !
5948  ! 8.c.2 Relation to lower ranked grids
5949  ! Includes update of unit numbers, and bound. data initialization.
5950  !
5951  ALLOCATE ( flrbpi(nrgrd) )
5952  CALL wmglow ( flrbpi )
5953  !
5954  ! ..... At this point the grid-search-utility (GSU) object for grids
5955  ! that do not belong to this processor is no longer needed.
5956  !
5957 #ifdef W3_MPI
5958  DO i=1, nrgrd
5959  CALL wmsetm ( i, mdse, mdst )
5960  CALL w3setg ( i, mdse, mdst )
5961 #endif
5962  ! the next line (with the W3GSUD call) removed Jan 8 2013.
5963  ! ...ref: personal communication,
5964  ! ...email from Rogers to Alves, Campbell, Tolman, Chawla Dec 13 2012.
5965  ! REMOVED !/MPI IF ( MPI_COMM_GRD .EQ. MPI_COMM_NULL ) CALL W3GSUD( GSU )
5966 #ifdef W3_MPI
5967  END DO
5968 #endif
5969  !
5970  ! ..... Unit numbers
5971  !
5972 
5973  DO i=1, nrgrd
5974  !
5975  CALL w3setg ( i, mdse, mdst )
5976  CALL w3seto ( i, mdse, mdst )
5977  !
5978  IF ( bcdump(i) .AND. flrbpi(i) ) THEN
5979  IF ( improc .EQ. nmperr ) WRITE (mdse,1080) i
5980  IF ( improc .EQ. nmplog ) WRITE (mdso,1082) i
5981  bcdump(i) = .false.
5982  END IF
5983  !
5984  IF ( bcdump(i) .AND. nbi.EQ.0 ) THEN
5985  IF ( improc .EQ. nmperr ) WRITE (mdse,1081) i
5986  IF ( improc .EQ. nmplog ) WRITE (mdso,1082) i
5987  bcdump(i) = .false.
5988  END IF
5989  !
5990 #ifdef W3_SHRD
5991  IF ( .NOT. flrbpi(i) .AND. flbpi ) THEN
5992 #endif
5993 #ifdef W3_MPI
5994  IF ( .NOT. flrbpi(i) .AND. flbpi .AND. &
5995  mpi_comm_grd .NE. mpi_comm_null) THEN
5996 #endif
5997  CALL wmuset ( mdse, mdst, nds(9), .false. )
5998  IF ( bcdump(i) .AND. iaproc.EQ.napbpt ) THEN
5999  j = len_trim(filext)
6000  tname(1:5) = 'nest.'
6001  tname(6:5+j) = filext(1:j)
6002  j = j + 5
6003  CALL wmuget ( mdse, mdst, nds(9), 'OUT' )
6004  CALL wmuset ( mdse, mdst, nds(9), .true., &
6005  name=trim(fnmpre)//tname(1:j), &
6006  desc='Output data file (nest dump)' )
6007  mds(9,i) = ndsfnd
6008  ELSE
6009  nds(9) = -1
6010  END IF
6011 #ifdef W3_MPI
6012  END IF ! IF ( .NOT. FLRBPI(I) .AND. FLBPI .AND. MPI_COMM_GRD .NE. MPI_COMM_NULL)
6013 #endif
6014 #ifdef W3_SHRD
6015  END IF ! IF ( .NOT. FLRBPI(I) .AND. FLBPI )
6016 #endif
6017  !
6018  END DO
6019  !
6020  ! ..... Data initialization
6021  !
6022  DO i=1, nrgrd
6023 #ifdef W3_MPI
6024  CALL wmsetm ( i, mdse, mdst )
6025  IF ( mpi_comm_grd .NE. mpi_comm_null ) CALL wmiobs ( i )
6026 #endif
6027 #ifdef W3_SHRD
6028  CALL wmiobs ( i )
6029 #endif
6030  END DO
6031  !
6032  DO i=1, nrgrd
6033 #ifdef W3_MPI
6034  CALL wmsetm ( i, mdse, mdst )
6035  IF ( mpi_comm_grd .NE. mpi_comm_null ) CALL wmiobg ( i )
6036 #endif
6037 #ifdef W3_SHRD
6038  CALL wmiobg ( i )
6039 #endif
6040  END DO
6041  !
6042 #ifdef W3_MPI
6043  DO i=1, nrgrd
6044  CALL wmsetm ( i, mdse, mdst )
6045  IF ( mpi_comm_grd .NE. mpi_comm_null ) CALL wmiobf ( i )
6046  END DO
6047 #endif
6048  !
6049  ! 8.c.3 Relation to same ranked grids
6050  !
6051 #ifdef W3_SMC
6052  !! Check whether there is a SMC grid group. JGLi12Apr2021
6053  ngrpsmc = 0
6054  DO jj=1, nrgrp
6055  j = 0
6056  DO ii=1, ingrp(jj,0)
6057  i = ingrp(jj,ii)
6058  IF( grids(i)%GTYPE .EQ. smctype ) j = j + 1
6059  ENDDO
6060  IF( j .GT. 1 ) ngrpsmc = jj
6061  ENDDO
6062  IF( improc.EQ.nmperr ) WRITE (mdse,*) " NGRPSMC =", ngrpsmc
6063 
6064  !! Equal ranked SMC grid group uses its own sub. JGLi12Apr2021
6065  IF( ngrpsmc .GT. 0 ) THEN
6066  CALL wmsmceql
6067  ELSE
6068 #endif
6069  !
6070  CALL wmgeql
6071  !
6072 #ifdef W3_SMC
6073  ENDIF
6074 #endif
6075  !
6076  ! 8.c.4 Relation to higher ranked grids
6077  !
6078  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) WRITE (mdss,938) &
6079  'Computing relation to higher ranked grids'
6080  CALL wmghgh
6081  IF ( mdss.NE.mdso .AND. nmpsc2.EQ.improc ) WRITE (mdss,938) &
6082  'Finished computing relation to higher ranked grids'
6083  !
6084  ! 8.c.5 Unified point output
6085  !
6086  IF ( unipts ) THEN
6087  !
6088  outpts(0)%TONEXT(1,2) = odat( 6,0)
6089  outpts(0)%TONEXT(2,2) = odat( 7,0)
6090  outpts(0)%DTOUT ( 2) = real( odat( 8,0) )
6091  outpts(0)%TOLAST(1,2) = odat( 9,0)
6092  outpts(0)%TOLAST(2,2) = odat(10,0)
6093  !
6094  tout = outpts(0)%TONEXT(:,2)
6095  tlst = outpts(0)%TOLAST(:,2)
6096  !
6097  DO
6098  dttst = dsec21( stime , tout )
6099  IF ( dttst .LT. 0 ) THEN
6100  CALL tick21 ( tout, outpts(0)%DTOUT(2) )
6101  ELSE
6102  EXIT
6103  END IF
6104  END DO
6105  !
6106  outpts(0)%TONEXT(:,2) = tout
6107  !
6108  dttst = dsec21( tout , tlst )
6109  IF (( dttst .LT. 0. ) .OR. ( odat(8,0) .EQ. 0 )) THEN
6110  unipts = .false.
6111  ELSE
6112  CALL wmiopp ( ot2(0)%NPTS, ot2(0)%X, ot2(0)%Y, &
6113  ot2(0)%PNAMES )
6114  END IF
6115  !
6116 #ifdef W3_MPI
6117  DO i=1, nrgrd
6118  CALL wmsetm ( i, mdse, mdst )
6119  CALL w3setg ( i, mdse, mdst )
6120  CALL w3seto ( i, mdse, mdst )
6121  IF ( fbcast .AND. mpi_comm_bct.NE.mpi_comm_null ) THEN
6122  CALL mpi_bcast ( nopts, 1, mpi_integer, 0, &
6123  mpi_comm_bct, ierr_mpi )
6124  END IF
6125  END DO
6126 #endif
6127  !
6128  END IF ! IF ( UNIPTS )
6129  !
6130  ! 8.c.6 Output
6131  !
6132  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6133  WRITE (mdss,938) 'Additional group information'
6134  !
6135  IF ( maxval(grdlow(:,0)) .GT. 0 ) THEN
6136  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6137  WRITE (mdss,933) 'Lower rank grid dependence'
6138  IF ( nmplog .EQ. improc ) &
6139  WRITE (mdso,933) 'Lower rank grid dependence'
6140  DO i=1, nrgrd
6141  WRITE (line(1:6),'(1X,I3,2X)') i
6142  jjj = 6
6143  IF ( grdlow(i,0) .NE. 0 ) THEN
6144  DO j=1, grdlow(i,0)
6145  WRITE (line(jjj+1:jjj+3),'(I3)') grdlow(i,j)
6146  jjj = jjj + 3
6147  END DO
6148  ELSE IF ( flrbpi(i) ) THEN
6149  jjj = 21
6150  line(7:jjj) = ' Data from file'
6151  ELSE
6152  jjj = 22
6153  line(7:jjj) = ' No dependencies'
6154  END IF
6155  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6156  WRITE(mdss,934) line(1:jjj)
6157  IF ( nmplog .EQ. improc ) WRITE(mdso,934) line(1:jjj)
6158  END DO
6159  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,935)
6160  IF ( nmplog .EQ. improc ) WRITE (mdso,935)
6161  ELSE
6162  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6163  WRITE (mdss,937) 'No lower rank grid dependencies'
6164  IF ( nmplog .EQ. improc ) &
6165  WRITE (mdso,937) 'No lower rank grid dependencies'
6166  END IF ! IF ( MAXVAL(GRDLOW(:,0)) .GT. 0 )
6167  DEALLOCATE ( flrbpi )
6168  !
6169  IF ( maxval(grdeql(:,0)) .GT. 0 ) THEN
6170  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6171  WRITE (mdss,933) 'Same rank grid dependence'
6172  IF ( nmplog .EQ. improc ) &
6173  WRITE (mdso,933) 'Same rank grid dependence'
6174  DO i=1, nrgrd
6175  WRITE (line(1:6),'(1X,I3,2X)') i
6176  jjj = 6
6177  IF ( grdeql(i,0) .NE. 0 ) THEN
6178  DO j=1, grdeql(i,0)
6179  WRITE (line(jjj+1:jjj+3),'(I3)') grdeql(i,j)
6180  jjj = jjj + 3
6181  END DO
6182  ELSE
6183  jjj = 22
6184  line(7:jjj) = ' No dependencies'
6185  END IF
6186  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6187  WRITE(mdss,934) line(1:jjj)
6188  IF ( nmplog .EQ. improc ) WRITE(mdso,934) line(1:jjj)
6189  END DO
6190  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,935)
6191  IF ( nmplog .EQ. improc ) WRITE (mdso,935)
6192  ELSE
6193  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6194  WRITE (mdss,937) 'No same rank grid dependencies'
6195  IF ( nmplog .EQ. improc ) &
6196  WRITE (mdso,937) 'No same rank grid dependencies'
6197  END IF ! IF ( MAXVAL(GRDEQL(:,0)) .GT. 0 )
6198  !
6199  IF ( maxval(grdhgh(:,0)) .GT. 0 ) THEN
6200  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6201  WRITE (mdss,933) 'Higher rank grid dependence'
6202  IF ( nmplog .EQ. improc ) &
6203  WRITE (mdso,933) 'Higher rank grid dependence'
6204  DO i=1, nrgrd
6205  WRITE (line(1:6),'(1X,I3,2X)') i
6206  jjj = 6
6207  IF ( grdhgh(i,0) .NE. 0 ) THEN
6208  DO j=1, grdhgh(i,0)
6209  WRITE (line(jjj+1:jjj+3),'(I3)') grdhgh(i,j)
6210  jjj = jjj + 3
6211  END DO
6212  ELSE
6213  jjj = 22
6214  line(7:jjj) = ' No dependencies'
6215  END IF
6216  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6217  WRITE(mdss,934) line(1:jjj)
6218  IF ( nmplog .EQ. improc ) WRITE(mdso,934) line(1:jjj)
6219  END DO
6220  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,935)
6221  IF ( nmplog .EQ. improc ) WRITE (mdso,935)
6222  ELSE
6223  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) &
6224  WRITE (mdss,937) 'No higher rank grid dependencies'
6225  IF ( nmplog .EQ. improc ) &
6226  WRITE (mdso,937) 'No higher rank grid dependencies'
6227  END IF ! IF ( MAXVAL(GRDHGH(:,0)) .GT. 0 )
6228  !
6229 #ifdef W3_T
6230  WRITE (mdst,9083)
6231  DO i=-nrinp, nrgrd
6232  WRITE (mdst,9084) i, idinp(i,:)
6233  END DO
6234 #endif
6235  !
6236  ! Test output of connected units (always)
6237  !
6238  CALL wmuset ( mdse, mdst, scratch, .false. )
6239  IF ( tstout ) CALL wmudmp ( mdst, 0 )
6240  !
6241  DEALLOCATE ( mds, ntrace, odat, flgrd, flgr2, flgd, flg2, inames,&
6242  mnames &
6243  ,outff )
6244  !
6245 #ifdef W3_MPI
6246  CALL mpi_barrier ( mpi_comm_mwave, ierr_mpi )
6247 #endif
6248  !
6249  CALL date_and_time ( values=clkdt2 )
6250  clkfin = tdiff( clkdt1,clkdt2 )
6251  !
6252 #ifdef W3_MPRF
6253  CALL prtime ( prftn )
6254  WRITE (mdsp,990) prft0, prftn, get_memory(), 'END'
6255 #endif
6256  !
6257  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,998)
6258 #ifdef W3_O10
6259  IF ( mdss.NE.mdso .AND. nmpscr.EQ.improc ) WRITE (mdss,999)
6260 #endif
6261  !
6262  RETURN
6263  !
6264  ! Escape locations read errors :
6265  !
6266 2003 CONTINUE
6267  IF ( improc .EQ. nmperr ) WRITE (mdse,1003)
6268  CALL extcde ( 2003 )
6269  RETURN
6270  !
6271 2104 CONTINUE
6272  IF ( improc .EQ. nmperr ) WRITE (mdse,1104) ierr
6273  CALL extcde ( 1104 )
6274  RETURN
6275  !
6276 2004 CONTINUE
6277  IF ( improc .EQ. nmperr ) WRITE (mdse,1004) ierr
6278  CALL extcde ( 2004 )
6279  RETURN
6280  !
6281 2010 CONTINUE
6282  IF ( improc .EQ. nmperr ) WRITE (mdse,1010) ierr
6283  CALL extcde ( 2010 )
6284  RETURN
6285  !
6286 2011 CONTINUE
6287  ! === no process number filtering for test file !!! ===
6288  WRITE (mdse,1011) ierr
6289  CALL extcde ( 2011 )
6290  RETURN
6291  !
6292 2020 CONTINUE
6293  IF ( improc .EQ. nmperr ) WRITE (mdse,1020)
6294  CALL extcde ( 2020 )
6295  RETURN
6296  !
6297 2021 CONTINUE
6298  IF ( improc .EQ. nmperr ) WRITE (mdse,1021)
6299  CALL extcde ( 2021 )
6300  RETURN
6301  !
6302 2030 CONTINUE
6303  IF ( improc .EQ. nmperr ) WRITE (mdse,1030) mnames(i), inames(i,j)
6304  CALL extcde ( 2030 )
6305  RETURN
6306  !
6307 2031 CONTINUE
6308  IF ( improc .EQ. nmperr ) WRITE (mdse,1031) inames(i,j), j
6309  CALL extcde ( 2031 )
6310  RETURN
6311  !
6312  !2050 CONTINUE
6313  ! IF ( IMPROC .EQ. NMPERR ) WRITE (MDSE,1040)
6314  ! CALL EXTCDE ( 2050 )
6315  ! RETURN
6316  !
6317 2051 CONTINUE
6318  IF ( improc .EQ. nmperr ) WRITE (mdse,1051) mn(:ii)
6319  CALL extcde ( 2051 )
6320  RETURN
6321  !
6322 2052 CONTINUE
6323  IF ( improc .EQ. nmperr ) WRITE (mdse,1052) j
6324  CALL extcde ( 2052 )
6325  RETURN
6326  !
6327 2053 CONTINUE
6328  IF ( improc .EQ. nmperr ) WRITE (mdse,1053)
6329  CALL extcde ( 2053 )
6330  RETURN
6331  !
6332 2054 CONTINUE
6333  IF ( improc .EQ. nmperr ) WRITE (mdse,1054)
6334  CALL extcde ( 2054 )
6335  RETURN
6336  !
6337 2055 CONTINUE
6338  IF ( improc .EQ. nmperr ) WRITE (mdse,1055)
6339  CALL extcde ( 2055 )
6340  RETURN
6341  !
6342 2060 CONTINUE
6343  IF ( improc .EQ. nmperr ) WRITE (mdse,1060)
6344  CALL extcde ( 2060 )
6345  RETURN
6346  !
6347 2061 CONTINUE
6348  IF ( improc .EQ. nmperr ) WRITE (mdse,1061) idtst, n_mov
6349  CALL extcde ( 2061 )
6350  RETURN
6351  !
6352 2062 CONTINUE
6353  IF ( improc .EQ. nmperr ) WRITE (mdse,1062) idtst
6354  CALL extcde ( 2062 )
6355  RETURN
6356  !
6357 2070 CONTINUE
6358  IF ( improc .EQ. nmperr ) WRITE (mdse,1070)
6359  CALL extcde ( 2070 )
6360  RETURN
6361  !
6362 2080 CONTINUE
6363  CALL extcde ( 2080 )
6364  RETURN
6365  !
6366  ! Formats
6367  !
6368 900 FORMAT ( ' ========== STARTING MWW3 INITIALIZATION (WMINITNML) =', &
6369  '============================'/)
6370 901 FORMAT ( ' WAVEWATCH III log file ', &
6371  ' version ',a/ &
6372  ' ==================================', &
6373  '==================================='/ &
6374  ' multi-grid model driver ', &
6375  'date : ',a10/50x,'time : ',a8)
6376  !
6377 910 FORMAT ( ' Opening input file ',a,' (unit number',i3,')')
6378 911 FORMAT ( ' Opening output file ',a,' (unit number',i3,')')
6379 912 FORMAT (/' Comment character : ''',a,'''')
6380  !
6381 920 FORMAT (/' Number of grids :',i3)
6382 921 FORMAT ( ' No input data grids.')
6383 922 FORMAT ( ' Input data grids :',i3)
6384 923 FORMAT ( ' Single point output file : ',a)
6385 1923 FORMAT (/' Output server type :',i3)
6386 2923 FORMAT ( ' Single point output proc : ',a)
6387 3923 FORMAT ( ' Grids share output procs : ',a)
6388  !
6389 924 FORMAT (/' Input grid information : '/ &
6390  ' nr extension lev. cur. wind ice tau', &
6391  ' rho data'/ &
6392  ' ----------------------------------------------', &
6393  '---------------')
6394 925 FORMAT (1x,i3,1x,a10,6(1x,a6),3(1x,a1))
6395 926 FORMAT ( ' ----------------------------------------------', &
6396  '---------------')
6397  !
6398 927 FORMAT (/' Grid for point output : '/ &
6399  ' nr extension '/ ' ---------------')
6400 928 FORMAT (5x,a10)
6401 929 FORMAT ( ' ---------------')
6402  !
6403 930 FORMAT (/' Wave grid information : '/ &
6404  ' nr extension lev. cur. wind ice tau', &
6405  ' rho data move1 rnk grp dmp'/ &
6406  ' -----------------------------------------------', &
6407  '-----------------------------------')
6408 931 FORMAT (1x,i3,1x,a10,6(1x,a6),3(1x,a1),2x,a4,2i4,3x,a1)
6409 932 FORMAT ( ' -----------------------------------------------', &
6410  '-----------------------------------'/)
6411 933 FORMAT ( ' ',a,' : '/ &
6412  ' nr grids (part of comm.)'/ &
6413  ' -----------------------------------------------', &
6414  '---------------------')
6415 934 FORMAT (a)
6416 935 FORMAT ( ' -----------------------------------------------', &
6417  '---------------------'/)
6418 936 FORMAT (/' ',a,' : '/ &
6419  ' nr Depends on '/ &
6420  ' -----------------------------------------------', &
6421  '---------------------')
6422 937 FORMAT ( ' ',a/)
6423 938 FORMAT (/' ',a/)
6424  !
6425 940 FORMAT (/' Time interval : '/ &
6426  ' --------------------------------------------------')
6427 941 FORMAT ( ' Starting time : ',a)
6428 942 FORMAT ( ' Ending time : ',a/)
6429 943 FORMAT (/' Model settings : '/ &
6430  ' --------------------------------------------------')
6431 944 FORMAT ( ' Masking computation in nesting : ',a)
6432 945 FORMAT ( ' Masking output in nesting : ',a/)
6433  !
6434 950 FORMAT (/' Output requests : (',a,') '/ &
6435  ' ==================================================')
6436 951 FORMAT (/' Type',i2,' : ',a/ &
6437  ' -----------------------------------------')
6438 952 FORMAT ( ' From : ',a)
6439 953 FORMAT ( ' To : ',a)
6440 954 FORMAT ( ' Interval : ',a/)
6441 955 FORMAT ( ' Fields : ',a)
6442 956 FORMAT ( ' ',a)
6443 957 FORMAT ( ' Point 1 : ',2e14.6,2x,a)
6444 958 FORMAT ( ' ',i6,' : ',2e14.6,2x,a)
6445 959 FORMAT ( ' No points defined')
6446 960 FORMAT ( ' The file with ',a,' data is ',a,'.')
6447 961 FORMAT ( ' IX fls : ',3i6/ &
6448  ' IY fls : ',3i6)
6449 962 FORMAT (/' Output request for model ',a,' (nr',i3,') '/ &
6450  ' ==================================================')
6451 963 FORMAT ( ' Output disabled')
6452  !
6453 965 FORMAT (/' Grid movement data (!/MGP, !/MGW): '/ &
6454  ' --------------------------------------------------')
6455 966 FORMAT ( ' ',a)
6456 967 FORMAT ( ' ',i6,2x,a)
6457 968 FORMAT ( ' ',i6,i11.8,i7.6,2f8.2)
6458  !
6459 970 FORMAT(//' Assigning resources : '/ &
6460  ' --------------------------------------------------')
6461 971 FORMAT ( ' ',a)
6462 972 FORMAT ( ' Process ',i5.5,' reserved for all point output.')
6463 973 FORMAT ( ' Processes ',i5.5,' through ',i5.5,' [',i3,']', &
6464  ' reserved for output.')
6465 974 FORMAT (/ &
6466  5x,' grid comp. grd pnt trk rst bpt prt'/ &
6467  5x,' ------------------------------------------------------', &
6468  '-------------')
6469 975 FORMAT (5x,' ',a10,2x,i5.5,'-',i5.5,6(2x,a5))
6470 976 FORMAT(5x,' -------------------------------------------------', &
6471  '------------------')
6472 977 FORMAT (5x,' Unified point output at ',i5.5)
6473 1974 FORMAT (' Resource assignement (processes) : '/ &
6474  ' grid comp. grd pnt trk rst bpt prt'/ &
6475  ' ------------------------------------------------------', &
6476  '-------------')
6477 1975 FORMAT (' ',a10,2x,i5.5,'-',i5.5,6(2x,a5))
6478 1976 FORMAT (' ---------------------------------------------------', &
6479  '----------------')
6480 1977 FORMAT (' Unified point output at ',i5.5)
6481  !
6482 980 FORMAT(//' Initializations :'/ &
6483  ' --------------------------------------------------')
6484 981 FORMAT ( ' Model number',i3,' [',a,']')
6485 982 FORMAT ( ' Initializing wave model ...')
6486 983 FORMAT ( ' Initializing model input ...')
6487 984 FORMAT ( ' ',a,': file not needed')
6488 985 FORMAT ( ' ',a,': file OK')
6489 986 FORMAT ( ' Unified point output [',a,']')
6490 987 FORMAT ( ' Initializing grids ...')
6491 988 FORMAT ( ' Input data grid',i3,' [',a,']')
6492  !
6493 #ifdef W3_MPRF
6494 990 FORMAT (1x,3f12.3,' WMINITNML',1x,a)
6495 #endif
6496  !
6497 998 FORMAT ( ' Running the model :'/ &
6498  ' --------------------------------------------------'/)
6499 999 FORMAT ( ' ========== END OF MWW3 INITIALIZATION (WMINITNML) ===', &
6500  '============================'/)
6501  !
6502 1003 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6503  ' PREMATURE END OF POINT FILE'/)
6504  !
6505 1104 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6506  ' ERROR IN OPENING POINT FILE'/ &
6507  ' IOSTAT =',i5/)
6508  !
6509 1004 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6510  ' ERROR IN READING FROM POINT FILE'/ &
6511  ' IOSTAT =',i5/)
6512 1010 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6513  ' ERROR IN OPENING LOG FILE'/ &
6514  ' IOSTAT =',i5/)
6515 1011 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6516  ' ERROR IN OPENING TEST FILE'/ &
6517  ' IOSTAT =',i5/)
6518 1020 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6519  ' ILLEGAL NUMBER OF GRIDS ( < 1 ) '/)
6520 1021 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6521  ' ILLEGAL NUMBER OF INPUT GRIDS ( < 0 ) '/)
6522 1030 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6523  ' INPUT GRID NAME NOT FOUND '/ &
6524  ' WAVE GRID : ',a/ &
6525  ' INPUT NAME : ',a/)
6526 1031 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : *** '/ &
6527  ' REQUESTED INPUT TYPE NOT FOUND IN INPUT GRID '/ &
6528  ' INPUT GRID : ',a/ &
6529  ' INPUT TYPE : ',i8/)
6530 1032 FORMAT (/' *** WAVEWATCH III WARNING IN WMINITNML : *** '/ &
6531  ' INPUT GRID ',a,' NOT USED '/)
6532 1040 FORMAT ( ' *** WAVEWATCH III WARNING IN W3MLTI : ***'/ &
6533  ' POSSIBLE LOAD IMBALANCE GROUP',i3,' :',2i6/)
6534  !1040 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
6535  ! ' ILLEGAL TIME INTERVAL'/)
6536 1050 FORMAT (/' *** WAVEWATCH III WARNING IN W3MLTI : ***'/ &
6537  ' UNIFIED POINT OUTPUT BUT NO OUTPUT'/ &
6538  ' UNIFIED POINT OUTPUT DISABLED'/)
6539 1051 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
6540  ' ILLEGAL MODEL ID [',a,']'/)
6541 1052 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
6542  ' ILLEGAL OUTPUT TYPE',i10/)
6543 1053 FORMAT (/' *** WAVEWATCH III WARNING IN W3MLTI : ***'/ &
6544  ' OUTPUT POINTS FOR INDIVIDUAL GRIDS CANNOT BE DEFINED'/ &
6545  ' WHEN UNIFIED POINT OUTPUT IS REQUESTED'/)
6546 1054 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
6547  ' POINT OUTPUT ACTIVATED, BUT NO POINTS DEFINED'/)
6548 1055 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
6549  ' POINT OUTPUT ACTIVATED, BUT NO FILE DEFINED'/)
6550 1060 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
6551  ' NO MOVING GRID DATA PRESENT'/)
6552 1061 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
6553  ' TOO MANY HOMOGENEOUS FIELDS : ',a,1x,i4/)
6554 1062 FORMAT (/' *** WAVEWATCH III ERROR IN W3MLTI : ***'/ &
6555  ' HOMOGENEOUS NAME NOT RECOGNIZED : ', a/)
6556 1070 FORMAT (/' *** WAVEWATCH III ERROR IN WMINITNML : ***'/ &
6557  ' ALL GRIDS ARE NOT USING THE SAME COORDINATE SYSTEM'/)
6558 1080 FORMAT (/' *** BOUNDARY DATA READ, WILL NOT DUMP, GRID :',i4, &
6559  ' ***')
6560 1081 FORMAT (/' *** NO BOUNDARY DATA TO DUMP, GRID :',i4,' ***')
6561 1082 FORMAT ( ' No boundary data dump for grid',i3/)
6562  !
6563 #ifdef W3_T
6564 9000 FORMAT ( ' TEST WMINITNML : UNIT NUMBERS : ',5i6/ &
6565  ' INPUT FILE NAME : ',a)
6566 #endif
6567  !
6568 #ifdef W3_T
6569 9020 FORMAT ( ' TEST WMINITNML : UNIT NUMBERS FOR GRIDS (',a,')'/ &
6570  15x,'GRID MDS(1-15)',43x,'NTRACE')
6571 9021 FORMAT (14x,16i4)
6572 9022 FORMAT ( ' TEST WMINITNML : UNIT NUMBERS FOR INTPUT FILES'/ &
6573  15x,'GRID MDSF(JFIRST-9)')
6574 9030 FORMAT ( ' TEST WMINITNML : FILE EXTENSIONS, INPUT FLAGS,', &
6575  ' RANK AND GROUP, PROC RANGE')
6576 9031 FORMAT ( ' ',i3,1x,a,20l2,2i4,2f6.2)
6577 9032 FORMAT ( ' TEST WMINITNML : PROCESSED RANK NUMBERS')
6578 9033 FORMAT ( ' ',i3,1x,a,1x,i4)
6579 9034 FORMAT ( ' TEST WMINITNML : NUMBER OF GROUPS :',i4)
6580 9035 FORMAT ( ' TEST WMINITNML : SIZE OF GROUPS :',20i3)
6581 9036 FORMAT ( ' TEST WMINITNML : GROUP SIZE AND COMPONENTS :')
6582 9037 FORMAT ( ' ',2i3,':',20i3)
6583 #endif
6584  !
6585 #ifdef W3_T
6586 9050 FORMAT ( ' TEST WMINITNML : GRID NUMBER',i3,' =================')
6587 9051 FORMAT ( ' TEST WMINITNML : ODAT : ',i9.8,i7.6,i7,i9.8,i7.6, &
6588  5(/24x,i9.8,i7.6,i7,i9.8,i7.6) )
6589 9052 FORMAT ( ' TEST WMINITNML : FLGRD : ',5(5l2,1x)/24x,5(5l2,1x))
6590 9053 FORMAT ( ' TEST WMINITNML : OUTFF : ',i9.8 &
6591  5(/24x,i9.8) )
6592 #endif
6593  !
6594 #ifdef W3_T
6595 9060 FORMAT ( ' TEST WMINITNML : GRID MOVEMENT DATA')
6596 9061 FORMAT ( ' ',i8.8,i7,1x,2f8.2)
6597 #endif
6598  !
6599 #ifdef W3_T
6600 9070 FORMAT ( ' TEST WMINITNML : ALLPRC ')
6601 9071 FORMAT ( ' ',i3,' : ',250i3)
6602 8042 FORMAT ( ' TEST WMINITNML : MODMAP ')
6603 8043 FORMAT ( ' TEST WMINITNML : LOADMP ')
6604 8044 FORMAT ( ' ',i3,' : ',250i2)
6605 #endif
6606  !
6607 #ifdef W3_T
6608 9080 FORMAT ( ' TEST WMINITNML : MODEL INITIALIZATION')
6609 9081 FORMAT ( ' MODEL AND TIME :',i4,i10.8,i8.6)
6610 9082 FORMAT ( ' STATUS AND TIMES :',i4,3(i10.8,i8.6))
6611 9083 FORMAT ( ' TEST WMINITNML : IDINP AFTER INITIALIZATION :')
6612 9084 FORMAT ( ' ',i4,17(2x,a3))
6613 #endif
6614  !/
6615  !/ End of WMINITNML ----------------------------------------------------- /
6616  !/
6617  END SUBROUTINE wminitnml
6618 
6619 
6620 
6621 
6622 
6623  !/
6624  !/ End of module WMINITMD -------------------------------------------- /
6625  !/
6626 END MODULE wminitmd
w3nmlmultimd::nml_output_date_t
Definition: w3nmlmultimd.F90:172
wmmdatmd::tdata
integer, dimension(:,:), allocatable tdata
TDATA.
Definition: wmmdatmd.F90:365
w3gdatmd::nk
integer, pointer nk
Definition: w3gdatmd.F90:1230
w3odatmd::iostyp
integer iostyp
Definition: w3odatmd.F90:321
w3gdatmd::nseal
integer, pointer nseal
Definition: w3gdatmd.F90:1097
w3odatmd::flbpo
logical, pointer flbpo
Definition: w3odatmd.F90:546
w3timemd::dsec21
real function dsec21(TIME1, TIME2)
Definition: w3timemd.F90:333
w3servmd::nextln
subroutine nextln(CHCKC, NDSI, NDSE)
Definition: w3servmd.F90:222
w3nmlmultimd::nml_homog_count_t
Definition: w3nmlmultimd.F90:188
include
cmake src_list cmake include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_switches.cmake) check_switches("$
Definition: CMakeLists.txt:15
wmmdatmd::mdse
integer mdse
MDSE.
Definition: wmmdatmd.F90:316
w3idatmd::inflags1
logical, dimension(:), pointer inflags1
Definition: w3idatmd.F90:260
wminitmd
Initialization of the multi-grid wave model.
Definition: wminitmd.F90:18
wmiopomd
Module for generating a single point output file for a multi- grid model implementation.
Definition: wmiopomd.F90:15
wmmdatmd::mdsi
integer mdsi
MDSI.
Definition: wmmdatmd.F90:312
wmgridmd::wmrspc
subroutine wmrspc
Generate map with flags for need of spectral grid conversion between models.
Definition: wmgridmd.F90:5139
w3odatmd::upproc
logical upproc
Definition: w3odatmd.F90:333
w3gdatmd::ygrd
double precision, dimension(:,:), pointer ygrd
Definition: w3gdatmd.F90:1205
w3gdatmd::gsu
type(t_gsu), pointer gsu
Definition: w3gdatmd.F90:1226
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
wmunitmd::wmudmp
subroutine wmudmp(NDS, IREQ)
Display assigned unit number information from private data base.
Definition: wmunitmd.F90:339
w3gdatmd::nspec
integer, pointer nspec
Definition: w3gdatmd.F90:1230
wmmdatmd::stime
integer, dimension(2) stime
STIME.
Definition: wmmdatmd.F90:328
wmmdatmd::dmv
real, dimension(:,:), pointer dmv
DMV.
Definition: wmmdatmd.F90:551
wmmdatmd::mdsupa
integer mdsupa
MDSUPA.
Definition: wmmdatmd.F90:319
w3timemd::tdiff
real function tdiff(T1, T2)
Definition: w3timemd.F90:576
wmmdatmd::clkfin
real clkfin
CLKFIN.
Definition: wmmdatmd.F90:376
w3gdatmd::dxdq
real, dimension(:,:), pointer dxdq
Definition: w3gdatmd.F90:1206
w3nmlmultimd::nml_homog_input_t
Definition: w3nmlmultimd.F90:193
w3gdatmd::flagst
logical, dimension(:), pointer flagst
Definition: w3gdatmd.F90:1221
w3nmlmultimd::nml_model_grid_t
Definition: w3nmlmultimd.F90:73
wmgridmd::wmglow
subroutine wmglow(FLRBPI)
Determine relations to lower ranked grids for each grid.
Definition: wmgridmd.F90:152
wmmdatmd::croot
integer, pointer croot
CROOT.
Definition: wmmdatmd.F90:545
w3wdatmd
Define data structures to set up wave model dynamic data for several models simultaneously.
Definition: w3wdatmd.F90:18
w3nmlmultimd::nml_output_type_t
Definition: w3nmlmultimd.F90:150
wmmdatmd::nmpscr
integer nmpscr
NMPSCR.
Definition: wmmdatmd.F90:324
w3adatmd::wadats
type(wadat), dimension(:), allocatable, target wadats
Definition: w3adatmd.F90:571
wmmdatmd::mdso
integer mdso
MDSO.
Definition: wmmdatmd.F90:313
w3odatmd::nopts
integer, pointer nopts
Definition: w3odatmd.F90:484
w3idatmd::inflags2
logical, dimension(:), pointer inflags2
Definition: w3idatmd.F90:260
w3nmlmultimd::nml_input_grid_t
Definition: w3nmlmultimd.F90:106
wmmdatmd::tmax
integer, dimension(:,:), allocatable tmax
TMAX.
Definition: wmmdatmd.F90:363
w3idatmd::inputs
type(input), dimension(:), allocatable, target inputs
Definition: w3idatmd.F90:232
wminitmd::wminit
subroutine wminit(IDSI, IDSO, IDSS, IDST, IDSE, IFNAME, MPI_COMM, PREAMB)
Initialize multi-grid version of WAVEWATCH III.
Definition: wminitmd.F90:131
constants::tstout
logical, parameter tstout
TSTOUT Flag for generation of test files.
Definition: constants.F90:56
w3odatmd::dtout
real, dimension(:), pointer dtout
Definition: w3odatmd.F90:467
w3gsrumd
Definition: w3gsrumd.F90:17
w3gdatmd::xgrd
double precision, dimension(:,:), pointer xgrd
Definition: w3gdatmd.F90:1205
w3gdatmd::sy
real, pointer sy
Definition: w3gdatmd.F90:1183
wmmdatmd::nrgrp
integer nrgrp
NRGRP.
Definition: wmmdatmd.F90:332
wmmdatmd::nmv
integer, pointer nmv
NMV.
Definition: wmmdatmd.F90:537
wminitmd::wminitnml
subroutine wminitnml(IDSI, IDSO, IDSS, IDST, IDSE, IFNAME, MPI_COMM, PREAMB)
Initialize multi-grid version of WAVEWATCH III.
Definition: wminitmd.F90:3502
w3odatmd::iaproc
integer, pointer iaproc
Definition: w3odatmd.F90:457
wmmdatmd::tsync
integer, dimension(:,:), allocatable tsync
TSYNC.
Definition: wmmdatmd.F90:362
w3odatmd::ngrpp
integer, parameter ngrpp
Definition: w3odatmd.F90:324
wmmdatmd::mdss
integer mdss
MDSS.
Definition: wmmdatmd.F90:314
w3wdatmd::time
integer, dimension(:), pointer time
Definition: w3wdatmd.F90:172
w3gdatmd::grids
type(grid), dimension(:), allocatable, target grids
Definition: w3gdatmd.F90:1088
constants::is_esmf_component
logical is_esmf_component
IS_ESMF_COMPONENT Flag for model invoked via ESMF.
Definition: constants.F90:109
w3odatmd::unipts
logical unipts
Definition: w3odatmd.F90:333
w3gdatmd::ny
integer, pointer ny
Definition: w3gdatmd.F90:1097
wmmdatmd::mpi_comm_grd
integer, pointer mpi_comm_grd
MPI_COMM_GRD.
Definition: wmmdatmd.F90:543
w3gdatmd::dydq
real, dimension(:,:), pointer dydq
Definition: w3gdatmd.F90:1207
wmmdatmd::grdeql
integer, dimension(:,:), allocatable grdeql
GRDEQL.
Definition: wmmdatmd.F90:357
wmmdatmd::bcdump
logical, dimension(:), allocatable bcdump
BCDUMP.
Definition: wmmdatmd.F90:382
wmmdatmd::nmplog
integer nmplog
NMPLOG.
Definition: wmmdatmd.F90:323
w3odatmd::fnmpre
character(len=80) fnmpre
Definition: w3odatmd.F90:330
w3odatmd::ofiles
integer, dimension(:), pointer ofiles
Definition: w3odatmd.F90:466
wminiomd
Internal IO routines for the multi-grid model.
Definition: wminiomd.F90:14
wmunitmd::wmuset
subroutine wmuset(NDSE, NDST, NDS, FLAG, TYPE, NAME, DESC)
Directly set information for a unit number in the data structure.
Definition: wmunitmd.F90:497
w3odatmd::nbi
integer, pointer nbi
Definition: w3odatmd.F90:530
wmunitmd::wmuget
subroutine wmuget(NDSE, NDST, NDS, TYPE, NR)
Find a free unit number for a given file type.
Definition: wmunitmd.F90:667
w3odatmd::flbpi
logical, pointer flbpi
Definition: w3odatmd.F90:546
wmmdatmd::improc
integer improc
IMPROC.
Definition: wmmdatmd.F90:322
w3odatmd::napbpt
integer, pointer napbpt
Definition: w3odatmd.F90:457
w3gdatmd::th
real, dimension(:), pointer th
Definition: w3gdatmd.F90:1234
w3gdatmd::w3dimx
subroutine w3dimx(IMOD, MX, MY, MSEA, NDSE, NDST ifdef W3_SMC
Definition: w3gdatmd.F90:1582
w3gdatmd::hqfac
real, dimension(:,:), pointer hqfac
Definition: w3gdatmd.F90:1212
wmgridmd::wmgeql
subroutine wmgeql
Determine relations to same ranked grids for each grid.
Definition: wmgridmd.F90:3709
w3gdatmd::w3setg
subroutine w3setg(IMOD, NDSE, NDST)
Definition: w3gdatmd.F90:2152
wmmdatmd::grdhgh
integer, dimension(:,:), allocatable grdhgh
GRDHGH.
Definition: wmmdatmd.F90:356
wmiopomd::wmiopp
subroutine wmiopp(NPT, XPT, YPT, PNAMES)
Initialization for unified point output.
Definition: wmiopomd.F90:110
wmmdatmd::ingrp
integer, dimension(:,:), allocatable ingrp
INGRP.
Definition: wmmdatmd.F90:355
w3servmd::wwtime
subroutine wwtime(STRNG)
Definition: w3servmd.F90:664
w3odatmd::ndse
integer, pointer ndse
Definition: w3odatmd.F90:456
w3gdatmd::nbsmc
integer, pointer nbsmc
Definition: w3gdatmd.F90:1168
w3gdatmd::nufc
integer, pointer nufc
Definition: w3gdatmd.F90:1167
wmmdatmd::toutp
integer, dimension(:,:), allocatable toutp
TOUTP.
Definition: wmmdatmd.F90:364
wmmdatmd::nmproc
integer nmproc
NMPROC.
Definition: wmmdatmd.F90:321
w3gdatmd::w3dims
subroutine w3dims(IMOD, MK, MTH, NDSE, NDST)
Definition: w3gdatmd.F90:1925
w3nmlmultimd::w3nmlmultidef
subroutine w3nmlmultidef(MPI_COMM, NDSI, INFILE, NML_DOMAIN, IERR)
Definition: w3nmlmultimd.F90:211
w3adatmd::w3seta
subroutine w3seta(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3adatmd.F90:2645
w3odatmd::tonext
integer, dimension(:,:), pointer tonext
Definition: w3odatmd.F90:464
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
wmmdatmd::mdsp
integer mdsp
MDSP.
Definition: wmmdatmd.F90:341
wmmdatmd::flghg1
logical flghg1
FLGHG1.
Definition: wmmdatmd.F90:379
w3gdatmd::nvfc
integer, pointer nvfc
Definition: w3gdatmd.F90:1167
w3initmd::w3init
subroutine w3init(IMOD, IsMulti, FEXT, MDS, MTRACE, ODAT, FLGRD, FLGR2, FLGD, FLG2, NPT, XPT, YPT, PNAMES, IPRT, PRTFRM, MPI_COMM, FLAGSTIDEIN)
Initialize WAVEWATCH III.
Definition: w3initmd.F90:164
w3nmlmultimd::w3nmlmulticonf
subroutine w3nmlmulticonf(MPI_COMM, NDSI, INFILE, NML_DOMAIN, NML_INPUT_GRID, NML_MODEL_GRID, NML_OUTPUT_TYPE, NML_OUTPUT_DATE, NML_HOMOG_COUNT, NML_HOMOG_INPUT, IERR)
Definition: w3nmlmultimd.F90:349
w3gdatmd::x0
real, pointer x0
Definition: w3gdatmd.F90:1183
w3gdatmd::nsea
integer, pointer nsea
Definition: w3gdatmd.F90:1097
wmmdatmd::amv
real, dimension(:,:), pointer amv
AMV.
Definition: wmmdatmd.F90:550
w3gdatmd::dydp
real, dimension(:,:), pointer dydp
Definition: w3gdatmd.F90:1207
wmmdatmd::mpi_comm_bct
integer, pointer mpi_comm_bct
MPI_COMM_BCT.
Definition: wmmdatmd.F90:544
w3servmd
Definition: w3servmd.F90:3
w3gdatmd::dxdp
real, dimension(:,:), pointer dxdp
Definition: w3gdatmd.F90:1206
wmmdatmd::idinp
character(len=3), dimension(:,:), allocatable idinp
IDINP.
Definition: wmmdatmd.F90:386
wmgridmd::wmghgh
subroutine wmghgh
Determine relation to higher ranked grids for each grid.
Definition: wmgridmd.F90:1100
w3gdatmd::nbac
integer, pointer nbac
Definition: w3gdatmd.F90:1168
w3timemd::tick21
subroutine tick21(TIME, DTIME)
Definition: w3timemd.F90:84
wmmdatmd::nrgrd
integer nrgrd
NRGRD.
Definition: wmmdatmd.F90:330
w3wdatmd::w3setw
subroutine w3setw(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3wdatmd.F90:660
wmmdatmd::tmv
integer, dimension(:,:,:), pointer tmv
TMV.
Definition: wmmdatmd.F90:538
wmmdatmd::ngrpsmc
integer ngrpsmc
NGRPSMC.
Definition: wmmdatmd.F90:334
w3odatmd::w3seto
subroutine w3seto(IMOD, NDSERR, NDSTST)
Definition: w3odatmd.F90:1523
w3timemd::stme21
subroutine stme21(TIME, DTME21)
Definition: w3timemd.F90:682
wmmdatmd::nmpupt
integer nmpupt
NMPUPT.
Definition: wmmdatmd.F90:327
w3gdatmd::nth
integer, pointer nth
Definition: w3gdatmd.F90:1230
w3odatmd
Definition: w3odatmd.F90:3
wmmdatmd::grdlow
integer, dimension(:,:), allocatable grdlow
GRDLOW.
Definition: wmmdatmd.F90:359
w3adatmd::w3naux
subroutine w3naux(NDSE, NDST)
Set up the number of grids to be used.
Definition: w3adatmd.F90:704
w3odatmd::nds
integer, dimension(:), pointer nds
Definition: w3odatmd.F90:464
wmunitmd::wmuinq
subroutine wmuinq(NDSE, NDST, NDS)
Update data base information for a given unit number.
Definition: wmunitmd.F90:839
wmgridmd
Routines to determine and process grid dependencies in the multi-grid wave model.
Definition: wmgridmd.F90:19
w3timemd::prinit
subroutine prinit
Definition: w3timemd.F90:930
w3odatmd::tolast
integer, dimension(:,:), pointer tolast
Definition: w3odatmd.F90:464
wmmdatmd::grstat
integer, dimension(:), allocatable grstat
GRSTAT.
Definition: wmmdatmd.F90:366
w3odatmd::nfbpo
integer, pointer nfbpo
Definition: w3odatmd.F90:530
w3odatmd::naproc
integer, pointer naproc
Definition: w3odatmd.F90:457
wmmdatmd::allprc
integer, dimension(:,:), allocatable allprc
ALLPRC.
Definition: wmmdatmd.F90:360
wmmdatmd::fbcast
logical, pointer fbcast
FBCAST.
Definition: wmmdatmd.F90:568
w3nmlmultimd::nml_domain_t
Definition: w3nmlmultimd.F90:27
wmmdatmd::nmperr
integer nmperr
NMPERR.
Definition: wmmdatmd.F90:326
w3iogrmd::w3iogr
subroutine w3iogr(INXOUT, NDSM, IMOD, FEXT ifdef W3_ASCII
Reading and writing of the model definition file.
Definition: w3iogrmd.F90:117
wmmdatmd::grgrp
integer, dimension(:), allocatable grgrp
GRGRP.
Definition: wmmdatmd.F90:354
wmmdatmd::nrinp
integer nrinp
NRINP.
Definition: wmmdatmd.F90:331
w3idatmd::w3seti
subroutine w3seti(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3idatmd.F90:819
w3gdatmd::smctype
integer, parameter smctype
Definition: w3gdatmd.F90:627
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
wmgridmd::wmsmceql
subroutine wmsmceql
Determine relations to same ranked SMC grids for each grid.
Definition: wmgridmd.F90:5285
wmunitmd::wmuini
subroutine wmuini(NDSE, NDST)
Allocate and initialize arrays of module.
Definition: wmunitmd.F90:126
wmmdatmd::mdst
integer mdst
MDST.
Definition: wmmdatmd.F90:315
w3nmlmultimd
Definition: w3nmlmultimd.F90:3
w3gdatmd::iclose
integer, pointer iclose
Definition: w3gdatmd.F90:1096
w3odatmd::napprt
integer, pointer napprt
Definition: w3odatmd.F90:457
w3gdatmd::fr1
real, pointer fr1
Definition: w3gdatmd.F90:1232
w3odatmd::naptrk
integer, pointer naptrk
Definition: w3odatmd.F90:457
w3timemd::prtime
subroutine prtime(PTIME)
Definition: w3timemd.F90:990
w3odatmd::flout
logical, dimension(:), pointer flout
Definition: w3odatmd.F90:468
w3iogomd
Gridded output of mean wave parameters.
Definition: w3iogomd.F90:15
w3servmd::strace
subroutine strace(IENT, SNAME)
Definition: w3servmd.F90:148
wmmdatmd::wmsetm
subroutine wmsetm(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: wmmdatmd.F90:1169
w3gdatmd::gtype
integer, pointer gtype
Definition: w3gdatmd.F90:1094
wminiomd::wmiobf
subroutine wmiobf(IMOD)
Finalize staging of internal boundary data in the data structure BPSTGE (MPI only).
Definition: wminiomd.F90:1212
w3idatmd
Define data structures to set up wave model input data for several models simultaneously.
Definition: w3idatmd.F90:16
wmmdatmd::wmndat
subroutine wmndat(NDSE, NDST)
Set up the number of grids to be used.
Definition: wmmdatmd.F90:584
w3gdatmd::w3nmod
subroutine w3nmod(NUMBER, NDSE, NDST, NAUX)
Definition: w3gdatmd.F90:1433
wmmdatmd::wmdimd
subroutine wmdimd(IMOD, NDSE, NDST, J)
Initialize an individual data grid at the proper dimensions.
Definition: wmmdatmd.F90:787
w3gdatmd::xfr
real, pointer xfr
Definition: w3gdatmd.F90:1232
wmmdatmd::grank
integer, dimension(:), allocatable grank
GRANK.
Definition: wmmdatmd.F90:353
w3odatmd::nappnt
integer, pointer nappnt
Definition: w3odatmd.F90:457
w3gdatmd::y0
real, pointer y0
Definition: w3gdatmd.F90:1183
w3servmd::wwdate
subroutine wwdate(STRNG)
Definition: w3servmd.F90:595
w3odatmd::napfld
integer, pointer napfld
Definition: w3odatmd.F90:457
w3gdatmd::hpfac
real, dimension(:,:), pointer hpfac
Definition: w3gdatmd.F90:1211
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
wmmdatmd::clkdt2
integer, dimension(8) clkdt2
CLKDT2.
Definition: wmmdatmd.F90:337
w3idatmd::iinit
logical, pointer iinit
Definition: w3idatmd.F90:259
w3gdatmd::sx
real, pointer sx
Definition: w3gdatmd.F90:1183
w3odatmd::ndst
integer, pointer ndst
Definition: w3odatmd.F90:456
w3gdatmd::narc
integer, pointer narc
Definition: w3gdatmd.F90:1168
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
wmmdatmd
Define data structures to set up wave model dynamic data for several models simultaneously.
Definition: wmmdatmd.F90:16
wmmdatmd::flghg2
logical flghg2
FLGHG2.
Definition: wmmdatmd.F90:380
w3servmd::extcde
subroutine extcde(IEXIT, UNIT, MSG, FILE, LINE, COMM)
Definition: w3servmd.F90:736
w3odatmd::w3nout
subroutine w3nout(NDSERR, NDSTST)
Definition: w3odatmd.F90:561
w3odatmd::outpts
type(output), dimension(:), allocatable, target outpts
Definition: w3odatmd.F90:452
w3gdatmd::gridshift
real(8), pointer gridshift
Definition: w3gdatmd.F90:1189
w3gdatmd::ncel
integer, pointer ncel
Definition: w3gdatmd.F90:1167
w3servmd::itrace
subroutine itrace(NDS, NMAX)
Definition: w3servmd.F90:91
w3fldsmd::w3fldo
subroutine w3fldo(INXOUT, IDFLD, NDS, NDST, NDSE, NX, NY, GTYPE, IERR, FEXT, FPRE, FHDR, TIDEFLAGIN)
Definition: w3fldsmd.F90:90
w3gdatmd::nrlv
integer, pointer nrlv
Definition: w3gdatmd.F90:1167
wmmdatmd::nmvmax
integer nmvmax
NMVMAX.
Definition: wmmdatmd.F90:333
wmmdatmd::inpmap
integer, dimension(:,:), allocatable inpmap
INPMAP.
Definition: wmmdatmd.F90:368
w3gdatmd::nx
integer, pointer nx
Definition: w3gdatmd.F90:1097
w3timemd
Definition: w3timemd.F90:3
wmmdatmd::clkdt1
integer, dimension(8) clkdt1
CLKDT1.
Definition: wmmdatmd.F90:336
w3idatmd::w3ninp
subroutine w3ninp(NDSE, NDST)
Set up the number of grids to be used.
Definition: w3idatmd.F90:283
wminiomd::wmiobs
subroutine wmiobs(IMOD)
Stage internal boundary data in the data structure BPSTGE.
Definition: wminiomd.F90:105
wminiomd::wmiobg
subroutine wmiobg(IMOD, DONE)
Gather internal boundary data for a given model.
Definition: wminiomd.F90:497
w3gdatmd::dtcfl
real, pointer dtcfl
Definition: w3gdatmd.F90:1183
w3idatmd::w3dimi
subroutine w3dimi(IMOD, NDSE, NDST, FLAGSTIDEIN)
Initialize an individual data grid at the proper dimensions.
Definition: w3idatmd.F90:435
wmmdatmd::mdsf
integer, dimension(:,:), allocatable mdsf
MDSF.
Definition: wmmdatmd.F90:352
wmunitmd
Dynamic assignement of unit numbers for the multi-grid wave model.
Definition: wmunitmd.F90:18
w3gdatmd::mapsta
integer, dimension(:,:), pointer mapsta
Definition: w3gdatmd.F90:1163
wmmdatmd::dtres
real, dimension(:), allocatable dtres
DTRES.
Definition: wmmdatmd.F90:377
w3initmd
Contains module W3INITMD.
Definition: w3initmd.F90:14
wmmdatmd::modmap
integer, dimension(:,:), allocatable modmap
MODMAP.
Definition: wmmdatmd.F90:361
w3initmd::wwver
character(len=10), parameter wwver
Definition: w3initmd.F90:129
w3gdatmd::mapst2
integer, dimension(:,:), pointer mapst2
Definition: w3gdatmd.F90:1163
wmmdatmd::etime
integer, dimension(2) etime
ETIME.
Definition: wmmdatmd.F90:329
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
wmmdatmd::mpi_comm_mwave
integer mpi_comm_mwave
MPI_COMM_MWAVE.
Definition: wmmdatmd.F90:344
w3fldsmd
Definition: w3fldsmd.F90:3
w3gdatmd::flagll
logical, pointer flagll
Definition: w3gdatmd.F90:1219
wmmdatmd::mdsup
integer mdsup
MDSUP.
Definition: wmmdatmd.F90:317
w3gdatmd::filext
character(len=13), pointer filext
Definition: w3gdatmd.F90:1224