source: trunk/expgui @ 14

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

# on 1998/12/31 13:10:07, toby did:
move scale to "scaling" (prev phase frac) page
add scroll bar to phase fractions
rename archiveexp to savearchiveexp
move "set expgui(changed) 0" to savearchiveexp

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