Content-type: text/html; charset=UTF-8
qddb_table define <rows> <columns> ?-variable <variable>? \ ?-order row|column? ?-autoeval on|off? \ ?-name <table name>? ?-title <title>? ?-comment <comment>? qddb_table delete <table_desc>|all qddb_table clear <table_desc> qddb_table copy <table_desc> qddb_table expr <expression> qddb_table expr_ok <expression> qddb_table eval <table_desc> qddb_table getval <table_desc> ?-format list|text|rows? \ ?-rowtitles on|off? ?-coltitles on|off? qddb_table setval <table_desc> <list> qddb_table cget <table_desc> ?options? qddb_table configure <table_desc> <option> <value> qddb_table sort <table_desc> ?-start <row name>? ?-end <row name>? \ ?-ascending <column list>? ?-sortby <column list>? qddb_table summary <table_desc> <x_col> <y_col> <range> <format> <function> Available table options: -order, -autoeval, -name, -title, -comment, -variable qddb_table row insert <table_desc> ?-before <row name>? ?-numrows number? qddb_table row delete <table_desc> <row name> qddb_table row clear <table_desc> <row name> qddb_table row copy <table_desc> <from> <to> qddb_table row eval <table_desc> <row name> qddb_table row maxnum <table_desc> qddb_table row getval <table_desc> <row name> qddb_table row setval <table_desc> <row name> <value list> qddb_table row cget <table_desc> <row name> ?<option> <value>? qddb_table row configure <table_desc> ?<option> <value>? Available row options: -comment, -title, -name, -variable qddb_table col insert <table_desc> ?-before <col name>? ?-numcols number? qddb_table col delete <table_desc> <col name> qddb_table col clear <table_desc> <col name> qddb_table col copy <table_desc> <from> <to> qddb_table col eval <table_desc> <col name> qddb_table col maxnum <table_desc> qddb_table col getval <table_desc> <col name> qddb_table col setval <table_desc> <col name> <value list> qddb_table col cget <table_desc> <col name> <option> qddb_table col configure <table_desc> <col name> ?<option> <value>? Available col options: -comment, -title, -name, -variable, -type, -calc, -justify, -width, -precision, -separator qddb_table cell clear <table_desc> <row name> <col name> qddb_table cell copy <table_desc> <from row> <from col> <to row> <to col> qddb_table cell eval <table_desc> <row name> <col name> qddb_table cell getval <table_desc> <row name> <col name> qddb_table cell setval <table_desc> <row name> <col name> <value> qddb_table cell cget <table_desc> <row name> <col name> <option> qddb_table cell configure <table_desc> <row name> <col name> \ ?<option> <value>? \ Available cell options: -comment, -title, -name, -variable, -type, -calc, -justify, -width, -precision, -separator
Note that qddb_table uses rows and columns beginning with 1.
list - an unformatted list of rows; each row is a list of cell values text - a formatted string, suitable for printing rows - a list of formatted rows, suitable for displaying in a listbox
real string real
requires an argument similar to the following:
{ {3.0 {hello world} 211.00} {2.01 {some string} 121.00} {1.0 {some third string} 1.212} }
-variable - a variable name to use as for quick access to cell values -name - a symbolic name for the table; must be of the form "[a-zA-Z][a-zA-Z0-9._-]*" -autoeval - whether autoevaluation is on or off -order - the default re-calculation order used when cell values change -title - a symbolic title for the table -comment - a general comment for the table
Type Range Format -------- ------------- --------------- string ignored ignored date sorting order display format real range precision integer range ignored
The <function> is an operation of like values in the <x_col> (specified by the range) on the values in the <y_col>. <function> can be any one of avg, sum, stddev, min, max, count, or prod.
-comment - a general comment for the row -name - a symbolic name for the row; must be of the form "[a-zA-Z][a-zA-Z0-9._-]*" -title - a title for the row -variable - an array variable that can be used for direct access to cell values in the row, using the column name as the index
-comment - a general comment for the column -name - a symbolic name for the column; must be of the form "[a-zA-Z][a-zA-Z0-9._-]*" -title - a title for the column -variable - an array variable that can be used for direct access to cell values in the column, using the column name as the index -type - the default type of the given column (string, real, integer, date, or calc) -justify - the default justification of the column for output purposes; may be one of 'left', 'right' 'center', or 'none'. The 'none' option provides no padding between separators. -width - the default width of the column for output purposes -precision - the default precision (to the right of the decimal) of the column if the column is of type real -separator - the default separator to append to the column for printing purposes (default: space)
-calc - formula for calculating the field if the cell is type 'calc'; if the field is not type 'calc', an error is returned.
Multiple options may be given in a single command.
var(1,1) var(1,2) var(1,3) var(2,1) var(2,2) var(2,3) var(3,1) var(3,2) var(3,3)
Row and column variables are bound as one-dimensional arrays. Cell variables are scalar Tcl variables.
If a name has been associated with a row, column or cell, then the variable is available in several forms:
tablevar(1,1) tablevar(row_name,1) tablevar(1,column_name) tablevar(row_name,column_name) tablevar(cell_name)
Row and column variables use their respective names in the one-dimensional array as well as numbers.
You can also evaluate arbitrary expressions that are not associated with a particular cell or table with qddb_table expr. You must provide an explicit table argument to any range functions (or to each range).
There are four types of subexpressions: numeric constants/expressions, ranges, range functions, and numeric functions. Ranges can only be used as arguments to a range function. Range functions take ranges as arguments and produce real numbers; numeric functions take numbers as arguments and produce real numbers.
All calculations and values are represented in double precision floating point.
- + * / %
For example, the following are all valid numeric expressions:
(2+3)/4 2+3/4 97*2+98*2/3-42.0
@range(row,col:row,col) @range(tablename,row,col:row,col) @row(row) @row(tablename,row) @col(col) @col(tablename,col) @cell(row,col) @cell(tablename,row,col) @(row,col?:row,col?) @(tablename,row,col?:row,col?)
The optional tablename may be either the explicit name of a table, or the table descriptor returned by qddb_table define. Each range must have an associated table, either explicit or implicit. qddb_table expr has no implicit table, so all range functions (see below) or ranges must specify a table explicitly. When a range function has a table argument, all ranges used as arguments to that function have an implicit table. Implicit tables do not propagate to subexpressions used within arguments to range functions.
Row and column names may be used as arguments to ranges, as well as numeric expressions and the following constants: @thisrow, @thiscol, @maxrow, and @maxcol. The constants are evaluated in the current table context (that is, the calculated field's implicit table).
Each range produces a list of cells to be evaluated by a range function. @range produces a list of all cells in the rectangular region specified by the four numeric arguments (row,col:row,col). Ranges have no meaning by themselves and must be used as arguments to a range function. Cell and cell ranges (@range and @cell) may be abbreviated with just '@'.
range_func(?tablename,? range1 ?, range2, ...?)
The range functions are:
@sum sum @prod product @avg average (mean) @stddev standard deviation @count num of cells in range @min minimum cell value @max maximum cell value
Here is an example:
set t [qddb_table define 10 10] set t2 [qddb_table define 10 10] # insert some values here set sum [qddb_table expr " @sum($t, # set up implicit table for ranges @range(1,1:@maxrow,@maxcol), # now override implicit table $t with $t2 @cell($t2,@maxrow,@maxcol) ) * 42 "]
@cellval(?t,?e1,e2) cell value @(e1,e2) in table 't' (equivalent to "@sum(?t,? @(e1,e2))") @sqrt(e) square root of 'e' @exp(e) exponential function of 'e' @ln(e) natural log of 'e' @log(e) log base 10 of 'e' @floor(e) largest integer not greater than 'e' @ceil(e) smallest integer not less than 'e' @rnd(e) round 'e' to nearest integer @round(e,n) round 'e' to 'n' decimal places @abs(e) absolute value of 'e' @pow(e1,e2) 'e1' raised to the power of 'e2' @pi a constant close to pi @degrees(e) convert 'e' radians to degrees @radians(e) convert 'e' degrees to radians @sin(e) sin of 'e' @cos(e) cos of 'e' @tan(e) tan of 'e' @asin(e) asin of 'e' @acos(e) acos of 'e' @atan(e) atan of 'e' @atan2(e1,e2) atan of e1/e2 @hypot(e1,e2) computes sqrt(e1*e1 + e2*e2) in such a way that underflow will not happen
= equal to < less than <= less than or equal to > greater than >= greater than or equal to != not equal to & logical and | logical or ! logical not (unary)
Logical expressions are used as the first argument to the @if function. If the logical expression is true, then @if evaluates to the second argument. If the logical expression is false, it evaluates to the third argument.
set t [qddb_table define 10 10] set t2 [qddb_table define 10 10] # insert some values here set stddev [qddb_table expr " @stddev($t, @range(1,1:@maxrow,@maxcol)) "] ;# standard deviation of all cells set num [qddb_table expr " (@if(@avg($t, @row(1)) < @avg($t2, @row(2)), @avg($t, @row(1)), @avg($t2, @row(2))) + @if(@avg($t, @col(1)) < @avg($t2, @col(2)), @avg($t, @col(1)), @avg($t2, @col(2))) ) / 2 "]
A Guide to QDDB Eric H. Herrin II and Raphael A. Finkel Qddb User's Guide An ASCII Database for Fast Queries of Relatively Stable Data Eric H. Herrin II and Raphael A. Finkel Computing Systems, Volume 4 Number 2 University of California Press, Berkeley CA Schema and Tuple Trees: An Intuitive Structure for Representing Relational Data Eric H. Herrin, II and Raphael A. Finkel Computing Systems, Volume 9, Number 2 MIT Press, Cambridge MA TCL and the TK Toolkit John K. Ousterhout Addison-Wesley, 1994 ISBN 0-201-63337-X
When setting an expression for a calculated field containing a reference to a non-existent table, the calculation is delayed until the table exists.