source: trunk/expgui @ 399

Last change on this file since 399 was 399, checked in by toby, 14 years ago

# on 2001/06/29 18:06:31, toby did:
Add Marquardt, convergence, LeBail? damping to LS page
bkgedit button to background edit dialog

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