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