WAVEWATCH III  beta 0.0.1
ww3_bound.F90
Go to the documentation of this file.
1 
5 
6 #include "w3macros.h"
7 !/ ------------------------------------------------------------------- /
15 PROGRAM w3bound
16  !/
17  !/ +-----------------------------------+
18  !/ | WAVEWATCH III NOAA/NCEP |
19  !/ | F. Ardhuin |
20  !/ | FORTRAN 90 |
21  !/ | Last update : 27-May-2021 |
22  !/ +-----------------------------------+
23  !/
24  !/ 28-Aug-2012 : adaptation from SHOM/Ifremer code ( version 4.08 )
25  !/ 01-Nov-2012 : Bug correction for NKI != NK ( version 4.08 )
26  !/ 20-Oct-2016 : Error statement updates ( version 5.15 )
27  !/ 21-Jul-2020 : Support rotated pole grid ( version 7.11 )
28  !/ Chris Bunney, UKMO.
29  !/ 27-May-2021 : Add namelist feature ( version 7.XX )
30  !/
31  !/ Copyright 2012-2012 National Weather Service (NWS),
32  !/ National Oceanic and Atmospheric Administration. All rights
33  !/ reserved. WAVEWATCH III is a trademark of the NWS.
34  !/ No unauthorized use without permission.
35  !/
36  ! 1. Purpose :
37  !
38  ! Combines spectra files into a nest.ww3 file for boundary conditions
39  !
40  ! 2. Method :
41  !
42  ! Finds nearest points and performs linear interpolation
43  !
44  ! The initial conditions are written to the restart.ww3 using the
45  ! subroutine W3IORS. Note that the name of the restart file is set
46  ! in W3IORS.
47  !
48  ! 3. Parameters :
49  !
50  ! Local parameters.
51  ! ----------------------------------------------------------------
52  ! NDSI Int. Input unit number ("ww3_bound.inp").
53  ! ITYPE Int. Type of data
54  ! ----------------------------------------------------------------
55  !
56  ! 4. Subroutines used :
57  !
58  ! Name Type Module Description
59  ! ----------------------------------------------------------------
60  ! STRACE Subr. Id. Subroutine tracing.
61  ! NEXTLN Subr. Id. Get next line from input filw
62  ! EXTCDE Subr. Id. Abort program as graceful as possible.
63  ! WAVNU1 Subr. W3DISPMD Solve dispersion relation.
64  ! W3IOGR Subr. W3IOGRMD Reading/writing model definition file.
65  ! W3EQTOLL Subr W3SERVMD Convert coordinates from rotated pole.
66  ! ----------------------------------------------------------------
67  !
68  ! 5. Called by :
69  !
70  ! None, stand-alone program.
71  !
72  ! 6. Error messages :
73  !
74  ! 7. Remarks :
75  !
76  ! - Can be used also to diagnose contents of nest.ww3 file
77  ! in read mode
78  !
79  ! - Input spectra are assumed to be formulated on a standard
80  ! pole. However, the model grid can be on a rotated pole.
81  !
82  ! 8. Structure :
83  !
84  ! ----------------------------------------------------
85  ! 1.a Set up data structures.
86  ! ( W3NMOD , W3NDAT , W3NOUT
87  ! W3SETG , W3SETW , W3SETO )
88  ! b I-O setup.
89  ! ....
90  ! 9. Convert energy to action
91  ! 10. Write restart file. ( W3IORS )
92  ! ----------------------------------------------------
93  !
94  ! 9. Switches :
95  !
96  ! !/SHRD Switch for shared / distributed memory architecture.
97  ! !/DIST Id.
98  !
99  ! !/SHRD Switch for message passing method.
100  ! !/MPI Id.
101  !
102  ! !/S Enable subroutine tracing.
103  !
104  ! !/O4 Output normalized 1-D energy spectrum.
105  ! !/O5 Output normalized 2-D energy spectrum.
106  ! !/O6 Output normalized wave heights (not MPP adapted).
107  !
108  ! 10. Source code :
109  !
110  !/ ------------------------------------------------------------------- /
111  USE constants
112  USE w3wdatmd, ONLY: w3ndat, w3setw
113  USE w3adatmd, ONLY: w3naux, w3seta
114  USE w3odatmd, ONLY: w3nout, w3seto, flbpi
115 
116  USE w3gdatmd, ONLY: nk, nth, xfr, fr1, gname, w3nmod, w3setg, &
117  nsea, mapsta, gtype, xgrd, ygrd, x0, y0, &
119 #ifdef W3_RTD
120  USE w3gdatmd, ONLY : polat, polon
121 #endif
122  USE w3odatmd, ONLY: ndso, ndse, fnmpre
123  USE w3iobcmd, ONLY: verbptbc, idstrbc
124  USE w3iogrmd, ONLY: w3iogr
125  USE w3timemd
126  USE w3nmlboundmd
127  USE w3servmd, ONLY: itrace, nextln, extcde
128 #ifdef W3_RTD
129  USE w3servmd, ONLY: w3eqtoll
130 #endif
131 #ifdef W3_S
132  USE w3servmd, ONLY : strace
133 #endif
134  !/
135  IMPLICIT NONE
136  !
137 #ifdef W3_MPI
138  include "mpif.h"
139 #endif
140  !/
141  !/ ------------------------------------------------------------------- /
142  !/ Local parameters
143  !/
144  TYPE(nml_bound_t) :: nml_bound
145  !
146  INTEGER :: time1(2)
147  INTEGER :: time2(2)
148  INTEGER :: ix
149  INTEGER :: iy
150  INTEGER :: isea
151  INTEGER :: i
152  INTEGER :: jj
153  INTEGER :: ip
154  INTEGER :: ip1
155  INTEGER :: j
156  INTEGER :: k
157  INTEGER :: itime
158  INTEGER :: ndsi
159  INTEGER :: ndsm
160  INTEGER :: ndsi2
161  INTEGER :: ndss
162  INTEGER :: ndsb
163  INTEGER :: ndstrc
164  INTEGER :: ntrace
165  INTEGER :: nk1
166  INTEGER :: nth1
167  INTEGER :: nspec1
168  INTEGER :: nbi
169  INTEGER :: nbi2
170  INTEGER :: nki
171  INTEGER :: nthi
172  INTEGER :: nbo
173  INTEGER :: nbo2
174  INTEGER :: ierr
175  INTEGER :: interp
176  INTEGER :: iloop
177  INTEGER :: ifmin
178  INTEGER :: ifmin2
179  INTEGER :: ifmax
180  INTEGER :: verbose
181  INTEGER :: ndsl
182 #ifdef W3_S
183  INTEGER, SAVE :: ient = 0
184 #endif
185  INTEGER :: ibo
186  INTEGER, ALLOCATABLE :: ipbpi(:,:)
187  INTEGER, ALLOCATABLE :: ipbpo(:,:)
188  !
189  REAL :: fr1i
190  REAL :: th1i
191  REAL :: depth
192  REAL :: u10
193  REAL :: udir
194  REAL :: curr
195  REAL :: currdir
196  REAL :: dmin
197  REAL :: dist
198  REAL :: dmin2
199  REAL :: cos1
200  !
201  REAL, ALLOCATABLE :: lats(:)
202  REAL, ALLOCATABLE :: lons(:)
203  REAL, ALLOCATABLE :: spec2d(:,:)
204  REAL, ALLOCATABLE :: freq(:)
205  REAL, ALLOCATABLE :: theta(:)
206  REAL, ALLOCATABLE :: xbpi(:)
207  REAL, ALLOCATABLE :: ybpi(:)
208  REAL, ALLOCATABLE :: rdbpi(:,:)
209  REAL, ALLOCATABLE :: xbpo(:)
210  REAL, ALLOCATABLE :: ybpo(:)
211  REAL, ALLOCATABLE :: rdbpo(:,:)
212  REAL, ALLOCATABLE :: abpin(:,:)
213 #ifdef W3_RTD
214  REAL, ALLOCATABLE :: xtmp(:)
215  REAL, ALLOCATABLE :: ytmp(:)
216  REAL, ALLOCATABLE :: angtmp(:)
217  LOGICAL :: isrtd
218 #endif
219  CHARACTER :: comstr
220  CHARACTER(LEN=80) :: line
221  CHARACTER(LEN=128) :: bndfile
222  CHARACTER(LEN=5) :: inxout
223  CHARACTER(LEN=10) :: vertest
224  CHARACTER(LEN=32) :: idtst
225  CHARACTER(LEN=120) :: filename
226  CHARACTER(LEN=120) :: string1
227  CHARACTER(LEN=120) :: buoyname
228  CHARACTER :: space
229  !
230  CHARACTER(LEN=120), ALLOCATABLE :: specfiles(:)
231  !
232  LOGICAL :: flgnml
233  !/
234  !/ ------------------------------------------------------------------- /
235 
236 
237  !/
238  ! 1. IO set-up.
239  !
240  CALL w3nmod ( 1, 6, 6 )
241  CALL w3setg ( 1, 6, 6 )
242  CALL w3ndat ( 6, 6 )
243  CALL w3setw ( 1, 6, 6 )
244  CALL w3naux ( 6, 6 )
245  CALL w3seta ( 1, 6, 6 )
246  CALL w3nout ( 6, 6 )
247  CALL w3seto ( 1, 6, 6 )
248  !
249  ndsi = 10
250  ndsb = 33
251  ndsm = 20
252  ndss = 40
253  ndsl = 50
254  !
255  ndstrc = 6
256  ntrace = 10
257  CALL itrace ( ndstrc, ntrace )
258  !
259 #ifdef W3_S
260  CALL strace (ient, 'W3BOUND')
261 #endif
262  !
263 
264  !
265  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
266  ! 2. Read model definition file.
267  !
268  CALL w3iogr ( 'READ', ndsm )
269  WRITE (ndso,920) gname
270 #ifdef W3_RTD
271  !
272  isrtd = polat .LT. 90.0
273  !
274 #endif
275  !
276  ! 3. Read input file
277  !
278  ! process ww3_bound namelist
279  !
280  INQUIRE(file=trim(fnmpre)//"ww3_bound.nml", exist=flgnml)
281  IF (flgnml) THEN
282  ! Read namelist
283  CALL w3nmlbound (ndsi, trim(fnmpre)//'ww3_bound.nml', nml_bound, ierr)
284 
285  inxout = nml_bound%MODE
286  interp = nml_bound%INTERP
287  verbose = nml_bound%VERBOSE
288  bndfile = nml_bound%FILE
289 
290  nbo2 = 0
291  OPEN(ndsl,file=trim(bndfile),status='OLD',err=809,iostat=ierr)
292  rewind(ndsl)
293  DO
294  READ (ndsl,*,END=400,ERR=802)
295  nbo2 = nbo2 + 1
296  END DO
297 400 CONTINUE
298  ALLOCATE(specfiles(nbo2))
299  rewind(ndsl)
300  DO i=1,nbo2
301  READ (ndsl,'(A120)',END=801,ERR=802) SPECFILES(I)
302  END DO
303  CLOSE(ndsl)
304 
305  END IF ! FLGNML
306 
307  !
308  ! process old ww3_bound.inp format
309  !
310  IF (.NOT. flgnml) THEN
311  OPEN (ndsi,file=trim(fnmpre)//'ww3_bound.inp',status='OLD',err=803,iostat=ierr)
312  rewind(ndsi)
313 
314  READ (ndsi,'(A)',END=801,ERR=802) comstr
315  IF (comstr.EQ.' ') comstr = '$'
316 
317 
318  CALL nextln ( comstr , ndsi , ndse )
319  READ (ndsi,*) inxout
320  CALL nextln ( comstr , ndsi , ndse )
321  READ (ndsi,*) interp
322  CALL nextln ( comstr , ndsi , ndse )
323  READ (ndsi,*) verbose
324  CALL nextln ( comstr , ndsi , ndse )
325  !
326  nbo2 = 0
327  !
328  ! ILOOP = 1 to count NBO2
329  ! ILOOP = 2 to read the file names
330  !
331  DO iloop = 1, 2
332  OPEN (ndss,file='ww3_bound.scratch',form='FORMATTED', &
333  status='UNKNOWN')
334  IF ( iloop .EQ. 1 ) THEN
335  ndsi2 = ndsi
336  ELSE
337  ndsi2 = ndss
338  ALLOCATE(specfiles(nbo2))
339  nbo2=0
340  ENDIF
341 
342  nbo2=0
343  ! Read input file names
344  DO
345  CALL nextln ( comstr , ndsi2 , ndse )
346  READ (ndsi2,'(A120)') filename
347  jj = len_trim(filename)
348  IF ( iloop .EQ. 1 ) THEN
349  backspace(ndsi)
350  READ (ndsi,'(A)') line
351  WRITE (ndss,'(A)') line
352  END IF
353  IF (filename(:jj).EQ."'STOPSTRING'") EXIT
354  nbo2=nbo2+1
355  IF (iloop.EQ.1) cycle
356  specfiles(nbo2)=filename
357  END DO
358 
359  IF ( iloop .EQ. 1 ) CLOSE ( ndss)
360 
361  IF ( iloop .EQ. 2 ) CLOSE ( ndss, status='DELETE' )
362  END DO ! ILOOP = 1, 2
363  CLOSE(ndsi)
364  END IF ! .NOT. FLGNML
365 
366 
367  !
368  !--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
369  ! 4. Tests the reading of the file
370  !
371  IF ( inxout.EQ.'READ') THEN
372  OPEN(ndsb,file='nest.ww3',form='UNFORMATTED', convert=file_endian,status='old')
373  READ(ndsb) idtst, vertest, nk1, nth1, xfr, fr1i, th1i, nbi
374  nspec1 = nk1 * nth1
375  IF ( idtst .NE. idstrbc ) THEN
376  WRITE (ndso,901) idtst, idstrbc
377  END IF
378  WRITE(ndso,*) "FORMAT VERSION: '",vertest,"'"
379  WRITE(ndso,*) "FILE TYPE: '",idtst,"'"
380  IF (verbose.EQ.1) WRITE(ndso,'(A,2I5,3F12.6,I5)') 'NK,NTH,XFR, FR1I, TH1I, NBI :', &
381  nk1,nth1,xfr, fr1i, th1i, nbi
382  ALLOCATE (xbpi(nbi),ybpi(nbi))
383  ALLOCATE (ipbpi(nbi,4),rdbpi(nbi,4))
384  READ(ndsb) (xbpi(i),i=1,nbi), &
385  (ybpi(i),i=1,nbi), &
386  ((ipbpi(i,j),i=1,nbi),j=1,4), &
387  ((rdbpi(i,j),i=1,nbi),j=1,4)
388  IF (verbose.EQ.1) WRITE(ndso,*) 'XBPI:',xbpi
389  IF (verbose.EQ.1) WRITE(ndso,*) 'YBPI:',ybpi
390  IF (verbose.EQ.1) WRITE(ndso,*) 'IPBPI:'
391  DO i=1,nbi
392  IF (verbose.EQ.1) WRITE(ndso,*) i,' interpolated from:',ipbpi(i,1:4)
393  IF (verbose.EQ.1) WRITE(ndso,*) i,' with coefficient :',rdbpi(i,1:4)
394  END DO
395  !
396  READ (ndsb) time2, nbi2
397  backspace(ndsb)
398  ALLOCATE (abpin(nspec1,nbi2))
399  ierr=0
400  DO WHILE (ierr.EQ.0)
401  READ (ndsb,iostat=ierr) time2, nbi2
402  IF (ierr.EQ.0) THEN
403  IF (verbose.EQ.1) WRITE(ndso,*) 'TIME2,NBI2:',time2, nbi2,ierr
404  DO ip=1, nbi2
405  READ (ndsb,iostat=ierr) abpin(:,ip)
406  END DO
407  END IF
408  END DO
409  CLOSE(ndsb)
410  END IF
411  !
412  !
413  IF ( inxout.EQ.'WRITE') THEN
414  IF ( flbpi) THEN
415  !
416  ! Defines position of active boundary points
417  !
418  nbo = 0
419  DO isea=1,nsea
420  ix = mapsf(isea,1)
421  iy = mapsf(isea,2)
422  IF (mapsta(iy,ix).EQ.2) THEN
423  nbo=nbo+1
424  END IF
425  END DO
426  ALLOCATE(xbpo(nbo),ybpo(nbo))
427 #ifdef W3_RTD
428  IF (isrtd) ALLOCATE(xtmp(nbo), ytmp(nbo), angtmp(nbo))
429 #endif
430  ALLOCATE (ipbpo(nbo,4),rdbpo(nbo,4))
431  ibo=0
432  DO isea=1,nsea
433  ix = mapsf(isea,1)
434  iy = mapsf(isea,2)
435  IF (mapsta(iy,ix).EQ.2) THEN
436  ibo=ibo+1
437  SELECT CASE ( gtype )
438  CASE ( rlgtype )
439  xbpo(ibo)=x0+sx*(ix-1)
440  ybpo(ibo)=y0+sy*(iy-1)
441  CASE ( clgtype )
442  xbpo(ibo)= xgrd(iy,ix)
443  ybpo(ibo)= ygrd(iy,ix)
444  CASE (ungtype)
445  xbpo(ibo)= xgrd(1,ix)
446  ybpo(ibo)= ygrd(1,ix)
447  END SELECT !GTYPE
448  END IF
449  END DO
450 #ifdef W3_RTD
451  ! Convert grid boundary cell locations to standard pole
452  IF( isrtd ) THEN
453  xtmp = xbpo
454  ytmp = ybpo
455  CALL w3eqtoll(ytmp, xtmp, ybpo, xbpo, angtmp, polat, polon, nbo)
456  DEALLOCATE(xtmp, ytmp, angtmp)
457  ENDIF
458 #endif
459  OPEN(ndsb,file='nest.ww3',form='UNFORMATTED', convert=file_endian,status='unknown')
460  ALLOCATE(lats(nbo2),lons(nbo2))
461  DO ip=1,nbo2
462  OPEN(200+ip,file=specfiles(ip),status='old',iostat=ierr)
463  IF (verbose.EQ.1) WRITE(ndso,'(A,I5,3A,I5)') &
464  'IP, file, I/O stat:',ip,', ', &
465  trim(specfiles(ip)), ', ',ierr
466  IF (ierr.NE.0) GOTO 810
467  READ(200+ip,'(A1,A22,A1,X,2I6)',iostat=ierr) &
468  space,string1,space,nki,nthi
469  IF (verbose.EQ.1) WRITE(ndso,'(A,3I5)') 'IP and spectral dimensions:',ip, nki,nthi
470  IF (ip.EQ.1) THEN
471  nk1=nki
472  nth1=nthi
473  nspec1 = nk1 * nth1
474  ALLOCATE (freq(nk1),theta(nth1))
475  ALLOCATE (spec2d(nk1,nth1))
476  ALLOCATE (abpin(nk*nth1,nbo2))
477  ELSE
478  !
479  ! To be cleaned up later ...
480  !
481  IF (nk1.NE.nki.OR.nth1.NE.nthi) THEN
482  WRITE(ndse,'(A,A,4I5)') 'ERROR, SPECTRAL GRID IN FILE:', &
483  trim(specfiles(ip)),nk1,nki,nth1,nthi
484  stop
485  END IF
486  END IF
487  !
488  READ(200+ip,*) freq(1:nk1)
489  READ(200+ip,*) theta(1:nth1)
490  END DO
491 
492  !
493  ! Defines frequency range in spectra
494  !
495 
496  ! Checks consistency of NK
497  IF (nki.GT.nk) GOTO 808
498  !
499  ! HERE we define IFMIN IFMIN2 IFMAX and IFMAX2 frequency indices
500  ! such that source spec SPEC (read in input) links with output spec
501  ! APBIN with APBIN(IFMIN2:IFMAX2) = SPEC(IFMIN:IFMAX)
502  ! Then APBIN(1:IFMIN2) = 0 and APBIN(IFMAX2:end) = 0
503  ifmin=1 ! index of first freq. in source spectrum
504  ifmin2=1 ! index of first freq. in output spectrum
505  ifmax=nk1 ! index of last freq. in source spectrum
506  ! IFMAX2=NK ! index of last freq. in output spectrum
507  !
508  ! Checks consistency of XFR
509  IF (abs((freq(ifmin+1)/freq(ifmin))-xfr).GT.0.005) GOTO 806
510  !
511  ! Checks consistency of NTH
512  ! WARNING: check is only done on number of directions, no check
513  ! is done on the relative offset of first direction in terms of
514  ! the directional increment [-0.5,0.5] (last parameter of the
515  ! spectral definition in ww3_grid.inp, on second active line)
516  IF (nthi.NE.nth) GOTO 807
517 
518  IF ((fr1-freq(1))/fr1.GT. 0.03) THEN
519  DO j=1,min(nk1,nk)
520  IF (abs(freq(j)-fr1) .LT. abs(freq(ifmin)-fr1)) THEN
521  ifmin=j
522  END IF
523  END DO
524  END IF
525  !
526  IF ((freq(1)-fr1)/fr1.GT. 0.03) THEN
527  DO j=1,min(nk,nk1)
528  IF (abs(freq(j)-fr1*xfr**(j-1)) .LT. abs(freq(ifmin2)-fr1)) THEN
529  ifmin2=j
530  END IF
531  END DO
532  END IF
533  !
534  IF ((freq(nk1)-fr1*xfr**(nk-1))/freq(nk1) .GT.0.03) THEN
535  DO j=1,nk
536  IF (abs(freq(j)-fr1*xfr**(nk1-1)) .LT. abs(freq(ifmax)-fr1*xfr**(nk1-1))) THEN
537  ifmax=j
538  END IF
539  END DO
540  END IF
541  !
542  ierr=0
543  itime=0
544  !
545  ! Loop on times
546  !
547  DO WHILE (ierr.EQ.0)
548  DO ip=1,nbo2
549  READ(200+ip,*,iostat=ierr) time2
550  IF (ierr.EQ.0) THEN
551  !
552  IF (ip.EQ.1) THEN
553  time1=time2
554  ELSE
555  IF (time1(1).NE.time2(1).OR.time1(2).NE.time2(2)) THEN
556  WRITE(ndse,*) 'AT POINT ',ip,', BAD TIMES:',time1, time2
557  END IF
558  END IF
559  !
560  READ(200+ip,'(A1,A10,A1,2F7.2,F10.1,F7.2,F6.1,F7.2,F6.1)') &
561  space,buoyname,space,lats(ip),lons(ip),depth,u10,udir,curr,currdir
562 #ifdef W3_RTD
563  IF (isrtd) THEN
564  ! Rotated coordinates are scaled in range 0 - 360
565  IF(lons(ip) .LT. 0) lons(ip) = lons(ip) + 360.0
566  IF(lons(ip) .GT. 360) lons(ip) = lons(ip) - 360.0
567  ENDIF
568 #endif
569  READ(200+ip,*,iostat=ierr) spec2d
570  IF (ifmin2.GT.1) THEN
571  !
572  ! Fills in the low frequency end of the spectrum
573  !
574  abpin(1:(ifmin2-1)*nth,ip)=0.
575  END IF
576  DO i=ifmin,ifmax
577  DO j=1,nth
578  abpin((i-ifmin+(ifmin2-1))*nth+j,ip)=spec2d(i,j)*tpiinv
579  END DO
580  END DO
581  IF (ifmax-ifmin+ifmin2.LT.nk1) THEN
582  !IF (VERBOSE.EQ.1) WRITE(NDSO,*) 'FILLING TAIL',IFMAX-IFMIN,NK1,IFMAX-IFMIN+(IFMIN2-1)
583  abpin((ifmax-ifmin+ifmin2)*nth+1:nk1*nth,ip)=0.
584  END IF
585  END IF ! ned of test on IERR
586  END DO
587  !
588  ! Writes header
589  !
590  IF (ierr.EQ.0) THEN
591  IF (itime.EQ.0) THEN
592  ! Correction for rounding error in ASCII files ...
593  IF (abs(theta(1)-0.5*pi).LT.0.01) theta(1)=0.5*pi
594  ! Writes header in nest.ww3 file
595  WRITE(ndsb) idstrbc, verbptbc, nk1, nth, xfr, freq(1), &
596  mod(2.5*pi-theta(1),tpi), nbo
597  ipbpo(:,:)=1
598  rdbpo(:,1)=1.
599  rdbpo(:,2:4)=0.
600  !
601  DO ip1=1,nbo
602  dmin=360.+180.
603  dmin2=360.+180.
604  DO ip=1,nbo2
605  !
606  ! Searches for the nearest 2 points where spectra are available
607  !
608  dist=sqrt((lons(ip)-xbpo(ip1))**2+(lats(ip)-ybpo(ip1))**2)
609  IF (dmin.EQ.(360.+180.)) THEN
610  IF(dist.LT.dmin) THEN
611  ipbpo(ip1,1)=ip
612  dmin=dist
613  END IF
614  ELSE
615  IF(dist.LT.dmin2) THEN
616  IF(dist.LT.dmin) THEN
617  ipbpo(ip1,2)=ipbpo(ip1,1)
618  dmin2=dmin
619  ipbpo(ip1,1)=ip
620  dmin=dist
621  ELSE
622  ipbpo(ip1,2)=ip
623  dmin2=dist
624  END IF
625  ENDIF
626  END IF
627  END DO
628  !IF (VERBOSE.EQ.1) WRITE(NDSO,*) 'DIST:',DMIN,DMIN2,IP1,IPBPO(IP1,1),IPBPO(IP1,2), &
629  ! LONS(IPBPO(IP1,1)),LONS(IPBPO(IP1,2)),XBPO(IP1), &
630  ! LATS(IPBPO(IP1,1)),LATS(IPBPO(IP1,2)),YBPO(IP1)
631  !
632  ! Computes linear interpolation coefficient between the nearest 2 points
633  !
634  IF (interp.GT.1.AND.nbo2.GT.1) THEN
635  dist=sqrt((lons(ipbpo(ip1,1))-lons(ipbpo(ip1,2)))**2 &
636  +(lats(ipbpo(ip1,1))-lats(ipbpo(ip1,2)))**2)
637  cos1=( (xbpo(ip1)-lons(ipbpo(ip1,1))) &
638  *(lons(ipbpo(ip1,2))-lons(ipbpo(ip1,1))) &
639  + (ybpo(ip1)-lats(ipbpo(ip1,1))) &
640  *(lats(ipbpo(ip1,2))-lats(ipbpo(ip1,1))))/(dist**2)
641  !COS2=( (XBPO(IP1)-LONS(IPBPO(IP1,2))) &
642  ! *(LONS(IPBPO(IP1,1))-LONS(IPBPO(IP1,2)))
643  ! + (YBPO(IP1)-LATS(IPBPO(IP1,2))) &
644  ! *(LATS(IPBPO(IP1,1))-LATS(IPBPO(IP1,2))))/(DIST**2)
645  rdbpo(ip1,1)=1-min(1.,max(0.,cos1))
646  rdbpo(ip1,2)=min(1.,max(0.,cos1))
647  END IF
648  !
649  IF (verbose.EQ.1) WRITE(ndso,*) 'IPBP:',ip1,(ipbpo(ip1,j),j=1,4)
650  IF (verbose.EQ.1) WRITE(ndso,*) 'RDBP:',ip1,(rdbpo(ip1,j),j=1,4)
651  !
652  END DO
653  WRITE(ndsb) (xbpo(i),i=1,nbo), &
654  (ybpo(i),i=1,nbo), &
655  ((ipbpo(i,j),i=1,nbo),j=1,4),&
656  ((rdbpo(i,j),i=1,nbo),j=1,4)
657  END IF
658 
659  WRITE(ndso,*) 'Writing boundary data for time:', time2, nbo2
660  WRITE(ndsb,iostat=ierr) time2, nbo2
661  DO ip=1, nbo2
662  WRITE (ndsb) abpin(:,ip)
663  END DO
664 
665  itime=itime+1
666  END IF
667  END DO
668  CLOSE(ndsb)
669  END IF
670  END IF
671  stop
672  !
673  ! Escape locations read errors :
674  !
675 
676 801 CONTINUE
677  WRITE (ndse,1001)
678  CALL extcde ( 61 )
679  !
680 802 CONTINUE
681  WRITE (ndse,1002) ierr
682  CALL extcde ( 62 )
683  !
684 803 CONTINUE
685  WRITE (ndse,1003)
686  CALL extcde ( 63 )
687  !
688 806 CONTINUE
689  WRITE (ndse,1006) xfr
690  CALL extcde ( 66 )
691  !
692 807 CONTINUE
693  WRITE (ndse,1007) nth, nthi
694  CALL extcde ( 67 )
695  !
696 808 CONTINUE
697  WRITE (ndse,1008) nk, nki
698  CALL extcde ( 68 )
699  !
700 809 CONTINUE
701  WRITE (ndse,1009) bndfile, ierr
702  CALL extcde ( 69 )
703  !
704 810 CONTINUE
705  WRITE (ndse,1010) specfiles(ip)
706  CALL extcde ( 70 )
707 
708  !
709  ! Formats
710  !
711 901 FORMAT (/' *** WAVEWATCH-III ERROR IN W3IOBC :'/ &
712  ' ILEGAL IDSTR, READ : ',a/ &
713  ' CHECK : ',a/)
714  !
715 920 FORMAT ( ' Grid name : ',a/)
716  !
717 1001 FORMAT (/' *** WAVEWATCH-III ERROR IN W3BOUND : '/ &
718  ' PREMATURE END OF INPUT FILE'/)
719  !
720 1002 FORMAT (/' *** WAVEWATCH III ERROR IN W3BOUND: '/ &
721  ' ERROR IN READING ',a,' FROM INPUT FILE'/ &
722  ' IOSTAT =',i5/)
723  !
724 1003 FORMAT (/' *** WAVEWATCH III ERROR IN W3BOUNC : '/ &
725  ' ERROR IN OPENING INPUT FILE: ', a/ &
726  ' IOSTAT =',i5/)
727  !
728 1006 FORMAT (/' *** WAVEWATCH III ERROR IN W3BOUND: '/ &
729  ' ILLEGAL XFR, XFR =',f12.6/)
730  !
731 1007 FORMAT (/' *** WAVEWATCH III ERROR IN W3BOUND: '/ &
732  ' ILLEGAL NTH, NTH =',i3,' DIFFERS FROM NTHI =',i3/)
733  !
734 1008 FORMAT (/' *** WAVEWATCH III ERROR IN W3BOUND: '/ &
735  ' ILLEGAL NK, NK =',i3,' DIFFERS FROM NKI =',i3/ &
736  ' IT WILL BE MANAGED SOON BY SPCONV')
737  !
738 1009 FORMAT (/' *** WAVEWATCH III ERROR IN W3BOUND : '/ &
739  ' ERROR IN OPENING SPEC FILE: ', a/ &
740  ' IOSTAT =',i5/)
741  !
742 1010 FORMAT (/' *** WAVEWATCH III ERROR IN W3BOUND : '/ &
743  ' SPEC FILE NOT EXISTING: ', a/)
744 
745 
746  !
747  !/
748  !/ End of W3BOUND ---------------------------------------------------- /
749  !/
750 END PROGRAM w3bound
751 !/ ------------------------------------------------------------------- /
w3gdatmd::nk
integer, pointer nk
Definition: w3gdatmd.F90:1230
constants::pi
real, parameter pi
PI Value of Pi.
Definition: constants.F90:71
w3servmd::nextln
subroutine nextln(CHCKC, NDSI, NDSE)
Definition: w3servmd.F90:222
include
cmake src_list cmake include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_switches.cmake) check_switches("$
Definition: CMakeLists.txt:15
w3bound
program w3bound
Combines spectra files into a nest. ww3 file for boundary conditions.
Definition: ww3_bound.F90:15
w3gdatmd::ygrd
double precision, dimension(:,:), pointer ygrd
Definition: w3gdatmd.F90:1205
w3adatmd
Define data structures to set up wave model auxiliary data for several models simultaneously.
Definition: w3adatmd.F90:26
w3gdatmd::ungtype
integer, parameter ungtype
Definition: w3gdatmd.F90:626
w3wdatmd
Define data structures to set up wave model dynamic data for several models simultaneously.
Definition: w3wdatmd.F90:18
w3gdatmd::rlgtype
integer, parameter rlgtype
Definition: w3gdatmd.F90:624
w3gdatmd::xgrd
double precision, dimension(:,:), pointer xgrd
Definition: w3gdatmd.F90:1205
w3gdatmd::sy
real, pointer sy
Definition: w3gdatmd.F90:1183
w3gdatmd::gname
character(len=30), pointer gname
Definition: w3gdatmd.F90:1223
w3odatmd::fnmpre
character(len=80) fnmpre
Definition: w3odatmd.F90:330
w3odatmd::flbpi
logical, pointer flbpi
Definition: w3odatmd.F90:546
w3servmd::w3eqtoll
subroutine w3eqtoll(PHI_EQ, LAMBDA_EQ, PHI, LAMBDA, ANGLED, PHI_POLE, LAMBDA_POLE, POINTS)
Definition: w3servmd.F90:1224
w3gdatmd::w3setg
subroutine w3setg(IMOD, NDSE, NDST)
Definition: w3gdatmd.F90:2152
w3odatmd::ndse
integer, pointer ndse
Definition: w3odatmd.F90:456
w3adatmd::w3seta
subroutine w3seta(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3adatmd.F90:2645
w3wdatmd::w3ndat
subroutine w3ndat(NDSE, NDST)
Set up the number of grids to be used.
Definition: w3wdatmd.F90:210
w3gdatmd::polat
real, pointer polat
Definition: w3gdatmd.F90:1191
w3gdatmd::x0
real, pointer x0
Definition: w3gdatmd.F90:1183
w3gdatmd::nsea
integer, pointer nsea
Definition: w3gdatmd.F90:1097
w3gdatmd::clgtype
integer, parameter clgtype
Definition: w3gdatmd.F90:625
w3servmd
Definition: w3servmd.F90:3
w3iobcmd::verbptbc
character(len=10), parameter verbptbc
Definition: w3iobcmd.F90:76
w3wdatmd::w3setw
subroutine w3setw(IMOD, NDSE, NDST)
Select one of the WAVEWATCH III grids / models.
Definition: w3wdatmd.F90:660
constants::tpiinv
real, parameter tpiinv
TPIINV Inverse of 2*Pi.
Definition: constants.F90:74
w3odatmd::w3seto
subroutine w3seto(IMOD, NDSERR, NDSTST)
Definition: w3odatmd.F90:1523
w3gdatmd::nth
integer, pointer nth
Definition: w3gdatmd.F90:1230
w3iobcmd::idstrbc
character(len=32), parameter idstrbc
Definition: w3iobcmd.F90:77
w3odatmd
Definition: w3odatmd.F90:3
w3adatmd::w3naux
subroutine w3naux(NDSE, NDST)
Set up the number of grids to be used.
Definition: w3adatmd.F90:704
w3iobcmd
Processing of boundary data output.
Definition: w3iobcmd.F90:14
w3gdatmd::mapsf
integer, dimension(:,:), pointer mapsf
Definition: w3gdatmd.F90:1163
w3iogrmd::w3iogr
subroutine w3iogr(INXOUT, NDSM, IMOD, FEXT ifdef W3_ASCII
Reading and writing of the model definition file.
Definition: w3iogrmd.F90:117
file
file(STRINGS ${CMAKE_BINARY_DIR}/switch switch_strings) separate_arguments(switches UNIX_COMMAND $
Definition: CMakeLists.txt:3
w3iogrmd
Reading/writing of model definition file.
Definition: w3iogrmd.F90:20
w3nmlboundmd::w3nmlbound
subroutine w3nmlbound(NDSI, INFILE, NML_BOUND, IERR)
Definition: w3nmlboundmd.F90:45
w3gdatmd::fr1
real, pointer fr1
Definition: w3gdatmd.F90:1232
constants::tpi
real, parameter tpi
TPI 2*Pi.
Definition: constants.F90:72
w3servmd::strace
subroutine strace(IENT, SNAME)
Definition: w3servmd.F90:148
w3gdatmd::gtype
integer, pointer gtype
Definition: w3gdatmd.F90:1094
w3odatmd::ndso
integer, pointer ndso
Definition: w3odatmd.F90:456
w3gdatmd::w3nmod
subroutine w3nmod(NUMBER, NDSE, NDST, NAUX)
Definition: w3gdatmd.F90:1433
w3gdatmd::xfr
real, pointer xfr
Definition: w3gdatmd.F90:1232
w3gdatmd::y0
real, pointer y0
Definition: w3gdatmd.F90:1183
w3nmlboundmd::nml_bound_t
Definition: w3nmlboundmd.F90:27
w3gdatmd::sx
real, pointer sx
Definition: w3gdatmd.F90:1183
constants
Define some much-used constants for global use (all defined as PARAMETER).
Definition: constants.F90:20
w3gdatmd
Definition: w3gdatmd.F90:16
constants::file_endian
character(*), parameter file_endian
FILE_ENDIAN Filled by preprocessor with 'big_endian', 'little_endian', or 'native'.
Definition: constants.F90:86
w3servmd::extcde
subroutine extcde(IEXIT, UNIT, MSG, FILE, LINE, COMM)
Definition: w3servmd.F90:736
w3odatmd::w3nout
subroutine w3nout(NDSERR, NDSTST)
Definition: w3odatmd.F90:561
w3servmd::itrace
subroutine itrace(NDS, NMAX)
Definition: w3servmd.F90:91
interp
subroutine interp(MXM, MYM, XC, IX21, IX22, IY21, IY22, RD11, RD12, RD21, RD22, FILLVALUE, FA)
Interpolate from a field read from file to the wave grid.
Definition: ww3_prnc.F90:2580
w3timemd
Definition: w3timemd.F90:3
w3nmlboundmd
Definition: w3nmlboundmd.F90:3
w3gdatmd::mapsta
integer, dimension(:,:), pointer mapsta
Definition: w3gdatmd.F90:1163
w3gdatmd::polon
real, pointer polon
Definition: w3gdatmd.F90:1191