::tclmeasure
Vector input
Read-only RBC vectors are accepted as inputs. Output replacement requires writable real vectors; tclmeasure never unlocks a vector. Use RBC 0.8.1 or newer headers and runtime.
Even an RBC-enabled build can load and process lists without RBC installed. The rbc::vector package is loaded
only when vector input or output is requested (including configuring a vector output default). Tk
initialization is not required for vector measurements; the installed RBC binary must still have its own system
library dependencies available.
With -data, measurement inputs are lists looked up in that dictionary, as before. Omit -data to interpret
-xname, -vec, -vec1, -vec2, -find and -deriv as RBC vector command names:
package require tclmeasure
package require rbc::vector
rbc::vector create time signal
time set {0 1 2 3}
signal set {0 2 4 6}
::tclmeasure::measure -xname time -trig {-at 0.5} -targ {-vec signal -val 3 -rise 1}
# -> xtrig 0.5 xtarg 1.5 xdelta 1.0
All measurement modes accept vectors. Names are resolved in the namespace of the caller of measure, with
normal Tcl command lookup; fully qualified names also work. Use the vector’s actual command name, not a Tcl
alias or an imported command with a different name. Mapped array variables are not needed. Only real vectors
are supported, with equal sample counts and strictly increasing X values. External vector index offsets do
not affect sample alignment. Supply at least two samples, or three for derivative measurements.
The wrapper passes names directly to C; it does not extract the full vectors as lists. A shared read-only
accessor serves both input types. RMS squares samples while reading, before interpolation, matching the list
implementation without creating a temporary vector. Returned values retain their existing forms by default.
-between and cumulative integration additionally support vector output; -cross all and scalar measurements
retain their existing result types. Interpolation and measurement semantics are unchanged.
The internal C commands retain their original list signatures. Their Vectors counterparts use the same
arguments with vector names in the data positions; unused FindDerivWhenVectors inputs remain empty strings.
RmsVectors uses the IntegVectors signature with the final cumulative flag set to false. These commands
initialize stubs in the current interpreter before borrowing sample storage and do not evaluate Tcl or process
events while reading it.
Vector output and package defaults
-between and -integ {... -cum} accept the outer option -output vector. Their result remains a dictionary
with x and y keys, but each value is a fully qualified real RBC vector name. Both list and vector inputs
support either output representation. Other measurement results are unchanged by -output, including a global
vector default.
set data [dict create time {0 1 2 3} current {0 2 4 6}]
set result [::tclmeasure::measure -data $data -xname time -between {-vec current -from 0.5 -to 2.5} -output vector -namespace ::results -names {x clippedTime y #auto}]
[dict get $result y] range 0 end
# -> 1.0 2.0 4.0 5.0
rbc::vector destroy {*}[dict values $result]
set saved [::tclmeasure::configure]
::tclmeasure::configure -output vector -ifexists replace
set integral [::tclmeasure::measure -data $data -xname time -integ {-vec current -cum} -namespace ::results -names {x integralTime y integral}]
::tclmeasure::configure {*}$saved
rbc::vector destroy {*}[dict values $integral]
configure is public but not namespace-exported. With no arguments it returns -output list -ifexists error
initially; with one option it returns that option’s value. Updates are atomic, interpreter-local and support
unambiguous option prefixes and -help. Per-call options override defaults. There is no -input setting:
supplying -data continues to select list input; omitting it selects vector input.
Option |
Meaning |
|---|---|
|
Representation of the two supported x/y results. |
|
Destination names for |
|
Shorthand for the |
|
Destination namespace, relative to the caller; missing parents are created. |
|
Reject collisions, or update existing writable real vectors in place. |
Without -namespace, relative destinations use the caller’s namespace. Fully qualified names override the
selected namespace; their parent namespace must exist. #auto (also namespace::#auto) uses RBC’s allocator;
auto is an ordinary name. Explicit names are literal, including parentheses. Empty names/namespaces,
unknown fields and duplicate destinations are rejected. Naming options require an eligible vector result.
No mapped array variable is created. The caller owns the vectors and must destroy them when no longer needed.
Replacement retains existing vector commands and graph clients. Complex or read-only vectors, aliases and unrelated commands cannot be replaced. Both results are computed and copied before publication, making reuse of input vectors as destinations safe. New vectors are removed on publication failure; already replaced existing vectors are not rolled back if an application notification callback causes a later failure. The current numerical kernels still produce their usual result lists internally; C publishes numeric copies through RBC’s API without Tcl loops over individual samples.
Interactive measurement help
Use measure -help for general options. Add measurement selectors to see the options for that mode:
measure -avg -help
measure -trig -targ -help
measure -find -when -help
measure -deriv -at -help
measure -integ -help
Mode help requires no -xname, data dictionary, or RBC package. It accepts selectors in either order and unambiguous prefixes, such as measure -tr -ta -help. -h also requests help. Use selector-only calls for contextual help; calls containing actual option values retain general help. Incompatible selector combinations are errors. Without -help, bare selectors still require their normal values.
Flat measurement clauses
Both forms below are equivalent. Repeated condition switches belong to the preceding selector, so trigger and target retain independent crossing conditions:
measure -xname time -data $data -trig -vec input -val 0.5 -rise 1 -targ -vec output -val 0.5 -rise 1
measure -xname time -data $data -trig {-vec input -val 0.5 -rise 1} -targ {-vec output -val 0.5 -rise 1}
measure -xname time -data $data -integ -vec current -cum -output vector
measure -trig -targ -help
measure -integ -help
Flat clauses work for -trig, -targ, -when, -integ, and all interval measurements. Nested and flat
clauses may be mixed. A new selector or outer option ends the current flat clause; place its conditions
together. Within a flat clause, local options take precedence, so -trig -at 1 sets the trigger coordinate.
Scalar -find, -deriv and outer -at arguments are unchanged. Unambiguous option prefixes and condition
validation remain available.
Interactive help uses argparse 0.70’s explicit -synopsis and -synopsiscmd options. Mode help shows the
public measure command and relevant condition options without requiring input data or RBC.
Commands
configure
Queries or changes package-wide output defaults in this Tcl interpreter.
configure ?option? configure ?-output list|vector? ?-ifexists error|replace?
Parameters
-ifexists policy:Default vector collision policy: error or replace; initially error.
-output mode:Default representation for -between and cumulative integration: list or vector; initially list.
Description
With no arguments, returns the complete option/value dictionary. With one option, returns its value. Updates validate every option before changing any defaults. Selecting vector output requires an RBC-enabled build and a loadable RBC vector package. Per-measurement options override these defaults. Other measurement results are unchanged. Input selection remains automatic: -data selects lists; omitting it selects vectors. This command is not namespace-exported; call it as ::tclmeasure::configure.
Return value
The queried value, or the complete configuration dictionary.
measure
Read-only RBC vectors are valid inputs. Storage is changed only when explicitly used as an output destination; locked vectors cannot be replaced and are never unlocked. Does different measurements of input data lists or real RBC vectors. With -data, names select lists in the supplied dictionary. Without -data, names select RBC vector commands in the caller’s namespace; direct vector support must be enabled at build time with –with-rbc. Vector names are passed directly to C without converting the samples to lists. All modes preserve their existing scalar/list/dictionary results by default. Mapped array variables are optional. Complex vectors are rejected. X must be strictly increasing and all inputs must have equal sample counts. Vector index offsets do not change sample alignment. Derivatives need at least three samples; other modes need at least two. See the installation page for optional RBC build and runtime dependencies.
measure -xname name ?-data dictionary? -between conditions ?-output list|vector? ?-name name? ?-names dictionary? ?-namespace name? ?-ifexists error|replace?
measure -xname name ?-data dictionary? -integ {-vec name -cum ?-from value? ?-to value?} ?-output list|vector? ?-name name? ?-names dictionary? ?-namespace name? ?-ifexists error|replace?
measure -xname value -data value -trig {-vec value -val value ?-td value? -cross|rise|fall value} -targ {-vec value -val value ?-td value? -cross|rise|fall value}
measure -xname value -data value -trig {-at value} -targ {-vec value -val value ?-td value? -cross|rise|fall value}
measure -xname value -data value -trig {-vec value -val value ?-td value? -cross|rise|fall value} -targ {-at value}
measure -xname value -data value ?-find|deriv value? -when {-vec value -val value ?-td value? ?-from value? ?-to value? -cross|rise|fall value}
measure -xname value -data value ?-find|deriv value? -when {-vec1 value -vec2 value ?-td value? ?-from value? ?-to value? -cross|rise|fall value}
measure -xname value -data value -find value -at value
measure -xname value -data value -deriv value -at value
measure -xname value -data value -avg|rms|pp|min|max|minat|maxat|between {-vec value ?-td value? ?-from value? ?-to value?}
measure -xname name ?-data dictionary? -trig -vec signal -val level ?-td x? -rise count -targ -vec signal -val level -rise count
measure -xname name ?-data dictionary? -integ -vec signal ?-from x? ?-to x? ?-cum? Bare selectors without -help remain measurement calls and require their normal arguments.
measure -xname value -data value -integ {-vec value ?-td value? ?-from value? ?-to value? ?-cum?}
Parameters
-at:Time for -find or -deriv.
-avg:Contains conditions for finding average value across the interval.
-between:Contains conditions for fetching data in the interval.
-data:Optional dictionary of named lists; omitting it selects direct RBC vector input.
-deriv:Contains conditions for deriv (see below), requires -when or -at.
-find:Contains conditions for find (see below), requires -when or -at.
-ifexists:Error or replace for output vector collisions; defaults to the package configuration.
-max:Contains conditions for finding maximum value in the interval.
-maxat:Contains conditions for finding time of maximum value in the interval.
-min:Contains conditions for finding minimum value in the interval.
-minat:Contains conditions for finding time of minimum value in the interval.
-name:Shorthand for the y output name; cannot be combined with the y entry in -names.
-names:Dictionary mapping x and/or y to output vector names; omitted fields use #auto.
-namespace:Vector destination namespace, relative to the caller; missing parents are created.
-output:List or vector for -between and cumulative integration; defaults to the package configuration.
-pp:Contains conditions for finding peak to peak value in the interval.
-rms:Contains conditions for finding root meas square value across the interval.
-targ:Contains conditions for target (see below), requires -trig.
-trig:Contains conditions for trigger (see below), selects Trigger-Target measurement, requires -targ.
-when:Contains conditions for when (see below)
-xname:Name of x list in data dictionary, or RBC vector command when -data is omitted. This list must be strictly increaing without duplicate elements.
Description
Vector output
-between and -integ with nested -cum return dictionaries with x and y fields. With -output vector, the values are fully qualified real RBC vector command names instead of lists. All other modes keep their existing results, even with a global vector default. Input selection and output selection are independent.
Omitted names and #auto use RBC’s own name allocator. auto without # is an ordinary literal name. Relative names use -namespace, or the caller’s namespace when omitted. Fully qualified names override that namespace; their own parent namespace must already exist. Empty names/namespaces, unknown -names fields and duplicate destinations are errors. Naming options require vector output from one of the two supported forms.
Explicit names are literal, including parentheses, and no mapped array variable is created. The caller owns returned vectors. With replace, existing writable real vectors are updated in place, retaining graph clients. Other commands, aliases, complex vectors and read-only vectors cannot be replaced. All calculations finish before publication, so destinations may also be inputs. On failure, newly created vectors are removed; replacement of existing vectors is not transactional against application notification callbacks.
Example:
set data [dict create time {0 1 2 3} current {0 2 4 6}]
set result [measure -data $data -xname time -between {-vec current -from 0.5 -to 2.5} # -output vector -namespace ::results -names {x time y #auto}]
set samples [[dict get $result y] range 0 end]
rbc::vector destroy {*}[dict values $result]
This procedure imitates the .meas command from SPICE3 and Ngspice in particular. It has mutiple modes, and each mod could have different forms:
Trigger-Target
In this mode it measures the difference in x list between two points selected from one or two input lists (vectors). First it searches for the trigger point along x list (vector) with certain value of input list, or certain x axis value, second it searches for the target point with with certain value of input list, or certain x axis value, and finally calculates difference between trigger and target point along x axis. The conditions for trigger and target could be in two forms: hit of certain value by specified vector, or certain exact point on x axis. These conditions are provided as a list of arguments to -trig and -targ switches:
- -vec:
Key in data dictionary, or RBC vector command when -data is omitted.
- -val:
Value to match.
- -td:
X axis delay after which the search is start, default is 0.0.
- -cross:
Condition’s count, cross conditions counts every time vector crosses value, and saves only n-th crossing the value. The possible values are positive integers, or
laststring.- -rise:
Condition’s count, rise conditions counts every time vector crosses value from lower to higher (rising slope), and saves only n-th crossing the value. The possible values are positive integers, or
laststring.- -fall:
Condition’s count, fall conditions counts every time vector crosses value from higher to lower (falling slope), and saves only n-th crossing the value. The possible values are positive integers, or
laststring.
or
- -at:
Exact x value.
Examples of usages:
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -trig {-vec y1 -val 0.1 -rise 3} # -targ {-vec y2 -val 0.5 -fall 5}
Here we use x key value as x axis, trigger vector point is when y1 crosses value 0.1, third rise, and target vector point is when y2 crosses value 0.5, fifth fall.
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -trig {-vec y1 -val 0.7 -rise 2} -targ {-at 20.0}
Here we use x key value as x axis, trigger vector point is when y1 crosses value 0.7, second rise, and target point is value 20.0 at x axis.
In this mode procedure returns dictionary with keys xtrig, xtarg, xdelta and corresponding values.
Find-When or Deriv-When
In this mode it measures any vector (or its derivative), when two signals cross each other or a signal crosses
a given value. Measurements start after a delay -td and may be restricted to a range between -from and -to.
Possible combinations of switches are -when {...} or -find {...} -when {...}. For -when the possible
switches are:
- -vec:
Key in data dictionary, or RBC vector command when -data is omitted.
- -val:
Value to match.
- -td:
X axis delay after which the search is start, default is 0.0.
- -from:
Start of the range in which search happens, default is minimum value of x.
- -to:
End of the range in which search happens, default is maximum value of x.
- -cross:
Condition’s count, cross conditions counts every time vector crosses value, and saves only n-th crossing the value. The possible values are positive integers,
allorlaststring.- -rise:
Condition’s count, rise conditions counts every time vector crosses value from lower to higher (rising slope), and saves only n-th crossing the value. The possible values are positive integers,
allorlaststring.- -fall:
Condition’s count, fall conditions counts every time vector crosses value from higher to lower (falling slope), and saves only n-th crossing the value. The possible values are positive integers,
allorlaststring.
or
- -vec1:
First key in data dictionary, or RBC vector command when -data is omitted.
- -vec2:
Second key in data dictionary, or RBC vector command when -data is omitted.
- -td:
X axis delay after which the search is start, default is 0.0.
- -from:
Start of the range in which search happens, default is minimum value of x.
- -to:
End of the range in which search happens, default is maximum value of x.
- -cross:
Condition’s count, cross conditions counts every time
-vec1vector crosses value, and saves only n-th crossing the value. The possible values are positive integers, orlaststring.- -rise:
Condition’s count, rise conditions counts every time
-vec1vector crosses value from lower to higher (rising slope), and saves only n-th crossing the value. The possible values are positive integers, orlaststring.- -fall:
Condition’s count, fall conditions counts every time
-vec1vector crosses value from higher to lower (falling slope), and saves only n-th crossing the value. The possible values are positive integers, orlaststring.
For -find and -deriv we specify the vector name in data dictionary for which values (or derivative) should be
found at when point.
Examples of usages:
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -find y1 -when {-vec y2 -val 0.5 -fall 5}
Here we use x key value as x axis, find vector is y1, and point is when vector y2 crosses value 0.5, fifth fall.
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -find y1 -when {-vec1 y1 -vec2 y2 -fall 5}
Here we use x key value as x axis, find vector is y1, and point is when vector y1 crosses y2, fifth fall of y1 vector.
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -when {-vec1 y1 -vec2 y2 -fall last -from 1 -to 30}
Here we use x key value as x axis, point is when vector y1 crosses y2, last fall of y1 vector, searching range is
[1,30]. In this mode procedure returns dictionary with keys xwhen, and yfind if -find switch is specified,
and corresponding values.
Find-At
In this mode it finds value of the vector at specified time.
Examples of usages:
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -find y1 -at 5
Deriv-At
In this mode it finds value of the vector’s derivative at specified time. Examples of usages:
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -deriv y1 -at 5
Avg|Rms|Min|Max|PP|MinAt|MaxAt|Between
This mode is combination of many modes with the same interface.
- -vec:
Key in data dictionary, or RBC vector command when -data is omitted.
- -from:
Start of the range in which search happens, default is minimum value of x.
- -to:
End of the range in which search happens, default is maximum value of x.
Examples of usages:
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -avg {-vec y1 -from 1 -to 5}
In Between mode, the x and y values are returned within specified interval.
Integ
This mode is combination of many modes with the same interface.
- -vec:
Key in data dictionary, or RBC vector command when -data is omitted.
- -from:
Start of the integration range, default is minimum value of x.
- -to:
End of the integration range, default is maximum value of x.
- -cum:
Returns the cumulative x/y dictionary instead of the final scalar; values follow -output.
Examples of usages:
measure -xname x -data [dict create x $x y1 $y1 y2 $y2] -avg {-vec y1 -from 1 -to 5}
Interactive help:
Use measure -help for general options, or select a mode before -help:
measure -avg -help, measure -trig -targ -help, measure -find -when -help,
measure -deriv -at -help, or measure -when -help.
Mode help accepts unambiguous selector prefixes and needs no input data or RBC support.
Conditions may be supplied as a nested list or as flat switches after their selector. Each flat clause
continues until the next outer option or measurement selector. Local options belong to the current clause;
for example, -at after a flat -trig belongs to the trigger. Values are consumed as single Tcl words, even
when they begin with a dash. Nested and flat clauses may be mixed. Existing option prefixes are supported.
measure -xname time -data $data -trig -vec in -val 0.5 -rise 1 -targ -vec out -val 0.5 -rise 1
measure -xname time -data $data -integ -vec current -from 0 -to 1 -cum
Copyright (c) George Yashin