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 | #Red dot image |
---|
12 | set images(normal) [image create photo -format gif -data { |
---|
13 | R0lGODlhDAAMANUAAPUAAM0VFcsVFckWFsIaGrwdHbgfH7YgIK0lJaUpKZ8sLJsuLpIzM5A0NIw2 |
---|
14 | Nog4OIM7O4E8PH89PXVBQXBERGxGRmpHR2hISGRKSl1OTllQUPv7+/n5+ff39/X19e3t7enp6ePj |
---|
15 | 47a2trKysrCwsKysrKqqqqioqH19fXt7e3l5eXNzc3FxcW9vb21tbWtra2lpaWdnZ11dXVlZWVVV |
---|
16 | VVNTU////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAADYALAAAAAAMAAwAAAZfQJvN |
---|
17 | U4LVai5SR2gLxWoSxWJSe4GGMEwAwAUQMi3OqSbodg21EQxiNlNWtUS7y5jR5HNAQ8aK5AEWKSY1 |
---|
18 | A3MHNSIdLxkFZggaLBs2IC81FQ4PFzUsH0wcJCpHKCKSNkEAOw== |
---|
19 | } ] |
---|
20 | |
---|
21 | #set images(active) [image create photo -format gif -data { |
---|
22 | # R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A |
---|
23 | # AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp |
---|
24 | # ZTKAsiCtWq0JADs= |
---|
25 | #} ] |
---|
26 | |
---|
27 | #Green dot image |
---|
28 | set images(active) [image create photo -format gif -data { |
---|
29 | R0lGODlhDAAMANUAAADIABGxEROuExWrFRenFxuhGx2fHR6dHiGZISOWIySVJCyKLC+GLzGDMTOA |
---|
30 | MzR/NDd7Nzx0PEFsQUJqQkVmRUdkR0lhSUteS09ZT1BXUFJUUvv7+/n5+ff39/X19e3t7enp6ePj |
---|
31 | 47a2trKysrCwsKysrKqqqqioqH19fXt7e3l5eXNzc3FxcW9vb21tbWtra2lpaWdnZ11dXVlZWVVV |
---|
32 | VVNTU////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAADYALAAAAAAMAAwAAAZeQJvN |
---|
33 | U4LVai5SR2gLxWqRBWNSe4GGMMsAwAUYMC3OSSPodgu1EQxiNlNWtUS765jRFHOuQ8Zi5ykpJhoB |
---|
34 | cwc1Ih0vFwRmCBksGzYgLzUSDQ8VNSwfTBwkKkcoIpE2QQA7 |
---|
35 | } ] |
---|
36 | |
---|
37 | proc loadBT5File {fileName x c cr t m} { |
---|
38 | global datasets |
---|
39 | global $x $c $cr $t $m |
---|
40 | |
---|
41 | #puts "In load proc: $x $c $cr $t $m" |
---|
42 | |
---|
43 | set lc 0 |
---|
44 | set mon(0) 0 |
---|
45 | set det1(0) 0 |
---|
46 | set det2(0) 0 |
---|
47 | set det3(0) 0 |
---|
48 | set det4(0) 0 |
---|
49 | set det5(0) 0 |
---|
50 | set xvar(0) 0 |
---|
51 | set trans(0) 0 |
---|
52 | |
---|
53 | if [catch {open $fileName r} fileId] { |
---|
54 | |
---|
55 | puts stderr "Cannot open file for reading: $fileId" |
---|
56 | |
---|
57 | } else { |
---|
58 | for {set lc 0} {$lc < 13} {incr lc} { |
---|
59 | gets $fileId line |
---|
60 | if { $lc == 0 } { |
---|
61 | regexp {^\'.+?\' \'.+?\' \'.+?\'.+?(\d+)\..+} $line match counttime |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | set lc 0 |
---|
66 | while true { |
---|
67 | if {[gets $fileId line] < 0} { |
---|
68 | break |
---|
69 | } else { |
---|
70 | regexp {^ +([^ ]+).*} $line match xvar($lc) |
---|
71 | } |
---|
72 | |
---|
73 | gets $fileId line |
---|
74 | regexp {^ (.+?),(.+?),(.+?),(.+?),(.+?),(.+?),(.+?),.*} $line match mon($lc) \ |
---|
75 | det2($lc) det1($lc) trans($lc) det3($lc) det4($lc) det5($lc) |
---|
76 | incr lc |
---|
77 | } |
---|
78 | |
---|
79 | close $fileId |
---|
80 | } |
---|
81 | |
---|
82 | foreach index [lsort -integer [array names xvar]] { |
---|
83 | $x append {$xvar($index)} |
---|
84 | $c append {$det1($index)+$det2($index)+$det3($index)+$det4($index)+$det5($index)} |
---|
85 | $cr append [expr [$c index $index] / $counttime] |
---|
86 | $t append {$trans($index)} |
---|
87 | $m append {$mon($index)} |
---|
88 | } |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | proc resetGraph { } { |
---|
93 | global graph |
---|
94 | global tv |
---|
95 | global images |
---|
96 | |
---|
97 | foreach elem [ $graph element show] { |
---|
98 | $graph element delete $elem |
---|
99 | |
---|
100 | set xvec [join "$elem _xvec" ""] |
---|
101 | set countratevec [join "$elem _countratevec" ""] |
---|
102 | set countvec [join "$elem _countvec" ""] |
---|
103 | set transvec [join "$elem _transvec" ""] |
---|
104 | set monvec [join "$elem _monvec" ""] |
---|
105 | |
---|
106 | global $xvec $countvec $countratevec $transvec $monvec |
---|
107 | |
---|
108 | blt::vector destroy $xvec |
---|
109 | blt::vector destroy $countratevec |
---|
110 | blt::vector destroy $countvec |
---|
111 | blt::vector destroy $transvec |
---|
112 | blt::vector destroy $monvec |
---|
113 | } |
---|
114 | |
---|
115 | $tv entry configure all -activeicons "$images(normal) $images(normal)" |
---|
116 | $tv entry configure all -icons "$images(normal) $images(normal)" |
---|
117 | } |
---|
118 | |
---|
119 | #foreach fileName $argv { |
---|
120 | proc addremovePlot { nodeID } { |
---|
121 | global graph |
---|
122 | global tv |
---|
123 | global images |
---|
124 | global .tree |
---|
125 | global plotType |
---|
126 | |
---|
127 | set fileName [.tree label $nodeID] |
---|
128 | #puts "$nodeID $fileName" |
---|
129 | set filebase [string trimright $fileName .bt5] |
---|
130 | |
---|
131 | if { ! [$graph element exists $filebase] } { |
---|
132 | |
---|
133 | $tv entry configure $nodeID -activeicons "$images(active) $images(active)" |
---|
134 | $tv entry configure $nodeID -icons "$images(active) $images(active)" |
---|
135 | |
---|
136 | set xvec [join "$filebase _xvec" ""] |
---|
137 | set countratevec [join "$filebase _countratevec" ""] |
---|
138 | set countvec [join "$filebase _countvec" ""] |
---|
139 | set transvec [join "$filebase _transvec" ""] |
---|
140 | set monvec [join "$filebase _monvec" ""] |
---|
141 | |
---|
142 | global $xvec $countvec $countratevec $transvec $monvec |
---|
143 | |
---|
144 | blt::vector create $xvec |
---|
145 | blt::vector create $countratevec |
---|
146 | blt::vector create $countvec |
---|
147 | blt::vector create $transvec |
---|
148 | blt::vector create $monvec |
---|
149 | |
---|
150 | loadBT5File $fileName $xvec $countvec $countratevec $transvec $monvec |
---|
151 | |
---|
152 | $graph element create $filebase -symbol scross \ |
---|
153 | -xdata $xvec \ |
---|
154 | -ydata $countvec |
---|
155 | |
---|
156 | switch -exact $plotType { |
---|
157 | count { $graph element configure $filebase -ydata $countvec} |
---|
158 | countrate { $graph element configure $filebase -ydata $countratevec} |
---|
159 | trans { $graph element configure $filebase -ydata $transvec} |
---|
160 | mon { $graph element configure $filebase -ydata $monvec} |
---|
161 | } |
---|
162 | |
---|
163 | } else { |
---|
164 | $tv entry configure $nodeID -activeicons "$images(normal) $images(normal)" |
---|
165 | $tv entry configure $nodeID -icons "$images(normal) $images(normal)" |
---|
166 | |
---|
167 | $graph element delete $filebase |
---|
168 | |
---|
169 | set xvec [join "$filebase _xvec" ""] |
---|
170 | set countratevec [join "$filebase _countratevec" ""] |
---|
171 | set countvec [join "$filebase _countvec" ""] |
---|
172 | set transvec [join "$filebase _transvec" ""] |
---|
173 | set monvec [join "$filebase _monvec" ""] |
---|
174 | |
---|
175 | global $xvec $countvec $transvec $monvec |
---|
176 | |
---|
177 | blt::vector destroy $xvec |
---|
178 | blt::vector destroy $countratevec |
---|
179 | blt::vector destroy $countvec |
---|
180 | blt::vector destroy $transvec |
---|
181 | blt::vector destroy $monvec |
---|
182 | |
---|
183 | |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | proc changePlotType {elem} { |
---|
188 | global graph |
---|
189 | global plotType |
---|
190 | |
---|
191 | set xvec [join "$elem _xvec" ""] |
---|
192 | set countratevec [join "$elem _countratevec" ""] |
---|
193 | set countvec [join "$elem _countvec" ""] |
---|
194 | set transvec [join "$elem _transvec" ""] |
---|
195 | set monvec [join "$elem _monvec" ""] |
---|
196 | |
---|
197 | global $xvec $countvec $transvec $monvec |
---|
198 | |
---|
199 | switch -exact $plotType { |
---|
200 | count { $graph element configure $elem -ydata $countvec} |
---|
201 | countrate { $graph element configure $elem -ydata $countratevec} |
---|
202 | trans { $graph element configure $elem -ydata $transvec} |
---|
203 | mon { $graph element configure $elem -ydata $monvec} |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | proc changeLogLinY {} { |
---|
208 | global graph |
---|
209 | global loglinY |
---|
210 | |
---|
211 | $graph axis configure y -logscale $loglinY |
---|
212 | } |
---|
213 | |
---|
214 | proc changeLogLinX {} { |
---|
215 | global graph |
---|
216 | global loglinX |
---|
217 | |
---|
218 | $graph axis configure x -logscale $loglinX |
---|
219 | } |
---|
220 | |
---|
221 | proc LoadTree { tree parentNode dir } { |
---|
222 | cd $dir |
---|
223 | foreach f [lsort [glob *.bt5]] { |
---|
224 | set e [$tree insert $parentNode -label $f -data "Plot 0"] |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | proc EmptyTree { tree } { |
---|
229 | $tree delete 0 |
---|
230 | } |
---|
231 | |
---|
232 | proc selectDirectory {} { |
---|
233 | |
---|
234 | global .tree |
---|
235 | |
---|
236 | set dir [tk_chooseDirectory -title "Set Data Directory"] |
---|
237 | |
---|
238 | if {$dir ne ""} { |
---|
239 | EmptyTree .tree |
---|
240 | catch { LoadTree .tree 0 $dir } result |
---|
241 | cd $dir |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | proc resetTree { } { |
---|
246 | |
---|
247 | global .tree |
---|
248 | |
---|
249 | EmptyTree .tree |
---|
250 | LoadTree .tree 0 [pwd] |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | proc filterTree { filterString } { |
---|
255 | |
---|
256 | global .tree |
---|
257 | |
---|
258 | resetTree |
---|
259 | |
---|
260 | if {$filterString ne ""} { |
---|
261 | set filterlist [.tree find 0 -glob $filterString -invert -depth 1] |
---|
262 | foreach node $filterlist { |
---|
263 | if { $node != 0 } { |
---|
264 | .tree delete $node |
---|
265 | } |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | } |
---|
270 | |
---|
271 | #Create menu frame |
---|
272 | set mf [frame .mf] |
---|
273 | |
---|
274 | # Create File menu |
---|
275 | menubutton $mf.filemb -text File -menu $mf.filemb.fileMenu |
---|
276 | set fm [menu $mf.filemb.fileMenu -tearoff 0] |
---|
277 | $fm add command -label "Set Data Dir" -command selectDirectory |
---|
278 | |
---|
279 | #Create Plot menu |
---|
280 | menubutton $mf.plotmb -text Plot -menu $mf.plotmb.plotMenu |
---|
281 | set pm [menu $mf.plotmb.plotMenu -tearoff 0] |
---|
282 | $pm add cascade -label "Type" -menu $pm.type |
---|
283 | $pm add cascade -label "X-Axis" -menu $pm.xaxis |
---|
284 | $pm add cascade -label "Y-Axis" -menu $pm.yaxis |
---|
285 | #Create sub menus |
---|
286 | set xam [menu $pm.xaxis -tearoff 0] |
---|
287 | $xam add radio -label "Lin" -variable loglinX -value "no" -command {changeLogLinX} |
---|
288 | $xam add radio -label "Log" -variable loglinX -value "yes" -command {changeLogLinX} |
---|
289 | |
---|
290 | set yam [menu $pm.yaxis -tearoff 0] |
---|
291 | $yam add radio -label "Lin" -variable loglinY -value "no" -command {changeLogLinY} |
---|
292 | $yam add radio -label "Log" -variable loglinY -value "yes" -command {changeLogLinY} |
---|
293 | |
---|
294 | set ptm [menu $pm.type -tearoff 0] |
---|
295 | $ptm add radio -label "Counts" -variable plotType -value "count" -command {foreach elem [$graph element show] { changePlotType $elem }} |
---|
296 | $ptm add radio -label "Count Rate" -variable plotType -value "countrate" -command {foreach elem [$graph element show] { changePlotType $elem }} |
---|
297 | $ptm add radio -label "Trans" -variable plotType -value "trans" -command {foreach elem [$graph element show] { changePlotType $elem }} |
---|
298 | $ptm add radio -label "Mon" -variable plotType -value "mon" -command {foreach elem [$graph element show] { changePlotType $elem }} |
---|
299 | |
---|
300 | #Set defaults |
---|
301 | set loglinX "no" |
---|
302 | set loglinY "no" |
---|
303 | set plotType "count" |
---|
304 | |
---|
305 | #pack menubuttons into menu |
---|
306 | pack $mf.filemb -side left |
---|
307 | pack $mf.plotmb -side left |
---|
308 | |
---|
309 | # Create tree |
---|
310 | blt::tree create .tree |
---|
311 | catch { LoadTree .tree 0 [pwd] } result |
---|
312 | |
---|
313 | # Create view+plot frame |
---|
314 | frame .vp |
---|
315 | # Create treeview frame |
---|
316 | set tvf [frame .vp.tvf] |
---|
317 | |
---|
318 | set tv [blt::treeview $tvf.t -tree .tree -scrollmode listbox \ |
---|
319 | -xscrollcommand "$tvf.xscroll set" \ |
---|
320 | -yscrollcommand "$tvf.yscroll set" \ |
---|
321 | -activeicons "$images(normal) $images(normal)" \ |
---|
322 | -icons "$images(normal) $images(normal)"] |
---|
323 | #$tvf.t column insert end Plot |
---|
324 | scrollbar $tvf.xscroll -orient horizontal -command "$tvf.t xview" |
---|
325 | scrollbar $tvf.yscroll -orient vertical -command "$tvf.t yview" |
---|
326 | |
---|
327 | #$tvf.t bind all <ButtonPress-1> {puts stdout [.tree label [%W curselection]]} |
---|
328 | $tvf.t bind all <ButtonPress-1> {addremovePlot [%W curselection]} |
---|
329 | |
---|
330 | pack $tvf.xscroll -side bottom -fill x |
---|
331 | pack $tvf.yscroll -side right -fill y |
---|
332 | pack $tvf.t -side left -fill both -expand true |
---|
333 | pack $tvf -side left -fill y -anchor w |
---|
334 | |
---|
335 | # Create graph |
---|
336 | set graph [blt::graph .vp.g] |
---|
337 | pack $graph -fill both -expand true -side left -anchor w |
---|
338 | |
---|
339 | # Create filter frame |
---|
340 | frame .filter |
---|
341 | label .filter.filterLabel -text "Filter: " |
---|
342 | entry .filter.filterEntry |
---|
343 | bind .filter.filterEntry <Return> {filterTree [%W get]} |
---|
344 | |
---|
345 | #button .filter.filterButton -text "Filter" -command {filterTree [.filter.filterEntry get]} |
---|
346 | pack .filter.filterLabel -side left |
---|
347 | pack .filter.filterEntry -side left |
---|
348 | #pack .filter.filterButton -side left |
---|
349 | #pack .filter.filterReset -side right -padx 25 |
---|
350 | |
---|
351 | #Plot controls |
---|
352 | set pcf [frame .filter.pc] |
---|
353 | #Clear plot button |
---|
354 | button $pcf.filterReset -text "Clear Plot" -command {resetGraph} |
---|
355 | |
---|
356 | ##Frame for radiobutton set to control plot type |
---|
357 | #set ptf [frame .filter.pc.pt -borderwidth 1 -relief raised] |
---|
358 | #radiobutton $ptf.c -text "Counts" -variable plotType -value "count" -command {foreach elem [$graph element show] { changePlotType $elem }} |
---|
359 | #radiobutton $ptf.cr -text "Count Rate" -variable plotType -value "countrate" -command {foreach elem [$graph element show] { changePlotType $elem }} |
---|
360 | #radiobutton $ptf.t -text "Trans" -variable plotType -value "trans" -command {foreach elem [$graph element show] { changePlotType $elem }} |
---|
361 | #radiobutton $ptf.m -text "Mon" -variable plotType -value "mon" -command {foreach elem [$graph element show] { changePlotType $elem }} |
---|
362 | #$ptf.c select |
---|
363 | #pack $ptf.m -side right |
---|
364 | #pack $ptf.t -side right |
---|
365 | #pack $ptf.cr -side right |
---|
366 | #pack $ptf.c -side right |
---|
367 | |
---|
368 | ##Frame for y-axis log/lin choice |
---|
369 | #set logfy [frame .filter.pc.logy -borderwidth 1 -relief raised] |
---|
370 | ##Log/lin radiobutton set |
---|
371 | #radiobutton $logfy.log -text "Log Y" -variable loglinY -value "yes" -command { changeLogLinY } |
---|
372 | #radiobutton $logfy.lin -text "Lin Y" -variable loglinY -value "no" -command { changeLogLinY } |
---|
373 | #$logfy.lin select |
---|
374 | #pack $logfy.log -side right |
---|
375 | #pack $logfy.lin -side right |
---|
376 | |
---|
377 | ##Frame for y-axis log/lin choice |
---|
378 | #set logfx [frame .filter.pc.logx -borderwidth 1 -relief raised] |
---|
379 | ##Log/lin radiobutton set |
---|
380 | #radiobutton $logfx.log -text "Log X" -variable loglinX -value "yes" -command { changeLogLinX } |
---|
381 | #radiobutton $logfx.lin -text "Lin X" -variable loglinX -value "no" -command { changeLogLinX } |
---|
382 | #$logfx.lin select |
---|
383 | #pack $logfx.log -side right |
---|
384 | #pack $logfx.lin -side right |
---|
385 | |
---|
386 | pack $pcf.filterReset -side right -padx 25 |
---|
387 | #pack $logfy -side right |
---|
388 | #pack $logfx -side right |
---|
389 | #pack $ptf -side right |
---|
390 | pack $pcf -side right |
---|
391 | |
---|
392 | |
---|
393 | # Pack widgets |
---|
394 | pack $mf -side top -anchor w |
---|
395 | pack .vp -fill both -expand true -anchor w |
---|
396 | pack .filter -side bottom -fill x -anchor sw |
---|
397 | |
---|
398 | Blt_ZoomStack $graph |
---|
399 | |
---|
400 | |
---|
401 | |
---|
402 | |
---|