******************************************************************
*
*	TITLE:  UNPACK VOYAGER 66 WORD EDR SUBHEADER (PLS DATA)
*
*	FILE NAME:  PLSCR2.FOR
*
*	PURPOSE:  TO UNPACK THE SUBHEADER (PLS DATA) ACCORDING TO THE 
*                  SPECIFIED MOD60 FORMAT
* 
*	HISTORY:
*
*	AUTHOR       	  DATE              CHANGE
*	--------          ----              ------
*	S. B. KRAMER     02/01/96           ORIGINAL CODE
*
*	CALLING SEQUENCE:  SUBROUTINE PLSCR2()
*
*	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 PLSCR2()
C
      INTEGER*2 TIME(6)
      LOGICAL*1 PSCAN(15)
      LOGICAL*4 STATIM
C
      INCLUDE 'UNPACK.INC'
C
      DATA ICALL/0/
C
      IF ( DRSDAT.NE.35 ) RETURN
C
      ICALL = ICALL + 1
C
      PCOMM1(1) = 0
      CALL MOVBIT(  PLS,   0,  8, PCOMM1(1),   8)
      CALL MOVBIT(  PLS,   8,  8, PCOMM1(1),   0)
C
      MCOMM1(1) = 0
      CALL MOVBIT(  PLS,  32,  8, MCOMM1(1),   8)
      CALL MOVBIT(  PLS,  40,  8, MCOMM1(1),   0)
      MCOMM2(1) = 0
      CALL MOVBIT(  PLS,  48,  8, MCOMM2(1),   8)
      CALL MOVBIT(  PLS,  56,  8, MCOMM2(1),   0)
C
C WORDS 3 - 5  (BITS 64-159) ARE SPARE
C
      CONTINUE
C
C MAG STATUS WORDS FOR MF'S 1, 11, 21, 31, 41, 51, 61, 71
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
      STAT1(1) = 0
      CALL MOVBIT(  PLS, 192,  8, STAT1(1),   8)
      CALL MOVBIT(  PLS, 200,  8, STAT1(1),   0)
      STAT2(1) = 0
      CALL MOVBIT(  PLS, 208,  8, STAT2(1),   8)
      CALL MOVBIT(  PLS, 216,  8, STAT2(1),   0)
      STAT1(2) = 0
      CALL MOVBIT(  PLS, 224,  8, STAT1(2),   8)
      CALL MOVBIT(  PLS, 232,  8, STAT1(2),   0)
      STAT1(3) = 0
      CALL MOVBIT(  PLS, 240,  8, STAT1(3),   8)
      CALL MOVBIT(  PLS, 248,  8, STAT1(3),   0)
      STAT1(4) = 0
      CALL MOVBIT(  PLS, 256,  8, STAT1(4),   8)
      CALL MOVBIT(  PLS, 264,  8, STAT1(4),   0)
      STAT1(5) = 0
      CALL MOVBIT(  PLS, 272,  8, STAT1(5),   8)
      CALL MOVBIT(  PLS, 280,  8, STAT1(5),   0)
C
C WORDS 10 - 14 AND 7 (BITS 288-447) ARE SPARE
C
      CONTINUE
C
C START SPACECRAFT EVENT TIME IN MILLISECONDS OF DAY (UNSIGNED INTEGER)
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)
      CONTINUE
C
C WORD 16 (BITS 480-511) SPARE
C
      CONTINUE
C
C PLASMA DATA (15 WORDS) IN WORDS 17-65 (BITS 512-2063)
C
      DO J = 1,15
       IOFF = (J-1)*8
       CALL MOVBIT(  PLS, 512+IOFF, 8, PSCAN(J), 0)
      END DO
C
C OUTPUT MAG AND PLS COMMAND WORDS AND MAG STATUS WORDS
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,5
        WRITE(90,800)  RECNUM,DATMOD,STATIM,TIME,MCOMM1(1),MCOMM2(1),
     &                 PCOMM1(1),PCOMM2(1),STAT1(I),STAT2(1)
       END DO
       WRITE(90,*) 
      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
