From d1a8637a2958ca1ee319b9758a9a99df2e9ea69c Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 12 Aug 2018 18:43:09 +0200 Subject: [PATCH] store deck for command mc_source for each circuit in ft_curckt->ci_mcdeck remove this storage during remcirc keep most recent deck in recent_deck --- src/frontend/inp.c | 53 +++++++++++++++++++++++++++++------ src/frontend/misccoms.c | 6 +++- src/frontend/runcoms2.c | 17 +++++++++-- src/include/ngspice/ftedefs.h | 1 + src/include/ngspice/fteext.h | 4 ++- 5 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 82f44facb..1fdf91708 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -53,6 +53,7 @@ static char *upper(register char *string); static bool doedit(char *filename); static struct card *com_options = NULL; static struct card *mc_deck = NULL; +static struct card *recent_deck = NULL; static void cktislinear(CKTcircuit *ckt, struct card *deck); static void dotifeval(struct card *deck); @@ -61,6 +62,10 @@ static wordlist *inp_savecurrents(struct card *deck, struct card *options, wordl static void eval_agauss(struct card *deck, char *fcn); void line_free_x(struct card *deck, bool recurse); void create_circbyline(char *line); +void inp_source_recent(void); +void inp_mc_free(void); +void inp_remove_recent(void); +static bool mc_reload = FALSE; extern bool ft_batchmode; @@ -331,13 +336,34 @@ line_reverse(struct card *head) } -/* free mc_deck */ +/* store ft_curckt->ci_mcdeck into a 'previous' deck */ void -mc_free(void) +inp_mc_free(void) { - line_free(mc_deck, TRUE); + if (ft_curckt && ft_curckt->ci_mcdeck) { + if (recent_deck) + line_free(recent_deck, TRUE); + recent_deck = ft_curckt->ci_mcdeck; + ft_curckt->ci_mcdeck = NULL; + } + else + fprintf(stderr, "Error: No circuit loaded\n"); +} + +/* called by com_rset: reload most recent circuit */ +void +inp_source_recent(void) { + mc_deck = recent_deck; + mc_reload = TRUE; + inp_spsource(NULL, FALSE, NULL, FALSE); } +/* remove the 'recent' deck */ +void +inp_remove_recent(void) { + if (recent_deck) + line_free(recent_deck, TRUE); +} /* check for .option seed=[val|random] and set the random number generator */ void @@ -435,17 +461,25 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) comfile = TRUE; /* save a copy of the deck for later reloading with 'mc_source' */ if (deck && !comfile) { - if (mc_deck) - mc_free(); + /* stored to new circuit ci_mcdeck in fcn */ mc_deck = inp_deckcopy_oc(deck); } } /* called with *fp == NULL and not intfile: we want to reload circuit from mc_deck */ else { - if (mc_deck) { + /* re-load input deck from the current circuit structure */ + if (ft_curckt && ft_curckt->ci_mcdeck) { + deck = inp_deckcopy(ft_curckt->ci_mcdeck); + expr_w_temper = TRUE; + } + /* re-load deck due to command 'reset' via function inp_source_recent() */ + else if (mc_reload) { deck = inp_deckcopy(mc_deck); expr_w_temper = TRUE; + mc_reload = FALSE; + fprintf(stdout, "Reset re-loads circuit %s\n", mc_deck->line); } + /* no circuit available, should not happen */ else { fprintf(stderr, "Error: No circuit loaded, cannot copy internally using mc_source\n"); controlled_exit(1); @@ -1115,6 +1149,7 @@ inp_dodeck( } ct->ci_name = tt; ct->ci_deck = deck; + ct->ci_mcdeck = mc_deck; ct->ci_options = options; if (deck->actualLine) ct->ci_origdeck = deck->actualLine; @@ -1299,7 +1334,7 @@ com_alterparam(wordlist *wl) char *pname, *pval, *tmp, *subcktname = NULL, *linein, *linefree, *s; bool found = FALSE; - if (!mc_deck) { + if (!ft_curckt->ci_mcdeck) { fprintf(cp_err, "Error: No internal deck available\n"); return; } @@ -1328,7 +1363,7 @@ com_alterparam(wordlist *wl) } tfree(linefree); tfree(s); - for (dd = mc_deck->nextcard; dd; dd = dd->nextcard) { + for (dd = ft_curckt->ci_mcdeck->nextcard; dd; dd = dd->nextcard) { char *curr_line = dd->line; /* alterparam subcktname pname=vpval Parameters from within subcircuit are no longer .param lines, but have been added to @@ -1366,7 +1401,7 @@ com_alterparam(wordlist *wl) /* find x line with same subcircuit name */ struct card *xx; char *bsubb = tprintf(" %s ", subcktname); - for (xx = mc_deck->nextcard; xx; xx = xx->nextcard) { + for (xx = ft_curckt->ci_mcdeck->nextcard; xx; xx = xx->nextcard) { char *xline = xx->line; if (*xline == 'x') { xline = strstr(xline, bsubb); diff --git a/src/frontend/misccoms.c b/src/frontend/misccoms.c index 5501ff70b..e521f177d 100644 --- a/src/frontend/misccoms.c +++ b/src/frontend/misccoms.c @@ -57,6 +57,7 @@ com_quit(wordlist *wl) return; #ifndef SHARED_MODULE +#if 0 if (!ft_ngdebug && !ft_nutmeg) { /* Destroy CKT */ struct circ *cc; @@ -64,6 +65,9 @@ com_quit(wordlist *wl) if (SIMinfo.deleteCircuit) SIMinfo.deleteCircuit(cc->ci_ckt); } +#endif + while (ft_curckt) + com_remcirc(NULL); exit(exitcode); #endif @@ -111,7 +115,7 @@ com_quit(wordlist *wl) destroy_const_plot(); spice_destroy_devices(); #endif - mc_free(); + #ifdef SHARED_MODULE /* add 1000 to notify that we exit from 'quit' */ controlled_exit(1000 + exitcode); diff --git a/src/frontend/runcoms2.c b/src/frontend/runcoms2.c index 46003054b..e4dff9889 100644 --- a/src/frontend/runcoms2.c +++ b/src/frontend/runcoms2.c @@ -32,6 +32,8 @@ extern char rawfileBuf[RAWBUF_SIZE]; extern void line_free_x(struct card *deck, bool recurse); extern INPmodel *modtab; +extern void com_mc_source(wordlist *wl); + #define line_free(line, flag) \ do { \ line_free_x(line, flag); \ @@ -171,10 +173,18 @@ com_resume(wordlist *wl) void com_rset(wordlist *wl) { - struct variable *v, *next; - NG_IGNORE(wl); +#if (1) + if (ft_curckt == NULL) { + fprintf(cp_err, "Error: there is no circuit loaded.\n"); + return; + } + com_remcirc(NULL); + inp_source_recent(); +#else + struct variable *v, *next; + if (ft_curckt == NULL) { fprintf(cp_err, "Error: there is no circuit loaded.\n"); return; @@ -190,6 +200,7 @@ com_rset(wordlist *wl) inp_dodeck(ft_curckt->ci_deck, ft_curckt->ci_name, NULL, TRUE, ft_curckt->ci_options, ft_curckt->ci_filename); +#endif } @@ -262,6 +273,8 @@ com_remcirc(wordlist *wl) rem_tlist(ft_curckt->devtlist); rem_tlist(ft_curckt->modtlist); + inp_mc_free(); + /* delete the actual circuit entry from ft_circuits */ for (p = ft_circuits; p; p = p->ci_next) { if (ft_curckt == p) { diff --git a/src/include/ngspice/ftedefs.h b/src/include/ngspice/ftedefs.h index 758268859..f7d6681a4 100644 --- a/src/include/ngspice/ftedefs.h +++ b/src/include/ngspice/ftedefs.h @@ -37,6 +37,7 @@ struct circ { struct dbcomm *ci_dbs; /* The database storing save, iplot, stop data */ struct card *ci_deck; /* The input deck. */ struct card *ci_origdeck; /* The input deck, before subckt expansion. */ + struct card *ci_mcdeck; /* The compacted input deck, used by mc_source */ struct card *ci_options; /* The .option cards from the deck... */ struct card *ci_meas; /* .measure commands to run after simulation */ struct card *ci_param; /* .param statements found in deck */ diff --git a/src/include/ngspice/fteext.h b/src/include/ngspice/fteext.h index 763a3b9d6..348b98d5b 100644 --- a/src/include/ngspice/fteext.h +++ b/src/include/ngspice/fteext.h @@ -220,7 +220,9 @@ extern char *find_back_assignment(const char *s, const char *start); extern struct card *line_nconc(struct card *head, struct card *rest); extern struct card *line_reverse(struct card *head); -extern void mc_free(void); +extern void inp_mc_free(void); +extern void inp_source_recent(void); +extern void inp_remove_recent(void); extern char **circarray; extern void rem_tlist(struct pt_temper *p);