c
c     file: /export/software/puddle0/dems/plotmatrix.f
c     Last Modified: 11/06/96
c
c     Written by: Glenn E. Moglen
c
c     Program reads in elevation OR area DEM file and then prints out
c     PURE matrix interpretation of that file for importation into
c     MATLAB.  Program reads from plotmatrix.in which has the format:
c
c     plotbasin.in:
c           input demfile
c           output matrixfile
c           ifile
c
c     where ifile = 
c                  0 if elevation DEM file
c                  1 if area DEM file
c 
      Program main            
      PARAMETER(IGRIDY=2404,IGRIDX=2404)                
      INTEGER*2 ELEV(IGRIDY,IGRIDX)
      integer*4 nx, ny, nxnew, nynew, area(igridy, igridx)
      real*4 dx, dy
      CHARACTER*80 infile, outfile      
      OPEN(UNIT=11,FILE='plotmatrix.in',STATUS='OLD',readonly)
      READ(11,22) infile, outfile
      read(11, *) ifile
 22   FORMAT(A80/A80)  
      close (11, status = 'keep')    
      open (16, file = outfile, form = 'formatted', status = 'unknown')   
      if (ifile .eq. 0) then      
         CALL demread (ELEV, infile, NX, NY, IGRIDY, DX, DY)
         do i = 1, nx
            write (16, 100) (elev(j, i), j = 1, ny)
         end do
      else
         call demread (area, infile, nx, ny, igridy, dx, dy)
         do i = 1, nx
               write (16, 100) (area(j, i), j = 1, ny)
         end do
      end if          
      close (16, status = 'keep')
 100  format (1x, 1000i7)
      end                                         
