diff --git a/src/frontend/commands.c b/src/frontend/commands.c index 548c5459c..a53d6ecc3 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 a4df90136..bb43139b4 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 line *com_options = NULL; +static struct line *mc_deck = NULL; static void cktislinear(CKTcircuit *ckt, struct line *deck); static void dotifeval(struct line *deck); static int inp_parse_temper(struct line *deck); @@ -327,6 +328,14 @@ line_reverse(struct line *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 @@ -341,7 +350,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) * intfile = whether input is from internal array. Values are TRUE/FALSE */ { - struct line *deck, *dd, *ld, *prev_param = NULL, *prev_card = NULL; + struct line *deck = NULL, *dd, *ld, *prev_param = NULL, *prev_card = NULL; struct line *realdeck = NULL, *options = NULL, *curr_meas = NULL; char *tt = NULL, name[BSIZE_SP], *s, *t, *temperature = NULL; double testemp = 0.0; @@ -362,7 +371,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); + /* inp_source() called with fp: load from file */ + if (fp) { + deck = inp_readall(fp, dir_name, comfile, intfile); + + /* files starting with *ng_script are user supplied command files */ + if (deck && ciprefix("*ng_script", deck->li_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); @@ -390,7 +421,7 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) if (!deck->li_next) 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 @@ -1062,6 +1093,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 4108b712f..d04725b12 100644 --- a/src/frontend/misccoms.c +++ b/src/frontend/misccoms.c @@ -110,6 +110,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 14b564827..45359b8dc 100644 --- a/src/include/ngspice/fteext.h +++ b/src/include/ngspice/fteext.h @@ -217,6 +217,7 @@ extern FILE *inp_pathopen(char *name, char *mode); extern char *search_identifier(char *str, const char *identifier, char *str_begin); extern struct line *line_nconc(struct line *head, struct line *rest); extern struct line *line_reverse(struct line *head); +extern void mc_free(void); extern char** circarray;