Changeset 447 for trunk/addcmds.tcl
- Timestamp:
- Dec 4, 2009 5:06:19 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/addcmds.tcl
- Property rcs:date changed from 2001/09/04 22:01:55 to 2001/09/25 23:25:21
- Property rcs:lines changed from +7 -3 to +350 -56
- Property rcs:rev changed from 1.21 to 1.22
r413 r447 1 1 # $Id$ 2 3 #----------- Add Phase routines ---------------------------------------- 2 4 3 5 proc MakeAddPhaseBox {} { … … 147 149 $np.error \ 148 150 "Error processing space group\nReview error message below" \ 149 $b 151 $b OK "" 1 150 152 set expgui(oldphaselist) -1 151 153 return … … 190 192 } errmsg 191 193 # load the revised exp file 194 set oldphaselist $expmap(phaselist) 192 195 loadexp $expgui(expfile) 193 196 set fp [open exptool.out r] … … 195 198 close $fp 196 199 destroy $np 200 set err 0 201 if {[llength $oldphaselist] == [llength $expmap(phaselist)]} {set err 1} 197 202 if {$errmsg != ""} { 203 set err 1 198 204 append errmsg "\n" $out 199 205 } else { 200 206 set errmsg $out 201 207 } 202 if {$expgui(showexptool)} { 203 ShowBigMessage \ 204 $np \ 205 "Please review the result from adding the phase" \ 206 $errmsg 208 if {$expgui(showexptool) || $err} { 209 set msg "Please review the result from adding the phase" 210 if {$err} {append msg "\nIt appears an error occurred!"} 211 ShowBigMessage $np $msg $errmsg OK "" $err 207 212 } 208 213 file delete exptool.in exptool.out … … 211 216 } 212 217 218 #----------- Add Histogram routines -------------------------------------- 213 219 proc MakeAddHistBox {} { 214 220 global expmap newhist … … 222 228 bind $np <Key-F1> "MakeWWWHelp expgui3.html AddHist" 223 229 224 grid [label $np.l0 -text "Adding new histogram"] \230 grid [label $np.l0 -text "Adding a new histogram"] \ 225 231 -column 0 -row 0 -sticky ew -columnspan 7 226 grid [label $np.l1 -text "Data file:"] -column 0 -row 1 232 grid [checkbutton $np.d0 -text "Dummy Histogram" -variable newhist(dummy) \ 233 -command "PostDummyOpts $np" \ 234 ] -column 2 -row 0 -columnspan 99 -sticky e 235 grid [label $np.l1 -text "Data file:"] -column 0 -row 2 227 236 grid [label $np.t1 -textvariable newhist(rawfile) -bd 2 -relief ridge] \ 228 -column 1 -row 1-columnspan 3 -sticky ew237 -column 1 -row 2 -columnspan 3 -sticky ew 229 238 grid [button $np.b1 -text "Select File" \ 230 239 -command "getrawfile $np" \ 231 ] -column 4 -row 1232 233 grid [label $np.lbank -text "Select bank" -anchor w] -column 1 -row 2-sticky w234 grid [frame $np.bank] -column 2 -row 2-columnspan 7 -sticky ew235 236 grid [label $np.l2 -text "Instrument\nParameter file:"] -column 0 -row 3240 ] -column 4 -row 2 241 242 grid [label $np.lbank -text "Select bank" -anchor w] -column 1 -row 3 -sticky w 243 grid [frame $np.bank] -column 2 -row 3 -columnspan 7 -sticky ew 244 245 grid [label $np.l2 -text "Instrument\nParameter file:"] -column 0 -row 5 237 246 grid [label $np.t2 -textvariable newhist(instfile) -bd 2 -relief ridge] \ 238 -column 1 -row 3-columnspan 3 -sticky ew247 -column 1 -row 5 -columnspan 3 -sticky ew 239 248 grid [button $np.b2 -text "Select File" \ 240 249 -command "getinstfile $np" \ 241 ] -column 4 -row 3 242 243 grid [label $np.lset -text "Select set" -anchor w] -column 1 -row 4 -sticky w 244 grid [frame $np.set] -column 2 -row 4 -columnspan 7 -sticky ew 245 246 grid [label $np.l3 -text "Usable data limit:"] -column 0 -row 5 -rowspan 2 250 ] -column 4 -row 5 251 252 grid [label $np.lset -text "Select set" -anchor w] -column 1 -row 6 -sticky w 253 grid [frame $np.set] -column 2 -row 6 -columnspan 7 -sticky ew 254 255 grid [button $np.f6a -text "Run\nRAWPLOT" -command RunRawplot] \ 256 -column 4 -row 8 -rowspan 2 257 grid [label $np.l3 -text "Usable data limit:"] -column 0 -row 8 -rowspan 2 247 258 grid [entry $np.e3 -width 12 -textvariable newhist(2tLimit) \ 248 ] -column 1 -row 5-rowspan 2259 ] -column 1 -row 8 -rowspan 2 249 260 grid [radiobutton $np.cb3 -text "D-min" -variable newhist(LimitMode) \ 250 -value 0] -column 2 -row 5-sticky w251 grid [radiobutton $np.cb4 -text "TOF-min\n2-Theta Max"\261 -value 0] -column 2 -row 8 -sticky w 262 grid [radiobutton $np.cb4 -textvariable newhist(limitLbl) \ 252 263 -variable newhist(LimitMode) -anchor w -justify l \ 253 -value 1] -column 2 -row 6 -sticky w 254 255 grid [frame $np.f6] -column 0 -row 7 -columnspan 5 -sticky ew 264 -value 1] -column 2 -row 9 -sticky w 265 set newhist(limitLbl) "TOF-min\n2-Theta Max" 266 # spacers 267 grid [frame $np.sp0 -bg white] \ 268 -columnspan 20 -column 0 -row 1 -sticky nsew -ipady 2 269 grid [frame $np.sp1 -bg white] \ 270 -columnspan 20 -column 0 -row 4 -sticky nsew -ipady 2 271 grid [frame $np.sp2 -bg white] \ 272 -columnspan 20 -column 0 -row 7 -sticky nsew -ipady 2 273 grid [frame $np.sp3 -bg white] \ 274 -columnspan 20 -column 0 -row 98 -sticky nsew -ipady 2 275 grid [frame $np.f6] -column 0 -row 99 -columnspan 5 -sticky ew 256 276 grid [button $np.f6.b6a -text Add \ 257 277 -command "addhist $np"] -column 0 -row 0 … … 263 283 -column 2 -row 0 -sticky e 264 284 grid columnconfigure $np.f6 2 -weight 1 265 266 grid [button $np.f6a -text "Run\nRAWPLOT" -command RunRawplot] \267 -column 4 -row 5 -rowspan 2268 269 285 grid columnconfigure $np 3 -weight 1 270 286 287 # dummy histogram stuff 288 frame $np.d1 289 grid [label $np.d1.l1 -text min] -col 1 -row 1 290 grid [label $np.d1.l2 -text max] -col 2 -row 1 291 grid [label $np.d1.l3 -text step] -col 3 -row 1 292 grid [label $np.d1.lu -text ""] -col 4 -row 1 -rowspan 2 293 grid [entry $np.d1.e1 -width 10 -textvariable newhist(tmin)] -col 1 -row 2 294 grid [entry $np.d1.e2 -width 10 -textvariable newhist(tmax)] -col 2 -row 2 295 grid [entry $np.d1.e3 -width 10 -textvariable newhist(tstep)] -col 3 -row 2 296 grid [label $np.d1.m1 -anchor w] -col 1 -row 3 -sticky ew 297 grid [label $np.d1.m2 -anchor w] -col 2 -row 3 -sticky ew 298 label $np.dl1 -text "Data range:" 299 label $np.dl2 -text "Allowed" 300 label $np.dl3 -text "\n" -justify left -fg blue 271 301 wm title $np "add new histogram" 272 302 303 set newhist(banknum) {} 304 set newhist(setnum) {} 273 305 if {[string trim $newhist(rawfile)] != {}} { 274 306 validaterawfile $np $newhist(rawfile) … … 277 309 validateinstfile $np $newhist(instfile) 278 310 } 279 set newhist(banknum) {} 280 set newhist(setnum) {} 281 # for {set i 0} {$i<100} {incr i} {set newhist(bank$i) 0} 282 # for {set i 0} {$i<100} {incr i} {set newhist(set$i) 0} 283 311 312 PostDummyOpts $np 284 313 # set grab, etc. 285 314 putontop $np … … 487 516 ] 488 517 } 518 set newhist(setnum) {} 489 519 validateinstfile $np $inp 490 520 } … … 534 564 } 535 565 } 566 # scan for the instrument constants 567 if {[regexp {INS ([ 1-9][0-9]) ICONS(.*)} $line a b c]} { 568 set b [string trim $b] 569 set newhist(inst${b}ICONS) [string trim $c] 570 } 571 if {[regexp {INS ([ 1-9][0-9])I ITYP(.*)} $line a b c]} { 572 set b [string trim $b] 573 set newhist(inst${b}ITYP) [string trim $c] 574 } 536 575 } 537 576 # were banks found? … … 556 595 } 557 596 grid [radiobutton $np.set.$i -text $i \ 597 -command "PostDummyOpts $np; ValidateDummyHist $np" \ 558 598 -variable newhist(setnum) -value $i] \ 559 599 -column [incr col] -row $row -sticky w 560 561 600 if {$newhist(instbanks) == 1} {set newhist(setnum) $i} 562 601 } 602 if {$newhist(dummy)} {PostDummyOpts $np; ValidateDummyHist $np} 563 603 } 564 604 565 605 proc addhist {np} { 566 global expgui newhist tcl_platform 606 global expgui newhist tcl_platform expmap 607 if {$newhist(dummy)} { 608 AddDummyHist $np 609 return 610 } 567 611 # validate the input 568 612 set err {} … … 638 682 } errmsg 639 683 # load the revised exp file 684 set oldpowderlist $expmap(powderlist) 640 685 loadexp $expgui(expfile) 641 686 set fp [open exptool.out r] … … 643 688 close $fp 644 689 destroy $np 690 set err 0 691 if {[llength $oldpowderlist] == [llength $expmap(powderlist)]} {set err 1} 645 692 if {$errmsg != ""} { 646 693 append errmsg "\n" $out 694 set err 1 647 695 } else { 648 696 set errmsg $out 649 697 } 650 if {$expgui(showexptool)} { 651 ShowBigMessage \ 652 $np \ 653 "Please review the result from adding the phase" \ 654 $errmsg 698 if {$expgui(showexptool) || $err} { 699 set msg "Please review the result from adding the histogram" 700 if {$err} {append msg "\nIt appears an error occurred!"} 701 ShowBigMessage $np $msg $errmsg OK "" $err 655 702 } 656 703 file delete exptool.in exptool.out … … 677 724 runGSASprog rawplot 1 678 725 } 679 726 #--- Dummy histogram stuff 727 proc PostDummyOpts {np} { 728 global newhist 729 if {$newhist(dummy)} { 730 trace variable newhist(tmin) w "ValidateDummyHist $np" 731 trace variable newhist(tmax) w "ValidateDummyHist $np" 732 trace variable newhist(tstep) w "ValidateDummyHist $np" 733 foreach w {l1 t1 lbank} { 734 $np.$w config -fg grey 735 } 736 $np.b1 config -state disabled 737 grid forget $np.l3 $np.e3 $np.cb3 $np.cb4 $np.bank $np.f6a 738 grid $np.dl1 -column 0 -row 8 739 grid $np.d1 -column 1 -row 8 -rowspan 2 -columnspan 4 -sticky e 740 grid $np.dl3 -column 0 -columnspan 99 -row 10 -sticky ew 741 if {$newhist(insttype) == "TOF"} { 742 $np.dl1 config -text "Data range:\n(TOF)" 743 $np.d1.lu config -text millisec 744 grid $np.dl2 -column 0 -row 9 745 catch { 746 foreach {x tmin tmax x} $newhist(inst${newhist(setnum)}ITYP) {} 747 $np.d1.m1 config -text $tmin 748 $np.d1.m2 config -text $tmax 749 } 750 } elseif {$newhist(insttype) == "CW"} { 751 $np.dl1 config -text "Data range:\n(2Theta)" 752 $np.d1.lu config -text degrees 753 #grid forget $np.dl2 754 $np.d1.m1 config -text >0. 755 $np.d1.m2 config -text <180. 756 } else { 757 $np.dl1 config -text "Data range:\n(Energy)" 758 $np.d1.lu config -text KeV 759 $np.d1.m1 config -text 1. 760 $np.d1.m2 config -text 200. 761 grid $np.dl2 -column 0 -row 9 762 } 763 } else { 764 foreach var {tmin tmax tstep} { 765 foreach v [ trace vinfo newhist($var)] { 766 eval trace vdelete newhist($var) $v 767 } 768 } 769 grid forget $np.dl1 $np.d1 $np.dl2 $np.dl3 770 foreach w {l1 t1 lbank} { 771 $np.$w config -fg black 772 } 773 $np.b1 config -state normal 774 grid $np.bank -column 2 -row 3 -columnspan 7 -sticky ew 775 grid $np.f6a -column 4 -row 8 -rowspan 2 776 grid $np.l3 -column 0 -row 8 -rowspan 2 777 grid $np.e3 -column 1 -row 8 -rowspan 2 778 grid $np.cb3 -column 2 -row 8 -sticky w 779 grid $np.cb4 -column 2 -row 9 -sticky w 780 } 781 } 782 783 proc ValidateDummyHist {np args} { 784 # validate input 785 global newhist 786 set msg {} 787 $np.dl3 config -text "\n" 788 foreach e {e1 e2 e3} v {tmin tmax tstep} { 789 if [catch {expr $newhist($v)}] { 790 $np.d1.$e config -fg red 791 append msg "Value of $newhist($v) is invalid for $v\n" 792 } else { 793 $np.d1.$e config -fg black 794 } 795 } 796 if {[catch {expr $newhist(setnum)}]} { 797 append msg "An instrument file bank number must be selected\n" 798 } elseif {$newhist(setnum) <= 0 || \ 799 $newhist(setnum) > $newhist(instbanks)} { 800 append msg "An invalid instrument file bank has been selected\n" 801 } 802 803 if {$msg != ""} {return $msg} 804 805 if {$newhist(tmax) <= $newhist(tmin)} { 806 $np.d1.e1 config -fg red 807 $np.d1.e2 config -fg red 808 return "Tmax <= Tmin\n" 809 } 810 811 812 set dmin -1 813 set dmax -1 814 if {$newhist(insttype) == "TOF"} { 815 catch { 816 foreach {x tmin tmax x} $newhist(inst${newhist(setnum)}ITYP) {} 817 if {$newhist(tmin) <$tmin } { 818 $np.d1.e1 config -fg red 819 append msg "Min value of $newhist(tmin) msec is invalid.\n" 820 } 821 if {$newhist(tmax) >$tmax } { 822 $np.d1.e2 config -fg red 823 append msg "Max value of $newhist(tmax) msec is invalid.\n" 824 } 825 set dmin [expr {1000. * $newhist(tmin) / \ 826 [lindex $newhist(inst${newhist(setnum)}ICONS) 0]}] 827 set dmax [expr {1000. * $newhist(tmax) / \ 828 [lindex $newhist(inst${newhist(setnum)}ICONS) 0]}] 829 } 830 } elseif {$newhist(insttype) == "CW"} { 831 if {$newhist(tmin) <= 0 } { 832 $np.d1.e1 config -fg red 833 append msg "Min value of $newhist(tmin) degrees is invalid.\n" 834 } 835 if {$newhist(tmax) >=180 } { 836 $np.d1.e2 config -fg red 837 append msg "Max value of $newhist(tmax) degrees is invalid.\n" 838 } 839 catch { 840 set dmin [expr {[lindex $newhist(inst${newhist(setnum)}ICONS) 0]\ 841 * 0.5 / sin(acos(0.)*$newhist(tmax)/180.)}] 842 set dmax [expr {[lindex $newhist(inst${newhist(setnum)}ICONS) 0]\ 843 * 0.5 / sin(acos(0.)*$newhist(tmin)/180.)}] 844 } 845 } else { 846 if {$newhist(tmin) <1 } { 847 $np.d1.e1 config -fg red 848 append msg "Min value of $newhist(tmin) KeV is invalid.\n" 849 } 850 if {$newhist(tmax) >200 } { 851 $np.d1.e2 config -fg red 852 append msg "Max value of $newhist(tmax) KeV is invalid.\n" 853 } 854 catch { 855 set ang [lindex $newhist(inst${newhist(setnum)}ICONS) 0] 856 set dmin [expr {12.398/ (2.0*sin($ang*acos(0.)/180) * \ 857 $newhist(tmax))}] 858 set dmax [expr {12.398/ (2.0*sin($ang*acos(0.)/180) * \ 859 $newhist(tmin))}] 860 } 861 } 862 if {$msg != ""} {return $msg} 863 set pnts -1 864 catch { 865 set pnts [expr {1+int(($newhist(tmax) - $newhist(tmin))/$newhist(tstep))}] 866 set qmin [expr {4.*acos(0)/$dmax}] 867 set qmax [expr {4.*acos(0)/$dmin}] 868 } 869 if {$pnts <= 0} { 870 $np.d1.e3 config -fg red 871 append msg "Step value of $newhist(tstep) is invalid.\n" 872 } 873 if {$pnts >20000} { 874 $np.d1.e3 config -fg red 875 append msg "Step value of $newhist(tstep) is too small (>20000 points).\n" 876 } 877 if {$msg != ""} {return $msg} 878 if {$dmin > 0 && $dmax > 0} { 879 catch { 880 set msg [format \ 881 { %d points.%s D-space range: %.2f-%.2f A, Q: %.2f-%.2f/A} \ 882 $pnts "\n" $dmin $dmax $qmin $qmax] 883 $np.dl3 config -text $msg 884 } 885 } 886 if {$msg != ""} {return ""} 887 $np.dl3 config -text [format { %d points.%s Range: ?} $pnts "\n"] 888 return "Invalid data range -- something is wrong!" 889 } 890 891 proc AddDummyHist {np} { 892 global newhist expgui expmap 893 global tcl_platform 894 set msg [ValidateDummyHist $np] 895 if {$msg != ""} { 896 MyMessageBox -parent $np -title "Add Histogram Error" \ 897 -message "The following error(s) were found in your input:\n$msg" \ 898 -icon error -type ok -default ok \ 899 -helplink "expgui3.html AddHistErr" 900 return 901 } 902 set fp [open exptool.in w] 903 puts $fp "D" 904 puts $fp $newhist(instfile) 905 puts $fp $newhist(setnum) 906 if {$newhist(insttype) == "TOF"} { 907 puts $fp "C" 908 } 909 puts $fp $newhist(tmin) 910 puts $fp $newhist(tmax) 911 puts $fp $newhist(tstep) 912 puts $fp "X" 913 puts $fp "0" 914 close $fp 915 # Save the current exp file 916 savearchiveexp 917 # disable the file changed monitor 918 set expgui(expModifiedLast) 0 919 set expnam [file root [file tail $expgui(expfile)]] 920 set err [catch { 921 if {$tcl_platform(platform) == "windows"} { 922 exec [file join $expgui(gsasexe) exptool.exe] $expnam \ 923 < exptool.in >& exptool.out 924 } else { 925 exec [file join $expgui(gsasexe) exptool] $expnam \ 926 < exptool.in >& exptool.out 927 } 928 } errmsg ] 929 # load the revised exp file 930 set oldpowderlist $expmap(powderlist) 931 loadexp $expgui(expfile) 932 set fp [open exptool.out r] 933 set out [read $fp] 934 close $fp 935 if {[llength $oldpowderlist] == [llength $expmap(powderlist)]} {set err 1} 936 if {$errmsg != ""} { 937 append errmsg "\n" $out 938 } else { 939 set errmsg $out 940 } 941 if {[regexp {\(P,H,A\)} $out]} { 942 set msg {You must upgrade the EXPTOOL program.} 943 append msg { This version cannot add dummy histograms.} 944 MyMessageBox -icon error -title "Old EXPTOOL program" \ 945 -message $msg -parent $np \ 946 -helplink "expguierr.html OldEXPTOOL" 947 # update the documentation & link 948 destroy $np 949 } elseif {$expgui(showexptool) || $err} { 950 set msg "Please review the result from adding the dummy histogram" 951 if {$err} {append msg "\nIt appears an error occurred!"} 952 ShowBigMessage $np $msg $errmsg OK "" $err 953 } else { 954 destroy $np 955 } 956 file delete exptool.in exptool.out 957 } 958 959 960 961 #----------- Add Atoms routines ---------------------------------------- 680 962 proc MakeAddAtomsBox {phase "atomlist {}"} { 681 963 global expmap expgui … … 826 1108 827 1109 proc addatom {phase top} { 828 global expgui env 1110 global expgui env expmap 829 1111 set np $top.canvas.fr 830 1112 set row 0 … … 924 1206 } errmsg 925 1207 # load the revised exp file 1208 set oldatomlist $expmap(atomlist_$phase) 926 1209 loadexp $expgui(expfile) 927 1210 set fp [open exptool.out r] … … 929 1212 close $fp 930 1213 destroy $top 1214 set err 0 1215 if {[llength $oldatomlist] == [llength $expmap(atomlist_$phase))]} { 1216 set err 1 1217 } 931 1218 if {$errmsg != ""} { 932 1219 append errmsg "\n" $out 1220 set err 1 933 1221 } else { 934 1222 set errmsg $out 935 1223 } 936 if {$expgui(showexptool)} { 937 ShowBigMessage \ 938 $top \ 939 "Please review the result from adding the atom(s)" \ 940 $errmsg 1224 if {$expgui(showexptool) || $err} { 1225 set msg "Please review the result from adding the atom(s)" 1226 if {$err} {append msg "\nIt appears an error occurred!"} 1227 ShowBigMessage $top $msg $errmsg OK "" $err 941 1228 } 942 1229 file delete exptool.in exptool.out 943 1230 } 944 1231 945 #---------------------------------------------- 946 # commands to modify a group of selected atoms |947 #---------------------------------------------- 1232 #--------------------------------------------------------------------------- 1233 # commands to modify a group of selected atoms 1234 #--------------------------------------------------------------------------- 948 1235 949 1236 # make the dialog to choose an action … … 1162 1449 } 1163 1450 1451 #----------- more Add Phase routines (import) ------------------------------- 1164 1452 proc ImportPhase {format np} { 1165 1453 global expgui … … 1398 1686 $top.error \ 1399 1687 "Error processing space group\nReview error message below" \ 1400 $b 1688 $b OK "" 1 1401 1689 return 1402 1690 } else { … … 1622 1910 } errmsg 1623 1911 # load the revised exp file 1912 set oldatomlist $expmap(atomlist_$phase) 1624 1913 loadexp $expgui(expfile) 1625 1914 set fp [open exptool.out r] 1626 1915 set out [read $fp] 1627 1916 close $fp 1917 set err 0 1918 if {[llength $oldatomlist] == [llength $expmap(atomlist_$phase))]} { 1919 set err 1 1920 } 1628 1921 if {$errmsg != ""} { 1629 1922 append errmsg "\n" $out 1923 set err 1 1630 1924 } else { 1631 1925 set errmsg $out 1632 1926 } 1633 1927 donewait 1634 if {$expgui(showexptool)} { 1635 ShowBigMessage \ 1636 $top \ 1637 "Please review the result from adding the atom(s)" \ 1638 $errmsg 1928 if {$expgui(showexptool) || $err} { 1929 set msg "Please review the result from adding the atom(s)" 1930 if {$err} {append msg "\nIt appears an error occurred!"} 1931 ShowBigMessage $top $msg $errmsg OK "" $err 1639 1932 } 1640 1933 file delete exptool.in exptool.out … … 1692 1985 # default 1693 1986 set newhist(insttype) CW 1987 set newhist(dummy) 0
Note: See TracChangeset
for help on using the changeset viewer.