source: trunk/expgui @ 30

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

# on 1999/01/20 19:29:10, toby did:
use custom file open box
allow for a new .EXP file to be opened from a dialog
add filesort option
add phase select to readnewexp
fix bug in SetupExtractHist? for empty .EXP files

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