*
* $Id$
*
* $Log$
* Revision 1.1  1996/03/08 15:21:42  mclareni
* Initial revision
*
*
#include "epio/pilot.h"
      SUBROUTINE EPADDH(LUNIT,NH,IH,IBUF,IERR)
C.
C. ADDS A USER PORTION TO THE STANDARD PHYSICAL HEADER.THE CURRENT BLOCK
C. IS WRITTEN OUT BEFOREHAND IF NOT EMPTY.
C.
C. THE PHYS. HEADER IS RESET TO THE STANDARD HEADER AFTER A REWIND.
C.
C. INPUT :
C.
C. LUNIT  LOGICAL UNIT
C.
C. NH     NO. OF 16 OR 32 BIT WORDS TO ADD ( 0 POSSIBLE - RESETS )
C.
C. IH     USER P.H. WORDS TO ADD (16 OR 32 BIT, RIGHT ADJ, 0 FILLED)
C.++++ important: 32 bit words have to be converted beforehand by user
C.
C. IBUF     USER PROVIDED UNIT BUFFER. MUST NOT BE TOUCHED BY USER.
C.
C. IERR     ERROR FLAG. SEE SEPARATE LIST.
#include "epio/epiocom.inc"
      DIMENSION IH(2),IBUF(2)
C--- CHECK WHETHER SAME USER UNIT AS LAST TIME
      IF(LASTUT.EQ.LUNIT)  GOTO 1551
C--- NEW UNIT - GET REF
      CALL EPUNIT(LUNIT,IERR)
      IF(IERR.EQ.0)  GOTO 1552
      GOTO 77777
 1551 IERR=0
      IF(LREF.NE.0)  GOTO 1552
      IERR=13
      CALL EPERRH(LUNIT,IERR)
      GOTO 77777
 1552 CONTINUE
C--- ERROR IF NO OUTPUT UNIT
      IF(LIST(ISTART+16).EQ.2)  GOTO 9901
C--- CREATE HEADER IF NOT YET DONE
      IF(LIST(ISTART+14).EQ.0)  CALL EPHEAD(IBUF)
C--- CLOSE
      CALL EPBOUT(IBUF,IERR)
      IF(IERR.NE.0)  GOTO 77777
      K=MAX0(0,NH)
C--- SET NEW HEADER LENGTH
      IF(LIST(ISTART+29).EQ.0)  THEN
         I=1
      ELSE
         I=2
      ENDIF
      LIST(ISTART+7)=I*(LIST(6)+K)
      LIST(ISTART+14)=LIST(ISTART+7)
      IF(LIST(ISTART+29).EQ.0)  THEN
         CALL BUN16W(IH,1,IBUF,LIST(6)+1,K)
      ELSE
         CALL BUN32W(IH,1,IBUF,LIST(6)+1,K)
      ENDIF
77777 RETURN
 9901 CONTINUE
C--- UNIT IS AN INPUT UNIT
      IERR=17
      CALL EPERRH(LUNIT,IERR)
      GOTO 77777
      END
