Contents of file named simple_filter.f90


! Demonstrate a simple bandpass Butterworth filter using
! the XAPIIR library distributed with SAC. 
program simple_filter
   implicit none
   integer, parameter :: nmax = 10000
   integer :: nlen, npts, nerr
   real*4 :: data(nmax) 
   real*4 :: beg, dt, unused

   ! filter parameters
   integer :: n_order, n_pass
   real*4 :: flo, fhi
   
   ! Read in the data file
   call rsac1('raw.sac',data,npts,beg,dt,nmax,nerr)

   ! Set up filter parameters
   n_order = 2   ! two pole
   n_pass  = 2   ! two pass   
   flo     = 1.0 ! low cut-off
   fhi     = 5.0 ! high cut-off
   unused  = 0.0 ! does not apply for Butterworth.
   
   ! call the filter library, specifying a Butterworth
   ! bandpass filter. 
   call xapiir(data,npts,'BUTTER', &
      unused,unused,n_order,'BP',flo,fhi,dt,n_pass)
   
   ! write the filtered back to disk.
   call wsac0('filt.sac',data,data,nerr)
   
end program simple_filter