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