Changeset 73
- Timestamp:
- Dec 4, 2009 4:59:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/liveplot
- Property rcs:date changed from 1999/02/16 18:05:57 to 1999/03/19 17:07:59
- Property rcs:lines changed from +10 -9 to +178 -23
- Property rcs:rev changed from 1.4 to 1.5
r53 r73 1 1 #!/usr/local/bin/wish 2 2 set Revision {$Revision$ $Date$} 3 3 4 bind all <Control-KeyPress-c> {destroy .} 4 5 # process command line arguments … … 24 25 if {$tcl_platform(platform) == "windows"} { 25 26 set graph(printout) 1 27 set expgui(tcldump) tcldump.exe 26 28 } else { 27 29 set graph(printout) 0 30 set expgui(tcldump) tcldump 28 31 } 29 32 … … 31 34 set graph(outname) out.ps 32 35 set graph(outcmd) lpr 36 set xunits {} 37 set yunits {} 38 set graph(xunits) 0 39 set graph(yunits) 0 40 set expgui(debug) 0 41 catch {if $env(DEBUG) {set expgui(debug) 1}} 42 #set expgui(debug) 1 33 43 34 44 if [catch {package require BLT} errmsg] { … … 105 115 set link [file readlink $expgui(script)] 106 116 if { [file pathtype $link] == "absolute" } { 107 hset expgui(script) $link117 set expgui(script) $link 108 118 } { 109 119 set expgui(script) [file dirname $expgui(script)]/$link … … 122 132 set expgui(gsasexe) [file join $expgui(gsasdir) exe] 123 133 124 125 proc readdata {box} { 134 proc readdata {box} { 135 global expgui 136 if [catch { 137 #puts [time { 138 if {$expgui(tcldump) == ""} { 139 readdata_hst $box 140 } else { 141 readdata_tcl $box 142 } 143 #}] 144 } errmsg] { 145 if $expgui(debug) {error $errmsg} 146 $box config -title "Read error: $errmsg" 147 catch {console show} 148 puts "error message: $errmsg" 149 update 150 } 151 } 152 153 proc readdata_hst {box} { 126 154 global expgui expnam reflns 127 155 global lasthst 128 global hst peakinfo units156 global hst peakinfo xunits 129 157 $box config -title "(Histogram update in progress)" 130 158 update 131 159 # parse the output of a file 132 if [catch {133 160 set lasthst $hst 134 161 ########################################################################### … … 155 182 set calclist {} 156 183 set bcklist {} 157 set units {}184 set xunits {} 158 185 # define a list of reflection positions for each phase 159 186 for {set i 1} {$i < 10} {incr i} { 160 187 set reflns($i) {} 161 # set flag$i 0162 188 } 163 189 set i 0 … … 188 214 } 189 215 } else { 190 regexp {Time|Theta|keV} $line units216 regexp {Time|Theta|keV} $line xunits 191 217 } 192 218 } 193 if {$ units == "Theta"} {setunits "2-Theta"}219 if {$xunits == "Theta"} {set xunits "2-Theta"} 194 220 close $input 195 221 catch {file delete histdump$hst.inp} … … 209 235 } 210 236 plotdata $box 211 } errmsg] { 212 $box config -title "Read error: $errmsg" 213 catch {console show} 214 puts "error message: $errmsg" 215 update 216 } 237 } 238 239 proc readdata_tcl {box} { 240 global expgui expnam reflns 241 global lasthst graph 242 global hst peakinfo xunits yunits 243 $box config -title "(Histogram update in progress)" 244 update 245 # parse the output of a file 246 set lasthst $hst 247 # use tcldump 248 set input [open histdump$hst.inp w] 249 puts $input "$hst" 250 # x units -- native 251 puts $input "$graph(xunits)" 252 # y units -- native 253 puts $input "$graph(yunits)" 254 # format (if implemented someday) 255 puts $input "0" 256 close $input 257 # initalize arrays 258 set X {} 259 set OBS {} 260 set CALC {} 261 set BKG {} 262 set refpos {} 263 global refhkllist refphaselist 264 set refhkllist {} 265 set refphaselist {} 266 for {set i 1} {$i < 10} {incr i} { 267 set reflns($i) {} 268 } 269 eval [exec $expgui(tcldump) $expnam < histdump$hst.inp] 270 catch {file delete histdump$hst.inp} 271 if {$X == ""} { 272 $box config -title "(Error reading Histogram $hst)" 273 foreach elem [$box element show] { 274 $box element config $elem -hide 1 275 } 276 return 277 } 278 foreach elem [$box element names] { 279 $box element config $elem -hide 0 280 } 281 xvec set $X 282 obsvec set $OBS 283 calcvec set $CALC 284 bckvec set $BKG 285 refposvec set $refpos 286 diffvec set [obsvec - calcvec] 287 global obsvec calcvec diffvec 288 set maxdiff [set diffvec(max)] 289 set ymin1 [expr [set calcvec(min)] - 1.1*$maxdiff] 290 set ymin2 [expr [set obsvec(min)] - 1.1*$maxdiff] 291 if {$ymin1 < $ymin2} { 292 diffvec set [diffvec + $ymin1] 293 } { 294 diffvec set [diffvec + $ymin2] 295 } 296 plotdata $box 297 } 298 299 proc lblhkl {plot x} { 300 global cellparm command blt_version refhkllist refphaselist peakinfo 301 # look for peaks within pixelregion pixels 302 set pixelregion 5 303 set xmin [$plot xaxis invtransform [expr $x - $pixelregion]] 304 set xmax [$plot xaxis invtransform [expr $x + $pixelregion]] 305 set peaknums [refposvec search $xmin $xmax] 306 set peaklist {} 307 set xcen 0 308 # select by displayed phases 309 set lbls 0 310 # puts "" 311 foreach peak $peaknums { 312 # puts "hkl [lindex $refhkllist $peak] phase [lindex $refphaselist $peak]" 313 if [set peakinfo(flag[lindex $refphaselist $peak])] { 314 set xcen [expr $xcen + [refposvec range $peak $peak]] 315 lappend peaklist [lindex $refhkllist $peak] 316 incr lbls 317 } 318 } 319 if {$peaklist == ""} return 320 set xcen [expr $xcen / $lbls] 321 # avoid bug in BLT 2.3 where Inf does not work for text markers 322 if {$blt_version == 2.3} { 323 set ycen [lindex [$plot yaxis limits] 1] 324 } else { 325 set ycen Inf 326 } 327 set mark [$plot marker create text -coords "$xcen $ycen" \ 328 -rotate 90 -text $peaklist -anchor n -bg ""] 329 after 10000 "$plot marker delete $mark" 217 330 } 218 331 219 332 proc plotdata {box} { 220 global expnam hst peakinfo units cycle reflns modtime333 global expnam hst peakinfo xunits yunits cycle reflns modtime 221 334 global lasthst graph 222 335 … … 237 350 diffvec notify now 238 351 $box config -title "$expnam cycle $cycle Hist $hst" 239 $box xaxis config -title $units 352 $box xaxis config -title $xunits 353 $box yaxis config -title $yunits 240 354 setlegend $box $graph(legend) 241 355 # now deal with peaks … … 474 588 } 475 589 590 if [file executable [file join $expgui(gsasexe) $expgui(tcldump)]] { 591 set expgui(tcldump) [file join $expgui(gsasexe) $expgui(tcldump)] 592 # puts "got tcldump" 593 } else { 594 set expgui(tcldump) {} 595 # puts "no tcldump" 596 } 597 476 598 # vectors 477 599 vector xvec … … 485 607 vector diffvec 486 608 diffvec notify never 609 vector refposvec 610 refposvec notify never 487 611 # create the graph 488 612 set box [graph .g] … … 490 614 $box element create obs -color black -symbol scross -linewidth 0 491 615 $box element create calc -color red -symbol none 492 #$box element create bckg -color green -symbol none493 616 $box element create diff -color blue -symbol none 494 617 $box element config obs -xdata xvec -ydata obsvec 495 618 $box element config calc -xdata xvec -ydata calcvec 496 #$box element config bckg -xdata xvec -ydata bckvec497 619 $box element config diff -xdata xvec -ydata diffvec 620 if {$expgui(tcldump) != ""} { 621 $box element create bckg -color green -symbol none 622 $box element config bckg -xdata xvec -ydata bckvec 623 bind $box <Shift-Button-1> "lblhkl %W %x" 624 } 498 625 $box yaxis config -title {} 499 626 setlegend $box $graph(legend) … … 512 639 .a.file.menu add cascade -label "Histogram" -menu .a.file.menu.hist 513 640 menu .a.file.menu.hist 514 foreach num {1 2 3 4 5 6 7 8 9} { 515 .a.file.menu.hist add radiobutton -label $num -value $num -variable hst \ 516 -command {plotdata $box} 641 for {set num 1} {$num < 99} {incr num 10} { 642 .a.file.menu.hist add cascade -label "$num-[expr $num+9]" \ 643 -menu .a.file.menu.hist.$num 644 menu .a.file.menu.hist.$num 645 for {set num1 $num} {$num1 < 10+$num} {incr num1} { 646 .a.file.menu.hist.$num add radiobutton -label $num1 -value $num1 \ 647 -variable hst \ 648 -command {set cycle [getcycle];readdata .g} 649 } 517 650 } 518 651 .a.file.menu add cascade -label Tickmarks -menu .a.file.menu.tick … … 537 670 -command "minioptionsbox $num" 538 671 } 672 if {$expgui(tcldump) != ""} { 673 .a.options.menu add cascade -label "X units" -menu .a.options.menu.xunits 674 menu .a.options.menu.xunits 675 .a.options.menu.xunits add radiobutton -label "As collected" \ 676 -variable graph(xunits) -value 0 \ 677 -command {set cycle [getcycle];readdata .g} 678 .a.options.menu.xunits add radiobutton -label "d-space" \ 679 -variable graph(xunits) -value 1 \ 680 -command {set cycle [getcycle];readdata .g} 681 .a.options.menu.xunits add radiobutton -label "Q" \ 682 -variable graph(xunits) -value 2 \ 683 -command {set cycle [getcycle];readdata .g} 684 .a.options.menu add cascade -label "Y units" -menu .a.options.menu.yunits 685 menu .a.options.menu.yunits 686 .a.options.menu.yunits add radiobutton -label "As collected" \ 687 -variable graph(yunits) -value 0 \ 688 -command {set cycle [getcycle];readdata .g} 689 .a.options.menu.yunits add radiobutton -label "Normalized" \ 690 -variable graph(yunits) -value 1 \ 691 -command {set cycle [getcycle];readdata .g} 692 } 693 539 694 .a.options.menu add checkbutton -label "Include legend" \ 540 695 -variable graph(legend) \
Note: See TracChangeset
for help on using the changeset viewer.