c         program subset
c         creates a standard file subset                               
c                                                                               
          subroutine subset(z,igrid,icol1,icol2,irow1,irow2,ierr)
          dimension z(1),title(14),pgm(2)                                    

          ierr = 0
          read(igrid,err=40,iostat=icheck) title,pgm,ncol,nrow,
     &         nz,xo,dx,yo,dy                       
          mcol=ncol+1                                                        

          ncol1=icol2-icol1+1                                                   
          nrow1=irow2-irow1+1                                                   
          xo1=xo+(icol1-1)*dx                                                   
          yo1=yo+(irow1-1)*dy                                                   

          open(igrid+1,status='scratch',form='unformatted',
     &         err=40,iostat=icheck)
          write(igrid+1,err=40,iostat=icheck) title,pgm,ncol1,nrow1,
     &          nz,xo1,dx,yo1,dy                      
c         add one to column indexes for dummy value at start 
c         of each row

          ic1=icol1 + 1                                               
          ic2=icol2 + 1                                                      
          do 20 i=1,nrow                                                      
          call rowin(z,mcol,igrid)                                             
25        if(i.lt.irow1) go to 20                                               
          write(igrid+1,err=40,iostat=icheck) z(1),(z(j),j=ic1,ic2) 
          if(i.eq.irow2) go to 30                           
20        continue                                                              
30        return                                                               
40        print *,'error no. ',icheck,' in subroutine subset'
          ierr = 1
          return
          end                                                                   
c**********
      subroutine rowin(z,ncol,in)
      dimension z(ncol)
      read(in) z
      return
      end
