source: trunk/expgui @ 481

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

# on 2001/10/31 20:06:10, toby did:
fix .Oxx bug when no files are found
add excledt support

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