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