source: trunk/excledt.tcl @ 770

Last change on this file since 770 was 759, checked in by toby, 16 years ago

# on 2003/12/05 12:56:23, toby did:
only display peak options for phases that are present
implement keyboard shortcuts (1,2,...) for showing reflection tickmarks
fix peak options menu bug

  • Property rcs:author set to toby
  • Property rcs:date set to 2003/12/05 12:56:23
  • Property rcs:lines set to +17 -11
  • Property rcs:rev set to 1.11
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 58.4 KB
Line 
1# $Id: excledt.tcl 759 2009-12-04 23:11:32Z toby $
2
3# create the main Excluded Region window
4proc ExclReaddata {box} { 
5    global expgui
6#    if [catch {
7        set loadtime [time {
8            ExclReaddata_hst $box
9#       }]
10        if $expgui(debug) {
11            tk_dialog .time "Timing info" \
12                    "Histogram loading took $loadtime" "" 0 OK
13        }
14#    } errmsg] {
15        if $expgui(debug) {
16            catch {console show}
17            error $errmsg
18        }
19#       $box config -title "Read error"
20#       tk_dialog .err "Read Error" "Read Error -- $errmsg" \
21#               error 0 OK
22#       update
23#    }
24    $box element show [lsort -decreasing [$box element show]]
25}
26   
27# get the data to plot using hstdump (tcldump does not show the excluded data)
28proc ExclReaddata_hst {box} {
29    global expgui reflns graph
30    global peakinfo
31    update
32    set hst $graph(hst)
33    # parse the output of a file
34    # use histdmp for histogram info
35    set input [open excl$hst.inp w]
36    puts $input "[file rootname [file tail $expgui(expfile)]]"
37    puts $input "L"
38    puts $input "$hst"
39    puts $input "0"
40    close $input
41    # use hstdmp without an experiment name so that output
42    # is not sent to the .LST file
43    exec [file join $expgui(gsasexe) hstdmp] < excl$hst.inp > excl$hst.out
44    set input [open excl$hst.out r]
45    catch {file delete excl$hst.inp}
46    # initalize arrays
47    set num -1
48    set xlist {}
49    set obslist {}
50    set calclist {}
51    set allxlist {}
52    set graph(xcaption) {}
53    set exclistx {}
54    set exclistobs {}
55    # define a list of reflection positions for each phase
56    for {set i 1} {$i < 10} {incr i} {
57        set reflns($i) {}
58    }
59    set i 0
60    while {[gets $input line] >= 0} {
61        incr i
62        # run update every 200th line
63        if {$i > 200} {set i 0; update}
64        if [scan $line %d num] {
65            if {$num > 0} {
66                set Ispec 0
67                set X -999
68                scan [string range $line 8 end] %e%e%e%e \
69                        X Iobs Icalc Ispec
70                #puts $line
71                lappend allxlist $X
72                # eliminate excluded points
73                if {$Ispec > 0.0 && $X >= 0} {
74                    lappend xlist $X
75                    lappend obslist $Iobs
76                    lappend calclist $Icalc
77                } elseif {$X != -999} {
78                    lappend exclistx $X
79                    lappend exclistobs $Iobs
80                }
81                if [regexp {[1-9]} [string range $line 6 7] ph] {
82                    lappend reflns($ph) $X
83                }
84            } 
85        } else {
86            regexp {Time|Theta|keV} $line graph(xcaption)
87        }
88    }
89    close $input
90    if {$graph(xcaption) == "Theta"} {set graph(xcaption) "2-Theta"}
91    # convert the x units, if requested
92    if {$graph(xunits) == 1} {
93        set xlist [tod $xlist $hst]
94        set exclistx [tod $exclistx $hst]
95        set graph(xcaption) d-space
96    } elseif {$graph(xunits) == 2} {
97        set xlist [toQ $xlist $hst]
98        set exclistx [toQ $exclistx $hst]
99        set graph(xcaption) Q
100    }
101    catch {file delete excl$hst.out}
102    catch {
103        if {[llength $allxlist] > 0} {
104            allxvec set $allxlist
105            xvec set $xlist
106            obsvec set $obslist
107            calcvec set $calclist
108            diffvec set [obsvec - calcvec]
109            exxvec set $exclistx
110            exobsvec set $exclistobs 
111            global obsvec calcvec diffvec
112            set maxdiff  [set diffvec(max)]
113            set cmin [set calcvec(min)]
114            set omin [set obsvec(min)]
115            set cmax [set calcvec(max)]
116            set omax [set obsvec(max)]
117            foreach {expgui(min) expgui(max)} {0 0} {}
118            catch {
119                set expgui(min) [expr $omin < $cmin ? $omin : $cmin]
120                set expgui(max) [expr $omax > $cmax ? $omax : $cmax]
121                set ymin1 [expr $cmin - 1.1*$maxdiff]
122                set ymin2 [expr $omin - 1.1*$maxdiff]
123                if {$ymin1 < $ymin2} {
124                    diffvec set [diffvec + $ymin1]
125                } {
126                    diffvec set [diffvec + $ymin2]
127                }
128            }
129        }
130    }
131    plotExclData
132}
133
134# plot the pattern with the requested x-axis units & the excluded regions
135proc plotExclData {args} {
136    global peakinfo  reflns
137    global graph expgui
138
139    set hst $graph(hst)
140    $graph(plot) config -title \
141            "[file tail $expgui(expfile)] cycle [expinfo cyclesrun] Hist $hst"
142    $graph(plot) xaxis config -title $graph(xcaption)
143    $graph(plot) yaxis config -title $graph(ycaption)
144    setlegend $graph(plot) $graph(legend)
145    # reconfigure the data display
146    $graph(plot) element configure 3 \
147            -symbol $peakinfo(obssym) -color $graph(color_obs) \
148            -pixels [expr 0.125 * $peakinfo(obssize)]i
149    $graph(plot) element config 2 -color $graph(color_calc)
150    $graph(plot) element config 12 \
151            -symbol $peakinfo(exclsym) -color $graph(color_excl) \
152            -pixels [expr 0.125 * $peakinfo(exclsize)]i
153
154    foreach vec {xvec obsvec calcvec diffvec exxvec exobsvec} {
155        $vec notify now
156    }
157    # now deal with tick marks
158    for {set i 1} {$i < 10} {incr i} {
159        if {$expgui(autotick)} {
160            set div [expr ( $expgui(max) - $expgui(min) )/40.]
161            set ymin [expr $expgui(min) - ($i+1) * $div]
162            set ymax [expr $expgui(min) - $i * $div]
163        } else {
164            set ymin $peakinfo(min$i)
165            set ymax $peakinfo(max$i)
166        }
167        set j 0
168        if [set peakinfo(flag$i)] {
169            if {$graph(xunits) == 1} {
170                set Xlist [tod $reflns($i) $hst]
171            } elseif {$graph(xunits) == 2} {
172                set Xlist [toQ $reflns($i) $hst]
173            } else {
174                set Xlist $reflns($i)
175            }
176            foreach X $Xlist {
177                incr j
178                catch {
179                    $graph(plot) marker create line -name peaks${i}_$j 
180                }
181                $graph(plot) marker config peaks${i}_$j  -under 1 \
182                        -coords "$X $ymin $X $ymax" 
183                catch {
184                    $graph(plot) marker config peaks${i}_$j \
185                            $graph(MarkerColorOpt) [list $peakinfo(color$i)]
186                    if $peakinfo(dashes$i) {
187                        $graph(plot) marker config peaks${i}_$j -dashes "5 5"
188                    }
189                }
190            }
191            catch {$graph(plot) element create phase$i}
192            catch {
193                $graph(plot) element config phase$i -color $peakinfo(color$i) 
194            }
195        } else {
196            eval $graph(plot) marker delete [$graph(plot) marker names peaks${i}_*]
197            eval $graph(plot) element delete [$graph(plot) element names phase$i]
198        }
199    }
200    # force an update of the plot as BLT may not
201    $graph(plot) config -title [$graph(plot) cget -title]
202    update
203}
204
205# show or hide the plot legend
206proc setlegend {box legend} {
207    global blt_version
208    if {$blt_version >= 2.3 && $blt_version < 8.0} {
209        if $legend {
210            $box legend config -hide no
211        } else {
212            $box legend config -hide yes
213        }
214    } else {
215        if $legend {
216            $box legend config -mapped yes
217        } else {
218            $box legend config -mapped no
219        }
220    }
221}
222
223# show tickmark options
224proc minioptionsbox {num} {
225    global blt_version tcl_platform peakinfo expgui
226    set bx .opt$num
227    catch {destroy $bx}
228    toplevel $bx
229    wm iconname $bx "Phase $num options"
230    wm title $bx "Phase $num options"
231
232    set i $num
233    pack [label $bx.0 -text "Phase $i reflns" ] -side top
234    pack [checkbutton $bx.1 -text "Show reflections" \
235            -variable peakinfo(flag$i)] -side top
236    # remove option that does not work
237    if {$blt_version != 8.0 || $tcl_platform(platform) != "windows"} {
238        pack [checkbutton $bx.2 -text "Use dashed line" \
239                -variable peakinfo(dashes$i)] -side top
240    }
241    if !$expgui(autotick) {
242        pack [frame $bx.p$i -bd 2 -relief groove] -side top
243        #       pack [checkbutton $bx.p$i.0 -text "Show phase $i reflns" \
244                #               -variable peakinfo(flag$i)] -side left -anchor w
245        pack [label $bx.p$i.1 -text "  Y min:"] -side left
246        pack [entry $bx.p$i.2 -textvariable peakinfo(min$i) -width 5] \
247                -side left
248        pack [label $bx.p$i.3 -text "  Y max:"] -side left
249        pack [entry $bx.p$i.4 -textvariable peakinfo(max$i) -width 5] \
250                -side left
251    }
252    pack [frame $bx.c$i -bd 2 -relief groove] -side top
253   
254    pack [label $bx.c$i.5 -text " color:"] -side left
255    pack [entry $bx.c$i.6 -textvariable peakinfo(color$i) -width 12] \
256            -side left
257    pack [button $bx.c$i.2 -bg $peakinfo(color$i) -state disabled] -side left
258    pack [button $bx.c$i.1 -text "Color\nmenu" \
259            -command "setcolor $i"] -side left
260    pack [frame $bx.b] -side top
261    pack [button $bx.b.4 -command "destroy $bx" -text Close ] -side right
262}
263
264proc setcolor {num} {
265    global peakinfo
266    set color [tk_chooseColor -initialcolor $peakinfo(color$num) -title "Choose color"]
267    if {$color == ""} return
268    set peakinfo(color$num) $color
269}
270
271proc makepostscriptout {} {
272    global graph
273    if !$graph(printout) {
274        set out [open "| $graph(outcmd) >& plot.msg" w]
275        catch {
276            puts $out [$graph(plot) postscript output -landscape 1 \
277                -decorations no -height 7.i -width 9.5i]
278            close $out
279        } msg
280        catch {
281            set out [open plot.msg r]
282            if {$msg != ""} {append msg "\n"}
283            append msg [read $out]
284            close $out
285            catch {file delete plot.msg}
286        }
287        if {$msg != ""} {
288            tk_dialog .msg "file created" \
289                    "Postscript file processed with command \
290                    $graph(outcmd). Result: $msg" "" 0 OK
291        } else {
292            tk_dialog .msg "file created" \
293                    "Postscript file processed with command \
294                    $graph(outcmd)" "" 0 OK
295        }
296    } else {
297        $graph(plot) postscript output $graph(outname) -landscape 1 \
298                -decorations no -height 7.i -width 9.5i   
299        tk_dialog .msg "file created" \
300                "Postscript file $graph(outname) created" "" 0 OK
301    }
302}
303
304proc setprintopt {page} {
305    global graph
306    if $graph(printout) { 
307        $page.4.1 config -fg black
308        $page.4.2 config -fg black -state normal
309        $page.6.1 config -fg #888 
310        $page.6.2 config -fg #888 -state disabled
311    } else {
312        $page.4.1 config -fg #888 
313        $page.4.2 config -fg #888 -state disabled
314        $page.6.1 config -fg black
315        $page.6.2 config -fg black -state normal
316    }
317}
318
319proc setpostscriptout {} {
320    global graph tcl_platform
321    set box .out
322    catch {destroy $box}
323    toplevel $box
324    wm title $box "Postscript options"
325    focus $box
326    pack [frame $box.4] -side top -anchor w -fill x
327    pack [checkbutton $box.4.a -text "Write PostScript files" \
328            -variable graph(printout) -offvalue 0 -onvalue 1 \
329            -command "setprintopt $box"] -side left -anchor w
330    pack [entry $box.4.2 -textvariable graph(outname)] -side right -anchor w
331    pack [label $box.4.1 -text "PostScript file name:"] -side right -anchor w
332    pack [frame $box.6] -side top -anchor w -fill x
333    pack [checkbutton $box.6.a -text "Print PostScript files" \
334            -variable graph(printout) -offvalue 1 -onvalue 0 \
335            -command "setprintopt $box" ] -side left -anchor w
336    pack [entry $box.6.2 -textvariable graph(outcmd)] -side right -anchor w
337    pack [label $box.6.1 -text "Command to print files:"] -side right -anchor w
338
339    pack [button $box.a -text "Close" -command "destroy $box"] -side top
340    if {$tcl_platform(platform) == "windows"} {
341        set graph(printout) 1
342        $box.4.a config -state disabled
343        $box.6.a config -fg #888 -state disabled
344    }
345    setprintopt $box
346}
347
348proc getsymopts {"sym obs"} {
349    global expgui peakinfo
350    set box .out
351    catch {destroy $box}
352    toplevel $box
353    focus $box
354    wm title .out "Set $sym symbol"
355    pack [frame $box.d] -side left -anchor n
356    pack [label $box.d.t -text "Symbol type"] -side top
357    set expgui(sym) $peakinfo(${sym}sym) 
358    set expgui(size) $peakinfo(${sym}size) 
359    foreach symbol {square circle diamond plus cross \
360            splus scross} \
361            symbol_name {square circle diamond plus cross \
362            thin-plus thin-cross} {
363        pack [radiobutton $box.d.$symbol \
364                -text $symbol_name -variable expgui(sym) \
365                -value $symbol] -side top -anchor w
366    }
367    pack [frame $box.e] -side left -anchor n -fill y
368    pack [label $box.e.l -text "Symbol Size"] -side top
369    pack [scale $box.e.s -variable expgui(size) \
370            -from .1 -to 3 -resolution 0.05] -side top
371    pack [frame $box.a] -side bottom
372    pack [button $box.a.1 -text "Apply" -command "setsymopts $sym"] -side left
373    pack [button $box.a.2 -text "Close" -command "destroy $box"] -side left
374}
375proc setsymopts {sym} {
376    global peakinfo expgui
377    if {$peakinfo(${sym}sym) != $expgui(sym)} {set peakinfo(${sym}sym) $expgui(sym)}
378    if {$peakinfo(${sym}size) != $expgui(size)} {set peakinfo(${sym}size) $expgui(size)}
379}
380
381proc updateplot {} {
382    global env tcl_platform graph expgui
383    set hst $graph(hst)
384    $graph(plot) config -title "Please wait: loading histogram $hst"
385    exxvec set {}
386    exobsvec  set {}
387    exxvec notify now
388    exobsvec notify now
389    eval $graph(plot) marker delete [$graph(plot) marker names]
390
391    ExclReaddata $graph(plot)
392    ShowExlMarks
393    $graph(plot) element config 3 -color $graph(color_obs)
394    $graph(plot) element config 2 -color $graph(color_calc)
395    $graph(plot) element config 12 -color $graph(color_excl)
396    foreach vec {xvec obsvec calcvec diffvec exxvec exobsvec} {
397        $vec notify now
398    }
399    FillExclRegionBox
400    $graph(plot) config -title \
401            "[file tail $expgui(expfile)] cycle [expinfo cyclesrun] Hist $hst"
402}
403
404# display the excluded regions with orange markers
405proc ShowExlMarks {} {
406    global graph
407    eval $graph(plot) marker delete [$graph(plot) marker names excl*]
408    set hst $graph(hst)
409    set exclist [histinfo $hst excl]
410    set i 0
411    foreach rng $exclist {
412        if {$graph(xunits) == 1} {
413            set rng [tod $rng $hst]
414        } elseif {$graph(xunits) == 2} {
415            set rng [toQ $rng $hst]
416        }
417        set x1 [lindex [lsort -real $rng] 0]
418        set x2 [lindex [lsort -real $rng] end]
419        $graph(plot) marker create line -under 1 -name excl[incr i] \
420                -coords "$x1 -Inf $x2 -Inf" \
421                $graph(MarkerColorOpt) $graph(color_excl) -linewidth 3
422        # copy any points that should be excluded
423        set l [lsort -integer [xvec search $x1 $x2]]
424        if {$l != ""} {
425            set n1 [lindex $l 0]
426            set n2 [lindex $l end]
427            exxvec append [xvec range $n1 $n2]
428            exobsvec append [obsvec range $n1 $n2]
429        }
430    }
431}
432
433# change the binding of the mouse, based on the selected mode
434proc exclEditMode {b bb} {
435    global zoom graph
436    # save the zoom and unzoom commands
437    if [catch {set zoom(in)}] {
438        # get binding
439        set zoom(bindtag) $graph(plot)
440        catch {
441            if {[bind bltZoomGraph] != ""} {
442                set zoom(bindtag) bltZoomGraph
443            }
444        }
445        set zoom(in) [bind $zoom(bindtag) <1>]
446        set zoom(out) [bind $zoom(bindtag) <3>]
447        # check for really new BLT where binding is handled differently
448        if {$zoom(in) == ""} {
449            foreach zoom(bindtag) [bindtags $graph(plot)] {
450                set zoom(in) [bind $zoom(bindtag) <1>]
451                set zoom(out) [bind $zoom(bindtag) <3>]
452                if {$zoom(in) != ""} break
453            }
454        }
455    }
456       
457    foreach c {1 2 3} {
458        if {$c == $b} {
459            $bb.l.b$c config -relief sunken
460        } else {
461            $bb.l.b$c config -relief raised
462        }
463    }
464
465    # reset previous mode; if in the middle
466    if {[string trim [bind $graph(plot) <Motion>]] != ""} {
467        if {[lindex [bind $graph(plot) <Motion>] 0] == "exclMove"} {
468            exclReset $zoom(bindtag)
469        } else {
470            blt::ResetZoom $graph(plot)
471        }
472    }
473    if {$b == 2} {
474        bind $zoom(bindtag) <1> "exclAdd $zoom(bindtag) %x %y"
475        $graph(plot) config -cursor arrow
476    } elseif {$b == 3} {
477        bind $zoom(bindtag) <1> "exclDel $zoom(bindtag) %x %y"
478        $graph(plot) config -cursor circle
479    } else {
480        bind $zoom(bindtag) <1> $zoom(in)
481        bind $zoom(bindtag) <3> $zoom(out)
482        $graph(plot) config -cursor crosshair
483    }
484}
485
486# called using the mouse to delete an excluded region
487proc exclDel {bindtag x y} {
488    global graph expgui
489    set x1 [$graph(plot) xaxis invtransform $x]
490    set hst $graph(hst)
491    if {$graph(xunits) == 1} {
492        set x1 [fromd $x1 $hst]
493    } elseif {$graph(xunits) == 2} {
494        set x1 [fromQ $x1 $hst]
495    }
496    set exclist [histinfo $hst excl]
497    # don't delete the high or low ranges
498    if {$x1 <= [lindex [lindex $exclist 0] 1] || \
499            $x1 >= [lindex [lindex $exclist end] 0]} {
500        bell
501        return
502    }
503    set newlist {}
504    set msg ""
505    foreach rng $exclist {
506        if {$x1 < [lindex $rng 0] || $x1 > [lindex $rng 1]} {
507            lappend newlist $rng
508        } else {
509            if {$graph(xunits) == 1} {
510                set drng [tod $rng $hst]
511                set msg "Delete excluded region from "
512                append msg "[format %.5f [lindex $drng 1]] A "
513                append msg "to [format %.5f [lindex $drng 0]] A?"
514            } elseif {$graph(xunits) == 2} {
515                set qrng [toQ $rng $hst]
516                set msg "Delete excluded region from "
517                append msg "[format %.5f [lindex $qrng 0]] A-1 "
518                append msg "to [format %.5f [lindex $qrng 1]] A-1?"
519            } else {
520                set msg "Delete excluded region from [lindex $rng 0] to [lindex $rng 1]?"
521            }
522            global graph
523            if {$graph(exclPrompt)} {
524                set ans [MyMessageBox -parent . -message $msg \
525                        -helplink "expguierr.html ExcludeRegion" \
526                        -title "Delete region" -type okcancel]
527            } else {
528                set ans ok
529            }
530            if {$ans == "ok"} {
531                incr expgui(changed)
532            } else {
533                lappend newlist $rng
534            }
535        }
536    }
537    if {[llength $newlist] == [llength $exclist]} {
538        if {$msg == ""} bell
539    } else {
540        histinfo $hst excl set $newlist
541        updateplot
542    }
543}
544
545# called using the mouse to create a new excluded region
546# once this is called, mouse motion causes a region to be highlighted
547# using exclMove. Button 1 completes the region, by calling exclDone while
548# button 3 resets the mode
549proc exclAdd {bindtag x y} {
550    global graph
551    bind $graph(plot) <Motion> "exclMove $bindtag %x %y"
552    bind $bindtag <1> "exclDone $bindtag %x %y"
553    bind $bindtag <3> "exclReset $bindtag"
554    set graph(excl-x1) [$graph(plot) xaxis invtransform $x]
555    $graph(plot) marker create text -name AddExclLbl -text "Adding\nRegion" \
556            -bg yellow -coords "+Inf +Inf" -anchor ne
557}
558
559# reset the "add region mode" (see exclAdd)
560proc exclReset {bindtag} {
561    global graph
562    bind $graph(plot) <Motion> {}
563    $graph(plot) marker delete exclShade
564    bind $bindtag <1> "exclAdd $bindtag %x %y"
565    $graph(plot) marker delete AddExclLbl
566}
567
568# highlight the potential excluded region (see exclAdd)
569proc exclMove {bindtag x y} {
570    global graph
571    set x1 $graph(excl-x1)
572    set x2 [$graph(plot) xaxis invtransform $x]
573    if { ![$graph(plot) marker exists "exclShade"] } {
574        $graph(plot) marker create polygon -name "exclShade" -under 1 -fill yellow
575    }
576    $graph(plot) marker configure "exclShade" \
577            -coords "$x1 -Inf $x1 +Inf $x2 +Inf $x2 -Inf"
578}
579
580# Called by a mouse click to complete a new excluded region (see exclAdd)
581proc exclDone {bindtag x y} {
582    global graph
583    bind $graph(plot) <Motion> {}
584    bind $bindtag <1> "exclAdd $bindtag %x %y"
585    set x1 $graph(excl-x1)
586    set x2 [$graph(plot) xaxis invtransform $x]
587    set hst $graph(hst)
588    if {$graph(xunits) == 1} {
589        set x1 [fromd $x1 $hst]
590        set x2 [fromd $x2 $hst]
591    } elseif {$graph(xunits) == 2} {
592        set x1 [fromQ $x1 $hst]
593        set x2 [fromQ $x2 $hst]
594    }
595    catch {
596        $graph(plot) marker delete "exclShade"
597    }
598    $graph(plot) marker delete AddExclLbl
599    # get the points in the range
600    set l [lsort -integer [allxvec search $x1 $x2]]
601    if {[llength $l] == 0} return
602    set p1 [allxvec index [set n1 [lindex $l 0]]]
603    set p2 [allxvec index [set n2 [lindex $l end]]]
604    if {$graph(xunits) == 1} {
605        set d1 [tod $p1 $hst]
606        set d2 [tod $p2 $hst]
607        set msg "Exclude data from "
608        append msg "[format %.5f $d2] A to [format %.5f $d1] A"
609        append msg " ([expr $n2-$n1+1] points)?"
610        set coords "$d2 -Inf $d1 -Inf"
611        set l [lsort -integer [xvec search $d1 $d2]]
612    } elseif {$graph(xunits) == 2} {
613        set q1 [toQ $p1 $hst]
614        set q2 [toQ $p2 $hst]
615        set msg "Exclude data from "
616        append msg "[format %.5f $q1] A-1 to [format %.5f $q2] A-1"
617        append msg " ([expr $n2-$n1+1] points)?"
618        set coords "$q1 -Inf $q2 -Inf"
619        set l [lsort -integer [xvec search $q1 $q2]]
620    } else {
621        set msg "Exclude data from "
622        append msg "[format %.5f $p1] to [format %.5f $p2]"
623        append msg " ([expr $n2-$n1+1] points)?"
624        set coords "$p1 -Inf $p2 -Inf"
625        set l [lsort -integer [xvec search $x1 $x2]]
626    }
627    global graph
628    if {$graph(exclPrompt)} {
629        set ans [MyMessageBox -parent . -message $msg -title "Exclude?"\
630                -type okcancel -helplink "expguierr.html ExcludeRegion"]
631    } else {
632        set ans ok
633    }
634    if {$ans != "ok"} {return}
635    # make the change
636    global expgui
637    incr expgui(changed)
638    set hst $graph(hst)
639    set exclist [histinfo $hst excl]
640    set oldtmin [lindex [lindex $exclist 0] 1]
641    set oldtmax [lindex [lindex $exclist end] 0]
642    # add the new excluded region at the end
643    lappend exclist [list $p1 $p2]
644    # sort and simplify the excluded region list
645    CheckForOverlappingRegions $exclist
646    CheckQmaxChanged $oldtmin $oldtmax
647    # update the plot to change the color of the points that are now excluded
648    exxvec append [xvec range [lindex $l 0] [lindex $l end]]
649    exobsvec append [obsvec range [lindex $l 0] [lindex $l end]]
650    exxvec notify now
651    exobsvec notify now
652    ShowExlMarks
653    FillExclRegionBox
654}
655
656# sort the regions and then go through the list of excluded regions and
657# merge regions that overlap
658proc CheckForOverlappingRegions {exclist} {
659    global expgui graph
660    set exclist [lsort -real -index 0 $exclist]
661    set prvlow -1
662    set prvhigh -1
663    set i 0
664    set ip -1
665    foreach pair $exclist {
666        set low [lindex $pair 0] 
667        set high [lindex $pair 1] 
668        # is there overlap with the previous range?
669        if {$low < $prvhigh && $i != 0} {
670            set exclist [lreplace $exclist $ip $i [list $prvlow $high]]
671            incr expgui(changed)
672            set prvhigh $high
673            continue
674        }
675        # are there any points between the regions
676        if {$i != 0} {
677            set seppts [allxvec search \
678                    [expr -.00001+$low] [expr .00001+$prvhigh]]
679            if {[llength $seppts] == 0} {
680                set exclist [lreplace $exclist $ip $i [list $prvlow $high]]
681                incr expgui(changed)
682                set prvhigh $high
683                continue
684            }
685        }
686        incr i; incr ip
687        set prvlow $low
688        set prvhigh $high
689    }
690    histinfo $graph(hst) excl set $exclist
691}
692
693# called in response to the File/"Set Min/Max Range" menu button
694proc setminormax {} {
695    global expmap graph expgui
696    set hst $graph(hst)
697    if {[string trim [string range $expmap(htype_$hst) 3 3]] == "D"} {
698        if {[string range $expmap(htype_$hst) 2 2] == "T"} {
699            set fac 1000.
700        } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
701            set fac 1.
702        } else {
703            set fac 100.
704        }
705        set start [expr {[histinfo $hst dstart]/$fac}]
706        set step  [expr {[histinfo $hst dstep]/$fac}]
707        set points [histinfo $hst dpoints]
708        set end [expr {$start + $points*$step}]
709        SetDummyRangeBox $hst $start $end $step
710        return
711    }
712    set box .limit
713    toplevel $box
714    wm title $box "Set usable range"
715    set link excledt.html
716    grid [button $box.help -text Help -bg yellow \
717            -command "MakeWWWHelp $link"] -column 98 -row 0
718    bind $box <Key-F1> "MakeWWWHelp $link"
719
720    set hst $graph(hst)
721    if {$graph(xunits) == 1} {
722        set var d
723        set unit A
724    } elseif {$graph(xunits) == 2} {
725        set var Q
726        set unit A-1
727    } elseif {[string range $expmap(htype_$hst) 2 2] == "T"} {
728        set var TOF
729        set unit ms
730    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
731        set var 2theta
732        set unit deg
733    } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
734        set var Energy
735        set unit KeV
736    } else {
737        set var ?
738        set unit ?
739    }
740    if {$graph(xunits) != 0} {
741    }
742    grid [label $box.t -text "Set usable data range, histogram $hst"] \
743            -column 0 -columnspan 4 -row 0
744    grid [label $box.lu -text "($unit)"] -column 2 -row 1 -rowspan 2
745    grid [label $box.lmn -text "$var minimum"] -column 0 -row 1
746    grid [entry $box.emn -textvariable graph(tmin) -width 10] -column 1 -row 1
747    grid [label $box.lmx -text "$var maximum"] -column 0 -row 2
748    grid [entry $box.emx -textvariable graph(tmax) -width 10] -column 1 -row 2
749    grid [frame $box.c] -column 0 -columnspan 99 -row 99
750    grid [button $box.c.1 -text Set -command "destroy $box"\
751            ] -column 1 -row 0
752    grid [button $box.c.2 -text Quit \
753            -command "foreach i {min max} {set graph(\$i) {}}; destroy $box" \
754            ] -column 2 -row 0
755    set exclist [histinfo $hst excl]
756    set oldtmin [lindex [lindex $exclist 0] 1]
757    set oldtmax [lindex [lindex $exclist end] 0]
758    if {$graph(xunits) == 1} {
759        set graph(tmax) [format %.4f [tod [lindex [lindex $exclist 0] 1] $hst]]
760        set graph(tmin) [format %.4f [tod [lindex [lindex $exclist end] 0] $hst]]
761    } elseif {$graph(xunits) == 2} {
762        set graph(tmin) [format %.4f [toQ [lindex [lindex $exclist 0] 1] $hst]]
763        set graph(tmax) [format %.4f [toQ [lindex [lindex $exclist end] 0] $hst]]
764    } else {
765        set graph(tmin) [lindex [lindex $exclist 0] 1]
766        set graph(tmax) [lindex [lindex $exclist end] 0]
767    }
768    foreach v {tmin tmax} {set start($v) $graph($v)}
769    bind $box <Return> "$box.c.1 invoke"
770    putontop $box
771    tkwait window $box
772    # fix grab...
773    afterputontop
774
775    set highchange 0
776    set startchanges $expgui(changed)
777    catch {
778        # did anything change?
779        if {$graph(tmin) != $start(tmin)} {
780            incr expgui(changed)
781            if {$graph(xunits) == 1} {
782                set tmax [fromd $graph(tmin) $hst]
783                set exclist [lreplace $exclist end end \
784                        [list $tmax [lindex [lindex $exclist end] 1]]]
785            } elseif {$graph(xunits) == 2} {
786                set tmin [fromQ $graph(tmin) $hst]
787                set exclist [lreplace $exclist 0 0 \
788                        [list [lindex [lindex $exclist 0] 0] $tmin]]
789            } else {
790                set exclist [lreplace $exclist 0 0 \
791                        [list [lindex [lindex $exclist 0] 0] $graph(tmin)]]
792            }
793        }
794    }
795    catch {
796        if {$graph(tmax) != $start(tmax)} {
797            incr expgui(changed)
798            if {$graph(xunits) == 1} {
799                set tmin [fromd $graph(tmax) $hst]
800                set exclist [lreplace $exclist 0 0 \
801                        [list [lindex [lindex $exclist 0] 0] $tmin]]
802            } elseif {$graph(xunits) == 2} {
803                set tmax [fromQ $graph(tmax) $hst]
804                set exclist [lreplace $exclist end end \
805                        [list $tmax [lindex [lindex $exclist end] 1]]]
806            } else {
807                set exclist [lreplace $exclist end end \
808                        [list $graph(tmax) [lindex [lindex $exclist end] 1]]]
809            }
810        }
811    }
812    if {$startchanges != $expgui(changed)} {
813        CheckForOverlappingRegions $exclist
814        CheckQmaxChanged $oldtmin $oldtmax
815        updateplot
816    } else {
817        return
818    }
819}
820
821# check to see if Qmax (2theta max or TOF min) has changed,
822# if so, other parts of the .EXP file must be changed
823proc CheckQmaxChanged {oldtmin oldtmax} {
824    global graph expmap
825    set hst $graph(hst)
826    set exclist [histinfo $hst excl]
827    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
828        set tmin [lindex [lindex $exclist 0] 1]
829        if {$oldtmin != $tmin} {
830            # edited minimum time -- reset d-min & set CHANS -- use EXPEDT
831            SetTminTOF $tmin [winfo parent $graph(plot)]
832            # Qmax got bigger. Show the new data?
833            if {$tmin < $oldtmin} {QmaxIncreased}
834        }
835    } else {
836        set tmax [lindex [lindex $exclist end] 0]
837        if {$oldtmax != $tmax} {
838            # edited 2theta or Energy max -- reset d-min
839            histinfo $hst dmin set [tod $tmax $hst]
840            if {$tmax > $oldtmax} {QmaxIncreased}
841        }
842    }
843}
844
845# if Qmax has changed, give the user the option to update now so that the
846# new data may be seen in the plot
847proc QmaxIncreased {} {
848    global graph expgui expmap
849    set hst $graph(hst)
850    set msg "The high Q (low d-space) data limit has changed.\nYou must run POWPREF to "
851    append msg "to see the full range of data displayed. Do you want to "
852    append msg "run POWPREF (& possibly GENLES with zero cycles)?"
853    set ans [MyMessageBox -parent . -message $msg -title "Process limits?"\
854            -helplink "expguierr.html ProcessRegions" \
855            -type {Skip {Run POWPREF} {Run POWPREF & GENLES}}]
856    if {$ans == "skip"} {
857        updateplot
858        return
859    } elseif {$ans == "run powpref"} {
860        set cmd powpref
861    } else {
862        set cmd "powpref genles"
863        expinfo cycles set 0
864    }
865    set auto $expgui(autoexpload)
866    set expgui(autoexpload) 1
867    #set expgui(autoiconify) 0
868    runGSASwEXP $cmd
869    set expgui(autoexpload) $auto
870    updateplot
871    if {[string range $expmap(htype_$hst) 2 2] != "T"} {CheckTmax}
872}
873
874# check the maximum 2theta/energy value against the excluded region
875# and reset the limit if it is too high. This is because POWPREF & GENLES
876# can be really slow when there are lots of extra reflections generated.
877proc CheckTmax {} {
878    global graph expgui
879    # clone xvec
880    xvec dup temp
881    set hst $graph(hst)
882    if {$graph(xunits) == 1} {
883        temp sort
884        set max [fromd [temp index 0] $hst]
885        set step [expr abs($max - [fromd [temp index 1] $hst])]
886    } elseif {$graph(xunits) == 2} {
887        temp sort -reverse
888        set max [fromQ [temp index 0] $hst]
889        set step [expr abs($max - [fromQ [temp index 1] $hst])]
890    } else {
891        temp sort -reverse
892        set max [temp index 0]
893        set step [expr $max - [temp index 1]]
894    }
895    set exclist [histinfo $hst excl]
896    if {[lindex [lindex $exclist end] 0] > $max + 10*$step} {
897        if {$graph(xunits) == 1} {
898            set msg "The lower data limit ([tod [lindex [lindex $exclist end] 0] $hst] A) " 
899            set d [tod $max $hst]
900            append msg "is much smaller than the smallest data point ($d A)\n"
901            append msg "You are suggested to set the lower d limit to $d A\n"
902        } elseif {$graph(xunits) == 2} {
903            set msg "The high Q data limit ([toQ [lindex [lindex $exclist end] 0] $hst] A-1) " 
904            set q [toQ $max $hst]
905            append msg "is much larger than the largest data point ($q A-1)\n"
906            append msg "You are suggested to set the upper Q limit to $q A-1\n"
907        } else {
908            set msg "The high Q (low d) data limit ([lindex [lindex $exclist end] 0]) " 
909            append msg "is much larger than the largest data point ($max)\n"
910            append msg "You are suggested to set the limit to $max\n"
911        }
912        append msg "OK to make this change?"
913        set ans [MyMessageBox -parent . -message $msg -title "Reset limits?"\
914                -helplink "expguierr.html RegionTooBig" \
915                -type {OK Cancel}]
916        if {$ans == "ok"} {
917            set item [list [expr $max+$step] [lindex [lindex $exclist end] 1]]
918            incr expgui(changed)
919            set exclist [lreplace $exclist end end $item]
920            histinfo $hst excl set $exclist
921            histinfo $hst dmin set [tod $max $hst]
922            updateplot
923            return
924        }
925    }
926}
927
928# CheckChanges is called before "exiting" (closing the window) to make
929# sure that POWPREF gets run before GENLES so that changes made here
930# take effect
931proc CheckChanges {startchanges} {
932    global expgui graph
933    set hst $graph(hst)
934    if {$expgui(changed) == $startchanges} return
935    set expgui(needpowpref) 2
936    set msg "Excluded regions/data range" 
937    if {[string first $msg $expgui(needpowpref_why)] == -1} {
938        append expgui(needpowpref_why) "\t$msg were changed\n"
939    }
940}
941
942# called in response to pressing one of the excluded region buttons
943# on the bottom bar
944proc EditExclRegion {reg "msg {}"} {
945    global graph expmap expgui
946    set hst $graph(hst)
947    set startchanges $expgui(changed)
948    set exclist [histinfo $hst excl]
949    set oldtmin [lindex [lindex $exclist 0] 1]
950    set oldtmax [lindex [lindex $exclist end] 0]
951    set i [expr {$reg -1}]
952    set range [lindex $exclist $i]
953    toplevel [set box .edit]
954    wm title $box "Edit excluded region"
955    set beg minimum
956    set end maximum
957    set graph(tmin) [format %.4f [lindex $range 0]]
958    set graph(tmax) [format %.4f [lindex $range 1]]
959    if {$msg != ""} {
960        grid [label $box.0 -text $msg -fg red] \
961                -column 1 -row 0 -columnspan 99
962    }
963    if {$graph(xunits) == 1} {
964        set var d-space
965        set unit A
966        set beg maximum
967        set end minimum
968        set graph(tmin) [format %.4f [tod [lindex $range 0] $hst]]
969        set graph(tmax) [format %.4f [tod [lindex $range 1] $hst]]
970    } elseif {$graph(xunits) == 2} {
971        set var Q
972        set unit A-1
973        set graph(tmin) [format %.4f [toQ [lindex $range 0] $hst]]
974        set graph(tmax) [format %.4f [toQ [lindex $range 1] $hst]]
975    } elseif {[string range $expmap(htype_$hst) 2 2] == "T"} {
976        set var TOF
977        set unit ms
978    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
979        set var 2theta
980        set unit deg
981    } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
982        set var Energy
983        set unit KeV
984    } else {
985        set var ?
986        set unit ?
987    }
988    if {$reg == 1} {
989        grid [label $box.1 -text "Editing Data Limits ($unit)"] \
990                -column 1 -row 1 -columnspan 99
991        grid [label $box.2 -text "$beg $var "] \
992                -column 1 -row 2
993        grid [entry $box.3 -width 12 -textvariable graph(tmax)] \
994                -column 2 -row 2
995    } elseif {$reg == [llength $exclist]} {
996        grid [label $box.1 -text "Editing Data Limits ($unit)"] \
997                -column 1 -row 1 -columnspan 99
998        grid [label $box.2 -text "$end $var "] \
999                -column 1 -row 2
1000        grid [entry $box.3 -width 12 -textvariable graph(tmin)] \
1001                -column 2 -row 2
1002    } else {
1003        grid [label $box.1 -text "Editing excluded region #$reg in $var ($unit)"] \
1004                -column 1 -row 1 -columnspan 99
1005        grid [label $box.2 -text "$beg $var "] \
1006                -column 1 -row 2
1007        grid [entry $box.3 -width 12 -textvariable graph(tmin)] \
1008                -column 2 -row 2
1009        grid [label $box.4 -text "$end $var "] \
1010                -column 1 -row 3
1011        grid [entry $box.5 -width 12 -textvariable graph(tmax)] \
1012                -column 2 -row 3
1013    }
1014    # save starting values as tmin & tmax
1015    foreach v {tmin tmax} {
1016        set $v $graph($v)
1017    }
1018    bind $box <Return> "destroy .edit"
1019    grid [frame $box.c] -column 1 -row 99 -columnspan 99
1020    grid [button $box.c.1 -text "OK" -command "destroy .edit"] \
1021            -column 1 -row 1
1022    grid [button $box.c.2 -text "Cancel" \
1023            -command "set graph(tmin) $tmin; set graph(tmax) $tmax;destroy .edit"] \
1024            -column 2 -row 1
1025    putontop $box
1026    tkwait window $box
1027    afterputontop
1028    if {$tmin != $graph(tmin)} {
1029        if {[catch {
1030            expr $graph(tmin)
1031            if {$graph(xunits) == 1} {
1032                set tmin [fromd $graph(tmin) $hst]
1033            } elseif {$graph(xunits) == 2} {
1034                set tmin [fromQ $graph(tmin) $hst]
1035            } else {
1036                set tmin $graph(tmin)
1037            }
1038        }]} {
1039            # recursive call -- should not happen too many times
1040            EditExclRegion $reg "Invalid value entered, try again"
1041            return
1042        }
1043        set exclist [lreplace $exclist $i $i [lreplace $range 0 0 $tmin]]
1044        incr expgui(changed)
1045    }
1046    if {$tmax != $graph(tmax)} {
1047        if {[catch {
1048            expr $graph(tmax)
1049            if {$graph(xunits) == 1} {
1050                set tmax [fromd $graph(tmax) $hst]
1051            } elseif {$graph(xunits) == 2} {
1052                set tmax [fromQ $graph(tmax) $hst]
1053            } else {
1054                set tmax $graph(tmax)
1055            }
1056        }]} {
1057            # recursive call -- should not happen too many times
1058            EditExclRegion $reg "Invalid value entered, try again"
1059            return
1060        }
1061        set exclist [lreplace $exclist $i $i [lreplace $range 1 1 $tmax]]
1062        incr expgui(changed)
1063    }
1064    # did anything change?
1065    if {$expgui(changed) == $startchanges} {return}
1066    # check and save the changed regions
1067    CheckForOverlappingRegions $exclist
1068    CheckQmaxChanged $oldtmin $oldtmax
1069    updateplot
1070}
1071
1072# this is done in response to a change in the window size (<Configure>)
1073# the change is done only when idle and only gets done once.
1074proc scheduleFillExclRegionBox {} {
1075    global graph
1076    # is an update pending?
1077    if {$graph(FillExclRegionBox)} return
1078    set graph(FillExclRegionBox) 1
1079    after idle FillExclRegionBox
1080}
1081
1082# put the background regions into buttons and resize the slider
1083proc FillExclRegionBox {} {
1084    global graph expmap
1085    set hst $graph(hst)
1086    set can $graph(ExclCanvas)
1087    set scroll $graph(ExclScroll)
1088   
1089    catch {destroy [set top $can.fr]}
1090    frame $top -class SmallFont
1091    $can create window 0 0 -anchor nw -window $top
1092    set exclist [histinfo $hst excl]
1093    set col 0
1094    if {[string trim [string range $expmap(htype_$graph(hst)) 3 3]] == "D"} {
1095        $graph(bbox).bl.1 config -text "Dummy\nHistogram"       
1096        foreach c {2 3} {
1097            $graph(bbox).l.b$c config -state disabled
1098        }
1099        if {[string range $expmap(htype_$graph(hst)) 2 2] == "T"} {
1100            set fac 1000.
1101        } elseif {[string range $expmap(htype_$graph(hst)) 2 2] == "E"} {
1102            set fac 1.
1103        } else {
1104            set fac 100.
1105        }           
1106        set start [expr {[histinfo $graph(hst) dstart]/$fac}]
1107        set step  [expr {[histinfo $graph(hst) dstep]/$fac}]
1108        set points [histinfo $graph(hst) dpoints]
1109        set end [expr {$start + $points*$step}]
1110        grid [label $top.$col -text "Range:" \
1111                    -padx 0 -pady 1 -bd 4] \
1112                    -row 0 -column $col
1113        incr col
1114        if {$graph(xunits) == 1} {
1115            foreach i {min max} \
1116                    v [lsort -real [tod [list $start $end] $graph(hst)]] {
1117                grid [label $top.$col -text "$i\n[format %.4f $v]" \
1118                        -padx 3 -pady 1 -bd 2 -relief groove] \
1119                        -row 0 -column $col -sticky ns
1120                incr col
1121            }
1122            grid [label $top.$col -text "\xc5" \
1123                    -padx 0 -pady 1 -bd 4] \
1124                    -row 0 -column $col -sticky nsw -ipadx 5
1125            incr col
1126            grid [label $top.$col -text "points\n$points" \
1127                    -padx 3 -pady 1 -bd 2 -relief groove] \
1128                    -row 0 -column $col -sticky ns
1129            incr col
1130        } elseif {$graph(xunits) == 2} {
1131            foreach i {min max} \
1132                    v [lsort -real [toQ [list $start $end] $graph(hst)]] {
1133                grid [label $top.$col -text "$i\n[format %.3f $v]" \
1134                        -padx 3 -pady 1 -bd 2 -relief groove] -row 0 -column $col -sticky ns
1135                incr col
1136            }
1137            grid [label $top.$col -text "\xc5" \
1138                    -padx 0 -pady 1] \
1139                    -row 0 -column $col
1140            incr col
1141            grid [label $top.$col -text "-1\n" \
1142                    -padx 0 -pady 0] \
1143                    -row 0 -column $col -sticky nsw -ipadx 5
1144            incr col
1145            grid [label $top.$col -text "points\n$points" \
1146                    -padx 3 -pady 1 -bd 2 -relief groove] -row 0 -column $col -sticky ns
1147            incr col
1148        } else {
1149            foreach i {start step end} {
1150                grid [label $top.$col -text "$i\n[set $i]" \
1151                        -padx 3 -pady 1 -bd 2 -relief groove] \
1152                        -row 0 -column $col -sticky ns
1153                incr col
1154            }
1155        }
1156        grid [button $top.b$col -text "Set" \
1157                -command "SetDummyRangeBox $graph(hst) $start $end $step"] \
1158                -sticky ns -row 0 -column $col
1159    } else {
1160        $graph(bbox).bl.1 config -text "Excluded\nRegions"
1161        foreach c {2 3} {
1162            $graph(bbox).l.b$c config -state normal
1163        }
1164        foreach rng $exclist {
1165            if {$graph(xunits) == 1} {
1166                set rng [tod $rng $hst]
1167                if {$col == 0} {
1168                    set lbl ">[format %.4f [lindex $rng 1]]"
1169                } else {
1170                    set lbl "[format %.4f [lindex $rng 0]]\nto [format %.4f [lindex $rng 1]]"
1171                }
1172                incr col
1173                if {$col == [llength $exclist]} {
1174                    set lbl "<[format %.4f [lindex $rng 0]]"
1175                }
1176            } else {
1177                if {$graph(xunits) == 2} {
1178                    set rng [toQ $rng $hst]
1179                }
1180                if {$col == 0} {
1181                    set lbl "<[format %.3f [lindex $rng 1]]"
1182                } else {
1183                    set lbl "[format %.3f [lindex $rng 0]]\nto [format %.3f [lindex $rng 1]]"
1184                }
1185                incr col
1186                if {$col == [llength $exclist]} {
1187                    set lbl ">[format %.3f [lindex $rng 0]]"
1188                }
1189            }
1190            grid [button $top.$col -text $lbl -command "EditExclRegion $col" \
1191                    -padx 1 -pady 1] -row 0 -column $col -sticky  ns
1192        }
1193    }
1194    update idletasks
1195    set sizes [grid bbox $top]
1196    $can config -scrollregion $sizes -height [lindex $sizes 3]
1197    if {[lindex $sizes 2] <= [winfo width $can]} {
1198        grid forget $scroll
1199    } else {
1200        grid $graph(ExclScroll) -column 1 -row 4 -columnspan 5 -sticky nsew
1201    }
1202    # clear flag
1203    set graph(FillExclRegionBox) 0
1204}
1205
1206# manual zoom option
1207proc BLTmanualZoom {} {
1208    global graph
1209    catch {toplevel .zoom}
1210    wm title .zoom "Manual zoom"
1211    eval destroy [grid slaves .zoom]
1212    raise .zoom
1213    wm title .zoom {Manual Scaling}
1214    grid [label .zoom.l1 -text minimum] -row 1 -column 2 
1215    grid [label .zoom.l2 -text maximum] -row 1 -column 3 
1216    grid [label .zoom.l3 -text x] -row 2 -column 1 
1217    grid [label .zoom.l4 -text y] -row 3 -column 1 
1218    grid [entry .zoom.xmin -textvariable graph(xmin) -width 10] -row 2 -column 2 
1219    grid [entry .zoom.xmax -textvariable graph(xmax) -width 10] -row 2 -column 3 
1220    grid [entry .zoom.ymin -textvariable graph(ymin) -width 10] -row 3 -column 2 
1221    grid [entry .zoom.ymax -textvariable graph(ymax) -width 10] -row 3 -column 3 
1222    grid [frame .zoom.b] -row 4 -column 1 -columnspan 3
1223    grid [button .zoom.b.1 -text "Set Scaling" \
1224             -command "SetManualZoom set"]  -row 4 -column 1 -columnspan 2
1225    grid [button .zoom.b.2 -text Reset \
1226            -command "SetManualZoom clear"] -row 4 -column 3
1227    grid [button .zoom.b.3 -text Close -command "destroy .zoom"] -row 4 -column 4 
1228    grid rowconfigure .zoom 1 -weight 1 -pad 5
1229    grid rowconfigure .zoom 2 -weight 1 -pad 5
1230    grid rowconfigure .zoom 3 -weight 1 -pad 5
1231    grid rowconfigure .zoom 4 -weight 0 -pad 5
1232    grid columnconfigure .zoom 1 -weight 1 -pad 20
1233    grid columnconfigure .zoom 1 -weight 1 
1234    grid columnconfigure .zoom 3 -weight 1 -pad 10
1235    foreach item {min min max max} \
1236            format {3   2   3   2} \
1237            axis   {x   y   x   y} {
1238        set val [$graph(plot) ${axis}axis cget -${item}]
1239        set graph(${axis}${item}) {(auto)}
1240        catch {set graph(${axis}${item}) [format %.${format}f $val]}
1241    }
1242    putontop .zoom
1243    tkwait window .zoom
1244    afterputontop   
1245}
1246
1247proc SetManualZoom {mode} {
1248    global graph
1249    if {$mode == "clear"} {
1250        foreach item {xmin ymin xmax ymax} {
1251            set graph($item) {(auto)}
1252        }
1253    }
1254    foreach item {xmin ymin xmax ymax} {
1255        if {[catch {expr $graph($item)}]} {
1256            set $item ""
1257        } else {
1258            set $item $graph($item)
1259        }
1260    }
1261    # reset the zoomstack
1262    catch {Blt_ZoomStack $graph(plot)}
1263    catch {$graph(plot) xaxis config -min $xmin -max $xmax}
1264    catch {$graph(plot) yaxis config -min $ymin -max $ymax}
1265}
1266
1267# code to create the EXCLEDT box
1268proc ShowExcl {} {
1269    global graph peakinfo expgui expmap
1270    # save the starting number of cycles & starting point
1271    set cycsav [expinfo cycles]
1272    set startchanges $expgui(changed)
1273    set graph(hst) [lindex $expgui(curhist) 0]
1274    if {[llength $expgui(curhist)] == 0} {
1275        set graph(hst) [lindex $expmap(powderlist) 0]
1276    } else {
1277        set graph(hst) [lindex $expmap(powderlist) $graph(hst)]
1278    }   
1279    set graph(exclbox) .excl
1280    catch {toplevel $graph(exclbox)}
1281    wm title $graph(exclbox) "Excluded Region/Data Range Edit"
1282    eval destroy [winfo children $graph(exclbox)]
1283    # create the graph
1284    if [catch {
1285        set graph(plot) [graph $graph(exclbox).g -plotbackground white]
1286    } errmsg] {
1287        MyMessageBox -parent . -title "BLT Error" \
1288                -message "BLT Setup Error: could not create a graph \
1289(error msg: $errmsg). \
1290There is a problem with the setup of BLT on your system. \
1291See the expgui.html file for more info." \
1292        -helplink "expgui.html blt" \
1293        -icon warning -type Skip -default "skip" 
1294        destroy $graph(exclbox)
1295        return
1296    }
1297    if [catch {
1298        Blt_ZoomStack $graph(plot)
1299    } errmsg] {
1300        MyMessageBox -parent . -title "BLT Error" \
1301                -message "BLT Setup Error: could not access a Blt_ routine \
1302(msg: $errmsg). \
1303The pkgIndex.tcl is probably not loading bltGraph.tcl.
1304See the expgui.html file for more info." \
1305        -helplink "expgui.html blt" \
1306        -icon warning -type {"Limp Ahead"} -default "limp Ahead" 
1307    }
1308    $graph(plot) element create 3 -color black -linewidth 0 -label Obs \
1309            -symbol $peakinfo(obssym) -color $graph(color_obs) \
1310            -pixels [expr 0.125 * $peakinfo(obssize)]i
1311    $graph(plot) element create 2 -label Calc -color $graph(color_calc) \
1312            -symbol none 
1313    $graph(plot) element create 12 -line 0 -label "Excl" \
1314            -color $graph(color_excl) \
1315            -symbol $peakinfo(exclsym) \
1316            -pixels [expr 0.15 * $peakinfo(exclsize)]i
1317    $graph(plot) element show "3 2 12 1"
1318    $graph(plot) element config 3 -xdata xvec -ydata obsvec
1319    $graph(plot) element config 2 -xdata xvec -ydata calcvec
1320    $graph(plot) element config 12 -xdata exxvec -ydata exobsvec
1321
1322    $graph(plot) yaxis config -title {} 
1323    setlegend $graph(plot) $graph(legend)
1324
1325    set graph(exclmenu) [frame $graph(exclbox).a -bd 3 -relief groove]
1326    pack [menubutton $graph(exclmenu).file -text File -underline 0 \
1327            -menu $graph(exclmenu).file.menu] -side left
1328    menu $graph(exclmenu).file.menu
1329    $graph(exclmenu).file.menu add cascade -label Tickmarks \
1330            -menu $graph(exclmenu).file.menu.tick
1331    menu $graph(exclmenu).file.menu.tick
1332
1333    $graph(exclmenu).file.menu add cascade -label Histogram \
1334            -menu $graph(exclmenu).file.menu.hist -state disabled
1335
1336    $graph(exclmenu).file.menu add command \
1337            -label "Set Min/Max Range" -command setminormax
1338    $graph(exclmenu).file.menu add command \
1339            -label "Update Plot" -command "CheckChanges $startchanges;updateplot"
1340    $graph(exclmenu).file.menu add command \
1341            -label "Make PostScript" -command makepostscriptout
1342    $graph(exclmenu).file.menu add command \
1343            -label Finish -command "CheckChanges $startchanges;destroy $graph(exclbox)"
1344
1345    pack [menubutton $graph(exclmenu).options -text Options -underline 0 \
1346            -menu $graph(exclmenu).options.menu] \
1347            -side left   
1348    menu $graph(exclmenu).options.menu
1349    $graph(exclmenu).options.menu add cascade -label "Configure Tickmarks" \
1350            -menu $graph(exclmenu).options.menu.tick
1351    menu $graph(exclmenu).options.menu.tick
1352    $graph(exclmenu).options.menu.tick add radiobutton \
1353            -label "Manual Placement" \
1354            -value 0 -variable expgui(autotick) -command plotExclData
1355    $graph(exclmenu).options.menu.tick add radiobutton \
1356            -label "Auto locate" \
1357            -value 1 -variable expgui(autotick) -command plotExclData
1358    $graph(exclmenu).options.menu.tick add separator
1359
1360    $graph(exclmenu).options.menu add cascade -label "Symbol Type" \
1361            -menu $graph(exclmenu).options.menu.sym
1362    menu $graph(exclmenu).options.menu.sym
1363    foreach var {excl obs} lbl {Excluded Observed} {
1364        $graph(exclmenu).options.menu.sym add command -label $lbl \
1365                -command "getsymopts $var"
1366    }
1367
1368    $graph(exclmenu).options.menu add cascade -label "Symbol color" \
1369            -menu $graph(exclmenu).options.menu.color
1370    menu $graph(exclmenu).options.menu.color
1371    foreach var {excl calc obs} lbl {Excluded Calculated Observed} {
1372        $graph(exclmenu).options.menu.color add command -label $lbl \
1373                -command "set graph(color_$var) \[tk_chooseColor -initialcolor \$graph(color_$var) -title \"Choose \$lbl color\"]; plotExclData"
1374    }
1375    $graph(exclmenu).options.menu add cascade -label "X units" \
1376            -menu $graph(exclmenu).options.menu.xunits
1377    menu $graph(exclmenu).options.menu.xunits
1378    $graph(exclmenu).options.menu.xunits add radiobutton \
1379            -label "As collected" \
1380            -variable graph(xunits) -value 0 \
1381            -command updateplot
1382    $graph(exclmenu).options.menu.xunits add radiobutton -label "d-space" \
1383            -variable graph(xunits) -value 1 \
1384            -command updateplot
1385    $graph(exclmenu).options.menu.xunits add radiobutton -label "Q" \
1386            -variable graph(xunits) -value 2 \
1387            -command updateplot
1388
1389    $graph(exclmenu).options.menu add checkbutton -label "Include legend" \
1390            -variable graph(legend) \
1391            -command {setlegend $graph(plot) $graph(legend)}
1392    $graph(exclmenu).options.menu add checkbutton -label "Prompt on add/del" \
1393            -variable graph(exclPrompt)
1394    $graph(exclmenu).options.menu add command -label "Set PS output" \
1395            -command setpostscriptout
1396    # phase options
1397    foreach num $expmap(phaselist) {
1398        $graph(exclmenu).file.menu.tick add checkbutton -label "Phase $num" \
1399                -variable peakinfo(flag$num)
1400        bind [winfo toplevel $graph(plot)] <Key-$num> \
1401                "set peakinfo(flag$num) \[expr !\$peakinfo(flag$num)\]"
1402        $graph(exclmenu).options.menu.tick add command -label "Phase $num" \
1403                -command "minioptionsbox $num"
1404    }
1405
1406    set graph(bbox) [set bb $graph(exclbox).b]
1407    catch {pack [frame $bb -bd 3 -relief sunken] -side bottom -fill both}
1408    grid [label $bb.top -text "Excluded Region Editing"] \
1409            -column 0 -row 0 -columnspan 4
1410    grid [button $bb.help -text Help -bg yellow \
1411            -command "MakeWWWHelp excledt.html"] \
1412            -column 5 -row 0 -rowspan 1 -sticky ne
1413   
1414    grid [frame $bb.l -bd 3 -relief groove] \
1415            -column 0 -row 1 -columnspan 2 -sticky nse
1416    grid [label $bb.l.1 -text "Mouse click\naction"] -column 0 -row 0
1417    foreach c {1 2 3} l {zoom "Add\nregion" "Delete\nregion"} {
1418        grid [button $graph(bbox).l.b$c -text $l -command "exclEditMode $c $bb"] \
1419                -column $c -row 0 -sticky ns
1420    }
1421    exclEditMode 1 $bb
1422
1423    grid [frame $bb.bl] \
1424            -column 0 -row 3 -rowspan 2 -sticky nsew
1425    grid [label $graph(bbox).bl.1 -text "Excluded\nRegions"] -column 0 -row 0 
1426    grid [canvas [set graph(ExclCanvas) $bb.bc] \
1427            -scrollregion {0 0 5000 500} -width 0 -height 0 \
1428            -xscrollcommand "$bb.bs set"] \
1429            -column 1 -row 3 -columnspan 5 -sticky nsew
1430    grid [scrollbar [set  graph(ExclScroll) $bb.bs] -command "$bb.bc xview" \
1431            -orient horizontal] \
1432            -column 1 -row 4 -columnspan 5 -sticky nsew
1433    grid [button $bb.cw -text "Save &\nFinish" \
1434            -command "CheckChanges $startchanges;destroy $graph(exclbox)"] \
1435        -column 4 -row 1 -columnspan 2 -sticky ns
1436
1437    grid columnconfigure $bb 1 -weight 1
1438    grid columnconfigure $bb 5 -weight 1
1439    grid rowconfigure $bb 3 -weight 1
1440    grid rowconfigure $bb 5 -weight 1
1441   
1442    pack $graph(exclmenu) -side top -fill both
1443    pack $graph(plot) -fill both -expand yes
1444
1445    # fill the histogram menu
1446    if {[llength $expmap(powderlist)] > 15} {
1447        set expgui(plotlist) {}
1448        $graph(exclmenu).file.menu entryconfigure Histogram -state normal
1449        menu $graph(exclmenu).file.menu.hist
1450        set i 0
1451        foreach num [lsort -integer $expmap(powderlist)] {
1452            incr i
1453            lappend expgui(plotlist) $num
1454            if {$i == 1} {
1455                set num1 $num
1456                menu $graph(exclmenu).file.menu.hist.$num1
1457            }
1458            $graph(exclmenu).file.menu.hist.$num1 add radiobutton \
1459                    -label $num -value $num \
1460                    -variable graph(hst) \
1461                    -command updateplot
1462            if {$i >= 10} {
1463                set i 0
1464                $graph(exclmenu).file.menu.hist add cascade \
1465                        -label "$num1-$num" \
1466                        -menu $graph(exclmenu).file.menu.hist.$num1
1467            }
1468        }
1469        if {$i != 0} {
1470            $graph(exclmenu).file.menu.hist add cascade \
1471                    -label "$num1-$num" \
1472                    -menu $graph(exclmenu).file.menu.hist.$num1
1473        }
1474    } elseif {[llength $expmap(powderlist)] > 1} {
1475        $graph(exclmenu).file.menu entryconfigure Histogram -state normal
1476        menu $graph(exclmenu).file.menu.hist
1477        set i 0
1478        foreach num [lsort -integer $expmap(powderlist)] {
1479            foreach num [lsort -integer $expmap(powderlist)] {
1480                lappend expgui(plotlist) $num
1481                $graph(exclmenu).file.menu.hist add radiobutton \
1482                        -label $num -value $num \
1483                        -variable graph(hst) \
1484                        -command updateplot
1485            }
1486        }
1487    } else {
1488        set expgui(plotlist) [lindex $expmap(powderlist) 0]
1489    }
1490
1491    # N = load next histogram
1492    bind $graph(exclbox) <Key-n> {
1493        global expgui graph
1494        set i [lsearch $expgui(plotlist) $graph(hst)]
1495        incr i
1496        if {$i >= [llength $expgui(plotlist)]} {set i 0}
1497        set graph(hst) [lindex $expgui(plotlist) $i]
1498        updateplot
1499    }
1500    bind $graph(exclbox) <Key-N> {
1501        global expgui graph
1502        set i [lsearch $expgui(plotlist) $graph(hst)]
1503        incr i
1504        if {$i >= [llength $expgui(plotlist)]} {set i 0}
1505        set graph(hst) [lindex $expgui(plotlist) $i]
1506        set cycle [getcycle];readdata .g
1507    }
1508    bind $graph(exclbox) <Key-z> {BLTmanualZoom}
1509    bind $graph(exclbox) <Key-Z> {BLTmanualZoom}
1510    updateplot
1511    trace variable peakinfo w plotExclData
1512
1513    # catch exits -- launch POWPREF; if changes non-zero
1514    wm protocol $graph(exclbox) WM_DELETE_WINDOW "CheckChanges $startchanges;destroy $graph(exclbox)"
1515    # respond to resize events
1516    bind $graph(exclbox) <Configure> scheduleFillExclRegionBox
1517    bind all <Control-KeyPress-c> "CheckChanges $startchanges;destroy $graph(exclbox)"
1518    #putontop $graph(exclbox)
1519    wm deiconify $graph(exclbox)
1520    wm iconify .
1521    update
1522    tkwait window $graph(exclbox)
1523    #afterputontop
1524    wm deiconify .
1525    bind all <Control-c> catchQuit
1526    # reset the number of cycles if they have changed
1527    if {$cycsav != [expinfo cycles]} {
1528        global entryvar
1529        set entryvar(cycles) $cycsav
1530    }
1531}
1532
1533proc SetDummyRangeBox {hst tmin tmax tstep} {
1534    global newhist expmap
1535    if {[histinfo $hst dtype] != "CONST"} {
1536        MyMessageBox -parent $np -title  "Change Range Error" \
1537                -message "This histogram (#$hst) does not have constant steps. The range must be changed in EXPEDT." \
1538                -icon error -type ok -default ok \
1539                -helplink "excledt.html editdummy"
1540        return
1541    }
1542    catch {toplevel [set np ".dummy"]}
1543    wm title $np "Dummy Histogram Range"
1544    eval destroy [winfo children $np]
1545    # delete old traces, if any
1546    foreach var {tmin tmax tstep} {
1547        foreach v [ trace vinfo newhist($var)] {
1548            eval trace vdelete newhist($var) $v
1549        }
1550    }
1551    # set defaults to current values
1552    foreach v {tmin tmax tstep} {set newhist($v) [set $v]}
1553    trace variable newhist(tmin) w "ValidateDummyRange $np $hst"
1554    trace variable newhist(tmax) w "ValidateDummyRange $np $hst"
1555    trace variable newhist(tstep) w "ValidateDummyRange $np $hst"
1556    pack [frame $np.d1]
1557    grid [label $np.d1.l1 -text min] -column 1 -row 1
1558    grid [label $np.d1.l2 -text max] -column 2 -row 1
1559    grid [label $np.d1.l3 -text step] -column 3 -row 1
1560    grid [label $np.d1.lu -text ""] -column 4 -row 1 -rowspan 2
1561    grid [entry $np.d1.e1 -width 10 -textvariable newhist(tmin)] -column 1 -row 2
1562    grid [entry $np.d1.e2 -width 10 -textvariable newhist(tmax)] -column 2 -row 2
1563    grid [entry $np.d1.e3 -width 10 -textvariable newhist(tstep)] -column 3 -row 2
1564    grid [label $np.d1.m1 -anchor w -padx 5] -column 1 -row 3 -sticky ew
1565    grid [label $np.d1.m2 -anchor w -padx 5] -column 2 -row 3 -sticky ew
1566    label $np.dl1 -text "Data range:"
1567    label $np.dl2 -text "Allowed"
1568    label $np.dl3 -text "\n" -justify left -fg blue
1569    grid [frame $np.f6] -column 0 -row 99 -columnspan 5 -sticky ew
1570    grid [button $np.f6.b6a -text Set \
1571            -command "SetDummyRange $np $hst"] -column 0 -row 0
1572    bind $np <Return> "SetDummyRange $np $hst"
1573    grid [button $np.f6.b6b -text Cancel \
1574            -command "destroy $np"] -column 1 -row 0
1575    set link "excledt.html editdummy"
1576    bind $np <Key-F1> "MakeWWWHelp $link"
1577    grid [button $np.f6.help -text Help -bg yellow \
1578            -command "MakeWWWHelp $link"] \
1579            -column 2 -row 0 -sticky e
1580    grid columnconfigure $np.f6 2 -weight 1
1581
1582    $np.d1.m1 config -text {}
1583    $np.d1.m2 config -text {}
1584    grid $np.dl1 -column 0 -row 8
1585    grid $np.d1 -column 1 -row 8 -rowspan 2 -columnspan 4 -sticky e
1586    grid $np.dl3 -column 0 -columnspan 99 -row 10 -sticky ew
1587    grid [label $np.l1 -text "Set range for dummy histogram $hst" \
1588            -justify center -anchor center -bg beige] \
1589            -row 0 -column 0 -columnspan 5 -sticky ew
1590    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
1591        $np.dl1 config -text "Data range:\n(TOF)"
1592        $np.d1.lu config -text millisec
1593        grid $np.dl2 -column 0 -row 9
1594        catch {
1595            set line [histinfo $hst ITYP]
1596            $np.d1.m1 config -text [lindex $line 1]
1597            $np.d1.m2 config -text [lindex $line 2]
1598        }
1599    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
1600        $np.dl1 config -text "Data range:\n(2Theta)"
1601        $np.d1.lu config -text degrees
1602        $np.d1.m1 config -text >0.
1603        $np.d1.m2 config -text <180.
1604    } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
1605        $np.dl1 config -text "Data range:\n(Energy)"
1606        $np.d1.lu config -text KeV
1607        $np.d1.m1 config -text 1.
1608        $np.d1.m2 config -text 200.
1609        grid $np.dl2 -column 0 -row 9
1610    }
1611    ValidateDummyRange $np $hst
1612    putontop $np
1613    grab $np
1614    tkwait window $np
1615    afterputontop   
1616}
1617
1618proc ValidateDummyRange {np hst args} {
1619    # validate input
1620    global newhist expmap
1621    set msg {}
1622    $np.dl3 config -text "\n"
1623    foreach e {e1 e2 e3} v {tmin tmax tstep} {
1624        if [catch {expr $newhist($v)}] {
1625            $np.d1.$e config -fg red
1626            append msg "Value of $newhist($v) is invalid for $v\n"
1627        } else {
1628            $np.d1.$e config -fg black
1629        }
1630    }
1631    if {$newhist(tmax) <= $newhist(tmin)} {
1632        $np.d1.e1 config -fg red
1633        $np.d1.e2 config -fg red
1634        return "Tmax <= Tmin\n"
1635    }
1636
1637
1638    set dmin -1
1639    set dmax -1
1640    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
1641        catch {
1642            set line [histinfo $hst ITYP]
1643            set tmin [lindex $line 1]
1644            set tmax [lindex $line 2]
1645            if {$newhist(tmin) <$tmin } {
1646                $np.d1.e1 config -fg red
1647                append msg "Min value of $newhist(tmin) msec is invalid.\n"
1648            }
1649            if {$newhist(tmax) >$tmax } {
1650                $np.d1.e2 config -fg red
1651                append msg "Max value of $newhist(tmax) msec is invalid.\n"
1652            }
1653            set difc [histinfo $hst difc]
1654            set dmin [expr {1000. * $newhist(tmin) / $difc}]
1655            set dmax [expr {1000. * $newhist(tmax) / $difc}]
1656        }
1657    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
1658        if {$newhist(tmin) <= 0 } {
1659            $np.d1.e1 config -fg red
1660            append msg "Min value of $newhist(tmin) degrees is invalid.\n"
1661        }
1662        if {$newhist(tmax) >=180 } {
1663            $np.d1.e2 config -fg red
1664            append msg "Max value of $newhist(tmax) degrees is invalid.\n"
1665        }
1666        catch {
1667            set lam [histinfo $hst lam1]
1668            set dmin [expr {$lam * 0.5 / sin(acos(0.)*$newhist(tmax)/180.)}]
1669            set dmax [expr {$lam * 0.5 / sin(acos(0.)*$newhist(tmin)/180.)}]
1670        }
1671    } else {
1672        if {$newhist(tmin) <1 } {
1673            $np.d1.e1 config -fg red
1674            append msg "Min value of $newhist(tmin) KeV is invalid.\n"
1675        }
1676        if {$newhist(tmax) >200 } {
1677            $np.d1.e2 config -fg red
1678            append msg "Max value of $newhist(tmax) KeV is invalid.\n"
1679        }
1680        catch {
1681            set ang [histinfo $hst lam1]
1682            set dmin [expr {12.398/ (2.0*sin($ang*acos(0.)/180) * \
1683                    $newhist(tmax))}]
1684            set dmax [expr {12.398/ (2.0*sin($ang*acos(0.)/180) * \
1685                    $newhist(tmin))}]
1686        }
1687    }
1688    if {$msg != ""} {return $msg}
1689    set pnts -1
1690    catch {
1691        set pnts [expr {1+int(($newhist(tmax) - $newhist(tmin))/$newhist(tstep))}]
1692        set qmin [expr {4.*acos(0)/$dmax}]
1693        set qmax [expr {4.*acos(0)/$dmin}]
1694    }
1695    if {$pnts <= 0} {
1696        $np.d1.e3 config -fg red
1697        append msg "Step value of $newhist(tstep) is invalid.\n"
1698    }
1699    if {$pnts >20000} {
1700        $np.d1.e3 config -fg red
1701        append msg "Step value of $newhist(tstep) is too small (>20000 points).\n"
1702    }
1703    if {$msg != ""} {return $msg}
1704    if {$dmin > 0 && $dmax > 0} {
1705        catch {
1706            set msg [format \
1707                    "  %d points.%s  D-space range: %.2f-%.2f \xc5,  Q: %.2f-%.2f/\xc5" \
1708                    $pnts "\n" $dmin $dmax $qmin $qmax]
1709            $np.dl3 config -text $msg
1710        }
1711    }
1712    if {$msg != ""} {return ""}
1713    $np.dl3 config -text [format {  %d points.%s  Range: ?} $pnts "\n"]
1714    return "Invalid data range -- something is wrong!"
1715}
1716
1717proc SetDummyRange {np hst} {
1718    global newhist expmap
1719    # validate last time
1720    set msg [ValidateDummyRange $np $hst]
1721    if {$msg != ""} {
1722        MyMessageBox -parent $np -title  "Change Range Error" \
1723                -message "The following error(s) were found in your input:\n$msg" \
1724                -icon error -type ok -default ok \
1725                -helplink "excledt.html editdummy"
1726        return
1727    }
1728    set pnts [expr {1+int(($newhist(tmax) - $newhist(tmin))/$newhist(tstep))}]
1729
1730    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
1731        lappend exclist "0 [expr {$newhist(tmin)-$newhist(tstep)}]" \
1732                "[expr {$newhist(tmax)+$newhist(tstep)}] 1000."
1733        histinfo $hst excl set $exclist
1734        histinfo $hst dpoints set $pnts
1735        histinfo $hst dstart  set [expr {$newhist(tmin)*1000.}]
1736        histinfo $hst dstep   set [expr {$newhist(tstep)*1000.}]
1737        histinfo $hst dmin set [tod $newhist(tmin) $hst]
1738    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
1739        lappend exclist "0 [expr {$newhist(tmin)-$newhist(tstep)}]" \
1740                "[expr {$newhist(tmax)+$newhist(tstep)}] 1000."
1741        histinfo $hst excl set $exclist
1742        histinfo $hst dpoints set $pnts
1743        histinfo $hst dstart  set [expr {$newhist(tmin)*100.}]
1744        histinfo $hst dstep   set [expr {$newhist(tstep)*100.}]
1745        histinfo $hst dmin set [tod $newhist(tmax) $hst]
1746    } else {
1747        lappend exclist "0 [expr {$newhist(tmin)-$newhist(tstep)}]" \
1748                "[expr {$newhist(tmax)+$newhist(tstep)}] 1000."
1749        histinfo $hst excl set $exclist
1750        histinfo $hst dpoints set $pnts
1751        histinfo $hst dstart  set $newhist(tmin)
1752        histinfo $hst dstep   set $newhist(tstep)
1753        histinfo $hst dmin set [tod $newhist(tmax) $hst]
1754    }
1755    global expgui
1756    incr expgui(changed) 5
1757    destroy $np
1758    updateplot
1759}
1760
1761# set the minimum tof/d-space using the EXPEDT program
1762proc SetTminTOF {tmin parent} {
1763    global expgui reflns graph tcl_platform
1764    set hst $graph(hst)
1765    set input [open excl$hst.inp w]
1766    puts $input "Y"
1767    puts $input "p h e $hst"
1768    puts $input "T"
1769    puts $input "$tmin"
1770    puts $input "/"
1771    puts $input "x x x"
1772    puts $input "x"
1773    close $input
1774    # Save the current exp file
1775    savearchiveexp
1776    # disable the file changed monitor
1777    set expgui(expModifiedLast) 0
1778    set expnam [file root [file tail $expgui(expfile)]]
1779    set err [catch {
1780        if {$tcl_platform(platform) == "windows"} {
1781            exec [file join $expgui(gsasexe) expedt.exe] $expnam < excl$hst.inp >& excl$hst.out
1782        } else {
1783            exec [file join $expgui(gsasexe) expedt] $expnam < excl$hst.inp >& excl$hst.out
1784        }
1785    } errmsg]
1786    loadexp $expgui(expfile)
1787    catch {file delete excl$hst.inp}
1788    if {$expgui(showexptool) || $err} {
1789        set fp [open excl$hst.out r]
1790        set out [read $fp]
1791        close $fp
1792        if {$errmsg != ""} {
1793            append errmsg "\n" $out
1794        } else {
1795            set errmsg $out
1796        }
1797        set msg "Please review the result from changing the TOF minimum." 
1798        if {$err} {append msg "\nIt appears an error occurred!"}
1799        ShowBigMessage $parent.msg $msg $errmsg OK "" $err
1800    }
1801}
Note: See TracBrowser for help on using the repository browser.