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