      SUBROUTINE VIM5CNT(GAMMA,GAMMA2,BAD,TIME,INBOARD)
C
C VIM5 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
      INTEGER*2 TIME(6)
      INTEGER*4 PRIOFF(3),SECOFF(3)
      LOGICAL*1 RECTEST,INBOARD
      REAL*4 GAMMA(3,400),GAMMA2(3,8),PRISEN(3),SECSEN(3)
C
      INCLUDE 'UNPACK.INC'
C
      IF (SYS2(32)) RECTEST = .TRUE.
C
      IP = 0
      IS = 0
      DO IWRD = 1,400
C
C 5 MF CYCLE COUNTER (20 MF / VIM-5 RECORD)
C
       ICYC = INT((IWRD-1)/100) + 1
C
C ASSIGN OFFSETS AND SENSITIVITIES TO LOCAL VARIABLES CHECKING PRIME
C LFM STATUS.
C
       DO IAX = 1,3
        IF (.NOT.INBOARD) PRIOFF(IAX) = OBOFF(IAX,OBRNG(ICYC))
        IF (.NOT.INBOARD) SECOFF(IAX) = IBOFF(IAX,IBRNG(ICYC))
        IF (.NOT.INBOARD) PRISEN(IAX) = OBSENS(IAX,OBRNG(ICYC))
        IF (.NOT.INBOARD) SECSEN(IAX) = IBSENS(IAX,IBRNG(ICYC))
        IF (INBOARD) PRIOFF(IAX) = IBOFF(IAX,IBRNG(ICYC))
        IF (INBOARD) SECOFF(IAX) = OBOFF(IAX,OBRNG(ICYC))
        IF (INBOARD) PRISEN(IAX) = IBSENS(IAX,IBRNG(ICYC))
        IF (INBOARD) SECSEN(IAX) = OBSENS(IAX,OBRNG(ICYC))
       END DO
C
C CONVERT PRIMARY MODE VIM-5 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 VIM-5 COUNTS TO GAMMAS
C
       IF (MOD(IWRD-1,50).EQ.0) THEN
C
        IP = IP + 1
        IS = IS + 1
        DO IAX = 1,3
         GAMMA2(IAX,IS) = BAD
         IF (SREF(IAX,IS).NE.0) GAMMA2(IAX,IS) =
     &   (SREF(IAX,IS)-SECOFF(IAX))*SECSEN(IAX)
        END DO
C
       ELSE IF (MOD(IWRD-1,25).EQ.0) THEN
        IP = IP + 1
       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),3(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),
     &  SREF(1,IS),SREF(2,IS),SREF(3,IS),
     &  GAMMA2(1,IS),GAMMA2(2,IS),GAMMA2(3,IS)
C
       END IF
C
      END DO
C
      RETURN 
      END
