source: trunk/expgui @ 112

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

# on 1999/10/11 19:48:35, toby did:
cleanup multiple histogram selection -> single histogram transition

rewrite global profile display code to group or not group phases together

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