    PROGRAM nag_write_mat_ex03

      ! 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_gen_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC CMPLX, KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: m = 4, n = 3
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, j, k, l
      CHARACTER (30) :: format
      CHARACTER (80) :: title
      ! .. Local Arrays ..
      COMPLEX (wp) :: a(m,n)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_write_mat_ex03'

      ! Generate an array of data

      l = -1
      DO j = 1, n
        l = -l*j
        DO i = 1, m
          k = (-1)**(i+j)
          a(i,j) = CMPLX(l,k*(i+j),kind=wp)
        END DO
      END DO

      ! Write a complex matrix using defaults

      WRITE (nag_std_out,*)

      CALL nag_write_gen_mat(a)

      ! Write a complex matrix with title, integer labels and
      ! cmplx_form='a'

      title = &
       'Output the same matrix with title, integer labels and cmplx_form="a"'

      WRITE (nag_std_out,*)

      CALL nag_write_gen_mat(a,title=title,int_row_labels=.TRUE., &
       int_col_labels=.TRUE.,cmplx_form='a')

      ! Write a complex matrix with title, integer labels and
      ! cmplx_form='d'

      title = 'Output the same matrix with title and cmplx_form="d"'
      format = '(s,f7.2,sp,f5.2,"i")'
      WRITE (nag_std_out,*)

      CALL nag_write_gen_mat(a,title=title,format=format,cmplx_form='d')

    END PROGRAM nag_write_mat_ex03
