      SUBROUTINE CR4CNT(GAMMA,GAMMA2,BAD,TIME,INBOARD)
C
C CR-4 ROUTINE
C
C THIS SUBROUTINE SUBTRACTS THE ZERO OFFSET FROM EACH COUNT AND MULTIPIES THE
C RESULTING DIFFERENCE BY THE SENSITIVITY TO YIELD FIELD STRENGTH IN GAMMAS.
C
C ORIGINAL SOURCE WRITTEN BY SANDY KRAMER, HUGHES STX, CODE 692  03/26/96
C
      INTEGER*2 TIME(6)
      INTEGER*4 PRIOFF(3),SECOFF(3)
      LOGICAL*1 RECTEST,INBOARD
      REAL*4 GAMMA(3,640),GAMMA2(3,80),PRISEN(3),SECSEN(3)
C
      INCLUDE 'UNPACK.INC'
C
      IF ( SYS2(32) ) RECTEST = .TRUE.
C
      DO IWRD = 1,640
C
       IWRD2 = (IWRD-1)/8 + 1
C
C 2 MF CYCLE COUNTER (40 MF / CR-4 RECORD)
C
       ICYC = INT((IWRD-1)/32) + 1
C
C ASSIGN OFFSETS AND SENSITIVITIES TO LOCAL VARIABLES CHECKING PRIME
C LFM STATUS.
C
       DO IAX = 1,3
        IF ( .NOT.INBOARD ) THEN
         PRIOFF(IAX) = OBOFF(IAX,OBRNG(ICYC))
         SECOFF(IAX) = IBOFF(IAX,IBRNG(ICYC))
         PRISEN(IAX) = OBSENS(IAX,OBRNG(ICYC))
         SECSEN(IAX) = IBSENS(IAX,IBRNG(ICYC))
        ELSE 
         PRIOFF(IAX) = IBOFF(IAX,IBRNG(ICYC))
         SECOFF(IAX) = OBOFF(IAX,OBRNG(ICYC))
         PRISEN(IAX) = IBSENS(IAX,IBRNG(ICYC))
         SECSEN(IAX) = OBSENS(IAX,OBRNG(ICYC))
        END IF
       END DO
C
C CONVERT PRIMARY MODE CR-4 COUNTS TO GAMMAS
C
       DO IAX = 1,3
        GAMMA(IAX,IWRD) = BAD
        IF ( PREC(IAX,IWRD).NE.0 ) GAMMA(IAX,IWRD) = 
     &  (PREC(IAX,IWRD)-PRIOFF(IAX))*PRISEN(IAX)
       END DO
C
C CONVERT SECONDARY MODE CR-4 COUNTS TO GAMMAS
C
       IF ( MOD(IWRD-1,8).EQ.0 ) THEN
        DO IAX = 1,3
         GAMMA2(IAX,IWRD2) = BAD
         IF ( SREC(IAX,IWRD2).NE.0 ) GAMMA2(IAX,IWRD2) =
     &   (SREC(IAX,IWRD2)-SECOFF(IAX))*SECSEN(IAX)
        END DO
       END IF
C
       IF ( RECTEST ) THEN
C
        IF ( IWRD.EQ.1 ) WRITE(81,'(1X,''EDR TIME: '',6(1X,I3))') TIME
C
        WRITE(81,'(4(1X,I5),3(1X,F7.3),4(1X,I5),3(1X,F7.3))') 
     &  IWRD,PREC(1,IWRD),PREC(2,IWRD),PREC(3,IWRD),
     &  GAMMA(1,IWRD),GAMMA(2,IWRD),GAMMA(3,IWRD),
     &  IWRD2,SREC(1,IWRD2),SREC(2,IWRD2),SREC(3,IWRD2),
     &  GAMMA2(1,IWRD2),GAMMA2(2,IWRD2),GAMMA2(3,IWRD2)
C
       END IF
C
      END DO
C
      RETURN 
      END
