source: sans/utils/bt5/bt5plot/bt5plot @ 24

Last change on this file since 24 was 23, checked in by ajj, 16 years ago

Added default values for radiobuttons in plot menu

  • Property svn:executable set to *
File size: 10.7 KB
Line 
1#!/usr/bin/wish
2
3package require BLT
4
5set images(normal) [image create photo -format gif -data {
6    R0lGODlhEAANAMIAAAAAAH9/f///////AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
7    AAM1WBrM+rAEMigJ8c3Kb3OSII6kGABhp1JnaK1VGwjwKwtvHqNzzd263M3H4n2OH1QBwGw6
8    nQkAOw==
9} ]
10
11set images(active) [image create photo -format gif -data {
12    R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
13    AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp
14    ZTKAsiCtWq0JADs=
15} ]
16
17proc 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
72proc 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 {
100proc 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
167proc changePlotType {elem} {
168        global graph
169        global plotType
170
171        set xvec [join "$elem _xvec" ""]
172        set countratevec [join "$elem _countratevec" ""]
173        set countvec [join "$elem _countvec" ""]
174        set transvec [join "$elem _transvec" ""]
175        set monvec [join "$elem _monvec" ""]
176
177        global $xvec $countvec $transvec $monvec
178       
179        switch -exact $plotType {
180                        count { $graph element configure $elem -ydata $countvec}
181                        countrate { $graph element configure $elem -ydata $countratevec}
182                        trans { $graph element configure $elem -ydata $transvec}
183                        mon { $graph element configure $elem -ydata  $monvec}
184        }
185}
186
187proc changeLogLinY {} {
188        global graph
189        global loglinY
190
191        $graph axis configure y -logscale $loglinY
192}       
193
194proc changeLogLinX {} {
195        global graph
196        global loglinX
197
198        $graph axis configure x -logscale $loglinX
199}       
200
201proc LoadTree { tree parentNode dir } {
202        cd $dir
203        foreach f [lsort [glob *.bt5]] {
204                set e [$tree insert $parentNode -label $f -data "Plot 0"]
205        }
206}
207
208proc EmptyTree { tree } {
209        $tree delete 0
210}
211
212proc selectDirectory {} {
213       
214        global .tree
215       
216        set dir [tk_chooseDirectory -title "Set Data Directory"]
217
218        if {$dir ne ""} {
219                EmptyTree .tree
220                catch { LoadTree .tree 0 $dir } result
221                cd $dir
222        }       
223}
224
225proc resetTree { } {
226
227        global .tree
228
229        EmptyTree .tree
230        LoadTree .tree 0 [pwd]
231}
232
233
234proc filterTree { filterString } {
235       
236        global .tree
237
238        resetTree
239       
240        if {$filterString ne ""} {
241                set filterlist [.tree find 0 -glob $filterString -invert -depth 1]
242                foreach node $filterlist {
243                        if { $node != 0 } {
244                                .tree delete $node
245                        }
246                }
247        }       
248       
249}
250
251#Create menu frame
252set mf [frame .mf]
253
254# Create File menu
255menubutton $mf.filemb -text File -menu $mf.filemb.fileMenu
256set fm [menu $mf.filemb.fileMenu -tearoff 0]
257$fm add command -label "Set Data Dir" -command selectDirectory
258
259#Create Plot menu
260menubutton $mf.plotmb -text Plot -menu $mf.plotmb.plotMenu
261set pm [menu $mf.plotmb.plotMenu -tearoff 0]
262$pm add cascade -label "Type" -menu $pm.type
263$pm add cascade -label "X-Axis" -menu $pm.xaxis
264$pm add cascade -label "Y-Axis" -menu $pm.yaxis
265#Create sub menus
266set xam [menu $pm.xaxis -tearoff 0]
267$xam add radio -label "Lin" -variable loglinX -value "no" -command {changeLogLinX}
268$xam add radio -label "Log" -variable loglinX -value "yes" -command {changeLogLinX}
269
270set yam [menu $pm.yaxis -tearoff 0]
271$yam add radio -label "Lin" -variable loglinY -value "no" -command {changeLogLinY}
272$yam add radio -label "Log" -variable loglinY -value "yes" -command {changeLogLinY}
273
274set ptm [menu $pm.type -tearoff 0]
275$ptm add radio  -label "Counts" -variable plotType -value "count" -command {foreach elem [$graph element show] { changePlotType $elem  }}
276$ptm add radio -label "Count Rate" -variable plotType -value "countrate" -command {foreach elem [$graph element show] { changePlotType $elem  }}
277$ptm add radio -label "Trans" -variable plotType -value "trans" -command {foreach elem [$graph element show] { changePlotType $elem  }}
278$ptm add radio -label "Mon" -variable plotType -value "mon" -command {foreach elem [$graph element show] { changePlotType $elem  }}
279
280#Set defaults
281set loglinX "no"
282set loglinY "no"
283set plotType "count"
284
285#pack menubuttons into menu
286pack $mf.filemb -side left
287pack $mf.plotmb -side left
288
289# Create tree
290blt::tree create .tree
291catch { LoadTree .tree 0 [pwd] } result
292
293# Create view+plot frame
294frame .vp
295# Create treeview frame
296set tvf [frame .vp.tvf]
297
298set tv [blt::treeview $tvf.t -tree .tree -scrollmode listbox \
299                                        -xscrollcommand "$tvf.xscroll set" \
300                                        -yscrollcommand "$tvf.yscroll set" \
301                                        -activeicons "$images(normal) $images(normal)" \
302                                        -icons "$images(normal) $images(normal)"]
303#$tvf.t column insert end Plot
304scrollbar $tvf.xscroll -orient horizontal -command "$tvf.t xview"
305scrollbar $tvf.yscroll -orient vertical -command "$tvf.t yview"
306
307#$tvf.t bind all <ButtonPress-1> {puts stdout [.tree label [%W curselection]]}
308$tvf.t bind all <ButtonPress-1> {addremovePlot [%W curselection]}
309
310pack $tvf.xscroll -side bottom -fill x
311pack $tvf.yscroll -side right -fill y
312pack $tvf.t -side left -fill both -expand true
313pack $tvf -side left -fill y -anchor w
314
315# Create graph
316set graph [blt::graph .vp.g]
317pack $graph -fill both -expand true -side left -anchor w
318
319# Create filter frame
320frame .filter
321label .filter.filterLabel -text "Filter: "
322entry .filter.filterEntry
323bind .filter.filterEntry <Return> {filterTree [%W get]}
324
325#button .filter.filterButton -text "Filter" -command {filterTree [.filter.filterEntry get]}
326pack .filter.filterLabel -side left
327pack .filter.filterEntry -side left
328#pack .filter.filterButton -side left
329#pack .filter.filterReset -side right -padx 25
330
331#Plot controls
332set pcf [frame .filter.pc]
333#Clear plot button
334button $pcf.filterReset -text "Clear Plot" -command {resetGraph}
335
336##Frame for radiobutton set to control plot type
337#set ptf [frame .filter.pc.pt -borderwidth 1 -relief raised]
338#radiobutton $ptf.c -text "Counts" -variable plotType -value "count" -command {foreach elem [$graph element show] { changePlotType $elem  }}
339#radiobutton $ptf.cr -text "Count Rate" -variable plotType -value "countrate" -command {foreach elem [$graph element show] { changePlotType $elem  }}
340#radiobutton $ptf.t -text "Trans" -variable plotType -value "trans" -command {foreach elem [$graph element show] { changePlotType $elem  }}
341#radiobutton $ptf.m -text "Mon" -variable plotType -value "mon" -command {foreach elem [$graph element show] { changePlotType $elem  }}
342#$ptf.c select
343#pack $ptf.m -side right
344#pack $ptf.t -side right
345#pack $ptf.cr -side right
346#pack $ptf.c -side right
347
348##Frame for y-axis log/lin choice
349#set logfy [frame .filter.pc.logy -borderwidth 1 -relief raised]
350##Log/lin radiobutton set
351#radiobutton $logfy.log -text "Log Y" -variable loglinY -value "yes" -command { changeLogLinY }
352#radiobutton $logfy.lin -text "Lin Y" -variable loglinY -value "no" -command { changeLogLinY }
353#$logfy.lin select
354#pack $logfy.log -side right
355#pack $logfy.lin -side right
356
357##Frame for y-axis log/lin choice
358#set logfx [frame .filter.pc.logx -borderwidth 1 -relief raised]
359##Log/lin radiobutton set
360#radiobutton $logfx.log -text "Log X" -variable loglinX -value "yes" -command { changeLogLinX }
361#radiobutton $logfx.lin -text "Lin X" -variable loglinX -value "no" -command { changeLogLinX }
362#$logfx.lin select
363#pack $logfx.log -side right
364#pack $logfx.lin -side right
365
366pack $pcf.filterReset -side right -padx 25
367#pack $logfy -side right
368#pack $logfx -side right
369#pack $ptf -side right
370pack $pcf -side right
371
372
373# Pack  widgets
374pack $mf -side top -anchor w
375pack .vp -fill both -expand true -anchor w
376pack .filter -side bottom -fill x -anchor sw
377
378Blt_ZoomStack $graph
379
380
381
382
Note: See TracBrowser for help on using the repository browser.