    PROGRAM nag_write_mat_ex04

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

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_out
      USE nag_write_mat, ONLY : nag_write_bnd_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND, REAL
      ! .. Parameters ..
      INTEGER, PARAMETER :: kl = 1, ku = 2, n = 5
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      INTEGER, PARAMETER :: diag_index = ku + 1
      ! .. Local Scalars ..
      INTEGER :: i, j
      CHARACTER (80) :: title
      ! .. Local Arrays ..
      REAL (wp) :: a(kl+ku+1,n)
      CHARACTER (6) :: col_labels(n)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_write_mat_ex04'

      ! Generate an array of data

      DO i = 1, kl + ku + 1
        DO j = 1, n
          a(i,j) = REAL(10*i+j,kind=wp)
        END DO
      END DO

      ! Write the complex 5 by 5 banded matrix stored in a

      WRITE (nag_std_out,*)

      CALL nag_write_bnd_mat(ku,a)

      ! Write the upper part of the 4 by 4 section of the banded matrix
      ! stored in a, using a title

      title = 'Output the upper part of a section of the band matrix'
      WRITE (nag_std_out,*)

      CALL nag_write_bnd_mat(ku,a(1:diag_index,1:4),title=title)

      ! Generate column labels

      DO i = 1, n
        WRITE (col_labels(i),'(a,i3)') 'col', i
      END DO

      ! Write one sub-diagonal and one super diagonal of the banded
      ! matrix stored in a, using a title, character column labels
      ! and integer row labels

      title = &
       'Output the band matrix with one sub-diagonal and one super-diagonal'
      WRITE (nag_std_out,*)

      CALL nag_write_bnd_mat(1,a(diag_index-1:diag_index+1,:),title=title, &
       col_labels=col_labels,int_row_labels=.TRUE.)

    END PROGRAM nag_write_mat_ex04
