source: trunk/expgui @ 97

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

# on 1999/07/22 20:04:23, toby did:
clear atom box etc when loading an "empty" .EXP file
avoid DisplayProfile? error when loading an "empty" .EXP file

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