c                                                                               
c     ASCII2SF  -ascii to standard grid                                         
c                                                                               
      character*50 infile,outfile                                               
      character*56 id,pgm*8                                                     
      dimension data(10008)
      print *,'80 column ascii to standard binary grid'                         
      print *,'Name of ascii input grid?'                                       
      read (5,100)infile                                                        
 100  format(a50)                                                               
      open(10,file=infile,form='formatted',status='old')
      print *,'Name of binary output grid'                                      
      read(5,100)outfile                                                        
c      open(11,file=outfile,form='unformatted',status='unknown')
      call gopen(11,outfile,'new','write',ierr)
c                                                                               
      read(10,110,err=1301,end=1302)id,pgm,ncol,nrow                            
  110 format(a56,a8,2i8)
      call pfinit(pgm)
      read(10,120,err=1301,end=1302)nz,xo,dx,yo,dy                              
  120 format(i2,4e18.8)                                                         
c      write(11)id,pgm,ncol,nrow,nz,xo,dx,yo,dy
      call gheader('w',11,id,ncol,nrow,xo,dx,yo,dy,ierr)
      write(6,130)id,pgm,ncol,nrow,nz,xo,dx,yo,dy                               
  130 format(1x,a56,a8,/,1x,'ncol=',i8,' nrow=',i8,' nz='
     1,i3,' xo=',e16.8,' dx=',e16.8,/,1x,'yo=',e16.8,'
     2 dy=',e16.8)
c                                                                               
      do 10 irow=1,nrow                                                         
      do 20 j=1,ncol+1,5                                                        
   20 if (inarow(data(j)).ne.0) go to 1303                                      
c   10 call outbrow(ncol+1,data)
   10 call grow('w',11,data(1),data(2),ncol,ierr)
      print *,'All done'                                                        
      call gclose(10,'keep')
      call gclose(11,'keep')
      return
c                                                                               
c     error exits                                                               
c                                                                               
 1301 print *,'Error reading header information'                                
      return
c                                                                               
 1302 print*,'End of file while reading header information'                     
      return
c                                                                               
 1303 print *,'Error while reading row',irow,' of input grid'                   
c      stop
      end                                                                       
c                                                                               
c     INAROW - INput Ascii ROW                                                  
c                                                                               
      integer function inarow(data)                                             
      dimension data(5)                                                         
      read(10,100,err=99,end=99)data                                            
  100 format(5e16.9)                                                            
      inarow=0                                                                  
      return                                                                    
c                                                                               
   99 inarow=-1                                                                 
      return                                                                    
      end                                                                       
c                                                                               
c     OUTBROW - OUTput Binary ROW                                               
c                                                                               
c      subroutine outbrow(idim,data)
c      dimension data(idim)
c      write(11) data
c      return
c      end
