source: trunk/expgui @ 12

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

# on 1998/12/28 02:33:30, toby did:
minor fixes
comment out $expgui(lsFrame).f1.a.cbXXX entries until Bob gets the new version out

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