ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/flatfield/pzt_flat_IDL/fxposit.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 FXPOSIT, XFILE, EXT_NO, readonly=readonly, COMPRESS=COMPRESS, $
2 SILENT = Silent, EXTNUM = extnum, ERRMSG= ERRMSG, LUNIT = lunit
3 ;+
4 ; NAME:
5 ; FXPOSIT
6 ; PURPOSE:
7 ; Return the unit number of a FITS file positioned at specified extension
8 ; EXPLANATION:
9 ; The FITS file will be ready to be read at the beginning of the
10 ; specified extension. Exither an extension number or extension name
11 ; can be specified. Called by headfits.pro, mrdfits.pro, readfits.pro
12 ;
13 ; CALLING SEQUENCE:
14 ; unit=FXPOSIT(FILE, EXT_NO_OR_NAME, /READONLY, COMPRESS=program,
15 ; ERRMSG= , EXTNUM= , UNIT=, /SILENT)
16 ;
17 ; INPUT PARAMETERS:
18 ; FILE = FITS file name, scalar string
19 ; EXT_NO_OR_NAME = Either the extension to be moved to (scalar
20 ; nonnegative integer) or the name of the extension to read
21 ; (scalar string)
22 ;
23 ; RETURNS:
24 ; Unit number of file or -1 if an error is detected.
25 ;
26 ; OPTIONAL INPUT KEYWORD PARAMETER:
27 ; /READONLY - If this keyword is set and non-zero, then OPENR rather
28 ; than OPENU will be used to open the FITS file.
29 ; COMPRESS - If this keyword is set and non-zero, then then treat
30 ; the file as compressed. If 1 assume a gzipped file.
31 ; and use IDLs internal decompression facility. For Unix
32 ; compressed or bzip2 compressed files spawn off a process to
33 ; decompress and use its output as the FITS stream. If the
34 ; keyword is not 1, then use its value as a string giving the
35 ; command needed for decompression.
36 ; LUNIT - Integer giving the file unit number. Use this keyword if
37 ; you want to override the default use of GET_LUN to obtain
38 ; a unit number.
39 ; /SILENT If set, then suppress any messages about invalid characters
40 ; in the FITS file.
41 ;
42 ; OPTIONAL OUTPUT KEYWORDS:
43 ; EXTNUM - Nonnegative integer give the extension number actually read
44 ; Useful only if the extension was specified by name.
45 ; ERRMSG = If this keyword is present, then any error messages will be
46 ; returned to the user in this parameter rather than
47 ; depending on the MESSAGE routine in IDL. If no errors are
48 ; encountered, then a null string is returned.
49 ; SIDE EFFECTS:
50 ; Opens and returns a file unit.
51 ; PROCEDURE:
52 ; Open the appropriate file, or spawn a command and intercept
53 ; the output.
54 ; Call FXMOVE to get to the appropriate extension.
55 ; PROCEDURE CALLS:
56 ; FXMOVE()
57 ; MODIFICATION HISTORY:
58 ; Derived from William Thompson's FXFINDEND routine.
59 ; Modified by T.McGlynn, 5-October-1994.
60 ; Modified by T.McGlynn, 25-Feb-1995 to handle compressed
61 ; files. Pipes cannot be accessed using FXHREAD so
62 ; MRD_HREAD was written.
63 ; W. Landsman 23-Apr-1997 Force the /bin/sh shell when uncompressing
64 ; T. McGlynn 03-June-1999 Use /noshell option to get rid of processes left by spawn.
65 ; Use findfile to retain ability to use wildcards
66 ; W. Landsman 03-Aug-1999 Use EXPAND_TILDE under Unix to find file
67 ; T. McGlynn 04-Apr-2000 Put reading code into FXMOVE,
68 ; additional support for compression from D.Palmer.
69 ; W. Landsman/D.Zarro 04-Jul-2000 Added test for !VERSION.OS EQ 'Win32' (WinNT)
70 ; W. Landsman 12-Dec-2000 Added /SILENT keyword
71 ; W. Landsman April 2002 Use FILE_SEARCH for V5.5 or later
72 ; W. Landsman Feb 2004 Assume since V5.3 (OPENR,/COMPRESS available)
73 ; W. Landsman,W. Thompson, 2-Mar-2004, Add support for BZIP2
74 ; W. Landsman Don't leave open file if an error occurs
75 ; W. Landsman Sep 2004 Treat FTZ extension as gzip compressed
76 ; W. Landsman Feb 2006 Removed leading spaces (prior to V5.5)
77 ; W. Landsman Nov 2006 Allow specification of extension name
78 ; Added EXTNUM, ERRMSG keywords
79 ; W. Landsman/N.Piskunov Dec 2007 Added LUNIT keyword
80 ;-
81 ;
82 ON_ERROR,2
83 compile_opt idl2
84 ;
85 ; Check the number of parameters.
86 ;
87 IF N_PARAMS() LT 2 THEN BEGIN
88 PRINT,'SYNTAX: UNIT = FXPOSIT(FILE, EXT_NO, /Readonly,' + $
89 'ERRMSG= , /SILENT, compress=prog, LUNIT = lunit)'
90 RETURN,-1
91 ENDIF
92 PRINTERR = NOT ARG_PRESENT(ERRMSG)
93 ERRMSG = ''
94
95 FILE = FILE_SEARCH(XFILE, COUNT=COUNT)
96
97 IF COUNT EQ 0 THEN BEGIN
98 ERRMSG = 'Specified FITS File not found '
99 IF PRINTERR THEN MESSAGE,ERRMSG,/CON
100 RETURN, -1 ; Don't print anything out, just report an error
101 ENDIF
102
103 FILE = FILE[0]
104 ;
105 ; Check if logical unit number is specified explicitly.
106 ;
107 IF KEYWORD_SET(LUNIT) THEN BEGIN
108 UNIT=LUNIT
109 GLUN = 0
110 ENDIF ELSE BEGIN
111 UNIT = -1
112 GLUN = 1
113 ENDELSE
114 ;
115 ; Check if this is a compressed file.
116 ;
117 UCMPRS = ' '
118 IF KEYWORD_SET(compress) THEN BEGIN
119 IF strcompress(string(compress),/remo) eq '1' THEN BEGIN
120 compress = 'gunzip'
121 ENDIF
122 UCMPRS = compress;
123 ENDIF ELSE BEGIN
124
125 LEN = STRLEN(FILE)
126 IF LEN GT 3 THEN $
127 TAIL = STRLOWCASE(STRMID(FILE, LEN-3, 3)) $
128 ELSE TAIL = ' '
129
130 IF STRMID(TAIL,1,2) EQ '.z' THEN $
131 UCMPRS = 'uncompress' $
132 ELSE IF TAIL EQ '.gz' or tail EQ 'ftz' THEN $
133 UCMPRS = 'gunzip' $
134 ELSE IF TAIL EQ 'bz2' THEN $
135 UCMPRS = 'bunzip2'
136
137 ENDELSE
138
139 ; Handle compressed files.
140
141 IF UCMPRS EQ 'gunzip' THEN BEGIN
142
143 IF KEYWORD_SET(READONLY) THEN BEGIN
144 OPENR, UNIT, FILE, /COMPRESS, GET_LUN=glun, ERROR = ERROR
145 ENDIF ELSE BEGIN
146 OPENU, UNIT, FILE, /COMPRESS, GET_LUN=glun, ERROR = ERROR
147 ENDELSE
148
149 ENDIF ELSE IF UCMPRS NE ' ' THEN BEGIN
150
151 IF (!VERSION.OS_FAMILY EQ 'unix') THEN BEGIN
152 SPAWN, [UCMPRS,'-c',FILE], UNIT=UNIT, /NOSHELL
153 ENDIF ELSE BEGIN
154 PRINT, 'MRDFITS: Only Unix IDL supports piped spawns'
155 PRINT, ' File must be uncompressed manually'
156 RETURN, -1
157 ENDELSE
158
159 ENDIF ELSE BEGIN
160 ;
161 ; Go to the start of the file.
162 ;
163 IF KEYWORD_SET(READONLY) THEN BEGIN
164 OPENR, UNIT, FILE, GET_LUN=glun, ERROR = ERROR
165 ENDIF ELSE BEGIN
166 OPENU, UNIT, FILE, GET_LUN=glun, ERROR = ERROR
167 ENDELSE
168
169 IF ERROR NE 0 THEN BEGIN
170 IF PRINTERR THEN PRINT,!ERROR_STATE.MSG ELSE $
171 ERRMSG = !ERROR_STATE.MSG
172 RETURN,-1
173 ENDIF
174 ENDELSE
175
176 IF SIZE(EXT_NO,/TNAME) NE 'STRING' THEN $
177 IF EXT_NO LE 0 THEN RETURN, UNIT
178
179 STAT = FXMOVE(UNIT, EXT_NO, SILENT = Silent, EXT_NO = extnum, $
180 ERRMSG=ERRMSG)
181 IF STAT LT 0 THEN BEGIN
182 IF(NOT KEYWORD_SET(LUNIT)) THEN FREE_LUN, UNIT
183 RETURN, STAT
184 ENDIF ELSE RETURN, UNIT
185 END
186
187