5102
|
1 %option prefix="gpt" |
|
2 %option noyywrap |
|
3 |
|
4 %{ |
|
5 // PKG_ADD: mark_as_rawcommand ("gplot"); |
|
6 // PKG_ADD: mark_as_rawcommand ("gset"); |
|
7 // PKG_ADD: mark_as_rawcommand ("gsplot"); |
|
8 |
|
9 // PKG_ADD: mark_as_rawcommand ("replot"); |
|
10 |
|
11 // PKG_ADD: mark_as_command ("gshow"); |
|
12 // PKG_ADD: mark_as_command ("hold"); |
|
13 // PKG_ADD: mark_as_command ("set"); |
|
14 // PKG_ADD: mark_as_command ("show"); |
|
15 |
|
16 // PKG_ADD: __gplot_init__ (); |
|
17 |
|
18 // PKG_ADD: atexit ("closeplot"); |
|
19 |
|
20 #ifdef HAVE_CONFIG_H |
|
21 #include <config.h> |
|
22 #endif |
|
23 |
|
24 #include <string> |
|
25 #include <fstream> |
|
26 #include <iostream> |
|
27 |
|
28 #ifdef HAVE_UNISTD_H |
|
29 #ifdef HAVE_SYS_TYPES_H |
|
30 #include <sys/types.h> |
|
31 #endif |
|
32 #include <unistd.h> |
|
33 #endif |
|
34 |
|
35 #include "file-ops.h" |
|
36 |
|
37 #include "defun-dld.h" |
|
38 #include "file-io.h" |
|
39 #include "gripes.h" |
|
40 #include "load-save.h" |
|
41 #include "parse.h" |
|
42 #include "procstream.h" |
|
43 #include "sighandlers.h" |
|
44 #include "utils.h" |
|
45 #include "variables.h" |
|
46 |
|
47 enum _toktype |
|
48 { |
|
49 START_PAREN = 1, |
|
50 END_PAREN, |
|
51 START_BRACE, |
|
52 END_BRACE, |
|
53 START_BRACKET, |
|
54 END_BRACKET, |
|
55 COLON, |
|
56 SEMICOLON, |
|
57 COMMA, |
|
58 QUOTE, |
|
59 IDENT, |
|
60 NUMBER, |
|
61 BINOP, |
|
62 UNOP, |
|
63 STRING, |
|
64 OTHER, |
|
65 TITLE, |
|
66 USING, |
|
67 WITH, |
|
68 AXES, |
|
69 CLEAR |
|
70 }; |
|
71 |
|
72 typedef bool (*pred) (const int); |
|
73 |
|
74 class |
|
75 gpt_parse_error |
|
76 { |
|
77 public: |
|
78 gpt_parse_error (void) : msg () { } |
|
79 gpt_parse_error (std::string errmsg) : msg (errmsg) { } |
|
80 |
|
81 std::string msg; |
|
82 }; |
|
83 |
|
84 static int is_plot_keyword (const std::string& s); |
|
85 |
|
86 static int handle_string (char delim); |
|
87 |
|
88 static inline bool can_be_plotkw (void); |
|
89 |
|
90 static bool gpt_quote_is_transpose; |
|
91 static bool gpt_allow_plotkw; |
|
92 static int gpt_parens; |
|
93 static int gpt_brackets; |
|
94 static int gpt_braces; |
|
95 |
|
96 static int send_to_plot_stream (const std::string& cmd); |
|
97 |
|
98 // needed by handle_string |
|
99 static char string_buf[256]; |
|
100 |
|
101 %} |
|
102 |
|
103 D [0-9] |
|
104 S [ \t] |
|
105 IDENT ([_a-zA-Z@][_a-zA-Z0-9]*) |
|
106 EXPON ([DdEe][+-]?{D}+) |
|
107 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
|
108 NOT ((\~)|(\!)) |
|
109 /* NOT is not strictly a binary operator, but is close enough for us. */ |
|
110 BINOP (({NOT})|(\.?([\*/\\^+-]|\*\*)=?)|([<=~!>&|]=)|([=&|<>]{1,2})|(<<=)|(>>=)|(\.)) |
5106
|
111 /* single quote (') transpose operator is handled separately. */ |
|
112 UNOP ((\+\+)|(\-\-)|(\.')) |
5102
|
113 |
|
114 %% |
|
115 |
|
116 "(" { |
|
117 gpt_quote_is_transpose = false; |
|
118 gpt_parens++; |
|
119 return START_PAREN; |
|
120 } |
|
121 |
|
122 ")" { |
|
123 gpt_quote_is_transpose = true; |
|
124 gpt_parens--; |
|
125 return END_PAREN; |
|
126 } |
|
127 |
|
128 "{" { |
|
129 gpt_quote_is_transpose = false; |
|
130 gpt_braces++; |
|
131 return START_BRACE; |
|
132 } |
|
133 |
|
134 "}" { |
|
135 gpt_quote_is_transpose = true; |
|
136 gpt_braces--; |
|
137 return END_BRACE; |
|
138 } |
|
139 |
|
140 "[" { |
|
141 gpt_quote_is_transpose = false; |
|
142 gpt_brackets++; |
|
143 return START_BRACKET; |
|
144 } |
|
145 |
|
146 "]" { |
|
147 gpt_quote_is_transpose = true; |
|
148 gpt_brackets--; |
|
149 return END_BRACKET; |
|
150 } |
|
151 |
|
152 ":" { |
|
153 gpt_quote_is_transpose = false; |
|
154 return COLON; |
|
155 } |
|
156 |
|
157 ";" { |
|
158 gpt_quote_is_transpose = false; |
|
159 return SEMICOLON; |
|
160 } |
|
161 |
|
162 "," { |
|
163 gpt_quote_is_transpose = false; |
|
164 return COMMA; |
|
165 } |
|
166 |
|
167 "'" { |
|
168 if (gpt_quote_is_transpose) |
|
169 { |
|
170 gpt_allow_plotkw = true; |
|
171 return QUOTE; |
|
172 } |
|
173 else |
|
174 { |
|
175 gpt_quote_is_transpose = true; |
|
176 gpt_allow_plotkw = true; |
|
177 return handle_string ('\''); |
|
178 } |
|
179 } |
|
180 |
|
181 "\"" { |
|
182 return handle_string ('"'); |
|
183 } |
|
184 |
|
185 {IDENT} { |
|
186 int itok; |
|
187 if (can_be_plotkw () && (itok = is_plot_keyword (yytext))) |
|
188 { |
|
189 gpt_quote_is_transpose = false; |
|
190 gpt_allow_plotkw = true; |
|
191 return itok; |
|
192 } |
|
193 else if (std::string (yytext) == "function") |
|
194 { |
|
195 throw gpt_parse_error ("The 'function' keyword is not allowed in plot commands."); |
|
196 } |
|
197 else |
|
198 { |
|
199 gpt_quote_is_transpose = true; |
|
200 gpt_allow_plotkw = true; |
|
201 return IDENT; |
|
202 } |
|
203 } |
|
204 |
|
205 {D}+/\.[\*/\\^'] | /* ' */ |
|
206 {NUMBER} { |
|
207 gpt_quote_is_transpose = true; |
|
208 gpt_allow_plotkw = true; |
|
209 return NUMBER; |
|
210 } |
|
211 |
|
212 {BINOP} { |
|
213 gpt_quote_is_transpose = false; |
|
214 gpt_allow_plotkw = false; |
|
215 return BINOP; |
|
216 } |
|
217 |
|
218 {UNOP} { |
|
219 gpt_quote_is_transpose = false; |
|
220 gpt_allow_plotkw = true; |
|
221 return UNOP; |
|
222 } |
|
223 |
|
224 {S} { /* Ignore spaces and tabs outside of character strings. */ } |
|
225 |
|
226 . { |
|
227 gpt_quote_is_transpose = false; |
|
228 gpt_allow_plotkw = true; |
|
229 warning ("unknown token = \"%s\" in plot command", yytext); |
|
230 return OTHER; |
|
231 } |
|
232 |
|
233 %% |
|
234 |
|
235 // If TRUE, a replot command is issued automatically each time a plot |
|
236 // changes in some way. |
|
237 static bool Vautomatic_replot; |
|
238 |
|
239 // The name of the shell command to execute to start gnuplot. |
|
240 static std::string Vgnuplot_binary; |
|
241 |
|
242 // TRUE if gnuplot appears to support multiple plot windows with X11. |
|
243 static bool Vgnuplot_has_frames; |
|
244 |
|
245 // The number of lines we've plotted so far. |
|
246 static int plot_line_count = 0; |
|
247 |
|
248 // Is this a parametric plot? Makes a difference for 3D plotting. |
|
249 static bool parametric_plot = false; |
|
250 |
|
251 // The gnuplot terminal type. |
|
252 static std::string gnuplot_terminal_type; |
|
253 |
|
254 // Should the graph window be cleared before plotting the next line? |
|
255 static bool clear_before_plotting = true; |
|
256 |
|
257 // Pipe to gnuplot. |
|
258 static oprocstream *plot_stream = 0; |
|
259 |
|
260 // Gnuplot command strings that we use. |
|
261 static std::string Vgnuplot_command_plot; |
|
262 static std::string Vgnuplot_command_replot; |
|
263 static std::string Vgnuplot_command_splot; |
|
264 static std::string Vgnuplot_command_using; |
|
265 static std::string Vgnuplot_command_with; |
|
266 static std::string Vgnuplot_command_axes; |
|
267 static std::string Vgnuplot_command_title; |
|
268 static std::string Vgnuplot_command_end; |
|
269 |
|
270 // (almost) copy-paste code from pt-plot.cc |
|
271 |
|
272 static std::string |
|
273 save_in_tmp_file (const octave_value& t, int ndim = 2, bool parametric = false) |
|
274 { |
|
275 std::string name = file_ops::tempnam ("", "oct-"); |
|
276 |
|
277 if (! name.empty ()) |
|
278 { |
|
279 std::ofstream file (name.c_str ()); |
|
280 |
|
281 if (file) |
|
282 { |
|
283 switch (ndim) |
|
284 { |
|
285 case 2: |
|
286 save_ascii_data_for_plotting (file, t, name); |
|
287 break; |
|
288 |
|
289 case 3: |
|
290 save_three_d (file, t, parametric); |
|
291 break; |
|
292 |
|
293 default: |
|
294 gripe_2_or_3_dim_plot (); |
|
295 break; |
|
296 } |
|
297 } |
|
298 else |
|
299 { |
|
300 error ("couldn't open temporary output file `%s'", name.c_str ()); |
|
301 name.resize (0); |
|
302 } |
|
303 } |
|
304 |
|
305 return name; |
|
306 } |
|
307 |
|
308 static void |
5142
|
309 close_plot_stream (bool remove_from_child_list = true) |
5102
|
310 { |
|
311 if (plot_stream) |
|
312 { |
5142
|
313 if (remove_from_child_list) |
|
314 octave_child_list::remove (plot_stream->pid ()); |
|
315 |
5102
|
316 send_to_plot_stream ("\nquit\n"); |
5142
|
317 |
5102
|
318 delete plot_stream; |
|
319 plot_stream = 0; |
|
320 } |
|
321 |
|
322 plot_line_count = 0; |
|
323 } |
|
324 |
5142
|
325 static bool |
|
326 plot_stream_event_handler (pid_t pid, int status) |
5102
|
327 { |
5142
|
328 bool retval = false; |
|
329 |
|
330 if (pid > 0) |
|
331 { |
|
332 if (WIFEXITED (status) || WIFSIGNALLED (status)) |
|
333 { |
|
334 close_plot_stream (false); |
5102
|
335 |
5142
|
336 warning ("connection to external plotter (pid = %d) lost --", pid); |
|
337 warning ("please try your plot command(s) again"); |
|
338 |
|
339 // Request removal of this PID from the list of child |
|
340 // processes. |
|
341 |
|
342 retval = true; |
|
343 } |
|
344 } |
|
345 |
|
346 return retval; |
5102
|
347 } |
|
348 |
|
349 static void |
|
350 open_plot_stream (void) |
|
351 { |
|
352 static bool initialized = false; |
|
353 |
|
354 if (plot_stream && ! *plot_stream) |
|
355 { |
|
356 delete plot_stream; |
|
357 plot_stream = 0; |
|
358 } |
|
359 |
|
360 if (! plot_stream) |
|
361 { |
|
362 initialized = false; |
|
363 |
|
364 plot_line_count = 0; |
|
365 |
|
366 std::string plot_prog; |
|
367 |
|
368 if (Vgnuplot_binary.empty ()) |
|
369 plot_prog = "gnuplot"; |
|
370 else |
|
371 plot_prog = "\"" + Vgnuplot_binary + "\""; |
|
372 |
|
373 // XXX FIXME XXX -- I'm not sure this is the right thing to do, |
|
374 // but without it, C-c at the octave prompt will kill gnuplot... |
|
375 |
|
376 #if defined (HAVE_POSIX_SIGNALS) |
|
377 sigset_t set, oset; |
|
378 sigemptyset (&set); |
|
379 sigaddset (&set, SIGINT); |
|
380 sigprocmask (SIG_BLOCK, &set, &oset); |
|
381 #else |
|
382 volatile octave_interrupt_handler old_interrupt_handler |
|
383 = octave_ignore_interrupts (); |
|
384 #endif |
|
385 |
|
386 plot_stream = new oprocstream (plot_prog.c_str ()); |
|
387 |
|
388 if (plot_stream) |
|
389 { |
|
390 if (! *plot_stream) |
|
391 { |
|
392 delete plot_stream; |
|
393 plot_stream = 0; |
|
394 |
|
395 error ("plot: unable to open pipe to `%s'", plot_prog.c_str ()); |
|
396 } |
|
397 else |
5142
|
398 octave_child_list::insert (plot_stream->pid (), |
|
399 plot_stream_event_handler); |
5102
|
400 } |
|
401 else |
|
402 error ("plot: unable to open pipe to `%s'", plot_prog.c_str ()); |
|
403 |
|
404 #if defined (HAVE_POSIX_SIGNALS) |
|
405 sigprocmask (SIG_SETMASK, &oset, 0); |
|
406 #else |
|
407 octave_set_interrupt_handler (old_interrupt_handler); |
|
408 #endif |
|
409 } |
|
410 |
|
411 if (! error_state && plot_stream && *plot_stream && ! initialized) |
|
412 { |
|
413 initialized = true; |
|
414 |
|
415 *plot_stream << "set style data lines\n"; |
|
416 |
|
417 if (! gnuplot_terminal_type.empty ()) |
|
418 *plot_stream << "set term " << gnuplot_terminal_type |
|
419 << Vgnuplot_command_end << "\n"; |
|
420 } |
|
421 } |
|
422 |
|
423 static int |
|
424 send_to_plot_stream (const std::string& cmd) |
|
425 { |
|
426 if (! (plot_stream && *plot_stream)) |
|
427 { |
|
428 open_plot_stream (); |
|
429 |
|
430 if (error_state) |
|
431 return -1; |
|
432 } |
|
433 |
|
434 int replot_len = Vgnuplot_command_replot.length (); |
|
435 int splot_len = Vgnuplot_command_splot.length (); |
|
436 int plot_len = Vgnuplot_command_plot.length (); |
|
437 |
|
438 bool is_replot = (Vgnuplot_command_replot == cmd.substr (0, replot_len)); |
|
439 bool is_splot = (Vgnuplot_command_splot == cmd.substr (0, splot_len)); |
|
440 bool is_plot = (Vgnuplot_command_plot == cmd.substr (0, plot_len)); |
|
441 |
|
442 if (plot_line_count == 0 && is_replot) |
|
443 error ("replot: no previous plot"); |
|
444 else |
|
445 { |
|
446 *plot_stream << cmd; |
|
447 |
|
448 if (! (is_replot || is_splot || is_plot) |
|
449 && plot_line_count > 0 |
|
450 && Vautomatic_replot) |
|
451 { |
|
452 *plot_stream << Vgnuplot_command_replot << Vgnuplot_command_end; |
|
453 } |
|
454 |
|
455 plot_stream->flush (); |
|
456 } |
|
457 |
|
458 return 0; |
|
459 } |
|
460 |
|
461 // Check if the parser state is such that a plot keyword can occur. |
|
462 static inline bool |
|
463 can_be_plotkw (void) |
|
464 { |
|
465 return (gpt_allow_plotkw |
|
466 && (gpt_braces == 0) |
|
467 && (gpt_brackets == 0) |
|
468 && (gpt_parens == 0)); |
|
469 } |
|
470 |
|
471 // (Probably not necessesary, but current Matlab style plot functions |
|
472 // break without this (they emit too short gnuplot commands)) |
|
473 static std::string |
|
474 plot_style_token (const std::string& s) |
|
475 { |
|
476 std::string retval; |
|
477 |
|
478 // XXX FIXME XXX -- specify minimum match length for these. |
|
479 static const char *plot_styles[] = |
|
480 { |
|
481 "boxes", |
|
482 "boxerrorbars", |
|
483 "boxxyerrorbars", |
|
484 "candlesticks", |
|
485 "dots", |
|
486 "errorbars", |
|
487 "financebars", |
|
488 "fsteps", |
|
489 "histeps", |
|
490 "impulses", |
|
491 "lines", |
|
492 "linespoints", |
|
493 "points", |
|
494 "steps", |
|
495 "vector", |
|
496 "xerrorbars", |
|
497 "xyerrorbars", |
|
498 "yerrorbars", |
|
499 0, |
|
500 }; |
|
501 |
|
502 const char * const *tmp = plot_styles; |
|
503 while (*tmp) |
|
504 { |
|
505 if (almost_match (*tmp, s.c_str ())) |
|
506 { |
|
507 retval = *tmp; |
|
508 break; |
|
509 } |
|
510 |
|
511 tmp++; |
|
512 } |
|
513 |
|
514 return retval; |
|
515 } |
|
516 |
|
517 // This is used to handle single-quote delimited strings. Kludge alert. |
|
518 static int |
|
519 handle_string (char delim) |
|
520 { |
|
521 int c; |
|
522 char *pos = string_buf; |
|
523 int escape_pending = 0; |
|
524 |
|
525 *pos++ = static_cast<char> (delim); |
|
526 while ((c = yyinput ()) != EOF) |
|
527 { |
|
528 if (c == '\\') |
|
529 { |
|
530 if (escape_pending) |
|
531 { |
|
532 *pos++ = static_cast<char> (c); |
|
533 escape_pending = 0; |
|
534 } |
|
535 else |
|
536 { |
|
537 *pos++ = static_cast<char> (c); |
|
538 escape_pending = 1; |
|
539 } |
|
540 continue; |
|
541 } |
|
542 else if (c == '\n') |
|
543 { |
|
544 error ("unterminated string constant"); |
|
545 break; |
|
546 } |
|
547 else if (c == delim) |
|
548 { |
|
549 if (escape_pending) |
|
550 *pos++ = static_cast<char> (c); |
|
551 else |
|
552 { |
|
553 c = yyinput (); |
|
554 if (c == delim) |
|
555 { |
|
556 *pos++ = static_cast<char> (c); |
|
557 *pos++ = static_cast<char> (c); |
|
558 } |
|
559 else |
|
560 { |
|
561 yyunput (c, yytext); |
|
562 *pos++ = static_cast<char> (delim); |
|
563 *pos++ = '\0'; |
|
564 yytext = string_buf; |
|
565 return STRING; |
|
566 } |
|
567 } |
|
568 } |
|
569 else |
|
570 { |
|
571 *pos++ = static_cast<char> (c); |
|
572 } |
|
573 |
|
574 escape_pending = 0; |
|
575 } |
|
576 |
|
577 throw gpt_parse_error ("Unterminated string?"); |
|
578 |
|
579 return 0; |
|
580 } |
|
581 |
|
582 // Check to see if a character string matches any one of the plot |
|
583 // option keywords. Don't match abbreviations for clear, since that's |
|
584 // not a gnuplot keyword (users will probably only expect to be able |
|
585 // to abbreviate actual gnuplot keywords). |
|
586 |
|
587 static int |
|
588 is_plot_keyword (const std::string& s) |
|
589 { |
|
590 const char *t = s.c_str (); |
|
591 if (almost_match ("title", t, 1)) |
|
592 { |
|
593 return TITLE; |
|
594 } |
|
595 else if (almost_match ("using", t, 1)) |
|
596 { |
|
597 return USING; |
|
598 } |
|
599 else if (almost_match ("with", t, 1)) |
|
600 { |
|
601 return WITH; |
|
602 } |
|
603 else if (almost_match ("axes", t, 2) || almost_match ("axis", t, 2)) |
|
604 { |
|
605 return AXES; |
|
606 } |
|
607 else if (strcmp ("clear", t) == 0) |
|
608 { |
|
609 return CLEAR; |
|
610 } |
|
611 else |
|
612 { |
|
613 return 0; |
|
614 } |
|
615 } |
|
616 |
|
617 // Some predicates on tokens |
|
618 |
|
619 // Return true for ":". |
|
620 static inline bool |
|
621 colonp (const int tok) |
|
622 { |
|
623 return (tok == COLON); |
|
624 } |
|
625 |
|
626 // Return TRUE for "]". |
|
627 static inline bool |
|
628 endbracketp (const int tok) |
|
629 { |
|
630 return (tok == END_BRACKET); |
|
631 } |
|
632 |
|
633 // Return TRUE for plot token, comma or end of input. |
|
634 static inline bool |
|
635 plottok_or_end_p (const int tok) |
|
636 { |
|
637 return (tok == TITLE |
|
638 || tok == USING |
|
639 || tok == WITH |
|
640 || tok == AXES |
|
641 || tok == CLEAR |
|
642 || tok == COMMA |
|
643 || tok == 0); |
|
644 } |
|
645 |
|
646 // Equivalent to (colonp (tok) || plottok_or_end_p (tok)). |
|
647 static inline bool |
|
648 colon_plottok_or_end_p (const int tok) |
|
649 { |
|
650 return (tok == COLON || plottok_or_end_p (tok)); |
|
651 } |
|
652 |
|
653 // read until test is true and delimiters are balanced, or end of input. |
|
654 // Return the last token in lasttok |
|
655 static std::string |
|
656 read_until (pred test, int& lasttok) throw (gpt_parse_error) |
|
657 { |
|
658 int tok; |
|
659 |
|
660 // We have to maintain balanced delimiters per subexpression too. |
|
661 int brackets = 0; |
|
662 int parens = 0; |
|
663 int braces = 0; |
|
664 std::string s; |
|
665 |
|
666 tok = gptlex (); |
|
667 |
|
668 while (tok && ! (test (tok) |
|
669 && brackets == 0 |
|
670 && parens == 0 |
|
671 && braces == 0)) |
|
672 { |
|
673 switch (tok) |
|
674 { |
|
675 case START_BRACKET: |
|
676 brackets++; |
|
677 break; |
|
678 |
|
679 case END_BRACKET: |
|
680 brackets--; |
|
681 break; |
|
682 |
|
683 case START_PAREN: |
|
684 parens++; |
|
685 break; |
|
686 |
|
687 case END_PAREN: |
|
688 parens--; |
|
689 break; |
|
690 |
|
691 case START_BRACE: |
|
692 braces++; |
|
693 break; |
|
694 |
|
695 case END_BRACE: |
|
696 braces--; |
|
697 break; |
|
698 |
|
699 default: |
|
700 break; |
|
701 } |
|
702 |
|
703 s += std::string (yytext) + " "; |
|
704 |
|
705 tok = gptlex (); |
|
706 } |
|
707 |
|
708 // Throw error only if we've reached the end token and the test |
|
709 // doesn't accept it. |
|
710 |
|
711 if (! test (tok) && ! tok) |
|
712 throw gpt_parse_error ("unexpected end of input"); |
|
713 |
|
714 lasttok = tok; |
|
715 |
|
716 return s; |
|
717 } |
|
718 |
|
719 // Eval the two expressions giving limits of range and print it. |
|
720 static std::string |
|
721 printrange (std::string starts, std::string ends) |
|
722 { |
|
723 octave_value startv, endv; |
|
724 int status; |
|
725 std::string s; |
|
726 OSSTREAM range_buf; |
|
727 |
|
728 range_buf << "["; |
|
729 |
|
730 if (! starts.empty ()) |
|
731 { |
|
732 startv = eval_string (starts, true, status); |
|
733 if (! startv.is_real_scalar ()) |
|
734 throw gpt_parse_error (); |
|
735 startv.print_raw (range_buf); |
|
736 } |
|
737 |
|
738 range_buf << ":"; |
|
739 |
|
740 if (! ends.empty ()) |
|
741 { |
|
742 endv = eval_string (ends, true, status); |
|
743 if (! endv.is_real_scalar ()) |
|
744 throw gpt_parse_error (); |
|
745 endv.print_raw (range_buf); |
|
746 } |
|
747 |
|
748 range_buf << "]"; |
|
749 range_buf << OSSTREAM_ENDS; |
|
750 |
|
751 s = OSSTREAM_STR (range_buf); |
|
752 |
|
753 return s; |
|
754 } |
|
755 |
|
756 // Handle plot parameters. |
|
757 |
|
758 // Title has one string expression which is evaluated and printed to the |
|
759 // gnuplot command string. |
|
760 static std::string |
|
761 handle_title (int& lasttok) |
|
762 { |
|
763 int tok; |
|
764 std::string retstr = Vgnuplot_command_title + " "; |
|
765 std::string title_expr_str; |
|
766 |
|
767 title_expr_str += read_until (plottok_or_end_p, tok); |
|
768 |
|
769 int status; |
|
770 octave_value tmp_data = eval_string (title_expr_str, true, status); |
|
771 |
|
772 if (status != 0 || ! tmp_data.is_defined ()) |
|
773 throw gpt_parse_error (); |
|
774 |
|
775 OSSTREAM tmp_buf; |
|
776 if (tmp_data.is_string ()) |
|
777 { |
|
778 tmp_buf << '"'; |
|
779 tmp_data.print_raw (tmp_buf); |
|
780 tmp_buf << '"' << OSSTREAM_ENDS; |
|
781 } |
|
782 else |
|
783 { |
|
784 warning ("line title must be a string"); |
|
785 tmp_buf << '"' << "line " << plot_line_count << '"'; |
|
786 } |
|
787 |
|
788 retstr += OSSTREAM_STR (tmp_buf); |
|
789 |
|
790 lasttok = tok; |
|
791 |
|
792 return retstr; |
|
793 } |
|
794 |
|
795 // Parse, evaluate and print colon separated expressions in the using |
|
796 // plot parameter. The use of trailing format string is not supported. |
|
797 static std::string |
|
798 handle_using (int& lasttok) |
|
799 { |
|
800 int tok; |
|
801 std::string expr_str; |
|
802 std::string retstr = Vgnuplot_command_using + " "; |
|
803 bool out = false; |
|
804 |
|
805 octave_value tmp_data; |
|
806 int status; |
|
807 while (! out) |
|
808 { |
|
809 expr_str = read_until (colon_plottok_or_end_p, tok); |
|
810 |
|
811 tmp_data = eval_string (expr_str, true, status); |
|
812 if (status != 0 || ! tmp_data.is_real_scalar ()) |
|
813 throw gpt_parse_error (); |
|
814 |
|
815 OSSTREAM tmp_buf; |
|
816 tmp_data.print_raw (tmp_buf); |
|
817 tmp_buf << OSSTREAM_ENDS; |
|
818 retstr += OSSTREAM_STR (tmp_buf); |
|
819 |
|
820 if (tok == COLON) |
|
821 retstr += ":"; |
|
822 else |
|
823 out = true; |
|
824 } |
|
825 |
|
826 lasttok = tok; |
|
827 |
|
828 return retstr; |
|
829 } |
|
830 |
|
831 // Presently just passes the linewidth, pointtype etc. tokens as they are. |
|
832 static std::string |
|
833 handle_style (int& lasttok) |
|
834 { |
|
835 std::string retstr = Vgnuplot_command_with + " "; |
|
836 std::string style; |
|
837 |
|
838 lasttok = gptlex (); |
|
839 |
|
840 if (lasttok != IDENT) |
|
841 throw gpt_parse_error ("expected plot style token"); |
|
842 |
|
843 style = std::string (yytext); |
|
844 style = plot_style_token (style); |
|
845 |
|
846 if (! style.empty ()) |
|
847 retstr += style; |
|
848 else |
|
849 retstr += std::string (yytext); |
|
850 |
|
851 // XXX FIXME XXX -- should evaluate the remaining tokens, but this |
|
852 // needs changes in the parser. |
|
853 retstr += " " + read_until (plottok_or_end_p, lasttok); |
|
854 |
|
855 return retstr; |
|
856 } |
|
857 |
|
858 // Axes has only one qualifier keyword, which is not evaluated. |
|
859 static std::string |
|
860 handle_axes (int& lasttok) |
|
861 { |
|
862 return Vgnuplot_command_axes + " " + read_until (plottok_or_end_p, lasttok); |
|
863 } |
|
864 |
|
865 // Parse and evaluate parameter string and pass it to gnuplot pipe. |
|
866 static int |
|
867 makeplot (std::string caller, std::string args) throw (gpt_parse_error) |
|
868 { |
|
869 YY_BUFFER_STATE bstate; |
|
870 |
|
871 bstate = yy_scan_string (args.c_str ()); |
|
872 yy_switch_to_buffer (bstate); |
|
873 std::string outstr; |
|
874 int ndim = 2; |
|
875 |
|
876 if (caller == "replot") |
|
877 { |
|
878 ndim = 1; |
|
879 outstr += Vgnuplot_command_replot + " "; |
|
880 } |
|
881 else if (caller == "plot") |
|
882 { |
|
883 ndim = 2; |
|
884 if (clear_before_plotting || plot_line_count == 0) |
|
885 { |
|
886 plot_line_count = 0; |
|
887 outstr += Vgnuplot_command_plot + " "; |
|
888 } |
|
889 else |
|
890 outstr += Vgnuplot_command_replot + " "; |
|
891 } |
|
892 else if (caller == "splot") |
|
893 { |
|
894 ndim = 3; |
|
895 if (clear_before_plotting || plot_line_count == 0) |
|
896 { |
|
897 plot_line_count = 0; |
|
898 outstr += Vgnuplot_command_splot + " "; |
|
899 } |
|
900 else |
|
901 outstr += Vgnuplot_command_replot + " "; |
|
902 } |
|
903 else |
|
904 throw gpt_parse_error ("unknown plot command"); |
|
905 |
|
906 gpt_quote_is_transpose = false; |
|
907 gpt_allow_plotkw = false; |
|
908 gpt_parens = 0; |
|
909 gpt_braces = 0; |
|
910 gpt_brackets = 0; |
|
911 |
|
912 int tok; |
|
913 tok = gptlex (); |
|
914 if (plottok_or_end_p (tok) && caller != "replot") |
|
915 throw gpt_parse_error ("must have something to plot"); |
|
916 |
|
917 while (tok) |
|
918 { |
|
919 bool title_set = false; |
|
920 bool using_set = false; |
|
921 bool style_set = false; |
|
922 bool axes_set = false; |
|
923 |
|
924 if (tok == START_BRACKET) |
|
925 { |
|
926 if (caller == "replot") |
|
927 throw gpt_parse_error ("can't specify new plot ranges with `replot' or while hold is on"); |
|
928 |
|
929 std::string xrange_start_str = read_until (colonp, tok); |
|
930 std::string xrange_end_str = read_until (endbracketp, tok); |
|
931 outstr += printrange (xrange_start_str, xrange_end_str) + " "; |
|
932 tok = gptlex (); |
|
933 if (tok == START_BRACKET) |
|
934 { |
|
935 std::string yrange_start_str = read_until (colonp, tok); |
|
936 std::string yrange_end_str = read_until (endbracketp, tok); |
|
937 outstr += printrange (yrange_start_str, yrange_end_str) + " "; |
|
938 tok = gptlex (); |
|
939 if (tok == START_BRACKET && caller == "gsplot") |
|
940 { |
|
941 std::string zrange_start_str = read_until (colonp, tok); |
|
942 std::string zrange_end_str = read_until (endbracketp, tok); |
|
943 outstr += printrange (zrange_start_str, zrange_end_str) + " "; |
|
944 tok = gptlex (); |
|
945 } |
|
946 } |
|
947 } |
|
948 |
|
949 if (plottok_or_end_p (tok)) |
|
950 throw gpt_parse_error ("must have something to plot"); |
|
951 else |
|
952 { |
|
953 std::string file; |
|
954 plot_line_count++; |
|
955 |
|
956 if (tok == STRING) |
|
957 { |
|
958 file = file_ops::tilde_expand (std::string (yytext)); |
|
959 // XXX FIXME XXX -- perhaps should check if the file exists? |
|
960 outstr += file + " "; |
|
961 // Discard junk after the string. |
|
962 read_until (plottok_or_end_p, tok); |
|
963 } |
|
964 else |
|
965 { |
|
966 std::string plot_expr_str; |
|
967 plot_expr_str += std::string (yytext) + " "; |
|
968 plot_expr_str += read_until (plottok_or_end_p, tok); |
|
969 |
|
970 int status; |
|
971 octave_value tmp_data = eval_string (plot_expr_str, |
|
972 true, status); |
|
973 |
|
974 if (status != 0 || ! tmp_data.is_defined ()) |
|
975 throw gpt_parse_error (); |
|
976 |
|
977 OSSTREAM tmp_buf; |
|
978 tmp_data.print_raw (tmp_buf); |
|
979 tmp_buf << OSSTREAM_ENDS; |
|
980 |
|
981 if (tmp_data.is_string ()) |
|
982 { |
|
983 file = file_ops::tilde_expand (tmp_data.string_value ()); |
|
984 // XXX FIXME XXX -- perhaps should check if the file exists? |
|
985 outstr += file + " "; |
|
986 } |
|
987 else |
|
988 { |
|
989 switch (ndim) |
|
990 { |
|
991 case 2: |
|
992 file = save_in_tmp_file (tmp_data, ndim); |
|
993 break; |
|
994 |
|
995 case 3: |
|
996 file = save_in_tmp_file (tmp_data, ndim, |
|
997 parametric_plot); |
|
998 break; |
|
999 |
|
1000 default: |
|
1001 gripe_2_or_3_dim_plot (); |
|
1002 break; |
|
1003 } |
|
1004 |
|
1005 if (file.length () > 0) |
|
1006 { |
|
1007 mark_for_deletion (file); |
|
1008 outstr += "'" + file + "' "; |
|
1009 } |
|
1010 } |
|
1011 } |
|
1012 } |
|
1013 |
|
1014 std::string title_str; |
|
1015 std::string using_str; |
|
1016 std::string style_str; |
|
1017 std::string axes_str; |
|
1018 |
|
1019 bool out = false; |
|
1020 while (tok && ! out) |
|
1021 { |
|
1022 switch (tok) |
|
1023 { |
|
1024 case COMMA: |
|
1025 out = true; |
|
1026 break; |
|
1027 |
|
1028 case TITLE: |
|
1029 if (! title_set) |
|
1030 title_str += handle_title (tok) + " "; |
|
1031 else |
|
1032 throw gpt_parse_error ("only one title option may be specified"); |
|
1033 title_set = true; |
|
1034 break; |
|
1035 |
|
1036 case USING: |
|
1037 if (! using_set) |
|
1038 using_str += handle_using (tok) + " "; |
|
1039 else |
|
1040 throw gpt_parse_error ("only one using option may be specified"); |
|
1041 using_set = true; |
|
1042 break; |
|
1043 |
|
1044 case WITH: |
|
1045 if (! style_set) |
|
1046 style_str += handle_style (tok) + " "; |
|
1047 else |
|
1048 throw gpt_parse_error ("only one style option may be specified"); |
|
1049 style_set = true; |
|
1050 break; |
|
1051 |
|
1052 case AXES: |
|
1053 if (! axes_set) |
|
1054 axes_str += handle_axes (tok) + " "; |
|
1055 else |
|
1056 throw gpt_parse_error ("only one axes option may be specified"); |
|
1057 axes_set = true; |
|
1058 break; |
|
1059 |
|
1060 default: |
|
1061 tok = 0; |
|
1062 break; |
|
1063 } |
|
1064 } |
|
1065 |
|
1066 if (! title_set) |
|
1067 { |
|
1068 OSSTREAM tmp_buf; |
|
1069 tmp_buf << Vgnuplot_command_title << " \"line " |
|
1070 << plot_line_count << "\" " << OSSTREAM_ENDS; |
|
1071 title_str = OSSTREAM_STR (tmp_buf); |
|
1072 title_set = true; |
|
1073 } |
|
1074 |
|
1075 // Plot parameters have to be output in this order. |
|
1076 if (using_set) |
|
1077 outstr += using_str; |
|
1078 |
|
1079 if (axes_set) |
|
1080 outstr += axes_str; |
|
1081 |
|
1082 if (title_set) |
|
1083 outstr += title_str; |
|
1084 |
|
1085 if (style_set) |
|
1086 outstr += style_str; |
|
1087 |
|
1088 if (out) |
|
1089 { |
|
1090 // Saw comma on while loop. |
|
1091 outstr += ", "; |
|
1092 gpt_quote_is_transpose = false; |
|
1093 gpt_allow_plotkw = false; |
|
1094 gpt_parens = 0; |
|
1095 gpt_braces = 0; |
|
1096 gpt_brackets = 0; |
|
1097 tok = gptlex (); |
|
1098 } |
|
1099 } |
|
1100 |
|
1101 outstr += Vgnuplot_command_end; |
|
1102 |
|
1103 // Terrible kludge, but line count is destroyed when plot stream |
|
1104 // is opened for the first time. |
|
1105 int linesave = plot_line_count; |
|
1106 send_to_plot_stream (outstr); |
|
1107 plot_line_count = linesave; |
|
1108 |
|
1109 return 1; |
|
1110 } |
|
1111 |
|
1112 static void |
|
1113 doplot (std::string caller, octave_value_list args) |
|
1114 { |
|
1115 std::string s; |
|
1116 int i = 0; |
|
1117 |
|
1118 while (i < args.length ()) |
|
1119 s += args (i++).string_value () + " "; |
|
1120 |
|
1121 try |
|
1122 { |
|
1123 makeplot (caller, s); |
|
1124 } |
|
1125 catch (gpt_parse_error e) |
|
1126 { |
|
1127 if (e.msg.empty ()) |
|
1128 error ("could not parse plot command"); |
|
1129 else |
|
1130 error (e.msg.c_str ()); |
|
1131 } |
|
1132 } |
|
1133 |
|
1134 DEFUN_DLD (gplot, args, , |
|
1135 "Plot with gnuplot.\n") |
|
1136 { |
|
1137 doplot ("plot", args); |
|
1138 return octave_value_list (); |
|
1139 } |
|
1140 |
|
1141 DEFUN_DLD (gsplot, args, , |
|
1142 "Plot with gnuplot.\n") |
|
1143 { |
|
1144 doplot ("splot", args); |
|
1145 return octave_value_list (); |
|
1146 } |
|
1147 |
|
1148 DEFUN_DLD (replot, args, , |
|
1149 "Plot with gnuplot.\n") |
|
1150 { |
|
1151 doplot ("replot", args); |
|
1152 return octave_value_list (); |
|
1153 } |
|
1154 |
|
1155 DEFUN_DLD (clearplot, , , |
|
1156 "-*- texinfo -*-\n\ |
|
1157 @deftypefn {Built-in Function} {} clearplot\n\ |
|
1158 @deftypefnx {Built-in Function} {} clg\n\ |
|
1159 Clear the plot window and any titles or axis labels. The name\n\ |
|
1160 @code{clg} is aliased to @code{clearplot} for compatibility with\n\ |
|
1161 @sc{Matlab}.\n\ |
|
1162 \n\ |
|
1163 The commands @kbd{gplot clear}, @kbd{gsplot clear}, and @kbd{replot\n\ |
|
1164 clear} are equivalent to @code{clearplot}. (Previously, commands like\n\ |
|
1165 @kbd{gplot clear} would evaluate @code{clear} as an ordinary expression\n\ |
|
1166 and clear all the visible variables.)\n\ |
|
1167 @end deftypefn") |
|
1168 { |
|
1169 octave_value_list retval; |
|
1170 |
|
1171 send_to_plot_stream ("clear\n"); |
|
1172 |
|
1173 // XXX FIXME XXX -- instead of just clearing these things, it would |
|
1174 // be nice if we could reset things to a user-specified default |
|
1175 // state. |
|
1176 |
|
1177 send_to_plot_stream ("set title\n"); |
|
1178 send_to_plot_stream ("set xlabel\n"); |
|
1179 send_to_plot_stream ("set ylabel\n"); |
|
1180 send_to_plot_stream ("set nogrid\n"); |
|
1181 send_to_plot_stream ("set nolabel\n"); |
|
1182 |
|
1183 // This makes a simple `replot' not work after a `clearplot' command |
|
1184 // has been issued. |
|
1185 |
|
1186 plot_line_count = 0; |
|
1187 |
|
1188 return retval; |
|
1189 } |
|
1190 |
|
1191 DEFUN_DLD (closeplot, , , |
|
1192 "-*- texinfo -*-\n\ |
|
1193 @deftypefn {Built-in Function} {} closeplot\n\ |
|
1194 Close stream to the @code{gnuplot} subprocess. If you are using X11,\n\ |
|
1195 this will close the plot window.\n\ |
|
1196 @end deftypefn") |
|
1197 { |
|
1198 octave_value_list retval; |
|
1199 close_plot_stream (); |
|
1200 return retval; |
|
1201 } |
|
1202 |
|
1203 DEFUN_DLD (hold, args, , |
|
1204 "-*- texinfo -*-\n\ |
|
1205 @deftypefn {Built-in Function} {} hold @var{args}\n\ |
|
1206 Tell Octave to `hold' the current data on the plot when executing\n\ |
|
1207 subsequent plotting commands. This allows you to execute a series of\n\ |
|
1208 plot commands and have all the lines end up on the same figure. The\n\ |
|
1209 default is for each new plot command to clear the plot device first.\n\ |
|
1210 For example, the command\n\ |
|
1211 \n\ |
|
1212 @example\n\ |
|
1213 hold on\n\ |
|
1214 @end example\n\ |
|
1215 \n\ |
|
1216 @noindent\n\ |
|
1217 turns the hold state on. An argument of @code{off} turns the hold state\n\ |
|
1218 off, and @code{hold} with no arguments toggles the current hold state.\n\ |
|
1219 @end deftypefn") |
|
1220 { |
|
1221 octave_value_list retval; |
|
1222 |
|
1223 int argc = args.length () + 1; |
|
1224 |
|
1225 string_vector argv = args.make_argv ("hold"); |
|
1226 |
|
1227 if (error_state) |
|
1228 return retval; |
|
1229 |
|
1230 switch (argc) |
|
1231 { |
|
1232 case 1: |
|
1233 clear_before_plotting = ! clear_before_plotting; |
|
1234 break; |
|
1235 |
|
1236 case 2: |
|
1237 if (argv[1] == "on") |
|
1238 clear_before_plotting = false; |
|
1239 else if (argv[1] == "off") |
|
1240 clear_before_plotting = true; |
|
1241 else |
|
1242 print_usage ("hold"); |
|
1243 break; |
|
1244 |
|
1245 default: |
|
1246 print_usage ("hold"); |
|
1247 break; |
|
1248 } |
|
1249 |
|
1250 return retval; |
|
1251 } |
|
1252 |
|
1253 DEFUN_DLD (ishold, , , |
|
1254 "-*- texinfo -*-\n\ |
|
1255 @deftypefn {Built-in Function} {} ishold\n\ |
|
1256 Return 1 if the next line will be added to the current plot, or 0 if\n\ |
|
1257 the plot device will be cleared before drawing the next line.\n\ |
|
1258 @end deftypefn") |
|
1259 { |
|
1260 return octave_value (! clear_before_plotting); |
|
1261 } |
|
1262 |
|
1263 DEFUN_DLD (purge_tmp_files, , , |
|
1264 "-*- texinfo -*-\n\ |
|
1265 @deftypefn {Built-in Function} {} purge_tmp_files\n\ |
|
1266 Delete the temporary files created by the plotting commands.\n\ |
|
1267 \n\ |
|
1268 Octave creates temporary data files for @code{gnuplot} and then sends\n\ |
|
1269 commands to @code{gnuplot} through a pipe. Octave will delete the\n\ |
|
1270 temporary files on exit, but if you are doing a lot of plotting you may\n\ |
|
1271 want to clean up in the middle of a session.\n\ |
|
1272 \n\ |
|
1273 A future version of Octave will eliminate the need to use temporary\n\ |
|
1274 files to hold the plot data.\n\ |
|
1275 @end deftypefn") |
|
1276 { |
|
1277 octave_value_list retval; |
|
1278 cleanup_tmp_files (); |
|
1279 return retval; |
|
1280 } |
|
1281 |
|
1282 DEFUN_DLD (graw, args, , |
|
1283 "-*- texinfo -*-\n\ |
|
1284 @deftypefn {Built-in Function} {} graw (@var{string})\n\ |
|
1285 Send @var{string} directly to gnuplot subprocess.\n\ |
|
1286 @end deftypefn") |
|
1287 { |
|
1288 octave_value_list retval; |
|
1289 |
|
1290 if (args.length () == 1 && args(0).is_string ()) |
|
1291 { |
|
1292 std::string cmd = args(0).string_value (); |
|
1293 |
|
1294 if (! (plot_stream && *plot_stream)) |
|
1295 open_plot_stream (); |
|
1296 |
|
1297 if (! error_state) |
|
1298 { |
|
1299 *plot_stream << cmd; |
|
1300 |
|
1301 plot_stream->flush (); |
|
1302 } |
|
1303 } |
|
1304 else |
|
1305 print_usage ("raw"); |
|
1306 |
|
1307 return retval; |
|
1308 } |
|
1309 |
|
1310 DEFUN_DLD (gset, args, , |
|
1311 "-*- texinfo -*-\n\ |
|
1312 @deffn {Command} gset options\n\ |
|
1313 Set plotting options for gnuplot\n\ |
|
1314 @end deffn") |
|
1315 { |
|
1316 octave_value_list retval; |
|
1317 |
|
1318 int argc = args.length () + 1; |
|
1319 |
|
1320 string_vector argv = args.make_argv ("set"); |
|
1321 |
|
1322 if (error_state) |
|
1323 return retval; |
|
1324 |
|
1325 OSSTREAM plot_buf; |
|
1326 |
|
1327 if (argc > 1) |
|
1328 { |
|
1329 if (almost_match ("parametric", argv[1], 3)) |
|
1330 parametric_plot = true; |
|
1331 else if (almost_match ("noparametric", argv[1], 5)) |
|
1332 parametric_plot = false; |
|
1333 else if (almost_match ("term", argv[1], 1)) |
|
1334 { |
|
1335 gnuplot_terminal_type = ""; |
|
1336 OSSTREAM buf; |
|
1337 int i; |
|
1338 for (i = 2; i < argc-1; i++) |
|
1339 buf << argv[i] << " "; |
|
1340 if (i < argc) |
|
1341 buf << argv[i]; |
|
1342 buf << Vgnuplot_command_end << OSSTREAM_ENDS; |
|
1343 gnuplot_terminal_type = OSSTREAM_STR (buf); |
|
1344 OSSTREAM_FREEZE (buf); |
|
1345 } |
|
1346 } |
|
1347 |
|
1348 int i; |
|
1349 for (i = 0; i < argc-1; i++) |
|
1350 plot_buf << argv[i] << " "; |
|
1351 |
|
1352 if (i < argc) |
|
1353 plot_buf << argv[i]; |
|
1354 |
|
1355 plot_buf << Vgnuplot_command_end << OSSTREAM_ENDS; |
|
1356 |
|
1357 send_to_plot_stream (OSSTREAM_STR (plot_buf)); |
|
1358 |
|
1359 OSSTREAM_FREEZE (plot_buf); |
|
1360 |
|
1361 return retval; |
|
1362 } |
|
1363 |
|
1364 DEFUN_DLD (set, args, nargout, |
|
1365 "-*- texinfo -*-\n\ |
|
1366 This command is has been replaced by @code{gset}.") |
|
1367 { |
|
1368 warning ("set is obsolete -- use gset instead"); |
|
1369 return Fgset (args, nargout); |
|
1370 } |
|
1371 |
|
1372 DEFUN_DLD (gshow, args, , |
|
1373 "-*- texinfo -*-\n\ |
|
1374 @deffn {Command} gshow options\n\ |
|
1375 Show plotting options.\n\ |
|
1376 @end deffn") |
|
1377 { |
|
1378 octave_value_list retval; |
|
1379 |
|
1380 int argc = args.length () + 1; |
|
1381 |
|
1382 string_vector argv = args.make_argv ("show"); |
|
1383 |
|
1384 if (error_state) |
|
1385 return retval; |
|
1386 |
|
1387 OSSTREAM plot_buf; |
|
1388 |
|
1389 int i; |
|
1390 for (i = 0; i < argc-1; i++) |
|
1391 plot_buf << argv[i] << " "; |
|
1392 if (i < argc) |
|
1393 plot_buf << argv[i]; |
|
1394 |
|
1395 plot_buf << Vgnuplot_command_end << OSSTREAM_ENDS; |
|
1396 |
|
1397 send_to_plot_stream (OSSTREAM_STR (plot_buf)); |
|
1398 |
|
1399 OSSTREAM_FREEZE (plot_buf); |
|
1400 |
|
1401 return retval; |
|
1402 } |
|
1403 |
|
1404 DEFUN_DLD (show, args, nargout, |
|
1405 "-*- texinfo -*-\n\ |
|
1406 This command is has been replaced by @code{gshow}.") |
|
1407 { |
|
1408 warning ("show is obsolete -- use gshow instead"); |
|
1409 return Fgshow (args, nargout); |
|
1410 } |
|
1411 |
|
1412 static int |
|
1413 automatic_replot (void) |
|
1414 { |
|
1415 Vautomatic_replot = check_preference ("automatic_replot"); |
|
1416 |
|
1417 return 0; |
|
1418 } |
|
1419 |
|
1420 static int |
|
1421 set_string_var (std::string& var, const char *nm) |
|
1422 { |
|
1423 int retval = 0; |
|
1424 |
|
1425 std::string s = builtin_string_variable (nm); |
|
1426 |
|
1427 if (s.empty ()) |
|
1428 { |
|
1429 gripe_invalid_value_specified (nm); |
|
1430 retval = -1; |
|
1431 } |
|
1432 else |
|
1433 var = s; |
|
1434 |
|
1435 return retval; |
|
1436 } |
|
1437 |
|
1438 static int |
|
1439 gnuplot_binary (void) |
|
1440 { |
|
1441 return set_string_var (Vgnuplot_binary, "gnuplot_binary"); |
|
1442 } |
|
1443 |
|
1444 static int |
|
1445 gnuplot_command_plot (void) |
|
1446 { |
|
1447 return set_string_var (Vgnuplot_command_plot, "gnuplot_command_plot"); |
|
1448 } |
|
1449 |
|
1450 static int |
|
1451 gnuplot_command_replot (void) |
|
1452 { |
|
1453 return set_string_var (Vgnuplot_command_replot, "gnuplot_command_replot"); |
|
1454 } |
|
1455 |
|
1456 static int |
|
1457 gnuplot_command_splot (void) |
|
1458 { |
|
1459 return set_string_var (Vgnuplot_command_splot, "gnuplot_command_splot"); |
|
1460 } |
|
1461 |
|
1462 static int |
|
1463 gnuplot_command_using (void) |
|
1464 { |
|
1465 return set_string_var (Vgnuplot_command_using, "gnuplot_command_using"); |
|
1466 } |
|
1467 |
|
1468 static int |
|
1469 gnuplot_command_with (void) |
|
1470 { |
|
1471 return set_string_var (Vgnuplot_command_with, "gnuplot_command_with"); |
|
1472 } |
|
1473 |
|
1474 static int |
|
1475 gnuplot_command_axes (void) |
|
1476 { |
|
1477 return set_string_var (Vgnuplot_command_axes, "gnuplot_command_axes"); |
|
1478 } |
|
1479 |
|
1480 static int |
|
1481 gnuplot_command_title (void) |
|
1482 { |
|
1483 return set_string_var (Vgnuplot_command_title, "gnuplot_command_title"); |
|
1484 } |
|
1485 |
|
1486 static int |
|
1487 gnuplot_command_end (void) |
|
1488 { |
|
1489 return set_string_var (Vgnuplot_command_end, "gnuplot_command_end"); |
|
1490 } |
|
1491 |
|
1492 static int |
|
1493 gnuplot_has_frames (void) |
|
1494 { |
|
1495 Vgnuplot_has_frames = check_preference ("gnuplot_has_frames"); |
|
1496 |
|
1497 return 0; |
|
1498 } |
|
1499 |
|
1500 DEFUN_DLD (__gplot_init__, , , |
|
1501 "-*- texinfo -*-\n\ |
|
1502 @deftypefn {Loadable Function} __gplot_init__ ()\n\ |
|
1503 @end deftypefn") |
|
1504 { |
|
1505 octave_value_list retval; |
|
1506 |
|
1507 static bool gplot_initialized = false; |
|
1508 |
|
1509 if (gplot_initialized) |
|
1510 return retval; |
|
1511 |
|
1512 gplot_initialized = true; |
|
1513 |
|
1514 DEFVAR (automatic_replot, true, automatic_replot, |
|
1515 "-*- texinfo -*-\n\ |
|
1516 @defvr {Built-in Variable} automatic_replot\n\ |
|
1517 You can tell Octave to redisplay the plot each time anything about it\n\ |
|
1518 changes by setting the value of the builtin variable\n\ |
|
1519 @code{automatic_replot} to a nonzero value. Although it is fairly\n\ |
|
1520 inefficient, especially for large plots, the default value is 1 for\n\ |
|
1521 compatibility with Matlab.\n\ |
|
1522 @end defvr"); |
|
1523 |
|
1524 DEFVAR (gnuplot_binary, GNUPLOT_BINARY, gnuplot_binary, |
|
1525 "-*- texinfo -*-\n\ |
|
1526 @defvr {Built-in Variable} gnuplot_binary\n\ |
|
1527 The name of the program invoked by the plot command. The default value\n\ |
|
1528 is @code{\"gnuplot\"}. @xref{Installation}.\n\ |
|
1529 @end defvr"); |
|
1530 |
|
1531 DEFVAR (gnuplot_command_plot, "pl", gnuplot_command_plot, |
|
1532 "-*- texinfo -*-\n\ |
|
1533 @defvr {Built-in Variable} gnuplot_command_plot\n\ |
|
1534 @end defvr"); |
|
1535 |
|
1536 DEFVAR (gnuplot_command_replot, "rep", gnuplot_command_replot, |
|
1537 "-*- texinfo -*-\n\ |
|
1538 @defvr {Built-in Variable} gnuplot_command_replot\n\ |
|
1539 @end defvr"); |
|
1540 |
|
1541 DEFVAR (gnuplot_command_splot, "sp", gnuplot_command_splot, |
|
1542 "-*- texinfo -*-\n\ |
|
1543 @defvr {Built-in Variable} gnuplot_command_splot\n\ |
|
1544 @end defvr"); |
|
1545 |
|
1546 DEFVAR (gnuplot_command_using, "u", gnuplot_command_using, |
|
1547 "-*- texinfo -*-\n\ |
|
1548 @defvr {Built-in Variable} gnuplot_command_using\n\ |
|
1549 @end defvr"); |
|
1550 |
|
1551 DEFVAR (gnuplot_command_with, "w", gnuplot_command_with, |
|
1552 "-*- texinfo -*-\n\ |
|
1553 @defvr {Built-in Variable} gnuplot_command_with\n\ |
|
1554 @end defvr"); |
|
1555 |
|
1556 DEFVAR (gnuplot_command_axes, "ax", gnuplot_command_axes, |
|
1557 "-*- texinfo -*-\n\ |
|
1558 @defvr {Built-in Variable} gnuplot_command_axes\n\ |
|
1559 @end defvr"); |
|
1560 |
|
1561 DEFVAR (gnuplot_command_title, "t", gnuplot_command_title, |
|
1562 "-*- texinfo -*-\n\ |
|
1563 @defvr {Built-in Variable} gnuplot_command_title\n\ |
|
1564 @end defvr"); |
|
1565 |
|
1566 DEFVAR (gnuplot_command_end, "\n", gnuplot_command_end, |
|
1567 "-*- texinfo -*-\n\ |
|
1568 @defvr {Built-in Variable} gnuplot_command_end\n\ |
|
1569 @end defvr"); |
|
1570 |
|
1571 #if defined (GNUPLOT_HAS_FRAMES) |
|
1572 bool with_frames = true; |
|
1573 #else |
|
1574 bool with_frames = false; |
|
1575 #endif |
|
1576 |
|
1577 DEFVAR (gnuplot_has_frames, with_frames, gnuplot_has_frames, |
|
1578 "-*- texinfo -*-\n\ |
|
1579 @defvr {Built-in Variable} gnuplot_has_frames\n\ |
|
1580 If the value of this variable is nonzero, Octave assumes that your copy\n\ |
|
1581 of gnuplot has support for multiple frames that is included in recent\n\ |
|
1582 3.6beta releases. Its initial value is determined by configure, but it\n\ |
|
1583 can be changed in your startup script or at the command line in case\n\ |
|
1584 configure got it wrong, or if you upgrade your gnuplot installation.\n\ |
|
1585 @end defvr"); |
|
1586 |
|
1587 return retval; |
|
1588 } |