Changeset 1142 for branches/sandbox


Ignore:
Timestamp:
Jun 1, 2011 5:50:48 PM (9 years ago)
Author:
toby
Message:

Add y-magnification regions to liveplot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/sandbox/liveplot

    r993 r1142  
    357357        catch {$vec variable $vec}
    358358    }
     359    ApplyMag
    359360    set maxdiff  [set diffvec(max)]
    360361    set cmin [set calcvec(min)]
     
    441442        wifdvec set $sumlist
    442443        wifdvec set [wifdvec / [wifdvec length]]
    443     }
    444     if {$graph(OmCoS)} {
     444    } elseif {$graph(OmCoS)} {
    445445        wifdvec set $WGT
    446446        wifdvec expr sqrt(wifdvec)
    447447        wifdvec set [wifdvec * diffvec]
     448    } else {
     449        wifdvec length 0
    448450    }
    449451    if $graph(backsub) {
     
    451453        calcvec set [calcvec - bckvec]
    452454    }
     455    ApplyMag
    453456    global obsvec calcvec diffvec
    454457    set maxdiff  [set diffvec(max)]
     
    20892092.a.options.menu.tick add separator
    20902093
     2094pack [menubutton .a.mag -text Magnification -underline 0 -menu .a.mag.menu] \
     2095        -side left
     2096menu .a.mag.menu
     2097set maglist {}
     2098proc ShowMag {} {
     2099    global blt_version tcl_platform peakinfo expgui
     2100    set bx .opt
     2101    catch {destroy $bx}
     2102    toplevel $bx
     2103    putontop $bx
     2104    wm iconname $bx "Mag Regs"
     2105    wm title $bx "Plot Magnification Regions"
     2106    pack [label $bx.0 -text "Magnification Regions:"] -side top
     2107    if {[llength $::maglist] == 0} {
     2108        set lbl "None"
     2109    } else {
     2110        set lbl ""
     2111        set xm $::xvec(min)
     2112        set ym 1.0
     2113        set ::maglist [lsort -real -index 0 $::maglist]
     2114        foreach pair $::maglist {
     2115            foreach {xh ymh} $pair {}
     2116            append lbl "\tfrom $xm to $xh: times $ym\n"
     2117            set xm $xh
     2118            set ym $ymh
     2119        }
     2120        set xh $::xvec(max)
     2121        append lbl "\tfrom $xm to $xh: times $ym"
     2122    }
     2123    pack [label $bx.1 -text $lbl -justify left] -side top
     2124    pack [button $bx.2 -text "Close" -command "destroy $bx"] -side top
     2125    tkwait window $bx
     2126    afterputontop
     2127}
     2128
     2129proc AddMag {} {
     2130    set bx .opt
     2131    catch {destroy $bx}
     2132    toplevel $bx
     2133    putontop $bx
     2134    wm iconname $bx "Add Regs"
     2135    wm title $bx "Add Plot Magnification Region"
     2136    pack [frame $bx.0] -side top
     2137    pack [label $bx.0.a -text "Magnify from "] -side left
     2138    pack [entry $bx.0.b -textvariable xmin -width 6] -side left
     2139    pack [label $bx.0.c -text " to next region. Multiply by "] -side left
     2140    pack [entry $bx.0.d -textvariable mult -width 4] -side left
     2141    pack [frame $bx.2] -side top
     2142    pack [button $bx.2.a -text "Add" -command "destroy $bx"] -side left
     2143    pack [button $bx.2.b -text "Cancel" -command "set mult {}; destroy $bx"] -side left
     2144    if {[catch {expr $::mult}]} {set ::mult 1.0}
     2145    if {$::mult <= 0} {set ::mult 1.0}
     2146    tkwait window $bx
     2147    afterputontop
     2148    catch {
     2149        if {$::xmin < $::xvec(min)} {set ::xmin $::xvec(min)}
     2150        if {$::xmin > $::xvec(max)} {set ::xmin $::xvec(max)}
     2151        if {$::mult > 0} {
     2152            lappend ::maglist [list $::xmin $::mult]
     2153            readdata .g
     2154        } else {
     2155            MyMessageBox -parent . -title "Invalid" \
     2156                -message "Invalid input, try again" \
     2157                -icon error -type Continue -default continue
     2158        }
     2159    }
     2160}
     2161proc ApplyMag {} {
     2162    foreach mrk [.g marker names mag*] {
     2163        .g marker delete $mrk
     2164    }
     2165    if {[llength $::maglist] == 0} return
     2166    global xvec
     2167    vector create ymult([xvec length])
     2168    set xl $xvec(min)
     2169    set ym 1.0
     2170    set i 0
     2171    set ::maglist [lsort -real -index 0 $::maglist]
     2172    foreach pair $::maglist {
     2173        foreach {xh ymh} $pair {}
     2174        set xr [xvec search $xl $xh]
     2175        #puts "$xl $xh [lindex $xr 0]:[lindex $xr end] $ym"
     2176        if {[lindex $xr 0] != [lindex $xr end]} {
     2177            set ymult([lindex $xr 0]:[lindex $xr end]) $ym
     2178            .g marker create line -coords "$xl -Inf $xl Inf" -name mag[incr i]
     2179            .g marker create text -coords "$xl Inf" -name mag[incr i] -text "x$ym" -anchor w
     2180        }
     2181        set xl $xh
     2182        set ym $ymh
     2183    }
     2184    set xh $xvec(max)
     2185    set xr [xvec search $xl $xh]
     2186    set ymult([lindex $xr 0]:[lindex $xr end]) $ym
     2187    #puts "$xl $xh [lindex $xr 0]:[lindex $xr end] $ym"
     2188    .g marker create line -coords "$xl -Inf $xl Inf" -name mag[incr i]
     2189    .g marker create text -coords "$xl Inf" -name mag[incr i] -text "x$ym" -anchor w
     2190    foreach vec {obsvec calcvec bckvec diffvec} {
     2191        global $vec
     2192        $vec expr {$vec * ymult}
     2193    }
     2194}
     2195
    20912196if {$program == "liveplot"} {
     2197    .a.mag.menu add command -label "Add region" -command "AddMag"
     2198    .a.mag.menu add command -label "Show" -command "ShowMag"
     2199    .a.mag.menu add separator
     2200    .a.mag.menu add command -label "Clear" \
     2201        -command "set maglist {}; readdata .g"
    20922202    .a.options.menu add command -label "Obs symbol" -command getsymopts
    20932203} else {
Note: See TracChangeset for help on using the changeset viewer.