      SUBROUTINE MAGSTATUS(TIME,NSTAT1,NSTAT2)
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), STAT2TEST(0:15,4)
      INTEGER*4 OBDIFF,IBDIFF
C
C ARRAY INDEX 0 NOT USED IN ALL LOGICAL*1 EXTRACTED STATUS WORD VARIABLES
C
      DATA ICALL/0/
C
      INCLUDE 'UNPACK.INC'
C
      IUNIT = 88
      ICALL = ICALL + 1
C
C FORTRAN OUTPUT UNIT ASSIGNED TO FILE NAME IN VMS DCL ROUTINE CALLING
C THE VOYPROD EXECUTABLE  ex. $ ASSIGN FILE.DAT  FOR088
C
      IF ( SYS2(25) .AND. ICALL.EQ.1 ) THEN
       OPEN(IUNIT,STATUS='NEW',FORM='FORMATTED',
     &      CARRIAGECONTROL='LIST',RECL=132)
C     &      CARRIAGECONTROL='LIST',RECL=80)
       WRITE(IUNIT,'(''REC   MODE        TIME'')')
       WRITE(IUNIT,'(''           YY DDD HH MM SS MS  STAT2 EFLIP '',
     &              ''PRIME OBLCK OBFLP IBLCK IBFLP MPROC POLAR '',
     &              ''IBCAL OBCAL'')')

      END IF
C      
C GET INSTRUMENT STATUS VALUES FROM SECOND STATUS WORD
C
      DO I = 1,NSTAT2
C
C ELECTRICAL FLIPPER STATUS
C
       EFLIP(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 0, 1, EFLIP(I), 0)
C
C EXTRACT PRIME LFM STATUS
C
       PRIME(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 1, 1, PRIME(I), 0)
C
C EXTRACT OUTBOARD LFM FLIPPER LOCK STATUS
C
       OBLOCK(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 2, 1, OBLOCK(I), 0)
C
C OUTBOARD LFM FLIP STATUS
C
       OBFLIP(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 3, 1, OBFLIP(I), 0)
C
C EXTRACT OUTBOARD LFM FLIPPER LOCK STATUS
C
       IBLOCK(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 4, 1, IBLOCK(I), 0)
C
C INBOARD LFM FLIP STATUS
C
       IBFLIP(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 5, 1, IBFLIP(I), 0)
C
C EXTRACT PROCESSOR STATUS
C
       MPROC(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 6, 1, MPROC(I), 0)
C
C EXTRACT POLARITY
C
       POLAR(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 7, 1, POLAR(I), 0)
C
C INBOARD LFM FLIGHT CALIBRATION INDICATOR
C
       IBCAL(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 10, 1, IBCAL(I), 0)
C
C OUTBOARD LFM FLIGHT CALIBRATION INDICATOR
C
       OBCAL(I) = .FALSE.
       CALL MOVBIT(STAT2(I), 11, 1, OBCAL(I), 0)
C
       IF ( SYS2(25) ) THEN
        WRITE(IUNIT,880) RECNUM,DATMOD,TIME,STAT2(I),EFLIP(I),PRIME(I),
     &   OBLOCK(I),OBFLIP(I),IBLOCK(I),IBFLIP(I),MPROC(I),POLAR(I),
     &   IBCAL(I),OBCAL(I)
       END IF
  880  FORMAT(I5.5,1X,I2,3X,I2.2,1X,I3.3,3(1X,I2.2),1X,I3.3,
     &        1X,Z4.4,2X,10(Z1,5X))
      END DO
C
C GET INSTRUMENT STATUS VALUES FROM FIRST STATUS WORD
C
      DO I=1,NSTAT1
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 (XXMODE = 1).
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(NSTAT1)
      OBRNG(0) = OBRNG(NSTAT1)
C
C PUT LAST MODE VALUE IN RESERVED RANGE VALUE REFERENCE ELEMENT 0
C
      IBMODE(0) = IBMODE(NSTAT1)
      OBMODE(0) = OBMODE(NSTAT1)
C
      RETURN
  888 FORMAT(1X,'*MAGSTATUS*  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,'*MAGSTATUS*  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,'*MAGSTATUS*  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,'*MAGSTATUS*  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
