      SUBROUTINE WRITE_DELTA_COUNTS(TIME,NPREF,NPDELTA,NSREF,NSDELTA)

c GLOBAL VARIABLES

c    PREF - primary reference word
c    PDELTA - primary delta word
c    SREF - secondary reference word
c    SDELTA - secondary delta word

c INPUT VARIABLES

c    NPREF - number of reference words
c    NPDELTA - number of primary delta words
c    NSREF - number of secondary reference words
c    NSDELTA - number of secondary delta words

c LOCAL VARIABLES

c    PSRATIO - number of secondary delta words per primary delta word
c    PRATIO - number of primary reference words per primary delta word
c    SRATIO - number of secondary reference words per primary delta word

      INTEGER*2 TIME(6)
      INTEGER*4 PSRATIO,PRATIO,SRATIO

      INCLUDE 'UNPACK.INC'

      PSRATIO = NPDELTA/NSDELTA
      PRATIO = NPDELTA/NPREF
      SRATIO = NPDELTA/NSREF
      DO IPDM = 1,NPDELTA
         ISDM = (IPDM-1)/PSRATIO + 1
         IP = (IPDM-1)/PRATIO + 1
         IS = (IPDM-1)/SRATIO + 1
         IF ( IPDM.EQ.1 ) THEN
            TIME(1) = YEAR3
            CALL CONHOUR(SCETHR,TIME)
            CALL CONSEC(SCETSC,TIME)
            TIME(6) = SCETML
            WRITE(80,'('' RECORD NUMBER: '',I5.5,''   TIME: '',
     &       I2,1X,I3,3(1X,I2.2),1X,I3.3)') RECNUM,TIME
         END IF
         WRITE(80,'(24(1X,I4))')
     &   IP, PREF(1,IP), PREF(2,IP), PREF(3,IP),
     &   IPDM, PDELTA(1,IPDM), PDELTA(2,IPDM), PDELTA(3,IPDM),
     &   IPDM, PREC(1,IPDM), PREC(2,IPDM), PREC(3,IPDM),
     &   IS, SREF(1,IS), SREF(2,IS), SREF(3,IS),
     &   ISDM, SDELTA(1,ISDM), SDELTA(2,ISDM), SDELTA(3,ISDM),
     &   ISDM, SREC(1,ISDM), SREC(2,ISDM), SREC(3,ISDM)
      END DO

      RETURN
      END
