******************************************************************
*
*	TITLE:  UNPACK VOYAGER 68 WORD EDR SUBHEADER (PLS DATA)
*
*************** CONTAINS L SHOER CORRECTION ******************
*
*	FILE NAME:  PLSGS3.FOR
*
*	PURPOSE:  TO UNPACK THE SUBHEADER (PLS DATA) ACCORDING TO THE 
*                  SPECIFIED MOD60 FORMAT
* 
*	HISTORY:
*
*	AUTHOR       	  DATE              CHANGE
*	--------          ----              ------
*	S. J. KEMPLER     8/12/85           ORIGINAL CODE
*	S. B. KRAMER     11/01/93           MODIFIED FOR NEW VOY PROD PGM
*
*	CALLING SEQUENCE:  SUBROUTINE PLSGS3()
*
*	ARGUMENT LIST:
*
*	NAME		TYPE	USED	PURPOSE
*	-----		-----	----	-------
*
*	MODULES REFERENCED:
*
*		MOVBIT
*
*	COMMON AREAS:
*
*		SEE UNPACK.INC FOR COMMON AREA DEFINITIONS
*
*	NOTES:
*
*		THE PLS DATA FORMAT TO BE USED IS DETERMINED BY THE REMAINDER
*                AFTER DIVIDING THE VARIABLE MOD60 BY 15.  THEREFORE,
*                FORMATS MAY BE NUMBERED 0 TO 14.
*
*	PDL:
*
*		SET UNSTAT TO 0
*		CALL MOVBIT TO LOAD THE FIRST 20 WORDS (PLS HEADER) INTO I*2
*                VARIABLES
*		CALCULATE THE REMAINDER OF MOD60 DIVIDED BY 15
*		CALL MOVBIT TO LOAD THE REMAINING 48 WORDS ACCORDING TO THE 
*                FORMAT NUMBER CALCULATED ABOVE (SEE NOTES) INTO I*2 VARIABLES
*		RETURN
*
*******************************************************************
      SUBROUTINE PLSGS3()
C
      INTEGER*2 TIME(6)
      LOGICAL*4 STATIM
      DATA ICALL/0/
C
      INCLUDE 'UNPACK.INC'
C
      IF (DRSDAT.NE.35) RETURN
      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 MAG STATUS WORDS FOR MF'S 1, 9, 17, 25, 33, 41, 49, 57, 65, 73
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 10 I=1,10
C
         J = (I-1) * 32
C
         STAT1(I) = 0
         CALL MOVBIT(  PLS, 72+J,  8, STAT1(I),   0)
         CALL MOVBIT(  PLS, 64+J,  8, STAT1(I),   8)
         STAT2(I) = 0
         CALL MOVBIT(  PLS, 88+J,  8, STAT2(I),   0)
         CALL MOVBIT(  PLS, 80+J,  8, STAT2(I),   8)
C
  10  CONTINUE
C
C START SPACECRAFT EVENT TIME IN MILLISECONDS OF DAY (UNSIGNED INTEGER)
C
      CALL MOVBIT(  PLS, 472,   8, STATIM,   0)
      CALL MOVBIT(  PLS, 464,   8, STATIM,   8)
      CALL MOVBIT(  PLS, 456,   8, STATIM,  16)
      CALL MOVBIT(  PLS, 448,   8, STATIM,  24)
C
      PLSREC = IMOD(MOD60,15) + 1
      GO TO (1,2,2,2,2,2,2,2,2,2,2,2,13,14,15) PLSREC
C
  1   L63 = 0
      CALL MOVBIT(  PLS, 640,   8,    L63,   0)
      L64 = 0
      CALL MOVBIT(  PLS, 648,   8,    L64,   0)
C
  2   LSTAT1 = 0
      CALL MOVBIT(  PLS, 864,   8, LSTAT1,   0)
C
      I=0
      DO 20 I1=1,16
         DO 21 I2=1,4
            I=I+1
            J = (I-1) * 8
            LSHORT(I1,I2) = 0
            CALL MOVBIT(  PLS, 872+J,  8, LSHORT(I1,I2),   0)
  21     CONTINUE
  20  CONTINUE
C
C     L SHORT CORRECTION BEFORE THE YEAR 2000
C
      IF (YEAR3.GT.60) THEN
         DO 25 I=1,15
            DO 26 J=1,4
                LSHORT(I,J) = LSHORT(I+1,J)
  26        CONTINUE
  25     CONTINUE
         DO 27 J=1,4
            LSHORT(16,J) = -1
  27     CONTINUE
      ENDIF
C
      ESTAT1 = 0
      CALL MOVBIT(  PLS, 1384,   8, ESTAT1,   0)
C
      DO 30 I=1,16
         J = (I-1) * 8
         ESHORT(I) = 0
         CALL MOVBIT(  PLS, 1392+J,  8, ESHORT(I),   0)
  30  CONTINUE
C
      LSTAT2 = 0
      CALL MOVBIT(  PLS, 1520,   8, LSTAT2,   0)
C
      I=0
      DO 40 I1=1,16
         DO 41 I2=1,4
            I=I+1
            J = (I-1) * 8
            LLONG(I1,I2) = 0
            CALL MOVBIT(  PLS, 1528+J,  8, LLONG(I1,I2),   0)
  41     CONTINUE
  40  CONTINUE
C
      ESTAT2 = 0
      CALL MOVBIT(  PLS, 2040,   8, ESTAT2,   0)
C
      DO 50 I=1,16
         J = (I-1) * 8
         ELONG(I) = 0
         CALL MOVBIT(  PLS, 2048+J,  8, ELONG(I),   0)
  50  CONTINUE
C
      GO TO 95
C
  13  MSTAT = 0
      CALL MOVBIT(  PLS,   640,  8, DMSTAT,   0)
C
      DO 60 I=1,191
         J = (I-1) * 8
         M(I) = 0
         CALL MOVBIT(  PLS, 648+J,  8, M(I),   0)
  60  CONTINUE
C
      GO TO 95
C
  14  DO 70 I=1,192
         J = (I-1) * 8
         M(I) = 0
         CALL MOVBIT(  PLS, 640+J,  8, M(I),   0)
  70  CONTINUE
C
      GO TO 95
C
  15  DO 80 I=1,129
         J = (I-1) * 8
         M(I) = 0
         CALL MOVBIT(  PLS, 640+J,  8, M(I),   0)
  80  CONTINUE
C
      LSTAT = 0
      CALL MOVBIT(  PLS, 1672,  8, LSTAT,   0)
C
      I=0
      DO 90 I1=1,16
         DO 91 I2=1,4
            I=I+1
            IF(I.GT.62) GO TO 95
            J = (I-1) * 8
            LLONG(I1,I2) = 0
            CALL MOVBIT(  PLS, 1680+J,  8, LLONG(I1,I2),   0)
  91     CONTINUE
  90  CONTINUE
  95  CONTINUE
C
C OUTPUT MAG/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,10
        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
