source: trunk/expgui @ 267

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

# on 2000/08/17 23:48:03, toby did:
implement Replace Phase
error trace on error in a *info command

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