source: trunk/expgui @ 21

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

# on 1999/01/07 04:43:03, toby did:
misc fixes:

set working directory when expgui(expfile) is changed because GSAS must be
run in the directory of the EP file

fixup relative paths if used for the script name

fix bug in expgui(gsasexe) file join

in DisplayProfile? & make sure that entrycmd(trace) is as 0 when return is done

add Override backspace to options

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