tclmeasure performs SPICE-style measurements on sampled waveforms in Tcl 9. It can measure propagation delay between two signals, find threshold crossings, calculate RMS and average values over an interval, and integrate a trace. It works directly with Tcl lists or real rbc-tk9 vectors, so the data can come from a simulator, a measurement file, or a Tcl script.
The ::tclmeasure::measure command takes an X axis and one or more signals sampled on that axis. For a transient waveform, X is usually time. For a DC sweep, it can be the swept voltage or current.
The input and output below are sampled at one-nanosecond intervals. To measure propagation delay, find when each signal first rises through 0.5 V and subtract the two crossing times. The crossings fall between samples.
package require tclmeasure
namespace import ::tclmeasure::measure
set data [dict create time {0 1 2 3 4} vin {0 1 1 1 1} vout {0 0 0 1 1}]
set result [measure -data $data -xname time -trig {-vec vin -val 0.5 -rise 1}\
-targ {-vec vout -val 0.5 -rise 1}]
puts [dict get $result xtrig] ;# 0.5 ns
puts [dict get $result xtarg] ;# 2.5 ns
puts [dict get $result xdelta] ;# 2.0 nsWith -data, -xname and -vec refer to keys in the supplied dictionary. Conditions can also be written as flat clauses. For example, -trig -vec vin -val 0.5 -rise 1 is equivalent to the braced trigger above.
List input and vector output can be combined. This example takes a current waveform from a Tcl dictionary and extracts the interval from 0.5 to 2.5. The result includes the interpolated endpoints and the original samples inside the interval.
package require tclmeasure
namespace import ::tclmeasure::measure
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]
set x [dict get $result x]
set y [dict get $result y]
puts [$x range 0 end] ;# 0.5 1.0 2.0 2.5
puts [$y range 0 end] ;# 1.0 2.0 4.0 5.0
::rbc::vector destroy $x $yTo read existing RBC vectors directly, omit -data and supply vector command names to -xname, -vec and the other signal options. All measurement modes accept real vector inputs. The X values must be strictly increasing, and each signal must have the same number of samples as X.
Vector output is available for -between and cumulative integration. Use -names {x timeOut y signalOut} to name both destinations. With -ifexists replace, repeated measurements update existing writable vectors in place, so a graph attached to them follows the changes. ::tclmeasure::configure sets the default output representation and replacement policy for the current interpreter.
tclmeasure 0.9 requires Tcl 9, argparse 0.70 or later, and Tcllib. List measurements work without RBC. Vector measurements require an RBC-enabled build and rbc::vector 0.8.1 or later. They can run in tclsh without opening a Tk display.
The rolling release provides archives for Linux GCC, Windows MSYS2/UCRT64 and Windows MSVC x64. These configurations are tested with Tcl 9.1.0 and RBC vector support. Choose the archive matching your Tcl installation, extract it into the installation prefix, and install the dependencies separately.
For a source build on Linux or in an MSYS2 UCRT64 shell:
./configure make make test make install
The default source build supports lists. To enable RBC vectors, add --with-rbc=/path/to/rbc to the configure command. Use --with-tcl=/path/to/tcl/lib to select a particular Tcl installation. For an MSVC build, use the supplied win/makefile.vc.
measure -help lists the general options. Supply the measurement selectors to see help for a particular operation. These calls require no sample data:
package require tclmeasure namespace import ::tclmeasure::measure measure -trig -targ -help measure -find -when -help measure -integ -help