FUNCTION gt_fkw_string, header, keyword, nomissing=nomissing
  fkw = fxpar(header,keyword)
  
  IF !err LT 0 AND NOT keyword_set(nomissing) THEN fkw = "MISSING"    
  
  return, fkw
END



FUNCTION gt_fkw_struct, header, keyword, nomissing=nomissing
  ind = where(tag_names(header) EQ strupcase(keyword))
  IF ind[0] NE -1 THEN fkw = header.(ind) ELSE $
     fkw = (keyword_set(nomissing)) ? 0:'MISSING'
  
  return, fkw
END



FUNCTION gt_fkw, header, keyword, nomissing=nomissing

;
;+
; 
; PURPOSE: finds and returns the value of the FITS keyword keyword
; (given as input) in the FITS header. Header may be strarr or struct.
; If the fits keyword does not exist, the string 'MISSING' is
; returned, or if keyword nomissing is set, 0 is returned.
;
; -

  IF n_params() NE 2 THEN $
     message, 'Use: result = gt_fkw(header, keyword)'
  
  headertype = size(header,/tname)
  
  CASE headertype OF 
     'STRING': fkw = gt_fkw_string(header, keyword, nomissing=nomissing)
     'STRUCT': fkw = gt_fkw_struct(header, keyword, nomissing=nomissing)
     else: message, 'Input header must be strarr or struct'
  ENDCASE
   
  return, fkw
  
END
