# HG changeset patch # User jwe # Date 772821581 0 # Node ID 90964309100be3d8185f4ea1749a64a51ad1c5a4 # Parent 94b7d47cd06455504fdaf1a43a2c9042efe15232 [project @ 1994-06-28 16:39:41 by jwe] diff --git a/src/builtins.cc b/src/builtins.cc --- a/src/builtins.cc +++ b/src/builtins.cc @@ -184,6 +184,10 @@ "history [N] [-w file] [-r file] [-q]\n\n\ display, save, or load command history", }, + { "hold", -1, builtin_hold, + "hold [on|off]\n\n\ +determine whether the plot window is cleared before the next line is drawn", }, + { "load", -1, builtin_load, "load [-force] file\n\nload variables from a file", }, diff --git a/src/parse.y b/src/parse.y --- a/src/parse.y +++ b/src/parse.y @@ -371,13 +371,25 @@ plot_command : PLOT plot_command1 { - tree_subplot_list *tmp = $2->reverse (); - $$ = new tree_plot_command (tmp, $1->pttype ()); - plotting = 0; - past_plot_range = 0; - in_plot_range = 0; - in_plot_using = 0; - in_plot_style = 0; + tree_subplot_list *tmp = (tree_subplot_list *) NULL; + if ($2 != (tree_subplot_list *) NULL) + tmp = $2->reverse (); + + if (tmp == (tree_subplot_list *) NULL + && $1->pttype () != token::replot) + { + yyerror ("must have something to plot"); + ABORT_PARSE; + } + else + { + $$ = new tree_plot_command (tmp, $1->pttype ()); + plotting = 0; + past_plot_range = 0; + in_plot_range = 0; + in_plot_using = 0; + in_plot_style = 0; + } } | PLOT ranges plot_command1 { @@ -419,7 +431,9 @@ { $$ = new tree_plot_range (); } ; -plot_command1 : plot_command2 +plot_command1 : // empty + { $$ = (tree_subplot_list *) NULL; } + | plot_command2 { $$ = $1; } | plot_command1 ',' plot_command2 { $$ = $1->chain ($3); } diff --git a/src/pt-plot.cc b/src/pt-plot.cc --- a/src/pt-plot.cc +++ b/src/pt-plot.cc @@ -40,11 +40,14 @@ } // The number of lines we\'ve plotted so far. -static int plot_line_count; +int plot_line_count; // Is this a parametric plot? Makes a difference for 3D plotting. int parametric_plot = 0; +// Should the graph window be cleared before plotting the next line? +int clear_before_plotting = 1; + /* * Plotting, eh? */ @@ -90,13 +93,33 @@ switch (ndim) { case 1: - plot_buf << "replot"; + if (plot_line_count == 0) + { + if (plot_list) + plot_buf << "plot"; + else + { + ::error ("replot: must have something to plot"); + return retval; + } + } + else + plot_buf << "replot"; break; case 2: - plot_buf << "plot"; + if (clear_before_plotting || plot_line_count == 0) + { + plot_line_count = 0; + plot_buf << "plot"; + } + else + plot_buf << "replot"; break; case 3: - plot_buf << "splot"; + { + plot_line_count = 0; + plot_buf << "splot"; + } break; default: panic_impossible (); @@ -104,12 +127,17 @@ } if (range != (tree_plot_limits *) NULL) - range->print (ndim, plot_buf); + { + if (plot_line_count == 0) + range->print (ndim, plot_buf); + else + warning ("can't specify new plot ranges with `replot' or while\ + hold is on"); + } if (error_state) return retval; - plot_line_count = 0; tree_subplot_list *ptr = plot_list; for ( ; ptr != NULL_TREE ; ptr = ptr->next_elem ()) { diff --git a/src/t-builtins.cc b/src/t-builtins.cc --- a/src/t-builtins.cc +++ b/src/t-builtins.cc @@ -103,6 +103,9 @@ // Is this a parametric plot? Makes a difference for 3D plotting. extern int parametric_plot; +// Should the graph window be cleared before plotting the next line? +extern int clear_before_plotting; + /* * Format a list in neat columns. Mostly stolen from GNU ls. This * should maybe be in utils.cc. @@ -630,6 +633,36 @@ return retval; } +/* + * Change state flag that determines whether lines are added to plots + * or drawn on new plots. + */ +tree_constant +builtin_hold (int argc, char **argv) +{ + tree_constant retval; + + switch (argc) + { + case 1: + clear_before_plotting = ! clear_before_plotting; + break; + case 2: + if (strcasecmp (argv[1], "on") == 0) + clear_before_plotting = 0; + else if (strcasecmp (argv[1], "off") == 0) + clear_before_plotting = 1; + else + print_usage ("hold"); + break; + default: + print_usage ("hold"); + break; + } + + return retval; +} + static int load_variable (char *nm, int force, istream& is) { diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -129,6 +129,9 @@ // Top level context (?) extern jmp_buf toplevel; +// The number of lines we\'ve plotted so far. +extern int plot_line_count; + // Pipe to gnuplot. static oprocstream plot_stream; @@ -546,7 +549,7 @@ else { char *infodir = octave_info_dir (); - info_file_string = strconcat (infodir, "octave.info"); + info_file_string = strconcat (infodir, "/octave.info"); } return info_file_string; } @@ -1302,6 +1305,8 @@ if (! plot_stream.is_open ()) { + plot_line_count = 0; + char *plot_prog = user_pref.gnuplot_binary; if (plot_prog != (char *) NULL) { @@ -1351,6 +1356,8 @@ { if (plot_stream.is_open ()) plot_stream.close (); + + plot_line_count = 0; } int