ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/flatfield/pzt_flat_IDL/fits_ascii_encode.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 function fits_ascii_encode, sum32
2 ;+
3 ; NAME:
4 ; FITS_ASCII_ENCODE()
5 ; PURPOSE:
6 ; Encode an unsigned longword as an ASCII string to insert in a FITS header
7 ; EXPLANATION:
8 ; Follows the 23 May 2002 version of the FITS checksum proposal at
9 ; http://heasarc.gsfc.nasa.gov/docs/heasarc/fits/checksum.html
10 ; CALLING SEQUENCE:
11 ; result = FITS_ASCII_ENCODE( sum32)
12 ; INPUTS:
13 ; sum32 - 32bit *unsigned longword* (e.g. as returned by CHECKSUM32)
14 ; RESULT:
15 ; A 16 character scalar string suitable for the CHECKSUM keyword
16 ; EXAMPLE:
17 ; A FITS header/data unit has a checksum of 868229149. Encode the
18 ; complement of this value (3426738146) into an ASCII string
19 ;
20 ; IDL> print,FITS_ASCII_ENCODE(3426738146U)
21 ; ===> "hcHjjc9ghcEghc9g"
22 ;
23 ; METHOD:
24 ; The 32bit value is interpreted as a sequence of 4 unsigned 8 bit
25 ; integers, and divided by 4. Add an offset of 48b (ASCII '0').
26 ; Remove non-alphanumeric ASCII characters (byte values 58-64 and 91-96)
27 ; by simultaneously incrementing and decrementing the values in pairs.
28 ; Cyclicly shift the string one place to the right.
29 ;
30 ; REVISION HISTORY:
31 ; Written W. Landsman SSAI December 2002
32 ;-
33 if N_Params() LT 1 then begin
34 print,'Syntax - result = FITS_ASCII_ENCODE( sum32)'
35 return,'0'
36 endif
37
38 ; Non-alphanumeric ASCII characters
39 exclude = [58b,59b,60b,61b,62b,63b,64b,91b,92b,93b,94b,95b,96b]
40 ch = bytarr(16)
41 t = byte(sum32,0,4)
42 byteorder,t,/htonl
43 quot = t/4 + 48b
44 for i=0,12,4 do ch[i] = quot
45
46 remain = t mod 4
47 ch[0] = ch[0:3] + remain ;Insert the remainder in the first 4 bytes
48
49 ;Step through the 16 bytes, 8 at a time, removing nonalphanumeric characters
50 repeat begin
51 check = 0b
52 for j=0,1 do begin
53 il = j*8
54 for i=il,il+3 do begin
55 bad = where( (exclude EQ ch[i]) or (exclude Eq ch[i+4]) , Nbad)
56 if Nbad GT 0 then begin
57 ch[i] = ch[i]+1b
58 ch[i+4] = ch[i+4] -1b
59 check=1b
60 endif
61 endfor
62 endfor
63 endrep until (check EQ 0b)
64
65 return, string( shift(ch,1))
66 end
67