source: trunk/expgui @ 61

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

# on 1999/02/19 18:17:14, toby did:
Cleanup warnings

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