source: trunk/expgui @ 82

Last change on this file since 82 was 82, checked in by toby, 13 years ago

# on 1999/04/08 20:43:10, toby did:
Add Id to top of file

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