source: trunk/widplt @ 839

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

# on 2005/03/24 21:52:39, toby did:
support function #5 (thanks RBVD)

  • Property rcs:author set to toby
  • Property rcs:date set to 2005/03/24 21:52:39
  • Property rcs:lines set to +4 -4
  • Property rcs:rev set to 1.19
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 39.2 KB
Line 
1#!/bin/sh
2# the next line restarts this script using wish found in the path\
3exec wish "$0" "$@"
4# If this does not work, change the #!/usr/bin/wish line below
5# to reflect the actual wish location and delete all preceeding lines
6#
7# (delete here and above)
8#!/usr/bin/wish
9# $Id: widplt 839 2009-12-04 23:12:55Z toby $
10set Revision {$Revision: 839 $ $Date: 2009-12-04 23:12:55 +0000 (Fri, 04 Dec 2009) $}
11package require Tk
12bind all <Control-KeyPress-c> {destroy .}
13set expnam [lindex $argv 0]
14if {$expnam != ""} {
15    if {[string toupper [file extension $expnam]] != ".EXP"} {
16        append expnam ".EXP"
17    }
18}
19# get name of script
20set expgui(script) [info script]
21# what are we running here?
22set program [file tail $argv0]
23# fix up problem with starkit tcl
24if {$program != "absplt" && $program != "widplt"} {
25        set program [file tail $expgui(script)]
26}
27
28if [catch {package require BLT} errmsg] {
29    tk_dialog .err "BLT Error" "Error -- Unable to load the BLT package" \
30            error 0 Quit
31    destroy .
32}
33
34# handle Tcl/Tk v8+ where BLT is in a namespace
35#  use the command so that it is loaded
36catch {blt::graph}
37catch {
38    namespace import blt::graph
39    namespace import blt::vector
40}
41# old versions of blt don't report a version number
42if [catch {set blt_version}] {set blt_version 0}
43
44set expgui(debug) 0
45catch {if $env(DEBUG) {set expgui(debug) 1}}
46#set expgui(debug) 1
47
48proc waitmsg {message} {
49    set w .wait
50    # kill any window/frame with this name
51    catch {destroy $w}
52    pack [frame $w]
53    frame $w.bot -relief raised -bd 1
54    pack $w.bot -side bottom -fill both
55    frame $w.top -relief raised -bd 1
56    pack $w.top -side top -fill both -expand 1
57    label $w.msg -justify left -text $message -wrap 3i
58    catch {$w.msg configure -font \
59                -Adobe-Times-Medium-R-Normal--*-180-*-*-*-*-*-*
60    }
61    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
62    label $w.bitmap -bitmap info
63    pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
64    update
65}
66
67proc donewaitmsg {} {
68    catch {destroy .wait}
69    update
70}
71
72if {$expnam != ""} {waitmsg "Loading $expnam, Please wait"}
73
74# get profile/absorption information out from an EXP file
75proc getprofiles {expnam} {
76    global WidSetList absSetList wave XY UVWP lblarr ttrange
77    global expmap
78
79    if {$expnam != ""} {
80        if {[expload $expnam] == -1} {
81            tk_dialog .err "EXP Error" "Warning -- Unable to read $expnam" \
82                error 0 OK
83            return
84        }
85        mapexp
86    } else {
87        set expmap(powderlist) {}
88    }
89    foreach hist $expmap(powderlist) {
90        # wavelength
91        set lambda1 [histinfo $hist lam1]
92        # data range
93        set drange [string trim [readexp "HST  $hist TRNGE"]]
94        global program
95        if {$program == "absplt"} {
96            global ABS
97            set ABS($hist) [list \
98                                [histinfo $hist abscor1] \
99                                [histinfo $hist abscor2] \
100                                [histinfo $hist abstype] \
101                                $drange \
102                                "Hist $hist" \
103                                $expmap(htype_$hist)]
104            lappend absSetList $hist
105        } else {
106            foreach phase $expmap(phaselist_$hist) {
107                set ptype [hapinfo $hist $phase proftype]
108                set pterms  [hapinfo $hist $phase profterms]
109                set key "H${hist}P${phase}"
110                # make sure the key is not present already
111                if {[lsearch $WidSetList $key] == -1} {
112                    lappend WidSetList $key
113                }
114                set lblarr($key) "Histogram $hist Phase $phase"
115                set wave($key) $lambda1
116                set ttrange($key) $drange
117                if {$ptype == 1} {
118                    set UVWP($key) [list [hapinfo $hist $phase pterm1] \
119                                        [hapinfo $hist $phase pterm2] \
120                                        [hapinfo $hist $phase pterm3] 0]
121                    set XY($key) {0 0}
122                } elseif {$ptype == 2} {
123                    set UVWP($key) [list [hapinfo $hist $phase pterm1] \
124                                        [hapinfo $hist $phase pterm2] \
125                                        [hapinfo $hist $phase pterm3] \
126                                        [hapinfo $hist $phase pterm9]]
127                    set XY($key) [list [hapinfo $hist $phase pterm4] \
128                                      [hapinfo $hist $phase pterm5]]
129                } elseif {$ptype == 3 || $ptype == 4 || $ptype == 5} {
130                    set UVWP($key) [list [hapinfo $hist $phase pterm1] \
131                                        [hapinfo $hist $phase pterm2] \
132                                        [hapinfo $hist $phase pterm3] \
133                                        [hapinfo $hist $phase pterm4]]
134                    if {$ptype == 3 || $ptype == 5} {
135                        set XY($key) [list [hapinfo $hist $phase pterm5] \
136                                          [hapinfo $hist $phase pterm6]]
137                    } else {
138                        set XY($key) [list [hapinfo $hist $phase pterm5] 0]
139                    }
140                }
141            }
142        }
143    }
144    MakeCascadeMenus
145}
146
147proc makepostscriptout {} {
148    global graph box
149    if !$graph(printout) {
150        set out [open "| $graph(outcmd) >& widplt.msg" w]
151        catch {
152            puts $out [$box postscript output -landscape 1 \
153                -decorations no -height 7.i -width 9.5i]
154            close $out
155        } msg
156        catch {
157            set out [open widplt.msg r]
158            if {$msg != ""} {append msg "\n"}
159            append msg [read $out]
160            close $out
161            file delete widplt.msg
162        }
163        if {$msg != ""} {
164            tk_dialog .msg "file created" \
165                    "Postscript file processed with command \
166                    $graph(outcmd). Result: $msg" "" 0 OK
167        } else {
168            tk_dialog .msg "file created" \
169                    "Postscript file processed with command \
170                    $graph(outcmd)" "" 0 OK
171        }
172    } else {
173        $box postscript output $graph(outname) -landscape 1 \
174                -decorations no -height 7.i -width 9.5i   
175        tk_dialog .msg "file created" \
176                "Postscript file $graph(outname) created" "" 0 OK
177    }
178}
179
180proc setprintopt {page} {
181    global graph
182    if $graph(printout) { 
183        $page.4.1 config -fg black
184        $page.4.2 config -fg black -state normal
185        $page.6.1 config -fg #888
186        $page.6.2 config -fg #888 -state disabled
187    } else {
188        $page.4.1 config -fg #888
189        $page.4.2 config -fg #888 -state disabled
190        $page.6.1 config -fg black
191        $page.6.2 config -fg black -state normal
192    }
193}
194
195proc seteqwave {top} {
196    global graph
197    set box .wave
198    catch {destroy $box}
199    toplevel $box
200    focus $box
201    grab $box
202    pack [frame $box.1] -side top
203    pack [label $box.1.a -text "Equivalent wavelength:"] -side top
204    pack [entry $box.1.b -textvariable graph(equivwave)] -side top
205    pack [frame $box.2] -side top
206    pack [button $box.2.c -text Clear -command "set graph(equivwave) {}; destroy $box"]
207    pack [button $box.2.u -text Use -command "destroy $box"]
208    tkwait window $box
209    plotdata $top
210}
211
212proc setpostscriptout {} {
213    global graph tcl_platform
214    set box .out
215    catch {destroy $box}
216    toplevel $box
217    focus $box
218    grab $box
219    pack [frame $box.4] -side top -anchor w -fill x
220    pack [checkbutton $box.4.a -text "Write PostScript files" \
221            -variable graph(printout) -offvalue 0 -onvalue 1 \
222            -command "setprintopt $box"] -side left -anchor w
223    pack [entry $box.4.2 -textvariable graph(outname)] -side right -anchor w
224    pack [label $box.4.1 -text "PostScript file name:"] -side right -anchor w
225    pack [frame $box.6] -side top -anchor w -fill x
226    pack [checkbutton $box.6.a -text "Print PostScript files" \
227            -variable graph(printout) -offvalue 1 -onvalue 0 \
228            -command "setprintopt $box" ] -side left -anchor w
229    pack [entry $box.6.2 -textvariable graph(outcmd)] -side right -anchor w
230    pack [label $box.6.1 -text "Command to print files:"] -side right -anchor w
231
232    pack [button $box.a -text "Close" -command "destroy $box"] -side top   
233    if {$tcl_platform(platform) == "windows"} {
234        set graph(printout) 1
235        $box.4.a config -state disabled
236        $box.6.a config -fg #888 -state disabled
237    }
238    setprintopt $box
239}
240
241proc aboutwidplot {} {
242    global Revision
243    tk_dialog .warn About "
244GSAS\n\
245A. C. Larson and\n R. B. Von Dreele,\n LANSCE, Los Alamos\n\n\
246WIDPLT/ABSPLT\nB. Toby, NIST\nNot subject to copyright\n\n\
247$Revision\n\
248" {} 0 OK
249}
250
251proc nextcolor {var} {
252    set num [uplevel "incr $var"]
253    return [lindex {red green blue cyan magenta yellow} [expr $num % 6]]
254}
255
256proc NewProfileValues {} {
257    global newmenu datanum
258    incr datanum
259    set base .edit
260    catch {destroy $base}
261    toplevel $base
262    focus $base
263    grab $base
264    wm title $base {Enter a new profile}
265    MakeEditProfileBox $base
266    grid [button $base.bttn1 -text Add \
267            -command "AddProfileValues; destroy $base"] -row 6 -column 6 
268    grid [button $base.bttn2 -text Quit \
269            -command "destroy $base"] -row 6 -column 7 
270    set newmenu(U) 0
271    set newmenu(V) 0
272    set newmenu(W) 0
273    set newmenu(P) 0
274    set newmenu(X) 0
275    set newmenu(Y) 0
276    set newmenu(min) 5
277    set newmenu(max) 100
278    set newmenu(label) "Curve #$datanum"
279    set newmenu(wave) 1.5418
280}
281
282proc AddProfileValues {} {
283    global newmenu datanum lblarr WidDisplay UVWP XY WidSetList ttrange wave
284    set key new$datanum
285    set UVWP($key) [list $newmenu(U) $newmenu(V) $newmenu(W) $newmenu(P)]
286    set XY($key) [list $newmenu(X) $newmenu(Y)]
287    set lblarr($key) $newmenu(label)
288    set ttrange($key) "$newmenu(min) $newmenu(max)"
289    set wave($key) $newmenu(wave)
290    lappend WidSetList $key
291    MakeCascadeMenus
292}
293
294proc editProfileValues {key} {
295    global newmenu WidSetList lblarr
296
297    set base .edit
298    catch {destroy $base}
299    toplevel $base
300    wm title $base {Edit a profile}
301    MakeEditProfileBox $base
302    grid [button $base.bttn1 -text Apply \
303            -command "SaveProfileEdits $key"] -row 6 -column 6 
304    grid [button $base.bttn2 -text Close \
305            -command "destroy $base"] -row 6 -column 7 
306
307    global UVWP XY ttrange wave lblarr
308    set newmenu(label) $lblarr($key)
309    set newmenu(U) [lindex $UVWP($key) 0]
310    set newmenu(V) [lindex $UVWP($key) 1]
311    set newmenu(W) [lindex $UVWP($key) 2]
312    set newmenu(P) [lindex $UVWP($key) 3]
313    set newmenu(X) [lindex $XY($key) 0]
314    set newmenu(Y) [lindex $XY($key) 1]
315    set newmenu(min) [lindex $ttrange($key) 0]
316    set newmenu(max) [lindex $ttrange($key) 1]
317    set newmenu(wave) $wave($key)
318}
319
320proc SaveProfileEdits {key} {
321    global newmenu datanum lblarr WidDisplay UVWP XY WidSetList ttrange wave box
322    set UVWP($key) [list $newmenu(U) $newmenu(V) $newmenu(W) $newmenu(P)]
323    set XY($key) [list $newmenu(X) $newmenu(Y)]
324    set ttrange($key) [list $newmenu(min) $newmenu(max)]
325    set wave($key) $newmenu(wave)
326    set lblarr($key) $newmenu(label)
327    MakeCascadeMenus
328    plotdata $box 
329}
330
331proc MakeEditProfileBox {base} {
332    grid [label $base.lb7 -text Gaussian] -row 2 -column 1  -columnspan 4
333    grid [label $base.lb8 -text Lorentz] -row 2 -column 6  -columnspan 2
334    grid [label $base.lb1 -text U] -row 3 -column 1
335    grid [label $base.lb2 -text V] -row 3 -column 2 
336    grid [label $base.lb3 -text W] -row 3 -column 3 
337    grid [label $base.lb4 -text P] -row 3 -column 4 
338    grid [label $base.lb5 -text X] -row 3 -column 6 
339    grid [label $base.lb6 -text Y] -row 3 -column 7
340    grid [entry $base.ent1 -textvariable newmenu(U) -width 12] \
341            -row 4 -column 1
342    grid [entry $base.ent2 -textvariable newmenu(V) -width 12] \
343            -row 4 -column 2 
344    grid [entry $base.ent3 -textvariable newmenu(W) -width 12] \
345            -row 4 -column 3 
346    grid [entry $base.ent4 -textvariable newmenu(P) -width 12] \
347            -row 4 -column 4 
348    grid [entry $base.ent5 -textvariable newmenu(X) -width 12] \
349            -row 4 -column 6 
350    grid [entry $base.ent6 -textvariable newmenu(Y) -width 12] \
351            -row 4 -column 7
352
353    grid [label $base.lb9 -text label] -row 5 -column 1  -sticky e
354    grid [entry $base.ent7 -textvariable newmenu(label)]\
355            -row 5 -column 2  -columnspan 3 -sticky ew
356
357    grid [label $base.lb13 -text Wavelength] -row 5 -column 5 -columnspan 2
358    grid [entry $base.ent11 -textvariable newmenu(wave) -width 8] \
359            -row 5 -column 7
360
361    grid [label $base.lb11 -text {2Theta Min}] -row 6 -column 1 
362    grid [entry $base.ent9 -textvariable newmenu(min) -width 9] \
363            -row 6 -column 2
364    grid [label $base.lb12 -text {2Theta Max}] -row 6 -column 3
365    grid [entry $base.ent10 -textvariable newmenu(max) -width 9] \
366            -row 6 -column 4
367    grid rowconfigure $base 5 -weight 0 -pad 40
368    grid columnconfigure $base 5 -weight 0 -minsize 25
369}
370
371proc editAbsValues {key} {
372    global newmenu absSetList lblarr
373
374    set base .edit
375    catch {destroy $base}
376    toplevel $base
377    wm title $base {Edit Absorption Values}
378    MakeEditAbsBox $base
379    grid [button $base.bttn1 -text Apply \
380            -command "SaveAbsorptionEdits $key"] -row 8 -column 6 
381    grid [button $base.bttn2 -text Close \
382            -command "destroy $base"] -row 8 -column 7 
383
384    global ABS
385    foreach v {1 2 opt range label htype} val $ABS($key) {
386        set newmenu($v) $val
387    }
388    foreach {newmenu(min) newmenu(max)} $newmenu(range) {}
389    if {[string range $newmenu(htype) 2 2] == "T"} {
390        set newmenu(units) "TOF (ms):"
391    } elseif {[string range $newmenu(htype) 2 2] == "C"} {
392        set newmenu(units) "2-Theta (deg):"
393    } elseif {[string range $newmenu(htype) 2 2] == "E"} {
394        set newmenu(units) "Energy (KeV):"
395    }
396}
397
398proc SaveAbsorptionEdits {key} {
399    global ABS newmenu box
400    set ABS($key) [list \
401            $newmenu(1) $newmenu(2) $newmenu(opt) \
402            [list $newmenu(min) $newmenu(max)] \
403            $newmenu(label) \
404            [lindex $ABS($key) 5]]
405    plotdata $box 
406}
407
408proc MakeEditAbsBox {base} {
409    grid [label $base.lb1 -text "Absorption Coefficients"] \
410            -row 2 -column 1  -columnspan 2
411    grid [label $base.lb1a -text "1"] -row 3 -column 1
412    grid [label $base.lb2a -text "2"] -row 3 -column 2
413    grid [label $base.lb3 -text Absorption\nFunction] \
414            -row 2 -column 6 -rowspan 2 -columnspan 2
415    grid [entry $base.ent1 -textvariable newmenu(1) -width 12] \
416            -row 4 -column 1
417    grid [entry $base.ent2 -textvariable newmenu(2) -width 12] \
418            -row 4 -column 2 
419    eval tk_optionMenu $base.m1 newmenu(opt) 0 1 2 3 4
420    grid $base.m1 -row 4 -column 6 -columnspan 2
421
422    grid [label $base.lb8 -textvariable newmenu(opttxt) \
423          -wrap 180 -justify left] -row 5 -column 1  -sticky e -columnspan 7
424    grid [label $base.lb9 -text label] -row 7 -column 1  -sticky e
425    grid [entry $base.ent7 -textvariable newmenu(label)]\
426            -row 7 -column 2  -columnspan 3 -sticky ew
427
428    grid [frame $base.f] -row 8 -column 1 -columnspan 4
429    grid [label $base.f.1 -textvariable newmenu(units)] -row 0 -column 1 
430    grid [label $base.f.2 -text {Min}] -row 0 -column 2
431    grid [entry $base.f.3 -textvariable newmenu(min) -width 9] \
432            -row 0 -column 3
433    grid [label $base.f.4 -text {Max}] -row 0 -column 4
434    grid [entry $base.f.5 -textvariable newmenu(max) -width 9] \
435            -row 0 -column 5
436    grid rowconfigure $base 6 -min 15
437}
438
439proc plotdata {top} {
440    global program graph
441    global UVWP XY wave lblarr WidSetList WidDisplay ttrange
442    global ABS absSetList AbsDisplay
443    if {$graph(plotunits) == "d"} {
444        $top xaxis configure -title "d (A)"
445    } elseif {$graph(plotunits) == "q"} {
446        $top xaxis configure -title "Q (A-1)"
447    } elseif {$graph(equivwave) == ""} {
448        $top xaxis configure -title "2Theta"
449    } else {
450        $top xaxis configure -title "2Theta @ $graph(equivwave)"
451    }
452    if {$program == "absplt"} {
453        $top yaxis config -title {Abs. Corr.} 
454    } else {
455        $top yaxis config -title {FWHM} 
456    }
457    $top yaxis configure -min 0 
458    $top xaxis configure -min 0
459    # delete all graphs
460    eval $top element delete [$top element names]
461    set num -1
462    if {$program == "absplt"} {
463        foreach item $absSetList {
464            if {$AbsDisplay($item)} {
465                set ttlist {}
466                set abscor1 [lindex $ABS($item) 0]
467                set abscor2 [lindex $ABS($item) 1]
468                set abstype [lindex $ABS($item) 2]
469                set abslbl [lindex $ABS($item) 4]
470                set htype [lindex $ABS($item) 5]
471                set ttmin [lindex [lindex $ABS($item) 3] 0]
472                set ttmax [lindex [lindex $ABS($item) 3] 1]
473                set ttstep [expr {($ttmax - $ttmin)/50.}]
474                if {$graph(equivwave) == ""} {
475                    if {[string range $htype 2 2] == "T"} {
476                        $top xaxis configure -title "TOF (ms)"
477                    } elseif {[string range $htype 2 2] == "E"} {
478                        $top xaxis configure -title "Energy (KeV)"
479                    }
480                }
481                for     {set tt $ttmin} \
482                        {$tt <= $ttmax} \
483                        {set tt [expr {$tt + $ttstep}]} {
484                    catch {
485                        lappend abslist [AbsorbCalc \
486                                $item $tt $abscor1 $abscor2 $abstype]
487                        lappend ttlist $tt
488                    }
489                }
490                if {[llength $ttlist] == 0} continue
491                if {$graph(plotunits) == "d"} {
492                    set ttlist [tod $ttlist $item]
493                } elseif {$graph(plotunits) == "q"} {
494                    set ttlist [toQ $ttlist $item]
495                }
496                catch {
497                    $top element create $item
498                }
499                $top element config $item -label $abslbl \
500                        -xdata $ttlist -ydata $abslist -linewidth 3 \
501                        -color [nextcolor num]
502            }
503        }
504    } else {
505        foreach item $WidSetList {
506            if {$WidDisplay($item)} {
507                if {[expr [lindex $XY($item) 0] + [lindex $XY($item) 1]] != 0} {
508                    set lflag 1
509                } else {
510                    set lflag 0
511                }
512                set ttlist {}
513                set fwhmlist {}
514                set lfwhmlist {}
515                set tfwhmlist {}
516                # loop over two-theta
517                for     {set tt [lindex $ttrange($item) 0]} \
518                        {$tt <= [lindex $ttrange($item) 1]} \
519                        {set tt [expr $tt + 4]} {
520                    set lfwhm 0
521                    catch {
522                        if {$graph(plotunits) == "d"} {
523                            lappend ttlist [tt2d $wave($item) $tt ]
524                            set gfwhm [deltad $wave($item) $tt \
525                                    [eval FWHM $tt $UVWP($item)]]
526                            lappend fwhmlist $gfwhm
527                            if $lflag {
528                                set lfwhm [deltad $wave($item) $tt \
529                                        [eval LFWHM $tt $XY($item)]]
530                                lappend lfwhmlist $lfwhm
531                            }
532                        } elseif {$graph(plotunits) == "q"} {
533                            lappend ttlist [tt2Q $wave($item) $tt ]
534                            set gfwhm [deltaQ $wave($item) $tt \
535                                    [eval FWHM $tt $UVWP($item)]]
536                            lappend fwhmlist $gfwhm
537                            if $lflag {
538                                set lfwhm [deltaQ $wave($item) $tt \
539                                        [eval LFWHM $tt $XY($item)]]
540                                lappend lfwhmlist $lfwhm
541                            }
542                        } elseif {$graph(equivwave) == ""} {
543                            lappend ttlist $tt
544                            set gfwhm [eval FWHM $tt $UVWP($item)]
545                            lappend fwhmlist $gfwhm
546                            if $lflag {
547                                set lfwhm [eval LFWHM $tt $XY($item)]
548                                lappend lfwhmlist $lfwhm
549                            }
550                        } else {
551                            set tteq [ttequiv $wave($item) $tt $graph(equivwave)]
552                            if {$tteq != ""} {
553                                lappend ttlist $tteq
554                                set gfwhm [delta2teq $wave($item) $tt \
555                                        [eval FWHM $tt $UVWP($item)] $graph(equivwave)]
556                                lappend fwhmlist $gfwhm
557                                if $lflag {
558                                    set lfwhm [delta2teq $wave($item) $tt \
559                                            [eval LFWHM $tt $XY($item)] $graph(equivwave)]
560                                    lappend lfwhmlist $lfwhm
561                                }
562                            }
563                        }
564                        # assume FWHM add as square roots
565                        lappend tfwhmlist \
566                                [expr sqrt($gfwhm*$gfwhm + $lfwhm*$lfwhm)]
567                    }
568                }
569                if $lflag {
570                    catch {
571                        $top element create ${item}G -label "$lblarr($item) G" 
572                    }
573                    $top element config ${item}G \
574                            -xdata $ttlist -ydata $fwhmlist -linewidth 3 \
575                            -color [nextcolor num]
576                    catch {
577                        $top element create ${item}L -label "$lblarr($item) L"
578                    }
579                    $top element config ${item}L \
580                            -xdata $ttlist -ydata $lfwhmlist -linewidth 3 \
581                            -color [nextcolor num]
582                }
583                catch {
584                    $top element create $item -label $lblarr($item) 
585                }
586                $top element config $item \
587                        -xdata $ttlist -ydata $tfwhmlist -linewidth 3 \
588                        -color [nextcolor num]
589            }
590        }
591    }
592}
593proc AbsorbCalc {hst ttof abscor1 abscor2 mode} {
594    global expmap
595    set htype $expmap(htype_$hst)
596    set pi [expr {2.*acos(0.)}]
597    # determine sin(theta) & lambda
598    if {[string range $htype 2 2] == "T"} {
599        set sth [expr {sin($pi * abs([histinfo $hst tofangle])/360.)}]
600        set lamb [expr {2 * [toftod $ttof $hst] * $sth}]
601    } elseif {[string range $htype 2 2] == "C"} {
602        set lamb [histinfo $hst lam1]
603        set sth [expr {sin($pi * ($ttof - [histinfo $hst zero]/100.)/360.)}]
604    } elseif {[string range $htype 2 2] == "E"} {
605        set lamb [expr { 12.398 / $ttof}]
606        set sth [expr {sin($pi * [histinfo $hst lam1] / 360.)}]
607    }
608    set sth2 [expr $sth*$sth]
609    set cth2 [expr {1 - $sth2}]
610    set cth  [expr {sqrt($cth2)}]
611
612    if {$mode == 0} { 
613        set murl [expr {$abscor1 * $lamb}]; # Lobanov & Alte da Veiga
614        if {$murl <= 3} {
615            set TERM0 [expr { 16.0/(3*$pi) }]
616            set TERM1 [expr { (25.99978-0.01911*pow($sth2,0.25)) * \
617                    exp(-0.024551*$sth2) + 0.109561*sqrt($sth2)-26.04556 }]
618            set TERM2 [expr {-0.02489 - 0.39499*$sth2 + \
619                    1.219077*pow($sth2,1.5) - 1.31268*pow($sth2,2) + \
620                    0.871081*pow($sth2,2.5) - 0.2327*pow($sth2,3) }]
621            set TERM3 [expr { 0.003045+0.018167*$sth2 - 0.03305*pow($sth2,2) }]
622            set TRANS [expr { -$TERM0*$murl - $TERM1*pow($murl,2) - \
623                    $TERM2*pow($murl,3) - $TERM3*pow($murl,4) }]
624            if {$TRANS <= -20.0} {
625                set TRANS 2.06E-9
626            } elseif {$TRANS >= 20.0} {
627                set TRANS 4.85E8
628            } else {
629                set TRANS [expr {exp($TRANS)}]
630            }
631        } else {
632            set TERM1 [expr { 1.433902 + 11.07504*$sth2 - \
633                    8.77629*pow($sth2,2) + 10.02088*pow($sth2,3) - \
634                    3.36778*pow($sth2,4) }]
635            set TERM2 [expr { (0.013869 - 0.01249*$sth2) * \
636                    exp(3.27094*$sth2) + \
637                    (0.337894 + 13.77317*$sth2) / \
638                    pow((1.0+11.53544*$sth2),1.555039) }]
639            set TERM3 [expr { 1.933433 / pow((1.0+23.12967*$sth2),1.686715) - \
640                    0.13576*sqrt($sth2) + 1.163198}]
641            set TERM4 [expr { 0.044365 - 0.4259 / \
642                    pow((1.0+0.41051*$sth2),148.4202) }]
643            set TRANS [expr { ($TERM1-$TERM4) / \
644                    pow((1.0+$TERM2*($murl-3.0)),$TERM3) + $TERM4 }]
645            set TRANS [expr { $TRANS/100.0}]
646        }
647    } elseif {$mode == 1} { 
648        #!Simple linear absorption
649        set TRANS [expr { -$abscor1*$lamb }]
650        set TRANS [expr { exp($TRANS) }]
651    } elseif {$mode == 2} { 
652        #!Pitschke, Hermann & Muttern - surface roughness
653        set TERM1 [expr { 1.0/$sth-$abscor2/$sth2 }]
654        set TERM2 [expr { 1.0-$abscor1*(1.0+$abscor2) }]
655        set TRANS [expr { (1.0-$abscor1*$TERM1)/$TERM2 }]
656    } elseif {$mode == 3} { 
657        #!Suortti - surface roughness
658        set TERM1 [expr { exp(-$abscor2/$sth) }]
659        set TERM2 [expr { $abscor1 + (1.0-$abscor1) * exp(-$abscor2) }]
660        set TRANS [expr { ($abscor1 +(1.0-$abscor1) * $TERM1)/$TERM2 }]
661    } elseif {$mode == 4} { 
662        #!Plate transmission absorption
663        if {abs($abscor2) < 1} {
664            #!Use symmetric fxn. if phi 1 deg or less
665            set TRANS [expr { -$abscor1*$lamb/$cth }]
666            set TRANS [expr { exp($TRANS) }]
667        } else {
668            #!Bigger tilts
669            set SPH [expr { sin($pi/180. * $abscor2) }]
670            set CPH [expr { cos($pi/180. * $abscor2) }]
671            set CTPP [expr { $CPH*$cth - $SPH*$sth }]
672            set CTMP [expr { $CPH*$cth + $SPH*$sth }]
673            set T [expr { -$abscor1*$lamb }]
674            set T1 [expr { $T / $CTPP }]
675            set TRANS1 [expr { exp($T1) }]
676            set T2 [expr { $T/$CTMP }]
677            set TRANS2 [expr { exp($T2) }]
678            set TB [expr { $T * (1.0 - $CTMP / $CTPP) }]
679            set TRANS [expr { ($TRANS1 - $TRANS2) / $TB }]
680        }
681    }
682    return $TRANS
683}
684
685# save some of the global options in ~/.gsas_config
686proc SaveOptions {} {
687    global graph  tcl_platform
688    if {$tcl_platform(platform) == "windows"} {
689        set fp [open c:/gsas.config a]
690    } else {
691        set fp [open [file join ~ .gsas_config] a]
692    }
693    puts $fp "# WIDPLT saved options from [clock format [clock ticks]]"
694    puts $fp "set graph(legend) [list $graph(legend)]"
695    puts $fp "set graph(printout) [list $graph(printout)]"
696    puts $fp "set graph(outname) [list $graph(outname)]"
697    puts $fp "set graph(outcmd) [list $graph(outcmd)]"
698    puts $fp "set graph(plotunits) [list $graph(plotunits)]"
699    puts $fp "set graph(equivwave) [list $graph(equivwave)]"
700    close $fp
701}
702
703proc MakeCascadeMenus {} {
704    global WidSetList lblarr box absSetList ABS
705    .a.plot.menu delete 0 end
706    .a.file.menu.edit delete 0 end
707    global program
708    if {$program != "absplt"} {
709        foreach item $WidSetList {
710            .a.plot.menu add checkbutton -label $lblarr($item) \
711                    -command "plotdata $box" -variable WidDisplay($item)
712            .a.file.menu.edit add command -label $lblarr($item) \
713                    -command "editProfileValues $item"
714        }
715    } else {
716        foreach item $absSetList {
717            .a.plot.menu add checkbutton -label [lindex $ABS($item) 4] \
718                    -command "plotdata $box" -variable AbsDisplay($item)
719            .a.file.menu.edit add command -label [lindex $ABS($item) 4] \
720                    -command "editAbsValues $item"
721        }
722    }
723}
724#-------------------------------------------------------------------------
725# converts 2theta(deg) to Q (A-1)
726proc tt2Q {lambda twotheta} {
727    set pi 3.14159
728    set torad [expr $pi / 360.]
729    return [expr 4 * $pi / ($lambda) * sin (($twotheta) * $torad)]
730}
731
732# converts Q (A-1) to 2theta(deg)
733proc Q2tt {lambda Q} {
734    set pi 3.14159
735    set todeg [expr 360. / $pi]
736    set asinarg [expr ($lambda) * $Q * 0.25 / $pi]
737    if {$asinarg <= 1} {
738        return [expr $todeg * asin ($asinarg)]
739    }
740    return {}
741}
742
743# converts a FWHM in 2theta(deg) to a FWHM in Q (A-1)
744proc deltaQ {lambda twotheta FWHM} {
745    return [expr [tt2Q $lambda $twotheta+($FWHM/2.)] - \
746                 [tt2Q $lambda $twotheta-($FWHM/2.)] ]
747}
748
749# converts 2theta(deg) to d (A)
750proc tt2d {lambda twotheta} {
751    set pi 3.14159
752    set torad [expr $pi / 360.]
753    return [expr 0.5 * ($lambda) / sin (($twotheta) * $torad)]
754}
755
756# converts d (A) to 2theta(deg)
757proc d2tt {lambda d} {
758    set pi 3.14159
759    set todeg [expr 360. / $pi]
760    set asinarg [expr ($lambda) * 0.5 / $d]
761    if {$asinarg <= 1} {
762        return [expr $todeg * asin ($asinarg)]
763    }
764    return {}
765}
766
767# converts a FWHM in 2theta(deg) to a FWHM in Q (A-1)
768proc deltad {lambda twotheta FWHM} {
769    return [expr [tt2d $lambda $twotheta-($FWHM/2.)] - \
770                 [tt2d $lambda $twotheta+($FWHM/2.)] ]
771}
772
773# computes an equivalent 2theta at a different wavelength
774proc ttequiv {lambda twotheta lambda_eq} {
775    return [Q2tt $lambda_eq [tt2Q $lambda $twotheta]]
776}
777
778# converts a FWHM in 2theta(deg) to a FWHM at in 2theta
779# at a different wavelength
780proc delta2teq {lambda twotheta FWHM lambda_eq} {
781    return [expr [Q2tt $lambda_eq [tt2Q $lambda $twotheta+($FWHM/2.)]] - \
782                 [Q2tt $lambda_eq [tt2Q $lambda $twotheta-($FWHM/2.)]] ]
783}
784
785# convert x values to d-space
786proc tod {xlist hst} {
787    global expmap
788    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
789        return [toftod $xlist $hst]
790    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
791        return [tttod $xlist $hst]
792    } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
793        return [engtod $xlist $hst]
794    } else {
795        return {}
796    }
797}
798
799# convert tof to d-space
800proc toftod {toflist hst} {
801    set difc [expr {[histinfo $hst difc]/1000.}]
802    set difc2 [expr {$difc*$difc}]
803    set difa [expr {[histinfo $hst difa]/1000.}]
804    set zero [expr {[histinfo $hst zero]/1000.}]
805    set ans {}
806    foreach tof $toflist {
807        if {$tof == 0.} {
808            lappend ans 0.
809        } elseif {$tof == 1000.} {
810            lappend ans 1000.
811        } else {
812            set td [expr {$tof-$zero}]
813            lappend ans [expr {$td*($difc2+$difa*$td)/ \
814                    ($difc2*$difc+2.0*$difa*$td)}]
815        }
816    }
817    return $ans
818}
819
820# convert two-theta to d-space
821proc tttod {twotheta hst} {
822    set lamo2 [expr {0.5 * [histinfo $hst lam1]}]
823    set zero [expr [histinfo $hst zero]/100.]
824    set ans {}
825    set cnv [expr {acos(0.)/180.}]
826    foreach tt $twotheta {
827        if {$tt == 0.} {
828            lappend ans 99999.
829        } elseif {$tt == 1000.} {
830            lappend ans 0.
831        } else {
832            lappend ans [expr {$lamo2 / sin($cnv*($tt-$zero))}]
833        }
834    }
835    return $ans
836}
837
838# convert energy (edx-ray) to d-space
839# (note that this ignores the zero correction)
840proc engtod {eng hst} {
841    set lam [histinfo $hst lam1]
842    set zero [histinfo $hst zero]
843    set ans {}
844    set v [expr {12.398/(2.0*[sind[expr ($lam/2.0)]])}]
845    foreach e $eng {
846        if {$e == 0.} {
847            lappend ans 1000.
848        } elseif {$e == 1000.} {
849            lappend ans 0.
850        } else {
851            lappend ans [expr {$v/$e}]
852        }
853    }
854    return $ans
855}
856
857# convert x values to Q
858proc toQ {xlist hst} {
859    global expmap
860    if {[string range $expmap(htype_$hst) 2 2] == "T"} {
861        return [toftoQ $xlist $hst]
862    } elseif {[string range $expmap(htype_$hst) 2 2] == "C"} {
863        return [tttoQ $xlist $hst]
864    } elseif {[string range $expmap(htype_$hst) 2 2] == "E"} {
865        return [engtoQ $xlist $hst]
866    } else {
867        return {}
868    }
869}
870# convert tof to Q
871proc toftoQ {toflist hst} {
872    set difc [expr {[histinfo $hst difc]/1000.}]
873    set difc2 [expr {$difc*$difc}]
874    set difa [expr {[histinfo $hst difa]/1000.}]
875    set zero [expr {[histinfo $hst zero]/1000.}]
876    set 2pi [expr {4.*acos(0.)}]
877    set ans {}
878    foreach tof $toflist {
879        if {$tof == 0.} {
880            lappend ans 99999.
881        } elseif {$tof == 1000.} {
882            lappend ans 0.
883        } else {
884            set td [expr {$tof-$zero}]
885            lappend ans [expr {$2pi * \
886                    ($difc2*$difc+2.0*$difa*$td)/($td*($difc2+$difa*$td))}]
887        }
888    }
889    return $ans
890}
891
892# convert two-theta to Q
893proc tttoQ {twotheta hst} {
894    set lamo2 [expr {0.5 * [histinfo $hst lam1]}]
895    set zero [expr [histinfo $hst zero]/100.]
896    set ans {}
897    set cnv [expr {acos(0.)/180.}]
898    set 2pi [expr {4.*acos(0.)}]
899    foreach tt $twotheta {
900        if {$tt == 0.} {
901            lappend ans 0.
902        } elseif {$tt == 1000.} {
903            lappend ans 1000.
904        } else {
905            lappend ans [expr {$2pi * sin($cnv*($tt-$zero)) / $lamo2}]
906        }
907    }
908    return $ans
909}
910# convert energy (edx-ray) to Q
911# (note that this ignores the zero correction)
912proc engtoQ {eng hst} {
913    set lam [histinfo $hst lam1]
914    set zero [histinfo $hst zero]
915    set ans {}
916    set v [expr {12.398/(2.0*[sind[expr ($lam/2.0)]])}]
917    set 2pi [expr {4.*acos(0.)}]
918    foreach e $eng {
919        if {$e == 0.} {
920            lappend ans 0.
921        } elseif {$e == 1000.} {
922            lappend ans 1000.
923        } else {
924            lappend ans [expr {$2pi * $e / $v}]
925        }
926    }
927    return $ans
928}
929proc sind {angle} {
930    return [expr {sin($angle*acos(0.)/90.)}]
931}
932
933proc FWHM {tt U V W P} {
934    set pi 3.14159
935    set torad [expr $pi / 360.]
936    # tan theta
937    set tantt [expr tan($tt * $torad ) ]
938    set costt [expr cos($tt * $torad ) ]
939    return [expr sqrt \
940            (8.* log(2) * ($U * $tantt * $tantt + $V * $tantt + $W \
941            + $P / ($costt * $costt))) / 100.]
942}
943proc LFWHM {tt X Y} {
944    set pi 3.14159
945    set torad [expr $pi / 360.]
946    # tan theta
947    set tantt [expr tan($tt * $torad ) ]
948    set costt [expr cos($tt * $torad ) ]
949    return [expr ($X / $costt + $Y * $tantt) / 100.]
950}
951
952proc setlegend {box legend} {
953    global blt_version
954    if {$blt_version >= 2.3 && $blt_version < 8.0} {
955        if $legend {
956            $box legend config -hide no
957        } else {
958            $box legend config -hide yes
959        }
960    } else {
961        if $legend {
962            $box legend config -mapped yes
963        } else {
964            $box legend config -mapped no
965        }
966    }
967}
968
969#-------------------------------------------------------------------------
970# export current plot to Grace
971#-------------------------------------------------------------------------
972if {$tcl_platform(platform) == "unix"} {
973    set graph(GraceFile) /tmp/grace_out.agr
974} else {
975    set graph(GraceFile) C:/graceout.agr
976}
977proc exportgrace {} {
978    global graph box
979    global tcl_platform graph
980    catch {toplevel .export}
981    raise .export
982    eval destroy [grid slaves .export]
983    set col 5
984    grid [label .export.1a -text Title:] -column 1 -row 1
985    set graph(title) [$box cget -title]
986    grid [entry .export.1b -width 60 -textvariable graph(title)] \
987            -column 2 -row 1 -columnspan 4
988    grid [label .export.2a -text Subtitle:] -column 1 -row 2
989    grid [entry .export.2b -width 60 -textvariable graph(subtitle)] \
990            -column 2 -row 2 -columnspan 4
991    grid [label .export.3a -text "File name:"] -column 1 -row 3
992    grid [entry .export.3b -width 60 -textvariable graph(GraceFile)] \
993            -column 2 -row 3 -columnspan 4
994    grid [button .export.help -text Help -bg yellow \
995            -command "MakeWWWHelp liveplot.html grace"] \
996            -column [incr col -1] -row 4
997    grid [button .export.c -text "Close" \
998            -command "set graph(export) 0; destroy .export"] \
999            -column [incr col -1] -row 4
1000    if {$tcl_platform(platform) == "unix" && [auto_execok xmgrace] != ""} {
1001        grid [button .export.d -text "Export & \nstart grace" \
1002            -command "set graph(export) 1; destroy .export"] \
1003                -column [incr col -1] -row 4
1004    }
1005    grid [button .export.e -text "Export" \
1006            -command "set graph(export) 2; destroy .export"] \
1007            -column [incr col -1] -row 4
1008    tkwait window .export
1009    if {$graph(export) == 0} return
1010    if {[catch {
1011        set fp [open $graph(GraceFile) w]
1012        puts $fp [output_grace $box $graph(title) $graph(subtitle)]
1013        close $fp
1014    } errmsg]} {
1015        MyMessageBox -parent . -title "Export Error" \
1016                -message "An error occured during the export: $errmsg" \
1017                -icon error -type Ignore -default ignore
1018        return
1019    }
1020
1021    if {$graph(export) == 1} {
1022        set err [catch {exec xmgrace $graph(GraceFile) &} errmsg]
1023        if $err {
1024        MyMessageBox -parent . -title "Grace Error" \
1025                -message "An error occured launching grace (xmgrace): $errmsg" \
1026                -icon error -type Ignore -default ignore
1027        }
1028    } else {
1029        MyMessageBox -parent . -title "OK" \
1030                -message "File $graph(GraceFile) created" \
1031                -type OK -default ok
1032    }
1033}
1034#-------------------------------------------------------------------------
1035# export current plot as .csv file
1036#-------------------------------------------------------------------------
1037proc makecsvfile {} {
1038    global graph box expnam program
1039    global tcl_platform graph
1040    set typelist {
1041        {{Comma separated} {.csv}        }
1042        {{Text File}       {.txt}        }
1043    }
1044    set file [tk_getSaveFile -filetypes $typelist \
1045            -initialfile ${expnam}_$program.csv]
1046    if {$file == ""} return
1047    set varlist {}
1048    set line {}
1049    foreach element_name [$box element names] {
1050        lappend varlist ${element_name}_x
1051        set ${element_name}_x [$box element cget $element_name -xdata]
1052        lappend varlist ${element_name}_y
1053        set ${element_name}_y [$box element cget $element_name -ydata]
1054        append line [$box element cget $element_name -label] "-X, "
1055        append line [$box element cget $element_name -label] "-Y, "
1056    }
1057    set fp [open $file w]
1058    # get x and y axis limits
1059    foreach v {x y} {
1060        foreach "${v}min ${v}max" [$box ${v}axis limits] {}
1061        puts $fp "\"$v axis range [set ${v}min] to [set ${v}max]\""
1062        puts $fp "\"$v axis label [$box ${v}axis cget -title]\""
1063    }
1064    puts $fp $line
1065    set i 0
1066    set done 1
1067    while {$done} {
1068        set line {}
1069        set done 0
1070        foreach var $varlist {
1071            set val [lindex [set $var] $i]
1072            if {$val != ""} {set done 1}
1073            append line "$val, "
1074        }
1075        if {$done} {puts $fp $line}
1076        incr i
1077    }
1078    close $fp
1079}
1080
1081
1082set graph(legend) 0
1083set graph(equivwave) {}
1084set graph(plotunits) tt
1085if {$tcl_platform(platform) == "windows"} {
1086    set graph(printout) 1
1087} else {
1088    set graph(printout) 0
1089}
1090set graph(outname) out.ps
1091set graph(outcmd) lpr
1092set WidSetList {}
1093set absSetList {}
1094
1095#----------------------------------------------------------------
1096# find location of other files relative to the current script
1097# 1st, translate links -- go six levels deep
1098foreach i {1 2 3 4 5 6} {
1099    if {[file type $expgui(script)] == "link"} {
1100        set link [file readlink $expgui(script)]
1101        if { [file  pathtype  $link] == "absolute" } {
1102h           set expgui(script) $link
1103        } {
1104            set expgui(script) [file dirname $expgui(script)]/$link
1105        }
1106    } else {
1107        break
1108    }
1109}
1110# fixup relative paths
1111if {[file pathtype $expgui(script)] == "relative"} {
1112    set expgui(script) [file join [pwd] $expgui(script)]
1113}
1114set expgui(scriptdir) [file dirname $expgui(script) ]
1115set expgui(docdir) [file join $expgui(scriptdir) doc]
1116# location for web pages, if not found locally
1117set expgui(website) www.ncnr.nist.gov/xtal/software/expgui
1118
1119# fetch EXP file processing routines
1120source [file join $expgui(scriptdir) readexp.tcl]
1121source [file join $expgui(scriptdir) gsascmds.tcl]
1122
1123# override options with locally defined values
1124set filelist [file join $expgui(scriptdir) localconfig]
1125if {$tcl_platform(platform) == "windows"} {
1126    lappend filelist "c:/gsas.config"
1127} else {
1128    lappend filelist [file join ~ .gsas_config]
1129}
1130if {[catch {
1131    foreach file $filelist {
1132        if [file exists $file] {source $file}
1133    }
1134} errmsg]} {
1135    set msg "Error reading file $file (aka [file nativename $file]): $errmsg"
1136    MyMessageBox -parent . -title "Customize warning" \
1137        -message $msg -icon warning -type Ignore -default ignore \
1138        -helplink "expguierr.html Customizewarning"
1139}
1140#----------------------------------------------------------------
1141
1142set datalist {}
1143foreach file [glob -nocomplain [file join $expgui(scriptdir) widplt_*]] {
1144    source $file
1145}
1146set WidSetList $datalist
1147
1148# create the graph
1149if [catch {
1150    set box [graph .g]
1151} errmsg] {
1152    tk_dialog .err "BLT Error" \
1153"BLT Setup Error: could not create a graph (msg: $errmsg). \
1154There is a problem with the setup of BLT on your system.
1155See the expgui.html file for more info." \
1156            error 0 "Quit"
1157exit
1158}
1159if [catch {
1160    Blt_ZoomStack $box
1161    Blt_ActiveLegend $box
1162    Blt_ClosestPoint $box
1163} errmsg] {
1164    tk_dialog .err "BLT Error" \
1165"BLT Setup Error: could not access a Blt_ routine (msg: $errmsg). \
1166The pkgIndex.tcl is probably not loading bltGraph.tcl.
1167See the expgui.html file for more info." \
1168            error 0 "Limp ahead"
1169}
1170$box config -title {}
1171setlegend $box $graph(legend)
1172
1173#frame .a -bd 8 -relief groove
1174frame .a -bd 2 -relief groove
1175
1176pack [menubutton .a.file -text File -underline 0 -menu .a.file.menu] -side left
1177menu .a.file.menu
1178pack [menubutton .a.plot -text "Plot Contents" -underline 0 -menu .a.plot.menu] -side left
1179menu .a.plot.menu
1180#.a.file.menu add cascade -label Tickmarks -menu .a.file.menu.tick
1181if {$expnam != ""} {
1182    .a.file.menu add command -label "Reload from EXP" \
1183            -command "getprofiles $expnam; plotdata $box"
1184}
1185if {$program == "absplt"} {
1186    .a.file.menu add cascade -label "Edit Abs Params" -menu .a.file.menu.edit
1187} else {
1188    .a.file.menu add command -label "Add New Curve" -command NewProfileValues
1189    .a.file.menu add cascade -label "Edit Curve" -menu .a.file.menu.edit
1190}
1191#.a.file.menu add command -label "Make PostScript" -command makepostscriptout
1192menu .a.file.menu.edit
1193.a.file.menu add cascade -label "Export plot" -menu .a.file.menu.export
1194menu .a.file.menu.export
1195.a.file.menu.export add command -label "Make PostScript" \
1196    -command makepostscriptout
1197if {$blt_version > 2.3 && $blt_version != 8.0} {
1198    source [file join $expgui(scriptdir) graceexport.tcl]
1199    .a.file.menu.export add command -label "to Grace" -command exportgrace
1200}
1201.a.file.menu.export add command -label "as .csv file" \
1202        -command makecsvfile
1203.a.file.menu add command -label Quit -command "destroy ."
1204pack [menubutton .a.options -text Options -underline 0 -menu .a.options.menu] \
1205        -side left   
1206menu .a.options.menu
1207if {$program == "absplt"} {
1208    .a.options.menu add radiobutton -label "2Theta/Tof/Eng" -value tt \
1209            -variable graph(plotunits) \
1210            -command "plotdata $box"
1211} else {
1212    .a.options.menu add radiobutton -label "2Theta" -value tt \
1213            -variable graph(plotunits) \
1214            -command "plotdata $box"
1215    .a.options.menu add command -label "Set Equiv. Wavelength" \
1216            -command "seteqwave $box"
1217}
1218.a.options.menu add radiobutton -label "d-space" -value d \
1219        -variable graph(plotunits) \
1220        -command "plotdata $box"
1221.a.options.menu add radiobutton -label "Q" -value q \
1222        -variable graph(plotunits) \
1223        -command "plotdata $box"
1224.a.options.menu add checkbutton -label "Include legend" \
1225        -variable graph(legend) \
1226        -command {setlegend $box $graph(legend)}
1227.a.options.menu add command -label "Set PS output" \
1228        -command setpostscriptout
1229.a.options.menu add command -label "Save Options" -underline 1 \
1230        -command "SaveOptions"
1231
1232pack [menubutton .a.help -text Help -underline 0 -menu .a.help.menu] -side right
1233menu .a.help.menu -tearoff 0
1234if {$program == "absplt"}  {
1235    .a.help.menu add command -command "MakeWWWHelp expgui.html ABSPLT" \
1236            -label "Web page"
1237} else {
1238    .a.help.menu add command -command "MakeWWWHelp expgui.html WIDPLT" \
1239            -label "Web page"
1240}
1241if {![catch {package require tkcon} errmsg]} {
1242    .a.help.menu add command -label "Open console" -command {tkcon show}
1243} elseif {$tcl_platform(platform) == "windows"} {
1244    .a.help.menu add command -label "Open console" -command {console show}
1245}
1246.a.help.menu add command -command aboutwidplot -label About
1247
1248pack .a -side top -fill both
1249pack $box -fill both -expand yes
1250
1251#----------------------------------------------------------------
1252# OK now go get the profile info
1253getprofiles $expnam
1254#----------------------------------------------------------------
1255
1256    trace variable newmenu(opt) w setoptmsg
1257
1258proc setoptmsg {args} {
1259    global newmenu
1260    array set opttxt {
1261        0 "Cylindrical samples, Lobanov & Alte da Veiga (TOF, CW, synch.)"
1262        1 "Simple linear (TOF)"
1263        2 "Surface Roughness, Pitschke, Hermann & Muttern (Bragg-Brentano)"
1264        3 "Surface Roughness, Suortti (Bragg-Brentano)"
1265        4 "Flat plate, transmission mode"
1266    }
1267    set newmenu(opttxt) ""
1268    catch {set newmenu(opttxt) [set opttxt($newmenu(opt))]}
1269}
1270set datanum 0
1271# seems to be needed in OSX
1272update
1273wm geom . [winfo reqwidth .]x[winfo reqheight .]
1274#
1275donewaitmsg
Note: See TracBrowser for help on using the repository browser.