Changeset 475


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

# on 2001/10/31 19:28:03, toby did:
Very major rewrite

make excledt run inside expgui
add dummy histogram support
add manual zoom and next histogram keys

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/excledt.tcl

    • Property rcs:date changed from 2001/10/31 19:24:11 to 2001/10/31 19:28:03
    • Property rcs:lines changed from +20 -9 to +776 -585
    • Property rcs:rev changed from 1.4 to 1.5
    r473 r475  
    1 #!/usr/local/bin/wish
    21# $Id$
    3 set Revision {$Revision$ $Date$}
    4 
    5 # process command line arguments
    6 set exitstat 0
    7 set expnam [lindex $argv 0]
    8 if {$expnam == ""} {puts "error -- no experiment name"; set exitstat 1}
    9 if $exitstat {
    10     puts "usage: $argv0 expnam \[hist #\] \[legend\]"
    11     destroy .
    12 }
    13 
    14 if {[lindex $argv 1] == ""} {
    15     set hst 1
    16 } else {
    17     set hst [lindex $argv 1]
    18     if {[llength $hst] > 1} {set hst [lindex $hst 0]}
    19 }
    20 if {[lindex $argv 2] == ""} {
    21     set graph(legend) 1
    22 } else {
    23     set graph(legend) [lindex $argv 2]
    24 }
    25 
    26 # default values
    27 set graph(exclPrompt) 1
    28 set expgui(font) 14
    29 set changes 0
    30 set graph(outname) out.ps
    31 set graph(outcmd) lpr
    32 set graph(color_excl) orange
    33 set graph(color_calc) red
    34 set graph(color_obs) black
    35 set xunits {}
    36 set yunits {}
    37 set graph(xunits) 0
    38 set graph(yunits) 0
    39 set graph(autoraise) 1
    40 set graph(FillExclRegionBox) 1
    41 set expgui(debug) 0
    42 catch {if $env(DEBUG) {set expgui(debug) 1}}
    43 #set expgui(debug) 1
    44 set expgui(autotick) 0
    45 # location for web pages, if not found locally
    46 set expgui(website) www.ncnr.nist.gov/xtal/software/expgui
    47 set peakinfo(obssym) scross
    48 set peakinfo(obssize) 1.0
    49 set peakinfo(exclsym) scross
    50 set peakinfo(exclsize) 1.2
    51 # create a set of markers for each phase
    52 for {set i 1} {$i < 10} {incr i} {
    53     set peakinfo(flag$i) 0
    54     set peakinfo(max$i) Inf
    55     set peakinfo(min$i) -Inf
    56     set peakinfo(dashes$i) 1
    57 }
    58 
    59 if [catch {package require BLT} errmsg] {
    60     tk_dialog .err "BLT Error" "Error -- Unable to load the BLT package" \
    61             error 0 Quit
    62     destroy .
    63 }
    64 # handle Tcl/Tk v8+ where BLT is in a namespace
    65 #  use the command so that it is loaded
    66 catch {blt::graph}
    67 catch {
    68     namespace import blt::graph
    69     namespace import blt::vector
    70 }
    71 # old versions of blt don't report a version number
    72 if [catch {set blt_version}] {set blt_version 0}
    73 # option for coloring markers: note that GH keeps changing how to do this!
    74 # also element -mapped => -show
    75 if {$blt_version < 2.3 || $blt_version >= 8.0} {
    76     # version 8.0 is ~same as 2.3
    77     set graph(MarkerColorOpt) -fg
    78     # mapped is needed in 8.0, both are OK in 2.3
    79     set graph(ElementShowOption) "-mapped 1"
    80     set graph(ElementHideOption) "-mapped 0"
    81 } elseif {$blt_version >= 2.4} {
    82     set graph(MarkerColorOpt) -outline
    83     set graph(ElementShowOption) "-hide 0"
    84     set graph(ElementHideOption) "-hide 1"
    85 } else {
    86     set graph(MarkerColorOpt) -color
    87     set graph(ElementShowOption) "-mapped 1"
    88     set graph(ElementHideOption) "-mapped 0"
    89 }
    90 
    91 #--------------------------------------------------------------
    92 # define constants
    93 array set peakinfo {
    94     color1 magenta
    95     color2 cyan
    96     color3 yellow
    97     color4 sienna
    98     color5 orange
    99     color6 DarkViolet
    100     color7 HotPink
    101     color8 salmon
    102     color9 LimeGreen
    103 }
    104 set cycle -1
    105 
    106 #----------------------------------------------------------------
    107 # where are we?
    108 set expgui(script) [info script]
    109 # translate links -- go six levels deep
    110 foreach i {1 2 3 4 5 6} {
    111     if {[file type $expgui(script)] == "link"} {
    112         set link [file readlink $expgui(script)]
    113         if { [file  pathtype  $link] == "absolute" } {
    114             set expgui(script) $link
    115         } {
    116             set expgui(script) [file dirname $expgui(script)]/$link
    117         }
    118     } else {
    119         break
    120     }
    121 }
    122 
    123 # fixup relative paths
    124 if {[file pathtype $expgui(script)] == "relative"} {
    125     set expgui(script) [file join [pwd] $expgui(script)]
    126 }
    127 set expgui(scriptdir) [file dirname $expgui(script) ]
    128 set expgui(gsasdir) [file dirname $expgui(scriptdir)]
    129 set expgui(gsasexe) [file join $expgui(gsasdir) exe]
    130 set expgui(docdir) [file join $expgui(scriptdir) doc]
    131 
    132 proc readdata {box} {
    133     global expgui expnam
    134     if [catch {
     2
     3proc ExclReaddata {box} {
     4    global expgui
     5#    if [catch {
    1356        set loadtime [time {
    136             readdata_hst $box
    137         }]
     7            ExclReaddata_hst $box
     8#       }]
    1389        if $expgui(debug) {
    13910            tk_dialog .time "Timing info" \
    14011                    "Histogram loading took $loadtime" "" 0 OK
    14112        }
    142     } errmsg] {
     13#    } errmsg] {
    14314        if $expgui(debug) {
    14415            catch {console show}
    14516            error $errmsg
    14617        }
    147         $box config -title "Read error"
    148         tk_dialog .err "Read Error" "Read Error -- $errmsg" \
    149                 error 0 OK
    150         update
    151     }
     18#       $box config -title "Read error"
     19#       tk_dialog .err "Read Error" "Read Error -- $errmsg" \
     20#               error 0 OK
     21#       update
     22#    }
    15223    $box element show [lsort -decreasing [$box element show]]
    15324}
    15425   
    155 proc readdata_hst {box} {
    156     global expgui expnam reflns graph
    157 #    global lasthst
    158     global hst peakinfo xunits
    159 #    $box config -title "(Histogram update in progress)"
     26proc ExclReaddata_hst {box} {
     27    global expgui reflns graph
     28    global peakinfo
    16029    update
     30    set hst $graph(hst)
    16131    # parse the output of a file
    162 #    set lasthst $hst
    16332    # use histdmp for histogram info
    16433    set input [open histdump$hst.inp w]
    165     puts $input "$expnam"
     34    puts $input "[file rootname [file tail $expgui(expfile)]]"
    16635    puts $input "L"
    16736    puts $input "$hst"
     
    17342    set input [open histdump$hst.out r]
    17443    catch {file delete histdump$hst.inp}
    175 
    17644    # initalize arrays
    17745    set num -1
     
    18048    set calclist {}
    18149    set allxlist {}
    182     set xunits {}
     50    set graph(xcaption) {}
    18351    set exclistx {}
    18452    set exclistobs {}
     
    21482            }
    21583        } else {
    216             regexp {Time|Theta|keV} $line xunits
     84            regexp {Time|Theta|keV} $line graph(xcaption)
    21785        }
    21886    }
    21987    close $input
    220     if {$xunits == "Theta"} {set xunits "2-Theta"}
     88    if {$graph(xcaption) == "Theta"} {set graph(xcaption) "2-Theta"}
    22189    # convert the x units, if requested
    22290    if {$graph(xunits) == 1} {
    22391        set xlist [tod $xlist $hst]
    22492        set exclistx [tod $exclistx $hst]
    225         set xunits d-space
     93        set graph(xcaption) d-space
    22694    } elseif {$graph(xunits) == 2} {
    22795        set xlist [toQ $xlist $hst]
    22896        set exclistx [toQ $exclistx $hst]
    229         set xunits Q
     97        set graph(xcaption) Q
    23098    }
    23199    catch {file delete histdump$hst.out}
     
    244112        set cmax [set calcvec(max)]
    245113        set omax [set obsvec(max)]
    246         set expgui(min) [expr $omin < $cmin ? $omin : $cmin]
    247         set expgui(max) [expr $omax > $cmax ? $omax : $cmax]
    248         set ymin1 [expr $cmin - 1.1*$maxdiff]
    249         set ymin2 [expr $omin - 1.1*$maxdiff]
    250         if {$ymin1 < $ymin2} {
    251             diffvec set [diffvec + $ymin1]
    252         } {
    253             diffvec set [diffvec + $ymin2]
     114        foreach {expgui(min) expgui(max)} {0 0} {}
     115        catch {
     116            set expgui(min) [expr $omin < $cmin ? $omin : $cmin]
     117            set expgui(max) [expr $omax > $cmax ? $omax : $cmax]
     118            set ymin1 [expr $cmin - 1.1*$maxdiff]
     119            set ymin2 [expr $omin - 1.1*$maxdiff]
     120            if {$ymin1 < $ymin2} {
     121                diffvec set [diffvec + $ymin1]
     122            } {
     123                diffvec set [diffvec + $ymin2]
     124            }
    254125        }
    255126    }
     
    309180    return $ans
    310181}
     182
    311183# convert energy (edx-ray) to d-space
    312184# (note that this ignores the zero correction)
     
    513385
    514386proc plotdata {args} {
    515     global box
    516     global expnam hst peakinfo xunits yunits cycle reflns
     387    global peakinfo  reflns
    517388    global graph expgui
    518389
    519     $box config -title "$expnam cycle $cycle Hist $hst"
    520     $box xaxis config -title $xunits
    521     $box yaxis config -title $yunits
    522     setlegend $box $graph(legend)
     390    set hst $graph(hst)
     391    $graph(plot) config -title \
     392            "[file tail $expgui(expfile)] cycle [expinfo cyclesrun] Hist $hst"
     393    $graph(plot) xaxis config -title $graph(xcaption)
     394    $graph(plot) yaxis config -title $graph(ycaption)
     395    setlegend $graph(plot) $graph(legend)
    523396    # reconfigure the data display
    524     $box element configure 3 \
     397    $graph(plot) element configure 3 \
    525398            -symbol $peakinfo(obssym) -color $graph(color_obs) \
    526399            -pixels [expr 0.125 * $peakinfo(obssize)]i
    527     $box element config 2 -color $graph(color_calc)
    528     $box element config 12 \
     400    $graph(plot) element config 2 -color $graph(color_calc)
     401    $graph(plot) element config 12 \
    529402            -symbol $peakinfo(exclsym) -color $graph(color_excl) \
    530403            -pixels [expr 0.125 * $peakinfo(exclsize)]i
     
    555428                incr j
    556429                catch {
    557                     $box marker create line -name peaks${i}_$j
     430                    $graph(plot) marker create line -name peaks${i}_$j
    558431                }
    559                 $box marker config peaks${i}_$j  -under 1 \
     432                $graph(plot) marker config peaks${i}_$j  -under 1 \
    560433                        -coords "$X $ymin $X $ymax"
    561434                catch {
    562                     $box marker config peaks${i}_$j \
     435                    $graph(plot) marker config peaks${i}_$j \
    563436                            $graph(MarkerColorOpt) [list $peakinfo(color$i)]
    564437                    if $peakinfo(dashes$i) {
    565                         $box marker config peaks${i}_$j -dashes "5 5"
     438                        $graph(plot) marker config peaks${i}_$j -dashes "5 5"
    566439                    }
    567440                }
    568441            }
    569             catch {$box element create phase$i}
     442            catch {$graph(plot) element create phase$i}
    570443            catch {
    571                 $box element config phase$i -color $peakinfo(color$i)
    572             }
    573         } else {
    574             eval $box marker delete [$box marker names peaks${i}_*]
    575             eval $box element delete [$box element names phase$i]
     444                $graph(plot) element config phase$i -color $peakinfo(color$i)
     445            }
     446        } else {
     447            eval $graph(plot) marker delete [$graph(plot) marker names peaks${i}_*]
     448            eval $graph(plot) element delete [$graph(plot) element names phase$i]
    576449        }
    577450    }
    578451    # force an update of the plot as BLT may not
    579     $box config -title [$box cget -title]
     452    $graph(plot) config -title [$graph(plot) cget -title]
    580453    update
    581454}
     
    646519
    647520proc makepostscriptout {} {
    648     global graph box
     521    global graph
    649522    if !$graph(printout) {
    650523        set out [open "| $graph(outcmd) >& plot.msg" w]
    651524        catch {
    652             puts $out [$box postscript output -landscape 1 \
     525            puts $out [$graph(plot) postscript output -landscape 1 \
    653526                -decorations no -height 7.i -width 9.5i]
    654527            close $out
     
    671544        }
    672545    } else {
    673         $box postscript output $graph(outname) -landscape 1 \
     546        $graph(plot) postscript output $graph(outname) -landscape 1 \
    674547                -decorations no -height 7.i -width 9.5i   
    675548        tk_dialog .msg "file created" \
     
    698571    catch {destroy $box}
    699572    toplevel $box
     573    wm title $box "Postscript options"
    700574    focus $box
    701575    pack [frame $box.4] -side top -anchor w -fill x
     
    727601    toplevel $box
    728602    focus $box
    729     wm title .out "set $sym symbol"
     603    wm title .out "Set $sym symbol"
    730604    pack [frame $box.d] -side left -anchor n
    731605    pack [label $box.d.t -text "Symbol type"] -side top
     
    754628}
    755629
    756 # save some of the global options in ~/.gsas_config
    757 proc SaveOptions {} {
    758     global graph expgui peakinfo
    759     set fp [open [file join ~ .gsas_config] a]
    760     foreach v {printout legend outname outcmd autoraise color_excl \
    761             color_obs color_calc} {
    762         puts $fp "set graph($v) $graph($v)"
    763     }
    764     foreach v {obssym obssize exclsym exclsize} {
    765         puts $fp "set peakinfo($v) $peakinfo($v)"
    766     }
    767     puts $fp "set expgui(font) $expgui(font)"
    768     puts $fp "set expgui(autotick) $expgui(autotick)"
    769     close $fp
    770 }
    771 
    772 proc about {} {
    773     global Revision
    774     tk_dialog .warn About "
    775 GSAS\n\
    776 A. C. Larson and\n R. B. Von Dreele,\n LANSCE, Los Alamos\n\n\
    777 EXCLEDT\nB. Toby, NIST\nNot subject to copyright\n\n\
    778 $Revision\n\
    779 " {} 0 OK
    780 }
    781 
    782 proc getcycle {} {
    783     global expnam
    784     set cycle -1
    785     catch {
    786         set fp [open $expnam.EXP r]
    787         set text [read $fp]
    788         close $fp
    789         regexp {GNLS  RUN.*Total cycles run *([0-9]*) } $text x cycle
    790     }
    791     return $cycle
    792 }
    793 
    794630proc updateplot {} {
    795     global cycle expnam env tcl_platform graph hst box
    796     $box config -title "Please wait: loading histogram $hst"
     631    global env tcl_platform graph expgui
     632    set hst $graph(hst)
     633    $graph(plot) config -title "Please wait: loading histogram $hst"
    797634    exxvec set {}
    798635    exobsvec  set {}
    799636    exxvec notify now
    800637    exobsvec notify now
    801     eval .g marker delete [.g marker names]
    802 
    803     # are we in windows and are "locked?" If not, OK to update
    804     if {$tcl_platform(platform) == "windows" && [file exists expgui.lck]} {
    805         .g config -title "(Experiment directory locked)"
    806         # check again in a second
    807         after 1000 updateplot
    808     } else {
    809         set cycle [getcycle]
    810         readdata .g
    811         if {$tcl_platform(platform) == "windows" && $graph(autoraise)} {
    812             # raise does not seem to be global in Windows,
    813             # but this works in Win-95
    814             # nothing seems to work in Win-NT
    815             wm withdraw .
    816             wm deiconify .
    817         } elseif {$graph(autoraise)} {
    818             raise .
    819         }
    820     }
     638    eval $graph(plot) marker delete [$graph(plot) marker names]
     639
     640    ExclReaddata $graph(plot)
    821641    ShowExlMarks
    822     $box element config 3 -color $graph(color_obs)
    823     $box element config 2 -color $graph(color_calc)
    824     $box element config 12 -color $graph(color_excl)
     642    $graph(plot) element config 3 -color $graph(color_obs)
     643    $graph(plot) element config 2 -color $graph(color_calc)
     644    $graph(plot) element config 12 -color $graph(color_excl)
    825645    foreach vec {xvec obsvec calcvec diffvec exxvec exobsvec} {
    826646        $vec notify now
    827647    }
    828648    FillExclRegionBox
    829     global cycle expnam
    830     $box config -title "$expnam cycle $cycle Hist $hst"
     649    $graph(plot) config -title \
     650            "[file tail $expgui(expfile)] cycle [expinfo cyclesrun] Hist $hst"
    831651}
    832652
    833653proc ShowExlMarks {} {
    834     global hst graph
    835     eval .g marker delete [.g marker names excl*]
     654    global graph
     655    eval $graph(plot) marker delete [$graph(plot) marker names excl*]
     656    set hst $graph(hst)
    836657    set exclist [histinfo $hst excl]
    837658    set i 0
     
    844665        set x1 [lindex [lsort -real $rng] 0]
    845666        set x2 [lindex [lsort -real $rng] end]
    846         .g marker create line -under 1 -name excl[incr i] \
     667        $graph(plot) marker create line -under 1 -name excl[incr i] \
    847668                -coords "$x1 -Inf $x2 -Inf" \
    848669                -outline $graph(color_excl) -linewidth 3
     
    860681# change the binding of the mouse, based on the selected mode
    861682proc exclEditMode {b bb} {
    862     global zoom box
     683    global zoom graph
    863684    # get binding
    864     set bindtag $box
     685    set bindtag $graph(plot)
    865686    catch {
    866687        if {[bind bltZoomGraph] != ""} {
     
    882703
    883704    # reset previous mode; if in the middle
    884     if {[string trim [bind $box <Motion>]] != ""} {
    885         if {[lindex [bind $box <Motion>] 0] == "exclMove"} {
     705    if {[string trim [bind $graph(plot) <Motion>]] != ""} {
     706        if {[lindex [bind $graph(plot) <Motion>] 0] == "exclMove"} {
    886707            exclReset $bindtag
    887708        } else {
    888             blt::ResetZoom $box
     709            blt::ResetZoom $graph(plot)
    889710        }
    890711    }
    891712    if {$b == 2} {
    892713        bind $bindtag <1> "exclAdd $bindtag %x %y"
    893         .g config -cursor arrow
     714        $graph(plot) config -cursor arrow
    894715    } elseif {$b == 3} {
    895716        bind $bindtag <1> "exclDel $bindtag %x %y"
    896         .g config -cursor circle
     717        $graph(plot) config -cursor circle
    897718    } else {
    898719        bind $bindtag <1> $zoom(in)
    899720        bind $bindtag <3> $zoom(out)
    900         .g config -cursor crosshair
     721        $graph(plot) config -cursor crosshair
    901722    }
    902723}
    903724
    904725proc exclDel {bindtag x y} {
    905     global graph box changes hst
    906     set x1 [$box xaxis invtransform $x]
     726    global graph expgui
     727    set x1 [$graph(plot) xaxis invtransform $x]
     728    set hst $graph(hst)
    907729    if {$graph(xunits) == 1} {
    908730        set x1 [fromd $x1 $hst]
     
    945767            }
    946768            if {$ans == "ok"} {
    947                 incr changes
     769                incr expgui(changed)
    948770            } else {
    949771                lappend newlist $rng
     
    960782
    961783proc exclAdd {bindtag x y} {
    962     global graph box
    963     bind $box <Motion> "exclMove $bindtag %x %y"
     784    global graph
     785    bind $graph(plot) <Motion> "exclMove $bindtag %x %y"
    964786    bind $bindtag <1> "exclDone $bindtag %x %y"
    965787    bind $bindtag <3> "exclReset $bindtag"
    966     set graph(excl-x1) [$box xaxis invtransform $x]
    967     .g marker create text -name AddExclLbl -text "Adding\nRegion" \
     788    set graph(excl-x1) [$graph(plot) xaxis invtransform $x]
     789    $graph(plot) marker create text -name AddExclLbl -text "Adding\nRegion" \
    968790            -bg yellow -coords "+Inf +Inf" -anchor ne
    969791}
    970792
    971793proc exclReset {bindtag} {
    972     global box
    973     bind $box <Motion> {}
    974     $box marker delete exclShade
     794    global graph
     795    bind $graph(plot) <Motion> {}
     796    $graph(plot) marker delete exclShade
    975797    bind $bindtag <1> "exclAdd $bindtag %x %y"
    976     .g marker delete AddExclLbl
     798    $graph(plot) marker delete AddExclLbl
    977799}
    978800
    979801proc exclMove {bindtag x y} {
    980     global graph box
     802    global graph
    981803    set x1 $graph(excl-x1)
    982     set x2 [$box xaxis invtransform $x]
    983     if { ![$box marker exists "exclShade"] } {
    984         $box marker create polygon -name "exclShade" -under 1 -fill yellow
    985     }
    986     $box marker configure "exclShade" \
     804    set x2 [$graph(plot) xaxis invtransform $x]
     805    if { ![$graph(plot) marker exists "exclShade"] } {
     806        $graph(plot) marker create polygon -name "exclShade" -under 1 -fill yellow
     807    }
     808    $graph(plot) marker configure "exclShade" \
    987809            -coords "$x1 -Inf $x1 +Inf $x2 +Inf $x2 -Inf"
    988810}
    989811
    990812proc exclDone {bindtag x y} {
    991     global box graph hst
    992     bind $box <Motion> {}
     813    global graph
     814    bind $graph(plot) <Motion> {}
    993815    bind $bindtag <1> "exclAdd $bindtag %x %y"
    994816    set x1 $graph(excl-x1)
    995     set x2 [$box xaxis invtransform $x]
     817    set x2 [$graph(plot) xaxis invtransform $x]
     818    set hst $graph(hst)
    996819    if {$graph(xunits) == 1} {
    997820        set x1 [fromd $x1 $hst]
     
    1002825    }
    1003826    catch {
    1004         $box marker delete "exclShade"
    1005     }
    1006     .g marker delete AddExclLbl
     827        $graph(plot) marker delete "exclShade"
     828    }
     829    $graph(plot) marker delete AddExclLbl
    1007830    # get the points in the range
    1008831    set l [lsort -integer [allxvec search $x1 $x2]]
     
    1041864    }
    1042865    if {$ans == "ok"} {
    1043         global changes
    1044         incr changes
    1045         global hst
     866        global expgui
     867        incr expgui(changed)
     868        set hst $graph(hst)
    1046869        set exclist [histinfo $hst excl]
    1047870        lappend exclist [list $p1 $p2]
     
    1065888
    1066889proc CheckForOverlappingRegions {exclist} {
     890    global expgui graph
    1067891    set exclist [lsort -real -index 0 $exclist]
    1068892    set prvlow -1
     
    1076900        if {$low < $prvhigh && $i != 0} {
    1077901            set exclist [lreplace $exclist $ip $i [list $prvlow $high]]
     902            incr expgui(changed)
    1078903            set prvhigh $high
    1079904            continue
     
    1085910            if {[llength $seppts] == 0} {
    1086911                set exclist [lreplace $exclist $ip $i [list $prvlow $high]]
     912                incr expgui(changed)
    1087913                set prvhigh $high
    1088914                continue
     
    1093919        set prvhigh $high
    1094920    }
    1095     global hst
    1096     histinfo $hst excl set $exclist
     921    histinfo $graph(hst) excl set $exclist
    1097922}
    1098923
    1099924proc setminormax {} {
    1100     set link excledt.html
     925    global expmap graph expgui
     926    if {[string trim [string range $expmap(htype_$graph(hst)) 3 3]] == "D"} {
     927        if {[string range $expmap(htype_$graph(hst)) 2 2] == "T"} {
     928            set fac 1000.
     929        } elseif {[string range $expmap(htype_$graph(hst)) 2 2] == "E"} {
     930            set fac 1.
     931        } else {
     932            set fac 100.
     933        }           
     934        set start [expr {[histinfo $graph(hst) dstart]/$fac}]
     935        set step  [expr {[histinfo $graph(hst) dstep]/$fac}]
     936        set points [histinfo $graph(hst) dpoints]
     937        set end [expr {$start + $points*$step}]
     938        SetDummyRangeBox $graph(hst) $start $end $step
     939        return
     940    }
    1101941    set box .limit
    1102942    toplevel $box
     943    wm title $box "Set usable range"
     944    set link excledt.html
    1103945    grid [button $box.help -text Help -bg yellow \
    1104946            -command "MakeWWWHelp $link"] -col 98 -row 0
    1105947    bind $box <Key-F1> "MakeWWWHelp $link"
    1106     global hst expmap graph expnam
    1107 
     948
     949    set hst $graph(hst)
    1108950    if {$graph(xunits) == 1} {
    1109951        set var d
     
    1127969    if {$graph(xunits) != 0} {
    1128970    }
    1129     grid [label $box.t -text "Set usable data range"] -col 0 -columnspan 4 -row 0
     971    grid [label $box.t -text "Set usable data range, histogram $hst"] \
     972            -col 0 -columnspan 4 -row 0
    1130973    grid [label $box.lu -text "($unit)"] -col 2 -row 1 -rowspan 2
    1131974    grid [label $box.lmn -text "$var minimum"] -col 0 -row 1
     
    11571000    # fix grab...
    11581001    afterputontop
    1159     global changes
     1002
    11601003    set highchange 0
    1161     set startchanges $changes
     1004    set startchanges $expgui(changed)
    11621005    catch {
    11631006        if {$graph(tmin) != $start(tmin)} {
    1164             incr changes
     1007            incr expgui(changed)
    11651008            if {$graph(xunits) == 1} {
    11661009                set tmax [fromd $graph(tmin) $hst]
     
    11811024    catch {
    11821025        if {$graph(tmax) != $start(tmax)} {
    1183             incr changes
     1026            incr expgui(changed)
    11841027            if {$graph(xunits) == 1} {
    11851028                set tmin [fromd $graph(tmax) $hst]
     
    12001043        }
    12011044    }
    1202     if {$startchanges != $changes} {
     1045    if {$startchanges != $expgui(changed)} {
    12031046        histinfo $hst excl set $exclist
    12041047        CheckForOverlappingRegions $exclist
     
    12171060    }
    12181061}
     1062
    12191063proc HighLimitChanged {} {
    1220     global expnam graph
     1064    global graph expgui
    12211065    set msg "The upper data limit has changed.\nYou must run POWPREF to "
    12221066    append msg "to see the full range of data displayed. Do you want to "
     
    12261070            -type {Skip {Run POWPREF} {Run POWPREF & GENLES}}]
    12271071    if {$ans == "skip"} {
    1228         expwrite $expnam
    12291072        updateplot
    12301073        return
    12311074    } elseif {$ans == "run powpref"} {
    12321075        set cmd powpref
    1233         set cycsav {}
    1234     } else {
    1235         set cycsav [expinfo cycles]
     1076    } else {
    12361077        set cmd "powpref genles"
    12371078        expinfo cycles set 0
    12381079    }
    1239     expwrite $expnam.EXP
    1240     global expgui env
    1241     set expgui(autoexpload) 0
    1242     set expgui(archive) 0
    1243     set expgui(expfile) $expnam.EXP
    1244     set env(GSASBACKSPACE) 0
    1245     set expgui(autoiconify) 0
     1080    set auto $expgui(autoexpload)
     1081    set expgui(autoexpload) 1
     1082    #set expgui(autoiconify) 0
    12461083    runGSASwEXP $cmd
     1084    set expgui(autoexpload) $auto
    12471085    updateplot
    1248     CheckTmax $cycsav
     1086    CheckTmax
    12491087}
    12501088
    12511089# find out what the maximum point really is
    1252 proc CheckTmax {cycsav} {
     1090proc CheckTmax {} {
     1091    global graph expgui
    12531092    # clone xvec
    12541093    xvec dup temp
    1255     global graph hst expnam
     1094    set hst $graph(hst)
    12561095    if {$graph(xunits) == 1} {
    12571096        temp sort
     
    12901129        if {$ans == "ok"} {
    12911130            set item [list [expr $max+$step] [lindex [lindex $exclist end] 1]]
     1131            incr expgui(changed)
    12921132            set exclist [lreplace $exclist end end $item]
    12931133            histinfo $hst excl set $exclist
    1294             if {$cycsav != ""} {
    1295                 expinfo cycles set $cycsav
    1296             }
    1297             expwrite $expnam.EXP
    12981134            updateplot
    12991135            return
    13001136        }
    13011137    }
    1302     if {$cycsav != ""} {
    1303         expinfo cycles set $cycsav
    1304         expwrite $expnam.EXP
    1305     }
    13061138}
    13071139
    13081140proc CheckChanges {} {
    1309     global changes hst graph
    1310     if {$changes == 0} return
    1311     set msg "The excluded regions have changed.\nYou must run POWPREF before "
    1312     append msg "running GENLES. Do you want to run POWPREF and possibly "
     1141    global expgui graph
     1142    set hst $graph(hst)
     1143    if {$expgui(changed) == 0} return
     1144    set msg "The excluded regions/ranges have changed.\nYou must run POWPREF before "
     1145    append msg "running GENLES. Do you want to run POWPREF and optionally "
    13131146    append msg "GENLES with zero cycles now?"
    13141147    set ans [MyMessageBox -parent . -message $msg -title "Process limits?"\
    13151148            -helplink "expguierr.html ProcessRegions" \
    13161149            -type {Skip {Run POWPREF} {Run POWPREF & GENLES}}]
    1317     global expgui env expnam
     1150    global expgui env
    13181151    if {$ans == "run powpref"} {
    13191152        set cmd powpref
    1320         set cycsav {}
    13211153    } elseif {$ans == "skip"} {
    1322         expwrite $expnam.EXP
    13231154        return
    13241155    } else {
    1325         set cycsav [expinfo cycles]
    13261156        set cmd "powpref genles"
    13271157        expinfo cycles set 0
    13281158    }
    1329     expwrite $expnam.EXP
    1330     set expgui(autoexpload) 0
    1331     set expgui(archive) 0
    1332     set expgui(expfile) $expnam.EXP
    1333     set env(GSASBACKSPACE) 0
    1334     set expgui(autoiconify) 0
     1159    set auto $expgui(autoexpload)
     1160    set expgui(autoexpload) 1
     1161    #set expgui(autoiconify) 0
    13351162    runGSASwEXP $cmd
    1336     set changes 0
    1337     CheckTmax $cycsav
     1163    set expgui(autoexpload) $auto
    13381164}
    13391165
    13401166proc EditExclRegion {reg "msg {}"} {
    1341     global graph hst expmap changes
    1342     set startchanges $changes
     1167    global graph expmap expgui
     1168    set hst $graph(hst)
     1169    set startchanges $expgui(changed)
    13431170    set exclist [histinfo $hst excl]
    13441171    set oldtmax [lindex [lindex $exclist end] 0]
     
    13461173    set range [lindex $exclist $i]
    13471174    toplevel [set box .edit]
     1175    wm title $box "Edit excluded region"
    13481176    set beg minimum
    13491177    set end maximum
     
    14331261        }
    14341262        set exclist [lreplace $exclist $i $i [lreplace $range 0 0 $tmin]]
    1435         incr changes
     1263        incr expgui(changed)
    14361264    }
    14371265    if {$tmax != $graph(tmax)} {
     
    14501278        }
    14511279        set exclist [lreplace $exclist $i $i [lreplace $range 1 1 $tmax]]
    1452         incr changes
    1453     }
    1454     if {$changes != $startchanges} {
     1280        incr expgui(changed)
     1281    }
     1282    if {$expgui(changed) != $startchanges} {
    14551283        histinfo $hst excl set $exclist
    14561284        CheckForOverlappingRegions $exclist
     
    14801308# put the background regions into buttons
    14811309proc FillExclRegionBox {} {
    1482     global graph hst
     1310    global graph expmap
     1311    set hst $graph(hst)
    14831312    set can $graph(ExclCanvas)
    14841313    set scroll $graph(ExclScroll)
     
    14891318    set exclist [histinfo $hst excl]
    14901319    set col 0
    1491     foreach rng $exclist {
     1320    if {[string trim [string range $expmap(htype_$graph(hst)) 3 3]] == "D"} {
     1321        $graph(bbox).bl.1 config -text "Dummy\nHistogram"       
     1322        foreach c {2 3} {
     1323            $graph(bbox).l.b$c config -state disabled
     1324        }
     1325        if {[string range $expmap(htype_$graph(hst)) 2 2] == "T"} {
     1326            set fac 1000.
     1327        } elseif {[string range $expmap(htype_$graph(hst)) 2 2] == "E"} {
     1328            set fac 1.
     1329        } else {
     1330            set fac 100.
     1331        }           
     1332        set start [expr {[histinfo $graph(hst) dstart]/$fac}]
     1333        set step  [expr {[histinfo $graph(hst) dstep]/$fac}]
     1334        set points [histinfo $graph(hst) dpoints]
     1335        set end [expr {$start + $points*$step}]
     1336        grid [label $top.$col -text "Range:" \
     1337                    -padx 0 -pady 1 -bd 4] \
     1338                    -row 0 -col $col
     1339        incr col
    14921340        if {$graph(xunits) == 1} {
    1493             set rng [tod $rng $hst]
    1494             if {$col == 0} {
    1495                 set lbl ">[format %.4f [lindex $rng 1]]"
     1341            foreach i {min max} \
     1342                    v [lsort -real [tod [list $start $end] $graph(hst)]] {
     1343                grid [label $top.$col -text "$i\n[format %.4f $v]" \
     1344                        -padx 3 -pady 1 -bd 2 -relief groove] \
     1345                        -row 0 -col $col -sticky ns
     1346                incr col
     1347            }
     1348            grid [label $top.$col -text "\xc5" \
     1349                    -padx 0 -pady 1 -bd 4] \
     1350                    -row 0 -col $col -sticky nsw -ipadx 5
     1351            incr col
     1352            grid [label $top.$col -text "points\n$points" \
     1353                    -padx 3 -pady 1 -bd 2 -relief groove] \
     1354                    -row 0 -col $col -sticky ns
     1355            incr col
     1356        } elseif {$graph(xunits) == 2} {
     1357            foreach i {min max} \
     1358                    v [lsort -real [toQ [list $start $end] $graph(hst)]] {
     1359                grid [label $top.$col -text "$i\n[format %.3f $v]" \
     1360                        -padx 3 -pady 1 -bd 2 -relief groove] -row 0 -col $col -sticky ns
     1361                incr col
     1362            }
     1363            grid [label $top.$col -text "\xc5" \
     1364                    -padx 0 -pady 1] \
     1365                    -row 0 -col $col
     1366            incr col
     1367            grid [label $top.$col -text "-1\n" \
     1368                    -padx 0 -pady 0] \
     1369                    -row 0 -col $col -sticky nsw -ipadx 5
     1370            incr col
     1371            grid [label $top.$col -text "points\n$points" \
     1372                    -padx 3 -pady 1 -bd 2 -relief groove] -row 0 -col $col -sticky ns
     1373            incr col
     1374        } else {
     1375            foreach i {start step end} {
     1376                grid [label $top.$col -text "$i\n[set $i]" \
     1377                        -padx 3 -pady 1 -bd 2 -relief groove] \
     1378                        -row 0 -col $col -sticky ns
     1379                incr col
     1380            }
     1381        }
     1382        grid [button $top.b$col -text "Set" \
     1383                -command "SetDummyRangeBox $graph(hst) $start $end $step"] \
     1384                -sticky ns -row 0 -col $col
     1385    } else {
     1386        $graph(bbox).bl.1 config -text "Excluded\nRegions"
     1387        foreach c {2 3} {
     1388            $graph(bbox).l.b$c config -state normal
     1389        }
     1390        foreach rng $exclist {
     1391            if {$graph(xunits) == 1} {
     1392                set rng [tod $rng $hst]
     1393                if {$col == 0} {
     1394                    set lbl ">[format %.4f [lindex $rng 1]]"
     1395                } else {
     1396                    set lbl "[format %.4f [lindex $rng 0]]\nto [format %.4f [lindex $rng 1]]"
     1397                }
     1398                incr col
     1399                if {$col == [llength $exclist]} {
     1400                    set lbl "<[format %.4f [lindex $rng 0]]"
     1401                }
    14961402            } else {
    1497                 set lbl "[format %.4f [lindex $rng 0]]\nto [format %.4f [lindex $rng 1]]"
    1498             }
    1499             incr col
    1500             if {$col == [llength $exclist]} {
    1501                 set lbl "<[format %.4f [lindex $rng 0]]"
    1502             }
    1503         } else {
    1504             if {$graph(xunits) == 2} {
    1505                 set rng [toQ $rng $hst]
    1506             }
    1507             if {$col == 0} {
    1508                 set lbl "<[format %.3f [lindex $rng 1]]"
    1509             } else {
    1510                 set lbl "[format %.3f [lindex $rng 0]]\nto [format %.3f [lindex $rng 1]]"
    1511             }
    1512             incr col
    1513             if {$col == [llength $exclist]} {
    1514                 set lbl ">[format %.3f [lindex $rng 0]]"
    1515             }
    1516         }
    1517         grid [button $top.$col -text $lbl -command "EditExclRegion $col" \
    1518                 -padx 1 -pady 1] -row 0 -col $col -sticky  ns
     1403                if {$graph(xunits) == 2} {
     1404                    set rng [toQ $rng $hst]
     1405                }
     1406                if {$col == 0} {
     1407                    set lbl "<[format %.3f [lindex $rng 1]]"
     1408                } else {
     1409                    set lbl "[format %.3f [lindex $rng 0]]\nto [format %.3f [lindex $rng 1]]"
     1410                }
     1411                incr col
     1412                if {$col == [llength $exclist]} {
     1413                    set lbl ">[format %.3f [lindex $rng 0]]"
     1414                }
     1415            }
     1416            grid [button $top.$col -text $lbl -command "EditExclRegion $col" \
     1417                    -padx 1 -pady 1] -row 0 -col $col -sticky  ns
     1418        }
    15191419    }
    15201420    update idletasks
     
    15301430}
    15311431
    1532 source [file join $expgui(scriptdir) gsascmds.tcl]
    1533 source [file join $expgui(scriptdir) readexp.tcl]
    1534 if {$tcl_platform(platform) == "windows"} {
    1535     # platform-specific code
    1536     if {$tcl_platform(os) == "Windows 95"} {
    1537         if [catch {package require winexec}] {
    1538             MyMessageBox -parent . -title "WINEXEC Error" \
    1539                     -message "Error -- Unable to load the WINEXEC package. This is needed in Win95 machines" \
    1540                     -icon error -type Quit -default quit \
    1541                     -helplink "expgui_Win_readme.html Winexec"
    1542             destroy .
    1543         }
    1544     }
    1545     set graph(printout) 1
    1546 } else {
    1547     set graph(printout) 0
    1548 }
    1549 
    1550 # do not need archiving or checking for changed files here
    1551 proc savearchiveexp {} {}
    1552 proc whenidle {} {}
    1553 
    1554 source [file join $expgui(scriptdir) opts.tcl]
    1555 # override options with locally defined values
    1556 if [file exists [file join $expgui(scriptdir) localconfig]] {
    1557     source [file join $expgui(scriptdir) localconfig]
    1558 }
    1559 if [file exists [file join ~ .gsas_config]] {
    1560     source [file join ~ .gsas_config]
    1561 }
    1562 SetTkDefaultOptions $expgui(font)
    1563 
    1564 # vectors
    1565 foreach vec {allxvec xvec obsvec calcvec diffvec exxvec exobsvec} {
    1566     vector $vec
    1567     $vec notify never
    1568 }
    1569 # create the graph
    1570 if [catch {
    1571     set box [graph .g -plotbackground white]
    1572 } errmsg] {
    1573     tk_dialog .err "BLT Error" \
    1574 "BLT Setup Error: could not create a graph (msg: $errmsg). \
    1575 There is a problem with the setup of BLT on your system.
     1432# manual zoom option
     1433proc BLTmanualZoom {} {
     1434    global graph
     1435    catch {toplevel .zoom}
     1436    wm title .zoom "Manual zoom"
     1437    eval destroy [grid slaves .zoom]
     1438    raise .zoom
     1439    wm title .zoom {Manual Scaling}
     1440    grid [label .zoom.l1 -text minimum] -row 1 -column 2
     1441    grid [label .zoom.l2 -text maximum] -row 1 -column 3
     1442    grid [label .zoom.l3 -text x] -row 2 -column 1
     1443    grid [label .zoom.l4 -text y] -row 3 -column 1
     1444    grid [entry .zoom.xmin -textvariable graph(xmin) -width 10] -row 2 -column 2
     1445    grid [entry .zoom.xmax -textvariable graph(xmax) -width 10] -row 2 -column 3
     1446    grid [entry .zoom.ymin -textvariable graph(ymin) -width 10] -row 3 -column 2
     1447    grid [entry .zoom.ymax -textvariable graph(ymax) -width 10] -row 3 -column 3
     1448    grid [frame .zoom.b] -row 4 -column 1 -columnspan 3
     1449    grid [button .zoom.b.1 -text "Set Scaling" \
     1450             -command "SetManualZoom set"]  -row 4 -column 1 -columnspan 2
     1451    grid [button .zoom.b.2 -text Reset \
     1452            -command "SetManualZoom clear"] -row 4 -column 3
     1453    grid [button .zoom.b.3 -text Close -command "destroy .zoom"] -row 4 -column 4
     1454    grid rowconfigure .zoom 1 -weight 1 -pad 5
     1455    grid rowconfigure .zoom 2 -weight 1 -pad 5
     1456    grid rowconfigure .zoom 3 -weight 1 -pad 5
     1457    grid rowconfigure .zoom 4 -weight 0 -pad 5
     1458    grid columnconfigure .zoom 1 -weight 1 -pad 20
     1459    grid columnconfigure .zoom 1 -weight 1
     1460    grid columnconfigure .zoom 3 -weight 1 -pad 10
     1461    foreach item {min min max max} \
     1462            format {3   2   3   2} \
     1463            axis   {x   y   x   y} {
     1464        set val [$graph(plot) ${axis}axis cget -${item}]
     1465        set graph(${axis}${item}) {(auto)}
     1466        catch {set graph(${axis}${item}) [format %.${format}f $val]}
     1467    }
     1468    putontop .zoom
     1469    tkwait window .zoom
     1470    afterputontop   
     1471}
     1472
     1473proc SetManualZoom {mode} {
     1474    global graph
     1475    if {$mode == "clear"} {
     1476        foreach item {xmin ymin xmax ymax} {
     1477            set graph($item) {(auto)}
     1478        }
     1479    }
     1480    foreach item {xmin ymin xmax ymax} {
     1481        set $item {}
     1482        catch {set $item [expr $graph($item)]} 
     1483    }
     1484    # reset the zoomstack
     1485    catch {Blt_ZoomStack $graph(plot)}
     1486    catch {$graph(plot) xaxis config -min $xmin -max $xmax}
     1487    catch {$graph(plot) yaxis config -min $ymin -max $ymax}
     1488}
     1489
     1490# code to create the EXCLEDT box
     1491proc ShowExcl {} {
     1492    global graph peakinfo expgui expmap
     1493    # save the starting number of cycles
     1494    set cycsav [expinfo cycles]
     1495    set graph(hst) [lindex $expgui(curhist) 0]
     1496    if {[llength $expgui(curhist)] == 0} {
     1497        set graph(hst) [lindex $expmap(powderlist) 0]
     1498    } else {
     1499        set graph(hst) [lindex $expmap(powderlist) $graph(hst)]
     1500    }   
     1501    set graph(exclbox) .excl
     1502    catch {toplevel $graph(exclbox)}
     1503    wm title $graph(exclbox) "Excluded Region/Data Range Edit"
     1504    eval destroy [winfo children $graph(exclbox)]
     1505    # create the graph
     1506    if [catch {
     1507        set graph(plot) [graph $graph(exclbox).g -plotbackground white]
     1508    } errmsg] {
     1509        MyMessageBox -parent . -title "BLT Error" \
     1510                -message "BLT Setup Error: could not create a graph \
     1511(error msg: $errmsg). \
     1512There is a problem with the setup of BLT on your system. \
    15761513See the expgui.html file for more info." \
    1577             error 0 "Quit"
    1578 exit
    1579 }
    1580 
    1581 if [catch {
    1582     Blt_ZoomStack $box
    1583 } errmsg] {
    1584     tk_dialog .err "BLT Error" \
    1585 "BLT Setup Error: could not access a Blt_ routine (msg: $errmsg). \
     1514        -helplink "expgui.html blt" \
     1515        -icon warning -type Skip -default "skip"
     1516        destroy $graph(exclbox)
     1517        return
     1518    }
     1519    if [catch {
     1520        Blt_ZoomStack $graph(plot)
     1521    } errmsg] {
     1522        MyMessageBox -parent . -title "BLT Error" \
     1523                -message "BLT Setup Error: could not access a Blt_ routine \
     1524(msg: $errmsg). \
    15861525The pkgIndex.tcl is probably not loading bltGraph.tcl.
    15871526See the expgui.html file for more info." \
    1588             error 0 "Limp ahead"
    1589 }
    1590 
    1591 $box element create 3 -color black -linewidth 0 -label Obs \
    1592         -symbol $peakinfo(obssym) -color $graph(color_obs) \
    1593         -pixels [expr 0.125 * $peakinfo(obssize)]i
    1594 $box element create 2 -label Calc -color $graph(color_calc)  -symbol none 
    1595 $box element create 12 -line 0 -label "Excl" -color $graph(color_excl) \
    1596         -symbol $peakinfo(exclsym) \
    1597         -pixels [expr 0.15 * $peakinfo(exclsize)]i
    1598 $box element show "3 2 12 1"
    1599 $box element config 3 -xdata xvec -ydata obsvec
    1600 $box element config 2 -xdata xvec -ydata calcvec
    1601 $box element config 12 -xdata exxvec -ydata exobsvec
    1602 
    1603 $box yaxis config -title {}
    1604 setlegend $box $graph(legend)
    1605 
    1606 frame .a -bd 3 -relief groove
    1607 pack [menubutton .a.file -text File -underline 0 -menu .a.file.menu] -side left
    1608 menu .a.file.menu
    1609 .a.file.menu add cascade -label Tickmarks -menu .a.file.menu.tick
    1610 menu .a.file.menu.tick
    1611 foreach num {1 2 3 4 5 6 7 8 9} {
    1612     .a.file.menu.tick add checkbutton -label "Phase $num" \
    1613             -variable  peakinfo(flag$num)
    1614 }
    1615 .a.file.menu add cascade -label Histogram -menu .a.file.menu.hist -state disabled
    1616 
    1617 .a.file.menu add command -label "Set Min/Max Range" -command setminormax
    1618 .a.file.menu add command -label "Update Plot" -command "CheckChanges;updateplot"
    1619 .a.file.menu add command -label "Make PostScript" -command makepostscriptout
    1620 .a.file.menu add command -label Exit -command "CheckChanges;exit"
    1621 
    1622 pack [menubutton .a.options -text Options -underline 0 -menu .a.options.menu] \
    1623         -side left   
    1624 menu .a.options.menu
    1625 .a.options.menu add cascade -label "Configure Tickmarks" -menu .a.options.menu.tick
    1626 menu .a.options.menu.tick
    1627 .a.options.menu.tick add radiobutton -label "Manual Placement" \
    1628         -value 0 -variable expgui(autotick) -command plotdata
    1629 .a.options.menu.tick add radiobutton -label "Auto locate" \
    1630         -value 1 -variable expgui(autotick) -command plotdata
    1631 .a.options.menu.tick add separator
    1632 foreach num {1 2 3 4 5 6 7 8 9} {
    1633     .a.options.menu.tick add command -label "Phase $num" \
    1634             -command "minioptionsbox $num"
    1635 }
    1636 .a.options.menu add cascade -label "Symbol Type" -menu .a.options.menu.sym
    1637 menu .a.options.menu.sym
    1638 foreach var {excl obs} lbl {Excluded Observed} {
    1639     .a.options.menu.sym add command -label $lbl -command "getsymopts $var"
    1640 }
    1641 
    1642 .a.options.menu add cascade -label "Symbol color" -menu .a.options.menu.color
    1643 menu .a.options.menu.color
    1644 foreach var {excl calc obs} lbl {Excluded Calculated Observed} {
    1645     .a.options.menu.color add command -label $lbl \
    1646         -command "set graph(color_$var) \[tk_chooseColor -initialcolor \$graph(color_$var) -title \"Choose \$lbl color\"]; plotdata"
    1647 }
    1648 .a.options.menu add cascade -label "X units" -menu .a.options.menu.xunits
    1649 menu .a.options.menu.xunits
    1650 .a.options.menu.xunits add radiobutton -label "As collected" \
    1651         -variable graph(xunits) -value 0 \
    1652         -command updateplot
    1653 .a.options.menu.xunits add radiobutton -label "d-space" \
    1654         -variable graph(xunits) -value 1 \
    1655         -command updateplot
    1656 .a.options.menu.xunits add radiobutton -label "Q" \
    1657         -variable graph(xunits) -value 2 \
    1658         -command updateplot
     1527        -helplink "expgui.html blt" \
     1528        -icon warning -type {"Limp Ahead"} -default "limp Ahead"
     1529    }
     1530    $graph(plot) element create 3 -color black -linewidth 0 -label Obs \
     1531            -symbol $peakinfo(obssym) -color $graph(color_obs) \
     1532            -pixels [expr 0.125 * $peakinfo(obssize)]i
     1533    $graph(plot) element create 2 -label Calc -color $graph(color_calc) \
     1534            -symbol none 
     1535    $graph(plot) element create 12 -line 0 -label "Excl" \
     1536            -color $graph(color_excl) \
     1537            -symbol $peakinfo(exclsym) \
     1538            -pixels [expr 0.15 * $peakinfo(exclsize)]i
     1539    $graph(plot) element show "3 2 12 1"
     1540    $graph(plot) element config 3 -xdata xvec -ydata obsvec
     1541    $graph(plot) element config 2 -xdata xvec -ydata calcvec
     1542    $graph(plot) element config 12 -xdata exxvec -ydata exobsvec
     1543
     1544    $graph(plot) yaxis config -title {}
     1545    setlegend $graph(plot) $graph(legend)
     1546
     1547    set graph(exclmenu) [frame $graph(exclbox).a -bd 3 -relief groove]
     1548    pack [menubutton $graph(exclmenu).file -text File -underline 0 \
     1549            -menu $graph(exclmenu).file.menu] -side left
     1550    menu $graph(exclmenu).file.menu
     1551    $graph(exclmenu).file.menu add cascade -label Tickmarks \
     1552            -menu $graph(exclmenu).file.menu.tick
     1553    menu $graph(exclmenu).file.menu.tick
     1554    foreach num {1 2 3 4 5 6 7 8 9} {
     1555        $graph(exclmenu).file.menu.tick add checkbutton -label "Phase $num" \
     1556                -variable peakinfo(flag$num)
     1557    }
     1558    $graph(exclmenu).file.menu add cascade -label Histogram \
     1559            -menu $graph(exclmenu).file.menu.hist -state disabled
     1560
     1561    $graph(exclmenu).file.menu add command \
     1562            -label "Set Min/Max Range" -command setminormax
     1563    $graph(exclmenu).file.menu add command \
     1564            -label "Update Plot" -command "CheckChanges;updateplot"
     1565    $graph(exclmenu).file.menu add command \
     1566            -label "Make PostScript" -command makepostscriptout
     1567    $graph(exclmenu).file.menu add command \
     1568            -label Finish -command "CheckChanges;destroy $graph(exclbox)"
     1569
     1570    pack [menubutton $graph(exclmenu).options -text Options -underline 0 \
     1571            -menu $graph(exclmenu).options.menu] \
     1572            -side left   
     1573    menu $graph(exclmenu).options.menu
     1574    $graph(exclmenu).options.menu add cascade -label "Configure Tickmarks" \
     1575            -menu $graph(exclmenu).options.menu.tick
     1576    menu $graph(exclmenu).options.menu.tick
     1577    $graph(exclmenu).options.menu.tick add radiobutton \
     1578            -label "Manual Placement" \
     1579            -value 0 -variable expgui(autotick) -command plotdata
     1580    $graph(exclmenu).options.menu.tick add radiobutton \
     1581            -label "Auto locate" \
     1582            -value 1 -variable expgui(autotick) -command plotdata
     1583    $graph(exclmenu).options.menu.tick add separator
     1584    foreach num {1 2 3 4 5 6 7 8 9} {
     1585        $graph(exclmenu).options.menu.tick add command -label "Phase $num" \
     1586                -command "minioptionsbox $num"
     1587    }
     1588    $graph(exclmenu).options.menu add cascade -label "Symbol Type" \
     1589            -menu $graph(exclmenu).options.menu.sym
     1590    menu $graph(exclmenu).options.menu.sym
     1591    foreach var {excl obs} lbl {Excluded Observed} {
     1592        $graph(exclmenu).options.menu.sym add command -label $lbl \
     1593                -command "getsymopts $var"
     1594    }
     1595
     1596    $graph(exclmenu).options.menu add cascade -label "Symbol color" \
     1597            -menu $graph(exclmenu).options.menu.color
     1598    menu $graph(exclmenu).options.menu.color
     1599    foreach var {excl calc obs} lbl {Excluded Calculated Observed} {
     1600        $graph(exclmenu).options.menu.color add command -label $lbl \
     1601                -command "set graph(color_$var) \[tk_chooseColor -initialcolor \$graph(color_$var) -title \"Choose \$lbl color\"]; plotdata"
     1602    }
     1603    $graph(exclmenu).options.menu add cascade -label "X units" \
     1604            -menu $graph(exclmenu).options.menu.xunits
     1605    menu $graph(exclmenu).options.menu.xunits
     1606    $graph(exclmenu).options.menu.xunits add radiobutton \
     1607            -label "As collected" \
     1608            -variable graph(xunits) -value 0 \
     1609            -command updateplot
     1610    $graph(exclmenu).options.menu.xunits add radiobutton -label "d-space" \
     1611            -variable graph(xunits) -value 1 \
     1612            -command updateplot
     1613    $graph(exclmenu).options.menu.xunits add radiobutton -label "Q" \
     1614            -variable graph(xunits) -value 2 \
     1615            -command updateplot
     1616
     1617    $graph(exclmenu).options.menu add checkbutton -label "Include legend" \
     1618            -variable graph(legend) \
     1619            -command {setlegend $graph(plot) $graph(legend)}
     1620    $graph(exclmenu).options.menu add checkbutton -label "Prompt on add/del" \
     1621            -variable graph(exclPrompt)
     1622    $graph(exclmenu).options.menu add command -label "Set PS output" \
     1623            -command setpostscriptout
     1624
     1625    set graph(bbox) [set bb $graph(exclbox).b]
     1626    catch {pack [frame $bb -bd 3 -relief sunken] -side bottom -fill both}
     1627    grid [label $bb.top -text "Excluded Region Editing"] \
     1628            -col 0 -row 0 -columnspan 4
     1629    grid [button $bb.help -text Help -bg yellow \
     1630            -command "MakeWWWHelp excledt.html"] \
     1631            -column 5 -row 0 -rowspan 1 -sticky ne
    16591632   
    1660 .a.options.menu add checkbutton -label "Include legend" \
    1661         -variable graph(legend) \
    1662         -command {setlegend $box $graph(legend)}
    1663 .a.options.menu add checkbutton -label "Prompt on add/del" \
    1664         -variable graph(exclPrompt)
    1665 .a.options.menu add command -label "Set PS output" -command setpostscriptout
    1666 
    1667 .a.options.menu add cascade -menu  .a.options.menu.font \
    1668         -label "Screen font"
    1669 menu .a.options.menu.font
    1670 foreach f {10 11 12 13 14 16 18 20 22} {
    1671     .a.options.menu.font add radiobutton \
    1672             -command {SetTkDefaultOptions $expgui(font); ResizeFont .} \
    1673         -label $f -value $f -variable expgui(font) -font "Helvetica -$f"
    1674 }
    1675 .a.options.menu add command -label "Save Options" -command "SaveOptions"
    1676 
    1677 set bb .b
    1678 catch {pack [frame $bb -bd 3 -relief sunken] -side bottom -fill both}
    1679 grid [label $bb.top -text "Excluded Region Editing"] \
    1680         -col 0 -row 0 -columnspan 4
    1681 grid [button $bb.help -text Help -bg yellow \
    1682         -command "MakeWWWHelp excledt.html"] \
    1683         -column 5 -row 0 -rowspan 1 -sticky ne
     1633    grid [frame $bb.l -bd 3 -relief groove] \
     1634            -col 0 -row 1 -columnspan 2 -sticky nse
     1635    grid [label $bb.l.1 -text "Mouse click\naction"] -col 0 -row 0
     1636    foreach c {1 2 3} l {zoom "Add\nregion" "Delete\nregion"} {
     1637        grid [button $graph(bbox).l.b$c -text $l -command "exclEditMode $c $bb"] \
     1638                -col $c -row 0 -sticky ns
     1639    }
     1640    exclEditMode 1 $bb
     1641
     1642    grid [frame $bb.bl] \
     1643            -col 0 -row 3 -rowspan 2 -sticky nsew
     1644    grid [label $graph(bbox).bl.1 -text "Excluded\nRegions"] -col 0 -row 0
     1645    grid [canvas [set graph(ExclCanvas) $bb.bc] \
     1646            -scrollregion {0 0 5000 500} -width 0 -height 0 \
     1647            -xscrollcommand "$bb.bs set"] \
     1648            -column 1 -row 3 -columnspan 5 -sticky nsew
     1649    grid [scrollbar [set  graph(ExclScroll) $bb.bs] -command "$bb.bc xview" \
     1650            -orient horizontal] \
     1651            -column 1 -row 4 -columnspan 5 -sticky nsew
     1652    grid [button $bb.cw -text "Save &\nFinish" \
     1653            -command "CheckChanges;destroy $graph(exclbox)"] \
     1654        -col 4 -row 1 -columnspan 2 -sticky ns
     1655
     1656    grid columnconfigure $bb 1 -weight 1
     1657    grid columnconfigure $bb 5 -weight 1
     1658    grid rowconfigure $bb 3 -weight 1
     1659    grid rowconfigure $bb 5 -weight 1
    16841660   
    1685 grid [frame $bb.l -bd 3 -relief groove] \
    1686         -col 0 -row 1 -columnspan 2 -sticky nse
    1687 grid [label $bb.l.1 -text "Mouse click\naction"] -col 0 -row 0
    1688 foreach c {1 2 3} l {zoom "Add\nregion" "Delete\nregion"} {
    1689     grid [button $bb.l.b$c -text $l -command "exclEditMode $c $bb"] \
    1690             -col $c -row 0 -sticky ns
    1691 }
    1692 exclEditMode 1 $bb
    1693 #grid [button $bb.mnmx -text "Min/Max\nRange" -command setminormax] \
    1694 #       -col 4 -columnspan 2 -row 1 -sticky e
    1695 
    1696 grid [frame $bb.bl] \
    1697         -col 0 -row 3 -rowspan 2 -sticky nsew
    1698 grid [label $bb.bl.1 -text "Excluded\nRegions"] -col 0 -row 0
    1699 grid [canvas [set graph(ExclCanvas) $bb.bc] \
    1700         -scrollregion {0 0 5000 500} -width 0 -height 0 \
    1701         -xscrollcommand "$bb.bs set"] \
    1702         -column 1 -row 3 -columnspan 5 -sticky nsew
    1703 grid [scrollbar [set  graph(ExclScroll) $bb.bs] -command "$bb.bc xview" \
    1704         -orient horizontal] \
    1705         -column 1 -row 4 -columnspan 5 -sticky nsew
    1706 grid [button $bb.cw -text "Save\n& Exit" \
    1707         -command "CheckChanges;exit"] \
    1708         -col 4 -row 1 -columnspan 2 -sticky ns
    1709 #grid [button $bb.cq -text "Quit" \
    1710 #       -command "exit"] \
    1711 #       -col 5 -row 3 -rowspan 2 -sticky ns
    1712 
    1713 grid columnconfigure $bb 1 -weight 1
    1714 #grid columnconfigure $bb 2 -weight 1
    1715 #grid columnconfigure $bb 3 -weight 1
    1716 grid columnconfigure $bb 5 -weight 1
    1717 grid rowconfigure $bb 3 -weight 1
    1718 grid rowconfigure $bb 5 -weight 1
    1719 #    .g config -title ""
    1720 
    1721 pack [menubutton .a.help -text Help -underline 0 -menu .a.help.menu] -side right
    1722 menu .a.help.menu -tearoff 0
    1723 .a.help.menu add command -command "MakeWWWHelp excledt.html" -label "Web page"
    1724 .a.help.menu add command -command about -label About
    1725 
    1726 pack .a -side top -fill both
    1727 pack $box -fill both -expand yes
    1728 
    1729 if {[expload $expnam.EXP] < 0} {exit}
    1730 mapexp
    1731 
    1732 # fill the histogram menu
    1733 if {[llength $expmap(powderlist)] > 1} {
    1734     .a.file.menu entryconfigure Histogram -state normal
    1735     menu .a.file.menu.hist
     1661    pack $graph(exclmenu) -side top -fill both
     1662    pack $graph(plot) -fill both -expand yes
     1663
     1664    # fill the histogram menu
    17361665    if {[llength $expmap(powderlist)] > 15} {
     1666        set expgui(plotlist) {}
     1667        $graph(exclmenu).file.menu entryconfigure Histogram -state normal
     1668        menu $graph(exclmenu).file.menu.hist
    17371669        set i 0
    17381670        foreach num [lsort -integer $expmap(powderlist)] {
    17391671            incr i
    1740             # for now include, but disable dummy histograms
    1741             set state disabled
    1742             if {[string trim [string range $expmap(htype_$num) 3 3]] != "D"} {
    1743                 set state normal
    1744             }
     1672            lappend expgui(plotlist) $num
    17451673            if {$i == 1} {
    17461674                set num1 $num
    1747                 menu .a.file.menu.hist.$num1
    1748             }
    1749             .a.file.menu.hist.$num1 add radiobutton -label $num -value $num \
    1750                     -variable hst -state $state \
    1751                     -command {set cycle [getcycle];readdata .g}
     1675                menu $graph(exclmenu).file.menu.hist.$num1
     1676            }
     1677            $graph(exclmenu).file.menu.hist.$num1 add radiobutton \
     1678                    -label $num -value $num \
     1679                    -variable graph(hst) \
     1680                    -command updateplot
    17521681            if {$i >= 10} {
    17531682                set i 0
    1754                 .a.file.menu.hist add cascade -label "$num1-$num" \
    1755                         -menu .a.file.menu.hist.$num1
     1683                $graph(exclmenu).file.menu.hist add cascade \
     1684                        -label "$num1-$num" \
     1685                        -menu $graph(exclmenu).file.menu.hist.$num1
    17561686            }
    17571687        }
    17581688        if {$i != 0} {
    1759             .a.file.menu.hist add cascade -label "$num1-$num" \
    1760                     -menu .a.file.menu.hist.$num1
    1761         }
    1762     } else {
     1689            $graph(exclmenu).file.menu.hist add cascade \
     1690                    -label "$num1-$num" \
     1691                    -menu $graph(exclmenu).file.menu.hist.$num1
     1692        }
     1693    } elseif {[llength $expmap(powderlist)] > 1} {
     1694        $graph(exclmenu).file.menu entryconfigure Histogram -state normal
     1695        menu $graph(exclmenu).file.menu.hist
     1696        set i 0
    17631697        foreach num [lsort -integer $expmap(powderlist)] {
    1764             # for now include, but disable dummy histograms
    1765             set state disabled
    1766             if {[string trim [string range $expmap(htype_$num) 3 3]] != "D"} {
    1767                 set state normal
    1768             }
    1769             .a.file.menu.hist add radiobutton -label $num -value $num \
    1770                     -variable hst -state $state \
    1771                     -command {set cycle [getcycle];readdata .g}
    1772         }
    1773     }
    1774 }
    1775 
    1776 updateplot
    1777 trace variable peakinfo w plotdata
    1778 
    1779 # catch exits -- launch POWPREF; if changes non-zero
    1780 wm protocol . WM_DELETE_WINDOW {CheckChanges;exit}
    1781 bind all <Control-KeyPress-c> {CheckChanges;exit}
    1782 # respond to resize events
    1783 bind . <Configure> scheduleFillExclRegionBox
     1698            foreach num [lsort -integer $expmap(powderlist)] {
     1699                lappend expgui(plotlist) $num
     1700                $graph(exclmenu).file.menu.hist add radiobutton \
     1701                        -label $num -value $num \
     1702                        -variable graph(hst) \
     1703                        -command updateplot
     1704            }
     1705        }
     1706    } else {
     1707        set expgui(plotlist) [lindex $expmap(powderlist) 0]
     1708    }
     1709
     1710    # N = load next histogram
     1711    bind $graph(exclbox) <Key-n> {
     1712        global expgui graph
     1713        set i [lsearch $expgui(plotlist) $graph(hst)]
     1714        incr i
     1715        if {$i >= [llength $expgui(plotlist)]} {set i 0}
     1716        set graph(hst) [lindex $expgui(plotlist) $i]
     1717        updateplot
     1718    }
     1719    bind $graph(exclbox) <Key-N> {
     1720        global expgui graph
     1721        set i [lsearch $expgui(plotlist) $graph(hst)]
     1722        incr i
     1723        if {$i >= [llength $expgui(plotlist)]} {set i 0}
     1724        set graph(hst) [lindex $expgui(plotlist) $i]
     1725        set cycle [getcycle];readdata .g
     1726    }
     1727    bind $graph(exclbox) <Key-z> {BLTmanualZoom}
     1728    bind $graph(exclbox) <Key-Z> {BLTmanualZoom}
     1729    updateplot
     1730    trace variable peakinfo w plotdata
     1731
     1732    # catch exits -- launch POWPREF; if changes non-zero
     1733    wm protocol $graph(exclbox) WM_DELETE_WINDOW {CheckChanges;destroy $graph(exclbox)}
     1734    # respond to resize events
     1735    bind $graph(exclbox) <Configure> scheduleFillExclRegionBox
     1736    bind all <Control-KeyPress-c> {CheckChanges;destroy $graph(exclbox)}
     1737    putontop $graph(exclbox)
     1738    tkwait window $graph(exclbox)
     1739    afterputontop
     1740    bind all <Control-c> catchQuit
     1741    # reset the number of cycles if they have changed
     1742    if {$cycsav != [expinfo cycles]} {
     1743        global entryvar
     1744        set entryvar(cycles) $cycsav
     1745    }
     1746}
     1747
     1748proc SetDummyRangeBox {hst tmin tmax tstep} {
     1749    global newhist expmap
     1750    if {[histinfo $hst dtype] != "CONST"} {
     1751        MyMessageBox -parent $np -title  "Change Range Error" \
     1752                -message "This histogram (#$hst) does not have constant steps. The range must be changed in EXPEDT." \
     1753                -icon error -type ok -default ok \
     1754                -helplink "excledt.html editdummy"
     1755        return
     1756    }
     1757    catch {toplevel [set np ".dummy"]}
     1758    wm title $np "Dummy Histogram Range"
     1759    eval destroy [winfo children $np]
     1760    # delete old traces, if any
     1761    foreach var {tmin tmax tstep} {
     1762        foreach v [ trace vinfo newhist($var)] {
     1763            eval trace vdelete newhist($var) $v
     1764        }
     1765    }
     1766    # set defaults to current values
     1767    foreach v {tmin tmax tstep} {set newhist($v) [set $v]}
     1768    trace variable newhist(tmin) w "ValidateDummyRange $np $hst"
     1769    trace variable newhist(tmax) w "ValidateDummyRange $np $hst"
     1770    trace variable newhist(tstep) w "ValidateDummyRange $np $hst"
     1771    pack [frame $np.d1]
     1772    grid [label $np.d1.l1 -text min] -col 1 -row 1
     1773    grid [label $np.d1.l2 -text max] -col 2 -row 1
     1774    grid [label $np.d1.l3 -text step] -col 3 -row 1
     1775    grid [label $np.d1.lu -text ""] -col 4 -row 1 -rowspan 2
     1776    grid [entry $np.d1.e1 -width 10 -textvariable newhist(tmin)] -col 1 -row 2
     1777    grid [entry $np.d1.e2 -width 10 -textvariable newhist(tmax)] -col 2 -row 2
     1778    grid [entry $np.d1.e3 -width 10 -textvariable newhist(tstep)] -col 3 -row 2
     1779    grid [label $np.d1.m1 -anchor w -padx 5] -col 1 -row 3 -sticky ew
     1780    grid [label $np.d1.m2 -anchor w -padx 5] -col 2 -row 3 -sticky ew
     1781    label $np.dl1 -text "Data range:"
     1782    label $np.dl2 -text "Allowed"
     1783    label $np.dl3 -text "\n" -justify left -fg blue
     1784    grid [frame $np.f6] -column 0 -row 99 -columnspan 5 -sticky ew
     1785    grid [button $np.f6.b6a -text Set \
     1786            -command "SetDummyRange $np $hst"] -column 0 -row 0
     1787    bind $np <Return> "SetDummyRange $np $hst"
     1788    grid [button $np.f6.b6b -text Cancel \
     1789            -command "destroy $np"] -column 1 -row 0
     1790    set link "excledt.html editdummy"
     1791    bind $np <Key-F1> "MakeWWWHelp $link"
     1792    grid [button $np.f6.help -text Help -bg yellow \
     1793            -command "MakeWWWHelp $link"] \
     1794            -column 2 -row 0 -sticky e
     1795    grid columnconfigure $np.f6 2 -weight 1
     1796
     1797    $np.d1.m1 config -text {}
     1798    $np.d1.m2 config -text {}
     1799    grid $np.dl1 -column 0 -row 8
     1800    grid $np.d1 -column 1 -row 8 -rowspan 2 -columnspan 4 -sticky e
     1801    grid $np.dl3 -column 0 -columnspan 99 -row 10 -sticky ew
     1802    grid [label $np.l1 -text "Set range for dummy histogram $hst" \
     1803            -justify center -anchor center -bg beige] \
     1804            -row 0 -column 0 -columnspan 5 -sticky ew
     1805    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
     1806        $np.dl1 config -text "Data range:\n(TOF)"
     1807        $np.d1.lu config -text millisec
     1808        grid $np.dl2 -column 0 -row 9
     1809        catch {
     1810            set line [histinfo $hst ITYP]
     1811            $np.d1.m1 config -text [lindex $line 1]
     1812            $np.d1.m2 config -text [lindex $line 2]
     1813        }
     1814    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
     1815        $np.dl1 config -text "Data range:\n(2Theta)"
     1816        $np.d1.lu config -text degrees
     1817        $np.d1.m1 config -text >0.
     1818        $np.d1.m2 config -text <180.
     1819    } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
     1820        $np.dl1 config -text "Data range:\n(Energy)"
     1821        $np.d1.lu config -text KeV
     1822        $np.d1.m1 config -text 1.
     1823        $np.d1.m2 config -text 200.
     1824        grid $np.dl2 -column 0 -row 9
     1825    }
     1826    ValidateDummyRange $np $hst
     1827    putontop $np
     1828    grab $np
     1829    tkwait window $np
     1830    afterputontop   
     1831}
     1832
     1833proc ValidateDummyRange {np hst args} {
     1834    # validate input
     1835    global newhist expmap
     1836    set msg {}
     1837    $np.dl3 config -text "\n"
     1838    foreach e {e1 e2 e3} v {tmin tmax tstep} {
     1839        if [catch {expr $newhist($v)}] {
     1840            $np.d1.$e config -fg red
     1841            append msg "Value of $newhist($v) is invalid for $v\n"
     1842        } else {
     1843            $np.d1.$e config -fg black
     1844        }
     1845    }
     1846    if {$newhist(tmax) <= $newhist(tmin)} {
     1847        $np.d1.e1 config -fg red
     1848        $np.d1.e2 config -fg red
     1849        return "Tmax <= Tmin\n"
     1850    }
     1851
     1852
     1853    set dmin -1
     1854    set dmax -1
     1855    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
     1856        catch {
     1857            set line [histinfo $hst ITYP]
     1858            set tmin [lindex $line 1]
     1859            set tmax [lindex $line 2]
     1860            if {$newhist(tmin) <$tmin } {
     1861                $np.d1.e1 config -fg red
     1862                append msg "Min value of $newhist(tmin) msec is invalid.\n"
     1863            }
     1864            if {$newhist(tmax) >$tmax } {
     1865                $np.d1.e2 config -fg red
     1866                append msg "Max value of $newhist(tmax) msec is invalid.\n"
     1867            }
     1868            set difc [histinfo $hst difc]
     1869            set dmin [expr {1000. * $newhist(tmin) / $difc}]
     1870            set dmax [expr {1000. * $newhist(tmax) / $difc}]
     1871        }
     1872    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
     1873        if {$newhist(tmin) <= 0 } {
     1874            $np.d1.e1 config -fg red
     1875            append msg "Min value of $newhist(tmin) degrees is invalid.\n"
     1876        }
     1877        if {$newhist(tmax) >=180 } {
     1878            $np.d1.e2 config -fg red
     1879            append msg "Max value of $newhist(tmax) degrees is invalid.\n"
     1880        }
     1881        catch {
     1882            set lam [histinfo $hst lam1]
     1883            set dmin [expr {$lam * 0.5 / sin(acos(0.)*$newhist(tmax)/180.)}]
     1884            set dmax [expr {$lam * 0.5 / sin(acos(0.)*$newhist(tmin)/180.)}]
     1885        }
     1886    } else {
     1887        if {$newhist(tmin) <1 } {
     1888            $np.d1.e1 config -fg red
     1889            append msg "Min value of $newhist(tmin) KeV is invalid.\n"
     1890        }
     1891        if {$newhist(tmax) >200 } {
     1892            $np.d1.e2 config -fg red
     1893            append msg "Max value of $newhist(tmax) KeV is invalid.\n"
     1894        }
     1895        catch {
     1896            set ang [histinfo $hst lam1]
     1897            set dmin [expr {12.398/ (2.0*sin($ang*acos(0.)/180) * \
     1898                    $newhist(tmax))}]
     1899            set dmax [expr {12.398/ (2.0*sin($ang*acos(0.)/180) * \
     1900                    $newhist(tmin))}]
     1901        }
     1902    }
     1903    if {$msg != ""} {return $msg}
     1904    set pnts -1
     1905    catch {
     1906        set pnts [expr {1+int(($newhist(tmax) - $newhist(tmin))/$newhist(tstep))}]
     1907        set qmin [expr {4.*acos(0)/$dmax}]
     1908        set qmax [expr {4.*acos(0)/$dmin}]
     1909    }
     1910    if {$pnts <= 0} {
     1911        $np.d1.e3 config -fg red
     1912        append msg "Step value of $newhist(tstep) is invalid.\n"
     1913    }
     1914    if {$pnts >20000} {
     1915        $np.d1.e3 config -fg red
     1916        append msg "Step value of $newhist(tstep) is too small (>20000 points).\n"
     1917    }
     1918    if {$msg != ""} {return $msg}
     1919    if {$dmin > 0 && $dmax > 0} {
     1920        catch {
     1921            set msg [format \
     1922                    "  %d points.%s  D-space range: %.2f-%.2f \xc5,  Q: %.2f-%.2f/\xc5" \
     1923                    $pnts "\n" $dmin $dmax $qmin $qmax]
     1924            $np.dl3 config -text $msg
     1925        }
     1926    }
     1927    if {$msg != ""} {return ""}
     1928    $np.dl3 config -text [format {  %d points.%s  Range: ?} $pnts "\n"]
     1929    return "Invalid data range -- something is wrong!"
     1930}
     1931
     1932proc SetDummyRange {np hst} {
     1933    global newhist expmap
     1934    # validate last time
     1935    set msg [ValidateDummyRange $np $hst]
     1936    if {$msg != ""} {
     1937        MyMessageBox -parent $np -title  "Change Range Error" \
     1938                -message "The following error(s) were found in your input:\n$msg" \
     1939                -icon error -type ok -default ok \
     1940                -helplink "excledt.html editdummy"
     1941        return
     1942    }
     1943    set pnts [expr {1+int(($newhist(tmax) - $newhist(tmin))/$newhist(tstep))}]
     1944
     1945    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
     1946        lappend exclist "0 [expr {$newhist(tmin)-$newhist(tstep)}]" \
     1947                "[expr {$newhist(tmax)+$newhist(tstep)}] 1000."
     1948        histinfo $hst excl set $exclist
     1949        histinfo $hst dpoints set $pnts
     1950        histinfo $hst dstart  set [expr {$newhist(tmin)*1000.}]
     1951        histinfo $hst dstep   set [expr {$newhist(tstep)*1000.}]
     1952        histinfo $hst dmin set [tod $newhist(tmin) $hst]
     1953    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
     1954        lappend exclist "0 [expr {$newhist(tmin)-$newhist(tstep)}]" \
     1955                "[expr {$newhist(tmax)+$newhist(tstep)}] 1000."
     1956        histinfo $hst excl set $exclist
     1957        histinfo $hst dpoints set $pnts
     1958        histinfo $hst dstart  set [expr {$newhist(tmin)*100.}]
     1959        histinfo $hst dstep   set [expr {$newhist(tstep)*100.}]
     1960        histinfo $hst dmin set [tod $newhist(tmax) $hst]
     1961    } else {
     1962        lappend exclist "0 [expr {$newhist(tmin)-$newhist(tstep)}]" \
     1963                "[expr {$newhist(tmax)+$newhist(tstep)}] 1000."
     1964        histinfo $hst excl set $exclist
     1965        histinfo $hst dpoints set $pnts
     1966        histinfo $hst dstart  set $newhist(tmin)
     1967        histinfo $hst dstep   set $newhist(tstep)
     1968        histinfo $hst dmin set [tod $newhist(tmax) $hst]
     1969    }
     1970    global expgui
     1971    incr expgui(changed) 5
     1972    destroy $np
     1973    updateplot
     1974}
Note: See TracChangeset for help on using the changeset viewer.