Scalar measurements of a plot with the .measure grammar of
ngspice-47 (SPICE3f5 has none): rise and fall times and delays
(TRIG ... TARG ...), level crossings (WHEN), values at a point
or at an event (FIND ... AT= / FIND ... WHEN), derivatives
(DERIV, a Dune extension), and window statistics (MIN, MAX,
MIN_AT, MAX_AT, PP, AVG, RMS, INTEG). The engine does
the measuring, exactly as for the deck's own .measure cards (which
spice_run() returns in $measurements); measurements read the
plot only and never change a simulation.
Arguments
- plot
A
spice_plotof a.tran,.ac,.dcor.spanalysis, fromspice_run()orspice_read_raw().- spec
A character vector of measurements, e.g.
"trig v(out) val=0.1 rise=1 targ v(out) val=0.9 rise=1","when v(out)=0.5 cross=last","max v(out) from=1n to=5n". Its names, when given, name the results; unnamed ones are calledmeasure(ormeasure1,measure2, ... for several).
Value
A tibble with one row per measurement:
name(chr),analysis(chr:"tran","ac","dc","sp") andplot(chr: the plot's label);value(dbl): the result – a time forWHENand delays, a value forFIND/MIN/AVG/..., the scale value forMIN_AT/MAX_AT;NAwhen the measurement failed;trig,targ,at,with,from,to(dbl): the extra numbers ngspice prints beside the value (delay ends; where aMIN/MAXoccurs; the extremum ofMIN_AT/MAX_AT; the window ofAVG/RMS/INTEG/PP),NAwhere they do not apply;error(chr): why the measurement failed ("out of interval (WHEN)": the event never happens in the window),NAotherwise.
An event that never happens is a row with error set, not an R
error. A malformed spec is an error of class
spice_error_measure.
Details
Each spec is what follows .meas <analysis> <name> on a card; the
analysis is the plot's own. Values take SPICE suffixes (2n, 1meg).
Crossings interpolate linearly between points; AVG integrates by
trapezoids over the window's points, RMS and INTEG by Simpson's
rules with the window edges interpolated, all as ngspice does.
Mirror of the Python package
This is spice.measure(); the deck's measurements are
Result.measurements there.
See also
spice_run() (its measurements field).
Examples
res <- spice_run("rc step
v1 in 0 pulse(0 1 1n 1p 1p 20n 40n)
r1 in out 1k
c1 out 0 1p
.tran 10p 10n
.meas tran trise trig v(out) val=0.1 rise=1 targ v(out) val=0.9 rise=1
.end")
res$measurements
#> # A tibble: 1 × 11
#> name analysis plot value trig targ at with from to error
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 trise tran Transien… 2.20e-9 1.11e-9 3.30e-9 NA NA NA NA NA
tran <- spice_plots(res)[["Transient Analysis"]]
spice_measure(tran, c(
t50 = "when v(out)=0.5",
slope = "deriv v(out) at=2n",
vmax = "max v(out)"
))
#> # A tibble: 3 × 11
#> name analysis plot value trig targ at with from to error
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 t50 tran Transient A… 1.69 e-9 NA NA NA NA NA NA NA
#> 2 slope tran Transient A… 3.68 e+8 NA NA NA NA NA NA NA
#> 3 vmax tran Transient A… 1.000e+0 NA NA 1e-8 NA NA NA NA