	program inplane
	
	include 'inplane.cmm'
        
	call ini
	call read
	
	do nch=1,3
	  do ncyc=1,mcyc(nch)
	    call calc
	  enddo
	enddo
	
	call out
	
	end



	subroutine ini
	
	include 'inplane.cmm'
	
	pi=4.*atan(1.)
	tec=23.0E-6
	
	chid(1)='gra'
	chid(2)='mbr'
	chid(3)='mcr'
	
	sysname( 1)='B+SW'
	sysname( 2)='B+SW'
	sysname( 3)='B+SW'
	sysname( 4)='B+SW'
        print *,'give the sysname '
        read(*,*)sysname(1)
        do i=2,4
          sysname(i)=sysname(1)
        enddo

	sysname( 5)='ss0'
	sysname( 6)='ss1'
	sysname( 7)='ss2'
	sysname( 8)='ss3'

	sysname( 9)='ass0'
	sysname(10)='ass1'
	sysname(11)='ass2'
	sysname(12)='ass3'

	sysname(13)='P0  '
	sysname(14)='P1  '
	sysname(15)='Q0  '
	sysname(16)='Q1  '
	
	offset(1,0,1)=  5.568
	offset(1,0,2)= 11.407
	offset(1,0,3)=  1.013
	offset(1,0,4)=  3.14

	offset(1,1,1)=  6.702
	offset(1,1,2)= 13.839
	offset(1,1,3)=  1.015
	offset(1,1,4)=-13.13
	
	offset(1,2,1)=  6.682
	offset(1,2,2)= 13.735
	offset(1,2,3)=  1.015
	offset(1,2,4)= -1.17

	offset(1,3,1)=  5.761
	offset(1,3,2)= 13.212
	offset(1,3,3)=  1.014
	offset(1,3,4)=-13.56
	
	offset(2,0,1)=  6.793
	offset(2,0,2)= 11.143
	offset(2,0,3)=  1.003
	offset(2,0,4)=  9.12

	offset(2,1,1)= 10.332
	offset(2,1,2)= 11.335
	offset(2,1,3)=  1.009
	offset(2,1,4)=  0.05
	
	offset(2,2,1)=  9.165
	offset(2,2,2)=  9.203
	offset(2,2,3)=  1.011
	offset(2,2,4)=  8.22

	offset(2,3,1)=  7.844
	offset(2,3,2)= 11.01
	offset(2,3,3)=  1.003
	offset(2,3,4)= -5.08

	offset(3,0,1)=  5.089
	offset(3,0,2)=  7.129
	offset(3,0,3)=  1.014
	offset(3,0,4)=-12.87

	offset(3,1,1)=  7.685
	offset(3,1,2)=  9.763
	offset(3,1,3)=  1.014
	offset(3,1,4)= -9.46
	
	offset(3,2,1)=  5.184
	offset(3,2,2)=  8.795
	offset(3,2,3)=  1.013
	offset(3,2,4)=-13.45

	offset(3,3,1)=  8.592
	offset(3,3,2)= 10.525
	offset(3,3,3)=  1.014
	offset(3,3,4)=-13.06
	
	geoz(1,1)=  29.
	geoz(1,2)= 110.
	geoz(1,3)= 480.

	geoz(2,1)= 250.
	geoz(2,2)= 535.
	geoz(2,3)= 720.

	geoz(3,1)= 487.
	geoz(3,2)= 987.
	geoz(3,3)=1080.
	
	end



	subroutine read
	
	include 'inplane.cmm'

	character*125 string
	character*1 ch(125)
	character*7 sys
	equivalence(string,ch)
	equivalence(ch(31),sys)
	dimension value(9)
	character*80 fname2
	character*21 fname3
	

	
	write(6,*)' which ras.???.res file (yyyymmdd)?'
	read(*,*)fname2
	write(*,*)'file  ',fname2
   
C
1030	format(a8)
C	write(fname2,1031)fname
1031	format('ras.',a8,'.res')
C	write(fname3,1032)fname
1032	format('daydat/rasdat',a8)

	do nch=1,1

	  write(*,*)'file to be opened ',fname2
	  open(1,file=fname2)
	  write(*,*)'file opened ',fname2

        open(33,file='tower')

	  ncyc=1
33	  do ns=0,3
44	    read(1,1000,end=99) string
1000	    format(a125)
	    if(sys.eq.sysname(ns+4*(nch-1)+1)) then
	      read(string,1002)nhour,nminu
	      time=nhour+float(nminu)/60.
	      tim(ncyc)=time
1002          format(21x,i2.2,1x,i2.2)
c	      write(6,*)nhour,nminu,time
c	      write(6,*) sys
	      read(1,1000)string
	      if(ch(1).eq.'u'.and.ch(2).eq.'d') then
	        read(string,1001)value
	        dat(nch,ns,1,ncyc)=value(1)
	        dat(nch,ns,2,ncyc)=value(2)
	        dat(nch,ns,3,ncyc)=value(3)
	        dat(nch,ns,4,ncyc)=1000.*value(6)
 	        write(33,*)time,(dat(nch,ns,k,ncyc),k=1,4)
1001	        format(9x,3e14.3,2e12.3,2e14.3,2e11.3)
c	        write(6,*)value
	      else
	        if(ns.ne.0) then
	          write(6,*)' bad cycle'
	          goto 33
	        endif
	      endif
	    else
	      goto 44
	    endif
	  enddo
	  do kskip=1,6
	    read(1,1000)string
	  enddo
	  ncyc=ncyc+1
	  goto 33
99	  close(1)

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

	enddo

         close(33)

	end







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