******************************************************************
*
*	TITLE:  UNPACK VOYAGER 360 WORD EDR SUBHEADER (PLS DATA)
*
*	FILE NAME:  PLSCR1.FOR
*
*	PURPOSE:  TO UNPACK THE SUBHEADER (PLS DATA) ACCORDING TO THE 
*                  SPECIFIED MOD60 FORMAT
* 
*	HISTORY:
*
*	AUTHOR       	  DATE              CHANGE
*	--------          ----              ------
*	S. B. KRAMER     10/04/95           ORIGINAL CODE
*
*	CALLING SEQUENCE:  SUBROUTINE PLSCR1()
*
*	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 PLSCR1()
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
      PCOMM1(1) = 0
      CALL MOVBIT(  PLS,   8,  8, PCOMM1(1),   0)
      CALL MOVBIT(  PLS,   0,  8, PCOMM1(1),   8)
      PCOMM2(1) = 0
      CALL MOVBIT(  PLS,  24,  8, PCOMM2(1),   0)
      CALL MOVBIT(  PLS,  16,  8, PCOMM2(1),   8)
      MCOMM1(1) = 0
      CALL MOVBIT(  PLS,  40,  8, MCOMM1(1),   0)
      CALL MOVBIT(  PLS,  32,  8, MCOMM1(1),   8)
      MCOMM2(1) = 0
      CALL MOVBIT(  PLS,  56,  8, MCOMM2(1),   0)
      CALL MOVBIT(  PLS,  48,  8, MCOMM2(1),   8)
C
C WORDS 3 AND 4 (BITS 64-127) ARE SPARE
C
      CONTINUE
C
C START SPACECRAFT EVENT TIME IN MILLISECONDS OF DAY (UNSIGNED INTEGER)
C
      CALL MOVBIT(  PLS, 152,   8, STATIM,   0)
      CALL MOVBIT(  PLS, 144,   8, STATIM,   8)
      CALL MOVBIT(  PLS, 136,   8, STATIM,  16)
      CALL MOVBIT(  PLS, 128,   8, STATIM,  24)
C
C WORDS 6 AND 7 (BITS 160-223) 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
      DO I=1,8
       J = (I-1) * 32
       STAT1(I) = 0
       CALL MOVBIT(  PLS, 232+J,  8, STAT1(I),   0)
       CALL MOVBIT(  PLS, 224+J,  8, STAT1(I),   8)
       STAT2(I) = 0
       CALL MOVBIT(  PLS, 248+J,  8, STAT2(I),   0)
       CALL MOVBIT(  PLS, 240+J,  8, STAT2(I),   8)
      END DO
C
C WORD 16 (BITS 480-511) SPARE
C
      CONTINUE
C
C PLASMA DATA IN WORDS 17-336 (BITS 512-10751) - 1280 PLASMA WORDS
C
      DO J = 1,1280
       IOFF = (J-1)*8 ! BIT OFFSET
       CALL MOVBIT(PLS, 512+IOFF, 8, M(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,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,8
        WRITE(90,800)  RECNUM,DATMOD,STATIM,TIME,MCOMM1(1),MCOMM2(1),
     &                 PCOMM1(1),PCOMM2(1),STAT1(I),STAT2(I)
       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
