source: trunk/expgui @ 139

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

# on 2000/05/17 18:45:27, toby did:
new option: allow a separate window for DISAGL
remove most underlines from menu options
provide keyboard accelerators for selected menu options
N.B. note new mechanism in gsasmenu.tcl for keyboard accelerators
use yellow highlight for active button on button bar

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