SUBROUTINE MovingAvg(DataIn,NumDataItems,NumItemsInAvg,SmoothedData)
! SUBROUTINE INFORMATION:
! AUTHOR Fred Buhl
! DATE WRITTEN January 2003
! MODIFIED na
! RE-ENGINEERED na
! PURPOSE OF THIS SUBROUTINE:
! Smooth the data in the 1-d array DataIn by averaging over a window NumItemsInAvg
! wide. Return the results in the 1-d array SmoothedData
! METHODOLOGY EMPLOYED:
! Note that DataIn and SmoothedData should have the same size. This is the reponsibility
! of the calling routine. NumItemsInAvg should be no bigger than the size of DataIn.
! REFERENCES:
! na.
! USE STATEMENTS:
! na
IMPLICIT NONE ! Enforce explicit typing of all variables in this routine
! SUBROUTINE ARGUMENT DEFINITIONS:
INTEGER, INTENT(IN) :: NumDataItems ! number of values in DataIn
REAL(r64), INTENT(IN), DIMENSION(NumDataItems) :: DataIn ! input data that needs smoothing
INTEGER, INTENT(IN) :: NumItemsInAvg ! number of items in the averaging window
REAL(r64), INTENT(OUT), DIMENSION(NumDataItems) :: SmoothedData ! output data after smoothing
! SUBROUTINE PARAMETER DEFINITIONS:
! INTERFACE BLOCK SPECIFICATIONS
! DERIVED TYPE DEFINITIONS
! SUBROUTINE LOCAL VARIABLE DECLARATIONS:
INTEGER :: i ! loop index
INTEGER :: j ! inner loop index
REAL(r64), DIMENSION(:), ALLOCATABLE :: TempData ! a scratch array
ALLOCATE(TempData(3*NumDataItems))
DO i=1,NumDataItems
TempData(i) = DataIn(i)
TempData(NumDataItems+i) = DataIn(i)
TempData(2*NumDataItems+i) = DataIn(i)
SmoothedData(i) = 0.0d0
END DO
DO i=1,NumDataItems
DO j=1,NumItemsInAvg
SmoothedData(i) = SmoothedData(i) + TempData(NumDataItems+i-NumItemsInAvg+j)
END DO
SmoothedData(i) = SmoothedData(i) / REAL(NumItemsInAvg,r64)
END DO
DEALLOCATE(TempData)
RETURN
END SUBROUTINE MovingAvg