c ck_fft.for
c
c  To check whether fftfilpc will redefine nrow.
c  Lin Cordell 14 Feb 91.
      dimension title(14)
      character*50 fname
      character*4 pgm1,pgm2
      data lnri/16/
      kr=11
      iw=6
      ir=5
      write(iw,115)
  115 format(' Enter ncol, nrow: ')
      print 1
      read*,ncol,nrow
20    format(a)
      print*,'Enter nadd:'
      print 1
1     format(' *'$)
      read*,nadd
c  note that x & y have been switched from normal (usgs) grid specficati
c  ...convention used is x-north y-east and z-down
      n1=nrow
      n2=ncol
      nx=n1
      ny=n2
      xo=xop
      yo=yop
      l=lnri+1
      lnri21=lnri/2+1
c  set no. of rows for fft: need m=l*2**k, m.gt. or .eq. nx+2*nadd.
c  m=no. of rows, l=no. from 9-16, k=interger.
      n1=n1+2*nadd
  190 l=l-1
      if(l.lt.lnri21) go to 260
      mr=n1/l+0.0000001
      k=1
      idiv=2
  200 iquot=mr/idiv+0.0000001
      if(iquot.lt.idiv) go to 210
      k=k+1
      mr=iquot
      go to 200
  210 k=k+1
      m=l*2**k
  220 mtest=l*2**(k-1)
      if(mtest.lt.n1) go to 230
      k=k-1
      m=mtest
      if(k.eq.0) go to 230
      go to 220
  230 lnxa=m-n1
      if(l.ne.lnri) go to 250
      nxa16=lnxa
  240 nri=l
      nxa=lnxa
      go to 190
  250 if(lnxa.ge.nxa) go to 190
      go to 240
  260 n1=n1+nxa
c  check to see if row block size of 16 will be more efficient
      n116=n1-nxa+nxa16
      ntest=0.9*n116
      if(ntest.gt.n1.or.n116.gt.2048) go to 270
      n1=n1-nxa+nxa16
      nxa=nxa16
      nri=16
  270 n2=n2+2*nadd
      write(iw,275)nri
  275 format(' blocking rows =',i3)
      if(n1.gt.2048.or.n2.gt.2048) go to 320
      nxa=nxa+2*nadd
      id2=n1
      if(n2.gt.n1)id2=n2
      id2=2*id2
c  input parameters for fft are set: call main program.
      write(5,21)n2,n1
   21 format(' New ncol = ',i4,'; new nrow = ',i4)
      itest=n1-nx+n2-ny
      if(itest.eq.0)then
        print*,'No changes.'
      else
        print*,'Dimensions would be changed'
      endif
c      call sfftfil(a1,work,nx,nri,itype,nxa,n1,n2,id2)
      go to 10
c  errors resulting in job abortion.
  280 write(iw,290)
  290 format(' #parameter error detected---case run aborted')
      go to 10
  300 write(iw,310)
  310 format(' #sign of z does not conform to continuation operator')
      go to 10
  320 write(iw,330)nx,ny,n1,n2
  330 format(' #no. of extended rows or columns exceeds 2048:'/
     1' input no. of rows and columns='2i4/
     2' no. of rows and columns required for filtering=',2i4,/)
  340 close(11)
      go to 10
  350 write(iw,360)
  360 format(' end of job')
   10 continue
      stop
      end
