From 29f364d4753ea10b84607e65c8f922f79d41d357 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 26 Jan 2019 09:48:30 +0100 Subject: [PATCH] creating a linearized cutout of the original vector by defining the vectors lin-tstart, lin-tstop, and lin-tstep before issuing the 'linearize' command --- src/frontend/linear.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/frontend/linear.c b/src/frontend/linear.c index 749481f47..7cb7d2512 100644 --- a/src/frontend/linear.c +++ b/src/frontend/linear.c @@ -17,6 +17,8 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group * we determine by looking at the transient parameters in the CKT struct. * If no circuit is loaded, e.g. because the 'load' command has been used * to obtain data, try to get parameters from scale vector. + * Interpolation may be restricted to only a region of the input vector, + * thus creating a cutout of the original vector. */ void @@ -26,6 +28,7 @@ com_linearize(wordlist *wl) struct plot *new, *old; struct dvec *newtime, *v; struct dvec *oldtime; + struct dvec *lin; int len, i; if (!plot_cur || !plot_cur->pl_dvecs || !plot_cur->pl_scale) { @@ -54,9 +57,33 @@ com_linearize(wordlist *wl) fprintf(cp_err, "Error: no data in vector\n"); return; } - tstart = plot_cur->pl_scale->v_realdata[0]; - tstop = plot_cur->pl_scale->v_realdata[length - 1]; - tstep = (tstop - tstart) / (double)length; + + /* if this plot contains special vectors lin-tstart, lin-tstop and lin-tstep use these instead */ + lin = vec_fromplot("lin-tstart", plot_cur); + if (lin) { + fprintf(cp_out, "linearize tstart is set to: %8e\n", lin->v_realdata[0]); + tstart = lin->v_realdata[0]; + } + else { + tstart = plot_cur->pl_scale->v_realdata[0]; + } + lin = vec_fromplot("lin-tstop", plot_cur); + if (lin) { + fprintf(cp_out, "linearize tstop is set to: %8e\n", lin->v_realdata[0]); + tstop = lin->v_realdata[0]; + } + else { + tstop = plot_cur->pl_scale->v_realdata[length - 1]; + } + lin = vec_fromplot("lin-tstep", plot_cur); + if (lin) { + fprintf(cp_out, "linearize tstep is set to: %8e\n", lin->v_realdata[0]); + tstep = lin->v_realdata[0]; + } + else { + tstep = (tstop - tstart) / (double)length; + } + } /* finally check if tstart, tstop and tstep are reasonable */ if (((tstop - tstart) * tstep <= 0.0) || ((tstop - tstart) < tstep)) {