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

📄 postcoms.c

📁 支持数字元件仿真的SPICE插件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* RCS Info: $Revision: 1.1 $ on $Date: 91/04/02 12:12:11 $ *           $Source: //pepper/atesse_spice/spice3/FTE/RCS/postcoms.c,v $ * Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group * * Various post-processor commands having to do with vectors. */#include "prefix.h"#include "CPdefs.h"#include "FTEdefs.h"#include "FTEparse.h"#include "FTEdata.h"#ifndef CMS#include "FTEredirect.h"#else  /* CMS */#include "FTEredir.h"#endif /* CMS */#include "suffix.h"static int dcomp();static void pvec();voidcom_let(wl)    wordlist *wl;{    struct dvec *t, *n;    char *vname, *s;    struct pnode *nn;    int dims[MAXDIMS], dimsgiven = 0;    if (!wl) {        com_display((wordlist *) NULL);        return;    }    vname = cp_unquote(wl->wl_word);    if (s = index(vname, '=')) {        *s = '\0';        if (*++s) {            wl->wl_word = copy(s);        } else            wl = wl->wl_next;    } else {        wl = wl->wl_next;        if (!wl || (*wl->wl_word != '=')) {            fprintf(cp_err, "Error: bad let syntax\n");            return;        }        if (wl->wl_word[1])            wl->wl_word = copy(&wl->wl_word[1]);        else            wl = wl->wl_next;    }    if (eq(vname, "all") || index(vname, '@')) {        fprintf(cp_err, "Error: bad variable name %s\n", vname);        return;    } else if (s = index(vname, '[')) {        *s++ = '\0';        while (isdigit(*s)) {            dims[dimsgiven++] = scannum(s);            while (isdigit(*s))                s++;            if ((*s != ']') || ((s[1] != '[') && s[1])) {                fprintf(cp_err, "Error: bad variable name %s\n",                        cp_unquote(wl->wl_word));                return;            }            s += 2;        }    }    nn = ft_getpnames(wl, true);    if (nn == NULL)        return;    t = ft_evaluate(nn);    if (!t)        return;    if (t->v_link2)        fprintf(cp_err, "Warning: extra wildcard values ignored\n");        if (dimsgiven) {        if (!(n = vec_get(vname))) {            fprintf(cp_err, "Error: no such vector %s\n", vname);            return;        }        /* Unfinished hacking... */    } else {        vec_remove(vname);        /* Note that we don't copy the assorted default junk... */        n = alloc(dvec);        n->v_type = t->v_type;        n->v_length = t->v_length;        n->v_scale = t->v_scale;        n->v_name = copy(vname);        n->v_flags = (t->v_flags | VF_PERMANENT);        if (isreal(t)) {            n->v_realdata = (double *) tmalloc(n->v_length *                    sizeof (double));            bcopy((char *) t->v_realdata, (char *) n->v_realdata,                    n->v_length * sizeof (double));        } else {            n->v_compdata = (complex *) tmalloc(n->v_length *                     sizeof (complex));            bcopy((char *) t->v_compdata, (char *) n->v_compdata,                    n->v_length * sizeof (complex));        }        vec_new(n);        cp_addkword(CT_VECTOR, n->v_name);    }    return;}/* Undefine vectors. */voidcom_unlet(wl)    wordlist *wl;{    while (wl) {        vec_remove(wl->wl_word);        wl = wl->wl_next;    }    return;}/* Load in a file. */voidcom_load(wl)    wordlist *wl;{    if (!wl)        ft_loadfile(ft_rawfile);    else        while (wl) {            ft_loadfile(cp_unquote(wl->wl_word));            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(wl)    wordlist *wl;{    struct dvec *v, *lv, *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], buf2[BSIZE];    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;    }    nn = ft_getpnames(wl, true);    if (nn == NULL)        return;    while (nn) {        if (!(v = ft_evaluate(nn)))            return;        if (!vecs)            vecs = lv = v;        else            lv->v_link2 = v;        for (lv = v; lv->v_link2; lv = lv->v_link2)            ;        nn = nn->pn_next;    }    /* 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)) {                    out_printf("%s = %s\n", buf,                        printnum(*v->v_realdata));                } else {                    out_printf("%s = %s,%s\n", buf,                        copy(printnum(realpart(v->v_compdata))),                        copy(printnum(imagpart(v->v_compdata))));                }            } else {                out_printf("%s = (  ", buf);                for (i = 0; i < v->v_length; i++)                    if (isreal(v)) {                        (void) strcpy(buf,                           printnum(v->v_realdata[i]));                        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 {                        (void) sprintf(buf, "%s,%s",                            copy(printnum(realpart(&v->v_compdata[i]))),                            copy(printnum(imagpart(&v->v_compdata[i]))));                        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... */        if (!noprintscale) {            if (!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 - strlen(p->pl_title)) / 2;        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(wl)       wordlist *wl;{    char *file, buf[BSIZE];    struct pnode *n;    struct dvec *d, *vecs = NULL, *lv = NULL, *end, *vv;    static wordlist all = { "all", NULL, NULL } ;    struct pnode *names;    bool oct=false;#ifdef ASCIIRAWFILE    bool ascii = ASCIIRAWFILE;#else    bool ascii = false;#endif    bool scalefound, appendwrite;    struct plot *tpl, newplot;    if (wl) {        file = wl->wl_word;        wl = wl->wl_next;    } else        file = ft_rawfile;    if (cp_getvar("filetype", VT_STRING, buf)) {        if (eq(buf, "binary"))            ascii = false;        else if(eq(buf,"oct"))             oct = true;        else if (!eq(buf, "ascii"))            fprintf(cp_err, "Warning: strange file type %s\n",                    buf);    }    (void) cp_getvar("appendwrite", VT_BOOL, (char *) &appendwrite);    if (wl)        names = ft_getpnames(wl, true);    else        names = ft_getpnames(&all, true);    if (names == NULL)        return;    for (n = names; n; n = n->pn_next) {        d = ft_evaluate(n);        if (!d)            return;        if (vecs)            lv->v_link2 = d;        else            vecs = d;        for (lv = d; lv->v_link2; lv = lv->v_link2)            ;    }    /* Now we have to write them out plot by plot. */    while (vecs) {        tpl = vecs->v_plot;        tpl->pl_written = true;        end = NULL;        bcopy((char *) tpl, (char *) &newplot, sizeof (struct plot));        scalefound = false;        /* Figure out how many vectors are in this plot... Also look         * for the scale, or a copy of it... Which may have a different         * name...         */        for (d = vecs; d; d = d->v_link2) {            if (d->v_plot == tpl) {                vv = vec_copy(d);                /* Note that since we are building a new plot                 * we don't want to vec_new this one...                 */                vv->v_name = vec_basename(vv);

⌨️ 快捷键说明

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