Changeset 721 for trunk/addcmds.tcl


Ignore:
Timestamp:
Dec 4, 2009 5:10:54 PM (14 years ago)
Author:
toby
Message:

# on 2003/08/11 19:19:37, toby did:
add support for adding multiple histograms
code cleanup -col -> -column

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/addcmds.tcl

    • Property rcs:date changed from 2003/05/22 21:39:30 to 2003/08/11 19:19:37
    • Property rcs:lines changed from +20 -1 to +195 -16
    • Property rcs:rev changed from 1.31 to 1.32
    r694 r721  
    312312    grid [button $np.f6.b6b -text Cancel \
    313313            -command "destroy $np"] -column 1 -row 0
     314    grid [button $np.f6.b6c -text "Add multiple banks" \
     315            -command "addMultiplehist $np" -state disabled] -column 2 -row 0
    314316    grid [button $np.f6.help -text Help -bg yellow \
    315317            -command "MakeWWWHelp expgui3.html AddHist"] \
     
    320322    # dummy histogram stuff
    321323    frame $np.d1
    322     grid [label $np.d1.l1 -text min] -col 1 -row 1
    323     grid [label $np.d1.l2 -text max] -col 2 -row 1
    324     grid [label $np.d1.l3 -text step] -col 3 -row 1
    325     grid [label $np.d1.lu -text ""] -col 4 -row 1 -rowspan 2
    326     grid [entry $np.d1.e1 -width 10 -textvariable newhist(tmin)] -col 1 -row 2
    327     grid [entry $np.d1.e2 -width 10 -textvariable newhist(tmax)] -col 2 -row 2
    328     grid [entry $np.d1.e3 -width 10 -textvariable newhist(tstep)] -col 3 -row 2
    329     grid [label $np.d1.m1 -anchor w] -col 1 -row 3 -sticky ew
    330     grid [label $np.d1.m2 -anchor w] -col 2 -row 3 -sticky ew
     324    grid [label $np.d1.l1 -text min] -column 1 -row 1
     325    grid [label $np.d1.l2 -text max] -column 2 -row 1
     326    grid [label $np.d1.l3 -text step] -column 3 -row 1
     327    grid [label $np.d1.lu -text ""] -column 4 -row 1 -rowspan 2
     328    grid [entry $np.d1.e1 -width 10 -textvariable newhist(tmin)] -column 1 -row 2
     329    grid [entry $np.d1.e2 -width 10 -textvariable newhist(tmax)] -column 2 -row 2
     330    grid [entry $np.d1.e3 -width 10 -textvariable newhist(tstep)] -column 3 -row 2
     331    grid [label $np.d1.m1 -anchor w] -column 1 -row 3 -sticky ew
     332    grid [label $np.d1.m2 -anchor w] -column 2 -row 3 -sticky ew
    331333    label $np.dl1 -text "Data range:"
    332334    label $np.dl2 -text "Allowed"
     
    514516        }
    515517    }
     518    SetMultipleAdd $np
    516519}
    517520
     
    641644    if {$newhist(dummy)} {PostDummyOpts $np; ValidateDummyHist $np}
    642645    LabelInstParm
     646    SetMultipleAdd $np
    643647}
    644648
     
    788792                -text "File names to be input to RAWPLOT" \
    789793                -justify center -anchor center] \
    790                 -col 0 -row 0 -columnspan 2
     794                -column 0 -row 0 -columnspan 2
    791795        if {$f1 != ""} {
    792796            grid [label $parent.msg.2a \
    793797                    -text "Raw histogram: $f1" \
    794798                    -justify center -anchor e] \
    795                     -col 0 -row 1
     799                    -column 0 -row 1
    796800            grid [button $parent.msg.2b \
    797801                    -command "clipboard clear; clipboard append $f1" \
    798802                    -text "put name\nin clipboard"] \
    799                     -col 1 -row 1
     803                    -column 1 -row 1
    800804        }           
    801805        if {$f2 != ""} {
     
    803807                    -text "Raw histogram: $f2" \
    804808                    -justify center -anchor e] \
    805                     -col 0 -row 2
     809                    -column 0 -row 2
    806810            grid [button $parent.msg.3b \
    807811                    -command "clipboard clear; clipboard append $f2" \
    808812                    -text "put name\nin clipboard"] \
    809                     -col 1 -row 2
     813                    -column 1 -row 2
    810814        }           
    811815        grid [button $parent.msg.4 \
    812816                -command "destroy $parent.msg" \
    813817                -text "Close"] \
    814                 -col 0 -columnspan 2 -row 9
     818                -column 0 -columnspan 2 -row 9
    815819    }
    816820    # start RAWPLOT
     
    10691073}
    10701074
    1071 
     1075#--- multiple histogram stuff
     1076proc SetMultipleAdd {np} {
     1077    global newhist
     1078    $np.f6.b6c configure -state disabled
     1079    catch {
     1080        if {$newhist(instbanks) == [llength $newhist(banklist)] \
     1081                && $newhist(instbanks) > 1} {
     1082            $np.f6.b6c configure -state normal
     1083        }
     1084    }
     1085}
     1086
     1087proc addMultiplehist {np} {
     1088    global newhist
     1089    # should not happen, but just in case
     1090    if {$newhist(instbanks) != [llength $newhist(banklist)]} {
     1091        $np.f6.b6c configure -state disable
     1092        return
     1093    }
     1094    catch {destroy [set top $np.addMult]}
     1095    toplevel $top
     1096    grid [canvas $top.canvas \
     1097            -scrollregion {0 0 5000 500} -width 0 -height 250 \
     1098            -yscrollcommand "$top.scroll set"] \
     1099            -column 0 -columnspan 2 -row 1 -sticky nsew
     1100    grid columnconfigure $top 0 -weight 1
     1101    grid rowconfigure $top 1 -weight 1
     1102    scrollbar $top.scroll \
     1103            -command "$top.canvas yview"
     1104    frame [set cfr $top.canvas.fr]
     1105    $top.canvas create window 0 0 -anchor nw -window $cfr
     1106    grid [label $top.top -text "Select banks to add" -bg beige] \
     1107            -column 0 -columnspan 3 -row 0 -sticky ew
     1108    grid [button $top.add -text Add -command "destroy $np"] -column 0 -row 2
     1109    grid [button $top.cancel -text Cancel -command "destroy $top"] \
     1110            -column 1 -row 2 -columnspan 2
     1111
     1112    set row 1
     1113    grid [label $cfr.t1 -text "Bank\n#"] -column 0 -row 0
     1114    switch $newhist(insttype) {
     1115        TOF {set txt "T-min\n(ms)"}
     1116        ED  {set txt "E-max\n(KeV)"}
     1117        default {set txt "2theta\nmax"}
     1118    }
     1119    grid [label $cfr.t2 -text $txt] -column 1 -row 0
     1120    foreach i $newhist(banklist) {
     1121        grid [checkbutton $cfr.c$i -text $i \
     1122                -variable newhist(usebank$i)] \
     1123                -column 0 -row [incr row] -sticky w
     1124        set newhist(usebank$i) 1
     1125        grid [entry $cfr.e$i -width 8 \
     1126                -textvariable newhist(tmin$i)] \
     1127                -column 1 -row $row -sticky w
     1128    }
     1129    # resize the list
     1130    update
     1131    set sizes [grid bbox $top.canvas.fr]
     1132    $top.canvas config -scrollregion $sizes -width [lindex $sizes 2]
     1133    # use the scroll for BIG lists
     1134    if {[lindex $sizes 3] > [winfo height $top.canvas]} {
     1135        grid $top.scroll -sticky ns -column 3 -row 1
     1136    } else {
     1137        grid forget $top.scroll
     1138    }
     1139    update
     1140    putontop $top
     1141    tkwait window $top
     1142    if {[winfo exists $np]} return
     1143
     1144    # validate the input
     1145    set err {}
     1146    if {[string trim $newhist(rawfile)] == ""} {
     1147        append err "  No data file specified\n"
     1148    }
     1149    if {[string trim $newhist(instfile)] == ""} {
     1150        append err "  No instrument parameter file specified\n"
     1151    }
     1152    foreach i $newhist(banklist) {
     1153        if {$newhist(usebank$i)} {
     1154            if {[catch {expr $newhist(tmin$i)}]} {
     1155                append err "  The Max/Min limit is not valid for bank $i\n"
     1156            } elseif {$newhist(tmin$i) <= 0} {
     1157                append err "  The Max/Min limit is not valid for bank $i\n"
     1158            }
     1159        }
     1160    }
     1161    if {$err != ""} {
     1162        MyMessageBox -parent $np -title  "Add Histogram Error" \
     1163                -message "The following error(s) were found in your input:\n$err" \
     1164                -icon error -type ok -default ok \
     1165                -helplink "expgui3.html AddHistErr"
     1166        return
     1167    }
     1168
     1169    # ok do it!
     1170    global tcl_platform expmap expgui
     1171    # Save the current exp file
     1172    savearchiveexp
     1173    set oldpowderlist $expmap(powderlist)
     1174    # disable the file changed monitor
     1175    set expgui(expModifiedLast) 0
     1176    set expnam [file root [file tail $expgui(expfile)]]
     1177    if {$tcl_platform(platform) == "windows"} {
     1178        set rfile [file attributes $newhist(rawfile) -shortname]
     1179        set ifile [file attributes $newhist(instfile) -shortname]
     1180        set exe [file join $expgui(gsasexe) exptool.exe]
     1181    } else {
     1182        set rfile $newhist(rawfile)
     1183        set ifile $newhist(instfile)
     1184        set exe [file join $expgui(gsasexe) exptool]
     1185    }
     1186    set k 0
     1187    set added 0
     1188    set outlog {}
     1189    set err 0
     1190    pleasewait "adding histograms" expgui(temp)
     1191    foreach i $newhist(banklist) {
     1192        incr k
     1193        if {$newhist(usebank$i)} {
     1194            incr added
     1195            set expgui(temp) "adding bank $i"
     1196            update
     1197            set fp [open exptool.in w]
     1198            puts $fp "H"
     1199            puts $fp $rfile
     1200            puts $fp $ifile
     1201            puts $fp $i
     1202            puts $fp $k
     1203            puts $fp "T"
     1204            puts $fp "$newhist(tmin$i)"
     1205            puts $fp "/"
     1206            puts $fp "X"
     1207            puts $fp "X"
     1208            close $fp
     1209            catch {
     1210                exec $exe $expnam < exptool.in >& exptool.out
     1211            } errmsg
     1212            set fp [open exptool.out r]
     1213            set out [read $fp]
     1214            close $fp
     1215            if {$errmsg != ""} {
     1216                append outlog "\n\n\nNOTE ERROR:\n" $errmsg $out
     1217                set err 1
     1218            } else {
     1219                append outlog $out
     1220            }
     1221        }
     1222    }
     1223    # load the revised exp file
     1224    loadexp $expgui(expfile)
     1225    if {[llength $oldpowderlist]+$added != [llength $expmap(powderlist)]} {
     1226        set err 1
     1227    }
     1228    # set the powpref warning (2 = required)
     1229    set expgui(needpowpref) 2
     1230    set msg "A histogram was added"
     1231    if {[string first $msg $expgui(needpowpref_why)] == -1} {
     1232        append expgui(needpowpref_why) "\t$msg\n"
     1233    }
     1234    file delete exptool.in exptool.out
     1235    donewait
     1236    if {$expgui(showexptool) || $err} {
     1237        set msg "Please review the result from adding the histogram"
     1238        if {$err} {append msg "\nIt appears an error occurred!"}
     1239        ShowBigMessage $np $msg $outlog OK "" $err
     1240    }
     1241    # select the most recently added histogram
     1242    if {!$err} {
     1243        set i [llength $expmap(histlistboxcontents)]
     1244        if {$i > 0} {
     1245            incr i -1
     1246            set expgui(curhist) $i
     1247            sethistlist
     1248        }
     1249    }
     1250}
    10721251
    10731252#----------- Add Atoms routines ----------------------------------------
Note: See TracChangeset for help on using the changeset viewer.