Changeset 535
- Timestamp:
- Dec 4, 2009 5:07:48 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lstview
- Property rcs:date changed from 2000/12/22 21:31:48 to 2002/01/22 21:52:22
- Property rcs:lines changed from +9 -7 to +302 -79
- Property rcs:rev changed from 1.8 to 1.9
r371 r535 6 6 # read from gzip .LST.gz files using gunzip and then append the .LST file 7 7 # start work on plotting variables change next line to use 8 set plotvars 08 set txtvw(plotvars) 1 9 9 set txtvw(font) "Courier" 10 10 set txtvw(menulength) 25 … … 12 12 set txtvw(string) {} 13 13 set txtvw(sum) 0 14 set txtvw(hideplot) 0 14 15 # maximum characters to read initially from a .LST file 15 16 set txtvw(maxchars) 1000000 … … 24 25 set filename $expnam.LST 25 26 set zfil {} 26 set fil{}27 set lstfp {} 27 28 # is there a compressed version of the file? 28 29 if {[file exists $filename.gz] && $tcl_platform(platform) != "windows"} { … … 59 60 60 61 proc findcyc {win menu {pos 0.0}} { 61 global txtvw valuelst 62 global txtvw 63 global trackinglist 62 64 set i 0 63 65 set lastpos {} … … 101 103 set x [$win get $line.0 $line.end] 102 104 scan $x %s%d%s%d%d%f%f%f a hst c d e f rwp rp 103 lappend valuelst(Rwp$hst) $cycle $rwp 104 lappend valuelst(Rp$hst) $cycle $rp 105 foreach d {Rwp Rp} value "$rwp $rp" { 106 set v ${d}_$hst 107 set var tracklist_$v 108 set trackinglist($v) "$d hist $hst" 109 global $var 110 set ${var}($cycle) $value 111 } 105 112 $win tag add rval $npos $line.end 106 113 set npos [$win search -regexp -count chars \ … … 113 120 set chi [string trim [$win get $chipos+16chars $chipos+23chars]] 114 121 set txtvw(lastchi) "Chi**2 $chi" 115 lappend valuelst(chi2) $cycle $chi 116 # puts "$cycle $chi" 117 } 118 set sumpos [$win search {Final sum} $pos $epos] 122 set var tracklist_chi2 123 set trackinglist(chi2) "red. Chi squared" 124 global $var 125 set ${var}($cycle) $chi 126 } 127 set sumpos [$win search {Final variable sum} $pos $epos] 119 128 if {$sumpos != ""} { 120 set finalshift [string trim [$win get $sumpos+42chars $sumpos+54chars]] 121 set txtvw(finalshift) "Shift $finalshift" 122 lappend valuelst(final_shft2) $cycle $finalshift 129 set line [$win get $sumpos "$sumpos lineend"] 130 regexp {: *([0-9\.]+) } $line a finalshift 131 set txtvw(finalshift) "Shift/SU $finalshift" 132 set var tracklist_fshft2 133 set trackinglist(fshft2) "Sum((shft/su)**2)" 134 global $var 135 set ${var}($cycle) $finalshift 123 136 } 124 137 # loop to highlight all R(F**2) values … … 131 144 catch { 132 145 regexp {gram *([0-9]+).*\) =(.*)} $x a hst rf2 133 lappend valuelst(Rbragg$hst) $cycle $rf2 146 set var tracklist_Rbragg_$hst 147 set trackinglist(Rbragg_$hst) "R(Bragg) hist $hst" 148 global $var 149 set ${var}($cycle) $rf2 134 150 } 135 151 $win tag add rval $npos $line.end … … 163 179 proc findsum {win menu {pos 0.0}} { 164 180 global txtvw 165 set fpos [$win search {Final sum(} $pos+1line end]166 if {$fpos == ""} return167 set pos [$win search {Summary table} $fpos+1line end]181 global trackinglist 182 set pos [$win search {Summary table} $pos+1line end] 183 # found a summary, now search back for the cycle number 168 184 while {$pos != ""} { 169 set line [lindex [split $fpos .] 0] 170 set x [$win get $line.0 $line.end] 171 regexp {cycle *([0-9]+) is} $x a lstcyc 185 # add it to the menu 172 186 incr txtvw(sum) 173 187 .a.goto.menu entryconfigure 3 -state normal … … 177 191 -command "$win see $pos" 178 192 if {[$menu index end] > $txtvw(menulength)} {$menu delete end} 179 set line [lindex [split $pos .] 0] 180 incr line 181 set ncyc [string range [string trim [$win get $line.0 $line.end]] end end] 182 while {[set x [$win get $line.0 $line.end]] != ""} { 183 incr line 184 set lbl [string trim [string range $x 0 8]] 185 if {$lbl != "Name" && [string range $x 0 0] != "1"} { 186 # are there values here? 187 set len [llength [set vals [string range $x 9 end]]] 188 foreach val $vals { 189 if {[scan $val %f s] == 1} { 190 lappend valuelst($lbl) [expr $lstcyc - $ncyc +1] $s 191 } 193 194 set npos [$win index "$pos+1line linestart"] 195 set fpos [$win index $pos-1line] 196 set pos [$win search {Summary table} $npos+1line end] 197 198 if {!$txtvw(plotvars)} continue 199 200 # parse outs the last listed cycle number 201 set lstcyc {} 202 while {$fpos != "0.0" && $lstcyc == ""} { 203 set line [$win get $fpos "$fpos lineend"] 204 regexp {cycle *([0-9]+):} $line a lstcyc 205 set fpos [$win index $fpos-1line] 206 } 207 # get the cycle offset 208 set ncyc [lindex [$win get $npos "$npos lineend"] end] 209 set npos [$win index "$npos+1line linestart"] 210 211 set end [$win index end] 212 # now read through the summary table 213 while {![string match *Fraction* \ 214 [set line [$win get $npos "$npos lineend"]] \ 215 ]} { 216 set v1 [string range $line 1 9] 217 # make a name without spaces 218 set v "zz$v1" 219 regsub -all " " $v "_" v 220 set var tracklist_$v 221 catch { 222 # are there any invalid numbers in the list? 223 foreach value [string range $line 10 end] { 224 expr [string trim $value] 225 } 226 227 # passed syntax check, add to list 228 set trackinglist($v) "shift/SU $v1" 229 global $var 230 231 set i 0 232 foreach value [string range $line 10 end] { 233 incr i 234 set cycle [expr {$lstcyc - $ncyc + $i}] 235 set ${var}($cycle) $value 192 236 } 193 237 } 194 } 195 set fpos [$win search {Final sum(} $pos+1line end] 196 if {$fpos == ""} return 197 set pos [$win search {Summary table} $fpos+1line end] 238 set npos [$win index "$npos+1line linestart"] 239 if {$npos == $end} break 240 } 198 241 } 199 242 } … … 235 278 } 236 279 237 proc updatetext {fil {repeat 1}} { 238 global txtvw filename tcl_platform 239 if $repeat {after 5000 updatetext $fil} 240 set txt [read $fil] 280 proc updatetext {"fil {}"} { 281 global txtvw filename tcl_platform lstfp 282 if {$fil == ""} { 283 after 5000 updatetext 284 set fil $lstfp 285 } 286 set txt {} 287 catch {set txt [read $fil]} 241 288 if {$txt == ""} return 242 289 .txt config -state normal … … 269 316 } 270 317 } 271 proc getstring {} { 318 319 proc GetSearchString {} { 272 320 catch {destroy .str} 273 321 toplevel .str … … 335 383 } 336 384 set expgui(scriptdir) [file dirname $expgui(script) ] 385 386 source [file join $expgui(scriptdir) gsascmds.tcl] 387 source [file join $expgui(scriptdir) opts.tcl] 388 337 389 # override options with locally defined values 338 390 if [file exists [file join $expgui(scriptdir) localconfig]] { … … 364 416 -side left 365 417 menu .a.file.menu 418 .a.file.menu add command -label "Delete $filename" -command KillLSTfile 419 .a.file.menu add command -label "Trim $filename" -command TrimLSTfile 366 420 .a.file.menu add command -label Exit -command "destroy ." 367 421 … … 387 441 -state disabled 388 442 menu .a.goto.menu.sum 389 .a.goto.menu add command -label "Set Search String" -command getstring 390 #pack [button .but.lbl1 -text "Set Search String" -command getstring] -side left 443 .a.goto.menu add command -label "Set Search String" -command GetSearchString 391 444 .a.goto.menu add cascade -label "" -menu .a.goto.menu.str -state disabled 392 445 menu .a.goto.menu.str … … 413 466 -command "SaveOptions" 414 467 415 if {$plotvars && ![catch {package require BLT}]} {416 pack [menubutton .a.plot -text "Plot" -underline 0 -menu .a.plot.menu ] \417 -side left418 menu .a.plot.menu -postcommand postingvars419 .a.plot.menu add cascade -label "Variable(s)" -menu .a.plot.menu.vars420 menu .a.plot.menu.vars421 }422 423 468 proc postingvars {} { 424 global valuelst 425 .a.plot.menu.vars delete 1 end 426 foreach var [lsort [array names valuelst]] { 427 .a.plot.menu.vars add checkbutton -label $var -command plotvars \ 428 -variable plotlist($var) 429 } 430 } 469 global trackinglist 470 eval destroy [winfo children .plot.c.f] 471 set i 0 472 foreach var [lsort [array names trackinglist]] { 473 grid [checkbutton .plot.c.f.$i -text $trackinglist($var) \ 474 -pady 0 -command plotvars -variable plotlist($var)] \ 475 -column 0 -row [incr i] -sticky w 476 } 477 } 478 479 proc makeplot {} { 480 # handle Tcl/Tk v8+ where BLT is in a namespace 481 # use the command so that it is loaded 482 catch {blt::graph} 483 catch { 484 namespace import blt::graph 485 } 486 toplevel .plot 487 grid [graph .plot.g] -col 0 -row 0 -sticky news 488 canvas .plot.c \ 489 -scrollregion {0 0 5000 1000} -width 40 -height 250 \ 490 -yscrollcommand ".plot.s set" 491 scrollbar .plot.s -command ".plot.c yview" 492 grid .plot.c -col 1 -row 0 -sticky news 493 frame .plot.c.f -class SmallFont 494 .plot.c create window 0 0 -anchor nw -window .plot.c.f 495 grid columnconfigure .plot 0 -weight 1 496 grid rowconfigure .plot 0 -weight 1 497 Blt_ZoomStack .plot.g 498 Blt_ActiveLegend .plot.g 499 .plot.g config -title "" 500 .plot.g xaxis config -title "cycle" 501 .plot.g yaxis config -title "" 502 wm iconify .plot 503 } 504 431 505 proc plotvars {} { 432 global valuelst plotlist 506 raise .plot 507 eval .plot.g element delete [.plot.g element names] 508 global trackinglist 509 global plotlist 510 set num 0 511 foreach v [lsort [array names trackinglist]] { 512 set datalist {} 513 if $plotlist($v) { 514 incr num 515 set var tracklist_$v 516 global $var 517 set color [lindex {red green blue magenta cyan yellow} \ 518 [expr $num % 6]] 519 foreach n [lsort -integer [array names $var]] { 520 lappend datalist $n [set ${var}($n)] 521 } 522 .plot.g element create "$var" -data $datalist -color $color \ 523 -label $trackinglist($v) 524 } 525 } 526 } 527 528 proc hideplot {} { 529 global txtvw 530 if {![winfo exists .plot]} { 531 makeplot 532 postingvars 533 } 534 # hide or show the plot 535 if {$txtvw(hideplot) != 1} { 536 wm iconify .plot 537 } else { 538 wm deiconify .plot 539 update idletasks 540 # size the box width & scrollregion height 541 set sizes [grid bbox .plot.c.f] 542 .plot.c config -scrollregion $sizes -width [lindex $sizes 2] 543 # is the scroll bar needed? 544 if {[winfo height .plot.c] >= [lindex $sizes 3]} { 545 grid forget .plot.s 546 } else { 547 grid .plot.s -col 2 -row 0 -sticky news 548 } 549 } 550 } 551 552 553 proc KillLSTfile {} { 554 global filename lstfp tcl_platform 555 # confirm the delete 556 set ans [tk_dialog .warn Notify \ 557 "OK to delete the contents of $filename?" "" 0 Yes No] 558 if {$ans != 0} return 559 # stop the updates 560 after cancel updatetext 561 # zero out the file 562 close $lstfp 563 set lstfp [open $filename w+] 564 .txt config -state normal 565 .txt delete 0.0 end 566 ClearMenus 567 updatetext 568 } 569 570 proc TrimLSTfile {} { 571 global filename lstfp tcl_platform txtvw 572 573 # get the last refinement run position 574 set loc {} 575 # get the starting location 433 576 catch { 434 toplevel .plot 435 pack [graph .plot.g] 436 Blt_ZoomStack .plot.g 437 Blt_ActiveLegend .plot.g 438 .plot.g config -title "" 439 .plot.g xaxis config -title "cycle" 440 .plot.g yaxis config -title "" 441 } 442 raise .plot 443 .plot.g element delete * 444 set num 0 445 foreach var [lsort [array names valuelst]] { 446 if $plotlist($var) { 447 incr num 448 set color [lindex {red green blue magenta cyan yellow} [expr $num % 6]] 449 .plot.g element create "$var" -data $valuelst($var) -color $color 450 } 451 } 577 set loc [lindex [.a.goto.menu.run entrycget 1 -command] end] 578 set loc [.txt index "$loc - 2lines"] 579 set txtvw(delete) [expr {100.*$loc/[.txt index end]}] 580 .txt see $loc 581 582 } 583 if {$loc == ""} { 584 set txtvw(delete) [expr {50.* \ 585 ([lindex [.txt yview] 0] + [lindex [.txt yview] 1])}] 586 set loc [expr {int(0.5+ $txtvw(delete) * [.txt index end]/100.)}].0 587 } 588 589 catch {toplevel .trim} 590 eval destroy [winfo children .trim] 591 wm title .trim "Trim $filename" 592 pack [label .trim.0 -text "File $filename has [expr {int([.txt index end])}] lines total."] -side top 593 pack [label .trim.1 -text "Select percentage of file to delete."] \ 594 -anchor w -side top 595 596 # set the slider resolution so that 1 division is on the 597 # order of 1-2 lines 598 set res .5 599 while {$res > 200./[.txt index end] && $res > 0.01} { 600 if {[string match *5* $res]} { 601 set res [expr $res/2.5] 602 } else { 603 set res [expr $res/2.] 604 } 605 } 606 pack [scale .trim.2 -command HighlightText -orient horizontal \ 607 -variable txtvw(delete) \ 608 -resolution $res] -expand yes -fill x 609 pack [frame .trim.3] 610 pack [button .trim.3.a -text Trim \ 611 -command {DeleteSelectedText; destroy .trim} \ 612 ] -side left 613 pack [button .trim.3.b -text Cancel -command {destroy .trim} ] -side left 614 # create a binding so that we can click on the text box 615 .txt tag delete b 616 .txt tag add b 0.0 end 617 .txt tag bind b <1> "ClickHighlightText %x %y" 618 # show the region pending delete 619 .txt tag delete pend 620 .txt tag add pend 0.0 $loc 621 .txt tag config pend -foreground grey 622 } 623 624 proc ClickHighlightText {x y} { 625 global txtvw 626 if {![winfo exists .trim]} return 627 set loc [.txt index "@$x,$y linestart"] 628 set txtvw(delete) [expr {100.*$loc/[.txt index end]}] 629 .txt tag delete pend 630 .txt tag add pend 0.0 $loc 631 .txt tag config pend -foreground grey 632 } 633 634 proc DeleteSelectedText {} { 635 global filename lstfp 636 .txt config -state normal 637 eval .txt delete [.txt tag nextrange pend 0.0] 638 # stop the updates 639 after cancel updatetext 640 # zero out the file 641 close $lstfp 642 set lstfp [open $filename w+] 643 puts $lstfp [.txt get 0.0 end] 644 .txt delete 0.0 end 645 ClearMenus 646 seek $lstfp 0 647 updatetext 648 } 649 650 proc ClearMenus {} { 651 foreach m {str run cyc sum} { 652 .a.goto.menu.$m delete 1 end 653 } 654 foreach num {1 2 3 5} { 655 .a.goto.menu entryconfigure $num -state disabled 656 } 657 global txtvw 658 set txtvw(runnumber) 0 659 set txtvw(sum) 0 660 } 661 662 proc HighlightText {args} { 663 global txtvw 664 set loc [expr {int(0.5+ $txtvw(delete) * [.txt index end]/100.)}].0 665 .txt tag delete pend 666 .txt tag add pend 0.0 $loc 667 .txt tag config pend -foreground grey 668 .txt see $loc 452 669 } 453 670 … … 457 674 458 675 grid [frame .but ] -column 0 -row 3 -columnspan 2 -sticky ew 459 pack [label .but.lbl2 -textvariable txtvw(lastcycle) -relief sunken] -side left 460 pack [label .but.lbl3 -textvariable txtvw(lastchi) -relief sunken] -side left 461 pack [label .but.lbl4 -textvariable txtvw(finalshift) -relief sunken] -side left 676 pack [label .but.lbl2 -textvariable txtvw(lastcycle) \ 677 -relief sunken -bd 2] -side left 678 pack [label .but.lbl3 -textvariable txtvw(lastchi) \ 679 -relief sunken -bd 2] -side left 680 pack [label .but.lbl4 -textvariable txtvw(finalshift) \ 681 -relief sunken -bd 2] -side left 462 682 bind all <Control-KeyPress-c> {destroy .} 463 683 bind . <KeyPress-Prior> ".txt yview scroll -1 page" … … 472 692 .txt tag config chi -background green 473 693 if [file exists $filename] { 474 set fil[open $filename r]694 set lstfp [open $filename r] 475 695 } else { 476 696 # create a file if it does not exist 477 set fil [open $filename a+] 478 close $fil 479 set fil [open $filename r] 697 set lstfp [open $filename w+] 480 698 } 481 699 donewaitmsg … … 483 701 if {$zfil != ""} {updatetext $zfil 0; close $zfil} 484 702 # read the initial file 485 updatetext $ fil 0703 updatetext $lstfp 486 704 # now start reading with updates 487 updatetext $fil 1 705 updatetext 706 707 if {$txtvw(plotvars) && ![catch {package require BLT}]} { 708 .a.options.menu add checkbutton -label "Show Plot" -command hideplot \ 709 -variable txtvw(hideplot) 710 }
Note: See TracChangeset
for help on using the changeset viewer.