      SUBROUTINE CR2COMM(TIME)
C
C CR2 ROUTINE
C
C ADAPTED FROM CR1COMM ROUTINE BY SANDY KRAMER  03/22/96
C
C THIS ROUTINE EXTRACTS VALUES FROM THE TWO STATUS WORDS, STAT1 AND STAT2,
C THAT WERE UNPACKED FROM THE PLASMA SUB-HEADER BLOCK.  STAT1 CONTAINS RANGE
C AND MODE VALUES.  STAT2 CONTAINS SENSOR STATES.
C
      INTEGER*2 TIME(6)
      INTEGER*4 OBDIFF,IBDIFF
C
      INCLUDE 'UNPACK.INC'
C
C GET INSTRUMENT STATUS VALUES FROM SECOND STATUS WORD (STAT2)
C
C
C ELECTRICAL FLIPPER STATUS
C
      EFLIP(1) = .FALSE.
      CALL MOVBIT(STAT2(1), 0, 1, EFLIP(1), 0)
C
C EXTRACT PRIME LFM STATUS
C
      PRIME(1) = .FALSE.
      CALL MOVBIT(STAT2(1), 1, 1, PRIME(1), 0)
C
C INBOARD LFM FLIP STATUS
C
      IBFLIP(1) = .FALSE.
      CALL MOVBIT(STAT2(1), 4, 2, IBFLIP(1), 0)
C
C OUTBOARD LFM FLIP STATUS
C
      OBFLIP(1) = .FALSE.
      CALL MOVBIT(STAT2(1), 2, 2, OBFLIP(1), 0)
C
C EXTRACT PROCESSOR STATUS
C
      MPROC(1) = .FALSE.
      CALL MOVBIT(STAT2(1), 6, 1, MPROC(1), 0)
C
C EXTRACT POLARITY
C
      POLAR(1) = .FALSE.
      CALL MOVBIT(STAT2(1), 7, 1, POLAR(1), 0)
C
C INBOARD LFM FLIGHT CALIBRATION INDICATOR
C
      IBCAL(1) = .FALSE.
      CALL MOVBIT(STAT2(1), 10, 1, IBCAL(1), 0)
C
C OUTBOARD LFM FLIGHT CALIBRATION INDICATOR
C
      OBCAL(1) = .FALSE.
      CALL MOVBIT(STAT2(1), 11, 1, OBCAL(1), 0)
C
C GET INSTRUMENT STATUS VALUES FROM FIRST STATUS WORD (STAT1)
C
      DO I=1,5
C
C CHECK FOR RANGE OVERRIDE
C
       IF ( RNGSET.NE.-1 ) THEN
        OBRNG(I) = RNGSET
        IBRNG(I) = RNGSET
        GOTO 100
       END IF
C
C EXTRACT OUTBOARD AND INBOARD RANGE MODES [0,1]
C
       IF ( MODSET.EQ.-1 ) THEN
        CALL MOVBIT(STAT1(I), 11, 1, OBMODE(I), 0)
        CALL MOVBIT(STAT1(I),  7, 1, IBMODE(I), 0)
       ELSE IF ( MODSET.EQ.0 ) THEN
        OBMODE(I) = .FALSE.
        IBMODE(I) = .FALSE.
       ELSE IF ( MODSET.EQ.1 ) THEN
        OBMODE(I) = .TRUE.
        IBMODE(I) = .TRUE.
       END IF          
C
C EXTRACT OUTBOARD AND INBOARD RANGE SENSITIVITIES [0,7]
C 
       DO J = 1,3
        CALL MOVBIT(STAT1(I), 11-J, 1, OBRNG(I), J-1)
        CALL MOVBIT(STAT1(I),  7-J, 1, IBRNG(I), J-1)
       END DO
C
C TEST FOR RANGE ERRORS.  SENSITIVITY MAY CHANGE ONLY BY ONE
C IN AUTO RANGE MODE.
C
       IBDIFF = ABS(IBRNG(I)-IBRNG(I-1))
       OBDIFF = ABS(OBRNG(I)-OBRNG(I-1))
C
C INBOARD MAG RANGE CHECK
C
       IF ( IBDIFF.GT.1 .AND. (IBMODE(I).AND.IBMODE(I-1)) ) THEN
        WRITE(68,889) TIME,RECNUM,I,IBRNG(I-1),IBRNG(I)
        IBRNG(I) = IBRNG(I-1)
        IBMODE(I) = IBMODE(I-1)
       ELSE IF ( IBDIFF.NE.0 ) THEN
        WRITE(68,899) TIME,RECNUM,I,IBRNG(I-1),IBRNG(I)
       END IF
C
C OUTBOARD MAG RANGE CHECK
C
       IF ( OBDIFF.GT.1 .AND. (OBMODE(I).AND.OBMODE(I-1)) ) THEN
        WRITE(68,888) TIME,RECNUM,I,OBRNG(I-1),OBRNG(I)
        OBRNG(I) = OBRNG(I-1)
        OBMODE(I) = OBMODE(I-1)
       ELSE IF ( OBDIFF.NE.0 ) THEN
        WRITE(68,898) TIME,RECNUM,I,OBRNG(I-1),OBRNG(I)
       END IF
C
  100  CONTINUE
C
      END DO
C
C PUT LAST RANGE VALUE IN RESERVED RANGE VALUE REFERENCE ELEMENT 0
C
      IBRNG(0) = IBRNG(5)
      OBRNG(0) = OBRNG(5)
C
C PUT LAST MODE VALUE IN RESERVED RANGE VALUE REFERENCE ELEMENT 0
C
      IBMODE(0) = IBMODE(5)
      OBMODE(0) = OBMODE(5)
C
      RETURN
  888 FORMAT(1X,'*CR2COMM*  OUTBOARD RANGE ERROR!',
     &       3X,I2,1X,I3.3,3(1X,I2.2),1X,I3.3,3X,
C    &       'REC# ',I4,3X,'STATUS PD ',I2,3X,'RANGE(I-1,I)',2(1X,I2))
     &       'REC# ',I4,3X,'STATUS PD ',I2,3X,'PREVIOUS RANGE = ',I2,3X,
     &       'CURRENT RANGE = ',I2)
  889 FORMAT(1X,'*CR2COMM*  INBOARD RANGE ERROR!',
     &       3X,I2,1X,I3.3,3(1X,I2.2),1X,I3.3,3X,
C    &       'REC# ',I4,3X,'STATUS PD ',I2,3X,'RANGE(I-1,I)',2(1X,I2))
     &       'REC# ',I4,3X,'STATUS PD ',I2,3X,'PREVIOUS RANGE = ',I2,3X,
     &       'CURRENT RANGE = ',I2)
  898 FORMAT(1X,'*CR2COMM*  OUTBOARD RANGE CHANGE',
     &       3X,I2,1X,I3.3,3(1X,I2.2),1X,I3.3,3X,
C    &       'REC# ',I4,3X,'STATUS PD ',I2,3X,'RANGE(I-1,I)',2(1X,I2))
     &       'REC# ',I4,3X,'STATUS PD ',I2,3X,'PREVIOUS RANGE = ',I2,3X,
     &       'CURRENT RANGE = ',I2)
  899 FORMAT(1X,'*CR2COMM*  INBOARD RANGE CHANGE',
     &       3X,I2,1X,I3.3,3(1X,I2.2),1X,I3.3,3X,
C    &       'REC# ',I4,3X,'STATUS PD ',I2,3X,'RANGE(I-1,I)',2(1X,I2))
     &       'REC# ',I4,3X,'STATUS PD ',I2,3X,'PREVIOUS RANGE = ',I2,3X,
     &       'CURRENT RANGE = ',I2)
       END
