CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      SUBROUTINE GET_FILE_HEADER( UNIT, FILE_HEADER )
C+
C
C FUNCTIONAL DESCRIPTION:
C
C     This routine gets the 48 byte file header from a SOHO Celias Level Zero
C     file and puts the values into a structure.
C
C FORMAL ARGUMENTS:
C
C     UNIT:
C	INT	  I	The stream id of the input file to be read.
C
C     FILE_HEADER:
C	/FILE_HDR/  O	A record of structure type FILE_HDR.  Upon return it
C			will contain the header information from the file
C			opened to UNIT. 
C
C INTERFACE:
C
!	INTERFACE
!	  SUBROUTINE GET_FILE_HEADER( UNIT, FILE_HEADER )
!	    INTEGER, INTENT(IN) :: UNIT
!	    RECORD /FILE_HDR/ FILE_HEADER
!	    INTENT(OUT) FILE_HEADER
!	  END SUBROUTINE GET_FILE_HEADER
!	END INTERFACE
C
C SIDE EFFECTS:
C
C     File pointer of file opened to UNIT is advanced 48 bytes.
C
C COMMON BLOCKS:
C
C     None
C
C INCLUDE FILES:
C
C     EDBDEF.INC
C
C CREATED:
C
C     30-AUG-1995    John Paquette
C
C This version:   1.5   20-APR-1999
C
C DEVELOPMENT HISTORY:
C 
C  Author       Date		Description of Change 
C  --------	-----------	--------------------- 
C  J. PAQUETTE  30-AUG-1995     Created
C  J. PAQUETTE   6-SEP-1995     Reading of LZ file now done by SOHO_READ_LZ
C  J. PAQUETTE  26-OCT-1995     Corrected error that made Receipt time always 0
C  J. PAQUETTE  29-OCT-1995     Now uses unit number (previously always=1)
C  L. Bleau	 8-APR-1996	changed SOHO_READ_LZ to READ_STREAM
C  L. Bleau	20-APR-1999	added IMPLICIT NONE, comments
C-
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CDEC$ IDENT	'1.5'
      IMPLICIT NONE
      INCLUDE 'INC_DIR:EDBDEF.INC'
      BYTE HDR(48)
      INTEGER*2 I2_HDR(24)
      INTEGER*4 NBYTES, UNIT
      CHARACTER*48 C_HDR
      EQUIVALENCE ( HDR(1), C_HDR, I2_HDR(1) )
      RECORD /FILE_HDR/ FILE_HEADER
C
      CALL READ_STREAM( UNIT, HDR, 48, NBYTES)
C
C Transfer header information into FILE_HEADER structure. Many of these quantitites are bit 
C fields of various lengths, and they are to be placed into INTEGER variables without sign
C extension. Those quantities that are already integers have an endianity of Motorola, which 
C is the opposite of the endianity used by VMS systems. Therefore, byte swapping is neccesary.
C
C The first 6 bits are always 0. The next ten are the Spacecraft ID.
C
      CALL SWAP_BYTES(I2_HDR(1))
      CALL MVBITS( I2_HDR(1), 0, 10, FILE_HEADER.SC_ID, 0)
C
C Convert the PB5C spacecraft clock time of the first packet to EPOCH time (time since 
C 1-JAN-1958) and to Gregorian time (Year, Day, Hour, Min ,Sec, etc).
C 
      CALL SOHO_PB5C_TO_EPOCH( I2_HDR(2), FILE_HEADER.FIRST_EPOCH )
      CALL SOHO_EPOCH_TO_GREG( FILE_HEADER.FIRST_EPOCH, FILE_HEADER.FIRST_TIME.YEAR,	
     &                         FILE_HEADER.FIRST_TIME.DOY, FILE_HEADER.FIRST_TIME.HR,
     &                         FILE_HEADER.FIRST_TIME.MIN, FILE_HEADER.FIRST_TIME.SEC,	
     &                         FILE_HEADER.FIRST_TIME.MSEC, FILE_HEADER.FIRST_TIME.MICRO )
C
C Convert the PB5C spacecraft clock time of the last packet to EPOCH time (time since 
C 1-JAN-1958) and to Gregorian time (Year, Day, Hour, Min ,Sec, etc).
C 
      CALL SOHO_PB5C_TO_EPOCH( I2_HDR(7), FILE_HEADER.LAST_EPOCH )
      CALL SOHO_EPOCH_TO_GREG( FILE_HEADER.LAST_EPOCH, FILE_HEADER.LAST_TIME.YEAR,	
     &                         FILE_HEADER.LAST_TIME.DOY, FILE_HEADER.LAST_TIME.HR,
     &                         FILE_HEADER.LAST_TIME.MIN, FILE_HEADER.LAST_TIME.SEC,	
     &                         FILE_HEADER.LAST_TIME.MSEC, FILE_HEADER.LAST_TIME.MICRO )
C
C Get the number of source packets in file.
C
      CALL SWAP_BYTES(I2_HDR(12))
      CALL SWAP_BYTES(I2_HDR(13))
      FILE_HEADER.NUM_PACKETS = ISHFT(ZEXT(I2_HDR(12)), 16) + ZEXT(I2_HDR(13))
C      
C Store the processing options. The meaning of these bits is as follows:
C Bit 3 Redundant data deleted          Bit 7 RS decoding
C Bit 6 Data merging                    Bit 8 Data reversal
C
      FILE_HEADER.PROC_OPT = ZEXT(HDR(27))
C      
C Store the Data type flags. Bit 1 indicates Routine production data
C                            Bit 2 indicates Quicklook data
C
      FILE_HEADER.DATA_TYPE_FLAGS = ZEXT(HDR(28))
C
C Convert the PB5B spacecraft clock time of the receipt at the originating node (whatever
C that means) to EPOCH time (time since 1-JAN-1958) and to Gregorian time (Year, Day, Hour,
C Minute ,Second, etc).
C 
      CALL SOHO_PB5C_TO_EPOCH( I2_HDR(15), FILE_HEADER.RECEIPT_EPOCH )
      CALL SOHO_EPOCH_TO_GREG( FILE_HEADER.RECEIPT_EPOCH, FILE_HEADER.RECEIPT_TIME.YEAR,	
     &                         FILE_HEADER.RECEIPT_TIME.DOY, FILE_HEADER.RECEIPT_TIME.HR,
     &                         FILE_HEADER.RECEIPT_TIME.MIN, FILE_HEADER.RECEIPT_TIME.SEC,	
     &                         FILE_HEADER.RECEIPT_TIME.MSEC, FILE_HEADER.RECEIPT_TIME.MICRO )
C
C Store the select options. This should have the value 2, meaning "Select by APID"
C
      FILE_HEADER.SEL_OPT = ZEXT(HDR(39))
C
C Get the number of selected APID's
C
      FILE_HEADER.NUM_SEL_APID = ZEXT(HDR(40))
C
C Get the actual APID (A9 hex for Celias science)
C
      CALL SWAP_BYTES(I2_HDR(21))
      FILE_HEADER.APID = ZEXT(I2_HDR(21))
C
C Get the number of Quality and Accounting Capsule lists in the file
C
      FILE_HEADER.NUM_QAC = ZEXT(HDR(44))
C
C Get the offset (presumably in bytes) to the QAC list (which begins after the last data
C packet.
C
      CALL SWAP_BYTES(I2_HDR(23))
      CALL SWAP_BYTES(I2_HDR(24))
      FILE_HEADER.QAC_OFFSET = ISHFT(ZEXT(I2_HDR(23)), 16) + ZEXT(I2_HDR(24))
C
C The file header has now been transferred to structure. Return.
C
      RETURN
      END
