annotate src/DLD-FUNCTIONS/__gnuplot_raw__.l @ 5791:70215aff5ccf

[project @ 2006-05-04 18:38:45 by jwe]
author jwe
date Thu, 04 May 2006 18:38:45 +0000
parents 60659f01c75b
children 1138ced03f14
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1 /*
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
2
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
3 Copyright (C) 2004 John W. Eaton and Teemu Ikonen
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
4
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
6
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
10 later version.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
11
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
15 for more details.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
16
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
18 along with Octavee; see the file COPYING. If not, write to the Free
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
20 02110-1301, USA.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
21
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
22 */
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
23
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
24 %option prefix="gpt"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
25 %option noyywrap
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
26
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
27 %{
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
28 // PKG_ADD: mark_as_rawcommand ("__gnuplot_plot__");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
29 // PKG_ADD: mark_as_rawcommand ("__gnuplot_set__");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
30 // PKG_ADD: mark_as_rawcommand ("__gnuplot_splot__");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
31 // PKG_ADD: mark_as_rawcommand ("__gnuplot_replot__");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
32
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
33 // PKG_ADD: mark_as_command ("__gnuplot_show__");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
34
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
35 // PKG_ADD: atexit ("closeplot");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
36
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
37 #ifdef HAVE_CONFIG_H
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
38 #include <config.h>
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
39 #endif
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
40
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
41 #include <map>
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
42 #include <string>
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
43 #include <fstream>
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
44 #include <iostream>
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
45 #include <sstream>
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
46
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
47 #ifdef HAVE_UNISTD_H
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
48 #ifdef HAVE_SYS_TYPES_H
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
49 #include <sys/types.h>
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
50 #endif
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
51 #include <unistd.h>
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
52 #endif
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
53
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
54 #include "file-ops.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
55 #include "oct-env.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
56
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
57 #include "defun-dld.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
58 #include "file-io.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
59 #include "gripes.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
60 #include "load-save.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
61 #include "parse.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
62 #include "procstream.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
63 #include "sighandlers.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
64 #include "utils.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
65 #include "variables.h"
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
66
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
67 enum _toktype
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
68 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
69 START_PAREN = 1,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
70 END_PAREN,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
71 START_BRACE,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
72 END_BRACE,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
73 START_BRACKET,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
74 END_BRACKET,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
75 COLON,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
76 SEMICOLON,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
77 COMMA,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
78 QUOTE,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
79 IDENT,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
80 NUMBER,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
81 BINOP,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
82 UNOP,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
83 STRING,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
84 OTHER,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
85 TITLE,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
86 USING,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
87 WITH,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
88 AXES,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
89 CLEAR
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
90 };
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
91
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
92 typedef bool (*pred) (const int);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
93
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
94 class
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
95 gpt_parse_error
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
96 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
97 public:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
98 gpt_parse_error (void) : msg () { }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
99 gpt_parse_error (std::string errmsg) : msg (errmsg) { }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
100
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
101 std::string msg;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
102 };
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
103
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
104 static bool gpt_quote_is_transpose;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
105 static bool gpt_allow_plotkw;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
106 static int gpt_parens;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
107 static int gpt_brackets;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
108 static int gpt_braces;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
109
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
110 static bool can_be_plotkw (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
111
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
112 static int is_plot_keyword (const std::string& s);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
113
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
114 static int handle_string (char delim);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
115 static std::string strbuf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
116
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
117 %}
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
118
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
119 D [0-9]
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
120 S [ \t]
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
121 IDENT ([_a-zA-Z@][_a-zA-Z0-9]*)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
122 EXPON ([DdEe][+-]?{D}+)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
123 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
124 NOT ((\~)|(\!))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
125 /* NOT is not strictly a binary operator, but is close enough for us. */
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
126 BINOP (({NOT})|(\.?([\*/\\^+-]|\*\*)=?)|([<=~!>&|]=)|([=&|<>]{1,2})|(<<=)|(>>=)|(\.))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
127 /* single quote (') transpose operator is handled separately. */
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
128 UNOP ((\+\+)|(\-\-)|(\.'))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
129
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
130 %%
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
131
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
132 "(" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
133 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
134 gpt_parens++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
135 return START_PAREN;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
136 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
137
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
138 ")" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
139 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
140 gpt_parens--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
141 return END_PAREN;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
142 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
143
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
144 "{" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
145 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
146 gpt_braces++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
147 return START_BRACE;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
148 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
149
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
150 "}" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
151 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
152 gpt_braces--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
153 return END_BRACE;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
154 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
155
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
156 "[" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
157 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
158 gpt_brackets++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
159 return START_BRACKET;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
160 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
161
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
162 "]" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
163 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
164 gpt_brackets--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
165 return END_BRACKET;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
166 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
167
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
168 ":" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
169 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
170 return COLON;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
171 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
172
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
173 ";" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
174 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
175 return SEMICOLON;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
176 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
177
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
178 "," {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
179 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
180 return COMMA;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
181 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
182
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
183 "'" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
184 if (gpt_quote_is_transpose)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
185 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
186 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
187 return QUOTE;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
188 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
189 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
190 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
191 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
192 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
193 return handle_string ('\'');
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
194 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
195 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
196
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
197 "\"" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
198 return handle_string ('"');
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
199 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
200
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
201 {IDENT} {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
202 int itok = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
203 if (can_be_plotkw () && (itok = is_plot_keyword (yytext)))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
204 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
205 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
206 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
207 return itok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
208 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
209 else if (std::string (yytext) == "function")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
210 throw gpt_parse_error ("function keyword not allowed in plot commands");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
211 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
212 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
213 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
214 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
215 return IDENT;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
216 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
217 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
218
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
219 {D}+/\.[\*/\\^'] | /* ' */
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
220 {NUMBER} {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
221 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
222 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
223 return NUMBER;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
224 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
225
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
226 {BINOP} {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
227 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
228 gpt_allow_plotkw = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
229 return BINOP;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
230 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
231
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
232 {UNOP} {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
233 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
234 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
235 return UNOP;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
236 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
237
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
238 {S} { /* Ignore spaces and tabs outside of character strings. */ }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
239
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
240 . {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
241 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
242 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
243 warning ("unknown token = \"%s\" in plot command", yytext);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
244 return OTHER;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
245 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
246
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
247 %%
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
248
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
249 // ------------------------------------------------------------
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
250 // Interface to external gnuplot process(es), including gnuplot
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
251 // command parser.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
252 // ------------------------------------------------------------
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
253
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
254 // The name of the shell command to execute to start gnuplot.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
255 static std::string Vgnuplot_binary = GNUPLOT_BINARY;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
256
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
257 // Append -title "Figure NN" to the gnuplot command?
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
258 static bool Vgnuplot_use_title_option = octave_env::have_x11_display ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
259
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
260 // Gnuplot command strings that we use.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
261 static std::string Vgnuplot_command_plot = "pl";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
262 static std::string Vgnuplot_command_replot = "rep";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
263 static std::string Vgnuplot_command_splot = "sp";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
264 static std::string Vgnuplot_command_using = "u";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
265 static std::string Vgnuplot_command_with = "w";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
266 static std::string Vgnuplot_command_axes = "ax";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
267 static std::string Vgnuplot_command_title = "t";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
268 static std::string Vgnuplot_command_end = "\n";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
269
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
270 // If TRUE, a replot command is issued automatically each time a plot
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
271 // changes in some way.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
272 static bool Vautomatic_replot = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
273
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
274 // Check if the parser state is such that a plot keyword can occur.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
275
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
276 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
277 can_be_plotkw (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
278 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
279 return (gpt_allow_plotkw
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
280 && (gpt_braces == 0)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
281 && (gpt_brackets == 0)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
282 && (gpt_parens == 0));
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
283 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
284
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
285 // Check to see if a character string matches any one of the plot
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
286 // option keywords. Don't match abbreviations for clear, since that's
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
287 // not a gnuplot keyword (users will probably only expect to be able
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
288 // to abbreviate actual gnuplot keywords).
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
289
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
290 static int
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
291 is_plot_keyword (const std::string& s)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
292 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
293 if (almost_match ("title", s, 1))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
294 return TITLE;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
295 else if (almost_match ("using", s, 1))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
296 return USING;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
297 else if (almost_match ("with", s, 1))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
298 return WITH;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
299 else if (almost_match ("axes", s, 2) || almost_match ("axis", s, 2))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
300 return AXES;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
301 else if ("clear" == s)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
302 return CLEAR;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
303 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
304 return 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
305 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
306
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
307 // This is used to handle character strings. Kludge alert.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
308
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
309 static int
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
310 handle_string (char delim)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
311 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
312 int c;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
313 bool escape_pending = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
314
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
315 strbuf = std::string (1, delim);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
316
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
317 while ((c = yyinput ()) != EOF)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
318 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
319 if (c == '\\')
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
320 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
321 if (escape_pending)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
322 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
323 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
324 escape_pending = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
325 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
326 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
327 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
328 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
329 escape_pending = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
330 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
331 continue;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
332 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
333 else if (c == '\n')
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
334 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
335 error ("unterminated string constant");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
336 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
337 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
338 else if (c == delim)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
339 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
340 if (escape_pending)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
341 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
342 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
343 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
344 c = yyinput ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
345
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
346 if (c == delim)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
347 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
348 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
349 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
350 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
351 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
352 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
353 yyunput (c, yytext);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
354 strbuf += static_cast<char> (delim);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
355 return STRING;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
356 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
357 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
358 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
359 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
360 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
361
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
362 escape_pending = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
363 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
364
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
365 throw gpt_parse_error ("unterminated string");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
366
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
367 return 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
368 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
369
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
370 // (Probably not necessesary, but current Matlab style plot functions
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
371 // break without this (they emit too short gnuplot commands))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
372
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
373 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
374 plot_style_token (const std::string& s)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
375 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
376 std::string retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
377
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
378 // FIXME -- specify minimum match length for these.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
379 static const char *plot_styles[] =
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
380 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
381 "boxes",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
382 "boxerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
383 "boxxyerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
384 "candlesticks",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
385 "dots",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
386 "errorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
387 "financebars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
388 "fsteps",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
389 "histeps",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
390 "impulses",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
391 "lines",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
392 "linespoints",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
393 "points",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
394 "steps",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
395 "vector",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
396 "xerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
397 "xyerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
398 "yerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
399 0,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
400 };
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
401
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
402 const char * const *tmp = plot_styles;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
403 while (*tmp)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
404 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
405 if (almost_match (*tmp, s.c_str ()))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
406 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
407 retval = *tmp;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
408 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
409 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
410
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
411 tmp++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
412 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
413
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
414 return retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
415 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
416
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
417 // Some predicates on tokens
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
418
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
419 // Return true for ":".
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
420
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
421 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
422 colonp (const int tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
423 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
424 return (tok == COLON);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
425 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
426
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
427 // Return TRUE for "]".
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
428
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
429 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
430 endbracketp (const int tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
431 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
432 return (tok == END_BRACKET);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
433 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
434
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
435 // Return TRUE for plot token, comma or end of input.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
436
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
437 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
438 plottok_or_end_p (const int tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
439 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
440 return (tok == TITLE
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
441 || tok == USING
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
442 || tok == WITH
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
443 || tok == AXES
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
444 || tok == CLEAR
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
445 || tok == COMMA
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
446 || tok == 0);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
447 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
448
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
449 // Equivalent to (colonp (tok) || plottok_or_end_p (tok)).
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
450
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
451 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
452 colon_plottok_or_end_p (const int tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
453 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
454 return (tok == COLON || plottok_or_end_p (tok));
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
455 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
456
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
457 // read until test is true and delimiters are balanced, or end of input.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
458 // Return the last token in lasttok
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
459
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
460 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
461 read_until (pred test, int& lasttok) throw (gpt_parse_error)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
462 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
463 int tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
464
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
465 // We have to maintain balanced delimiters per subexpression too.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
466 int brackets = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
467 int parens = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
468 int braces = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
469 std::string s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
470
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
471 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
472
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
473 while (tok && ! (test (tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
474 && brackets == 0
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
475 && parens == 0
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
476 && braces == 0))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
477 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
478 switch (tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
479 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
480 case START_BRACKET:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
481 brackets++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
482 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
483
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
484 case END_BRACKET:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
485 brackets--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
486 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
487
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
488 case START_PAREN:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
489 parens++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
490 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
491
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
492 case END_PAREN:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
493 parens--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
494 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
495
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
496 case START_BRACE:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
497 braces++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
498 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
499
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
500 case END_BRACE:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
501 braces--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
502 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
503
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
504 default:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
505 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
506 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
507
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
508 s += (tok == STRING ? strbuf : std::string (yytext)) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
509
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
510 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
511 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
512
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
513 // Throw error only if we've reached the end token and the test
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
514 // doesn't accept it.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
515
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
516 if (! test (tok) && ! tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
517 throw gpt_parse_error ("unexpected end of input");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
518
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
519 lasttok = tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
520
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
521 return s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
522 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
523
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
524 // Eval the two expressions giving limits of range and print it.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
525
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
526 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
527 printrange (std::string starts, std::string ends)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
528 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
529 octave_value startv, endv;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
530 int status;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
531 std::string s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
532 std::ostringstream range_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
533
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
534 range_buf << "[";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
535
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
536 if (! starts.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
537 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
538 startv = eval_string (starts, true, status);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
539 if (! startv.is_real_scalar ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
540 throw gpt_parse_error ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
541 startv.print_raw (range_buf);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
542 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
543
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
544 range_buf << ":";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
545
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
546 if (! ends.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
547 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
548 endv = eval_string (ends, true, status);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
549 if (! endv.is_real_scalar ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
550 throw gpt_parse_error ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
551 endv.print_raw (range_buf);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
552 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
553
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
554 range_buf << "]";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
555
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
556 s = range_buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
557
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
558 return s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
559 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
560
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
561 // Handle plot parameters.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
562
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
563 // Parse, evaluate and print colon separated expressions in the using
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
564 // plot parameter. The use of trailing format string is not supported.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
565
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
566 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
567 handle_using (int& lasttok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
568 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
569 int tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
570 std::string expr_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
571 std::string retstr = Vgnuplot_command_using + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
572 bool out = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
573
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
574 octave_value tmp_data;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
575 int status;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
576 while (! out)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
577 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
578 expr_str = read_until (colon_plottok_or_end_p, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
579
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
580 tmp_data = eval_string (expr_str, true, status);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
581 if (status != 0 || ! tmp_data.is_real_scalar ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
582 throw gpt_parse_error ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
583
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
584 std::ostringstream tmp_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
585 tmp_data.print_raw (tmp_buf);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
586 retstr += tmp_buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
587
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
588 if (tok == COLON)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
589 retstr += ":";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
590 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
591 out = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
592 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
593
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
594 lasttok = tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
595
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
596 return retstr;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
597 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
598
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
599 // Presently just passes the linewidth, pointtype etc. tokens as they are.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
600
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
601 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
602 handle_style (int& lasttok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
603 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
604 std::string retstr = Vgnuplot_command_with + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
605 std::string style;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
606
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
607 lasttok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
608
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
609 if (lasttok != IDENT)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
610 throw gpt_parse_error ("expected plot style token");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
611
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
612 style = std::string (yytext);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
613 style = plot_style_token (style);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
614
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
615 if (! style.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
616 retstr += style;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
617 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
618 retstr += std::string (yytext);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
619
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
620 // FIXME -- should evaluate the remaining tokens, but this
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
621 // needs changes in the parser.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
622 retstr += " " + read_until (plottok_or_end_p, lasttok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
623
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
624 return retstr;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
625 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
626
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
627 // Axes has only one qualifier keyword, which is not evaluated.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
628
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
629 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
630 handle_axes (int& lasttok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
631 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
632 return Vgnuplot_command_axes + " " + read_until (plottok_or_end_p, lasttok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
633 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
634
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
635 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
636 save_in_tmp_file (const octave_value& t, int ndim = 2, bool parametric = false)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
637 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
638 std::string name = file_ops::tempnam ("", "oct-");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
639
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
640 if (! name.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
641 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
642 std::ofstream file (name.c_str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
643
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
644 if (file)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
645 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
646 switch (ndim)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
647 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
648 case 2:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
649 save_ascii_data_for_plotting (file, t, name);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
650 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
651
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
652 case 3:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
653 save_three_d (file, t, parametric);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
654 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
655
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
656 default:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
657 gripe_2_or_3_dim_plot ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
658 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
659 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
660 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
661 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
662 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
663 error ("couldn't open temporary output file `%s'", name.c_str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
664 name.resize (0);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
665 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
666 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
667
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
668 return name;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
669 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
670
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
671 static int
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
672 get_current_figure (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
673 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
674 int retval = 1;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
675
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
676 octave_value cf = get_global_value ("__current_figure__", true);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
677
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
678 if (cf.is_defined ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
679 retval = cf.int_value ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
680 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
681 set_global_value ("__current_figure__", retval);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
682
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
683 return retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
684 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
685
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
686 class
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
687 gnuplot
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
688 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
689 protected:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
690
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
691 gnuplot (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
692 : plot_line_count (0), parametric_plot (false),
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
693 use_title_option (Vgnuplot_use_title_option),
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
694 gnuplot_exe (Vgnuplot_binary),
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
695 gnuplot_terminal_type (), plot_stream () { }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
696
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
697 public:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
698
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
699 ~gnuplot (void) { }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
700
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
701 static bool have_instance (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
702
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
703 static bool ensure_instance (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
704
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
705 static bool ensure_plot_stream (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
706
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
707 static void open (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
708
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
709 static void close (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
710
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
711 static void close_all (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
712
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
713 static bool plot_stream_event_handler (pid_t pid, int status);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
714
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
715 static void send (const std::string& cmd)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
716 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
717 if (ensure_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
718 instance->do_send (cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
719 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
720
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
721 static void send_raw (const std::string& cmd)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
722 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
723 if (ensure_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
724 instance->do_send_raw (cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
725 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
726
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
727 static void clear (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
728 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
729 if (ensure_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
730 instance->do_clear ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
731 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
732
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
733 static void set (const string_vector& argv)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
734 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
735 if (ensure_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
736 instance->do_set (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
737 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
738
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
739 static void show (const string_vector& argv)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
740 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
741 if (ensure_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
742 instance->do_show (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
743 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
744
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
745 static void set_gnuplot_exe (const std::string& exe)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
746 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
747 if (ensure_instance ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
748 instance->do_set_gnuplot_exe (exe);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
749 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
750
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
751 static void set_gnuplot_use_title_option (bool opt)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
752 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
753 if (ensure_instance ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
754 instance->do_set_gnuplot_use_title_option (opt);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
755 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
756
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
757 // FIXME -- should only remove tmp files associated with
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
758 // gnuplot?
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
759 static void cleanup_tmp_files (void) { ::cleanup_tmp_files (); }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
760
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
761 static void plot (const string_vector& argv)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
762 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
763 if (ensure_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
764 instance->do_plot (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
765 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
766
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
767 private:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
768
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
769 static gnuplot *instance;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
770
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
771 static std::map<int, gnuplot *> instance_map;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
772
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
773 // The number of lines we've plotted so far.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
774 int plot_line_count;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
775
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
776 // Is this a parametric plot? Makes a difference for 3D plotting.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
777 bool parametric_plot;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
778
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
779 // Should we append '-title "TITLE"' to the gnuplot command?
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
780 bool use_title_option;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
781
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
782 // The executable program to run.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
783 std::string gnuplot_exe;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
784
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
785 // The gnuplot terminal type.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
786 std::string gnuplot_terminal_type;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
787
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
788 // Pipe to gnuplot.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
789 oprocstream *plot_stream;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
791 pid_t pid (void) const;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
792
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
793 static gnuplot *lookup_by_pid (pid_t pid);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
794
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
795 void do_open (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
796
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
797 void do_close (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
798
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
799 void delete_plot_stream (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
800
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
801 void reset_plot_stream (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
802
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
803 void do_send (const std::string& cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
804
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
805 void do_send_raw (const std::string& cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
806
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
807 void do_clear (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
808
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
809 void do_set (const string_vector& argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
810
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
811 void do_show (const string_vector& argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
812
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
813 void do_set_gnuplot_exe (const std::string& exe) { gnuplot_exe = exe; }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
814
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
815 void do_set_gnuplot_use_title_option (bool opt) { use_title_option = opt; }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
816
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
817 void do_plot (const string_vector& argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
818
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
819 std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
820 makeplot (std::string caller, std::string args) throw (gpt_parse_error);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
821
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
822 std::string handle_title (int& lasttok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
823 };
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
824
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
825 gnuplot *gnuplot::instance = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
826
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
827 std::map<int, gnuplot *> gnuplot::instance_map;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
828
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
829 bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
830 gnuplot::have_instance (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
831 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
832 int current_figure = get_current_figure ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
833
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
834 if (instance_map.find (current_figure) != instance_map.end ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
835 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
836 instance = instance_map[current_figure];
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
837 return true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
838 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
839 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
840 return false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
841 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
842
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
843 bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
844 gnuplot::ensure_instance (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
845 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
846 if (! have_instance ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
847 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
848 instance = new gnuplot ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
849
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
850 if (! instance)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
851 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
852 ::error ("unable to create gnuplot object!");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
853
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
854 return false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
855 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
856 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
857 instance_map[get_current_figure ()] = instance;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
858 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
859
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
860 return true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
861 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
862
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
863 bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
864 gnuplot::ensure_plot_stream (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
865 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
866 if (ensure_instance ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
867 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
868 instance->do_open ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
869
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
870 if (error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
871 return false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
872 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
873
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
874 return true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
875 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
876
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
877 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
878 gnuplot::close (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
879 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
880 if (have_instance ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
881 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
882 instance->do_close ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
883
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
884 instance_map.erase (get_current_figure ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
885 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
886 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
887
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
888 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
889 gnuplot::close_all (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
890 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
891 for (std::map<int, gnuplot *>::const_iterator p = instance_map.begin ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
892 p != instance_map.end ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
893 p++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
894 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
895 gnuplot *elt = p->second;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
896
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
897 elt->do_close ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
898 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
899 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
900
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
901 pid_t
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
902 gnuplot::pid (void) const
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
903 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
904 return plot_stream ? plot_stream->pid () : -1;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
905 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
906
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
907 gnuplot *
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
908 gnuplot::lookup_by_pid (pid_t pid)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
909 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
910 gnuplot *retval = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
911
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
912 for (std::map<int, gnuplot *>::const_iterator p = instance_map.begin ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
913 p != instance_map.end ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
914 p++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
915 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
916 gnuplot *elt = p->second;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
917
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
918 if (elt && elt->pid () == pid)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
919 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
920 retval = elt;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
921 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
922 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
923 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
924
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
925 return retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
926 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
927
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
928 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
929 gnuplot::do_open (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
930 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
931 static bool initialized = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
932
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
933 if (plot_stream && ! *plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
934 do_close ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
935
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
936 if (! plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
937 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
938 initialized = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
939
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
940 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
941
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
942 std::string cmd;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
943
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
944 if (gnuplot_exe.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
945 cmd = "gnuplot";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
946 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
947 cmd = "\"" + gnuplot_exe + "\"";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
948
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
949 // FIXME -- I'm not sure this is the right thing to do,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
950 // but without it, C-c at the octave prompt will kill gnuplot...
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
951
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
952 #if defined (HAVE_POSIX_SIGNALS)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
953 sigset_t nset, oset;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
954 sigemptyset (&nset);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
955 sigaddset (&nset, SIGINT);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
956 sigprocmask (SIG_BLOCK, &nset, &oset);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
957 #else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
958 volatile octave_interrupt_handler old_interrupt_handler
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
959 = octave_ignore_interrupts ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
960 #endif
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
961
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
962 if (use_title_option)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
963 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
964 std::ostringstream buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
965
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
966 buf << cmd << " -title \"Figure " << get_current_figure () << "\"";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
967
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
968 cmd = buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
969 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
970
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
971 plot_stream = new oprocstream (cmd.c_str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
972
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
973 if (plot_stream && *plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
974 octave_child_list::insert (plot_stream->pid (),
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
975 plot_stream_event_handler);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
976 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
977 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
978 delete_plot_stream ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
979
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
980 error ("plot: unable to open pipe to `%s'", cmd.c_str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
981 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
982
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
983 #if defined (HAVE_POSIX_SIGNALS)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
984 sigprocmask (SIG_SETMASK, &oset, 0);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
985 #else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
986 octave_set_interrupt_handler (old_interrupt_handler);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
987 #endif
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
988 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
989
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
990 if (! error_state && plot_stream && *plot_stream && ! initialized)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
991 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
992 initialized = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
993
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
994 do_send_raw ("set style data lines\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
995
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
996 if (! gnuplot_terminal_type.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
997 do_send_raw ("set term " + gnuplot_terminal_type
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
998 + Vgnuplot_command_end + "\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
999 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1000 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1001
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1002 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1003 gnuplot::delete_plot_stream (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1004 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1005 do_send_raw ("\nquit\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1006
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1007 delete plot_stream;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1008 plot_stream = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1009 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1010
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1011 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1012 gnuplot::reset_plot_stream (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1013 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1014 delete_plot_stream ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1015
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1016 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1017 parametric_plot = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1018 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1019
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1020 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1021 gnuplot::do_close (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1022 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1023 if (plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1024 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1025 octave_child_list::remove (plot_stream->pid ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1026
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1027 delete_plot_stream ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1028 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1029
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1030 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1031 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1032
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1033 bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1034 gnuplot::plot_stream_event_handler (pid_t pid, int status)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1035 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1036 bool retval = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1037
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1038 if (pid > 0)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1039 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1040 if (WIFEXITED (status) || WIFSIGNALLED (status))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1041 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1042 gnuplot *plotter = gnuplot::lookup_by_pid (pid);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1043
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1044 // We should only print a warning or request removal of the
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1045 // process from the child list if the process died
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1046 // unexpectedly. If do_close is responsible for
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1047 // gnuplot's death, then plotter will be 0 here and we don't
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1048 // need to do anything.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1049
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1050 if (plotter)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1051 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1052 plotter->reset_plot_stream ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1053
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1054 warning ("connection to external plotter (pid = %d) lost --", pid);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1055 // Request removal of this PID from the list of child
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1056 // processes.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1057
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1058 retval = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1059 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1060 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1061 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1062
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1063 return retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1064 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1065
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1066 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1067 gnuplot::do_send (const std::string& cmd)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1068 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1069 int replot_len = Vgnuplot_command_replot.length ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1070
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1071 bool is_replot = (Vgnuplot_command_replot == cmd.substr (0, replot_len));
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1072
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1073 if (! (plot_line_count == 0 && is_replot))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1074 do_send_raw (cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1075 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1076
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1077 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1078 gnuplot::do_send_raw (const std::string& cmd)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1079 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1080 if (plot_stream && *plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1081 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1082 *plot_stream << cmd;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1083
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1084 plot_stream->flush ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1085 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1086 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1087
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1088 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1089 gnuplot::do_clear (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1090 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1091 do_send_raw ("clear\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1092
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1093 // FIXME -- instead of just clearing these things, it would
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1094 // be nice if we could reset things to a user-specified default
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1095 // state.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1096
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1097 do_send_raw ("set title\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1098 do_send_raw ("set xlabel\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1099 do_send_raw ("set ylabel\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1100 do_send_raw ("set nogrid\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1101 do_send_raw ("set nolabel\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1102
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1103 // This makes a simple `replot' not work after a `clearplot' command
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1104 // has been issued.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1105
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1106 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1107 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1108
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1109 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1110 gnuplot::do_set (const string_vector& argv)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1111 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1112 int argc = argv.length ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1113
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1114 std::ostringstream plot_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1115
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1116 if (argc > 1)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1117 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1118 if (almost_match ("parametric", argv[1], 3))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1119 parametric_plot = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1120 else if (almost_match ("noparametric", argv[1], 5))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1121 parametric_plot = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1122 else if (almost_match ("term", argv[1], 1))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1123 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1124 gnuplot_terminal_type = "";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1125 std::ostringstream buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1126 int i;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1127 for (i = 2; i < argc-1; i++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1128 buf << argv[i] << " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1129 if (i < argc)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1130 buf << argv[i];
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1131 buf << Vgnuplot_command_end;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1132 gnuplot_terminal_type = buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1133 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1134 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1135
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1136 int i;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1137 for (i = 0; i < argc-1; i++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1138 plot_buf << argv[i] << " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1139
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1140 if (i < argc)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1141 plot_buf << argv[i];
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1142
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1143 plot_buf << Vgnuplot_command_end;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1144
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1145 do_send_raw (plot_buf.str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1146 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1147
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1148 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1149 gnuplot::do_show (const string_vector& argv)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1150 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1151 int argc = argv.length ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1152
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1153 std::ostringstream plot_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1154
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1155 int i;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1156 for (i = 0; i < argc-1; i++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1157 plot_buf << argv[i] << " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1158 if (i < argc)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1159 plot_buf << argv[i];
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1160
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1161 plot_buf << Vgnuplot_command_end;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1162
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1163 do_send (plot_buf.str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1164 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1165
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1166 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1167 gnuplot::do_plot (const string_vector& argv)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1168 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1169 std::string s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1170
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1171 for (int i = 1; i < argv.length (); i++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1172 s += argv[i] + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1173
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1174 try
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1175 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1176 std::string cmd = makeplot (argv[0], s);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1177
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1178 do_send (cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1179 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1180 catch (gpt_parse_error& e)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1181 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1182 if (e.msg.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1183 error ("could not parse plot command");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1184 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1185 error (e.msg.c_str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1186 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1187 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1188
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1189 // Parse and evaluate parameter string and pass it to gnuplot pipe.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1190
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1191 std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1192 gnuplot::makeplot (std::string caller, std::string args)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1193 throw (gpt_parse_error)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1194 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1195 std::string retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1196
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1197 YY_BUFFER_STATE bstate;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1198
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1199 bstate = yy_scan_string (args.c_str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1200 yy_switch_to_buffer (bstate);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1201 std::string outstr;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1202 int ndim = 2;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1203
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1204 if (caller == "replot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1205 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1206 ndim = 1;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1207 outstr += Vgnuplot_command_replot + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1208 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1209 else if (caller == "plot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1210 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1211 ndim = 2;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1212 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1213 outstr += Vgnuplot_command_plot + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1214 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1215 else if (caller == "splot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1216 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1217 ndim = 3;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1218 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1219 outstr += Vgnuplot_command_splot + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1220 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1221 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1222 throw gpt_parse_error ("unknown plot command");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1223
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1224 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1225 gpt_allow_plotkw = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1226 gpt_parens = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1227 gpt_braces = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1228 gpt_brackets = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1229
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1230 int tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1231 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1232 if (plottok_or_end_p (tok) && caller != "replot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1233 throw gpt_parse_error ("must have something to plot");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1234
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1235 while (tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1236 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1237 bool title_set = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1238 bool using_set = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1239 bool style_set = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1240 bool axes_set = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1241
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1242 if (tok == START_BRACKET)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1243 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1244 if (caller == "replot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1245 throw gpt_parse_error ("can't specify new plot ranges with `replot' or while hold is on");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1246
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1247 std::string xrange_start_str = read_until (colonp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1248 std::string xrange_end_str = read_until (endbracketp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1249 outstr += printrange (xrange_start_str, xrange_end_str) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1250 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1251 if (tok == START_BRACKET)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1252 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1253 std::string yrange_start_str = read_until (colonp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1254 std::string yrange_end_str = read_until (endbracketp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1255 outstr += printrange (yrange_start_str, yrange_end_str) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1256 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1257 if (tok == START_BRACKET && caller == "gsplot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1258 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1259 std::string zrange_start_str = read_until (colonp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1260 std::string zrange_end_str = read_until (endbracketp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1261 outstr += printrange (zrange_start_str, zrange_end_str) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1262 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1263 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1264 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1265 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1266
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1267 if (plottok_or_end_p (tok))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1268 return std::string ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1269 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1270 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1271 std::string file;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1272 plot_line_count++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1273
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1274 std::string plot_expr_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1275 plot_expr_str += std::string (yytext) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1276 plot_expr_str += read_until (plottok_or_end_p, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1277
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1278 int status = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1279 octave_value tmp_data = eval_string (plot_expr_str,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1280 true, status);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1281
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1282 if (status != 0 || ! tmp_data.is_defined ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1283 throw gpt_parse_error ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1284
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1285 std::ostringstream tmp_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1286 tmp_data.print_raw (tmp_buf);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1287
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1288 if (tmp_data.is_string ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1289 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1290 file = file_ops::tilde_expand (tmp_data.string_value ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1291 // FIXME -- perhaps should check if the file exists?
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1292 outstr += file + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1293 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1294 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1295 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1296 switch (ndim)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1297 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1298 case 2:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1299 file = save_in_tmp_file (tmp_data, ndim);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1300 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1301
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1302 case 3:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1303 file = save_in_tmp_file (tmp_data, ndim,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1304 parametric_plot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1305 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1306
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1307 default:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1308 gripe_2_or_3_dim_plot ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1309 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1310 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1311
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1312 if (file.length () > 0)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1313 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1314 mark_for_deletion (file);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1315 outstr += "'" + file + "' ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1316 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1317 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1318 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1319
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1320 std::string title_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1321 std::string using_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1322 std::string style_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1323 std::string axes_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1324
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1325 bool out = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1326 while (tok && ! out)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1327 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1328 switch (tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1329 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1330 case COMMA:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1331 out = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1332 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1333
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1334 case TITLE:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1335 if (! title_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1336 title_str += handle_title (tok) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1337 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1338 throw gpt_parse_error ("only one title option may be specified");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1339 title_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1340 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1341
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1342 case USING:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1343 if (! using_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1344 using_str += handle_using (tok) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1345 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1346 throw gpt_parse_error ("only one using option may be specified");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1347 using_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1348 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1349
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1350 case WITH:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1351 if (! style_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1352 style_str += handle_style (tok) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1353 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1354 throw gpt_parse_error ("only one style option may be specified");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1355 style_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1356 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1357
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1358 case AXES:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1359 if (! axes_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1360 axes_str += handle_axes (tok) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1361 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1362 throw gpt_parse_error ("only one axes option may be specified");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1363 axes_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1364 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1365
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1366 default:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1367 tok = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1368 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1369 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1370 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1371
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1372 if (! title_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1373 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1374 std::ostringstream tmp_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1375 tmp_buf << Vgnuplot_command_title << " \"line "
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1376 << plot_line_count << "\" ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1377 title_str = tmp_buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1378 title_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1379 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1380
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1381 // Plot parameters have to be output in this order.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1382 if (using_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1383 outstr += using_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1384
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1385 if (axes_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1386 outstr += axes_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1387
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1388 if (title_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1389 outstr += title_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1390
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1391 if (style_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1392 outstr += style_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1393
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1394 if (out)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1395 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1396 // Saw comma on while loop.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1397 outstr += ", ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1398 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1399 gpt_allow_plotkw = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1400 gpt_parens = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1401 gpt_braces = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1402 gpt_brackets = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1403 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1404 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1405 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1406
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1407 outstr += Vgnuplot_command_end;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1408
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1409 return outstr;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1410 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1411
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1412 // Title has one string expression which is evaluated and printed to the
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1413 // gnuplot command string.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1414
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1415 std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1416 gnuplot::handle_title (int& lasttok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1417 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1418 int tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1419 std::string retstr = Vgnuplot_command_title + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1420 std::string title_expr_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1421
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1422 title_expr_str += read_until (plottok_or_end_p, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1423
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1424 int status;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1425 octave_value tmp_data = eval_string (title_expr_str, true, status);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1426
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1427 if (status != 0 || ! tmp_data.is_defined ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1428 throw gpt_parse_error ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1429
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1430 std::ostringstream tmp_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1431 if (tmp_data.is_string ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1432 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1433 tmp_buf << '"';
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1434 tmp_data.print_raw (tmp_buf);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1435 tmp_buf << '"';
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1436 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1437 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1438 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1439 warning ("line title must be a string");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1440 tmp_buf << '"' << "line " << plot_line_count << '"';
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1441 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1442
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1443 retstr += tmp_buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1444
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1445 lasttok = tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1446
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1447 return retstr;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1448 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1449
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1450 // The static instance of this class is here so that
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1451 // gnuplot::close_all will be called when the .oct file is unloaded.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1452
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1453 class
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1454 gnuplot_X
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1455 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1456 public:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1457 gnuplot_X (void) { }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1458 ~gnuplot_X (void) { gnuplot::close_all (); }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1459 };
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1460
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1461 static gnuplot_X X;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1462
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1463 // -----------------------
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1464 // User-callable functions
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1465 // -----------------------
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1466
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1467 DEFUN_DLD (automatic_replot, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1468 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1469 @deftypefn {Loadable Function} {@var{val} =} automatic_replot ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1470 @deftypefnx {Loadable Function} {@var{old_val} =} automatic_replot (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1471 Query or set the current automatic replot state. Although it is fairly\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1472 inefficient, especially for large plots, automatic replotting is enabled\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1473 by default for compatibility with Matlab.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1474 \n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1475 When setting the state, @var{new_val}\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1476 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1477 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1478 return SET_INTERNAL_VARIABLE (automatic_replot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1479 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1480
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1481 DEFUN_DLD (gnuplot_binary, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1482 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1483 @deftypefn {Loadable Function} gnuplot_binary\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1484 The name of the program invoked by the plot command. The default value\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1485 is @code{\"gnuplot\"}. @xref{Installation}.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1486 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1487 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1488 octave_value retval = SET_INTERNAL_VARIABLE (gnuplot_binary);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1489
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1490 if (! error_state && args.length () == 1)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1491 gnuplot::set_gnuplot_exe (Vgnuplot_binary);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1492
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1493 return retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1494 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1495
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1496 DEFUN_DLD (gnuplot_command_plot, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1497 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1498 @deftypefn {Loadable Function} {@var{val} = } gnuplot_command_plot ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1499 @deftypefnx {Loadable Function} {@var{old_val} = } gnuplot_command_plot (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1500 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1501 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1502 return SET_INTERNAL_VARIABLE (gnuplot_command_plot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1503 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1504
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1505 DEFUN_DLD (gnuplot_command_replot, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1506 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1507 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_replot ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1508 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_replot (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1509 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1510 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1511 return SET_INTERNAL_VARIABLE (gnuplot_command_replot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1512 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1513
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1514 DEFUN_DLD (gnuplot_command_splot, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1515 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1516 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_splot ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1517 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_splot (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1518 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1519 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1520 return SET_INTERNAL_VARIABLE (gnuplot_command_splot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1521 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1522
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1523 DEFUN_DLD (gnuplot_command_using, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1524 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1525 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_using ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1526 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_using (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1527 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1528 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1529 return SET_INTERNAL_VARIABLE (gnuplot_command_using);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1530 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1531
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1532 DEFUN_DLD (gnuplot_command_with, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1533 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1534 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_with ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1535 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_with (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1536 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1537 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1538 return SET_INTERNAL_VARIABLE (gnuplot_command_with);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1539 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1540
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1541 DEFUN_DLD (gnuplot_command_axes, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1542 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1543 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_axes ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1544 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_axes (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1545 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1546 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1547 return SET_INTERNAL_VARIABLE (gnuplot_command_axes);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1548 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1549
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1550 DEFUN_DLD (gnuplot_command_title, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1551 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1552 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_title ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1553 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_title (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1554 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1555 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1556 return SET_INTERNAL_VARIABLE (gnuplot_command_title);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1557 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1558
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1559 DEFUN_DLD (gnuplot_command_end, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1560 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1561 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_end ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1562 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_command_end (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1563 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1564 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1565 return SET_INTERNAL_VARIABLE (gnuplot_command_end);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1566 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1567
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1568 DEFUN_DLD (gnuplot_use_title_option, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1569 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1570 @deftypefn {Loadable Function} {@var{val} =} gnuplot_use_title_option ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1571 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_use_title_option (@var{new_val})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1572 If enabled, append @samp{-title \"Figure NN\"} to the gnuplot command.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1573 By default, this feature is enabled if the @code{DISPLAY} environment\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1574 variable is set when Octave starts.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1575 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1576 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1577 return SET_INTERNAL_VARIABLE (gnuplot_use_title_option);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1578 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1579
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1580 DEFUN_DLD (clearplot, , ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1581 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1582 @deftypefn {Loadable Function} {} clearplot\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1583 @deftypefnx {Loadable Function} {} clg\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1584 Clear the plot window and any titles or axis labels. The name\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1585 @code{clg} is aliased to @code{clearplot} for compatibility with\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1586 @sc{Matlab}.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1587 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1588 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1589 gnuplot::clear ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1590
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1591 octave_value_list args;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1592
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1593 args(0) = "off";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1594
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1595 feval ("hold", args);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1596
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1597 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1598 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1599
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1600 DEFUN_DLD (closeplot, , ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1601 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1602 @deftypefn {Loadable Function} {} closeplot\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1603 Close stream to the @code{gnuplot} subprocess. If you are using X11,\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1604 this will close the plot window.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1605 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1606 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1607 gnuplot::close ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1608
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1609 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1610 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1611
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1612 DEFUN_DLD (purge_tmp_files, , ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1613 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1614 @deftypefn {Loadable Function} {} purge_tmp_files\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1615 Delete the temporary files created by the plotting commands.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1616 \n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1617 Octave creates temporary data files for @code{gnuplot} and then sends\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1618 commands to @code{gnuplot} through a pipe. Octave will delete the\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1619 temporary files on exit, but if you are doing a lot of plotting you may\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1620 want to clean up in the middle of a session.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1621 \n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1622 A future version of Octave will eliminate the need to use temporary\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1623 files to hold the plot data.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1624 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1625 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1626 gnuplot::cleanup_tmp_files ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1627
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1628 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1629 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1630
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1631 DEFUN_DLD (__gnuplot_raw__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1632 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1633 @deftypefn {Loadable Function} {} __gnuplot_raw__ (@var{string})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1634 Send @var{string} directly to gnuplot subprocess.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1635 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1636 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1637 if (args.length () == 1 && args(0).is_string ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1638 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1639 std::string cmd = args(0).string_value ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1640
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1641 gnuplot::send_raw (cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1642 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1643 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1644 print_usage ("__gnuplot_raw__");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1645
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1646 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1647 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1648
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1649 DEFUN_DLD (__gnuplot_set__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1650 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1651 @deffn {{Loadable Function} __gnuplot_set__ options\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1652 Set plotting options for gnuplot\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1653 @end deffn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1654 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1655 string_vector argv = args.make_argv ("set");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1656
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1657 if (! error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1658 gnuplot::set (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1659
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1660 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1661 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1662
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1663 DEFUN_DLD (__gnuplot_show__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1664 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1665 @deffn {{Loadable Function} __gnuplot_show__ options\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1666 Show plotting options.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1667 @end deffn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1668 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1669 string_vector argv = args.make_argv ("show");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1670
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1671 if (! error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1672 gnuplot::show (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1673
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1674 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1675 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1676
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1677 DEFUN_DLD (__gnuplot_plot__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1678 "Plot with gnuplot.\n")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1679 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1680 string_vector argv = args.make_argv ("plot");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1681
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1682 if (! error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1683 gnuplot::plot (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1684
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1685 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1686 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1687
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1688 DEFUN_DLD (__gnuplot_splot__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1689 "Plot with gnuplot.\n")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1690 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1691 string_vector argv = args.make_argv ("splot");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1692
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1693 if (! error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1694 gnuplot::plot (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1695
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1696 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1697 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1698
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1699 DEFUN_DLD (__gnuplot_replot__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1700 "Plot with gnuplot.\n")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1701 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1702 string_vector argv = args.make_argv ("replot");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1703
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1704 if (! error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1705 gnuplot::plot (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1706
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1707 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1708 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1709
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1710 /*
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1711 ;;; Local Variables: ***
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1712 ;;; mode: C++ ***
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1713 ;;; End: ***
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1714 */