source: trunk/expgui @ 385

Last change on this file since 385 was 385, checked in by toby, 13 years ago

# on 2001/04/17 22:51:20, toby did:
Use CR/LF format files on all platforms

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