      PROGRAM XTIME
C
C CORRECT FOR RE-STARTS OF THE DIFFRACTOMETER EXPOSURE TIME CLOCK.
C
C THE DATA FILE MUST HAVE THE DATA IN THE ORDER IN WHICH THEY WERE
C MEASURED.
C
      CHARACTER ATIME*8,ADATE*9,AFILE*40
      DIMENSION NN(10),TT(10)
      CALL TIME (ATIME)
      CALL DATE (ADATE)
      TYPE 1100
1100  FORMAT ('0PROGRAM XTIME.'/'0ENTER DATA FILE NAME.')
      ACCEPT 1101,AFILE
1101  FORMAT (A)
      OPEN (UNIT=1,FILE=AFILE,STATUS='OLD',FORM='UNFORMATTED')
      N=0
      I=0
      T1=0
1     READ (1,END=8) II,IH,IK,IL,A1,A2,A3,A4,Y,SIGY,T
      N=N+1
      IF (T.LT.T1) THEN
        I=I+1
        NN(I)=N
        TT(I)=T1-T
      END IF
      T1=T
      GO TO 1
8     IF (I.EQ.0) STOP 'NO RE-STARTS ENCOUNTERED'
      OPEN (UNIT=3,FILE='xtime.lp',STATUS='NEW')
      WRITE (3,1000) ATIME,ADATE
      T=0
      M=I
      DO I=1,M
        T=T+TT(I)
        WRITE (3,1001) NN(I),T
      END DO
      WRITE (3,1010)
1000  FORMAT ('1PROGRAM XTIME.  'A,1X,A/'0        N     XTIME'/
     &'         -     -----')
1001  FORMAT (I10,F10.3)
1010  FORMAT ('0        N         I    H  K  L         Y      SIGY     X
     &TIME'/'         -         -    -  -  -         -      ----     ---
     &--')
      REWIND 1
      OPEN (UNIT=2,FILE='data.xtime',STATUS='NEW',FORM='UNFORMATTED')
      NMAX=N
      JJ=0
      N=0
2     READ (1,END=9) II,IH,IK,IL,A1,A2,A3,A4,Y,SIGY,T
      N=N+1
      DO I=1,M
        IF (N.GE.NN(I)) T=T+TT(I)
      END DO
      WRITE (2) II,IH,IK,IL,A1,A2,A3,A4,Y,SIGY,T
      IF (N.EQ.1.OR.II.LT.0.OR.N.EQ.NMAX) THEN
        IF (II.NE.JJ-1) WRITE (3,1005)
        WRITE (3,1002) N,II,IH,IK,IL,Y,SIGY,T
        JJ=II
      END IF
1005  FORMAT (1X)
1002  FORMAT (2I10,2X,3I3,2F10.2,F10.3)
      GO TO 2
9     TYPE 1003
1003  FORMAT ('0OUTPUT DATA FILE IS NAMED "data.xtime".')
      STOP
      END
