1 | #!/usr/bin/wish |
---|
2 | |
---|
3 | package require BLT |
---|
4 | |
---|
5 | set images(normal) [image create photo -format gif -data { |
---|
6 | R0lGODlhEAANAMIAAAAAAH9/f///////AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A |
---|
7 | AAM1WBrM+rAEMigJ8c3Kb3OSII6kGABhp1JnaK1VGwjwKwtvHqNzzd263M3H4n2OH1QBwGw6 |
---|
8 | nQkAOw== |
---|
9 | } ] |
---|
10 | |
---|
11 | set images(active) [image create photo -format gif -data { |
---|
12 | R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A |
---|
13 | AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp |
---|
14 | ZTKAsiCtWq0JADs= |
---|
15 | } ] |
---|
16 | |
---|
17 | proc loadBT5File {fileName x c cr t m} { |
---|
18 | global datasets |
---|
19 | global $x $c $cr $t $m |
---|
20 | |
---|
21 | #puts "In load proc: $x $c $cr $t $m" |
---|
22 | |
---|
23 | set lc 0 |
---|
24 | set mon(0) 0 |
---|
25 | set det1(0) 0 |
---|
26 | set det2(0) 0 |
---|
27 | set det3(0) 0 |
---|
28 | set det4(0) 0 |
---|
29 | set det5(0) 0 |
---|
30 | set xvar(0) 0 |
---|
31 | set trans(0) 0 |
---|
32 | |
---|
33 | if [catch {open $fileName r} fileId] { |
---|
34 | |
---|
35 | puts stderr "Cannot open file for reading: $fileId" |
---|
36 | |
---|
37 | } else { |
---|
38 | for {set lc 0} {$lc < 13} {incr lc} { |
---|
39 | gets $fileId line |
---|
40 | if { $lc == 0 } { |
---|
41 | regexp {^\'.+?\' \'.+?\' \'.+?\'.+?(\d+)\..+} $line match counttime |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | set lc 0 |
---|
46 | while true { |
---|
47 | if {[gets $fileId line] < 0} { |
---|
48 | break |
---|
49 | } else { |
---|
50 | regexp {^ +([^ ]+).*} $line match xvar($lc) |
---|
51 | } |
---|
52 | |
---|
53 | gets $fileId line |
---|
54 | regexp {^ (.+?),(.+?),(.+?),(.+?),(.+?),(.+?),(.+?),.*} $line match mon($lc) \ |
---|
55 | det2($lc) det1($lc) trans($lc) det3($lc) det4($lc) det5($lc) |
---|
56 | incr lc |
---|
57 | } |
---|
58 | |
---|
59 | close $fileId |
---|
60 | } |
---|
61 | |
---|
62 | foreach index [lsort -integer [array names xvar]] { |
---|
63 | $x append {$xvar($index)} |
---|
64 | $c append {$det1($index)+$det2($index)+$det3($index)+$det4($index)+$det5($index)} |
---|
65 | $cr append [expr [$c index $index] / $counttime] |
---|
66 | $t append {$trans($index)} |
---|
67 | $m append {$mon($index)} |
---|
68 | } |
---|
69 | |
---|
70 | } |
---|
71 | |
---|
72 | proc resetGraph { } { |
---|
73 | global graph |
---|
74 | global tv |
---|
75 | global images |
---|
76 | |
---|
77 | foreach elem [ $graph element show] { |
---|
78 | $graph element delete $elem |
---|
79 | |
---|
80 | set xvec [join "$elem _xvec" ""] |
---|
81 | set countratevec [join "$elem _countratevec" ""] |
---|
82 | set countvec [join "$elem _countvec" ""] |
---|
83 | set transvec [join "$elem _transvec" ""] |
---|
84 | set monvec [join "$elem _monvec" ""] |
---|
85 | |
---|
86 | global $xvec $countvec $countratevec $transvec $monvec |
---|
87 | |
---|
88 | blt::vector destroy $xvec |
---|
89 | blt::vector destroy $countratevec |
---|
90 | blt::vector destroy $countvec |
---|
91 | blt::vector destroy $transvec |
---|
92 | blt::vector destroy $monvec |
---|
93 | } |
---|
94 | |
---|
95 | $tv entry configure all -activeicons "$images(normal) $images(normal)" |
---|
96 | $tv entry configure all -icons "$images(normal) $images(normal)" |
---|
97 | } |
---|
98 | |
---|
99 | #foreach fileName $argv { |
---|
100 | proc addremovePlot { nodeID } { |
---|
101 | global graph |
---|
102 | global tv |
---|
103 | global images |
---|
104 | global .tree |
---|
105 | global plotType |
---|
106 | |
---|
107 | set fileName [.tree label $nodeID] |
---|
108 | #puts "$nodeID $fileName" |
---|
109 | set filebase [string trimright $fileName .bt5] |
---|
110 | |
---|
111 | if { ! [$graph element exists $filebase] } { |
---|
112 | |
---|
113 | $tv entry configure $nodeID -activeicons "$images(active) $images(active)" |
---|
114 | $tv entry configure $nodeID -icons "$images(active) $images(active)" |
---|
115 | |
---|
116 | set xvec [join "$filebase _xvec" ""] |
---|
117 | set countratevec [join "$filebase _countratevec" ""] |
---|
118 | set countvec [join "$filebase _countvec" ""] |
---|
119 | set transvec [join "$filebase _transvec" ""] |
---|
120 | set monvec [join "$filebase _monvec" ""] |
---|
121 | |
---|
122 | global $xvec $countvec $countratevec $transvec $monvec |
---|
123 | |
---|
124 | blt::vector create $xvec |
---|
125 | blt::vector create $countratevec |
---|
126 | blt::vector create $countvec |
---|
127 | blt::vector create $transvec |
---|
128 | blt::vector create $monvec |
---|
129 | |
---|
130 | loadBT5File $fileName $xvec $countvec $countratevec $transvec $monvec |
---|
131 | |
---|
132 | $graph element create $filebase -symbol scross \ |
---|
133 | -xdata $xvec \ |
---|
134 | -ydata $countvec |
---|
135 | |
---|
136 | switch -exact $plotType { |
---|
137 | count { $graph element configure $filebase -ydata $countvec} |
---|
138 | countrate { $graph element configure $filebase -ydata $countratevec} |
---|
139 | trans { $graph element configure $filebase -ydata $transvec} |
---|
140 | mon { $graph element configure $filebase -ydata $monvec} |
---|
141 | } |
---|
142 | |
---|
143 | } else { |
---|
144 | $tv entry configure $nodeID -activeicons "$images(normal) $images(normal)" |
---|
145 | $tv entry configure $nodeID -icons "$images(normal) $images(normal)" |
---|
146 | |
---|
147 | $graph element delete $filebase |
---|
148 | |
---|
149 | set xvec [join "$filebase _xvec" ""] |
---|
150 | set countratevec [join "$filebase _countratevec" ""] |
---|
151 | set countvec [join "$filebase _countvec" ""] |
---|
152 | set transvec [join "$filebase _transvec" ""] |
---|
153 | set monvec [join "$filebase _monvec" ""] |
---|
154 | |
---|
155 | global $xvec $countvec $transvec $monvec |
---|
156 | |
---|
157 | blt::vector destroy $xvec |
---|
158 | blt::vector destroy $countratevec |
---|
159 | blt::vector destroy $countvec |
---|
160 | blt::vector destroy $transvec |
---|
161 | blt::vector destroy $monvec |
---|
162 | |
---|
163 | |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | |
---|
168 | proc LoadTree { tree parentNode dir } { |
---|
169 | cd $dir |
---|
170 | foreach f [lsort [glob *.bt5]] { |
---|
171 | set e [$tree insert $parentNode -label $f -data "Plot 0"] |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | proc EmptyTree { tree } { |
---|
176 | $tree delete 0 |
---|
177 | } |
---|
178 | |
---|
179 | proc selectDirectory {} { |
---|
180 | |
---|
181 | global .tree |
---|
182 | |
---|
183 | set dir [tk_chooseDirectory -title "Set Data Directory"] |
---|
184 | |
---|
185 | if {$dir ne ""} { |
---|
186 | EmptyTree .tree |
---|
187 | LoadTree .tree 0 $dir |
---|
188 | cd $dir |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | proc resetTree { } { |
---|
193 | |
---|
194 | global .tree |
---|
195 | |
---|
196 | EmptyTree .tree |
---|
197 | LoadTree .tree 0 [pwd] |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | proc filterTree { filterString } { |
---|
202 | |
---|
203 | global .tree |
---|
204 | |
---|
205 | resetTree |
---|
206 | |
---|
207 | if {$filterString ne ""} { |
---|
208 | set filterlist [.tree find 0 -glob $filterString -invert -depth 1] |
---|
209 | foreach node $filterlist { |
---|
210 | if { $node != 0 } { |
---|
211 | .tree delete $node |
---|
212 | } |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | } |
---|
217 | |
---|
218 | # Create menu |
---|
219 | menubutton .mb -text File -menu .mb.fileMenu |
---|
220 | set m [menu .mb.fileMenu -tearoff 0] |
---|
221 | $m add command -label "Set Data Dir" -command selectDirectory |
---|
222 | |
---|
223 | # Create tree |
---|
224 | blt::tree create .tree |
---|
225 | catch { LoadTree .tree 0 [pwd] } result |
---|
226 | |
---|
227 | # Create view+plot frame |
---|
228 | frame .vp |
---|
229 | # Create treeview frame |
---|
230 | set tvf [frame .vp.tvf] |
---|
231 | |
---|
232 | set tv [blt::treeview $tvf.t -tree .tree -scrollmode listbox \ |
---|
233 | -xscrollcommand "$tvf.xscroll set" \ |
---|
234 | -yscrollcommand "$tvf.yscroll set" \ |
---|
235 | -activeicons "$images(normal) $images(normal)" \ |
---|
236 | -icons "$images(normal) $images(normal)"] |
---|
237 | #$tvf.t column insert end Plot |
---|
238 | scrollbar $tvf.xscroll -orient horizontal -command "$tvf.t xview" |
---|
239 | scrollbar $tvf.yscroll -orient vertical -command "$tvf.t yview" |
---|
240 | |
---|
241 | #$tvf.t bind all <ButtonPress-1> {puts stdout [.tree label [%W curselection]]} |
---|
242 | $tvf.t bind all <ButtonPress-1> {addremovePlot [%W curselection]} |
---|
243 | |
---|
244 | pack $tvf.xscroll -side bottom -fill x |
---|
245 | pack $tvf.yscroll -side right -fill y |
---|
246 | pack $tvf.t -side left -fill both -expand true |
---|
247 | pack $tvf -side left -fill y -anchor w |
---|
248 | |
---|
249 | # Create graph |
---|
250 | set graph [blt::graph .vp.g] |
---|
251 | pack $graph -fill both -expand true -side left -anchor w |
---|
252 | |
---|
253 | # Create filter frame |
---|
254 | frame .filter |
---|
255 | label .filter.filterLabel -text "Filter: " |
---|
256 | entry .filter.filterEntry |
---|
257 | bind .filter.filterEntry <Return> {filterTree [%W get]} |
---|
258 | |
---|
259 | #button .filter.filterButton -text "Filter" -command {filterTree [.filter.filterEntry get]} |
---|
260 | pack .filter.filterLabel -side left |
---|
261 | pack .filter.filterEntry -side left |
---|
262 | #pack .filter.filterButton -side left |
---|
263 | #pack .filter.filterReset -side right -padx 25 |
---|
264 | |
---|
265 | #Plot controls |
---|
266 | set pcf [frame .filter.pc] |
---|
267 | button $pcf.filterReset -text "Clear Plot" -command {resetGraph} |
---|
268 | radiobutton $pcf.c -text "Counts" -variable plotType -value "count" |
---|
269 | radiobutton $pcf.cr -text "Count Rate" -variable plotType -value "countrate" |
---|
270 | radiobutton $pcf.t -text "Trans" -variable plotType -value "trans" |
---|
271 | radiobutton $pcf.m -text "Mon" -variable plotType -value "mon" |
---|
272 | $pcf.c select |
---|
273 | pack $pcf.filterReset -side right -padx 25 |
---|
274 | pack $pcf.m -side right |
---|
275 | pack $pcf.t -side right |
---|
276 | pack $pcf.cr -side right |
---|
277 | pack $pcf.c -side right |
---|
278 | pack $pcf -side right |
---|
279 | |
---|
280 | |
---|
281 | # Pack widgets |
---|
282 | pack .mb -side top -anchor w |
---|
283 | pack .vp -fill both -expand true -anchor w |
---|
284 | pack .filter -side bottom -fill x -anchor sw |
---|
285 | |
---|
286 | Blt_ZoomStack $graph |
---|
287 | |
---|
288 | |
---|
289 | |
---|
290 | |
---|