ngspice/src/frontend/runcoms2.c

281 lines
7.2 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
**********/
/*
* Circuit simulation commands.
*/
#include "ngspice/ngspice.h"
#include "ngspice/cpdefs.h"
#include "ngspice/ftedefs.h"
#include "ngspice/ftedev.h"
#include "ngspice/ftedebug.h"
#include "ngspice/dvec.h"
#include "ngspice/trandefs.h"
2000-04-27 22:03:57 +02:00
src/Makefile.am src/help.c src/main.c src/circuit/Makefile.am src/circuit/ifnewuid.c src/frontend/Makefile.am src/frontend/aspice.c src/frontend/circuits.h src/frontend/com_display.c src/frontend/com_hardcopy.c src/frontend/commands.c src/frontend/commands.h src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/device.c src/frontend/diff.c src/frontend/display.c src/frontend/dotcards.c src/frontend/fourier.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/mw_coms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/postcoms.c src/frontend/postsc.c src/frontend/rawfile.c src/frontend/resource.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/subckt.c src/frontend/vectors.c src/frontend/where.c src/frontend/plotting/Makefile.am src/frontend/plotting/agraf.c src/frontend/plotting/graf.c src/frontend/plotting/plotcurv.c src/frontend/plotting/plotit.c src/frontend/plotting/x11.c src/frontend/plotting/xgraph.c src/include/Makefile.am src/maths/cmaths/cmath4.c src/misc/terminal.c src/misc/terminal.h src/parser/cshpar.c src/parser/front.c src/parser/front.h src/parser/history.c src/parser/history.h src/parser/modify.c src/parser/var2.c src/parser/var2.h src/parser/variable.c: Refactoring of frontend code. * src/include/ftehelp.h src/include/variable.h: Moved into frontend directory. * src/include/cpdefs.h src/include/cpextern.h src/include/ftedefs.h src/include/plot.h: Updates.
2000-06-27 18:09:02 +02:00
#include "circuits.h"
#include "runcoms2.h"
#include "runcoms.h"
src/Makefile.am src/help.c src/main.c src/circuit/Makefile.am src/circuit/ifnewuid.c src/frontend/Makefile.am src/frontend/aspice.c src/frontend/circuits.h src/frontend/com_display.c src/frontend/com_hardcopy.c src/frontend/commands.c src/frontend/commands.h src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/device.c src/frontend/diff.c src/frontend/display.c src/frontend/dotcards.c src/frontend/fourier.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/mw_coms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/postcoms.c src/frontend/postsc.c src/frontend/rawfile.c src/frontend/resource.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/subckt.c src/frontend/vectors.c src/frontend/where.c src/frontend/plotting/Makefile.am src/frontend/plotting/agraf.c src/frontend/plotting/graf.c src/frontend/plotting/plotcurv.c src/frontend/plotting/plotit.c src/frontend/plotting/x11.c src/frontend/plotting/xgraph.c src/include/Makefile.am src/maths/cmaths/cmath4.c src/misc/terminal.c src/misc/terminal.h src/parser/cshpar.c src/parser/front.c src/parser/front.h src/parser/history.c src/parser/history.h src/parser/modify.c src/parser/var2.c src/parser/var2.h src/parser/variable.c: Refactoring of frontend code. * src/include/ftehelp.h src/include/variable.h: Moved into frontend directory. * src/include/cpdefs.h src/include/cpextern.h src/include/ftedefs.h src/include/plot.h: Updates.
2000-06-27 18:09:02 +02:00
#include "variable.h"
#include "breakp2.h"
#include "plotting/graf.h"
#include "spiceif.h"
#include "outitf.h"
#include "numparam/numpaif.h"
#include "ngspice/inpdefs.h"
2000-04-27 22:03:57 +02:00
#define RAWBUF_SIZE 32768
2009-01-31 15:32:12 +01:00
extern char rawfileBuf[RAWBUF_SIZE];
2011-07-20 01:06:29 +02:00
extern void line_free_x(struct line * deck, bool recurse);
extern INPmodel *modtab;
#define line_free(line, flag) \
do { \
line_free_x(line, flag); \
line = NULL; \
} while(0)
2000-04-27 22:03:57 +02:00
/* Continue a simulation. If there is non in progress, this is the
* equivalent of "run".
*/
/* This is a hack to tell iplot routine to redraw the grid and initialize
the display device
*/
2000-04-27 22:03:57 +02:00
bool resumption = FALSE;
2000-04-27 22:03:57 +02:00
void
com_resume(wordlist *wl)
{
struct dbcomm *db;
int err;
/*rawfile output saj*/
bool dofile = FALSE;
char buf[BSIZE_SP];
bool ascii = AsciiRawFile;
/*end saj*/
NG_IGNORE(wl);
/*saj fix segment*/
if (!ft_curckt) {
fprintf(cp_err, "Error: there aren't any circuits loaded.\n");
return;
} else if (ft_curckt->ci_ckt == NULL) { /* Set noparse? */
fprintf(cp_err, "Error: circuit not parsed.\n");
return;
}
/*saj*/
if (ft_curckt->ci_inprogress == FALSE) {
fprintf(cp_err, "Note: run starting\n");
com_run(NULL);
return;
}
ft_curckt->ci_inprogress = TRUE;
ft_setflag = TRUE;
reset_trace();
for (db = dbs, resumption = FALSE; db; db = db->db_next)
if (db->db_type == DB_IPLOT || db->db_type == DB_IPLOTALL)
resumption = TRUE;
/*rawfile output saj*/
if (last_used_rawfile)
dofile = TRUE;
if (cp_getvar("filetype", CP_STRING, buf)) {
if (eq(buf, "binary"))
ascii = FALSE;
else if (eq(buf, "ascii"))
ascii = TRUE;
else
fprintf(cp_err,
"Warning: strange file type \"%s\" (using \"ascii\")\n", buf);
}
if (dofile) {
2012-10-22 23:06:25 +02:00
if (!last_used_rawfile)
rawfileFp = stdout;
#if defined(__MINGW32__) || defined(_MSC_VER)
2012-10-22 23:06:25 +02:00
/* ask if binary or ASCII, open file with w or wb hvogt 15.3.2000 */
else if (ascii) {
if ((rawfileFp = fopen(last_used_rawfile, "a")) == NULL) {
setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE);
perror(last_used_rawfile);
ft_setflag = FALSE;
return;
}
2012-10-22 23:06:25 +02:00
} else if (!ascii) {
if ((rawfileFp = fopen(last_used_rawfile, "ab")) == NULL) {
setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE);
perror(last_used_rawfile);
ft_setflag = FALSE;
return;
}
2012-10-22 23:06:25 +02:00
}
/*---------------------------------------------------------------------------*/
#else
else if (!(rawfileFp = fopen(last_used_rawfile, "a"))) {
setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE);
perror(last_used_rawfile);
ft_setflag = FALSE;
return;
}
#endif
rawfileBinary = !ascii;
} else {
rawfileFp = NULL;
} /* if dofile */
/*end saj*/
err = if_run(ft_curckt->ci_ckt, "resume", NULL,
ft_curckt->ci_symtab);
/*close rawfile saj*/
if (rawfileFp) {
if (ftell(rawfileFp) == 0) {
(void) fclose(rawfileFp);
(void) unlink(last_used_rawfile);
} else {
(void) fclose(rawfileFp);
}
}
/*end saj*/
if (err == 1) {
/* The circuit was interrupted somewhere. */
fprintf(cp_err, "simulation interrupted\n");
} else if (err == 2) {
fprintf(cp_err, "simulation aborted\n");
ft_curckt->ci_inprogress = FALSE;
} else {
ft_curckt->ci_inprogress = FALSE;
}
2000-04-27 22:03:57 +02:00
}
2000-04-27 22:03:57 +02:00
/* Throw out the circuit struct and recreate it from the deck. This command
* should be obsolete.
*/
void
com_rset(wordlist *wl)
{
struct variable *v, *next;
2010-11-16 21:38:24 +01:00
NG_IGNORE(wl);
2010-11-16 20:11:32 +01:00
2000-04-27 22:03:57 +02:00
if (ft_curckt == NULL) {
fprintf(cp_err, "Error: there is no circuit loaded.\n");
return;
}
INPkillMods();
2000-04-27 22:03:57 +02:00
if_cktfree(ft_curckt->ci_ckt, ft_curckt->ci_symtab);
for (v = ft_curckt->ci_vars; v; v = next) {
next = v->va_next;
tfree(v);
2000-04-27 22:03:57 +02:00
}
ft_curckt->ci_vars = NULL;
2011-04-28 17:59:36 +02:00
inp_dodeck(ft_curckt->ci_deck, ft_curckt->ci_name, NULL,
TRUE, ft_curckt->ci_options, ft_curckt->ci_filename);
2000-04-27 22:03:57 +02:00
}
2011-07-20 01:06:29 +02:00
/* Clears ckt and removes current circuit from database */
2011-07-20 01:06:29 +02:00
void
com_remcirc(wordlist *wl)
{
struct variable *v, *next;
struct line *dd; /*in: the spice deck */
struct circ *p, *prev = NULL;
#ifdef SHARED_MODULE
/* This may happen only with shared ngspice during transient analysis,
if simulation is stopped with 'bg_halt'
and then circuit shall be removed prematurely. */
TRANan *job = (TRANan *) ft_curckt->ci_ckt->CKTcurJob;
if ((job->JOBtype == 4) && (job->TRANplot))
SPfrontEnd->OUTendPlot (job->TRANplot);
#endif
2011-07-20 01:06:29 +02:00
NG_IGNORE(wl);
if (ft_curckt == NULL) {
fprintf(cp_err, "Error: there is no circuit loaded.\n");
return;
}
/* delete numparam data structure dicoS */
nupa_del_dicoS();
dbfree(ft_curckt->ci_dbs);
2013-08-20 20:42:34 +02:00
ft_curckt->ci_dbs = NULL;
dbs = NULL;
2011-07-20 01:06:29 +02:00
/* The next lines stem from com_rset */
INPkillMods();
2011-07-20 01:06:29 +02:00
if_cktfree(ft_curckt->ci_ckt, ft_curckt->ci_symtab);
for (v = ft_curckt->ci_vars; v; v = next) {
next = v->va_next;
tfree(v->va_name);
tfree(v);
2011-07-20 01:06:29 +02:00
}
ft_curckt->ci_vars = NULL;
/* delete the deck, parameter list, and options list in ft_curckt */
2011-07-20 01:06:29 +02:00
dd = ft_curckt->ci_deck;
line_free(dd, TRUE);
dd = ft_curckt->ci_param;
line_free(dd, TRUE);
dd = ft_curckt->ci_options;
line_free(dd, TRUE);
wl_free(ft_curckt->ci_commands);
tfree(ft_curckt->FTEstats);
2013-08-21 20:50:02 +02:00
ft_sim->deleteTask (ft_curckt->ci_ckt, ft_curckt->ci_defTask);
2011-07-20 01:06:29 +02:00
if (ft_curckt->ci_name)
tfree(ft_curckt->ci_name);
if (ft_curckt->ci_filename)
tfree(ft_curckt->ci_filename);
/* delete the actual circuit entry from ft_circuits */
for (p = ft_circuits; p; p = p->ci_next) {
if (ft_curckt == p) {
if (prev == NULL) {
ft_circuits = p->ci_next;
tfree(p);
p = NULL;
break;
} else {
2011-07-20 01:06:29 +02:00
prev->ci_next = p->ci_next;
tfree(p);
p = NULL;
break;
}
}
prev = p;
}
2011-07-20 01:06:29 +02:00
/* make first entry in ft_circuits the actual circuit (or NULL) */
ft_curckt = ft_circuits;
if (ft_curckt) {
modtab = ft_curckt->ci_modtab;
dbs = ft_curckt->ci_dbs;
}
2011-07-20 01:06:29 +02:00
}