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

📄 postcoms.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 2 页
字号:
    static wordlist all = { "all", NULL, NULL } ;    struct pnode *names;    bool ascii = AsciiRawFile;    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, "ascii"))            ascii = TRUE;	else            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);                if (end)                    end->v_next = vv;                else                    end = newplot.pl_dvecs = vv;                end = vv;                if (vec_eq(d, tpl->pl_scale)) {                    newplot.pl_scale = vv;                    scalefound = TRUE;                }            }        }        end->v_next = NULL;        /* Maybe we shouldn't make sure that the default scale is         * present if nobody uses it.         */        if (!scalefound) {            newplot.pl_scale = vec_copy(tpl->pl_scale);            newplot.pl_scale->v_next = newplot.pl_dvecs;            newplot.pl_dvecs = newplot.pl_scale;        }        /* Now let's go through and make sure that everything that          * has its own scale has it in the plot.         */        for (;;) {            scalefound = FALSE;            for (d = newplot.pl_dvecs; d; d = d->v_next) {                if (d->v_scale) {                    for (vv = newplot.pl_dvecs; vv; vv =                            vv->v_next)                        if (vec_eq(vv, d->v_scale))                            break;                    /* We have to grab it... */                    vv = vec_copy(d->v_scale);                    vv->v_next = newplot.pl_dvecs;                    newplot.pl_dvecs = vv;                    scalefound = TRUE;                }            }            if (!scalefound)                break;            /* Otherwise loop through again... */        }        if (ascii)            raw_write(file, &newplot, appendwrite, FALSE);        else            raw_write(file, &newplot, appendwrite, TRUE);        /* Now throw out the vectors we have written already... */        for (d = vecs, lv = NULL;  d; d = d->v_link2)            if (d->v_plot == tpl) {                if (lv) {                    lv->v_link2 = d->v_link2;                    d = lv;                } else                    vecs = d->v_link2;            } else                lv = d;        /* If there are more plots we want them appended... */        appendwrite = TRUE;    }    return;}/* If the named vectors have more than 1 dimension, then consider * to be a collection of one or more matrices.  This command transposes * each named matrix. */voidcom_transpose(wordlist *wl){    struct dvec *d;    char *s;    while (wl) {        s = cp_unquote(wl->wl_word);        d = vec_get(s);        tfree(s); /*DG: Avoid Memory Leak */        if (d == NULL)            fprintf(cp_err, "Error: no such vector as %s.\n",                 wl->wl_word);        else            while (d) {                vec_transpose(d);                d = d->v_link2;            }        if (wl->wl_next == NULL)            return;        wl = wl->wl_next;    }}/* Take a set of vectors and form a new vector of the nth elements of each. */voidcom_cross(wordlist *wl){    char *newvec, *s;    struct dvec *n, *v, *vecs = NULL, *lv = NULL;    struct pnode *pn;    int i, ind;    bool comp = FALSE;    double *d;    newvec = wl->wl_word;    wl = wl->wl_next;    s = wl->wl_word;    if (!(d = ft_numparse(&s, FALSE))) {        fprintf(cp_err, "Error: bad number %s\n", wl->wl_word);        return;    }    if ((ind = *d) < 0) {        fprintf(cp_err, "Error: badstrchr %d\n", ind);        return;    }    wl = wl->wl_next;    pn = ft_getpnames(wl, TRUE);    while (pn) {        if (!(n = ft_evaluate(pn)))            return;        if (!vecs)            vecs = lv = n;        else            lv->v_link2 = n;        for (lv = n; lv->v_link2; lv = lv->v_link2)            ;        pn = pn->pn_next;    }    for (n = vecs, i = 0; n; n = n->v_link2) {        if (iscomplex(n))            comp = TRUE;        i++;    }        vec_remove(newvec);    v = alloc(struct dvec);    v->v_name = copy(newvec);    v->v_type = vecs ? vecs->v_type : SV_NOTYPE;    v->v_length = i;    v->v_flags |= VF_PERMANENT;    v->v_flags = comp ? VF_COMPLEX : VF_REAL;    if (comp)        v->v_compdata = (complex *) tmalloc(i * sizeof (complex));    else        v->v_realdata = (double *) tmalloc(i * sizeof (double));        /* Now copy the ind'ths elements into this one. */    for (n = vecs, i = 0; n; n = n->v_link2, i++)        if (n->v_length > ind) {            if (comp) {                realpart(&v->v_compdata[i]) =                        realpart(&n->v_compdata[ind]);                imagpart(&v->v_compdata[i]) =                        imagpart(&n->v_compdata[ind]);            } else                v->v_realdata[i] = n->v_realdata[ind];        } else {            if (comp) {                realpart(&v->v_compdata[i]) = 0.0;                imagpart(&v->v_compdata[i]) = 0.0;            } else                v->v_realdata[i] = 0.0;        }    vec_new(v);    v->v_flags |= VF_PERMANENT;    cp_addkword(CT_VECTOR, v->v_name);    return;}voidcom_destroy(wordlist *wl){    struct plot *pl, *npl = NULL;    if (!wl)        killplot(plot_cur);    else if (eq(wl->wl_word, "all")) {        for (pl = plot_list; pl; pl = npl) {            npl = pl->pl_next;            if (!eq(pl->pl_typename, "const"))                killplot(pl);        }    } else {        while (wl) {            for (pl = plot_list; pl; pl = pl->pl_next)                if (eq(pl->pl_typename, wl->wl_word))                    break;            if (pl)                killplot(pl);            else                fprintf(cp_err, "Error: no such plot %s\n",                        wl->wl_word);            wl = wl->wl_next;        }    }    return;}static voidkillplot(struct plot *pl){    struct dvec *v, *nv = NULL;    struct plot *op;    if (eq(pl->pl_typename, "const")) {        fprintf(cp_err, "Error: can't destroy the constant plot\n");        return;    }    /*  pl_dvecs, pl_scale */    for (v = pl->pl_dvecs; v; v = nv) {        nv = v->v_next;        vec_free(v);    }    /* unlink from plot_list (linked via pl_next) */    if (pl == plot_list) {        plot_list = pl->pl_next;        if (pl == plot_cur)            plot_cur = plot_list;    } else {        for (op = plot_list; op; op = op->pl_next)            if (op->pl_next == pl)                break;        if (!op)            fprintf(cp_err,                "Internal Error: kill plot -- not in list\n");        op->pl_next = pl->pl_next;        if (pl == plot_cur)            plot_cur = op;    }    tfree(pl->pl_title);    tfree(pl->pl_name);    tfree(pl->pl_typename);    wl_free(pl->pl_commands);    tfree(pl->pl_date); /* va: also tfree (memory leak) */    if (pl->pl_ccom)    /* va: also tfree (memory leak) */    {        throwaway((struct ccom *)pl->pl_ccom);    }    if (pl->pl_env) /* The 'environment' for this plot. */    {    	/* va: HOW to do? */        printf("va: killplot should tfree pl->pl_env=(%p)\n", pl->pl_env); fflush(stdout);    }    tfree(pl); /* va: also tfree pl itself (memory leak) */        return;}voidcom_splot(wordlist *wl){    struct plot *pl;    char buf[BSIZE_SP], *s, *t;    if (wl) {        plot_setcur(wl->wl_word);        return;    }    fprintf(cp_out, "\tType the name of the desired plot:\n\n");    fprintf(cp_out, "\tnew\tNew plot\n");    for (pl = plot_list; pl; pl = pl->pl_next)        fprintf(cp_out, "%s%s\t%s (%s)\n",                (pl == plot_cur) ? "Current " : "\t",                pl->pl_typename, pl->pl_title, pl->pl_name);        fprintf(cp_out, "? ");    if (!fgets(buf, BSIZE_SP, cp_in)) {        clearerr(cp_in);        return;    }    t = buf;    if (!(s = gettok(&t)))        return;    plot_setcur(s);    return;}

⌨️ 快捷键说明

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