source: trunk/expgui @ 395

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

# on 2001/05/23 20:11:12, toby did:
use www.ncnr.nist.gov/xtal/software/expgui as default location for web pages
fix intermediate or old GSAS versions with fonts file in /fonts/ or named pgfont.dat
clean up file archiving in UNIX

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