diff --git a/ChangeLog b/ChangeLog index 6f88f3868..dea489e06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-02-27 Holger Vogt + * command.c, gnuplot.c, gnuplot.h, com_gnuplot.c, com_gnuplot.h, plotit.c: + new command 'wrdata file vecs' for simple tabular printout of data + 2010-02-26 Holger Vogt * vsrc.c, vsrcacct.c, vsrcask.c, vsrcdefs.h, vsrcload.c, vsrcpar.c: PWL source now has a repeat parameter (r=value) and a delay parameter diff --git a/src/frontend/com_gnuplot.c b/src/frontend/com_gnuplot.c index 57bb859c5..9e69b37b8 100644 --- a/src/frontend/com_gnuplot.c +++ b/src/frontend/com_gnuplot.c @@ -30,12 +30,41 @@ com_gnuplot(wordlist *wl) (void) plotit(wl, fname, "gnuplot"); -#if 0 /* Leave temp file sitting around so gnuplot can grab it from background. */ - if (tempf) - (void) unlink(fname); -#endif + if (tempf) { + tfree(fname); + } return; } + +/* data printout to file plotargs */ +void +com_write_simple(wordlist *wl) +{ + char *fname = NULL; + bool tempf = FALSE; + + if (wl) { + fname = wl->wl_word; + wl = wl->wl_next; + } + if (!wl) { + return; + } + if (cieq(fname, "temp") || cieq(fname, "tmp")) { + fname = smktemp("gp"); /* Is this the correct name ? */ + tempf = TRUE; + } + + (void) plotit(wl, fname, "writesimple"); + + /* Leave temp file sitting around so gnuplot can grab it from + background. */ + if (tempf) { + tfree(fname); + } + + return; +} \ No newline at end of file diff --git a/src/frontend/com_gnuplot.h b/src/frontend/com_gnuplot.h index 255d5717f..122cd744a 100644 --- a/src/frontend/com_gnuplot.h +++ b/src/frontend/com_gnuplot.h @@ -2,5 +2,5 @@ #define _COM_GNUPLOT_H void com_gnuplot(wordlist *wl); - +void com_write_simple(wordlist *wl); #endif diff --git a/src/frontend/commands.c b/src/frontend/commands.c index adbfa36ab..acae8ad88 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -164,6 +164,10 @@ struct comm spcp_coms[] = { { 1, 041000, 041000, 041000 }, E_DEFHMASK, 2, LOTS, (void (*)()) NULL, "file plotargs : Send plot to gnuplot." } , + { "wrdata", com_write_simple, FALSE, FALSE, TRUE, + { 1, 041000, 041000, 041000 }, E_DEFHMASK, 2, LOTS, + (void (*)()) NULL, + "file plotargs : Send plot data to file." } , { "hardcopy", com_hardcopy, FALSE, FALSE, TRUE, { 1, 041000, 041000, 041000 }, E_DEFHMASK, 0, LOTS, (void (*)()) NULL, @@ -576,6 +580,10 @@ struct comm nutcp_coms[] = { { 1, 041000, 041000, 041000 }, E_DEFHMASK, 2, LOTS, (void (*)()) NULL, "file plotargs : Send plot to gnuplot." } , + { "wrdata", com_write_simple, FALSE, FALSE, TRUE, + { 1, 041000, 041000, 041000 }, E_DEFHMASK, 2, LOTS, + (void (*)()) NULL, + "file plotargs : Send plot data to file." } , { "hardcopy", com_hardcopy, FALSE, FALSE, TRUE, { 1, 041000, 041000, 041000 }, E_DEFHMASK, 0, LOTS, (void (*)()) NULL, diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index 0234c1ae2..7c73c0e4d 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -172,13 +172,13 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab /* 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); - } + 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"); @@ -222,3 +222,59 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab return; } + +/* 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, yval; + int i, numVecs; + + char filename_data[128]; + + sprintf(filename_data, "%s.data", filename); + + /* 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, "w"))) { + 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]); + + 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 ); + + return; +} \ No newline at end of file diff --git a/src/frontend/plotting/gnuplot.h b/src/frontend/plotting/gnuplot.h index afc84c17c..30c5f0033 100644 --- a/src/frontend/plotting/gnuplot.h +++ b/src/frontend/plotting/gnuplot.h @@ -11,6 +11,9 @@ void ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, struct dvec *vecs); +void ft_writesimple(double *xlims, double *ylims, char *filename, char *title, + char *xlabel, char *ylabel, GRIDTYPE gridtype, PLOTTYPE plottype, + struct dvec *vecs); #endif diff --git a/src/frontend/plotting/plotit.c b/src/frontend/plotting/plotit.c index 47d24791c..bc0c67b5f 100644 --- a/src/frontend/plotting/plotit.c +++ b/src/frontend/plotting/plotit.c @@ -1017,6 +1017,17 @@ plotit(wordlist *wl, char *hcopy, char *devname) goto quit; } + if (devname && eq(devname, "writesimple")) { + /* Interface to simple write output */ + ft_writesimple(xlims, ylims, hcopy, + title ? title : vecs->v_plot->pl_title, + xlabel ? xlabel : ft_typabbrev(vecs->v_scale->v_type), + ylabel ? ylabel : ft_typabbrev(j), + gtype, ptype, vecs); + rtn = TRUE; + goto quit; + } + #ifdef TCL_MODULE if (devname && eq(devname, "blt")) { /* Just send the pairs to Tcl/Tk */ diff --git a/visualc/vngspice.sln b/visualc/vngspice.sln index 992f525b0..ae8bcc66a 100644 --- a/visualc/vngspice.sln +++ b/visualc/vngspice.sln @@ -25,12 +25,12 @@ Global {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|Win32.Build.0 = console_release|Win32 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|x64.ActiveCfg = console_release|x64 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.console_release|x64.Build.0 = console_release|x64 - {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|Win32.ActiveCfg = Release|Win32 - {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|Win32.Build.0 = Release|Win32 + {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|Win32.ActiveCfg = Debug|Win32 + {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|Win32.Build.0 = Debug|Win32 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|x64.ActiveCfg = Debug|x64 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Debug|x64.Build.0 = Debug|x64 - {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|Win32.ActiveCfg = Release|Win32 - {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|Win32.Build.0 = Release|Win32 + {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|Win32.ActiveCfg = Debug|Win32 + {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|Win32.Build.0 = Debug|Win32 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|x64.ActiveCfg = Release|x64 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.Release|x64.Build.0 = Release|x64 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.release64|Win32.ActiveCfg = release64|x64