******************************************************************
*
*	TITLE:  UNPACK VOYAGER 60 WORD EDR HEADER
*
*	FILE NAME:  UNHEAD.FOR
*
*	PURPOSE:  TO UNPACK THE HEADER BLOCK
*
*	HISTORY:
*
*	AUTHOR            DATE             CHANGE
*	--------          ----             ------
*	S. J. KEMPLER     8/12/85          ORIGINAL CODE
*       S. B. KRAMER      9/27/92          MODIFIED FOR VIM-5 MODE
*       S. B. KRAMER     10/26/93          MODIFIED FOR ALL MODES
*
*	CALLING SEQUENCE:  SUBROUTINE UNHEAD(INBUF)
*
*	MODULES REFERENCED:
*
*		MOVBIT
*
*	COMMON AREAS:
*
*		SEE UNPACK.INC FOR COMMON AREA DEFINITIONS
*
*	PDL:
*
*		GET HEADER BLOCK FROM EDR RECORD
*		CALL MOVBIT TO LOAD DATMOD WITH DATA MODE
*		CALL MOVBIT TO LOAD MOD60 WITH MOD 60 COUNT WORD
*		LOAD PROJID WITH THE 3 CHARACTER PROJECT ID
*		CALL MOVBIT TO LOAD ALL OTHER ITEMS OF THE HEADER FIELD 
*                INTO INDIVIDUAL I*2 VARIABLES
*		RETURN
*
******************************************************************* 
C
      SUBROUTINE UNHEAD(INBUF)
C
      LOGICAL*1 INBUF(11280),LPROJ(3)
C
      INCLUDE 'UNPACK.INC'
C
      EQUIVALENCE (PROJID,LPROJ(1))
C
C ASSIGN FIRST 240 BYTES OF EDR RECORD TO HEADER ARRAY (ALL MODES)
C
      DO I = 1,240
       HEAD(I) = INBUF(I)
      END DO
C
      LPROJ(1) = HEAD(1)
      LPROJ(2) = HEAD(2)
      LPROJ(3) = HEAD(3)
C
      ISTAT = LIB$TRA_EBC_ASC(PROJID,PROJID)
C
C IDENTIFY MARINER JUPITER SATURN (MJS) PROJECT ID
C
      IF (PROJID.NE.'MJS') RETURN
C
C ERROR IN KEMPLER'S DECOMMUTATION REVERSES RECID AND SCID 
C CORRECTED FOR VIM-5 PROCESSING (SBK - 10/8/92)
C
      HEAD(4) = FLIP(ZEXT(HEAD(4)))
      RECID = 0
      CALL MOVBIT(  HEAD,  24,  1,  RECID,   3)
      CALL MOVBIT(  HEAD,  25,  1,  RECID,   2)
      CALL MOVBIT(  HEAD,  26,  1,  RECID,   1)
      CALL MOVBIT(  HEAD,  27,  1,  RECID,   0)
      SCID = 0
      CALL MOVBIT(  HEAD,  28,  1,   SCID,   3)
      CALL MOVBIT(  HEAD,  29,  1,   SCID,   2)
      CALL MOVBIT(  HEAD,  30,  1,   SCID,   1)
      CALL MOVBIT(  HEAD,  31,  1,   SCID,   0)
C
      RECNUM = 0
      CALL MOVBIT(  HEAD,  40,  8, RECNUM,   0)
      CALL MOVBIT(  HEAD,  32,  8, RECNUM,   8)
      DATMOD = 0
      CALL MOVBIT(  HEAD,  48,  8, DATMOD,   0)
C
      HEAD(8) = FLIP(ZEXT(HEAD(8)))
      EEXTFL = 0
      CALL MOVBIT(  HEAD,  56,  1, EEXTFL,   1)
      CALL MOVBIT(  HEAD,  57,  1, EEXTFL,   0)
      SCPLAB = 0
      CALL MOVBIT(  HEAD,  58,  1, SCPLAB,   0)
      RECTIM = 0
      CALL MOVBIT(  HEAD,  59,  1, RECTIM,   4)
      CALL MOVBIT(  HEAD,  60,  1, RECTIM,   3)
      CALL MOVBIT(  HEAD,  61,  1, RECTIM,   2)
      CALL MOVBIT(  HEAD,  62,  1, RECTIM,   1)
      CALL MOVBIT(  HEAD,  63,  1, RECTIM,   0)
C
      ERTSHR = 0
      CALL MOVBIT(  HEAD,  72,  8, ERTSHR,   0)
      CALL MOVBIT(  HEAD,  64,  8, ERTSHR,   8)
      ERTSSC = 0
      CALL MOVBIT(  HEAD,  88,  8, ERTSSC,   0)
      CALL MOVBIT(  HEAD,  80,  8, ERTSSC,   8)
      ERTSML = 0
      CALL MOVBIT(  HEAD, 104,  8, ERTSML,   0)
      CALL MOVBIT(  HEAD,  96,  8, ERTSML,   8)
      YEAR1 = 0
      CALL MOVBIT(  HEAD, 112,  8,  YEAR1,   0)
C
      HEAD(16) = FLIP(ZEXT(HEAD(16)))
      DATSRC = 0
      CALL MOVBIT(  HEAD, 120,  1, DATSRC,   1)
      CALL MOVBIT(  HEAD, 121,  1, DATSRC,   0)
      GOLAY = 0
      CALL MOVBIT(  HEAD, 122,  1,  GOLAY,   1)
      CALL MOVBIT(  HEAD, 123,  1,  GOLAY,   0)
      SEGNUM = 0
      CALL MOVBIT(  HEAD, 124,  1, SEGNUM,   3)
      CALL MOVBIT(  HEAD, 125,  1, SEGNUM,   2)
      CALL MOVBIT(  HEAD, 126,  1, SEGNUM,   1)
      CALL MOVBIT(  HEAD, 127,  1, SEGNUM,   0)
C
      ERTEHR = 0
      CALL MOVBIT(  HEAD, 136,  8, ERTEHR,   0)
      CALL MOVBIT(  HEAD, 128,  8, ERTEHR,   8)
      ERTESC = 0
      CALL MOVBIT(  HEAD, 152,  8, ERTESC,   0)
      CALL MOVBIT(  HEAD, 144,  8, ERTESC,   8)
      ERTEML = 0
      CALL MOVBIT(  HEAD, 168,  8, ERTEML,   0)
      CALL MOVBIT(  HEAD, 160,  8, ERTEML,   8)
      YEAR2 = 0
      CALL MOVBIT(  HEAD, 176,  8,  YEAR2,   0)
      SWVERS = 0
      CALL MOVBIT(  HEAD, 184,  8, SWVERS,   0)
      SCETHR = 0
      CALL MOVBIT(  HEAD, 200,  8, SCETHR,   0)
      CALL MOVBIT(  HEAD, 192,  8, SCETHR,   8)
      SCETSC = 0
      CALL MOVBIT(  HEAD, 216,  8, SCETSC,   0)
      CALL MOVBIT(  HEAD, 208,  8, SCETSC,   8)
      SCETML = 0
      CALL MOVBIT(  HEAD, 232,  8, SCETML,   0)
      CALL MOVBIT(  HEAD, 224,  8, SCETML,   8)
      YEAR3 = 0
      CALL MOVBIT(  HEAD, 240,  8,  YEAR3,   0)
C
      HEAD(32) = FLIP(ZEXT(HEAD(32)))
      SCEVFL = 0
      CALL MOVBIT(  HEAD, 248,  1, SCEVFL,   3)
      CALL MOVBIT(  HEAD, 249,  1, SCEVFL,   2)
      CALL MOVBIT(  HEAD, 250,  1, SCEVFL,   1)
      CALL MOVBIT(  HEAD, 251,  1, SCEVFL,   0)
      CORRFL = 0
      CALL MOVBIT(  HEAD, 252,  1, CORRFL,   3)
      CALL MOVBIT(  HEAD, 253,  1, CORRFL,   2)
      CALL MOVBIT(  HEAD, 254,  1, CORRFL,   1)
      CALL MOVBIT(  HEAD, 255,  1, CORRFL,   0)
C
      MOD216 = 0
      CALL MOVBIT(  HEAD, 264,  8, MOD216,   0)
      CALL MOVBIT(  HEAD, 256,  8, MOD216,   8)
      MOD60 = 0
      CALL MOVBIT(  HEAD, 272,  8,  MOD60,   0)
      LINCNT = 0
      CALL MOVBIT(  HEAD, 288,  8, LINCNT,   0)
      CALL MOVBIT(  HEAD, 280,  8, LINCNT,   8)
      TELRAT = 0
      CALL MOVBIT(  HEAD, 296,  8, TELRAT,   0)
      EFFRAT = 0
      CALL MOVBIT(  HEAD, 304,  8, EFFRAT,   0)
      FORMID = 0
      CALL MOVBIT(  HEAD, 312,  8, FORMID,   0)
      BERTOL = 0
      CALL MOVBIT(  HEAD, 320,  8, BERTOL,   0)
      DSNCON = 0
      CALL MOVBIT(  HEAD, 328,  8, DSNCON,   0)
      RECAGC = 0
      CALL MOVBIT(  HEAD, 344,  8, RECAGC,   0)
      CALL MOVBIT(  HEAD, 336,  8, RECAGC,   8)
      DSNNUM = 0
      CALL MOVBIT(  HEAD, 352,  8, DSNNUM,   0)
      EBEC = 0
      CALL MOVBIT(  HEAD, 376,  8,   EBEC,   0)
      CALL MOVBIT(  HEAD, 368,  8,   EBEC,   8)
      SYMSNR = 0
      CALL MOVBIT(  HEAD, 392,  8, SYMSNR,   0)
      CALL MOVBIT(  HEAD, 384,  8, SYMSNR,   8)
      DECSNR = 0
      CALL MOVBIT(  HEAD, 408,  8, DECSNR,   0)
      CALL MOVBIT(  HEAD, 400,  8, DECSNR,   8)
      PHYSRN = 0
      CALL MOVBIT(  HEAD, 424,  8, PHYSRN,   0)
      CALL MOVBIT(  HEAD, 416,  8, PHYSRN,   8)
C
C 8 BIT DATA QUALITY STATUS WORD//8 BIT DATA QUALITY INDICATOR
C
      DO 10 I=1,10
         J = (I-1) * 16
         DQSW(I) = 0
         CALL MOVBIT(  HEAD, 432+J,  8, DQSW(I),   0)
         DQI(I) = 0
         CALL MOVBIT(  HEAD, 440+J,  8,  DQI(I),   0)
  10  CONTINUE
C
C UNPACK 4 BIT DATA PRESENCE INDICATORS (80 MF MAX) 
C CR-7 AND VIM-5 MODES
C
      IF ( DATMOD.EQ.6 .OR. DATMOD.EQ.24 .OR. DATMOD.EQ.29 ) THEN
       DO 20 I=1,40
          J = (I-1) * 8
          K = I*2 - 1
          L = I*2
          DPI(K) = 0
          DPI(L) = 0
          CALL MOVBIT(  HEAD, 592+J,  4, DPI(L),   0)
          CALL MOVBIT(  HEAD, 596+J,  4, DPI(K),   0)
  20   CONTINUE
C
C UNPACK 8 BIT DATA PRESENCE INDICATORS (150 MF MAX) 
C CR-1 THROUGH CR-6 MODES
C
      ELSE IF ( DATMOD.GE.1 .AND. DATMOD.LE.7 .AND. DATMOD.NE.6 ) THEN
       DO 30 I=1,150
        J = (I-1)*8
        DPI(I) = 0
        CALL MOVBIT(  HEAD, 592+J,  8, DPI(I),   0)
  30   CONTINUE
C
C UNPACK 8 BIT DATA PRESENCE INDICATORS AND 8 BIT GOLAY CORRECTION
C INDICATORS (80 MF MAX) 
C GS-X MODES
C
      ELSE IF ( DATMOD.LE.31 ) THEN
       DO 40 I=1,80
        J = (I-1)*16
        DPI(I) = 0
        CALL MOVBIT(  HEAD, 592+J,  8, DPI(I),   0)
        GCI(I) = 0
        CALL MOVBIT(  HEAD, 600+J,  8, GCI(I),   0)
  40   CONTINUE
      ELSE
C      INVALID DATMOD VALUE
      END IF
C
C FIELDS GCI, DPIRIS, GPIRIS ARE NOT USED IN VIM-5 MODE.
C THEREFORE BITS 892 - 1887 ARE SPARES.
C
      DRSDAT = 0
      CALL MOVBIT(  HEAD, 1888,  8, DRSDAT,   0)
      GCBEC = 0
      CALL MOVBIT(  HEAD, 1896,  8,  GCBEC,   0)
      GBITES = 0
      CALL MOVBIT(  HEAD, 1912,  8, GBITES,   0)
      CALL MOVBIT(  HEAD, 1904,  8, GBITES,   8)
C
      RETURN
      END
