5102
|
1 %option prefix="gpt" |
|
2 %option noyywrap |
|
3 |
|
4 %{ |
5215
|
5 // PKG_ADD: mark_as_rawcommand ("__gnuplot_plot__"); |
|
6 // PKG_ADD: mark_as_rawcommand ("__gnuplot_set__"); |
|
7 // PKG_ADD: mark_as_rawcommand ("__gnuplot_splot__"); |
|
8 // PKG_ADD: mark_as_rawcommand ("__gnuplot_replot__"); |
|
9 |
5102
|
10 // PKG_ADD: mark_as_rawcommand ("gplot"); |
|
11 // PKG_ADD: mark_as_rawcommand ("gset"); |
|
12 // PKG_ADD: mark_as_rawcommand ("gsplot"); |
|
13 |
5215
|
14 // PKG_ADD: mark_as_command ("__gnuplot_show__"); |
|
15 |
5102
|
16 // PKG_ADD: mark_as_command ("gshow"); |
5215
|
17 |
5102
|
18 // PKG_ADD: mark_as_command ("hold"); |
5215
|
19 |
5102
|
20 // PKG_ADD: mark_as_command ("set"); |
|
21 // PKG_ADD: mark_as_command ("show"); |
|
22 |
5215
|
23 // PKG_ADD: __gnuplot_init__ (); |
5102
|
24 |
|
25 // PKG_ADD: atexit ("closeplot"); |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include <string> |
|
32 #include <fstream> |
|
33 #include <iostream> |
|
34 |
|
35 #ifdef HAVE_UNISTD_H |
|
36 #ifdef HAVE_SYS_TYPES_H |
|
37 #include <sys/types.h> |
|
38 #endif |
|
39 #include <unistd.h> |
|
40 #endif |
|
41 |
|
42 #include "file-ops.h" |
|
43 |
|
44 #include "defun-dld.h" |
|
45 #include "file-io.h" |
|
46 #include "gripes.h" |
|
47 #include "load-save.h" |
|
48 #include "parse.h" |
|
49 #include "procstream.h" |
|
50 #include "sighandlers.h" |
|
51 #include "utils.h" |
|
52 #include "variables.h" |
|
53 |
|
54 enum _toktype |
|
55 { |
|
56 START_PAREN = 1, |
|
57 END_PAREN, |
|
58 START_BRACE, |
|
59 END_BRACE, |
|
60 START_BRACKET, |
|
61 END_BRACKET, |
|
62 COLON, |
|
63 SEMICOLON, |
|
64 COMMA, |
|
65 QUOTE, |
|
66 IDENT, |
|
67 NUMBER, |
|
68 BINOP, |
|
69 UNOP, |
|
70 STRING, |
|
71 OTHER, |
|
72 TITLE, |
|
73 USING, |
|
74 WITH, |
|
75 AXES, |
|
76 CLEAR |
|
77 }; |
|
78 |
|
79 typedef bool (*pred) (const int); |
|
80 |
|
81 class |
|
82 gpt_parse_error |
|
83 { |
|
84 public: |
|
85 gpt_parse_error (void) : msg () { } |
|
86 gpt_parse_error (std::string errmsg) : msg (errmsg) { } |
|
87 |
|
88 std::string msg; |
|
89 }; |
|
90 |
|
91 static int is_plot_keyword (const std::string& s); |
|
92 |
|
93 static int handle_string (char delim); |
|
94 |
|
95 static inline bool can_be_plotkw (void); |
|
96 |
|
97 static bool gpt_quote_is_transpose; |
|
98 static bool gpt_allow_plotkw; |
|
99 static int gpt_parens; |
|
100 static int gpt_brackets; |
|
101 static int gpt_braces; |
|
102 |
|
103 static int send_to_plot_stream (const std::string& cmd); |
|
104 |
|
105 // needed by handle_string |
|
106 static char string_buf[256]; |
|
107 |
|
108 %} |
|
109 |
|
110 D [0-9] |
|
111 S [ \t] |
|
112 IDENT ([_a-zA-Z@][_a-zA-Z0-9]*) |
|
113 EXPON ([DdEe][+-]?{D}+) |
|
114 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
|
115 NOT ((\~)|(\!)) |
|
116 /* NOT is not strictly a binary operator, but is close enough for us. */ |
|
117 BINOP (({NOT})|(\.?([\*/\\^+-]|\*\*)=?)|([<=~!>&|]=)|([=&|<>]{1,2})|(<<=)|(>>=)|(\.)) |
5106
|
118 /* single quote (') transpose operator is handled separately. */ |
|
119 UNOP ((\+\+)|(\-\-)|(\.')) |
5102
|
120 |
|
121 %% |
|
122 |
|
123 "(" { |
|
124 gpt_quote_is_transpose = false; |
|
125 gpt_parens++; |
|
126 return START_PAREN; |
|
127 } |
|
128 |
|
129 ")" { |
|
130 gpt_quote_is_transpose = true; |
|
131 gpt_parens--; |
|
132 return END_PAREN; |
|
133 } |
|
134 |
|
135 "{" { |
|
136 gpt_quote_is_transpose = false; |
|
137 gpt_braces++; |
|
138 return START_BRACE; |
|
139 } |
|
140 |
|
141 "}" { |
|
142 gpt_quote_is_transpose = true; |
|
143 gpt_braces--; |
|
144 return END_BRACE; |
|
145 } |
|
146 |
|
147 "[" { |
|
148 gpt_quote_is_transpose = false; |
|
149 gpt_brackets++; |
|
150 return START_BRACKET; |
|
151 } |
|
152 |
|
153 "]" { |
|
154 gpt_quote_is_transpose = true; |
|
155 gpt_brackets--; |
|
156 return END_BRACKET; |
|
157 } |
|
158 |
|
159 ":" { |
|
160 gpt_quote_is_transpose = false; |
|
161 return COLON; |
|
162 } |
|
163 |
|
164 ";" { |
|
165 gpt_quote_is_transpose = false; |
|
166 return SEMICOLON; |
|
167 } |
|
168 |
|
169 "," { |
|
170 gpt_quote_is_transpose = false; |
|
171 return COMMA; |
|
172 } |
|
173 |
|
174 "'" { |
|
175 if (gpt_quote_is_transpose) |
|
176 { |
|
177 gpt_allow_plotkw = true; |
|
178 return QUOTE; |
|
179 } |
|
180 else |
|
181 { |
|
182 gpt_quote_is_transpose = true; |
|
183 gpt_allow_plotkw = true; |
|
184 return handle_string ('\''); |
|
185 } |
|
186 } |
|
187 |
|
188 "\"" { |
|
189 return handle_string ('"'); |
|
190 } |
|
191 |
|
192 {IDENT} { |
|
193 int itok; |
|
194 if (can_be_plotkw () && (itok = is_plot_keyword (yytext))) |
|
195 { |
|
196 gpt_quote_is_transpose = false; |
|
197 gpt_allow_plotkw = true; |
|
198 return itok; |
|
199 } |
|
200 else if (std::string (yytext) == "function") |
|
201 { |
|
202 throw gpt_parse_error ("The 'function' keyword is not allowed in plot commands."); |
|
203 } |
|
204 else |
|
205 { |
|
206 gpt_quote_is_transpose = true; |
|
207 gpt_allow_plotkw = true; |
|
208 return IDENT; |
|
209 } |
|
210 } |
|
211 |
|
212 {D}+/\.[\*/\\^'] | /* ' */ |
|
213 {NUMBER} { |
|
214 gpt_quote_is_transpose = true; |
|
215 gpt_allow_plotkw = true; |
|
216 return NUMBER; |
|
217 } |
|
218 |
|
219 {BINOP} { |
|
220 gpt_quote_is_transpose = false; |
|
221 gpt_allow_plotkw = false; |
|
222 return BINOP; |
|
223 } |
|
224 |
|
225 {UNOP} { |
|
226 gpt_quote_is_transpose = false; |
|
227 gpt_allow_plotkw = true; |
|
228 return UNOP; |
|
229 } |
|
230 |
|
231 {S} { /* Ignore spaces and tabs outside of character strings. */ } |
|
232 |
|
233 . { |
|
234 gpt_quote_is_transpose = false; |
|
235 gpt_allow_plotkw = true; |
|
236 warning ("unknown token = \"%s\" in plot command", yytext); |
|
237 return OTHER; |
|
238 } |
|
239 |
|
240 %% |
|
241 |
|
242 // If TRUE, a replot command is issued automatically each time a plot |
|
243 // changes in some way. |
|
244 static bool Vautomatic_replot; |
|
245 |
|
246 // The name of the shell command to execute to start gnuplot. |
|
247 static std::string Vgnuplot_binary; |
|
248 |
|
249 // TRUE if gnuplot appears to support multiple plot windows with X11. |
|
250 static bool Vgnuplot_has_frames; |
|
251 |
|
252 // The number of lines we've plotted so far. |
|
253 static int plot_line_count = 0; |
|
254 |
|
255 // Is this a parametric plot? Makes a difference for 3D plotting. |
|
256 static bool parametric_plot = false; |
|
257 |
|
258 // The gnuplot terminal type. |
|
259 static std::string gnuplot_terminal_type; |
|
260 |
|
261 // Should the graph window be cleared before plotting the next line? |
|
262 static bool clear_before_plotting = true; |
|
263 |
|
264 // Pipe to gnuplot. |
|
265 static oprocstream *plot_stream = 0; |
|
266 |
|
267 // Gnuplot command strings that we use. |
|
268 static std::string Vgnuplot_command_plot; |
|
269 static std::string Vgnuplot_command_replot; |
|
270 static std::string Vgnuplot_command_splot; |
|
271 static std::string Vgnuplot_command_using; |
|
272 static std::string Vgnuplot_command_with; |
|
273 static std::string Vgnuplot_command_axes; |
|
274 static std::string Vgnuplot_command_title; |
|
275 static std::string Vgnuplot_command_end; |
|
276 |
|
277 // (almost) copy-paste code from pt-plot.cc |
|
278 |
|
279 static std::string |
|
280 save_in_tmp_file (const octave_value& t, int ndim = 2, bool parametric = false) |
|
281 { |
|
282 std::string name = file_ops::tempnam ("", "oct-"); |
|
283 |
|
284 if (! name.empty ()) |
|
285 { |
|
286 std::ofstream file (name.c_str ()); |
|
287 |
|
288 if (file) |
|
289 { |
|
290 switch (ndim) |
|
291 { |
|
292 case 2: |
|
293 save_ascii_data_for_plotting (file, t, name); |
|
294 break; |
|
295 |
|
296 case 3: |
|
297 save_three_d (file, t, parametric); |
|
298 break; |
|
299 |
|
300 default: |
|
301 gripe_2_or_3_dim_plot (); |
|
302 break; |
|
303 } |
|
304 } |
|
305 else |
|
306 { |
|
307 error ("couldn't open temporary output file `%s'", name.c_str ()); |
|
308 name.resize (0); |
|
309 } |
|
310 } |
|
311 |
|
312 return name; |
|
313 } |
|
314 |
|
315 static void |
5142
|
316 close_plot_stream (bool remove_from_child_list = true) |
5102
|
317 { |
|
318 if (plot_stream) |
|
319 { |
5142
|
320 if (remove_from_child_list) |
|
321 octave_child_list::remove (plot_stream->pid ()); |
|
322 |
5102
|
323 send_to_plot_stream ("\nquit\n"); |
5142
|
324 |
5102
|
325 delete plot_stream; |
|
326 plot_stream = 0; |
|
327 } |
|
328 |
|
329 plot_line_count = 0; |
|
330 } |
|
331 |
5142
|
332 static bool |
|
333 plot_stream_event_handler (pid_t pid, int status) |
5102
|
334 { |
5142
|
335 bool retval = false; |
|
336 |
|
337 if (pid > 0) |
|
338 { |
|
339 if (WIFEXITED (status) || WIFSIGNALLED (status)) |
|
340 { |
|
341 close_plot_stream (false); |
5102
|
342 |
5142
|
343 warning ("connection to external plotter (pid = %d) lost --", pid); |
|
344 warning ("please try your plot command(s) again"); |
|
345 |
|
346 // Request removal of this PID from the list of child |
|
347 // processes. |
|
348 |
|
349 retval = true; |
|
350 } |
|
351 } |
|
352 |
|
353 return retval; |
5102
|
354 } |
|
355 |
|
356 static void |
|
357 open_plot_stream (void) |
|
358 { |
|
359 static bool initialized = false; |
|
360 |
|
361 if (plot_stream && ! *plot_stream) |
|
362 { |
|
363 delete plot_stream; |
|
364 plot_stream = 0; |
|
365 } |
|
366 |
|
367 if (! plot_stream) |
|
368 { |
|
369 initialized = false; |
|
370 |
|
371 plot_line_count = 0; |
|
372 |
|
373 std::string plot_prog; |
|
374 |
|
375 if (Vgnuplot_binary.empty ()) |
|
376 plot_prog = "gnuplot"; |
|
377 else |
|
378 plot_prog = "\"" + Vgnuplot_binary + "\""; |
|
379 |
|
380 // XXX FIXME XXX -- I'm not sure this is the right thing to do, |
|
381 // but without it, C-c at the octave prompt will kill gnuplot... |
|
382 |
|
383 #if defined (HAVE_POSIX_SIGNALS) |
|
384 sigset_t set, oset; |
|
385 sigemptyset (&set); |
|
386 sigaddset (&set, SIGINT); |
|
387 sigprocmask (SIG_BLOCK, &set, &oset); |
|
388 #else |
|
389 volatile octave_interrupt_handler old_interrupt_handler |
|
390 = octave_ignore_interrupts (); |
|
391 #endif |
|
392 |
|
393 plot_stream = new oprocstream (plot_prog.c_str ()); |
|
394 |
|
395 if (plot_stream) |
|
396 { |
|
397 if (! *plot_stream) |
|
398 { |
|
399 delete plot_stream; |
|
400 plot_stream = 0; |
|
401 |
|
402 error ("plot: unable to open pipe to `%s'", plot_prog.c_str ()); |
|
403 } |
|
404 else |
5142
|
405 octave_child_list::insert (plot_stream->pid (), |
|
406 plot_stream_event_handler); |
5102
|
407 } |
|
408 else |
|
409 error ("plot: unable to open pipe to `%s'", plot_prog.c_str ()); |
|
410 |
|
411 #if defined (HAVE_POSIX_SIGNALS) |
|
412 sigprocmask (SIG_SETMASK, &oset, 0); |
|
413 #else |
|
414 octave_set_interrupt_handler (old_interrupt_handler); |
|
415 #endif |
|
416 } |
|
417 |
|
418 if (! error_state && plot_stream && *plot_stream && ! initialized) |
|
419 { |
|
420 initialized = true; |
|
421 |
|
422 *plot_stream << "set style data lines\n"; |
|
423 |
|
424 if (! gnuplot_terminal_type.empty ()) |
|
425 *plot_stream << "set term " << gnuplot_terminal_type |
|
426 << Vgnuplot_command_end << "\n"; |
|
427 } |
|
428 } |
|
429 |
|
430 static int |
|
431 send_to_plot_stream (const std::string& cmd) |
|
432 { |
|
433 if (! (plot_stream && *plot_stream)) |
|
434 { |
|
435 open_plot_stream (); |
|
436 |
|
437 if (error_state) |
|
438 return -1; |
|
439 } |
|
440 |
|
441 int replot_len = Vgnuplot_command_replot.length (); |
|
442 |
|
443 bool is_replot = (Vgnuplot_command_replot == cmd.substr (0, replot_len)); |
|
444 |
5152
|
445 if (! (plot_line_count == 0 && is_replot)) |
5102
|
446 { |
|
447 *plot_stream << cmd; |
|
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)) |
5152
|
944 return 1; |
5102
|
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 |
5152
|
964 int status = 0; |
5102
|
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 + " "; |
5152
|
980 } |
5102
|
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; |
5152
|
997 } |
5102
|
998 |
|
999 if (file.length () > 0) |
|
1000 { |
|
1001 mark_for_deletion (file); |
|
1002 outstr += "'" + file + "' "; |
|
1003 } |
5152
|
1004 } |
5102
|
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 (clearplot, , , |
|
1129 "-*- texinfo -*-\n\ |
|
1130 @deftypefn {Built-in Function} {} clearplot\n\ |
|
1131 @deftypefnx {Built-in Function} {} clg\n\ |
|
1132 Clear the plot window and any titles or axis labels. The name\n\ |
|
1133 @code{clg} is aliased to @code{clearplot} for compatibility with\n\ |
|
1134 @sc{Matlab}.\n\ |
|
1135 @end deftypefn") |
|
1136 { |
|
1137 octave_value_list retval; |
|
1138 |
|
1139 send_to_plot_stream ("clear\n"); |
|
1140 |
|
1141 // XXX FIXME XXX -- instead of just clearing these things, it would |
|
1142 // be nice if we could reset things to a user-specified default |
|
1143 // state. |
|
1144 |
|
1145 send_to_plot_stream ("set title\n"); |
|
1146 send_to_plot_stream ("set xlabel\n"); |
|
1147 send_to_plot_stream ("set ylabel\n"); |
|
1148 send_to_plot_stream ("set nogrid\n"); |
|
1149 send_to_plot_stream ("set nolabel\n"); |
|
1150 |
|
1151 // This makes a simple `replot' not work after a `clearplot' command |
|
1152 // has been issued. |
|
1153 |
|
1154 plot_line_count = 0; |
|
1155 |
|
1156 return retval; |
|
1157 } |
|
1158 |
|
1159 DEFUN_DLD (closeplot, , , |
|
1160 "-*- texinfo -*-\n\ |
|
1161 @deftypefn {Built-in Function} {} closeplot\n\ |
|
1162 Close stream to the @code{gnuplot} subprocess. If you are using X11,\n\ |
|
1163 this will close the plot window.\n\ |
|
1164 @end deftypefn") |
|
1165 { |
|
1166 octave_value_list retval; |
|
1167 close_plot_stream (); |
|
1168 return retval; |
|
1169 } |
|
1170 |
|
1171 DEFUN_DLD (hold, args, , |
|
1172 "-*- texinfo -*-\n\ |
|
1173 @deftypefn {Built-in Function} {} hold @var{args}\n\ |
|
1174 Tell Octave to `hold' the current data on the plot when executing\n\ |
|
1175 subsequent plotting commands. This allows you to execute a series of\n\ |
|
1176 plot commands and have all the lines end up on the same figure. The\n\ |
|
1177 default is for each new plot command to clear the plot device first.\n\ |
|
1178 For example, the command\n\ |
|
1179 \n\ |
|
1180 @example\n\ |
|
1181 hold on\n\ |
|
1182 @end example\n\ |
|
1183 \n\ |
|
1184 @noindent\n\ |
|
1185 turns the hold state on. An argument of @code{off} turns the hold state\n\ |
|
1186 off, and @code{hold} with no arguments toggles the current hold state.\n\ |
|
1187 @end deftypefn") |
|
1188 { |
|
1189 octave_value_list retval; |
|
1190 |
|
1191 int argc = args.length () + 1; |
|
1192 |
|
1193 string_vector argv = args.make_argv ("hold"); |
|
1194 |
|
1195 if (error_state) |
|
1196 return retval; |
|
1197 |
|
1198 switch (argc) |
|
1199 { |
|
1200 case 1: |
|
1201 clear_before_plotting = ! clear_before_plotting; |
|
1202 break; |
|
1203 |
|
1204 case 2: |
|
1205 if (argv[1] == "on") |
|
1206 clear_before_plotting = false; |
|
1207 else if (argv[1] == "off") |
|
1208 clear_before_plotting = true; |
|
1209 else |
|
1210 print_usage ("hold"); |
|
1211 break; |
|
1212 |
|
1213 default: |
|
1214 print_usage ("hold"); |
|
1215 break; |
|
1216 } |
|
1217 |
|
1218 return retval; |
|
1219 } |
|
1220 |
|
1221 DEFUN_DLD (ishold, , , |
|
1222 "-*- texinfo -*-\n\ |
|
1223 @deftypefn {Built-in Function} {} ishold\n\ |
|
1224 Return 1 if the next line will be added to the current plot, or 0 if\n\ |
|
1225 the plot device will be cleared before drawing the next line.\n\ |
|
1226 @end deftypefn") |
|
1227 { |
|
1228 return octave_value (! clear_before_plotting); |
|
1229 } |
|
1230 |
|
1231 DEFUN_DLD (purge_tmp_files, , , |
|
1232 "-*- texinfo -*-\n\ |
|
1233 @deftypefn {Built-in Function} {} purge_tmp_files\n\ |
|
1234 Delete the temporary files created by the plotting commands.\n\ |
|
1235 \n\ |
|
1236 Octave creates temporary data files for @code{gnuplot} and then sends\n\ |
|
1237 commands to @code{gnuplot} through a pipe. Octave will delete the\n\ |
|
1238 temporary files on exit, but if you are doing a lot of plotting you may\n\ |
|
1239 want to clean up in the middle of a session.\n\ |
|
1240 \n\ |
|
1241 A future version of Octave will eliminate the need to use temporary\n\ |
|
1242 files to hold the plot data.\n\ |
|
1243 @end deftypefn") |
|
1244 { |
|
1245 octave_value_list retval; |
|
1246 cleanup_tmp_files (); |
|
1247 return retval; |
|
1248 } |
|
1249 |
5215
|
1250 DEFUN_DLD (__gnuplot_raw__, args, , |
5102
|
1251 "-*- texinfo -*-\n\ |
5215
|
1252 @deftypefn {Built-in Function} {} __gnuplot_raw__ (@var{string})\n\ |
5102
|
1253 Send @var{string} directly to gnuplot subprocess.\n\ |
|
1254 @end deftypefn") |
|
1255 { |
|
1256 octave_value_list retval; |
|
1257 |
|
1258 if (args.length () == 1 && args(0).is_string ()) |
|
1259 { |
|
1260 std::string cmd = args(0).string_value (); |
|
1261 |
|
1262 if (! (plot_stream && *plot_stream)) |
|
1263 open_plot_stream (); |
|
1264 |
|
1265 if (! error_state) |
|
1266 { |
|
1267 *plot_stream << cmd; |
|
1268 |
|
1269 plot_stream->flush (); |
|
1270 } |
|
1271 } |
|
1272 else |
|
1273 print_usage ("raw"); |
|
1274 |
|
1275 return retval; |
|
1276 } |
|
1277 |
5215
|
1278 DEFUN_DLD (__gnuplot_set__, args, , |
5102
|
1279 "-*- texinfo -*-\n\ |
5215
|
1280 @deffn {Command} __gnuplot_set__ options\n\ |
5102
|
1281 Set plotting options for gnuplot\n\ |
|
1282 @end deffn") |
|
1283 { |
|
1284 octave_value_list retval; |
|
1285 |
|
1286 int argc = args.length () + 1; |
|
1287 |
|
1288 string_vector argv = args.make_argv ("set"); |
|
1289 |
|
1290 if (error_state) |
|
1291 return retval; |
|
1292 |
|
1293 OSSTREAM plot_buf; |
|
1294 |
|
1295 if (argc > 1) |
|
1296 { |
|
1297 if (almost_match ("parametric", argv[1], 3)) |
|
1298 parametric_plot = true; |
|
1299 else if (almost_match ("noparametric", argv[1], 5)) |
|
1300 parametric_plot = false; |
|
1301 else if (almost_match ("term", argv[1], 1)) |
|
1302 { |
|
1303 gnuplot_terminal_type = ""; |
|
1304 OSSTREAM buf; |
|
1305 int i; |
|
1306 for (i = 2; i < argc-1; i++) |
|
1307 buf << argv[i] << " "; |
|
1308 if (i < argc) |
|
1309 buf << argv[i]; |
|
1310 buf << Vgnuplot_command_end << OSSTREAM_ENDS; |
|
1311 gnuplot_terminal_type = OSSTREAM_STR (buf); |
|
1312 OSSTREAM_FREEZE (buf); |
|
1313 } |
|
1314 } |
|
1315 |
|
1316 int i; |
|
1317 for (i = 0; i < argc-1; i++) |
|
1318 plot_buf << argv[i] << " "; |
|
1319 |
|
1320 if (i < argc) |
|
1321 plot_buf << argv[i]; |
|
1322 |
|
1323 plot_buf << Vgnuplot_command_end << OSSTREAM_ENDS; |
|
1324 |
|
1325 send_to_plot_stream (OSSTREAM_STR (plot_buf)); |
|
1326 |
|
1327 OSSTREAM_FREEZE (plot_buf); |
|
1328 |
|
1329 return retval; |
|
1330 } |
|
1331 |
5215
|
1332 DEFUN_DLD (__gnuplot_show__, args, , |
5102
|
1333 "-*- texinfo -*-\n\ |
5215
|
1334 @deffn {Command} __gnuplot_show__ options\n\ |
5102
|
1335 Show plotting options.\n\ |
|
1336 @end deffn") |
|
1337 { |
|
1338 octave_value_list retval; |
|
1339 |
|
1340 int argc = args.length () + 1; |
|
1341 |
|
1342 string_vector argv = args.make_argv ("show"); |
|
1343 |
|
1344 if (error_state) |
|
1345 return retval; |
|
1346 |
|
1347 OSSTREAM plot_buf; |
|
1348 |
|
1349 int i; |
|
1350 for (i = 0; i < argc-1; i++) |
|
1351 plot_buf << argv[i] << " "; |
|
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 |
5215
|
1364 DEFUN_DLD (__gnuplot_plot__, args, , |
|
1365 "Plot with gnuplot.\n") |
|
1366 { |
|
1367 doplot ("plot", args); |
|
1368 return octave_value_list (); |
|
1369 } |
|
1370 |
|
1371 DEFUN_DLD (__gnuplot_splot__, args, , |
|
1372 "Plot with gnuplot.\n") |
|
1373 { |
|
1374 doplot ("splot", args); |
|
1375 return octave_value_list (); |
|
1376 } |
|
1377 |
|
1378 DEFUN_DLD (__gnuplot_replot__, args, , |
|
1379 "Plot with gnuplot.\n") |
5102
|
1380 { |
5215
|
1381 doplot ("replot", args); |
|
1382 return octave_value_list (); |
|
1383 } |
|
1384 |
|
1385 // Deprecated functions. |
|
1386 |
|
1387 #define WARN_DEPRECATED(FOLD, FNEW) \ |
|
1388 do \ |
|
1389 { \ |
|
1390 static bool warned = false; \ |
|
1391 if (! warned) \ |
|
1392 { \ |
|
1393 warned = true; \ |
|
1394 warning (#FOLD " is deprecated and will be removed from a future"); \ |
|
1395 warning ("version of Octave."); \ |
|
1396 warning ("You should use the higher-level plot functions"); \ |
|
1397 warning ("(\"plot\", \"mesh\", \"semilogx\", etc.) instead"); \ |
|
1398 warning ("of the low-level plotting commands."); \ |
|
1399 warning ("If you absolutely must use this function, use the"); \ |
|
1400 warning ("internal version " #FNEW " instead."); \ |
|
1401 } \ |
|
1402 } \ |
|
1403 while (0) |
|
1404 |
|
1405 #define DEPRECATED_BODY(FOLD, FNEW) \ |
|
1406 WARN_DEPRECATED (FOLD, FNEW); \ |
|
1407 return feval (#FNEW, args) |
|
1408 |
|
1409 // We can't further simplify this by putting the DEFUN_DLD in a macro |
|
1410 // because then the mk-oct-links script will fail. |
|
1411 |
|
1412 DEFUN_DLD (gplot, args, , |
|
1413 "") |
|
1414 { |
|
1415 DEPRECATED_BODY (gplot, __gnuplot_plot__); |
|
1416 } |
|
1417 |
|
1418 DEFUN_DLD (gsplot, args, , |
|
1419 "") |
|
1420 { |
|
1421 DEPRECATED_BODY (gsplot, __gnuplot_splot__); |
|
1422 } |
|
1423 |
|
1424 DEFUN_DLD (graw, args, , |
|
1425 "") |
|
1426 { |
5251
|
1427 DEPRECATED_BODY (graw, __gnuplot_raw__); |
5215
|
1428 } |
|
1429 |
|
1430 DEFUN_DLD (gset, args, , |
|
1431 "") |
|
1432 { |
|
1433 DEPRECATED_BODY (gset, __gnuplot_set__); |
|
1434 } |
|
1435 |
|
1436 DEFUN_DLD (gshow, args, , |
|
1437 "") |
|
1438 { |
5251
|
1439 DEPRECATED_BODY (gshow, __gnuplot_show__); |
5102
|
1440 } |
|
1441 |
|
1442 static int |
|
1443 automatic_replot (void) |
|
1444 { |
|
1445 Vautomatic_replot = check_preference ("automatic_replot"); |
|
1446 |
|
1447 return 0; |
|
1448 } |
|
1449 |
|
1450 static int |
|
1451 set_string_var (std::string& var, const char *nm) |
|
1452 { |
|
1453 int retval = 0; |
|
1454 |
|
1455 std::string s = builtin_string_variable (nm); |
|
1456 |
|
1457 if (s.empty ()) |
|
1458 { |
|
1459 gripe_invalid_value_specified (nm); |
|
1460 retval = -1; |
|
1461 } |
|
1462 else |
|
1463 var = s; |
|
1464 |
|
1465 return retval; |
|
1466 } |
|
1467 |
|
1468 static int |
|
1469 gnuplot_binary (void) |
|
1470 { |
|
1471 return set_string_var (Vgnuplot_binary, "gnuplot_binary"); |
|
1472 } |
|
1473 |
|
1474 static int |
|
1475 gnuplot_command_plot (void) |
|
1476 { |
|
1477 return set_string_var (Vgnuplot_command_plot, "gnuplot_command_plot"); |
|
1478 } |
|
1479 |
|
1480 static int |
|
1481 gnuplot_command_replot (void) |
|
1482 { |
|
1483 return set_string_var (Vgnuplot_command_replot, "gnuplot_command_replot"); |
|
1484 } |
|
1485 |
|
1486 static int |
|
1487 gnuplot_command_splot (void) |
|
1488 { |
|
1489 return set_string_var (Vgnuplot_command_splot, "gnuplot_command_splot"); |
|
1490 } |
|
1491 |
|
1492 static int |
|
1493 gnuplot_command_using (void) |
|
1494 { |
|
1495 return set_string_var (Vgnuplot_command_using, "gnuplot_command_using"); |
|
1496 } |
|
1497 |
|
1498 static int |
|
1499 gnuplot_command_with (void) |
|
1500 { |
|
1501 return set_string_var (Vgnuplot_command_with, "gnuplot_command_with"); |
|
1502 } |
|
1503 |
|
1504 static int |
|
1505 gnuplot_command_axes (void) |
|
1506 { |
|
1507 return set_string_var (Vgnuplot_command_axes, "gnuplot_command_axes"); |
|
1508 } |
|
1509 |
|
1510 static int |
|
1511 gnuplot_command_title (void) |
|
1512 { |
|
1513 return set_string_var (Vgnuplot_command_title, "gnuplot_command_title"); |
|
1514 } |
|
1515 |
|
1516 static int |
|
1517 gnuplot_command_end (void) |
|
1518 { |
|
1519 return set_string_var (Vgnuplot_command_end, "gnuplot_command_end"); |
|
1520 } |
|
1521 |
|
1522 static int |
|
1523 gnuplot_has_frames (void) |
|
1524 { |
|
1525 Vgnuplot_has_frames = check_preference ("gnuplot_has_frames"); |
|
1526 |
|
1527 return 0; |
|
1528 } |
|
1529 |
5215
|
1530 DEFUN_DLD (__gnuplot_init__, , , |
5102
|
1531 "-*- texinfo -*-\n\ |
5215
|
1532 @deftypefn {Loadable Function} __gnuplot_init__ ()\n\ |
5102
|
1533 @end deftypefn") |
|
1534 { |
|
1535 octave_value_list retval; |
|
1536 |
5215
|
1537 static bool gnuplot_initialized = false; |
5102
|
1538 |
5215
|
1539 if (gnuplot_initialized) |
5102
|
1540 return retval; |
|
1541 |
5215
|
1542 gnuplot_initialized = true; |
5102
|
1543 |
|
1544 DEFVAR (automatic_replot, true, automatic_replot, |
|
1545 "-*- texinfo -*-\n\ |
|
1546 @defvr {Built-in Variable} automatic_replot\n\ |
|
1547 You can tell Octave to redisplay the plot each time anything about it\n\ |
|
1548 changes by setting the value of the builtin variable\n\ |
|
1549 @code{automatic_replot} to a nonzero value. Although it is fairly\n\ |
|
1550 inefficient, especially for large plots, the default value is 1 for\n\ |
|
1551 compatibility with Matlab.\n\ |
|
1552 @end defvr"); |
|
1553 |
|
1554 DEFVAR (gnuplot_binary, GNUPLOT_BINARY, gnuplot_binary, |
|
1555 "-*- texinfo -*-\n\ |
|
1556 @defvr {Built-in Variable} gnuplot_binary\n\ |
|
1557 The name of the program invoked by the plot command. The default value\n\ |
|
1558 is @code{\"gnuplot\"}. @xref{Installation}.\n\ |
|
1559 @end defvr"); |
|
1560 |
|
1561 DEFVAR (gnuplot_command_plot, "pl", gnuplot_command_plot, |
|
1562 "-*- texinfo -*-\n\ |
|
1563 @defvr {Built-in Variable} gnuplot_command_plot\n\ |
|
1564 @end defvr"); |
|
1565 |
|
1566 DEFVAR (gnuplot_command_replot, "rep", gnuplot_command_replot, |
|
1567 "-*- texinfo -*-\n\ |
|
1568 @defvr {Built-in Variable} gnuplot_command_replot\n\ |
|
1569 @end defvr"); |
|
1570 |
|
1571 DEFVAR (gnuplot_command_splot, "sp", gnuplot_command_splot, |
|
1572 "-*- texinfo -*-\n\ |
|
1573 @defvr {Built-in Variable} gnuplot_command_splot\n\ |
|
1574 @end defvr"); |
|
1575 |
|
1576 DEFVAR (gnuplot_command_using, "u", gnuplot_command_using, |
|
1577 "-*- texinfo -*-\n\ |
|
1578 @defvr {Built-in Variable} gnuplot_command_using\n\ |
|
1579 @end defvr"); |
|
1580 |
|
1581 DEFVAR (gnuplot_command_with, "w", gnuplot_command_with, |
|
1582 "-*- texinfo -*-\n\ |
|
1583 @defvr {Built-in Variable} gnuplot_command_with\n\ |
|
1584 @end defvr"); |
|
1585 |
|
1586 DEFVAR (gnuplot_command_axes, "ax", gnuplot_command_axes, |
|
1587 "-*- texinfo -*-\n\ |
|
1588 @defvr {Built-in Variable} gnuplot_command_axes\n\ |
|
1589 @end defvr"); |
|
1590 |
|
1591 DEFVAR (gnuplot_command_title, "t", gnuplot_command_title, |
|
1592 "-*- texinfo -*-\n\ |
|
1593 @defvr {Built-in Variable} gnuplot_command_title\n\ |
|
1594 @end defvr"); |
|
1595 |
|
1596 DEFVAR (gnuplot_command_end, "\n", gnuplot_command_end, |
|
1597 "-*- texinfo -*-\n\ |
|
1598 @defvr {Built-in Variable} gnuplot_command_end\n\ |
|
1599 @end defvr"); |
|
1600 |
|
1601 #if defined (GNUPLOT_HAS_FRAMES) |
|
1602 bool with_frames = true; |
|
1603 #else |
|
1604 bool with_frames = false; |
|
1605 #endif |
|
1606 |
|
1607 DEFVAR (gnuplot_has_frames, with_frames, gnuplot_has_frames, |
|
1608 "-*- texinfo -*-\n\ |
|
1609 @defvr {Built-in Variable} gnuplot_has_frames\n\ |
|
1610 If the value of this variable is nonzero, Octave assumes that your copy\n\ |
|
1611 of gnuplot has support for multiple frames that is included in recent\n\ |
|
1612 3.6beta releases. Its initial value is determined by configure, but it\n\ |
|
1613 can be changed in your startup script or at the command line in case\n\ |
|
1614 configure got it wrong, or if you upgrade your gnuplot installation.\n\ |
|
1615 @end defvr"); |
|
1616 |
|
1617 return retval; |
|
1618 } |