Changeset 494


Ignore:
Timestamp:
Dec 4, 2009 5:07:06 PM (14 years ago)
Author:
toby
Message:

# on 2001/12/16 18:09:18, toby did:
Major revisions:

add braces for expressions
move BLT load after sourcing
Add Linear Algebra use (La1.0)
rework Chebyshev fit to use direct (La) solution
fix manual zoom
improve error messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/liveplot

    • Property rcs:date changed from 2001/11/19 19:50:05 to 2001/12/16 18:09:18
    • Property rcs:lines changed from +10 -4 to +204 -224
    • Property rcs:rev changed from 1.23 to 1.24
    r489 r494  
    7575}
    7676
     77proc waitmsg {message} {
     78    set w .wait
     79    # kill any window/frame with this name
     80    catch {destroy $w}
     81    pack [frame $w]
     82    frame $w.bot -relief raised -bd 1
     83    pack $w.bot -side bottom -fill both
     84    frame $w.top -relief raised -bd 1
     85    pack $w.top -side top -fill both -expand 1
     86    label $w.msg -justify left -text $message -wrap 3i
     87    catch {$w.msg configure -font \
     88                -Adobe-Times-Medium-R-Normal--*-180-*-*-*-*-*-*
     89    }
     90    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
     91    label $w.bitmap -bitmap info
     92    pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
     93    update
     94}
     95
     96proc donewaitmsg {} {
     97    catch {destroy .wait}
     98    update
     99}
     100
     101waitmsg "Loading histogram, Please wait"
     102
     103#--------------------------------------------------------------
     104# define constants
     105array set peakinfo {
     106    color1 magenta
     107    color2 cyan
     108    color3 yellow
     109    color4 sienna
     110    color5 orange
     111    color6 DarkViolet
     112    color7 HotPink
     113    color8 salmon
     114    color9 LimeGreen
     115}
     116set cycle -1
     117set modtime 0
     118
     119#----------------------------------------------------------------
     120# where are we?
     121set expgui(script) [info script]
     122# translate links -- go six levels deep
     123foreach i {1 2 3 4 5 6} {
     124    if {[file type $expgui(script)] == "link"} {
     125        set link [file readlink $expgui(script)]
     126        if { [file  pathtype  $link] == "absolute" } {
     127            set expgui(script) $link
     128        } {
     129            set expgui(script) [file dirname $expgui(script)]/$link
     130        }
     131    } else {
     132        break
     133    }
     134}
     135
     136# fixup relative paths
     137if {[file pathtype $expgui(script)] == "relative"} {
     138    set expgui(script) [file join [pwd] $expgui(script)]
     139}
     140set expgui(scriptdir) [file dirname $expgui(script) ]
     141set expgui(gsasdir) [file dirname $expgui(scriptdir)]
     142set expgui(gsasexe) [file join $expgui(gsasdir) exe]
     143set expgui(docdir) [file join $expgui(scriptdir) doc]
     144
     145source [file join $expgui(scriptdir) gsascmds.tcl]
     146source [file join $expgui(scriptdir) readexp.tcl]
     147source [file join $expgui(scriptdir) opts.tcl]
     148
     149if {$program == "bkgedit"}  {
     150    lappend auto_path $expgui(scriptdir)
     151    if {$tcl_version < 8.1} {
     152        MyMessageBox -parent . -title "La Load Error" \
     153                -message "$program requires Tcl/Tk version 8.1 or higher" \
     154                -helplink "expgui.html La" \
     155                -icon error -type Exit -default exit
     156        exit
     157    }
     158    if [catch {package require La} errmsg] {
     159        MyMessageBox -parent . -title "La Load Error" \
     160                -message "Error -- Unable to load the La (Linear Algebra) package; cannot run $program" \
     161                -helplink "expgui.html La" \
     162                -icon error -type Exit -default exit
     163        exit
     164    }
     165}
     166
    77167if [catch {package require BLT} errmsg] {
    78     tk_dialog .err "BLT Error" "Error -- Unable to load the BLT package" \
    79             error 0 Quit
    80     destroy .
     168    MyMessageBox -parent . -title "BLT Error" \
     169            -message "Error -- Unable to load the BLT package; cannot run $program" \
     170            -helplink "expgui.html blt" \
     171            -icon error -type Exit -default exit
     172    exit
    81173}
    82174# handle Tcl/Tk v8+ where BLT is in a namespace
     
    106198    set graph(ElementHideOption) "-mapped 0"
    107199}
    108 
    109 proc waitmsg {message} {
    110     set w .wait
    111     # kill any window/frame with this name
    112     catch {destroy $w}
    113     pack [frame $w]
    114     frame $w.bot -relief raised -bd 1
    115     pack $w.bot -side bottom -fill both
    116     frame $w.top -relief raised -bd 1
    117     pack $w.top -side top -fill both -expand 1
    118     label $w.msg -justify left -text $message -wrap 3i
    119     catch {$w.msg configure -font \
    120                 -Adobe-Times-Medium-R-Normal--*-180-*-*-*-*-*-*
    121     }
    122     pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
    123     label $w.bitmap -bitmap info
    124     pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
    125     update
    126 }
    127 
    128 proc donewaitmsg {} {
    129     catch {destroy .wait}
    130     update
    131 }
    132 
    133 waitmsg "Loading histogram, Please wait"
    134 
    135 #--------------------------------------------------------------
    136 # define constants
    137 array set peakinfo {
    138     color1 magenta
    139     color2 cyan
    140     color3 yellow
    141     color4 sienna
    142     color5 orange
    143     color6 DarkViolet
    144     color7 HotPink
    145     color8 salmon
    146     color9 LimeGreen
    147 }
    148 set cycle -1
    149 set modtime 0
    150 
    151 #----------------------------------------------------------------
    152 # where are we?
    153 set expgui(script) [info script]
    154 # translate links -- go six levels deep
    155 foreach i {1 2 3 4 5 6} {
    156     if {[file type $expgui(script)] == "link"} {
    157         set link [file readlink $expgui(script)]
    158         if { [file  pathtype  $link] == "absolute" } {
    159             set expgui(script) $link
    160         } {
    161             set expgui(script) [file dirname $expgui(script)]/$link
    162         }
    163     } else {
    164         break
    165     }
    166 }
    167 
    168 # fixup relative paths
    169 if {[file pathtype $expgui(script)] == "relative"} {
    170     set expgui(script) [file join [pwd] $expgui(script)]
    171 }
    172 set expgui(scriptdir) [file dirname $expgui(script) ]
    173 set expgui(gsasdir) [file dirname $expgui(scriptdir)]
    174 set expgui(gsasexe) [file join $expgui(gsasdir) exe]
    175 set expgui(docdir) [file join $expgui(scriptdir) doc]
    176200
    177201# called by a trace on expgui(lblfontsize)
     
    277301                    lappend obslist $Iobs
    278302                    lappend calclist $Icalc
    279                     lappend bcklist [expr $fixB + $fitB]
     303                    lappend bcklist [expr {$fixB + $fitB}]
    280304                }
    281305                # add peaks to peak lists
     
    304328    set cmax [set calcvec(max)]
    305329    set omax [set obsvec(max)]
    306     set expgui(min) [expr $omin < $cmin ? $omin : $cmin]
    307     set expgui(max) [expr $omax > $cmax ? $omax : $cmax]
    308     set ymin1 [expr $cmin - 1.1*$maxdiff]
    309     set ymin2 [expr $omin - 1.1*$maxdiff]
     330    set expgui(min) [expr {$omin < $cmin ? $omin : $cmin}]
     331    set expgui(max) [expr {$omax > $cmax ? $omax : $cmax}]
     332    set ymin1 [expr {$cmin - 1.1*$maxdiff}]
     333    set ymin2 [expr {$omin - 1.1*$maxdiff}]
    310334    if {$ymin1 < $ymin2} {
    311335        diffvec set [diffvec + $ymin1]
     
    373397        set sumlist {}
    374398        foreach n [wifdvec range 0 end] {
    375             set sum [expr $sum + $n]
     399            set sum [expr {$sum + $n}]
    376400            lappend sumlist $sum
    377401        }
     
    389413    set cmax [set calcvec(max)]
    390414    set omax [set obsvec(max)]
    391     set expgui(min) [expr $omin < $cmin ? $omin : $cmin]
    392     set expgui(max) [expr $omax > $cmax ? $omax : $cmax]
    393     set ymin1 [expr $cmin - 1.1*$maxdiff]
    394     set ymin2 [expr $omin - 1.1*$maxdiff]
     415    set expgui(min) [expr {$omin < $cmin ? $omin : $cmin}]
     416    set expgui(max) [expr {$omax > $cmax ? $omax : $cmax}]
     417    set ymin1 [expr {$cmin - 1.1*$maxdiff}]
     418    set ymin2 [expr {$omin - 1.1*$maxdiff}]
    395419    if {$ymin1 < $ymin2} {
    396420        diffvec set [diffvec + $ymin1]
     
    409433        foreach {xmin xmax} [$plot xaxis limits] {}
    410434    } else {
    411         set xmin [$plot xaxis invtransform [expr $x - $expgui(pixelregion)]]
    412         set xmax [$plot xaxis invtransform [expr $x + $expgui(pixelregion)]]
     435        set xmin [$plot xaxis invtransform [expr {$x - $expgui(pixelregion)}]]
     436        set xmax [$plot xaxis invtransform [expr {$x + $expgui(pixelregion)}]]
    413437    }
    414438    set peaknums [refposvec search $xmin $xmax]
     
    450474                set lbls 1
    451475            } elseif {abs($xcen/$lbls-$pos) <= $expgui(pixelregion)} {
    452                 set xcen [expr $xcen + $pos]
     476                set xcen [expr {$xcen + $pos}]
    453477                lappend peaklist [lindex $refhkllist $peak]
    454478                incr lbls
     
    467491    global blt_version tcl_platform tcl_version expgui
    468492    if {$peaklist == ""} return
    469     set xcen [expr $xcen / $lbls]
     493    set xcen [expr {$xcen / $lbls}]
    470494    # avoid bug in BLT 2.3 where Inf does not work for text markers
    471495    if {$blt_version == 2.3} {
     
    489513    if {$expgui(fadetime) > 0} {
    490514        catch {
    491             after [expr $expgui(fadetime) * 1000 ] \
     515            after [expr {$expgui(fadetime) * 1000 }] \
    492516                    "catch \{ $plot marker delete $mark \}"
    493517        }
     
    543567    for {set i 1} {$i < 10} {incr i} {
    544568        if {$expgui(autotick)} {
    545             set div [expr ( $expgui(max) - $expgui(min) )/40.]
    546             set ymin [expr $expgui(min) - ($i+1) * $div]
    547             set ymax [expr $expgui(min) - $i * $div]
     569            set div [expr {( $expgui(max) - $expgui(min) )/40.}]
     570            set ymin [expr {$expgui(min) - ($i+1) * $div}]
     571            set ymax [expr {$expgui(min) - $i * $div}]
    548572        } else {
    549573            set ymin $peakinfo(min$i)
     
    925949}
    926950
    927 # determine a very approximate set of Chebyshev coefficients of order n
    928 # to compute Y from X (fast but not very good)
    929 proc chebgen {X Y xmin xmax n} {
    930     if {[llength $X] != [llength $Y]} return
    931     set xnorm [expr {2. / ($xmax - $xmin)}]
    932     set pi [expr {2*asin(1)}]
    933     set a(0) 0.
    934     for {set i 1} {$i < $n} {incr i} {set a($i) 0.}
    935     foreach x1 $X x2 [lrange $X 1 end] y1 $Y y2 [lrange $Y 1 end] {
    936         if {$x2 == ""} break
    937         set xs1 [expr {-1 + ($x1 - $xmin) * $xnorm}]
    938         set th1 [expr {acos(-1 + ($x1 - $xmin) * $xnorm)}]
    939         set xs2 [expr {-1 + ($x2 - $xmin) * $xnorm}]
    940         set th2 [expr {acos(-1 + ($x2 - $xmin) * $xnorm)}]
    941         set thbar [expr {($th1 + $th2)/2.}]
    942         set dth [expr {$th1 - $th2}]
    943         set xsbar [expr {cos($thbar)}]
    944         # skip duplicate points
    945         if {$xs2 == $xs1} continue
    946         set ybar [expr {($xsbar - $xs1) / ($xs2 - $xs1) * ($y2 - $y1) + $y1}]
    947         # seems to work better starting with just 2 terms
    948 #       for {set i 0} {$i < $n} {incr i}
    949         for {set i 0} {$i < 2} {incr i} {
    950             set a($i) [expr {$a($i) + $ybar * cos($i*$thbar) * $dth}]
    951         }
    952     }
    953     set A [expr {$a(0) / $pi}]
    954     for {set i 1} {$i < $n} {incr i} {
    955         lappend A [expr {2 * $a($i) / $pi}]
    956     }
    957     return $A
    958 }
    959 
    960 # disable the improve fit button
    961 proc bkgResetFit {} {
    962     .bkg.f.fit2 config -state disabled
    963 }
    964 
    965 # enable the improve fit button, if appropriate
    966 proc bkgMoreFit {} {
    967     global cheblist
    968     if {[llength $cheblist] < 2} {bkgResetFit;return}
    969     .bkg.f.fit2 config -state normal
    970 }
    971 
    972 # perform a Gauss-Newton fit to optimize Chebyshev coefficients A
    973 proc chebGN {X Y S A xmin xmax "damp 0.75"} {
    974     # Gauss-Newton
    975     if {[llength $X] != [llength $Y]} return
    976     set xnorm [expr {2. / ($xmax - $xmin)}]
    977     # denominator
    978     set sum2 0.
    979     foreach x $X s $S {
    980         set xs [expr {-1 + (1.*$x - $xmin) * $xnorm}]
     951# Chebyschev fit, evaluate the LS vector, V_n = sum_i (T_n(X_i) * Y_i/sigma_i**2)
     952proc ChebMakeV {xl yl o xmin xmax} {
     953    for {set i 0} {$i < $o} {incr i} {
     954        set sum($i) 0.
     955    }
     956    foreach y $yl x $xl {
     957        # rescale x
     958        set xs [expr {-1 + 2 * (1.*$x - $xmin) / (1.*$xmax - 1.*$xmin)}]
     959        # compute the Chebyschev term Tn(xs)
    981960        set Tpp 0
    982961        set Tp 0
    983         foreach a1 $A {
     962        for {set i 0} {$i < $o} {incr i} {
    984963            if {$Tpp == $Tp && $Tp == 0} {
    985964                set T 1
    986965            } elseif {$Tpp == 0} {
    987966                set T $xs
    988             } else {   
     967            } else {
    989968                set T [expr {2. * $xs * $Tp - $Tpp}]
    990969            }
    991             set sum2 [expr {$sum2 + $T /($s*$s)}]
     970            set sum($i) [expr {$sum($i) + $y * $T}]
     971# weighted
     972            # set sum($i) [expr {$sum($i) + $y * $T / ($sigma*$sigma)}]
    992973            set Tpp $Tp
    993974            set Tp $T
    994975        }
    995976    }
    996     # Evaluate Ycalc & sum(delta2)
    997     set sumd2 0.
    998     foreach x $X y $Y {
    999 #       set xs [expr {-1 + (1.*$x - $xmin) * $xnorm}]
    1000         lappend Ycalc [set yc [chebeval $A $x $xmin $xmax]]
    1001         set sumd2 [expr {$sumd2 + ($y - $yc)*($y - $yc)}]
    1002     }
    1003     set k -1
    1004     foreach a $A {incr k; set sum($k) 0}
    1005     foreach x $X y $Y yc $Ycalc s $S {
    1006         set xs [expr {-1 + (1.*$x - $xmin) * $xnorm}]
    1007         set Tpp 0
    1008         set Tp 0
    1009         set k -1
    1010         foreach a $A {
    1011             incr k
    1012             if {$Tpp == $Tp && $Tp == 0} {
    1013                 set T 1
    1014             } elseif {$Tpp == 0} {
    1015                 set T $xs
    1016             } else {   
    1017                 set T [expr {2. * $xs * $Tp - $Tpp}]
     977    lappend vec 2 $o 0
     978    for {set i 0} {$i < $o} {incr i} {
     979        lappend vec $sum($i)
     980    }
     981    return $vec
     982}
     983
     984# Chebyschev fit, evaluate the LS Hessian, A
     985# where A_jk = sum_i {T_j(X_i) * T_k(X_i)/(sigma_i**2)}
     986proc ChebMakeA {xl o xmin xmax} {
     987    for {set j 0} {$j < $o} {incr j} {
     988        for {set i 0} {$i <= $j} {incr i} {
     989            set sum(${i}_$j) 0.
     990        }
     991    }
     992    foreach x $xl {
     993        # rescale x
     994        set xs [expr {-1 + 2 * (1.*$x - $xmin) / (1.*$xmax - 1.*$xmin)}]
     995        # compute the Chebyschev term Tj(xs)
     996        set Tjpp 0
     997        set Tjp 0
     998        for {set j 0} {$j < $o} {incr j} {
     999            if {$Tjpp == $Tjp && $Tjp == 0} {
     1000                set Tj 1
     1001            } elseif {$Tjpp == 0} {
     1002                set Tj $xs
     1003            } else {
     1004                set Tj [expr {2. * $xs * $Tjp - $Tjpp}]
    10181005            }
    1019             set sum($k) [expr {$sum($k) + ($T * ($yc - $y))/($s*$s)}]
    1020             set Tpp $Tp
    1021             set Tp $T
    1022         }
    1023     }
    1024     set sumd2r $sumd2
    1025     set d $damp
    1026     # compute new cheb terms
    1027     while {$d > $damp/32} {
    1028         set k -1
    1029         set Anew {}
    1030         foreach a $A {
    1031             incr k
    1032             lappend Anew [expr {$a - $d*($sum($k) / $sum2)}]
    1033         }
    1034         # Evaluate new Ycalc & sum(delta2)
    1035         set sumd2r 0.
    1036         foreach x $X y $Y {
    1037 #           set xs [expr {-1 + (1.*$x - $xmin) * $xnorm}]
    1038             set yc [chebeval $Anew $x $xmin $xmax]
    1039             set sumd2r [expr {$sumd2r + ($y - $yc)*($y - $yc)}]
    1040         }
    1041         # are these shifts an improvement?
    1042         if {$sumd2r < $sumd2} {
    1043             # are we converged?
    1044             if {[expr {($sumd2-$sumd2r)/$sumd2}] < 0.0001} {return ""}
    1045             return $Anew
    1046         }
    1047         set d [expr {$d/2.}]
    1048     }
    1049     return ""
     1006            set Tjpp $Tjp
     1007            set Tjp $Tj
     1008            # compute the Chebyschev term Ti(xs)
     1009            set Tipp 0
     1010            set Tip 0
     1011            for {set i 0} {$i <= $j} {incr i} {
     1012                if {$Tipp == $Tip && $Tip == 0} {
     1013                    set Ti 1
     1014                } elseif {$Tipp == 0} {
     1015                    set Ti $xs
     1016                } else {
     1017                    set Ti [expr {2. * $xs * $Tip - $Tipp}]
     1018                }
     1019                set Tipp $Tip
     1020                set Tip $Ti
     1021                set sum(${i}_$j) [expr {$sum(${i}_$j) + $Ti * $Tj}]
     1022# weighted
     1023                # set sum(${i}_$j) [expr {$sum(${i}_$j) + $Ti * $Tj / ($sigma * $sigma)}]
     1024            }
     1025        }
     1026    }
     1027    lappend mat 2 $o $o
     1028    for {set i 0} {$i < $o} {incr i} {
     1029        for {set j 0} {$j < $o} {incr j} {
     1030            if {$j < $i} {
     1031                lappend mat $sum(${j}_$i)
     1032            } else {
     1033                lappend mat $sum(${i}_$j)
     1034            }
     1035        }
     1036    }
     1037    return $mat
    10501038}
    10511039
     
    10641052        set zoomcommand [bind $bindtag <1>]
    10651053        .bkg.f.fit1 config -state disabled
    1066         .bkg.f.fit2 config -state disabled
    10671054        .bkg.f.terms config -state disabled
     1055    }
     1056    if {$b == ""} {
     1057        foreach c {1 2 3} {
     1058            if {[.bkg.l.b$c cget -relief] == "sunken"} {set b $c}
     1059        }
    10681060    }
    10691061    foreach c {1 2 3} {
     
    11131105        for {set i 2} {$i <= $l/1.5} {incr i 2} {
    11141106            $termmenu insert end radiobutton -label $i \
    1115                     -variable chebterms  -command {bkgMoreFit}
     1107                    -variable chebterms
    11161108            set imax $i
    11171109        }
     
    11191111    } else {
    11201112        .bkg.f.fit1 config -state disabled
    1121         .bkg.f.fit2 config -state disabled
    11221113        .bkg.f.terms config -state disabled
    11231114        set chebterms 2
     
    11341125    lappend bkglist [list $x [lindex $xy 1]]
    11351126    set bkglist [lsort -real -index 0  $bkglist]
    1136     bkgMoreFit
    11371127    bkgFillPoints
    11381128    bkgPointPlot
     
    11661156    }
    11671157    set bkglist [lreplace $bkglist $closest $closest]
    1168     bkgMoreFit
    11691158    bkgPointPlot
    11701159    bkgFillPoints
     
    12021191    bkgFillPoints
    12031192    set cheblist ""
    1204     bkgResetFit
    12051193    BkgFillCheb
    12061194    set chebterms 2
     
    12081196
    12091197# fit a Chebyshev polynomial to the selected background points
    1210 proc bkgFit {termlist button} {
     1198proc bkgFit {button} {
    12111199    global bkglist chebterms cheblist
     1200    # keep the button down while working
    12121201    $button config -relief sunken
    12131202    update
     1203    # make a list of X & Y values
    12141204    foreach p $bkglist {
    12151205        lappend S 1.
     
    12181208        }
    12191209    }
     1210
     1211    # perform the Fit
    12201212    global tmin tmax
    1221     if {[llength $termlist] < 2} {
    1222         # get a starting point
    1223         set termlist [chebgen $X $Y $tmin $tmax $chebterms]
    1224         # plot it
    1225         set calcb {}
    1226         foreach x [xvec range 0 end] {
    1227             lappend calcb [chebeval $termlist $x $tmin $tmax]
    1228         }
    1229         .g element configure 11 -xdata xvec -ydata $calcb
    1230         update
    1231     } elseif {[llength $termlist] < $chebterms} {
    1232         while {[llength $termlist] < $chebterms} {
    1233             lappend termlist 0.
    1234         }
    1235     } elseif {[llength $termlist] > $chebterms} {
    1236         set termlist [lrange $termlist 0 [expr $chebterms -1]]
    1237     }
    1238     # iterate
    1239     for {set i 1} {$i < 20} {incr i} {
    1240         set termlist1 [chebGN $X $Y $S $termlist $tmin $tmax]
    1241         # have we converged?
    1242         if {$termlist1 == ""} {
    1243             bkgResetFit
    1244             set cheblist $termlist
    1245             BkgFillCheb
    1246             bkgFillPoints
    1247             $button config -relief raised
    1248             return
    1249         }
    1250         set termlist $termlist1
    1251         set calcb {}
    1252         foreach x [xvec range 0 end] {
    1253             lappend calcb [chebeval $termlist $x $tmin $tmax]
    1254         }
    1255         .g element configure 11 -xdata xvec -ydata $calcb
    1256         update
    1257     }
    1258     set cheblist $termlist
     1213    set V [ChebMakeV $X $Y $chebterms $tmin $tmax]
     1214    #La::show $V
     1215    set A [ChebMakeA $X $chebterms $tmin $tmax]
     1216    #La::show $A
     1217    set cheblist [lrange [La::msolve $A $V] 3 end]
    12591218    BkgFillCheb
    12601219    bkgFillPoints
    1261     bkgMoreFit
     1220    # compute the curve and display it
     1221    set calcb {}
     1222    foreach x [xvec range 0 end] {
     1223        lappend calcb [chebeval $cheblist $x $tmin $tmax]
     1224    }
     1225    .g element configure 11 -xdata xvec -ydata $calcb
     1226    update
    12621227    $button config -relief raised
    12631228}
     
    13111276        .g element configure 11 -xdata xvec -ydata $calcb
    13121277        update
    1313         bkgMoreFit
    13141278    }
    13151279}
     
    13521316    global bkgedit bkglist tmin tmax
    13531317    regexp {(.)([0-9]*)} $i junk var num
    1354     if [catch {expr $bkgedit($i)}] {
     1318    if [catch {expr {$bkgedit($i)}}] {
    13551319        $top.$num.e$var config -fg red
    13561320    } else {
     
    14241388        catch {set graph(${axis}${item}) [format %.${format}f $val]}
    14251389    }
     1390    bind .zoom <Return> "SetManualZoom set"
    14261391}
    14271392
     
    14341399    }
    14351400    foreach item {xmin ymin xmax ymax} {
    1436         set $item {}
    1437         catch {set $item [expr $graph($item)]} 
     1401        if {[catch {expr $graph($item)}]} {
     1402            set $item ""
     1403        } else {
     1404            set $item $graph($item)
     1405        }
    14381406    }
    14391407    # reset the zoomstack
     
    14411409    catch {$graph(blt) xaxis config -min $xmin -max $xmax}
    14421410    catch {$graph(blt) yaxis config -min $ymin -max $ymax}
    1443 }
    1444 
    1445 source [file join $expgui(scriptdir) gsascmds.tcl]
    1446 source [file join $expgui(scriptdir) readexp.tcl]
    1447 source [file join $expgui(scriptdir) opts.tcl]
     1411    global program
     1412    if {$program == "bkgedit"} {bkgEditMode ""}
     1413}
    14481414
    14491415# override options with locally defined values
     
    14651431
    14661432# vectors
    1467 foreach vec {xvec obsvec calcvec bckvec diffvec refposvec wifdvec} {
    1468     vector $vec
    1469     $vec notify never
    1470 }
     1433if [catch {
     1434    foreach vec {xvec obsvec calcvec bckvec diffvec refposvec wifdvec} {
     1435        vector $vec
     1436        $vec notify never
     1437    }
     1438} errmsg] {
     1439    MyMessageBox -parent . -title "BLT Error" \
     1440            -message "BLT Setup Error: could not define vectors \
     1441(msg: $errmsg). \
     1442$program cannot be run without vectors." \
     1443            -helplink "expgui.html blt" \
     1444            -icon error -type Skip -default skip
     1445    exit
     1446}
     1447
    14711448# create the graph
    14721449if [catch {
    14731450    set box [graph .g -plotbackground white]
     1451    set graph(blt) $box
    14741452} errmsg] {
    1475     tk_dialog .err "BLT Error" \
    1476 "BLT Setup Error: could not create a graph (msg: $errmsg). \
    1477 There is a problem with the setup of BLT on your system.
     1453    MyMessageBox -parent . -title "BLT Error" \
     1454            -message "BLT Setup Error: could not create a graph \
     1455(error msg: $errmsg). \
     1456There is a problem with the setup of BLT on your system. \
    14781457See the expgui.html file for more info." \
    1479             error 0 "Quit"
    1480 exit
     1458            -helplink "expgui.html blt" \
     1459            -icon warning -type Exit -default "exit"
     1460    exit
    14811461}
    14821462if [catch {
    14831463    Blt_ZoomStack $box
    14841464} errmsg] {
    1485     tk_dialog .err "BLT Error" \
    1486 "BLT Setup Error: could not access a Blt_ routine (msg: $errmsg). \
     1465    MyMessageBox -parent . -title "BLT Error" \
     1466            -message "BLT Setup Error: could not access a Blt_ routine \
     1467(msg: $errmsg). \
    14871468The pkgIndex.tcl is probably not loading bltGraph.tcl.
    14881469See the expgui.html file for more info." \
    1489             error 0 "Limp ahead"
     1470        -helplink "expgui.html blt" \
     1471        -icon warning -type {"Limp Ahead"} -default "limp Ahead"
    14901472}
    14911473# modify zoom so that y2axis is not zoomed in for blt2.4u+
     
    16691651    grid [frame .bkg.f -bd 3 -relief groove] \
    16701652            -col 3 -row 1 -columnspan 2 -sticky nsw
    1671     grid [button .bkg.f.fit1 -text "Start\nFit" -command {bkgFit "" .bkg.f.fit1}] \
     1653    grid [button .bkg.f.fit1 -text "Fit" -command {bkgFit .bkg.f.fit1}] \
    16721654            -col 1 -row 1
    1673     grid [button .bkg.f.fit2 -text "Improve\nFit" \
    1674             -command {bkgFit $cheblist .bkg.f.fit2}] -col 2 -row 1
    16751655    grid [label .bkg.f.tl -text "with"] -col 3 -row 1
    16761656    set termmenu [tk_optionMenu .bkg.f.terms chebterms 0]
Note: See TracChangeset for help on using the changeset viewer.