[92] | 1 | # $Id: addcmds.tcl 931 2009-12-05 01:39:46Z toby $ |
---|
| 2 | |
---|
[447] | 3 | #----------- Add Phase routines ---------------------------------------- |
---|
| 4 | |
---|
[92] | 5 | proc MakeAddPhaseBox {} { |
---|
[383] | 6 | global expmap expgui |
---|
[92] | 7 | |
---|
[268] | 8 | set expgui(coordList) {} |
---|
[92] | 9 | set nextphase "" |
---|
| 10 | foreach p {1 2 3 4 5 6 7 8 9} { |
---|
| 11 | if {[lsearch $expmap(phaselist) $p] == -1} { |
---|
| 12 | set nextphase $p |
---|
| 13 | break |
---|
| 14 | } |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | # no more room |
---|
| 18 | if {$nextphase == ""} { |
---|
[383] | 19 | MyMessageBox -parent . -title "Add Phase Error" \ |
---|
| 20 | -message "There are already 9 phases. You cannot add more." \ |
---|
| 21 | -icon error |
---|
[92] | 22 | return |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | set np .newphase |
---|
| 26 | catch {destroy $np} |
---|
| 27 | toplevel $np |
---|
[321] | 28 | bind $np <Key-F1> "MakeWWWHelp expgui2.html addphase" |
---|
[92] | 29 | |
---|
| 30 | grid [label $np.l1 -text "Adding phase #$nextphase"] \ |
---|
| 31 | -column 0 -row 0 -sticky w |
---|
| 32 | grid [label $np.l2 -text "Phase title:"] -column 0 -row 1 |
---|
| 33 | grid [entry $np.t1 -width 68] -column 1 -row 1 -columnspan 8 |
---|
| 34 | grid [label $np.l3 -text "Space Group:"] -column 0 -row 2 |
---|
| 35 | grid [entry $np.t2 -width 12] -column 1 -row 2 |
---|
[905] | 36 | grid [frame $np.ct -bd 2 -relief groove] -column 3 -row 2 |
---|
| 37 | grid [frame $np.f -bd 4 -relief groove] -column 4 -row 2 -columnspan 8 |
---|
| 38 | grid [label $np.ct.l -text "Cell\nType"] -column 0 -row 2 |
---|
| 39 | set menu [tk_optionMenu $np.ct.s expgui(addPhaseCellType) ""] |
---|
| 40 | $menu delete 0 |
---|
| 41 | foreach val {Any Cubic Tetragonal Hexagonal Rhombohedral Orthorhombic Monoclinic} \ |
---|
| 42 | lbl {Any Cubic Tetrag Hexag Rhomb. Ortho Mono} { |
---|
| 43 | $menu add radiobutton -value $lbl -label $val \ |
---|
| 44 | -command "set expgui(addPhaseCellType) $lbl" |
---|
| 45 | } |
---|
| 46 | grid $np.ct.s |
---|
| 47 | foreach v [ trace vinfo expgui(addPhaseCellType)] { |
---|
| 48 | eval trace vdelete expgui(addPhaseCellType) $v |
---|
| 49 | } |
---|
| 50 | #set expgui(addPhaseCellType) Any |
---|
| 51 | $menu invoke 0 |
---|
| 52 | trace variable expgui(addPhaseCellType) w "SetAddCellSymConstr $np.f" |
---|
| 53 | |
---|
[92] | 54 | set col -1 |
---|
| 55 | foreach i {a b c} { |
---|
[268] | 56 | grid [label $np.f.l1$i -text " $i "] -column [incr col] -row 1 |
---|
[92] | 57 | grid [entry $np.f.e1$i -width 12] -column [incr col] -row 1 |
---|
| 58 | } |
---|
| 59 | set col -1 |
---|
| 60 | foreach i {a b g} { |
---|
[413] | 61 | grid [label $np.f.l2$i -text $i] -column [incr col] -row 2 |
---|
| 62 | set font [$np.f.l2$i cget -font] |
---|
| 63 | $np.f.l2$i config -font "Symbol [lrange $font 1 end]" |
---|
[92] | 64 | grid [entry $np.f.e2$i -width 12] -column [incr col] -row 2 |
---|
| 65 | $np.f.e2$i insert 0 90. |
---|
| 66 | } |
---|
| 67 | |
---|
[268] | 68 | grid [frame $np.bf] -row 3 -column 0 -columnspan 10 -sticky ew |
---|
| 69 | grid [button $np.bf.b1 -text Add \ |
---|
[92] | 70 | -command "addphase $np"] -column 2 -row 3 |
---|
| 71 | bind $np <Return> "addphase $np" |
---|
[268] | 72 | grid [button $np.bf.b2 -text Cancel \ |
---|
[92] | 73 | -command "destroy $np"] -column 3 -row 3 |
---|
[268] | 74 | grid columnconfig $np.bf 4 -weight 1 |
---|
[321] | 75 | grid [button $np.bf.help -text Help -bg yellow \ |
---|
| 76 | -command "MakeWWWHelp expgui2.html addphase"] \ |
---|
| 77 | -column 4 -row 3 |
---|
[268] | 78 | |
---|
| 79 | # get the input formats if not already defined |
---|
| 80 | GetImportFormats |
---|
| 81 | if {[llength $expgui(importFormatList)] > 0} { |
---|
| 82 | grid [frame $np.bf.fr -bd 4 -relief groove] -column 5 -row 3 |
---|
| 83 | grid [button $np.bf.fr.b3 -text "Import phase from: " \ |
---|
| 84 | -command "ImportPhase \$expgui(importFormat) $np"] \ |
---|
| 85 | -column 0 -row 0 -sticky e |
---|
[553] | 86 | set menu [eval tk_optionMenu $np.bf.fr.b4 expgui(importFormat) \ |
---|
| 87 | $expgui(importFormatList)] |
---|
| 88 | for {set i 0} {$i <= [$menu index end]} {incr i} { |
---|
| 89 | $menu entryconfig $i -command "ImportPhase \$expgui(importFormat) $np" |
---|
| 90 | } |
---|
[268] | 91 | grid $np.bf.fr.b4 -column 1 -row 0 -sticky w |
---|
| 92 | grid rowconfig $np.bf.fr 0 -pad 10 |
---|
| 93 | grid columnconfig $np.bf.fr 0 -pad 10 |
---|
| 94 | grid columnconfig $np.bf.fr 1 -pad 10 |
---|
| 95 | } |
---|
[92] | 96 | wm title $np "add new phase" |
---|
| 97 | |
---|
[326] | 98 | # set grab, etc. |
---|
[92] | 99 | putontop $np |
---|
[268] | 100 | |
---|
[92] | 101 | tkwait window $np |
---|
[268] | 102 | |
---|
[326] | 103 | # fix grab... |
---|
[92] | 104 | afterputontop |
---|
| 105 | } |
---|
[905] | 106 | proc SetAddCellSymConstr {box args} { |
---|
| 107 | switch $::expgui(addPhaseCellType) { |
---|
| 108 | Any { |
---|
| 109 | foreach i {a b c} { |
---|
| 110 | $box.e1$i configure -textvariable "" -state normal |
---|
| 111 | } |
---|
| 112 | foreach i {a b g} { |
---|
| 113 | $box.e2$i configure -textvariable "" -state normal |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | Cubic { |
---|
| 117 | set ::expgui(AddCella) [$box.e1a get] |
---|
| 118 | foreach i {a b c} { |
---|
| 119 | $box.e1$i configure -textvariable expgui(AddCella) -state normal |
---|
| 120 | } |
---|
| 121 | foreach i {a b g} { |
---|
| 122 | $box.e2$i configure -textvariable "" -state normal |
---|
| 123 | $box.e2$i delete 0 end |
---|
| 124 | $box.e2$i insert 0 90. |
---|
| 125 | $box.e2$i configure -textvariable "" -state disabled |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | Tetrag { |
---|
| 129 | set ::expgui(AddCella) [$box.e1a get] |
---|
| 130 | foreach i {a b} { |
---|
| 131 | $box.e1$i configure -textvariable expgui(AddCella) -state normal |
---|
| 132 | } |
---|
| 133 | $box.e1c configure -textvariable "" -state normal |
---|
| 134 | foreach i {a b g} { |
---|
| 135 | $box.e2$i configure -textvariable "" -state normal |
---|
| 136 | $box.e2$i delete 0 end |
---|
| 137 | $box.e2$i insert 0 90. |
---|
| 138 | $box.e2$i configure -textvariable "" -state disabled |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | Hexag { |
---|
| 142 | set ::expgui(AddCella) [$box.e1a get] |
---|
| 143 | foreach i {a b} { |
---|
| 144 | $box.e1$i configure -textvariable expgui(AddCella) -state normal |
---|
| 145 | } |
---|
| 146 | $box.e1c configure -textvariable "" -state normal |
---|
| 147 | foreach i {a b g} { |
---|
| 148 | $box.e2$i configure -textvariable "" -state normal |
---|
| 149 | $box.e2$i delete 0 end |
---|
| 150 | if {$i == "g"} { |
---|
| 151 | $box.e2$i insert 0 120. |
---|
| 152 | } else { |
---|
| 153 | $box.e2$i insert 0 90. |
---|
| 154 | } |
---|
| 155 | $box.e2$i configure -textvariable "" -state disabled |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | Rhomb. { |
---|
| 159 | set ::expgui(AddCella) [$box.e1a get] |
---|
| 160 | foreach i {a b c} { |
---|
| 161 | $box.e1$i configure -textvariable expgui(AddCella) -state normal |
---|
| 162 | } |
---|
| 163 | set ::expgui(AddCellalpha) [$box.e2a get] |
---|
| 164 | foreach i {a b g} { |
---|
| 165 | $box.e2$i configure -textvariable expgui(AddCellalpha) -state normal |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | Ortho { |
---|
| 169 | foreach i {a b c} { |
---|
| 170 | $box.e1$i configure -textvariable "" -state normal |
---|
| 171 | } |
---|
| 172 | foreach i {a b g} { |
---|
| 173 | $box.e2$i configure -textvariable "" -state normal |
---|
| 174 | $box.e2$i delete 0 end |
---|
| 175 | $box.e2$i insert 0 90. |
---|
| 176 | $box.e2$i configure -textvariable "" -state disabled |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | Mono { |
---|
| 180 | foreach i {a b c} { |
---|
| 181 | $box.e1$i configure -textvariable "" -state normal |
---|
| 182 | } |
---|
| 183 | foreach i {a g} { |
---|
| 184 | $box.e2$i configure -textvariable "" -state normal |
---|
| 185 | $box.e2$i delete 0 end |
---|
| 186 | $box.e2$i insert 0 90. |
---|
| 187 | $box.e2$i configure -textvariable "" -state disabled |
---|
| 188 | } |
---|
| 189 | $box.e2b configure -textvariable "" -state normal |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | } |
---|
[92] | 193 | |
---|
[905] | 194 | |
---|
[92] | 195 | proc addphase {np} { |
---|
[237] | 196 | global expgui expmap |
---|
[92] | 197 | # validate the input |
---|
| 198 | set err {} |
---|
| 199 | set title [$np.t1 get] |
---|
| 200 | if {[string trim $title] == ""} { |
---|
| 201 | append err " Title cannot be blank\n" |
---|
| 202 | } |
---|
| 203 | set spg [$np.t2 get] |
---|
| 204 | if {[string trim $spg] == ""} { |
---|
| 205 | append err " Space group cannot be blank\n" |
---|
| 206 | } |
---|
| 207 | foreach i {a b c} { |
---|
| 208 | set cell($i) [$np.f.e1$i get] |
---|
| 209 | if {[string trim $cell($i)] == ""} { |
---|
| 210 | append err " $i cannot be blank\n" |
---|
| 211 | } elseif {[catch {expr $cell($i)}]} { |
---|
| 212 | append err " $i is not valid\n" |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | foreach i {a b g} lbl {alpha beta gamma} { |
---|
| 217 | set cell($lbl) [$np.f.e2$i get] |
---|
| 218 | if {[string trim $cell($lbl)] == ""} { |
---|
| 219 | append err " $lbl cannot be blank\n" |
---|
| 220 | } elseif {[catch {expr $cell($lbl)}]} { |
---|
| 221 | append err " $lbl is not valid\n" |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | |
---|
[905] | 225 | if {$expgui(addPhaseCellType) == "Rhomb."} { |
---|
| 226 | # check for proper use of space group in Rhomb. setting |
---|
| 227 | if {[string toupper [string range [string trim $spg] 0 0]] != "R"} { |
---|
| 228 | append err "Rhombohedral cell specified, but space group does not start with R\n" |
---|
| 229 | } |
---|
| 230 | if {[string toupper [string range [string trim $spg] end end]] != "R"} { |
---|
| 231 | append spg " R" |
---|
| 232 | if {$err == ""} { |
---|
| 233 | # no need to warn on error |
---|
| 234 | MyMessageBox -parent $np -title "Space Group Fix" \ |
---|
| 235 | -message "Adding a final 'R' to the space group for rhombohedral space group set in rhombohedral cell, as required in GSAS" \ |
---|
| 236 | -icon warning |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | } |
---|
[92] | 240 | if {$err != ""} { |
---|
[383] | 241 | MyMessageBox -parent . -title "Add Phase Error" \ |
---|
| 242 | -message "The following error(s) were found in your input:\n$err" \ |
---|
| 243 | -icon error |
---|
[378] | 244 | set expgui(oldphaselist) -1 |
---|
[92] | 245 | return |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | # check the space group |
---|
| 249 | set fp [open spg.in w] |
---|
| 250 | puts $fp "N" |
---|
| 251 | puts $fp "N" |
---|
| 252 | puts $fp $spg |
---|
| 253 | puts $fp "Q" |
---|
| 254 | close $fp |
---|
| 255 | global tcl_platform |
---|
| 256 | catch { |
---|
| 257 | if {$tcl_platform(platform) == "windows"} { |
---|
| 258 | exec [file join $expgui(gsasexe) spcgroup.exe] < spg.in >& spg.out |
---|
| 259 | } else { |
---|
| 260 | exec [file join $expgui(gsasexe) spcgroup] < spg.in >& spg.out |
---|
| 261 | } |
---|
| 262 | } |
---|
| 263 | set fp [open spg.out r] |
---|
| 264 | set out [read $fp] |
---|
| 265 | close $fp |
---|
| 266 | # attempt to parse out the output (fix up if parse did not work) |
---|
| 267 | if {[regexp "space group symbol.*>(.*)Enter a new space group symbol" \ |
---|
| 268 | $out a b ] != 1} {set b $out} |
---|
| 269 | if {[string first Error $b] != -1} { |
---|
| 270 | # got an error, show it |
---|
| 271 | ShowBigMessage \ |
---|
| 272 | $np.error \ |
---|
| 273 | "Error processing space group\nReview error message below" \ |
---|
[447] | 274 | $b OK "" 1 |
---|
[378] | 275 | set expgui(oldphaselist) -1 |
---|
[92] | 276 | return |
---|
| 277 | } else { |
---|
| 278 | # show the result and confirm |
---|
| 279 | set opt [ShowBigMessage \ |
---|
| 280 | $np.check \ |
---|
| 281 | "Check the symmetry operators in the output below" \ |
---|
| 282 | $b \ |
---|
| 283 | {Continue Redo} ] |
---|
[378] | 284 | if {$opt > 1} { |
---|
| 285 | set expgui(oldphaselist) -1 |
---|
| 286 | return |
---|
| 287 | } |
---|
[92] | 288 | } |
---|
| 289 | file delete spg.in spg.out |
---|
| 290 | # ok do it! |
---|
[905] | 291 | set errmsg [runAddPhase $title $spg \ |
---|
| 292 | $cell(a) $cell(b) $cell(c) \ |
---|
| 293 | $cell(alpha) $cell(beta) $cell(gamma)] |
---|
| 294 | RecordMacroEntry "runAddPhase [list $title] [list $spg] \ |
---|
| 295 | $cell(a) $cell(b) $cell(c) \ |
---|
| 296 | $cell(alpha) $cell(beta) $cell(gamma)" 0 |
---|
| 297 | destroy $np |
---|
| 298 | if {$expgui(showexptool) || $errmsg != ""} { |
---|
| 299 | if {$errmsg != ""} { |
---|
| 300 | set err 1 |
---|
| 301 | append errmsg "\n" $expgui(exptoolout) |
---|
| 302 | } else { |
---|
| 303 | set err 0 |
---|
| 304 | set errmsg $expgui(exptoolout) |
---|
| 305 | } |
---|
| 306 | set msg "Please review the result from adding the phase" |
---|
| 307 | if { $errmsg != ""} {append msg "\nIt appears an error occurred!"} |
---|
| 308 | ShowBigMessage $np $msg $errmsg OK "" $err |
---|
| 309 | } |
---|
| 310 | # set the powpref warning (2 = required) |
---|
| 311 | set expgui(needpowpref) 2 |
---|
| 312 | set msg "A phase was added" |
---|
| 313 | if {[string first $msg $expgui(needpowpref_why)] == -1} { |
---|
| 314 | append expgui(needpowpref_why) "\t$msg\n" |
---|
| 315 | } |
---|
| 316 | # now select the new phase |
---|
| 317 | SelectOnePhase [lindex $expmap(phaselist) end] |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | proc runAddPhase {title spg a b c alpha beta gamma} { |
---|
| 321 | global expgui expmap tcl_platform |
---|
[92] | 322 | set fp [open exptool.in w] |
---|
| 323 | puts $fp "P" |
---|
| 324 | puts $fp $title |
---|
| 325 | puts $fp $spg |
---|
[905] | 326 | puts $fp "$a $b $c $alpha $beta $gamma" |
---|
[92] | 327 | puts $fp "/" |
---|
| 328 | close $fp |
---|
| 329 | # Save the current exp file |
---|
| 330 | savearchiveexp |
---|
| 331 | # disable the file changed monitor |
---|
| 332 | set expgui(expModifiedLast) 0 |
---|
| 333 | set expnam [file root [file tail $expgui(expfile)]] |
---|
[268] | 334 | # save the previous phase list |
---|
| 335 | set expgui(oldphaselist) $expmap(phaselist) |
---|
[905] | 336 | set err [catch { |
---|
[92] | 337 | if {$tcl_platform(platform) == "windows"} { |
---|
| 338 | exec [file join $expgui(gsasexe) exptool.exe] $expnam \ |
---|
| 339 | < exptool.in >& exptool.out |
---|
| 340 | } else { |
---|
| 341 | exec [file join $expgui(gsasexe) exptool] $expnam \ |
---|
| 342 | < exptool.in >& exptool.out |
---|
| 343 | } |
---|
[905] | 344 | } errmsg] |
---|
[92] | 345 | # load the revised exp file |
---|
[447] | 346 | set oldphaselist $expmap(phaselist) |
---|
[92] | 347 | loadexp $expgui(expfile) |
---|
| 348 | set fp [open exptool.out r] |
---|
[905] | 349 | set expgui(exptoolout) [read $fp] |
---|
[92] | 350 | close $fp |
---|
[905] | 351 | catch {file delete exptool.in exptool.out} |
---|
| 352 | |
---|
| 353 | if {[llength $oldphaselist] == [llength $expmap(phaselist)]} { |
---|
[447] | 354 | set err 1 |
---|
[905] | 355 | if {$errmsg == ""} {set errmsg "No phase added"} |
---|
| 356 | } |
---|
| 357 | if {$err} { |
---|
| 358 | return $errmsg |
---|
[113] | 359 | } else { |
---|
[905] | 360 | return "" |
---|
[113] | 361 | } |
---|
[92] | 362 | } |
---|
| 363 | |
---|
[905] | 364 | |
---|
[447] | 365 | #----------- Add Histogram routines -------------------------------------- |
---|
[668] | 366 | proc LabelInstParm {args} { |
---|
| 367 | global newhist |
---|
| 368 | switch $newhist(insttype) { |
---|
| 369 | TOF { |
---|
| 370 | set newhist(instfiletext) "Neutron Time of Flight" |
---|
| 371 | catch { |
---|
| 372 | set b $newhist(setnum) |
---|
| 373 | append newhist(instfiletext) ", 2theta = $newhist(inst${b}Angle)" |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | ED {set newhist(instfiletext) "X-ray Energy Dispersive"} |
---|
| 377 | "CW X" {set newhist(instfiletext) "CW X-ray"} |
---|
| 378 | "CW N" {set newhist(instfiletext) "CW Neutron"} |
---|
| 379 | } |
---|
| 380 | } |
---|
| 381 | trace variable newhist(setnum) w LabelInstParm |
---|
[874] | 382 | trace variable newhist(LimitMode) w ClearHistLimit |
---|
| 383 | set newhist(LimitMode_boxes) {} |
---|
| 384 | |
---|
| 385 | proc ClearHistLimit {args} { |
---|
| 386 | global newhist |
---|
| 387 | if {$newhist(LimitMode) == 1} {return} |
---|
| 388 | foreach box $newhist(LimitMode_boxes) { |
---|
| 389 | catch {$box delete 0 end} |
---|
| 390 | } |
---|
| 391 | } |
---|
| 392 | |
---|
[92] | 393 | proc MakeAddHistBox {} { |
---|
| 394 | global expmap newhist |
---|
| 395 | |
---|
| 396 | # --> should check here if room for another histogram, but only texture |
---|
| 397 | # folks will ever need that |
---|
| 398 | |
---|
[922] | 399 | |
---|
| 400 | # set if the CIF import loads OK |
---|
| 401 | set OK 1 |
---|
| 402 | catch { |
---|
| 403 | if {[info procs ReadCIF4GSAS] == ""} { |
---|
| 404 | set OK 0 |
---|
| 405 | source [file join $::expgui(scriptdir) cif2fxye.tcl] |
---|
| 406 | } |
---|
| 407 | } errmsg |
---|
| 408 | |
---|
[92] | 409 | set np .newhist |
---|
| 410 | catch {destroy $np} |
---|
| 411 | toplevel $np |
---|
[321] | 412 | bind $np <Key-F1> "MakeWWWHelp expgui3.html AddHist" |
---|
[92] | 413 | |
---|
[447] | 414 | grid [label $np.l0 -text "Adding a new histogram"] \ |
---|
[92] | 415 | -column 0 -row 0 -sticky ew -columnspan 7 |
---|
[447] | 416 | grid [checkbutton $np.d0 -text "Dummy Histogram" -variable newhist(dummy) \ |
---|
| 417 | -command "PostDummyOpts $np" \ |
---|
| 418 | ] -column 2 -row 0 -columnspan 99 -sticky e |
---|
| 419 | grid [label $np.l1 -text "Data file:"] -column 0 -row 2 |
---|
[132] | 420 | grid [label $np.t1 -textvariable newhist(rawfile) -bd 2 -relief ridge] \ |
---|
[447] | 421 | -column 1 -row 2 -columnspan 3 -sticky ew |
---|
[92] | 422 | grid [button $np.b1 -text "Select File" \ |
---|
| 423 | -command "getrawfile $np" \ |
---|
[447] | 424 | ] -column 4 -row 2 |
---|
[922] | 425 | if {$OK} { |
---|
| 426 | grid [button $np.b1a -text "Import CIF" \ |
---|
| 427 | -command "ReadCIF4GSAS $np" \ |
---|
| 428 | ] -column 5 -row 2 |
---|
| 429 | } |
---|
[92] | 430 | |
---|
[447] | 431 | grid [label $np.lbank -text "Select bank" -anchor w] -column 1 -row 3 -sticky w |
---|
| 432 | grid [frame $np.bank] -column 2 -row 3 -columnspan 7 -sticky ew |
---|
[92] | 433 | |
---|
[447] | 434 | grid [label $np.l2 -text "Instrument\nParameter file:"] -column 0 -row 5 |
---|
[132] | 435 | grid [label $np.t2 -textvariable newhist(instfile) -bd 2 -relief ridge] \ |
---|
[447] | 436 | -column 1 -row 5 -columnspan 3 -sticky ew |
---|
[92] | 437 | grid [button $np.b2 -text "Select File" \ |
---|
| 438 | -command "getinstfile $np" \ |
---|
[447] | 439 | ] -column 4 -row 5 |
---|
[694] | 440 | grid [button $np.edit -text "Edit file" \ |
---|
| 441 | -command {EditInstFile $newhist(instfile)}] \ |
---|
| 442 | -column 5 -row 5 |
---|
[92] | 443 | |
---|
[447] | 444 | grid [label $np.lset -text "Select set" -anchor w] -column 1 -row 6 -sticky w |
---|
| 445 | grid [frame $np.set] -column 2 -row 6 -columnspan 7 -sticky ew |
---|
[668] | 446 | grid [label $np.t2a -textvariable newhist(instfiletext) \ |
---|
| 447 | -justify center -anchor center -fg blue] \ |
---|
| 448 | -column 0 -row 8 -columnspan 99 -sticky ew |
---|
[92] | 449 | |
---|
[668] | 450 | grid [button $np.f6a -text "Run\nRAWPLOT" -command "RunRawplot $np"] \ |
---|
| 451 | -column 4 -row 18 -rowspan 2 |
---|
| 452 | grid [label $np.l3 -text "Usable data limit:"] -column 0 -row 18 -rowspan 3 |
---|
[92] | 453 | grid [entry $np.e3 -width 12 -textvariable newhist(2tLimit) \ |
---|
[668] | 454 | ] -column 1 -row 18 -rowspan 3 |
---|
[874] | 455 | grid [radiobutton $np.cb3 -text "d-min" -variable newhist(LimitMode) \ |
---|
[668] | 456 | -value 0] -column 2 -row 18 -sticky w |
---|
[447] | 457 | grid [radiobutton $np.cb4 -textvariable newhist(limitLbl) \ |
---|
[394] | 458 | -variable newhist(LimitMode) -anchor w -justify l \ |
---|
[668] | 459 | -value 1] -column 2 -row 20 -sticky w |
---|
[874] | 460 | set newhist(LimitMode_boxes) $np.e3 |
---|
[668] | 461 | grid [radiobutton $np.cb5 -text "Q-max" -variable newhist(LimitMode) \ |
---|
| 462 | -value 2] -column 2 -row 19 -sticky w |
---|
[447] | 463 | set newhist(limitLbl) "TOF-min\n2-Theta Max" |
---|
| 464 | # spacers |
---|
| 465 | grid [frame $np.sp0 -bg white] \ |
---|
| 466 | -columnspan 20 -column 0 -row 1 -sticky nsew -ipady 2 |
---|
| 467 | grid [frame $np.sp1 -bg white] \ |
---|
| 468 | -columnspan 20 -column 0 -row 4 -sticky nsew -ipady 2 |
---|
| 469 | grid [frame $np.sp2 -bg white] \ |
---|
[668] | 470 | -columnspan 20 -column 0 -row 17 -sticky nsew -ipady 2 |
---|
[447] | 471 | grid [frame $np.sp3 -bg white] \ |
---|
| 472 | -columnspan 20 -column 0 -row 98 -sticky nsew -ipady 2 |
---|
| 473 | grid [frame $np.f6] -column 0 -row 99 -columnspan 5 -sticky ew |
---|
[92] | 474 | grid [button $np.f6.b6a -text Add \ |
---|
| 475 | -command "addhist $np"] -column 0 -row 0 |
---|
| 476 | bind $np <Return> "addhist $np" |
---|
| 477 | grid [button $np.f6.b6b -text Cancel \ |
---|
| 478 | -command "destroy $np"] -column 1 -row 0 |
---|
[721] | 479 | grid [button $np.f6.b6c -text "Add multiple banks" \ |
---|
| 480 | -command "addMultiplehist $np" -state disabled] -column 2 -row 0 |
---|
[321] | 481 | grid [button $np.f6.help -text Help -bg yellow \ |
---|
| 482 | -command "MakeWWWHelp expgui3.html AddHist"] \ |
---|
| 483 | -column 2 -row 0 -sticky e |
---|
| 484 | grid columnconfigure $np.f6 2 -weight 1 |
---|
[447] | 485 | grid columnconfigure $np 3 -weight 1 |
---|
[167] | 486 | |
---|
[447] | 487 | # dummy histogram stuff |
---|
| 488 | frame $np.d1 |
---|
[721] | 489 | grid [label $np.d1.l1 -text min] -column 1 -row 1 |
---|
| 490 | grid [label $np.d1.l2 -text max] -column 2 -row 1 |
---|
| 491 | grid [label $np.d1.l3 -text step] -column 3 -row 1 |
---|
| 492 | grid [label $np.d1.lu -text ""] -column 4 -row 1 -rowspan 2 |
---|
| 493 | grid [entry $np.d1.e1 -width 10 -textvariable newhist(tmin)] -column 1 -row 2 |
---|
| 494 | grid [entry $np.d1.e2 -width 10 -textvariable newhist(tmax)] -column 2 -row 2 |
---|
| 495 | grid [entry $np.d1.e3 -width 10 -textvariable newhist(tstep)] -column 3 -row 2 |
---|
| 496 | grid [label $np.d1.m1 -anchor w] -column 1 -row 3 -sticky ew |
---|
| 497 | grid [label $np.d1.m2 -anchor w] -column 2 -row 3 -sticky ew |
---|
[447] | 498 | label $np.dl1 -text "Data range:" |
---|
| 499 | label $np.dl2 -text "Allowed" |
---|
| 500 | label $np.dl3 -text "\n" -justify left -fg blue |
---|
[92] | 501 | wm title $np "add new histogram" |
---|
| 502 | |
---|
[447] | 503 | set newhist(banknum) {} |
---|
| 504 | set newhist(setnum) {} |
---|
[92] | 505 | if {[string trim $newhist(rawfile)] != {}} { |
---|
| 506 | validaterawfile $np $newhist(rawfile) |
---|
| 507 | } |
---|
| 508 | if {[string trim $newhist(instfile)] != {}} { |
---|
| 509 | validateinstfile $np $newhist(instfile) |
---|
| 510 | } |
---|
| 511 | |
---|
[447] | 512 | PostDummyOpts $np |
---|
[326] | 513 | # set grab, etc. |
---|
[92] | 514 | putontop $np |
---|
| 515 | |
---|
| 516 | tkwait window $np |
---|
| 517 | |
---|
[326] | 518 | # fix grab... |
---|
[92] | 519 | afterputontop |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | # convert a file to Win-95 direct access |
---|
[383] | 523 | proc WinCvt {file win} { |
---|
[92] | 524 | global expgui |
---|
| 525 | if ![file exists $file] { |
---|
[383] | 526 | MyMessageBox -parent $win -title "Convert Error" \ |
---|
| 527 | -message "File $file does not exist" -icon error |
---|
[92] | 528 | return |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | set tmpname "[file join [file dirname $file] tempfile.xxx]" |
---|
| 532 | set oldname "[file rootname $file].org" |
---|
| 533 | if [file exists $oldname] { |
---|
[383] | 534 | set ans [MyMessageBox -parent $win -title "OK to overwrite?" \ |
---|
| 535 | -message "File [file tail $oldname] exists in [file dirname $oldname]. OK to overwrite?" \ |
---|
| 536 | -icon question -type yesno -default yes] |
---|
| 537 | if {$ans == "no"} return |
---|
[92] | 538 | catch {file delete $oldname} |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | if [catch { |
---|
| 542 | set in [open $file r] |
---|
| 543 | # needed to test under UNIX |
---|
| 544 | set out [open $tmpname w] |
---|
| 545 | fconfigure $out -translation crlf |
---|
| 546 | set len [gets $in line] |
---|
| 547 | if {$len > 160} { |
---|
[668] | 548 | # this is an old-style UNIX file. Hope there are no control characters |
---|
[92] | 549 | set i 0 |
---|
| 550 | set j 79 |
---|
| 551 | while {$j < $len} { |
---|
| 552 | puts $out [string range $line $i $j] |
---|
| 553 | incr i 80 |
---|
| 554 | incr j 80 |
---|
| 555 | } |
---|
| 556 | } else { |
---|
| 557 | while {$len >= 0} { |
---|
| 558 | append line " " |
---|
| 559 | append line " " |
---|
| 560 | set line [string range $line 0 79] |
---|
| 561 | puts $out $line |
---|
| 562 | set len [gets $in line] |
---|
| 563 | } |
---|
| 564 | } |
---|
| 565 | close $in |
---|
| 566 | close $out |
---|
| 567 | file rename $file $oldname |
---|
| 568 | file rename $tmpname $file |
---|
| 569 | } errmsg] { |
---|
[383] | 570 | MyMessageBox -parent $win -title Notify \ |
---|
| 571 | -message "Error in conversion:\n$errmsg" -icon warning |
---|
[92] | 572 | } |
---|
| 573 | return $file |
---|
| 574 | } |
---|
| 575 | |
---|
| 576 | proc getrawfile {np} { |
---|
| 577 | global newhist tcl_platform |
---|
| 578 | if {$tcl_platform(platform) == "windows"} { |
---|
| 579 | set inp [ |
---|
| 580 | tk_getOpenFile -parent $np -initialfile $newhist(rawfile) -filetypes { |
---|
| 581 | {"Data files" .GSAS} {"Data files" .GSA} |
---|
[905] | 582 | {"Data files" .RAW} {"Data files" .FXYE} {"All files" *} |
---|
[92] | 583 | } |
---|
| 584 | ] |
---|
| 585 | } else { |
---|
| 586 | set inp [ |
---|
| 587 | tk_getOpenFile -parent $np -initialfile $newhist(rawfile) -filetypes { |
---|
| 588 | {"Data files" .GSA*} {"Data files" .RAW} |
---|
[905] | 589 | {"Data files" .gsa*} {"Data files" .raw} {"Data files" .fxye} |
---|
[92] | 590 | {"All files" *} |
---|
| 591 | } |
---|
| 592 | ] |
---|
| 593 | } |
---|
| 594 | validaterawfile $np $inp |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | proc validaterawfile {np inp} { |
---|
[383] | 598 | global expgui newhist |
---|
[92] | 599 | if {$inp == ""} return |
---|
| 600 | if [catch {set in [open $inp r]}] { |
---|
[383] | 601 | MyMessageBox -parent $np -title "Open error" \ |
---|
| 602 | -message "Unable to open file $inp" -icon error |
---|
[92] | 603 | return |
---|
| 604 | } |
---|
| 605 | set newhist(banklist) {} |
---|
[354] | 606 | foreach child [winfo children $np.bank] {destroy $child} |
---|
[92] | 607 | # is this a properly formatted file? |
---|
[383] | 608 | # -- are lines the correct length & terminated with a CR-LF? |
---|
| 609 | fconfigure $in -translation lf |
---|
| 610 | set i 0 |
---|
| 611 | while {[set len [gets $in line]] > 0} { |
---|
| 612 | incr i |
---|
[905] | 613 | #if {$len != 81 || [string range $line end end] != "\r"} { |
---|
| 614 | # set ans [MyMessageBox -parent $np -title "Convert?" \ |
---|
| 615 | # -message "File $inp is not in the correct format for GSAS.\nOK to convert?" \ |
---|
| 616 | # -icon warning -type {OK Quit} -default OK] |
---|
| 617 | # if {$ans == "ok"} { |
---|
| 618 | # # convert and reopen the file |
---|
| 619 | # close $in |
---|
| 620 | # WinCvt $inp $np |
---|
| 621 | # set i 0 |
---|
| 622 | # set in [open $inp r] |
---|
| 623 | # fconfigure $in -translation lf |
---|
| 624 | # set line {} |
---|
| 625 | # } else { |
---|
| 626 | # return |
---|
| 627 | # } |
---|
| 628 | #} |
---|
[383] | 629 | # scan for BANK lines |
---|
| 630 | if {[string first BANK $line] == 0} { |
---|
| 631 | scan $line "BANK%d" num |
---|
| 632 | lappend newhist(banklist) $num |
---|
| 633 | # compute last point |
---|
[394] | 634 | set tmin 0 |
---|
[383] | 635 | set tmax 0 |
---|
| 636 | catch { |
---|
| 637 | scan $line "BANK%d%d%d%s%f%f" num nchan nrec rest start step |
---|
[394] | 638 | set tmin [expr $start/100.] |
---|
[383] | 639 | set tmax [expr ($start + $step*($nchan-1))/100.] |
---|
[92] | 640 | } |
---|
[394] | 641 | set newhist(tmin$num) $tmin |
---|
[383] | 642 | set newhist(tmax$num) $tmax |
---|
[92] | 643 | } |
---|
[383] | 644 | # check for "Instrument parameter file" line |
---|
| 645 | if {$i == 2 && [string first "Instrument parameter" $line] == 0} { |
---|
| 646 | validateinstfile $np \ |
---|
| 647 | [file join [file dirname $inp] \ |
---|
| 648 | [string trim [string range $line 26 end]]] |
---|
| 649 | } |
---|
[92] | 650 | } |
---|
| 651 | # were banks found? |
---|
| 652 | if {$newhist(banklist) == ""} { |
---|
[383] | 653 | MyMessageBox -parent $np -title "Read error" \ |
---|
| 654 | -message "File $inp has no BANK lines.\nThis is not a valid GSAS data file." \ |
---|
| 655 | -icon warning |
---|
[92] | 656 | return |
---|
| 657 | } |
---|
[132] | 658 | # don't use a full path unless needed |
---|
| 659 | if {[pwd] == [file dirname $inp]} { |
---|
| 660 | set newhist(rawfile) [file tail $inp] |
---|
| 661 | } else { |
---|
| 662 | set newhist(rawfile) $inp |
---|
| 663 | } |
---|
[354] | 664 | set row 0 |
---|
| 665 | set col -1 |
---|
[874] | 666 | set flag 0 |
---|
[92] | 667 | foreach i $newhist(banklist) { |
---|
[354] | 668 | if {$col > 8} { |
---|
| 669 | set col -1 |
---|
| 670 | incr row |
---|
| 671 | } |
---|
| 672 | grid [radiobutton $np.bank.$i -text $i -command SetTmax \ |
---|
| 673 | -variable newhist(banknum) -value $i] \ |
---|
| 674 | -column [incr col] -row $row -sticky w |
---|
[132] | 675 | # only 1 choice, so set it |
---|
[354] | 676 | if {[llength $newhist(banklist)] == 1} { |
---|
| 677 | set newhist(banknum) $i |
---|
| 678 | SetTmax |
---|
| 679 | } else { |
---|
[874] | 680 | set flag 1 |
---|
[354] | 681 | } |
---|
[92] | 682 | } |
---|
[874] | 683 | if {$flag} { |
---|
| 684 | set newhist(2tLimit) {} |
---|
| 685 | set newhist(LimitMode) {} |
---|
| 686 | } |
---|
[721] | 687 | SetMultipleAdd $np |
---|
[92] | 688 | } |
---|
| 689 | |
---|
[354] | 690 | proc SetTmax {} { |
---|
| 691 | global newhist |
---|
| 692 | set num $newhist(banknum) |
---|
[394] | 693 | if {$newhist(insttype) == "TOF"} { |
---|
[668] | 694 | set newhist(2tLimit) [expr {$newhist(tmin$num) / 10.}] |
---|
[394] | 695 | if {[llength $newhist(banklist)] == $newhist(instbanks)} { |
---|
| 696 | set newhist(setnum) $newhist(banknum) |
---|
| 697 | } |
---|
| 698 | } else { |
---|
| 699 | set newhist(2tLimit) $newhist(tmax$num) |
---|
| 700 | } |
---|
[354] | 701 | set newhist(LimitMode) 1 |
---|
[394] | 702 | |
---|
[354] | 703 | } |
---|
| 704 | |
---|
[92] | 705 | proc getinstfile {np} { |
---|
| 706 | global newhist tcl_platform |
---|
| 707 | if {$tcl_platform(platform) == "windows"} { |
---|
| 708 | set inp [ |
---|
| 709 | tk_getOpenFile -parent $np -initialfile $newhist(instfile) -filetypes { |
---|
| 710 | {"Inst files" .INST} {"Inst files" .INS} |
---|
| 711 | {"Inst files" .PRM} {"All files" *} |
---|
| 712 | } |
---|
| 713 | ] |
---|
| 714 | } else { |
---|
| 715 | set inp [ |
---|
| 716 | tk_getOpenFile -parent $np -initialfile $newhist(instfile) -filetypes { |
---|
| 717 | {"Inst files" .INS*} {"Inst files" .ins*} |
---|
| 718 | {"Inst files" .PRM} {"Inst files" .prm} |
---|
| 719 | {"All files" *} |
---|
| 720 | } |
---|
| 721 | ] |
---|
| 722 | } |
---|
[447] | 723 | set newhist(setnum) {} |
---|
[92] | 724 | validateinstfile $np $inp |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | proc validateinstfile {np inp} { |
---|
[383] | 728 | global expgui newhist |
---|
[92] | 729 | if {$inp == ""} return |
---|
| 730 | if [catch {set in [open $inp r]}] { |
---|
[383] | 731 | MyMessageBox -parent $np -title "Open error" \ |
---|
| 732 | -message "Unable to open file $inp" -icon error |
---|
[92] | 733 | return |
---|
| 734 | } |
---|
| 735 | set newhist(instbanks) {} |
---|
[354] | 736 | foreach child [winfo children $np.set] {destroy $child} |
---|
[92] | 737 | # is this a properly formatted file? |
---|
[383] | 738 | # -- are lines the correct length & terminated with a CR-LF? |
---|
| 739 | fconfigure $in -translation lf |
---|
[905] | 740 | while {[set len [gets $in line]] >= 0} { |
---|
[383] | 741 | if {$len != 81 || [string range $line end end] != "\r"} { |
---|
| 742 | set ans [MyMessageBox -parent $np -title "Convert?" \ |
---|
| 743 | -message "File $inp is not in the correct format for GSAS.\nOK to convert?" \ |
---|
| 744 | -icon warning -type {OK Quit} -default OK] |
---|
| 745 | if {$ans == "ok"} { |
---|
| 746 | # convert and reopen the file |
---|
[92] | 747 | close $in |
---|
[383] | 748 | WinCvt $inp $np |
---|
[92] | 749 | set in [open $inp r] |
---|
[383] | 750 | fconfigure $in -translation lf |
---|
[92] | 751 | set line {} |
---|
| 752 | } else { |
---|
| 753 | return |
---|
| 754 | } |
---|
| 755 | } |
---|
[383] | 756 | # scan for the INS BANK line |
---|
| 757 | if {[string first "INS BANK" $line] == 0} { |
---|
| 758 | set newhist(instbanks) \ |
---|
| 759 | [string trim [string range $line 12 end]] |
---|
[92] | 760 | } |
---|
[668] | 761 | # scan for the INS HTYPE line |
---|
[394] | 762 | if {[string first "INS HTYPE" $line] == 0} { |
---|
| 763 | if {[string index [lindex $line 2] 2] == "T"} { |
---|
| 764 | set newhist(insttype) TOF |
---|
| 765 | } elseif {[string index [lindex $line 2] 2] == "E"} { |
---|
| 766 | set newhist(insttype) ED |
---|
[668] | 767 | } elseif {[string index [lindex $line 2] 1] == "X"} { |
---|
| 768 | set newhist(insttype) "CW X" |
---|
[394] | 769 | } else { |
---|
[668] | 770 | set newhist(insttype) "CW N" |
---|
[394] | 771 | } |
---|
| 772 | } |
---|
[447] | 773 | # scan for the instrument constants |
---|
| 774 | if {[regexp {INS ([ 1-9][0-9]) ICONS(.*)} $line a b c]} { |
---|
| 775 | set b [string trim $b] |
---|
| 776 | set newhist(inst${b}ICONS) [string trim $c] |
---|
| 777 | } |
---|
| 778 | if {[regexp {INS ([ 1-9][0-9])I ITYP(.*)} $line a b c]} { |
---|
| 779 | set b [string trim $b] |
---|
| 780 | set newhist(inst${b}ITYP) [string trim $c] |
---|
| 781 | } |
---|
[668] | 782 | if {[regexp {INS ([ 1-9][0-9])BNKPAR(.*)} $line a b c]} { |
---|
| 783 | set b [string trim $b] |
---|
| 784 | set newhist(inst${b}Angle) [string trim [lindex $c 1]] |
---|
| 785 | } |
---|
[92] | 786 | } |
---|
| 787 | # were banks found? |
---|
| 788 | if {$newhist(instbanks) == ""} { |
---|
[383] | 789 | MyMessageBox -parent $np -title "Read error" -message \ |
---|
| 790 | "File $inp has no \"INS BANK\" line.\nThis is not a valid GSAS Instrument Parameter file." \ |
---|
| 791 | -icon warning |
---|
[92] | 792 | return |
---|
| 793 | } |
---|
[132] | 794 | # don't use a full path unless needed |
---|
| 795 | if {[pwd] == [file dirname $inp]} { |
---|
| 796 | set newhist(instfile) [file tail $inp] |
---|
| 797 | } else { |
---|
| 798 | set newhist(instfile) $inp |
---|
| 799 | } |
---|
[354] | 800 | set col -1 |
---|
| 801 | set row 0 |
---|
[92] | 802 | for {set i 1} {$i <= $newhist(instbanks)} {incr i} { |
---|
[354] | 803 | if {$col > 8} { |
---|
| 804 | set col -1 |
---|
| 805 | incr row |
---|
| 806 | } |
---|
| 807 | grid [radiobutton $np.set.$i -text $i \ |
---|
[447] | 808 | -command "PostDummyOpts $np; ValidateDummyHist $np" \ |
---|
[354] | 809 | -variable newhist(setnum) -value $i] \ |
---|
| 810 | -column [incr col] -row $row -sticky w |
---|
[132] | 811 | if {$newhist(instbanks) == 1} {set newhist(setnum) $i} |
---|
[92] | 812 | } |
---|
[447] | 813 | if {$newhist(dummy)} {PostDummyOpts $np; ValidateDummyHist $np} |
---|
[668] | 814 | LabelInstParm |
---|
[721] | 815 | SetMultipleAdd $np |
---|
[92] | 816 | } |
---|
| 817 | |
---|
| 818 | proc addhist {np} { |
---|
[447] | 819 | global expgui newhist tcl_platform expmap |
---|
| 820 | if {$newhist(dummy)} { |
---|
| 821 | AddDummyHist $np |
---|
| 822 | return |
---|
| 823 | } |
---|
[92] | 824 | # validate the input |
---|
| 825 | set err {} |
---|
| 826 | if {[string trim $newhist(rawfile)] == ""} { |
---|
| 827 | append err " No data file specified\n" |
---|
| 828 | } |
---|
| 829 | if {[string trim $newhist(instfile)] == ""} { |
---|
| 830 | append err " No instrument parameter file specified\n" |
---|
| 831 | } |
---|
| 832 | if {[string trim $newhist(banknum)] == ""} { |
---|
| 833 | append err " Bank number must be specified\n" |
---|
| 834 | } elseif {[catch {expr $newhist(banknum)}]} { |
---|
| 835 | append err " Bank number is not valid\n" |
---|
| 836 | } |
---|
| 837 | if {[string trim $newhist(setnum)] == ""} { |
---|
| 838 | append err " Parameter set number must be specified\n" |
---|
| 839 | } elseif {[catch {expr $newhist(setnum)}]} { |
---|
| 840 | append err " Parameter set number is not valid\n" |
---|
| 841 | } |
---|
| 842 | if {[string trim $newhist(2tLimit)] == ""} { |
---|
| 843 | append err " 2Theta/d-space limit must be specified\n" |
---|
| 844 | } elseif {[catch {expr $newhist(2tLimit)}]} { |
---|
| 845 | append err " The 2Theta/d-space limit is not valid\n" |
---|
[668] | 846 | } elseif {$newhist(2tLimit) <= 0} { |
---|
| 847 | append err " The 2Theta/d-space limit is not valid\n" |
---|
[92] | 848 | } |
---|
| 849 | if {[string trim $newhist(LimitMode)] == ""} { |
---|
[668] | 850 | append err " Please choose between either a 2Theta, Q or d-space limit\n" |
---|
[92] | 851 | } |
---|
| 852 | |
---|
| 853 | if {$err != ""} { |
---|
[321] | 854 | MyMessageBox -parent $np -title "Add Histogram Error" \ |
---|
| 855 | -message "The following error(s) were found in your input:\n$err" \ |
---|
| 856 | -icon error -type ok -default ok \ |
---|
| 857 | -helplink "expgui3.html AddHistErr" |
---|
[92] | 858 | return |
---|
| 859 | } |
---|
| 860 | |
---|
[905] | 861 | if {$newhist(LimitMode) == 1} { |
---|
| 862 | set mode "T" |
---|
| 863 | set value $newhist(2tLimit) |
---|
| 864 | } elseif {$newhist(LimitMode) == 2} { |
---|
| 865 | set mode "D" |
---|
| 866 | set Q 100 |
---|
| 867 | catch {set Q [expr {4*acos(0)/$newhist(2tLimit)}]} |
---|
| 868 | set value $Q |
---|
| 869 | } else { |
---|
| 870 | set mode "D" |
---|
| 871 | set value $newhist(2tLimit) |
---|
| 872 | } |
---|
| 873 | |
---|
[92] | 874 | # ok do it! |
---|
[905] | 875 | set errmsg [runAddHist $newhist(rawfile) $newhist(instfile) $newhist(banknum) $newhist(setnum) $mode $value] |
---|
| 876 | # save call to Macro file |
---|
| 877 | RecordMacroEntry "runAddHist [list $newhist(rawfile)] [list $newhist(instfile)] $newhist(banknum) $newhist(setnum) $mode $value" 0 |
---|
| 878 | |
---|
| 879 | destroy $np |
---|
| 880 | if {$expgui(showexptool) || $errmsg != ""} { |
---|
| 881 | if {$errmsg != ""} { |
---|
[931] | 882 | set errcode 1 |
---|
[905] | 883 | append errmsg "\n" $expgui(exptoolout) |
---|
[931] | 884 | set err "error" |
---|
[905] | 885 | } else { |
---|
[931] | 886 | set errcode 0 |
---|
[905] | 887 | set errmsg $expgui(exptoolout) |
---|
| 888 | } |
---|
| 889 | set msg "Please review the result from adding the histogram" |
---|
| 890 | if {$errmsg != ""} {append msg "\nIt appears an error occurred!"} |
---|
[931] | 891 | ShowBigMessage $np $msg $errmsg OK "" $errcode |
---|
[905] | 892 | } |
---|
| 893 | # select the most recently added histogram |
---|
[931] | 894 | if {$err != ""} { |
---|
| 895 | # set the powpref warning (2 = required) |
---|
| 896 | set expgui(needpowpref) 2 |
---|
| 897 | set msg "A histogram was added" |
---|
| 898 | if {[string first $msg $expgui(needpowpref_why)] == -1} { |
---|
| 899 | append expgui(needpowpref_why) "\t$msg\n" |
---|
| 900 | } |
---|
[905] | 901 | set i [llength $expmap(histlistboxcontents)] |
---|
| 902 | if {$i > 0} { |
---|
| 903 | incr i -1 |
---|
| 904 | set expgui(curhist) $i |
---|
| 905 | sethistlist |
---|
| 906 | } |
---|
| 907 | } |
---|
| 908 | } |
---|
| 909 | proc runAddHist {rawfile instfile banknum setnum mode value} { |
---|
| 910 | global expgui expmap tcl_platform |
---|
[92] | 911 | set fp [open exptool.in w] |
---|
| 912 | puts $fp "H" |
---|
[232] | 913 | if {$tcl_platform(platform) == "windows"} { |
---|
[905] | 914 | puts $fp [file attributes $rawfile -shortname] |
---|
| 915 | puts $fp [file attributes $instfile -shortname] |
---|
[232] | 916 | } else { |
---|
[905] | 917 | puts $fp $rawfile |
---|
| 918 | puts $fp $instfile |
---|
[232] | 919 | } |
---|
[905] | 920 | puts $fp $banknum |
---|
| 921 | puts $fp $setnum |
---|
| 922 | puts $fp $mode |
---|
| 923 | puts $fp "$value" |
---|
[92] | 924 | puts $fp "/" |
---|
| 925 | puts $fp "X" |
---|
| 926 | puts $fp "X" |
---|
| 927 | close $fp |
---|
| 928 | # Save the current exp file |
---|
| 929 | savearchiveexp |
---|
| 930 | # disable the file changed monitor |
---|
| 931 | set expgui(expModifiedLast) 0 |
---|
| 932 | set expnam [file root [file tail $expgui(expfile)]] |
---|
[905] | 933 | set err [catch { |
---|
[92] | 934 | if {$tcl_platform(platform) == "windows"} { |
---|
| 935 | exec [file join $expgui(gsasexe) exptool.exe] $expnam \ |
---|
| 936 | < exptool.in >& exptool.out |
---|
| 937 | } else { |
---|
| 938 | exec [file join $expgui(gsasexe) exptool] $expnam \ |
---|
| 939 | < exptool.in >& exptool.out |
---|
| 940 | } |
---|
[905] | 941 | } errmsg] |
---|
[92] | 942 | # load the revised exp file |
---|
[447] | 943 | set oldpowderlist $expmap(powderlist) |
---|
[92] | 944 | loadexp $expgui(expfile) |
---|
[905] | 945 | if {[llength $oldpowderlist] == [llength $expmap(powderlist)]} { |
---|
| 946 | append errmsg "\nNo histogram added" |
---|
| 947 | set err 1 |
---|
| 948 | } |
---|
[92] | 949 | set fp [open exptool.out r] |
---|
[905] | 950 | set expgui(exptoolout) [read $fp] |
---|
[92] | 951 | close $fp |
---|
[905] | 952 | catch {file delete exptool.in exptool.out} |
---|
| 953 | if {$err} { |
---|
| 954 | return $errmsg |
---|
[113] | 955 | } else { |
---|
[905] | 956 | return "" |
---|
[113] | 957 | } |
---|
[92] | 958 | } |
---|
| 959 | |
---|
[668] | 960 | proc RunRawplot {parent} { |
---|
[232] | 961 | global newhist tcl_platform |
---|
[668] | 962 | set f1 $newhist(rawfile) |
---|
| 963 | set f2 $newhist(instfile) |
---|
[232] | 964 | # for Windows put a message on top, in case file names must be shortened |
---|
| 965 | if {$tcl_platform(platform) == "windows"} { |
---|
| 966 | catch {set f1 [file nativename \ |
---|
| 967 | [file attributes $newhist(rawfile) -shortname]]} |
---|
| 968 | catch {set f2 [file nativename \ |
---|
| 969 | [file attributes $newhist(instfile) -shortname]]} |
---|
| 970 | } |
---|
[668] | 971 | if {$f1 != "" || $f2 != ""} { |
---|
| 972 | #set msg "Note: input to RAWPLOT\n" |
---|
| 973 | #if {$f1 != ""} {append msg "data file: $f1\n"} |
---|
| 974 | #if {$f2 != ""} {append msg "instrument file: $f2"} |
---|
| 975 | catch {toplevel $parent.msg} |
---|
| 976 | catch {eval destroy [winfo children $parent.msg]} |
---|
| 977 | wm title $parent.msg "File names" |
---|
| 978 | grid [label $parent.msg.1 \ |
---|
| 979 | -text "File names to be input to RAWPLOT" \ |
---|
| 980 | -justify center -anchor center] \ |
---|
[721] | 981 | -column 0 -row 0 -columnspan 2 |
---|
[668] | 982 | if {$f1 != ""} { |
---|
| 983 | grid [label $parent.msg.2a \ |
---|
| 984 | -text "Raw histogram: $f1" \ |
---|
| 985 | -justify center -anchor e] \ |
---|
[721] | 986 | -column 0 -row 1 |
---|
[668] | 987 | grid [button $parent.msg.2b \ |
---|
| 988 | -command "clipboard clear; clipboard append $f1" \ |
---|
| 989 | -text "put name\nin clipboard"] \ |
---|
[721] | 990 | -column 1 -row 1 |
---|
[668] | 991 | } |
---|
| 992 | if {$f2 != ""} { |
---|
| 993 | grid [label $parent.msg.3a \ |
---|
| 994 | -text "Raw histogram: $f2" \ |
---|
| 995 | -justify center -anchor e] \ |
---|
[721] | 996 | -column 0 -row 2 |
---|
[668] | 997 | grid [button $parent.msg.3b \ |
---|
| 998 | -command "clipboard clear; clipboard append $f2" \ |
---|
| 999 | -text "put name\nin clipboard"] \ |
---|
[721] | 1000 | -column 1 -row 2 |
---|
[668] | 1001 | } |
---|
| 1002 | grid [button $parent.msg.4 \ |
---|
| 1003 | -command "destroy $parent.msg" \ |
---|
| 1004 | -text "Close"] \ |
---|
[721] | 1005 | -column 0 -columnspan 2 -row 9 |
---|
[668] | 1006 | } |
---|
[232] | 1007 | # start RAWPLOT |
---|
[358] | 1008 | runGSASprog rawplot 1 |
---|
[668] | 1009 | if {[winfo exists $parent.msg]} {raise $parent.msg} |
---|
| 1010 | update |
---|
[232] | 1011 | } |
---|
[447] | 1012 | #--- Dummy histogram stuff |
---|
| 1013 | proc PostDummyOpts {np} { |
---|
| 1014 | global newhist |
---|
| 1015 | if {$newhist(dummy)} { |
---|
| 1016 | trace variable newhist(tmin) w "ValidateDummyHist $np" |
---|
| 1017 | trace variable newhist(tmax) w "ValidateDummyHist $np" |
---|
| 1018 | trace variable newhist(tstep) w "ValidateDummyHist $np" |
---|
| 1019 | foreach w {l1 t1 lbank} { |
---|
| 1020 | $np.$w config -fg grey |
---|
| 1021 | } |
---|
[458] | 1022 | $np.d1.m1 config -text {} |
---|
| 1023 | $np.d1.m2 config -text {} |
---|
[447] | 1024 | $np.b1 config -state disabled |
---|
[668] | 1025 | grid forget $np.l3 $np.e3 $np.cb3 $np.cb4 $np.cb5 $np.bank $np.f6a |
---|
| 1026 | grid $np.dl1 -column 0 -row 18 |
---|
| 1027 | grid $np.d1 -column 1 -row 18 -rowspan 2 -columnspan 4 -sticky e |
---|
| 1028 | grid $np.dl3 -column 0 -columnspan 99 -row 20 -sticky ew |
---|
[447] | 1029 | if {$newhist(insttype) == "TOF"} { |
---|
| 1030 | $np.dl1 config -text "Data range:\n(TOF)" |
---|
| 1031 | $np.d1.lu config -text millisec |
---|
[668] | 1032 | grid $np.dl2 -column 0 -row 19 |
---|
[447] | 1033 | catch { |
---|
[472] | 1034 | set s $newhist(setnum) |
---|
| 1035 | foreach {x tmin tmax x} $newhist(inst${s}ITYP) {} |
---|
[447] | 1036 | $np.d1.m1 config -text $tmin |
---|
| 1037 | $np.d1.m2 config -text $tmax |
---|
| 1038 | } |
---|
[668] | 1039 | } elseif {[lindex $newhist(insttype) 0] == "CW"} { |
---|
[447] | 1040 | $np.dl1 config -text "Data range:\n(2Theta)" |
---|
| 1041 | $np.d1.lu config -text degrees |
---|
| 1042 | #grid forget $np.dl2 |
---|
| 1043 | $np.d1.m1 config -text >0. |
---|
| 1044 | $np.d1.m2 config -text <180. |
---|
[458] | 1045 | } elseif {$newhist(insttype) == "ED"} { |
---|
[447] | 1046 | $np.dl1 config -text "Data range:\n(Energy)" |
---|
| 1047 | $np.d1.lu config -text KeV |
---|
| 1048 | $np.d1.m1 config -text 1. |
---|
| 1049 | $np.d1.m2 config -text 200. |
---|
[668] | 1050 | grid $np.dl2 -column 0 -row 19 |
---|
[458] | 1051 | } else { |
---|
| 1052 | $np.dl1 config -text "No file\nselected" |
---|
| 1053 | $np.d1.lu config -text {} |
---|
[447] | 1054 | } |
---|
| 1055 | } else { |
---|
| 1056 | foreach var {tmin tmax tstep} { |
---|
| 1057 | foreach v [ trace vinfo newhist($var)] { |
---|
| 1058 | eval trace vdelete newhist($var) $v |
---|
| 1059 | } |
---|
| 1060 | } |
---|
| 1061 | grid forget $np.dl1 $np.d1 $np.dl2 $np.dl3 |
---|
| 1062 | foreach w {l1 t1 lbank} { |
---|
| 1063 | $np.$w config -fg black |
---|
| 1064 | } |
---|
| 1065 | $np.b1 config -state normal |
---|
| 1066 | grid $np.bank -column 2 -row 3 -columnspan 7 -sticky ew |
---|
[668] | 1067 | grid $np.f6a -column 4 -row 18 -rowspan 3 |
---|
| 1068 | grid $np.l3 -column 0 -row 18 -rowspan 3 |
---|
| 1069 | grid $np.e3 -column 1 -row 18 -rowspan 3 |
---|
| 1070 | grid $np.cb3 -column 2 -row 18 -sticky w |
---|
| 1071 | grid $np.cb4 -column 2 -row 20 -sticky w |
---|
| 1072 | grid $np.cb5 -column 2 -row 19 -sticky w |
---|
[447] | 1073 | } |
---|
| 1074 | } |
---|
[232] | 1075 | |
---|
[447] | 1076 | proc ValidateDummyHist {np args} { |
---|
| 1077 | # validate input |
---|
| 1078 | global newhist |
---|
| 1079 | set msg {} |
---|
| 1080 | $np.dl3 config -text "\n" |
---|
| 1081 | foreach e {e1 e2 e3} v {tmin tmax tstep} { |
---|
| 1082 | if [catch {expr $newhist($v)}] { |
---|
| 1083 | $np.d1.$e config -fg red |
---|
| 1084 | append msg "Value of $newhist($v) is invalid for $v\n" |
---|
| 1085 | } else { |
---|
| 1086 | $np.d1.$e config -fg black |
---|
| 1087 | } |
---|
| 1088 | } |
---|
| 1089 | if {[catch {expr $newhist(setnum)}]} { |
---|
| 1090 | append msg "An instrument file bank number must be selected\n" |
---|
| 1091 | } elseif {$newhist(setnum) <= 0 || \ |
---|
| 1092 | $newhist(setnum) > $newhist(instbanks)} { |
---|
| 1093 | append msg "An invalid instrument file bank has been selected\n" |
---|
| 1094 | } |
---|
| 1095 | |
---|
| 1096 | if {$msg != ""} {return $msg} |
---|
| 1097 | |
---|
| 1098 | if {$newhist(tmax) <= $newhist(tmin)} { |
---|
| 1099 | $np.d1.e1 config -fg red |
---|
| 1100 | $np.d1.e2 config -fg red |
---|
| 1101 | return "Tmax <= Tmin\n" |
---|
| 1102 | } |
---|
| 1103 | |
---|
| 1104 | |
---|
| 1105 | set dmin -1 |
---|
| 1106 | set dmax -1 |
---|
| 1107 | if {$newhist(insttype) == "TOF"} { |
---|
| 1108 | catch { |
---|
[472] | 1109 | set s $newhist(setnum) |
---|
| 1110 | foreach {x tmin tmax x} $newhist(inst${s}ITYP) {} |
---|
[447] | 1111 | if {$newhist(tmin) <$tmin } { |
---|
| 1112 | $np.d1.e1 config -fg red |
---|
| 1113 | append msg "Min value of $newhist(tmin) msec is invalid.\n" |
---|
| 1114 | } |
---|
| 1115 | if {$newhist(tmax) >$tmax } { |
---|
| 1116 | $np.d1.e2 config -fg red |
---|
| 1117 | append msg "Max value of $newhist(tmax) msec is invalid.\n" |
---|
| 1118 | } |
---|
[472] | 1119 | set s $newhist(setnum) |
---|
[447] | 1120 | set dmin [expr {1000. * $newhist(tmin) / \ |
---|
[472] | 1121 | [lindex $newhist(inst${s}ICONS) 0]}] |
---|
[447] | 1122 | set dmax [expr {1000. * $newhist(tmax) / \ |
---|
[472] | 1123 | [lindex $newhist(inst${s}ICONS) 0]}] |
---|
[447] | 1124 | } |
---|
[668] | 1125 | } elseif {[lindex $newhist(insttype) 0] == "CW"} { |
---|
[447] | 1126 | if {$newhist(tmin) <= 0 } { |
---|
| 1127 | $np.d1.e1 config -fg red |
---|
| 1128 | append msg "Min value of $newhist(tmin) degrees is invalid.\n" |
---|
| 1129 | } |
---|
| 1130 | if {$newhist(tmax) >=180 } { |
---|
| 1131 | $np.d1.e2 config -fg red |
---|
| 1132 | append msg "Max value of $newhist(tmax) degrees is invalid.\n" |
---|
| 1133 | } |
---|
| 1134 | catch { |
---|
[472] | 1135 | set s $newhist(setnum) |
---|
| 1136 | set dmin [expr {[lindex $newhist(inst${s}ICONS) 0]\ |
---|
[447] | 1137 | * 0.5 / sin(acos(0.)*$newhist(tmax)/180.)}] |
---|
[472] | 1138 | set dmax [expr {[lindex $newhist(inst${s}ICONS) 0]\ |
---|
[447] | 1139 | * 0.5 / sin(acos(0.)*$newhist(tmin)/180.)}] |
---|
| 1140 | } |
---|
| 1141 | } else { |
---|
| 1142 | if {$newhist(tmin) <1 } { |
---|
| 1143 | $np.d1.e1 config -fg red |
---|
| 1144 | append msg "Min value of $newhist(tmin) KeV is invalid.\n" |
---|
| 1145 | } |
---|
| 1146 | if {$newhist(tmax) >200 } { |
---|
| 1147 | $np.d1.e2 config -fg red |
---|
| 1148 | append msg "Max value of $newhist(tmax) KeV is invalid.\n" |
---|
| 1149 | } |
---|
| 1150 | catch { |
---|
[472] | 1151 | set s $newhist(setnum) |
---|
| 1152 | set ang [lindex $newhist(inst${s}ICONS) 0] |
---|
[447] | 1153 | set dmin [expr {12.398/ (2.0*sin($ang*acos(0.)/180) * \ |
---|
| 1154 | $newhist(tmax))}] |
---|
| 1155 | set dmax [expr {12.398/ (2.0*sin($ang*acos(0.)/180) * \ |
---|
| 1156 | $newhist(tmin))}] |
---|
| 1157 | } |
---|
| 1158 | } |
---|
| 1159 | if {$msg != ""} {return $msg} |
---|
| 1160 | set pnts -1 |
---|
| 1161 | catch { |
---|
| 1162 | set pnts [expr {1+int(($newhist(tmax) - $newhist(tmin))/$newhist(tstep))}] |
---|
| 1163 | set qmin [expr {4.*acos(0)/$dmax}] |
---|
| 1164 | set qmax [expr {4.*acos(0)/$dmin}] |
---|
| 1165 | } |
---|
| 1166 | if {$pnts <= 0} { |
---|
| 1167 | $np.d1.e3 config -fg red |
---|
| 1168 | append msg "Step value of $newhist(tstep) is invalid.\n" |
---|
| 1169 | } |
---|
| 1170 | if {$pnts >20000} { |
---|
| 1171 | $np.d1.e3 config -fg red |
---|
| 1172 | append msg "Step value of $newhist(tstep) is too small (>20000 points).\n" |
---|
| 1173 | } |
---|
| 1174 | if {$msg != ""} {return $msg} |
---|
| 1175 | if {$dmin > 0 && $dmax > 0} { |
---|
| 1176 | catch { |
---|
| 1177 | set msg [format \ |
---|
| 1178 | { %d points.%s D-space range: %.2f-%.2f A, Q: %.2f-%.2f/A} \ |
---|
| 1179 | $pnts "\n" $dmin $dmax $qmin $qmax] |
---|
| 1180 | $np.dl3 config -text $msg |
---|
| 1181 | } |
---|
| 1182 | } |
---|
| 1183 | if {$msg != ""} {return ""} |
---|
| 1184 | $np.dl3 config -text [format { %d points.%s Range: ?} $pnts "\n"] |
---|
| 1185 | return "Invalid data range -- something is wrong!" |
---|
| 1186 | } |
---|
| 1187 | |
---|
| 1188 | proc AddDummyHist {np} { |
---|
| 1189 | global newhist expgui expmap |
---|
| 1190 | global tcl_platform |
---|
| 1191 | set msg [ValidateDummyHist $np] |
---|
| 1192 | if {$msg != ""} { |
---|
| 1193 | MyMessageBox -parent $np -title "Add Histogram Error" \ |
---|
| 1194 | -message "The following error(s) were found in your input:\n$msg" \ |
---|
| 1195 | -icon error -type ok -default ok \ |
---|
| 1196 | -helplink "expgui3.html AddHistErr" |
---|
| 1197 | return |
---|
| 1198 | } |
---|
[905] | 1199 | |
---|
| 1200 | set errmsg [runAddDummyHist $newhist(instfile) $newhist(setnum) \ |
---|
| 1201 | $newhist(insttype) \ |
---|
| 1202 | $newhist(tmin) $newhist(tmax) $newhist(tstep)] |
---|
| 1203 | RecordMacroEntry "runAddDummyHist [list $newhist(instfile)] $newhist(setnum) $newhist(insttype) $newhist(tmin) $newhist(tmax) $newhist(tstep)" 0 |
---|
| 1204 | |
---|
| 1205 | if {$errmsg != ""} { |
---|
| 1206 | append errmsg "\n" $out |
---|
| 1207 | } else { |
---|
| 1208 | set errmsg $out |
---|
| 1209 | } |
---|
| 1210 | if {[regexp {\(P,H,A\)} $expgui(exptoolout)]} { |
---|
| 1211 | set msg {You must upgrade the EXPTOOL program.} |
---|
| 1212 | append msg { This version cannot add dummy histograms.} |
---|
| 1213 | MyMessageBox -icon error -title "Old EXPTOOL program" \ |
---|
| 1214 | -message $msg -parent $np \ |
---|
| 1215 | -helplink "expguierr.html OldEXPTOOL" |
---|
| 1216 | # update the documentation & link |
---|
| 1217 | destroy $np |
---|
| 1218 | } elseif {$expgui(showexptool) || $errmsg != ""} { |
---|
| 1219 | if {$errmsg != ""} { |
---|
| 1220 | set err 1 |
---|
| 1221 | append errmsg "\n" $expgui(exptoolout) |
---|
| 1222 | } else { |
---|
| 1223 | set err 0 |
---|
| 1224 | set errmsg $expgui(exptoolout) |
---|
| 1225 | } |
---|
| 1226 | set msg "Please review the result from adding the dummy histogram" |
---|
| 1227 | if {$err} {append msg "\nIt appears an error occurred!"} |
---|
| 1228 | ShowBigMessage $np $msg $errmsg OK "" $err |
---|
| 1229 | } else { |
---|
| 1230 | destroy $np |
---|
| 1231 | } |
---|
| 1232 | file delete exptool.in exptool.out |
---|
| 1233 | # set the powpref warning (2 = required) |
---|
| 1234 | set expgui(needpowpref) 2 |
---|
| 1235 | set msg "A histogram was added" |
---|
| 1236 | if {[string first $msg $expgui(needpowpref_why)] == -1} { |
---|
| 1237 | append expgui(needpowpref_why) "\t$msg\n" |
---|
| 1238 | } |
---|
| 1239 | } |
---|
| 1240 | proc runAddDummyHist {instfile setnum insttype tmin tmax tstep} { |
---|
| 1241 | global expgui expmap tcl_platform |
---|
[447] | 1242 | set fp [open exptool.in w] |
---|
| 1243 | puts $fp "D" |
---|
[905] | 1244 | puts $fp $instfile |
---|
| 1245 | puts $fp $setnum |
---|
| 1246 | if {$insttype == "TOF"} { |
---|
[447] | 1247 | puts $fp "C" |
---|
| 1248 | } |
---|
[905] | 1249 | puts $fp $tmin |
---|
| 1250 | puts $fp $tmax |
---|
| 1251 | puts $fp $tstep |
---|
[447] | 1252 | puts $fp "X" |
---|
| 1253 | puts $fp "0" |
---|
| 1254 | close $fp |
---|
| 1255 | # Save the current exp file |
---|
| 1256 | savearchiveexp |
---|
| 1257 | # disable the file changed monitor |
---|
| 1258 | set expgui(expModifiedLast) 0 |
---|
| 1259 | set expnam [file root [file tail $expgui(expfile)]] |
---|
| 1260 | set err [catch { |
---|
| 1261 | if {$tcl_platform(platform) == "windows"} { |
---|
| 1262 | exec [file join $expgui(gsasexe) exptool.exe] $expnam \ |
---|
| 1263 | < exptool.in >& exptool.out |
---|
| 1264 | } else { |
---|
| 1265 | exec [file join $expgui(gsasexe) exptool] $expnam \ |
---|
| 1266 | < exptool.in >& exptool.out |
---|
| 1267 | } |
---|
| 1268 | } errmsg ] |
---|
| 1269 | # load the revised exp file |
---|
| 1270 | set oldpowderlist $expmap(powderlist) |
---|
| 1271 | loadexp $expgui(expfile) |
---|
| 1272 | set fp [open exptool.out r] |
---|
[905] | 1273 | set expgui(exptoolout) [read $fp] |
---|
[447] | 1274 | close $fp |
---|
[905] | 1275 | catch {file delete exptool.in exptool.out} |
---|
| 1276 | if {[llength $oldpowderlist] == [llength $expmap(powderlist)]} { |
---|
| 1277 | set err 1 |
---|
| 1278 | if {$errmsg == ""} {set errmsg "No histogram added"} |
---|
[447] | 1279 | } |
---|
[905] | 1280 | if {$err} { |
---|
| 1281 | return $errmsg |
---|
[447] | 1282 | } else { |
---|
[905] | 1283 | return "" |
---|
[447] | 1284 | } |
---|
| 1285 | } |
---|
| 1286 | |
---|
[721] | 1287 | #--- multiple histogram stuff |
---|
| 1288 | proc SetMultipleAdd {np} { |
---|
| 1289 | global newhist |
---|
| 1290 | $np.f6.b6c configure -state disabled |
---|
| 1291 | catch { |
---|
| 1292 | if {$newhist(instbanks) == [llength $newhist(banklist)] \ |
---|
| 1293 | && $newhist(instbanks) > 1} { |
---|
| 1294 | $np.f6.b6c configure -state normal |
---|
| 1295 | } |
---|
| 1296 | } |
---|
| 1297 | } |
---|
[447] | 1298 | |
---|
[721] | 1299 | proc addMultiplehist {np} { |
---|
| 1300 | global newhist |
---|
| 1301 | # should not happen, but just in case |
---|
| 1302 | if {$newhist(instbanks) != [llength $newhist(banklist)]} { |
---|
| 1303 | $np.f6.b6c configure -state disable |
---|
| 1304 | return |
---|
| 1305 | } |
---|
| 1306 | catch {destroy [set top $np.addMult]} |
---|
| 1307 | toplevel $top |
---|
| 1308 | grid [canvas $top.canvas \ |
---|
| 1309 | -scrollregion {0 0 5000 500} -width 0 -height 250 \ |
---|
| 1310 | -yscrollcommand "$top.scroll set"] \ |
---|
[874] | 1311 | -column 0 -columnspan 2 -row 2 -sticky ns |
---|
[721] | 1312 | grid columnconfigure $top 0 -weight 1 |
---|
[874] | 1313 | grid rowconfigure $top 2 -weight 1 |
---|
[721] | 1314 | scrollbar $top.scroll \ |
---|
| 1315 | -command "$top.canvas yview" |
---|
| 1316 | frame [set cfr $top.canvas.fr] |
---|
| 1317 | $top.canvas create window 0 0 -anchor nw -window $cfr |
---|
| 1318 | grid [label $top.top -text "Select banks to add" -bg beige] \ |
---|
| 1319 | -column 0 -columnspan 3 -row 0 -sticky ew |
---|
[874] | 1320 | grid [frame $top.vartyp -bd 2 -relief groove] \ |
---|
| 1321 | -column 0 -columnspan 3 -row 1 -sticky ew |
---|
| 1322 | grid [label $top.vartyp.top -text "Data limit units:"] -column 0 -row 0 -columnspan 3 -sticky w |
---|
| 1323 | grid [radiobutton $top.vartyp.cb3 -text "d-min" -variable newhist(LimitMode) \ |
---|
| 1324 | -value 0] -column 0 -row 1 -sticky w |
---|
| 1325 | grid [radiobutton $top.vartyp.cb4 -textvariable newhist(datalimlbl) \ |
---|
| 1326 | -variable newhist(LimitMode) -anchor w -justify l \ |
---|
| 1327 | -value 1] -column 1 -row 1 -sticky w |
---|
| 1328 | grid [radiobutton $top.vartyp.cb5 -text "Q-max" -variable newhist(LimitMode) \ |
---|
| 1329 | -value 2] -column 2 -row 1 -sticky w |
---|
| 1330 | set newhist(LimitMode) 1 |
---|
| 1331 | |
---|
| 1332 | grid [button $top.add -text Add -command "destroy $np"] -column 0 -row 3 |
---|
[721] | 1333 | grid [button $top.cancel -text Cancel -command "destroy $top"] \ |
---|
[874] | 1334 | -column 1 -row 3 -columnspan 2 |
---|
[721] | 1335 | set row 1 |
---|
| 1336 | grid [label $cfr.t1 -text "Bank\n#"] -column 0 -row 0 |
---|
| 1337 | switch $newhist(insttype) { |
---|
[874] | 1338 | TOF {set newhist(datalimlbl) "T-min\n(ms)"} |
---|
| 1339 | ED {set newhist(datalimlbl) "E-max\n(KeV)"} |
---|
| 1340 | default {set newhist(datalimlbl) "2theta\nmax"} |
---|
[721] | 1341 | } |
---|
[874] | 1342 | grid [label $cfr.t2 -textvariable newhist(datalimlbl)] -column 1 -row 0 |
---|
[721] | 1343 | foreach i $newhist(banklist) { |
---|
| 1344 | grid [checkbutton $cfr.c$i -text $i \ |
---|
| 1345 | -variable newhist(usebank$i)] \ |
---|
| 1346 | -column 0 -row [incr row] -sticky w |
---|
| 1347 | set newhist(usebank$i) 1 |
---|
[874] | 1348 | grid [entry $cfr.e$i -width 8 -textvariable newhist(tlimit$i)] \ |
---|
| 1349 | -column 1 -row $row -sticky w |
---|
| 1350 | lappend newhist(LimitMode_boxes) $cfr.e$i |
---|
[865] | 1351 | if {$newhist(insttype) == "TOF"} { |
---|
[874] | 1352 | set newhist(tlimit$i) $newhist(tmin$i) |
---|
[865] | 1353 | } else { |
---|
[874] | 1354 | set newhist(tlimit$i) $newhist(tmax$i) |
---|
[865] | 1355 | } |
---|
[721] | 1356 | } |
---|
| 1357 | # resize the list |
---|
| 1358 | update |
---|
| 1359 | set sizes [grid bbox $top.canvas.fr] |
---|
| 1360 | $top.canvas config -scrollregion $sizes -width [lindex $sizes 2] |
---|
| 1361 | # use the scroll for BIG lists |
---|
| 1362 | if {[lindex $sizes 3] > [winfo height $top.canvas]} { |
---|
[874] | 1363 | grid $top.scroll -sticky ns -column 3 -row 2 |
---|
[721] | 1364 | } else { |
---|
| 1365 | grid forget $top.scroll |
---|
| 1366 | } |
---|
| 1367 | update |
---|
| 1368 | putontop $top |
---|
| 1369 | tkwait window $top |
---|
[738] | 1370 | afterputontop |
---|
| 1371 | |
---|
[721] | 1372 | if {[winfo exists $np]} return |
---|
| 1373 | |
---|
| 1374 | # validate the input |
---|
| 1375 | set err {} |
---|
| 1376 | if {[string trim $newhist(rawfile)] == ""} { |
---|
| 1377 | append err " No data file specified\n" |
---|
| 1378 | } |
---|
| 1379 | if {[string trim $newhist(instfile)] == ""} { |
---|
| 1380 | append err " No instrument parameter file specified\n" |
---|
| 1381 | } |
---|
| 1382 | foreach i $newhist(banklist) { |
---|
| 1383 | if {$newhist(usebank$i)} { |
---|
[874] | 1384 | if {[catch {expr $newhist(tlimit$i)}]} { |
---|
[721] | 1385 | append err " The Max/Min limit is not valid for bank $i\n" |
---|
[874] | 1386 | } elseif {$newhist(tlimit$i) <= 0} { |
---|
[721] | 1387 | append err " The Max/Min limit is not valid for bank $i\n" |
---|
| 1388 | } |
---|
| 1389 | } |
---|
| 1390 | } |
---|
| 1391 | if {$err != ""} { |
---|
| 1392 | MyMessageBox -parent $np -title "Add Histogram Error" \ |
---|
| 1393 | -message "The following error(s) were found in your input:\n$err" \ |
---|
| 1394 | -icon error -type ok -default ok \ |
---|
| 1395 | -helplink "expgui3.html AddHistErr" |
---|
| 1396 | return |
---|
| 1397 | } |
---|
| 1398 | |
---|
| 1399 | # ok do it! |
---|
| 1400 | global tcl_platform expmap expgui |
---|
| 1401 | # Save the current exp file |
---|
| 1402 | savearchiveexp |
---|
| 1403 | set oldpowderlist $expmap(powderlist) |
---|
| 1404 | # disable the file changed monitor |
---|
| 1405 | set expgui(expModifiedLast) 0 |
---|
| 1406 | set k 0 |
---|
| 1407 | set added 0 |
---|
| 1408 | set outlog {} |
---|
| 1409 | set err 0 |
---|
| 1410 | pleasewait "adding histograms" expgui(temp) |
---|
| 1411 | foreach i $newhist(banklist) { |
---|
| 1412 | incr k |
---|
| 1413 | if {$newhist(usebank$i)} { |
---|
| 1414 | incr added |
---|
| 1415 | set expgui(temp) "adding bank $i" |
---|
| 1416 | update |
---|
[905] | 1417 | |
---|
[874] | 1418 | if {$newhist(LimitMode) == 1} { |
---|
[905] | 1419 | set mode "T" |
---|
| 1420 | set value $newhist(tlimit$i) |
---|
[874] | 1421 | } elseif {$newhist(LimitMode) == 2} { |
---|
[905] | 1422 | set mode "D" |
---|
[874] | 1423 | set Q 100 |
---|
| 1424 | catch {set Q [expr {4*acos(0)/$newhist(tlimit$i)}]} |
---|
[905] | 1425 | set value $Q |
---|
[874] | 1426 | } else { |
---|
[905] | 1427 | set mode "D" |
---|
| 1428 | set value $newhist(tlimit$i) |
---|
[874] | 1429 | } |
---|
[905] | 1430 | set errmsg [runAddHist $newhist(rawfile) $newhist(instfile) $i $k $mode $value] |
---|
| 1431 | # save call to Macro file |
---|
| 1432 | RecordMacroEntry "runAddHist [list $newhist(rawfile)] [list $newhist(instfile)] $i $k $mode $value" 0 |
---|
[721] | 1433 | if {$errmsg != ""} { |
---|
[905] | 1434 | append outlog "\n\n\nNOTE ERROR:\n" $errmsg $expgui(exptoolout) |
---|
[721] | 1435 | set err 1 |
---|
| 1436 | } else { |
---|
[905] | 1437 | append outlog $expgui(exptoolout) |
---|
[721] | 1438 | } |
---|
| 1439 | } |
---|
| 1440 | } |
---|
| 1441 | # load the revised exp file |
---|
| 1442 | loadexp $expgui(expfile) |
---|
| 1443 | if {[llength $oldpowderlist]+$added != [llength $expmap(powderlist)]} { |
---|
| 1444 | set err 1 |
---|
| 1445 | } |
---|
| 1446 | # set the powpref warning (2 = required) |
---|
| 1447 | set expgui(needpowpref) 2 |
---|
| 1448 | set msg "A histogram was added" |
---|
| 1449 | if {[string first $msg $expgui(needpowpref_why)] == -1} { |
---|
| 1450 | append expgui(needpowpref_why) "\t$msg\n" |
---|
| 1451 | } |
---|
| 1452 | donewait |
---|
| 1453 | if {$expgui(showexptool) || $err} { |
---|
| 1454 | set msg "Please review the result from adding the histogram" |
---|
| 1455 | if {$err} {append msg "\nIt appears an error occurred!"} |
---|
| 1456 | ShowBigMessage $np $msg $outlog OK "" $err |
---|
| 1457 | } |
---|
| 1458 | # select the most recently added histogram |
---|
| 1459 | if {!$err} { |
---|
| 1460 | set i [llength $expmap(histlistboxcontents)] |
---|
| 1461 | if {$i > 0} { |
---|
| 1462 | incr i -1 |
---|
| 1463 | set expgui(curhist) $i |
---|
| 1464 | sethistlist |
---|
| 1465 | } |
---|
| 1466 | } |
---|
| 1467 | } |
---|
| 1468 | |
---|
[447] | 1469 | #----------- Add Atoms routines ---------------------------------------- |
---|
[268] | 1470 | proc MakeAddAtomsBox {phase "atomlist {}"} { |
---|
| 1471 | global expmap expgui |
---|
[92] | 1472 | |
---|
[179] | 1473 | # is there room for more atoms? Well, we will check this someday |
---|
[92] | 1474 | if {$phase == ""} return |
---|
| 1475 | if {[llength $phase] != 1} return |
---|
| 1476 | |
---|
[179] | 1477 | set top .newatoms |
---|
| 1478 | catch {destroy $top} |
---|
| 1479 | toplevel $top |
---|
[321] | 1480 | bind $top <Key-F1> "MakeWWWHelp expgui2.html addatoms" |
---|
[92] | 1481 | |
---|
[179] | 1482 | grid [label $top.l1 -relief groove -bd 4 -anchor center\ |
---|
| 1483 | -text "Adding atoms to phase #$phase"] \ |
---|
| 1484 | -column 0 -row 0 \ |
---|
| 1485 | -sticky we -columnspan 10 |
---|
| 1486 | |
---|
| 1487 | grid [canvas $top.canvas \ |
---|
| 1488 | -scrollregion {0 0 5000 500} -width 0 -height 250 \ |
---|
| 1489 | -yscrollcommand "$top.scroll set"] \ |
---|
| 1490 | -column 0 -row 2 -columnspan 4 -sticky nsew |
---|
| 1491 | grid columnconfigure $top 3 -weight 1 |
---|
| 1492 | grid rowconfigure $top 2 -weight 1 |
---|
| 1493 | grid rowconfigure $top 1 -pad 5 |
---|
| 1494 | scrollbar $top.scroll \ |
---|
| 1495 | -command "$top.canvas yview" |
---|
| 1496 | frame $top.canvas.fr |
---|
| 1497 | $top.canvas create window 0 0 -anchor nw -window $top.canvas.fr |
---|
| 1498 | |
---|
| 1499 | set np $top.canvas.fr |
---|
| 1500 | set row 0 |
---|
| 1501 | set col 0 |
---|
[379] | 1502 | grid [label $np.l_${row}0 -text " # "] -column $col -row $row |
---|
| 1503 | foreach i {Atom\ntype Name x y z Occ Uiso} \ |
---|
| 1504 | var {type name x y z occ uiso} { |
---|
| 1505 | grid [button $np.l_${row}$i -text $i -padx 0 -pady 0 \ |
---|
| 1506 | -command "sortAddAtoms $phase $top $var"] \ |
---|
| 1507 | -column [incr col] -row $row -sticky nsew |
---|
[92] | 1508 | } |
---|
[379] | 1509 | grid [label $np.l_${row}Use -text Use\nFlag] -column [incr col] -row $row |
---|
[92] | 1510 | |
---|
[179] | 1511 | set expgui(SetAddAtomsScroll) 0 |
---|
[268] | 1512 | set i [llength $atomlist] |
---|
| 1513 | if {$i == 0} {incr i} |
---|
| 1514 | for {set j 0} {$j < $i} {incr j} { |
---|
| 1515 | MakeAddAtomsRow $top |
---|
| 1516 | } |
---|
| 1517 | set row 0 |
---|
| 1518 | foreach item $atomlist { |
---|
| 1519 | incr row |
---|
| 1520 | foreach val $item w {n x y z t o u} { |
---|
| 1521 | if {$val != ""} { |
---|
| 1522 | $np.e${row}$w delete 0 end |
---|
| 1523 | $np.e${row}$w insert end $val |
---|
| 1524 | } |
---|
| 1525 | } |
---|
| 1526 | } |
---|
[179] | 1527 | bind $top <Configure> "SetAddAtomsScroll $top" |
---|
[268] | 1528 | grid rowconfigure $top 3 -min 10 |
---|
[179] | 1529 | grid [button $top.b1 -text "Add Atoms"\ |
---|
[268] | 1530 | -command "addatom $phase $top"] -column 0 -row 5 -sticky w |
---|
[179] | 1531 | bind $top <Return> "addatom $phase $top" |
---|
| 1532 | grid [button $top.b2 -text Cancel \ |
---|
[268] | 1533 | -command "destroy $top"] -column 1 -row 5 -sticky w |
---|
[321] | 1534 | grid [button $top.help -text Help -bg yellow \ |
---|
| 1535 | -command "MakeWWWHelp expgui2.html addatoms"] \ |
---|
| 1536 | -column 0 -columnspan 2 -row 4 |
---|
[179] | 1537 | |
---|
[268] | 1538 | # get the input formats if not already defined |
---|
| 1539 | GetImportFormats |
---|
| 1540 | if {[llength $expgui(importFormatList)] > 0} { |
---|
| 1541 | grid [frame $top.fr -bd 4 -relief groove] \ |
---|
| 1542 | -column 3 -row 5 -columnspan 2 -sticky e |
---|
| 1543 | grid [button $top.fr.b3 -text "Import atoms from: " \ |
---|
[379] | 1544 | -command "ImportAtoms \$expgui(importFormat) $top $phase"] \ |
---|
[268] | 1545 | -column 0 -row 0 -sticky e |
---|
[553] | 1546 | set menu [eval tk_optionMenu $top.fr.b4 expgui(importFormat) \ |
---|
| 1547 | $expgui(importFormatList)] |
---|
| 1548 | for {set i 0} {$i <= [$menu index end]} {incr i} { |
---|
| 1549 | $menu entryconfig $i -command "ImportAtoms \$expgui(importFormat) $top $phase" |
---|
| 1550 | } |
---|
[268] | 1551 | grid $top.fr.b4 -column 1 -row 0 -sticky w |
---|
| 1552 | grid rowconfig $top.fr 0 -pad 10 |
---|
| 1553 | grid columnconfig $top.fr 0 -pad 10 |
---|
| 1554 | grid columnconfig $top.fr 1 -pad 10 |
---|
| 1555 | } |
---|
| 1556 | |
---|
| 1557 | grid [button $top.b3 -text "More atom boxes" \ |
---|
[179] | 1558 | -command "MakeAddAtomsRow $top"] -column 3 \ |
---|
| 1559 | -columnspan 2 -row 4 -sticky e |
---|
| 1560 | |
---|
| 1561 | wm title $top "add new atom" |
---|
| 1562 | |
---|
[326] | 1563 | # set grab, etc. |
---|
[179] | 1564 | putontop $top |
---|
| 1565 | |
---|
| 1566 | tkwait window $top |
---|
| 1567 | |
---|
[326] | 1568 | # fix grab... |
---|
[179] | 1569 | afterputontop |
---|
| 1570 | } |
---|
| 1571 | |
---|
| 1572 | proc MakeAddAtomsRow {top} { |
---|
| 1573 | set np $top.canvas.fr |
---|
[92] | 1574 | set col -1 |
---|
[179] | 1575 | set row 1 |
---|
| 1576 | # find an empty row |
---|
| 1577 | while {![catch {grid info $np.e${row}t}]} {incr row} |
---|
| 1578 | grid [label $np.e${row}num -text $row] -column [incr col] -row $row |
---|
[92] | 1579 | grid [entry $np.e${row}t -width 5] -column [incr col] -row $row |
---|
| 1580 | grid [entry $np.e${row}n -width 8] -column [incr col] -row $row |
---|
| 1581 | foreach i {x y z o u} { |
---|
[179] | 1582 | grid [entry $np.e${row}$i -width 9] -column [incr col] -row $row |
---|
[92] | 1583 | } |
---|
[179] | 1584 | grid [checkbutton $np.e${row}use -variable expgui(UseAtom$row)] \ |
---|
| 1585 | -column [incr col] -row $row |
---|
[92] | 1586 | # default occupancy |
---|
| 1587 | $np.e${row}o delete 0 end |
---|
| 1588 | $np.e${row}o insert end 1.0 |
---|
| 1589 | # default Uiso |
---|
| 1590 | $np.e${row}u delete 0 end |
---|
| 1591 | $np.e${row}u insert end 0.025 |
---|
[268] | 1592 | # default label |
---|
[92] | 1593 | $np.e${row}n delete 0 end |
---|
| 1594 | $np.e${row}n insert end (default) |
---|
[179] | 1595 | # use by default |
---|
| 1596 | $np.e${row}use select |
---|
[92] | 1597 | |
---|
[179] | 1598 | SetAddAtomsScroll $top |
---|
[268] | 1599 | return $row |
---|
[179] | 1600 | } |
---|
[92] | 1601 | |
---|
[179] | 1602 | proc SetAddAtomsScroll {top} { |
---|
| 1603 | global expgui |
---|
| 1604 | if $expgui(SetAddAtomsScroll) return |
---|
| 1605 | # prevent reentrance |
---|
| 1606 | set expgui(SetAddAtomsScroll) 1 |
---|
| 1607 | update |
---|
| 1608 | set sizes [grid bbox $top.canvas.fr] |
---|
| 1609 | $top.canvas config -scrollregion $sizes -width [lindex $sizes 2] |
---|
| 1610 | # use the scroll for BIG atom lists |
---|
| 1611 | if {[lindex $sizes 3] > [winfo height $top.canvas]} { |
---|
| 1612 | grid $top.scroll -sticky ns -column 4 -row 2 |
---|
| 1613 | } else { |
---|
| 1614 | grid forget $top.scroll |
---|
| 1615 | } |
---|
| 1616 | update |
---|
| 1617 | set expgui(SetAddAtomsScroll) 0 |
---|
[92] | 1618 | } |
---|
| 1619 | |
---|
[536] | 1620 | # Validate the atoms in the atoms add/phase replace box |
---|
| 1621 | # returns a null string on error or a list of atoms |
---|
[553] | 1622 | proc ValidateAtomsBox {top np} { |
---|
| 1623 | global expgui |
---|
[179] | 1624 | set row 0 |
---|
| 1625 | # loop over the defined rows |
---|
[92] | 1626 | set err {} |
---|
[179] | 1627 | set atomlist {} |
---|
[378] | 1628 | set validatmtypes { |
---|
[493] | 1629 | H H-1 H_1 H_2 D H_3 HE HE_3 HE_4 LI LI+1 LI_6 LI_7 BE BE+2 B B_10 |
---|
[779] | 1630 | B_11 C CV C_12 C_13 N N_14 N_15 O O-1 O-2 O_16 O_17 O_18 F F-1 F_19 NE |
---|
[378] | 1631 | NE_20 NE_21 NE_22 NA NA+1 NA_23 MG MG+2 MG_24 MG_25 MG_26 AL AL+3 |
---|
| 1632 | AL_27 SI SI+4 SIV SI_28 SI_29 SI_30 P P_31 S S_32 S_33 S_34 CL CL-1 |
---|
| 1633 | CL_35 CL_37 AR AR_36 AR_40 K K+1 K_39 K_41 CA CA+2 CA_40 CA_44 SC SC+3 |
---|
| 1634 | SC_45 TI TI+2 TI+3 TI+4 TI_46 TI_47 TI_48 TI_49 TI_50 V V+2 V+3 V+5 |
---|
| 1635 | V_51 CR CR+2 CR+3 CR_50 CR_52 CR_53 CR_54 MN MN+2 MN+3 MN+4 MN_55 FE |
---|
| 1636 | FE+2 FE+3 FE_54 FE_56 FE_57 FE_58 CO CO+2 CO+3 CO_59 NI NI+2 NI+3 |
---|
| 1637 | NI_58 NI_60 NI_61 NI_62 NI_64 CU CU+1 CU+2 CU_63 CU_65 ZN ZN+2 ZN_64 |
---|
| 1638 | ZN_66 ZN_67 ZN_68 GA GA+3 GE GE+4 AS AS_75 SE BR BR-1 BR_79 BR_81 KR |
---|
| 1639 | RB RB+1 SR SR+2 Y Y+3 Y_89 ZR ZR+4 NB NB+3 NB+5 NB_93 MO MO+3 MO+5 |
---|
| 1640 | MO+6 TC TC_98 RU RU+3 RU+4 RH RH+3 RH+4 RH_103 PD PD+2 PD+4 AG AG+1 |
---|
| 1641 | AG+2 CD CD+2 CD_112 CD_113 CD_114 CD_116 IN IN+3 IN_113 IN_115 SN SN+2 |
---|
| 1642 | SN+4 SB SB+3 SB+5 TE I I-1 I_127 XE CS CS+1 CS_133 BA BA+2 LA LA+3 CE |
---|
| 1643 | CE+3 CE+4 PR PR+3 PR+4 PR_141 ND ND+3 PM PM+3 PM_147 SM SM+3 SM_152 |
---|
| 1644 | SM_154 EU EU+2 EU+3 EU_153 GD GD+3 GD_160 TB TB+3 TB_159 DY DY+3 HO |
---|
| 1645 | HO+3 HO_165 ER ER+3 TM TM+3 TM_169 YB YB+2 YB+3 LU LU+3 HF HF+4 TA |
---|
| 1646 | TA+5 TA_181 W W+6 RE OS OS+4 IR IR+3 IR+4 PT PT+2 PT+4 AU AU+1 AU+3 |
---|
| 1647 | AU_197 HG HG+1 HG+2 TL TL+1 TL+3 PB PB+2 PB+4 BI BI+3 BI+5 BI_209 PO |
---|
| 1648 | PO_210 AT AT_210 RN RN_222 FR FR_223 RA RA+2 RA_226 AC AC+3 AC_227 TH |
---|
| 1649 | TH+4 TH_232 PA PA_231 U U+3 U+4 U+6 U_235 U_238 NP NP+3 NP+4 NP+6 |
---|
| 1650 | NP_237 PU PU+3 PU+4 PU+6 PU_239 PU_240 PU_242 AM AM_243 CM CM_244 BK |
---|
| 1651 | BK_247 CF CF_249 |
---|
| 1652 | } |
---|
[536] | 1653 | # loop over the defined rows |
---|
[179] | 1654 | while {![catch {grid info $np.e[incr row]t}]} { |
---|
| 1655 | if !{$expgui(UseAtom$row)} continue |
---|
| 1656 | # ignore blank entries |
---|
| 1657 | set line {} |
---|
| 1658 | foreach i {t x y z} { |
---|
| 1659 | append line [string trim [$np.e${row}$i get]] |
---|
[92] | 1660 | } |
---|
[179] | 1661 | if {$line == ""} continue |
---|
[536] | 1662 | |
---|
[179] | 1663 | # validate the input |
---|
| 1664 | if {[set type [string trim [$np.e${row}t get]]] == ""} { |
---|
| 1665 | append err " line $row: No atom type specified\n" |
---|
| 1666 | } |
---|
[378] | 1667 | if {[lsearch $validatmtypes [string toupper $type]] == -1} { |
---|
[905] | 1668 | append err " line $row: Atom type $type is not defined for x-rays in GSAS. If you are fitting magnetic scattering, this could be defined. If so, use a different type and use EXPEDT to change the type back.\n\n" |
---|
[378] | 1669 | } |
---|
[179] | 1670 | set name [string trim [$np.e${row}n get]] |
---|
| 1671 | if {$name == "(default)"} {set name "/"} |
---|
| 1672 | if {$name == ""} {set name "/"} |
---|
| 1673 | foreach i {x y z o u} n {x y z Occ Uiso} { |
---|
| 1674 | if {[set $i [string trim [$np.e${row}$i get]]] == ""} { |
---|
| 1675 | append err " line $row: No value specified for $n\n" |
---|
| 1676 | } elseif {[catch {expr [set $i]}]} { |
---|
| 1677 | append err " line $row: The value for $n is invalid\n" |
---|
| 1678 | } |
---|
| 1679 | } |
---|
| 1680 | lappend atomlist "$type $x $y $z $o $name I $u" |
---|
[536] | 1681 | } |
---|
[92] | 1682 | if {$err != ""} { |
---|
[179] | 1683 | MyMessageBox -icon warning -message "Note Errors:\n$err" -parent $top |
---|
[536] | 1684 | return {} |
---|
[92] | 1685 | } |
---|
[179] | 1686 | if {[llength $atomlist] == 0} { |
---|
| 1687 | MyMessageBox -icon warning -message "No atoms to load!" -parent $top |
---|
[536] | 1688 | return {} |
---|
[179] | 1689 | } |
---|
[536] | 1690 | return $atomlist |
---|
| 1691 | } |
---|
| 1692 | |
---|
[905] | 1693 | proc runAddAtoms {phase atomlist} { |
---|
| 1694 | global expgui env expmap tcl_platform |
---|
| 1695 | # needed in UNIX |
---|
| 1696 | set env(ATOMDATA) [file join $expgui(gsasdir) data atmdata.dat] |
---|
| 1697 | set env(gsas) [file nativename $expgui(gsasdir)] |
---|
| 1698 | # needed in Windows |
---|
| 1699 | set env(GSAS) [file nativename $expgui(gsasdir)] |
---|
[536] | 1700 | |
---|
[92] | 1701 | set fp [open exptool.in w] |
---|
| 1702 | puts $fp "A" |
---|
| 1703 | puts $fp $phase |
---|
[179] | 1704 | # number of atoms |
---|
| 1705 | puts $fp [llength $atomlist] |
---|
| 1706 | foreach atomline $atomlist { |
---|
| 1707 | puts $fp $atomline |
---|
| 1708 | } |
---|
[92] | 1709 | close $fp |
---|
[905] | 1710 | |
---|
[92] | 1711 | # Save the current exp file |
---|
| 1712 | savearchiveexp |
---|
| 1713 | # disable the file changed monitor |
---|
| 1714 | set expgui(expModifiedLast) 0 |
---|
| 1715 | set expnam [file root [file tail $expgui(expfile)]] |
---|
[905] | 1716 | |
---|
| 1717 | set err [catch { |
---|
[92] | 1718 | if {$tcl_platform(platform) == "windows"} { |
---|
| 1719 | exec [file join $expgui(gsasexe) exptool.exe] $expnam \ |
---|
| 1720 | < exptool.in >& exptool.out |
---|
| 1721 | } else { |
---|
| 1722 | exec [file join $expgui(gsasexe) exptool] $expnam \ |
---|
| 1723 | < exptool.in >& exptool.out |
---|
| 1724 | } |
---|
[905] | 1725 | } errmsg] |
---|
[92] | 1726 | # load the revised exp file |
---|
[447] | 1727 | set oldatomlist $expmap(atomlist_$phase) |
---|
[92] | 1728 | loadexp $expgui(expfile) |
---|
| 1729 | set fp [open exptool.out r] |
---|
[905] | 1730 | set expgui(exptoolout) [read $fp] |
---|
[92] | 1731 | close $fp |
---|
[905] | 1732 | catch {file delete exptool.in exptool.out} |
---|
[447] | 1733 | if {[llength $oldatomlist] == [llength $expmap(atomlist_$phase))]} { |
---|
| 1734 | set err 1 |
---|
[905] | 1735 | if {$errmsg == ""} {set errmsg "No atom(s) added"} |
---|
[447] | 1736 | } |
---|
[905] | 1737 | } |
---|
| 1738 | |
---|
| 1739 | proc addatom {phase top} { |
---|
| 1740 | global expgui env expmap |
---|
| 1741 | set np $top.canvas.fr |
---|
| 1742 | # validate the atoms info |
---|
| 1743 | set atomlist [ValidateAtomsBox $top $np] |
---|
| 1744 | if {$atomlist == ""} return |
---|
| 1745 | |
---|
| 1746 | # ok add the atoms! |
---|
| 1747 | set errmsg [runAddAtoms $phase $atomlist] |
---|
| 1748 | RecordMacroEntry "runAddAtoms $phase [list $atomlist]" 0 |
---|
| 1749 | |
---|
| 1750 | destroy $top |
---|
| 1751 | set err 0 |
---|
[113] | 1752 | if {$errmsg != ""} { |
---|
[905] | 1753 | append errmsg "\n" $expgui(exptoolout) |
---|
[447] | 1754 | set err 1 |
---|
[113] | 1755 | } else { |
---|
[905] | 1756 | set errmsg $expgui(exptoolout) |
---|
[113] | 1757 | } |
---|
[447] | 1758 | if {$expgui(showexptool) || $err} { |
---|
| 1759 | set msg "Please review the result from adding the atom(s)" |
---|
| 1760 | if {$err} {append msg "\nIt appears an error occurred!"} |
---|
| 1761 | ShowBigMessage $top $msg $errmsg OK "" $err |
---|
[321] | 1762 | } |
---|
[92] | 1763 | } |
---|
[254] | 1764 | |
---|
[447] | 1765 | #--------------------------------------------------------------------------- |
---|
| 1766 | # commands to modify a group of selected atoms |
---|
| 1767 | #--------------------------------------------------------------------------- |
---|
[254] | 1768 | |
---|
| 1769 | # make the dialog to choose an action |
---|
| 1770 | proc MakeXformAtomsBox {phase} { |
---|
| 1771 | global expgui expmap |
---|
| 1772 | set numberList {} |
---|
| 1773 | set p $expgui(curPhase) |
---|
| 1774 | foreach AtomIndex $expgui(selectedatomlist) { |
---|
| 1775 | # get atom number & phase |
---|
| 1776 | set tuple [lindex $expmap(atomlistboxcontents) $AtomIndex] |
---|
| 1777 | lappend numberList [lindex $tuple 0] |
---|
| 1778 | } |
---|
| 1779 | if {$numberList == ""} return |
---|
| 1780 | if {[llength $numberList] > 1} { |
---|
| 1781 | set suffix s |
---|
| 1782 | set suffixy "ies" |
---|
| 1783 | } else { |
---|
| 1784 | set suffix "" |
---|
| 1785 | set suffixy "y" |
---|
| 1786 | } |
---|
| 1787 | set w .global |
---|
| 1788 | catch {destroy $w} |
---|
| 1789 | toplevel $w |
---|
| 1790 | wm title $w "Edit Atomic Parameter -- phase #$phase" |
---|
[321] | 1791 | bind $w <Key-F1> "MakeWWWHelp expgui2.html xform" |
---|
[254] | 1792 | # this needs to track by phase |
---|
| 1793 | grid [label $w.0 \ |
---|
| 1794 | -text "Modifying atom${suffix} [CompressList $numberList] Phase $phase" \ |
---|
| 1795 | -bg yellow -anchor center] -row 0 -column 0 -columnspan 10 \ |
---|
| 1796 | -sticky nsew |
---|
| 1797 | grid rowconfigure $w 0 -pad 5 |
---|
| 1798 | grid rowconfigure $w 1 -minsize 2 |
---|
| 1799 | |
---|
| 1800 | grid [TitleFrame $w.1 -bd 6 -relief groove -text "Modify coordinates"] \ |
---|
| 1801 | -row 2 -column 0 -columnspan 10 -sticky news |
---|
| 1802 | set w1 [$w.1 getframe] |
---|
| 1803 | set row 0 |
---|
| 1804 | foreach v {x y z} { |
---|
| 1805 | incr row |
---|
| 1806 | set col -1 |
---|
| 1807 | grid [label $w1.l$v -text "new $v = "] -column [incr col] -row $row |
---|
| 1808 | foreach o {x y z} { |
---|
| 1809 | grid [entry $w1.e${v}${o} -width 6] -column [incr col] -row $row |
---|
| 1810 | $w1.e${v}${o} delete 0 end |
---|
| 1811 | if {$v == $o} { |
---|
| 1812 | $w1.e${v}${o} insert end "1.0" |
---|
| 1813 | } else { |
---|
| 1814 | $w1.e${v}${o} insert end "0." |
---|
| 1815 | } |
---|
| 1816 | grid [label $w1.p${v}${o} -text " $o + "] \ |
---|
| 1817 | -column [incr col] -row $row |
---|
| 1818 | } |
---|
| 1819 | grid [entry $w1.e${v} -width 6] -column [incr col] -row $row |
---|
| 1820 | $w1.e${v} delete 0 end |
---|
| 1821 | $w1.e${v} insert end "0." |
---|
| 1822 | } |
---|
| 1823 | grid [button $w1.do -text "Transform Coordinates" \ |
---|
| 1824 | -command "XformAtomsCoord $phase [list $numberList] $w1" \ |
---|
| 1825 | ] -row [incr row] -column 0 -columnspan 10 |
---|
| 1826 | |
---|
[847] | 1827 | set shift [GetOrigin1Shift $phase] |
---|
| 1828 | grid [button $w1.d1 -text "Xform Origin 1 to Origin 2" \ |
---|
| 1829 | -command "XformAtoms2Origin2 $phase [list $numberList] $w1 [list $shift]" \ |
---|
[865] | 1830 | ] -row [incr row] -column 3 -columnspan 10 -sticky e |
---|
[847] | 1831 | if {$shift == ""} {$w1.d1 config -state disabled} |
---|
| 1832 | |
---|
[865] | 1833 | grid [button $w1.d4 -text "Reset Multiplicities" \ |
---|
| 1834 | -command "ResetMultiplicities $phase $w" \ |
---|
| 1835 | ] -row $row -column 0 -columnspan 3 -sticky w |
---|
[847] | 1836 | |
---|
[865] | 1837 | |
---|
[254] | 1838 | grid rowconfigure $w 3 -minsize 5 |
---|
| 1839 | grid [TitleFrame $w.4 -bd 6 -relief groove -text "Modify occupanc${suffixy}"] \ |
---|
| 1840 | -row 4 -column 0 -columnspan 10 -sticky news |
---|
| 1841 | set w2 [$w.4 getframe] |
---|
| 1842 | grid [label $w2.1 -text "Occupancy: "] -row 1 -column 0 |
---|
| 1843 | grid [entry $w2.e -width 10] -column 1 -row 1 |
---|
| 1844 | $w2.e delete 0 end |
---|
| 1845 | $w2.e insert end 1.0 |
---|
| 1846 | grid columnconfigure $w2 2 -weight 1 |
---|
| 1847 | grid [button $w2.do -text "Set Occupanc${suffixy}" \ |
---|
| 1848 | -command "XformAtomsOcc $phase [list $numberList] $w2" \ |
---|
| 1849 | ] -row 2 -column 0 -columnspan 10 |
---|
| 1850 | |
---|
| 1851 | grid rowconfigure $w 5 -minsize 5 |
---|
| 1852 | grid [TitleFrame $w.6 -bd 6 -relief groove \ |
---|
| 1853 | -text "Modify Displacement Parameter$suffix"] \ |
---|
| 1854 | -row 6 -column 0 -columnspan 10 -sticky news |
---|
| 1855 | set w2 [$w.6 getframe] |
---|
| 1856 | grid [entry $w2.e -width 10] -column 1 -row 1 |
---|
| 1857 | $w2.e delete 0 end |
---|
| 1858 | $w2.e insert end 0.025 |
---|
| 1859 | grid columnconfigure $w2 2 -weight 1 |
---|
| 1860 | grid [button $w2.do -text "Set U" \ |
---|
| 1861 | -command "XformAtomsU $phase [list $numberList] $w2" \ |
---|
| 1862 | ] -row 2 -column 0 -columnspan 10 |
---|
| 1863 | grid [frame $w2.f] -row 3 -column 0 -columnspan 10 |
---|
| 1864 | |
---|
[536] | 1865 | if {[lindex $expmap(phasetype) [expr {$p - 1}]] != 4} { |
---|
| 1866 | grid [label $w2.1 -text "Uiso or Uequiv: "] -row 1 -column 0 |
---|
| 1867 | grid [button $w2.f.iso -text "Set Isotropic" \ |
---|
| 1868 | -command "XformAtomsU $phase [list $numberList] iso" \ |
---|
| 1869 | ] -row 0 -column 0 |
---|
| 1870 | grid [button $w2.f.aniso -text "Set Anisotropic" \ |
---|
| 1871 | -command "XformAtomsU $phase [list $numberList] aniso" \ |
---|
| 1872 | ] -row 0 -column 1 |
---|
| 1873 | } else { |
---|
| 1874 | grid [label $w2.1 -text "Uiso: "] -row 1 -column 0 |
---|
| 1875 | } |
---|
| 1876 | |
---|
[865] | 1877 | grid rowconfigure $w 7 -minsize 5 |
---|
[536] | 1878 | if {[lindex $expmap(phasetype) [expr {$p - 1}]] != 4} { |
---|
| 1879 | grid [TitleFrame $w.8 -bd 6 -relief groove \ |
---|
| 1880 | -text "Erase Atom$suffix"] \ |
---|
| 1881 | -row 8 -column 0 -columnspan 10 -sticky news |
---|
| 1882 | set w2 [$w.8 getframe] |
---|
| 1883 | grid [button $w2.do -text "Erase Atom${suffix}" \ |
---|
| 1884 | -command "EraseAtoms $phase [list $numberList] $w" \ |
---|
| 1885 | ] -row 2 -column 0 -columnspan 10 |
---|
| 1886 | } |
---|
[254] | 1887 | |
---|
[865] | 1888 | grid rowconfigure $w 11 -minsize 5 |
---|
| 1889 | grid [frame $w.b] -row 12 -column 0 -columnspan 10 -sticky ew |
---|
[321] | 1890 | pack [button $w.b.3 -text Close -command "destroy $w"] -side left \ |
---|
| 1891 | -padx 5 -pady 5 |
---|
| 1892 | pack [button $w.b.help -text Help -bg yellow \ |
---|
| 1893 | -command "MakeWWWHelp expgui2.html xform"] -side right \ |
---|
| 1894 | -padx 5 -pady 5 |
---|
[254] | 1895 | bind $w <Return> "destroy $w" |
---|
| 1896 | |
---|
| 1897 | # force the window to stay on top |
---|
| 1898 | putontop $w |
---|
| 1899 | focus $w.b.3 |
---|
| 1900 | tkwait window $w |
---|
| 1901 | afterputontop |
---|
| 1902 | # if there are selected atoms, reset their display |
---|
| 1903 | if {[llength $expgui(selectedatomlist)] != 0} editRecord |
---|
| 1904 | } |
---|
| 1905 | |
---|
| 1906 | # transform the coordinates |
---|
| 1907 | proc XformAtomsCoord {phase numberList w1} { |
---|
[536] | 1908 | global expgui expmap |
---|
| 1909 | if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} { |
---|
| 1910 | set cmd mmatominfo |
---|
| 1911 | } else { |
---|
| 1912 | set cmd atominfo |
---|
| 1913 | } |
---|
[254] | 1914 | # get the matrix |
---|
| 1915 | foreach v {x y z} { |
---|
| 1916 | foreach o {x y z} { |
---|
| 1917 | set matrix(${v}${o}) [$w1.e${v}${o} get] |
---|
| 1918 | } |
---|
| 1919 | set matrix(${v}) [$w1.e${v} get] |
---|
| 1920 | } |
---|
| 1921 | foreach atom $numberList { |
---|
| 1922 | foreach v {x y z} { |
---|
[536] | 1923 | set $v [$cmd $phase $atom $v] |
---|
[254] | 1924 | } |
---|
| 1925 | foreach v {x y z} { |
---|
| 1926 | set new$v $matrix(${v}) |
---|
| 1927 | foreach o {x y z} { |
---|
| 1928 | set new$v [expr [set new$v] + $matrix(${v}${o})*[set $o]] |
---|
| 1929 | } |
---|
[536] | 1930 | $cmd $phase $atom $v set [set new$v] |
---|
[905] | 1931 | RecordMacroEntry "$cmd $phase $atom $v set [set new$v]" 0 |
---|
[254] | 1932 | } |
---|
| 1933 | incr expgui(changed) |
---|
| 1934 | } |
---|
[905] | 1935 | RecordMacroEntry "incr expgui(changed)" 0 |
---|
[865] | 1936 | # update multiplicities for the phase |
---|
| 1937 | set parent [winfo toplevel $w1] |
---|
| 1938 | ResetMultiplicities $phase $parent |
---|
| 1939 | SelectOnePhase $phase |
---|
| 1940 | MyMessageBox -parent $parent -type OK -default ok -title "Transform applied" \ |
---|
| 1941 | -message "The coordinates of atoms [CompressList $numberList] have been transformed" |
---|
| 1942 | # UpdateAtomLine $numberList $phase |
---|
| 1943 | destroy $parent |
---|
[254] | 1944 | } |
---|
| 1945 | |
---|
| 1946 | # set the occupancies to a single value |
---|
| 1947 | proc XformAtomsOcc {phase numberList w2} { |
---|
[536] | 1948 | global expgui expmap |
---|
| 1949 | if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} { |
---|
| 1950 | set cmd mmatominfo |
---|
| 1951 | } else { |
---|
| 1952 | set cmd atominfo |
---|
| 1953 | } |
---|
[254] | 1954 | # get the value |
---|
| 1955 | set val [$w2.e get] |
---|
| 1956 | foreach atom $numberList { |
---|
[536] | 1957 | $cmd $phase $atom frac set $val |
---|
[905] | 1958 | RecordMacroEntry "$cmd $phase $atom frac set $val" 0 |
---|
[254] | 1959 | incr expgui(changed) |
---|
| 1960 | } |
---|
[905] | 1961 | RecordMacroEntry "incr expgui(changed)" 0 |
---|
[536] | 1962 | UpdateAtomLine $numberList $phase |
---|
[254] | 1963 | } |
---|
| 1964 | |
---|
| 1965 | # transform Uiso or Uij; if anisotropic set Uequiv to Uij |
---|
| 1966 | proc XformAtomsU {phase numberList w2} { |
---|
| 1967 | global expgui |
---|
[905] | 1968 | set istart $expgui(changed) |
---|
[254] | 1969 | if {$w2 == "iso"} { |
---|
| 1970 | foreach atom $numberList { |
---|
| 1971 | if {[atominfo $phase $atom temptype] != "I"} { |
---|
| 1972 | atominfo $phase $atom temptype set I |
---|
[905] | 1973 | RecordMacroEntry "atominfo $phase $atom temptype set I" 0 |
---|
[487] | 1974 | incr expgui(changed) |
---|
[254] | 1975 | } |
---|
| 1976 | } |
---|
| 1977 | } elseif {$w2 == "aniso"} { |
---|
| 1978 | foreach atom $numberList { |
---|
| 1979 | if {[atominfo $phase $atom temptype] == "I"} { |
---|
| 1980 | atominfo $phase $atom temptype set A |
---|
[905] | 1981 | RecordMacroEntry "atominfo $phase $atom temptype set A" 0 |
---|
[487] | 1982 | incr expgui(changed) |
---|
[254] | 1983 | } |
---|
| 1984 | } |
---|
| 1985 | } else { |
---|
| 1986 | # get the value |
---|
| 1987 | set val [$w2.e get] |
---|
| 1988 | foreach atom $numberList { |
---|
[536] | 1989 | global expmap |
---|
| 1990 | if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} { |
---|
| 1991 | mmatominfo $phase $atom Uiso set $val |
---|
[905] | 1992 | RecordMacroEntry "mmatominfo $phase $atom Uiso set $val" 0 |
---|
[536] | 1993 | } elseif {[atominfo $phase $atom temptype] == "I"} { |
---|
[254] | 1994 | atominfo $phase $atom Uiso set $val |
---|
[905] | 1995 | RecordMacroEntry "atominfo $phase $atom Uiso set $val" 0 |
---|
[254] | 1996 | } else { |
---|
[905] | 1997 | foreach var {U11 U22 U33} { |
---|
| 1998 | atominfo $phase $atom $var set $val |
---|
| 1999 | RecordMacroEntry "atominfo $phase $atom $var set $val" 0 |
---|
| 2000 | } |
---|
| 2001 | foreach var {U12 U13 U23} { |
---|
| 2002 | atominfo $phase $atom $var set 0.0 |
---|
| 2003 | RecordMacroEntry "atominfo $phase $atom $var set 0.0" 0 |
---|
| 2004 | } |
---|
[254] | 2005 | } |
---|
| 2006 | incr expgui(changed) |
---|
| 2007 | } |
---|
| 2008 | } |
---|
[905] | 2009 | if {$istart != $expgui(changed)} {RecordMacroEntry "incr expgui(changed)" 0} |
---|
[536] | 2010 | UpdateAtomLine $numberList $phase |
---|
[254] | 2011 | } |
---|
| 2012 | |
---|
| 2013 | # confirm and erase atoms |
---|
| 2014 | proc EraseAtoms {phase numberList w2} { |
---|
| 2015 | global expgui |
---|
| 2016 | if {[llength $numberList] <= 0} return |
---|
| 2017 | # make a list of atoms |
---|
| 2018 | foreach atom $numberList { |
---|
| 2019 | append atomlist "\n\t$atom [atominfo $phase $atom label]" |
---|
| 2020 | } |
---|
| 2021 | set msg "OK to remove the following [llength $numberList] atoms from phase $phase:$atomlist" |
---|
| 2022 | set val [MyMessageBox -parent $w2 -type okcancel -icon warning \ |
---|
| 2023 | -default cancel -title "Confirm Erase" -message $msg] |
---|
| 2024 | if {$val == "ok"} { |
---|
| 2025 | foreach atom $numberList { |
---|
| 2026 | EraseAtom $atom $phase |
---|
[905] | 2027 | RecordMacroEntry "EraseAtom $atom $phase" 0 |
---|
[254] | 2028 | incr expgui(changed) |
---|
| 2029 | } |
---|
[905] | 2030 | RecordMacroEntry "incr expgui(changed)" 0 |
---|
[254] | 2031 | mapexp |
---|
[905] | 2032 | RecordMacroEntry "mapexp" 0 |
---|
[536] | 2033 | DisplayAllAtoms $phase |
---|
[254] | 2034 | destroy $w2 |
---|
| 2035 | } |
---|
| 2036 | } |
---|
| 2037 | |
---|
[447] | 2038 | #----------- more Add Phase routines (import) ------------------------------- |
---|
[268] | 2039 | proc ImportPhase {format np} { |
---|
| 2040 | global expgui |
---|
[905] | 2041 | if {[llength $expgui(extensions_$format)] == 1} { |
---|
[920] | 2042 | lappend typelist [list $format $expgui(extensions_$format)] |
---|
[905] | 2043 | } else { |
---|
| 2044 | foreach item $expgui(extensions_$format) { |
---|
| 2045 | lappend typelist [list "All $format" $item] |
---|
| 2046 | lappend typelist [list "$format $item" $item] |
---|
| 2047 | } |
---|
[268] | 2048 | } |
---|
| 2049 | lappend typelist [list "All files" *] |
---|
| 2050 | set file [tk_getOpenFile -parent $np -filetypes $typelist] |
---|
| 2051 | if {![file exists $file]} return |
---|
| 2052 | # read in the file |
---|
| 2053 | set input [$expgui(proc_$format) $file] |
---|
| 2054 | catch { |
---|
| 2055 | $np.bf.b1 config -text "Continue" -command "addphase $np; AddAtomsList" |
---|
| 2056 | bind $np <Return> "addphase $np; AddAtomsList" |
---|
| 2057 | } |
---|
| 2058 | catch { |
---|
| 2059 | $np.t1 delete 0 end |
---|
| 2060 | $np.t1 insert end "from $file" |
---|
| 2061 | } |
---|
| 2062 | $np.t2 delete 0 end |
---|
| 2063 | $np.t2 insert end [lindex $input 0] |
---|
| 2064 | foreach i {.e1a .e1b .e1c .e2a .e2b .e2g} val [lindex $input 1] { |
---|
| 2065 | $np.f$i delete 0 end |
---|
| 2066 | $np.f$i insert end $val |
---|
| 2067 | } |
---|
| 2068 | set expgui(coordList) [lindex $input 2] |
---|
[284] | 2069 | set msg [lindex $input 3] |
---|
| 2070 | if {$msg != ""} { |
---|
[378] | 2071 | catch {destroy $np.msg} |
---|
| 2072 | grid [label $np.msg -text $msg -fg red -anchor center -bd 4 -relief raised] \ |
---|
| 2073 | -column 0 -columnspan 99 -row 20 -sticky ew |
---|
[284] | 2074 | } |
---|
[268] | 2075 | } |
---|
| 2076 | |
---|
[379] | 2077 | proc ImportAtoms {format top phase} { |
---|
[268] | 2078 | global expgui |
---|
[905] | 2079 | if {[llength $expgui(extensions_$format)] == 1} { |
---|
[921] | 2080 | lappend typelist [list $format $expgui(extensions_$format)] |
---|
[905] | 2081 | } else { |
---|
| 2082 | foreach item $expgui(extensions_$format) { |
---|
| 2083 | lappend typelist [list "All $format" $item] |
---|
| 2084 | lappend typelist [list "$format $item" $item] |
---|
| 2085 | } |
---|
[268] | 2086 | } |
---|
| 2087 | lappend typelist [list "All files" *] |
---|
| 2088 | set file [tk_getOpenFile -parent $top -filetypes $typelist] |
---|
| 2089 | if {![file exists $file]} return |
---|
[536] | 2090 | # disable during read |
---|
| 2091 | catch { |
---|
| 2092 | foreach b "$top.b1 $top.b2 $top.fr.b3" { |
---|
| 2093 | $b config -state disabled |
---|
| 2094 | } |
---|
| 2095 | } |
---|
[268] | 2096 | # read in the file |
---|
| 2097 | set input [$expgui(proc_$format) $file] |
---|
| 2098 | # add atoms to table |
---|
| 2099 | foreach item [lindex $input 2] { |
---|
| 2100 | set row [MakeAddAtomsRow $top] |
---|
| 2101 | set np $top.canvas.fr |
---|
| 2102 | foreach val $item w {n x y z t o u} { |
---|
| 2103 | if {$val != ""} { |
---|
| 2104 | $np.e${row}$w delete 0 end |
---|
| 2105 | $np.e${row}$w insert end $val |
---|
| 2106 | } |
---|
| 2107 | } |
---|
| 2108 | } |
---|
[379] | 2109 | # sort the atoms by number, so that empty entries are at the bottom |
---|
| 2110 | sortAddAtoms $phase $top number |
---|
[536] | 2111 | # reenable |
---|
| 2112 | catch { |
---|
| 2113 | foreach b "$top.b1 $top.b2 $top.fr.b3" { |
---|
| 2114 | $b config -state normal |
---|
| 2115 | } |
---|
| 2116 | } |
---|
[268] | 2117 | } |
---|
| 2118 | |
---|
| 2119 | proc AddAtomsList {} { |
---|
| 2120 | global expgui expmap |
---|
[378] | 2121 | # skip if we aborted out of addphase |
---|
| 2122 | if {$expgui(oldphaselist) == -1} return |
---|
[268] | 2123 | # find the new phase |
---|
| 2124 | set phase {} |
---|
| 2125 | foreach p $expmap(phaselist) { |
---|
| 2126 | if {[lsearch $expgui(oldphaselist) $p] == -1} { |
---|
| 2127 | set phase $p |
---|
| 2128 | break |
---|
| 2129 | } |
---|
| 2130 | } |
---|
| 2131 | if {$phase == ""} return |
---|
| 2132 | MakeAddAtomsBox $phase $expgui(coordList) |
---|
| 2133 | } |
---|
| 2134 | |
---|
| 2135 | # get the input formats by sourcing files named import_*.tcl |
---|
| 2136 | proc GetImportFormats {} { |
---|
| 2137 | global expgui tcl_platform |
---|
| 2138 | # only needs to be done once |
---|
| 2139 | if [catch {set expgui(importFormatList)}] { |
---|
| 2140 | set filelist [glob -nocomplain [file join $expgui(scriptdir) import_*.tcl]] |
---|
| 2141 | foreach file $filelist { |
---|
[641] | 2142 | set description "" |
---|
[268] | 2143 | source $file |
---|
[641] | 2144 | if {$description != ""} { |
---|
| 2145 | lappend expgui(importFormatList) $description |
---|
| 2146 | if {$tcl_platform(platform) == "unix"} { |
---|
| 2147 | set extensions "[string tolower $extensions] [string toupper $extensions]" |
---|
| 2148 | } |
---|
| 2149 | set expgui(extensions_$description) $extensions |
---|
| 2150 | set expgui(proc_$description) $procname |
---|
[268] | 2151 | } |
---|
| 2152 | } |
---|
| 2153 | } |
---|
| 2154 | } |
---|
| 2155 | |
---|
| 2156 | proc MakeReplacePhaseBox {} { |
---|
| 2157 | global expmap expgui tcl_platform |
---|
| 2158 | |
---|
| 2159 | set expgui(coordList) {} |
---|
| 2160 | # ignore the command if no phase is selected |
---|
| 2161 | foreach p {1 2 3 4 5 6 7 8 9} { |
---|
| 2162 | if {[lsearch $expmap(phaselist) $expgui(curPhase)] == -1} { |
---|
| 2163 | return |
---|
| 2164 | } |
---|
| 2165 | } |
---|
| 2166 | |
---|
| 2167 | set top .newphase |
---|
| 2168 | catch {destroy $top} |
---|
| 2169 | toplevel $top |
---|
[321] | 2170 | bind $top <Key-F1> "MakeWWWHelp expgui2.html replacephase" |
---|
[268] | 2171 | |
---|
| 2172 | grid [label $top.l1 -text "Replacing phase #$expgui(curPhase)" \ |
---|
| 2173 | -bg yellow -anchor center] -column 0 -columnspan 8 -row 0 -sticky ew |
---|
| 2174 | grid [label $top.l3a -text "Current Space Group: "] \ |
---|
| 2175 | -column 0 -row 2 -columnspan 2 -sticky e |
---|
| 2176 | grid [label $top.l3b -text [phaseinfo $expgui(curPhase) spacegroup]\ |
---|
| 2177 | -bd 4 -relief groove] \ |
---|
| 2178 | -column 2 -row 2 -sticky ew |
---|
| 2179 | grid [label $top.l4 -text "New Space Group: "] \ |
---|
| 2180 | -column 0 -row 3 -columnspan 2 -sticky e |
---|
| 2181 | grid [entry $top.t2 -width 12] -column 2 -row 3 -sticky w |
---|
| 2182 | grid [radiobutton $top.r1 -text "Reenter current atoms"\ |
---|
| 2183 | -variable expgui(DeleteAllAtoms) -value 0] \ |
---|
| 2184 | -column 1 -row 4 -columnspan 8 -sticky w |
---|
| 2185 | grid [radiobutton $top.r2 -text "Delete current atoms" \ |
---|
| 2186 | -variable expgui(DeleteAllAtoms) -value 1] \ |
---|
| 2187 | -column 1 -row 5 -columnspan 8 -sticky w |
---|
| 2188 | |
---|
| 2189 | grid [frame $top.f -bd 4 -relief groove] \ |
---|
| 2190 | -column 3 -row 2 -columnspan 3 -rowspan 4 |
---|
| 2191 | set col -1 |
---|
| 2192 | foreach i {a b c} { |
---|
| 2193 | grid [label $top.f.l1$i -text " $i "] -column [incr col] -row 1 |
---|
| 2194 | grid [entry $top.f.e1$i -width 12] -column [incr col] -row 1 |
---|
| 2195 | $top.f.e1$i delete 0 end |
---|
| 2196 | $top.f.e1$i insert 0 [phaseinfo $expgui(curPhase) $i] |
---|
| 2197 | } |
---|
| 2198 | set col -1 |
---|
| 2199 | foreach i {a b g} var {alpha beta gamma} { |
---|
[413] | 2200 | grid [label $top.f.l2$i -text $i] -column [incr col] -row 2 |
---|
| 2201 | set font [$top.f.l2$i cget -font] |
---|
| 2202 | $top.f.l2$i config -font "Symbol [lrange $font 1 end]" |
---|
[268] | 2203 | grid [entry $top.f.e2$i -width 12] -column [incr col] -row 2 |
---|
| 2204 | $top.f.e2$i delete 0 end |
---|
| 2205 | $top.f.e2$i insert 0 [phaseinfo $expgui(curPhase) $var] |
---|
| 2206 | } |
---|
| 2207 | |
---|
| 2208 | grid [button $top.b1 -text Continue \ |
---|
| 2209 | -command "replacephase1 $top $expgui(curPhase)"] \ |
---|
| 2210 | -column 0 -row 6 -sticky w |
---|
| 2211 | bind $top <Return> "replacephase1 $top $expgui(curPhase)" |
---|
| 2212 | grid [button $top.b2 -text Cancel \ |
---|
| 2213 | -command "destroy $top"] -column 1 -row 6 -sticky w |
---|
[321] | 2214 | grid [button $top.help -text Help -bg yellow \ |
---|
| 2215 | -command "MakeWWWHelp expgui2.html replacephase"] \ |
---|
| 2216 | -column 2 -row 6 |
---|
[268] | 2217 | |
---|
| 2218 | # get the input formats if not already defined |
---|
| 2219 | GetImportFormats |
---|
| 2220 | if {[llength $expgui(importFormatList)] > 0} { |
---|
| 2221 | grid [frame $top.fr -bd 4 -relief groove] \ |
---|
| 2222 | -column 2 -row 6 -columnspan 8 -sticky e |
---|
| 2223 | grid [button $top.fr.b3 -text "Import phase from: " \ |
---|
| 2224 | -command "ImportPhase \$expgui(importFormat) $top"] \ |
---|
| 2225 | -column 0 -row 0 -sticky e |
---|
[553] | 2226 | set menu [eval tk_optionMenu $top.fr.b4 expgui(importFormat) \ |
---|
| 2227 | $expgui(importFormatList)] |
---|
| 2228 | for {set i 0} {$i <= [$menu index end]} {incr i} { |
---|
[754] | 2229 | $menu entryconfig $i -command "ImportPhase \$expgui(importFormat) $top" |
---|
[553] | 2230 | } |
---|
[268] | 2231 | grid $top.fr.b4 -column 1 -row 0 -sticky w |
---|
| 2232 | grid rowconfig $top.fr 0 -pad 10 |
---|
| 2233 | grid columnconfig $top.fr 0 -pad 10 |
---|
| 2234 | grid columnconfig $top.fr 1 -pad 10 |
---|
[284] | 2235 | # grid columnconfig $top 4 -weight 1 |
---|
| 2236 | grid columnconfig $top 2 -weight 1 |
---|
[268] | 2237 | } |
---|
| 2238 | |
---|
| 2239 | wm title $top "Replace phase $expgui(curPhase)" |
---|
| 2240 | |
---|
[326] | 2241 | # set grab, etc. |
---|
[268] | 2242 | putontop $top |
---|
| 2243 | |
---|
| 2244 | tkwait window $top |
---|
| 2245 | |
---|
[326] | 2246 | # fix grab... |
---|
[268] | 2247 | afterputontop |
---|
| 2248 | } |
---|
| 2249 | |
---|
| 2250 | proc replacephase1 {top phase} { |
---|
| 2251 | # validate cell & space group & save to pass |
---|
| 2252 | global expgui expmap |
---|
| 2253 | set expgui(SetAddAtomsScroll) 0 |
---|
| 2254 | # validate the input |
---|
| 2255 | set err {} |
---|
| 2256 | set spg [$top.t2 get] |
---|
| 2257 | if {[string trim $spg] == ""} { |
---|
| 2258 | append err " Space group cannot be blank\n" |
---|
| 2259 | } |
---|
| 2260 | set cell {} |
---|
| 2261 | foreach i {a b c a b g} lbl {a b c alpha beta gamma} n {1 1 1 2 2 2} { |
---|
| 2262 | set $lbl [$top.f.e${n}$i get] |
---|
| 2263 | if {[string trim [set $lbl]] == ""} { |
---|
| 2264 | append err " $lbl cannot be blank\n" |
---|
| 2265 | } elseif {[catch {expr [set $lbl]}]} { |
---|
| 2266 | append err " [set $lbl] is not valid for $lbl\n" |
---|
| 2267 | } |
---|
| 2268 | lappend cell [set $lbl] |
---|
| 2269 | } |
---|
| 2270 | |
---|
| 2271 | if {$err != ""} { |
---|
[383] | 2272 | MyMessageBox -parent $top -title "Replace Phase Error" -icon warning \ |
---|
| 2273 | -message "The following error(s) were found in your input:\n$err" |
---|
[268] | 2274 | return |
---|
| 2275 | } |
---|
| 2276 | |
---|
| 2277 | # check the space group |
---|
| 2278 | set fp [open spg.in w] |
---|
| 2279 | puts $fp "N" |
---|
| 2280 | puts $fp "N" |
---|
| 2281 | puts $fp $spg |
---|
| 2282 | puts $fp "Q" |
---|
| 2283 | close $fp |
---|
| 2284 | global tcl_platform |
---|
| 2285 | catch { |
---|
| 2286 | if {$tcl_platform(platform) == "windows"} { |
---|
| 2287 | exec [file join $expgui(gsasexe) spcgroup.exe] < spg.in >& spg.out |
---|
| 2288 | } else { |
---|
| 2289 | exec [file join $expgui(gsasexe) spcgroup] < spg.in >& spg.out |
---|
| 2290 | } |
---|
| 2291 | } |
---|
| 2292 | set fp [open spg.out r] |
---|
| 2293 | set out [read $fp] |
---|
| 2294 | close $fp |
---|
| 2295 | # attempt to parse out the output (fix up if parse did not work) |
---|
| 2296 | if {[regexp "space group symbol.*>(.*)Enter a new space group symbol" \ |
---|
| 2297 | $out a b ] != 1} {set b $out} |
---|
| 2298 | if {[string first Error $b] != -1} { |
---|
| 2299 | # got an error, show it |
---|
| 2300 | ShowBigMessage \ |
---|
| 2301 | $top.error \ |
---|
| 2302 | "Error processing space group\nReview error message below" \ |
---|
[447] | 2303 | $b OK "" 1 |
---|
[268] | 2304 | return |
---|
| 2305 | } else { |
---|
| 2306 | # show the result and confirm |
---|
| 2307 | set opt [ShowBigMessage \ |
---|
| 2308 | $top.check \ |
---|
| 2309 | "Check the symmetry operators in the output below" \ |
---|
| 2310 | $b \ |
---|
| 2311 | {Continue Redo} ] |
---|
| 2312 | if {$opt > 1} return |
---|
| 2313 | } |
---|
| 2314 | file delete spg.in spg.out |
---|
| 2315 | # draw coordinates box |
---|
| 2316 | eval destroy [winfo children $top] |
---|
| 2317 | grid [label $top.l1 -relief groove -bd 4 -anchor center\ |
---|
| 2318 | -text "Atom list for phase #$phase"] \ |
---|
| 2319 | -column 0 -row 0 \ |
---|
| 2320 | -sticky we -columnspan 10 |
---|
| 2321 | grid [canvas $top.canvas \ |
---|
| 2322 | -scrollregion {0 0 5000 500} -width 0 -height 250 \ |
---|
| 2323 | -yscrollcommand "$top.scroll set"] \ |
---|
| 2324 | -column 0 -row 2 -columnspan 4 -sticky nsew |
---|
| 2325 | grid columnconfigure $top 3 -weight 1 |
---|
| 2326 | grid rowconfigure $top 2 -weight 1 |
---|
| 2327 | grid rowconfigure $top 1 -pad 5 |
---|
| 2328 | scrollbar $top.scroll \ |
---|
| 2329 | -command "$top.canvas yview" |
---|
| 2330 | frame $top.canvas.fr |
---|
| 2331 | $top.canvas create window 0 0 -anchor nw -window $top.canvas.fr |
---|
| 2332 | |
---|
| 2333 | set np $top.canvas.fr |
---|
| 2334 | set row 0 |
---|
| 2335 | set col 0 |
---|
[379] | 2336 | grid [label $np.l_${row}0 -text " # "] -column $col -row $row |
---|
| 2337 | foreach i {Atom\ntype Name x y z Occ Uiso} \ |
---|
| 2338 | var {type name x y z occ uiso} { |
---|
| 2339 | grid [button $np.l_${row}$i -text $i -padx 0 -pady 0 \ |
---|
| 2340 | -command "sortAddAtoms $phase $top $var"] \ |
---|
| 2341 | -column [incr col] -row $row -sticky nsew |
---|
[268] | 2342 | } |
---|
[379] | 2343 | grid [label $np.l_${row}Use -text Use\nFlag] -column [incr col] -row $row |
---|
[268] | 2344 | |
---|
| 2345 | # add the old atoms, if appropriate |
---|
| 2346 | if {!$expgui(DeleteAllAtoms)} { |
---|
| 2347 | # loop over all atoms |
---|
| 2348 | foreach atom $expmap(atomlist_$phase) { |
---|
| 2349 | set row [MakeAddAtomsRow $top] |
---|
| 2350 | # add all atoms in the current phase to the list |
---|
| 2351 | foreach w {n x y z t o} var {label x y z type frac} { |
---|
| 2352 | $np.e${row}$w delete 0 end |
---|
| 2353 | $np.e${row}$w insert end [atominfo $phase $atom $var] |
---|
| 2354 | } |
---|
| 2355 | $np.e${row}u delete 0 end |
---|
| 2356 | if {[atominfo $phase $atom temptype] == "I"} { |
---|
| 2357 | $np.e${row}u insert end [atominfo $phase $atom Uiso] |
---|
| 2358 | } else { |
---|
| 2359 | $np.e${row}u insert end [expr ( \ |
---|
| 2360 | [atominfo $phase $atom U11] + \ |
---|
| 2361 | [atominfo $phase $atom U22] + \ |
---|
| 2362 | [atominfo $phase $atom U33]) / 3.] |
---|
| 2363 | } |
---|
| 2364 | } |
---|
| 2365 | } |
---|
| 2366 | |
---|
| 2367 | # add coordinates that have been read in, if any |
---|
| 2368 | foreach item $expgui(coordList) { |
---|
| 2369 | set row [MakeAddAtomsRow $top] |
---|
| 2370 | foreach val $item w {n x y z t o u} { |
---|
| 2371 | if {$val != ""} { |
---|
| 2372 | $np.e${row}$w delete 0 end |
---|
| 2373 | $np.e${row}$w insert end $val |
---|
| 2374 | } |
---|
| 2375 | } |
---|
| 2376 | } |
---|
| 2377 | # a blank spot in the table |
---|
| 2378 | MakeAddAtomsRow $top |
---|
| 2379 | |
---|
| 2380 | bind $top <Configure> "SetAddAtomsScroll $top" |
---|
| 2381 | grid rowconfigure $top 3 -min 10 |
---|
| 2382 | grid [button $top.b1 -text "Continue"\ |
---|
| 2383 | -command "replacephase2 $phase $top [list $spg] [list $cell]"] \ |
---|
| 2384 | -column 0 -row 5 -sticky w |
---|
| 2385 | bind $top <Return> "replacephase2 $phase $top [list $spg] [list $cell]" |
---|
| 2386 | grid [button $top.b2 -text Cancel \ |
---|
| 2387 | -command "destroy $top"] -column 1 -row 5 -sticky w |
---|
| 2388 | if {[llength $expgui(importFormatList)] > 0} { |
---|
| 2389 | grid [frame $top.fr -bd 4 -relief groove] \ |
---|
| 2390 | -column 3 -row 5 -columnspan 2 -sticky e |
---|
| 2391 | grid [button $top.fr.b3 -text "Import atoms from: " \ |
---|
[379] | 2392 | -command "ImportAtoms \$expgui(importFormat) $top $phase"] \ |
---|
[268] | 2393 | -column 0 -row 0 -sticky e |
---|
[553] | 2394 | set menu [eval tk_optionMenu $top.fr.b4 expgui(importFormat) \ |
---|
| 2395 | $expgui(importFormatList)] |
---|
| 2396 | for {set i 0} {$i <= [$menu index end]} {incr i} { |
---|
| 2397 | $menu entryconfig $i -command "ImportAtoms \$expgui(importFormat) $top $phase" |
---|
| 2398 | } |
---|
[268] | 2399 | grid $top.fr.b4 -column 1 -row 0 -sticky w |
---|
| 2400 | grid rowconfig $top.fr 0 -pad 10 |
---|
| 2401 | grid columnconfig $top.fr 0 -pad 10 |
---|
| 2402 | grid columnconfig $top.fr 1 -pad 10 |
---|
| 2403 | } |
---|
| 2404 | |
---|
| 2405 | grid [button $top.b3 -text "More atom boxes" \ |
---|
| 2406 | -command "MakeAddAtomsRow $top"] -column 3 \ |
---|
| 2407 | -columnspan 2 -row 4 -sticky e |
---|
| 2408 | |
---|
| 2409 | wm title $top "Replacing phase: Enter atoms" |
---|
| 2410 | SetAddAtomsScroll $top |
---|
| 2411 | |
---|
[326] | 2412 | # fix grab for old window |
---|
[268] | 2413 | afterputontop |
---|
[326] | 2414 | # set grab, etc. |
---|
[268] | 2415 | putontop $top |
---|
| 2416 | } |
---|
| 2417 | |
---|
| 2418 | proc replacephase2 {phase top spg cell} { |
---|
[905] | 2419 | global expgui expmap |
---|
[268] | 2420 | # validate coordinates |
---|
| 2421 | set np $top.canvas.fr |
---|
[536] | 2422 | # validate the atoms info |
---|
| 2423 | set atomlist [ValidateAtomsBox $top $np] |
---|
[553] | 2424 | if {$atomlist == ""} return |
---|
[268] | 2425 | |
---|
| 2426 | pleasewait "updating phase" |
---|
[905] | 2427 | replacephase3 $phase [list $spg] [list $cell] [list $atomlist] |
---|
[268] | 2428 | |
---|
[447] | 2429 | set err 0 |
---|
[536] | 2430 | if {[llength $atomlist] != [llength $expmap(atomlist_$phase))]} { |
---|
[447] | 2431 | set err 1 |
---|
| 2432 | } |
---|
[268] | 2433 | if {$errmsg != ""} { |
---|
| 2434 | append errmsg "\n" $out |
---|
[447] | 2435 | set err 1 |
---|
[268] | 2436 | } else { |
---|
| 2437 | set errmsg $out |
---|
| 2438 | } |
---|
| 2439 | donewait |
---|
[447] | 2440 | if {$expgui(showexptool) || $err} { |
---|
| 2441 | set msg "Please review the result from adding the atom(s)" |
---|
| 2442 | if {$err} {append msg "\nIt appears an error occurred!"} |
---|
| 2443 | ShowBigMessage $top $msg $errmsg OK "" $err |
---|
[321] | 2444 | } |
---|
[668] | 2445 | # set the powpref warning (2 = required) |
---|
| 2446 | set expgui(needpowpref) 2 |
---|
| 2447 | set msg "A phase was replaced" |
---|
| 2448 | if {[string first $msg $expgui(needpowpref_why)] == -1} { |
---|
| 2449 | append expgui(needpowpref_why) "\t$msg\n" |
---|
| 2450 | } |
---|
[268] | 2451 | destroy $top |
---|
| 2452 | } |
---|
| 2453 | |
---|
[905] | 2454 | |
---|
[921] | 2455 | proc replacephase3 {phase spg cell atomlist} { |
---|
[905] | 2456 | global expgui expmap |
---|
| 2457 | # replace spacegroup and cell |
---|
| 2458 | phaseinfo $phase spacegroup set $spg |
---|
| 2459 | RecordMacroEntry "phaseinfo $phase spacegroup set [list $spg]" 0 |
---|
| 2460 | foreach val $cell var {a b c alpha beta gamma} { |
---|
| 2461 | phaseinfo $phase $var set $val |
---|
| 2462 | RecordMacroEntry "phaseinfo $phase $var set $val" 0 |
---|
| 2463 | } |
---|
| 2464 | incr expgui(changed) |
---|
| 2465 | # delete all atoms |
---|
| 2466 | foreach i $expmap(atomlist_$phase) { |
---|
| 2467 | EraseAtom $i $phase |
---|
| 2468 | RecordMacroEntry "EraseAtom $i $phase" 0 |
---|
| 2469 | incr expgui(changed) |
---|
| 2470 | } |
---|
| 2471 | RecordMacroEntry "incr expgui(changed)" 0 |
---|
| 2472 | # write new atoms from table as input to exptool |
---|
| 2473 | set errmsg [runAddAtoms $phase $atomlist] |
---|
| 2474 | RecordMacroEntry "runAddAtoms $phase [list $atomlist]" 0 |
---|
| 2475 | } |
---|
| 2476 | |
---|
[379] | 2477 | proc sortAddAtoms {phase top sortvar} { |
---|
| 2478 | global expgui |
---|
| 2479 | set np $top.canvas.fr |
---|
| 2480 | set validlist {} |
---|
| 2481 | set invalidlist {} |
---|
| 2482 | set row 0 |
---|
| 2483 | while {![catch {grid info $np.e[incr row]t}]} { |
---|
| 2484 | set valid 1 |
---|
| 2485 | set line $row |
---|
| 2486 | if !{$expgui(UseAtom$row)} {set valid 0} |
---|
| 2487 | lappend line $expgui(UseAtom$row) |
---|
| 2488 | if {[set type [string trim [$np.e${row}t get]]] == ""} {set valid 0} |
---|
| 2489 | lappend line [string trim [$np.e${row}t get]] |
---|
| 2490 | lappend line [string trim [$np.e${row}n get]] |
---|
| 2491 | foreach i {x y z o u} { |
---|
| 2492 | set tmp [string trim [$np.e${row}$i get]] |
---|
| 2493 | lappend line $tmp |
---|
| 2494 | if {$tmp == "" || [catch {expr $tmp}]} {set valid 0} |
---|
| 2495 | } |
---|
| 2496 | if {$valid} { |
---|
| 2497 | lappend validlist $line |
---|
| 2498 | } else { |
---|
| 2499 | lappend invalidlist $line |
---|
| 2500 | } |
---|
| 2501 | } |
---|
| 2502 | switch $sortvar { |
---|
| 2503 | type {set sortlist [lsort -index 2 -dictionary $validlist]} |
---|
| 2504 | name {set sortlist [lsort -index 3 -dictionary $validlist]} |
---|
| 2505 | x {set sortlist [lsort -index 4 -real $validlist]} |
---|
| 2506 | y {set sortlist [lsort -index 5 -real $validlist]} |
---|
| 2507 | z {set sortlist [lsort -index 6 -real $validlist]} |
---|
| 2508 | occ {set sortlist [lsort -index 7 -real $validlist]} |
---|
| 2509 | uiso {set sortlist [lsort -index 8 -real $validlist]} |
---|
| 2510 | default {set sortlist $validlist} |
---|
| 2511 | } |
---|
| 2512 | |
---|
| 2513 | if {[llength $invalidlist] > 0} {append sortlist " $invalidlist"} |
---|
| 2514 | set row 0 |
---|
| 2515 | foreach line $sortlist { |
---|
| 2516 | incr row |
---|
| 2517 | set expgui(UseAtom$row) [lindex $line 1] |
---|
| 2518 | foreach item [lrange $line 2 end] \ |
---|
| 2519 | var {t n x y z o u} { |
---|
| 2520 | $np.e${row}$var delete 0 end |
---|
| 2521 | $np.e${row}$var insert end $item |
---|
| 2522 | } |
---|
| 2523 | } |
---|
| 2524 | } |
---|
[694] | 2525 | |
---|
| 2526 | proc EditInstFile {"filename {}"} { |
---|
| 2527 | global expgui |
---|
| 2528 | # on the first call, load the commands |
---|
| 2529 | if {[catch { |
---|
| 2530 | if {[info procs instMakeWindow] == ""} { |
---|
| 2531 | source [file join $expgui(scriptdir) instedit.tcl] |
---|
| 2532 | } |
---|
| 2533 | } errmsg]} { |
---|
| 2534 | MyMessageBox -parent . -title "Load error" \ |
---|
| 2535 | -message "Unexpected error while sourcing file instedit.tcl: $errmsg" \ |
---|
| 2536 | -icon error |
---|
| 2537 | } |
---|
| 2538 | instMakeWindow $filename |
---|
| 2539 | } |
---|
| 2540 | |
---|
[847] | 2541 | # load a list of Origin 1/2 space groups |
---|
| 2542 | proc GetOrigin12List {} { |
---|
| 2543 | # don't need to read the file twice |
---|
| 2544 | if {[array names ::Origin1list] != ""} return |
---|
| 2545 | set line {} |
---|
| 2546 | set fp1 [open [file join $::expgui(scriptdir) spacegrp.ref] r] |
---|
| 2547 | while {[lindex $line 1] != 230} { |
---|
| 2548 | if {[gets $fp1 line] < 0} break |
---|
| 2549 | } |
---|
| 2550 | while {[gets $fp1 line] >= 0} { |
---|
[853] | 2551 | set key [string tolower [lindex $line 8]] |
---|
[847] | 2552 | regsub -all " " $key "" key |
---|
| 2553 | regsub -- "-3" $key "3" key |
---|
| 2554 | if {$key != ""} { |
---|
[853] | 2555 | # puts "$key -- [lindex $line 1] [lindex $line 8] [lindex $line 9]" |
---|
[847] | 2556 | set ::Origin1list($key) [lindex $line 9] |
---|
| 2557 | } |
---|
| 2558 | } |
---|
| 2559 | close $fp1 |
---|
| 2560 | } |
---|
| 2561 | |
---|
| 2562 | # get the shift to be added to origin 1 coordinates to obtain origin 2 settings |
---|
| 2563 | proc GetOrigin1Shift {phase} { |
---|
| 2564 | GetOrigin12List |
---|
[853] | 2565 | set spg [string tolower [phaseinfo $phase spacegroup]] |
---|
[847] | 2566 | regsub -all " " $spg "" spg |
---|
| 2567 | regsub -- "-3" $spg "3" spg |
---|
| 2568 | if {[catch {set shift $::Origin1list($spg)}]} { |
---|
| 2569 | return "" |
---|
| 2570 | } else { |
---|
| 2571 | return $shift |
---|
| 2572 | } |
---|
| 2573 | } |
---|
| 2574 | |
---|
[849] | 2575 | proc XformAtoms2Origin2 {phase numberList w1 shift} { |
---|
| 2576 | global expgui expmap |
---|
| 2577 | set parent [winfo toplevel $w1] |
---|
| 2578 | if {[llength $numberList] != [llength $expmap(atomlist_$phase)]} { |
---|
| 2579 | # not all atoms were selected in phase -- do a sanity check |
---|
| 2580 | set msg {You have selected only some atoms to be shifted. Do you want to shift all atoms or only the selected atoms?} |
---|
| 2581 | set val [MyMessageBox -parent $parent -icon warning \ |
---|
| 2582 | -type "{Use all} {Use Selection}" -default "use all" \ |
---|
| 2583 | -title "Shift all" -message $msg] |
---|
[853] | 2584 | # puts "$phase $numberList $w1 $shift" |
---|
[849] | 2585 | if {$val == "use all"} {set numberList $expmap(atomlist_$phase)} |
---|
| 2586 | } |
---|
| 2587 | if {[lindex $expmap(phasetype) [expr {$phase - 1}]] == 4} { |
---|
| 2588 | set cmd mmatominfo |
---|
| 2589 | } else { |
---|
| 2590 | set cmd atominfo |
---|
| 2591 | } |
---|
| 2592 | foreach atom $numberList { |
---|
| 2593 | foreach v {x y z} vs $shift { |
---|
| 2594 | set c [$cmd $phase $atom $v] |
---|
| 2595 | $cmd $phase $atom $v set [expr {$c + $vs}] |
---|
[905] | 2596 | RecordMacroEntry "$cmd $phase $atom $v set [expr {$c + $vs}]" 0 |
---|
[849] | 2597 | } |
---|
| 2598 | incr expgui(changed) |
---|
| 2599 | } |
---|
| 2600 | |
---|
[905] | 2601 | RecordMacroEntry "incr expgui(changed)" 0 |
---|
[865] | 2602 | ResetMultiplicities $phase $parent |
---|
| 2603 | SelectOnePhase $phase |
---|
[849] | 2604 | MyMessageBox -parent $parent -type OK -default ok -title "Shift applied" \ |
---|
[865] | 2605 | -message "A shift of \"$shift\" has been added to coordinates of atoms [CompressList $numberList]" |
---|
| 2606 | # UpdateAtomLine $numberList $phase |
---|
[849] | 2607 | destroy $parent |
---|
| 2608 | } |
---|
[865] | 2609 | |
---|
| 2610 | # reset the site multiplicities using the EXPEDT program |
---|
| 2611 | proc ResetMultiplicities {phase parent} { |
---|
[905] | 2612 | global expgui |
---|
| 2613 | set errmsg [RunResetMultiplicities $phase] |
---|
| 2614 | RecordMacroEntry "RunResetMultiplicities $phase" 0 |
---|
| 2615 | |
---|
| 2616 | if {$expgui(showexptool) || $errmsg != ""} { |
---|
| 2617 | if {$errmsg != ""} { |
---|
| 2618 | set err 1 |
---|
| 2619 | append errmsg "\n" $expgui(exptoolout) |
---|
| 2620 | } else { |
---|
| 2621 | set err 0 |
---|
| 2622 | set errmsg $expgui(exptoolout) |
---|
| 2623 | } |
---|
| 2624 | set msg "Please review the result from listing the phase." |
---|
| 2625 | if {$errmsg != ""} {append msg "\nIt appears an error occurred!"} |
---|
| 2626 | ShowBigMessage $parent.msg $msg $errmsg OK "" $err |
---|
| 2627 | } |
---|
| 2628 | } |
---|
| 2629 | proc RunResetMultiplicities {phase} { |
---|
[865] | 2630 | global expgui tcl_platform |
---|
| 2631 | set input [open resetmult.inp w] |
---|
| 2632 | puts $input "Y" |
---|
| 2633 | puts $input "l a p $phase" |
---|
| 2634 | puts $input "l" |
---|
| 2635 | puts $input "x x x" |
---|
| 2636 | puts $input "x" |
---|
| 2637 | close $input |
---|
| 2638 | # Save the current exp file |
---|
| 2639 | savearchiveexp |
---|
| 2640 | # disable the file changed monitor |
---|
| 2641 | set expgui(expModifiedLast) 0 |
---|
| 2642 | set expnam [file root [file tail $expgui(expfile)]] |
---|
| 2643 | set err [catch { |
---|
| 2644 | if {$tcl_platform(platform) == "windows"} { |
---|
| 2645 | exec [file join $expgui(gsasexe) expedt.exe] $expnam < resetmult.inp >& resetmult.out |
---|
| 2646 | } else { |
---|
| 2647 | exec [file join $expgui(gsasexe) expedt] $expnam < resetmult.inp >& resetmult.out |
---|
| 2648 | } |
---|
| 2649 | } errmsg] |
---|
| 2650 | loadexp $expgui(expfile) |
---|
[905] | 2651 | set fp [open resetmult.out r] |
---|
| 2652 | set out [read $fp] |
---|
| 2653 | close $fp |
---|
| 2654 | set expgui(exptoolout) $out |
---|
| 2655 | catch {file delete resetmult.inp resetmult.out} |
---|
| 2656 | if {$err} { |
---|
| 2657 | return $errmsg |
---|
| 2658 | } else { |
---|
| 2659 | return "" |
---|
[865] | 2660 | } |
---|
| 2661 | } |
---|
| 2662 | |
---|
| 2663 | # default values |
---|
[458] | 2664 | set newhist(insttype) {} |
---|
[447] | 2665 | set newhist(dummy) 0 |
---|
[668] | 2666 | set newhist(instfiletext) {} |
---|