source: trunk/expgui @ 118

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

# on 1999/11/16 15:59:22, toby did:
Switch over to use of pure Tk notebook widget when Tix is not present
define expgui(initstring) for user-defined initializations

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