Jspice3
iplot.c File Reference
#include "spice.h"
#include "ftedefs.h"
#include "ftedebug.h"
#include "plotdefs.h"
Include dependency graph for iplot.c:

Go to the source code of this file.

Macros

#define XFACTOR   2 /* How much to expand the X scale during iplot. */
 
#define YFACTOR   1.5 /* How much to expand the Y scale during iplot. */
 

Functions

static void iplot ()
 
static struct dvlistget_dvecs ()
 
void gr_iplot (struct plot *plot)
 
static void iplot (struct dbcomm *db, struct plot *pl)
 
static struct dvlistget_dvecs (struct dbcomm *db)
 
void gr_end_iplot ()
 

Variables

struct dbcommdbiplot
 
GRAPHEchoGraph
 

Macro Definition Documentation

#define XFACTOR   2 /* How much to expand the X scale during iplot. */

Definition at line 16 of file iplot.c.

#define YFACTOR   1.5 /* How much to expand the Y scale during iplot. */

Definition at line 17 of file iplot.c.

Function Documentation

static struct dvlist* get_dvecs ( )
static
static struct dvlist* get_dvecs ( struct dbcomm db)
static

Definition at line 322 of file iplot.c.

326 {
327  struct dvec *v;
328  struct dvlist *dl, *dl0 = NULL;
329  struct dbcomm *dc;
330  wordlist *wl0, *wl, wt;
331  char *tmp;
332  struct pnode *pn;
333 
334  wt.wl_prev = wt.wl_next = NULL;
335 again:
336  for (dc = db; dc; dc = dc->db_also) {
337  if (eq(dc->db_nodename1,"all")) {
339  for (wl = wl0; wl; wl = wl->wl_next) {
340  if (dl0 == NULL) {
341  dl = dl0 = alloc(struct dvlist);
342  }
343  else {
344  dl->dl_next = alloc(struct dvlist);
345  dl = dl->dl_next;
346  }
347  dl->dl_dvec = (struct dvec*)((char**)wl->wl_word)[1];
348  }
349  wl_free(wl0);
350  continue;
351  }
353 /* hook for expressions
354  if (!v) {
355  wt.wl_word = dc->db_nodename1;
356  pn = ft_getpnames(&wt, false);
357  if (!pn)
358  continue;
359  v = ft_evaluate(pn);
360  inp_pnfree(pn);
361  }
362 */
363  if (!v)
364  continue;
365 
366  if (dl0 == NULL) {
367  dl = dl0 = alloc(struct dvlist);
368  }
369  else {
370  dl->dl_next = alloc(struct dvlist);
371  dl = dl->dl_next;
372  }
373  dl->dl_dvec = v;
374  }
375 
376  if (!dispdev->windows) {
377  /* pick up any more dvecs */
378  for (db = db->db_next; db; db = db->db_next) {
379  if (db->db_type != DB_IPLOT)
380  continue;
381  goto again;
382  }
383  }
384 
385  return (dl0);
386 }
#define eq(a, b)
Definition: misc.h:29
struct plot * plot_cur
Definition: vectors.c:43
Definition: ftedata.h:49
DISPDEVICE * dispdev
Definition: display.c:112
Definition: library.c:18
void * pl_hashtab
Definition: ftedata.h:66
#define alloc(type)
Definition: cdmacs.h:21
struct dvlist * dl_next
Definition: ftedata.h:51
void wl_free()
bool windows
Definition: plotdev.h:61
char * db_nodename1
Definition: ftedebug.h:23
struct wordlist * wl_prev
Definition: cpstd.h:24
char db_type
Definition: ftedebug.h:22
#define NULL
Definition: spdefs.h:121
struct dbcomm * db_next
Definition: ftedebug.h:28
struct dvec * vec_fromplot()
Definition: ftedata.h:24
struct dvec * dl_dvec
Definition: ftedata.h:50
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
struct dbcomm * db_also
Definition: ftedebug.h:27
#define DB_IPLOT
Definition: ftedebug.h:16
void * htab_list()
Definition: fteparse.h:16
void gr_end_iplot ( )

Definition at line 397 of file iplot.c.

398 {
399 
400  struct dbcomm *db, *prev, *next;
401  GRAPH *graph;
402  struct dvec *dv;
403  struct dvlist *ddv, *ddn;
404 
405  EchoGraph = NULL;
406 
407  /* redraw for the last time */
408  for (db = dbiplot; db; db = db->db_next) {
409  if (db->db_type == DB_IPLOT) {
410 
411  if (db->db_graphid) {
412  graph = FindGraph(db->db_graphid);
413  PushGraphContext(graph);
414  if (eq(db->db_nodename2,"graf"))
415  iplot_end();
416  else {
417  (*graph->redraw)(graph);
418  gr_end();
419  }
420  if (!dispdev->windows) {
421  db->db_graphid = 0;
422  if (graph->graphtype == GR_PLOT) {
423  /* the dveclist has not been copied */
424  for (ddv = (struct dvlist *)graph->plotdata; ddv;
425  ddv = ddn) {
426  ddn = ddv->dl_next;
427  txfree((char*)ddv);
428  }
429  graph->plotdata = (GRDATA)NULL;
430  }
431  DevHalt();
432  PopGraphContext();
433  DestroyGraph(graph->graphid);
434  return;
435  }
436  PopGraphContext();
437  }
438  }
439  }
440 
441  /* Tricky stuff - if an iplot window is closed before the simulation
442  * is complete, it is assumed that the debug is no longer wanted.
443  * DestroyGraph simply sets the debug type to DB_DEADIPLOT (so that
444  * no more plotting is done). Below we finish killing the associated
445  * graph, and unlink the dead iplot from the debug list.
446  * After the simulation finishes, we can kill the window without
447  * affecting the debug list, as the db_graphid is set to zero (below).
448  */
449 
450  prev = NULL;
451  for (db = dbiplot; db; prev = db, db = next) {
452  next = db->db_next;
453  if (db->db_type == DB_DEADIPLOT) {
454  if (db->db_graphid) {
455  /* should always be true */
456 
457  graph = FindGraph(db->db_graphid);
458  if (graph->graphtype == GR_PLOT) {
459  /* the dveclist has not been copied */
460  for (ddv = (struct dvlist *)graph->plotdata; ddv;
461  ddv = ddn) {
462  ddn = ddv->dl_next;
463  txfree((char*)ddv);
464  }
465  graph->plotdata = (GRDATA)NULL;
466  }
467  DestroyGraph(db->db_graphid);
468  if (prev)
469  prev->db_next = next;
470  else
471  dbiplot = next;
472  dbfree(db);
473  }
474  }
475  else if (db->db_type == DB_IPLOT) {
476 
477  if (db->db_graphid) {
478 
479  graph = FindGraph(db->db_graphid);
480  if (graph->graphtype == GR_PLOT) {
481  /* get private copy of dvecs, free list */
482  ddv = (struct dvlist*)graph->plotdata;
483  graph->plotdata = (*graph->copydata)(graph->plotdata);
484  for ( ; ddv; ddv = ddn) {
485  ddn = ddv->dl_next;
486  txfree((char*)ddv);
487  }
488  }
489  db->db_graphid = 0;
490  }
491  else {
492  /* warn that this wasn't plotted */
493  fprintf(cp_err, "Warning: iplot %d was not executed.\n",
494  db->db_number);
495  }
496  }
497  }
498  return;
499 }
#define eq(a, b)
Definition: misc.h:29
struct dbcomm * dbiplot
Definition: main.c:186
char * GRDATA
Definition: ftegraph.h:26
int db_graphid
Definition: ftedebug.h:26
void dbfree()
void iplot_end()
Definition: newgraf.c:709
Definition: ftedata.h:49
DISPDEVICE * dispdev
Definition: display.c:112
GRDATA(* copydata)()
Definition: ftegraph.h:72
GRAPH * EchoGraph
Definition: newgraf.c:53
struct dvlist * dl_next
Definition: ftedata.h:51
FILE * cp_err
Definition: help.c:101
bool windows
Definition: plotdev.h:61
void DevHalt()
Definition: display.c:226
char db_type
Definition: ftedebug.h:22
void txfree()
void PushGraphContext()
#define NULL
Definition: spdefs.h:121
int graphtype
Definition: ftegraph.h:31
int graphid
Definition: ftegraph.h:30
GRDATA plotdata
Definition: ftegraph.h:33
struct dbcomm * db_next
Definition: ftedebug.h:28
Definition: ftegraph.h:29
char * db_nodename2
Definition: ftedebug.h:24
Definition: ftedata.h:24
GRAPH * FindGraph()
#define DB_DEADIPLOT
Definition: ftedebug.h:18
void PopGraphContext()
Definition: graphdb.c:270
int DestroyGraph()
#define GR_PLOT
Definition: ftegraph.h:20
void(* redraw)()
Definition: ftegraph.h:70
#define DB_IPLOT
Definition: ftedebug.h:16
void gr_end()
Definition: graf.c:168
void gr_iplot ( struct plot plot)

Definition at line 29 of file iplot.c.

38 {
39 
40  struct dbcomm *db;
41  GRAPH *g;
42  int gid;
43 
44  for (db = dbiplot; db; db = db->db_next) {
45  if (db->db_type == DB_IPLOT) {
46 
47  gid = db->db_graphid;
48  if (gid) {
49  g = FindGraph(db->db_graphid);
50  if (g) {
51  if (!EchoGraph)
52  EchoGraph = g;
54  }
55  }
56  iplot(db, plot);
57  if (gid && g) PopGraphContext();
58  if (!dispdev->windows)
59  return;
60  }
61  }
62 }
struct dbcomm * dbiplot
Definition: main.c:186
int db_graphid
Definition: ftedebug.h:26
DISPDEVICE * dispdev
Definition: display.c:112
GRAPH * EchoGraph
Definition: newgraf.c:53
static void iplot()
bool windows
Definition: plotdev.h:61
char db_type
Definition: ftedebug.h:22
void PushGraphContext()
struct dbcomm * db_next
Definition: ftedebug.h:28
Definition: ftegraph.h:29
GRAPH * FindGraph()
void PopGraphContext()
Definition: graphdb.c:270
Definition: cddefs.h:227
#define DB_IPLOT
Definition: ftedebug.h:16
static void iplot ( )
static
static void iplot ( struct dbcomm db,
struct plot pl 
)
static

Definition at line 66 of file iplot.c.

70 {
71  struct dvlist *dl0, *dl;
72  struct dvec *xs = pl->pl_scale;
73  int len = xs->v_length;
74  struct dvec *v;
75  double *lims, dy;
76  double start, stop;
77  int j;
78  bool changed = false;
79  int yt;
80  double xlims[2], ylims[2];
81  GRAPH *graph;
82  struct grinit gr;
83 
84  /* db is NULL if the graphics does not support more than one
85  * window.
86  */
87 
88  if (ft_grdb)
89  fprintf(cp_err, "Entering iplot, len = %d\n\r", len);
90 
91  if (len < IPOINTMIN) {
92  /* Nothing yet, initialize flag for errors */
93  return;
94  }
95 
96  if (len == IPOINTMIN || !db->db_graphid) {
97  /* Draw the grid for the first time, and plot everything. */
98 
99  /* Error handling: If an error occurs during plot inialization,
100  * db_iteration is set to -1 (db_graphid remains 0), so this
101  * routine just exits on future calls. If an error occurs later,
102  * db_iteration is set to -1, and the plot is "frozen".
103  */
104 
105  if (len == IPOINTMIN)
106  db->db_iteration = 0;
107 
108  if (db->db_iteration == -1) /* error flag, set below */
109  return;
110 
111  dl0 = get_dvecs(db);
112  if (dl0 == NULL) {
113  db->db_iteration = -1;
114  return;
115  }
116 
117  if (eq(db->db_nodename2,"graf")) {
118  db->db_graphid = iplot_begin(dl0,pl);
119  if (!db->db_graphid)
120  db->db_iteration = -1;
121  return;
122  }
123 
124  lims = ft_minmax(xs, true);
125  xlims[0] = lims[0];
126  xlims[1] = lims[1];
127  ylims[0] = 1;
128  ylims[1] = -1;
129  for (j = 0, dl = dl0; dl; j++, dl = dl->dl_next) {
130  v = dl->dl_dvec;
131  lims = ft_minmax(v, true);
132  if (ylims[0] > ylims[1]) {
133  ylims[0] = lims[0];
134  ylims[1] = lims[1];
135  }
136  else {
137  if (lims[0] < ylims[0]) ylims[0] = lims[0];
138  if (lims[1] > ylims[1]) ylims[1] = lims[1];
139  }
140  if (ylims[0] == ylims[1]) {
141  ylims[0] -= 1e-30;
142  ylims[1] += 1e-30;
143  }
144  }
145  if (ft_grdb)
146  fprintf(cp_err,
147  "iplot: after %d, xlims = %G, %G, ylims = %G, %G\n\r",
148  IPOINTMIN,
149  xlims[0],
150  xlims[1],
151  ylims[0],
152  ylims[1]);
153 
154  for (yt = dl0->dl_dvec->v_type, dl = dl0; dl; dl = dl->dl_next)
155  if (dl->dl_dvec->v_type != yt) {
156  yt = 0;
157  break;
158  }
159 
160  gr.xlims = xlims;
161  gr.ylims = ylims;
162  gr.xname = xs->v_name;
163  gr.plotname = pl->pl_title;
164  gr.hcopy = NULL;
165  gr.nplots = j;
166  gr.xdelta = 0.0;
167  gr.ydelta = 0.0;
168  gr.gridtype = GRID_LIN;
169  gr.plottype = PLOT_LIN;
170  gr.xlabel = xs->v_name;
171  gr.ylabel = "";
172  gr.xtype = xs->v_type;
173  gr.ytype = yt;
174  gr.pname = "";
175  gr.commandline = "iplot";
176 
177  graph = gr_init(dl0,(char*)&gr);
178  if (graph)
179  db->db_graphid = graph->graphid;
180  if (!db->db_graphid)
181  db->db_iteration = -1;
182  return;
183  }
184 
185 /* bad foobar here for ^C pause in DOS, have to restart graphics */
186 
187  /* error occurred */
188  if (db->db_iteration == -1)
189  return;
190 
191  if (eq(db->db_nodename2,"graf")) {
192  if (iplot_point()) {
193  /* error */
194  db->db_iteration = -1;
195  }
196  return;
197  }
198 
199  /* First see if we have to make the screen bigger */
200  dy = (isreal(xs) ? xs->v_realdata[len - 1] :
201  realpart(&xs->v_compdata[len - 1]));
202  if (ft_grdb)
203  fprintf(cp_err, "x = %G\n\r", dy);
204 
205  /* hack to keep from overshooting range */
206  stop = pl->pl_stop;
207  start = pl->pl_start;
208  if (stop < start) {
209  stop = pl->pl_start;
210  start = pl->pl_stop;
211  }
212 
213  while (dy < currentgraph->datawindow.xmin) {
214  changed = true;
215  if (ft_grdb)
216  fprintf(cp_err, "resize: xlo %G -> %G\n\r",
221 
225 
226  if (start != stop && currentgraph->datawindow.xmin < start) {
228  break;
229  }
230  }
233 
234  while (dy > currentgraph->datawindow.xmax) {
235  changed = true;
236  if (ft_grdb)
237  fprintf(cp_err, "resize: xhi %G -> %G\n\r",
242 
246 
247  if (start != stop && currentgraph->datawindow.xmax > stop) {
248  currentgraph->datawindow.xmax = stop;
249  break;
250  }
251  }
252 
253  dl0 = (struct dvlist*)currentgraph->plotdata;
254  for (dl = dl0; dl; dl = dl->dl_next) {
255  v = dl->dl_dvec;
256  dy = (isreal(v) ? v->v_realdata[len - 1] :
257  realpart(&v->v_compdata[len - 1]));
258  if (ft_grdb)
259  fprintf(cp_err, "y = %G\n\r", dy);
260 
261  while (dy < currentgraph->datawindow.ymin) {
262  changed = true;
263  if (ft_grdb)
264  fprintf(cp_err, "resize: ylo %G -> %G\n\r",
272  }
273 
278 
279  while (dy > currentgraph->datawindow.ymax) {
280  changed = true;
281  if (ft_grdb)
282  fprintf(cp_err, "resize: yhi %G -> %G\n\r",
287 
291  }
292  }
293  if (changed) {
294  /* Redraw everything. */
296  }
297  else {
298  /* Just connect the last two points. This won't
299  * be done with curve interpolation, so it might
300  * look funny.
301  */
302  for (dl = dl0; dl; dl = dl->dl_next) {
303  v = dl->dl_dvec;
304  gr_point(v,
305  (isreal(xs) ? xs->v_realdata[len - 1] :
306  realpart(&xs->v_compdata[len - 1])),
307  (isreal(v) ? v->v_realdata[len - 1] :
308  realpart(&v->v_compdata[len - 1])),
309  (isreal(xs) ? xs->v_realdata[len - 2] :
310  realpart(&xs->v_compdata[len - 2])),
311  (isreal(v) ? v->v_realdata[len - 2] :
312  realpart(&v->v_compdata[len - 2])),
313  len - 1);
314  }
315  }
316  DevUpdate();
317  return;
318 }
#define eq(a, b)
Definition: misc.h:29
GRAPH * gr_init()
void gr_point()
char * pl_title
Definition: ftedata.h:62
int db_graphid
Definition: ftedebug.h:26
#define YFACTOR
Definition: iplot.c:17
Definition: ftedata.h:49
double ymin
Definition: ftegraph.h:58
double * ylims
Definition: plotdefs.h:30
static double e
Definition: vectors.c:17
int iplot_begin()
#define XFACTOR
Definition: iplot.c:16
struct graph::@3 datawindow
complex * v_compdata
Definition: ftedata.h:29
struct dvlist * dl_next
Definition: ftedata.h:51
FILE * cp_err
Definition: help.c:101
static char start[32]
Definition: subckt.c:76
int iplot_point()
Definition: newgraf.c:602
struct dvec * pl_scale
Definition: ftedata.h:68
#define NULL
Definition: spdefs.h:121
int graphid
Definition: ftegraph.h:30
GRDATA plotdata
Definition: ftegraph.h:33
Definition: ftegraph.h:29
char * db_nodename2
Definition: ftedebug.h:24
#define isreal(v)
Definition: ftedata.h:54
Definition: ftedata.h:24
struct dvec * dl_dvec
Definition: ftedata.h:50
double * xlims
Definition: plotdefs.h:29
char * v_name
Definition: ftedata.h:25
void DevUpdate()
Definition: display.c:359
int db_iteration
Definition: ftedebug.h:25
int v_type
Definition: ftedata.h:26
double pl_start
Definition: ftedata.h:76
bool ft_grdb
Definition: options.c:28
static struct dvlist * get_dvecs()
GRAPH * currentgraph
Definition: graphdb.c:21
#define IPOINTMIN
Definition: ftedefs.h:17
void(* redraw)()
Definition: ftegraph.h:70
double * ft_minmax()
double xmax
Definition: ftegraph.h:58
int v_length
Definition: ftedata.h:34
double pl_stop
Definition: ftedata.h:77
double * v_realdata
Definition: ftedata.h:28
double ymax
Definition: ftegraph.h:58
double xmin
Definition: ftegraph.h:58
#define realpart(cval)
Definition: cpstd.h:35

Variable Documentation

struct dbcomm* dbiplot

Definition at line 186 of file main.c.

GRAPH* EchoGraph

Definition at line 53 of file newgraf.c.