      subroutine readforce(ifile)
*  
* Reads force sensors and prepares histoos
*
      include 'Online.cmm'
      character*300 line

      character*80  ffname,fname
      character*10 chstime

      character*10 chdatt
      character*8 chtimt
      character*10 chdat
      character*8  chtim
      character*8 fdate
      integer jj,mm,dd

      character*6 chsens_nr(16),chsans_nr(16),srid
      character*2 chid
      logical first
*
      real forces(16)


	
      do idh=1,16
       call hbook1(300+idh,'nfill',200,0.,24.,0.)
       call hbook1(400+idh,'force',200,0.,24.,0.) 
      enddo
*
*  Prompt for file-name and start-time and #of sensors
*

      if (forcename(8:15).ne.rname(5:12)) then
	print *,'RASNIK file date differs from FORCE file!!!'
        print *,'RASNIK file ',rname
        print *,'Force file ',forcename
      endif
      call forcefile(ifile,forcename)
      nsens=16
** Loop
        msens = 0
	nlines=0
  100   read(ifile,'(a)',ERR=200,END=300)line
  101   continue
        nlines=nlines+1
C action for dat Date with sensornumber line
	
        if( line(1:2) .eq. 'dd' ) then ! bingo
           read(line,1000,ERR=500,END=500)
     +            chdatt,chtimt,(chsans_nr(i),i=1,nsens) 
 500	continue
           msens = 0
           do i=1,nsens
            if( ((chsans_nr(i)(1:2) .eq. 'Fo') .or.
     +           (chsans_nr(i)(1:2) .eq. 'Pr')) ) then
                msens = msens + 1
	     else
                goto 102
	     endif
           enddo
  102      if ( msens .eq. 0 ) then
             print *,' ZERO sensors recognised'
           endif 
           print *,msens,' sensors recognised'
           nsens=msens
           do i=1,nsens
              chsens_nr(i) = chsans_nr(i) 
           enddo
           goto 100
        else
         if (nlines.lt.2 .or. msens.eq.0) goto 100 ! skip very fist part of file with muck
C action for dat force-data line
           read(line,1001,ERR=100,END=100) chdat,chtim
           read(line(20:300),*,ERR=100,END=100)(forces(i),i=1,nsens)
           if (chdat(1:2).ne.datum(7:8)) goto 100 ! wrong date
           read(chtim,1002) nhour,nmin,nsec
           time=nhour+float(nmin)/60.+float(nsec)/3600.
           if (time.gt.0) then ! make sure time is a valid number
		i=i
	   else
		goto 100
	   endif
           read(chdat,1003) dd,mm,jj
           if( dd .gt. 0 )  jday = jaardag(dd,mm,jj)
           do i=1,nsens
             srid=chsens_nr(i)
             chid=srid(6:6)
             read(chid,501)idh
             if (chsens_nr(i)(1:2) .eq. 'Pr') idh=idh+8
 501	format(i1)

         if (forces(i).gt.-10 .and. forces(i).lt.100) then
	     call hfill(300+idh,time,0.,1.)
	     call hfill(400+idh,time,0.,forces(i))
	 else
	    print *,'WARNING: BAD Force reading ',idh, forces(i)
	 endif
           enddo
           goto 100
        endif

	print *,' pass this point never '
	
 2000 format(i4,1x,i2.2,1x,i2.2,1x,i4,
     >                  f8.4,30f7.3) 
 1000 format(18(a,1x))
 1001 format(a,1x,a)
c 1001 format(a,1x,a,16(1x,f6.3))
 1002 format(i2.2,1x,i2.2,1x,i2.2)
 1003 format(i2,1x,i2,1x,i4)
  200 print *,' Read error'
  300 print *,' End file ',line

        call hforce

	   tiet=11.0

	do itower=1,8
 	   call get_force(tiet,force)
	   print *,'tijd and tower and force',tiet,itower,force
	enddo
      end


   
	subroutine hforce
C fills empty bins in histograms.

        nbin=200
	xl=0.
	xh=24.

       do idh=1,16
	
       ifirst=0
       ilast=0
       if (ifirst.eq.0 .and. ilast.eq.0) goto 10
 20	continue
        if (ifirst.eq.1 .and. ilast.eq.nbin) then ! no info
          goto 33
        endif


        if (ifirst.eq.1) then ! first part missing
          do j=1,ilast
            call hix(idh+300,j,x1)
            call hix(idh+300,j+1,x2)
            x=(x1+x2)/2.
            call hfill(idh+300,x,0.,hi(idh+300,ilast+1))
            call hfill(idh+400,x,0.,hi(idh+400,ilast+1))
          enddo
          ilast=0
          ifirst=0
        endif

	if (ilast.eq.nbin) then ! last part missing
	  do j=ifirst,nbin
            call hix(idh+300,j,x1)
            call hix(idh+300,j-1,x2)
            x=x1+ (x1-x2)/2.
            call hfill(idh+300,x,0.,hi(idh+300,ifirst-1))
            call hfill(idh+400,x,0.,hi(idh+400,ifirst-1))
          enddo
          ilast=0
          ifirst=0
        endif

	if (ifirst.gt.0 .and. ilast.gt.0) then ! some times are missing
          do j=ifirst,ilast
            call hix(idh+300,ifirst-1,xf)
            call hix(idh+300,ilast+1,xl)
            tempf=hi(idh+400,ifirst-1)/hi(idh+300,ifirst-1)
            templ=hi(idh+400,ilast+1)/hi(idh+300,ilast+1)
            call hix(idh+300,j,x1)
            call hix(idh+300,j+1,x2)
            x=(x1+x2)/2.
            dx=x2-x1
	    xf=xf+dx/2.
            xl=xl+dx/2.
            temp=tempf+ (templ-tempf)/(xl-xf) * (x-xf)
            call hfill(idh+300,x,0.,1.)
            call hfill(idh+400,x,0.,temp)
          enddo
          ilast=0
          ifirst=0
        endif
 10	continue
           ifirst=0
           ilast=0
	do i=1,nbin
           rfill=hi(300+idh,i)
           if (rfill.lt.0.0001 .and. ifirst.eq.0)  ifirst=i
           if (rfill.gt.0.0001 .and.
     +          ifirst.ne.0 .and. ilast.ne.0) goto 20
           if (rfill.lt.0.0001 .and. 
     +         ifirst.gt.0)  ilast=i
	enddo ! i to nbin
        if (ifirst.ne.0 .and. ilast.ne.0) goto 20
 33	continue
       enddo ! idh to 33
      end

	subroutine get_force(time_now,force)
	include 'Online.cmm'
        logical hexist
	tav=0
	rav=0
	force=-1.
	   if (hexist(300+itower)) then
	     force=hx(400+itower,time_now)
	     rcount=hx(300+itower,time_now)
           else
	     print *,'WARNING : force not available ',itower
	   endif
	  if (rcount.gt.0) force=force/rcount
	end



