1 |
;+ |
2 |
; NAME: |
3 |
; FITSIO_READ_IMAGE |
4 |
; |
5 |
; PURPOSE: |
6 |
; Read FITS image and header using external FITSIO library routines |
7 |
; |
8 |
; CALLING SEQUENCE: |
9 |
; img = FITSIO_READ_IMAGE( filename [, hd] [, /double | /single] $ |
10 |
; [, /chksum] ) |
11 |
; |
12 |
; INPUTS: |
13 |
; filename: string containing name of FITS file to read. By default |
14 |
; the FIRST image in the FITS file will be read. To read |
15 |
; an image after the first one, one must give the filename |
16 |
; in the FITSIO notation, e.g., 'foo.fits[2]' for the second |
17 |
; extension, or the third HDU, of foo.fits. |
18 |
; /single: force output image to be of type single-precision float |
19 |
; /double: force output image to be of type double-precision float |
20 |
; /chksum: verify FITS checksum |
21 |
; |
22 |
; OUTPUTS: |
23 |
; img: image data array |
24 |
; hd: array of strings containing FITS header "cards" which |
25 |
; can be parsed with SXPAR and similar procedures (optional) |
26 |
; |
27 |
; MODIFICATION HISTORY: |
28 |
; 2008.09.08 Keh-Cheng Chu |
29 |
; Initial release |
30 |
; 2010.05.15 Keh-Cheng Chu |
31 |
; Make second parameter optional |
32 |
; Added checksum verification in external routine |
33 |
; 2010.06.01 Keh-Cheng Chu |
34 |
; Added /single and /double keywords |
35 |
; 2010.06.11 Keh-Cheng Chu |
36 |
; Make checksum verification selectable by keyword |
37 |
; 2010.12.17 Keh-Cheng Chu |
38 |
; Instead of calling fits_get_img_equivtype() to determine |
39 |
; output data type, always choose float (double) type for |
40 |
; BITPIX = 8 or 16 (32 or 64) when there is non-default |
41 |
; BSCALE and BZERO. |
42 |
; |
43 |
;- |
44 |
|
45 |
function FITSIO_READ_IMAGE, filename, hd, single=single, double=double, $ |
46 |
chksum=chksum |
47 |
|
48 |
compile_opt IDL2, logical_predicate, strictarrsubs |
49 |
on_error, 2 |
50 |
|
51 |
if (n_params() gt 2 or n_params() lt 1) then message, $ |
52 |
'Usage: img = FITSIO_READ_IMAGE( filename [, hd] [, /single | /double] )' |
53 |
|
54 |
forcesingle = keyword_set(single) |
55 |
forcedouble = keyword_set(double) |
56 |
if (forcesingle and forcedouble) then message, $ |
57 |
'Error: both /single and /double specified!' |
58 |
|
59 |
;LIB = '/home/kehcheng/idl/fitsio/fitsio.so' |
60 |
LIB = '/home/jsoc/idl/fitsio.so' |
61 |
|
62 |
extnum = 999l |
63 |
dtype = 999l |
64 |
naxis = 999l |
65 |
naxes = lon64arr(8) |
66 |
do_chksum = keyword_set(chksum) |
67 |
errmsg = call_external(LIB,'get_info',filename,extnum,dtype,naxis,naxes, $ |
68 |
do_chksum, /s_value, value=[1,0,0,0,0,0]) |
69 |
if (strlen(errmsg) gt 0) then begin |
70 |
print,errmsg |
71 |
return, -1 |
72 |
endif |
73 |
|
74 |
if (n_params() eq 2) then begin |
75 |
s = strpos(filename, '[') |
76 |
if (s eq -1) then begin |
77 |
hd = headfits(filename, exten=extnum) |
78 |
endif else begin |
79 |
fn = strmid(filename, 0, s) |
80 |
hd = headfits(fn, exten=extnum) |
81 |
endelse |
82 |
endif |
83 |
|
84 |
naxes = naxes[0:naxis-1] |
85 |
if (forcesingle) then dtype = 4 |
86 |
if (forcedouble) then dtype = 5 |
87 |
img = make_array(dimension=naxes, type=dtype) |
88 |
errmsg = call_external(LIB,'get_data',filename,dtype,img, /s_value, value=[1,0,0]) |
89 |
if (strlen(errmsg) gt 0) then begin |
90 |
print,errmsg |
91 |
return, -1 |
92 |
endif |
93 |
|
94 |
return, img |
95 |
end |