    PROGRAM nag_write_mat_ex02

      ! 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_tri_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND, REAL
      ! .. Parameters ..
      INTEGER, PARAMETER :: m = 5, n = 4
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, j
      CHARACTER (160) :: title
      CHARACTER (1) :: uplo
      ! .. Local Arrays ..
      REAL (wp) :: a(n,n), p((m*(m+1))/2)
      CHARACTER (6) :: row_labels(m)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_write_mat_ex02'

      ! Generate an array of data

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

      ! Write real upper triangular matrix stored in convential storage
      ! using default optional arguments

      uplo = 'U'
      WRITE (nag_std_out,*)

      CALL nag_write_tri_mat(uplo,a)

      ! Generate arrays of data and row labels

      DO i = 1, (m*(m+1))/2
        p(i) = REAL(10*i,kind=wp)
      END DO

      DO i = 1, m
        WRITE (row_labels(i),'(a,i3)') 'row', i
      END DO

      ! Write real lower triangular matrix stored in packed storage
      ! using title, unit diagonal elements, character row labels
      ! and integer column labels

      uplo = 'l'
      title = 'Output real lower triangular matrix in packed storage &
       &with unit diagonal        elements, title, character row &
       &labels and integer column labels'

      WRITE (nag_std_out,*)

      CALL nag_write_tri_mat(uplo,p,diag='u',title=title, &
       row_labels=row_labels,int_col_labels=.TRUE.)

    END PROGRAM nag_write_mat_ex02
