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