100 PRIVATE :: lfactor, tauwinds, irange
121 SUBROUTINE w3spr6 (A, CG, WN, EMEAN, FMEAN, WNMEAN, AMAX, FP)
200 REAL,
INTENT(IN) :: a(
nth,
nk), cg(
nk), wn(
nk)
201 REAL,
INTENT(OUT) :: emean, fmean, wnmean, amax, fp
207 INTEGER,
SAVE :: ient = 0
210 REAL :: eb(
nk), eband
211 REAL,
PARAMETER :: hsmin = 0.05
217 CALL strace (ient,
'W3SPR6')
222 eb = sum(a,1) *
dden / cg
227 fmean = sum(eb /
sig(1:
nk))
228 wnmean = sum(eb / sqrt(wn))
233 emean = emean + eband *
fte
234 fmean = fmean + eband *
ftf
235 wnmean = wnmean + eband *
ftwn
238 fmean =
tpiinv * emean / max(1.0e-7, fmean)
239 wnmean = ( emean / max(1.0e-7,wnmean) )**2
247 IF (4.0*sqrt(emean) .GT. hsmin)
THEN
249 fp = sum(
sig(1:
nk) * eb**4 *
dsii) / max(1e-10, sum(eb**4 *
dsii))
290 SUBROUTINE w3sin6 (A, CG, WN2, UABS, USTAR, USDIR, CD, DAIR, &
291 TAUWX, TAUWY, TAUNWX, TAUNWY, S, D )
390 REAL,
INTENT(IN) :: a (nspec), cg(nk), wn2(nspec)
391 REAL,
INTENT(IN) :: uabs, ustar, usdir, cd, dair
392 REAL,
INTENT(OUT) :: tauwx, tauwy, taunwx, taunwy
393 REAL,
INTENT(OUT) :: s(nspec), d(nspec)
398 INTEGER,
SAVE :: ient = 0
400 INTEGER :: ik, ith, ikn(nk)
401 REAL :: cosu, sinu, uproxy
402 REAL,
DIMENSION(NSPEC) :: cg2, ecos2, esin2, dsii2
403 REAL,
DIMENSION(NK) :: dsii, sig, wn
404 REAL :: k(nth,nk), sdensig(nth,nk)
405 REAL,
DIMENSION(NK) :: adensig, kmax, anar, sqrtbn
406 REAL,
DIMENSION(NSPEC) :: w1, w2, sqrtbn2, cinv2
407 REAL,
DIMENSION(NK) :: lfact, cinv
410 CALL strace (ient,
'W3SIN6')
435 ecos2 =
ecos(1:nspec)
436 esin2 =
esin(1:nspec)
438 ikn = irange(1,nspec,nth)
440 dsii2 = dden2 / dth / sig2
447 cg2(ikn+(ith-1)) = cg
453 k = reshape(a,(/ nth,nk /))
454 adensig = sum(k,1) * sig * dth
459 IF (kmax(ik).LT.1.0e-34)
THEN
462 k(1:nth,ik) = k(1:nth,ik)/kmax(ik)
467 anar = 1.0/( sum(k,1) * dth )
469 sqrtbn = sqrt( anar * adensig * wn**3 )
471 sqrtbn2(ikn+(ith-1)) = sqrtbn
478 w1 = max( 0., uproxy * cinv2* ( ecos2*cosu + esin2*sinu ) - 1. )**2
480 d = (dair /
dwat) * sig2 * &
481 (2.8 - ( 1. + tanh(10.*sqrtbn2*w1 - 11.) )) *sqrtbn2*w1
488 sdensig = reshape(s*sig2/cg2,(/ nth,nk /))
489 CALL lfactor(sdensig, cinv, uabs, ustar, usdir, sig, dsii, &
490 lfact, tauwx, tauwy )
493 IF (sum(lfact) .LT. nk)
THEN
495 d(ikn+ith-1) = d(ikn+ith-1) * lfact
506 w2 = min( 0., uproxy * cinv2* ( ecos2*cosu + esin2*sinu ) - 1. )**2
508 (2.8 - ( 1. + tanh(10.*sqrtbn2*w2 - 11.) )) *sqrtbn2*w2 )
512 sdensig = reshape(s*sig2/cg2,(/ nth,nk /))
546 SUBROUTINE w3sds6 (A, CG, WN, S, D)
643 REAL,
INTENT(IN) :: a(nspec), cg(nk), wn(nk)
644 REAL,
INTENT(OUT) :: s(nspec), d(nspec)
649 INTEGER,
SAVE :: ient = 0
651 INTEGER :: ik, ith, ikn(nk)
664 REAL :: adf(nk), xfac, edensmax
666 CHARACTER(LEN=23) :: idtime
672 CALL strace (ient,
'W3SDS6')
676 ikn = irange(1,nspec,nth)
688 etdens = (
tpi * bnt ) / ( anar * cg * wn**3 )
689 edens = sum(reshape(a,(/ nth,nk /)),1) *
tpi * sig2(ikn) * dth / cg
690 exdens = max(0.0,edens-etdens)
694 nexdens = exdens / etdens
696 edensmax = maxval(edens)*1e-5
697 IF (all(edens .GT. edensmax))
THEN
698 nexdens = exdens / edens
701 IF (edens(ik) .GT. edensmax) nexdens(ik) = exdens(ik) / edens(ik)
711 adf = anar * (nexdens**
sds6p2)
712 xfac = (1.0-1.0/xfr)/(xfr-1.0/xfr)
716 IF (ik .GT. 1 .AND. ik .LT. nk) dfii(ik) = dfii(ik) * xfac
717 t2(ik) =
sds6a2 * sum( adf(1:ik)*dfii(1:ik) )
721 t12 = -1.0 * ( max(0.0,t1)+max(0.0,t2) )
731 WRITE (
ndst,270)
'T1*E',idtime(1:19),(t1*edens)
732 WRITE (
ndst,270)
'T2*E',idtime(1:19),(t2*edens)
733 WRITE (
ndst,271) sum(sum(reshape(s,(/ nth,nk /)),1)*dden/cg)
735 270
FORMAT (
' TEST W3SDS6 : ',a,
'(',a,
')',
':',70e11.3)
736 271
FORMAT (
' TEST W3SDS6 : Total SDS =',e13.5)
769 SUBROUTINE lfactor(S, CINV, U10, USTAR, USDIR, SIG, DSII, &
770 LFACT, TAUWX, TAUWY )
861 REAL,
INTENT(IN) :: s(nth,nk)
862 REAL,
INTENT(IN) :: cinv(nk)
863 REAL,
INTENT(IN) :: u10
864 REAL,
INTENT(IN) :: ustar, usdir
865 REAL,
INTENT(IN) :: sig(nk)
866 REAL,
INTENT(IN) :: dsii(nk)
867 REAL,
INTENT(OUT) :: lfact(nk)
868 REAL,
INTENT(OUT) :: tauwx, tauwy
872 INTEGER,
SAVE :: ient = 0
874 REAL,
PARAMETER :: frqmax = 10.
875 INTEGER,
PARAMETER:: itermax = 80
877 INTEGER :: ik, nk10hz, sign_new, sign_old
879 REAL :: ecos2(nspec), esin2(nspec)
880 REAL,
ALLOCATABLE :: ik10hz(:), lf10hz(:), sig10hz(:), cinv10hz(:)
881 REAL,
ALLOCATABLE :: sdens10hz(:), sdensx10hz(:), sdensy10hz(:)
882 REAL,
ALLOCATABLE :: dsii10hz(:), ucinv10hz(:)
883 REAL :: tau_tot, tau, tau_vis, tau_wav
884 REAL :: tauvx, tauvy, taux, tauy
885 REAL :: tau_nnd, tau_init(2)
886 REAL :: uproxy, rtau, drtau, err
888 CHARACTER(LEN=23) :: idtime
892 CALL strace (ient,
'LFACTOR')
898 nk10hz = ceiling(alog(frqmax/(sig(1)/
tpi))/alog(xfr))+1
899 nk10hz = max(nk,nk10hz)
901 ALLOCATE(ik10hz(nk10hz))
902 ik10hz = real( irange(1,nk10hz,1) )
904 ALLOCATE(sig10hz(nk10hz))
905 ALLOCATE(cinv10hz(nk10hz))
906 ALLOCATE(dsii10hz(nk10hz))
907 ALLOCATE(lf10hz(nk10hz))
908 ALLOCATE(sdens10hz(nk10hz))
909 ALLOCATE(sdensx10hz(nk10hz))
910 ALLOCATE(sdensy10hz(nk10hz))
911 ALLOCATE(ucinv10hz(nk10hz))
913 ecos2 = ecos(1:nspec)
914 esin2 = esin(1:nspec)
919 IF (nk .LT. nk10hz)
THEN
920 sdens10hz(1:nk) = sum(s,1) * dth
921 sdensx10hz(1:nk) = sum(max(0.,s)*reshape(ecos2,(/nth,nk/)),1) * dth
922 sdensy10hz(1:nk) = sum(max(0.,s)*reshape(esin2,(/nth,nk/)),1) * dth
923 sig10hz = sig(1)*xfr**(ik10hz-1.0)
924 cinv10hz(1:nk) = cinv
925 cinv10hz(nk+1:nk10hz) = sig10hz(nk+1:nk10hz)*0.101978
926 dsii10hz = 0.5 * sig10hz * (xfr-1.0/xfr)
928 dsii10hz(1) = 0.5 * sig10hz(1) * (xfr-1.0)
929 dsii10hz(nk10hz) = 0.5 * sig10hz(nk10hz) * (xfr-1.0) / xfr
932 sdens10hz(nk+1:nk10hz) = sdens10hz(nk) * (sig10hz(nk)/sig10hz(nk+1:nk10hz))**2
933 sdensx10hz(nk+1:nk10hz) = sdensx10hz(nk) * (sig10hz(nk)/sig10hz(nk+1:nk10hz))**2
934 sdensy10hz(nk+1:nk10hz) = sdensy10hz(nk) * (sig10hz(nk)/sig10hz(nk+1:nk10hz))**2
939 sdens10hz(1:nk) = sum(s,1) * dth
940 sdensx10hz(1:nk) = sum(max(0.,s)*reshape(ecos2,(/nth,nk/)),1) * dth
941 sdensy10hz(1:nk) = sum(max(0.,s)*reshape(esin2,(/nth,nk/)),1) * dth
946 tau_tot = ustar**2 *
dair
950 tau_vis = max(0.0, -5.0e-5*u10 + 1.1e-3) * u10**2 *
dair
952 tau_vis = min(0.95 * tau_tot, tau_vis)
954 tauvx = tau_vis * cos(usdir)
955 tauvy = tau_vis * sin(usdir)
958 tauwx = tauwinds(sdensx10hz,cinv10hz,dsii10hz)
959 tauwy = tauwinds(sdensy10hz,cinv10hz,dsii10hz)
960 tau_nnd = tauwinds(sdens10hz, cinv10hz,dsii10hz)
961 tau_wav = sqrt(tauwx**2 + tauwy**2)
962 tau_init = (/tauwx,tauwy/)
966 tau = sqrt(taux**2 + tauy**2)
967 err = (tau-tau_tot)/tau_tot
975 IF (tau .GT. tau_tot)
THEN
979 sign_new = int(sign(1.0,err))
982 ucinv10hz = 1.0 - (uproxy * cinv10hz)
985 WRITE (
ndst,270) idtime, u10
989 lf10hz = min(1.0, exp(ucinv10hz * rtau) )
991 tau_nnd = tauwinds(sdens10hz *lf10hz,cinv10hz,dsii10hz)
992 tauwx = tauwinds(sdensx10hz*lf10hz,cinv10hz,dsii10hz)
993 tauwy = tauwinds(sdensy10hz*lf10hz,cinv10hz,dsii10hz)
994 tau_wav = sqrt(tauwx**2 + tauwy**2)
998 tau = sqrt(taux**2 + tauy**2)
999 err = (tau-tau_tot) / tau_tot
1002 sign_new = int(sign(1.0, err))
1004 WRITE (
ndst,272) ik, rtau, drtau, tau, tau_tot, err, &
1005 tauwx, tauwy, tauvx, tauvy, tau_nnd
1009 IF (sign_new .NE. sign_old) overshot = .true.
1010 IF (overshot) drtau = max(0.5*(1.0+drtau),1.00010)
1012 rtau = rtau * (drtau**sign_new)
1014 IF (abs(err) .LT. 1.54e-4)
EXIT
1017 IF (ik .GE. itermax)
WRITE (
ndst,280) idtime(1:19), u10, tau, &
1018 tau_tot, err, tauwx, tauwy, tauvx, tauvy,tau_nnd
1021 lfact(1:nk) = lf10hz(1:nk)
1024 WRITE (
ndst,273)
'Sin ', idtime(1:19), sdens10hz*
tpi
1025 WRITE (
ndst,273)
'SinR', idtime(1:19), sdens10hz*lf10hz*
tpi
1026 WRITE (
ndst,274)
'Sin ', sum(sdens10hz(1:nk)*dsii)
1027 WRITE (
ndst,274)
'SinR ', sum(sdens10hz(1:nk)*lf10hz(1:nk)*dsii)
1028 WRITE (
ndst,274)
'SinR/C', tauwinds(sdens10hz(1:nk)*lfact,cinv,dsii)
1030 270
FORMAT (
' TEST W3SIN6 : LFACTOR SUBROUTINE CALCULATING FOR ', &
1032 271
FORMAT (
' TEST W3SIN6 : IK RTAU DRTAU TAU TAU_TOT' &
1033 ' ERR TAUW_X TAUW_Y TAUV_X TAUV_Y TAU1D' )
1034 272
FORMAT (
' TEST W3SIN6 : ',i2,2f9.5,2f8.5,e10.2,4f7.4,f7.3 )
1035 273
FORMAT (
' TEST W3SIN6 : ',a,
'(',a,
'):', 70e11.3 )
1037 274
FORMAT (
' TEST W3SIN6 : Total ',a,
' =', e13.5 )
1038 280
FORMAT (
' WARNING LFACTOR (TIME,U10,TAU,TAU_TOT,ERR,TAUW_XY,' &
1039 'TAUV_XY,TAU_SCALAR): ',a,f6.1,2f7.4,e10.3,4f7.4,f7.3 )
1041 DEALLOCATE(ik10hz,sig10hz,cinv10hz,dsii10hz,lf10hz)
1042 DEALLOCATE(sdens10hz,sdensx10hz,sdensy10hz,ucinv10hz)
1044 END SUBROUTINE lfactor
1126 REAL,
INTENT(IN) :: S(NTH,NK)
1127 REAL,
INTENT(IN) :: CINV(NK)
1128 REAL,
INTENT(IN) :: SIG(NK)
1129 REAL,
INTENT(IN) :: DSII(NK)
1130 REAL,
INTENT(OUT) :: TAUNWX, TAUNWY
1134 INTEGER,
SAVE :: IENT = 0
1136 REAL,
PARAMETER :: FRQMAX = 10.
1139 REAL :: ECOS2(NSPEC), ESIN2(NSPEC)
1140 REAL,
ALLOCATABLE :: IK10Hz(:), SIG10Hz(:), CINV10Hz(:)
1141 REAL,
ALLOCATABLE :: SDENSX10Hz(:), SDENSY10Hz(:)
1142 REAL,
ALLOCATABLE :: DSII10Hz(:), UCINV10Hz(:)
1146 CALL strace (ient,
'TAU_WAVE_ATMOS')
1151 nk10hz = ceiling(alog(frqmax/(sig(1)/
tpi))/alog(
xfr))+1
1152 nk10hz = max(nk,nk10hz)
1154 ALLOCATE(ik10hz(nk10hz))
1155 ik10hz = real( irange(1,nk10hz,1) )
1157 ALLOCATE(sig10hz(nk10hz))
1158 ALLOCATE(cinv10hz(nk10hz))
1159 ALLOCATE(dsii10hz(nk10hz))
1160 ALLOCATE(sdensx10hz(nk10hz))
1161 ALLOCATE(sdensy10hz(nk10hz))
1162 ALLOCATE(ucinv10hz(nk10hz))
1164 ecos2 =
ecos(1:nspec)
1165 esin2 =
esin(1:nspec)
1170 IF (nk .LT. nk10hz)
THEN
1171 sdensx10hz(1:nk) = sum(abs(min(0.,s))*reshape(ecos2,(/nth,nk/)),1) *
dth
1172 sdensy10hz(1:nk) = sum(abs(min(0.,s))*reshape(esin2,(/nth,nk/)),1) *
dth
1173 sig10hz = sig(1)*
xfr**(ik10hz-1.0)
1174 cinv10hz(1:nk) = cinv
1175 cinv10hz(nk+1:nk10hz) = sig10hz(nk+1:nk10hz)*0.101978
1176 dsii10hz = 0.5 * sig10hz * (
xfr-1.0/
xfr)
1178 dsii10hz(1) = 0.5 * sig10hz(1) * (
xfr-1.0)
1179 dsii10hz(nk10hz) = 0.5 * sig10hz(nk10hz) * (
xfr-1.0) /
xfr
1182 sdensx10hz(nk+1:nk10hz) = sdensx10hz(nk) * (sig10hz(nk)/sig10hz(nk+1:nk10hz))**2
1183 sdensy10hz(nk+1:nk10hz) = sdensy10hz(nk) * (sig10hz(nk)/sig10hz(nk+1:nk10hz))**2
1188 sdensx10hz(1:nk) = sum(abs(min(0.,s))*reshape(ecos2,(/nth,nk/)),1) *
dth
1189 sdensy10hz(1:nk) = sum(abs(min(0.,s))*reshape(esin2,(/nth,nk/)),1) *
dth
1194 taunwx = tauwinds(sdensx10hz,cinv10hz,dsii10hz)
1195 taunwy = tauwinds(sdensy10hz,cinv10hz,dsii10hz)
1214 FUNCTION irange(X0,X1,DX)
RESULT(IX)
1232 INTEGER,
INTENT(IN) :: X0, X1, DX
1233 INTEGER,
ALLOCATABLE :: IX(:)
1237 n = int(real(x1-x0)/real(dx))+1
1240 ix(i) = x0+ (i-1)*dx
1267 FUNCTION tauwinds(SDENSIG,CINV,DSII)
RESULT(TAU_WINDS)
1289 REAL,
INTENT(IN) :: SDENSIG(:)
1290 REAL,
INTENT(IN) :: CINV(:)
1291 REAL,
INTENT(IN) :: DSII(:)
1294 tau_winds =
grav *
dwat * sum(sdensig*cinv*dsii)
1296 END FUNCTION tauwinds