******************************************************************
*
*	TITLE:  UNPACK VOYAGER 218 WORD CR-4 EDR SUBHEADER (PLS DATA)
*
*	FILE NAME:  PLSCR4.FOR
*
*	PURPOSE:  TO UNPACK THE SUBHEADER (PLS DATA) ACCORDING TO THE 
*                  SPECIFIED MOD60 FORMAT
* 
*	HISTORY:
*
*	AUTHOR       	  DATE              CHANGE
*	--------          ----              ------
*	S. B. KRAMER     01/29/96           ORIGINAL CODE
*                                           (MODE CR-4)
*
*	CALLING SEQUENCE:  SUBROUTINE PLSCR4()
*
*	MODULES REFERENCED:
*
*		MOVBIT
*
*	COMMON AREAS:
*
*		SEE UNPACK.INC FOR COMMON AREA DEFINITIONS
*
*	PDL:
*
*		EXTRACT MAG AND PLASMA COMMAND WORDS
*		EXTRACT MAG STATUS WORDS
*		RETURN
*
******************************************************************
      SUBROUTINE PLSCR4()
C
      INTEGER*2 TIME(6)
C
      LOGICAL*4 STATIM
C
      INCLUDE 'UNPACK.INC'
C
      DATA ICALL/0/
C
      IF ( DRSDAT.NE.35 ) RETURN
C
      ICALL = ICALL + 1
C
C PLASMA COMMAND WORDS
C
      PCOMM1(1) = 0
      PCOMM2(1) = 0
      CALL MOVBIT(PLS,  0,  8, PCOMM1(1), 8)
      CALL MOVBIT(PLS,  8,  8, PCOMM1(1), 0)
      CALL MOVBIT(PLS, 16,  8, PCOMM2(1), 8)
      CALL MOVBIT(PLS, 24,  8, PCOMM2(1), 0)
C
      PCOMM1(2) = 0
      PCOMM2(2) = 0
      CALL MOVBIT(PLS, 32,  8, PCOMM1(2), 8)
      CALL MOVBIT(PLS, 40,  8, PCOMM1(2), 0)
      CALL MOVBIT(PLS, 48,  8, PCOMM2(2), 8)
      CALL MOVBIT(PLS, 56,  8, PCOMM2(2), 0)
C
C MAG COMMAND WORDS
C
      MCOMM1(1) = 0
      MCOMM2(1) = 0
      CALL MOVBIT(PLS, 64,  8, MCOMM1(1), 8)
      CALL MOVBIT(PLS, 72,  8, MCOMM1(1), 0)
      CALL MOVBIT(PLS, 80,  8, MCOMM2(1), 8)
      CALL MOVBIT(PLS, 88,  8, MCOMM2(1), 0)
C
      MCOMM1(2) = 0
      MCOMM2(2) = 0
      CALL MOVBIT(PLS,  96,  8, MCOMM1(2), 8)
      CALL MOVBIT(PLS, 104,  8, MCOMM1(2), 0)
      CALL MOVBIT(PLS, 112,  8, MCOMM2(2), 8)
      CALL MOVBIT(PLS, 120,  8, MCOMM2(2), 0)
C
C MAG STATUS WORDS FORMAT
C
C BIT  15             0                     15             0
C      |______________|                     |______________|
C      |    STAT1     |                     |    STAT2     |
C      +--------------+                     +--------------+
C
C 15 - FILL                                 FILL
C 14 - FILL                                 FILL
C 13 - FILL                                 FILL
C 12 - FILL                                 FILL
C 11 - OBLFM MODE                           OBLFM FLIGHT CALIBRATION
C 10 - OBLFM RANGE BIT 1 (LSB)              IBLFM FLIGHT CALIBRATION
C  9 - OBLFM RANGE BIT 2                    OBHFM FLIGHT CALIBRATION
C  8 - OBLFM RANGE BIT 3 (MSB)              IBHFM FLIGHT CALIBRATION
C  7 - IBLFM MODE                           IFC POLARITY
C  6 - IBLFM RANGE BIT 1 (LSB)              PROCESSOR SELECTION
C  5 - IBLFM RANGE BIT 2                    IBLFM FLIPPER POSITION
C  4 - IBLFM RANGE BIT 3 (MSB)              IBLFM FLIPPER LOCK STATUS
C  3 - OBHFM MODE                           OBLFM FLIPPER POSITION
C  2 - OBHFM RANGE BIT 1                    OBLFM FLIPPER LOCK STATUS
C  1 - IBHFM MODE                           PRIME LFM STATUS
C  0 - IBHFM RANGE BIT 1                    ELECTRICAL FLIPPER
C
C MAG STATUS WORDS FOR MF-1, MF-3, MF-5, MF-7, MF-9
C
      STAT2(1) = 0
      CALL MOVBIT(PLS, 128,  8, STAT2(1), 8)
      CALL MOVBIT(PLS, 136,  8, STAT2(1), 0)
      DO J = 1,5
       STAT1(J) = 0
       I = (J-1)*16
       CALL MOVBIT(PLS, 144+I,  8, STAT1(J), 8)
       CALL MOVBIT(PLS, 152+I,  8, STAT1(J), 0)
      END DO
C
C MAG STATUS WORDS FOR MF-11, MF-13, MF-15, MF-17, MF-19
C
      STAT2(2) = 0
      CALL MOVBIT(PLS, 224,  8, STAT2(2), 8)
      CALL MOVBIT(PLS, 232,  8, STAT2(2), 0)
      DO J = 6,10
       I = (J-6)*16
       STAT1(J) = 0
       CALL MOVBIT(PLS, 240,  8, STAT1(J), 8)
       CALL MOVBIT(PLS, 248,  8, STAT1(J), 0)
      END DO
C
C MAG STATUS WORDS FOR MF-21, MF-23, MF-25, MF-27, MF-29
C
      STAT2(3) = 0
      CALL MOVBIT(PLS, 320,  8, STAT2(3), 8)
      CALL MOVBIT(PLS, 328,  8, STAT2(3), 0)
      DO J = 11,15
       I = (J-11)*16
       STAT1(J) = 0
       CALL MOVBIT(PLS, 336+I,  8, STAT1(J), 8)
       CALL MOVBIT(PLS, 344+I,  8, STAT1(J), 0)
      END DO
C
C MAG STATUS WORDS FOR MF-31
C
      STAT2(4) = 0
      CALL MOVBIT(PLS, 416,  8, STAT2(4), 8)
      CALL MOVBIT(PLS, 424,  8, STAT2(4), 0)
      STAT1(16) = 0
      CALL MOVBIT(PLS, 432,  8, STAT1(16), 8)
      CALL MOVBIT(PLS, 440,  8, STAT1(16), 0)
C
C START SPACECRAFT EVENT TIME IN MILLISECONDS OF DAY (UNSIGNED INTEGER)
C WORD 15
C
      CALL MOVBIT(PLS, 448, 8, STATIM, 24)
      CALL MOVBIT(PLS, 456, 8, STATIM, 16)
      CALL MOVBIT(PLS, 464, 8, STATIM,  8)
      CALL MOVBIT(PLS, 472, 8, STATIM,  0)
C
C MAG STATUS WORDS FOR MF-33, MF-35, MF-37, MF-39
C
      DO J = 17,20
       I = (J-17)*16
       STAT1(J) = 0
       CALL MOVBIT(PLS, 480+I,  8, STAT1(J), 8)
       CALL MOVBIT(PLS, 488+I,  8, STAT1(J), 0)
      END DO
C
C SPARE BITS 544-575 (WORD 18)
C
      CONTINUE
C
C PLASMA WORDS (800 WORDS)
C
      DO J = 1,800
       IOFF = (J-1)*8
       CALL MOVBIT(PLS, 576+IOFF, 8, M(J), 0)
      END DO
C
      IF ( SYS2(25) ) THEN
C
       IF ( ICALL.EQ.1 ) THEN
        OPEN(90,FILE='STATUS.DAT',FORM='FORMATTED',STATUS='NEW',
     &       CARRIAGECONTROL='LIST')
         WRITE(90,'('' REC  M   MILLI-         TIME         MAG  MAG'',
     &              ''  PLS  PLS  MAG  MAG'')')
         WRITE(90,'(''  #   O   SECONDS                     CMD  CMD'',
     &              ''  CMD  CMD  STAT STAT'')')
         WRITE(90,'(''      D   OF DAY  YY DDD HH MM SS MS  #1   #2'',
     &              ''   #1   #2   #1   #2'')')
         WRITE(90,'(''      E'')')
         WRITE(90,*)
        END IF
C
       TIME(1) = YEAR3
       CALL CONHOUR(SCETHR,TIME)
       CALL CONSEC(SCETSC,TIME)
       TIME(6) = SCETML
       DO I=1,20
        J = (I-1)/10 + 1
        K = (I-1)/5 + 1
        WRITE(90,800)  RECNUM,DATMOD,STATIM,TIME,MCOMM1(J),MCOMM2(J),
     &                 PCOMM1(J),PCOMM2(J),STAT1(I),STAT2(K)
       END DO
      END IF
C
      RETURN
  800 FORMAT(I5,1X,Z2.2,1X,I8,1X,I2,1X,I3.3,3(1X,I2.2),1X,I3.3,
     &       6(1X,Z4.4))
      END
