	CHARACTER*(*) FUNCTION CHFITSMHV(LU,MAP_NUMBER,KEYWORD,DEFAULT)
C
C       This function returns a character value from or associatied with a 
C  FITS header keyword.  The character value will have its surrounding single
C  quotes striped away.
C			Donald H. Gudehus, June 16, 2005
C
C	LU		(C)	The logical unit that the file was opened on
C	MAP_NUMBER	(C)	The map number within the file.  If more than
C				one map exists, then there will also be a
C				primary header which can be referenced with
C				MAP_NUMBER=0.
C	KEYWORD		(C)	The FITS keyword
C	DEFAULT         (C/R)   The value to be returned if keyword not found
C
	CHARACTER*(*) KEYWORD,DEFAULT
C
	BYTE PHYSREC(3000)
	CHARACTER*80 KEYCARD
	CHARACTER*3000 CHARPHYSREC
	EQUIVALENCE (PHYSREC,CHARPHYSREC)
C
	INCLUDE 'fitsfacts.for'
C
	IF (LU.LT.LUMIN.OR.LU.GT.LUMAX) THEN
	  CALL ERROR(-4,'LU out of range in CHFITSMHV')
	END IF
	IF (MAP_NUMBER.LT.0.OR.MAP_NUMBER.GT.NUMMAPS(LU))
	1CALL ERROR(-4,'MAP_NUMBER out of range in CHFITSMHV')
	IBLKLEN=2880
	IFOUND=0
C
C  If the keyword has a value which should already be in one of the FITSFACTS
C  COMMON blocks, just retrieve the information from there.
	IF (KEYWORD.EQ.'BITPIX') THEN
	  IFOUND=1
	  IF (BITPIX(MAP_NUMBER,LU).EQ.8) THEN
	    CHFITSMHV='I1'
	  ELSE IF (BITPIX(MAP_NUMBER,LU).EQ.16) THEN
	    CHFITSMHV='I2'
	  ELSE IF (BITPIX(MAP_NUMBER,LU).EQ.32) THEN
	    CHFITSMHV='I4'
	  ELSE IF (BITPIX(MAP_NUMBER,LU).EQ.-32) THEN
	    CHFITSMHV='R4'
	    IF (COMPLX(MAP_NUMBER,LU)) CHFITSMHV='C8'
	  ELSE IF (BITPIX(MAP_NUMBER,LU).EQ.-64) THEN
	    CHFITSMHV='R8'
	    IF (COMPLX(MAP_NUMBER,LU)) CHFITSMHV='C16'
	  ELSE
	    IFOUND=0
	  END IF
	ELSE
C  Search through the keywords in the header
	  KEYCARD=' '
	  CHFITSMHV=' '
	  N=LEN(KEYWORD)
	  IR=HEADERRECORDS(1,MAP_NUMBER,LU)
	  DO WHILE(KEYCARD(1:3).NE.'END')
	    IBPTR=1
	    READ(LU,REC=IR,IOSTAT=ISTAT) (PHYSREC(I),I=1,IBLKLEN)
	    IF (ISTAT.NE.0) THEN
	      CALL ERROR(-3,'Error in reading physical record')
	    END IF
	    DO WHILE(KEYCARD(1:3).NE.'END'.AND.IBPTR.LE.2801)
	      KEYCARD=CHARPHYSREC(IBPTR:IBPTR+79)
C  Eliminate control characters
	      DO I=1,80
	        IF (ICHAR(KEYCARD(I:I)).LT.32) KEYCARD(I:I)=' '
	      END DO
	      IF (KEYCARD(1:N).EQ.KEYWORD(1:N)) THEN
	        IND=INDEX(KEYCARD,'''')
	        CHFITSMHV=KEYCARD(IND+1:)
	        IND=INDEX(CHFITSMHV,'''')
	        CHFITSMHV=CHFITSMHV(1:IND-1)
C  Strip trailing blanks
	        I=IND-1
	        DO WHILE(CHFITSMHV(I:I).EQ.' ')
	          I=I-1
	        END DO
	        CHFITSMHV=CHFITSMHV(1:I)
	        IF (IND.EQ.0) THEN
	          IFOUND=0
	        ELSE
	          IFOUND=1
	        END IF
	      END IF
	      IBPTR=IBPTR+80
	    END DO
	    IR=IR+1
	  END DO
	END IF
C
	IF (IFOUND.NE.1) CHFITSMHV=DEFAULT
C
	RETURN
	END
