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