    PROGRAM nag_write_mat_ex07

      ! 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
      ! .. Local Scalars ..
      INTEGER :: i, indent, j, m, n, rec_len
      CHARACTER (20) :: format
      CHARACTER (80) :: title
      ! .. Local Arrays ..
      INTEGER, ALLOCATABLE :: a(:,:)
      CHARACTER (20), ALLOCATABLE :: col_labels(:), row_labels(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_write_mat_ex07'

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

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

      READ (nag_std_in,*) row_labels
      READ (nag_std_in,*) col_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 integer rectangular matrix with various optional
      ! parameters set

      format = 'I8'
      title = 'Output an integer rectangular matrix'
      rec_len = 72
      indent = 4

      WRITE (nag_std_out,*)

      CALL nag_write_gen_mat(a,format=format,title=title, &
       row_labels=row_labels,col_labels=col_labels,rec_len=rec_len, &
       indent=indent)

      DEALLOCATE (a,row_labels,col_labels) ! Deallocate storage

    END PROGRAM nag_write_mat_ex07
