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. The subroutine can be run in three different modes. C ipshtd uses this program only in in mode = 0. C C CALLING SEQUENCE: C call 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- subroutine Timesmooth(nLng,nLat,nT,Z,iFillBadZ,Widtime,Wclip,Ztmp) real Z(nLng,nLat,nT), & Ztmp(nLng,nLat,nT) Widtime2 = Widtime*Widtime Bad = BadR4() Wc = Wclip if(Wc.le.0.11) Wc = .11 ! Default value of Wclip clip = 1./(Wc*Wc) nTm1 = nT-1 do i=1,nLng do j=1,nLat do k=1,nT Ztmp(i,j,k) = Z(i,j,k) end do end do end do do i=1,nLng do j=1,nLat do k=1,nT wt = 0. zwt = 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. zwt = Ztmp(i,j,k) + zwt end if if(wt.ne.0.) then zwt = zwt/wt else zwt = Bad end if if(iFillBadZ.eq.0.and.Z(i,j,k).ne.Bad) Z(i,j,k) = zwt if(iFillBadZ.eq.1) Z(i,j,k) = zwt if(iFillBadZ.eq.2.and.Z(i,j,k).eq.Bad) Z(i,j,k) = zwt end do end do end do return end