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.
This commit is contained in:
h_vogt 2016-05-29 01:15:05 +02:00 committed by rlar
parent c554f5786a
commit f42e49770b
5 changed files with 49 additions and 3 deletions

View File

@ -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,

View File

@ -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. */

View File

@ -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);

View File

@ -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);

View File

@ -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;