function FITSKEYUPD, Header, Keyword, Value, Comment, $ DEFAULT=DEFAULT, IFNEW=IFNEW ;+ ; NAME: ; FITSKEYUPD ; ; PURPOSE: ; This function updates FITS Header keywords with an intelligent ; defaulting mechanism that makes it useful in data analysis ; pipelines. ; ; CATEGORY: ; Astronomical data analysis ; ; CALLING SEQUENCE: ; ; Header = FITSKEYUPD(Header, Keyword, Value, Comment) ; ; INPUTS: ; Header: The FITS header to be updated. ; ; Keyword: FITS keyword to create/update in Header. ; ; Value: Value to set in Header. ; ; OPTIONAL INPUTS: ; Comment: Comment to use. Otherwise use original ; comment. ; ; KEYWORD PARAMETERS: ; DEFAULT: If Value is undefined, use this value ; instead. This is useful if the function call ; used a variable for Value that was undefined. ; ; IFNEW: If set, the Header is only updated if the ; Keyword does not already exist in the Header. ; ; OUTPUTS: ; This function returns the modified header. ; ; PROCEDURE: ; Create/modify the Keyword unless the Header has it already and ; IFNEW is set. The pre-existing header comment is used unless a ; comment was supplied in the function call. The specified ; Value is used, unless it is undefined. If Value is undefined ; and the Keyword does not already exist in the Header, the ; quantity given by DEFAULT is used. If Value and DEFAULT are both ; undefined, the function does not modify the Header. ; ; This function is intended for use by analysis pipeline functions ; that set a number of new keywords to default values, but that ; accept override arguments. In this case, the default values ; are given to the DEFAULT keyword, and the override arguments ; are passed to the Value argument. ; ; EXAMPLE: ; The following might appear in a function with an optional ; argument of override: ; ; val = 0.3 ; com = 'Exposure' ; H = fitskeyupd(H, 'ITIME', val, com, /ifnew) ; set if it isn't set ; H = fitskeyupd(H, 'ITIME', val, com) ; set no matter what ; H = fitskeyupd(H, 'ITIME', override, com, default=val) ; ; if override defined, set no matter what ; ; if key doesn't exist, set default ; ; MODIFICATION HISTORY: ; Written by: Joseph Harrington, Cornell. 2002 Feb 13 ; jh@oobleck.astro.cornell.edu ;- ; check for the entry, get the comment dummy = sxpar(header, keyword, count=count, comment=origcomment) ; do nothing if it exists and we're not forcing if count eq 1 and keyword_set(ifnew) then begin return, header endif if not keyword_defined(value) then begin if keyword_defined(default) then begin useval = default endif else begin return, header endelse endif else begin useval = value endelse if keyword_defined(comment) then begin usecomment = comment endif else begin usecomment = origcomment ; ok if it's undefined endelse sxaddpar, header, keyword, useval, usecomment return, header end