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