📄 doplot.c
字号:
/**********Copyright 1990 Regents of the University of California. All rights reserved.Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group**********//* * Plotting routines */#include "spice.h"#include "fteinput.h"#include "ftedbgra.h"#include "cpdefs.h"#include "fteconst.h"#include "ftedefs.h"#include "ftedev.h"#include "ftedata.h"#include "fteparse.h"#include "fteext.h"#include "suffix.h"static char *getword();static bool getflag();static double *getlims();static void compress();static void xtend();static bool plotit();extern double *ft_SMITHminmax( );extern void ft_xgraph();static bool sameflag;#ifdef HAS_MFBchar *MFBHardcopy = (char *) NULL; /* hack for MFB hardcopy */#endif /* HAS_MFB *//* asciiplot file name ... [xlimit] xhi xlo] [vs xname] */voidcom_asciiplot(wl) wordlist *wl;{ (void) plotit(wl, (char *) NULL, "lpr"); return;}/* xgraph file plotargs */voidcom_xgraph(wl) wordlist *wl;{ char *fname; char buf[BSIZE_SP]; bool tempf = false; char *devtype;#ifdef HAS_SYSTEM if (wl) { fname = wl->wl_word; wl = wl->wl_next; } if (!wl) { return; } if (cieq(fname, "temp") || cieq(fname, "tmp")) { fname = smktemp("xg"); tempf = true; } (void) plotit(wl, fname, "xgraph");#ifdef HAS_UNLINK/* Leave temp file sitting around so xgraph can grab it from background. if (tempf) (void) unlink(fname);*/#endif#else /* NOT HAS_SYSTEM */ fprintf(cp_err, "Sorry: xgraph not available.\n");#endif return;}/* hardcopy file plotargs, or 'hardcopy file' -- with no other args this * prompts the user for a window to dump to a plot file. XXX no it doesn't. */voidcom_hardcopy(wl) wordlist *wl;{ char *buf2, *prompt( ); wordlist *process( ); char *fname; char buf[BSIZE_SP], device[BSIZE_SP]; bool tempf = false; char *devtype; char format[513]; int printed; int hc_button; int foundit; if (!cp_getvar("hcopydev", VT_STRING, device)) *device = '\0'; if (wl) { hc_button = 0; fname = wl->wl_word; wl = wl->wl_next; } else { hc_button = 1; fname = smktemp("hc"); tempf = true; } if (!cp_getvar("hcopydevtype", VT_STRING, buf)) { devtype = "plot5"; } else { devtype = buf; }/* enable screen plot selection for these display types */ foundit = 0;#ifdef HAS_X_ if (!wl && hc_button) { REQUEST request; RESPONSE response; GRAPH *tempgraph; request.option = click_option; Input(&request, &response); if (response.option == error_option) return; if (response.reply.graph) { if (DevSwitch(devtype)) return; tempgraph = CopyGraph(response.reply.graph); tempgraph->devdep = fname; if (NewViewport(tempgraph)) { DevSwitch(NULL); return; } gr_resize(tempgraph); gr_redraw(tempgraph); DestroyGraph(tempgraph->graphid); DevSwitch(NULL); foundit = 1; } }#endif if (!foundit) { if (!wl) { outmenuprompt("which variable ? "); if ((buf2 = prompt(cp_in)) == (char *) -1) /* XXXX Sick */ return; wl = alloc(struct wordlist); wl->wl_word = buf2; wl->wl_next = NULL; wl = process(wl); }#ifdef HAS_MFB MFBHardcopy = fname;#endif /* HAS_MFB */ if (DevSwitch(devtype)) return; if (!wl || !plotit(wl, fname, (char *) NULL)) { printf("com_hardcopy: graph not defined\n"); DevSwitch(NULL); /* remember to switch back */ return; } DevSwitch(NULL); } printed = 0;#ifdef HAS_SYSTEM if (*device) {#ifdef SYSTEM_PLOT5LPR if (!strcmp(devtype, "plot5") || !strcmp(devtype, "MFB")) { if (!cp_getvar("lprplot5", VT_STRING, format)) strcpy(format, SYSTEM_PLOT5LPR); (void) sprintf(buf, format, device, fname); fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); (void) system(buf); printed = 1; }#endif#ifdef SYSTEM_PSLPR if (!printed && !strcmp(devtype, "postscript")) { /* note: check if that was a postscript printer XXX */ if (!cp_getvar("lprps", VT_STRING, format)) strcpy(format, SYSTEM_PSLPR); (void) sprintf(buf, format, device, fname); fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); (void) system(buf); printed = 1; }#endif }#endif if (!printed) { if (!strcmp(devtype, "plot5")) { fprintf(cp_out, "The file \"%s\" may be printed with the Unix \"plot\" command,\n", fname); fprintf(cp_out, "\tor by using the '-g' flag to the Unix lpr command.\n"); } else if (!strcmp(devtype, "postscript")) { fprintf(cp_out, "The file \"%s\" may be printed on a postscript printer.\n", fname); } else if (!strcmp(devtype, "MFB")) { fprintf(cp_out, "The file \"%s\" may be printed on a MFB device.\n", fname); } }#ifdef HAS_UNLINK 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 wordlist *wl_root;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_SP], buf[BSIZE_SP], *pname; int newlen; struct dvec *v, *newv_scale; double *newdata, *newscale; double tstep, tstart, tstop, ttime; double dummy; if (!wl) return false; wl_root = wl; /* 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(struct 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, "linear")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_LIN; 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; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -