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