From 8a1eff8e88de0275908e06ecf49cfbc2192a1207 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 2 May 2020 20:06:58 +0200 Subject: [PATCH] Add function 'remzerovec' to remove vectors of length 0 from current plot. Maybe of interest if you have option savecurrents, write xx all, and ac generates length 0 vectors --- src/frontend/commands.c | 8 ++++++++ src/frontend/postcoms.c | 17 +++++++++++++++++ src/frontend/postcoms.h | 1 + 3 files changed, 26 insertions(+) diff --git a/src/frontend/commands.c b/src/frontend/commands.c index 119bd1dcc..1beeedd3a 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -236,6 +236,10 @@ struct comm spcp_coms[] = { { 040000, 040000, 040000, 040000 }, E_DEFHMASK, 1, LOTS, NULL, "varname ... : Undefine vectors." } , + { "remzerovec", com_remzerovec, FALSE, FALSE, + { 040000, 040000, 040000, 040000 }, E_DEFHMASK, 0, LOTS, + NULL, + "remove zero length vectors." } , { "print", com_print, FALSE, TRUE, { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, arg_print, @@ -716,6 +720,10 @@ struct comm nutcp_coms[] = { { 040000, 040000, 040000, 040000 }, E_DEFHMASK, 1, LOTS, NULL, "varname ... : Undefine vectors." } , + { "remzerovec", com_remzerovec, FALSE, FALSE, + { 040000, 040000, 040000, 040000 }, E_DEFHMASK, 0, LOTS, + NULL, + "remove zero length vectors." }, { "print", com_print, FALSE, TRUE, { 040000, 040000, 040000, 040000 }, E_BEGINNING, 1, LOTS, arg_print, diff --git a/src/frontend/postcoms.c b/src/frontend/postcoms.c index 4d1a7c1d4..926f12ad0 100644 --- a/src/frontend/postcoms.c +++ b/src/frontend/postcoms.c @@ -71,6 +71,23 @@ com_unlet(wordlist *wl) } /* end of function com_unlet */ +/* Remove zero length vectors in the wordlist from the current plot */ +void +com_remzerovec(wordlist* wl) +{ + NG_IGNORE(wl); + + struct dvec* ov; + + for (ov = plot_cur->pl_dvecs; ov; ov = ov->v_next) { + if (ov->v_length == 0) { + ov->v_flags &= ~VF_PERMANENT; + /* Remove from the keyword list. */ + cp_remkword(CT_VECTOR, ov->v_name); + } + } /* end of loop over vectors to delete */ +} /* end of function com_remzerovec */ + /* Load in a file. */ void diff --git a/src/frontend/postcoms.h b/src/frontend/postcoms.h index cff23e94a..7d31b1d26 100644 --- a/src/frontend/postcoms.h +++ b/src/frontend/postcoms.h @@ -15,6 +15,7 @@ void com_transpose(wordlist *wl); void com_cross(wordlist *wl); void com_destroy(wordlist *wl); void com_splot(wordlist *wl); +void com_remzerovec(wordlist* wl); void destroy_const_plot(void);