From 91e40f1ecb2fc7dd55bde29cb43604e5272d6336 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 22 Feb 2019 22:36:44 +0100 Subject: [PATCH 1/7] remove bug 388: enable plot unit W for plotting @q1[p] --- src/frontend/outitf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/frontend/outitf.c b/src/frontend/outitf.c index 5f754c627..2d9858be9 100644 --- a/src/frontend/outitf.c +++ b/src/frontend/outitf.c @@ -905,7 +905,7 @@ guess_type(const char *name) type = SV_TEMP; else if (cieq(name, "res-sweep")) type = SV_RES; - else if ((*name == '@') && substring("[g", name)) + else if ((*name == '@') && substring("[g", name)) /* token starting with [g */ type = SV_ADMITTANCE; else if ((*name == '@') && substring("[c", name)) type = SV_CAPACITANCE; @@ -913,6 +913,8 @@ guess_type(const char *name) type = SV_CURRENT; else if ((*name == '@') && substring("[q", name)) type = SV_CHARGE; + else if ((*name == '@') && substring("[p]", name)) /* token is exactly [p] */ + type = SV_POWER; else type = SV_VOLTAGE; From b2aaa44bb49e3d1ba3892295f92a8812469e9610 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 23 Feb 2019 21:55:59 +0100 Subject: [PATCH 2/7] patch no. 30 by astx: don't show command window if gnuplot_terminal is set to png/quit --- src/frontend/plotting/gnuplot.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index 1ff24fa01..7242ef1c4 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -83,6 +83,8 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab terminal_type = 1; if (cieq(terminal,"png")) terminal_type = 2; + if (cieq(terminal,"png/quit")) + terminal_type = 3; } if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth, 0)) @@ -216,6 +218,12 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab } fprintf(file, "set format y \"%%g\"\n"); fprintf(file, "set format x \"%%g\"\n"); + + if (terminal_type == 3) { + fprintf(file, "set terminal png noenhanced\n"); + fprintf(file, "set out \'%s.png\'\n", filename); + } + fprintf(file, "plot "); i = 0; @@ -234,20 +242,26 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab /* do not print an eps or png file if filename start with 'np_' */ if (!ciprefix("np_", filename)) { - fprintf(file, "set terminal push\n"); + if (terminal_type != 3) + fprintf(file, "set terminal push\n"); if (terminal_type == 1) { fprintf(file, "set terminal postscript eps color noenhanced\n"); fprintf(file, "set out \'%s.eps\'\n", filename); } - else { + if (terminal_type == 2) { fprintf(file, "set terminal png noenhanced\n"); fprintf(file, "set out \'%s.png\'\n", filename); } - fprintf(file, "replot\n"); - fprintf(file, "set term pop\n"); + if (terminal_type != 3) { + fprintf(file, "replot\n"); + fprintf(file, "set term pop\n"); + } } - fprintf(file, "replot\n"); + if (terminal_type == 3) + fprintf(file, "exit\n"); + else + fprintf(file, "replot\n"); (void) fclose(file); @@ -293,7 +307,12 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab _flushall(); #else /* for external fcn system() from LINUX environment */ - (void) sprintf(buf, "xterm -e gnuplot %s - &", filename_plt); + if (terminal_type == 3) { + fprintf(cp_out, "writing plot to file %s\n", filename_plt); + (void) sprintf(buf, "gnuplot %s", filename_plt); + } + else + (void) sprintf(buf, "xterm -e gnuplot %s - &", filename_plt); #endif err = system(buf); From 6952c4fb7e45ebb162b88a200f053805d3f58583 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 23 Feb 2019 22:57:34 +0100 Subject: [PATCH 3/7] redo gnuplot_terminal: Do not save eps/png automatically none 1: do not print an eps or png file (default) png 2: print png file, keep command window open png/quit 3: print png file, quit command window eps 4: print eps file, keep command window open eps/quit 5: print eps file, quit command window --- src/frontend/plotting/gnuplot.c | 54 ++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index 7242ef1c4..a84925939 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -85,6 +85,10 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab terminal_type = 2; if (cieq(terminal,"png/quit")) terminal_type = 3; + if (cieq(terminal, "eps")) + terminal_type = 4; + if (cieq(terminal, "eps/quit")) + terminal_type = 5; } if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth, 0)) @@ -219,11 +223,6 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab fprintf(file, "set format y \"%%g\"\n"); fprintf(file, "set format x \"%%g\"\n"); - if (terminal_type == 3) { - fprintf(file, "set terminal png noenhanced\n"); - fprintf(file, "set out \'%s.png\'\n", filename); - } - fprintf(file, "plot "); i = 0; @@ -240,28 +239,35 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab } fprintf(file, "\n"); - /* do not print an eps or png file if filename start with 'np_' */ - if (!ciprefix("np_", filename)) { - if (terminal_type != 3) - fprintf(file, "set terminal push\n"); - if (terminal_type == 1) { - fprintf(file, "set terminal postscript eps color noenhanced\n"); - fprintf(file, "set out \'%s.eps\'\n", filename); - } - if (terminal_type == 2) { - fprintf(file, "set terminal png noenhanced\n"); - fprintf(file, "set out \'%s.png\'\n", filename); - } - if (terminal_type != 3) { - fprintf(file, "replot\n"); - fprintf(file, "set term pop\n"); - } + /* terminal_type + 1: do not print an eps or png file + 2: print png file, keep command window open + 3: print png file, quit command window + 4: print eps file, keep command window open + 5: print eps file, quit command window + */ + if ((terminal_type == 2) || (terminal_type == 4)) + fprintf(file, "set terminal push\n"); + if ((terminal_type == 4) || (terminal_type == 5)) { + fprintf(file, "set terminal postscript eps color noenhanced\n"); + fprintf(file, "set out \'%s.eps\'\n", filename); + } + if ((terminal_type == 2) || (terminal_type == 3)) { + fprintf(file, "set terminal png noenhanced\n"); + fprintf(file, "set out \'%s.png\'\n", filename); + } + if ((terminal_type == 2) || (terminal_type == 4)) { + fprintf(file, "replot\n"); + fprintf(file, "set term pop\n"); + fprintf(file, "replot\n"); } - if (terminal_type == 3) - fprintf(file, "exit\n"); - else + if ((terminal_type == 3) || (terminal_type == 5)) { fprintf(file, "replot\n"); + fprintf(file, "exit\n"); + } + + (void) fclose(file); From b6d0cf3bc67f7a915ffc8a3b0494bc1fde9bade7 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 23 Feb 2019 23:08:35 +0100 Subject: [PATCH 4/7] sprintf -> snprintf: prevent buffer overflow --- src/frontend/plotting/gnuplot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index a84925939..5a2c50c28 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -55,8 +55,8 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab char filename_data[128]; char filename_plt[128]; - sprintf(filename_data, "%s.data", filename); - sprintf(filename_plt, "%s.plt", filename); + snprintf(filename_data, 128, "%s.data", filename); + snprintf(filename_plt, 128, "%s.plt", filename); /* Sanity checking. */ for (v = vecs, numVecs = 0; v; v = v->v_link2) From b2b86f2011cba04bd583f419c4f8da197d32522e Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 23 Feb 2019 23:36:47 +0100 Subject: [PATCH 5/7] no plotting, only saving to file if gnuplot_terminal is eps/quit or png/quit --- src/frontend/plotting/gnuplot.c | 42 +++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index 5a2c50c28..f6286dbc1 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -223,21 +223,23 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab fprintf(file, "set format y \"%%g\"\n"); fprintf(file, "set format x \"%%g\"\n"); - fprintf(file, "plot "); - i = 0; + if ((terminal_type != 3) && (terminal_type != 5)) { + 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 ", - filename_data, i-1, i, plotstyle, linewidth); - quote_gnuplot_string(file, v->v_name); + /* 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 ", + filename_data, i - 1, i, plotstyle, linewidth); + quote_gnuplot_string(file, v->v_name); + } } + fprintf(file, "\n"); } - fprintf(file, "\n"); /* terminal_type 1: do not print an eps or png file @@ -263,7 +265,21 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab } if ((terminal_type == 3) || (terminal_type == 5)) { - fprintf(file, "replot\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 ", + filename_data, i - 1, i, plotstyle, linewidth); + quote_gnuplot_string(file, v->v_name); + } + } + fprintf(file, "\n"); fprintf(file, "exit\n"); } From 39ae5960531f50bb722feef5541bc35956f2f7ec Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 24 Feb 2019 01:00:06 +0100 Subject: [PATCH 6/7] delete the plt and data files after writing eps or png (only if gnuplot_terminal is set to eps/quit of png/quit) --- src/frontend/plotting/gnuplot.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index f6286dbc1..a3bd3ee74 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -16,7 +16,12 @@ #include "ngspice/dvec.h" #include "ngspice/fteparse.h" #include "gnuplot.h" - +#if defined(__MINGW32__) || defined(_MSC_VER) +#undef BOOLEAN +#include +#else +#include +#endif #define GP_MAXVECTORS 64 @@ -338,6 +343,23 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab #endif err = system(buf); + /* delete the plt and data files */ + if ((terminal_type == 3) || (terminal_type == 5)) { + /* wait for gnuplot generating eps or png file */ +#if defined(__MINGW32__) || defined(_MSC_VER) + Sleep(200); +#else + usleep(200000); +#endif + if (remove(filename_data)) { + fprintf(stderr, "Could not remove file %s\n", filename_data); + perror(NULL); + } + if (remove(filename_plt)) { + fprintf(stderr, "Could not remove file %s\n", filename_plt); + perror(NULL); + } + } } From 759afd1f844678dada95c2704e8aed56f8f047a8 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sun, 24 Feb 2019 19:39:54 +0100 Subject: [PATCH 7/7] fix a typo, correct writing to files under Linux --- src/frontend/plotting/gnuplot.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index a3bd3ee74..2d5220d03 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -20,7 +20,7 @@ #undef BOOLEAN #include #else -#include +#include #endif #define GP_MAXVECTORS 64 @@ -335,7 +335,11 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab #else /* for external fcn system() from LINUX environment */ if (terminal_type == 3) { - fprintf(cp_out, "writing plot to file %s\n", filename_plt); + fprintf(cp_out, "writing plot to file %s.png\n", filename); + (void) sprintf(buf, "gnuplot %s", filename_plt); + } + else if (terminal_type == 5) { + fprintf(cp_out, "writing plot to file %s.eps\n", filename); (void) sprintf(buf, "gnuplot %s", filename_plt); } else