Jspice3
runcoms.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3f2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1985 Wayne A. Christopher
5  1993 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * Circuit simulation commands.
10  */
11 
12 #include "spice.h"
13 #include "ftedefs.h"
14 #include "fteinp.h"
15 #include "spfteext.h"
16 #include "scedio.h"
17 
18 /* Routines for the commands op, tran, ac, dc, listing, device, state,
19  * resume, stop, trace, run, end. Op, tran, ac, and dc cause the action
20  * to be performed immediately, and run causes whatever actions were
21  * present in the deck to be carried out. End has the effect of stopping
22  * any simulations in progress, as opposed to ending te input deck as
23  * the .end card does.
24  */
25 
26 static FILE *rawfileFp;
27 static bool rawfileBinary;
28 
29 
30 void
32 
33 wordlist *wl;
34 {
35  struct circ *p;
36  int i, j = 0;
37  char buf[BSIZE_SP];
38  char *xx = "Type the number of the desired circuit: ";
39 
40  if (ft_circuits == NULL) {
41  fprintf(cp_err, "Error: there aren't any circuits loaded.\n");
42  return;
43  }
44  if (wl == NULL) {
45  for (p = ft_circuits; p; p = p->ci_next) {
46  if (ft_curckt == p)
47  out_printf("Current %-4d%s\n", ++j, p->ci_name);
48  else
49  out_printf(" %-4d%s\n", ++j, p->ci_name);
50  }
51  out_printf("\n");
52  (void) SCEDfgets(buf,BSIZE_SP,cp_in,xx);
53 
54  clearerr(cp_in);
55  if ((sscanf(buf, " %d ", &i) != 1) || (i < 0) || (i > j))
56  return;
57  for (p = ft_circuits; --i > 0; p = p->ci_next);
58  }
59  else {
60  for (p = ft_circuits; p; p = p->ci_next)
61  if (ciprefix(wl->wl_word, p->ci_name))
62  break;
63  if (p == NULL) {
64  fprintf(cp_err, "Warning: no such circuit \"%s\"\n",
65  wl->wl_word);
66  return;
67  }
68  out_printf("%s\n", p->ci_name);
69  }
70  if (ft_curckt) {
71  /* Actually this can't be false */
75  }
76  ft_curckt = p;
77  return;
78 }
79 
80 
81 void
83 
84 wordlist *wl;
85 {
86  ft_dosim("pz", wl);
87  return;
88 }
89 
90 
91 void
93 
94 wordlist *wl;
95 {
96  ft_dosim("op", wl);
97  return;
98 }
99 
100 
101 void
103 
104 wordlist *wl;
105 {
106  ft_dosim("dc", wl);
107  return;
108 }
109 
110 
111 void
113 
114 wordlist *wl;
115 {
116  ft_dosim("ac", wl);
117  return;
118 }
119 
120 
121 void
123 
124 wordlist *wl;
125 {
126  ft_dosim("tf", wl);
127  return;
128 }
129 
130 
131 void
133 
134 wordlist *wl;
135 {
136  ft_dosim("tran", wl);
137  return;
138 }
139 
140 
141 void
143 
144 wordlist *wl;
145 {
146  ft_dosim("sens", wl);
147  return;
148 }
149 
150 
151 void
153 
154 wordlist *wl;
155 {
156  ft_dosim("disto", wl);
157  return;
158 }
159 
160 
161 void
163 
164 wordlist *wl;
165 {
166  ft_dosim("noise", wl);
167  return;
168 }
169 
170 
171 void
172 ft_dosim(what, wl)
173 
174 char *what;
175 wordlist *wl;
176 {
177  bool dofile = false;
178  char buf[BSIZE_SP];
179  struct circ *ct;
180  int err = 0;
181  bool ascii = true;
182  extern char *kw_filetype;
183 
184  /* give sced access to loop command */
185  if (eq(what,"loop")) {
186  com_loop(wl);
187  return;
188  }
189 
190  if (ft_servermode || (eq(what, "run") && wl))
191  dofile = true;
192 
193  if (cp_getvar(kw_filetype, VT_STRING, buf)) {
194  if (eq(buf, "binary"))
195  ascii = false;
196 #ifdef notdef
197  else if (eq(buf, "oct"))
198  oct = true;
199 #endif
200  else if (!eq(buf, "ascii"))
201  fprintf(cp_err, "Warning: strange file type %s\n", buf);
202  }
203 
204  if (!ft_curckt) {
205  fprintf(cp_err, "Error: there aren't any circuits loaded.\n");
206  return;
207  }
208  else if (ft_curckt->ci_ckt == NULL) { /* Set noparse? */
209  fprintf(cp_err, "Error: circuit not parsed.\n");
210  return;
211  }
212  for (ct = ft_circuits; ct; ct = ct->ci_next)
213  if (ct->ci_inprogress && (ct != ft_curckt)) {
214  fprintf(cp_err,
215  "Warning: losing old state for circuit '%s'\n", ct->ci_name);
216  ct->ci_inprogress = false;
217  }
218  if (ft_curckt->ci_inprogress && !eq(what, "resume")) {
219  ft_setflag = true;
220  fprintf(cp_err, "Resuming run in progress.\n");
221  com_resume((wordlist *) NULL);
222  return;
223  }
224  if (ft_curckt->ci_runonce)
225  com_rset((wordlist *) NULL);
226 
227  ft_intrpt = false;
228  if (dofile) {
229  if (ft_servermode)
230  rawfileFp = cp_out;
231  else if (!wl || !wl->wl_word || !*wl->wl_word) {
232  if (ft_rawfile)
233  if (!(rawfileFp = fopen(ft_rawfile, "w"))) {
234  perror(wl->wl_word);
235  return;
236  }
237  else
238  rawfileFp = cp_out;
239  }
240  else if (!(rawfileFp = fopen(wl->wl_word, "w"))) {
241  perror(wl->wl_word);
242  return;
243  }
244  rawfileBinary = !ascii;
245  }
246  else {
247  rawfileFp = NULL;
248  }
249 
250  ft_curckt->ci_inprogress = true;
251  err = if_run(what, wl);
252  if (err == 1) {
253  /* The circuit was interrupted somewhere. */
254  DevGrHalt();
255  fprintf(cp_err, "%s: simulation interrupted\n", what);
256  }
257  else if (err == 2) {
258  DevGrHalt();
259  ft_curckt->ci_inprogress = false;
260  fprintf(cp_err, "%s: simulation aborted\n", what);
261  }
262  else
263  ft_curckt->ci_inprogress = false;
264 
265  if (rawfileFp && rawfileFp != cp_out) {
266  (void) fclose(rawfileFp);
267  rawfileFp = NULL;
268  }
269  ft_curckt->ci_runonce = true;
270 }
271 
272 
273 /* Continue a simulation. If there is non in progress, this is the
274  * equivalent of "run".
275  */
276 
277 /* ARGSUSED */
278 void
280 
281 wordlist *wl;
282 {
283  int err;
284 
285  if (!ft_curckt) return;
286  if (ft_curckt->ci_inprogress == false) {
287  fprintf(cp_err, "Note: run starting\n");
288  com_run((wordlist *) NULL);
289  return;
290  }
291  ft_curckt->ci_inprogress = true;
292 
293  err = if_run("resume", (wordlist *) NULL);
294  if (err == 1) {
295  /* The circuit was interrupted somewhere. */
296  DevGrHalt();
297  fprintf(cp_err, "simulation interrupted\n");
298  }
299  else if (err == 2) {
300  DevGrHalt();
301  ft_curckt->ci_inprogress = false;
302  fprintf(cp_err, "simulation aborted\n");
303  }
304  else
305  ft_curckt->ci_inprogress = false;
306 
307  if (rawfileFp && rawfileFp != cp_out) {
308  (void) fclose(rawfileFp);
309  rawfileFp = NULL;
310  }
311  ft_curckt->ci_runonce = true;
312 }
313 
314 
315 void
317 
318 /* Usage is run [filename]
319  */
320 wordlist *wl;
321 {
322  ft_dosim("run", wl);
323  return;
324 }
325 
326 
327 void
328 ft_dorun(file)
329 
330 char *file;
331 {
332  static wordlist wl = { NULL, NULL, NULL } ;
333 
334  wl.wl_word = file;
335  if (file)
336  ft_dosim("run", &wl);
337  else
338  ft_dosim("run", (wordlist *) NULL);
339  return;
340 }
341 
342 
343 /* ARGSUSED */
344 void
346 
347 /* Throw out the circuit struct and recreate it from the original deck.
348  * The shell variables are updated.
349  */
350 wordlist *wl;
351 {
352  struct line *deck, *dd;
353  char *filename, *cblock;
354 
355  if (ft_curckt == NULL) {
356  fprintf(cp_err, "Error: there is no circuit loaded.\n");
357  return;
358  }
359 
360  /*
361  (*(ft_sim->deleteTask))(ft_curckt->ci_ckt,ft_curckt->ci_defTask);
362  if_cktfree(ft_curckt->ci_ckt, (char*)ft_curckt->ci_symtab);
363  inp_dodeck(ft_curckt->ci_deck, ft_curckt->ci_name, (wordlist *) NULL,
364  true, ft_curckt->ci_options, ft_curckt->ci_filename);
365  ft_curckt->ci_runonce = false;
366  */
367 
368  dd = ft_curckt->ci_deck;
369  deck = dd->li_actual;
370  dd->li_actual = NULL;
372  filename = ft_curckt->ci_filename;
374  cblock = ft_curckt->ci_contblk;
376  if_cktclear();
377  inp_spdeck(deck,filename);
378  ft_curckt->ci_contblk = cblock;
379  txfree(filename);
380 }
381 
382 
383 /* ARGSUSED */
384 bool
385 ft_getOutReq(fpp, plotp, binp, name, title)
386 
387 FILE **fpp;
388 struct plot **plotp;
389 bool *binp;
390 char *name, *title;
391 {
392  /*struct plot *pl;*/
393 
394  if (rawfileFp) {
395  *fpp = rawfileFp;
396  *binp = rawfileBinary;
397  return (true);
398  }
399  else {
400  return (false);
401  }
402 }
403 
404 
405 void
407 
408 /* free command - free the current plot, circuit */
409 wordlist *wl;
410 {
411  char s[8];
412  char *xx1 = "Delete all plots (no) ? ";
413  char *xx2 = "Delete current plot (yes) ? ";
414  char *xx3 = "Delete all circuits (no) ? ";
415  char *xx4 = "Delete current circuit (yes) ? ";
416  bool yes = false;
417  bool plots = false;
418  bool circuits = false;
419  bool all = false;
420  wordlist *ww;
421 
422 
423  for (ww = wl; ww; ww = ww->wl_next) {
424  if (ciprefix("p",ww->wl_word)) {
425  plots = true;
426  continue;
427  }
428  if (ciprefix("c",ww->wl_word)) {
429  circuits = true;
430  continue;
431  }
432  if (ciprefix("y",ww->wl_word)) {
433  yes = true;
434  continue;
435  }
436  if (ciprefix("a",ww->wl_word)) {
437  all = true;
438  continue;
439  }
440  }
441  if (!plots && !circuits) {
442  plots = true;
443  circuits = true;
444  }
445  vec_gc();
446 
447  if (plots) {
448  if (!plot_cur || eq(plot_cur->pl_name,"constants"))
449  (void) fprintf(cp_err,"No plot to delete.\n");
450  else {
451  if (all) {
452  if (!yes)
453  (void) SCEDfgets(s,8,cp_in,xx1);
454  if (yes || *s == 'y' || *s == 'Y')
455  while (plot_cur && !eq(plot_cur->pl_name,"constants"))
457  }
458  else {
459  if (!yes)
460  (void) SCEDfgets(s,8,cp_in,xx2);
461  if (yes || *s == 'y' || *s == 'Y' || *s == '\n')
463  }
464  }
465  }
466 
467  if (circuits) {
468  if (!ft_curckt) {
469  (void) fprintf(cp_err,"No circuit to delete.\n");
470  return;
471  }
472  else {
473  if (all) {
474  if (!yes)
475  (void) SCEDfgets(s,8,cp_in,xx3);
476  if (yes || *s == 'y' || *s == 'Y')
477  while (ft_curckt)
478  if_cktclear();
479  }
480  else {
481  if (!yes)
482  (void) SCEDfgets(s,8,cp_in,xx4);
483  if (yes || *s == 'y' || *s == 'Y' || *s == '\n')
484  if_cktclear();
485  }
486  }
487  }
488 }
struct line * li_actual
Definition: fteinp.h:19
void com_disto(wordlist *wl)
Definition: runcoms.c:152
bool ft_intrpt
Definition: main.c:47
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
#define xx1
#define eq(a, b)
Definition: misc.h:29
int ciprefix()
struct circ * ci_next
Definition: ftedefs.h:37
bool cp_getvar(char *n, int t, char *r)
Definition: help.c:184
void out_printf()
int if_run()
char * pl_name
Definition: ftedata.h:64
Definition: ftedefs.h:25
Definition: cddefs.h:119
void ft_dosim(char *what, wordlist *wl)
Definition: runcoms.c:172
struct plot * plot_cur
Definition: vectors.c:43
struct line * ci_origdeck
Definition: ftedefs.h:31
void com_tf(wordlist *wl)
Definition: runcoms.c:122
struct line * ci_deck
Definition: ftedefs.h:30
char * ci_devices
Definition: ftedefs.h:39
bool inp_spdeck(struct line *deck, char *filename)
Definition: inp.c:463
void vec_gc()
Definition: vectors.c:681
bool ci_inprogress
Definition: ftedefs.h:34
FILE * p
Definition: proc2mod.c:48
char * ci_ckt
Definition: ftedefs.h:27
Definition: ftedata.h:61
char * ci_filename
Definition: ftedefs.h:40
void com_sens(wordlist *wl)
Definition: runcoms.c:142
#define xx4
Definition: library.c:18
char * ci_contblk
Definition: ftedefs.h:29
bool ft_setflag
Definition: main.c:48
char * ci_nodes
Definition: ftedefs.h:38
char * kw_filetype
Definition: options.c:355
void com_rset(wordlist *wl)
Definition: runcoms.c:345
char * ft_rawfile
Definition: main.c:39
FILE * cp_err
Definition: help.c:101
void com_tran(wordlist *wl)
Definition: runcoms.c:132
#define CT_DEVNAMES
Definition: fteconst.h:87
Definition: fteinp.h:14
void com_pz(wordlist *wl)
Definition: runcoms.c:82
struct circ * ft_circuits
Definition: main.c:185
void if_cktclear()
Definition: spiceif.c:476
void txfree()
#define NULL
Definition: spdefs.h:121
void com_noise(wordlist *wl)
Definition: runcoms.c:162
struct circ * ft_curckt
Definition: main.c:184
FILE * cp_out
Definition: help.c:101
bool ft_servermode
Definition: main.c:46
bool ft_getOutReq(FILE **fpp, struct plot **plotp, bool *binp, char *name, char *title)
Definition: runcoms.c:385
char * SCEDfgets(char *s, int n, FILE *fp, char *prompt)
Definition: scedstub.c:41
#define VT_STRING
Definition: cpstd.h:63
void perror()
void com_scirc(wordlist *wl)
Definition: runcoms.c:31
bool ci_runonce
Definition: ftedefs.h:35
static FILE * rawfileFp
Definition: runcoms.c:26
Definition: cpstd.h:21
#define xx3
void com_dc(wordlist *wl)
Definition: runcoms.c:102
void com_free(wordlist *wl)
Definition: runcoms.c:406
Definition: netlist.c:477
void DevGrHalt()
Definition: display.c:151
struct wordlist * wl_next
Definition: cpstd.h:23
#define CT_NODENAMES
Definition: fteconst.h:89
#define xx2
char * ci_name
Definition: ftedefs.h:26
Definition: mfb.h:383
char * wl_word
Definition: cpstd.h:22
void ft_dorun(char *file)
Definition: runcoms.c:328
FILE * cp_in
Definition: help.c:101
void com_run(wordlist *wl)
Definition: runcoms.c:316
void com_resume(wordlist *wl)
Definition: runcoms.c:279
void clearerr(FILE *fp)
Definition: libfuncs.c:116
void com_op(wordlist *wl)
Definition: runcoms.c:92
void com_loop()
void com_destroy()
static bool rawfileBinary
Definition: runcoms.c:27
void com_ac(wordlist *wl)
Definition: runcoms.c:112
char * cp_kwswitch()