source: trunk/expgui @ 327

Last change on this file since 327 was 327, checked in by toby, 11 years ago

# on 2000/10/18 00:00:05, toby did:
move platform-specific runtime code from gsascmds.tcl to here so
that it gets run after the local config files are read
Switch tk_dialog to MyMessageBox? and add WWW references for soem error mgs
disable add histogram until after a phase has been added
add update idletasks to profile, so that something happens right away

  • Property rcs:author set to toby
  • Property rcs:date set to 2000/10/18 00:00:05
  • Property rcs:lines set to +39 -5
  • Property rcs:rev set to 1.38
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 120.5 KB
Line 
1#!/usr/local/bin/wish
2# $Id: expgui 327 2009-12-04 23:04:12Z toby $
3set expgui(Revision) {$Revision: 327 $ $Date: 2009-12-04 23:04:12 +0000 (Fri, 04 Dec 2009) $}
4
5# to do:
6#
7# need to change heading and button label depending on where getExpFileName
8# is called from?
9#
10# global background editing & profile work differently: should both
11# start out blank with a "load from option"?
12#
13# idea:
14# a scroll list for all histogram refinement flags ; click on takes you to the
15# appropriate menu.
16#
17# idea:
18#   change cell parameters to labels and have a edit cell button
19#   that enforces metric symmetry
20#
21# to allow "global" access on phase page
22#   change buttons from radio to multiple
23#   -- or display all 9 cell flag/damps and all atoms
24#   make editMultipleRecords work with multiple phases, also cell flag/damp
25#   blank cell entries
26#   add phase to atom number in listing
27#   DisplayAllAtoms needs to loop over phases: expgui(curPhase)
28#
29# idea: load more than one bank from a multi-bank .RAW file
30#
31if {$tcl_version < 8.0} {
32    tk_dialog .expFileErrorMsg "Version Error" \
33            "EXPGUI requires Tcl/Tk version 8.0 or higher" error 0 "Exit"
34    exit
35}
36
37# the shell variable tells expgui to act as a shell for GSAS
38# as well as edit the EXP file. In no-shell mode, it can
39# only be used to edit the .EXP file as a callable program
40set expgui(shell) 1
41catch {if $env(EXPGUI_NOSHELL) {set expgui(shell) 0}}
42
43if {$argv != ""} {
44    if {[string match *noshell* [string tolower $argv]]} {
45        puts noshell
46        set expgui(shell) 0
47        set expgui(expfile) [lindex $argv 1]
48    } else {
49        set expgui(expfile) [lindex $argv 0]
50    }
51    if {[string toupper [file extension $expgui(expfile)]] != ".EXP"} {
52        append expgui(expfile) ".EXP"
53    }
54} else {
55    set expgui(expfile) {}
56}
57
58set expgui(curhist) {}
59set expmap(powderlist) {}
60set expgui(bkgcolor1) #fdf
61
62set expgui(debug) 0
63catch {if $env(DEBUG) {set expgui(debug) 1}}
64#set expgui(debug) 1
65
66# default for archive mode = on
67set expgui(archive) 1
68# default for autoexec load = off
69set expgui(autoexpload) 0
70# default for show EXPTOOL output = off
71set expgui(showexptool) 0
72# save the name of the wish executable
73set wishshell [info nameofexecutable]
74# misc constants
75set txtvw(font) "Courier"
76set expgui(coordfont) "-*-courier-bold-r-normal--12-*"
77set expgui(histfont) "-*-courier-bold-r-normal--12-*"
78set liveplot(hst) 1
79set liveplot(legend) 1
80set expgui(filesort) 1
81set expgui(initstring) {}
82# use a separate window for DISAGL (default)
83set expgui(disaglSeparateBox) 1
84set expgui(DefaultPeakType) 0
85# default: keep current atoms when replacing a phase
86set expgui(DeleteAllAtoms) 0
87#=============================================================================
88#----------------------------------------------------------------
89# where are we?
90set expgui(script) [info script]
91# translate links -- go six levels deep
92foreach i {1 2 3 4 5 6} {
93    if {[file type $expgui(script)] == "link"} {
94        set link [file readlink $expgui(script)]
95        if { [file  pathtype  $link] == "absolute" } {
96            set expgui(script) $link
97        } {
98            set expgui(script) [file dirname $expgui(script)]/$link
99        }
100    } else {
101        break
102    }
103}
104# fixup relative paths
105if {[file pathtype $expgui(script)] == "relative"} {
106    set expgui(script) [file join [pwd] $expgui(script)]
107}
108set expgui(scriptdir) [file dirname $expgui(script) ]
109set expgui(gsasdir) [file dirname $expgui(scriptdir)]
110set expgui(gsasexe) [file join $expgui(gsasdir) exe]
111set expgui(docdir) [file join $expgui(scriptdir) doc]
112#----------------------------------------------------------------
113lappend auto_path $expgui(scriptdir)
114set expgui(havetix) 0
115set expgui(haveBW) 1
116# for debugging non-BWidget version set environment variable NOBWIDGET
117catch {if $env(NOBWIDGET) {set expgui(haveBW) 0}}
118if $expgui(haveBW) {
119    if [catch {package require BWidget}] {set expgui(haveBW) 0}
120}
121# get the notebook widget if not using BWidgets
122if {!$expgui(haveBW)} {source [file join $expgui(scriptdir) notebook.tcl]}
123#----------------------------------------------------------------
124if [file exists [file join $expgui(scriptdir) opts.tcl]] {
125    source [file join $expgui(scriptdir) opts.tcl]
126}
127# fetch EXP file processing routines
128source [file join $expgui(scriptdir) readexp.tcl]
129# commands for running GSAS programs
130source [file join $expgui(scriptdir) gsascmds.tcl]
131# contents of GSAS menus
132source [file join $expgui(scriptdir) gsasmenu.tcl]
133# commands for adding phases, histograms & atoms
134source [file join $expgui(scriptdir) addcmds.tcl]
135# commands for preferred orientation
136source [file join $expgui(scriptdir) orient.tcl]
137#---------------------------------------------------------------------------
138# override options with locally defined values
139if [file exists [file join $expgui(scriptdir) localconfig]] {
140    source [file join $expgui(scriptdir) localconfig]
141}
142if [file exists [file join ~ .gsas_config]] {
143    source [file join ~ .gsas_config]
144}
145#---------------------------------------------------------------------------
146# platform-specific code
147if {$tcl_platform(platform) == "windows"} {
148    set expgui(exptool) [file join $expgui(gsasexe) exptool.exe]
149    if [catch {package require winexec}] {
150        MyMessageBox -parent . -title "WINEXEC Error" \
151                -message "Error -- Unable to load the WINEXEC package. This is needed in Win95 machines" \
152                -icon error -type Quit -default quit \
153                -helplink "expgui_Win_readme.html Winexec"
154        destroy .
155    }
156    if ![file exists [file join $expgui(gsasdir) fonts grfont.dat]] {
157        MyMessageBox -parent . -title "PGPLOT Error" \
158                -message "Warning -- Unable to find file GRFONT.DAT. GSAS graphics will not work. Is GSAS correctly installed?" \
159                -icon warning -type {"Limp Ahead"} -default "Limp Ahead" \
160                -helplink "expguierr.html NoPGPLOT"
161    }
162} else {
163    set expgui(exptool) [file join $expgui(gsasexe) exptool]
164    if ![file exists [file join $expgui(gsasdir) pgl grfont.dat]] {
165        MyMessageBox -parent . -title "PGPLOT Error" \
166                -message "Warning -- Unable to find file grfont.dat. GSAS graphics will not work. Is GSAS correctly installed?" \
167                -icon warning -type {"Limp Ahead"} -default "Limp Ahead" \
168                -helplink "expguierr.html NoPGPLOT"
169    }
170    if [catch {set env(GSASBACKSPACE)}] {set env(GSASBACKSPACE) 1}
171}
172#---------------------------------------------------------------------------
173if {$expgui(expfile) != ""} {
174    if ![file exists $expgui(expfile)] {
175        update
176        set ans [
177        MyMessageBox -parent . -title "File Open Error" \
178                -message "File [file tail $expgui(expfile)] does not exist in [file dirname $expgui(expfile)]. OK to create?" \
179                -icon question -type {"Select other" "Create"} -default "select other" \
180                -helplink "expguierr.html OpenErr"
181        ]
182        if {[string tolower $ans] != "create"} {set expgui(expfile) {}}
183    }
184}
185if {$expgui(expfile) == ""} {
186    # center the parent window because the getExpFileName window
187    # will be centered above it.
188    wm withdraw .
189    set x [expr [winfo screenwidth .]/2 - [winfo reqwidth .]/2 ]
190    set y [expr [winfo screenheight .]/2 - [winfo reqheight .]/2]
191    wm geom . +$x+$y
192    wm deiconify .
193    # windows needed this update before when using tk_getOpenFile.
194    # I am not sure it is still needed.
195    update
196    #
197    set expgui(expfile) [getExpFileName old]
198}
199if {$expgui(expfile) == ""} exit
200# you've been warned this .EXP does not exist!
201if ![file exists $expgui(expfile)] {
202    # create an "empty" exp file
203    createexp $expgui(expfile) \
204            [getstring "title for experiment $expgui(expfile)" 60 0]
205}
206catch {cd [string trim [file dirname $expgui(expfile)]]}
207
208#
209# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
210# <<<<<<<<<<    BEGINNING OF MAIN: GLOBAL AREA FOR DATA EXTRACTION >>>>>>>>>>>
211# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
212# load exp file and set up dialogs
213proc loadexp {expfile} {
214    global expgui expmap entryvar entrycmd tcl_platform
215    set exploadtime [time {set fmt [expload $expfile]}]
216    if $expgui(debug) {puts "expload $exploadtime"}
217    # if the file was not in the correct format, force a rewrite before use
218    if {$fmt < 0} {
219        # read error
220        return
221    } elseif {$fmt == 0 && $tcl_platform(platform) == "windows"} {
222        set expgui(changed) 1
223    } elseif {$fmt == 1 && $tcl_platform(platform) == "unix"} {
224        set expgui(changed) 1
225    } else {
226        set expgui(changed) 0
227    }
228
229    # force exp files to be upper case, force save if name changes
230    set filetail [file tail $expfile]
231    set filetailcaps [string toupper $filetail]
232    if {$tcl_platform(platform) == "unix" && $filetail != $filetailcaps} {
233        set expgui(changed) 1
234    }
235    if {[file dirname $expfile] == "."} {
236        set expgui(expfile) $filetailcaps
237    } else {
238        set expgui(expfile) [file join \
239                [file dirname $expfile] $filetailcaps]
240    }
241
242    mapexp
243    set expgui(expModifiedLast) 0
244    catch {
245        set expgui(expModifiedLast) [file mtime $expgui(expfile)]
246    }
247    set expgui(last_History) [string range [string trim [lindex [exphistory last] 1]] 0 50 ]
248    # set the window/icon title
249    wm title . "EXPGUI $expfile"
250    set expgui(titleunchanged) 1
251    wm iconname . [file tail $expfile]
252
253    # set the number of phases on the phase page
254    setphases
255
256    # disable the "global options" that don't make sense based on
257    # which histograms present
258    foreach num {1 2 3 4 5} {
259        set flag($num) 0
260    }
261    # save a list of the allowed modes, too
262    set expgui(AllowedHistSelectModes) {0 6}
263    foreach h $expmap(powderlist) {
264        if {[string range $expmap(htype_$h) 2 2] == "T"} {set flag(1) 1}
265        if {[string range $expmap(htype_$h) 1 2] == "NC"} {set flag(2) 1}
266        if {[string range $expmap(htype_$h) 1 2] == "XC" && \
267                [histinfo $h lam2] != 0.0} {set flag(3) 1}
268        if {[string range $expmap(htype_$h) 1 2] == "XC" && \
269                [histinfo $h lam2] == 0.0} {set flag(4) 1}
270        if {[string range $expmap(htype_$h) 1 2] == "XE"} {set flag(5) 1}
271    }
272    foreach num {1 2 3 4 5} \
273            lbl {TOF "CW Neutron" "Alpha12 Xray" "Monochromatic Xray" \
274            "Energy Disp Xray"} {
275        if $flag($num) {
276            $expgui(fm).option.menu.editmode entryconfigure $lbl -state normal
277            lappend expgui(AllowedHistSelectModes) $num
278        } else {
279            $expgui(fm).option.menu.editmode entryconfigure $lbl -state disabled
280        }
281    }
282    # disable traces on entryvar until we are ready
283    set entrycmd(trace) 0
284    trace vdelete entryvar w entvartrace
285
286    # propogate changes on the least squares page
287    set entryvar(cycles) [expinfo cycles]
288    set entrycmd(cycles) "expinfo cycles"
289    # set expgui(globalmode) 0
290    set expgui(printopt) "Print Options ([expinfo print])"
291    set entryvar(title) [expinfo title]
292    global printopts
293    foreach num [array names printopts] {
294        set entrycmd(printopt$num) "printsetting $num"
295        set entryvar(printopt$num) [printsetting $num]
296    }
297    # enable traces on entryvar
298    set entrycmd(trace) 1
299    trace variable entryvar w entvartrace
300
301    # set fo extraction on LS page
302    SetupExtractHist
303
304    # update the histogram list & update the page
305    sethistlist
306
307    # start checking for external changes
308    afterawhile
309}
310
311# called to reread the .EXP file
312proc rereadexp {expfile} {
313    global expgui
314    if $expgui(changed) {
315        set decision [tk_dialog .instrSaveData {Save .EXP changes} \
316                {You have made changes to the Experiment. Rereading will cause the changes to be lost. Select an option:} \
317                {} 0 "Save and reread" "Reread without Save" "Cancel reread command"]
318        switch $decision {
319            0 { savearchiveexp }
320            1 { }
321            2 { return }
322        }
323    }
324    loadexp $expgui(expfile)
325}
326
327proc SaveAsFile {} {
328    global expgui
329    set newexpfile [getExpFileName new]
330    if {$newexpfile == ""} return
331    expwrite $newexpfile
332    set expgui(expfile) $newexpfile
333    catch {cd [string trim [file dirname $expgui(expfile)]]}
334    set expgui(changed) 0
335    set expgui(expModifiedLast) [file mtime $expgui(expfile)]
336    set expgui(last_History) [string range [string trim [lindex [exphistory last] 1]] 0 50 ]
337    # set the window/icon title
338    wm title . $expgui(expfile)
339    set expgui(titleunchanged) 1
340    wm iconname . [file tail $expgui(expfile)]
341}
342
343# called to read a different .EXP file
344proc readnewexp {} {
345    global expgui expmap
346    if $expgui(changed) {
347        set decision [tk_dialog .instrSaveData {Save .EXP changes} \
348                {You have made changes to the Experiment. Reading a different file will cause the changes to be lost. Select an option:} \
349                {} 0 "Save and read" "Read without Save" "Cancel read command"]
350        switch $decision {
351            0 { savearchiveexp }
352            1 {                }
353            2 { return }
354        }
355    }
356    set newexpfile [getExpFileName old]
357    if {$newexpfile == ""} return
358
359    # switch to the 1st page
360    RaisePage lsFrame
361
362    if ![file exists $newexpfile] {
363        # you've been warned this .EXP does not exist!
364        # create an "empty" exp file
365        createexp $newexpfile \
366                [getstring "title for experiment $newexpfile" 60 0]
367    }
368    set expgui(expfile) $newexpfile
369    catch {cd [string trim [file dirname $expgui(expfile)]]}
370    set expgui(globalmode) 0
371    loadexp $expgui(expfile)
372
373    # select the 1st phase
374    SelectOnePhase [lindex $expmap(phaselist) 0]
375    # select the first histogram in the list by default (if there are any)
376    if {[llength $expmap(histlistboxcontents)] > 0} {
377        set expgui(curhist) 0
378    } else {
379        set expgui(curhist) {}
380    }
381    if {[CountHistory] > 100} {
382        DeleteHistoryRecords "This .EXP file has [CountHistory] history records\nErasing most will speed EXPGUI"
383    }
384}
385
386#------------- set up data read/write layer ----------------------
387# trace routine on entryvar
388proc entvartrace {array elem action} {
389    global expgui entrycmd entryvar entrybox
390    if !$entrycmd(trace) return
391   
392    catch {
393        if {$entrycmd($elem) == ""} return
394        incr expgui(changed)
395        if $expgui(debug) {puts "$entrycmd($elem)  set $entryvar($elem) "}
396        if {$entrycmd($elem) == ""} return
397        if [catch {
398            set result [eval $entrycmd($elem) set [list $entryvar($elem)]]
399            if {!$result} {
400                if $expgui(debug) {puts "error with $entrycmd($elem)"}
401                catch {$entrybox($elem) config -fg red}
402            } else {
403                catch {$entrybox($elem) config -fg black}
404            }
405            if {[lindex $entrycmd($elem) 0] == "atominfo"} {
406                after idle {DisplayAllAtoms noreset}
407            }
408        } errmsg] {error $errmsg}       
409    }
410}
411
412# disable traces on entryvar until we are ready
413set entrycmd(trace) 0
414trace variable entryvar w entvartrace
415
416#
417#
418#
419##############################################################################
420#####                    #####################################################
421##### PROCEDURES SECTION #####################################################
422#####                    #####################################################
423##############################################################################
424
425# save some of the global options in ~/.gsas_config
426proc SaveOptions {} {
427    global expgui env tcl_platform
428    set fp [open [file join ~ .gsas_config] a]
429    foreach item {archive asorttype hsorttype filesort disaglSeparateBox} {
430        puts $fp "set expgui($item) $expgui($item)"
431    }
432    if {$tcl_platform(platform) != "windows"} {
433        puts $fp "set env(GSASBACKSPACE) $env(GSASBACKSPACE)"
434        puts $fp "set expgui(autoexpload) $expgui(autoexpload)"
435    }
436    puts $fp "set expgui(showexptool) $expgui(showexptool)"
437    close $fp
438}
439
440proc About { } {
441    global expgui expmap
442    tk_dialog .about {About...} \
443"EXPGUI\n\
444Jonathan Wasserman and Brian Toby\n\
445NIST Center for Neutron Research\n\n\
4462000, Not subject to copyright\n\n\
447Revision [lindex $expgui(Revision) 1] (readexp.tcl [lindex $expmap(Revision) 1])\n\n\
448Generalized Structure Analysis System (GSAS)\n\
449A. C. Larson and\n R. B. Von Dreele,\n LANSCE, Los Alamos\n\n\
450" \
451        info 0 OK
452}
453
454# wait until idle
455proc afterawhile {} {
456    # cancel any other instances of this loop
457    after cancel afterawhile
458    after cancel whenidle
459    after cancel whenidle
460    after idle whenidle
461}
462
463# This is called every 2 seconds to check for changes to the .EXP file
464proc whenidle {} {
465    global expgui
466    if $expgui(titleunchanged) {
467        if {$expgui(changed) != 0} {
468            wm title . "$expgui(expfile) (modified)"
469            set expgui(titleunchanged) 0
470        }
471    }
472    if {$expgui(expModifiedLast) == 0} {
473        after 2000 afterawhile
474        return
475    }
476    if {[file mtime $expgui(expfile)] != $expgui(expModifiedLast)} {
477        set ans [ReloadExpMsg [file tail $expgui(expfile)] $expgui(changed)]
478        if {$ans == 0} {
479            loadexp $expgui(expfile)
480        } elseif {$ans == 1} {
481            # reset the time to the next version
482            set expgui(expModifiedLast) [file mtime $expgui(expfile)]
483        } elseif {$ans == 2} {
484            SaveAsFile
485        }
486    }
487    after 2000 afterawhile
488}
489
490# place a message about changes over the main window
491proc ReloadExpMsg {file changes} {
492    global expgui tcl_platform
493    set msg "File $file has been modified by another program"
494    if {$changes == 1} {
495        append msg " and you have made a change to this version.\n"
496    } elseif {$changes > 0} {
497        append msg " and you have made $changes changes to this version.\n"
498    } else {
499        append msg ".\n"
500    }
501    append msg "Do you want to use the newer (modified) version or continue with the older (previous) version of the file?"
502
503    set w .ask
504    catch {destroy $w}
505    toplevel $w -class Dialog
506    wm title $w "Reload?"
507    wm iconname $w "Reload?"
508    wm protocol $w WM_DELETE_WINDOW { }
509    wm transient $w .
510    bind $w <Key-F1> "MakeWWWHelp expguierr.html Overwrite"
511    pack [button $w.help -text Help -bg yellow \
512            -command "MakeWWWHelp expguierr.html Overwrite"] \
513            -side top -anchor e
514    frame $w.bot
515    pack $w.bot -side bottom
516    frame $w.top
517    pack $w.top -side top -fill both -expand 1
518    label $w.top.msg -justify left \
519            -wraplength 5i -font {Times 18} \
520            -text $msg
521    if {$tcl_platform(platform) == "windows"} {
522        $w.top.msg config -font {Times 14}
523    }
524    pack $w.top.msg  -side right -expand 1 -fill both -padx 3m -pady 3m
525    pack [button $w.bot.1 -text "Load new" \
526            -default active -command "set expgui(dialogbutton) 0" \
527            ] -side left -expand 1 -padx 3m -pady 2m
528    pack [button $w.bot.2 -text "Continue with old" \
529            -command "set expgui(dialogbutton) 1"] \
530            -side left -expand 1 -padx 3m -pady 2m
531    if {$changes > 0} {
532        pack [button $w.bot.3 -text "Save edited version" \
533            -command "set expgui(dialogbutton) 2"] \
534            -side left -expand 1 -padx 3m -pady 2m
535    }
536    # Create a binding for <Return> on the dialog
537    bind $w <Return> "tkButtonInvoke $w.bot.1"
538    wm withdraw $w
539    update idletasks
540
541    # for windows put the box in the upper left, for
542    # unix center it over the parent (in unix it appears later)
543    #if {$tcl_platform(platform) == "windows"} {
544        #wm geom $w +0+0
545    #} else {
546
547        # for now, always center the message over the main window
548        # center the new window in the middle of the parent
549        set x [expr [winfo x .] + [winfo width .]/2 - \
550                [winfo reqwidth $w]/2 - [winfo vrootx .]]
551        set y [expr [winfo y .] + [winfo height .]/2 - \
552                [winfo reqheight $w]/2 - [winfo vrooty .]]
553        wm geom $w +$x+$y
554    #}
555    wm deiconify $w
556
557    # Grab the focus
558    set oldFocus [focus]
559    set oldGrab [grab current $w]
560    if {[string compare $oldGrab ""]} {
561        set grabStatus [grab status $oldGrab]
562    }
563    grab $w
564    focus $w.bot.1
565    # for windows rearrange window stacking
566    if {$tcl_platform(platform) == "windows"} {
567        lower .
568        raise $w .
569    }
570    update idletasks
571
572    tkwait variable expgui(dialogbutton)
573    catch {focus $oldFocus}
574    destroy $w
575    if {[string compare $oldGrab ""]} {
576        if {![string compare $grabStatus "global"]} {
577            grab -global $oldGrab
578        } else {
579            grab $oldGrab
580        }
581    }
582    # for windows rearrange window stacking
583    if {$tcl_platform(platform) == "windows"} {
584        raise .
585    }
586    return $expgui(dialogbutton)
587}
588
589# --------  called to confirm before exiting
590proc catchQuit {} {
591    if {[confirmBeforeSave] == "Continue"} {
592        destroy .
593    }
594}
595# save the .EXP file before exiting?
596proc confirmBeforeSave {} {
597    global expgui
598    if !$expgui(changed) {
599        return "Continue"
600    }
601    set decision [tk_dialog .instrSaveData {Save .EXP changes} \
602            {You have made changes to the Experiment, but the changes are not saved. Select an option:} \
603            {} 0 "Save and Exit" "Exit without Save" "Cancel exit command"]
604    switch $decision {
605        0 { savearchiveexp;  return "Continue" }
606        1 {                  return "Continue" }
607        2 {                  return "Cancel"   }
608    }
609}
610
611proc archiveexp {} {
612    global expgui tcl_platform
613    # is there a file to archive
614    if {![file exists $expgui(expfile)]} return
615    catch {
616        set expnam [file rootname $expgui(expfile)]
617        if {$tcl_platform(platform) == "windows"} {
618            set version -1
619            catch {source $expnam.version}
620            incr version
621            if ![file executable [file join $expgui(scriptdir) pkzip.exe]] {
622                # archive w/o pkzip
623                set file $expnam![format "%3.3d" $version].EXP
624                file copy -force $expnam.EXP $file
625                set fp [open $expnam.lst a]
626                puts $fp "\n--------------------------------------------------------------"
627                puts $fp "Archiving $expnam.EXP as $file"
628                puts $fp "--------------------------------------------------------------\n"
629                close $fp
630            } else {
631                # archive with PKZIP           
632                # need to limit expnam to 8 characters
633                set sexp [string toupper [string range [file root [file tail $expnam] ] 0 7]]
634                # PKZIP can't handle long dir names either
635                cd [set dir [file dirname $expnam]]
636                set file $sexp.[format "%3.3d" $version]
637                file copy -force $expnam.EXP $file
638                exec [file join $expgui(scriptdir) pkzip.exe] -m $sexp $file > zip.out &
639                set fp [open $expnam.lst a]
640                puts $fp "\n--------------------------------------------------------------"
641                puts $fp "Archiving $expnam.EXP as $file in [file join $dir $sexp.ZIP]"
642                puts $fp "--------------------------------------------------------------\n"
643                close $fp
644            }
645            set fp [open $expnam.version w]
646            puts $fp "set version $version"
647            close $fp
648        } else {
649            set files [glob -nocomplain $expnam.EXP.*]
650            if {$files == ""} {
651                set file $expnam.EXP.000
652            } else {
653                set file [lindex [lsort -decreasing $files] 0]
654                regexp {.*\.EXP.0?0?([0-9]*).*} $file junk number
655                incr number
656                set file $expnam.EXP.[format "%3.3d" $number]
657            }
658            file copy $expgui(expfile) $file
659            if [catch {exec gzip $file}] {
660                exec echo "\n----------------------------------------------" >> $expnam.LST
661                exec echo "     Archiving $expnam.EXP as $file " >> $expnam.LST
662                exec echo "----------------------------------------------\n" >> $expnam.LST
663            } else {
664                exec echo "\n----------------------------------------------" >> $expnam.LST
665                exec echo "     Archiving $expnam.EXP as $file.gz " >> $expnam.LST
666                exec echo "----------------------------------------------\n" >> $expnam.LST
667            }
668        }
669    } errmsg
670    if {$errmsg != ""} {
671        tk_dialog .warn Confirm "Error in archive: $errmsg" warning 0 OK
672    }
673}
674
675# save and optionally archive the expfile
676proc savearchiveexp {} {
677    global expgui expmap
678    if !$expgui(changed) return
679    if $expgui(archive) archiveexp
680    # add a history record
681    exphistory add " EXPGUI [lindex $expgui(Revision) 1] [lindex $expmap(Revision) 1] ($expgui(changed) changes) -- [clock format [clock seconds]]"
682    # now save the file
683    expwrite $expgui(expfile)
684    set expgui(changed) 0
685    set expgui(expModifiedLast) [file mtime $expgui(expfile)]
686    set expgui(last_History) [string range [string trim [lindex [exphistory last] 1]] 0 50 ]
687    wm title . $expgui(expfile)
688    set expgui(titleunchanged) 1
689}
690
691# setup buttons for each phase on the phase page
692proc setphases {} {
693    global expgui expmap
694    eval destroy [winfo children $expgui(phaseFrame).top.ps]
695    pack [label $expgui(phaseFrame).top.ps.0 -text Phase:] -side left
696    foreach num $expmap(phaselist) type $expmap(phasetype) {
697        pack [button $expgui(phaseFrame).top.ps.$num -text $num \
698                -command "SelectOnePhase $num" -padx 1.5m] -side left
699        if {$type > 3} {
700            $expgui(phaseFrame).top.ps.$num config -state disabled
701        }
702    }
703    if {[file executable $expgui(exptool)] && \
704            [llength $expmap(phaselist)]} {
705        pack [button $expgui(phaseFrame).top.ps.10 \
706                -text "Replace" -command MakeReplacePhaseBox \
707                ] -side left
708    }
709}
710
711# Procedure to respond to changes the phase.
712#  This loads the "phases" widgets with data corresponding to the selected phase.
713proc SelectOnePhase {num} {
714    global entryvar entrycmd entrybox expmap expgui
715    set crsPhase {}
716    $expgui(atomxform) config -text "Xform Atoms" -state disabled
717    foreach n $expmap(phaselist) type $expmap(phasetype) {
718        if {$n == $num && $type <= 3} {
719            catch {$expgui(phaseFrame).top.ps.$num config -relief sunken}
720            set crsPhase $num
721            if {$type == 3} {
722                set expgui(phasetype) "Magnetic\nOnly"
723            } elseif {$type == 2} {
724                set expgui(phasetype) "Magnetic\n& Nuclear"
725            } elseif {$type == 4} {
726                # this is not used at present
727                set expgui(phasetype) "Macromolecular"
728            } else {
729                set expgui(phasetype) ""
730            }
731        } else {
732            catch {$expgui(phaseFrame).top.ps.$n config -relief raised}
733        }
734    }
735    # no phase is selected
736    if {$crsPhase == "" || [llength $expmap(phaselist)] == 0} {
737        # disable traces on entryvar
738        set entrycmd(trace) 0
739        set entrycmd(phasename) ""
740        set entryvar(phasename) ""
741        foreach ent {a b c alpha beta gamma cellref celldamp} {
742            set entrycmd($ent) ""
743            set entryvar($ent) ""
744        }
745        set expgui(curPhase) {}
746        # enable traces on entryvar
747        set entrycmd(trace) 1
748        $expgui(EditingAtoms) config -text ""
749        DisplayAtom 0 0
750        DisplayU 0 0
751        DisplayRefFlags 0 0
752        $expgui(atomlistbox) delete 0 end
753        return
754    }
755
756    set expgui(curPhase) $crsPhase
757    # we have a phase
758
759    # disable traces on entryvar for right now
760    set entrycmd(trace) 0
761
762    ##########################################################
763    ######   SECTION: ASSIGNMENT OF DATA VARIABLES  ##########
764    ##########################################################
765    # phase title
766    set entrycmd(phasename) "phaseinfo $crsPhase name"
767    set entryvar(phasename) [phaseinfo $crsPhase name]
768    # cell parameters & flags
769    foreach ent {a b c alpha beta gamma cellref celldamp} {
770        set entrycmd($ent) "phaseinfo $crsPhase $ent"
771        set entryvar($ent) [phaseinfo $crsPhase $ent]
772        # reset item to black
773        catch {$entrybox($ent) config -fg black}
774    }
775
776    #Procedure call: DisplayU -- Display Anisotropic/Isotropic widget or disable
777    # initialize to diasbled
778    DisplayAtom 0 0
779    DisplayU 0 0
780    DisplayRefFlags 0 0
781    $expgui(EditingAtoms) config -text ""
782
783    DisplayAllAtoms
784
785    # enable traces on entryvar now
786    set entrycmd(trace) 1
787}
788
789set expgui(noreenterDisplayAllAtoms) 0
790# Populate expgui(atomlistbox) (ScrolledListBox) with atoms from selected phase.
791proc DisplayAllAtoms {"mode reset"} {
792    global entryvar entrycmd expmap expgui
793    # if it does not show, dont bother
794    if {$expgui(pagenow) != "phaseFrame"} return
795    if {$expgui(curPhase) == ""} return
796    if $expgui(noreenterDisplayAllAtoms) return
797   
798    set expgui(noreenterDisplayAllAtoms) 1
799    if {$mode != "reset"} {
800        # save the scrolled position
801        set pos [lindex [$expgui(atomlistbox) yview] 0]
802    } else {
803        # this is a reset -- clear the selected atoms list
804        set expgui(selectedatomlist) {}
805    }
806    $expgui(atomlistbox) delete 0 end
807    # loop over atoms
808    set maxline I
809    set phase $expgui(curPhase)
810    set atomlist {}
811    set typehead "type  "
812    set namehead "  name  "
813    set multhead "Mult"
814    set coordhead "   "
815    set frachead "Occupancy"
816    if  {$expgui(asorttype) == "type"} {
817        # sort on atom type
818        set typehead "type* "
819        foreach atom $expmap(atomlist_$phase) {
820            lappend atomlist "$atom [atominfo $phase $atom type] $phase"
821        }
822        set expmap(atomlistboxcontents) [lsort -ascii -index 1 $atomlist]
823    } elseif {$expgui(asorttype) == "number"} {
824        # sort on atom number
825        set namehead "* name  "
826        foreach atom $expmap(atomlist_$phase) {
827            lappend atomlist "$atom $atom $phase"
828        }
829        set expmap(atomlistboxcontents) [lsort -integer -index 1 $atomlist]
830    } elseif {$expgui(asorttype) == "mult"} {
831        # sort on atom number
832        set multhead "Mlt*"
833        foreach atom $expmap(atomlist_$phase) {
834            lappend atomlist "$atom [atominfo $phase $atom mult] $phase"
835        }
836        set expmap(atomlistboxcontents) [lsort -integer -decreasing -index 1 $atomlist]
837    } elseif {$expgui(asorttype) == "occupancy"} {
838        # sort on atom number
839        set frachead "  Occup* "
840        foreach atom $expmap(atomlist_$phase) {
841            lappend atomlist "$atom [atominfo $phase $atom frac] $phase"
842        }
843        set expmap(atomlistboxcontents) [lsort -real -decreasing -index 1 $atomlist]
844    } elseif {$expgui(asorttype) == "x"} {
845        # sort on x
846        set coordhead "(x*)"
847        foreach atom $expmap(atomlist_$phase) {
848            lappend atomlist "$atom [atominfo $phase $atom x] $phase"
849        }
850        set expmap(atomlistboxcontents) [lsort -real -index 1 $atomlist]
851    } elseif {$expgui(asorttype) == "y"} {
852        # sort on y
853        set coordhead "(y*)"
854        foreach atom $expmap(atomlist_$phase) {
855            lappend atomlist "$atom [atominfo $phase $atom y] $phase"
856        }
857        set expmap(atomlistboxcontents) [lsort -real -index 1 $atomlist]
858    } elseif {$expgui(asorttype) == "z"} {
859        # sort on z
860        set coordhead "(z*)"
861        foreach atom $expmap(atomlist_$phase) {
862            lappend atomlist "$atom [atominfo $phase $atom z] $phase"
863        }
864        set expmap(atomlistboxcontents) [lsort -real -index 1 $atomlist]
865    } else {
866        error "Bad expgui(asorttype) = $expgui(asorttype)"
867    }
868
869    foreach tuple $expmap(atomlistboxcontents) {
870        set atom [lindex $tuple 0]
871        set phase [lindex $tuple 2]
872        set refflag {}
873        foreach type {x u f} {
874            if {[atominfo $phase $atom ${type}ref]} {
875                append refflag "[string toupper $type][atominfo $phase $atom ${type}damp] "
876            } else {
877                append refflag " [atominfo $phase $atom ${type}damp] "
878            }   
879        }
880        set line [format "%3d %-6s %-6s %8s %10.6f%10.6f%10.6f%4d%9.4f" \
881                $atom \
882                [atominfo $phase $atom label] \
883                [atominfo $phase $atom type] \
884                $refflag \
885                [atominfo $phase $atom x] \
886                [atominfo $phase $atom y] \
887                [atominfo $phase $atom z] \
888                [atominfo $phase $atom mult] \
889                [atominfo $phase $atom frac]
890        ]
891
892        # add temperature factors (iso/anoiso)
893        if {[atominfo $phase $atom temptype] == "A"} {
894            set maxline A
895            append line [format "  %9.5f%9.5f%9.5f%9.5f%9.5f%9.5f" \
896                    [atominfo $phase $atom U11] \
897                    [atominfo $phase $atom U22] \
898                    [atominfo $phase $atom U33] \
899                    [atominfo $phase $atom U12] \
900                    [atominfo $phase $atom U23] \
901                    [atominfo $phase $atom U13]
902            ]
903        } else {
904            append line [format "  %9.5f" \
905                    [atominfo $phase $atom Uiso]
906            ]
907        }
908        $expgui(atomlistbox) insert end $line
909    }
910    $expgui(atomtitle) delete 0 end
911    if {$maxline == "A"} {
912        $expgui(atomtitle) insert end [format "%10s %6s %8s%29s %9s  %s" \
913                $namehead $typehead "ref/damp  " \
914                "fractional coordinates$coordhead" \
915                "$multhead $frachead" \
916                " Uiso/Uij                                            "]
917    } else {
918        $expgui(atomtitle) insert end [format "%10s %6s %8s%29s %9s  %s" \
919                $namehead $typehead "ref/damp  " \
920                "fractional coordinates$coordhead" \
921                "$multhead $frachead" \
922                " Uiso"]
923    }
924    if {$mode != "reset"} {
925        # restore the selected items
926        foreach i $expgui(selectedatomlist) {
927            $expgui(atomlistbox) selection set $i
928        }
929        # restore the last scrolled position
930        $expgui(atomlistbox) yview moveto $pos
931    }
932    set expgui(noreenterDisplayAllAtoms) 0
933}
934
935# Procedure to select all atoms in response to a right-click
936proc SelectAllAtoms {} {
937    global expgui
938    $expgui(atomlistbox) selection set 0 end
939    # call editRecord in case trace was called before the selection was made
940    editRecord
941}
942
943# Procedure to respond to left mouse release in the atoms Pane
944proc editRecord { args } {
945    global entrycmd expgui
946    set expgui(selectedatomlist) [$expgui(atomlistbox) curselection]
947    # disable traces on entryvar for right now
948    set entrycmd(trace) 0
949
950    if {[llength $expgui(selectedatomlist)] == 0} {
951        if $expgui(debug) {error "Attempt display non-existent atoms"}
952    } elseif {[llength $expgui(selectedatomlist)] == 1} {
953        editOneRecord $expgui(selectedatomlist)
954    } else {
955        editMultipleRecords $expgui(selectedatomlist)
956    }
957    # reenable traces on entryvar
958    set entrycmd(trace) 1
959    # repaint the atoms box in case anything was changed
960    #    DisplayAllAtoms noreset
961}
962
963proc editOneRecord { AtomIndex } {
964    global expmap expgui
965    # get atom number & phase
966    set tuple [lindex $expmap(atomlistboxcontents) $AtomIndex]
967    set atomnum [lindex $tuple 0]
968    set p [lindex $tuple 2]
969    DisplayU $atomnum $p
970    DisplayAtom $atomnum $p
971    DisplayRefFlags $atomnum $p
972    $expgui(EditingAtoms) config -text "Editing atom #$atomnum -- [atominfo $p $atomnum label]"
973    $expgui(atomxform) config -text "Xform Atom" -state normal
974}
975
976# this will not work for a multi-phase list of atoms (yet)
977proc editMultipleRecords { AtomIndexList } {
978    global expmap expgui
979    set numberList {}
980    # current phase
981    set p $expgui(curPhase)
982    foreach AtomIndex $AtomIndexList {
983        # get atom number & phase
984        set tuple [lindex $expmap(atomlistboxcontents) $AtomIndex]
985        lappend numberList [lindex $tuple 0]
986#       set p [lindex $tuple 2]
987    }
988    # this needs to track by phase
989    $expgui(EditingAtoms) config -text \
990            "Set refinement options: atoms [CompressList $numberList]"
991    DisplayU 0 0
992    DisplayAtom 0 0
993    # this needs to track by phase
994    DisplayRefFlags $numberList $p
995    $expgui(atomxform) config -text "Xform Atoms" -state normal
996}
997
998# format a string of numbers to save space, e.g. "1 2 3 4 6 7 19 13 14 15"
999# becomes "1-4,6,7,13-15,19"
1000proc CompressList {numberList} {
1001    # format the number list to save space
1002    set lastnum -99
1003    set flist {}
1004    set count 0
1005    if [catch {set sortlist [lsort -integer $numberList]}] {return $numberList}
1006    foreach num $sortlist {
1007            set next [expr $lastnum+1]
1008            if {$num != $next} {
1009                if {$count == 0 && $flist != ""} {
1010                    append flist ",$num"
1011                } elseif {$count == 1 && $flist != ""} {
1012                    append flist ",$lastnum,$num"
1013                } elseif {$flist != ""} {
1014                    append flist "-$lastnum,$num"
1015            } else {
1016                append flist "$num"
1017            }
1018            set lastnum $num
1019            set count 0
1020        } else {
1021            incr count
1022            incr lastnum
1023        }
1024    }
1025    if {$count == 1 && $flist != ""} {
1026        append flist ",$lastnum"
1027    } elseif {$flist != "" && $count > 1} {
1028        append flist "-$lastnum"
1029    }
1030    return $flist
1031}
1032
1033# Procedure to display Isotropic or Anisotropic temperature factors
1034#  Changes the display to one entry widget for Isotropic motion OR
1035#   6 entry widgets for Anisotropic motion in Frame3.
1036#   or disables the widet entirly if atom = 0
1037proc DisplayU { atomnum p} {
1038    global expgui entryvar entrycmd
1039    if {$atomnum == 0} {
1040        set iOrA disable
1041    } else {
1042        set iOrA [atominfo $p $atomnum temptype]
1043    }
1044
1045    set firstbox [lindex $expgui(anisolabels) 0]
1046    if { $iOrA == "A" } {
1047        $firstbox config -text "U11 "
1048        foreach item $expgui(anisolabels) {
1049            $item config -fg black
1050        }
1051        foreach item $expgui(anisoentry) var {U11 U22 U33 U12 U13 U23} {
1052            set entrycmd($var) "atominfo $p $atomnum $var"
1053            set entryvar($var) [eval $entrycmd($var)]
1054            $item config -fg black -state normal  -bg white
1055        }
1056    } elseif { $iOrA == "I" || $iOrA == "disable"} {
1057        foreach item $expgui(anisolabels) {
1058            $item config -fg $expgui(bkgcolor1)
1059        }
1060        foreach item [lrange $expgui(anisoentry) 1 end] \
1061                var {U22 U33 U12 U13 U23} {
1062            set entrycmd($var) ""
1063            set entryvar($var) ""
1064            $item config -fg $expgui(bkgcolor1) -bg $expgui(bkgcolor1) \
1065                    -state disabled
1066        }
1067        if { $iOrA == "disable"} {
1068            set entrycmd($var) ""
1069            set entryvar($var) ""
1070            [lindex $expgui(anisoentry) 0] config \
1071                    -fg $expgui(bkgcolor1) -bg $expgui(bkgcolor1) \
1072                    -state disabled
1073        } else {
1074            set entrycmd(U11) "atominfo $p $atomnum Uiso"
1075            set entryvar(U11) [eval $entrycmd(U11)]
1076            $firstbox config -text Uiso -fg black
1077            [lindex $expgui(anisoentry) 0] config -fg black -bg white -state normal
1078        }
1079    }
1080}
1081
1082# need to think about multiple phases
1083
1084# Procedure to display refinement flags
1085proc DisplayRefFlags { atomnum p} {
1086    global expgui entryvar entrycmd
1087    if {$atomnum == 0} {
1088        foreach label $expgui(atomreflbl) {
1089            $label config -fg $expgui(bkgcolor1)
1090        }
1091        foreach entry $expgui(atomref) {
1092            $entry config -state disabled \
1093                    -fg $expgui(bkgcolor1) -bg $expgui(bkgcolor1)
1094            # turn off checkbuttons
1095            catch {$entry deselect}
1096
1097        }
1098        return
1099    }
1100    foreach label $expgui(atomreflbl) {
1101        $label config -fg black
1102    }
1103    foreach entry $expgui(atomref) {
1104        $entry config -state normal -fg black -bg $expgui(bkgcolor1)
1105    }
1106    foreach var {xref uref fref xdamp udamp fdamp}  {
1107        set entrycmd($var) "atominfo $p [list $atomnum] $var"
1108        set entryvar($var) [eval $entrycmd($var)]
1109    }
1110}
1111
1112# Procedure to display an atom in the atom edit boxes
1113proc DisplayAtom { atomnum p} {
1114    global expgui entryvar entrycmd
1115    if {$atomnum == 0} {
1116        foreach label $expgui(atomlabels) {
1117            $label config -fg $expgui(bkgcolor1)
1118        }
1119        foreach entry $expgui(atomentry) {
1120            $entry config -state disabled \
1121                    -fg $expgui(bkgcolor1) -bg $expgui(bkgcolor1)
1122        }
1123        return
1124    }
1125    foreach label $expgui(atomlabels) {
1126        $label config -fg black
1127    }
1128    foreach entry $expgui(atomentry) {
1129        $entry config -state normal -fg black -bg white
1130    }
1131    foreach var {x y z label frac } {
1132        set entrycmd($var) "atominfo $p $atomnum $var"
1133        set entryvar($var) [eval $entrycmd($var)]
1134    }
1135}
1136
1137# make a histogram box; used in MakeHistPane,
1138proc MakeHistBox {frm} {
1139    global expgui
1140    grid [label $frm.mode -text "Select a Histogram" \
1141            -bg beige -anchor center] \
1142            -row 0 -column 0 -columnspan 2 -sticky ew
1143    bind $frm.mode <Button-1> {
1144        set i [lsearch $expgui(AllowedHistSelectModes) $expgui(globalmode)]
1145        set expgui(globalmode) [lindex \
1146                "$expgui(AllowedHistSelectModes) \
1147                $expgui(AllowedHistSelectModes)" [incr i]]
1148        sethistlist
1149    }
1150    bind $frm.mode <Button-3> {set expgui(globalmode) 0; sethistlist}
1151    grid [listbox $frm.title -height 1 -relief flat \
1152            -exportselection 0 \
1153            -font $expgui(histfont) ] -row 1 -column 0 -sticky ew
1154    grid [listbox $frm.lbox -height 10 -width 25 \
1155            -exportselection 0 \
1156            -font $expgui(histfont) \
1157            -xscrollcommand "$frm.x set" \
1158            -yscrollcommand "$frm.y set" \
1159            ] -row 2 -column 0 -sticky news
1160    lappend expgui(HistSelectList) $frm
1161    grid [scrollbar $frm.x -orient horizontal \
1162            -command "move2boxes \" $frm.title $frm.lbox \" "
1163    ] -row 3 -column 0 -sticky ew
1164    grid [scrollbar $frm.y \
1165            -command "$frm.lbox yview"] \
1166            -row 2 -column 1 -sticky ns
1167    grid columnconfigure $frm 0 -weight 1
1168    grid rowconfigure $frm 2 -weight 1
1169}
1170
1171# update the histogram list
1172# to do: show histogram ref flags?
1173proc sethistlist {} {
1174    global expgui expmap
1175    array set lbl {
1176        1 "Select 1 or more\nTOF Histograms"
1177        2 "Select 1 or more\nCW Neutron Histograms"
1178        3 "Select 1 or more\nAlpha 1,2 X-ray Histograms"
1179        4 "Select 1 or more\nmonochromatic X-ray Histograms"
1180        5 "Select 1 or more Energy\nDisperive X-ray Histograms"
1181        6 "Select 1 or more of\n any type Histograms"
1182    }
1183    foreach lbox $expgui(HistSelectList) {
1184        $lbox.title delete 0 end
1185        $lbox.lbox delete 0 end
1186        if {$expgui(globalmode) != 0} {
1187            $lbox.lbox config -selectmode extended
1188            $lbox.mode config -text $lbl($expgui(globalmode)) -bg yellow
1189        } else {
1190            $lbox.lbox config -selectmode browse
1191            $lbox.mode config -text "Select a histogram" -bg beige
1192        }
1193    }
1194    # disable the unallowed pages in all mode
1195    if {$expgui(globalmode) == 6} {
1196        foreach pair $expgui(GlobalModeAllDisable) {
1197            if {$expgui(pagenow) == [lindex $pair 0]} {
1198                RaisePage lsFrame
1199            }
1200            eval [lindex $pair 1] -state disabled
1201        }
1202    } else {
1203        foreach pair $expgui(GlobalModeAllDisable) {
1204            eval [lindex $pair 1] -state normal
1205        }
1206    }
1207    set histlist {}
1208    if  {$expgui(hsorttype) == "type"} {
1209        # sort on histogram type
1210        foreach h [lsort -integer -increasing $expmap(powderlist)] {
1211            lappend histlist "$h [string range $expmap(htype_$h) 1 2]"
1212        }
1213        set expmap(histlistboxcontents) [lsort -ascii -index 1 $histlist]
1214    } elseif {$expgui(hsorttype) == "number"} {
1215        # sort on histogram number
1216        foreach h [lsort -integer -increasing $expmap(powderlist)] {
1217            lappend histlist "$h $h"
1218        }
1219        set expmap(histlistboxcontents) [lsort -integer -index 1 $histlist]
1220    } elseif {$expgui(hsorttype) == "bank"} {
1221        # sort on original bank number
1222        foreach h [lsort -integer -increasing $expmap(powderlist)] {
1223            lappend histlist "$h [histinfo $h bank]"
1224        }
1225        set expmap(histlistboxcontents) [lsort -integer -index 1 $histlist]
1226    } elseif {$expgui(hsorttype) == "angle"} {
1227        # sort on wavelength (CW) or angle (E disp.)
1228        foreach h [lsort -integer -increasing $expmap(powderlist)] {
1229            if {[string range $expmap(htype_$h) 2 2] == "T"} {
1230                set det [format %8.2f [histinfo $h tofangle]]
1231            } elseif {[string range $expmap(htype_$h) 2 2] == "C"} {
1232                set det [format %8.5f [histinfo $h lam1]]
1233            } elseif {[string range $expmap(htype_$h) 2 2] == "E"} {
1234                set det [format %8.2f [histinfo $h lam1]]
1235            } else {
1236                set det {}
1237            }
1238            lappend histlist "$h $det"
1239        }
1240        set expmap(histlistboxcontents) [lsort -real -index 1 $histlist]
1241    }
1242
1243    # title field needs to match longest title
1244    foreach lbox $expgui(HistSelectList) {
1245        $lbox.title insert end [format "%2s %s %4s %8s  %-67s" \
1246                "h#" \
1247                type \
1248                bank \
1249                "ang/wave" \
1250                "    title" \
1251                ]
1252    }
1253    foreach tuple $expmap(histlistboxcontents) {
1254        set h [lindex $tuple 0]
1255
1256        if {$expgui(globalmode) == 1} {
1257            if {[string range $expmap(htype_$h) 2 2] != "T"} continue
1258        } elseif {$expgui(globalmode) == 2} {
1259            if {[string range $expmap(htype_$h) 1 2] != "NC"} continue
1260        } elseif {$expgui(globalmode) == 3} {
1261            if {[string range $expmap(htype_$h) 1 2] != "XC" || \
1262                    [histinfo $h lam2] == 0.0} continue
1263        } elseif {$expgui(globalmode) == 4} {
1264            if {[string range $expmap(htype_$h) 1 2] != "XC" || \
1265                    [histinfo $h lam2] != 0.0} continue
1266        } elseif {$expgui(globalmode) == 5} {
1267            if {[string range $expmap(htype_$h) 1 2] != "XE"} continue
1268        }
1269
1270        if {[string range $expmap(htype_$h) 2 2] == "T"} {
1271            set det [format %8.2f [histinfo $h tofangle]]
1272        } elseif {[string range $expmap(htype_$h) 2 2] == "C"} {
1273            set det [format %8.5f [histinfo $h lam1]]
1274        } elseif {[string range $expmap(htype_$h) 2 2] == "E"} {
1275            set det [format %8.2f [histinfo $h lam1]]
1276        } else {
1277            set det {}
1278        }
1279        foreach lbox $expgui(HistSelectList) {
1280            $lbox.lbox insert end [format "%2d  %s  %4d %8s  %-67s" \
1281                    $h \
1282                    [string range $expmap(htype_$h) 1 2] \
1283                    [histinfo $h bank] \
1284                    $det \
1285                    [string range [histinfo $h title] 0 66] \
1286                    ]
1287        }
1288    }
1289    UpdateCurrentPage
1290}
1291
1292proc UpdateCurrentPage {} {
1293    global expgui
1294    foreach set $expgui(frameactionlist) {
1295        if {$expgui(pagenow) == [lindex $set 0]} {catch [lindex $set 1]}
1296    }
1297}
1298
1299#-----------------------------------------------------------------------
1300# ----------- draw Histogram page
1301#-----------------------------------------------------------------------
1302proc DisplayHistogram {} {
1303    global expgui entrycmd entryvar entrybox expmap
1304
1305    # trap if more than one histogram is selected unless global mode
1306    if {$expgui(globalmode) == 0 && [llength $expgui(curhist)] > 1} {
1307        set expgui(curhist) [lindex $expgui(curhist) 0]
1308    }
1309
1310    # disable the add histogram button if no phases are present
1311    if {[llength $expmap(phaselist)] == 0} {
1312        $expgui(histFrame).newh configure -state disabled
1313    } else {
1314        $expgui(histFrame).newh configure -state normal
1315    }
1316
1317    # display the selected histograms
1318    $expgui(histFrame).hs.lbox selection clear 0 end
1319    foreach h $expgui(curhist) {
1320        $expgui(histFrame).hs.lbox selection set $h
1321    }
1322
1323    # disable traces on entryvar for right now
1324    set entrycmd(trace) 0
1325
1326    # get histogram list
1327    set histlist {}
1328    foreach item $expgui(curhist) {
1329        lappend histlist [lindex $expmap(powderlist) $item]
1330    }
1331    # must have at least one histogram selected here
1332    if {[llength $histlist] == 0} {
1333        set expgui(backtermlbl) ""
1334        set expgui(backtypelbl) ""
1335        foreach var {bref bdamp} {
1336            set entrycmd($var) ""
1337            set entryvar($var) ""
1338        }
1339        $expgui(histFrame).top.txt config -text "No Selected Histograms"
1340        grid $expgui(histFrame).top -column 1 -row 0 -sticky nsew       
1341        set expgui(bkglbl) ""
1342        eval destroy [winfo children $expgui(diffBox)]
1343        set entrycmd(trace) 1
1344        return
1345    }
1346
1347    if {$expgui(globalmode) != 0} {
1348        set expgui(backtermlbl) ""
1349        set expgui(backtypelbl) ""
1350        foreach var {bref bdamp} {
1351            set entrycmd($var) "histinfo [list $histlist] $var"
1352            set entryvar($var) [histinfo [lindex $histlist 0] $var]
1353        }
1354    } else {
1355        set hist $histlist
1356        set terms [histinfo $hist backterms]
1357        set expgui(backtermlbl) "($terms terms)"
1358        set expgui(backtypelbl) "Function type [histinfo $hist backtype]"
1359        foreach var {bref bdamp} {
1360            set entrycmd($var) "histinfo $hist $var"
1361            set entryvar($var) [eval $entrycmd($var)]
1362        }
1363    }
1364    # Top box
1365    if $expgui(haveBW) {
1366        catch {destroy $expgui(histFrame).pflag}
1367    }
1368    if {$expgui(globalmode) != 0} {
1369        $expgui(histFrame).top.txt config \
1370                -text "Selected Histograms: [CompressList $histlist]"
1371        grid $expgui(histFrame).top -column 1 -row 0 -sticky nsew       
1372        set expgui(bkglbl) "Globally Edit Background"
1373    } else {
1374        grid forget $expgui(histFrame).top
1375        set expgui(bkglbl) "Edit Background"
1376        if {$expgui(haveBW) && [llength $expmap(phaselist)] > 1} {
1377            TitleFrame $expgui(histFrame).pflag  \
1378                    -borderwidth 4 -side left -relief groove \
1379                    -text "Phase Flags"
1380            set expgui(pflag) [$expgui(histFrame).pflag getframe]
1381            grid $expgui(histFrame).pflag -column 1 -row 1 -sticky nsew
1382            grid rowconfigure $expgui(histFrame) 2 -minsize 35
1383            foreach p $expmap(phaselist) {
1384                pack [checkbutton $expgui(pflag).$p \
1385                        -command "GetPhaseFlags $hist" \
1386                        -variable expgui(pflag$p) -text $p] -side left
1387                if {[lsearch $expmap(phaselist_$hist) $p] == -1} {
1388                    set expgui(pflag$p) 0
1389                } else {
1390                    set expgui(pflag$p) 1
1391                }
1392            }
1393        }
1394    }
1395
1396    # diffractometer constants
1397    foreach var {lam1 lam2 kratio pola ipola ddamp zero \
1398            wref pref dcref daref ratref ttref zref } {
1399        set entrycmd($var) "histinfo [list $histlist] $var"
1400        set entryvar($var) [histinfo [lindex $histlist 0] $var]
1401    }
1402
1403    eval destroy [winfo children $expgui(diffBox)]
1404    if {$expgui(globalmode) == 0} {
1405        if {[string range $expmap(htype_$hist) 2 2] == "T"} {
1406        #------
1407        # TOF |
1408        #------
1409            grid [ label $expgui(diffBox).lDCrc -text "Refine DIFC" ] \
1410                    -column 1 -row 1
1411            grid [ checkbutton $expgui(diffBox).rfDCrc -variable entryvar(dcref) ] \
1412                    -column 2 -row 1
1413            grid [ label $expgui(diffBox).lDCdifc -text DIFC ] \
1414                    -column 3 -row 1 -sticky w
1415            grid [ entry $expgui(diffBox).eDCdifc -textvariable entryvar(lam1) \
1416                    -width 15 ] -column 4 -row 1
1417            set entrybox(lam1) $expgui(diffBox).eDCdifc
1418            #
1419            grid [ label $expgui(diffBox).lDCra -text "Refine DIFA" ] \
1420                    -column 1 -row 2
1421            grid [ checkbutton $expgui(diffBox).rfDCra -variable entryvar(daref) ] \
1422                    -column 2 -row 2
1423            grid [ label $expgui(diffBox).lDCdifa -text DIFA ] \
1424                    -column 3 -row 2
1425            grid [ entry $expgui(diffBox).eDCdifa -textvariable entryvar(lam2) \
1426                    -width 15 ] -column 4 -row 2
1427            set entrybox(lam2) $expgui(diffBox).eDCdifa
1428            #
1429            grid [ label $expgui(diffBox).lDCzero -text "Zero"] \
1430                    -column 3 -row 3
1431            grid [ entry $expgui(diffBox).eDCzero -textvariable entryvar(zero) \
1432                    -width 15 ] -column 4 -row 3
1433            set entrybox(zero) $expgui(diffBox).eDCzero
1434            grid [ label $expgui(diffBox).lDCzref -text "Refine zero" ] \
1435                    -column 1 -row 3 -sticky w
1436            grid [ checkbutton $expgui(diffBox).rfDCzref \
1437                    -variable entryvar(zref) ] -column 2 -row 3
1438        } elseif {[string range $expmap(htype_$hist) 1 2] == "NC"} {
1439        #---------------
1440        # CW - neutron |
1441        #---------------
1442            grid [ label $expgui(diffBox).lDC1 -text "Refine wave" ] \
1443                    -column 1 -row 1
1444            grid [ checkbutton $expgui(diffBox).rfDC1 -variable entryvar(wref) ] \
1445                    -column 2 -row 1
1446            grid [ label $expgui(diffBox).lDCdifc -text wave ] \
1447                    -column 3 -row 1 -sticky w
1448            grid [ entry $expgui(diffBox).eDCdifc -textvariable entryvar(lam1) \
1449                    -width 15 ] -column 4 -row 1
1450            set entrybox(lam1) $expgui(diffBox).eDCdifc
1451            #
1452            grid [ label $expgui(diffBox).lDCzref -text "Refine zero" ] \
1453                    -column 1 -row 3 -sticky w
1454            grid [ checkbutton $expgui(diffBox).rfDCzref \
1455                    -variable entryvar(zref) ] -column 2 -row 3
1456            grid [ label $expgui(diffBox).lDCzero -text "Zero"] \
1457                    -column 3 -row 3
1458            grid [ entry $expgui(diffBox).eDCzero -textvariable entryvar(zero) \
1459                    -width 15 ] -column 4 -row 3
1460            set entrybox(zero) $expgui(diffBox).eDCzero
1461        } elseif {[string range $expmap(htype_$hist) 1 2] == "XC" && \
1462                [histinfo $hist lam2] == 0.0} {
1463        #--------------------------
1464        # CW - x-ray 1 wavelength |
1465        #--------------------------
1466            grid [ label $expgui(diffBox).lDC1 -text "Refine wave" ] \
1467                    -column 1 -row 1
1468            grid [ checkbutton $expgui(diffBox).rfDC1 -variable entryvar(wref) ] \
1469                    -column 2 -row 1
1470            grid [ label $expgui(diffBox).lDCdifc -text wave ] \
1471                    -column 3 -row 1 -sticky w
1472            grid [ entry $expgui(diffBox).eDCdifc -textvariable entryvar(lam1) \
1473                    -width 15 ] -column 4 -row 1
1474            set entrybox(lam1) $expgui(diffBox).eDCdifc
1475            #
1476            grid [ label $expgui(diffBox).lDCzref -text "Refine zero" ] \
1477                    -column 1 -row 3 -sticky w
1478            grid [ checkbutton $expgui(diffBox).rfDCzref \
1479                    -variable entryvar(zref) ] -column 2 -row 3
1480            grid [ label $expgui(diffBox).lDCzero -text "Zero"] \
1481                    -column 3 -row 3
1482            grid [ entry $expgui(diffBox).eDCzero -textvariable entryvar(zero) \
1483                    -width 15 ] -column 4 -row 3
1484            set entrybox(zero) $expgui(diffBox).eDCzero
1485            #
1486            grid [ label $expgui(diffBox).lDCpref -text "Refine POLA" ] \
1487                    -column 1 -row 4 -sticky w
1488            grid [ checkbutton $expgui(diffBox).rfDCpref \
1489                    -variable entryvar(pref) ] -column 2 -row 4
1490            grid [ label $expgui(diffBox).lDCpola -text POLA ] \
1491                    -column 3 -row 4
1492            grid [ entry $expgui(diffBox).eDCpola \
1493                    -textvariable entryvar(pola) -width 15 ] -column 4 -row 4
1494            set entrybox(pola) $expgui(diffBox).eDCpola
1495            grid [ label $expgui(diffBox).lDCipola -text "IPOLA" ] \
1496                    -column 5 -row 4
1497            grid [ entry $expgui(diffBox).eDCipola -width 2 \
1498                    -textvariable entryvar(ipola)] -column 6 -row 4
1499            set entrybox(ipola) $expgui(diffBox).eDCipola
1500        } elseif {[string range $expmap(htype_$hist) 1 2] == "XC"} {
1501        #---------------------------
1502        # CW - x-ray 2 wavelengths |
1503        #---------------------------
1504            grid [ label $expgui(diffBox).lDCdifc -text wavelengths ] \
1505                    -column 3 -row 1 -sticky w
1506            grid [ entry $expgui(diffBox).eDCdifc -textvariable entryvar(lam1) \
1507                    -width 15 ] -column 4 -row 1
1508            set entrybox(lam1) $expgui(diffBox).eDCdifc
1509            grid [ entry $expgui(diffBox).eDCdifa -textvariable entryvar(lam2) \
1510                    -width 15 ] -column 5 -row 1
1511            set entrybox(lam2) $expgui(diffBox).eDCdifa
1512            #
1513            grid [ label $expgui(diffBox).lDCrref -text "Refine ratio" ] \
1514                    -column 1 -row 2 -sticky w
1515            grid [ checkbutton $expgui(diffBox).rfDCrref \
1516                    -variable entryvar(ratref) ] -column 2 -row 2
1517            grid [ label $expgui(diffBox).lDCratio -text Ratio ] \
1518                    -column 3 -row 2
1519            grid [ entry $expgui(diffBox).eDCkratio \
1520                    -textvariable entryvar(kratio) \
1521                    -width 15 ] -column 4 -row 2
1522            set entrybox(kratio) $expgui(diffBox).eDCkratio
1523            #
1524            grid [ label $expgui(diffBox).lDCzero -text "Zero"] \
1525                    -column 3 -row 3
1526            grid [ entry $expgui(diffBox).eDCzero -textvariable entryvar(zero) \
1527                    -width 15 ] -column 4 -row 3
1528            grid [ label $expgui(diffBox).lDCzref -text "Refine zero" ] \
1529                    -column 1 -row 3 -sticky w
1530            set entrybox(zero) $expgui(diffBox).eDCzero
1531            grid [ checkbutton $expgui(diffBox).rfDCzref \
1532                    -variable entryvar(zref) ] -column 2 -row 3
1533            grid [ label $expgui(diffBox).lDCpref -text "Refine POLA" ] \
1534                    -column 1 -row 4 -sticky w
1535            grid [ checkbutton $expgui(diffBox).rfDCpref \
1536                    -variable entryvar(pref) ] -column 2 -row 4
1537            grid [ label $expgui(diffBox).lDCpola -text POLA ] \
1538                    -column 3 -row 4
1539            grid [ entry $expgui(diffBox).eDCpola \
1540                    -textvariable entryvar(pola) -width 15 ] -column 4 -row 4
1541            set entrybox(pola) $expgui(diffBox).eDCpola
1542            grid [ label $expgui(diffBox).lDCipola -text "IPOLA" ] \
1543                    -column 5 -row 4
1544            grid [ entry $expgui(diffBox).eDCipola -width 2 \
1545                    -textvariable entryvar(ipola)] -column 6 -row 4
1546            set entrybox(ipola) $expgui(diffBox).eDCipola
1547        } elseif {[string range $expmap(htype_$hist) 1 2] == "XE"} {
1548        #-------------
1549        # ED - x-ray |
1550        #-------------
1551            grid [ label $expgui(diffBox).lDC1 -text "Refine 2theta" ] \
1552                    -column 1 -row 1
1553            grid [ checkbutton $expgui(diffBox).rfDC1 -variable entryvar(ttref) ] \
1554                    -column 2 -row 1
1555            grid [ label $expgui(diffBox).lDCdifc -text 2Theta ] \
1556                    -column 3 -row 1 -sticky w
1557            grid [ entry $expgui(diffBox).eDCdifc -textvariable entryvar(lam1) \
1558                    -width 15 ] -column 4 -row 1
1559            set entrybox(lam1) $expgui(diffBox).eDCdifc
1560            #
1561            grid [ label $expgui(diffBox).lDCpref -text "Refine POLA" ] \
1562                    -column 1 -row 4 -sticky w
1563            grid [ checkbutton $expgui(diffBox).rfDCpref \
1564                    -variable entryvar(pref) ] -column 2 -row 4
1565            grid [ label $expgui(diffBox).lDCpola -text POLA ] \
1566                    -column 3 -row 4
1567            grid [ entry $expgui(diffBox).eDCpola \
1568                    -textvariable entryvar(pola) -width 15 ] -column 4 -row 4
1569            set entrybox(pola) $expgui(diffBox).eDCpola
1570            grid [ label $expgui(diffBox).lDCipola -text "IPOLA" ] \
1571                    -column 5 -row 4
1572            grid [ entry $expgui(diffBox).eDCipola -width 2 \
1573                    -textvariable entryvar(ipola)] -column 6 -row 4
1574            set entrybox(ipola) $expgui(diffBox).eDCipola
1575        }
1576    } elseif {$expgui(globalmode) == 1} {
1577        #-------------
1578        # Global TOF |
1579        #-------------
1580        grid [ label $expgui(diffBox).lDCrc -text "Refine DIFC" ] \
1581                -column 1 -row 1
1582        grid [ checkbutton $expgui(diffBox).rfDCrc -variable entryvar(dcref) ] \
1583                -column 2 -row 1
1584        grid [button $expgui(diffBox).bDCdifc -text "Set DIFC Globally" \
1585                -command "editglobalparm histinfo difc {DIFC}"] -column 3 -row 1
1586        #
1587        grid [ label $expgui(diffBox).lDCra -text "Refine DIFA" ] \
1588                -column 1 -row 2
1589        grid [ checkbutton $expgui(diffBox).rfDCra -variable entryvar(daref) ] \
1590                -column 2 -row 2
1591        grid [ button $expgui(diffBox).bDCdifa -text "Set DIFA Globally" \
1592                -command "editglobalparm histinfo difa {DIFA}"] -column 3 -row 2
1593        #
1594        grid [ label $expgui(diffBox).lDCzref -text "Refine zero" ] \
1595                -column 1 -row 3 -sticky w
1596        grid [ checkbutton $expgui(diffBox).rfDCzref \
1597                -variable entryvar(zref) ] -column 2 -row 3
1598        grid [ button $expgui(diffBox).bDCzero -text "Set ZERO Globally" \
1599                -command "editglobalparm histinfo zero {Zero}"] -column 3 -row 3
1600    } elseif {$expgui(globalmode) == 2} {
1601        #--------------------
1602        # Global CW neutron |
1603        #--------------------
1604        grid [ label $expgui(diffBox).lDC1 -text "Refine wave" ] \
1605                -column 1 -row 1
1606        grid [ checkbutton $expgui(diffBox).rfDC1 -variable entryvar(wref) ] \
1607                -column 2 -row 1
1608        grid [button $expgui(diffBox).bDCdifc -text "Set Wave Globally" \
1609                -command "editglobalparm histinfo lam1 Wavelength"] \
1610                -column 3 -row 1
1611        #
1612        grid [ label $expgui(diffBox).lDCzref -text "Refine zero" ] \
1613                -column 1 -row 3 -sticky w
1614        grid [ checkbutton $expgui(diffBox).rfDCzref \
1615                -variable entryvar(zref) ] -column 2 -row 3
1616        grid [button $expgui(diffBox).bDCzero -text "Set Zero Globally" \
1617                -command "editglobalparm histinfo zero Zero"] -column 3 -row 3
1618    } elseif {$expgui(globalmode) == 4} {
1619        #----------------------
1620        # Global CW mono xray |
1621        #----------------------
1622        grid [ label $expgui(diffBox).lDC1 -text "Refine wave" ] \
1623                -column 1 -row 1
1624        grid [ checkbutton $expgui(diffBox).rfDC1 -variable entryvar(wref) ] \
1625                -column 2 -row 1
1626        grid [button $expgui(diffBox).bDCdifc -text "Set Wave Globally" \
1627                -command "editglobalparm histinfo lam1 Wavelength"] \
1628                -column 3 -row 1
1629        #
1630        grid [ label $expgui(diffBox).lDCzref -text "Refine zero" ] \
1631                -column 1 -row 3 -sticky w
1632        grid [ checkbutton $expgui(diffBox).rfDCzref \
1633                -variable entryvar(zref) ] -column 2 -row 3
1634        grid [button $expgui(diffBox).bDCzero -text "Set Zero Globally" \
1635                -command "editglobalparm histinfo zero Zero"] -column 3 -row 3
1636        #
1637        grid [ label $expgui(diffBox).lDCpref -text "Refine POLA" ] \
1638                -column 1 -row 4 -sticky w
1639        grid [ checkbutton $expgui(diffBox).rfDCpref \
1640                -variable entryvar(pref) ] -column 2 -row 4
1641        grid [button $expgui(diffBox).bDCpola -text "Set POLA Globally" \
1642                -command "editglobalparm histinfo pola POLA"] -column 3 -row 4
1643        grid [button $expgui(diffBox).bDCipola -text "Set IPOLA Globally" \
1644                -command "editglobalparm histinfo ipola IPOLA"] -column 4 -row 4
1645    } elseif {$expgui(globalmode) == 3} {
1646        #------------------------
1647        # Global alpha 1,2 xray |
1648        #------------------------
1649        grid [button $expgui(diffBox).bDCl1 -text "Set Wave1 Globally" \
1650                -command "editglobalparm histinfo lam1 {Wavelength 1}"] \
1651                -column 3 -row 1
1652        grid [button $expgui(diffBox).bDCl2 -text "Set Wave2 Globally" \
1653                -command "editglobalparm histinfo lam2 {Wavelength 2}"] \
1654                -column 4 -row 1
1655        #
1656        grid [ label $expgui(diffBox).lDCratref -text "Refine Ratio" ] \
1657                -column 1 -row 3 -sticky w
1658        grid [ checkbutton $expgui(diffBox).rfDCratref \
1659                -variable entryvar(ratref) ] -column 2 -row 3
1660        grid [button $expgui(diffBox).bDCrrat -text "Set Ratio Globally" \
1661                -command "editglobalparm histinfo ratio {Wavelength Ratio}"] \
1662                -column 3 -row 3
1663        #
1664        grid [ label $expgui(diffBox).lDCzref -text "Refine zero" ] \
1665                -column 1 -row 3 -sticky w
1666        grid [ checkbutton $expgui(diffBox).rfDCzref \
1667                -variable entryvar(zref) ] -column 2 -row 3
1668        grid [button $expgui(diffBox).bDCzero -text "Set Zero Globally" \
1669                -command "editglobalparm histinfo zero Zero"] -column 3 -row 3
1670        #
1671        grid [ label $expgui(diffBox).lDCpref -text "Refine POLA" ] \
1672                -column 1 -row 4 -sticky w
1673        grid [ checkbutton $expgui(diffBox).rfDCpref \
1674                -variable entryvar(pref) ] -column 2 -row 4
1675        grid [button $expgui(diffBox).bDCpola -text "Set POLA Globally" \
1676                -command "editglobalparm histinfo pola POLA"] -column 3 -row 4
1677        grid [button $expgui(diffBox).bDCipola -text "Set IPOLA Globally" \
1678                -command "editglobalparm histinfo ipola IPOLA"] -column 4 -row 4
1679    } elseif {$expgui(globalmode) == 5} {
1680        #-----------------
1681        # Global ED xray |
1682        #-----------------
1683        grid [ label $expgui(diffBox).lDC1 -text "Refine 2theta" ] \
1684                -column 1 -row 1
1685        grid [ checkbutton $expgui(diffBox).rfDC1 -variable entryvar(ttref) ] \
1686                -column 2 -row 1
1687        grid [button $expgui(diffBox).bDCdifc -text "Set 2Theta Globally" \
1688                -command "editglobalparm histinfo ratio {Fixed 2Theta}"] \
1689                -column 3 -row 1
1690        #
1691        grid [ label $expgui(diffBox).lDCpref -text "Refine POLA" ] \
1692                -column 1 -row 4 -sticky w
1693        grid [ checkbutton $expgui(diffBox).rfDCpref \
1694                -variable entryvar(pref) ] -column 2 -row 4
1695        grid [button $expgui(diffBox).bDCpola -text "Set POLA Globally" \
1696                -command "editglobalparm histinfo pola POLA"] -column 3 -row 4
1697        grid [button $expgui(diffBox).bDCipola -text "Set IPOLA Globally" \
1698                -command "editglobalparm histinfo ipola IPOLA"] -column 4 -row 4
1699    }
1700    if {$expgui(globalmode) == 0} {
1701        grid [frame $expgui(diffBox).d] -column 5 -row 5 \
1702                -columnspan 2 -sticky e
1703    } else {
1704        grid [frame $expgui(diffBox).d] -column 4 -row 5 \
1705                -columnspan 2 -sticky e
1706    }
1707    grid [label $expgui(diffBox).d.lDamp -text "Damping  "] \
1708            -column 1 -row 1
1709    tk_optionMenu $expgui(diffBox).d.om entryvar(ddamp) 0 1 2 3 4 5 6 7 8 9
1710    grid $expgui(diffBox).d.om -column 2 -row 1
1711    grid columnconfigure $expgui(diffBox) 9  -weight 1
1712    grid columnconfigure $expgui(diffBox) 0  -weight 1
1713    update idletasks
1714    # enable traces on entryvar now
1715    set entrycmd(trace) 1
1716}
1717
1718# this gets the phase flags as set in the expgui(pflag*) elements
1719# (linked to phase flag checkbuttons) and the sets the "HST xx NPHAS" flags
1720# accordingly using SetPhaseFlag
1721proc GetPhaseFlags {hist} {
1722    global expmap expgui
1723    set plist {}
1724    foreach p $expmap(phaselist) {
1725        if {$expgui(pflag$p)} {lappend plist $p}
1726    }
1727    SetPhaseFlag $hist $plist
1728    incr expgui(changed)
1729    mapexp
1730}
1731
1732#-----------------------------------------------------------------------
1733# populate the Scaling page
1734#-----------------------------------------------------------------------
1735proc DisplayFrac {} {
1736    global expgui entrycmd entryvar entrybox expmap
1737
1738    # trap if more than one histogram is selected unless global mode
1739    if {$expgui(globalmode) == 0 && [llength $expgui(curhist)] > 1} {
1740        set expgui(curhist) [lindex $expgui(curhist) 0]
1741    }
1742
1743    # display the selected histograms
1744    $expgui(fracFrame).hs.lbox selection clear 0 end
1745    foreach h $expgui(curhist) {
1746        $expgui(fracFrame).hs.lbox selection set $h
1747    }
1748
1749    # disable traces on entryvar
1750    set entrycmd(trace) 0
1751
1752    # get histogram list
1753    set histlist {}
1754    foreach item $expgui(curhist) {
1755        lappend histlist [lindex $expmap(powderlist) $item]
1756    }
1757
1758    # must have at least one histogram selected here
1759    if {[llength $histlist] == 0} {
1760        foreach var {scale sref sdamp} {
1761            set entrycmd($var) ""
1762            set entryvar($var) ""
1763        }
1764        set parm [grid info $expgui(scaleBox).but1]
1765        if {$parm != ""} {
1766            grid forget  $expgui(scaleBox).but1
1767            eval grid $expgui(scaleBox).ent1 $parm
1768        }
1769        # destroy the contents of the frame
1770        set phaseFractf1 $expgui(FracBox).f
1771        eval destroy [winfo children $phaseFractf1]
1772        # reenable traces on entryvar
1773        set entrycmd(trace) 1
1774        return
1775    }
1776
1777    #--------------
1778    # Scale factor
1779    #--------------
1780    if {$expgui(globalmode) != 0} {
1781        foreach var {scale sref sdamp} {
1782            set entrycmd($var) "histinfo [list $histlist] $var"
1783            set entryvar($var) [histinfo [lindex $histlist 0] $var]
1784        }
1785        # reset scale to black
1786        catch {$entrybox(scale) config -fg black}
1787        set parm [grid info $expgui(scaleBox).ent1]
1788        if {$parm != ""} {
1789            grid forget  $expgui(scaleBox).ent1
1790            eval grid $expgui(scaleBox).but1 $parm
1791        }
1792    } else {
1793        set hist $histlist
1794        foreach var {scale sref sdamp} {
1795            set entrycmd($var) "histinfo $hist $var"
1796            set entryvar($var) [eval $entrycmd($var)]
1797        }
1798        # reset scale to black
1799        catch {$entrybox(scale) config -fg black}
1800        set parm [grid info $expgui(scaleBox).but1]
1801        if {$parm != ""} {
1802            grid forget  $expgui(scaleBox).but1
1803            eval grid $expgui(scaleBox).ent1 $parm
1804        }
1805    }
1806
1807    #----------------
1808    # Phase Fractions
1809    #----------------
1810    set phaseFractf1 $expgui(FracBox).f
1811    # destroy the contents of the frame
1812    eval destroy [winfo children $phaseFractf1]
1813    if {$expgui(globalmode) != 0} {
1814        set txt "Phase Fractions for Histograms: [CompressList $histlist]"
1815    } else {
1816        set txt "Phase Fractions"
1817    }
1818    if $expgui(haveBW) {
1819        $expgui(fracFrame).f1.phaseFrac configure -text $txt
1820    } else {
1821        grid [label $phaseFractf1.txt -anchor center -text $txt] \
1822                -column 0 -row 0 -sticky news
1823    }
1824    # Create the frame inside the canvas, One frame for each Phase.
1825    foreach i {1 2 3 4 5 6 7 8 9} {set phasehistlist($i) ""}
1826    foreach hist $histlist {
1827        foreach i $expmap(phaselist_$hist) {
1828            lappend phasehistlist($i) $hist
1829        }
1830    }
1831    foreach i {1 2 3 4 5 6 7 8 9} {
1832        if {[llength $phasehistlist($i)] == 0} continue
1833        set framePF [frame $phaseFractf1.pF$i -relief groove  -bd 4]
1834        grid $framePF -column 0 -row $i -sticky ew
1835        # Label Heading for each phase.
1836        if {$expgui(globalmode) != 0} {
1837            grid [label $framePF.l1 \
1838                    -text "Phase $i Hist: [CompressList $phasehistlist($i)]"] \
1839                    -column 0 -row 0 -sticky nws
1840            grid [button $framePF.but1 -text "Set Globally" \
1841                    -command "editglobalparm hapinfo frac \"Phase $i Fraction\" \
1842                    [list $phasehistlist($i)] $i" \
1843                    ] -column 1 -row 0
1844        } else {
1845            grid [label $framePF.l1  -text "Phase $i"] \
1846                    -column 0 -row 0 -sticky nws
1847            grid [entry $framePF.ent -textvariable entryvar(frac$i) -width 15]\
1848                    -column 1 -row 0
1849            set entrybox(frac$i) $framePF.ent
1850        }
1851        set entrycmd(frac$i) "hapinfo $hist $i frac"
1852        set entryvar(frac$i) [hapinfo $hist $i frac]
1853        grid [label $framePF.l2  -text "  Refine"] \
1854                -column 2 -row 0 -sticky nws
1855        grid [checkbutton $framePF.cb -variable entryvar(frref$i)] \
1856                -column 3 -row 0 -sticky nws
1857        set entrycmd(frref$i) "hapinfo $hist $i frref"
1858        set entryvar(frref$i) [hapinfo $hist $i frref]
1859        grid [label $framePF.l3  -text "  Damping"] \
1860                -column 4 -row 0 -sticky nws
1861        tk_optionMenu $framePF.tkOptDamp entryvar(frdamp$i) \
1862                0 1 2 3 4 5 6 7 8 9     
1863        set entrycmd(frdamp$i) "hapinfo $hist $i frdamp"
1864        set entryvar(frdamp$i) [hapinfo $hist $i frdamp]
1865        grid $framePF.tkOptDamp -row 0 -sticky nsw -column 5
1866    }
1867    # resize the scroll window to match the actual
1868    update idletasks
1869    $expgui(FracBox) config -scrollregion [grid bbox $expgui(FracBox).f]
1870    $expgui(FracBox) config -width [lindex [grid bbox $expgui(FracBox).f] 2]
1871    update idletasks
1872    # enable traces on entryvar now
1873    set entrycmd(trace) 1
1874}
1875
1876#-----------------------------------------------------------------------
1877# display the profile page
1878#-----------------------------------------------------------------------
1879proc DisplayProfile {} {
1880    global expgui entrycmd entryvar entrybox expmap
1881
1882    # trap if more than one histogram is selected unless global mode
1883    if {$expgui(globalmode) == 0 && [llength $expgui(curhist)] > 1} {
1884        set expgui(curhist) [lindex $expgui(curhist) 0]
1885    }
1886    # display the selected histograms
1887    $expgui(profFrame).hs.lbox selection clear 0 end
1888    foreach h $expgui(curhist) {
1889        $expgui(profFrame).hs.lbox selection set $h
1890    }
1891
1892    # destroy the contents of the frame
1893    eval destroy [winfo children $expgui(ProfileBox).f]
1894    # since the next steps can take a while, do a screen update
1895    update idletasks
1896
1897    if {$expgui(globalmode) == 0} {
1898        # must have at least one histogram selected here
1899        if {[llength $expgui(curhist)] == 0} return
1900        # disable traces on entryvar for right now
1901        set entrycmd(trace) 0
1902        set hist [lindex $expmap(powderlist) $expgui(curhist)]
1903        # no defined histograms?
1904        if {$hist == ""} return
1905        # Create one frame for each Phase.
1906        set ind -1
1907        set htype [string range $expmap(htype_$hist) 2 2]
1908        foreach i $expmap(phaselist_$hist) {
1909            incr ind
1910            # Label Heading for each phase.
1911            set ptype [string trim [hapinfo $hist $i proftype]]
1912            if {$expgui(haveBW)} {
1913                grid [TitleFrame $expgui(ProfileBox).f.$i \
1914                        -text "Hist $hist -- Phase $i (type $ptype)" \
1915                        -relief groove -bd 2] \
1916                        -column 0 -row $ind -sticky ew
1917                set ProfileFrame [$expgui(ProfileBox).f.$i getframe]
1918                grid [frame $ProfileFrame.1] \
1919                        -column 0 -row 0 -columnspan 10
1920                pack [label $ProfileFrame.1.l  \
1921                        -text Damping]\
1922                        -side left
1923            } else {
1924                grid [frame $expgui(ProfileBox).f.$i -relief groove -bd 4] \
1925                        -column 0 -row $ind -sticky ew
1926                set ProfileFrame $expgui(ProfileBox).f.$i
1927                grid [frame $ProfileFrame.1] \
1928                        -column 0 -row 0 -columnspan 10 -sticky ew
1929                pack [label $ProfileFrame.1.l  \
1930                        -text "Phase $i (type $ptype)    Damping"]\
1931                        -side left
1932            }
1933            tk_optionMenu $ProfileFrame.1.tkOptDamp entryvar(pdamp_$i) \
1934                    0 1 2 3 4 5 6 7 8 9
1935            set entrycmd(pdamp_$i) "hapinfo $hist $i pdamp"
1936            set entryvar(pdamp_$i) [hapinfo $hist $i pdamp]
1937            pack $ProfileFrame.1.tkOptDamp -side left
1938            pack [label $ProfileFrame.1.l1 \
1939                    -text "  Peak cutoff"]\
1940                    -side left
1941            pack [entry $ProfileFrame.1.e1  \
1942                    -width 10 -textvariable entryvar(pcut_$i)]\
1943                    -side left
1944            set entrybox(pcut_$i) $ProfileFrame.1.e1
1945            set entrycmd(pcut_$i) "hapinfo $hist $i pcut"
1946            set entryvar(pcut_$i) [hapinfo $hist $i pcut]
1947
1948            pack [button $ProfileFrame.1.b1  \
1949                    -text "Change Type" \
1950                    -command "ChangeProfileType $hist $i"]\
1951                    -side left
1952           
1953            set col -1
1954            set row 1
1955            set nterms [hapinfo $hist $i profterms]
1956            set lbls "dummy [GetProfileTerms $i $hist $ptype]"
1957            for { set num 1 } { $num <= $nterms } { incr num } {
1958                set term {}
1959                catch {set term [lindex $lbls $num]}
1960                if {$term == ""} {set term $num}
1961                incr col
1962                grid [label $ProfileFrame.l${num}_${i} -text "$term"] \
1963                        -row $row -column $col
1964                incr col
1965                grid [checkbutton $ProfileFrame.ref${num}_${i} \
1966                        -variable entryvar(pref${num}_$i)] -row $row -column $col
1967                set entrycmd(pref${num}_$i) "hapinfo $hist $i pref$num"
1968                set entryvar(pref${num}_$i) [hapinfo $hist $i pref$num]
1969                incr col
1970                grid [entry $ProfileFrame.ent${num}_${i} \
1971                        -textvariable entryvar(pterm${num}_$i)\
1972                        -width 12] -row $row -column $col
1973                set entrybox(pterm${num}_$i) $ProfileFrame.ent${num}_${i}
1974                set entrycmd(pterm${num}_$i) "hapinfo $hist $i pterm$num"
1975                set entryvar(pterm${num}_$i) [hapinfo $hist $i pterm$num]
1976                if {$col > 6} {set col -1; incr row}
1977            }
1978        }
1979        grid columnconfigure $expgui(ProfileBox).f 0 -weight 1
1980    } else {
1981        # get histogram list
1982        set histlist {}
1983        foreach item $expgui(curhist) {
1984            lappend histlist [lindex $expmap(powderlist) $item]
1985        }
1986        # must have at least one histogram selected here
1987        if {[llength $histlist] == 0} return
1988        # disable traces on entryvar for right now
1989        set entrycmd(trace) 0
1990        # loop through histograms & phases, set up an array by phase & profile type
1991        catch {unset prtyparray histarray phasearray}
1992        foreach hist $histlist {
1993            foreach phase $expmap(phaselist_$hist) {
1994                set prtyp [string trim [hapinfo $hist $phase proftype]]
1995                set key ${prtyp}_$phase
1996                lappend prtyparray($key) $hist
1997                lappend histarray($key) $hist
1998                lappend phasearray($key) $phase
1999            }
2000        }
2001       
2002        set ptype ""
2003        set i -1
2004        # loop over all combined phases and profile types, sorted 1st by profile number
2005        foreach key [lsort [array names prtyparray]] {
2006            # split key
2007            scan $key %d_%d prftyp p
2008
2009            if {$ptype != $prftyp || !$expgui(globalphasemode)} {
2010                set ptype $prftyp
2011                set curhistlist $histarray($key)
2012                set curphaslist $phasearray($key)
2013               
2014                set hist1 [lindex $curhistlist 0]
2015                set phase1 [lindex $curphaslist 0]
2016                set nterms [hapinfo $hist1 $phase1 profterms]
2017                set htype [string range $expmap(htype_$hist1) 2 2]
2018                set lbls "dummy [GetProfileTerms $phase1 $hist1 $ptype]"
2019                # Create a frame for this type
2020                incr i
2021                set boxtitle "Phase $p, hist [CompressList $histarray($key)]"
2022                if {$expgui(haveBW)} {
2023                    grid [TitleFrame $expgui(ProfileBox).f.$i \
2024                            -text "(type $ptype)" \
2025                            -relief groove -bd 2] \
2026                            -column 0 -row $i -sticky ew
2027                    set ProfileFrame [$expgui(ProfileBox).f.$i getframe]
2028                    grid [frame $ProfileFrame.0] \
2029                            -column 0 -row 0 -columnspan 20 -sticky ew
2030                } else {
2031                    grid [frame $expgui(ProfileBox).f.$i \
2032                            -relief groove -bd 4] \
2033                            -column 0 -row $i -sticky ew
2034                    set ProfileFrame $expgui(ProfileBox).f.$i
2035                    grid [frame $ProfileFrame.0] \
2036                            -column 0 -row 0 -columnspan 20 -sticky ew
2037                    grid [label $ProfileFrame.0.0  \
2038                            -text "Profile Type $ptype   "] -row 0 -column 0
2039                }
2040                grid [label $ProfileFrame.0.1  \
2041                        -anchor w] -row 0 -column 1
2042                grid [frame $ProfileFrame.1] \
2043                        -column 0 -row 1 -columnspan 20 -sticky ew
2044                grid [label $ProfileFrame.1.2  \
2045                        -text "Damping"] -row 0 -column 2
2046                tk_optionMenu $ProfileFrame.1.tkOptDamp \
2047                        entryvar(pdamp_$i) 0 1 2 3 4 5 6 7 8 9
2048                grid $ProfileFrame.1.tkOptDamp -row 0 -column 3
2049                grid [button $ProfileFrame.1.edit \
2050                        -text "Global Edit"] -row 0 -column 4 -sticky w
2051                set entryvar(pdamp_$i) [hapinfo $hist $phase pdamp]
2052                grid [button $ProfileFrame.1.b1 -text "Change Type"] \
2053                        -row 0 -column 5 -sticky w
2054                set col -1
2055                set row 2
2056                for { set num 1 } { $num <= $nterms } { incr num } {
2057                    set term {}
2058                    catch {set term [lindex $lbls $num]}
2059                    if {$term == ""} {set term $num}
2060                    incr col
2061                    grid [label $ProfileFrame.l${num}_${i} \
2062                            -text "$term"] -row $row -column $col
2063                    incr col
2064                    grid [checkbutton $ProfileFrame.ref${num}_${i} \
2065                            -variable entryvar(pref${num}_$i)] \
2066                            -row $row -column $col
2067                    set entryvar(pref${num}_$i) [hapinfo $hist $phase pref$num]
2068                    if {$col > 10} {set col -1; incr row}
2069                }
2070                grid columnconfigure $expgui(ProfileBox).f 0 -weight 1
2071            } else {
2072                # add to the current entry
2073                eval lappend curhistlist $histarray($key)
2074                eval lappend curphaslist $phasearray($key)
2075                append boxtitle "\nPhase $p, hist [CompressList $histarray($key)]"
2076            }
2077            $ProfileFrame.0.1 config -text $boxtitle
2078            $ProfileFrame.1.edit config -command "\
2079                    EditProfile \"\n$boxtitle\" \
2080                    [list $curhistlist] \
2081                    [list $curphaslist]"
2082            $ProfileFrame.1.b1 config -command "ChangeProfileType \
2083                    [list $curhistlist] [list $curphaslist]"
2084            set entrycmd(pdamp_$i) "hapinfo \
2085                    [list $curhistlist] \
2086                    [list $curphaslist] pdamp"
2087            for { set num 1 } { $num <= $nterms } { incr num } {
2088                set entrycmd(pref${num}_$i) "hapinfo \
2089                        [list $curhistlist] \
2090                        [list $curphaslist] pref$num"
2091            }
2092        }
2093    }
2094   
2095    # resize the scroll window to match the actual
2096    update idletasks
2097    $expgui(ProfileBox) config -scrollregion [grid bbox $expgui(ProfileBox).f]
2098    $expgui(ProfileBox) config -width [lindex [grid bbox $expgui(ProfileBox).f] 2]
2099    update idletasks
2100    ResizeNotebook
2101    # enable traces on entryvar now
2102    set entrycmd(trace) 1
2103}
2104
2105# process the bit settings in the print options
2106#   bitnum -- the number of the bit to be tested/set starting at 0 for the LSBit
2107proc printsetting {bitnum "action get" "value {}"} {
2108    global entryvar expgui
2109    if {$action == "get"} {
2110        return [expr ([expinfo print] & int(pow(2,$bitnum))) != 0]
2111    } elseif $value {
2112        set newval [expr ([expinfo print] | int(pow(2,$bitnum)))]
2113    } else {
2114        set newval [expr ([expinfo print] & ~int(pow(2,$bitnum)))]
2115    }
2116    expinfo print set $newval
2117    set expgui(printopt) "Print Options ([expinfo print])"
2118}
2119
2120# need to respond to mouse presses -- control variable associated with extract Fobs
2121# and set the LeBail extraction flags
2122proc SetupExtractHist {} {
2123    global expgui entrycmd entryvar expmap
2124
2125    # display the selected histograms
2126    $expgui(lsFrame).hs.lbox selection clear 0 end
2127    foreach h $expgui(curhist) {
2128        $expgui(lsFrame).hs.lbox selection set $h
2129    }
2130
2131    # get histogram list
2132    set histlist {}
2133    foreach item $expgui(curhist) {
2134        set hist [lindex $expmap(powderlist) $item]
2135        if {$hist != ""} {lappend histlist $hist}
2136    }
2137    set entrycmd(fobsextract) "histinfo [list $histlist] foextract"
2138    if {[llength $histlist] == 0 || [string trim $histlist] == ""} {
2139        foreach phase {1 2 3 4 5 6 7 8 9} {
2140            $expgui(FobsExtractFrame).l$phase config -fg grey
2141            set expgui(Fextract$phase) {}
2142            foreach item $expgui(ExtractSettingsRadiobuttons) {
2143                ${item}$phase config -state disabled -bd 1
2144            }
2145        }
2146    } elseif {[llength $histlist] == 1} {
2147        # disable traces on entryvar
2148        set entrycmd(trace) 0
2149        set entryvar(fobsextract) [histinfo $histlist foextract]
2150        foreach phase {1 2 3 4 5 6 7 8 9} {
2151            # is the phase present?
2152            if {[lsearch -exact $expmap(phaselist_$histlist) $phase] == -1} {
2153                $expgui(FobsExtractFrame).l$phase config -fg grey
2154                set expgui(Fextract$phase) {}
2155                foreach item $expgui(ExtractSettingsRadiobuttons) {
2156                    ${item}$phase config -state disabled -bd 1
2157                }
2158            } else {
2159                $expgui(FobsExtractFrame).l$phase config -fg black
2160                foreach item $expgui(ExtractSettingsRadiobuttons) {
2161                    ${item}$phase config -state normal -bd 2
2162                }
2163                set expgui(Fextract$phase) [hapinfo $histlist $phase extmeth]
2164            }
2165        }
2166    } elseif {[llength $histlist] > 1} {
2167        # disable traces on entryvar
2168        set entrycmd(trace) 0
2169        # multiple histograms need phases in any histogram
2170        foreach phase {1 2 3 4 5 6 7 8 9} {
2171            set gotphase($phase) 0
2172        }           
2173        foreach hist $histlist {
2174            foreach phase $expmap(phaselist_$hist) {
2175                set gotphase($phase) 1
2176            }
2177        }
2178        foreach phase {1 2 3 4 5 6 7 8 9} {
2179            set expgui(Fextract$phase) {}
2180            if $gotphase($phase) {
2181                $expgui(FobsExtractFrame).l$phase config -fg black
2182                foreach item $expgui(ExtractSettingsRadiobuttons) {
2183                    ${item}$phase config -state normal -bd 2
2184                }
2185            } else {
2186                $expgui(FobsExtractFrame).l$phase config -fg grey
2187                foreach item $expgui(ExtractSettingsRadiobuttons) {
2188                    ${item}$phase config -state disabled -bd 1
2189                }
2190            }
2191        }
2192    }
2193    # reenable traces
2194    set entrycmd(trace) 1
2195}
2196# respond to a change in the fobs extraction method for a phase
2197# force the main extraction flag on, if fobs extraction is selected for any phase
2198proc HistExtractSet {phase} {
2199    global expgui entryvar expmap
2200    foreach item $expgui(curhist) {
2201        lappend histlist [lindex $expmap(powderlist) $item]
2202    }
2203    hapinfo $histlist $phase extmeth set $expgui(Fextract$phase)
2204    incr expgui(changed)
2205    if {$expgui(Fextract$phase) != 0} {set entryvar(fobsextract) 1}
2206}
2207#---------------------------- Global Edit Functions ------------------------
2208proc editbackground {} {
2209    global expgui expmap entrycmd
2210    set histlist {}
2211    foreach n $expgui(curhist) {
2212        lappend histlist [lindex $expmap(powderlist) $n]
2213    }
2214    if {[llength $histlist] == 0} return
2215
2216    set w .back
2217    catch {destroy $w}
2218    toplevel $w -bg beige
2219    if {$expgui(globalmode) != 0} {
2220        wm title $w "Global Edit Background"
2221    } else {
2222        wm title $w "Edit Background"
2223    }
2224   
2225    pack [frame $w.0 -bd 6 -relief groove  -bg beige \
2226            ] -side top -expand yes -fill both
2227    if {[llength $histlist] > 1} {
2228        grid [label $w.0.a \
2229            -text "Setting background terms for histograms [CompressList $histlist]" \
2230            -bg beige] -row 0 -column 0 -columnspan 10
2231    } else {
2232        grid [label $w.0.a \
2233            -text "Setting background terms for histogram $histlist" \
2234            -bg beige] -row 0 -column 0 -columnspan 10
2235    }
2236    set hist [lindex $histlist 0]
2237    grid [label $w.0.b -text "Function type"  -bg beige]  -row 1 -column 0
2238
2239    # disable traces on  expgui(backtype) & expgui(backterms) now
2240    set entrycmd(trace) 0
2241
2242    # number of terms
2243    set expgui(backtype) [histinfo $hist backtype]
2244    set expgui(orig_backtype) $expgui(backtype)
2245    set expgui(prev_backtype) $expgui(backtype)
2246    set typemenu [tk_optionMenu $w.0.type expgui(backtype) null]
2247    $typemenu delete 0 end
2248    foreach item {
2249        "1 - Shifted Chebyshev"
2250        "2 - Cosine Fourier series"
2251        "3 - Radial distribution peaks"
2252        "4 - Power series in Q**2n/n!"
2253        "5 - Power series in n!/Q**2n"
2254        "6 - Power series in Q**2n/n! and n!/Q**2n"
2255        "7 - Linear interpolation function"
2256        "8 - Reciprocal interpolation function"
2257    } {
2258        set val [lindex $item 0]
2259        $typemenu insert end radiobutton -variable expgui(backtype) \
2260                -label $item -value $val
2261    }
2262
2263    grid $w.0.type   -row 1 -column 1
2264    grid [label $w.0.c -text "  Number of terms"  -bg beige] -row 1 -column 2
2265
2266    # function type
2267    set expgui(backterms) [histinfo $hist backterms]
2268    set expgui(orig_backterms) $expgui(backterms)
2269    set list {}; for {set i 1} {$i <= 36} {incr i} {lappend list $i}
2270    eval tk_optionMenu $w.0.terms expgui(backterms) $list
2271    grid $w.0.terms   -row 1 -column 3
2272    # enable traces on  expgui(backtype) & expgui(backterms) now
2273    set entrycmd(trace) 1
2274
2275    #set background terms
2276    for {set num 1 } { $num <= 36 } { incr num } {
2277        set var "bterm$num"
2278        set expgui($var) {}
2279        set expgui(orig_$var) {}
2280    }
2281    if {[llength $histlist] == 1} {
2282        for {set num 1 } { $num <= $expgui(backterms) } { incr num } {
2283            set var "bterm$num"
2284            set expgui($var) [histinfo $histlist $var]
2285            set expgui(orig_$var) $expgui($var)
2286        }
2287    }
2288
2289    pack [frame $w.1 -bd 6 -relief groove  -bg beige] -side top \
2290            -expand yes -fill both
2291    ShowBackTerms $w.1
2292
2293    set expgui(temp) {}
2294    pack [frame $w.b -bg beige] -fill x -expand yes -side top
2295    grid [button $w.b.2 -text Set -command "destroy $w"] -row 0 -column 1
2296    grid [button $w.b.3 -text Quit \
2297            -command "QuitEditBackground $w"] -row 0 -column 2
2298    grid [button $w.b.help -text Help -bg yellow \
2299            -command "MakeWWWHelp expgui3.html EditBackground"] \
2300            -row 0 -column 4
2301    grid columnconfig $w.b 0 -weight 1
2302    grid columnconfig $w.b 3 -weight 1
2303    bind $w <Key-F1> "MakeWWWHelp expgui3.html EditBackground"
2304    bind $w <Return> "destroy $w"
2305
2306    # force the window to stay on top
2307    putontop $w
2308
2309    focus $w.b.2
2310    tkwait window $w
2311    afterputontop
2312
2313    if {$expgui(temp) != ""} return
2314
2315    if {$expgui(orig_backtype) != $expgui(backtype)} {
2316        histinfo $histlist backtype set $expgui(backtype)
2317        incr expgui(changed)
2318    }
2319    if {$expgui(orig_backterms) != $expgui(backterms)} {
2320        histinfo $histlist backterms set $expgui(backterms)
2321        incr expgui(changed)
2322    }
2323    for {set num 1 } { $num <= $expgui(backterms) } { incr num } {
2324        set var "bterm$num"
2325        if {$expgui(orig_$var) != $expgui($var)} {
2326            histinfo $histlist $var set $expgui($var)
2327            incr expgui(changed)
2328        }
2329    }
2330
2331    if {$expgui(globalmode) == 0} {
2332        set expgui(backtypelbl) "Function type [histinfo $hist backtype]"
2333        set expgui(backtermlbl) "([histinfo $hist backterms] terms)"
2334    }
2335}
2336
2337trace variable expgui(backterms) w ChangeBackTerms
2338proc ChangeBackTerms {a b c} {
2339    global entrycmd expgui
2340    if !$entrycmd(trace) return
2341    ShowBackTerms .back.1
2342}
2343
2344trace variable expgui(backtype) w ChangeBackType
2345# reset the terms to 1, 0, 0... when the number of terms increase
2346proc ChangeBackType {a b c} {
2347    global entrycmd expgui
2348    if !$entrycmd(trace) return
2349    if {$expgui(prev_backtype) == $expgui(backtype)} return
2350    set expgui(prev_backtype) $expgui(backtype)
2351    for {set num 1 } { $num <= $expgui(backterms) } { incr num } {
2352        set var "bterm$num"
2353        if {$num == 1} {
2354            set expgui($var) 1.0
2355        } else {
2356            set expgui($var) 0.0
2357        }
2358    }
2359}
2360
2361proc ShowBackTerms {w } {
2362    global expgui expmap
2363    # destroy the contents of the frame
2364    eval destroy [winfo children $w]
2365    set histlist {}
2366    foreach n $expgui(curhist) {
2367        lappend histlist [lindex $expmap(powderlist) $n]
2368    }
2369    set widgetsPerRow 4
2370    for {set rows 2; set num 1 } { $num <= $expgui(backterms) } { incr rows } {
2371        for {set cols 0} { (2*$widgetsPerRow > $cols) && ($num <= $expgui(backterms)) }  { incr num }  {
2372            set var "bterm$num"
2373            grid [label $w.l$num -text $num -bg beige]  \
2374                    -row $rows -column $cols -sticky nes
2375            incr cols
2376            grid [entry $w.e$num -width 15 -textvariable expgui($var) \
2377                    ] -row $rows  -column $cols  -sticky news
2378            incr cols
2379        }
2380    }
2381}
2382
2383proc QuitEditBackground {w} {
2384    global expgui
2385    # lets find out if anything changed
2386    set changed 0
2387    if {$expgui(orig_backtype) != $expgui(backtype)} {
2388        set changed 1
2389    }
2390    if {$expgui(orig_backterms) != $expgui(backterms)} {
2391        set changed 1
2392    }
2393    for {set num 1 } { $num <= $expgui(backterms) } { incr num } {
2394        set var "bterm$num"
2395        if {$expgui(orig_$var) != $expgui($var)} {
2396            set changed 1
2397            break
2398        }
2399    }
2400    if $changed {
2401        set decision [tk_dialog .changes "Abandon Changes" \
2402                "You have made changes to the background. Ok to abandon changes?" \
2403                warning 0 Abandon Keep]
2404        if !$decision {
2405            set expgui(temp) "Quit"
2406            destroy $w
2407        }
2408    } else {
2409        set expgui(temp) "Quit"
2410        destroy $w
2411    }
2412}
2413
2414# this probably needs work
2415proc editglobalparm {cmd variable title "histlist {}" "phase {}"} {
2416    global expgui expmap
2417    set w .global
2418    catch {destroy $w}
2419    toplevel $w -bg beige
2420    wm title $w "Edit Global Parameter"
2421    set expgui(temp) {}
2422    if {[llength $histlist] == 0} {
2423        set hist {}
2424        foreach n $expgui(curhist) {
2425            lappend hist [lindex $expmap(powderlist) $n]
2426        }
2427    } else {
2428        set hist $histlist
2429    }
2430    pack [frame $w.0 -bd 6 -relief groove -bg beige] \
2431            -side top -expand yes -fill both
2432    grid [label $w.0.a -text "Setting $title for histograms [CompressList $hist]"\
2433            -bg beige] \
2434            -row 0 -column 0 -columnspan 10
2435    grid [entry $w.0.b -textvariable expgui(temp)] \
2436            -row 1 -column 0
2437
2438
2439    pack [frame $w.b -bg beige] -fill x -expand yes -side top
2440    pack [button $w.b.2 -text Set -command "destroy $w"] -side left
2441    pack [button $w.b.3 -text Quit -command "set expgui(temp) {}; destroy $w"] -side left
2442    pack [button $w.b.help -text Help -bg yellow \
2443            -command "MakeWWWHelp expgui3.html EditParm"] -side right
2444    bind $w <Key-F1> "MakeWWWHelp expgui3.html EditParm"
2445    bind $w <Return> "destroy $w"
2446
2447    # force the window to stay on top
2448    putontop $w
2449    focus $w.b.2
2450    tkwait window $w
2451    afterputontop
2452
2453    if {$expgui(temp) != ""} {
2454        foreach h $hist {
2455            if {$cmd == "histinfo"} {
2456                histinfo $h $variable set $expgui(temp)
2457                incr expgui(changed)
2458                if $expgui(debug) {
2459                    puts "histinfo $h $variable set $expgui(temp)"
2460                }
2461            } elseif {$cmd == "hapinfo"} {
2462                hapinfo $h $phase $variable set $expgui(temp)
2463                incr expgui(changed)
2464                if $expgui(debug) {
2465                    puts "hapinfo $phase $h $variable set $expgui(temp)"
2466                }
2467            } else {
2468                error "$cmd unimplemented"
2469            }
2470        }
2471    }
2472}
2473
2474proc EditProfile {title histlist phaselist} {
2475    global expgui expmap entrycmd
2476    set w .back
2477    catch {destroy $w}
2478    toplevel $w -bg beige
2479    wm title $w "Global Edit Profile"
2480    set hist [lindex $histlist 0]
2481    set phase [lindex $phaselist 0]
2482    set ptype [string trim [hapinfo $hist $phase proftype]]
2483    set htype [string range $expmap(htype_$hist) 2 2]
2484    set nterms [hapinfo $hist $phase profterms]
2485   
2486    pack [frame $w.0 -bd 6 -relief groove  -bg beige \
2487            ] -side top -expand yes -fill both
2488    grid [label $w.0.a \
2489            -text "Setting profile terms: $title" \
2490            -bg beige] -row 0 -column 0 -columnspan 10
2491    grid [label $w.0.b -text "Function type $ptype"  -bg beige]  -row 1 -column 0
2492    grid [label $w.0.c -text "  Peak cutoff" -bg beige] -row 1 -column 3
2493    grid [entry $w.0.d -width 10 ]  -row 1 -column 4
2494    set entrylist {}
2495    lappend entrylist "pcut $w.0.d"
2496
2497    set col -1
2498    set row 1
2499    set lbls "dummy [GetProfileTerms $phase $hist $ptype]"
2500    pack [frame $w.1 -bd 6 -relief groove  -bg beige \
2501            ] -side top -expand yes -fill both
2502    for { set num 1 } { $num <= $nterms } { incr num } {
2503        set term {}
2504        catch {set term [lindex $lbls $num]}
2505        if {$term == ""} {set term $num}
2506        incr col
2507        grid [label $w.1.l${num} -text "$term" -bg beige] \
2508                -row $row -column $col
2509        incr col
2510        grid [entry $w.1.ent${num} \
2511                -width 14] -row $row -column $col
2512        lappend entrylist "pterm$num $w.1.ent${num}"   
2513        if {$col > 6} {set col -1; incr row}
2514    }
2515    pack [frame $w.b -bg beige] -fill x -expand yes -side top
2516    grid [button $w.b.2 -text Set \
2517            -command "SetEditProfile [list $entrylist] [list $phaselist] \
2518            [list $histlist] $w"] -row 0 -column 1
2519    grid [button $w.b.3 -text Quit \
2520            -command "QuitEditProfile $w [list $entrylist]"] -row 0 -column 2
2521    grid [button $w.b.help -text Help -bg yellow \
2522            -command "MakeWWWHelp expgui5.html GlobalEdit"] \
2523            -row 0 -column 4
2524    grid columnconfig $w.b 0 -weight 1
2525    grid columnconfig $w.b 3 -weight 1
2526    bind $w <Key-F1> "MakeWWWHelp expgui5.html GlobalEdit"
2527    bind $w <Return> "QuitEditProfile $w [list $entrylist]"
2528
2529    # force the window to stay on top
2530    putontop $w
2531    focus $w.b.2
2532    tkwait window $w
2533    afterputontop
2534}
2535
2536proc SetEditProfile {entrylist phaselist histlist w} {
2537    global expgui
2538    foreach item $entrylist {
2539        set value [ [lindex $item 1] get ]
2540        if {$value != ""} {
2541            hapinfo $histlist $phaselist [lindex $item 0] set $value
2542            incr expgui(changed)
2543            if $expgui(debug) {
2544                puts "hapinfo [list $phaselist] [list $histlist] [lindex $item 0] set $value"
2545            }
2546        }
2547    }
2548    destroy $w
2549}
2550
2551proc QuitEditProfile {w entrylist} {
2552    global expgui
2553    # lets find out if anything changed
2554    set changed 0
2555    foreach item $entrylist {
2556        if {[ [lindex $item 1] get ] != ""} {set changed 1; break}
2557    }
2558    if $changed {
2559        set decision [tk_dialog .changes "Abandon Changes" \
2560                "You have made changes to the Profile. Ok to abandon changes?" \
2561                warning 0 Abandon Keep]
2562        if !$decision {destroy $w}
2563    } else {
2564        destroy $w
2565    }
2566}
2567
2568##############################################################################
2569##                               #############################################
2570## END OF THE PROCEDURES SECTION #############################################
2571##                               #############################################
2572##############################################################################
2573
2574# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2575# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<                          <<<<<<<<<<<<<<<<<<<
2576# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<   BEGIN:  GUI SECTION    >>>>>>>>>>>>>>>>>>>
2577# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                          >>>>>>>>>>>>>>>>>>>
2578# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2579# A frame for menu items at top of display
2580set expgui(fm) [frame .fm -relief raised -borderwidth 2 -width 150 -height 40]
2581# Pack the menu frame.
2582pack $expgui(fm) -fill x -side top -anchor n
2583
2584# create a button bar
2585pack [frame .bar -relief raised -bd 2 -bg beige] -fill x -side top -anchor n
2586
2587# Creating the notebook and panes
2588
2589# create an array element describing each notebook page (used with BW only)
2590# element 0 -- pane name
2591#         1 -- Label on frame
2592#         2 -- initialization command
2593#         3 -- update command
2594#         4 -- 0/1 Use 1 if pane should be disabled in when all histograms
2595#                are selected in global mode, 0 otherwise
2596#         5 -- Web page for pane
2597#         6 -- name anchor on Web page for pane
2598set expgui(notebookpagelist) {
2599    {lsFrame     "LS Controls" \
2600            "" \
2601            SetupExtractHist \
2602            0  expgui1.html ""}
2603    {phaseFrame   Phase        \
2604            "" \
2605            "SelectOnePhase \$expgui(curPhase); DisplayAllAtoms noreset" \
2606            0  expgui2.html ""}
2607    {histFrame    Histogram \
2608            MakeHistPane \
2609            DisplayHistogram \
2610            1  expgui3.html ""}
2611    {fracFrame    Scaling \
2612            MakeScalingPane \
2613            DisplayFrac \
2614            0  expgui4.html ""}
2615    {profFrame    Profile \
2616            MakeProfilePane \
2617            DisplayProfile \
2618            1  expgui5.html ""}
2619    {consFrame    Constraints \
2620            "source [file join $expgui(scriptdir) atomcons.tcl]; MakeConstraintsPane" \
2621            DisplayConstraintsPane \
2622            0  expgui6.html ""}
2623    {orientFrame  "MD Pref Orient" \
2624            MakeOrientPane \
2625            DisplayOrient \
2626            0  expgui7.html MD}
2627    {odfFrame  "SH Pref Orient" \
2628            "source [file join $expgui(scriptdir) odf.tcl]; MakeODFPane" \
2629            DisplayODFPane \
2630            0  expgui7.html ODF}
2631}
2632
2633if $expgui(haveBW) {
2634    pack [NoteBook .n -bd 2] -expand yes -fill both
2635    foreach item $expgui(notebookpagelist) {
2636        set frm [lindex $item 0]
2637        set expgui($frm) [\
2638            .n insert end $frm -text [lindex $item 1] \
2639            -createcmd [lindex $item 2] \
2640            -raisecmd "set expgui(pagenow) $frm; [lindex $item 3]"]
2641
2642        # at this time expgui(frameactionlist) is generated
2643        # from expgui(notebookpagelist), but in the future it might
2644        # make sense to use expgui(notebookpagelist) directly
2645        lappend expgui(frameactionlist) "$frm [list [lindex $item 3]]"
2646
2647        # panes to disable in global "all" mode
2648        if {[lindex $item 4]} {
2649            lappend expgui(GlobalModeAllDisable) \
2650                    "$frm \{.n itemconfigure $frm\}"
2651        }
2652    }
2653} else {
2654    Notebook:create .n \
2655            -pages {lsFrame phaseFrame histFrame fracFrame profFrame}
2656    pack .n -anchor w -fill both -expand yes
2657    foreach item {lsFrame phaseFrame histFrame fracFrame profFrame \
2658            orientFrame} \
2659            page {"LS Controls" Phase Histogram Scaling Profile \
2660            "MD Pref Orient"} {
2661        set expgui($item) [Notebook:frame .n $item]
2662        Notebook:pageconfig .n $item -command "InitPage $item" -title $page
2663    }
2664    lappend expgui(frameactionlist) "lsFrame SetupExtractHist"
2665    lappend expgui(frameactionlist) "phaseFrame {DisplayAllAtoms noreset}"
2666    lappend expgui(frameactionlist) "histFrame DisplayHistogram"
2667    lappend expgui(frameactionlist) "fracFrame DisplayFrac"
2668    lappend expgui(frameactionlist) "profFrame DisplayProfile"
2669    lappend expgui(frameactionlist) "orientFrame DisplayOrient"
2670    set expgui(GlobalModeAllDisable) {}
2671    lappend expgui(GlobalModeAllDisable) "histFrame {Notebook:pageconfig .n histFrame}"
2672    lappend expgui(GlobalModeAllDisable) "profFrame {Notebook:pageconfig .n profFrame}"
2673}
2674
2675# this is used to bring up the selected frame
2676proc RaisePage {nextpage} {
2677    global expgui
2678    if $expgui(haveBW) {
2679        .n see $nextpage
2680        .n raise $nextpage
2681        set expgui(pagenow) $nextpage
2682    } else {
2683        Notebook:raise .n $nextpage
2684        InitPage $nextpage
2685    }
2686}
2687# this is only called when BWidget is not in use
2688proc InitPage {nextpage} {
2689    global expgui
2690    set expgui(pagenow) $nextpage
2691    UpdateCurrentPage
2692}
2693# resize the notebook to fit all the tabs and the largest page
2694proc ResizeNotebook {} {
2695    global expgui
2696    if {$expgui(haveBW)} {
2697        .n compute_size
2698    } else {
2699        Notebook:resize .n
2700    }
2701}
2702
2703#----------------------------------------------------------------------------
2704proc MakePhasePane {} {
2705    #\/ \/ \/ \/ \/ \/ \/ BEGINNING OF PHASE PANE CODE \/ \/ \/ \/ \/ \/ \/
2706    global expgui entryvar entrybox entrycmd
2707    frame $expgui(phaseFrame).top
2708    set frameLatt [frame $expgui(phaseFrame).frameLatt]
2709    #  This is a big frame in the Phase notebook pane to hold atomic data.
2710    set fbig [frame $expgui(phaseFrame).fbig -width 180 \
2711            -relief raised -borderwidth 4]
2712    #  This is a frame just below the big frame: for edits
2713    set frame3 [frame $expgui(phaseFrame).frame3 -width 100 \
2714            -relief raised -borderwidth 4 -bg $expgui(bkgcolor1)]
2715
2716    grid $expgui(phaseFrame).top -sticky news -row 0 -column 0
2717    grid $frameLatt -sticky news -row 2 -column 0
2718    grid $fbig -sticky news -row 3 -column 0
2719    # give extra space to the atoms box
2720    grid columnconfigure $expgui(phaseFrame) 0 -weight 1
2721    grid rowconfigure $expgui(phaseFrame) 3 -weight 1
2722    grid $frame3 -sticky news -row 4 -column 0
2723    grid columnconfigure $expgui(phaseFrame) 0 -weight 1
2724    grid rowconfigure $expgui(phaseFrame) 3 -weight 1
2725    grid [frame  $expgui(phaseFrame).top.ps] -column 0 -row 0 -sticky w
2726    # this is where the buttons will go
2727    pack [label $expgui(phaseFrame).top.ps.0 -text "No Phases"] -side left
2728   
2729    grid [label $expgui(phaseFrame).top.lA -text title: \
2730            -fg blue ] -column 1 -row 0 -sticky e
2731    grid [entry $expgui(phaseFrame).top.lB -textvariable entryvar(phasename) \
2732            -fg blue -width 45] -column 2 -row 0 -sticky e
2733    grid columnconfigure $expgui(phaseFrame).top 1 -weight 1
2734    # ------------- Lattice Parameter Box ------------------
2735    set row 0
2736    foreach col {2 4 6} var {a b c} lbl {a b c} {
2737        grid [label $frameLatt.l$var -text $lbl] \
2738                -column $col -row $row -padx 5 -sticky e
2739        incr col
2740        grid [entry $frameLatt.e$var -textvariable entryvar($var) -width 10] \
2741            -column $col -row $row -padx 5
2742        set entrybox($var) $frameLatt.e$var
2743    }
2744    incr row
2745    foreach col {2 4 6} var {alpha beta gamma} lbl {a b g} {
2746        grid [label $frameLatt.l$var -text $lbl -font symbol] \
2747                -column $col -row $row -padx 5 -sticky e
2748        incr col
2749        grid [entry $frameLatt.e$var -textvariable entryvar($var) -width 10] \
2750            -column $col -row $row -padx 5
2751        set entrybox($var) $frameLatt.e$var
2752    }
2753   
2754    grid [label $frameLatt.lr -text "Refine Cell"] -column 8 -row 0 -padx 5 -sticky e
2755    grid [label $frameLatt.ld -text "Cell damping"] -column 8 -row 1 -padx 5 -sticky e
2756    set cFlag [checkbutton $frameLatt.c -text "" -variable entryvar(cellref)]
2757    grid $cFlag -column 9 -row 0 -padx 5 -sticky e
2758    tk_optionMenu $frameLatt.om entryvar(celldamp) 0 1 2 3 4 5 6 7 8 9
2759    grid $frameLatt.om -column 9 -row 1 -padx 5 -sticky e
2760    grid [label $frameLatt.phasetype -textvariable expgui(phasetype) -fg blue] \
2761            -column 1 -row 0 -rowspan 2
2762    if [file executable $expgui(exptool)] {
2763        grid [button $expgui(phaseFrame).frameLatt.newp \
2764                -text "Add\nPhase" -padx 1.5m -command MakeAddPhaseBox \
2765                ] -column 0 -row 0 -rowspan 2 -sticky w
2766    }
2767    grid columnconfig $frameLatt  1 -weight 1
2768    grid columnconfig $frameLatt  0 -weight 1
2769    #-------------- Begin Atom Coordinates Box  ------------------------------
2770    grid [listbox  $fbig.title -height 1 -relief flat \
2771            -exportselection 0 -bg lightgrey -fg black \
2772            -selectforeground black -selectbackground lightgrey] \
2773            -row 0 -column 0 -sticky ew
2774    set expgui(atomtitle) $fbig.title
2775    bind $expgui(atomtitle) <Button-1> {
2776        set i [lsearch {number type mult x y z occupancy} $expgui(asorttype)]
2777        incr i
2778        set expgui(asorttype) [lindex {number type mult x y z occupancy number} $i]
2779        DisplayAllAtoms
2780    }
2781    bind $expgui(atomtitle) <Button-3> {set expgui(asorttype) number; DisplayAllAtoms}
2782
2783    $expgui(atomtitle) configure -font $expgui(coordfont) -selectmode extended
2784    grid [listbox   $fbig.lbox -height 10 \
2785            -exportselection 0 \
2786            -xscrollcommand " $fbig.bscr set"\
2787            -yscrollcommand " $fbig.rscr set"\
2788            ] -row 1 -column 0 -sticky news
2789    set expgui(atomlistbox) $fbig.lbox
2790    $expgui(atomlistbox) configure -font $expgui(coordfont) -selectmode extended
2791    grid [scrollbar $fbig.bscr -orient horizontal \
2792            -command "move2boxes \" $fbig.title $fbig.lbox \" " \
2793            ] -row 2 -column 0 -sticky ew
2794    grid [scrollbar $fbig.rscr  -command "$fbig.lbox yview" \
2795            ] -row 1 -column 1 -sticky ns
2796    # give extra space to the atoms box
2797    grid columnconfigure $fbig 0 -weight 1
2798    grid rowconfigure $fbig 1 -weight 1
2799   
2800    #   BIND mouse in editbox
2801    bind $expgui(atomlistbox) <ButtonRelease-1>   editRecord
2802    bind $expgui(atomlistbox) <Button-3>   SelectAllAtoms
2803   
2804    #-------------- End Atoms Section  ---------------------------------
2805
2806    # --------------------------- Begin Edit Box ------------------------
2807    grid [set expgui(EditingAtoms) [label $frame3.top -bg $expgui(bkgcolor1) -fg blue]] \
2808            -column 0 -row 0 -padx 2 -pady 3 -columnspan 10 -sticky w
2809    if [file executable $expgui(exptool)] {
2810        button $frame3.newa -text "Add New Atoms" \
2811                -bg $expgui(bkgcolor1) -highlightthickness 0 \
2812                -command {MakeAddAtomsBox $expgui(curPhase)}
2813        grid $frame3.newa -column 11 -row 0
2814    }
2815    button [set expgui(atomxform) $frame3.xa] \
2816            -bg $expgui(bkgcolor1) -highlightthickness 0 \
2817            -command {MakeXformAtomsBox $expgui(curPhase)}
2818    grid $expgui(atomxform) -column 11 -row 1 -sticky ew
2819
2820    set f3l1 [label $frame3.l1 -text "Refinement Flags:" -bg $expgui(bkgcolor1)]
2821    grid $f3l1 -column 0 -row 1 -padx 2 -sticky nsw -pady 3
2822    foreach lbl {X U F} var {xref uref fref} col {1 2 3} {
2823        grid [checkbutton $frame3.cf$col \
2824                -text $lbl -variable entryvar($var) \
2825                -bg $expgui(bkgcolor1) -highlightthickness 0 \
2826                -activebackground $expgui(bkgcolor1)] \
2827                -column $col -row 1 -padx 4 -pady 3 -sticky w
2828    }
2829    set f3l4 [label $frame3.l4 -text "  Damping:" -bg $expgui(bkgcolor1)]
2830    grid $f3l4 -column 4 -row 1 -padx 2 -sticky nsw -pady 3
2831   
2832    set col 4
2833    foreach var {xdamp udamp fdamp} num {2 3 4} lbl {X U F} {
2834        grid [label $frame3.lom$num -text $lbl \
2835                -bg $expgui(bkgcolor1)] \
2836                -column [incr col] -row 1 -padx 2 -pady 3 -sticky w
2837        tk_optionMenu $frame3.om$num entryvar($var) 0 1 2 3 4 5 6 7 8 9
2838        $frame3.om$num config -highlightthickness 0
2839        grid $frame3.om$num -column [incr col] -row 1 -padx 2 -pady 3 -sticky w
2840    }
2841    set expgui(atomreflbl) "$frame3.l1 $frame3.l4 $frame3.lom2 $frame3.lom3 $frame3.lom4 "
2842    set expgui(atomref) "$frame3.cf1 $frame3.cf2 $frame3.cf3 $frame3.om2 $frame3.om3 $frame3.om4"
2843   
2844    set coords [frame $frame3.coords  -width 100 -borderwidth 0  -bg $expgui(bkgcolor1)]
2845    grid $coords -column 0 -row 6 -columnspan 12 -sticky nsew
2846   
2847    set f3l1 [label $frame3.coords.l1 -text "Label" -bg $expgui(bkgcolor1)]
2848    grid $f3l1 -column 0 -row 4 -padx 2 -sticky nsw -pady 3
2849    set expgui(atomlabels) $f3l1
2850
2851    set f3e1 [entry  $frame3.coords.e1 -textvariable entryvar(label) -width 6]
2852    grid $f3e1 -column 1 -row 4 -padx 2 -sticky nsw -pady 3
2853    set expgui(atomentry) $f3e1
2854
2855    set f3l8 [label $frame3.coords.l8 -text "Coordinates" -bg $expgui(bkgcolor1)]
2856    grid $f3l8 -column 2 -row 4 -padx 2 -sticky nsw -pady 3
2857    lappend expgui(atomlabels) $f3l8
2858    set f3l11 [label $frame3.coords.l11 -text "Occupancy" -bg $expgui(bkgcolor1)]
2859    grid $f3l11 -column 6 -row 4 -padx 2 -sticky nsw -pady 3
2860    lappend expgui(atomlabels) $f3l11
2861
2862    foreach var {x y z frac} col {3 4 5 7} {
2863        set entrybox($var) [entry $frame3.coords.e$var \
2864                -textvariable entryvar($var) -width 10]
2865        grid $entrybox($var) -column $col -row 4 -padx 2 -sticky nsw -pady 3
2866        lappend expgui(atomentry) $entrybox($var)
2867    }
2868
2869
2870    set f3f31 [frame $frame3.f3f31  -width 100 -borderwidth 0 -bg $expgui(bkgcolor1)]
2871    grid $f3f31 -column 0 -row 7 -columnspan 12
2872    set expgui(anisolabels) {}
2873    foreach lbl {13 14 15 16 17 18} txt {Uiso U22 U33 U12 U13 U23} {
2874        lappend expgui(anisolabels)  [\
2875                label $f3f31.l$lbl -text $txt -bg $expgui(bkgcolor1)
2876        ]
2877    }
2878    set expgui(anisoentry) {}
2879    foreach i {e13 e14 e15 e16 e17 e18} var {U11 U22 U33 U12 U13 U23} {
2880        lappend expgui(anisoentry) [\
2881                entry $f3f31.$i -textvariable entryvar($var) \
2882                -width 10]
2883        set entrybox($var) $f3f31.$i
2884    }
2885   
2886    set col 0
2887    foreach item1 $expgui(anisolabels) item2 $expgui(anisoentry) {
2888        grid $item1 -column $col -row 0 -sticky nsw -pady 3
2889        incr col
2890        grid $item2 -column $col -row 0 -sticky nsw -pady 3
2891        incr col
2892    }
2893    # --------------------------- End Edit Box -------------------------
2894   
2895    #/\ /\ /\ /\ /\ /\ /\ END OF PHASE PANE CODE /\ /\ /\ /\ /\ /\ /\ /\ /
2896    # resize in case the pane needs more space
2897    ResizeNotebook
2898}
2899
2900proc move2boxes {boxlist args} {
2901    foreach listbox $boxlist {
2902        eval $listbox xview $args
2903    }
2904}
2905#-----------------------------------------------------------------------------
2906proc MakeHistPane {} {
2907    #v v v v v v v v v v  BEGINNING OF HISTOGRAM PANE CODE v v v v v v v v v v
2908    global expgui
2909   
2910    grid columnconfigure $expgui(histFrame) 0 -weight 1
2911    grid rowconfigure $expgui(histFrame) 1 -weight 1
2912    grid rowconfigure $expgui(histFrame) 2 -weight 1
2913    grid rowconfigure $expgui(histFrame) 3 -weight 1
2914
2915    grid [frame $expgui(histFrame).hs] \
2916            -column 0 -row 0 -rowspan 10 -sticky nsew
2917    MakeHistBox $expgui(histFrame).hs
2918    bind $expgui(histFrame).hs.lbox <ButtonRelease-1>  {
2919        set expgui(curhist) [$expgui(histFrame).hs.lbox curselection]
2920        DisplayHistogram
2921    }
2922    bind $expgui(histFrame).hs.lbox <Button-3>  {
2923        if $expgui(globalmode) {
2924            $expgui(histFrame).hs.lbox selection set 0 end
2925            set expgui(curhist) [$expgui(histFrame).hs.lbox curselection]
2926            DisplayHistogram
2927        }
2928    }
2929   
2930    frame $expgui(histFrame).top -borderwidth 4 -relief groove
2931    grid [label $expgui(histFrame).top.txt] -row 0 -column 0
2932    if $expgui(haveBW) {
2933        foreach item {backBox diffBox} num {2 3} \
2934                title {Background "Diffractometer Constants"} {
2935            TitleFrame $expgui(histFrame).$item  \
2936                    -borderwidth 4 -side left -relief groove -text $title
2937            set expgui($item) [$expgui(histFrame).$item getframe]
2938            grid $expgui(histFrame).$item -column 1 -row $num -sticky nsew
2939            grid rowconfigure $expgui(histFrame) $num -minsize 100
2940        }
2941    } else {
2942        foreach item {backBox diffBox} num {1 2} \
2943                title {Background "Diffractometer Constants"} {
2944            frame $expgui(histFrame).$item  -borderwidth 4 -relief groove
2945            grid $expgui(histFrame).$item -column 1 -row $num -sticky nsew
2946            set expgui($item)  $expgui(histFrame).$item
2947            grid [label $expgui(histFrame).$item.title -text $title] \
2948                    -row 0 -column 0 -columnspan 10 -sticky nw
2949        }
2950    }
2951    if [file executable $expgui(exptool)] {
2952        button $expgui(histFrame).newh -text "Add New Histogram" -command MakeAddHistBox
2953        grid $expgui(histFrame).newh -column 1 -row 6
2954    }
2955
2956    # BACKGROUND information.
2957    # <<<<<<<<<<<<<<<<<<<<<<<<< BACKGROUND  <<<<<<<<<<<<<<<<<<<<<
2958    grid [frame $expgui(backBox).frm1 ] -row 0 -column 0  -columnspan 11
2959    grid [label $expgui(backBox).frm1.lBGType \
2960            -textvariable expgui(backtypelbl)] \
2961            -row 1 -column 0 -sticky nws  -padx 2 -pady 3
2962    grid [label $expgui(backBox).frm1.lBGTerms \
2963            -textvariable expgui(backtermlbl)] \
2964            -row 1 -column 1 -sticky nws  -padx 2 -pady 3
2965    grid [button $expgui(backBox).frm1.edit -textvariable expgui(bkglbl) \
2966            -command editbackground] \
2967            -row 1 -column 2 -columnspan 3 -sticky w -padx 2 -pady 3
2968    grid [frame $expgui(backBox).frm2 ] \
2969            -row 1 -column 0 -columnspan 11 -sticky e
2970    grid [label $expgui(backBox).frm2.lfBG -text "  Refine background" ] \
2971            -row 2 -column 1 -sticky news -padx 4 -pady 3
2972    grid [checkbutton $expgui(backBox).frm2.rfBG -text "" \
2973            -variable  entryvar(bref) ] \
2974            -row 2 -column 2 -sticky news -padx 4 -pady 3
2975    grid [label $expgui(backBox).frm2.lBGDamp -text Damping ] \
2976            -row 2 -column 3 -sticky w    -padx 2 -pady 3
2977    tk_optionMenu $expgui(backBox).frm2.om  entryvar(bdamp) 0 1 2 3 4 5 6 7 8 9
2978    grid $expgui(backBox).frm2.om \
2979            -row 2 -column 4 -sticky news -padx 4 -pady 3 -sticky e
2980    #^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^END OF HISTOGRAM PANE CODE ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
2981    # insert the histograms & resize in case the pane needs more space
2982    sethistlist
2983    ResizeNotebook
2984}
2985###############################################################################
2986proc MakeScalingPane {} {
2987    #v v v v v v v v v v  BEGINNING OF SCALING PANE CODE v v v v v v v v v v
2988    global expgui entryvar entrybox
2989
2990    pack [frame $expgui(fracFrame).hs] -side left -expand y -fill both
2991    MakeHistBox $expgui(fracFrame).hs
2992    bind $expgui(fracFrame).hs.lbox <ButtonRelease-1> {
2993        set expgui(curhist) [$expgui(fracFrame).hs.lbox curselection]
2994        DisplayFrac
2995    }
2996    bind $expgui(fracFrame).hs.lbox <Button-3>  {
2997        if $expgui(globalmode) {
2998            $expgui(fracFrame).hs.lbox selection set 0 end
2999            set expgui(curhist) [$expgui(fracFrame).hs.lbox curselection]
3000            DisplayFrac
3001        }
3002    }
3003
3004    pack [frame $expgui(fracFrame).f1] -fill both -expand true
3005    # Create a large canvas area containing a frame for each phase in the data set.
3006    # The canvas and vertical scrollbar are inside a frame called f1
3007    if $expgui(haveBW) {
3008        TitleFrame $expgui(fracFrame).f1.scaleBox \
3009                -borderwidth 4 -text "Scale Factor"
3010        #           -borderwidth 4 -width 600 -height 100 -label "Scale Factor"
3011        grid $expgui(fracFrame).f1.scaleBox -column 0 -row 0 -sticky nsew -columnspan 2
3012        set expgui(scaleBox)  [$expgui(fracFrame).f1.scaleBox getframe]
3013        grid [label $expgui(scaleBox).histSFLabel -text Scale] \
3014                -row 1 -column 0 -sticky nws  -padx 2 -pady 3
3015    } else {
3016        frame $expgui(fracFrame).f1.scaleBox  -borderwidth 4 -relief groove
3017        grid $expgui(fracFrame).f1.scaleBox -column 0 -row 0 -sticky nsew -columnspan 2
3018        set expgui(scaleBox)  $expgui(fracFrame).f1.scaleBox
3019        grid [label $expgui(scaleBox).histSFLabel -text "Scale Factor"] \
3020                -row 1 -column 0 -sticky nws  -padx 2 -pady 3
3021    }
3022    grid [entry $expgui(scaleBox).ent1 -textvariable entryvar(scale) -width 15] \
3023            -row 1 -column 1 -sticky ew -padx 4 -pady 3
3024    set entrybox(scale) $expgui(scaleBox).ent1
3025
3026    button $expgui(scaleBox).but1 -text "Set Globally" \
3027            -command "editglobalparm histinfo scale {Scale Factor}"
3028
3029    grid [label $expgui(scaleBox).histSFRLabel -text " Refine"] \
3030            -row 1 -column 2 -sticky nws  -padx 2 -pady 3
3031    grid [checkbutton $expgui(scaleBox).rf -variable entryvar(sref)] \
3032            -row 1 -column 3 -sticky news -padx 4 -pady 3
3033    grid [label $expgui(scaleBox).lD1 -text "Damping"] \
3034            -row 1 -column 4 -sticky w    -padx 2 -pady 3
3035    tk_optionMenu $expgui(scaleBox).om entryvar(sdamp) 0 1 2 3 4 5 6 7 8 9
3036    grid $expgui(scaleBox).om \
3037            -row 1 -column 5 -sticky news -padx 4 -pady 3
3038    grid columnconfigure $expgui(scaleBox) 6  -weight 1
3039   
3040    if $expgui(haveBW) {
3041        grid [TitleFrame $expgui(fracFrame).f1.phaseFrac -bd 4 \
3042                -text "Phase Fractions" -relief groove] \
3043                -sticky news -row 1 -column 0 -columnspan 2
3044        set PhaseFractBox [$expgui(fracFrame).f1.phaseFrac getframe]
3045    } else {
3046        set PhaseFractBox $expgui(fracFrame).f1
3047    }
3048    grid columnconfigure $expgui(fracFrame).f1 0 -weight 1
3049    grid rowconfigure $expgui(fracFrame).f1 1 -weight 1
3050   
3051    grid [set expgui(FracBox) [canvas $PhaseFractBox.fracBox \
3052            -scrollregion {0 0 5000 500} \
3053            -yscrollcommand "$PhaseFractBox.yscroll set" \
3054            -width 500 -height 350 -bg lightgrey]] \
3055            -sticky  news -row 1 -column 0
3056    grid [scrollbar $PhaseFractBox.yscroll \
3057            -command "$expgui(FracBox) yview" \
3058            -orient vertical] \
3059            -sticky ns -row 1 -column 1
3060    frame $expgui(FracBox).f -bd 0
3061    $expgui(FracBox) create window 0 0 -anchor nw  -window $expgui(FracBox).f
3062
3063    # the rest of the page is created in DisplayFrac
3064
3065    # insert the histograms & resize in case the pane needs more space
3066    sethistlist
3067    ResizeNotebook
3068    # ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ END OF SCALING PANE CODE ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
3069}
3070###############################################################################
3071proc MakeProfilePane {} {
3072    global expgui
3073    # v v v v v v v v v v BEGINNING OF PROFILE PANE CODE v v v v v v v v v v v
3074    pack [frame $expgui(profFrame).hs] -side left -expand y -fill both
3075    MakeHistBox $expgui(profFrame).hs
3076    bind $expgui(profFrame).hs.lbox <ButtonRelease-1> {
3077        set expgui(curhist) [$expgui(profFrame).hs.lbox curselection]
3078        DisplayProfile
3079    }
3080    bind $expgui(profFrame).hs.lbox <Button-3>  {
3081        if $expgui(globalmode) {
3082            $expgui(profFrame).hs.lbox selection set 0 end
3083            set expgui(curhist) [$expgui(profFrame).hs.lbox curselection]
3084            DisplayProfile
3085        }
3086    }
3087
3088    # Create a large canvas area containing a frame for each phase in the data set.
3089    # The canvas and vertical scrollbar are inside a frame called f1
3090    pack [frame $expgui(profFrame).f1] -fill both -expand true
3091    grid [set expgui(ProfileBox) [canvas $expgui(profFrame).f1.profileBox \
3092            -scrollregion {0 0 5000 500} -width 500 -height 350 -bg lightgrey]] \
3093            -sticky  news -row 0 -column 0
3094    grid [scrollbar $expgui(profFrame).f1.yscroll -orient vertical] \
3095            -sticky ns -row 0 -column 1
3096   
3097    $expgui(ProfileBox) config -yscrollcommand "$expgui(profFrame).f1.yscroll set"
3098    $expgui(profFrame).f1.yscroll config -command { $expgui(ProfileBox) yview }
3099   
3100    grid columnconfigure $expgui(profFrame).f1 1 -weight 1
3101    grid rowconfigure $expgui(profFrame).f1 0 -weight 1
3102    frame $expgui(ProfileBox).f -bd 0
3103    $expgui(ProfileBox) create window 0 0 -anchor nw  -window $expgui(ProfileBox).f
3104   
3105    # insert the histograms & resize in case the pane needs more space
3106    sethistlist
3107    ResizeNotebook
3108    # ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ END OF PROFILE PANE CODE ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
3109}
3110
3111##############################################################################
3112# v v v v v v v v v v BEGINNING OF LS PANE CODE v v v v v v v v v v v v v
3113array set printopts {
3114    0 "Print the reciprocal metric tensor changes"
3115    1 "Print the correlation matrix"
3116    2 "Print the Least-Squares matrices and vectors"
3117    4 "Print the linear constraint matrices"
3118    5 "Print the applied  shifts and shift factors"
3119    6 "Print the reciprocal metric tensor Var-Covar terms"
3120    7 "Print all parameters for each cycle"
3121    8 "Print summary shift/esd data after last cycle"
3122    9 "Print zero/unit pole figure constraint terms"
3123}
3124pack [frame $expgui(lsFrame).hs] -side left -expand y -fill both
3125MakeHistBox $expgui(lsFrame).hs
3126bind $expgui(lsFrame).hs.lbox <ButtonRelease-1> {
3127    set expgui(curhist) [$expgui(lsFrame).hs.lbox curselection]
3128    SetupExtractHist
3129}
3130bind $expgui(lsFrame).hs.lbox <Button-3>  {
3131    if $expgui(globalmode) {
3132        $expgui(lsFrame).hs.lbox selection set 0 end
3133        set expgui(curhist) [$expgui(lsFrame).hs.lbox curselection]
3134        SetupExtractHist
3135    }
3136}
3137
3138pack [frame $expgui(lsFrame).f1] -fill both -expand true
3139grid rowconfigure $expgui(lsFrame).f1  4 -weight 1
3140set row 0
3141grid [label $expgui(lsFrame).f1.his1 -pady 6 -text "Last History:"] -row $row -column 0
3142grid [label $expgui(lsFrame).f1.his2 -relief raised -bd 2 -pady 6 \
3143        -textvariable expgui(last_History)] \
3144        -row $row -column 1 -columnspan 5 -sticky w
3145incr row
3146grid [label $expgui(lsFrame).f1.tit1 -pady 6 -text "Title:"] -row $row -column 0
3147grid [entry $expgui(lsFrame).f1.tit2 \
3148        -textvariable entryvar(title) -width 48] \
3149        -row $row -column 1 -columnspan 5 -sticky w
3150set entrycmd(title) "expinfo title"
3151
3152incr row
3153grid [frame $expgui(lsFrame).f1.b -bd 4 -relief groove] \
3154        -row $row -column 0 -columnspan 2 -pady 3
3155grid [label $expgui(lsFrame).f1.b.lcyc -text "Number of Cycles"] -row 0 -column 0
3156grid [entry $expgui(lsFrame).f1.b.ecyc -width 3 \
3157        -textvariable entryvar(cycles)] -row 0 -column 1
3158set entrybox(cycles) $expgui(lsFrame).f1.b.ecyc
3159grid [menubutton $expgui(lsFrame).f1.lprint -textvariable expgui(printopt) \
3160        -menu $expgui(lsFrame).f1.lprint.menu -bd 4 -relief raised \
3161        ] -row $row -column 2
3162menu $expgui(lsFrame).f1.lprint.menu
3163foreach num [lsort [array names printopts]] {
3164    $expgui(lsFrame).f1.lprint.menu add checkbutton \
3165            -label "$printopts($num) ([expr int(pow(2,$num))])"\
3166        -variable entryvar(printopt$num)
3167}
3168#grid [frame $expgui(lsFrame).f1.c -bd 4 -relief groove] -row $row -column 3
3169#grid [label $expgui(lsFrame).f1.c.fol -text "Extract Fobs"] -row 0 -column 2
3170#grid [checkbutton $expgui(lsFrame).f1.c.foc -variable entryvar(fobsextract)] -row 0 -column 3
3171incr row
3172if {$expgui(haveBW)} {
3173    grid [TitleFrame $expgui(lsFrame).f1.a -bd 4 -relief groove \
3174            -text "Reflection Intensity Extraction" \
3175            ] -row $row -column 0 -columnspan 6
3176    set expgui(FobsExtractFrame) [$expgui(lsFrame).f1.a getframe]
3177} else {
3178    grid [frame $expgui(lsFrame).f1.a -bd 4 -relief groove \
3179            ] -row $row -column 0 -columnspan 6
3180    set expgui(FobsExtractFrame) $expgui(lsFrame).f1.a
3181}
3182grid rowconfigure $expgui(lsFrame).f1 $row -pad 16
3183grid [frame $expgui(FobsExtractFrame).c -bd 4 -relief groove] \
3184        -row 0 -column 8 -columnspan 3 -sticky e
3185grid [label $expgui(FobsExtractFrame).c.fol -text "Extract Fobs"] \
3186        -row 0 -column 2
3187grid [checkbutton $expgui(FobsExtractFrame).c.foc \
3188        -variable entryvar(fobsextract)] -row 0 -column 3
3189foreach num {1 2 3 4 5 6 7 8 9} {
3190    grid [label $expgui(FobsExtractFrame).l$num -text $num] -row 1 -column $num
3191    grid [radiobutton $expgui(FobsExtractFrame).cc$num \
3192            -command "HistExtractSet $num" \
3193            -variable expgui(Fextract$num) -value 0] \
3194            -row 2 -column $num
3195    grid [radiobutton $expgui(FobsExtractFrame).ca$num \
3196            -command "HistExtractSet $num" \
3197            -variable expgui(Fextract$num) -value 1] \
3198            -row 3 -column $num
3199    grid [radiobutton $expgui(FobsExtractFrame).cb$num \
3200            -command "HistExtractSet $num" \
3201            -variable expgui(Fextract$num) -value 2] \
3202            -row 4 -column $num
3203}
3204set expgui(ExtractSettingsRadiobuttons) $expgui(FobsExtractFrame).cc
3205lappend expgui(ExtractSettingsRadiobuttons) $expgui(FobsExtractFrame).ca
3206lappend expgui(ExtractSettingsRadiobuttons) $expgui(FobsExtractFrame).cb
3207
3208grid [label $expgui(FobsExtractFrame).t \
3209        -text "Extraction\nMethod" -anchor c] \
3210        -column 0 -row 0 -rowspan 2 -sticky s
3211grid [label $expgui(FobsExtractFrame).t0 -text "Phase #" -anchor sw] \
3212        -column 1 -row 0 -columnspan 7 -sticky sw
3213grid [label $expgui(FobsExtractFrame).t1 -text "Rietveld" -anchor c] -column 0 -row 2
3214grid [label $expgui(FobsExtractFrame).t2 -text "F(calc) Weighted" -anchor c] -column 0 -row 3
3215grid [label $expgui(FobsExtractFrame).t3 -text "Equally Weighted" -anchor c] -column 0 -row 4
3216grid [label $expgui(FobsExtractFrame).t2a -text "(Model biased)" -anchor c] -column 10 -row 3
3217grid [label $expgui(FobsExtractFrame).t3a -text "(Le Bail method)" -anchor c] -column 10 -row 4
3218# ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ END OF LS PANE CODE ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
3219#-------------------------------------------------------------------------
3220#-------------------------------------------------------------------------
3221#vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv THE MENU BAR vvvvvvvvvvvvvvvvvvvvvv
3222
3223#---- file menu button
3224menubutton $expgui(fm).file -text File -menu $expgui(fm).file.menu
3225menu $expgui(fm).file.menu
3226if $expgui(debug) {
3227    $expgui(fm).file.menu add command -label "Reset" -command "reset"
3228}
3229if {$expgui(shell)} {
3230    $expgui(fm).file.menu add command -label "expnam" -command readnewexp
3231}
3232$expgui(fm).file.menu add command -label "Save" -underline 0 \
3233        -command savearchiveexp
3234foreach c {s S} {bind . <Alt-$c> [list savearchiveexp]}
3235$expgui(fm).file.menu add command -label "Save As" \
3236        -command "SaveAsFile"
3237$expgui(fm).file.menu add command -label "Reread .EXP file" \
3238        -command {rereadexp $expgui(expfile)}
3239
3240#---- help menu button
3241menubutton $expgui(fm).help -text Help -menu $expgui(fm).help.menu
3242menu $expgui(fm).help.menu
3243$expgui(fm).help.menu add command -command showhelp -underline 0 \
3244        -label "Help Summary"
3245$expgui(fm).help.menu add command -command MakeWWWHelp  \
3246        -label "Help on current pane"
3247$expgui(fm).help.menu add command -command "MakeWWWHelp menu" \
3248        -label "Help on menu"
3249foreach c {h H} {bind . <Alt-$c> [list showhelp]}
3250# define help actions
3251bind . <Key-F1> MakeWWWHelp
3252$expgui(fm).help.menu add command -label "About..." -command About
3253
3254#---- options menu button
3255menubutton $expgui(fm).option -text Options \
3256        -menu $expgui(fm).option.menu
3257menu $expgui(fm).option.menu
3258
3259if {$expgui(shell)} {
3260    $expgui(fm).option.menu add checkbutton  -label "Archive EXP" \
3261            -variable expgui(archive)
3262    $expgui(fm).option.menu add checkbutton  -label "Use DISAGL window" \
3263            -variable expgui(disaglSeparateBox)
3264}
3265$expgui(fm).option.menu add cascade -menu  $expgui(fm).option.menu.asort \
3266        -label "Sort atoms by"
3267
3268set expgui(asorttype) number
3269menu $expgui(fm).option.menu.asort
3270foreach opt {number type mult x y z occupancy} {
3271    $expgui(fm).option.menu.asort add radiobutton -command DisplayAllAtoms \
3272            -label $opt -value $opt -variable expgui(asorttype)
3273}
3274
3275$expgui(fm).option.menu add cascade -menu  $expgui(fm).option.menu.hsort \
3276        -label "Sort histograms by"
3277
3278set expgui(hsorttype) number
3279menu $expgui(fm).option.menu.hsort
3280$expgui(fm).option.menu.hsort add radiobutton -command sethistlist \
3281        -label number -value number -variable expgui(hsorttype)
3282$expgui(fm).option.menu.hsort add radiobutton -command sethistlist \
3283        -label "Histogram type" -value type -variable expgui(hsorttype)
3284$expgui(fm).option.menu.hsort add radiobutton -command sethistlist \
3285        -label "Bank #" -value bank -variable expgui(hsorttype)
3286$expgui(fm).option.menu.hsort add radiobutton -command sethistlist \
3287        -label "Angle/Wavelength" -value angle -variable expgui(hsorttype)
3288
3289#---- Global mode menu button
3290$expgui(fm).option.menu add cascade -menu $expgui(fm).option.menu.editmode \
3291        -label "Multiple hist. selection"
3292menu $expgui(fm).option.menu.editmode
3293$expgui(fm).option.menu.editmode add radiobutton  -label "Off" \
3294        -variable expgui(globalmode) -value 0 \
3295        -command sethistlist
3296$expgui(fm).option.menu.editmode add radiobutton  -label "All" \
3297        -variable expgui(globalmode) -value 6 \
3298        -command sethistlist
3299$expgui(fm).option.menu.editmode add radiobutton  -label "TOF" \
3300        -variable expgui(globalmode) -value 1 \
3301        -command sethistlist
3302$expgui(fm).option.menu.editmode add radiobutton  -label "CW Neutron" \
3303        -variable expgui(globalmode) -value 2  \
3304        -command sethistlist
3305$expgui(fm).option.menu.editmode add radiobutton  -label "Alpha12 Xray" \
3306        -variable expgui(globalmode) -value 3 \
3307        -command sethistlist
3308$expgui(fm).option.menu.editmode add radiobutton  -label "Monochromatic Xray" \
3309        -variable expgui(globalmode) -value 4 \
3310        -command sethistlist
3311$expgui(fm).option.menu.editmode add radiobutton  -label "Energy Disp Xray" \
3312        -variable expgui(globalmode) -value 5 \
3313        -command sethistlist
3314$expgui(fm).option.menu.editmode add separator
3315$expgui(fm).option.menu.editmode add checkbutton \
3316        -label "Group phases together" \
3317        -variable expgui(globalphasemode) \
3318        -command sethistlist
3319
3320set expgui(globalmode) 0
3321set expgui(globalphasemode) 1
3322
3323if {$tcl_platform(platform) == "unix"} {
3324    $expgui(fm).option.menu  add checkbutton -label "Override backspace" \
3325            -variable env(GSASBACKSPACE)
3326    if {$expgui(shell)} {
3327        $expgui(fm).option.menu  add checkbutton -label "Autoload EXP" \
3328                -variable expgui(autoexpload)
3329    }
3330    $expgui(fm).option.menu  add checkbutton -label "Show EXPTOOL output" \
3331                -variable expgui(showexptool)
3332}
3333
3334$expgui(fm).option.menu add command -label "Save Options" \
3335        -command "SaveOptions"
3336
3337pack $expgui(fm).file $expgui(fm).option -side left  -in $expgui(fm)
3338
3339if {$expgui(shell)} {
3340    foreach menu $expgui(menunames) {
3341        set m [string tolower $menu]
3342        pack [menubutton $expgui(fm).$m -text $menu \
3343                -menu $expgui(fm).$m.menu] -side left
3344        menu $expgui(fm).$m.menu
3345    }
3346}
3347pack $expgui(fm).help  -side right -in $expgui(fm)
3348
3349if {$expgui(shell)} {
3350    # add the commands in expgui_menulist
3351    foreach menu [array names expgui_menulist ] {
3352        foreach cmd $expgui_menulist($menu) {
3353            set action {}
3354            set opt {}
3355            catch {set action [lindex $expgui_cmdlist($cmd) 0]}
3356            catch {set opt [lindex $expgui_cmdlist($cmd) 2]}
3357            if {$expgui(debug) && $action == ""} {puts "blank command for $cmd"}
3358            if {$action != "" && $action != "-"} {
3359                eval $expgui(fm).$menu.menu add command \
3360                        -label $cmd $opt -command [list [subst $action]]
3361                if {[lindex $opt 0] == "-underline"} {
3362                    catch {
3363                        set num [lindex $opt 1]
3364                        set key [string range $cmd $num $num]
3365                        bind . <Alt-[string tolower $key]> [subst $action]
3366                        bind . <Alt-[string toupper $key]> [subst $action]
3367                    }
3368                }
3369            }
3370        }
3371    }
3372}
3373# setup command help
3374foreach cmd [array names expgui_cmdlist] {
3375    set help {}
3376    catch {set help [lindex $expgui_cmdlist($cmd) 1]}
3377    if {$help == ""} {
3378        if {$expgui(debug)} {puts "no help for $cmd"}
3379    } else {
3380        # remove
3381        regsub -all \x09 $help " " help
3382        # preserve blank lines
3383        regsub -all \x0A\x0A $help "AAA1234567890AAA" help
3384        regsub -all \x0A $help " " help
3385        regsub -all "AAA1234567890AAA" $help \x0A\x0A help
3386        regsub -all " +" $help " " help
3387        set expgui_helplist($cmd) [string trim $help]
3388    }
3389}
3390if {$expgui(shell)} {
3391    # set up button bar
3392    foreach cmd $expgui(buttonlist) {
3393        set action {}
3394        catch {set action [lindex $expgui_cmdlist($cmd) 0]}
3395        if {$expgui(debug) && $action == ""} {puts "blank command for $cmd"}
3396        if {$action != ""} {
3397            pack [eval button .bar.$cmd -bg beige -activebackground yellow \
3398                    -text $cmd -command [list [subst $action]]] -side left
3399        }
3400    }
3401}
3402
3403$expgui(fm).file.menu add command -label "Exit"  -underline 1 -command catchQuit
3404foreach c {X x} {bind . <Alt-$c> [list catchQuit]}
3405#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ END OF MENU DEFINITION ^^^^^^^^^^^^^^^^^^^
3406
3407# make the phase pane
3408MakePhasePane
3409# and the rest of the windows w/o BWidget
3410if !$expgui(haveBW) {
3411    MakeHistPane
3412    MakeScalingPane
3413    MakeProfilePane
3414}
3415
3416# handle indirect exits
3417wm protocol . WM_DELETE_WINDOW catchQuit
3418bind . <Control-c> catchQuit
3419
3420set expgui(curPhase) ""
3421set expgui(pagenow) ""
3422set expgui(curhist) {}
3423set expgui(selectedatomlist) {}
3424
3425loadexp $expgui(expfile)
3426
3427# select the 1st phase
3428SelectOnePhase [lindex $expmap(phaselist) 0]
3429# select the first histogram in the list by default (if there are any)
3430if {[llength $expmap(histlistboxcontents)] > 0} {
3431    set expgui(curhist) 0
3432} else {
3433    set expgui(curhist) {}
3434}
3435
3436# execute any local commands for final initialization
3437eval $expgui(initstring)
3438
3439# resize the notebook to fit all the tabs and the largest page
3440ResizeNotebook
3441
3442RaisePage lsFrame
3443if {[CountHistory] > 100} {
3444    DeleteHistoryRecords "This .EXP file has [CountHistory] history records\nErasing most will speed EXPGUI"
3445}
Note: See TracBrowser for help on using the repository browser.