ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/flatfield/pzt_flat_IDL/mrd_hread.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 pro mrd_hread, unit, header, status, SILENT = silent, FIRSTBLOCK = firstblock
2 ;+
3 ; NAME:
4 ; MRD_HREAD
5 ;
6 ; PURPOSE:
7 ; Reads a FITS header from an opened disk file or Unix pipe
8 ; EXPLANATION:
9 ; Like FXHREAD but also works with compressed Unix files
10 ;
11 ; CALLING SEQUENCE:
12 ; MRD_HREAD, UNIT, HEADER [, STATUS, /SILENT ]
13 ; INPUTS:
14 ; UNIT = Logical unit number of an open FITS file
15 ; OUTPUTS:
16 ; HEADER = String array containing the FITS header.
17 ; OPT. OUTPUTS:
18 ; STATUS = Condition code giving the status of the read. Normally, this
19 ; is zero, but is set to -1 if an error occurs, or if the
20 ; first byte of the header is zero (ASCII null).
21 ; OPTIONAL KEYWORD INPUT:
22 ; /SILENT - If set, then warning messages about any invalid characters in
23 ; the header are suppressed.
24 ; /FIRSTBLOCK - If set, then only the first block (36 lines or less) of
25 ; the FITS header are read into the output variable. If only
26 ; size information (e.g. BITPIX, NAXIS) is needed from the
27 ; header, then the use of this keyword can save time. The
28 ; file pointer is still positioned at the end of the header,
29 ; even if the /FIRSTBLOCK keyword is supplied.
30 ; RESTRICTIONS:
31 ; The file must already be positioned at the start of the header. It
32 ; must be a proper FITS file.
33 ; SIDE EFFECTS:
34 ; The file ends by being positioned at the end of the FITS header, unless
35 ; an error occurs.
36 ; REVISION HISTORY:
37 ; Written, Thomas McGlynn August 1995
38 ; Modified, Thomas McGlynn January 1996
39 ; Changed MRD_HREAD to handle Headers which have null characters
40 ; A warning message is printed out but the program continues.
41 ; Previously MRD_HREAD would fail if the null characters were
42 ; not in the last 2880 byte block of the header. Note that
43 ; such characters are illegal in the header but frequently
44 ; are produced by poor FITS writers.
45 ; Converted to IDL V5.0 W. Landsman September 1997
46 ; Added /SILENT keyword W. Landsman December 2000
47 ; Added /FIRSTBLOCK keyword W. Landsman February 2003
48 ;-
49 block = string(replicate(32b, 80, 36))
50
51 w = [-1]
52 nblock = 0
53
54 while w[0] eq -1 do begin
55
56 ; Shouldn't get eof in middle of header.
57 if eof(unit) then begin
58 free_lun, unit
59 status = -1
60 return
61 endif
62
63 on_ioerror, error_return
64 readu, unit, block
65 on_ioerror, null
66
67 ; Check that there aren't improper null characters
68 ; in strings that are causing them to be truncated.
69 ; Issue a warning but continue if problems are found.
70 w = where(strlen(block) ne 80)
71 if (w[0] ne -1) then begin
72 if not keyword_set(SILENT) then message, /INF, $
73 'Warning-Invalid characters in header'
74 block[w] = string(replicate(32b, 80))
75 endif
76 w = where(strmid(block, 0, 8) eq 'END ')
77 if nblock EQ 0 then begin
78 if w[0] eq -1 then header = block $
79 else header = [block[0:w[0]]]
80 nblock = nblock + 1
81 endif else begin
82 if not keyword_set(firstblock) then begin
83 if w[0] eq -1 then header = [header, block] $
84 else header = [header, block[0:w[0]]]
85 endif
86 endelse
87
88 endwhile
89
90 status = 0
91 return
92 error_return:
93 status = -1
94 return
95 end
96