ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/flatfield/pzt_flat_IDL/fitsio_read_image.pro
Revision: 1.1
Committed: Fri Feb 18 00:21:17 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:
IDL package for calculating pzt flatfields
2011.02.17

File Contents

# Content
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 ;
38 ;-
39
40 function FITSIO_READ_IMAGE, filename, hd, single=single, double=double, $
41 chksum=chksum
42
43 compile_opt IDL2, logical_predicate, strictarrsubs
44 on_error, 2
45
46 if (n_params() gt 2 or n_params() lt 1) then message, $
47 'Usage: img = FITSIO_READ_IMAGE( filename [, hd] [, /single | /double] )'
48
49 forcesingle = keyword_set(single)
50 forcedouble = keyword_set(double)
51 if (forcesingle and forcedouble) then message, $
52 'Error: both /single and /double specified!'
53
54 LIB = '/home/kehcheng/idl/fitsio/fitsio.so'
55
56 extnum = 999l
57 dtype = 999l
58 naxis = 999l
59 naxes = lon64arr(8)
60 do_chksum = keyword_set(chksum)
61 errmsg = call_external(LIB,'get_info',filename,extnum,dtype,naxis,naxes, $
62 do_chksum, /s_value, value=[1,0,0,0,0,0])
63 if (strlen(errmsg) gt 0) then begin
64 print,errmsg
65 return, -1
66 endif
67
68 if (n_params() eq 2) then begin
69 s = strpos(filename, '[')
70 if (s eq -1) then begin
71 hd = headfits(filename, exten=extnum)
72 endif else begin
73 fn = strmid(filename, 0, s)
74 hd = headfits(fn, exten=extnum)
75 endelse
76 endif
77
78
79 ;added to handle zero length fits files RW
80 if (naxes[0] eq 0) then begin
81 print,'no data'
82 return,-1
83 endif
84
85 naxes = naxes[0:naxis-1]
86 if (forcesingle) then dtype = 4
87 if (forcedouble) then dtype = 5
88 img = make_array(dimension=naxes, type=dtype)
89 errmsg = call_external(LIB,'get_data',filename,dtype,img, /s_value, value=[1,0,0])
90 if (strlen(errmsg) gt 0) then begin
91 print,errmsg
92 return, -1
93 endif
94
95 return, img
96 end