aboutsummaryrefslogtreecommitdiff
path: root/idl/cf_plot_rate3.pro
blob: 6a2669b0b0f9d7044fe75eecbd8e49e4d7f38992 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
;+
;  cf_plot_rate3.pro is a procedure to plot the count rate and screening 
;			as a function of time for calfuse 3.0 data. 
;
;  Author:  Edward M. Murphy
;  Written: 2000 April 21
;
;       Calling sequence: cf_plot_rate3, rootname
;
;       Inputs:    rootname will have 'idf.fit' added to it.
;
; 02/20/03 JC Hsu      Adapt from cf_plot_rate.pro to work on version 3.0 data.
; 06/23/04 V Dixon     Mark low-voltage periods with cross-hatch.
; 03/16/05 V Dixon     Ignore timeline table entries that extend beyond
;			the end of the exposure.
; 08/01/05 V Dixon     If IDL version > 6.0, generate GIF file.
; 11/03/05 V Dixon     Shade OPUS and SAA bad times before drawing rest of plot.
;-

pro cf_plot_rate3,rootname

	!quiet=1

	; Open input IDF file
	filename=rootname+'idf.fit'
	dummy=mrdfits(filename,0,ah,/SILENT)

	; Read primary header keywords
	pdate = fxpar(ah,'DATE')
	dateobs = fxpar(ah,'DATEOBS')
	expstart = fxpar(ah,'EXPSTART')
	expend = fxpar(ah,'EXPEND')
	detector = fxpar(ah,'DETECTOR')

	exposure = (expend - expstart) * 24. * 3600.

	; Define plot attributes.
	!p.multi=[0,1,2]
	set_plot,'Z'
	device,set_resolution=[1024,512]

	!x.style=1
	!y.style=1
	!x.tickformat='(I6)'

	!x.title="Time (seconds)"
	!y.title="Count rate"
	!p.charsize=1.2
	!p.background=255
	!p.color=0

	; Read columns from the timeline extension (ext 3)
	ftab_ext, filename, 'TIME', time0, exten_no=3
	ftab_ext, filename, 'STATUS_FLAGS', flags, exten_no=3
	if (exposure gt 55000) then begin
	    good = where(time0 lt 55000, n)
	    exposure = time0[n-1] - time0[0]
	endif
	good = where(time0 lt exposure)
	time = [0, time0[good], exposure]

	; Compute the day/night screenings (bit 1)
	flags1 = ishft(flags, 7) 
	flags1 = ishft(flags1, -7) ; only keep bit 1

	; Compute the limb angle screening (bit 2)
	flags2 = ishft(flags, 6) ;
	flags2 = ishft(flags2, -7) ; only keep bit 2

	; Compute the SAA screening (bit 3)
	flags3 = ishft(flags, 5) ;
	flags3 = ishft(flags3, -7) ; only keep bit 3

	; Compute the HV screening (bit 4)
	flags4 = ishft(flags, 4) ;
	flags4 = ishft(flags4, -7) ; only keep bit 4

	; Compute burst screening (bit 5)
	flags5 = ishft(flags, 3) ;
	flags5 = ishft(flags5, -7) ; only keep bit 5

	; Compute OPUS screening (bit 6)
	flags6 = ishft(flags, 2) ;
	flags6 = ishft(flags6, -7) ; only keep bit 6

	; Compute jitter screening (bit 7)
	flags7 = ishft(flags, 1) ;
	flags7 = ishft(flags7, -7) ; only keep bit 7

	ftab_ext, filename, 'BKGD_CNT_RATE', bkgd, exten_no=3
	len = size(time0)
	packet = 1 > len[1]/100 ; determine rebinning size
	wht = where(time0 eq time0)
	whbin = where(wht mod packet eq 0)

	for i = 1, 2 do begin

		if (i eq 1) then text = ' LiF' else text = ' SiC'
		!p.title=filename + text

		; Draw grid, shade bad times, then over-plot count rate arrays.
		if (i eq 1) then col = 'LIF' else col = 'SIC'
		ftab_ext, filename, col+'_CNT_RATE', crate, exten_no=3
		ymin = 1
		ymax = max([1000,crate * 2.])
		crate = crate > ymin
		!y.range=[ymin, ymax]
		plot_io, time0, crate, /nodata, xr=[0,exposure]
	
		; Shade OPUS 
		flags16 = flags6 * (ymax-ymin) + ymin
		flags16 = [0, flags16[good], 0]
		polyfill, time, flags16, COL = 0.75 * !D.N_COLORS
		;oplot, time, flags16, psym=10, linestyle=2

		; Shade SAA violations 
		flags13 = flags3 * (ymax/100-ymin) + ymin
		flags13 = [0., flags13[good], 0.]
		polyfill, time, flags13, COL = 0.25 * !D.N_COLORS
		flags13 = flags3 * (ymax-ymin) + ymin
		oplot, time, flags13, psym=10, linestyle=2

		; Shade day/night screenings
		flags11 = flags1 * (0.2*ymax) + ymax
		flags11 = [ymax, flags11[good], ymax]
		oplot, time, flags11, psym=10
		polyfill, time, flags11

		; Shade limb angle 
		flags12 = flags2 * (ymax-ymin) + ymin
		flags12 = [0, flags12[good], 0]
		oplot, time, flags12, psym=10, linestyle=2
		polyfill, time, flags12, /line_fill, orientation=0

		; Shade low-voltage periods.
		flags14 = flags4 * (ymax-ymin) + ymin
		flags14 = [0, flags14[good], 0]
		oplot, time, flags14, psym=10, linestyle=2
		polyfill, time, flags14, /line_fill, orientation=45
		polyfill, time, flags14, /line_fill, orientation=135

		; Shade burst 
		flags15 = flags5 * (ymax-ymin) + ymin
		flags15 = [0, flags15[good], 0]
		oplot, time, flags15, psym=10, linestyle=2
		polyfill, time, flags15, /line_fill, orientation=45

 		; Shade jitter
		flags17 = flags7 * (ymax-ymin) + ymin
		flags17 = [0, flags17[good], 0]
		oplot, time, flags17, psym=10, linestyle=2
		polyfill, time, flags17, /line_fill, orientation=135

		; Overplot count-rate arrays.
		oplot, time0, crate, linestyle=0, psym=10
		oplot, time0(whbin), bkgd(whbin)+0.001, linestyle=1
	endfor

	; Draw legend
	plot,[0,1],xstyle=7,ystyle=7,/nodata,position=[345-20,5,345+21,25],$
		/noerase,title=" ",xtitle=" ",ytitle=" ",xrange=[0,1],$
		yrange=[0,1],/DEVICE
	polyfill,[0,1,1,0],[0,0,1,1], COL = 0.75 * !D.N_COLORS
	oplot,[0,1,1,0,0],[0,0,1,1,0],psym=10
	xyouts,345-17,10,'OPUS',charsize=1,color=0,/DEVICE

	plot,[0,1],xstyle=7,ystyle=7,/nodata,position=[400-20,5,400+21,25],$
		/noerase,title=" ",xtitle=" ",ytitle=" ",xrange=[0,1],$
		yrange=[0,1],/DEVICE
	polyfill,[0,1,1,0],[0,0,0.36,0.36], COL = 0.25 * !D.N_COLORS
	oplot,[0,1,1,0,0],[0,0,1,1,0],psym=10
	xyouts,400-12,13,'SAA',charsize=1,color=0,/DEVICE

	plot,[0,1],xstyle=7,ystyle=7,/nodata,position=[450-15,5,450+15,25],$
		/noerase,title=" ",xtitle=" ",ytitle=" ",xrange=[0,1],$
		yrange=[0,1],/DEVICE
	polyfill,[0,1,1,0],[0.8,0.8,1,1]
	xyouts,450-11,10,'Day',charsize=1,color=0,/DEVICE

	plot,[0,1],xstyle=7,ystyle=7,/nodata,position=[710-15,5,710+15,25],$
		/noerase,title=" ",xtitle=" ",ytitle=" ",xrange=[0,1],$
		yrange=[0,1],/DEVICE
	polyfill,[0,1,1,0],[0,0,1,1],/line_fill,orientation=0
	oplot,[0,1,1,0,0],[0,0,1,1,0],psym=10
	xyouts,710+20,10,'Limb',charsize=1,color=0,/DEVICE

	plot,[0,1],xstyle=7,ystyle=7,/nodata,position=[790-15,5,790+15,25],$
		/noerase,title=" ",xtitle=" ",ytitle=" ",xrange=[0,1],$
		yrange=[0,1],/DEVICE
	polyfill,[0,1,1,0],[0,0,1,1],/line_fill,orientation=45
	oplot,[0,1,1,0,0],[0,0,1,1,0],psym=10
	xyouts,790+20,10,'Burst',charsize=1,color=0,/DEVICE

	plot,[0,1],xstyle=7,ystyle=7,/nodata,position=[870-15,5,870+15,25],$
		/noerase,title=" ",xtitle=" ",ytitle=" ",xrange=[0,1],$
		yrange=[0,1],/DEVICE
	polyfill,[0,1,1,0],[0,0,1,1],/line_fill,orientation=135
	oplot,[0,1,1,0,0],[0,0,1,1,0],psym=10
	xyouts,870+20,10,'Jitter',charsize=1,color=0,/DEVICE

	plot,[0,1],xstyle=7,ystyle=7,/nodata,position=[950-15,5,950+15,25],$
		/noerase,title=" ",xtitle=" ",ytitle=" ",xrange=[0,1],$
		yrange=[0,1],/DEVICE
	polyfill,[0,1,1,0],[0,0,1,1],/line_fill,orientation=45
	polyfill,[0,1,1,0],[0,0,1,1],/line_fill,orientation=135
	oplot,[0,1,1,0,0],[0,0,1,1,0],psym=10
	xyouts,950+20,10,'HV',charsize=1,color=0,/DEVICE

	xyouts,835,27,'Screenings :',charsize=.9,color=0,/DEVICE,alignment=.5
	xyouts,20,16,'RAW file written at '+pdate,charsize=0.90,color=0,$
		/DEVICE
	xyouts,925,495,'DATEOBS: '+dateobs,charsize=.9,color=0,$
		/DEVICE,alignment=.5

	; Create a GIF/JPEG file: 
	ver = float(!version.release)
	if (ver ge 5.4 and ver le 6.0) then begin
		xyouts,20,6,'JPG file written at '+!stime,charsize=0.90,$
			color=0,/DEVICE
		write_jpeg,rootname+'rat.jpg',TVRD()
	endif else begin
		xyouts,20,6,'GIF file written at '+!stime,charsize=0.90,$
			color=0,/DEVICE
		write_gif,rootname+'rat.gif',TVRD()
	endelse
return
end