source: trunk/expgui @ 133

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

# on 2000/05/17 16:17:21, toby did:
cleanup reading lowercase .exp files
remove Tix!!! replace with BWidget
use options (opt.tcl) to get Tix-like appearance
treat "fixed" .EXP files as changed (to force a write before use)
Add support for 2 "leBail" options in the '00 version of GSAS
Change display of update message when .EXP is changed (with attention
to Windows screen placement)
Ignore macromolecular phases; recognize & flag magnetic phases
Use BWidget frame labels where possible
Move pane drawing from global code to MakePhasePane?, MakeHistPane?, MakeScalingPane? {} {
Move pane drawing from global code to MakePhasePane?, MakeHistPane?, MakeScalingPane?, MakeProfilePane?

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