From fb6bb8b1a6ce57e4f7edbdcba3f964e8b8521175 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sun, 29 May 2016 00:53:07 +0200 Subject: [PATCH] inp.c, copy deck for internal re-sourcing with 'mc_source' to enable Monte-Carlo simulation with commercial model deck --- src/frontend/inp.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index ea9833868..f923e6516 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); @@ -309,7 +310,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; @@ -330,7 +331,30 @@ 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) { + if (mc_deck) { + line_free_x(mc_deck, TRUE); + mc_deck = NULL; + } + 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 (!comfile) + mc_deck = inp_deckcopy(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\n"); + controlled_exit(1); + } + } endTime = seconds(); tfree(dir_name);