    PROGRAM nag_write_mat_ex05

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

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_write_mat, ONLY : nag_write_gen_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, j, m, n
      CHARACTER (20) :: format
      CHARACTER (80) :: title
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: a(:,:)
      CHARACTER (20), ALLOCATABLE :: row_labels(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_write_mat_ex05'

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

      ALLOCATE (a(m,n),row_labels(m)) ! Allocate storage

      READ (nag_std_in,*) row_labels

      ! Generate an array of data ..

      DO j = 1, n
        DO i = 1, m
          a(i,j) = 10*i + j
        END DO
      END DO

      ! Write m by n real rectangular matrix with various optional
      ! parameters set

      format = 'F11.4'
      title = 'Output of a real rectangular matrix'

      WRITE (nag_std_out,*)

      CALL nag_write_gen_mat(a,format=format,title=title, &
       row_labels=row_labels)

      DEALLOCATE (a,row_labels)    ! Deallocate storage

    END PROGRAM nag_write_mat_ex05
