diff --git a/src/callback.c b/src/callback.c index a13fd78a..d2d01081 100644 --- a/src/callback.c +++ b/src/callback.c @@ -660,9 +660,8 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int my_strdup2(1506, &express, ntok); } if(strstr(express, " ")) { - j = xctx->graph_nvars; for(dset = 0 ; dset < xctx->graph_datasets; dset++) { - plot_raw_custom_data(sweep_idx, ofs, ofs + xctx->graph_npoints[dset] - 1, express); + j = plot_raw_custom_data(sweep_idx, ofs, ofs + xctx->graph_npoints[dset] - 1, express); ofs += xctx->graph_npoints[dset]; } } else { diff --git a/src/draw.c b/src/draw.c index d6989414..485c0421 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1767,6 +1767,7 @@ static void draw_graph_points(int idx, int first, int last, register SPICE_DATA *gv = xctx->graph_values[idx]; dbg(1, "draw_graph_points: idx=%d, first=%d, last=%d, wcnt=%d\n", idx, first, last, wcnt); + if(idx == -1) return; digital = gr->digital; if(digital) { s1 = DIG_NWAVES; /* 1/DIG_NWAVES waveforms fit in graph if unscaled vertically */ @@ -2392,7 +2393,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr) char *saven, *savec, *saves, *nptr, *cptr, *sptr; const char *ntok, *ctok, *stok; char *bus_msb = NULL; - int wcnt = 0, idx; + int wcnt = 0, idx, expression; int measure_p = -1; double measure_x; double measure_prev_x; @@ -2439,6 +2440,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr) draw_graph_variables(wcnt, wave_color, n_nodes, sweep_idx, flags, ntok, stok, bus_msb, gr); /* if ntok following possible 'alias;' definition contains spaces --> custom data plot */ idx = -1; + expression = 0; if(xctx->graph_values && !bus_msb) { if(strstr(ntok, ";")) { my_strdup2(1191, &express, find_nth(ntok, ";", 2)); @@ -2446,11 +2448,11 @@ void draw_graph(int i, const int flags, Graph_ctx *gr) my_strdup2(1192, &express, ntok); } if(strstr(express, " ")) { - idx = xctx->graph_nvars; + expression = 1; } } /* quickly find index number of ntok variable to be plotted */ - if( idx == xctx->graph_nvars || (idx = get_raw_index(bus_msb ? bus_msb : express)) != -1 ) { + if( expression || (idx = get_raw_index(bus_msb ? bus_msb : express)) != -1 ) { int p, dset, ofs; int poly_npoints; int first, last; @@ -2499,7 +2501,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr) sweep_idx, wcnt, n_nodes, gr); } } else { - if(idx == xctx->graph_nvars) plot_raw_custom_data(sweep_idx, first, last, express); + if(expression) idx = plot_raw_custom_data(sweep_idx, first, last, express); draw_graph_points(idx, first, last, point, wave_color, wcnt, n_nodes, gr); } } @@ -2540,7 +2542,7 @@ void draw_graph(int i, const int flags, Graph_ctx *gr) sweep_idx, wcnt, n_nodes, gr); } } else { - if(idx == xctx->graph_nvars) plot_raw_custom_data(sweep_idx, first, last, express); + if(expression) idx = plot_raw_custom_data(sweep_idx, first, last, express); draw_graph_points(idx, first, last, point, wave_color, wcnt, n_nodes, gr); } } diff --git a/src/save.c b/src/save.c index 29272734..2b018074 100644 --- a/src/save.c +++ b/src/save.c @@ -536,7 +536,7 @@ typedef struct { double prevx; } Stack1; -void plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr) +int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr) { int i, p, idx; const char *n; @@ -554,7 +554,7 @@ void plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr) if(stackptr1 >= STACKMAX -2) { dbg(0, "stack overflow in graph expression parsing. Interrupted\n"); my_free(576, &ntok_copy); - return; + return -1; } ntok_ptr = NULL; dbg(1, " plot_raw_custom_data(): n = %s\n", n); @@ -584,7 +584,7 @@ void plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr) if(idx == -1) { dbg(1, "plot_raw_custom_data(): no data found: %s\n", n); my_free(645, &ntok_copy); - return; /* no data found in raw file */ + return -1; /* no data found in raw file */ } stack1[stackptr1].i = idx; stackptr1++; @@ -716,6 +716,7 @@ void plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr) } /* for(i = 0; i < stackptr1; i++) */ y[p] = stack2[0]; } + return xctx->graph_nvars; } double get_raw_value(int dataset, int idx, int point) diff --git a/src/xschem.h b/src/xschem.h index f1f50c07..6857655f 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1028,7 +1028,7 @@ extern int get_raw_index(const char *node); extern void free_rawfile(int dr); extern int read_rawfile(const char *f); extern double get_raw_value(int dataset, int idx, int point); -extern void plot_raw_custom_data(int sweep_idx, int first, int last, const char *ntok); +extern int plot_raw_custom_data(int sweep_idx, int first, int last, const char *ntok); extern int schematic_waves_loaded(void); extern int edit_wave_attributes(int what, int i, Graph_ctx *gr); extern void draw_graph(int i, int flags, Graph_ctx *gr);