RBC vectors support

Optional RBC vector output

The default build and output remain Tcl lists (or dictionaries of lists), with no RBC dependency. To enable real and complex rbc-tk9 output, use Tcl 9 and RBC 0.8.1 or newer headers and runtime:

./configure --with-tcl=/path/to/tcl/lib --with-rbc=/path/to/rbc-tk9
make clean
make

--with-rbc accepts a source tree, installation prefix, or directory containing rbcVector.h, rbcDecls.h and rbcStubLib.c, just as in tclmeasure. The portable stub client is compiled into this package; the RBC shared library is not linked. --without-rbc selects the default list-only build. Even an enabled build can load and read lists without RBC installed. rbc::vector is required only when vector output is selected. No Tk initialization is needed, although the installed RBC binary must have its system library dependencies available.

Set handle defaults with -output list|vector and -ifexists error|replace. The initial defaults are list and error; omitted -output and -ifexists at open time inherit the package configuration.

Either option can be overridden for a single vector or vectors call, without changing the handle defaults:

set raw [::tclsimrawreader::openraw file.raw -output vector -ifexists error -namespace ::wave]
set signal [$raw vector v(out)]
# -> ::wave::v(out)
set values [$signal index :]
set commands [$raw vectors {time v(out)} -ifexists replace]
# -> time ::wave::time v(out) ::wave::v(out)
set values [$raw vector v(out) -output list]
$raw close
# Created vectors remain alive and are owned by the caller.

For openraw, options may precede or follow the file name. For read commands, -output, -ifexists and -namespace may precede or follow the selection; -plot precedes it as before. Existing -from, -count, selected-name lists, -all, dialects and multi-plot handling work in both output modes. In vector mode, vector returns one fully qualified command name; vectors returns a dictionary whose original raw-name keys map to fully qualified command names. An empty selection returns an empty dictionary. A zero-length range creates an empty vector.

An explicit openraw -namespace name selects a fixed destination for all vector reads. Relative names resolve against the opening caller; missing namespaces and parents are created at open time. The qualified name is retained for reads from other namespaces. Without this option, destinations use the read caller as before. A per-read -namespace name on vector or vectors overrides the handle setting for that call only. It requires effective vector output, resolves relative to the read caller, and creates missing parents. For example: $raw vectors -all -output vector -namespace ::snapshots -names #auto. Empty namespace names are rejected. This option also works with list defaults and later -output vector overrides. Closing the handle deletes neither the namespace nor its caller-owned output vectors.

Destination names and ownership

Raw names are preserved whenever they are safe literal RBC names. Balanced parentheses, underscores, periods, letters, digits, @ and single interior colons are retained. Vectors are created with -literal true, so numeric names such as v(1) or v(1)(2:4) are never interpreted as length/range specifications. Examples:

Raw name

Destination tail

time

time

v(out)

v(out)

v(1)

v(1)

v_28out_29

v_28out_29

L2:flux

L2:flux

v(a-b)

_raw_7628612D6229

sub::node

_raw_7375623A3A6E6F6465

Names with unsupported characters, unbalanced parentheses, ::, a leading/trailing colon, or the reserved prefix _raw_ use a fallback: _raw_ followed by the uppercase hexadecimal UTF-8 bytes of the complete original name. The empty name maps to _raw_. Reserving this prefix keeps fallback names distinct from literal names; a raw name that already begins with _raw_ is itself encoded. Original dictionary keys are always retained.

The destination uses the per-call namespace, then the handle namespace, then the read caller namespace. Raw namespace separators are encoded, so a raw name cannot select a different namespace. Use $raw vectors -all -output vector -namespace ::signals to choose a namespace explicitly (create it first). Newly created vectors have no mapped Tcl array variable: use the returned command, for example $signal index 1:20, rather than Tcl array substitution $v(out)(1:20). New vector indexes start at zero, including partial reads. Closing a handle does not destroy its output vectors; use rbc::vector destroy when done.

This naming replaces the earlier encoding of every parenthesis and underscore. Existing vectors are not renamed. Use returned command names or dictionary values rather than reconstructing names using the old encoding.

Collisions and numeric types

-ifexists error rejects an existing vector or command. -ifexists replace replaces the data of an existing RBC vector of the same numeric type, retaining the vector identity, clients, index offset and any existing array mapping. It never overwrites an unrelated Tcl command. RBC vector types are immutable: a real/complex mismatch is an error even with replace; explicitly destroy the old vector first if changing type is intended.

Each variable’s resolved raw storage determines its RBC type. Complex samples become complex RBC vectors without losing their imaginary components. Real samples (including real axes in mixed layouts) remain real vectors. Numeric data is decoded into buffers directly, without a full intermediate Tcl list. All selected data is read and all known name/type collisions are checked before publication, so read and preflight errors leave existing values unchanged. RBC notifications and command traces may execute application callbacks during publication; updates are not a transaction against reentrant application code.

Read-only destinations

-ifexists replace preserves the read-only state and never unlocks a destination. A locked real or complex output fails with RBC VECTOR READONLY. Every selected destination is checked before reading/publishing results, so a pre-existing lock on a later column leaves earlier vectors unchanged. Permission is checked again during publication to handle callbacks. List output remains available regardless of destination locks. Unlock explicitly before replacing, or request a fresh destination / #auto. Newly created vectors are writable.

Automatic and explicit output vector names

For a single read, use -name #auto with vector output. For a bulk read, use -names #auto to allocate a fresh RBC vector for every selected signal:

set raw [::tclsimrawreader::openraw file.raw -namespace ::results]
set one [$raw vector v(out) -output vector -name #auto]
set waves [$raw vectors -all -output vector -names #auto]
# Original raw names remain dictionary keys; values are actual RBC command names.
set output [dict get $waves v(out)]
puts [$output length]
::rbc::vector destroy $one {*}[dict values $waves]
$raw close

-names also accepts a dictionary mapping selected raw names to destinations, for example -names {time #auto v(out) saved}. Omitted entries retain the normal signal-derived naming. -name belongs to vector; -names belongs to vectors. Both require vector output and may precede or follow the selection. They are per-read options, not openraw defaults. Unknown or unselected keys, duplicate selections/destinations, and empty destinations are errors.

Relative destinations, including #auto, use the per-call -namespace, the handle’s namespace, or the read caller’s namespace, in that order. Omitted -names entries use signal-derived names in the selected namespace. An absolute destination overrides this location; its parent namespace must exist. RBC itself expands a final #auto component in the selected namespace: the reader does not generate names or counters. auto without # is an ordinary explicit name. Repeated automatic reads create distinct vectors even with -ifexists replace; explicit names retain the existing collision/type policy. Real and complex output, empty ranges, and lack of mapped Tcl arrays behave as before. Returned vectors outlive the raw handle and are owned by the caller. If publication fails, vectors created by that read are removed.

Package defaults

Set representation and collision defaults once after loading the package:

package require tclsimrawreader
::tclsimrawreader::configure -output vector -ifexists replace

New handles inherit output and collision defaults unless their creation call supplies -output or -ifexists explicitly. Existing handles keep their settings; per-read overrides still take precedence.

Use ::tclsimrawreader::configure to query all settings, or ::tclsimrawreader::configure -output to query one. The all-settings dictionary can be restored with ::tclsimrawreader::configure {*}$saved. Initial representation defaults remain list; the initial -ifexists policy is error. Invalid requests and unavailable vector support leave settings unchanged. Configuration belongs to the current Tcl interpreter. The command is public but not namespace-exported, so wildcard imports cannot introduce a configure collision. Namespace selection and naming are unchanged. -ifexists replace still requires a compatible, writable destination.

The collision setting affects vector output only and can be configured even in a build without RBC.


Copyright (c) George Yashin