source: trunk/expgui @ 539

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

# on 2002/01/22 22:29:18, toby did:
Significant change in display of atoms on phase panel:

changing an atom queues an update for that atom only
using new routine UpdateAtomLine?
avoid duplicate refresh (killer for big lists)

Display atoms in MM phases
Add a Export coordinates menu cascade that gets built

when used rather than every time the software is loaded (better speed)

new routines: FormatAtomLine? & UpdateAtomLine? so that only 1

atom can be updated at a time

CompressList? now divides up the list with <CR> if a maximum

length is supplied

Remove AddAtoms? & ReplacePhase? buttons for MM phases (not supported)

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