151 INTEGER :: ndsi, ndsf, ndsm, ndsdat, ndstrc, ntrace
152 INTEGER :: ierr, ifld, i, jj, j, ix, iy
153 INTEGER :: dttst, ndsen, prtide_dt
154 INTEGER :: tide_prmf, flagtide, tindex
155 INTEGER :: tideok, tide_max, tide_maxi
156 INTEGER :: k, icon, ix2, sumok, nbad, iter
157 INTEGER :: ie, ip, ip2, ii, ifound, alreadyfound
158 INTEGER :: tide_kd0, int24, intdys
160 INTEGER :: ierr_mpi, ind, rest, slice
162 INTEGER :: time(2), tide_start(2), tide_end(2)
163 INTEGER :: indmax(70), pr_inds(70)
165 INTEGER,
ALLOCATABLE :: badpoints(:,:), vneigh(:,:), conn(:)
167 INTEGER,
ALLOCATABLE :: nelem(:), cumul(:)
170 REAL :: wcurtidex, wcurtidey, tide_argx, tide_argy
171 REAL :: ampcos, ampsin
173 REAL :: tide_fx(44),ux(44),vx(44), maxvalcon(70)
175 REAL,
ALLOCATABLE :: fx(:,:), fy(:,:), fa(:,:)
177 REAL,
ALLOCATABLE :: fx1d(:), fy1d(:), fa1d(:)
178 REAL,
ALLOCATABLE :: fx1dl(:), fy1dl(:), fa1dl(:)
181 DOUBLE PRECISION :: d1,h,tide_hour,hh,pp,s,p,enp,dh,dpp,ds,dp,dnp,tau
183 CHARACTER*256 :: filenamext
184 CHARACTER :: tideconstnames*1024
185 CHARACTER*23 :: idtime
186 CHARACTER :: comstr*1, idfld*3
188 CHARACTER(LEN=100) :: tidecon_prnames(70), tidecon_maxnames(70)
189 CHARACTER(LEN=100) :: tidecon_maxvals(70)
213 CALL w3seto ( 1, 6, 6 )
228 CALL itrace ( ndstrc, ntrace )
244 CALL strace (ient,
'W3PRTIDE')
256 CALL mpi_init ( ierr_mpi )
257 CALL mpi_comm_size ( mpi_comm_world, naproc, ierr_mpi )
258 CALL mpi_comm_rank ( mpi_comm_world, iaproc, ierr_mpi )
262 IF ( iaproc .EQ. naperr )
THEN
268 IF ( iaproc .EQ. napout )
WRITE (
ndso,900)
270 OPEN (ndsi,
file=trim(
fnmpre)//
'ww3_prtide.inp',status=
'OLD', &
273 READ (ndsi,
'(A)',
END=801,ERR=802,IOSTAT=IERR) comstr
274 IF (comstr.EQ.
' ') comstr =
'$'
275 IF ( iaproc .EQ. napout )
WRITE (ndso,901) comstr
283 CALL w3iogr (
'READ', ndsm )
284 IF ( iaproc .EQ. napout )
WRITE (ndso,902) gname
285 ALLOCATE ( fx(nx,ny), fy(nx,ny), fa(nx,ny), badpoints(nx,ny) )
293 CALL nextln ( comstr , ndsi , ndsen )
294 READ (ndsi,*,
END=801,ERR=802,IOSTAT=IERR) idfld
296 IF ( idfld.EQ.
'LEV' )
THEN
298 ELSE IF ( idfld.EQ.
'CUR' )
THEN
301 WRITE (ndse,1030) idfld
305 CALL nextln ( comstr , ndsi , ndsen )
306 READ (ndsi,
'(A)',
END=801,ERR=802,IOSTAT=IERR) tideconstnames
307 CALL nextln ( comstr , ndsi , ndse )
308 tidecon_prnames(:)=
''
309 CALL strsplit(tideconstnames,tidecon_prnames)
311 CALL nextln ( comstr , ndsi , ndsen )
312 READ (ndsi,
'(A)',
END=801,ERR=802,IOSTAT=IERR) tideconstnames
313 tidecon_maxnames(:)=
''
314 CALL strsplit(tideconstnames,tidecon_maxnames)
316 CALL nextln ( comstr , ndsi , ndsen )
317 tidecon_maxvals(:)=
''
318 READ (ndsi,
'(A)',
END=801,ERR=802,IOSTAT=IERR) tideconstnames
319 CALL strsplit(tideconstnames,tidecon_maxvals)
321 CALL nextln ( comstr , ndsi , ndsen )
322 READ (ndsi,*,
END=801,ERR=802,IOSTAT=IERR) TIDE_START,PRTIDE_DT,tide_end
323 CALL nextln ( comstr , ndsi , ndsen )
324 READ (ndsi,*,
END=801,ERR=802,IOSTAT=IERR) filenamext
326 CALL w3fldo (
'READ', idfld, ndsf, ndst, &
327 ndse, nx, ny, gtype, &
328 ierr, filenamext,
'', tideflagin=flagtide )
330 IF (flagtide.NE.1)
GOTO 803
332 CALL vuf_set_parameters
340 CALL w3fldtide1 (
'READ', ndsf, ndst, ndse, nx, ny, idfld, ierr )
341 CALL w3fldtide2 (
'READ', ndsf, ndst, ndse, nx, ny, idfld, 0, ierr )
346 IF (gtype.EQ.ungtype)
THEN
348 countri = maxval(ccon)
349 ALLOCATE(vneigh(nx,2*countri))
360 IF (ip == trigp(1,ie))
THEN
364 IF (vneigh(ip,i).EQ.trigp(ip2,ie)) alreadyfound=alreadyfound+1
366 IF (alreadyfound.EQ.0)
THEN
368 vneigh(ip,ifound)=trigp(ip2,ie)
373 IF (ip == trigp(2,ie))
THEN
377 IF (vneigh(ip,i).EQ.trigp(mod(ip2-1,3)+1,ie)) alreadyfound=alreadyfound+1
379 IF (alreadyfound.EQ.0)
THEN
381 vneigh(ip,ifound)=trigp(mod(ip2-1,3)+1,ie)
386 IF (ip == trigp(3,ie))
THEN
390 IF (vneigh(ip,i).EQ.trigp(ip2,ie)) alreadyfound=alreadyfound+1
392 IF (alreadyfound.EQ.0)
THEN
394 vneigh(ip,ifound)=trigp(ip2,ie)
405 IF (vneigh(ip,jj).EQ. vneigh(ip,i))
THEN
406 countcon(ip)=countcon(ip)-1
407 vneigh(ip,i:ifound)=vneigh(ip,i+1:ifound+1)
421 CALL tide_find_indices_prediction(tidecon_prnames,pr_inds,tide_prmf)
424 DO WHILE (len_trim(tidecon_maxnames(tide_maxi+1)).NE.0)
425 tide_maxi=tide_maxi+1
427 IF (trim(tidecon_name(j)).EQ.trim(tidecon_maxnames(tide_maxi)))
THEN
430 READ(tidecon_maxvals(tide_maxi),*) maxvalcon(tide_max)
431 IF (iaproc.EQ.napout)
THEN
432 WRITE(ndso,
'(A,I8,A,F10.2)') &
433 'Maximum allowed value for amplitude:',&
434 j,trim(tidecon_name(j)),maxvalcon(tide_max)
447 IF (iaproc .EQ. napout)
THEN
448 CALL w3fldo (
'WRITE', idfld, ndsdat, ndst, ndse, nx, ny, &
449 gtype, ierr,
'ww3', tideflagin=flagtide)
461 IF(rest.GE.iaproc) slice=slice+1
466 ALLOCATE ( fx1d(nx), fy1d(nx), fa1d(nx))
474 ALLOCATE(fx1dl(slice))
475 ALLOCATE(fy1dl(slice))
476 ALLOCATE(fa1dl(slice))
485 ALLOCATE(nelem(naproc))
486 ALLOCATE(cumul(naproc))
487 nelem(1) = nx / naproc
488 IF (rest .GT. 0) nelem(1) = nelem(1) + 1
491 cumul(i)=cumul(i-1)+nelem(i-1)
492 nelem(i) = nx / naproc
493 IF (rest .GT. i-1) nelem(i) = nelem(i) + 1
498 WRITE(100+iaproc,*)
"Number of points for this processor ", iaproc,
" : ", nelem(iaproc),
' / ', nx
499 WRITE(100+iaproc,*)
"Cumul of points for this processor ", iaproc,
" : ", cumul(iaproc),
' / ', nx
508 dttst = dsec21( tide_start , tide_end )
509 IF ( dttst .LE. 0. .OR. prtide_dt .LT. 1 )
GOTO 888
516 dttst = dsec21( time, tide_end )
517 IF ( dttst .LT. 0. )
GOTO 888
519 CALL stme21 ( time , idtime )
520 IF ( iaproc .EQ. napout )
WRITE (ndso,973) idtime
522 tide_hour = time2hours(time)
527 d1=d1-dfloat(tide_kd0)-0.5d0
528 CALL astr(d1,h,pp,s,p,enp,dh,dpp,ds,dp,dnp)
530 intdys=int((tide_hour+0.00001)/int24)
531 hh=tide_hour-dfloat(intdys*int24)
543 IF (tindex.EQ.1)
THEN
548 IF (abs(tidal_const(ix,iy,indmax(i),1,1)) .GT.maxvalcon(i) .OR. &
549 abs(tidal_const(ix,iy,indmax(i),2,1)) .GT.maxvalcon(i))
THEN
551 WRITE(ndso,
'(A,I8,F10.2,A,2F10.2)') &
552 '[BAD POINT] GREATER THAN THRESHOLD ', maxvalcon(i), &
553 ' AT INDEX ', indmax(i), &
554 ' WITH X-Y COMPONENTS : ', abs(tidal_const(ix,iy,indmax(i),1:2,1))
556 badpoints(ix,iy) = badpoints(ix,iy) + (1-tideok)
559 IF (badpoints(ix,iy).GT.0)
THEN
561 WRITE(ndse,*)
'BAD POINT:',ix,iy,nbad, &
562 tidal_const(ix,iy,:,1,1),
'##',tidal_const(ix,iy,:,2,1)
570 IF (badpoints(ix,iy).GT.0)
THEN
571 tidal_const(ix,iy,:,1,1)=0
572 tidal_const(ix,iy,:,2,1)=0
575 IF (tidefill.AND.(gtype.EQ.ungtype))
THEN
585 DO icon=1,countcon(ix)
587 IF (badpoints(ix2,iy).EQ.0)
THEN
589 ampcos = ampcos+tidal_const(ix2,iy,j,k,1)*cos(tidal_const(ix2,iy,j,k,2)*
dera)
590 ampsin = ampsin+tidal_const(ix2,iy,j,k,1)*sin(tidal_const(ix2,iy,j,k,2)*
dera)
597 IF (tidecon_name(j).NE.
'Z0 ')
THEN
598 tidal_const(ix,iy,j,k,1) = sqrt(ampcos**2+ampsin**2)/sumok
599 tidal_const(ix,iy,j,k,2) = atan2(ampsin,ampcos)/
dera
601 tidal_const(ix,iy,j,k,1) = ampcos/sumok
602 tidal_const(ix,iy,j,k,2) = 0.
604 IF(k.EQ.2.AND.j.EQ.tide_mf)
THEN
616 IF ( iaproc .EQ. napout )
WRITE(ndse,*)
'Number of remaining bad points:',nbad
629 DO ix=cumul(iaproc)+1,cumul(iaproc)+nelem(iaproc)
634 CALL setvuf_fast(h,pp,s,p,enp,dh,dpp,ds,dp,dnp,tau,real(ygrd(iy,ix)),tide_fx,ux,vx)
639 IF (trim(tidecon_name(j)).EQ.
'Z0')
THEN
640 wcurtidex = wcurtidex+tidal_const(ix,iy,j,1,1)
641 wcurtidey = wcurtidey+tidal_const(ix,iy,j,2,1)
643 tide_argx=(vx(j)+ux(j))*twpi-tidal_const(ix,iy,j,1,2)*
dera
644 tide_argy=(vx(j)+ux(j))*twpi-tidal_const(ix,iy,j,2,2)*
dera
645 wcurtidex = wcurtidex+tide_fx(j)*tidal_const(ix,iy,j,1,1)*cos(tide_argx)
646 wcurtidey = wcurtidey+tide_fx(j)*tidal_const(ix,iy,j,2,1)*cos(tide_argy)
649 IF (abs(wcurtidex).GT.10..OR.abs(wcurtidey).GT.10.)
THEN
651 'WARNING: VERY STRONG CURRENT... BAD CONSTITUENTS?', &
652 ix, wcurtidex, wcurtidey , tidal_const(ix,iy,:,1,1),
'##',tidal_const(ix,iy,:,2,1)
657 fx1dl(ind) = wcurtidex
658 fy1dl(ind) = wcurtidey
663 fx(ix,iy) = wcurtidex
664 fy(ix,iy) = wcurtidey
674 IF (naproc.GT.1)
THEN
675 CALL mpi_gatherv(fx1dl, slice, mpi_real, fx1d, nelem, &
676 cumul, mpi_real, napout-1, mpi_comm_world, ierr_mpi)
677 CALL mpi_gatherv(fy1dl, slice, mpi_real, fy1d, nelem, &
678 cumul, mpi_real, napout-1, mpi_comm_world, ierr_mpi)
679 CALL mpi_gatherv(fa1dl, slice, mpi_real, fa1d, nelem, &
680 cumul, mpi_real, napout-1, mpi_comm_world, ierr_mpi)
692 IF (iaproc .EQ. napout)
THEN
717 DO ix=cumul(iaproc)+1,cumul(iaproc)+nelem(iaproc)
722 CALL setvuf_fast(h,pp,s,p,enp,dh,dpp,ds,dp,dnp,tau,real(ygrd(iy,ix)),tide_fx,ux,vx)
726 IF (tindex.EQ.1)
THEN
729 IF (abs(tidal_const(ix,iy,indmax(i),1,1)) .GT.maxvalcon(i)) &
732 IF (tideok.EQ.0)
THEN
733 WRITE(ndse,*)
'BAD POINT:',ix,iy, tidal_const(ix,iy,:,1,1)
734 tidal_const(ix,iy,:,1,1)=0
741 IF (trim(tidecon_name(j)).EQ.
'Z0')
THEN
742 wcurtidex = wcurtidex+tidal_const(ix,iy,j,1,1)
744 tide_argx=(vx(j)+ux(j))*twpi-tidal_const(ix,iy,j,1,2)*
dera
745 wcurtidex = wcurtidex+tide_fx(j)*tidal_const(ix,iy,j,1,1)*cos(tide_argx)
752 fa1dl(ind) = wcurtidex
758 fa(ix,iy) = wcurtidex
769 IF (naproc.GT.1)
THEN
770 CALL mpi_gatherv(fx1dl, slice, mpi_real, fx1d, nelem,&
771 cumul, mpi_real, napout-1, mpi_comm_world, ierr_mpi)
772 CALL mpi_gatherv(fy1dl, slice, mpi_real, fy1d, nelem,&
773 cumul, mpi_real, napout-1, mpi_comm_world, ierr_mpi)
774 CALL mpi_gatherv(fa1dl, slice, mpi_real, fa1d, nelem,&
775 cumul, mpi_real, napout-1, mpi_comm_world, ierr_mpi)
787 IF (iaproc .EQ. napout)
THEN
808 IF (iaproc .EQ. napout)
THEN
814 CALL w3fldg (
'WRITE', idfld, ndsdat, ndst, ndse, nx, ny, &
815 nx, ny, time, time, time, fx, fy, fa, time, &
825 CALL tick21 ( time, float(prtide_dt) )
835 WRITE (ndse,1000) ierr
843 WRITE (ndse,1002) ierr
851 IF ( iaproc .EQ. napout )
WRITE (ndso,999)
853 CALL mpi_finalize ( ierr_mpi )
859 900
FORMAT (/15x,
' *** WAVEWATCH III tide prediction *** '/ &
860 15x,
'==============================================='/)
861 901
FORMAT (
' Comment character is ''',a,
''''/)
862 902
FORMAT (
' Grid name : ',a/)
863 973
FORMAT (
' Time : ',a)
865 999
FORMAT(/
' End of program '/ &
866 ' ========================================='/ &
867 ' WAVEWATCH III Input preprocessing '/)
869 1000
FORMAT (/
' *** WAVEWATCH III ERROR IN W3PRTIDE : '/ &
870 ' ERROR IN OPENING INPUT FILE'/ &
873 1001
FORMAT (/
' *** WAVEWATCH III ERROR IN W3PRTIDE : '/ &
874 ' PREMATURE END OF INPUT FILE'/)
876 1002
FORMAT (/
' *** WAVEWATCH III ERROR IN W3PRTIDE : '/ &
877 ' ERROR IN READING FROM INPUT FILE'/ &
880 1003
FORMAT (/
' *** WAVEWATCH III ERROR IN W3PRTIDE : '/ &
881 ' THE INPUT FILE DOES NOT CONTAIN TIDAL DATA'/)
883 1030
FORMAT (/
' *** WAVEWATCH III ERROR IN W3PRTIDE : '/ &
884 ' ILLEGAL FIELD ID -->',a,
'<--'/)