ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/flatfield/pzt_flat_IDL/sxaddhist.pro
Revision: 1.1
Committed: Tue Feb 22 04:26:53 2011 UTC (12 years, 7 months ago) by richard
Branch: MAIN
CVS Tags: Ver_6-0, Ver_6-1, Ver_6-2, Ver_6-3, Ver_6-4, Ver_9-1, Ver_5-14, Ver_5-13, Ver_LATEST, Ver_9-3, Ver_9-41, Ver_9-2, Ver_8-8, Ver_8-2, Ver_8-3, Ver_8-0, Ver_8-1, Ver_8-6, Ver_8-7, Ver_8-4, Ver_8-5, Ver_7-1, Ver_7-0, Ver_9-5, Ver_9-4, Ver_8-10, Ver_8-11, Ver_8-12, Ver_9-0, HEAD
Log Message:
2011.02.21
fixed issues with fits library.

File Contents

# Content
1 pro sxaddhist,history,header,blank = blank,comment= comment, location=key, $
2 pdu=pdu
3 ;+
4 ; NAME:
5 ; SXADDHIST
6 ; PURPOSE:
7 ; Procedure to add HISTORY (or COMMENT) line(s) to a FITS header
8 ;
9 ; EXPLANATION:
10 ; The advantage of using SXADDHIST instead of SXADDPAR is that with
11 ; SXADDHIST many HISTORY or COMMENT records can be added in a single call.
12 ;
13 ; CALLING SEQUENCE
14 ; sxaddhist, history, header, [ /PDU, /COMMENT ]
15 ;
16 ; INPUTS:
17 ; history - string or string array containing history or comment line(s)
18 ; to add to the FITS header
19 ; INPUT/OUTPUT
20 ; header - FITS header (string array). Upon output, it will contain the
21 ; specified HISTORY records added to the end
22 ;
23 ; OPTIONAL KEYWORD INPUTS:
24 ; /BLANK - If specified then blank (' ') keywords will be written
25 ; rather than 'HISTORY ' keywords.
26 ; /COMMENT - If specified, then 'COMMENT ' keyword will be written rather
27 ; than 'HISTORY ' keywords.
28 ; Note that according to the FITS definition, any number of
29 ; 'COMMENT' and 'HISTORY' or blank keywords may appear in a header,
30 ; whereas all other keywords may appear only once.
31 ; LOCATION=key - If present, the history will be added before this
32 ; keyword. Otherwise put it at the end.
33 ; /PDU - if specified, the history will be added to the primary
34 ; data unit header, (before the line beginning BEGIN EXTENSION...)
35 ; Otherwise, it will be added to the end of the header.
36 ; This has meaning only for extension headers using the STScI
37 ; inheritance convention.
38 ; OUTPUTS:
39 ; header - updated FITS header
40 ;
41 ; EXAMPLES:
42 ; sxaddhist, 'I DID THIS', header ;Add one history record
43 ;
44 ; hist = strarr(3)
45 ; hist[0] = 'history line number 1'
46 ; hist[1[ = 'the next history line'
47 ; hist[2] = 'the last history line'
48 ; sxaddhist, hist, header ;Add three history records
49 ;
50 ; SIDE EFFECTS:
51 ; Header array is truncated to the final END statement
52 ; LOCATION overrides PDU.
53 ; HISTORY:
54 ; D. Lindler Feb. 87
55 ; April 90 Converted to new idl D. Lindler
56 ; Put only a single space after HISTORY W. Landsman November 1992
57 ; Aug. 95 Added PDU keyword parameters
58 ; Converted to IDL V5.0 W. Landsman September 1997
59 ; LOCATION added. M. Greason, 28 September 2004.
60 ;-
61 ;--------------------------------------------------------------------
62 On_error,2
63
64 if N_params() LT 2 then begin
65 print, ' Syntax - SXADDHIST, hist, header, '
66 print, ' /PDU, /BLANK, /COMMENT, LOCATION= ] '
67 return
68 endif
69
70 ; Check input parameters
71
72 if (n_elements(key) LE 0) then keynam = '' $
73 else keynam = strupcase(strtrim(key, 2))
74
75 s = size(history) & ndim = s[0] & type = s[ndim+1]
76 if type NE 7 then message, $
77 'Invalid history lines specified; must be a string or string array'
78
79 if keyword_set(COMMENT) then keyword = 'COMMENT ' else $
80 if keyword_set(BLANK) then keyword = ' ' else $
81 keyword = 'HISTORY '
82 nadd = N_elements(history) ;Number of lines to add
83
84 s = size(header) & ndim2 = s[0] & type = s[ndim2+1]
85 if (ndim2 NE 1) or (type NE 7) then message, $
86 'Invalid FITS header supplied; header must be a string array'
87
88 nlines = N_elements(header) ;Number of lines in header
89
90 ; Find END statement of FITS header
91
92 endline = where( strtrim(strmid(header,0,8),2) EQ 'END' )
93 n = endline[0]
94 if n LT 0 then message, $
95 'Invalid FITS header array, END keyword not found'
96
97 blank = string( replicate(32b,80) )
98 n1 = n ;position to insert
99 ;
100 ; if LOCATION was specified and found, make room before it.
101 ;
102 locfnd = 0
103 if (strlen(keynam) gt 0) then begin
104 extline = where( strupcase(strtrim(strmid(header,0,8),2)) EQ keynam )
105 n_ext = extline[0]
106 if (n_ext gt 1) then begin
107 n1 = n_ext
108 locfnd = 1
109 endif
110 endif
111 ;
112 ; if /PDU find beginning of the extension header and make room for the
113 ; history
114 ;
115 if (keyword_set(PDU) and (locfnd EQ 0)) then begin
116 extline = where( strupcase(strtrim(strmid(header,0,8),2)) EQ 'BEGIN EX' )
117 n_ext = extline[0]
118 if n_ext gt 1 then n1 = n_ext
119 end
120 ;
121 ; make room in the header
122 ;
123 if n1 eq 0 then header = [replicate(blank,nadd),header[n1:n]] else $
124 header = [header[0:n1-1],replicate(blank,nadd),header[n1:n]]
125
126 ; Add history records to header starting at position N1
127
128 for i = 0, nadd-1 do begin
129
130 newline = blank
131 strput, newline, keyword + history[i]
132 header[n1+i] = newline
133
134 endfor
135 return
136 end