source: trunk/expgui @ 28

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

# on 1999/01/13 05:02:47, toby did:
redo loadexp so that page does not change on reload
Add SaveOptions?

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