C+ C NAME: C TimeSmooth C PURPOSE: C Smoothes a three-dimensional array in time by filtering with a C Gaussian filter. The third dimension in the array is assumed to be C evenly-spaced. C CALLING SEQUENCE: subroutine Timesmooth(nLng,nLat,nT,Z,iFillBadZ,Widtime,Wclip,Ztmp) C INPUTS: C nLng integer # longitudes C nLat integer # latitudes C nT integer # times C Z(nLng,nLat,nT) real 3D array of function values C iFillBadZ integer 0: Invalid elements remain invalid; C valid elements are replaced by a C smoothed value C 1: All elements (valid and invalid) are C replaced by smoothed values. C 2: Invalid elements are replaced by C smoothed values; valid elements remain C untouched. C Widtime real Width of Gaussian used for time C smoothing (in units of nT) C Wclip real amplitude of Gaussian clipping C relative to midpoint C Ztmp(nLng,nLat,nT) real 3D temporary array of function values C OUTPUTS: C Z(nLng,nLat,nR) real smoothed array of function values C PROCEDURE: C MODIFICATION HISTORY: C Sept-1999, B. Jackson (UCSD) C- real Z(nLng,nLat,nT) real Ztmp(nLng,nLat,nT) Widtime2 = Widtime*Widtime Bad = BadR4() Wc = Wclip if (Wc .le. 0.11) Wc = 0.11 ! Default value of Wclip clip = 1.0/(Wc*Wc) nTm1 = nT-1 !$omp parallel private(i,j,k,wt,zwt,gamp,kk,km,kp,ex) !$omp do schedule(static) do k=1,nT do j=1,nLat do i=1,nLng Ztmp(i,j,k) = Z(i,j,k) end do end do end do !$omp end do nowait !$omp do schedule(static) do k=1,nT do j=1,nLat do i=1,nLng wt = 0.0 zwt = 0.0 do kk=1,nTm1 gamp = kk*kk/Widtime2 if (gamp .le. clip) then km = k - kk kp = k + kk if (km .ge. 1) then if (Ztmp(i,j,km) .ne. Bad) then ex = exp(-gamp) wt = wt + ex zwt = Ztmp(i,j,km)*ex + zwt end if end if if (kp .le. nT) then if (Ztmp(i,j,kp) .ne. Bad) then ex = exp(-gamp) wt = wt + ex zwt = Ztmp(i,j,kp)*ex + zwt end if end if end if end do if (Ztmp(i,j,k) .ne. Bad) then wt = wt + 1.0 zwt = zwt+ Ztmp(i,j,k) end if if (wt .ne. 0.0) then zwt = zwt/wt else zwt = Bad end if if (iFillBadZ .eq. 0) then if (Z(i,j,k) .ne. Bad) Z(i,j,k) = zwt else if (iFillBadZ .eq. 1) then Z(i,j,k) = zwt else if (iFillBadZ .eq. 2) then if (Z(i,j,k) .eq. Bad) Z(i,j,k) = zwt end if end do end do end do !$omp end do nowait !$omp end parallel return end