      common /decima/ r(2000), r2(6000)
      character ifile*50, ofile*50
      character id*56, p*8
      data isw / 13 /
      data jsw / 14 /
      ifile = ' '
      ofile = ' '
      write(unit=*, fmt=1) 
    1 format(8h ifile :$)
      read(unit=5, fmt=37) ifile
   37 format(a50)
      open(unit=isw, file=ifile, status='old', form='unformatted') 
      write(unit=*, fmt=2) 
    2 format(8h ofile :$)
      read(unit=5, fmt=37) ofile
      open(unit=jsw, file=ofile, status='new', form='unformatted') 
      read(unit=isw) id, p, nc, nr, nz, xo, dx, yo, dy
      write(unit=*, fmt=11) id, nc, nr, xo, yo, dx, dy
   11 format(1x,a56,/,' size: ',i4' X 'i4,/,' origin: ',2g14.7,/,
     &' increments: ',2g14.7)
   22 write(unit=*, fmt=33) 
   33 format(27h enter replication factor: $)
      read(unit=5, fmt=*, err=22) iskip
      if (iskip .le. 1) goto 22
      k = iskip - 1
      nc2 = nc * iskip
      nr2 = nr * iskip
      write(unit=*, fmt=3) nc2, nr2
    3 format(13h new grid is ,i4,3h X ,i4)
      dx2 = dx / float(iskip)
      dy2 = dy / float(iskip)
      xo=xo-float(k)*dx2/2.
      yo=yo-float(k)*dy2/2.
      write(unit=*, fmt=4) xo, yo, dx2, dy2
    4 format(' new origin is ',2g14.7,/,' new increments are ',2g14.7)
      write(unit=jsw) id, p, nc2, nr2, nz, xo, dx2, yo, dy2
      i = 1
      do 50 i2 = 1, nc2
      if (i .gt. nc) stop 222
   50 i = (i2 / iskip) + 1
      do 20 j = 1, nr2
      call rowio(nc, r, -1, isw, jsw, ie)
      if (ie .eq. 1) stop 'eof on ifile'
      i = 1
      do 10 i2 = 1, nc2
      r2(i2) = r(i)
   10 i = (i2 / iskip) + 1
      do 15 k2 = 1, iskip
      call rowio(nc2, r2, 0, isw, jsw, ie)
   15 continue
   20 continue
   99 close(unit=10) 
      close(unit=11) 
      stop 
      end
c
c  WHERE IOP<0 READ; IOP=0 WRITE; IOP>0 READ&WRITE
c
      subroutine rowio(n, z, iop, idev, jdev, iend)
      dimension z(n)
      iend = 0
      if (iop) 1, 2, 1
    1 read(unit=idev, end=10) xo, z
      if (iop) 9, 9, 2
    2 write(unit=jdev) xo, z
    9 return 
   10 iend = 1
      return 
      end
