source: trunk/expgui @ 48

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

# on 1999/02/02 17:26:27, toby did:
fix typo in 1.8
update phase page on reload
make sure that all set commands trigger the expgui(changed) flag

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