c     Program that applies a static shift to the shot
c     times in the shottable and correct for clock drift
c
c     Thomas Funck  Dalhousie/RV Oceanus  July 28, 2000
c
      character*60 input,output
      character*80 text
c
      write (*,*) 'Name of input-file:'
      read (*,999) input
c
      write (*,*) 'Name of output-file:'
      read (*,999) output
  999 format (a60)
c
      write (*,*) 'Static shift in msec'
      write (*,*) '- if trace to be moved up'
      write (*,*) '+ if trace to be moved down'
      write (*,*) 'Same sign like in depl. sheets.'
      read (*,*) tsh
c
      write (*,*) 'Time of clock reset:'
      write (*,*) 'day hour min sec'
      read (*,*) id1,ih1,im1,is1
c
      write (*,*) 'Time of clock check:'
      write (*,*) 'day hour min sec'
      read (*,*) id2,ih2,im2,is2
c
      write (*,*) 'Clock drift in msec (+/-):'
      read (*,*) drt
c
c     Calculation of hourly clock drift
c
      td=float(id2-id1)*24.+float(ih2-ih1)
     &   +float(im2-im1)/60.+float(is2-is1)/3600.
      dh=drt/td
      write (*,996) dh
  996 format (' Drift rate ',f8.2,' msec/hour')
c
      open (10,file=input,status='old')
      open (11,file=output,status='new')
c
c     Reading/writing header of original shot table
c
      do 10 i=1,3
        read (10,998) text
  998   format (a80)
        write (11,998) text
   10 continue
c
      read (10,998) text
      write (11,990)
  990 format (5x,'.0000',12x,'Clock drift rate (ms/hr)')
c
      do 15 i=1,3
        read (10,998) text
        write (11,998) text
   15 continue
c
c     Reading input file and apply time corrections for
c     each shot
c
   20 read (10,997,err=20,end=30) ish,id,ih,im,sec,y,x,xoff
  997 format (i5,i4,2i3,f8.4,f11.6,f12.6,f10.3)
c
c     Calculation of drift for individual shots
c
      th=float(id-id1)*24.+float(ih-ih1)
     &   +float(im-im1)/60.+(sec-float(is1))/3600.
      td=th*dh
c
c     Summation of drift and static correction (in seconds)
c
      tc=(tsh+td)/1000.
      sec=sec+tc
c
c     Check if the seconds of shottime jump below
c     0 or above 60 due to the corrections applied
c
c     If yes, adjust the time
c
      if (sec.ge.60.) then
        sec=sec-60.
        im=im+1
       else
      endif
      if (sec.lt.0.) then
        sec=sec+60.
        im=im-1
       else
      endif
      if (im.ge.60) then
        im=im-60
        ih=ih+1
       else
      endif
      if (im.lt.0) then
        im=im+60
        ih=ih-1
       else
      endif
      if (ih.ge.24) then
        ih=ih-24
        id=id+1
       else
      endif
      if (ih.lt.0) then
        ih=ih+24
        id=id-1
       else
      endif
c
c     Writing the output
c
      write (11,997) ish,id,ih,im,sec,y,x,xoff
      goto 20
c
   30 close (10)
      close (11)
      stop
      end
