source: trunk/expgui @ 500

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

# on 2001/12/16 20:13:10, toby did:
make top of window a bit smaller

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