From 5c3a6a3829ba2545e5d2f0475602c4963a1750cd Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sun, 29 May 2016 01:15:05 +0200 Subject: [PATCH] new command 'mc_source' to internally reload circuit We store a copy of the whole deck in 'mc_deck'. 'mc_source' can be used to re-read this copy. --- src/frontend/commands.c | 4 ++++ src/frontend/inp.c | 45 +++++++++++++++++++++++++++++++++--- src/frontend/inp.h | 1 + src/frontend/misccoms.c | 1 + src/include/ngspice/fteext.h | 1 + 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/frontend/commands.c b/src/frontend/commands.c index 1480c0139..caf2877d4 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -325,6 +325,10 @@ struct comm spcp_coms[] = { { 1, 0, 0, 0 }, E_DEFHMASK, 0, 1, NULL, "[filename] : Edit a spice deck and then load it in." } , + { "mc_source", com_mc_source, TRUE, FALSE, + { 0, 0, 0, 0 }, E_DEFHMASK, 0, 0, + NULL, + ": Re-source the actual circuit deck for MC simulation." }, { "dump", com_dump, TRUE, FALSE, { 0, 0, 0, 0 }, E_DEFHMASK, 0, 0, NULL, diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 5cbe1c32f..1819897b5 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -52,6 +52,7 @@ Author: 1985 Wayne A. Christopher static char *upper(register char *string); static bool doedit(char *filename); static struct card *com_options = NULL; +static struct card *mc_deck = NULL; static void cktislinear(CKTcircuit *ckt, struct card *deck); static void dotifeval(struct card *deck); @@ -329,6 +330,14 @@ line_reverse(struct card *head) } +/* free mc_deck */ +void +mc_free(void) +{ + line_free_x(mc_deck, TRUE); +} + + /* The routine to source a spice input deck. We read the deck in, take * out the front-end commands, and create a CKT structure. Also we * filter out the following cards: .save, .width, .four, .print, and @@ -343,7 +352,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) * intfile = whether input is from internal array. Values are TRUE/FALSE */ { - struct card *deck, *dd, *ld, *prev_param = NULL, *prev_card = NULL; + struct card *deck = NULL, *dd, *ld, *prev_param = NULL, *prev_card = NULL; struct card *realdeck = NULL, *options = NULL, *curr_meas = NULL; char *tt = NULL, name[BSIZE_SP], *s, *t, *temperature = NULL; double testemp = 0.0; @@ -365,7 +374,29 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) char *dir_name = ngdirname(filename ? filename : "."); startTime = seconds(); - deck = inp_readall(fp, dir_name, comfile, intfile, &expr_w_temper); + /* inp_source() called with fp: load from file */ + if (fp) { + deck = inp_readall(fp, dir_name, comfile, intfile, &expr_w_temper); + + /* files starting with *ng_script are user supplied command files */ + if (deck && ciprefix("*ng_script", deck->line)) + comfile = TRUE; + /* save a copy of the deck for later reloading with 'mc_source' */ + if (deck && !comfile) { + if (mc_deck) + mc_free(); + mc_deck = inp_deckcopy_oc(deck); + } + } + /* inp_spsource() called with *fp == NULL: we want to reload circuit for MC simulation */ + else { + if (mc_deck) + deck = inp_deckcopy(mc_deck); + else { + fprintf(stderr, "Error: No circuit loaded, cannot copy internally using mc_source\n"); + controlled_exit(1); + } + } endTime = seconds(); tfree(dir_name); @@ -393,7 +424,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) if (!deck->nextcard) fprintf(cp_err, "Warning: no lines in input\n"); } - if (!intfile) + if (fp && !intfile) fclose(fp); /* Now save the IO context and start a new control set. After we @@ -1072,6 +1103,14 @@ inp_dodeck( } +void +com_mc_source(wordlist *wl) +{ + NG_IGNORE(wl); + inp_spsource(NULL, FALSE, NULL, FALSE); +} + + /* Edit and re-load the current input deck. Note that if these * commands are used on a non-unix machine, they will leave spice.tmp * junk files lying around. */ diff --git a/src/frontend/inp.h b/src/frontend/inp.h index f6c94af53..2c929a05c 100644 --- a/src/frontend/inp.h +++ b/src/frontend/inp.h @@ -9,6 +9,7 @@ void com_listing(wordlist *wl); void com_edit(wordlist *wl); void com_source(wordlist *wl); +void com_mc_source(wordlist *wl); void com_circbyline(wordlist *wl); diff --git a/src/frontend/misccoms.c b/src/frontend/misccoms.c index d41ff6774..04f3f30f4 100644 --- a/src/frontend/misccoms.c +++ b/src/frontend/misccoms.c @@ -115,6 +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/include/ngspice/fteext.h b/src/include/ngspice/fteext.h index 7944df884..763a3b9d6 100644 --- a/src/include/ngspice/fteext.h +++ b/src/include/ngspice/fteext.h @@ -220,6 +220,7 @@ 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 char **circarray; extern void rem_tlist(struct pt_temper *p);