CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      SUBROUTINE DUMP_REL_FILE_HEADER(INUNIT, OUTUNIT, LENGTH, NPACKETS,
     &				      QAC_OFFSET)
C+
C
C FUNCTIONAL DESCRIPTION:
C
C     This routine dumps the file headers of REL files, which have varying
C     lengths, and are different in format from regular data files' headers;
C     they are ASCII, not binary.  It also extracts the number of packets from
C     the header and the offset in bytes to the QAC list.
C
C FORMAL ARGUMENTS:
C
C     INUNIT:
C	I*4	  I	The stream identifier of the REL file to be dumped.
C
C     OUTUNIT:
C	I*4	  I	The Fortran unit number of the output file to which
C			the dumped header information will be written.
C
C     LENGTH:
C	I*4	  I	The number of bytes to be read from the header of the
C			REL file. 
C
C     NPACKETS:
C	I*4	  O	An integer variable which upon return will contain the
C			number of packets in the REL file.
C
C     QAC_OFFSET:
C	I*4	  O	An integer variable which upon return will contain the
C			byte offset within the REL file of the first QAC entry.
C
C INTERFACE:
C
!	INTERFACE
!	  SUBROUTINE DUMP_REL_FILE_HEADER(INUNIT, OUTUNIT, LENGTH, NPACKETS,
!     &					  QAC_OFFSET) 
!	    INTEGER, INTENT(IN) :: INUNIT, OUTUNIT, LENGTH
!	    INTEGER, INTENT(OUT) :: NPACKETS, QAC_OFFSET
!	  END SUBROUTINE DUMP_REL_FILE_HEADER
!	END INTERFACE
C
C IMPLICIT INPUTS:
C
C     Variable FILE_HEADER from common block RELHDR contains the file header
C     that was read from the data file.
C
C IMPLICIT OUTPUTS:
C
C     None
C
C SIDE EFFECTS:
C
C     None
C
C COMMON BLOCKS:
C
C     RELHDR		contains FILE_HEADER, which was written to by 
C			GET_REL_FILE_HEADER
C
C INCLUDE FILES:
C
C     None
C
C DESIGN:
C
C     call GET_REL_FILE_HEADER to read an and partly decode file header
C     search for embedded LFs in header and record their positions
C     do a WRITE for each header line separated by LFs, using substring
C      operation with positions recorded in previous step
C
C CREATED:
C
C     6-OCT-1995   John Paquette
C
C This version:   1.5   15-NOV-1999
C
C DEVELOPMENT HISTORY:
C 
C  Author       Date		Description of Change 
C  --------	-----------	--------------------- 
C  J. PAQUETTE   6-OCT-1995     Created
C  J. PAQUETTE  10-OCT-1995     Changed output format for header
C  J. PAQUETTE  12-OCT-1995     Added comments
C  J. PAQUETTE  29-OCT-1995     Changed calling sequence to allow differnent
C                               input units. Previously always=1
C  L. Bleau	17-JAN-1996	added code to extract value of STARTIME keyword
C				and return it in parameter START_DATE
C  L. Bleau	19-JAN-1996	remove START_DATE from parameter list, pass
C                               header in common block
C  J. PAQUETTE  27-FEB-1996     Added capability to get QAC_OFFSET; also added
C                               it to the argument list
C  L. Bleau	28-FEB-1996	removed call to SOHO_READ_LZ, substituted call
C                               to GET_REL_FILE_HEADER to do the reading for
C                               us; commented out code which obtains NPACKETS
C                               and QAC_OFFSET, as these are already decoded by
C                               GET_REL_FILE_HEADER   
C  L. Bleau	 8-APR-1996	changed SOHO_READ_LZ to READ_STREAM
C  L. Bleau	 9-APR-1999	added comments
C  L. Bleau	 3-NOV-1999	added comments
C  L. Bleau	15-NOV-1999	added comments, deleted commented/unused code
C
C-
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CDEC$ IDENT '1.5'
      INTEGER*4 INUNIT, OUTUNIT, LENGTH, START, ENDLINE(0:20)
      INTEGER*4 NP_START, NP_END, NP_LENGTH, NPACKETS
      INTEGER*4 QACO_START, QACO_END, QACO_LENGTH, QAC_OFFSET
      INTEGER I, J, NLINES, NBYTES
      BYTE HEADER(512)
      CHARACTER*512 FILE_HEADER
      EQUIVALENCE (HEADER(1),FILE_HEADER)
      COMMON /RELHDR/ FILE_HEADER
C
      ENDLINE(0) = -1
      CALL GET_REL_FILE_HEADER(INUNIT, LENGTH, NPACKETS, QAC_OFFSET)
      J = 1
      DO 100 I = J, LENGTH
        IF(HEADER(I) .EQ. '0A'X) THEN
          ENDLINE(J)= I - 1
          J = J + 1
        ENDIF
  100 CONTINUE
      NLINES = J - 1
      WRITE(OUTUNIT,125)
  125 FORMAT(/' FILE HEADER:')
      DO 200 I = 1, NLINES
        WRITE(OUTUNIT, 150) FILE_HEADER(ENDLINE(I-1) + 2:ENDLINE(I))
  150   FORMAT(1X,A)
  200 CONTINUE
C
      RETURN
      END                                     

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      SUBROUTINE GET_REL_FILE_HEADER(INUNIT, LENGTH, NPACKETS, QAC_OFFSET)
C+
C
C FUNCTIONAL DESCRIPTION:
C
C     This routine reads the file header of an REL file, which has varying
C     lengths, and is different in format from a regular data file's header;
C     they are ASCII, not binary.  It also extracts the number of packets from
C     the header and the offset in bytes to the QAC list.  The file header is
C     stored in the common block RELHDR, where it can be accessed by other
C     modules. 
C
C FORMAL ARGUMENTS:
C
C     INUNIT:
C	I*4	  I	The stream identifier of the REL file to be dumped.
C
C     LENGTH:
C	I*4	  I	The number of bytes to be read from the header of the
C			REL file. 
C
C     NPACKETS:
C	I*4	  O	An integer variable which upon return will contain the
C			number of packets in the REL file.
C
C     QAC_OFFSET:
C	I*4	  O	An integer variable which upon return will contain the
C			byte offset within the REL file of the first QAC entry.
C
C INTERFACE:
C
!	INTERFACE
!	  SUBROUTINE GET_REL_FILE_HEADER(INUNIT, LENGTH, NPACKETS, QAC_OFFSET)
!	    INTEGER, INTENT(IN) :: INUNIT, LENGTH
!	    INTEGER, INTENT(OUT) :: NPACKETS, QAC_OFFSET
!	  END SUBROUTINE GET_REL_FILE_HEADER
!	END INTERFACE
C
C IMPLICIT INPUTS:
C
C     None
C
C IMPLICIT OUTPUTS:
C
C     The file reader is read from the file and stored into FILE_HEADER,
C     which is part of common block RELHDR.
C
C SIDE EFFECTS:
C
C     None
C
C COMMON BLOCKS:
C
C     RELHDR		contains FILE_HEADER and is used to pass the header
C			back to other programs
C
C INCLUDE FILES:
C
C     None
C
C DESIGN:
C
C     blank fill header variable since READ_STREAM doesn't
C     read in file header from data file
C     locate and decode number of packets field, return in NPACKETS
C     locate and decode offset to QAC, return in QAC_OFFSET
C     if this is a QKL, which has no QAC, return a 0 in QAC_OFFSET
C
C CREATED:
C
C     6-OCT-1995     John Paquette
C
C This version:  21-JUN-1995
C
C DEVELOPMENT HISTORY:
C 
C  Author       Date		Description of Change 
C  --------	-----------	--------------------- 
C  J. PAQUETTE   6-OCT-1995     Created
C  J. PAQUETTE  10-OCT-1995     Changed output format for header
C  J. PAQUETTE  12-OCT-1995     Added comments
C  J. PAQUETTE  29-OCT-1995     Changed calling sequence to allow differnent input 
C                               units. Previously always=1
C  L. Bleau	17-JAN-1996	added code to extract value of STARTIME keyword
C				and return it in parameter START_DATE
C  L. Bleau	19-JAN-1996	remove START_DATE from parameter list, pass
C                               header in common block
C  J. PAQUETTE  27-FEB-1996     Added capability to get QAC_OFFSET; also added it
C                               to the argument list
C  L. Bleau	28-FEB-1996	copied DUMP_REL_FILE_HEADER, made new routine
C				to only get the REL file header and store it in
C				common /RELHDR/
C  L. Bleau	 5-MAR-1995	check for QAC offset info not in header and
C				return QAC_OFFSET as 0 to indicate no QAC info
C  J. PAQUETTE  21-JUN-1996     Blank the file header at start of routine
C  L. Bleau	 9-APR-1999	added comments
C  L. Bleau	 3-NOV-1999	added comments
C  L. Bleau	15-NOV-1999	added comments
C
C-
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      INTEGER*4 INUNIT, LENGTH, START, ENDLINE(0:20), NP_START, NP_END, NP_LENGTH, NPACKETS,
     &          QACO_START, QACO_END, QACO_LENGTH, QAC_OFFSET
      INTEGER I, J, NLINES, NBYTES
      BYTE HEADER(512)
      CHARACTER*(512) FILE_HEADER
      EQUIVALENCE (HEADER(1),FILE_HEADER)
      COMMON /RELHDR/ FILE_HEADER
C
      FILE_HEADER = ' '
      ENDLINE(0) = -1
      CALL READ_STREAM( INUNIT, HEADER, LENGTH, NBYTES)
C
C Get the number of packets
C
      NP_START = INDEX(FILE_HEADER, 'NUM_PACK=') + 10
      NP_END = INDEX(FILE_HEADER, 'STARTIME') - 2
      NP_LENGTH = NP_START - NP_END + 1
      READ(FILE_HEADER(NP_START:NP_END), 55) NPACKETS
C
C Get the offset in bytes from the end of the file header to the start of the QAC list
C
      QACO_START = INDEX(FILE_HEADER, 'QAC Offset=') + 11
      QACO_END = INDEX(FILE_HEADER, 'DU Offset=') - 2
      QACO_LENGTH = QACO_START - QACO_END + 1
C
C In QKL files QAC offset and DU offset are not present, for some reason. 
C Detect this by testing QAC_START and QAC_END.  INDEX returns a 0 in this
C case, but both variable have had a constant added, so test against that
C constant.  If either failed flag file as having no QAC information, otherwise
C decode the value into QAC_OFFSET.
C
      IF (QACO_START .EQ. 11 .OR. QACO_END .EQ. -2) THEN
	QAC_OFFSET = 0
      ELSE
	READ(FILE_HEADER(QACO_START:QACO_END), 55) QAC_OFFSET
      ENDIF
C      
  55  FORMAT(I)
C
      RETURN
      END                                     
