source: trunk/expgui @ 71

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

# on 1999/03/19 17:07:59, toby did:
bug fixes for reading new .EXP files

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