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 Holger Vogt
parent 464f855d1d
commit 5c3a6a3829
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 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. */

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

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

View File

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