📄 doplot.c
字号:
if (getflag(wl, "smith")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_SMITH; gfound = true; } } if (getflag(wl, "smithgrid")) { if (gfound) fprintf(cp_err, "Warning: too many grid types given\n"); else { gtype = GRID_SMITHGRID; 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, "smithgrid")) gtype = GRID_SMITHGRID; 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; } free_pnode(names); 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) { if (lv) lv->v_link2 = vec_mkfamily(d); else vecs = lv = 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) { if (d->v_plot->pl_scale) d->v_scale = d->v_plot->pl_scale; else d->v_scale = d; } /* See if the log flag is set anywhere... */ if (!gfound) { for (d = vecs; d; d = d->v_link2) if (d->v_scale && (d->v_scale->v_gridtype == GRID_XLOG)) gtype = GRID_XLOG; for (d = vecs; d; d = d->v_link2) if (d->v_gridtype == GRID_YLOG) { if ((gtype == GRID_XLOG) || (gtype == GRID_LOGLOG)) gtype = GRID_LOGLOG; else gtype = GRID_YLOG; } for (d = vecs; d; d = d->v_link2) if (d->v_gridtype == GRID_SMITH || d->v_gridtype == GRID_SMITHGRID || d->v_gridtype == GRID_POLAR) { gtype = d->v_gridtype; break; } } /* See if there are any default plot types... Here, like above, we * don't do entirely the best thing when there is a mixed set of * default plot types... */ if (!sameflag && !pfound) { ptype = PLOT_LIN; for (d = vecs; d; d = d->v_link2) if (d->v_plottype != PLOT_LIN) { ptype = d->v_plottype; break; } } /* Check and see if this is pole zero stuff. */ if ((vecs->v_type == SV_POLE) || (vecs->v_type == SV_ZERO)) oneval = true; for (d = vecs; d; d = d->v_link2) if (((d->v_type == SV_POLE) || (d->v_type == SV_ZERO)) != oneval ? 1 : 0) { fprintf(cp_err,"Error: plot must be either all pole-zero or contain no poles or zeros\n"); return (false); } if ((gtype == GRID_POLAR) || (gtype == GRID_SMITH || gtype == GRID_SMITHGRID)) { oneval = true; } /* If we are plotting scalars, make sure there is enough * data to fit on the screen. */ for (d = vecs; d; d = d->v_link2) if (d->v_length == 1) xtend(d, d->v_scale->v_length); /* Now patch up each vector with the compression and the index * selection. */ if (xcompress || xindices) { for (d = vecs; d; d = d->v_link2) { compress(d, xcompress, xindices); d->v_scale = vec_copy(d->v_scale); compress(d->v_scale, xcompress, xindices); } } /* Transform for smith plots */ if (gtype == GRID_SMITH) { double re, im, rex, imx; double r, i, x; struct dvec **prevvp, *n; int j; prevvp = &vecs; for (d = vecs; d; d = d->v_link2) { if (d->v_flags & VF_PERMANENT) { n = vec_copy(d); n->v_flags &= ~VF_PERMANENT; n->v_link2 = d->v_link2; d = n; *prevvp = d; } prevvp = &d->v_link2; if (isreal(d)) { fprintf(cp_err, "Warning: plotting real data \"%s\" on a smith grid\n", d->v_name); for (j = 0; j < d->v_length; j++) { r = d->v_realdata[j]; d->v_realdata[j] = (r - 1) / (r + 1); } } else { for (j = 0; j < d->v_length; j++) { /* (re - 1, im) / (re + 1, im) */ re = realpart(d->v_compdata + j); im = imagpart(d->v_compdata + j); rex = re + 1; imx = im; re = re - 1; /* (re, im) / (rex, imx) */ x = 1 - (imx / rex) * (imx / rex); r = re / rex + im / rex * imx / rex; i = im / rex - re / rex * imx / rex; realpart(d->v_compdata + j) = r / x; imagpart(d->v_compdata + j) = i / x; } } } } /* Figure out the proper x- and y-axis limits. */ if (ylim) {#ifdef notdef if (gtype == GRID_SMITH) { if (xlim) { SMITH_tfm(xlim[0], ylim[0], &dummy, &ylims[0]); SMITH_tfm(xlim[1], ylim[1], &dummy, &ylims[1]); } else { SMITH_tfm(0.0, ylim[0], &dummy, &ylims[0]); SMITH_tfm(0.0, ylim[1], &dummy, &ylims[1]); } } else { }#endif ylims[0] = ylim[0]; ylims[1] = ylim[1]; } else if (oneval) { ylims[0] = HUGE; ylims[1] = - ylims[0]; for (d = vecs; d; d = d->v_link2) {#ifdef notdef if (gtype == GRID_SMITH) { dd = ft_SMITHminmax(d, true); if( dd[0] < 0.0 ) dd[0] *= 1.1; else dd[0] *= 0.9; if( dd[1] >= 0.0 ) dd[1] *= 1.1; else dd[1] *= 0.9; } else#endif dd = ft_minmax(d, true); if (dd[0] < ylims[0]) ylims[0] = dd[0]; if (dd[1] > ylims[1]) ylims[1] = dd[1]; } } else { ylims[0] = HUGE; ylims[1] = - ylims[0]; for (d = vecs; d; d = d->v_link2) { dd = ft_minmax(d, true); if (dd[0] < ylims[0]) ylims[0] = dd[0]; if (dd[1] > ylims[1]) ylims[1] = dd[1]; } /* XXX */ for (d = vecs; d; d = d->v_link2) { if (d->v_flags & VF_MINGIVEN) if (ylims[0] < d->v_minsignal) ylims[0] = d->v_minsignal; if (d->v_flags & VF_MAXGIVEN) if (ylims[1] > d->v_maxsignal) ylims[1] = d->v_maxsignal; } } if (xlim) {#ifdef notdef if (gtype == GRID_SMITH) { if (ylim) { SMITH_tfm(xlim[0], ylim[0], &xlims[0], &dummy); SMITH_tfm(xlim[1], ylim[1], &xlims[1], &dummy); } else { SMITH_tfm(xlim[0], 0.0, &xlims[0], &dummy); SMITH_tfm(xlim[1], 0.0, &xlims[1], &dummy); } } else { }#endif xlims[0] = xlim[0]; xlims[1] = xlim[1]; } else if (oneval) { xlims[0] = HUGE; xlims[1] = - xlims[0]; for (d = vecs; d; d = d->v_link2) {#ifdef notdef if (gtype == GRID_SMITH) { dd = ft_SMITHminmax(d, false); if( dd[0] < 0.0 ) dd[0] *= 1.1; else dd[0] *= 0.9; if( dd[1] >= 0.0 ) dd[1] *= 1.1; else dd[1] *= 0.9; } else#endif dd = ft_minmax(d, false); if (dd[0] < xlims[0]) xlims[0] = dd[0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -