! $Id: runav.f90 2022-10-27 09:51:28Z ychen $ !****s* fsi/runav * ! ! NAME ! runav - This subroutine performs running averaging with sliding window ! ! SYNOPSIS ! call runav(nw,x,y) ! ! DESCRIPTION ! This subroutine performs running averaging with sliding window ! ! INPUTS ! INTEGER, :: nw window size for averaging (nw must be odd !!!) ! REAL(wp), DIMENSION(:), :: x input array ! ! OUTPUT ! REAL(wp), DIMENSION(:), :: y output array after smoothing ! ! AUTHOR ! Yong Chen, NOAA/NESDIS/STAR, yong.chen@noaa.gov ! Loknath Adhikari, UMD/CISESS, loknath.adhikari@noaa.gov ! ! COPYRIGHT ! Copyright (c) 2022-2023 Yong Chen ! For further details please refer to the file COPYRIGHT ! which you should have received as part of this distribution. ! !**** SUBROUTINE runav(nw,x,y) USE typesizes, ONLY: wp => EightByteReal IMPLICIT none INTEGER, INTENT(inout) :: nw ! window size for averaging (nw must be odd !!!) REAL(wp), DIMENSION(:), INTENT(in) :: x ! input array REAL(wp), DIMENSION(:), INTENT(inout) :: y ! output array after smoothing INTEGER :: nmax, i, j, nw2 nmax = SIZE(x) DO i=1,nmax y(i) = x(i) ENDDO ! make sure nx is an odd number IF (mod(nw, 2) /= 1) THEN nw = nw - 1 ENDIF nw2=(nw-1)/2 DO i = nw2+1,nmax-nw2 y(i)=0.0_wp DO j=-nw2,+nw2 y(i)=y(i) + x(i+j) ENDDO y(i)=y(i)/nw ENDDO END SUBROUTINE runav