Changeset 666 for trunk/excledt.tcl


Ignore:
Timestamp:
Dec 4, 2009 5:09:59 PM (11 years ago)
Author:
toby
Message:

# on 2003/04/10 21:55:15, toby did:
Major revisions to fix TOF bugs

(use EXPEDT to set TMIN)

move conversion routines to readexp.tcl
many new comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/excledt.tcl

    • Property rcs:date changed from 2002/07/18 20:50:04 to 2003/04/10 21:55:15
    • Property rcs:lines changed from +25 -15 to +180 -374
    • Property rcs:rev changed from 1.8 to 1.9
    r630 r666  
    11# $Id$
    22
     3# create the main Excluded Region window
    34proc ExclReaddata {box} {
    45    global expgui
     
    2425}
    2526   
     27# get the data to plot using hstdump (tcldump does not show the excluded data)
    2628proc ExclReaddata_hst {box} {
    2729    global expgui reflns graph
     
    3941    # use hstdmp without an experiment name so that output
    4042    # is not sent to the .LST file
    41     exec $expgui(gsasexe)/hstdmp < excl$hst.inp > excl$hst.out
     43    exec [file join $expgui(gsasexe) hstdmp] < excl$hst.inp > excl$hst.out
    4244    set input [open excl$hst.out r]
    4345    catch {file delete excl$hst.inp}
     
    127129        }
    128130    }
    129     plotdata
    130 }
    131 
    132 # convert x values to d-space
    133 proc tod {xlist hst} {
    134     global expmap
    135     if {[string range $expmap(htype_$hst) 2 2] == "T"} {
    136         return [toftod $xlist $hst]
    137     } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
    138         return [tttod $xlist $hst]
    139     } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
    140         return [engtod $xlist $hst]
    141     } else {
    142         return {}
    143     }
    144 }
    145 
    146 # convert tof to d-space
    147 proc toftod {toflist hst} {
    148     set difc [expr {[histinfo $hst difc]/1000.}]
    149     set difc2 [expr {$difc*$difc}]
    150     set difa [expr {[histinfo $hst difa]/1000.}]
    151     set zero [expr {[histinfo $hst zero]/1000.}]
    152     set ans {}
    153     foreach tof $toflist {
    154         if {$tof == 0.} {
    155             lappend ans 0.
    156         } elseif {$tof == 1000.} {
    157             lappend ans 1000.
    158         } else {
    159             set td [expr {$tof-$zero}]
    160             lappend ans [expr {$td*($difc2+$difa*$td)/ \
    161                     ($difc2*$difc+2.0*$difa*$td)}]
    162         }
    163     }
    164     return $ans
    165 }
    166 
    167 # convert two-theta to d-space
    168 proc tttod {twotheta hst} {
    169     set lamo2 [expr {0.5 * [histinfo $hst lam1]}]
    170     set zero [expr [histinfo $hst zero]/100.]
    171     set ans {}
    172     set cnv [expr {acos(0.)/180.}]
    173     foreach tt $twotheta {
    174         if {$tt == 0.} {
    175             lappend ans 99999.
    176         } elseif {$tt == 1000.} {
    177             lappend ans 0.
    178         } else {
    179             lappend ans [expr {$lamo2 / sin($cnv*($tt-$zero))}]
    180         }
    181     }
    182     return $ans
    183 }
    184 
    185 # convert energy (edx-ray) to d-space
    186 # (note that this ignores the zero correction)
    187 proc engtod {eng hst} {
    188     set lam [histinfo $hst lam1]
    189     set zero [histinfo $hst zero]
    190     set ans {}
    191     set v [expr {12.398/(2.0*[sind[expr ($lam/2.0)]])}]
    192     foreach e $eng {
    193         if {$e == 0.} {
    194             lappend ans 1000.
    195         } elseif {$e == 1000.} {
    196             lappend ans 0.
    197         } else {
    198             lappend ans [expr {$v/$e}]
    199         }
    200     }
    201     return $ans
    202 }
    203 
    204 # convert x values to Q
    205 proc toQ {xlist hst} {
    206     global expmap
    207     if {[string range $expmap(htype_$hst) 2 2] == "T"} {
    208         return [toftoQ $xlist $hst]
    209     } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
    210         return [tttoQ $xlist $hst]
    211     } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
    212         return [engtoQ $xlist $hst]
    213     } else {
    214         return {}
    215     }
    216 }
    217 # convert tof to Q
    218 proc toftoQ {toflist hst} {
    219     set difc [expr {[histinfo $hst difc]/1000.}]
    220     set difc2 [expr {$difc*$difc}]
    221     set difa [expr {[histinfo $hst difa]/1000.}]
    222     set zero [expr {[histinfo $hst zero]/1000.}]
    223     set 2pi [expr {4.*acos(0.)}]
    224     set ans {}
    225     foreach tof $toflist {
    226         if {$tof == 0.} {
    227             lappend ans 99999.
    228         } elseif {$tof == 1000.} {
    229             lappend ans 0.
    230         } else {
    231             set td [expr {$tof-$zero}]
    232             lappend ans [expr {$2pi * \
    233                     ($difc2*$difc+2.0*$difa*$td)/($td*($difc2+$difa*$td))}]
    234         }
    235     }
    236     return $ans
    237 }
    238 
    239 # convert two-theta to Q
    240 proc tttoQ {twotheta hst} {
    241     set lamo2 [expr {0.5 * [histinfo $hst lam1]}]
    242     set zero [expr [histinfo $hst zero]/100.]
    243     set ans {}
    244     set cnv [expr {acos(0.)/180.}]
    245     set 2pi [expr {4.*acos(0.)}]
    246     foreach tt $twotheta {
    247         if {$tt == 0.} {
    248             lappend ans 0.
    249         } elseif {$tt == 1000.} {
    250             lappend ans 1000.
    251         } else {
    252             lappend ans [expr {$2pi * sin($cnv*($tt-$zero)) / $lamo2}]
    253         }
    254     }
    255     return $ans
    256 }
    257 # convert energy (edx-ray) to Q
    258 # (note that this ignores the zero correction)
    259 proc engtoQ {eng hst} {
    260     set lam [histinfo $hst lam1]
    261     set zero [histinfo $hst zero]
    262     set ans {}
    263     set v [expr {12.398/(2.0*[sind[expr ($lam/2.0)]])}]
    264     set 2pi [expr {4.*acos(0.)}]
    265     foreach e $eng {
    266         if {$e == 0.} {
    267             lappend ans 0.
    268         } elseif {$e == 1000.} {
    269             lappend ans 1000.
    270         } else {
    271             lappend ans [expr {$2pi * $e / $v}]
    272         }
    273     }
    274     return $ans
    275 }
    276 proc sind {angle} {
    277     return [expr {sin($angle*acos(0.)/90.)}]
    278 }
    279 
    280 # convert d-space values to 2theta, TOF or KeV
    281 proc fromd {dlist hst} {
    282     global expmap
    283     if {[string range $expmap(htype_$hst) 2 2] == "T"} {
    284         set difc [expr {[histinfo $hst difc]/1000.}]
    285         set difa [expr {[histinfo $hst difa]/1000.}]
    286         set zero [expr {[histinfo $hst zero]/1000.}]
    287         set ans {}
    288         foreach d $dlist {
    289             if {$d == 0.} {
    290                 lappend ans 0.
    291             } elseif {$d == 1000.} {
    292                 lappend ans 1000.
    293             } else {
    294                 lappend ans [expr {$difc*$d + $difa*$d*$d + $zero}]
    295             }
    296         }
    297         return $ans
    298     } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
    299         set lamo2 [expr {0.5 * [histinfo $hst lam1]}]
    300         set zero [expr [histinfo $hst zero]/100.]
    301         set ans {}
    302         set cnv [expr {180./acos(0.)}]
    303         foreach d $dlist {
    304             if {$d == 99999.} {
    305                 lappend ans 0
    306             } elseif {$d == 0.} {
    307                 lappend ans 1000.
    308             } else {
    309                 lappend ans [expr {$cnv*asin($lamo2/$d) + $zero}]
    310             }
    311         }
    312         return $ans
    313     } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
    314         set lam [histinfo $hst lam1]
    315         set zero [histinfo $hst zero]
    316         set v [expr {12.398/(2.0*[sind[expr ($lam/2.0)]])}]
    317         set ans {}
    318         foreach d $dlist {
    319             if {$d == 1000.} {
    320                 lappend ans 0
    321             } elseif {$d == 0.} {
    322                 lappend ans 1000.
    323             } else {
    324                 lappend ans [expr {$v/$d}]
    325             }
    326         }
    327         return $ans
    328     } else {
    329         return {}
    330     }
    331 }
    332 
    333 # convert Q values to 2theta, TOF or KeV
    334 proc fromQ {Qlist hst} {
    335     global expmap
    336     if {[string range $expmap(htype_$hst) 2 2] == "T"} {
    337         set difc [expr {[histinfo $hst difc]/1000.}]
    338         set difa [expr {[histinfo $hst difa]/1000.}]
    339         set zero [expr {[histinfo $hst zero]/1000.}]
    340         set ans {}
    341         foreach Q $Qlist {
    342             if {$Q == 0.} {
    343                 lappend ans 1000.
    344             } elseif {$Q == 99999.} {
    345                 lappend ans 1000.
    346             } else {
    347                 set d [expr {4.*acos(0.)/$Q}]
    348                 lappend ans [expr {$difc*$d + $difa*$d*$d + $zero}]
    349             }
    350         }
    351         return $ans
    352     } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
    353         set lamo4pi [expr {[histinfo $hst lam1]/(8.*acos(0.))}]
    354         set zero [expr [histinfo $hst zero]/100.]
    355         set ans {}
    356         set cnv [expr {180./acos(0.)}]
    357         foreach Q $Qlist {
    358             if {$Q == 0.} {
    359                 lappend ans 0
    360             } elseif {$Q == 1000.} {
    361                 lappend ans 1000.
    362             } else {
    363                 lappend ans [expr {$cnv*asin($Q*$lamo4pi) + $zero}]
    364             }
    365         }
    366         return $ans
    367     } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
    368         set lam [histinfo $hst lam1]
    369         set zero [histinfo $hst zero]
    370         set v [expr {12.398/(2.0*[sind[expr ($lam/2.0)]])}]
    371         set ans {}
    372         set 2pi [expr {4.*acos(0.)}]
    373         foreach Q $Qlist {
    374             if {$Q == 1000.} {
    375                 lappend ans 0
    376             } elseif {$Q == 0.} {
    377                 lappend ans 1000.
    378             } else {
    379                 lappend ans [expr {$Q * $v/$2pi}]
    380             }
    381         }
    382         return $ans
    383     } else {
    384         return {}
    385     }
    386 }
    387 
    388 proc plotdata {args} {
     131    plotExclData
     132}
     133
     134# plot the pattern with the requested x-axis units & the excluded regions
     135proc plotExclData {args} {
    389136    global peakinfo  reflns
    390137    global graph expgui
     
    456203}
    457204
     205# show or hide the plot legend
    458206proc setlegend {box legend} {
    459207    global blt_version
     
    473221}
    474222
     223# show tickmark options
    475224proc minioptionsbox {num} {
    476225    global blt_version tcl_platform peakinfo expgui
     
    653402}
    654403
     404# display the excluded regions with orange markers
    655405proc ShowExlMarks {} {
    656406    global graph
     
    734484}
    735485
     486# called using the mouse to delete an excluded region
    736487proc exclDel {bindtag x y} {
    737488    global graph expgui
     
    792543}
    793544
     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
    794549proc exclAdd {bindtag x y} {
    795550    global graph
     
    802557}
    803558
     559# reset the "add region mode" (see exclAdd)
    804560proc exclReset {bindtag} {
    805561    global graph
     
    810566}
    811567
     568# highlight the potential excluded region (see exclAdd)
    812569proc exclMove {bindtag x y} {
    813570    global graph
     
    821578}
    822579
     580# Called by a mouse click to complete a new excluded region (see exclAdd)
    823581proc exclDone {bindtag x y} {
    824582    global graph
     
    874632        set ans ok
    875633    }
    876     if {$ans == "ok"} {
    877         global expgui
    878         incr expgui(changed)
    879         set hst $graph(hst)
    880         set exclist [histinfo $hst excl]
    881         lappend exclist [list $p1 $p2]
    882         set oldtmax [lindex [lindex $exclist end] 0]
    883         CheckForOverlappingRegions $exclist
    884         if {$oldtmax < [set tmax [lindex [lindex $exclist end] 0]]} {
    885             histinfo $hst dmin set [tod $tmax $hst]
    886             HighLimitChanged
    887         } elseif {$oldtmax != [set tmax [lindex [lindex $exclist end] 0]]} {
    888             histinfo $hst dmin set [tod $tmax $hst]
    889         } else {
    890             exxvec append [xvec range [lindex $l 0] [lindex $l end]]
    891             exobsvec append [obsvec range [lindex $l 0] [lindex $l end]]
    892             exxvec notify now
    893             exobsvec notify now
    894         }
    895         ShowExlMarks
    896         FillExclRegionBox
    897     }
    898 }
    899 
     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
    900658proc CheckForOverlappingRegions {exclist} {
    901659    global expgui graph
     
    933691}
    934692
     693# called in response to the File/"Set Min/Max Range" menu button
    935694proc setminormax {} {
    936695    global expmap graph expgui
    937     if {[string trim [string range $expmap(htype_$graph(hst)) 3 3]] == "D"} {
    938         if {[string range $expmap(htype_$graph(hst)) 2 2] == "T"} {
     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"} {
    939699            set fac 1000.
    940         } elseif {[string range $expmap(htype_$graph(hst)) 2 2] == "E"} {
     700        } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
    941701            set fac 1.
    942702        } else {
    943703            set fac 100.
    944         }           
    945         set start [expr {[histinfo $graph(hst) dstart]/$fac}]
    946         set step  [expr {[histinfo $graph(hst) dstep]/$fac}]
    947         set points [histinfo $graph(hst) dpoints]
     704        }
     705        set start [expr {[histinfo $hst dstart]/$fac}]
     706        set step  [expr {[histinfo $hst dstep]/$fac}]
     707        set points [histinfo $hst dpoints]
    948708        set end [expr {$start + $points*$step}]
    949         SetDummyRangeBox $graph(hst) $start $end $step
     709        SetDummyRangeBox $hst $start $end $step
    950710        return
    951711    }
     
    994754            ] -col 2 -row 0
    995755    set exclist [histinfo $hst excl]
     756    set oldtmin [lindex [lindex $exclist 0] 1]
    996757    set oldtmax [lindex [lindex $exclist end] 0]
    997758    if {$graph(xunits) == 1} {
     
    1015776    set startchanges $expgui(changed)
    1016777    catch {
     778        # did anything change?
    1017779        if {$graph(tmin) != $start(tmin)} {
    1018780            incr expgui(changed)
    1019781            if {$graph(xunits) == 1} {
    1020782                set tmax [fromd $graph(tmin) $hst]
    1021                 incr highchange
    1022                 set item [list $tmax [lindex [lindex $exclist end] 1]]
    1023                 set exclist [lreplace $exclist end end $item]
    1024                 histinfo $hst dmin set [tod $tmax $hst]
     783                set exclist [lreplace $exclist end end \
     784                        [list $tmax [lindex [lindex $exclist end] 1]]]
    1025785            } elseif {$graph(xunits) == 2} {
    1026786                set tmin [fromQ $graph(tmin) $hst]
    1027                 set item [list [lindex [lindex $exclist 0] 0] $tmin]
    1028                 set exclist [lreplace $exclist 0 0 $item]
     787                set exclist [lreplace $exclist 0 0 \
     788                        [list [lindex [lindex $exclist 0] 0] $tmin]]
    1029789            } else {
    1030                 set item [list [lindex [lindex $exclist 0] 0] $graph(tmin)]
    1031                 set exclist [lreplace $exclist 0 0 $item]
     790                set exclist [lreplace $exclist 0 0 \
     791                        [list [lindex [lindex $exclist 0] 0] $graph(tmin)]]
    1032792            }
    1033793        }
     
    1038798            if {$graph(xunits) == 1} {
    1039799                set tmin [fromd $graph(tmax) $hst]
    1040                 set item [list [lindex [lindex $exclist 0] 0] $tmin]
    1041                 set exclist [lreplace $exclist 0 0 $item]
     800                set exclist [lreplace $exclist 0 0 \
     801                        [list [lindex [lindex $exclist 0] 0] $tmin]]
    1042802            } elseif {$graph(xunits) == 2} {
    1043803                set tmax [fromQ $graph(tmax) $hst]
    1044                 incr highchange
    1045                 set item [list $tmax [lindex [lindex $exclist end] 1]]
    1046                 set exclist [lreplace $exclist end end $item]
    1047                 histinfo $hst dmin set [tod  $tmax $hst]
     804                set exclist [lreplace $exclist end end \
     805                        [list $tmax [lindex [lindex $exclist end] 1]]]
    1048806            } else {
    1049                 incr highchange
    1050                 set item [list $graph(tmax) [lindex [lindex $exclist end] 1]]
    1051                 set exclist [lreplace $exclist end end $item]
    1052                 histinfo $hst dmin set [tod  $graph(tmax) $hst]
     807                set exclist [lreplace $exclist end end \
     808                        [list $graph(tmax) [lindex [lindex $exclist end] 1]]]
    1053809            }
    1054810        }
    1055811    }
    1056812    if {$startchanges != $expgui(changed)} {
    1057         histinfo $hst excl set $exclist
    1058813        CheckForOverlappingRegions $exclist
     814        CheckQmaxChanged $oldtmin $oldtmax
     815        updateplot
    1059816    } else {
    1060817        return
    1061818    }
    1062     if {$highchange && \
    1063             $oldtmax < [set tmax [lindex [lindex $exclist end] 0]]} {
    1064         histinfo $hst dmin set [tod $tmax $hst]
    1065         HighLimitChanged
    1066     } elseif {$oldtmax != [set tmax [lindex [lindex $exclist end] 0]]} {
    1067         histinfo $hst dmin set [tod $tmax $hst]
    1068         updateplot
    1069     } else {
    1070         updateplot
    1071     }
    1072 }
    1073 
    1074 proc HighLimitChanged {} {
    1075     global graph expgui
    1076     set msg "The upper data limit has changed.\nYou must run POWPREF to "
     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 "
    1077851    append msg "to see the full range of data displayed. Do you want to "
    1078852    append msg "run POWPREF (& possibly GENLES with zero cycles)?"
     
    1095869    set expgui(autoexpload) $auto
    1096870    updateplot
    1097     CheckTmax
    1098 }
    1099 
    1100 # find out what the maximum point really is
     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.
    1101877proc CheckTmax {} {
    1102878    global graph expgui
     
    1125901            append msg "You are suggested to set the lower d limit to $d A\n"
    1126902        } elseif {$graph(xunits) == 2} {
    1127             set msg "The upper data limit ([toQ [lindex [lindex $exclist end] 0] $hst] A-1) "
     903            set msg "The high Q data limit ([toQ [lindex [lindex $exclist end] 0] $hst] A-1) "
    1128904            set q [toQ $max $hst]
    1129905            append msg "is much larger than the largest data point ($q A-1)\n"
    1130906            append msg "You are suggested to set the upper Q limit to $q A-1\n"
    1131907        } else {
    1132             set msg "The upper data limit ([lindex [lindex $exclist end] 0]) "
     908            set msg "The high Q (low d) data limit ([lindex [lindex $exclist end] 0]) "
    1133909            append msg "is much larger than the largest data point ($max)\n"
    1134             append msg "You are suggested to set the upper limit to $max\n"
     910            append msg "You are suggested to set the limit to $max\n"
    1135911        }
    1136912        append msg "OK to make this change?"
     
    1143919            set exclist [lreplace $exclist end end $item]
    1144920            histinfo $hst excl set $exclist
     921            histinfo $hst dmin set [tod $max $hst]
    1145922            updateplot
    1146923            return
     
    1149926}
    1150927
    1151 proc CheckChanges {} {
     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} {
    1152932    global expgui graph
    1153933    set hst $graph(hst)
    1154     if {$expgui(changed) == 0} return
    1155     set msg "The excluded regions/ranges have changed.\nYou must run POWPREF before "
    1156     append msg "running GENLES. Do you want to run POWPREF and optionally "
    1157     append msg "GENLES with zero cycles now?"
    1158     set ans [MyMessageBox -parent . -message $msg -title "Process limits?"\
    1159             -helplink "expguierr.html ProcessRegions" \
    1160             -type {Skip {Run POWPREF} {Run POWPREF & GENLES}}]
    1161     global expgui env
    1162     if {$ans == "run powpref"} {
    1163         set cmd powpref
    1164     } elseif {$ans == "skip"} {
    1165         return
    1166     } else {
    1167         set cmd "powpref genles"
    1168         expinfo cycles set 0
    1169     }
    1170     set auto $expgui(autoexpload)
    1171     set expgui(autoexpload) 1
    1172     #set expgui(autoiconify) 0
    1173     runGSASwEXP $cmd
    1174     set expgui(autoexpload) $auto
    1175 }
    1176 
     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
    1177944proc EditExclRegion {reg "msg {}"} {
    1178945    global graph expmap expgui
     
    1180947    set startchanges $expgui(changed)
    1181948    set exclist [histinfo $hst excl]
     949    set oldtmin [lindex [lindex $exclist 0] 1]
    1182950    set oldtmax [lindex [lindex $exclist end] 0]
    1183951    set i [expr {$reg -1}]
     
    12441012                -col 2 -row 3
    12451013    }
     1014    # save starting values as tmin & tmax
    12461015    foreach v {tmin tmax} {
    12471016        set $v $graph($v)
     
    12681037            }
    12691038        }]} {
     1039            # recursive call -- should not happen too many times
    12701040            EditExclRegion $reg "Invalid value entered, try again"
    12711041            return
     
    12851055            }
    12861056        }]} {
     1057            # recursive call -- should not happen too many times
    12871058            EditExclRegion $reg "Invalid value entered, try again"
    12881059            return
     
    12911062        incr expgui(changed)
    12921063    }
    1293     if {$expgui(changed) != $startchanges} {
    1294         histinfo $hst excl set $exclist
    1295         CheckForOverlappingRegions $exclist
    1296         if {$reg == [llength $exclist]} {
    1297             histinfo $hst dmin set [tod $tmin $hst]
    1298         }
    1299         if {$oldtmax < [set tmax [lindex [lindex $exclist end] 0]]} {
    1300             histinfo $hst dmin set [tod $tmin $hst]
    1301             HighLimitChanged
    1302         } elseif {$oldtmax != [set tmax [lindex [lindex $exclist end] 0]]} {
    1303             histinfo $hst dmin set [tod $tmin $hst]
    1304             updateplot
    1305         } else {
    1306             updateplot
    1307         }
    1308         FillExclRegionBox
    1309     }
    1310 }
    1311 
     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.
    13121074proc scheduleFillExclRegionBox {} {
    13131075    global graph
     
    13171079    after idle FillExclRegionBox
    13181080}
    1319 # put the background regions into buttons
     1081
     1082# put the background regions into buttons and resize the slider
    13201083proc FillExclRegionBox {} {
    13211084    global graph expmap
     
    15051268proc ShowExcl {} {
    15061269    global graph peakinfo expgui expmap
    1507     # save the starting number of cycles
     1270    # save the starting number of cycles & starting point
    15081271    set cycsav [expinfo cycles]
     1272    set startchanges $expgui(changed)
    15091273    set graph(hst) [lindex $expgui(curhist) 0]
    15101274    if {[llength $expgui(curhist)] == 0} {
     
    15761340            -label "Set Min/Max Range" -command setminormax
    15771341    $graph(exclmenu).file.menu add command \
    1578             -label "Update Plot" -command "CheckChanges;updateplot"
     1342            -label "Update Plot" -command "CheckChanges $startchanges;updateplot"
    15791343    $graph(exclmenu).file.menu add command \
    15801344            -label "Make PostScript" -command makepostscriptout
    15811345    $graph(exclmenu).file.menu add command \
    1582             -label Finish -command "CheckChanges;destroy $graph(exclbox)"
     1346            -label Finish -command "CheckChanges $startchanges;destroy $graph(exclbox)"
    15831347
    15841348    pack [menubutton $graph(exclmenu).options -text Options -underline 0 \
     
    15911355    $graph(exclmenu).options.menu.tick add radiobutton \
    15921356            -label "Manual Placement" \
    1593             -value 0 -variable expgui(autotick) -command plotdata
     1357            -value 0 -variable expgui(autotick) -command plotExclData
    15941358    $graph(exclmenu).options.menu.tick add radiobutton \
    15951359            -label "Auto locate" \
    1596             -value 1 -variable expgui(autotick) -command plotdata
     1360            -value 1 -variable expgui(autotick) -command plotExclData
    15971361    $graph(exclmenu).options.menu.tick add separator
    15981362    foreach num {1 2 3 4 5 6 7 8 9} {
     
    16131377    foreach var {excl calc obs} lbl {Excluded Calculated Observed} {
    16141378        $graph(exclmenu).options.menu.color add command -label $lbl \
    1615                 -command "set graph(color_$var) \[tk_chooseColor -initialcolor \$graph(color_$var) -title \"Choose \$lbl color\"]; plotdata"
     1379                -command "set graph(color_$var) \[tk_chooseColor -initialcolor \$graph(color_$var) -title \"Choose \$lbl color\"]; plotExclData"
    16161380    }
    16171381    $graph(exclmenu).options.menu add cascade -label "X units" \
     
    16651429            -column 1 -row 4 -columnspan 5 -sticky nsew
    16661430    grid [button $bb.cw -text "Save &\nFinish" \
    1667             -command "CheckChanges;destroy $graph(exclbox)"] \
     1431            -command "CheckChanges $startchanges;destroy $graph(exclbox)"] \
    16681432        -col 4 -row 1 -columnspan 2 -sticky ns
    16691433
     
    17421506    bind $graph(exclbox) <Key-Z> {BLTmanualZoom}
    17431507    updateplot
    1744     trace variable peakinfo w plotdata
     1508    trace variable peakinfo w plotExclData
    17451509
    17461510    # catch exits -- launch POWPREF; if changes non-zero
    1747     wm protocol $graph(exclbox) WM_DELETE_WINDOW {CheckChanges;destroy $graph(exclbox)}
     1511    wm protocol $graph(exclbox) WM_DELETE_WINDOW "CheckChanges $startchanges;destroy $graph(exclbox)"
    17481512    # respond to resize events
    17491513    bind $graph(exclbox) <Configure> scheduleFillExclRegionBox
    1750     bind all <Control-KeyPress-c> {CheckChanges;destroy $graph(exclbox)}
     1514    bind all <Control-KeyPress-c> "CheckChanges $startchanges;destroy $graph(exclbox)"
    17511515    putontop $graph(exclbox)
    17521516    wm deiconify $graph(exclbox)
     
    19881752    updateplot
    19891753}
     1754
     1755# set the minimum tof/d-space using the EXPEDT program
     1756proc SetTminTOF {tmin parent} {
     1757    global expgui reflns graph tcl_platform
     1758    set hst $graph(hst)
     1759    set input [open excl$hst.inp w]
     1760    puts $input "Y"
     1761    puts $input "p h e $hst"
     1762    puts $input "T"
     1763    puts $input "$tmin"
     1764    puts $input "/"
     1765    puts $input "x x x"
     1766    puts $input "x"
     1767    close $input
     1768    # Save the current exp file
     1769    savearchiveexp
     1770    # disable the file changed monitor
     1771    set expgui(expModifiedLast) 0
     1772    set expnam [file root [file tail $expgui(expfile)]]
     1773    set err [catch {
     1774        if {$tcl_platform(platform) == "windows"} {
     1775            exec [file join $expgui(gsasexe) expedt.exe] $expnam < excl$hst.inp >& excl$hst.out
     1776        } else {
     1777            exec [file join $expgui(gsasexe) expedt] $expnam < excl$hst.inp >& excl$hst.out
     1778        }
     1779    } errmsg]
     1780    loadexp $expgui(expfile)
     1781    catch {file delete excl$hst.inp}
     1782    if {$expgui(showexptool) || $err} {
     1783        set fp [open excl$hst.out r]
     1784        set out [read $fp]
     1785        close $fp
     1786        if {$errmsg != ""} {
     1787            append errmsg "\n" $out
     1788        } else {
     1789            set errmsg $out
     1790        }
     1791        set msg "Please review the result from changing the TOF minimum."
     1792        if {$err} {append msg "\nIt appears an error occurred!"}
     1793        ShowBigMessage $parent.msg $msg $errmsg OK "" $err
     1794    }
     1795}
Note: See TracChangeset for help on using the changeset viewer.