⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postcoms.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********Copyright 1990 Regents of the University of California.  All rights reserved.Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group **********//* * Various post-processor commands having to do with vectors. */#include <ngspice.h>#include <cpdefs.h>#include <ftedefs.h>#include <dvec.h>#include <sim.h>#include <plot.h>#include "completion.h"#include "postcoms.h"#include "quote.h"#include "variable.h"#include "parser/complete.h" /* va: throwaway *//* static declarations */static void killplot(struct plot *pl);/* Undefine vectors. */voidcom_unlet(wordlist *wl){    while (wl) {        vec_remove(wl->wl_word);        wl = wl->wl_next;    }    return;}/* Load in a file. */voidcom_load(wordlist *wl){char *copypath;    if (!wl)        ft_loadfile(ft_rawfile);    else        while (wl) {            /*ft_loadfile(cp_unquote(wl->wl_word)); DG: bad memory leak*/            copypath=cp_unquote(wl->wl_word);/*DG*/            ft_loadfile(copypath);            tfree(copypath);            wl = wl->wl_next;        }    /* note: default is to display the vectors in the last (current) plot */    com_display(NULL);    return;}/* Print out the value of an expression. When we are figuring out what to * print, link the vectors we want with v_link2... This has to be done * because of the way temporary vectors are linked together with permanent * ones under the plot. */voidcom_print(wordlist *wl){    struct dvec *v, *lv = NULL, *bv, *nv, *vecs = NULL;    int i, j, ll, width = DEF_WIDTH, height = DEF_HEIGHT, npoints, lineno;    struct pnode *nn;    struct plot *p;    bool col = TRUE, nobreak = FALSE, noprintscale, plotnames = FALSE;    bool optgiven = FALSE;    char *s, buf[BSIZE_SP], buf2[BSIZE_SP];    char numbuf[BSIZE_SP], numbuf2[BSIZE_SP]; /* Printnum buffers */    int ngood;    if (wl == NULL)        return;            if (eq(wl->wl_word, "col")) {        col = TRUE;        optgiven = TRUE;        wl = wl->wl_next;    } else if (eq(wl->wl_word, "line")) {        col = FALSE;        optgiven = TRUE;        wl = wl->wl_next;    }    ngood = 0;    for (nn = ft_getpnames(wl, TRUE); nn; nn = nn->pn_next) {        if (!(v = ft_evaluate(nn)))	    continue;	if (!vecs)	    vecs = lv = v;	else	    lv->v_link2 = v;	for (lv = v; lv->v_link2; lv = lv->v_link2)	    ;	ngood += 1;    }    if (!ngood)	return;    /* See whether we really have to print plot names. */    for (v = vecs; v; v = v->v_link2)        if (vecs->v_plot != v->v_plot) {            plotnames = TRUE;            break;        }        if (!optgiven) {        /* Figure out whether col or line should be used... */        col = FALSE;        for (v = vecs; v; v = v->v_link2)            if (v->v_length > 1) {                col = TRUE;                break;            }    }    out_init();    if (!col) {        for (v = vecs; v; v = v->v_link2) {            if (plotnames) {                (void) sprintf(buf, "%s.%s", v->v_plot->pl_typename,                        vec_basename(v));            } else {                (void) strcpy(buf, vec_basename(v));            }            for (s = buf; *s; s++)                ;            s--;            while (isspace(*s)) {                *s = '\0';                s--;            }            ll = 10;            if (v->v_length == 1) {                if (isreal(v)) {                	printnum(numbuf, *v->v_realdata);                    out_printf("%s = %s\n", buf, numbuf);                } else {                 /*DG: memory leak here copy of the string returned by printnum will never be freed                     out_printf("%s = %s,%s\n", buf,                        copy(printnum(realpart(v->v_compdata))),                        copy(printnum(imagpart(v->v_compdata)))); */                                            printnum(numbuf,  realpart(v->v_compdata));                    printnum(numbuf2, imagpart(v->v_compdata));                                        out_printf("%s = %s,%s\n", buf,                        numbuf,                        numbuf2);                                   }            } else {                out_printf("%s = (  ", buf);                for (i = 0; i < v->v_length; i++)                    if (isreal(v)) {                    	                    	printnum(numbuf, v->v_realdata[i]);                        (void) strcpy(buf, numbuf);                        out_send(buf);                        ll += strlen(buf);                        ll = (ll + 7) / 8;                        ll = ll * 8 + 1;                        if (ll > 60) {                            out_send("\n\t");                            ll = 9;                        } else                            out_send("\t");                    } else {                        /*DG*/                        printnum(numbuf,  realpart(&v->v_compdata[i]));                        printnum(numbuf2, imagpart(&v->v_compdata[i]));                        (void) sprintf(buf, "%s,%s",                            numbuf,                            numbuf2);                        out_send(buf);                        ll += strlen(buf);                        ll = (ll + 7) / 8;                        ll = ll * 8 + 1;                        if (ll > 60) {                            out_send("\n\t");                            ll = 9;                        } else                            out_send("\t");                    }                out_send(")\n");            }        }    } else {    /* Print in columns. */        if (cp_getvar("width", VT_NUM, (char *) &i))            width = i;        if (width < 40)            width = 40;        if (cp_getvar("height", VT_NUM, (char *) &i))            height = i;        if (height < 20)            height = 20;        if (!cp_getvar("nobreak", VT_BOOL, (char *) &nobreak) && !ft_nopage)            nobreak = FALSE;	else	    nobreak = TRUE;        (void) cp_getvar("noprintscale", VT_BOOL, (char *)                 &noprintscale);        bv = vecs;nextpage:        /* Make the first vector of every page be the scale... */	/* XXX But what if there is no scale?  e.g. op, pz */        if (!noprintscale && bv->v_plot->pl_ndims) {            if (bv->v_plot->pl_scale && !vec_eq(bv, bv->v_plot->pl_scale)) {                nv = vec_copy(bv->v_plot->pl_scale);                vec_new(nv);                nv->v_link2 = bv;                bv = nv;            }        }        ll = 8;        for (lv = bv; lv; lv = lv->v_link2) {            if (isreal(lv))                ll += 16;   /* Two tabs for real, */            else                ll += 32;   /* 4 for complex. */            /* Make sure we have at least 2 vectors per page... */            if ((ll > width) && (lv != bv) && (lv != bv->v_link2))                break;        }        /* Print the header on the first page only. */        p = bv->v_plot;        j = (width - (int) strlen(p->pl_title)) / 2;	/* Yes, keep "(int)" */	if (j < 0)		j = 0;        for (i = 0; i < j; i++)            buf2[i] = ' ';        buf2[j] = '\0';        out_send(buf2);        out_send(p->pl_title);        out_send("\n");        out_send(buf2);        (void) sprintf(buf, "%s  %s", p->pl_name, p->pl_date);        j = (width - strlen(buf)) / 2;        out_send(buf);        out_send("\n");        for (i = 0; i < width; i++)            buf2[i] = '-';        buf2[width] = '\n';        buf2[width+1] = '\0';        out_send(buf2);        (void) sprintf(buf, "Index   ");        for (v = bv; v && (v != lv); v = v->v_link2) {            if (isreal(v))                (void) sprintf(buf2, "%-16.15s", v->v_name);            else                (void) sprintf(buf2, "%-32.31s", v->v_name);            (void) strcat(buf, buf2);           }        lineno = 3;        j = 0;        npoints = 0;        for (v = bv; (v && (v != lv)); v = v->v_link2)            if (v->v_length > npoints)                npoints = v->v_length;pbreak:     /* New page. */        out_send(buf);        out_send("\n");        for (i = 0; i < width; i++)            buf2[i] = '-';        buf2[width] = '\n';        buf2[width+1] = '\0';        out_send(buf2);        lineno += 2;loop:        while ((j < npoints) && (lineno < height)) {/*            out_printf("%d\t", j); */	    sprintf(out_pbuf, "%d\t", j);	    out_send(out_pbuf);            for (v = bv; (v && (v != lv)); v = v->v_link2) {                if (v->v_length <= j) {                    if (isreal(v))                        out_send("\t\t");                    else                        out_send("\t\t\t\t");                } else {                    if (isreal(v)) {                        sprintf(out_pbuf, "%e\t",                         	v->v_realdata[j]);			out_send(out_pbuf);                    } else {                        sprintf(out_pbuf, "%e,\t%e\t",                        	realpart(&v->v_compdata[j]),                        	imagpart(&v->v_compdata[j]));			out_send(out_pbuf);		    }                }            }            out_send("\n");            j++;            lineno++;        }        if ((j == npoints) && (lv == NULL)) /* No more to print. */            goto done;        if (j == npoints) { /* More vectors to print. */            bv = lv;            out_send("\f\n");   /* Form feed. */            goto nextpage;        }        /* Otherwise go to a new page. */        lineno = 0;        if (nobreak)            goto loop;        else            out_send("\f\n");   /* Form feed. */        goto pbreak;    }done:    /* Get rid of the vectors. */    return;}/* Write out some data. write filename expr ... Some cleverness here is * required.  If the user mentions a few vectors from various plots, * probably he means for them to be written out seperate plots.  In any * case, we have to be sure to write out the scales for everything we * write... */voidcom_write(wordlist *wl){    char *file, buf[BSIZE_SP];    struct pnode *n;    struct dvec *d, *vecs = NULL, *lv = NULL, *end, *vv;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -