📄 doplot.c
字号:
/* RCS Info: $Revision: 1.1 $ on $Date: 91/04/02 12:11:30 $ * $Source: //pepper/atesse_spice/spice3/FTE/RCS/doplot.c,v $ * Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group * * Plotting routines */#include "prefix.h"#include "FTEinput.h"#ifndef CMS#include "FTEdbgraph.h"#else /* CMS */#include "FTEdbgra.h"#endif /* CMS */#include "CPdefs.h"#ifndef CMS#include "FTEconstant.h"#else /* CMS */#include "FTEconst.h"#endif /* CMS */#include "FTEdefs.h"#include "FTEdata.h"#include "FTEparse.h"#ifndef CMS#include "FTEredirect.h"#else /* CMS */#include "FTEredir.h"#endif /* CMS */#include "suffix.h"static char *getword();static bool getflag();static double *getlims();static void compress();static void extend();static bool plotit();static bool sameflag;/* asciiplot file name ... [xlimit] xhi xlo] [vs xname] */voidcom_asciiplot(wl) wordlist *wl;{ (void) plotit(wl, (char *) NULL, "lpr"); return;}/* hardcopy file plotargs, or 'hardcopy file' -- with no other args this * prompts the user for a window to dump to a plot file. */voidcom_hardcopy(wl) wordlist *wl;{ char *fname; char buf[BSIZE], device[BSIZE]; bool tempf = false; char *devtype;#ifdef UNIX if (!cp_getvar("hcopydev", VT_STRING, device))#endif *device = '\0'; if (wl) { fname = wl->wl_word; wl = wl->wl_next; } else { fname = mktemp(copy("/tmp/hcXXXXXX")); tempf = true; } if (!cp_getvar("hcopydevtype", VT_STRING, buf)) { devtype = "plot5"; } else { devtype = buf; }/* enable screen plot selection for these display types */#if defined(GI_X) || defined(GI_X11) if (!wl) { REQUEST request; RESPONSE response; GRAPH *tempgraph; request.option = click_option; Input(&request, &response); if (response.option == error_option) return; if (DevSwitch(devtype)) return; tempgraph = CopyGraph(response.reply.graph); tempgraph->devdep = fname; if (NewViewport(tempgraph)) { DevSwitch(NULL); return; } gr_redraw(tempgraph); DestroyGraph(tempgraph->graphid); DevSwitch(NULL); } else {#endif if (DevSwitch(devtype)) return; if (!plotit(wl, fname, (char *) NULL)) { DevSwitch(NULL); /* remember to switch back */ return; } DevSwitch(NULL);#if defined(GI_X) || defined(GI_X11) }#endif if (*device) {#ifdef UNIX fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); if (!strcmp(devtype, "plot5")) { (void) sprintf(buf, "lpr -P%s -g %s", device, fname); (void) system(buf); } else { /* note: check if that was a postscript printer XXX */ (void) sprintf(buf, "lpr -P%s %s", device, fname); (void) system(buf); }#endif } else { if (!strcmp(devtype, "plot5")) { fprintf(cp_out, "You can print the image in %s with the plot(1) ", fname); fprintf(cp_out, "command,\n\tor the -g flag to lpr.\n"); } else { fprintf(cp_out, "You can print the image in %s with the lpr command to a \postscript printer.\n", fname); } }#ifdef UNIX if (tempf && *device) (void) unlink(fname);#endif return;}/* plot name ... [xl[imit]] xlo xhi] [yl[imit ylo yhi] [vs xname] */voidcom_plot(wl) wordlist *wl;{ (void) plotit(wl, (char *) NULL, (char *) NULL); return;}/* The common routine for all plotting commands. This does hardcopy * and graphics plotting. */static boolplotit(wl, hcopy, devname) wordlist *wl; char *hcopy, *devname;{ /* All these things are static so that "samep" will work. */ static double *xcompress = NULL, *xindices = NULL; static double *xlim = NULL, *ylim = NULL; static double *xdelta = NULL, *ydelta = NULL; static char *xlabel = NULL, *ylabel = NULL, *title = NULL; static bool nointerp = false; static GRIDTYPE gtype = GRID_LIN; static PLOTTYPE ptype = PLOT_LIN; bool gfound = false, pfound = false, oneval = false; double *dd, ylims[2], xlims[2]; struct pnode *n, *names; struct dvec *dv, *d = NULL, *vecs = NULL, *lv, *lastvs = NULL; char *xn; int i, j, xt; double tt, mx, my, rad; wordlist *wwl, *tw; char cline[BSIZE], buf[BSIZE], *pname; int newlen; struct dvec *v, *newv_scale; double *newdata, *newscale; double tstep, tstart, tstop, ttime; /* First get the command line, without the limits. */ wwl = wl_copy(wl); (void) getlims(wwl, "xl", 2); (void) getlims(wwl, "xlimit", 2); (void) getlims(wwl, "yl", 2); (void) getlims(wwl, "ylimit", 2); (void) sprintf(cline, "plot %s", wl_flatten(wwl)); wl_free(wwl); /* Now extract all the parameters. */ /* In case the parameter is the first on the line, we need a * "buffer" word... */ tw = alloc(wordlist); wl->wl_prev = tw; tw->wl_next = wl; wl = tw; tw->wl_word = ""; sameflag = getflag(wl, "samep"); if (!sameflag || !xlim) { xlim = getlims(wl, "xl", 2); if (!xlim) xlim = getlims(wl, "xlimit", 2); } else { (void) getlims(wl, "xl", 2); (void) getlims(wl, "xlimit", 2); } if (!sameflag || !ylim) { ylim = getlims(wl, "yl", 2); if (!ylim) ylim = getlims(wl, "ylimit", 2); } else { (void) getlims(wl, "yl", 2); (void) getlims(wl, "ylimit", 2); } if (!sameflag || !xcompress) { xcompress = getlims(wl, "xcompress", 1); if (!xcompress) xcompress = getlims(wl, "xcomp", 1); } else { (void) getlims(wl, "xcompress", 1); (void) getlims(wl, "xcomp", 1); } if (!sameflag || !xindices) { xindices = getlims(wl, "xindices", 2); if (!xindices) xindices = getlims(wl, "xind", 2); } else { (void) getlims(wl, "xindices", 2); (void) getlims(wl, "xind", 2); } if (!sameflag || !xdelta) { xdelta = getlims(wl, "xdelta", 1); if (!xdelta) xdelta = getlims(wl, "xdel", 1); } else { (void) getlims(wl, "xdelta", 1); (void) getlims(wl, "xdel", 1); } if (!sameflag || !ydelta) { ydelta = getlims(wl, "ydelta", 1); if (!ydelta) ydelta = getlims(wl, "ydel", 1); } else { (void) getlims(wl, "ydelta", 1); (void) getlims(wl, "ydel", 1); } /* Get the grid type and the point type. Note we can't do if-else * here because we want to catch all the grid types. */ if (getflag(wl, "lingrid")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_LIN; gfound = true; } } if (getflag(wl, "loglog")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_LOGLOG; gfound = true; } } if (getflag(wl, "nogrid")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_NONE; gfound = true; } } if (getflag(wl, "xlog")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_XLOG; gfound = true; } } if (getflag(wl, "ylog")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_YLOG; gfound = true; } } if (getflag(wl, "polar")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_POLAR; gfound = true; } } if (getflag(wl, "smith")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_SMITH; gfound = true; } } if (!sameflag && !gfound) { if (cp_getvar("gridstyle", VT_STRING, buf)) { if (eq(buf, "lingrid")) gtype = GRID_LIN; else if (eq(buf, "loglog")) gtype = GRID_LOGLOG; else if (eq(buf, "xlog")) gtype = GRID_XLOG; else if (eq(buf, "ylog")) gtype = GRID_YLOG; else if (eq(buf, "smith")) gtype = GRID_SMITH; else if (eq(buf, "polar")) gtype = GRID_POLAR; else if (eq(buf, "nogrid")) gtype = GRID_NONE; else { fprintf(cp_err, "Warning: strange grid type %s\n", buf); gtype = GRID_LIN; } gfound = true; } else gtype = GRID_LIN; } /* Now get the point type. */ if (getflag(wl, "linplot")) { if (pfound) fprintf(cp_err, "Warning: too many plot types given\n"); else { ptype = PLOT_LIN; pfound = true; } } if (getflag(wl, "combplot")) { if (pfound) fprintf(cp_err, "Warning: too many plot types given\n"); else { ptype = PLOT_COMB; pfound = true; } } if (getflag(wl, "pointplot")) { if (pfound) fprintf(cp_err, "Warning: too many plot types given\n"); else { ptype = PLOT_POINT; pfound = true; } } if (!sameflag && !pfound) { if (cp_getvar("plotstyle", VT_STRING, buf)) { if (eq(buf, "linplot")) ptype = PLOT_LIN; else if (eq(buf, "combplot")) ptype = PLOT_COMB; else if (eq(buf, "pointplot")) ptype = PLOT_POINT; else { fprintf(cp_err, "Warning: strange plot type %s\n", buf); ptype = PLOT_LIN; } pfound = true; } else ptype = PLOT_LIN; } if (!sameflag || !xlabel) xlabel = getword(wl, "xlabel"); else (void) getword(wl, "xlabel"); if (!sameflag || !ylabel) ylabel = getword(wl, "ylabel"); else (void) getword(wl, "ylabel"); if (!sameflag || !title) title = getword(wl, "title"); else (void) getword(wl, "title"); if (!sameflag) nointerp = getflag(wl, "nointerp"); else if (getflag(wl, "nointerp")) nointerp = true; wl = wl->wl_next; if (!wl) { fprintf(cp_err, "Error: no vectors given\n"); return (false); } wl->wl_prev = NULL; /* Now parse the vectors. We have a list of the form * "a b vs c d e vs f g h". Since it's a bit of a hassle for * us to parse the vector boundaries here, we do this -- call * ft_getpnames() without the check flag, and then look for 0-length * vectors with the name "vs"... This is a sort of a gross hack, * since we have to check for 0-length vectors ourselves after * evaulating the pnodes... */ names = ft_getpnames(wl, false); if (names == NULL) return (false); /* Now evaluate the names. */ for (n = names, lv = NULL; n; n = n->pn_next) { if (n->pn_value && (n->pn_value->v_length == 0) && eq(n->pn_value->v_name, "vs")) { if (!lv) { fprintf(cp_err, "Error: misplaced vs arg\n"); return (false); } else { if (!(n = n->pn_next)) { fprintf(cp_err, "Error: missing vs arg\n"); return (false); } dv = ft_evaluate(n); if (!dv) return (false); if (lastvs) lv = lastvs->v_link2; else lv = vecs; while (lv) { lv->v_scale = dv; lastvs = lv; lv = lv->v_link2; } } continue; } dv = ft_evaluate(n); if (!dv) return (false); if (!d) vecs = dv; else d->v_link2 = dv; for (d = dv; d->v_link2; d = d->v_link2) ; lv = dv; } d->v_link2 = NULL; /* Now check for 0-length vectors. */ for (d = vecs; d; d = d->v_link2) if (!d->v_length) { fprintf(cp_err, "Error: %s: no such vector\n", d->v_name); return (false); } /* If there are higher dimensional vectors, transform them into a * family of vectors. */ for (d = vecs, lv = NULL; d; d = d->v_link2) { if (d->v_numdims > 1) { lv->v_link2 = vec_mkfamily(d); while (lv->v_link2) lv = lv->v_link2; lv->v_link2 = d->v_link2; d = lv; } else lv = d; } /* Now fill in the scales for vectors who aren't already fixed up. */ for (d = vecs; d; d = d->v_link2) if (!d->v_scale) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -