Add a new command 'clip vectorname xmin xmax'
This will create a new vector cl_vectorname in the current plot, with all data values outside of xmin, xmax set to NaN. Example: clip v(9) 1.5u 2.5u plot cl_v(9)
This commit is contained in:
parent
9e6be83c4e
commit
7a609ccd9c
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "ngspice/bool.h"
|
||||
#include "ngspice/wordlist.h"
|
||||
#include "ngspice/fteext.h"
|
||||
|
||||
#include "plotting/plotit.h"
|
||||
|
||||
|
|
@ -24,3 +25,18 @@ com_bltplot(wordlist *wl)
|
|||
|
||||
#endif
|
||||
|
||||
void
|
||||
com_clip(wordlist *wl)
|
||||
{
|
||||
int err;
|
||||
double xmin, xmax;
|
||||
char *vecname = wl->wl_word;
|
||||
wl = wl->wl_next;
|
||||
char *mword = wl->wl_word;
|
||||
xmin = INPevaluate(&mword, &err, TRUE);
|
||||
wl = wl->wl_next;
|
||||
mword = wl->wl_word;
|
||||
xmax = INPevaluate(&mword, &err, TRUE);
|
||||
vec_clip(vecname, xmin, xmax);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ void com_plot(wordlist *wl);
|
|||
#ifdef TCL_MODULE
|
||||
void com_bltplot(wordlist *wl);
|
||||
#endif
|
||||
void com_clip(wordlist *wl);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -602,6 +602,10 @@ struct comm spcp_coms[] = {
|
|||
{ 0, 0, 0, 0 }, E_DEFHMASK, 0, 0,
|
||||
NULL,
|
||||
": Print circuit inventory" },
|
||||
{ "clip", com_clip, TRUE, FALSE,
|
||||
{ 0, 0, 0, 0 }, E_DEFHMASK, 3, 3,
|
||||
NULL,
|
||||
": Clip the named vector between xmin and xmax" },
|
||||
#ifdef HAVE_TSEARCH
|
||||
{ "check_ifparm", com_check_ifparm, TRUE, FALSE,
|
||||
{ 0, 0, 0, 0 }, E_DEFHMASK, 0, 0,
|
||||
|
|
@ -1006,6 +1010,10 @@ struct comm nutcp_coms[] = {
|
|||
{ 0, 0, 0, 0 }, E_DEFHMASK, 0, 0,
|
||||
NULL,
|
||||
": Print circuit inventory" } ,
|
||||
{ "clip", com_clip, TRUE, FALSE,
|
||||
{ 0, 0, 0, 0 }, E_DEFHMASK, 3, 3,
|
||||
NULL,
|
||||
": Clip the named vector between xmin and xmax" },
|
||||
{ NULL, NULL, FALSE, FALSE,
|
||||
{ 0, 0, 0, 0 }, E_DEFHMASK, 0, LOTS,
|
||||
NULL,
|
||||
|
|
|
|||
|
|
@ -1151,3 +1151,49 @@ plot_prefix(char *pre, char *str)
|
|||
else
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/* clip a vector between hte two scale values xmin and xmax
|
||||
add a copy of the vector to the current plot
|
||||
Set all data outside xmin and xmax will be set to NAN */
|
||||
bool
|
||||
vec_clip(char* vecname, double xmin, double xmax)
|
||||
{
|
||||
/* check for xmin and xmax */
|
||||
if (xmax < xmin) {
|
||||
double tmp = xmin;
|
||||
xmin = xmax;
|
||||
xmax = tmp;
|
||||
}
|
||||
else if (xmax == xmin) {
|
||||
fprintf(stderr, "Warnig: Cannot clip vector %s\n", vecname);
|
||||
return FALSE;
|
||||
}
|
||||
/* Create new vector as copy within current plot */
|
||||
struct dvec *oldvec = vec_fromplot(vecname, plot_cur);
|
||||
struct dvec *newvec = vec_copy(oldvec);
|
||||
char *oldname = oldvec->v_name;
|
||||
char *newname = tprintf("cl_%s", oldname);
|
||||
// char * newname = copy("new1");
|
||||
tfree(newvec->v_name);
|
||||
newvec->v_name = newname;
|
||||
vec_new(newvec);
|
||||
newvec->v_flags = oldvec->v_flags;
|
||||
/* Compare newvec->v_scale to xmin, xmax */
|
||||
int length = newvec->v_length;
|
||||
int i;
|
||||
for (i = 0; i < length; i++) {
|
||||
if ((plot_cur->pl_scale->v_realdata[i] < xmin) || (plot_cur->pl_scale->v_realdata[i] > xmax))
|
||||
if (isreal(newvec)) {
|
||||
newvec->v_realdata[i] = NAN;
|
||||
}
|
||||
else {
|
||||
newvec->v_compdata[i].cx_real = NAN;
|
||||
newvec->v_compdata[i].cx_imag = NAN;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
vec_rebuild_lookup_table(plot_cur);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -366,6 +366,7 @@ extern void plot_new(struct plot *pl);
|
|||
extern char *vec_basename(struct dvec *v);
|
||||
extern bool plot_prefix(char *pre, char *str);
|
||||
extern void vec_transpose(struct dvec *v);
|
||||
extern bool vec_clip(char* vecname, double xmin, double xmax);
|
||||
|
||||
/* main.c */
|
||||
extern bool ft_intrpt;
|
||||
|
|
|
|||
Loading…
Reference in New Issue