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

📄 outitf.c

📁 spice中支持多层次元件模型仿真的可单独运行的插件源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    return (OK);}/* ARGSUSED */ /* until some code gets written */intOUTbeginDomain(plotPtr, refName, refType, outerRefValue)    GENERIC *plotPtr;    char *refName;    int refType;    IFvalue *outerRefValue;{    return (OK);}/* ARGSUSED */ /* until some code gets written */intOUTendDomain(plotPtr)    GENERIC *plotPtr;{    return (OK);}/* ARGSUSED */ /* until some code gets written */intOUTattributes(plotPtr, varName, param, value)    GENERIC *plotPtr;    char *varName;    int param;    IFvalue *value;{    runDesc *run = (runDesc *) plotPtr;    struct dvec *d;    struct dataDesc *dd;    int type;    int i;    if (param == OUT_SCALE_LIN)	type = GRID_LIN;    else if (param == OUT_SCALE_LOG)	type = GRID_XLOG;    else	return E_UNSUPP;    if (run->writeOut) {	if (varName) {	    for (i = 0; i < run->numData; i++)		if (!strcmp(varName, run->data[i].name))		    run->data[i].gtype = type;	} else {	    run->data[run->refIndex].gtype = type;	}    } else {	if (varName) {	    for (d = run->runPlot->pl_dvecs; d; d = d->v_next)		if (!strcmp(varName, d->v_name))		    d->v_gridtype = type;	} else {	    run->runPlot->pl_scale->v_gridtype = type;	}    }    return (OK);}/* The file writing routines. */static voidfileInit(run)    runDesc *run;{    char buf[513];    int i;    /* This is a hack. */    run->isComplex = false;    for (i = 0; i < run->numData; i++)        if (run->data[i].type == IF_COMPLEX)            run->isComplex = true;    i = 0;    sprintf(buf, "Title: %s\n", run->name);    i += strlen(buf);    fputs(buf, run->fp);    sprintf(buf, "Date: %s\n", datestring());    i += strlen(buf);    fputs(buf, run->fp);    sprintf(buf, "Plotname: %s\n", run->type);    i += strlen(buf);    fputs(buf, run->fp);    sprintf(buf, "Flags: %s\n", run->isComplex ? "complex" : "real");    i += strlen(buf);    fputs(buf, run->fp);    sprintf(buf, "No. Variables: %d\n", run->numData);    i += strlen(buf);    fputs(buf, run->fp);    sprintf(buf, "No. Points: ");    i += strlen(buf);    fputs(buf, run->fp);    fflush(run->fp);        /* Gotta do this for LATTICE. */    if (run->fp == stdout || (run->pointPos = ftell(run->fp)) <= 0)	run->pointPos = i;    fprintf(run->fp, "0       \n"); /* Save 8 spaces here. */    fprintf(run->fp, "Command: version %s\n", ft_sim->version);    fprintf(run->fp, "Variables:\n");    return;}static voidfileInit_pass2(run)    runDesc *run;{    int i, type;    char *name, buf[BSIZE_SP];    for (i = 0; i < run->numData; i++) {        if (isdigit(*run->data[i].name)) {        (void) sprintf(buf, "V(%s)", run->data[i].name);          name = buf;        } else {          name = run->data[i].name;        }        if (substring("#branch", name))            type = SV_CURRENT;        else if (cieq(name, "time"))            type = SV_TIME;        else if (cieq(name, "frequency"))            type = SV_FREQUENCY;        else             type = SV_VOLTAGE;        fprintf(run->fp, "\t%d\t%s\t%s", i, name,                ft_typenames(type));	if (run->data[i].gtype == GRID_XLOG)	    fprintf(run->fp, "\tgrid=3");	fprintf(run->fp, "\n");    }    fprintf(run->fp, "%s:\n", run->binary ? "Binary" : "Values");    return;}static voidfileStartPoint(fp, bin, num)    FILE *fp;    bool bin;    int num;{    if (!bin)        fprintf(fp, "%d\t", num - 1);    return;}static voidfileAddRealValue(fp, bin, value)    FILE *fp;    bool bin;    double value;{    if (bin)        fwrite((char *) &value, sizeof (double), 1, fp);    else        fprintf(fp, "\t%.*e\n", DOUBLE_PRECISION, value);        return;}static voidfileAddComplexValue(fp, bin, value)    FILE *fp;    bool bin;    IFcomplex value;{    if (bin) {        fwrite((char *) &value.real, sizeof (double), 1, fp);        fwrite((char *) &value.imag, sizeof (double), 1, fp);    } else {        fprintf(fp, "\t%.*e,%.*e\n", DOUBLE_PRECISION, value.real,                DOUBLE_PRECISION, value.imag);    }}/* ARGSUSED */ /* until some code gets written */static voidfileEndPoint(fp, bin)    FILE *fp;    bool bin;{    return;}/* Here's the hack...  Run back and fill in the number of points. */static voidfileEnd(run)    runDesc *run;{    long place;    if (run->fp != stdout) {	place = ftell(run->fp);	fseek(run->fp, run->pointPos, 0);	fprintf(run->fp, "%d", run->pointCount);	fseek(run->fp, place, 0);    } else {	/* Yet another hack-around */	fprintf(stderr, "@@@ %ld %d\n", run->pointPos, run->pointCount);    }    fflush(run->fp);    return;}/* The plot maintenance routines. */static voidplotInit(run)    runDesc *run;{    struct plot *pl = plot_alloc(run->type);    char buf[100];    struct dvec *v;    dataDesc *dd;    int i;    pl->pl_title = copy(run->name);    pl->pl_name = copy(run->type);    pl->pl_date = copy(datestring( ));    pl->pl_ndims = 0;    plot_new(pl);    plot_setcur(pl->pl_typename);    run->runPlot = pl;    /* This is a hack. */    /* if any of them complex, make them all complex */    run->isComplex = false;    for (i = 0; i < run->numData; i++) {      if (run->data[i].type == IF_COMPLEX) run->isComplex = true;    }    for (i = 0; i < run->numData; i++) {        dd = &run->data[i];        v = alloc(struct dvec);        if (isdigit(*dd->name)) {            (void) sprintf(buf, "V(%s)", dd->name);            v->v_name = copy(buf);        } else            v->v_name = copy(dd->name);        if (substring("#branch", v->v_name))            v->v_type = SV_CURRENT;        else if (cieq(v->v_name, "time"))            v->v_type = SV_TIME;        else if (cieq(v->v_name, "frequency"))            v->v_type = SV_FREQUENCY;        else             v->v_type = SV_VOLTAGE;        v->v_length = 0;        v->v_scale = NULL;        if (!run->isComplex) {            v->v_flags = VF_REAL;            v->v_realdata = NULL;        } else {            v->v_flags = VF_COMPLEX;            v->v_compdata = NULL;        }        v->v_flags |= VF_PERMANENT;        vec_new(v);        dd->vec = v;    }}static voidplotAddRealValue(desc, value)    dataDesc *desc;    double value;{    struct dvec *v = desc->vec;    if (isreal(v)) {      v->v_realdata = (double *) trealloc((char *) v->v_realdata,            sizeof (double) * (v->v_length + 1));      v->v_realdata[v->v_length] = value;    } else {      /* a real parading as a VF_COMPLEX */      v->v_compdata = (complex *) trealloc((char *) v->v_compdata,            sizeof (complex) * (v->v_length + 1));      v->v_compdata[v->v_length].cx_real = value;      v->v_compdata[v->v_length].cx_imag = (double) 0;    }    v->v_length++;    return;}static voidplotAddComplexValue(desc, value)    dataDesc *desc;    IFcomplex value;{    struct dvec *v = desc->vec;    v->v_compdata = (complex *) trealloc((char *) v->v_compdata,            sizeof (complex) * (v->v_length + 1));    v->v_compdata[v->v_length].cx_real = value.real;    v->v_compdata[v->v_length].cx_imag = value.imag;    v->v_length++;    return;}/* ARGSUSED */ /* until some code gets written */static voidplotEnd(run)    runDesc *run;{    return;}/* ParseSpecial takes something of the form "@name[param,index]" and rips * out name, param, and index. */static boolparseSpecial(name, dev, param, ind)    char *name;    char *dev;    char *param;    char *ind;{    char *s;    *dev = *param = *ind = '\0';    if (*name != '@')        return (false);    name++;        s = dev;    while (*name && (*name != '['))        *s++ = *name++;    *s = '\0';    if (!*name)        return (true);    name++;    s = param;    while (*name && (*name != ',') && (*name != ']'))        *s++ = *name++;    *s = '\0';    if (*name == ']')        return (!name[1] ? true : false);    else if (!*name)        return (false);    name++;    s = ind;    while (*name && (*name != ']'))        *s++ = *name++;    *s = '\0';    if (*name && !name[1])        return (true);    else        return (false);}/* This routine must match two names with or without a V() around them. */static boolname_eq(n1, n2)    char *n1, *n2;{    char buf1[BSIZE_SP], buf2[BSIZE_SP], *s;    if (s = index(n1, '(')) {        strcpy(buf1, s);        if (!(s = index(buf1, ')')))            return (false);        *s = '\0';        n1 = buf1;    }    if (s = index(n2, '(')) {        strcpy(buf2, s);        if (!(s = index(buf2, ')')))            return (false);        *s = '\0';        n2 = buf2;    }    return (strcmp(n1, n2) ? false : true);}static boolgetSpecial(desc, run, val)    dataDesc *desc;    runDesc *run;    IFvalue *val;{    IFvalue selector;    struct variable *vv;    selector.iValue = desc->specIndex;    if (INPaName(desc->specParamName, val, run->circuit, &desc->specType,            desc->specName, &desc->specFast, ft_sim, &desc->type,            &selector) == OK) {      desc->type &= (IF_REAL | IF_COMPLEX);   /* mask out other bits */      return(true);    } else if (vv = if_getstat(run->circuit, &desc->name[1])) {						/* skip @ sign */      desc->type = IF_REAL;      if (vv->va_type == VT_REAL)	val->rValue = vv->va_real;      else if (vv->va_type == VT_NUM)	val->rValue = vv->va_num;      else if (vv->va_type == VT_BOOL)	val->rValue = (vv->va_bool ? 1.0 : 0.0);      else {	return (false); /* not a real */      }      tfree(vv);      return(true);    }    return (false);}static voidfreeRun(run)    runDesc *run;{    int i;    for (i=0; i < run->numData; i++) {/*    vec_free(run->data[i].vec); */ /* kill run, leave plot */      tfree(run->data[i].name);      tfree(run->data[i].specParamName);    }    tfree(run->data);/*  killplot(run->runPlot); */ /* kill run, leave plot */    free(run->type);    free(run->name);    free(run);}intOUTstopnow(){    if (ft_intrpt || shouldstop) {        ft_intrpt = shouldstop = false;        return (1);    } else        return (0);}/* Print out error messages. */static struct mesg {        char *string;        long flag;} msgs[] = {        { "Warning", ERR_WARNING } ,        { "Fatal error", ERR_FATAL } ,        { "Panic", ERR_PANIC } ,        { "Note", ERR_INFO } ,        { NULL, 0 }} ;voidOUTerror(flags,format,names)     int flags;    char *format;    IFuid *names;{    struct mesg *m;    char buf[BSIZE_SP], *s, *bptr;    int nindex = 0;    if ((flags == ERR_INFO) && cp_getvar("printinfo", VT_BOOL,	    (char *) &printinfo))	return;    for (m = msgs; m->flag; m++)                if (flags & m->flag)                        fprintf(cp_err, "%s: ", m->string);    for (s = format, bptr = buf; *s; s++) {      if (*s == '%' && (s == format || *(s-1) != '%') && *(s+1) == 's') {	if (names[nindex])	  strcpy(bptr, names[nindex]);	else	  strcpy(bptr, "(null)");        bptr += strlen(bptr);        s++;        nindex++;      } else {        *bptr++ = *s;      }    }    *bptr = '\0';        fprintf(cp_err, "%s\n", buf);        fflush(cp_err);}

⌨️ 快捷键说明

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