    PROGRAM c09bafe

!      C09BAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : c09baf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: ifail, j, n, nscal, wparam
       CHARACTER (10)                  :: wavnam
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: c(:,:), x(:)
       INTEGER, ALLOCATABLE            :: scales(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          trim
!      .. Executable Statements ..
       WRITE (nout,*) 'C09BAF Example Program Results'
       WRITE (nout,*)
!      Skip heading in data file
       READ (nin,*)
!      Read problem parameters
       READ (nin,*) n, nscal
       ALLOCATE (c(nscal,n),scales(nscal),x(n))
       READ (nin,*) wavnam, wparam
       WRITE (nout,99999) trim(wavnam), wparam, n, nscal

!      Read data array and write it out

       READ (nin,*) scales(1:nscal)
       READ (nin,*) x(1:n)

       WRITE (nout,99998) scales(1:nscal)
       WRITE (nout,99997) x(1:n)

!      ifail: behaviour on error exit   
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
       CALL c09baf(wavnam,wparam,n,x,nscal,scales,c,ifail)

       WRITE (nout,99996) nscal
       WRITE (nout,99995) scales(1:nscal)
       DO j = 1, n
          WRITE (nout,99994) c(1:nscal,j)
       END DO

99999  FORMAT (2X,'Parameters read from file ::'/4X,'Wavelet : ',A, &
          ',  wparam : ',I6/10X,'n : ',I6,',   nscal : ',I6)
99998  FORMAT (/2X,'Input Data ::'/4X,' Scales :',5(I8,1X):)
99997  FORMAT (5X,'     x :',5(F8.3,1X),(/13X,5(F8.3,1X)):)
99996  FORMAT (/2X,'Number of Scales :      ',I10)
99995  FORMAT (2X,'Wavelet coefficients C ::'/4X,'Scale :',I7,3I13)
99994  FORMAT (10X,4(1P,E11.4,2X):)
    END PROGRAM c09bafe
