    PROGRAM nag_gen_bnd_lin_sys_ex01

      ! Example Program Text for nag_gen_bnd_lin_sys
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_gen_bnd_lin_sys, ONLY : nag_gen_bnd_lin_sol
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND, MAX, MIN
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, j, kl, ku, n
      REAL (wp) :: bwd_err, fwd_err, rcond
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: a(:,:), b(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) &
       'Example Program Results for nag_gen_bnd_lin_sys_ex01'

      READ (nag_std_in,*)          ! Skip heading in data file
      READ (nag_std_in,*) n, kl, ku

      ALLOCATE (a(kl+ku+1,n),b(n)) ! Allocate storage

      DO i = 1, n
        READ (nag_std_in,*) (a(ku+1+i-j,j),j=MAX(1,i-kl),MIN(i+ku,n))
      END DO
      READ (nag_std_in,*) b

      ! Solve the system of equations

      CALL nag_gen_bnd_lin_sol(ku,a,b,rcond=rcond,bwd_err=bwd_err, &
       fwd_err=fwd_err)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,'(1X,''kappa(A) (1/rcond)''/2X,ES11.2)') 1/rcond
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Solution'
      WRITE (nag_std_out,'(4X,F9.4)') b
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Backward error bound'
      WRITE (nag_std_out,'(2X,4ES11.2)') bwd_err
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Forward error bound (estimate)'
      WRITE (nag_std_out,'(2X,4ES11.2)') fwd_err

      DEALLOCATE (a,b)             ! Deallocate storage

    END PROGRAM nag_gen_bnd_lin_sys_ex01
