ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/flatfield/pzt_flat_IDL/fits_add_checksum.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 fits_add_checksum, hdr, im, no_timestamp = no_timestamp, $
2 FROM_IEEE=from_IEEE
3 ;+
4 ; NAME:
5 ; FITS_ADD_CHECKSUM
6 ; PURPOSE:
7 ; Add or update the CHECKSUM and DATASUM keywords in a FITS header
8 ; EXPLANATION:
9 ; Follows the 23 May 2002 version of the FITS checksum proposal at
10 ; http://heasarc.gsfc.nasa.gov/docs/heasarc/fits/checksum.html
11 ; CALLING SEQUENCE:
12 ; FITS_ADD_CHECKSUM, Hdr, [ Data, /No_TIMESTAMP, /FROM_IEEE ]
13 ; INPUT-OUTPUT:
14 ; Hdr - FITS header (string array), it will be updated with new
15 ; (or modfied) CHECKSUM and DATASUM keywords
16 ; OPTIONAL INPUT:
17 ; Data - data array associated with the FITS header. If not supplied, or
18 ; set to a scalar, then the program checks whether there is a
19 ; DATASUM keyword already in the FITS header containing the 32bit
20 ; checksum for the data. if there is no such keyword then there
21 ; assumed to be no data array associated with the FITS header.
22 ; OPTIONAL INPUT KEYWORDS:
23 ; /FROM_IEEE - If this keyword is set, then the input is assumed to be in
24 ; big endian format (e.g. an untranslated FITS array). This
25 ; keyword only has an effect on little endian machines (e.g.
26 ; a Linux box).
27 ; /No_TIMESTAMP - If set, then a time stamp is not included in the comment
28 ; field of the CHECKSUM and DATASUM keywords. Unless the
29 ; /No_TIMESTAMP keyword is set, repeated calls to FITS_ADD_CHECKSUM
30 ; with the same header and data will yield different values of
31 ; CHECKSUM (as the date stamp always changes). However, use of the
32 ; date stamp is recommended in the checksum proposal.
33 ; PROCEDURES USED:
34 ; CHECKSUM32, FITS_ASCII_ENCODE(), GET_DATE, SXADDPAR, SXPAR()
35 ; REVISION HISTORY:
36 ; W. Landsman SSAI December 2002
37 ; Fix problem with images with a multiple of 2880 bytes. W.L. May 2008
38 ; Avoid conversion error when DATASUM is an empty string W.L. June 2008
39 ; Don't update DATASUM if not already present and no data array supplied
40 ; W.L. July 2008
41 ;-
42 On_error,2
43 compile_opt idl2
44
45 if N_params() EQ 0 then begin
46 print,'Syntax - FITS_ADD_CHECKSUM, Hdr, Data, /No_TIMESTAMP, /FROM_IEEE'
47 return
48 endif
49
50 datasum = sxpar(hdr,'DATASUM', Count = N_DATASUM)
51 Nim = N_elements(im)
52 datasum_update = 1b
53 if Nim GT 1 then begin
54 checksum32,im, dsum,FROM_IEEE = from_IEEE
55 remain = Nim mod 2880
56 if remain GT 0 then begin
57 exten = sxpar( hdr, 'XTENSION', Count = N_exten)
58 if N_exten GT 0 then if exten EQ 'TABLE ' then $
59 checksum32,[dsum,replicate(32b,2880-remain)],dsum
60 endif
61 sdsum = strtrim(dsum,2)
62 dsum_exist= 1b
63 endif else begin
64 if N_datasum EQ 0 then begin ;Don't update DATASUM keyword
65 datasum_update = 0b
66 sdsum = ' 0'
67 endif else begin
68 if strtrim(datasum,2) EQ '' then dsum=0 else dsum = ulong(datasum)
69 sdsum = strtrim(dsum,2)
70 endelse
71 endelse
72
73 if keyword_set(no_timestamp) then tm = '' else Get_date,tm,/timetag
74
75 ; Do the Checksum keywords already exist?
76
77 if N_DATASUM GT 0 then verb = 'updated ' else verb = 'created '
78 if datasum_update then sxaddpar,hdr,'DATASUM', sdsum, $
79 ' data unit checksum ' + verb + tm
80
81 test = sxpar(hdr,'CHECKSUM', Count = N_CHECKSUM)
82 if N_CHECKSUM GT 0 then verb = 'updated ' else verb = 'created '
83 sxaddpar,hdr,'CHECKSUM','0000000000000000', $
84 ' HDU checksum ' + verb + tm ;Initialize CHECKSUM keyword
85 bhdr = byte(hdr)
86 remain = N_elements(bhdr) mod 2880
87 if remain NE 0 then $
88 bhdr = [reform(bhdr,N_elements(bhdr)), replicate(32b, 2880 - remain) ]
89 checksum32,bhdr, hsum, /NoSAVE
90 if N_elements(dsum) GT 0 then checksum32, [dsum,hsum], hdusum $
91 else hdusum = hsum
92
93 ch = FITS_ASCII_ENCODE(not hdusum) ;ASCII encode the complement of the checksum
94 sxaddpar,hdr,'CHECKSUM',ch
95
96 return
97 end