ngspice/src/frontend/plotting/xgraph.c

167 lines
3.8 KiB
C
Raw Normal View History

2000-04-27 22:03:57 +02:00
/**********
Copyright 1992 Regents of the University of California. All rights reserved.
Author: 1992 David A. Gates, U. C. Berkeley CAD Group
**********/
/*
* Xgraph-11 plots.
*/
#include "ngspice.h"
#include "cpdefs.h"
#include "ftedefs.h"
* src/Makefile.am src/main.c src/sconvert.c src/analysis/cktdisto.c src/analysis/cktnoise.c src/analysis/noisean.c: Updates for the new header files. * src/maths/cmaths/cmath1.c src/maths/cmaths/cmath2.c src/maths/cmaths/cmath3.c src/maths/cmaths/cmath4.c: Updates for the new header files. * src/frontend/.cvsignore src/frontend/Makefile.am: Updates for the new files. * src/frontend/agraf.c src/frontend/aspice.c src/frontend/breakp.c src/frontend/breakp2.c src/frontend/circuits.c src/frontend/cpitf.c src/frontend/debugcom.c src/frontend/define.c src/frontend/diff.c src/frontend/dimens.c src/frontend/display.c src/frontend/doplot.c src/frontend/dotcards.c src/frontend/evaluate.c src/frontend/fourier.c src/frontend/graf.c src/frontend/grid.c src/frontend/inp.c src/frontend/inpcom.c src/frontend/interp.c src/frontend/linear.c src/frontend/misccoms.c src/frontend/misccoms.h src/frontend/miscvars.c src/frontend/mw_coms.c src/frontend/newcoms.c src/frontend/nutinp.c src/frontend/options.c src/frontend/outitf.c src/frontend/parse.c src/frontend/plotcurv.c src/frontend/points.c src/frontend/postcoms.c src/frontend/rawfile.c src/frontend/runcoms.c src/frontend/runcoms2.c src/frontend/shyu.c src/frontend/spec.c src/frontend/spiceif.c src/frontend/typesdef.c src/frontend/vectors.c src/frontend/where.c src/frontend/postcoms.c: Updates for the new header files. Some commands have moved into the new files below. * src/frontend/README src/frontend/com_compose.c src/frontend/com_compose.h src/frontend/com_display.c src/frontend/com_display.h src/frontend/com_let.c src/frontend/com_let.h src/frontend/com_setscale.c src/frontend/com_setscale.h src/frontend/commands.c src/frontend/commands.h src/frontend/completion.h src/frontend/streams.h src/frontend/testcommands.c: Separation into different com_* commands. This is a start. The rest of the subdirectory needs doing. * src/include/complex.h src/include/cpdefs.h src/include/cpextern.h src/include/cpstd.h src/include/fteconst.h src/include/ftedata.h src/include/ftedev.h src/include/fteext.h src/include/ftegraph.h src/include/fteparse.h src/include/dvec.h src/include/grid.h src/include/plot.h src/include/pnode.h src/include/sim.h src/include/variable.h src/include/wordlist.h src/include/bool.h: Separation of header files into smaller pieces. This limits recompilation to only the affected source files. The original header files have a warning message embedded to flag obsoleted use. * src/frontend/compose.c src/frontend/compose.h src/frontend/nutctab.c src/frontend/nutctab.h src/frontend/plot5.c src/frontend/plot5.h src/frontend/spcmdtab.c src/frontend/x11.c src/frontend/x11.h src/frontend/xgraph.c src/frontend/xgraph.h: Moved these files into src/frontend/plotting subdirectory. * src/frontend/plotting/.cvsignore src/frontend/plotting/Makefile.am src/frontend/plotting/plot5.c src/frontend/plotting/plot5.h src/frontend/plotting/plotting.c src/frontend/plotting/plotting.h src/frontend/plotting/pvec.c src/frontend/plotting/pvec.h src/frontend/plotting/x11.c src/frontend/plotting/x11.h src/frontend/plotting/xgraph.c src/frontend/plotting/xgraph.h: The new libplotting library with automake and CVS infrastructure.
2000-05-06 16:12:51 +02:00
#include "dvec.h"
2000-04-27 22:03:57 +02:00
#include "fteparse.h"
#include "xgraph.h"
#define XG_MAXVECTORS 64
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", VT_NUM, &linewidth))
linewidth = 1;
if (linewidth < 1) linewidth = 1;
if (!cp_getvar("pointstyle", VT_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"))) {
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 );
return;
}