      program formatagrid
C program to structure an ascii grid for MODFLOW formatted input
C reads a matrix, then assigns correct formatting and write result 
      parameter(nrowmax=200,ncolmax=200)
C
      real*8 deltax,deltay
      real*8 floatmatrix
      integer nrows,ncols
      integer intmatrix
      dimension floatmatrix(nrowmax,ncolmax)
      dimension intmatrix(nrowmax,ncolmax)
      character*10 ch1,ch2,ch3,ch4,ch5,ch6,ch7
C
C assume redirection is used for I/O 
C
      read(*,*)nrows,ncols
      read(*,*)deltay,deltax
      do 1001 irow=1,nrows
        read(unit=5,fmt=*,end=8001)(intmatrix(irow,jcol),jcol=1,ncols)
 1001 continue
 8001 write(*,*)'exit because EOF marker'
      write(*,*)'irow value ',irow
      write(*,*)'jcol value ',jcol
      write(*,*)'nrows :',nrows
      write(*,*)'ncols :',ncols
      write(*,*)'spacing between rows    :',deltay
      write(*,*)'spacing between columns :',deltax
C typical formatting directives for 2Darray reader
C 234567890123456789012345678901234567890123456789012345678901234567890
      ch1='        1'
      ch2='         1'
      ch3='    (10I3)'
      ch4='          '
      ch5='         0'
      ch6='   IBOUND-'
      ch7='         1'
      write(*,*)ch1 // ch2 // ch3 // ch4 // ch5 // ch6 // ch7
C write the boundary array
      do 1005 irow=1,nrows
        write(*,9002)(intmatrix(irow,jcol),jcol=1,ncols)
 1005 continue
C build the storage array

      stop
 9001 format(10(1x,g9.3))
 9002 format(10(1x,i2))
      end
