        program inplane
	
	include 'inplane.cmm'

	open(33,file='steer')
	  read(33,'(a)')fname
          read(33,*)tcut
        close(33)
	
        
	call ini
	call read
	
	end



	subroutine ini
	
	include 'inplane.cmm'
	
	pi=4.*atan(1.)
	tec=23.0E-6
	end



	subroutine read
	include 'inplane.cmm'
	character*125 string
        character*8 resu
	character*1 ch(125)
	character*16 sys,sname
	character*60 comment,comm
	equivalence(string,ch)
	equivalence(ch(31),sys)
	equivalence(ch(65),comment)
	dimension value(9)
1030	format(a8)
1031	format('ras.',a8,'.res')
1032	format('daydat/rasdat',a8)

        ipass=0

	 open(1,file=fname)
	 write(*,*)'file opened ',fname

        open(33,file='raw.dat')
        open(34,file='correction.dat')

       print *,
     +   'SYSTEM:   TIME(h.m):     X:       Y:
     +    SCALE:    ROTZ:  '

	nch=1
	ns=1

	  ncyc=1
44	    read(1,1000,end=99) string
1000	    format(a125)
	    if(ch(1).eq.'s' .and. ch(2).eq.'t') then
              sname=sys
              comm=comment
	      read(string,1002)nhour,nminu
	      time=nhour+float(nminu)/60.
              time_print=nhour+float(nminu)/100.
	      tim(ncyc)=time
1002          format(21x,i2.2,1x,i2.2)
	      read(1,1000)string
	      if(ch(1).eq.'u'.and.ch(2).eq.'d') then
	          read(string,1001)value
                 if (time.gt.tcut) then
                  ipass=1
                  call get_offsets(sname)
                  x=value(1)
                  y=value(2)
		  scale=value(3)
		  rotz=1000.*value(6)
                  call get_correction(x,y,scale,rotz)
                  write(34,*) sname, time, x,y,scale,rotz
                  write(*,*)'-----> ',comm
                  dx=abs(x)
                  dy=abs(y)
                  dd=abs(abs(x)-15.017)
                  if (dd.lt.dx) dx=dd
                  dd=abs(abs(y)-26.011)
                  if (dd.lt.dy) dy=dd
                  dd=abs(abs(y)-2.*26.011)
                  if (dd.lt.dy) dy=dd
                 
                  resu='RED'
                  if (dx.le.0.010 .and. dy.le.0.010) resu='ORANGE'
                  if (dx.le.0.006 .and. dy.le.0.006) resu='GREEN'


                  write(*,201) sname, time_print, x,y,scale,rotz,resu
 201	          format(a8,F5.2,' x= ',F8.3,' y= ',F8.3,
     +                  ' s= ',F8.3,' Az= ',F8.3,'      ',a8)
1001	          format(9x,3e14.3,2e12.3,2e14.3,2e11.3)
                endif
                
c	        write(6,*)value
	      else
		goto 44
              endif
	    else
	      goto 44
	    endif
	  do kskip=1,6
	    read(1,1000,END=99)string
	  enddo ! kskip -3
	  ncyc=ncyc+1
	  goto 44
99	  close(1)

	  mcyc(nch)=ncyc-1
	  write(6,1050)nch,mcyc(nch)
1050	  format(' nch,mcyc:',2i5)


         close(33)
         close(34)

	if (ipass.eq.1) then
          if (tcut.ge.0) tcut=time ! auto-update-mode
        else
	  print *,'NO DATA FOUND - CHECK FILE steer '
          print *,'DATA ignored before time ',tcut
        endif
	
        open(33,file='steer')
          write(33,'(a)')fname
          write(33,*)tcut
        close(33)


	end







	include 'out.f'
	include 'calc.f'
        include 'get_offsets.f'
