tclsimrawreader is a Tcl 9 C extension for reading SPICE simulation results from .raw files. It reads ASCII and binary output from ngspice, Xyce, SPICE OPUS and LTspice. A script can inspect the available plots and signal names, then read only the signals and sample ranges it needs. Results are returned as Tcl lists or, optionally, as real or complex rbc-tk9 vectors.
The repository includes an ngspice voltage-divider raw file . Run the example from the repository root, or change path to the downloaded file.
package require tclsimrawreader
set path [file join test raw_files ngspice dc.raw]
set raw [::tclsimrawreader::openraw $path]
try {
puts [$raw names]
# v(v-sweep) v(in) v(out) i(v1)
puts [$raw npoints]
# 51
set samples [$raw vectors {v(in) v(out)} -from 0 -count 4]
foreach vin [dict get $samples v(in)] vout [dict get $samples v(out)] {
puts [format {%.1f V in -> %.3f V out} $vin $vout]
}
} finally {
$raw close
}The four output voltages are 0.000, 0.067, 0.133 and 0.200 V. Use vector to read one signal as a list, vectors to read selected signals as a dictionary keyed by their raw-file names, or vectors -all to read every signal in the selected plot.
A stepped run can contain several waveforms with the same signal names. The reader exposes each step as an indexed plot. This example uses the stepped transient fixture and prints the number of samples and the available signals for each step.
set path [file join test raw_files ltspice tran_multiplot.raw]
set raw [::tclsimrawreader::openraw -dialect ltspice $path]
try {
foreach plot [$raw plots] {
set index [dict get $plot index]
puts [format {Plot %d: %s, %d samples}\
$index [dict get $plot plotname] [dict get $plot npoints]]
puts [$raw names -plot $index]
}
} finally {
$raw close
}Use -plot before the signal selection when reading data, for example $raw vector -plot 1 time. Plot indices start at zero.
An RBC-enabled build can read samples directly into rbc-tk9 vectors. This is useful when passing a simulation trace to a graph or to tclmeasure. Real signals produce real vectors, and complex signals retain both components.
set path [file join test raw_files ngspice dc.raw]
set raw [::tclsimrawreader::openraw $path]
try {
set signals [$raw vectors {v(in) v(out)} -output vector -names #auto]
} finally {
$raw close
}
set vout [dict get $signals v(out)]
puts [format {Final output: %.3f V} [$vout index end]]
# Final output: 3.333 V
::rbc::vector destroy {*}[dict values $signals]The dictionary retains the original signal names as keys. Its values are the fully qualified vector commands. These vectors belong to the caller and remain available after the file is closed.
Set -output vector on openraw to make vector output the default for that handle. Use -namespace to group destinations and -ifexists replace to update an existing writable vector of the same numeric type. A graph attached to that vector keeps its connection across reads.
tclsimrawreader 0.5 targets Tcl 9. Its runtime dependencies are argparse 0.70 or later and Tcllib. The default source build reads data into Tcl lists. Vector output additionally requires an RBC-enabled build and rbc::vector 0.8.1 or later and works in tclsh without a display.
The rolling release provides installation archives and checksums for Linux GCC, Windows MSYS2/UCRT64 and Windows MSVC x64. These configurations are tested with Tcl 9.1.0 and RBC vector support. Extract the archive matching your Tcl installation into its 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
Use --with-tcl=/path/to/tcl/lib to select a Tcl installation. Add --with-rbc=/path/to/rbc to enable vector output. For MSVC, use the supplied win/makefile.vc.
For interactive help on opening a file:
package require tclsimrawreader ::tclsimrawreader::openraw -help