cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c      program ckvalue
c
c      Checks an aeromag file for values which exceed given threshholds.

      character id1*8
      character*1 ans
      dimension post1(8)

      print '(a,$)', ' Give post option to be tested [1-6]:  '
      read *, nopt
      nopt=nopt+2

      print '(/a,$)', ' Give min,max acceptable values:  '
      read *, vmin,vmax

      call getfile2(21,' Infile ','in','unformatted','.pos')
      call getfile2(22,' Outfile of good values ','out',
     &   'unformatted','.gd')

      print '(/a,$)',' Want an ascii outfile of bad values? [y/n]: '
      read '(a1)',ans
      if(ans.eq.'y') then
        call getfile2(23,' Bad value file ','out','formatted',
     &   '.bad')
      else
      endif


      ngood=0
      nbadv=0
      npts=0
 10   call getpost (21, id1, post1, *90)
      npts=npts+1
      v1=post1(nopt)
      if(v1.le.vmin.or.v1.ge.vmax) go to 30
      call putpost (22, id1, post1)
      ngood=ngood+1
      go to 10

c     bad points get dumped ingloriously....

 30   if(ans.eq.'y') write(23,101) id1,post1
 101  format(a8,f10.4,f9.4,f8.2,f9.2,3f8.2,f11.3)
      nbadv=nbadv+1
      go to 10

 90   close(21)
      call closeblp (22)
      if(ans.eq.'y') close(23)

      print *,'   NPTS      =',npts
      print *,'   NGOOD     =',ngood
      print *,'   NBADV     =',nbadv

      stop ' '
      end
