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

📄 outitf.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 3 页
字号:
    }    fprintf(run->fp, "%s:\n", run->binary ? "Binary" : "Values");                   fflush(run->fp);        /* Make all sure this gets to disk */    /*  Allocate Row buffer  */    if (run->binary) {      rowbuflen=(run->numData)*sizeof(double);      if (run->isComplex) rowbuflen *=2;      rowbuf=(double *)tmalloc(rowbuflen);    } else rowbuf=NULL;    return;        }static voidfileStartPoint(FILE *fp, bool bin, int num){    if (!bin)        fprintf(fp, "%d\t", num - 1);            /*  reset buffer pointer to zero  */            column = 0;    return;}static voidfileAddRealValue(FILE *fp, bool bin, double value){    if (bin)        rowbuf[column++]=value;    else	fprintf(fp, "\t%.*e\n", DOUBLE_PRECISION, value);	 return;}static voidfileAddComplexValue(FILE *fp, bool bin, IFcomplex value){    if (bin) {        rowbuf[column++]=value.real;        rowbuf[column++]=value.imag;    } else {        fprintf(fp, "\t%.*e,%.*e\n", DOUBLE_PRECISION, value.real,                DOUBLE_PRECISION, value.imag);    }}/* ARGSUSED */ /* until some code gets written */static voidfileEndPoint(FILE *fp, bool bin){  if (bin) {    /*  write row buffer to file  */    fwrite((char *)rowbuf, rowbuflen, 1, fp);  }; /* otherwise the data has already been written */  return;}/* Here's the hack...  Run back and fill in the number of points. */static voidfileEnd(runDesc *run){    long place;    if (run->fp != stdout) {	place = ftell(run->fp);	fseek(run->fp, run->pointPos, 0);        fprintf(run->fp, "%d", run->pointCount);	fprintf(stderr, "\nNo. of Data Rows : %d\n", run->pointCount);	fseek(run->fp, place, 0);    } else {	/* Yet another hack-around */	fprintf(stderr, "@@@ %ld %d\n", run->pointPos, run->pointCount);    }    fflush(run->fp);    if (run->binary) {      /* deallocate row buffer */      tfree(rowbuf);    }    return;}/* The plot maintenance routines. */static voidplotInit(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 if (cieq(v->v_name, "temp-sweep")) /* Added by H.T */            v->v_type = SV_TEMP;        else if (cieq(v->v_name, "res-sweep")) /* Added by H.T */            v->v_type = SV_RES;        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(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++;    v->v_dims[0]=v->v_length; /* va, must be updated */    return;}static voidplotAddComplexValue(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++;    v->v_dims[0]=v->v_length; /* va, must be updated */    return;}/* ARGSUSED */ /* until some code gets written */static voidplotEnd(runDesc *run){    fprintf(stderr, "\nNo. of Data Rows : %d\n", run->pointCount);    return;}/* ParseSpecial takes something of the form "@name[param,index]" and rips * out name, param, andstrchr. */static boolparseSpecial(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(char *n1, char *n2){    char buf1[BSIZE_SP], buf2[BSIZE_SP], *s;    if ((s =strchr(n1, '('))) {        strcpy(buf1, s);        if (!(s =strchr(buf1, ')')))            return FALSE;        *s = '\0';        n1 = buf1;    }    if ((s =strchr(n2, '('))) {        strcpy(buf2, s);        if (!(s =strchr(buf2, ')')))            return FALSE;        *s = '\0';        n2 = buf2;    }    return (strcmp(n1, n2) ? FALSE : TRUE);}static boolgetSpecial(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(runDesc *run){    int i;    for (i=0; i < run->numData; i++) {      tfree(run->data[i].name);      tfree(run->data[i].specParamName);    }    tfree(run->data);    tfree(run->type);    tfree(run->name);    tfree(run);}intOUTstopnow(void){    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(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 + -