source: trunk/expgui @ 199

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

# on 2000/06/09 03:45:28, toby did:
Change Reload msg as per suggestions
add MD pref orientation pane
fix bug in non-BWidget implementation
make CompressList? survive use of strings
use -exportselection 0 for listboxes to avoid cut/paste conflicts

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