예제 #1
0
LRESULT HcpyPlotBW( HWND hwnd)
{
   int bgcolor;
   if (cp_getvar("hcopypscolor", CP_NUM, &bgcolor))
       cp_remvar("hcopypscolor");
	com_hardcopy(NULL); 
	return 0;
}
예제 #2
0
int WIN_Text( char * text, int x, int y)
{
   tpWindowData wd;
   HFONT hfont;
   LOGFONT lf;
  
   int CentiDegrees = 0;

   if (!currentgraph) return 0;
   wd = pWindowData(currentgraph);
   if (!wd) return 0;

   lf.lfHeight         = (int) (1.1 * currentgraph->fontheight) ; 
   lf.lfWidth          = 0 ;
   lf.lfEscapement     = CentiDegrees ;
   lf.lfOrientation    = CentiDegrees ;
   lf.lfWeight         = 500 ;
   lf.lfItalic         = 0 ;
   lf.lfUnderline      = 0 ;
   lf.lfStrikeOut      = 0 ;
   lf.lfCharSet        = 0 ;
   lf.lfOutPrecision   = 0 ;
   lf.lfClipPrecision  = 0 ;
   lf.lfQuality        = 0 ;
   lf.lfPitchAndFamily = 0 ;

   /* set up fonts */
   if (!cp_getvar("wfont", CP_STRING, lf.lfFaceName)) {
      (void) lstrcpy(lf.lfFaceName, DEF_FONTW);
   }
   if (!cp_getvar("wfont_size", CP_NUM, (char *) &(lf.lfHeight))) {
      lf.lfHeight  = (int) (1.1 * currentgraph->fontheight) ;
   }
     
//   lstrcpy (lf.lfFaceName, "Courier"/*"Times New Roman"*/) ;

   hfont = CreateFontIndirect (&lf);
   SelectObject(wd->hDC, hfont);

   SetTextColor( wd->hDC, ColorTable[wd->ColorIndex]);
   TextOut( wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, strlen(text));

   DeleteObject(SelectObject(wd->hDC, GetStockObject(SYSTEM_FONT)));

   return (0);
}
예제 #3
0
/* simple printout of data into a file, similar to data table in ft_gnuplot
   command: wrsimple file vecs
 */
void
ft_writesimple(double *xlims, double *ylims, char *filename, char *title, char *xlabel, char *ylabel, GRIDTYPE gridtype, PLOTTYPE plottype, struct dvec *vecs)
{
    FILE *file_data;
    struct dvec *v, *scale = NULL;
    double xval;
    int i, numVecs;
    bool appendwrite;

    char filename_data[128];

    NG_IGNORE(xlims);
    NG_IGNORE(ylims);
    NG_IGNORE(title);
    NG_IGNORE(xlabel);
    NG_IGNORE(ylabel);
    NG_IGNORE(gridtype);
    NG_IGNORE(plottype);

    sprintf(filename_data, "%s.data", filename);
    appendwrite = cp_getvar("appendwrite", CP_BOOL, NULL);

    /* Sanity checking. */
    for (v = vecs, numVecs = 0; v; v = v->v_link2)
        numVecs++;

    if (numVecs == 0)
        return;

    /* Open the output data file. */
    if ((file_data = fopen(filename_data, appendwrite ? "a" : "w")) == NULL) {
        perror(filename);
        return;
    }

    i = 0;
    for (v = vecs; v; v = v->v_link2)
        scale = v->v_scale;

    /* Write out the data as simple arrays */
    for (i = 0; i < scale->v_length; i++) {
        for (v = vecs; v; v = v->v_link2) {
            scale = v->v_scale;

            xval = isreal(scale) ?
                   scale->v_realdata[i] : realpart(scale->v_compdata[i]);

            if (isreal(v))
                fprintf(file_data, "% e % e ", xval, v->v_realdata[i]);
            else
                fprintf(file_data, "% e % e % e ", xval, realpart(v->v_compdata[i]), imagpart(v->v_compdata[i]));
        }
        fprintf(file_data, "\n");
    }

    (void) fclose(file_data);
}
예제 #4
0
main(int ac, char **av)
#endif /* HAS_WINDOWS */
{
    wordlist *wl = NULL;

#ifndef X_DISPLAY_MISSING
    char *displayname;
    /* grrr, Xtk forced contortions */
    char *argv[2];
    int argc = 2;
    char buf[512];
#endif /* X_DISPLAY_MISSING */

    ivars( );

    cp_in = stdin;
    cp_out = stdout;
    cp_err = stderr;

#ifndef X_DISPLAY_MISSING

    if (cp_getvar("display", CP_STRING, buf)) {
      displayname = buf;
    } else if (!(displayname = getenv("DISPLAY"))) {
      fprintf(stderr, "Can't open X display.");
      goto out;
    }

    argv[0] = "nutmeg";
    argv[1] = displayname;
    /* initialize X toolkit */
    toplevel = XtInitialize("nutmeg", "Nutmeg", NULL, 0, &argc, argv);
    
out:
#endif /* X_DISPLAY_MISSING */

    if (ac > 1)
        wl = wl_build(av + 1);
    hlp_main(Help_Path, wl);

#ifndef X_DISPLAY_MISSING
    if (hlp_usex) {
	printf("Hit control-C when done.\n");		/* sigh */
	XtMainLoop();
    }
#endif /* X_DISPLAY_MISSING */

#ifdef HAS_WINDOWS
	/* Keep window open untill a key is pressed */
	printf("Press a key to quit\n");
	while( getchar() == EOF) {}
#endif /* HAS_WINDOWS */

    return EXIT_NORMAL;
}
예제 #5
0
파일: x11.c 프로젝트: amarnathmhn/ngspice
int
X11_Arc(int x0, int y0, int radius, double theta, double delta_theta)
{
    int t1, t2;

    if (0 && !cp_getvar("x11lineararcs", CP_BOOL, NULL))
        linear_arc(x0, y0, radius, theta, delta_theta);

    if (DEVDEP(currentgraph).isopen) {
        t1 = (int) (64 * (180.0 / M_PI) * theta);
        t2 = (int) (64 * (180.0 / M_PI) * delta_theta);
        if (t2 == 0)
            return 0;
        XDrawArc(display, DEVDEP(currentgraph).window, DEVDEP(currentgraph).gc,
                 x0 - radius,
                 currentgraph->absolute.height - radius - y0,
                 (Dimension) (2 * radius), (Dimension) (2 * radius), t1, t2);
    }

    return 0;
}
예제 #6
0
파일: graf.c 프로젝트: imr/ngspice
void
gr_pmsg(char *text)
{
    char buf[BSIZE_SP];
    buf[0] = '\0';

    DevUpdate();

    if (cp_getvar("device", CP_STRING, buf, sizeof(buf)) && !(strcmp("/dev/tty", buf) == 0))
        fprintf(cp_err, "%s", text);
    else if (currentgraph->grid.xlabel)
        /* MW. grid.xlabel may be NULL */
        DevDrawText(text, currentgraph->viewport.width -
                    (int) (strlen(currentgraph->grid.xlabel) + 3) *
                    currentgraph->fontwidth,
                    currentgraph->absolute.height - currentgraph->fontheight, 0);
    else
        fprintf(cp_err, " %s \n", text);

    DevUpdate();
}
예제 #7
0
파일: hpgl.c 프로젝트: Anastien/ngspice
int GL_Init(void)
{
    if (!cp_getvar("hcopyscale", CP_STRING, psscale)) {
        scale = 1.0;
    } else {
        sscanf(psscale, "%lf", &scale);
        if ((scale <= 0) || (scale > 10))
            scale = 1.0;
    }

    dispdev->numlinestyles = NUMELEMS(linestyle);
    dispdev->numcolors = 6;

    dispdev->width = (int)(DELXMAX * scale);
    dispdev->height = (int)(DELYMAX * scale);


    screenflag = 0;
    dispdev->minx = (int)(XOFF * 1.0);
    dispdev->miny = (int)(YOFF * 1.0);

    return (0);
}
예제 #8
0
파일: x11.c 프로젝트: aesop972/ngspice-gss
int
X11_Arc(int x0, int y0, int radius, double theta1, double theta2)
{

    int	t1, t2;

    if (!cp_getvar("x11lineararcs", VT_BOOL, (char *) &t1)) {
	linear_arc(x0, y0, radius, theta1, theta2);
    }

    if (DEVDEP(currentgraph).isopen) {
	if (theta1 >= theta2)
	    theta2 = 2 * M_PI + theta2;
	t1 = 64 * (180.0 / M_PI) * theta1;
	t2 = 64 * (180.0 / M_PI) * theta2 - t1;
	if (t2 == 0)
		return 0;
	XDrawArc(display, DEVDEP(currentgraph).window, DEVDEP(currentgraph).gc,
		x0 - radius,
		currentgraph->absolute.height - radius - y0,
		2 * radius, 2 * radius, t1, t2);		
    }
    return 0;
}
예제 #9
0
void
raw_write(char *name, struct plot *pl, bool app, bool binary)
{
    FILE *fp;
    bool realflag = TRUE, writedims;
    bool raw_padding;
    int length, numdims, dims[MAXDIMS];
    int nvars, i, j, prec;
    struct dvec *v, *lv;
    wordlist *wl;
    struct variable *vv;
    double dd;
    char buf[BSIZE_SP];
    char *branch;

    raw_padding = !cp_getvar("nopadding", CP_BOOL, NULL);

    /* Why bother printing out an empty plot? */
    if (!pl->pl_dvecs) {
        fprintf(cp_err, "Error: plot is empty, nothing written.\n");
        return;
    }

    if (raw_prec != -1)
        prec = raw_prec;
    else
        prec = DEFPREC;

#if defined(__MINGW32__) || defined(_MSC_VER)

    /* - Binary file binary write -  hvogt 15.03.2000 ---------------------*/
    if (binary) {
        if ((fp = fopen(name, app ? "ab" : "wb")) == NULL) {
            perror(name);
            return;
        }
        fprintf(cp_out, "binary raw file\n");
    } else {
        if ((fp = fopen(name, app ? "a" : "w")) == NULL) {
            perror(name);
            return;
        }
        fprintf(cp_out, "ASCII raw file\n");
    }
    /* --------------------------------------------------------------------*/

#else

    if (!(fp = fopen(name, app ? "a" : "w"))) {
        perror(name);
        return;
    }

#endif

    numdims = nvars = length = 0;
    for (v = pl->pl_dvecs; v; v = v->v_next) {
        if (iscomplex(v))
            realflag = FALSE;
        nvars++;
        /* Find the length and dimensions of the longest vector
         * in the plot.
         * Be paranoid and assume somewhere we may have
         * forgotten to set the dimensions of 1-D vectors.
         */
        if (v->v_numdims <= 1) {
            v->v_numdims = 1;
            v->v_dims[0] = v->v_length;
        }
        if (v->v_length > length) {
            length = v->v_length;
            numdims = v->v_numdims;
            for (j = 0; j < numdims; j++) {
                dims[j] = v->v_dims[j];
            }
        }
    }

    fprintf(fp, "Title: %s\n", pl->pl_title);
    fprintf(fp, "Date: %s\n", pl->pl_date);
    fprintf(fp, "Plotname: %s\n", pl->pl_name);
    fprintf(fp, "Flags: %s%s\n",
            realflag ? "real" : "complex", raw_padding ? "" : " unpadded");
    fprintf(fp, "No. Variables: %d\n", nvars);
    fprintf(fp, "No. Points: %d\n", length);
    if (numdims > 1) {
        dimstring(dims, numdims, buf);
        fprintf(fp, "Dimensions: %s\n", buf);
    }

    for (wl = pl->pl_commands; wl; wl = wl->wl_next)
        fprintf(fp, "Command: %s\n", wl->wl_word);

    for (vv = pl->pl_env; vv; vv = vv->va_next) {
        wl = cp_varwl(vv);
        if (vv->va_type == CP_BOOL) {
            fprintf(fp, "Option: %s\n", vv->va_name);
        } else {
            fprintf(fp, "Option: %s = ", vv->va_name);
            if (vv->va_type == CP_LIST)
                fprintf(fp, "( ");
            wl_print(wl, fp);
            if (vv->va_type == CP_LIST)
                fprintf(fp, " )");
            (void) putc('\n', fp);
        }
    }

    /* Before we write the stuff out, make sure that the scale is the first
     * in the list.
     */
    for (lv = NULL, v = pl->pl_dvecs; v != pl->pl_scale; v = v->v_next)
        lv = v;
    if (lv) {
        lv->v_next = v->v_next;
        v->v_next = pl->pl_dvecs;
        pl->pl_dvecs = v;
    }

    fprintf(fp, "Variables:\n");
    for (i = 0, v = pl->pl_dvecs; v; v = v->v_next) {
        if (v->v_type == SV_CURRENT) {
            branch = NULL;
            if ((branch = strstr(v->v_name, "#branch")) != NULL) {
                *branch = '\0';
            }
            fprintf(fp, "\t%d\ti(%s)\t%s", i++, v->v_name, ft_typenames(v->v_type));
            if (branch != NULL) *branch = '#';
        } else if (v->v_type == SV_VOLTAGE) {
            fprintf(fp, "\t%d\t%s\t%s", i++, v->v_name, ft_typenames(v->v_type));
        } else {
            fprintf(fp, "\t%d\t%s\t%s", i++, v->v_name, ft_typenames(v->v_type));
        }
        if (v->v_flags & VF_MINGIVEN)
            fprintf(fp, " min=%e", v->v_minsignal);
        if (v->v_flags & VF_MAXGIVEN)
            fprintf(fp, " max=%e", v->v_maxsignal);
        if (v->v_defcolor)
            fprintf(fp, " color=%s", v->v_defcolor);
        if (v->v_gridtype)
            fprintf(fp, " grid=%d", v->v_gridtype);
        if (v->v_plottype)
            fprintf(fp, " plot=%d", v->v_plottype);
        /* Only write dims if they are different from default. */
        writedims = FALSE;
        if (v->v_numdims != numdims) {
            writedims = TRUE;
        } else {
            for (j = 0; j < numdims; j++)
                if (dims[j] != v->v_dims[j])
                    writedims = TRUE;
        }
        if (writedims) {
            dimstring(v->v_dims, v->v_numdims, buf);
            fprintf(fp, " dims=%s", buf);
        }
        (void) putc('\n', fp);
    }

    if (binary) {
        fprintf(fp, "Binary:\n");
        for (i = 0; i < length; i++) {
            for (v = pl->pl_dvecs; v; v = v->v_next) {
                /* Don't run off the end of this vector's data. */
                if (i < v->v_length) {
                    if (realflag) {
                        dd = (isreal(v) ? v->v_realdata[i] :
                              realpart(v->v_compdata[i]));
                        (void) fwrite(&dd, sizeof(double), 1, fp);
                    } else if (isreal(v)) {
                        dd = v->v_realdata[i];
                        (void) fwrite(&dd, sizeof(double), 1, fp);
                        dd = 0.0;
                        (void) fwrite(&dd, sizeof(double), 1, fp);
                    } else {
                        dd = realpart(v->v_compdata[i]);
                        (void) fwrite(&dd, sizeof(double), 1, fp);
                        dd = imagpart(v->v_compdata[i]);
                        (void) fwrite(&dd, sizeof(double), 1, fp);
                    }
                } else if (raw_padding) {
                    dd = 0.0;
                    if (realflag) {
                        (void) fwrite(&dd, sizeof(double), 1, fp);
                    } else {
                        (void) fwrite(&dd, sizeof(double), 1, fp);
                        (void) fwrite(&dd, sizeof(double), 1, fp);
                    }
                }
            }
        }
    } else {
        fprintf(fp, "Values:\n");
        for (i = 0; i < length; i++) {
            fprintf(fp, " %d", i);
            for (v = pl->pl_dvecs; v; v = v->v_next) {
                if (i < v->v_length) {
                    if (realflag)
                        fprintf(fp, "\t%.*e\n", prec,
                                isreal(v) ? v->v_realdata[i] :
                                realpart(v->v_compdata[i]));
                    else if (isreal(v))
                        fprintf(fp, "\t%.*e,0.0\n", prec,
                                v->v_realdata[i]);
                    else
                        fprintf(fp, "\t%.*e,%.*e\n", prec,
                                realpart(v->v_compdata[i]),
                                prec,
                                imagpart(v->v_compdata[i]));
                } else if (raw_padding) {
                    if (realflag)
                        fprintf(fp, "\t%.*e\n", prec, 0.0);
                    else
                        fprintf(fp, "\t%.*e,%.*e\n", prec, 0.0, prec, 0.0);
                }
            }
            (void) putc('\n', fp);
        }
    }
    (void) fclose(fp);
}
예제 #10
0
파일: graf.c 프로젝트: imr/ngspice
int
gr_init(double *xlims, double *ylims, /* The size of the screen. */
        char *xname, char *plotname,  /* What to label things. */
        char *hcopy,                  /* The raster file. */
        int nplots,                   /* How many plots there will be. */
        double xdelta, double ydelta, /* Line increments for the scale. */
        GRIDTYPE gridtype,            /* The grid type */
        PLOTTYPE plottype,            /*  and the plot type. */
        char *xlabel, char *ylabel,   /* Labels for axes. */
        int xtype, int ytype,         /* The types of the data graphed. */
        char *pname,
        char *commandline)            /* For xi_zoomdata() */
{
    GRAPH *graph;
    wordlist *wl;
    char *comb_title;

    NG_IGNORE(nplots);

    if ((graph = NewGraph()) == NULL)
        return (FALSE);

    /*
      The global currentgraph will always be the current graph.
    */
    SetGraphContext(graph->graphid);

    graph->onevalue = (xname ? FALSE : TRUE);

    /* communicate filename to plot 5 driver */
    if (hcopy)
        graph->devdep = hcopy;

    cur.plotno = 0;

    /* note: should do only once, maybe in gr_init_once */
    if (!cp_getvar("pointchars", CP_STRING, pointchars, sizeof(pointchars)))
        (void) strcpy(pointchars, DEFPOINTCHARS);

    if (!cp_getvar("ticmarks", CP_NUM, &graph->ticmarks, 0)) {
        if (cp_getvar("ticmarks", CP_BOOL, NULL, 0))
            graph->ticmarks = 10;
        else
            graph->ticmarks = 0;
    }

    if (cp_getvar("ticlist", CP_LIST, ticlist, 0)) {
        wl = vareval("ticlist");
        ticlist = wl_flatten(wl);
        graph->ticdata = readtics(ticlist);
    } else {
        graph->ticdata = NULL;
    }

    if (!xlims || !ylims) {
        internalerror("gr_init:  no range specified");
        return (FALSE);
    }

    /* save upper and lower limits */
    graph->data.xmin = xlims[0];
    graph->data.xmax = xlims[1];
    graph->data.ymin = ylims[0];
    graph->data.ymax = ylims[1];

    /* get title into plot window */
    if (!pname)
        pname = "(unknown)";
    if (!plotname)
        plotname = "(unknown)";

    comb_title = tprintf("%s: %s", pname, plotname);
    graph->plotname = comb_title;

    /* note: have enum here or some better convention */
    if (NewViewport(graph) == 1) {
        /* note: where is the error message generated? */
        /* note: undo tmallocs */
        fprintf(cp_err, "Can't open viewport for graphics.\n");
        return (FALSE);
    }

    /* layout decisions */
    /* note: have to do before gr_fixgrid and after NewViewport */
    graph->viewportxoff = graph->fontwidth * 8;  /* 8 lines on left */
    graph->viewportyoff = graph->fontheight * 4; /* 4 on bottom */

    DevClear();

    graph->grid.gridtype = gridtype;
    graph->plottype = plottype;
    graph->grid.xdatatype = xtype;
    graph->grid.ydatatype = ytype;
    graph->grid.xdelta = xdelta;
    graph->grid.ydelta = ydelta;
    graph->grid.ysized = 0;
    graph->grid.xsized = 0;

    if (!graph->onevalue) {
        if (xlabel)
            graph->grid.xlabel = xlabel;
        else
            graph->grid.xlabel = xname;

        if (ylabel)
            graph->grid.ylabel = ylabel;
    } else {
        if (xlabel)
            graph->grid.xlabel = xlabel;
        else
            graph->grid.xlabel = "real";

        if (ylabel)
            graph->grid.ylabel = ylabel;
        else
            graph->grid.ylabel = "imag";
    }

    gr_resize_internal(graph);
    gr_redrawgrid(graph);

    /* Set up colors and line styles. */
    if (dispdev->numlinestyles == 1)
        cur.linestyle = 0; /* Use the same one all the time. */
    else
        cur.linestyle = 1;

    /* XXX Special exception for SMITH */
    if (dispdev->numcolors > 2 &&
        (graph->grid.gridtype == GRID_SMITH ||
         graph->grid.gridtype == GRID_SMITHGRID))
    {
        cur.color = 3;
    } else {
        cur.color = 1;
    }

    graph->commandline = copy(commandline);

    return (TRUE);
}
예제 #11
0
int WIN_Init( )
{
   char colorstring[BSIZE_SP];

   /* Initialization of display descriptor */
   dispdev->width         = GetSystemMetrics( SM_CXSCREEN);
   dispdev->height        = GetSystemMetrics( SM_CYSCREEN);
   dispdev->numlinestyles = 5;   /* see implications in WinPrint! */
   dispdev->numcolors     = NumWinColors;

   /* always, user may have set color0 to white */
   /* get background color information from spinit, only "white"
      is recognized as a suitable option! */
   if (cp_getvar("color0", CP_STRING, colorstring)) {
      if (cieq(colorstring, "white")) isblack = FALSE; 
      else isblack = TRUE;	
   }	
      /* get linewidth information from spinit */
      if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth))
         linewidth = 0;
      if (linewidth < 0) linewidth = 0;  

   /* only for the first time: */
   if (!IsRegistered) {

	  isblackold = isblack;
	  
      /* get linewidth information from spinit 
      if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth))
         linewidth = 0;
      if (linewidth < 0) linewidth = 0;        */

      /* Initialize colors */
      if (isblack) {
         ColorTable[0] = RGB(  0,  0,  0);   /* black   = background */
         ColorTable[1] = RGB(255,255,255);   /* white    = text and grid */
      }
      else {
         ColorTable[0] = RGB(255,255,255);   /* white   = background */
         ColorTable[1] = RGB(  0,  0,  0);   /* black   = text and grid */
      }
	  
      ColorTable[2] = RGB(  0,255,  0);   /* green   = first line */
      ColorTable[3] = RGB(255,  0,  0);   /* red */
      ColorTable[4] = RGB(  0,  0,255);   /* blue */
      ColorTable[5] = RGB(255,255,  0);   /* yellow */
      ColorTable[6] = RGB(255,  0,255);   /* violett */
      ColorTable[7] = RGB(  0,255,255);   /* azur */
      ColorTable[8] = RGB(255,128,  0);   /* orange */
      ColorTable[9] = RGB(128, 64,  0);   /* brown */
      ColorTable[10]= RGB(128,  0,255);   /* light violett */
      ColorTable[11]= RGB(255,128,128);   /* pink */
      /* 2. color bank (with different line style */
      if (isblack)
         ColorTable[12]= RGB(255,255,255);   /* white */
      else
         ColorTable[12]= RGB(  0,  0,  0);   /* black */
      ColorTable[13]= RGB(  0,255,  0);   /* green */
      ColorTable[14]= RGB(255,  0,  0);   /* red */
      ColorTable[15]= RGB(  0,  0,255);   /* blue */
      ColorTable[16]= RGB(255,255,  0);   /* yellow */
      ColorTable[17]= RGB(255,  0,255);   /* violett */
      ColorTable[18]= RGB(  0,255,255);   /* azur */
      ColorTable[19]= RGB(255,128,  0);   /* orange */
      ColorTable[20]= RGB(128, 64,  0);   /* brown */
      ColorTable[21]= RGB(128,  0,255);   /* light violett */
      ColorTable[22]= RGB(255,128,128);   /* pink */

      /* Ansii fixed font */
      PlotFont = GetStockFont( ANSI_FIXED_FONT);

      /* register window class */
      TheWndClass.lpszClassName  = WindowName;
      TheWndClass.hInstance      = hInst;
      TheWndClass.lpfnWndProc    = PlotWindowProc;
      TheWndClass.style       = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
      TheWndClass.lpszMenuName   = NULL;
      TheWndClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
      if (isblack)
         TheWndClass.hbrBackground  = GetStockObject( BLACK_BRUSH);
      else
         TheWndClass.hbrBackground  = GetStockObject( WHITE_BRUSH);
      TheWndClass.hIcon          = LoadIcon(hInst, MAKEINTRESOURCE(2));
      TheWndClass.cbClsExtra     = 0;
      TheWndClass.cbWndExtra     = sizeof(GRAPH *);
      if (!RegisterClass(&TheWndClass)) return 1;
   }
    /* not first time */
	else if (isblackold != isblack) {
	  if (isblack) {
         ColorTable[0] = RGB(  0,  0,  0);   /* black   = background */
         ColorTable[1] = RGB(255,255,255);   /* white    = text and grid */
      }
      else {
         ColorTable[0] = RGB(255,255,255);   /* white   = background */
         ColorTable[1] = RGB(  0,  0,  0);   /* black   = text and grid */
      }   
      if (isblack)
         ColorTable[12]= RGB(255,255,255);   /* white */
      else
         ColorTable[12]= RGB(  0,  0,  0);   /* black */
		 		 
      isblackold=isblack;
   }	
   IsRegistered = 1;

   /* ready */
   return (0);
}
예제 #12
0
파일: x11.c 프로젝트: amarnathmhn/ngspice
/* NewViewport is responsible for filling in graph->viewport */
int
X11_NewViewport(GRAPH *graph)
{
    char fontname[513]; /* who knows . . . */
    char *p, *q;
    Cursor cursor;
    XSetWindowAttributes w_attrs;
    XGCValues gcvalues;

    static Arg formargs[ ] = {
        { XtNleft, (XtArgVal) XtChainLeft },
        { XtNresizable, (XtArgVal) TRUE }
    };
    static Arg bboxargs[ ] = {
        { XtNfromHoriz, (XtArgVal) NULL },
        { XtNbottom, (XtArgVal) XtChainTop },
        { XtNtop, (XtArgVal) XtChainTop },
        { XtNleft, (XtArgVal) XtChainRight },
        { XtNright, (XtArgVal) XtChainRight }
    };
    static Arg buttonargs[ ] = {
        { XtNlabel, (XtArgVal) NULL },
        { XtNfromVert, (XtArgVal) NULL },
        { XtNbottom, (XtArgVal) XtChainTop },
        { XtNtop, (XtArgVal) XtChainTop },
        { XtNleft, (XtArgVal) XtRubber },
        { XtNright, (XtArgVal) XtRubber },
        { XtNresizable, (XtArgVal) TRUE }
    };
    static Arg viewargs[] = {
        { XtNresizable, (XtArgVal) TRUE },
        { XtNwidth, (XtArgVal) 300 },
        { XtNheight, (XtArgVal) 300 },
        { XtNright, (XtArgVal) XtChainRight }
    };
    int trys;

    graph->devdep = TMALLOC(X11devdep, 1);

    /* set up new shell */
    DEVDEP(graph).shell = XtCreateApplicationShell
        ("shell", topLevelShellWidgetClass, NULL, 0);

    XtVaSetValues(DEVDEP(graph).shell, XtNtitle, graph->plotname, NULL);

    /* set up form widget */
    DEVDEP(graph).form = XtCreateManagedWidget
        ("form", formWidgetClass, DEVDEP(graph).shell, formargs, XtNumber(formargs));

    /* set up viewport */
    DEVDEP(graph).view = XtCreateManagedWidget
        ("viewport", widgetClass, DEVDEP(graph).form, viewargs, XtNumber(viewargs));
    XtAddEventHandler(DEVDEP(graph).view, ButtonPressMask, FALSE,
                      handlebuttonev, graph);
    XtAddEventHandler(DEVDEP(graph).view, KeyPressMask, FALSE,
                      handlekeypressed, graph);
    XtAddEventHandler(DEVDEP(graph).view, StructureNotifyMask, FALSE,
                      resize, graph);
    XtAddEventHandler(DEVDEP(graph).view, ExposureMask, FALSE,
                      redraw, graph);

    /* set up button box */
    XtSetArg(bboxargs[1], XtNfromHoriz, DEVDEP(graph).view);
    DEVDEP(graph).buttonbox = XtCreateManagedWidget
        ("buttonbox", boxWidgetClass, DEVDEP(graph).form, bboxargs, XtNumber(bboxargs));

    /* set up buttons */
    XtSetArg(buttonargs[0], XtNlabel, "quit");
    XtSetArg(bboxargs[1], XtNfromVert, NULL);
    DEVDEP(graph).buttons[0] = XtCreateManagedWidget
        ("quit", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1);
    XtAddCallback(DEVDEP(graph).buttons[0], XtNcallback, killwin, graph);

    XtSetArg(buttonargs[0], XtNlabel, "hardcopy");
    XtSetArg(bboxargs[1], XtNfromVert, DEVDEP(graph).buttons[0]);
    DEVDEP(graph).buttons[1] = XtCreateManagedWidget
        ("hardcopy", commandWidgetClass, DEVDEP(graph).buttonbox, buttonargs, 1);
    XtAddCallback(DEVDEP(graph).buttons[1], XtNcallback, hardcopy, graph);

    /* set up fonts */
    if (!cp_getvar("font", CP_STRING, fontname))
        (void) strcpy(fontname, DEF_FONT);

    for (p = fontname; *p && *p <= ' '; p++)
        ;

    if (p != fontname) {
        for (q = fontname; *p; *q++ = *p++)
            ;
        *q = 0;
    }

    trys = 1;
    while (!(DEVDEP(graph).font = XLoadQueryFont(display, fontname))) {
        sprintf(ErrorMessage, "can't open font %s", fontname);
        strcpy(fontname, "fixed");
        if (trys > 1) {
            internalerror(ErrorMessage);
            RECOVERNEWVIEWPORT();
            return (1);
        }
        trys += 1;
    }

    graph->fontwidth = DEVDEP(graph).font->max_bounds.rbearing -
        DEVDEP(graph).font->min_bounds.lbearing + 1;
    graph->fontheight = DEVDEP(graph).font->max_bounds.ascent +
        DEVDEP(graph).font->max_bounds.descent + 1;

    XtRealizeWidget(DEVDEP(graph).shell);

    DEVDEP(graph).window = XtWindow(DEVDEP(graph).view);
    DEVDEP(graph).isopen = 0;
    w_attrs.bit_gravity = ForgetGravity;
    XChangeWindowAttributes(display, DEVDEP(graph).window, CWBitGravity,
                            &w_attrs);
    /* have to note font and set mask GCFont in XCreateGC, p.w.h. */
    gcvalues.font = DEVDEP(graph).font->fid;
    gcvalues.line_width = MW_LINEWIDTH;
    gcvalues.cap_style = CapNotLast;
    gcvalues.function = GXcopy;
    DEVDEP(graph).gc = XCreateGC(display, DEVDEP(graph).window,
                                 GCFont | GCLineWidth | GCCapStyle | GCFunction, &gcvalues);

    /* should absolute.positions really be shell.pos? */
    graph->absolute.xpos = DEVDEP(graph).view->core.x;
    graph->absolute.ypos = DEVDEP(graph).view->core.y;
    graph->absolute.width = DEVDEP(graph).view->core.width;
    graph->absolute.height = DEVDEP(graph).view->core.height;

    initlinestyles();
    initcolors(graph);

    /* set up cursor */
    cursor = XCreateFontCursor(display, XC_left_ptr);
    XDefineCursor(display, DEVDEP(graph).window, cursor);

    /* WM_DELETE_WINDOW protocol */
    atom_wm_protocols = XInternAtom(display, "WM_PROTOCOLS", False);
    atom_wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XtAddEventHandler(DEVDEP(graph).shell, NoEventMask, True, handle_wm_messages, graph);
    XSetWMProtocols(display, XtWindow(DEVDEP(graph).shell), &atom_wm_delete_window, 1);

    return (0);
}
예제 #13
0
파일: x11.c 프로젝트: amarnathmhn/ngspice
int
X11_Init(void)
{
    char buf[512];
    char *displayname;

    XGCValues gcvalues;

    /* grrr, Xtk forced contortions */
    char *argv[2];
    int argc = 2;

    if (cp_getvar("display", CP_STRING, buf)) {
        displayname = buf;
    } else if (!(displayname = getenv("DISPLAY"))) {
        internalerror("Can't open X display.");
        return (1);
    }

#  ifdef DEBUG
    _Xdebug = 1;
#  endif

    argv[0] = "ngspice";
    argv[1] = displayname;
/*
  argv[2] = "-geometry";
  argv[3] = "=1x1+2+2";
*/

    /* initialize X toolkit */
    toplevel = XtInitialize("ngspice", "Nutmeg", NULL, 0, &argc, argv);

    display = XtDisplay(toplevel);

    X11_Open = 1;

    /* "invert" works better than "xor" for B&W */

    /* xor gc should be a function of the pixels that are written on */
    /* gcvalues.function = GXxor; */
    /* this patch makes lines visible on true color displays
       Guenther Roehrich 22-Jan-99 */
    gcvalues.function = GXinvert;
    gcvalues.line_width = 1;
    gcvalues.foreground = 1;
    gcvalues.background = 0;

    xorgc = XCreateGC(display, DefaultRootWindow(display),
                      GCLineWidth | GCFunction | GCForeground | GCBackground,
                      &gcvalues);

    /* set correct information */
    dispdev->numlinestyles = NUMLINESTYLES;
    dispdev->numcolors = NUMCOLORS;

    dispdev->width = DisplayWidth(display, DefaultScreen(display));
    dispdev->height = DisplayHeight(display, DefaultScreen(display));

    /* we don't want non-fatal X errors to call exit */
    XSetErrorHandler(errorhandler);

    numdispplanes = DisplayPlanes(display, DefaultScreen(display));

    return (0);
}
예제 #14
0
파일: b4par.c 프로젝트: amarnathmhn/ngspice
int
BSIM4param(
int param,
IFvalue *value,
GENinstance *inst,
IFvalue *select)
{
    double scale;

    BSIM4instance *here = (BSIM4instance*)inst;

    NG_IGNORE(select);

    if (!cp_getvar("scale", CP_REAL, &scale))
        scale = 1;

    switch(param) 
    {   case BSIM4_W:
            here->BSIM4w = value->rValue * scale;
            here->BSIM4wGiven = TRUE;
            break;
        case BSIM4_L:
            here->BSIM4l = value->rValue * scale;
            here->BSIM4lGiven = TRUE;
            break;
        case BSIM4_M:
            here->BSIM4m = value->rValue;
            here->BSIM4mGiven = TRUE;
            break;
        case BSIM4_NF:
            here->BSIM4nf = value->rValue;
            here->BSIM4nfGiven = TRUE;
            break;
        case BSIM4_MIN:
            here->BSIM4min = value->iValue;
            here->BSIM4minGiven = TRUE;
            break;
        case BSIM4_AS:
            here->BSIM4sourceArea = value->rValue * scale * scale;
            here->BSIM4sourceAreaGiven = TRUE;
            break;
        case BSIM4_AD:
            here->BSIM4drainArea = value->rValue * scale * scale;
            here->BSIM4drainAreaGiven = TRUE;
            break;
        case BSIM4_PS:
            here->BSIM4sourcePerimeter = value->rValue * scale;
            here->BSIM4sourcePerimeterGiven = TRUE;
            break;
        case BSIM4_PD:
            here->BSIM4drainPerimeter = value->rValue * scale;
            here->BSIM4drainPerimeterGiven = TRUE;
            break;
        case BSIM4_NRS:
            here->BSIM4sourceSquares = value->rValue;
            here->BSIM4sourceSquaresGiven = TRUE;
            break;
        case BSIM4_NRD:
            here->BSIM4drainSquares = value->rValue;
            here->BSIM4drainSquaresGiven = TRUE;
            break;
        case BSIM4_OFF:
            here->BSIM4off = value->iValue;
            break;
        case BSIM4_SA:
            here->BSIM4sa = value->rValue;
            here->BSIM4saGiven = TRUE;
            break;
        case BSIM4_SB:
            here->BSIM4sb = value->rValue;
            here->BSIM4sbGiven = TRUE;
            break;
        case BSIM4_SD:
            here->BSIM4sd = value->rValue;
            here->BSIM4sdGiven = TRUE;
            break;
        case BSIM4_SCA:
            here->BSIM4sca = value->rValue;
            here->BSIM4scaGiven = TRUE;
            break;
        case BSIM4_SCB:
            here->BSIM4scb = value->rValue;
            here->BSIM4scbGiven = TRUE;
            break;
        case BSIM4_SCC:
            here->BSIM4scc = value->rValue;
            here->BSIM4sccGiven = TRUE;
            break;
        case BSIM4_SC:
            here->BSIM4sc = value->rValue;
            here->BSIM4scGiven = TRUE;
            break;
        case BSIM4_RBSB:
            here->BSIM4rbsb = value->rValue;
            here->BSIM4rbsbGiven = TRUE;
            break;
        case BSIM4_RBDB:
            here->BSIM4rbdb = value->rValue;
            here->BSIM4rbdbGiven = TRUE;
            break;
        case BSIM4_RBPB:
            here->BSIM4rbpb = value->rValue;
            here->BSIM4rbpbGiven = TRUE;
            break;
        case BSIM4_RBPS:
            here->BSIM4rbps = value->rValue;
            here->BSIM4rbpsGiven = TRUE;
            break;
        case BSIM4_RBPD:
            here->BSIM4rbpd = value->rValue;
            here->BSIM4rbpdGiven = TRUE;
            break;
        case BSIM4_DELVTO:
            here->BSIM4delvto = value->rValue;
            here->BSIM4delvtoGiven = TRUE;
            break;
        case BSIM4_XGW:
            here->BSIM4xgw = value->rValue;
            here->BSIM4xgwGiven = TRUE;
            break;
        case BSIM4_NGCON:
            here->BSIM4ngcon = value->rValue;
            here->BSIM4ngconGiven = TRUE;
            break;
        case BSIM4_TRNQSMOD:
            here->BSIM4trnqsMod = value->iValue;
            here->BSIM4trnqsModGiven = TRUE;
            break;
        case BSIM4_ACNQSMOD:
            here->BSIM4acnqsMod = value->iValue;
            here->BSIM4acnqsModGiven = TRUE;
            break;
        case BSIM4_RBODYMOD:
            here->BSIM4rbodyMod = value->iValue;
            here->BSIM4rbodyModGiven = TRUE;
            break;
        case BSIM4_RGATEMOD:
            here->BSIM4rgateMod = value->iValue;
            here->BSIM4rgateModGiven = TRUE;
            break;
        case BSIM4_GEOMOD:
            here->BSIM4geoMod = value->iValue;
            here->BSIM4geoModGiven = TRUE;
            break;
        case BSIM4_RGEOMOD:
            here->BSIM4rgeoMod = value->iValue;
            here->BSIM4rgeoModGiven = TRUE;
            break;
        case BSIM4_IC_VDS:
            here->BSIM4icVDS = value->rValue;
            here->BSIM4icVDSGiven = TRUE;
            break;
        case BSIM4_IC_VGS:
            here->BSIM4icVGS = value->rValue;
            here->BSIM4icVGSGiven = TRUE;
            break;
        case BSIM4_IC_VBS:
            here->BSIM4icVBS = value->rValue;
            here->BSIM4icVBSGiven = TRUE;
            break;
        case BSIM4_IC:
            switch(value->v.numValue)
            {   case 3:
                    here->BSIM4icVBS = *(value->v.vec.rVec+2);
                    here->BSIM4icVBSGiven = TRUE;
                case 2:
                    here->BSIM4icVGS = *(value->v.vec.rVec+1);
                    here->BSIM4icVGSGiven = TRUE;
                case 1:
                    here->BSIM4icVDS = *(value->v.vec.rVec);
                    here->BSIM4icVDSGiven = TRUE;
                    break;
                default:
                    return(E_BADPARM);
            }
            break;
        default:
            return(E_BADPARM);
    }
    return(OK);
}
예제 #15
0
파일: measure.c 프로젝트: fengmm521/myspice
//bool
//do_measure(
//    char *what,   /*in: analysis type*/
//    bool chk_only /*in: TRUE if checking for "autostop", FALSE otherwise*/
//)
int
do_measure(
           char *what,   /*in: analysis type*/
           int chk_only /*in: TRUE if checking for "autostop", FALSE otherwise*/
)
{
    struct line *meas_card, *meas_results = NULL, *end = NULL, *newcard;
    char        *line, *an_name, *an_type, *resname, *meastype, *str_ptr, out_line[1000];
    int         ok = 0;
    int         fail;
    int         num_failed = 0;
    double      result = 0;
//    bool        first_time = TRUE;
//    bool        measures_passed;
    int        first_time = TRUE;
    int        measures_passed;
    wordlist    *measure_word_list;
    int         precision = measure_get_precision();

#ifdef HAS_PROGREP
    if (!chk_only)
        SetAnalyse("meas", 0);
#endif

    an_name = strdup(what); /* analysis type, e.g. "tran" */
    strtolower(an_name);
    measure_word_list = NULL;
    measures_passed = TRUE;

    /* don't allow .meas if batchmode is set by -b and -r rawfile given */
    if (ft_batchmode && rflag) {
        fprintf(cp_err, "\nNo .measure possible in batch mode (-b) with -r rawfile set!\n");
        fprintf(cp_err, "Remove rawfile and use .print or .plot or\n");
        fprintf(cp_err, "select interactive mode (optionally with .control section) instead.\n\n");
        return (measures_passed);
    }

    /* don't allow autostop if no .meas commands are given in the input file */
    if ((cp_getvar("autostop", CP_BOOL, NULL)) && (ft_curckt->ci_meas == NULL)) {
        fprintf(cp_err, "\nWarning: No .meas commands found!\n");
        fprintf(cp_err, "  Option autostop is not available, ignored!\n\n");
        cp_remvar("autostop");
        return (FALSE);
    }

    /* Evaluating the linked list of .meas cards, assembled from the input deck
       by fcn inp_spsource() in inp.c:575.
       A typical .meas card will contain:
       parameter        value
       nameof card      .meas(ure)
       analysis type    tran        only tran available currently
       result name      myout       defined by user
       measurement type trig|delay|param|expr|avg|mean|max|min|rms|integ(ral)|when

       The measurement type determines how to continue the .meas card.
       param|expr are skipped in first pass through .meas cards and are treated in second pass,
       all others are treated in fcn get_measure2() (com_measure2.c).
       */

    /* first pass through .meas cards: evaluate everything except param|expr */
    for (meas_card = ft_curckt->ci_meas; meas_card != NULL; meas_card = meas_card->li_next) {
        line = meas_card->li_line;

        txfree(gettok(&line)); /* discard .meas */

        an_type = gettok(&line);
        resname = gettok(&line);
        meastype = gettok(&line);

        if (chkAnalysisType(an_type) != TRUE) {
            if (!chk_only) {
                fprintf(cp_err, "Error: unrecognized analysis type '%s' for the following .meas statement on line %d:\n", an_type, meas_card->li_linenum);
                fprintf(cp_err, "       %s\n", meas_card->li_line);
            }

            txfree(an_type);
            txfree(resname);
            txfree(meastype);
            continue;
        }
        /* print header before evaluating first .meas line */
        else if (first_time) {
            first_time = FALSE;

            if (!chk_only && strcmp(an_type, "tran") == 0) {
                fprintf(stdout, "\n  Measurements for Transient Analysis\n\n");
            }
        }

        /* skip param|expr measurement types for now -- will be done after other measurements */
        if (strncmp(meastype, "param", 5) == 0 || strncmp(meastype, "expr", 4) == 0)
            continue;

        /* skip .meas line, if analysis type from line and name of analysis performed differ */
        if (strcmp(an_name, an_type) != 0) {
            txfree(an_type);
            txfree(resname);
            txfree(meastype);
            continue;
        }

        /* New way of processing measure statements using common code
           in fcn get_measure2() (com_measure2.c)*/
        out_line[0] = '\0';
        measure_word_list = measure_parse_line(meas_card->li_line);
        if (measure_word_list) {
            fail = get_measure2(measure_word_list, &result, out_line, chk_only);
            if (fail) {
                measures_passed = FALSE;
                if (!chk_only)
                    fprintf(stderr, " %s failed!\n\n", meas_card->li_line);
                num_failed++;
                if (chk_only) {
                    /* added for speed - cleanup last parse and break */
                    txfree(an_type);
                    txfree(resname);
                    txfree(meastype);
                    wl_free(measure_word_list);
                    break;
                }
            } else {
                if (!chk_only)
                    nupa_add_param(resname, result);
            }
            wl_free(measure_word_list);
        } else {
            measures_passed = FALSE;
            num_failed++;
        }

        if (!chk_only) {
            newcard          = alloc(struct line);
            newcard->li_line = strdup(out_line);
            newcard->li_next = NULL;

            if (meas_results == NULL) {
                meas_results = end = newcard;
            } else {
                end->li_next = newcard;
                end          = newcard;
            }
        }

        txfree(an_type);
        txfree(resname);
        txfree(meastype);

    } /* end of for loop (first pass through .meas lines) */
예제 #16
0
int HSMHVparam(
     int param,
     IFvalue *value,
     GENinstance *inst,
     IFvalue *select)
{
  double scale;

  HSMHVinstance *here = (HSMHVinstance*)inst;

  NG_IGNORE(select);

  if (!cp_getvar("scale", CP_REAL, &scale))
      scale = 1;

  switch (param) {
  case HSMHV_COSELFHEAT:
    here->HSMHV_coselfheat = value->iValue;
    here->HSMHV_coselfheat_Given = TRUE;
    break;
  case HSMHV_COSUBNODE:
    here->HSMHV_cosubnode = value->iValue;
    here->HSMHV_cosubnode_Given = TRUE;
    break;
  case HSMHV_W:
    here->HSMHV_w = value->rValue * scale;
    here->HSMHV_w_Given = TRUE;
    break;
  case HSMHV_L:
    here->HSMHV_l = value->rValue * scale;
    here->HSMHV_l_Given = TRUE;
    break;
  case HSMHV_AS:
    here->HSMHV_as = value->rValue * scale * scale;
    here->HSMHV_as_Given = TRUE;
    break;
  case HSMHV_AD:
    here->HSMHV_ad = value->rValue * scale * scale;
    here->HSMHV_ad_Given = TRUE;
    break;
  case HSMHV_PS:
    here->HSMHV_ps = value->rValue * scale;
    here->HSMHV_ps_Given = TRUE;
    break;
  case HSMHV_PD:
    here->HSMHV_pd = value->rValue * scale;
    here->HSMHV_pd_Given = TRUE;
    break;
  case HSMHV_NRS:
    here->HSMHV_nrs = value->rValue;
    here->HSMHV_nrs_Given = TRUE;
    break;
  case HSMHV_NRD:
    here->HSMHV_nrd = value->rValue;
    here->HSMHV_nrd_Given = TRUE;
    break;
  case HSMHV_DTEMP:
    here->HSMHV_dtemp = value->rValue;
    here->HSMHV_dtemp_Given = TRUE;
    break;
  case HSMHV_OFF:
    here->HSMHV_off = value->iValue;
    break;
  case HSMHV_IC_VBS:
    here->HSMHV_icVBS = value->rValue;
    here->HSMHV_icVBS_Given = TRUE;
    break;
  case HSMHV_IC_VDS:
    here->HSMHV_icVDS = value->rValue;
    here->HSMHV_icVDS_Given = TRUE;
    break;
  case HSMHV_IC_VGS:
    here->HSMHV_icVGS = value->rValue;
    here->HSMHV_icVGS_Given = TRUE;
    break;
  case HSMHV_IC:
    switch (value->v.numValue) {
    case 3:
      here->HSMHV_icVBS = *(value->v.vec.rVec + 2);
      here->HSMHV_icVBS_Given = TRUE;
    case 2:
      here->HSMHV_icVGS = *(value->v.vec.rVec + 1);
      here->HSMHV_icVGS_Given = TRUE;
    case 1:
      here->HSMHV_icVDS = *(value->v.vec.rVec);
      here->HSMHV_icVDS_Given = TRUE;
      break;
    default:
      return(E_BADPARM);
    }
    break;
  case  HSMHV_CORBNET: 
    here->HSMHV_corbnet = value->iValue;
    here->HSMHV_corbnet_Given = TRUE;
    break;
  case  HSMHV_RBPB:
    here->HSMHV_rbpb = value->rValue;
    here->HSMHV_rbpb_Given = TRUE;
    break;
  case  HSMHV_RBPD:
    here->HSMHV_rbpd = value->rValue;
    here->HSMHV_rbpd_Given = TRUE;
    break;
  case  HSMHV_RBPS:
    here->HSMHV_rbps = value->rValue;
    here->HSMHV_rbps_Given = TRUE;
    break;
  case  HSMHV_RBDB:
    here->HSMHV_rbdb = value->rValue;
    here->HSMHV_rbdb_Given = TRUE;
    break;
  case  HSMHV_RBSB:
    here->HSMHV_rbsb = value->rValue;
    here->HSMHV_rbsb_Given = TRUE;
    break;
  case  HSMHV_CORG: 
    here->HSMHV_corg = value->iValue;
    here->HSMHV_corg_Given = TRUE;
    break;
  case  HSMHV_NGCON:
    here->HSMHV_ngcon = value->rValue;
    here->HSMHV_ngcon_Given = TRUE;
    break;
  case  HSMHV_XGW:
    here->HSMHV_xgw = value->rValue;
    here->HSMHV_xgw_Given = TRUE;
    break;
  case  HSMHV_XGL:
    here->HSMHV_xgl = value->rValue;
    here->HSMHV_xgl_Given = TRUE;
    break;
  case  HSMHV_NF:
    here->HSMHV_nf = value->rValue;
    here->HSMHV_nf_Given = TRUE;
    break;
  case  HSMHV_SA:
    here->HSMHV_sa = value->rValue;
    here->HSMHV_sa_Given = TRUE;
    break;
  case  HSMHV_SB:
    here->HSMHV_sb = value->rValue;
    here->HSMHV_sb_Given = TRUE;
    break;
  case  HSMHV_SD:
    here->HSMHV_sd = value->rValue;
    here->HSMHV_sd_Given = TRUE;
    break;
  case  HSMHV_NSUBCDFM:
    here->HSMHV_nsubcdfm = value->rValue;
    here->HSMHV_nsubcdfm_Given = TRUE;
    break;
  case  HSMHV_M:
    here->HSMHV_m = value->rValue;
    here->HSMHV_m_Given = TRUE;
    break;
  case  HSMHV_SUBLD1:
    here->HSMHV_subld1 = value->rValue;
    here->HSMHV_subld1_Given = TRUE;
    break;
  case  HSMHV_SUBLD2:
    here->HSMHV_subld2 = value->rValue;
    here->HSMHV_subld2_Given = TRUE;
    break;
  case  HSMHV_LOVER:
    here->HSMHV_lover = value->rValue;
    here->HSMHV_lover_Given = TRUE;
    break;
  case  HSMHV_LOVERS:
    here->HSMHV_lovers = value->rValue;
    here->HSMHV_lovers_Given = TRUE;
    break;
  case  HSMHV_LOVERLD:
    here->HSMHV_loverld = value->rValue;
    here->HSMHV_loverld_Given = TRUE;
    break;
  case  HSMHV_LDRIFT1:
    here->HSMHV_ldrift1 = value->rValue;
    here->HSMHV_ldrift1_Given = TRUE;
    break;
  case  HSMHV_LDRIFT2:
    here->HSMHV_ldrift2 = value->rValue;
    here->HSMHV_ldrift2_Given = TRUE;
    break;
  case  HSMHV_LDRIFT1S:
    here->HSMHV_ldrift1s = value->rValue;
    here->HSMHV_ldrift1s_Given = TRUE;
    break;
  case  HSMHV_LDRIFT2S:
    here->HSMHV_ldrift2s = value->rValue;
    here->HSMHV_ldrift2s_Given = TRUE;
    break;
  default:
    return(E_BADPARM);
  }
  return(OK);
}
예제 #17
0
static int
dosim(
    char *what, /* in: command (pz,op,dc,ac,tf,tran,sens,disto,noise,run) */
    wordlist *wl /* in: command option */
    /* global variables in: ft_curckt, ft_circuits,
       out: ft_setflag, ft_intrpt, rawfileFp, rawfileBinary,
       last_used_rawfile
    */
    )
{
    wordlist *ww = NULL;
    bool dofile = FALSE;
    char buf[BSIZE_SP];
    struct circ *ct;
    int err = 0;
    /* set file type to binary or to what is given by environmental
       variable SPICE_ASCIIRAWFILE in ivars.c */
    bool ascii = AsciiRawFile;
    if (eq(what, "run") && wl)
        dofile = TRUE;
    /* add "what" to beginning of wordlist wl, except "what" equals "run"
       and a rawfile name is given (in wl) */
    if (!dofile) {
        ww = wl_cons(copy(what), wl);
    }
    /* reset output file type according to variable given in spinit */
    if (cp_getvar("filetype", CP_STRING, buf)) {
        if (eq(buf, "binary"))
            ascii = FALSE;
        else if (eq(buf, "ascii"))
            ascii = TRUE;
        else {
            fprintf(cp_err,
                    "Warning: strange file type \"%s\" (using \"ascii\")\n", buf);
            ascii = TRUE;
        }
    }

    if (!ft_curckt) {
        fprintf(cp_err, "Error: there aren't any circuits loaded.\n");
        return 1;
    } else if (ft_curckt->ci_ckt == NULL) { /* Set noparse? */
        fprintf(cp_err, "Error: circuit not parsed.\n");
        return 1;
    }
    for (ct = ft_circuits; ct; ct = ct->ci_next)
        if (ct->ci_inprogress && (ct != ft_curckt)) {
            fprintf(cp_err,
                    "Warning: losing old state for circuit '%s'\n",
                    ct->ci_name);
            ct->ci_inprogress = FALSE;
        }
    /* "resume" will never occur in ngspice */
    if (ft_curckt->ci_inprogress && eq(what, "resume")) {
        ft_setflag = TRUE;  /* don't allow abort upon interrupt during run  */
        ft_intrpt = FALSE;
        fprintf(cp_err, "Warning: resuming run in progress.\n");
        com_resume(NULL);
        ft_setflag = FALSE;  /* Now allow aborts again  */
        return 0;
    }

    /* From now on until the next prompt, an interrupt will just
     * set a flag and let spice finish up, then control will be
     * passed back to the user.
     */
    ft_setflag = TRUE;  /* Don't allow abort upon interrupt during run.  */
    ft_intrpt = FALSE;
    /* command "run" is given with rawfile name in wl */
    if (dofile) {
        if (!*wl->wl_word)
            rawfileFp = stdout;
#if defined(__MINGW32__) || defined(_MSC_VER)
        /* ask if binary or ASCII, open file with wb or w */
        else if (ascii) {
            if ((rawfileFp = fopen(wl->wl_word, "w")) == NULL) {
                perror(wl->wl_word);
                ft_setflag = FALSE;
                return 1;
            }
            fprintf(cp_out, "ASCII raw file\n");
        }
        else if (!ascii) {
            if ((rawfileFp = fopen(wl->wl_word, "wb")) == NULL) {
                perror(wl->wl_word);
                ft_setflag = FALSE;
                return 1;
            }
            fprintf(cp_out, "binary raw file\n");
        }
/*---------------------------------------------------------------------------*/
#else
        else if (!(rawfileFp = fopen(wl->wl_word, "w"))) {
            setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE);
            perror(wl->wl_word);
            ft_setflag = FALSE;
            return 1;
        }
#endif /* __MINGW32__ */
        rawfileBinary = !ascii;
    } else {
        rawfileFp = NULL;
    }

    /*save rawfile name */
    if (last_used_rawfile)
        tfree(last_used_rawfile);
    if (rawfileFp)
        last_used_rawfile = copy(wl->wl_word);
    else
        last_used_rawfile = NULL;

    ft_curckt->ci_inprogress = TRUE;
    /* "sens2" not used in ngspice */
    if (eq(what, "sens2")) {
        if (if_sens_run(ft_curckt->ci_ckt, ww, ft_curckt->ci_symtab) == 1) {
            /* The circuit was interrupted somewhere. */
            fprintf(cp_err, "%s simulation interrupted\n", what);
#ifdef XSPICE
            /* gtri - add - 12/12/90 - wbk - record error and return errchk */
            g_ipc.run_error = IPC_TRUE;
            if (g_ipc.enabled)
                ipc_send_errchk();
            /* gtri - end - 12/12/90 */
#endif
        } else {
            ft_curckt->ci_inprogress = FALSE;
        }
        /* Do a run of the circuit */
    } else {
        err = if_run(ft_curckt->ci_ckt, what, ww, ft_curckt->ci_symtab);
        if (err == 1) {
            /* The circuit was interrupted somewhere. */
            fprintf(cp_err, "%s simulation interrupted\n", what);
#ifdef XSPICE
            /* record error and return errchk */
            g_ipc.run_error = IPC_TRUE;
            if (g_ipc.enabled)
                ipc_send_errchk();
            /* gtri - end - 12/12/90 */
#endif
            err = 0;
        } else if (err == 2) {
            fprintf(cp_err, "%s simulation(s) aborted\n", what);
            ft_curckt->ci_inprogress = FALSE;
            err = 1;
        } else {
            ft_curckt->ci_inprogress = FALSE;
        }
    }
    /* close the rawfile */
    if (rawfileFp) {
        if (ftell(rawfileFp) == 0) {
            (void) fclose(rawfileFp);
            (void) unlink(wl->wl_word);
        } else {
            (void) fclose(rawfileFp);
        }
    }
    ft_curckt->ci_runonce = TRUE;
    ft_setflag = FALSE;

    /* va: garbage collection: unlink first word (inserted here) and tfree it */
    if (!dofile) {
        tfree(ww->wl_word);
        if (wl)
            wl->wl_prev = NULL;
        tfree(ww);
    }

    /* execute the .measure statements */
    if (!err && ft_curckt->ci_last_an && ft_curckt->ci_meas)
        do_measure(ft_curckt->ci_last_an, FALSE);

    return err;
}
예제 #18
0
void
ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlabel, char *ylabel, GRIDTYPE gridtype, PLOTTYPE plottype, struct dvec *vecs)
{
    FILE *file, *file_data;
    struct dvec *v, *scale = NULL;
    double xval, yval, extrange;
    int i, numVecs, linewidth, err, terminal_type;
    bool xlog, ylog, nogrid, markers;
    char buf[BSIZE_SP], pointstyle[BSIZE_SP], *text, plotstyle[BSIZE_SP], terminal[BSIZE_SP];

    char filename_data[128];
    char filename_plt[128];

    sprintf(filename_data, "%s.data", filename);
    sprintf(filename_plt, "%s.plt", filename);

    /* Sanity checking. */
    for (v = vecs, numVecs = 0; v; v = v->v_link2)
        numVecs++;

    if (numVecs == 0) {
        return;
    } else if (numVecs > GP_MAXVECTORS) {
        fprintf(cp_err, "Error: too many vectors for gnuplot.\n");
        return;
    }

    if (fabs((ylims[1]-ylims[0])/ylims[0]) < 1.0e-6) {
        fprintf(cp_err, "Error: range min ... max too small for using gnuplot.\n");
        fprintf(cp_err, "  Consider plotting with offset %g.\n", ylims[0]);
        return;
    }

    extrange = 0.05 * (ylims[1] - ylims[0]);

    if (!cp_getvar("gnuplot_terminal", CP_STRING, terminal)) {
        terminal_type = 1;
    } else {
        terminal_type = 1;
        if (cieq(terminal,"png"))
            terminal_type = 2;
    }

    if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth))
        linewidth = 1;
    if (linewidth < 1) linewidth = 1;

    if (!cp_getvar("pointstyle", CP_STRING, pointstyle)) {
        markers = FALSE;
    } else {
        if (cieq(pointstyle,"markers"))
            markers = TRUE;
        else
            markers = FALSE;
    }

    /* Make sure the gridtype is supported. */
    switch (gridtype) {
    case GRID_LIN:
        nogrid = xlog = ylog = FALSE;
        break;
    case GRID_XLOG:
        xlog = TRUE;
        nogrid = ylog = FALSE;
        break;
    case GRID_YLOG:
        ylog = TRUE;
        nogrid = xlog = FALSE;
        break;
    case GRID_LOGLOG:
        xlog = ylog = TRUE;
        nogrid = FALSE;
        break;
    case GRID_NONE:
        nogrid = TRUE;
        xlog = ylog = FALSE;
        break;
    default:
        fprintf(cp_err, "Error: grid type unsupported by gnuplot.\n");
        return;
    }

    /* Open the output gnuplot file. */
    if ((file = fopen(filename_plt, "w")) == NULL) {
        perror(filename);
        return;
    }

    /* Set up the file header. */
#if !defined(__MINGW__) && !defined(_MSC_VER)
    fprintf(file, "set terminal X11\n");
#endif
    if (title) {
        text = cp_unquote(title);
        fprintf(file, "set title \"%s\"\n", text);
        tfree(text);
    }
    if (xlabel) {
        text = cp_unquote(xlabel);
        fprintf(file, "set xlabel \"%s\"\n", text);
        tfree(text);
    }
    if (ylabel) {
        text = cp_unquote(ylabel);
        fprintf(file, "set ylabel \"%s\"\n", text);
        tfree(text);
    }
    if (!nogrid) {
        if (linewidth > 1)
            fprintf(file, "set grid lw %d \n" , linewidth);
        else
            fprintf(file, "set grid\n");
    }
    if (xlog) {
        fprintf(file, "set logscale x\n");
        if (xlims)
            fprintf(file, "set xrange [%1.0e:%1.0e]\n", 
                pow(10, floor(log10(xlims[0]))), pow(10, ceil(log10(xlims[1]))));
            fprintf(file, "set xrange [%e:%e]\n", xlims[0], xlims[1]);
            fprintf(file, "set mxtics 10\n");
            fprintf(file, "set grid mxtics\n");
    } else {
        fprintf(file, "unset logscale x \n");
        if (xlims)
            fprintf(file, "set xrange [%e:%e]\n", xlims[0], xlims[1]);
    }
    if (ylog) {
        fprintf(file, "set logscale y \n");
        if (ylims)
            fprintf(file, "set yrange [%1.0e:%1.0e]\n", 
                pow(10, floor(log10(ylims[0]))), pow(10, ceil(log10(ylims[1]))));
            fprintf(file, "set mytics 10\n");
            fprintf(file, "set grid mytics\n");
    } else {
        fprintf(file, "unset logscale y \n");
        if (ylims)
            fprintf(file, "set yrange [%e:%e]\n", ylims[0] - extrange, ylims[1] + extrange);
    }

    fprintf(file, "#set xtics 1\n");
    fprintf(file, "#set x2tics 1\n");
    fprintf(file, "#set ytics 1\n");
    fprintf(file, "#set y2tics 1\n");

    if (linewidth > 1)
        fprintf(file, "set border lw %d\n", linewidth);

    if (plottype == PLOT_COMB) {
        strcpy(plotstyle, "boxes");
    } else if (plottype == PLOT_POINT) {
        if (markers) {
            // fprintf(file, "Markers: True\n");
        } else {
            // fprintf(file, "LargePixels: True\n");
        }
        strcpy(plotstyle, "points");
    } else {
        strcpy(plotstyle, "lines");
    }

    /* Open the output gnuplot data file. */
    if ((file_data = fopen(filename_data, "w")) == NULL) {
        perror(filename);
        return;
    }
    fprintf(file, "set format y \"%%g\"\n");
    fprintf(file, "set format x \"%%g\"\n");
    fprintf(file, "plot ");
    i = 0;

    /* Write out the gnuplot command */
    for (v = vecs; v; v = v->v_link2) {
        scale = v->v_scale;
        if (v->v_name) {
            i = i + 2;
            if (i > 2) fprintf(file, ",\\\n");
            fprintf(file, "\'%s\' using %d:%d with %s lw %d title \"%s\" ",
                    filename_data, i-1, i, plotstyle, linewidth, v->v_name);
        }
    }
    fprintf(file, "\n");
    fprintf(file, "set terminal push\n");
    if (terminal_type == 1) {
        fprintf(file, "set terminal postscript eps color\n");
        fprintf(file, "set out \'%s.eps\'\n", filename);
    } else {
        fprintf(file, "set terminal png\n");
        fprintf(file, "set out \'%s.png\'\n", filename);
    }
    fprintf(file, "replot\n");
    fprintf(file, "set term pop\n");

    fprintf(file, "replot\n");

    (void) fclose(file);

    /* Write out the data and setup arrays */
    for (i = 0; i < scale->v_length; i++) {
        for (v = vecs; v; v = v->v_link2) {
            scale = v->v_scale;

            xval = isreal(scale) ?
                   scale->v_realdata[i] : realpart(scale->v_compdata[i]);

            yval = isreal(v) ?
                   v->v_realdata[i] : realpart(v->v_compdata[i]);

            fprintf(file_data, "%e %e ", xval, yval);
        }
        fprintf(file_data, "\n");
    }

    (void) fclose(file_data);

#if defined(__MINGW32__) || defined(_MSC_VER)
    /* for external fcn system() */
    // (void) sprintf(buf, "start /B wgnuplot %s -" ,  filename_plt);
    (void) sprintf(buf, "start /B wgnuplot -persist %s " ,  filename_plt);
    _flushall();
#else
    /* for external fcn system() from LINUX environment */
    (void) sprintf(buf, "xterm -e gnuplot %s - &", filename_plt);
#endif
    err = system(buf);

}
예제 #19
0
파일: nutinp.c 프로젝트: fengmm521/myspice
//void
//inp_nutsource(FILE *fp, bool comfile, char *filename)
void
inp_nutsource(FILE *fp, int comfile, char *filename)
{
    struct line *deck, *dd, *ld;
    struct line *realdeck, *options = NULL;
    char *tt = NULL, name[BSIZE_SP], *s, *t;
    //bool commands = FALSE;
    int commands = FALSE;
    wordlist *wl = NULL, *end = NULL;
    wordlist *controls = NULL;
    FILE *lastin, *lastout, *lasterr;

    deck = inp_readall(fp, NULL, comfile, FALSE); /* still to check if . or filename instead of NULL */
    if (!deck)
        return;

    realdeck = inp_deckcopy(deck);

    if (!comfile) {
        /* Save the title before INPgetTitle gets it. */
        tt = copy(deck->li_line);
        if (!deck->li_next)
            fprintf(cp_err, "Warning: no lines in deck...\n");
    }
    (void) fclose(fp);

    /* Now save the IO context and start a new control set...  After
     * we are done with the source we'll put the old file descriptors
     * back.  I guess we could use a FILE stack, but since this routine
     * is recursive anyway...
     */
    lastin = cp_curin;
    lastout = cp_curout;
    lasterr = cp_curerr;
    cp_curin = cp_in;
    cp_curout = cp_out;
    cp_curerr = cp_err;

    cp_pushcontrol();

    /* We should now go through the deck and execute front-end
     * commands and remove them. Front-end commands are enclosed by
     * the lines .control and .endc, unless comfile
     * is TRUE, in which case every line must be a front-end command.
     * There are too many problems with matching the first word on
     * the line.
     */
    ld = deck;
    if (comfile) {
        /* This is easy. */
        for (dd = deck; dd; dd = ld) {
            ld = dd->li_next;
            if ((dd->li_line[0] == '*') && (dd->li_line[1] != '#'))
                continue;
            if (!ciprefix(".control", dd->li_line) &&
                !ciprefix(".endc", dd->li_line)) {
                if (dd->li_line[0] == '*')
                    (void) cp_evloop(dd->li_line + 2);
                else
                    (void) cp_evloop(dd->li_line);
            }
            tfree(dd->li_line);
            tfree(dd);
        }
    } else {
        for (dd = deck->li_next; dd; dd = ld->li_next) {
            if ((dd->li_line[0] == '*') && (dd->li_line[1] != '#')) {
                ld = dd;
                continue;
            }
            (void) strncpy(name, dd->li_line, BSIZE_SP);
            for (s = name; *s && isspace(*s); s++)
                ;
            for (t = s; *t && !isspace(*t); t++)
                ;
            *t = '\0';

            if (ciprefix(".control", dd->li_line)) {
                ld->li_next = dd->li_next;
                tfree(dd->li_line);
                tfree(dd);
                if (commands)
                    fprintf(cp_err, "Warning: redundant .control line\n");
                else
                    commands = TRUE;
            } else if (ciprefix(".endc", dd->li_line)) {
                ld->li_next = dd->li_next;
                tfree(dd->li_line);
                tfree(dd);
                if (commands)
                    commands = FALSE;
                else
                    fprintf(cp_err, "Warning: misplaced .endc line\n");
            } else if (commands || prefix("*#", dd->li_line)) {
                controls = wl_cons(NULL, controls);
                wl = controls;
                if (prefix("*#", dd->li_line))
                    wl->wl_word = copy(dd->li_line + 2);
                else
                    wl->wl_word = dd->li_line;
                ld->li_next = dd->li_next;
                tfree(dd);
            } else if (!*dd->li_line) {
                /* So blank lines in com files don't get
                 * considered as circuits.
                 */
                ld->li_next = dd->li_next;
                tfree(dd->li_line);
                tfree(dd);
            } else {
                inp_casefix(s);
                inp_casefix(dd->li_line);
                if (eq(s, ".width") || ciprefix(".four", s) ||
                    eq(s, ".plot")  ||
                    eq(s, ".print") ||
                    eq(s, ".save"))
                {
                    wl_append_word(&wl, &end, copy(dd->li_line));
                    ld->li_next = dd->li_next;
                    tfree(dd->li_line);
                    tfree(dd);
                } else {
                    ld = dd;
                }
            }
        }
        if (deck->li_next) {
            /* There is something left after the controls. */
            fprintf(cp_out, "\nCircuit: %s\n\n", tt);
            fprintf(stderr, "\nCircuit: %s\n\n", tt);

            /* Now expand subcircuit macros. Note that we have to
             * fix the case before we do this but after we
             * deal with the commands.
             */
            if (!cp_getvar("nosubckt", CP_BOOL, NULL))
                deck->li_next = inp_subcktexpand(deck->li_next);
            deck->li_actual = realdeck;
            nutinp_dodeck(deck, tt, wl, FALSE, options, filename);
        }

        /* Now that the deck is loaded, do the commands... */
        controls = wl_reverse(controls);
        for (wl = controls; wl; wl = wl->wl_next)
            (void) cp_evloop(wl->wl_word);
        wl_free(controls);
    }

    /* Now reset everything.  Pop the control stack, and fix up the IO
     * as it was before the source.
     */
    cp_popcontrol();

    cp_curin = lastin;
    cp_curout = lastout;
    cp_curerr = lasterr;

    tfree(tt);
}
예제 #20
0
파일: diff.c 프로젝트: fengmm521/myspice
void
com_diff(wordlist *wl)
{
    double vntol, abstol, reltol, tol, cmax, cm1, cm2;
    struct plot *p1, *p2 = NULL;
    struct dvec *v1, *v2;
    double d1, d2;
    ngcomplex_t c1, c2, c3;
    int i, j;
    char *v1_name;          /* cannonical v1 name */
    char *v2_name;          /* cannonical v2 name */
    NGHASHPTR crossref_p;   /* cross reference hash table */
    SPICE_DSTRING ibuf;     /* used to build cannonical name */
    wordlist *tw;
    char numbuf[BSIZE_SP], numbuf2[BSIZE_SP], numbuf3[BSIZE_SP], numbuf4[BSIZE_SP]; /* For printnum */

    if (!cp_getvar("diff_vntol", CP_REAL, &vntol))
        vntol = 1.0e-6;
    if (!cp_getvar("diff_abstol", CP_REAL, &abstol))
        abstol = 1.0e-12;
    if (!cp_getvar("diff_reltol", CP_REAL, &reltol))
        reltol = 0.001;

    /* Let's try to be clever about defaults. This code is ugly. */
    if (!wl || !wl->wl_next) {
        if (plot_list && plot_list->pl_next && !plot_list->pl_next->pl_next) {
            p1 = plot_list;
            p2 = plot_list->pl_next;
            if (wl && !eq(wl->wl_word, p1->pl_typename) &&
                !eq(wl->wl_word, p2->pl_typename)) {
                fprintf(cp_err, "Error: no such plot \"%s\"\n",
                        wl->wl_word);
                return;
            }
            fprintf(cp_err, "Plots are \"%s\" and \"%s\"\n",
                    plot_list->pl_typename,
                    plot_list->pl_next->pl_typename);
            if (wl)
                wl = NULL;
        } else {
            fprintf(cp_err, "Error: plot names not given.\n");
            return;
        }
    } else {
        for (p1 = plot_list; p1; p1 = p1->pl_next)
            if (eq(wl->wl_word, p1->pl_typename))
                break;
        if (!p1) {
            fprintf(cp_err, "Error: no such plot %s\n", wl->wl_word);
            return;
        }
        wl = wl->wl_next;
    }

    if (!p2) {
        for (p2 = plot_list; p2; p2 = p2->pl_next)
            if (eq(wl->wl_word, p2->pl_typename))
                break;
        if (!p2) {
            fprintf(cp_err, "Error: no such plot %s\n", wl->wl_word);
            return;
        }
        wl = wl->wl_next;
    }

    /* Now do some tests to make sure these plots are really the
     * same type, etc.
     */
    if (!eq(p1->pl_name, p2->pl_name))
        fprintf(cp_err,
                "Warning: plots %s and %s seem to be of different types\n",
                p1->pl_typename, p2->pl_typename);
    if (!eq(p1->pl_title, p2->pl_title))
        fprintf(cp_err,
                "Warning: plots %s and %s seem to be from different circuits\n",
                p1->pl_typename, p2->pl_typename);

    /* This may not be the best way to do this.  It wasn't :).  The original
     * was O(n2) - not good.  Now use a hash table to reduce it to O(n). */
    for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next)
        v1->v_link2 = NULL;

    spice_dstring_init(&ibuf);
    crossref_p = nghash_init(NGHASH_MIN_SIZE);
    nghash_unique(crossref_p, FALSE);

    for (v2 = p2->pl_dvecs; v2; v2 = v2->v_next) {
        v2->v_link2 = NULL;
        v2_name = cannonical_name(v2->v_name, &ibuf);
        nghash_insert(crossref_p, v2_name, v2);
    }

    for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next) {
        v1_name = cannonical_name(v1->v_name, &ibuf);
        for (v2 = nghash_find(crossref_p, v1_name);
             v2;
             v2 = nghash_find_again(crossref_p, v1_name))
        {
            if (!v2->v_link2 &&
                ((v1->v_flags & (VF_REAL | VF_COMPLEX)) ==
                 (v2->v_flags & (VF_REAL | VF_COMPLEX))) &&
                (v1->v_type == v2->v_type))
            {
                v1->v_link2 = v2;
                v2->v_link2 = v1;
                break;
            }
        }
    }

    spice_dstring_free(&ibuf);
    nghash_free(crossref_p, NULL, NULL);

    for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next)
        if (!v1->v_link2)
            fprintf(cp_err,
                    ">>> %s vector %s in %s not in %s, or of wrong type\n",
                    isreal(v1) ? "real" : "complex",
                    v1->v_name, p1->pl_typename, p2->pl_typename);

    for (v2 = p2->pl_dvecs; v2; v2 = v2->v_next)
        if (!v2->v_link2)
            fprintf(cp_err,
                    ">>> %s vector %s in %s not in %s, or of wrong type\n",
                    isreal(v2) ? "real" : "complex",
                    v2->v_name, p2->pl_typename, p1->pl_typename);

    /* Throw out the ones that aren't in the arg list */
    if (wl && !eq(wl->wl_word, "all")) {    /* Just in case */
        for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next)
            if (v1->v_link2) {
                for (tw = wl; tw; tw = tw->wl_next)
                    if (nameeq(v1->v_name, tw->wl_word))
                        break;
                if (!tw)
                    v1->v_link2 = NULL;
            }
        for (v2 = p2->pl_dvecs; v2; v2 = v2->v_next)
            if (v2->v_link2) {
                for (tw = wl; tw; tw = tw->wl_next)
                    if (nameeq(v2->v_name, tw->wl_word))
                        break;
                if (!tw)
                    v2->v_link2 = NULL;
            }
    }

    /* Now we have all the vectors linked to their twins.  Travel
     * down each one and print values that differ enough.
     */
    for (v1 = p1->pl_dvecs; v1; v1 = v1->v_next) {
        if (!v1->v_link2)
            continue;
        v2 = v1->v_link2;
        if (v1->v_type == SV_VOLTAGE)
            tol = vntol;
        else
            tol = abstol;
        j = MAX(v1->v_length, v2->v_length);
        for (i = 0; i < j; i++) {
            if (v1->v_length <= i) {
                fprintf(cp_out,
                        ">>> %s is %d long in %s and %d long in %s\n",
                        v1->v_name, v1->v_length,
                        p1->pl_typename, v2->v_length, p2->pl_typename);
                break;
            } else if (v2->v_length <= i) {
                fprintf(cp_out,
                        ">>> %s is %d long in %s and %d long in %s\n",
                        v2->v_name, v2->v_length,
                        p2->pl_typename, v1->v_length, p1->pl_typename);
                break;
            } else {
                if (isreal(v1)) {
                    d1 = v1->v_realdata[i];
                    d2 = v2->v_realdata[i];
                    if (MAX(fabs(d1), fabs(d2)) * reltol +
                        tol < fabs(d1 - d2)) {
                        printnum(numbuf, d1);
                        fprintf(cp_out,
                                "%s.%s[%d] = %-15s ",
                                p1->pl_typename, v1->v_name, i, numbuf);
                        printnum(numbuf, d2);
                        fprintf(cp_out,
                                "%s.%s[%d] = %s\n",
                                p2->pl_typename, v2->v_name, i, numbuf);
                    }
                } else {
                    c1 = v1->v_compdata[i];
                    c2 = v2->v_compdata[i];
                    realpart(c3) = realpart(c1) - realpart(c2);
                    imagpart(c3) = imagpart(c1) - imagpart(c2);
                    /* Stupid evil PC compilers */
                    cm1 = cmag(c1);
                    cm2 = cmag(c2);
                    cmax = MAX(cm1, cm2);
                    if (cmax * reltol + tol < cmag(c3)) {

                        printnum(numbuf, realpart(c1));
                        printnum(numbuf2, imagpart(c1));
                        printnum(numbuf3, realpart(c2));
                        printnum(numbuf4, imagpart(c2));

                        fprintf(cp_out,
                                "%s.%s[%d] = %-10s, %-10s %s.%s[%d] = %-10s, %s\n",
                                p1->pl_typename, v1->v_name, i,
                                numbuf,
                                numbuf2,
                                p2->pl_typename, v2->v_name, i,
                                numbuf3,
                                numbuf4);
                    }
                }
            }
        }
    }
}
예제 #21
0
int
BSIM3v1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
{
    double scale;

    BSIM3v1instance *here = (BSIM3v1instance*)inst;

    if ( !cp_getvar( "scale", CP_REAL, (double*) &scale ) ) scale = 1;

    switch(param) 
    {   case BSIM3v1_W:
            here->BSIM3v1w = value->rValue*scale;
            here->BSIM3v1wGiven = TRUE;
            break;
        case BSIM3v1_L:
            here->BSIM3v1l = value->rValue*scale;
            here->BSIM3v1lGiven = TRUE;
            break;
	    case BSIM3v1_M:
            here->BSIM3v1m = value->rValue;
            here->BSIM3v1mGiven = TRUE;
            break;
        case BSIM3v1_AS:
            here->BSIM3v1sourceArea = value->rValue*scale*scale;
            here->BSIM3v1sourceAreaGiven = TRUE;
            break;
        case BSIM3v1_AD:
            here->BSIM3v1drainArea = value->rValue*scale*scale;
            here->BSIM3v1drainAreaGiven = TRUE;
            break;
        case BSIM3v1_PS:
            here->BSIM3v1sourcePerimeter = value->rValue*scale;
            here->BSIM3v1sourcePerimeterGiven = TRUE;
            break;
        case BSIM3v1_PD:
            here->BSIM3v1drainPerimeter = value->rValue*scale;
            here->BSIM3v1drainPerimeterGiven = TRUE;
            break;
        case BSIM3v1_NRS:
            here->BSIM3v1sourceSquares = value->rValue;
            here->BSIM3v1sourceSquaresGiven = TRUE;
            break;
        case BSIM3v1_NRD:
            here->BSIM3v1drainSquares = value->rValue;
            here->BSIM3v1drainSquaresGiven = TRUE;
            break;
        case BSIM3v1_OFF:
            here->BSIM3v1off = value->iValue;
            break;
        case BSIM3v1_IC_VBS:
            here->BSIM3v1icVBS = value->rValue;
            here->BSIM3v1icVBSGiven = TRUE;
            break;
        case BSIM3v1_IC_VDS:
            here->BSIM3v1icVDS = value->rValue;
            here->BSIM3v1icVDSGiven = TRUE;
            break;
        case BSIM3v1_IC_VGS:
            here->BSIM3v1icVGS = value->rValue;
            here->BSIM3v1icVGSGiven = TRUE;
            break;
        case BSIM3v1_NQSMOD:
            here->BSIM3v1nqsMod = value->iValue;
            here->BSIM3v1nqsModGiven = TRUE;
            break;
        case BSIM3v1_IC:
            switch(value->v.numValue){
                case 3:
                    here->BSIM3v1icVBS = *(value->v.vec.rVec+2);
                    here->BSIM3v1icVBSGiven = TRUE;
                case 2:
                    here->BSIM3v1icVGS = *(value->v.vec.rVec+1);
                    here->BSIM3v1icVGSGiven = TRUE;
                case 1:
                    here->BSIM3v1icVDS = *(value->v.vec.rVec);
                    here->BSIM3v1icVDSGiven = TRUE;
                    break;
                default:
                    return(E_BADPARM);
            }
            break;
        default:
            return(E_BADPARM);
    }
    return(OK);
}
예제 #22
0
int
fourier(wordlist *wl, struct plot *current_plot)
{
    struct dvec *time, *vec;
    struct pnode *pn, *names;
    double *ff, fundfreq, *data = NULL;
    int nfreqs, fourgridsize, polydegree;
    double *freq, *mag, *phase, *nmag, *nphase;  /* Outputs from CKTfour */
    double thd, *timescale = NULL;
    char *s;
    int i, err, fw;
    char xbuf[20];
    int shift;
    int rv = 1;

    char newvecname[32];
    struct dvec *n;
    int newveccount = 1;
    static int callstof = 1;

    if (!current_plot)
        return 1;

    sprintf(xbuf, "%1.1e", 0.0);
    shift = (int) strlen(xbuf) - 7;
    if (!current_plot || !current_plot->pl_scale) {
        fprintf(cp_err, "Error: no vectors loaded.\n");
        return 1;
    }

    if (!cp_getvar("nfreqs", CP_NUM, &nfreqs) || nfreqs < 1)
        nfreqs = 10;
    if (!cp_getvar("polydegree", CP_NUM, &polydegree) || polydegree < 0)
        polydegree = 1;
    if (!cp_getvar("fourgridsize", CP_NUM, &fourgridsize) || fourgridsize < 1)
        fourgridsize = DEF_FOURGRIDSIZE;

    time = current_plot->pl_scale;
    if (!isreal(time)) {
        fprintf(cp_err, "Error: fourier needs real time scale\n");
        return 1;
    }
    s = wl->wl_word;
    if ((ff = ft_numparse(&s, FALSE)) == NULL || (*ff <= 0.0)) {
        fprintf(cp_err, "Error: bad fund freq %s\n", wl->wl_word);
        return 1;
    }
    fundfreq = *ff;

    freq = TMALLOC(double, nfreqs);
    mag = TMALLOC(double, nfreqs);
    phase = TMALLOC(double, nfreqs);
    nmag = TMALLOC(double, nfreqs);
    nphase = TMALLOC(double, nfreqs);

    wl = wl->wl_next;
    names = ft_getpnames(wl, TRUE);
    for (pn = names; pn; pn = pn->pn_next) {
        vec = ft_evaluate(pn);
        for (; vec; vec = vec->v_link2) {

            if (vec->v_length != time->v_length) {
                fprintf(cp_err,
                        "Error: lengths don't match: %d, %d\n",
                        vec->v_length, time->v_length);
                continue;
            }

            if (!isreal(vec)) {
                fprintf(cp_err, "Error: %s isn't real!\n", vec->v_name);
                continue;
            }

            if (polydegree) {
                double *dp, d;
                /* Build the grid... */
                timescale = TMALLOC(double, fourgridsize);
                data = TMALLOC(double, fourgridsize);
                dp = ft_minmax(time, TRUE);
                /* Now get the last fund freq... */
                d = 1 / fundfreq;   /* The wavelength... */
                if (dp[1] - dp[0] < d) {
                    fprintf(cp_err, "Error: wavelength longer than time span\n");
                    goto done;
                } else if (dp[1] - dp[0] > d) {
                    dp[0] = dp[1] - d;
                }

                d = (dp[1] - dp[0]) / fourgridsize;
                for (i = 0; i < fourgridsize; i++)
                    timescale[i] = dp[0] + i * d;

                /* Now interpolate the data... */
                if (!ft_interpolate(vec->v_realdata, data,
                                    time->v_realdata, vec->v_length,
                                    timescale, fourgridsize,
                                    polydegree)) {
                    fprintf(cp_err, "Error: can't interpolate\n");
                    goto done;
                }
            } else {
                fourgridsize = vec->v_length;
                data = vec->v_realdata;
                timescale = time->v_realdata;
            }

            err = CKTfour(fourgridsize, nfreqs, &thd, timescale,
                          data, fundfreq, freq, mag, phase, nmag,
                          nphase);
            if (err != OK) {
                ft_sperror(err, "fourier");
                goto done;
            }

            fprintf(cp_out, "Fourier analysis for %s:\n", vec->v_name);
            fprintf(cp_out,
                    "  No. Harmonics: %d, THD: %g %%, Gridsize: %d, Interpolation Degree: %d\n\n",
                    nfreqs, thd, fourgridsize,
                    polydegree);
            /* Each field will have width cp_numdgt + 6 (or 7
             * with HP-UX) + 1 if there is a - sign.
             */
            fw = ((cp_numdgt > 0) ? cp_numdgt : 6) + 5 + shift;
            fprintf(cp_out, "Harmonic %-*s %-*s %-*s %-*s %-*s\n",
                    fw, "Frequency", fw, "Magnitude",
                    fw, "Phase", fw, "Norm. Mag",
                    fw, "Norm. Phase");
            fprintf(cp_out, "-------- %-*s %-*s %-*s %-*s %-*s\n",
                    fw, "---------", fw, "---------",
                    fw, "-----", fw, "---------",
                    fw, "-----------");
            for (i = 0; i < nfreqs; i++) {
                char *pnumfr, *pnumma, *pnumph,  *pnumnm,   *pnumnp;
                pnumfr = pnum(freq[i]);
                pnumma = pnum(mag[i]);
                pnumph = pnum(phase[i]);
                pnumnm = pnum(nmag[i]);
                pnumnp = pnum(nphase[i]);
                fprintf(cp_out,
                        " %-4d    %-*s %-*s %-*s %-*s %-*s\n",
                        i,
                        fw, pnumfr,
                        fw, pnumma,
                        fw, pnumph,
                        fw, pnumnm,
                        fw, pnumnp);
                tfree(pnumfr);
                tfree(pnumma);
                tfree(pnumph);
                tfree(pnumnm);
                tfree(pnumnp);
            }
            fputs("\n", cp_out);

            /* generate name for new vector, using vec->name */
            sprintf(newvecname, "fourier%d%d", callstof, newveccount);

            /* create and assign a new vector n */
            /* with size 3 * nfreqs in current plot */
            n = alloc(struct dvec);
            ZERO(n, struct dvec);
            n->v_name = copy(newvecname);
            n->v_type = SV_NOTYPE;
            n->v_flags = (VF_REAL | VF_PERMANENT);
            n->v_length = 3 * nfreqs;
            n->v_numdims = 2;
            n->v_dims[0] = 3;
            n->v_dims[1] = nfreqs;

            n->v_realdata = TMALLOC(double, n->v_length);

            vec_new(n);

            /* store data in vector: freq, mag, phase */
            for (i = 0; i < nfreqs; i++) {
                n->v_realdata[i] = freq[i];
                n->v_realdata[i + nfreqs] = mag[i];
                n->v_realdata[i + 2 * nfreqs] = phase[i];
            }
            newveccount++;

            if (polydegree) {
                tfree(timescale);
                tfree(data);
            }
            timescale = NULL;
            data = NULL;
        }
    }
예제 #23
0
파일: xgraph.c 프로젝트: Anastien/ngspice
void
ft_xgraph(double *xlims, double *ylims, char *filename, char *title, char *xlabel, char *ylabel, GRIDTYPE gridtype, PLOTTYPE plottype, struct dvec *vecs)
{
    FILE *file;
    struct dvec *v, *scale;
    double xval, yval;
    int i, numVecs, linewidth;
    bool xlog, ylog, nogrid, markers;
    char buf[BSIZE_SP], pointstyle[BSIZE_SP], *text;

    /* Sanity checking. */
    for (v = vecs, numVecs = 0; v; v = v->v_link2)
        numVecs++;

    if (numVecs == 0) {
        return;
    } else if (numVecs > XG_MAXVECTORS) {
        fprintf(cp_err, "Error: too many vectors for Xgraph.\n");
        return;
    }

    if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth))
        linewidth = 1;

    if (linewidth < 1)
        linewidth = 1;

    if (!cp_getvar("pointstyle", CP_STRING, pointstyle)) {
        markers = FALSE;
    } else {
        if (cieq(pointstyle, "markers"))
            markers = TRUE;
        else
            markers = FALSE;
    }

    /* Make sure the gridtype is supported. */
    switch (gridtype) {
    case GRID_LIN:
        nogrid = xlog = ylog = FALSE;
        break;
    case GRID_XLOG:
        xlog = TRUE;
        nogrid = ylog = FALSE;
        break;
    case GRID_YLOG:
        ylog = TRUE;
        nogrid = xlog = FALSE;
        break;
    case GRID_LOGLOG:
        xlog = ylog = TRUE;
        nogrid = FALSE;
        break;
    case GRID_NONE:
        nogrid = TRUE;
        xlog = ylog = FALSE;
        break;
    default:
        fprintf(cp_err, "Error: grid type unsupported by Xgraph.\n");
        return;
    }

    /* Open the output file. */
    if ((file = fopen(filename, "w")) == NULL) {
        perror(filename);
        return;
    }

    /* Set up the file header. */
    if (title) {
        text = cp_unquote(title);
        fprintf(file, "TitleText: %s\n", text);
        tfree(text);
    }
    if (xlabel) {
        text = cp_unquote(xlabel);
        fprintf(file, "XUnitText: %s\n", text);
        tfree(text);
    }
    if (ylabel) {
        text = cp_unquote(ylabel);
        fprintf(file, "YUnitText: %s\n", text);
        tfree(text);
    }
    if (nogrid) {
        fprintf(file, "Ticks: True\n");
    }

    if (xlog) {
        fprintf(file, "LogX: True\n");
        if (xlims) {
            fprintf(file, "XLowLimit:  % e\n", log10(xlims[0]));
            fprintf(file, "XHighLimit: % e\n", log10(xlims[1]));
        }
    } else {
        if (xlims) {
            fprintf(file, "XLowLimit:  % e\n", xlims[0]);
            fprintf(file, "XHighLimit: % e\n", xlims[1]);
        }
    }

    if (ylog) {
        fprintf(file, "LogY: True\n");
        if (ylims) {
            fprintf(file, "YLowLimit:  % e\n", log10(ylims[0]));
            fprintf(file, "YHighLimit: % e\n", log10(ylims[1]));
        }
    } else {
        if (ylims) {
            fprintf(file, "YLowLimit:  % e\n", ylims[0]);
            fprintf(file, "YHighLimit: % e\n", ylims[1]);
        }
    }

    fprintf(file, "LineWidth: %d\n", linewidth);
    fprintf(file, "BoundBox: True\n");

    if (plottype == PLOT_COMB) {
        fprintf(file, "BarGraph: True\n");
        fprintf(file, "NoLines: True\n");
    } else if (plottype == PLOT_POINT) {
        if (markers)
            fprintf(file, "Markers: True\n");
        else
            fprintf(file, "LargePixels: True\n");
        fprintf(file, "NoLines: True\n");
    }

    /* Write out the data. */
    for (v = vecs; v; v = v->v_link2) {
        scale = v->v_scale;
        if (v->v_name)
            fprintf(file, "\"%s\"\n", v->v_name);

        for (i = 0; i < scale->v_length; i++) {
            xval = isreal(scale) ?
                scale->v_realdata[i] : realpart(scale->v_compdata[i]);
            yval = isreal(v) ?
                v->v_realdata[i] : realpart(v->v_compdata[i]);
            fprintf(file, "% e % e\n", xval, yval);
        }
        fprintf(file, "\n");
    }

    (void) fclose(file);
    (void) sprintf(buf, "xgraph %s &", filename);
    (void) system(buf);
}
예제 #24
0
파일: x11.c 프로젝트: amarnathmhn/ngspice
/* should be able to do this by sleight of hand on graph parameters */
static void
zoomin(GRAPH *graph)
{
/* note: need to add circular boxes XXX */

    int x0, y0, x1, y1;
    double fx0, fx1, fy0, fy1, ftemp;
    char buf[BSIZE_SP];
    char buf2[128];
    char *t;

    Window rootwindow, childwindow;
    int rootx, rooty;
    unsigned int state;
    int x, y, upperx, uppery;
    unsigned width, height;

    /* open box and get area to zoom in on */

    XQueryPointer(display, DEVDEP(graph).window, &rootwindow,
                  &childwindow, &rootx, &rooty, &x0, &y0, &state);

    x = x1 = x0 + BOXSIZE;
    y = y1 = y0 + BOXSIZE;

    upperx = x0;
    uppery = y0;

    width  = BOXSIZE;
    height = BOXSIZE;

    XDrawRectangle(display, DEVDEP(graph).window, xorgc,
                   upperx, uppery, width, height);

    XWarpPointer(display, None, DEVDEP(graph).window, 0, 0, 0, 0, x1, y1);

    while (state & Button3Mask) {
        if (x != x1 || y != y1) {

            x1 = x;
            y1 = y;

            XDrawRectangle(display, DEVDEP(graph).window, xorgc,
                           upperx, uppery, width, height);

            upperx = MIN(x1, x0);
            uppery = MIN(y1, y0);

            width  = (unsigned) ABS(x1 - x0);
            height = (unsigned) ABS(y1 - y0);

            XDrawRectangle(display, DEVDEP(graph).window, xorgc,
                           upperx, uppery, width, height);
        }
        XQueryPointer(display, DEVDEP(graph).window, &rootwindow,
                      &childwindow, &rootx, &rooty, &x, &y, &state);
    }
    XDrawRectangle(display, DEVDEP(graph).window, xorgc,
                   upperx, uppery, width, height);

    X_ScreentoData(graph, x0, y0, &fx0, &fy0);
    X_ScreentoData(graph, x1, y1, &fx1, &fy1);

    if (fx0 > fx1) {
        ftemp = fx0;
        fx0 = fx1;
        fx1 = ftemp;
    }
    if (fy0 > fy1) {
        ftemp = fy0;
        fy0 = fy1;
        fy1 = ftemp;
    }

    strncpy(buf2, graph->plotname, sizeof(buf2));
    if ((t = strchr(buf2, ':')) != NULL)
        *t = 0;

    if (!eq(plot_cur->pl_typename, buf2)) {
        (void) sprintf(buf,
                       "setplot %s; %s xlimit %.20e %.20e ylimit %.20e %.20e; setplot $curplot\n",
                       buf2, graph->commandline, fx0, fx1, fy0, fy1);
    } else {
        (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n",
                       graph->commandline, fx0, fx1, fy0, fy1);
    }

/* don't use the following if using GNU Readline or BSD EditLine */
#if !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE)
    {
        wordlist *wl;

        /* hack for Gordon Jacobs */
        /* add to history list if plothistory is set */
        if (cp_getvar("plothistory", CP_BOOL, NULL)) {
            wl = cp_parse(buf);
            (void) cp_addhistent(cp_event++, wl);
        }
    }
#endif /* !defined(HAVE_GNUREADLINE) && !defined(HAVE_BSDEDITLINE) */

    (void) cp_evloop(buf);
}
예제 #25
0
파일: x11.c 프로젝트: amarnathmhn/ngspice
static void
initcolors(GRAPH *graph)
{
    int i;
    static char *colornames[] = {   "black",    /* white */
                                    "white", "red", "blue",
                                    "orange", "green", "pink",
                                    "brown", "khaki", "plum",
                                    "orchid", "violet", "maroon",
                                    "turquoise", "sienna", "coral",
                                    "cyan", "magenta", "gold",
                                    "yellow", ""
    };

    XColor visualcolor, exactcolor;
    char buf[BSIZE_SP], colorstring[BSIZE_SP];
    int xmaxcolors = NUMCOLORS; /* note: can we get rid of this? */

    if (numdispplanes == 1) {
        /* black and white */
        xmaxcolors = 2;
        DEVDEP(graph).colors[0] = DEVDEP(graph).view->core.background_pixel;
        if (DEVDEP(graph).colors[0] == WhitePixel(display, DefaultScreen(display)))
            DEVDEP(graph).colors[1] = BlackPixel(display, DefaultScreen(display));
        else
            DEVDEP(graph).colors[1] = WhitePixel(display, DefaultScreen(display));

    } else {
        if (numdispplanes < NXPLANES)
            xmaxcolors = 1 << numdispplanes;

        for (i = 0; i < xmaxcolors; i++) {
            (void) sprintf(buf, "color%d", i);
            if (!cp_getvar(buf, CP_STRING, colorstring))
                (void) strcpy(colorstring, colornames[i]);
            if (!XAllocNamedColor(display,
                                  DefaultColormap(display, DefaultScreen(display)),
                                  colorstring, &visualcolor, &exactcolor)) {
                (void) sprintf(ErrorMessage,
                               "can't get color %s\n", colorstring);
                externalerror(ErrorMessage);
                DEVDEP(graph).colors[i] = i ? BlackPixel(display,
                                                         DefaultScreen(display))
                    : WhitePixel(display, DefaultScreen(display));
                continue;
            }
            DEVDEP(graph).colors[i] = visualcolor.pixel;

            /* MW. I don't need this, everyone must know what he is doing
               if (i > 0 &&
               DEVDEP(graph).colors[i] == DEVDEP(graph).view->core.background_pixel) {
               DEVDEP(graph).colors[i] = DEVDEP(graph).colors[0];
               } */

        }
        /* MW. Set Beackgroound here */
        XSetWindowBackground(display, DEVDEP(graph).window, DEVDEP(graph).colors[0]);

        /* if (DEVDEP(graph).colors[0] != DEVDEP(graph).view->core.background_pixel) {
        DEVDEP(graph).colors[0] = DEVDEP(graph).view->core.background_pixel;
        } */
    }

    for (i = xmaxcolors; i < NUMCOLORS; i++) {
        DEVDEP(graph).colors[i] = DEVDEP(graph).colors[i + 1 - xmaxcolors];
    }
}
예제 #26
0
파일: b3v32par.c 프로젝트: imr/ngspice
int
BSIM3v32param (int param, IFvalue *value, GENinstance *inst, IFvalue *select)
{
    double scale;

    BSIM3v32instance *here = (BSIM3v32instance*)inst;

    NG_IGNORE(select);

    if (!cp_getvar("scale", CP_REAL, &scale, 0))
        scale = 1;

    switch(param)
    {   case BSIM3v32_W:
            here->BSIM3v32w = value->rValue*scale;
            here->BSIM3v32wGiven = TRUE;
            break;
        case BSIM3v32_L:
            here->BSIM3v32l = value->rValue*scale;
            here->BSIM3v32lGiven = TRUE;
            break;
        case BSIM3v32_M:
            here->BSIM3v32m = value->rValue;
            here->BSIM3v32mGiven = TRUE;
            break;
        case BSIM3v32_AS:
            here->BSIM3v32sourceArea = value->rValue*scale*scale;
            here->BSIM3v32sourceAreaGiven = TRUE;
            break;
        case BSIM3v32_AD:
            here->BSIM3v32drainArea = value->rValue*scale*scale;
            here->BSIM3v32drainAreaGiven = TRUE;
            break;
        case BSIM3v32_PS:
            here->BSIM3v32sourcePerimeter = value->rValue*scale;
            here->BSIM3v32sourcePerimeterGiven = TRUE;
            break;
        case BSIM3v32_PD:
            here->BSIM3v32drainPerimeter = value->rValue*scale;
            here->BSIM3v32drainPerimeterGiven = TRUE;
            break;
        case BSIM3v32_NRS:
            here->BSIM3v32sourceSquares = value->rValue;
            here->BSIM3v32sourceSquaresGiven = TRUE;
            break;
        case BSIM3v32_NRD:
            here->BSIM3v32drainSquares = value->rValue;
            here->BSIM3v32drainSquaresGiven = TRUE;
            break;
        case BSIM3v32_OFF:
            here->BSIM3v32off = value->iValue;
            break;
        case BSIM3v32_IC_VBS:
            here->BSIM3v32icVBS = value->rValue;
            here->BSIM3v32icVBSGiven = TRUE;
            break;
        case BSIM3v32_IC_VDS:
            here->BSIM3v32icVDS = value->rValue;
            here->BSIM3v32icVDSGiven = TRUE;
            break;
        case BSIM3v32_IC_VGS:
            here->BSIM3v32icVGS = value->rValue;
            here->BSIM3v32icVGSGiven = TRUE;
            break;
        case BSIM3v32_NQSMOD:
            here->BSIM3v32nqsMod = value->iValue;
            here->BSIM3v32nqsModGiven = TRUE;
            break;
        case BSIM3v32_GEO:
            here->BSIM3v32geo = value->iValue;
            here->BSIM3v32geoGiven = TRUE;
            break;
        case BSIM3v32_DELVTO:
            here->BSIM3v32delvto = value->rValue;
            here->BSIM3v32delvtoGiven = TRUE;
            break;
        case BSIM3v32_MULU0:
            here->BSIM3v32mulu0 = value->rValue;
            here->BSIM3v32mulu0Given = TRUE;
            break;
        case BSIM3v32_IC:
            switch(value->v.numValue){
                case 3:
                    here->BSIM3v32icVBS = *(value->v.vec.rVec+2);
                    here->BSIM3v32icVBSGiven = TRUE;
                case 2:
                    here->BSIM3v32icVGS = *(value->v.vec.rVec+1);
                    here->BSIM3v32icVGSGiven = TRUE;
                case 1:
                    here->BSIM3v32icVDS = *(value->v.vec.rVec);
                    here->BSIM3v32icVDSGiven = TRUE;
                    break;
                default:
                    return(E_BADPARM);
            }
            break;
        default:
            return(E_BADPARM);
    }
    return(OK);
}
예제 #27
0
파일: outitf.c 프로젝트: Anastien/ngspice
static int
beginPlot(JOB *analysisPtr, CKTcircuit *circuitPtr, char *cktName, char *analName, char *refName, int refType, int numNames, char **dataNames, int dataType, bool windowed, runDesc **runp)
{
    runDesc *run;
    struct save_info *saves;
    bool *savesused = NULL;
    int numsaves;
    int i, j, depind = 0;
    char namebuf[BSIZE_SP], parambuf[BSIZE_SP], depbuf[BSIZE_SP];
    char *ch, tmpname[BSIZE_SP];
    bool saveall  = TRUE;
    bool savealli = FALSE;
    char *an_name;
    /*to resume a run saj
     *All it does is reassign the file pointer and return (requires *runp to be NULL if this is not needed)
     */

    if (dataType == 666 && numNames == 666) {
        run = *runp;
        run->writeOut = ft_getOutReq(&run->fp, &run->runPlot, &run->binary,
                                     run->type, run->name);

    } else {
        /*end saj*/

        /* Check to see if we want to print informational data. */
        if (cp_getvar("printinfo", CP_BOOL, NULL))
            fprintf(cp_err, "(debug printing enabled)\n");

        /* Check to see if we want to save only interpolated data. */
        if (cp_getvar("interp", CP_BOOL, NULL)) {
            interpolated = TRUE;
            fprintf(cp_out, "Warning: Interpolated raw file data!\n\n");
        }

        *runp = run = TMALLOC(struct runDesc, 1);

        /* First fill in some general information. */
        run->analysis = analysisPtr;
        run->circuit = circuitPtr;
        run->name = copy(cktName);
        run->type = copy(analName);
        run->windowed = windowed;
        run->numData = 0;

        an_name = spice_analysis_get_name(analysisPtr->JOBtype);
        ft_curckt->ci_last_an = an_name;

        /* Now let's see which of these things we need.  First toss in the
         * reference vector.  Then toss in anything that getSaves() tells
         * us to save that we can find in the name list.  Finally unpack
         * the remaining saves into parameters.
         */
        numsaves = ft_getSaves(&saves);
        if (numsaves) {
            savesused = TMALLOC(bool, numsaves);
            saveall = FALSE;
            for (i = 0; i < numsaves; i++) {
                if (saves[i].analysis && !cieq(saves[i].analysis, an_name)) {
                    /* ignore this one this time around */
                    savesused[i] = TRUE;
                    continue;
                }

                /*  Check for ".save all" and new synonym ".save allv"  */

                if (cieq(saves[i].name, "all") || cieq(saves[i].name, "allv")) {
                    saveall = TRUE;
                    savesused[i] = TRUE;
                    saves[i].used = 1;
                    continue;
                }

                /*  And now for the new ".save alli" option  */

                if (cieq(saves[i].name, "alli")) {
                    savealli = TRUE;
                    savesused[i] = TRUE;
                    saves[i].used = 1;
                    continue;
                }
            }
        }

        /* Pass 0. */
        if (refName) {
            addDataDesc(run, refName, refType, -1);
            for (i = 0; i < numsaves; i++)
                if (!savesused[i] && name_eq(saves[i].name, refName)) {
                    savesused[i] = TRUE;
                    saves[i].used = 1;
                }
        } else {
            run->refIndex = -1;
        }


        /* Pass 1. */
        if (numsaves && !saveall) {
            for (i = 0; i < numsaves; i++)
                if (!savesused[i])
                    for (j = 0; j < numNames; j++)
                        if (name_eq(saves[i].name, dataNames[j])) {
                            addDataDesc(run, dataNames[j], dataType, j);
                            savesused[i] = TRUE;
                            saves[i].used = 1;
                            break;
                        }
        } else {
            for (i = 0; i < numNames; i++)
                if (!refName || !name_eq(dataNames[i], refName))
                    /*  Save the node as long as it's an internal device node  */
                    if (!strstr(dataNames[i], "#internal") &&
                        !strstr(dataNames[i], "#source") &&
                        !strstr(dataNames[i], "#drain") &&
                        !strstr(dataNames[i], "#collector") &&
                        !strstr(dataNames[i], "#emitter") &&
                        !strstr(dataNames[i], "#base"))
                    {
                        addDataDesc(run, dataNames[i], dataType, i);
                    }
        }

        /* Pass 1 and a bit.
           This is a new pass which searches for all the internal device
           nodes, and saves the terminal currents instead  */

        if (savealli) {
            depind = 0;
            for (i = 0; i < numNames; i++) {
                if (strstr(dataNames[i], "#internal") ||
                    strstr(dataNames[i], "#source") ||
                    strstr(dataNames[i], "#drain") ||
                    strstr(dataNames[i], "#collector") ||
                    strstr(dataNames[i], "#emitter") ||
                    strstr(dataNames[i], "#base"))
                {
                    tmpname[0] = '@';
                    tmpname[1] = '\0';
                    strncat(tmpname, dataNames[i], BSIZE_SP-1);
                    ch = strchr(tmpname, '#');

                    if (strstr(ch, "#collector")) {
                        strcpy(ch, "[ic]");
                    } else if (strstr(ch, "#base")) {
                        strcpy(ch, "[ib]");
                    } else if (strstr(ch, "#emitter")) {
                        strcpy(ch, "[ie]");
                        if (parseSpecial(tmpname, namebuf, parambuf, depbuf))
                            addSpecialDesc(run, tmpname, namebuf, parambuf, depind);
                        strcpy(ch, "[is]");
                    } else if (strstr(ch, "#drain")) {
                        strcpy(ch, "[id]");
                        if (parseSpecial(tmpname, namebuf, parambuf, depbuf))
                            addSpecialDesc(run, tmpname, namebuf, parambuf, depind);
                        strcpy(ch, "[ig]");
                    } else if (strstr(ch, "#source")) {
                        strcpy(ch, "[is]");
                        if (parseSpecial(tmpname, namebuf, parambuf, depbuf))
                            addSpecialDesc(run, tmpname, namebuf, parambuf, depind);
                        strcpy(ch, "[ib]");
                    } else if (strstr(ch, "#internal") && (tmpname[1] == 'd')) {
                        strcpy(ch, "[id]");
                    } else {
                        fprintf(cp_err,
                                "Debug: could output current for %s\n", tmpname);
                        continue;
                    }
                    if (parseSpecial(tmpname, namebuf, parambuf, depbuf)) {
                        if (*depbuf) {
                            fprintf(stderr,
                                    "Warning : unexpected dependent variable on %s\n", tmpname);
                        } else {
                            addSpecialDesc(run, tmpname, namebuf, parambuf, depind);
                        }
                    }
                }
            }
        }


        /* Pass 2. */
        for (i = 0; i < numsaves; i++) {

            if (savesused[i])
                continue;

            if (!parseSpecial(saves[i].name, namebuf, parambuf, depbuf)) {
                if (saves[i].analysis)
                    fprintf(cp_err, "Warning: can't parse '%s': ignored\n",
                            saves[i].name);
                continue;
            }

            /* Now, if there's a dep variable, do we already have it? */
            if (*depbuf) {
                for (j = 0; j < run->numData; j++)
                    if (name_eq(depbuf, run->data[j].name))
                        break;
                if (j == run->numData) {
                    /* Better add it. */
                    for (j = 0; j < numNames; j++)
                        if (name_eq(depbuf, dataNames[j]))
                            break;
                    if (j == numNames) {
                        fprintf(cp_err,
                                "Warning: can't find '%s': value '%s' ignored\n",
                                depbuf, saves[i].name);
                        continue;
                    }
                    addDataDesc(run, dataNames[j], dataType, j);
                    savesused[i] = TRUE;
                    saves[i].used = 1;
                    depind = j;
                } else {
                    depind = run->data[j].outIndex;
                }
            }

            addSpecialDesc(run, saves[i].name, namebuf, parambuf, depind);
        }

        if (numsaves) {
            for (i = 0; i < numsaves; i++) {
                tfree(saves[i].analysis);
                tfree(saves[i].name);
            }
            tfree(saves);
            tfree(savesused);
        }

        if (numNames &&
            ((run->numData == 1 && run->refIndex != -1) ||
             (run->numData == 0 && run->refIndex == -1)))
        {
            fprintf(cp_err, "Error: no data saved for %s; analysis not run\n",
                    spice_analysis_get_description(analysisPtr->JOBtype));
            return E_NOTFOUND;
        }

        /* Now that we have our own data structures built up, let's see what
         * nutmeg wants us to do.
         */
        run->writeOut = ft_getOutReq(&run->fp, &run->runPlot, &run->binary,
                                     run->type, run->name);

        if (run->writeOut) {
            fileInit(run);
        } else {
            plotInit(run);
            if (refName)
                run->runPlot->pl_ndims = 1;
        }
    }

    /* define storage for old and new data, to allow interpolation */
    if (interpolated && run->circuit->CKTcurJob->JOBtype == 4) {
        valueold = TMALLOC(double, run->numData);
        for (i = 0; i < run->numData; i++)
            valueold[i] = 0.0;
        valuenew = TMALLOC(double, run->numData);
    }
예제 #28
0
파일: capparam.c 프로젝트: imr/ngspice
/* ARGSUSED */
int
CAPparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
{
    double scale;

    CAPinstance *here = (CAPinstance*)inst;

    NG_IGNORE(select);

    if (!cp_getvar("scale", CP_REAL, &scale, 0))
        scale = 1;

    switch(param) {
    case CAP_CAP:
        here->CAPcapac = value->rValue;
        if (!here->CAPmGiven)
            here->CAPm = 1.0;
        here->CAPcapGiven = TRUE;
        break;
    case CAP_IC:
        here->CAPinitCond = value->rValue;
        here->CAPicGiven = TRUE;
        break;
    case CAP_TEMP:
        here->CAPtemp = value->rValue + CONSTCtoK;
        here->CAPtempGiven = TRUE;
        break;
    case CAP_DTEMP:
        here->CAPdtemp = value->rValue;
        here->CAPdtempGiven = TRUE;
        break;
    case CAP_WIDTH:
        here->CAPwidth = value->rValue * scale;
        here->CAPwidthGiven = TRUE;
        break;
    case CAP_LENGTH:
        here->CAPlength = value->rValue * scale;
        here->CAPlengthGiven = TRUE;
        break;
    case CAP_M:
        here->CAPm = value->rValue;
        here->CAPmGiven = TRUE;
        break;
    case CAP_SCALE:
        here->CAPscale = value->rValue;
        here->CAPscaleGiven = TRUE;
        break;
    case CAP_CAP_SENS:
        here->CAPsenParmNo = value->iValue;
        break;
    case CAP_TC1:
        here->CAPtc1 = value->rValue;
        here->CAPtc1Given = TRUE;
        break;
    case CAP_TC2:
        here->CAPtc2 = value->rValue;
        here->CAPtc2Given = TRUE;
        break;
    case CAP_BV_MAX:
        here->CAPbv_max = value->rValue;
        here->CAPbv_maxGiven = TRUE;
        break;
    default:
        return(E_BADPARM);
    }
    return(OK);
}
예제 #29
0
int HSM2param(
    int param,
    IFvalue *value,
    GENinstance *inst,
    IFvalue *select)
{
    double scale;

    HSM2instance *here = (HSM2instance*)inst;

    NG_IGNORE(select);

    if (!cp_getvar("scale", CP_REAL, &scale))
        scale = 1;

    switch (param) {
    case HSM2_W:
        here->HSM2_w = value->rValue * scale;
        here->HSM2_w_Given = TRUE;
        break;
    case HSM2_L:
        here->HSM2_l = value->rValue * scale;
        here->HSM2_l_Given = TRUE;
        break;
    case HSM2_AS:
        here->HSM2_as = value->rValue * scale * scale;
        here->HSM2_as_Given = TRUE;
        break;
    case HSM2_AD:
        here->HSM2_ad = value->rValue * scale * scale;
        here->HSM2_ad_Given = TRUE;
        break;
    case HSM2_PS:
        here->HSM2_ps = value->rValue * scale;
        here->HSM2_ps_Given = TRUE;
        break;
    case HSM2_PD:
        here->HSM2_pd = value->rValue * scale;
        here->HSM2_pd_Given = TRUE;
        break;
    case HSM2_NRS:
        here->HSM2_nrs = value->rValue;
        here->HSM2_nrs_Given = TRUE;
        break;
    case HSM2_NRD:
        here->HSM2_nrd = value->rValue;
        here->HSM2_nrd_Given = TRUE;
        break;
    case HSM2_TEMP:
        here->HSM2_temp = value->rValue;
        here->HSM2_temp_Given = TRUE;
        break;
    case HSM2_DTEMP:
        here->HSM2_dtemp = value->rValue;
        here->HSM2_dtemp_Given = TRUE;
        break;
    case HSM2_OFF:
        here->HSM2_off = value->iValue;
        break;
    case HSM2_IC_VBS:
        here->HSM2_icVBS = value->rValue;
        here->HSM2_icVBS_Given = TRUE;
        break;
    case HSM2_IC_VDS:
        here->HSM2_icVDS = value->rValue;
        here->HSM2_icVDS_Given = TRUE;
        break;
    case HSM2_IC_VGS:
        here->HSM2_icVGS = value->rValue;
        here->HSM2_icVGS_Given = TRUE;
        break;
    case HSM2_IC:
        switch (value->v.numValue) {
        case 3:
            here->HSM2_icVBS = *(value->v.vec.rVec + 2);
            here->HSM2_icVBS_Given = TRUE;
        case 2:
            here->HSM2_icVGS = *(value->v.vec.rVec + 1);
            here->HSM2_icVGS_Given = TRUE;
        case 1:
            here->HSM2_icVDS = *(value->v.vec.rVec);
            here->HSM2_icVDS_Given = TRUE;
            break;
        default:
            return(E_BADPARM);
        }
        break;
    case  HSM2_CORBNET:
        here->HSM2_corbnet = value->iValue;
        here->HSM2_corbnet_Given = TRUE;
        break;
    case  HSM2_RBPB:
        here->HSM2_rbpb = value->rValue;
        here->HSM2_rbpb_Given = TRUE;
        break;
    case  HSM2_RBPD:
        here->HSM2_rbpd = value->rValue;
        here->HSM2_rbpd_Given = TRUE;
        break;
    case  HSM2_RBPS:
        here->HSM2_rbps = value->rValue;
        here->HSM2_rbps_Given = TRUE;
        break;
    case  HSM2_RBDB:
        here->HSM2_rbdb = value->rValue;
        here->HSM2_rbdb_Given = TRUE;
        break;
    case  HSM2_RBSB:
        here->HSM2_rbsb = value->rValue;
        here->HSM2_rbsb_Given = TRUE;
        break;
    case  HSM2_CORG:
        here->HSM2_corg = value->iValue;
        here->HSM2_corg_Given = TRUE;
        break;
    /*   case  HSM2_RSHG: */
    /*     here->HSM2_rshg = value->rValue; */
    /*     here->HSM2_rshg_Given = TRUE; */
    /*     break; */
    case  HSM2_NGCON:
        here->HSM2_ngcon = value->rValue;
        here->HSM2_ngcon_Given = TRUE;
        break;
    case  HSM2_XGW:
        here->HSM2_xgw = value->rValue;
        here->HSM2_xgw_Given = TRUE;
        break;
    case  HSM2_XGL:
        here->HSM2_xgl = value->rValue;
        here->HSM2_xgl_Given = TRUE;
        break;
    case  HSM2_NF:
        here->HSM2_nf = value->rValue;
        here->HSM2_nf_Given = TRUE;
        break;
    case  HSM2_SA:
        here->HSM2_sa = value->rValue;
        here->HSM2_sa_Given = TRUE;
        break;
    case  HSM2_SB:
        here->HSM2_sb = value->rValue;
        here->HSM2_sb_Given = TRUE;
        break;
    case  HSM2_SD:
        here->HSM2_sd = value->rValue;
        here->HSM2_sd_Given = TRUE;
        break;
    case  HSM2_NSUBCDFM:
        here->HSM2_nsubcdfm = value->rValue;
        here->HSM2_nsubcdfm_Given = TRUE;
        break;
    case  HSM2_MPHDFM:
        here->HSM2_mphdfm = value->rValue;
        here->HSM2_mphdfm_Given = TRUE;
        break;
    case  HSM2_M:
        here->HSM2_m = value->rValue;
        here->HSM2_m_Given = TRUE;
        break;

    /* WPE */
    case HSM2_SCA:
        here->HSM2_sca = value->rValue;
        here->HSM2_sca_Given = TRUE;
        break;
    case HSM2_SCB:
        here->HSM2_scb = value->rValue;
        here->HSM2_scb_Given = TRUE;
        break;
    case HSM2_SCC:
        here->HSM2_scc= value->rValue;
        here->HSM2_scc_Given = TRUE;
        break;
    default:
        return(E_BADPARM);
    }
    return(OK);
}
예제 #30
0
파일: runcoms2.c 프로젝트: Anastien/ngspice
void
com_resume(wordlist *wl)
{
    struct dbcomm *db;
    int err;

    /*rawfile output saj*/
    bool dofile = FALSE;
    char buf[BSIZE_SP];
    bool ascii = AsciiRawFile;
    /*end saj*/

    NG_IGNORE(wl);

    /*saj fix segment*/
    if (!ft_curckt) {
        fprintf(cp_err, "Error: there aren't any circuits loaded.\n");
        return;
    } else if (ft_curckt->ci_ckt == NULL) { /* Set noparse? */
        fprintf(cp_err, "Error: circuit not parsed.\n");
        return;
    }
    /*saj*/

    if (ft_curckt->ci_inprogress == FALSE) {
        fprintf(cp_err, "Note: run starting\n");
        com_run(NULL);
        return;
    }
    ft_curckt->ci_inprogress = TRUE;
    ft_setflag = TRUE;

    reset_trace();
    for (db = dbs, resumption = FALSE; db; db = db->db_next)
        if (db->db_type == DB_IPLOT || db->db_type == DB_IPLOTALL)
            resumption = TRUE;

    /*rawfile output saj*/
    if (last_used_rawfile)
        dofile = TRUE;

    if (cp_getvar("filetype", CP_STRING, buf)) {
        if (eq(buf, "binary"))
            ascii = FALSE;
        else if (eq(buf, "ascii"))
            ascii = TRUE;
        else
            fprintf(cp_err,
                    "Warning: strange file type \"%s\" (using \"ascii\")\n", buf);
    }

    if (dofile) {
        if (!last_used_rawfile)
            rawfileFp = stdout;
#if defined(__MINGW32__) || defined(_MSC_VER)
        /* ask if binary or ASCII, open file with w or wb   hvogt 15.3.2000 */
        else if (ascii) {
            if ((rawfileFp = fopen(last_used_rawfile, "a")) == NULL) {
                setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE);
                perror(last_used_rawfile);
                ft_setflag = FALSE;
                return;
            }
        } else if (!ascii) {
            if ((rawfileFp = fopen(last_used_rawfile, "ab")) == NULL) {
                setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE);
                perror(last_used_rawfile);
                ft_setflag = FALSE;
                return;
            }
        }
        /*---------------------------------------------------------------------------*/
#else
        else if (!(rawfileFp = fopen(last_used_rawfile, "a"))) {
            setvbuf(rawfileFp, rawfileBuf, _IOFBF, RAWBUF_SIZE);
            perror(last_used_rawfile);
            ft_setflag = FALSE;
            return;
        }
#endif
        rawfileBinary = !ascii;
    } else {
        rawfileFp = NULL;
    } /* if dofile */

    /*end saj*/

    err = if_run(ft_curckt->ci_ckt, "resume", NULL,
                 ft_curckt->ci_symtab);

    /*close rawfile saj*/
    if (rawfileFp) {
        if (ftell(rawfileFp) == 0) {
            (void) fclose(rawfileFp);
            (void) unlink(last_used_rawfile);
        } else {
            (void) fclose(rawfileFp);
        }
    }
    /*end saj*/

    if (err == 1) {
        /* The circuit was interrupted somewhere. */

        fprintf(cp_err, "simulation interrupted\n");
    } else if (err == 2) {
        fprintf(cp_err, "simulation aborted\n");
        ft_curckt->ci_inprogress = FALSE;
    } else {
        ft_curckt->ci_inprogress = FALSE;
    }
}