source: trunk/expgui @ 93

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

# on 1999/07/21 16:32:11, toby did:
add autoload mode
add support for adding phases, histograms and atoms
reset expmap when loading a new .EXP file
use putontop and afterputontop
change alpha, beta & gamma to greek letters

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