      SUBROUTINE FORMHR(FORMO,NVAR,FORMH,IFORM)
C      
C     SUBROUTINE TO MAKE AN APPROPRIATE HEADER FORMAT FROM A SPECIFIED 
C     OUTPUT FORMAT
C          IFORM=0; MAKE A FORMAT TO READ A DEPTH OR FLAGS RECORD
C          IFORM=1; MAKE A DEPTH HEADER FORMAT
C          IFORM=2; MAKE A FLAGS HEADER FORMAT
C
      CHARACTER FORMO*(*),FORMH*(*),WORK*(60),FIELDS(50)*10
C
C     CONVERT ANY LOWER CASE LETTERS TO UPPER CASE
C
      CALL CAPLYZE(FORMO)
C
      I1=INDEX(FORMO,'(')
      IF(I1.GT.0)THEN
C
C          CHECK FOR IMBEDDED PARENTHESES
C
           ICHK = INDEX(FORMO(I1+1:),'(')
           IF(ICHK.EQ.0)THEN
C
                I2=INDEX(FORMO,')')
                IF(I2.GT.0)THEN
                     WORK=FORMO(I1+1:I2-1)                 
                     CALL GETFIELDS(WORK,FIELDS,I2-2,NFIELD)
                     CALL BRKFIELD(FIELDS,NFIELD)
                ELSE
                     NFIELD=0
                ENDIF
           ELSE
                NFIELD=0
           ENDIF
      ELSE
           NFIELD=0
      ENDIF
C
      IF(NFIELD.LE.0)THEN
           FORMH='*'
      ELSE
           IF(IFORM.EQ.0)THEN
                CALL RDFORM(FIELDS,NFIELD,FORMH)
           ELSE IF(IFORM.EQ.1)THEN
                CALL MKFORM_DEPTH(FIELDS,NFIELD,NVAR,FORMH)
           ELSE IF (IFORM.EQ.2)THEN
                CALL MKFORM_FLAGS(FIELDS,NFIELD,FORMH)
           ENDIF
      ENDIF
C
      IF(FORMH.EQ.'*')WRITE(FORMH,100)NVAR
  100 FORMAT('(',I2,'F7.1)')
      RETURN 
      END
