Changeset 646
- Timestamp:
- Dec 4, 2009 5:09:39 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/browsecif.tcl
- Property rcs:date changed from 2002/08/09 16:43:07 to 2002/09/05 18:24:04
- Property rcs:rev changed from 1.1 to 1.2
- Property rcs:lines set to +151 -41
r638 r646 297 297 toplevel .msg 298 298 wm transient .msg [winfo toplevel .] 299 pack [frame .msg.f -bd 4 -relief groove] 299 pack [frame .msg.f -bd 4 -relief groove] -padx 5 -pady 5 300 300 pack [message .msg.f.m -text "Please wait $message"] 301 301 wm withdraw .msg … … 400 400 # the contents of each loop are saved as blockN(loop_M) 401 401 # 402 # if the filename is blank or not specified, the current contents 403 # of the text widget, $txt, is parsed. 404 # 402 405 # The proc returns the number of blocks that have been read or a 403 406 # null string if the file cannot be opened … … 406 409 # but the parser could get confused if the CIF has invalid syntax 407 410 # 408 proc ParseCIF {txt filename} {411 proc ParseCIF {txt "filename {}"} { 409 412 global CIF tcl_version 413 global CIF_dataname_index 410 414 411 415 if {$tcl_version < 8.2} { … … 416 420 } 417 421 418 if [catch { 419 set fp [open $filename r] 420 $txt insert end [read $fp] 421 close $fp 422 }] {return ""} 422 if {$filename != ""} { 423 if [catch { 424 $txt configure -state normal 425 set fp [open $filename r] 426 $txt insert end [read $fp] 427 close $fp 428 $txt configure -state disabled 429 }] { 430 return "" 431 } 432 } 433 423 434 424 435 set pos 1.0 … … 486 497 # in a loop header, save the names in the loop list 487 498 lappend looplist $dataname 499 # check the categories used in the loop 500 set category {} 501 catch { 502 set category [lindex \ 503 [lindex $CIF_dataname_index($dataname) 1] 5] 504 } 505 # don't worry if we don't have a category 506 if {$category != ""} { 507 if {$catlist == ""} { 508 set catlist $category 509 } elseif {[lsearch $catlist $category] == -1} { 510 # error two categories in a loop 511 lappend catlist $category 512 append block${blocks}(errors) \ 513 "Multiple categories ($catlist) in a loop_ for $dataname at line [lindex [split $pos .] 0]\n" 514 } 515 } 516 488 517 if {$blocks == 0} { 489 518 # an error -- a loop_ before a data_ block start … … 519 548 incr loopnum 520 549 set looplist {} 550 set catlist {} 521 551 set block${blocks}(loop_${loopnum}) {} 522 552 # move forward past current token … … 675 705 # frame gives the name of the toplevel or frame to hold the browser 676 706 proc CIFBrowser {txt blocklist "selected {}" "frame .cif"} { 677 global CIF CIFtreeindex 707 global CIF CIFtreeindex CIF_dataname_index 678 708 679 709 if {$selected == ""} {set selected $blocklist} … … 722 752 } 723 753 foreach loop [lsort [array names block$n loop_*]] { 724 $CIF(tree) insert end block$n block${n}$loop -text $loop \ 754 # make a list of categories used in the loop 755 set catlist {} 756 foreach name [lsort [set block${n}($loop)]] { 757 set category {} 758 catch { 759 foreach {type range elist esd units category} \ 760 [lindex $CIF_dataname_index($name) 1] {} 761 } 762 if {$category != "" && [lsearch $catlist $category] == -1} { 763 lappend catlist $category 764 } 765 } 766 767 $CIF(tree) insert end block$n block${n}$loop \ 768 -text "$loop ($catlist)" \ 725 769 -image [Bitmap::get file] -data "block$n loop" 726 770 set CIFtreeindex(block${n}$loop) block${n}$loop … … 826 870 if {[CheckForCIFEdits]} return 827 871 set pointer [$CIF(tree) itemcget $name -data] 828 set dataname [ $CIF(tree) itemcget $name -text]872 set dataname [lindex [$CIF(tree) itemcget $name -text] 0] 829 873 showCIFbyDataname $pointer $dataname 830 874 } … … 992 1036 } 993 1037 994 # Parse a number in CIF, that may include a SU (ESD) value 995 # note that this routine will ignore spaces, quotes & semicolons 996 proc ParseSU {value} { 997 # if there is no SU just return the value 998 if {[string first "(" $value] == -1} { 999 return $value 1000 } 1001 # is there a decimal point? 1002 if [regexp {([-+]?[0-9]*\.)([0-9]*)\(([0-9]+)\)} $value junk a b err] { 1003 set ex [string length $b] 1004 return [list ${a}${b} [expr {pow(10.,-$ex)*$err}]] 1005 } 1006 if [regexp {([-+]?[0-9]*)\(([0-9]+)\)} $value junk a err] { 1007 return [list ${a} $err] 1008 } 1009 tk_dialog .err {ParseSU Error} \ 1010 "ParseSU: Error processing value $value" \ 1011 warning 0 Continue 1038 # scan a number in crystallographic uncertainty representation 1039 # i.e.: 1.234(12), 1234(23), 1.234e-2(14), -1.234-08(14), etc. 1040 proc ParseSU {num} { 1041 # is there an error on this value? 1042 if {![regexp {([-+eEdD.0-9]+)\(([0-9]+)\)} $num x a err]} { 1043 set a $num 1044 set err {} 1045 } 1046 # parse off an exponent, if present 1047 if {[regexp {([-+.0-9]+)[EeDd]([-+0-9]+)} $a x a1 exp]} { 1048 # [+-]###.###e+## or [+-]###.###D-## etc. 1049 set a $a1 1050 # remove leading zeros from exponent 1051 regsub {([+-]?)0*([0-9]+)} $exp {\1\2} exp 1052 } elseif {[regexp {([-+.0-9]+)([-+][0-9]+)} $a x a1 exp]} { 1053 # [+-]###.###+## or [+-]###.###-## etc. [no 1054 set a $a1 1055 # remove leading zeros from exponent 1056 regsub {([+-]?)0*([0-9]+)} $exp {\1\2} exp 1057 } else { 1058 set exp 0 1059 } 1060 # now parse the main number and count the digits after the decimal 1061 set a2 {} 1062 set a3 {} 1063 regexp {^([-+0-9]*)\.?([0-9]*)$} $a x a2 a3 1064 set l [string length $a3] 1065 1066 set val . 1067 set error {} 1068 if {[catch { 1069 set val [expr ${a2}.${a3} * pow(10,$exp)] 1070 if {$err != ""} { 1071 set error [expr $err*pow(10,$exp-$l)] 1072 } 1073 }]} { 1074 # something above was invalid 1075 if {$err != ""} { 1076 return "$val ." 1077 } else { 1078 return $val 1079 } 1080 } 1081 if {$error == ""} { 1082 return $val 1083 } else { 1084 return [list $val $error] 1085 } 1012 1086 } 1013 1087 … … 1027 1101 if {$file == ""} return 1028 1102 if {![file exists $file]} return 1029 pleasewait "Reading CIF f ile"1103 pleasewait "Reading CIF from file" 1030 1104 set blocks [ParseCIF $file] 1031 1105 if {$blocks == ""} { … … 1077 1151 # exceed 80 characters/line 1078 1152 proc ReplaceMarkedText {txt mark value} { 1153 $txt configure -state normal 1079 1154 # is this a multi-line string? 1080 1155 set num [string first \n $value] … … 1114 1189 $txt delete ${mark}.l ${mark}.r 1115 1190 $txt insert ${mark}.l $tmp 1191 $txt configure -state disabled 1116 1192 return 1117 1193 } elseif {($spaces != -1 || [string trim $value] == "") \ … … 1145 1221 $txt insert $mark.r \n 1146 1222 } 1223 $txt configure -state disabled 1147 1224 } 1148 1225 … … 1222 1299 if {[ 1223 1300 catch { 1224 foreach {type range elist esd units } [lindex $CIF_dataname_index($dataname) 1] {}1301 foreach {type range elist esd units category} [lindex $CIF_dataname_index($dataname) 1] {} 1225 1302 } 1226 1303 ]} {return "warning: dataname $dataname not defined"} … … 1279 1356 global CIF 1280 1357 set deflist [GetCIFDefinitions $defs] 1281 $CIF(defBox) delete 1.0 end 1282 foreach d $deflist { 1283 foreach {namelist definition} $d {} 1284 foreach n $namelist { 1285 $CIF(defBox) insert end $n dataname 1358 catch { 1359 $CIF(defBox) delete 1.0 end 1360 foreach d $deflist { 1361 foreach {namelist definition} $d {} 1362 foreach n $namelist { 1363 $CIF(defBox) insert end $n dataname 1364 $CIF(defBox) insert end \n 1365 } 1286 1366 $CIF(defBox) insert end \n 1287 } 1288 $CIF(defBox) insert end \n 1289 $CIF(defBox) insert end $definition 1290 $CIF(defBox) insert end \n 1291 $CIF(defBox) insert end \n 1292 } 1293 $CIF(defBox) tag config dataname -background yellow 1367 $CIF(defBox) insert end $definition 1368 $CIF(defBox) insert end \n 1369 $CIF(defBox) insert end \n 1370 } 1371 $CIF(defBox) tag config dataname -background yellow 1372 } 1294 1373 } 1295 1374 … … 1300 1379 if {[ 1301 1380 catch { 1302 foreach {type range elist esd units } [lindex $CIF_dataname_index($dataname) 1] {}1381 foreach {type range elist esd units category} [lindex $CIF_dataname_index($dataname) 1] {} 1303 1382 } 1304 1383 ]} { … … 1512 1591 if {[CheckForCIFEdits]} return 1513 1592 1593 $CIF(txt) configure -state normal 1514 1594 set looplist [set ${block}($loop)] 1515 1595 set length [llength [set ${block}([lindex $looplist 0])]] … … 1548 1628 $CIF(LoopSpinBox) setvalue last 1549 1629 ShowLoopVar $block $loop 1630 $CIF(txt) configure -state disabled 1550 1631 } 1551 1632 … … 1593 1674 if {$ans == "keep"} {return} 1594 1675 1676 $CIF(txt) configure -state normal 1595 1677 foreach widget $CIF(widgetlist) { 1596 1678 foreach {dataname block index} $CIFinfoArr($widget) {} … … 1600 1682 set ${block}($dataname) [lreplace [set ${block}($dataname)] $index $index] 1601 1683 } 1684 $CIF(txt) configure -state disabled 1602 1685 1603 1686 set max [lindex [$CIF(LoopSpinBox) cget -range] 1] … … 1605 1688 $CIF(LoopSpinBox) configure -range "1 $max 1" 1606 1689 $CIF(LoopSpinBox) setvalue last 1690 } 1691 1692 # display & highlight a line in the CIF text viewer 1693 proc MarkGotoLine {line} { 1694 global CIF 1695 $CIF(txt) tag delete currentline 1696 $CIF(txt) tag add currentline $line.0 $line.end 1697 $CIF(txt) tag configure currentline -foreground blue 1698 $CIF(txt) see $line.0 1699 } 1700 1701 # Extract a value from a CIF in the CIF text viewer 1702 proc ValueFromCIF {block item} { 1703 global $block CIF 1704 set val {} 1705 catch { 1706 set mark [set ${block}($item)] 1707 if {[llength $mark] == 1} { 1708 set val [string trim [StripQuotes [$CIF(txt) get $mark.l $mark.r]]] 1709 } else { 1710 foreach m $mark { 1711 lappend val [string trim [StripQuotes [$CIF(txt) get $m.l $m.r]]] 1712 } 1713 } 1714 } 1715 return $val 1607 1716 } 1608 1717 … … 1614 1723 set CIF(lastLoopIndex) {} 1615 1724 set CIF(autosave_edits) 0 1725 set CIF(editmode) 0
Note: See TracChangeset
for help on using the changeset viewer.