1
|
1 // tree-plot.cc -*- C++ -*- |
|
2 /* |
|
3 |
322
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
524
|
28 #if defined (__GNUG__) |
|
29 #pragma implementation |
|
30 #endif |
|
31 |
|
32 #include <sys/types.h> |
|
33 #ifdef HAVE_UNISTD_H |
|
34 #include <unistd.h> |
|
35 #endif |
1
|
36 #include <iostream.h> |
86
|
37 #include <fstream.h> |
1
|
38 #include <strstream.h> |
|
39 |
524
|
40 #include "SLStack.h" |
|
41 #include "procstream.h" |
|
42 |
|
43 #include "user-prefs.h" |
|
44 #include "tree-const.h" |
|
45 #include "tree-plot.h" |
1
|
46 #include "error.h" |
|
47 #include "utils.h" |
|
48 #include "tree.h" |
524
|
49 #include "defun.h" |
1
|
50 |
87
|
51 extern "C" |
|
52 { |
|
53 char *tilde_expand (char *s); /* From readline's tilde.c */ |
|
54 } |
|
55 |
1
|
56 // The number of lines we\'ve plotted so far. |
478
|
57 int plot_line_count; |
1
|
58 |
|
59 // Is this a parametric plot? Makes a difference for 3D plotting. |
|
60 int parametric_plot = 0; |
|
61 |
478
|
62 // Should the graph window be cleared before plotting the next line? |
|
63 int clear_before_plotting = 1; |
|
64 |
524
|
65 // List of files to delete when we exit or crash. |
|
66 static SLStack <char *> tmp_files; |
|
67 |
|
68 // Pipe to gnuplot. |
|
69 static oprocstream plot_stream; |
|
70 |
1
|
71 /* |
|
72 * Plotting, eh? |
|
73 */ |
|
74 |
|
75 tree_plot_command::tree_plot_command (void) |
|
76 { |
524
|
77 range = 0; |
|
78 plot_list = 0; |
1
|
79 ndim = 0; |
|
80 } |
|
81 |
|
82 tree_plot_command::tree_plot_command (tree_subplot_list *plt, int nd) |
|
83 { |
524
|
84 range = 0; |
1
|
85 plot_list = plt; |
|
86 ndim = nd; |
|
87 } |
|
88 |
|
89 tree_plot_command::tree_plot_command (tree_subplot_list *plt, |
|
90 tree_plot_limits *rng, int nd) |
|
91 { |
|
92 range = rng; |
|
93 plot_list = plt; |
|
94 ndim = nd; |
|
95 } |
|
96 |
|
97 tree_plot_command::~tree_plot_command (void) |
|
98 { |
|
99 delete range; |
|
100 delete plot_list; |
|
101 } |
|
102 |
|
103 tree_constant |
|
104 tree_plot_command::eval (int print) |
|
105 { |
|
106 tree_constant retval; |
|
107 |
143
|
108 if (error_state) |
|
109 return retval; |
|
110 |
1
|
111 ostrstream plot_buf; |
|
112 |
|
113 switch (ndim) |
|
114 { |
476
|
115 case 1: |
478
|
116 if (plot_line_count == 0) |
|
117 { |
|
118 if (plot_list) |
|
119 plot_buf << "plot"; |
|
120 else |
|
121 { |
|
122 ::error ("replot: must have something to plot"); |
|
123 return retval; |
|
124 } |
|
125 } |
|
126 else |
|
127 plot_buf << "replot"; |
476
|
128 break; |
1
|
129 case 2: |
478
|
130 if (clear_before_plotting || plot_line_count == 0) |
|
131 { |
|
132 plot_line_count = 0; |
|
133 plot_buf << "plot"; |
|
134 } |
|
135 else |
|
136 plot_buf << "replot"; |
1
|
137 break; |
|
138 case 3: |
478
|
139 { |
|
140 plot_line_count = 0; |
|
141 plot_buf << "splot"; |
|
142 } |
1
|
143 break; |
|
144 default: |
|
145 panic_impossible (); |
|
146 break; |
|
147 } |
|
148 |
524
|
149 if (range) |
478
|
150 { |
|
151 if (plot_line_count == 0) |
|
152 range->print (ndim, plot_buf); |
|
153 else |
|
154 warning ("can't specify new plot ranges with `replot' or while\ |
|
155 hold is on"); |
|
156 } |
1
|
157 |
191
|
158 if (error_state) |
|
159 return retval; |
|
160 |
524
|
161 for (tree_subplot_list *ptr = plot_list; ptr; ptr = ptr->next_elem ()) |
1
|
162 { |
|
163 plot_line_count++; |
|
164 |
|
165 if (ptr != plot_list) |
|
166 plot_buf << ",\\\n "; |
|
167 |
|
168 int status = ptr->print (ndim, plot_buf); |
|
169 if (status < 0) |
|
170 return retval; |
|
171 } |
|
172 |
|
173 plot_buf << "\n" << ends; |
|
174 |
|
175 // Just testing... |
|
176 // char *message = plot_buf.str (); |
|
177 // cout << "[*]" << message << "[*]\n"; |
|
178 |
|
179 if (parametric_plot && ndim == 2) |
|
180 { |
|
181 warning ("can't make 2D parametric plot -- setting noparametric..."); |
|
182 send_to_plot_stream ("set noparametric\n"); |
|
183 char *message = plot_buf.str (); |
|
184 send_to_plot_stream (message); |
|
185 delete [] message; |
|
186 send_to_plot_stream ("set parametric\n"); |
|
187 } |
|
188 else |
|
189 { |
|
190 char *message = plot_buf.str (); |
|
191 send_to_plot_stream (message); |
|
192 delete [] message; |
|
193 } |
|
194 |
|
195 return retval; |
|
196 } |
|
197 |
|
198 tree_subplot_list::tree_subplot_list (void) |
|
199 { |
524
|
200 plot_data = 0; |
|
201 using = 0; |
|
202 title = 0; |
|
203 style = 0; |
|
204 next = 0; |
1
|
205 } |
|
206 |
491
|
207 tree_subplot_list::tree_subplot_list (tree_expression *data) |
1
|
208 { |
|
209 plot_data = data; |
524
|
210 using = 0; |
|
211 title = 0; |
|
212 style = 0; |
|
213 next = 0; |
1
|
214 } |
|
215 |
|
216 tree_subplot_list::tree_subplot_list (tree_subplot_list *t) |
|
217 { |
|
218 plot_data = t->plot_data; |
|
219 using = t->using; |
|
220 title = t->title; |
|
221 style = t->style; |
|
222 next = t->next; |
|
223 } |
|
224 |
491
|
225 tree_subplot_list::tree_subplot_list (tree_subplot_using *u, |
|
226 tree_expression *t, |
1
|
227 tree_subplot_style *s) |
|
228 { |
524
|
229 plot_data = 0; |
1
|
230 using = u; |
|
231 title = t; |
|
232 style = s; |
524
|
233 next = 0; |
1
|
234 } |
|
235 |
|
236 tree_subplot_list::~tree_subplot_list (void) |
|
237 { |
|
238 delete plot_data; |
|
239 delete using; |
|
240 delete title; |
|
241 delete style; |
|
242 delete next; |
|
243 } |
|
244 |
|
245 tree_subplot_list * |
491
|
246 tree_subplot_list::set_data (tree_expression *data) |
1
|
247 { |
|
248 plot_data = data; |
|
249 return this; |
|
250 } |
|
251 |
|
252 tree_subplot_list * |
|
253 tree_subplot_list::chain (tree_subplot_list *t) |
|
254 { |
|
255 tree_subplot_list *tmp = new tree_subplot_list (t); |
|
256 tmp->next = this; |
|
257 return tmp; |
|
258 } |
|
259 |
|
260 tree_subplot_list * |
|
261 tree_subplot_list::reverse (void) |
|
262 { |
|
263 tree_subplot_list *list = this; |
|
264 tree_subplot_list *next; |
524
|
265 tree_subplot_list *prev = 0; |
1
|
266 |
524
|
267 while (list) |
1
|
268 { |
|
269 next = list->next; |
|
270 list->next = prev; |
|
271 prev = list; |
|
272 list = next; |
|
273 } |
|
274 return prev; |
|
275 } |
|
276 |
|
277 tree_subplot_list * |
|
278 tree_subplot_list::next_elem (void) |
|
279 { |
|
280 return next; |
|
281 } |
|
282 |
|
283 tree_constant |
|
284 tree_subplot_list::eval (int print) |
|
285 { |
|
286 return plot_data->eval (0); |
|
287 } |
|
288 |
|
289 int |
|
290 tree_subplot_list::print (int ndim, ostrstream& plot_buf) |
|
291 { |
|
292 int nc = 0; |
524
|
293 if (plot_data) |
1
|
294 { |
|
295 tree_constant data = plot_data->eval (0); |
191
|
296 if (! error_state && data.is_defined ()) |
1
|
297 { |
524
|
298 char *file = 0; |
86
|
299 if (data.is_string_type ()) |
|
300 { |
87
|
301 file = tilde_expand (data.string_value ()); |
86
|
302 ifstream ftmp (file); |
|
303 if (ftmp) |
|
304 { |
|
305 plot_buf << " \"" << file << '"'; |
87
|
306 free (file); |
134
|
307 goto have_existing_file_or_command; |
86
|
308 } |
|
309 else |
87
|
310 { |
|
311 free (file); |
524
|
312 file = 0; |
134
|
313 |
|
314 // Opening as a file failed. Let's try passing it along as a plot |
|
315 // command. |
|
316 plot_buf << " " << data.string_value (); |
|
317 goto have_existing_file_or_command; |
87
|
318 } |
86
|
319 } |
|
320 |
1
|
321 nc = data.columns (); |
|
322 switch (ndim) |
|
323 { |
|
324 case 2: |
|
325 file = save_in_tmp_file (data, ndim); |
|
326 break; |
|
327 case 3: |
|
328 file = save_in_tmp_file (data, ndim, parametric_plot); |
|
329 break; |
|
330 default: |
|
331 panic_impossible (); |
|
332 break; |
|
333 } |
|
334 |
|
335 if (file) |
|
336 { |
|
337 mark_for_deletion (file); |
|
338 plot_buf << " \"" << file << '"'; |
|
339 } |
|
340 } |
|
341 else |
|
342 return -1; |
|
343 } |
|
344 else |
|
345 return -1; |
|
346 |
134
|
347 have_existing_file_or_command: |
86
|
348 |
524
|
349 if (using) |
1
|
350 { |
|
351 int status = using->print (ndim, nc, plot_buf); |
|
352 if (status < 0) |
|
353 return -1; |
|
354 } |
|
355 |
524
|
356 if (title) |
1
|
357 { |
|
358 tree_constant tmp = title->eval (0); |
191
|
359 if (! error_state && tmp.is_string_type ()) |
1
|
360 plot_buf << " title " << '"' << tmp.string_value () << '"'; |
|
361 else |
|
362 { |
|
363 warning ("line title must be a string"); |
|
364 plot_buf << " title " << '"' << "line " << plot_line_count << '"'; |
|
365 } |
|
366 } |
|
367 else |
|
368 plot_buf << " title " << '"' << "line " << plot_line_count << '"'; |
|
369 |
524
|
370 if (style) |
1
|
371 { |
|
372 int status = style->print (plot_buf); |
|
373 if (status < 0) |
|
374 return -1; |
|
375 } |
|
376 |
|
377 return 0; |
|
378 } |
|
379 |
|
380 tree_plot_limits::tree_plot_limits (void) |
|
381 { |
524
|
382 x_range = 0; |
|
383 y_range = 0; |
|
384 z_range = 0; |
1
|
385 } |
|
386 |
|
387 tree_plot_limits::tree_plot_limits (tree_plot_range *xlim) |
|
388 { |
|
389 x_range = xlim; |
524
|
390 y_range = 0; |
|
391 z_range = 0; |
1
|
392 } |
|
393 |
|
394 tree_plot_limits::tree_plot_limits (tree_plot_range *xlim, |
|
395 tree_plot_range *ylim) |
|
396 { |
|
397 x_range = xlim; |
|
398 y_range = ylim; |
524
|
399 z_range = 0; |
1
|
400 } |
|
401 |
|
402 tree_plot_limits::tree_plot_limits (tree_plot_range *xlim, |
|
403 tree_plot_range *ylim, |
|
404 tree_plot_range *zlim) |
|
405 { |
|
406 x_range = xlim; |
|
407 y_range = ylim; |
|
408 z_range = zlim; |
|
409 } |
|
410 |
|
411 tree_plot_limits::~tree_plot_limits (void) |
|
412 { |
|
413 delete x_range; |
|
414 delete y_range; |
|
415 delete z_range; |
|
416 } |
|
417 |
|
418 tree_constant |
|
419 tree_plot_limits::eval (int print) |
|
420 { |
|
421 tree_constant retval; |
|
422 return retval; |
|
423 } |
|
424 |
|
425 void |
|
426 tree_plot_limits::print (int ndim, ostrstream& plot_buf) |
|
427 { |
|
428 if (ndim == 2 || ndim == 3) |
|
429 { |
524
|
430 if (x_range) |
1
|
431 x_range->print (plot_buf); |
|
432 else |
|
433 return; |
|
434 |
524
|
435 if (y_range) |
1
|
436 y_range->print (plot_buf); |
|
437 else |
|
438 return; |
|
439 } |
|
440 |
524
|
441 if (ndim == 3 && z_range) |
1
|
442 z_range->print (plot_buf); |
|
443 } |
|
444 |
|
445 tree_plot_range::tree_plot_range (void) |
|
446 { |
524
|
447 lower = 0; |
|
448 upper = 0; |
1
|
449 } |
|
450 |
491
|
451 tree_plot_range::tree_plot_range (tree_expression *l, tree_expression *u) |
1
|
452 { |
|
453 lower = l; |
|
454 upper = u; |
|
455 } |
|
456 |
|
457 tree_plot_range::~tree_plot_range (void) |
|
458 { |
|
459 delete lower; |
|
460 delete upper; |
|
461 } |
|
462 |
|
463 tree_constant |
|
464 tree_plot_range::eval (int print) |
|
465 { |
|
466 tree_constant retval; |
|
467 return retval; |
|
468 } |
|
469 |
|
470 void |
|
471 tree_plot_range::print (ostrstream& plot_buf) |
|
472 { |
|
473 plot_buf << " ["; |
|
474 |
524
|
475 if (lower) |
1
|
476 { |
|
477 tree_constant lower_val = lower->eval (0); |
191
|
478 if (error_state) |
|
479 { |
240
|
480 ::error ("evaluating lower bound of plot range"); |
191
|
481 return; |
|
482 } |
|
483 else |
|
484 { |
|
485 double lo = lower_val.to_scalar (); |
|
486 plot_buf << lo; |
|
487 } |
1
|
488 } |
|
489 |
|
490 plot_buf << ":"; |
|
491 |
524
|
492 if (upper) |
1
|
493 { |
|
494 tree_constant upper_val = upper->eval (0); |
191
|
495 if (error_state) |
|
496 { |
240
|
497 ::error ("evaluating upper bound of plot range"); |
191
|
498 return; |
|
499 } |
|
500 else |
|
501 { |
|
502 double hi = upper_val.to_scalar (); |
|
503 plot_buf << hi; |
|
504 } |
1
|
505 } |
|
506 |
|
507 plot_buf << "]"; |
|
508 } |
|
509 |
|
510 tree_subplot_using::tree_subplot_using (void) |
|
511 { |
|
512 qualifier_count = 0; |
524
|
513 x[0] = 0; |
|
514 x[1] = 0; |
|
515 x[2] = 0; |
|
516 x[3] = 0; |
|
517 scanf_fmt = 0; |
1
|
518 } |
|
519 |
491
|
520 tree_subplot_using::tree_subplot_using (tree_expression *fmt) |
1
|
521 { |
|
522 qualifier_count = 0; |
524
|
523 x[0] = 0; |
|
524 x[1] = 0; |
|
525 x[2] = 0; |
|
526 x[3] = 0; |
1
|
527 scanf_fmt = fmt; |
|
528 } |
|
529 |
|
530 tree_subplot_using::~tree_subplot_using (void) |
|
531 { |
|
532 delete scanf_fmt; |
|
533 } |
|
534 |
|
535 tree_subplot_using * |
491
|
536 tree_subplot_using::set_format (tree_expression *fmt) |
1
|
537 { |
|
538 scanf_fmt = fmt; |
|
539 return this; |
|
540 } |
|
541 |
|
542 tree_subplot_using * |
491
|
543 tree_subplot_using::add_qualifier (tree_expression *t) |
1
|
544 { |
|
545 if (qualifier_count < 4) |
|
546 x[qualifier_count] = t; |
|
547 |
|
548 qualifier_count++; |
|
549 |
|
550 return this; |
|
551 } |
|
552 |
|
553 tree_constant |
|
554 tree_subplot_using::eval (int print) |
|
555 { |
|
556 tree_constant retval; |
|
557 return retval; |
|
558 } |
|
559 |
|
560 int |
|
561 tree_subplot_using::print (int ndim, int n_max, ostrstream& plot_buf) |
|
562 { |
|
563 if ((ndim == 2 && qualifier_count > 4) |
|
564 || (ndim == 3 && qualifier_count > 3)) |
|
565 return -1; |
|
566 |
|
567 for (int i = 0; i < qualifier_count; i++) |
|
568 { |
524
|
569 if (x[i]) |
1
|
570 { |
|
571 tree_constant tmp = x[i]->eval (0); |
191
|
572 if (error_state) |
|
573 { |
240
|
574 ::error ("evaluating plot using command"); |
191
|
575 return -1; |
|
576 } |
|
577 |
1
|
578 double val; |
|
579 if (tmp.is_defined ()) |
|
580 { |
|
581 val = tmp.to_scalar (); |
|
582 if (i == 0) |
|
583 plot_buf << " using "; |
|
584 else |
|
585 plot_buf << ":"; |
|
586 |
|
587 int n = NINT (val); |
|
588 |
322
|
589 if (n < 1 || n_max > 0 && n > n_max) |
1
|
590 { |
240
|
591 ::error ("using: column %d out of range", n); |
1
|
592 return -1; |
|
593 } |
|
594 else |
|
595 plot_buf << n; |
|
596 } |
|
597 else |
|
598 return -1; |
|
599 } |
|
600 else |
|
601 return -1; |
|
602 } |
|
603 |
524
|
604 if (scanf_fmt) |
1
|
605 warning ("ignoring scanf format in plot command"); |
|
606 |
|
607 return 0; |
|
608 } |
|
609 |
|
610 tree_subplot_style::tree_subplot_style (void) |
|
611 { |
524
|
612 style = 0; |
|
613 linetype = 0; |
|
614 pointtype = 0; |
1
|
615 } |
|
616 |
|
617 tree_subplot_style::tree_subplot_style (char *s) |
|
618 { |
|
619 style = strsave (s); |
524
|
620 linetype = 0; |
|
621 pointtype = 0; |
1
|
622 } |
|
623 |
491
|
624 tree_subplot_style::tree_subplot_style (char *s, tree_expression *lt) |
1
|
625 { |
|
626 style = strsave (s); |
|
627 linetype = lt; |
524
|
628 pointtype = 0; |
1
|
629 } |
|
630 |
491
|
631 tree_subplot_style::tree_subplot_style (char *s, tree_expression *lt, |
|
632 tree_expression *pt) |
1
|
633 { |
|
634 style = strsave (s); |
|
635 linetype = lt; |
|
636 pointtype = pt; |
|
637 } |
|
638 |
|
639 tree_subplot_style::~tree_subplot_style (void) |
|
640 { |
|
641 delete [] style; |
|
642 delete linetype; |
|
643 delete pointtype; |
|
644 } |
|
645 |
|
646 tree_constant |
|
647 tree_subplot_style::eval (int print) |
|
648 { |
|
649 tree_constant retval; |
|
650 return retval; |
|
651 } |
|
652 |
|
653 int |
|
654 tree_subplot_style::print (ostrstream& plot_buf) |
|
655 { |
524
|
656 if (style) |
1
|
657 { |
|
658 plot_buf << " with " << style; |
|
659 |
524
|
660 if (linetype) |
1
|
661 { |
|
662 tree_constant tmp = linetype->eval (0); |
191
|
663 if (! error_state && tmp.is_defined ()) |
1
|
664 { |
|
665 double val = tmp.to_scalar (); |
|
666 plot_buf << " " << NINT (val); |
|
667 } |
|
668 else |
191
|
669 { |
240
|
670 ::error ("evaluating plot style command"); |
191
|
671 return -1; |
|
672 } |
1
|
673 } |
|
674 |
524
|
675 if (pointtype) |
1
|
676 { |
|
677 tree_constant tmp = pointtype->eval (0); |
191
|
678 if (! error_state && tmp.is_defined ()) |
1
|
679 { |
|
680 double val = tmp.to_scalar (); |
|
681 plot_buf << " " << NINT (val); |
|
682 } |
|
683 else |
191
|
684 { |
240
|
685 ::error ("evaluating plot style command"); |
191
|
686 return -1; |
|
687 } |
1
|
688 } |
|
689 } |
|
690 else |
|
691 return -1; |
|
692 |
|
693 return 0; |
|
694 } |
|
695 |
524
|
696 char * |
|
697 save_in_tmp_file (tree_constant& t, int ndim, int parametric) |
|
698 { |
|
699 char *name = strsave (tmpnam (0)); |
|
700 if (name) |
|
701 { |
|
702 ofstream file (name); |
|
703 if (file) |
|
704 { |
|
705 switch (ndim) |
|
706 { |
|
707 case 2: |
|
708 t.save (file); |
|
709 break; |
|
710 case 3: |
|
711 t.save_three_d (file, parametric); |
|
712 break; |
|
713 default: |
|
714 panic_impossible (); |
|
715 break; |
|
716 } |
|
717 } |
|
718 else |
|
719 { |
|
720 error ("couldn't open temporary output file `%s'", name); |
|
721 delete [] name; |
|
722 name = 0; |
|
723 } |
|
724 } |
|
725 return name; |
|
726 } |
|
727 |
|
728 void |
|
729 mark_for_deletion (const char *filename) |
|
730 { |
|
731 char *tmp = strsave (filename); |
|
732 tmp_files.push (tmp); |
|
733 } |
|
734 |
|
735 void |
|
736 cleanup_tmp_files (void) |
|
737 { |
|
738 while (! tmp_files.empty ()) |
|
739 { |
|
740 char *filename = tmp_files.pop (); |
|
741 unlink (filename); |
|
742 delete [] filename; |
|
743 } |
|
744 } |
|
745 |
|
746 int |
|
747 send_to_plot_stream (const char *cmd) |
|
748 { |
|
749 // From sighandlers.cc: |
|
750 extern int pipe_handler_error_count; |
|
751 |
|
752 static int initialized = 0; |
|
753 |
|
754 if (! plot_stream.is_open ()) |
|
755 { |
|
756 plot_line_count = 0; |
|
757 |
|
758 char *plot_prog = user_pref.gnuplot_binary; |
|
759 if (plot_prog) |
|
760 { |
|
761 plot_stream.open (plot_prog); |
|
762 if (! plot_stream.is_open ()) |
|
763 { |
|
764 warning ("plot: unable to open pipe to `%s'", |
|
765 plot_prog); |
|
766 |
|
767 if (strcmp (plot_prog, "gnuplot") != 0) |
|
768 { |
|
769 warning ("having trouble finding plotting program."); |
|
770 warning ("trying again with `gnuplot'"); |
|
771 goto last_chance; |
|
772 } |
|
773 } |
|
774 } |
|
775 else |
|
776 { |
|
777 last_chance: |
|
778 |
|
779 plot_stream.open ("gnuplot"); |
|
780 |
|
781 if (! plot_stream.is_open ()) |
|
782 { |
|
783 error ("plot: unable to open pipe to `%s'", plot_prog); |
|
784 return -1; |
|
785 } |
|
786 } |
|
787 } |
|
788 |
|
789 if (! initialized) |
|
790 { |
|
791 initialized = 1; |
|
792 plot_stream << "set data style lines\n"; |
|
793 } |
|
794 |
|
795 plot_stream << cmd; |
|
796 plot_stream.flush (); |
|
797 pipe_handler_error_count = 0; |
|
798 |
|
799 return 0; |
|
800 } |
|
801 |
|
802 void |
|
803 close_plot_stream (void) |
|
804 { |
|
805 if (plot_stream.is_open ()) |
|
806 plot_stream.close (); |
|
807 |
|
808 plot_line_count = 0; |
|
809 } |
|
810 |
|
811 DEFUN ("closeplot", Fcloseplot, Scloseplot, 1, 0, |
|
812 "closeplot (): close the stream to plotter") |
|
813 { |
|
814 Octave_object retval; |
|
815 close_plot_stream (); |
|
816 return retval; |
|
817 } |
|
818 |
|
819 DEFUN_TEXT ("hold", Fhold, Shold, -1, 1, |
|
820 "hold [on|off]\n\ |
|
821 \n\ |
|
822 determine whether the plot window is cleared before the next line is\n\ |
|
823 drawn. With no argument, toggle the current state.") |
|
824 { |
|
825 Octave_object retval; |
|
826 |
|
827 DEFINE_ARGV("hold"); |
|
828 |
|
829 switch (argc) |
|
830 { |
|
831 case 1: |
|
832 clear_before_plotting = ! clear_before_plotting; |
|
833 break; |
|
834 case 2: |
|
835 if (strcasecmp (argv[1], "on") == 0) |
|
836 clear_before_plotting = 0; |
|
837 else if (strcasecmp (argv[1], "off") == 0) |
|
838 clear_before_plotting = 1; |
|
839 else |
|
840 print_usage ("hold"); |
|
841 break; |
|
842 default: |
|
843 print_usage ("hold"); |
|
844 break; |
|
845 } |
|
846 |
|
847 DELETE_ARGV; |
|
848 |
|
849 return retval; |
|
850 } |
|
851 |
|
852 DEFUN ("purge_tmp_files", Fpurge_tmp_files, Spurge_tmp_files, 5, 1, |
|
853 "delete temporary data files used for plotting") |
|
854 { |
|
855 Octave_object retval; |
|
856 cleanup_tmp_files (); |
|
857 return retval; |
|
858 } |
|
859 |
|
860 DEFUN_TEXT ("set", Fset, Sset, -1, 1, |
|
861 "set [options]\n\ |
|
862 \n\ |
|
863 set plotting options") |
|
864 { |
|
865 Octave_object retval; |
|
866 |
|
867 DEFINE_ARGV("set"); |
|
868 |
|
869 ostrstream plot_buf; |
|
870 |
|
871 if (argc > 1) |
|
872 { |
|
873 if (almost_match ("parametric", argv[1], 3)) |
|
874 parametric_plot = 1; |
|
875 else if (almost_match ("noparametric", argv[1], 5)) |
|
876 parametric_plot = 0; |
|
877 } |
|
878 |
|
879 for (int i = 0; i < argc; i++) |
|
880 plot_buf << argv[i] << " "; |
|
881 |
|
882 plot_buf << "\n" << ends; |
|
883 |
|
884 char *plot_command = plot_buf.str (); |
|
885 send_to_plot_stream (plot_command); |
|
886 |
|
887 delete [] plot_command; |
|
888 |
|
889 DELETE_ARGV; |
|
890 |
|
891 return retval; |
|
892 } |
|
893 |
|
894 /* |
|
895 * Set plotting options. |
|
896 */ |
|
897 DEFUN_TEXT ("show", Fshow, Sshow, -1, 1, |
|
898 "show [options]\n\ |
|
899 \n\ |
|
900 show plotting options") |
|
901 { |
|
902 Octave_object retval; |
|
903 |
|
904 DEFINE_ARGV("show"); |
|
905 |
|
906 ostrstream plot_buf; |
|
907 |
|
908 for (int i = 0; i < argc; i++) |
|
909 plot_buf << argv[i] << " "; |
|
910 |
|
911 plot_buf << "\n" << ends; |
|
912 |
|
913 char *plot_command = plot_buf.str (); |
|
914 send_to_plot_stream (plot_command); |
|
915 |
|
916 delete [] plot_command; |
|
917 |
|
918 DELETE_ARGV; |
|
919 |
|
920 return retval; |
|
921 } |
|
922 |
1
|
923 /* |
|
924 ;;; Local Variables: *** |
|
925 ;;; mode: C++ *** |
|
926 ;;; page-delimiter: "^/\\*" *** |
|
927 ;;; End: *** |
|
928 */ |