      SUBROUTINE HDR1OUT(IUNIT,EDRTIME,EDRDSN,SEDRDSN,ZERODSN,SENSDSN)
C
C THIS ROUTINE WRITES THE HDR1 RECORD WHICH CONTAINS INFORMATION ABOUT
C PROCESSING PARAMETERS, RUN-TIME INPUT AND BASIC SPACECRAFT TELEMETRY.
C THE HDR1 RECORD APPEARS AS THE FIRST AND LAST FILE OF BOTH SUMMARY 
C AND DETAIL FILES.  
C
C WRITTEN BY SANDY KRAMER, HSTX, CODE 692
C
      CHARACTER TFLAG*4,RECTYPE*4,FLTID*4,TIMEFMT*4,TELFMT*4,
     &          RUNTYPE*8,COORD*4,RUNTIME*9,RUNMONTH*4,
     &          ZERODSN*8,SENSDSN*8,ZERONAME*8,SENSNAME*8,
     &          EDRDSN(10)*8,SEDRDSN(6)*8,EDRNAME(10)*8,
     &          SEDRNAME(6)*8,DM(0:31)*4
      INTEGER*2 EDRTIME(6),TIME(6),DATAID(2),WORD32(2)
      INTEGER*4 RUNDAY,RUNYEAR,CALDAY
      LOGICAL*1 MAGSYS(32),EDRSYS(32)
      REAL*4 HDR1(100)
C
      INCLUDE 'UNPACK.INC'
C
      EQUIVALENCE (HDR1(1),RECTYPE),     (HDR1(2),TELFMT),
     &            (HDR1(3),FLTID),       (HDR1(4),TIME(1)),
     &            (HDR1(7),RUNYEAR),     (HDR1(8),CALDAY),
     &            (HDR1(9),RUNMONTH),    (HDR1(10),RUNDAY),
     &            (HDR1(11),RUNTYPE),    (HDR1(13),COORD),
     &            (HDR1(17),DATAID(1)),  (HDR1(32),WORD32(1)),
     &            (HDR1(33),EDRNAME(1)), (HDR1(53),SEDRNAME(1)),
     &            (HDR1(69),EDRSYS),     (HDR1(77),MAGSYS),    
     &            (HDR1(93),ZERONAME),   (HDR1(95),SENSNAME)
C
      DATA DM/'ENG ','CR-2','CR-3','CR-4','CR-5','CR-6','CR-7','CR-1',
     &        'G10A','****','GS-3','****','GS-7','****','GS-6','GS-4',
     &        '****','GS-2','****','****','****','****','OC-2','OC-1',
     &        'CR5A','GS10','GS-8','****','****','UV5A','****','****'/
C
C OUTPUT RECORD COUNTER
C
      RECWRITE = RECWRITE + 1
C
C GET SYSTEM DATE ( DD-MMM-YY )
C
      CALL DATE(RUNTIME)
      RUNMONTH = ' '//RUNTIME(4:6)
      READ(RUNTIME,'(7X,I2)') RUNYEAR
      IF ( RUNYEAR.GT.77 ) THEN
       RUNYEAR = RUNYEAR + 1900
      ELSE
       RUNYEAR = RUNYEAR + 2000
      END IF
      READ(RUNTIME,'(I2,7X)') RUNDAY
      IF (RUNMONTH.EQ.'JAN') THEN
       CALDAY = 1
      ELSE IF (RUNMONTH.EQ.' FEB') THEN
       CALDAY = 32
      ELSE IF (RUNMONTH.EQ.' MAR') THEN
       CALDAY = 60
      ELSE IF (RUNMONTH.EQ.' APR') THEN
       CALDAY = 91
      ELSE IF (RUNMONTH.EQ.' MAY') THEN
       CALDAY = 121
      ELSE IF (RUNMONTH.EQ.' JUN') THEN
       CALDAY = 152
      ELSE IF (RUNMONTH.EQ.' JUL') THEN
       CALDAY = 182
      ELSE IF (RUNMONTH.EQ.' AUG') THEN
       CALDAY = 213
      ELSE IF (RUNMONTH.EQ.' SEP') THEN
       CALDAY = 244
      ELSE IF (RUNMONTH.EQ.' OCT') THEN
       CALDAY = 274
      ELSE IF (RUNMONTH.EQ.' NOV') THEN
       CALDAY = 305
      ELSE IF (RUNMONTH.EQ.' DEC') THEN
       CALDAY = 335
      ELSE
       CALDAY = -1
      END IF
      IF (MOD(RUNYEAR,4).EQ.0.AND.CALDAY.GT.1) CALDAY = CALDAY + 1
      CALDAY = CALDAY + RUNDAY - 1
C
      RECTYPE = 'HDR1'
      IF ( SYS2(17) .OR. SYS2(18) .OR. SYS2(19) .OR. SYS2(20) ) THEN
       RUNTYPE = 'ENCOUNTR'
      ELSE
       RUNTYPE = 'CRUISE'
      END IF
      IF ( SYS2(7).OR..NOT.SYS2(9) ) THEN
       IF ( SYS2(17) ) THEN
        COORD = 'S3'
       ELSE IF ( SYS2(18) ) THEN
        COORD = 'L1'
       ELSE IF ( SYS2(19) ) THEN
        COORD = 'U1'
       ELSE IF ( SYS2(20) ) THEN
        COORD = 'N1'
       ELSE
        COORD = 'HG'
       END IF
      ELSE
       COORD = 'PL  '
      END IF
      DATAID(1) = 8
      WORD32(1) = RECWRITE
      WORD32(2) = 68
C
C TELEMETRY FORMAT
C
      TELFMT = DM(DATMOD)
C
C S/C ID
C
      IF (SCID.EQ.0) THEN 
       FLTID = 'FLT2'
      ELSE IF (SCID.EQ.1) THEN
       FLTID = 'FLT1'
      ELSE IF (SCID.EQ.2) THEN
       FLTID = 'PTM '
      ELSE IF (SCID.EQ.3) THEN
       FLTID = 'SIM1'
      ELSE IF (SCID.EQ.4) THEN
       FLTID = 'SIM2'
      ELSE
       FLTID = 'UKWN'
      END IF
C
C DATA TIME
C
      DO I = 1,6
       TIME(I) = EDRTIME(I)
      END DO
C
C MAG SWITCHING VECTORS
C
      DO I = 1,32
       MAGSYS(I) = SYS2(I)
      END DO
C
C EDR DATA SET NAME(S)
C
      DO I = 1,10
       EDRNAME(I) = EDRDSN(I)
      END DO
C
C SEDR DATA SET NAME(S)
C
      DO I = 1,6
       SEDRNAME(I) = SEDRDSN(I)
      END DO
C
C ZERO TABLE NAME
C
      ZERONAME = ZERODSN
C
C SENSITIVITY TABLE NAME
C
      SENSNAME = SENSDSN
C
      WRITE(IUNIT) HDR1
C
      RETURN
      END
