source: trunk/expgui @ 289

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

# on 2000/10/02 16:54:10, toby did:
remove unneeded raise command in ReloadExpMsg? -- seems to cause a major delay

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