annotate src/DLD-FUNCTIONS/__gnuplot_raw__.l @ 5958:85c7dc4afe6b

[project @ 2006-08-23 18:35:38 by jwe]
author jwe
date Wed, 23 Aug 2006 18:35:39 +0000
parents 5e41e06f6a78
children 5c2747f40b56
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_splot__");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
30 // PKG_ADD: mark_as_rawcommand ("__gnuplot_replot__");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
31
5796
20f4bd627a74 [project @ 2006-05-09 02:04:54 by jwe]
jwe
parents: 5794
diff changeset
32 // PKG_ADD: mark_as_command ("__gnuplot_set__");
5790
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"
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
60 #include "ls-oct-ascii.h"
5790
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,
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
79 DOLLAR,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
80 IDENT,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
81 NUMBER,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
82 BINOP,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
83 UNOP,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
84 STRING,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
85 OTHER,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
86 TITLE,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
87 USING,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
88 WITH,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
89 AXES,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
90 CLEAR
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
93 typedef bool (*pred) (const int);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
94
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
95 class
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
96 gpt_parse_error
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
97 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
98 public:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
99 gpt_parse_error (void) : msg () { }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
100 gpt_parse_error (std::string errmsg) : msg (errmsg) { }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
101
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
102 std::string msg;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
105 static bool gpt_quote_is_transpose;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
106 static bool gpt_allow_plotkw;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
107 static int gpt_parens;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
108 static int gpt_brackets;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
109 static int gpt_braces;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
110
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
111 static bool can_be_plotkw (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
112
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
113 static int is_plot_keyword (const std::string& s);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
114
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
115 static int handle_string (char delim);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
116 static std::string strbuf;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
120 D [0-9]
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
121 S [ \t]
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
122 IDENT ([_a-zA-Z@][_a-zA-Z0-9]*)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
123 EXPON ([DdEe][+-]?{D}+)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
124 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
125 NOT ((\~)|(\!))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
126 /* 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
127 BINOP (({NOT})|(\.?([\*/\\^+-]|\*\*)=?)|([<=~!>&|]=)|([=&|<>]{1,2})|(<<=)|(>>=)|(\.))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
128 /* single quote (') transpose operator is handled separately. */
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
129 UNOP ((\+\+)|(\-\-)|(\.'))
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 "(" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
134 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
135 gpt_parens++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
136 return START_PAREN;
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 ")" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
140 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
141 gpt_parens--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
142 return END_PAREN;
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 "{" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
146 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
147 gpt_braces++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
148 return START_BRACE;
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 "}" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
152 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
153 gpt_braces--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
154 return END_BRACE;
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 "[" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
158 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
159 gpt_brackets++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
160 return START_BRACKET;
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 "]" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
164 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
165 gpt_brackets--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
166 return END_BRACKET;
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 ":" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
170 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
171 return COLON;
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 ";" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
175 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
176 return SEMICOLON;
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 "," {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
180 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
181 return COMMA;
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 "'" {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
185 if (gpt_quote_is_transpose)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
186 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
187 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
188 return QUOTE;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
189 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
190 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
191 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
192 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
193 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
194 return handle_string ('\'');
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
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
198 "$" {
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
199 gpt_quote_is_transpose = false;
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
200 return DOLLAR;
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
201 }
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
202
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
203
5790
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 return handle_string ('"');
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
206 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
207
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
208 {IDENT} {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
209 int itok = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
210 if (can_be_plotkw () && (itok = is_plot_keyword (yytext)))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
211 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
212 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
213 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
214 return itok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
215 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
216 else if (std::string (yytext) == "function")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
217 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
218 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
219 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
220 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
221 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
222 return IDENT;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
223 }
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 {D}+/\.[\*/\\^'] | /* ' */
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
227 {NUMBER} {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
228 gpt_quote_is_transpose = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
229 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
230 return NUMBER;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
233 {BINOP} {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
234 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
235 gpt_allow_plotkw = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
236 return BINOP;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
239 {UNOP} {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
240 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
241 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
242 return UNOP;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
243 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
244
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
245 {S} { /* Ignore spaces and tabs outside of character strings. */ }
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 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
249 gpt_allow_plotkw = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
250 warning ("unknown token = \"%s\" in plot command", yytext);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
251 return OTHER;
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 %%
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
255
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 // Interface to external gnuplot process(es), including gnuplot
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
258 // command parser.
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
261 // 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
262 static std::string Vgnuplot_binary = GNUPLOT_BINARY;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
263
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
264 // Append -title "Figure NN" to the gnuplot command?
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
265 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
266
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
267 // Gnuplot command strings that we use.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
268 static std::string Vgnuplot_command_plot = "pl";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
269 static std::string Vgnuplot_command_replot = "rep";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
270 static std::string Vgnuplot_command_splot = "sp";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
271 static std::string Vgnuplot_command_using = "u";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
272 static std::string Vgnuplot_command_with = "w";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
273 static std::string Vgnuplot_command_axes = "ax";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
274 static std::string Vgnuplot_command_title = "t";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
275 static std::string Vgnuplot_command_end = "\n";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
276
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
277 // 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
278 // changes in some way.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
279 static bool Vautomatic_replot = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
280
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
281 // 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
282
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
283 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
284 can_be_plotkw (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
285 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
286 return (gpt_allow_plotkw
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
287 && (gpt_braces == 0)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
288 && (gpt_brackets == 0)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
289 && (gpt_parens == 0));
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
290 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
291
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
292 // 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
293 // 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
294 // 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
295 // to abbreviate actual gnuplot keywords).
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
296
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
297 static int
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
298 is_plot_keyword (const std::string& s)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
299 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
300 if (almost_match ("title", s, 1))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
301 return TITLE;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
302 else if (almost_match ("using", s, 1))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
303 return USING;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
304 else if (almost_match ("with", s, 1))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
305 return WITH;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
306 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
307 return AXES;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
308 else if ("clear" == s)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
309 return CLEAR;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
310 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
311 return 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
312 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
313
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
314 // This is used to handle character strings. Kludge alert.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
315
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
316 static int
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
317 handle_string (char delim)
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 int c;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
320 bool escape_pending = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
321
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
322 strbuf = std::string (1, delim);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
323
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
324 while ((c = yyinput ()) != EOF)
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 if (c == '\\')
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 if (escape_pending)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
329 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
330 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
331 escape_pending = false;
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
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 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
336 escape_pending = true;
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 continue;
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 else if (c == '\n')
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
341 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
342 error ("unterminated string constant");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
343 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
344 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
345 else if (c == delim)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
346 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
347 if (escape_pending)
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 else
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 c = yyinput ();
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 if (c == delim)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
354 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
355 strbuf += static_cast<char> (c);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
356 strbuf += static_cast<char> (c);
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 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
359 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
360 yyunput (c, yytext);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
361 strbuf += static_cast<char> (delim);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
362 return STRING;
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 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
366 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
367 strbuf += static_cast<char> (c);
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 escape_pending = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
370 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
371
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
372 throw gpt_parse_error ("unterminated string");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
373
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
374 return 0;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
377 // (Probably not necessesary, but current Matlab style plot functions
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
378 // break without this (they emit too short gnuplot commands))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
379
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
380 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
381 plot_style_token (const std::string& s)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
382 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
383 std::string retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
384
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
385 // FIXME -- specify minimum match length for these.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
386 static const char *plot_styles[] =
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
387 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
388 "boxes",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
389 "boxerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
390 "boxxyerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
391 "candlesticks",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
392 "dots",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
393 "errorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
394 "financebars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
395 "fsteps",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
396 "histeps",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
397 "impulses",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
398 "lines",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
399 "linespoints",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
400 "points",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
401 "steps",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
402 "vector",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
403 "xerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
404 "xyerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
405 "yerrorbars",
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
406 0,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
407 };
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
408
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
409 const char * const *tmp = plot_styles;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
410 while (*tmp)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
411 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
412 if (almost_match (*tmp, s.c_str ()))
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 retval = *tmp;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
415 break;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
418 tmp++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
419 }
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 return retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
422 }
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 // Some predicates on tokens
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 // Return true for ":".
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
427
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
428 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
429 colonp (const int tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
430 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
431 return (tok == COLON);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
432 }
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 // Return TRUE for "]".
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
435
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
436 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
437 endbracketp (const int tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
438 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
439 return (tok == END_BRACKET);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
440 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
441
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
442 // Return TRUE for plot token, comma or end of input.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
443
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
444 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
445 plottok_or_end_p (const int tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
446 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
447 return (tok == TITLE
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
448 || tok == USING
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
449 || tok == WITH
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
450 || tok == AXES
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
451 || tok == CLEAR
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
452 || tok == COMMA
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
453 || tok == 0);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
454 }
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 // Equivalent to (colonp (tok) || plottok_or_end_p (tok)).
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
457
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
458 static bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
459 colon_plottok_or_end_p (const int tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
460 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
461 return (tok == COLON || plottok_or_end_p (tok));
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
464 // 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
465 // Return the last token in lasttok
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
466
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
467 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
468 read_until (pred test, int& lasttok) throw (gpt_parse_error)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
469 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
470 int tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
471
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
472 // We have to maintain balanced delimiters per subexpression too.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
473 int brackets = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
474 int parens = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
475 int braces = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
476 std::string s;
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 tok = gptlex ();
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 while (tok && ! (test (tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
481 && brackets == 0
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
482 && parens == 0
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
483 && braces == 0))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
484 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
485 switch (tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
486 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
487 case START_BRACKET:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
488 brackets++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
489 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
490
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
491 case END_BRACKET:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
492 brackets--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
493 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
494
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
495 case START_PAREN:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
496 parens++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
497 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
498
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
499 case END_PAREN:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
500 parens--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
501 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
502
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
503 case START_BRACE:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
504 braces++;
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 case END_BRACE:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
508 braces--;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
509 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
510
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
511 default:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
512 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
513 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
514
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
515 s += (tok == STRING ? strbuf : std::string (yytext)) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
516
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
517 tok = gptlex ();
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
520 // 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
521 // doesn't accept it.
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 if (! test (tok) && ! tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
524 throw gpt_parse_error ("unexpected end of input");
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 lasttok = tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
527
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
528 return s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
529 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
530
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
531 // 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
532
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
533 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
534 printrange (std::string starts, std::string ends)
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 octave_value startv, endv;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
537 int status;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
538 std::string s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
539 std::ostringstream range_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
540
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
541 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 if (! starts.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
544 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
545 startv = eval_string (starts, true, status);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
546 if (! startv.is_real_scalar ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
547 throw gpt_parse_error ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
548 startv.print_raw (range_buf);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
549 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
550
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
551 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 if (! ends.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
554 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
555 endv = eval_string (ends, true, status);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
556 if (! endv.is_real_scalar ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
557 throw gpt_parse_error ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
558 endv.print_raw (range_buf);
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 range_buf << "]";
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 s = range_buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
564
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
565 return s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
566 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
567
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
568 // Handle plot parameters.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
569
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
570 // Parse, evaluate and print colon separated expressions in the using
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
571 // 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
572
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
573 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
574 handle_using (int& lasttok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
575 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
576 int tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
577 std::string expr_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
578 std::string retstr = Vgnuplot_command_using + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
579 bool out = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
580
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
581 octave_value tmp_data;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
582 int status;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
583 while (! out)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
584 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
585 expr_str = read_until (colon_plottok_or_end_p, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
586
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
587 if (! expr_str.empty () && expr_str[0] == '(')
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
588 retstr += expr_str;
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
589 else
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
590 {
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
591 tmp_data = eval_string (expr_str, true, status);
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
592 if (status != 0 || ! tmp_data.is_real_scalar ())
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
593 throw gpt_parse_error ();
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
594
5958
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
595 std::ostringstream tmp_buf;
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
596 tmp_data.print_raw (tmp_buf);
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
597 retstr += tmp_buf.str ();
85c7dc4afe6b [project @ 2006-08-23 18:35:38 by jwe]
jwe
parents: 5832
diff changeset
598 }
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
599
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
600 if (tok == COLON)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
601 retstr += ":";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
602 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
603 out = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
604 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
605
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
606 lasttok = tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
607
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
608 return retstr;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
609 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
610
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
611 // 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
612
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
613 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
614 handle_style (int& lasttok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
615 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
616 std::string retstr = Vgnuplot_command_with + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
617 std::string style;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
618
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
619 lasttok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
620
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
621 if (lasttok != IDENT)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
622 throw gpt_parse_error ("expected plot style token");
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 style = std::string (yytext);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
625 style = plot_style_token (style);
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 if (! style.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
628 retstr += style;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
629 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
630 retstr += std::string (yytext);
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 // FIXME -- should evaluate the remaining tokens, but this
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
633 // needs changes in the parser.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
634 retstr += " " + read_until (plottok_or_end_p, lasttok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
635
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
636 return retstr;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
639 // Axes has only one qualifier keyword, which is not evaluated.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
640
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
641 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
642 handle_axes (int& lasttok)
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 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
645 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
646
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
647 static std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
648 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
649 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
650 std::string name = file_ops::tempnam ("", "oct-");
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 if (! name.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
653 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
654 std::ofstream file (name.c_str ());
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 if (file)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
657 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
658 switch (ndim)
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 case 2:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
661 save_ascii_data_for_plotting (file, t, name);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
662 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
663
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
664 case 3:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
665 save_three_d (file, t, parametric);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
666 break;
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 default:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
669 gripe_2_or_3_dim_plot ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
670 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
671 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
672 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
673 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
674 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
675 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
676 name.resize (0);
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 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
679
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
680 return name;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
681 }
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 static int
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
684 get_current_figure (void)
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 int retval = 1;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
687
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
688 octave_value cf = get_global_value ("__current_figure__", true);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
689
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
690 if (cf.is_defined ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
691 retval = cf.int_value ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
692 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
693 set_global_value ("__current_figure__", retval);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
694
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
695 return retval;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
698 class
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
699 gnuplot
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 protected:
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 gnuplot (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
704 : plot_line_count (0), parametric_plot (false),
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
705 use_title_option (Vgnuplot_use_title_option),
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
706 gnuplot_exe (Vgnuplot_binary),
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
707 gnuplot_terminal_type (), plot_stream () { }
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 public:
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 ~gnuplot (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 have_instance (void);
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 bool ensure_instance (void);
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 static bool ensure_plot_stream (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
718
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
719 static void open (void);
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 close (void);
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 static void close_all (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
724
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
725 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
726
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
727 static void send (const std::string& cmd)
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_send (cmd);
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 send_raw (const std::string& cmd)
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_send_raw (cmd);
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 clear (void)
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_clear ();
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 (const string_vector& argv)
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_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
748 instance->do_set (argv);
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 show (const string_vector& argv)
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_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
754 instance->do_show (argv);
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 static void set_gnuplot_exe (const std::string& exe)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
758 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
759 if (ensure_instance ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
760 instance->do_set_gnuplot_exe (exe);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
761 }
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 static void set_gnuplot_use_title_option (bool opt)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
764 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
765 if (ensure_instance ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
766 instance->do_set_gnuplot_use_title_option (opt);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
767 }
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 // FIXME -- should only remove tmp files associated with
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
770 // gnuplot?
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
771 static void cleanup_tmp_files (void) { ::cleanup_tmp_files (); }
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 static void plot (const string_vector& argv)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
774 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
775 if (ensure_plot_stream ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
776 instance->do_plot (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
777 }
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 private:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
780
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
781 static gnuplot *instance;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
782
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
783 static std::map<int, gnuplot *> instance_map;
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 number of lines we've plotted so far.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
786 int plot_line_count;
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 // 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
789 bool parametric_plot;
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 // Should we append '-title "TITLE"' to the gnuplot command?
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
792 bool use_title_option;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
793
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
794 // The executable program to run.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
795 std::string gnuplot_exe;
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 // The gnuplot terminal type.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
798 std::string gnuplot_terminal_type;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
799
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
800 // Pipe to gnuplot.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
801 oprocstream *plot_stream;
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 pid_t pid (void) const;
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 static gnuplot *lookup_by_pid (pid_t pid);
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_open (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_close (void);
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 delete_plot_stream (void);
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 reset_plot_stream (void);
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_send (const std::string& cmd);
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_send_raw (const std::string& cmd);
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 void do_clear (void);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
820
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
821 void do_set (const string_vector& argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
822
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
823 void do_show (const string_vector& argv);
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 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
826
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
827 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
828
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
829 void do_plot (const string_vector& argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
830
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
831 std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
832 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
833
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
834 std::string handle_title (int& lasttok);
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
837 gnuplot *gnuplot::instance = 0;
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 std::map<int, gnuplot *> gnuplot::instance_map;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
840
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
841 bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
842 gnuplot::have_instance (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
843 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
844 int current_figure = get_current_figure ();
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 (instance_map.find (current_figure) != instance_map.end ())
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 = instance_map[current_figure];
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
849 return true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
850 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
851 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
852 return false;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
855 bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
856 gnuplot::ensure_instance (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
857 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
858 if (! have_instance ())
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 instance = new gnuplot ();
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 if (! instance)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
863 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
864 ::error ("unable to create gnuplot object!");
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 return false;
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 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
869 instance_map[get_current_figure ()] = instance;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
870 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
871
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
872 return true;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
875 bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
876 gnuplot::ensure_plot_stream (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
877 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
878 if (ensure_instance ())
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 instance->do_open ();
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 if (error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
883 return false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
884 }
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 return true;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
889 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
890 gnuplot::close (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
891 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
892 if (have_instance ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
893 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
894 instance->do_close ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
895
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
896 instance_map.erase (get_current_figure ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
897 }
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 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
901 gnuplot::close_all (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
902 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
903 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
904 p != instance_map.end ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
905 p++)
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 *elt = p->second;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
908
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
909 elt->do_close ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
910 }
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
913 pid_t
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
914 gnuplot::pid (void) const
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 return plot_stream ? plot_stream->pid () : -1;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
919 gnuplot *
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
920 gnuplot::lookup_by_pid (pid_t pid)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
921 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
922 gnuplot *retval = 0;
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 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
925 p != instance_map.end ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
926 p++)
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 gnuplot *elt = p->second;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
929
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
930 if (elt && elt->pid () == pid)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
931 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
932 retval = elt;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
933 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
934 }
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
937 return retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
938 }
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 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
941 gnuplot::do_open (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
942 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
943 static bool initialized = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
944
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
945 if (plot_stream && ! *plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
946 do_close ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
947
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
948 if (! plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
949 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
950 initialized = false;
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 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
953
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
954 std::string cmd;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
955
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
956 if (gnuplot_exe.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
957 cmd = "gnuplot";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
958 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
959 cmd = "\"" + gnuplot_exe + "\"";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
960
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
961 // 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
962 // 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
963
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
964 #if defined (HAVE_POSIX_SIGNALS)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
965 sigset_t nset, oset;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
966 sigemptyset (&nset);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
967 sigaddset (&nset, SIGINT);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
968 sigprocmask (SIG_BLOCK, &nset, &oset);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
969 #else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
970 volatile octave_interrupt_handler old_interrupt_handler
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
971 = octave_ignore_interrupts ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
972 #endif
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
973
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
974 if (use_title_option)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
975 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
976 std::ostringstream buf;
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 buf << cmd << " -title \"Figure " << get_current_figure () << "\"";
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 cmd = buf.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 plot_stream = new oprocstream (cmd.c_str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
984
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
985 if (plot_stream && *plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
986 octave_child_list::insert (plot_stream->pid (),
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
987 plot_stream_event_handler);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
988 else
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 delete_plot_stream ();
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 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
993 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
994
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
995 #if defined (HAVE_POSIX_SIGNALS)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
996 sigprocmask (SIG_SETMASK, &oset, 0);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
997 #else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
998 octave_set_interrupt_handler (old_interrupt_handler);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
999 #endif
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 if (! error_state && plot_stream && *plot_stream && ! initialized)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1003 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1004 initialized = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1005
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1006 do_send_raw ("set style data lines\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1007
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1008 if (! gnuplot_terminal_type.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1009 do_send_raw ("set term " + gnuplot_terminal_type
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1010 + Vgnuplot_command_end + "\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1011 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1012 }
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 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1015 gnuplot::delete_plot_stream (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1016 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1017 do_send_raw ("\nquit\n");
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 delete plot_stream;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1020 plot_stream = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1021 }
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 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1024 gnuplot::reset_plot_stream (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1025 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1026 delete_plot_stream ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1027
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1028 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1029 parametric_plot = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1030 }
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 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1033 gnuplot::do_close (void)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1034 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1035 if (plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1036 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1037 octave_child_list::remove (plot_stream->pid ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1038
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1039 delete_plot_stream ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1040 }
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 plot_line_count = 0;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1045 bool
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1046 gnuplot::plot_stream_event_handler (pid_t pid, int status)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1047 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1048 bool retval = false;
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 (pid > 0)
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 if (WIFEXITED (status) || WIFSIGNALLED (status))
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 gnuplot *plotter = gnuplot::lookup_by_pid (pid);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1055
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1056 // 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
1057 // process from the child list if the process died
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1058 // unexpectedly. If do_close is responsible for
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1059 // 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
1060 // need to do anything.
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 if (plotter)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1063 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1064 plotter->reset_plot_stream ();
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 warning ("connection to external plotter (pid = %d) lost --", pid);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1067 // Request removal of this PID from the list of child
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1068 // processes.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1069
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1070 retval = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1071 }
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 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1074
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1075 return retval;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1078 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1079 gnuplot::do_send (const std::string& cmd)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1080 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1081 int replot_len = Vgnuplot_command_replot.length ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1082
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1083 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
1084
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1085 if (! (plot_line_count == 0 && is_replot))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1086 do_send_raw (cmd);
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1089 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1090 gnuplot::do_send_raw (const std::string& cmd)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1091 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1092 if (plot_stream && *plot_stream)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1093 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1094 *plot_stream << cmd;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1095
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1096 plot_stream->flush ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1097 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1098 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1099
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1100 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1101 gnuplot::do_clear (void)
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 do_send_raw ("clear\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1104
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1105 // FIXME -- instead of just clearing these things, it would
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1106 // 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
1107 // state.
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 do_send_raw ("set title\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1110 do_send_raw ("set xlabel\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1111 do_send_raw ("set ylabel\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1112 do_send_raw ("set nogrid\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1113 do_send_raw ("set nolabel\n");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1114
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1115 // 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
1116 // has been issued.
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 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1119 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1120
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1121 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1122 gnuplot::do_set (const string_vector& argv)
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 int argc = argv.length ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1125
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1126 std::ostringstream plot_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1127
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1128 if (argc > 1)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1129 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1130 if (almost_match ("parametric", argv[1], 3))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1131 parametric_plot = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1132 else if (almost_match ("noparametric", argv[1], 5))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1133 parametric_plot = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1134 else if (almost_match ("term", argv[1], 1))
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 gnuplot_terminal_type = "";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1137 std::ostringstream buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1138 int i;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1139 for (i = 2; i < argc-1; i++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1140 buf << argv[i] << " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1141 if (i < argc)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1142 buf << argv[i];
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1143 buf << Vgnuplot_command_end;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1144 gnuplot_terminal_type = buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1145 }
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 int i;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1149 for (i = 0; i < argc-1; i++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1150 plot_buf << argv[i] << " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1151
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1152 if (i < argc)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1153 plot_buf << argv[i];
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 plot_buf << Vgnuplot_command_end;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1156
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1157 do_send_raw (plot_buf.str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1158 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1159
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1160 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1161 gnuplot::do_show (const string_vector& argv)
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 int argc = argv.length ();
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 std::ostringstream plot_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1166
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1167 int i;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1168 for (i = 0; i < argc-1; i++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1169 plot_buf << argv[i] << " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1170 if (i < argc)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1171 plot_buf << argv[i];
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1172
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1173 plot_buf << Vgnuplot_command_end;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1174
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1175 do_send (plot_buf.str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1176 }
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 void
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1179 gnuplot::do_plot (const string_vector& argv)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1180 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1181 std::string s;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1182
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1183 for (int i = 1; i < argv.length (); i++)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1184 s += argv[i] + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1185
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1186 try
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 std::string cmd = makeplot (argv[0], s);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1189
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1190 do_send (cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1191 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1192 catch (gpt_parse_error& e)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1193 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1194 if (e.msg.empty ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1195 error ("could not parse plot command");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1196 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1197 error (e.msg.c_str ());
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 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1200
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1201 // 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
1202
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1203 std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1204 gnuplot::makeplot (std::string caller, std::string args)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1205 throw (gpt_parse_error)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1206 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1207 std::string retval;
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 YY_BUFFER_STATE bstate;
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 bstate = yy_scan_string (args.c_str ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1212 yy_switch_to_buffer (bstate);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1213 std::string outstr;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1214 int ndim = 2;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1215
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1216 if (caller == "replot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1217 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1218 ndim = 1;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1219 outstr += Vgnuplot_command_replot + " ";
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 if (caller == "plot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1222 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1223 ndim = 2;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1224 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1225 outstr += Vgnuplot_command_plot + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1226 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1227 else if (caller == "splot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1228 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1229 ndim = 3;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1230 plot_line_count = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1231 outstr += Vgnuplot_command_splot + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1232 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1233 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1234 throw gpt_parse_error ("unknown plot command");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1235
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1236 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1237 gpt_allow_plotkw = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1238 gpt_parens = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1239 gpt_braces = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1240 gpt_brackets = 0;
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 int tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1243 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1244 if (plottok_or_end_p (tok) && caller != "replot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1245 throw gpt_parse_error ("must have something to plot");
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 while (tok)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1248 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1249 bool title_set = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1250 bool using_set = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1251 bool style_set = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1252 bool axes_set = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1253
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1254 if (tok == START_BRACKET)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1255 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1256 if (caller == "replot")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1257 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
1258
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1259 std::string xrange_start_str = read_until (colonp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1260 std::string xrange_end_str = read_until (endbracketp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1261 outstr += printrange (xrange_start_str, xrange_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 if (tok == START_BRACKET)
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 std::string yrange_start_str = read_until (colonp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1266 std::string yrange_end_str = read_until (endbracketp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1267 outstr += printrange (yrange_start_str, yrange_end_str) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1268 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1269 if (tok == START_BRACKET && caller == "gsplot")
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 zrange_start_str = read_until (colonp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1272 std::string zrange_end_str = read_until (endbracketp, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1273 outstr += printrange (zrange_start_str, zrange_end_str) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1274 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1275 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1276 }
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1279 if (plottok_or_end_p (tok))
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1280 return std::string ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1281 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1282 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1283 std::string file;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1284 plot_line_count++;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1285
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1286 std::string plot_expr_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1287 plot_expr_str += std::string (yytext) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1288 plot_expr_str += read_until (plottok_or_end_p, tok);
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 int status = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1291 octave_value tmp_data = eval_string (plot_expr_str,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1292 true, status);
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 if (status != 0 || ! tmp_data.is_defined ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1295 throw gpt_parse_error ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1296
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1297 std::ostringstream tmp_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1298 tmp_data.print_raw (tmp_buf);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1299
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1300 if (tmp_data.is_string ())
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 file = file_ops::tilde_expand (tmp_data.string_value ());
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1303 // FIXME -- perhaps should check if the file exists?
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1304 outstr += file + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1305 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1306 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1307 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1308 switch (ndim)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1309 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1310 case 2:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1311 file = save_in_tmp_file (tmp_data, ndim);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1312 break;
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 case 3:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1315 file = save_in_tmp_file (tmp_data, ndim,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1316 parametric_plot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1317 break;
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 default:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1320 gripe_2_or_3_dim_plot ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1321 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1322 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1323
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1324 if (file.length () > 0)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1325 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1326 mark_for_deletion (file);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1327 outstr += "'" + file + "' ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1328 }
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 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1331
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1332 std::string title_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1333 std::string using_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1334 std::string style_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1335 std::string axes_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1336
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1337 bool out = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1338 while (tok && ! out)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1339 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1340 switch (tok)
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 COMMA:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1343 out = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1344 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1345
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1346 case TITLE:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1347 if (! title_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1348 title_str += handle_title (tok) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1349 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1350 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
1351 title_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1352 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1353
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1354 case USING:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1355 if (! using_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1356 using_str += handle_using (tok) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1357 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1358 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
1359 using_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1360 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1361
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1362 case WITH:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1363 if (! style_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1364 style_str += handle_style (tok) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1365 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1366 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
1367 style_set = true;
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 case AXES:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1371 if (! axes_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1372 axes_str += handle_axes (tok) + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1373 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1374 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
1375 axes_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1376 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1377
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1378 default:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1379 tok = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1380 break;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1381 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1382 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1383
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1384 if (! title_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1385 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1386 std::ostringstream tmp_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1387 tmp_buf << Vgnuplot_command_title << " \"line "
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1388 << plot_line_count << "\" ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1389 title_str = tmp_buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1390 title_set = true;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1391 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1392
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1393 // Plot parameters have to be output in this order.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1394 if (using_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1395 outstr += using_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1396
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1397 if (axes_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1398 outstr += axes_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1399
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1400 if (title_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1401 outstr += title_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1402
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1403 if (style_set)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1404 outstr += style_str;
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 if (out)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1407 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1408 // Saw comma on while loop.
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1409 outstr += ", ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1410 gpt_quote_is_transpose = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1411 gpt_allow_plotkw = false;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1412 gpt_parens = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1413 gpt_braces = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1414 gpt_brackets = 0;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1415 tok = gptlex ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1416 }
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1419 outstr += Vgnuplot_command_end;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1420
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1421 return outstr;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1422 }
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 // 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
1425 // gnuplot command string.
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 std::string
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1428 gnuplot::handle_title (int& lasttok)
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 int tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1431 std::string retstr = Vgnuplot_command_title + " ";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1432 std::string title_expr_str;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1433
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1434 title_expr_str += read_until (plottok_or_end_p, tok);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1435
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1436 int status;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1437 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
1438
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1439 if (status != 0 || ! tmp_data.is_defined ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1440 throw gpt_parse_error ();
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 std::ostringstream tmp_buf;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1443 if (tmp_data.is_string ())
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 tmp_buf << '"';
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1446 tmp_data.print_raw (tmp_buf);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1447 tmp_buf << '"';
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 else
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1450 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1451 warning ("line title must be a string");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1452 tmp_buf << '"' << "line " << plot_line_count << '"';
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1453 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1454
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1455 retstr += tmp_buf.str ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1456
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1457 lasttok = tok;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1458
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1459 return retstr;
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1462 // The static instance of this class is here so that
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1463 // 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
1464
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1465 class
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1466 gnuplot_X
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1467 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1468 public:
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1469 gnuplot_X (void) { }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1470 ~gnuplot_X (void) { gnuplot::close_all (); }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1471 };
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1472
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1473 static gnuplot_X X;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1474
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1475 // -----------------------
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1476 // User-callable functions
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
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1479 DEFUN_DLD (automatic_replot, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1480 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1481 @deftypefn {Loadable Function} {@var{val} =} automatic_replot ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1482 @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
1483 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
1484 inefficient, especially for large plots, automatic replotting is enabled\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1485 by default for compatibility with Matlab.\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 return SET_INTERNAL_VARIABLE (automatic_replot);
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
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1491 DEFUN_DLD (gnuplot_binary, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1492 "-*- texinfo -*-\n\
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1493 @deftypefn {Loadable Function} {@var{val} =} gnuplot_binary ()\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1494 @deftypefnx {Loadable Function} {@var{old_val} =} gnuplot_binary (@var{new_val})\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1495 Query or set the name of the program invoked by the plot command.\n\
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1496 The default value @code{\"gnuplot\"}. @xref{Installation}.\n\
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1497 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1498 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1499 octave_value retval = SET_INTERNAL_VARIABLE (gnuplot_binary);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1500
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1501 if (! error_state && args.length () == 1)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1502 gnuplot::set_gnuplot_exe (Vgnuplot_binary);
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 return retval;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1505 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1506
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1507 DEFUN_DLD (gnuplot_command_plot, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1508 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1509 @deftypefn {Loadable Function} {@var{val} = } gnuplot_command_plot ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1510 @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
1511 @end deftypefn")
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 return SET_INTERNAL_VARIABLE (gnuplot_command_plot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1514 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1515
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1516 DEFUN_DLD (gnuplot_command_replot, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1517 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1518 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_replot ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1519 @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
1520 @end deftypefn")
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 return SET_INTERNAL_VARIABLE (gnuplot_command_replot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1523 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1524
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1525 DEFUN_DLD (gnuplot_command_splot, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1526 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1527 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_splot ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1528 @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
1529 @end deftypefn")
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 return SET_INTERNAL_VARIABLE (gnuplot_command_splot);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1532 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1533
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1534 DEFUN_DLD (gnuplot_command_using, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1535 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1536 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_using ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1537 @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
1538 @end deftypefn")
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 return SET_INTERNAL_VARIABLE (gnuplot_command_using);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1541 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1542
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1543 DEFUN_DLD (gnuplot_command_with, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1544 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1545 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_with ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1546 @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
1547 @end deftypefn")
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 return SET_INTERNAL_VARIABLE (gnuplot_command_with);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1550 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1551
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1552 DEFUN_DLD (gnuplot_command_axes, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1553 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1554 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_axes ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1555 @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
1556 @end deftypefn")
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 return SET_INTERNAL_VARIABLE (gnuplot_command_axes);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1559 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1560
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1561 DEFUN_DLD (gnuplot_command_title, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1562 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1563 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_title ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1564 @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
1565 @end deftypefn")
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 return SET_INTERNAL_VARIABLE (gnuplot_command_title);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1568 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1569
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1570 DEFUN_DLD (gnuplot_command_end, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1571 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1572 @deftypefn {Loadable Function} {@var{val} =} gnuplot_command_end ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1573 @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
1574 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1575 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1576 return SET_INTERNAL_VARIABLE (gnuplot_command_end);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1577 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1578
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5791
diff changeset
1579 DEFUN_DLD (gnuplot_use_title_option, args, nargout,
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1580 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1581 @deftypefn {Loadable Function} {@var{val} =} gnuplot_use_title_option ()\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1582 @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
1583 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
1584 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
1585 variable is set when Octave starts.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1586 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1587 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1588 return SET_INTERNAL_VARIABLE (gnuplot_use_title_option);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1589 }
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 DEFUN_DLD (clearplot, , ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1592 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1593 @deftypefn {Loadable Function} {} clearplot\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1594 @deftypefnx {Loadable Function} {} clg\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1595 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
1596 @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
1597 @sc{Matlab}.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1598 @end deftypefn")
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 gnuplot::clear ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1601
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1602 octave_value_list args;
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1603
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1604 args(0) = "off";
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1605
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1606 feval ("hold", args);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1607
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1608 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1609 }
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 DEFUN_DLD (closeplot, , ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1612 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1613 @deftypefn {Loadable Function} {} closeplot\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1614 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
1615 this will close the plot window.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1616 @end deftypefn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1617 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1618 gnuplot::close ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1619
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1620 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1621 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1622
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1623 DEFUN_DLD (purge_tmp_files, , ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1624 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1625 @deftypefn {Loadable Function} {} purge_tmp_files\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1626 Delete the temporary files created by the plotting commands.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1627 \n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1628 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
1629 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
1630 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
1631 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
1632 \n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1633 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
1634 files to hold the plot data.\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 gnuplot::cleanup_tmp_files ();
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 return octave_value_list ();
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
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1642 DEFUN_DLD (__gnuplot_raw__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1643 "-*- texinfo -*-\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1644 @deftypefn {Loadable Function} {} __gnuplot_raw__ (@var{string})\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1645 Send @var{string} directly to gnuplot subprocess.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1646 @end deftypefn")
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 if (args.length () == 1 && args(0).is_string ())
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1649 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1650 std::string cmd = args(0).string_value ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1651
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1652 gnuplot::send_raw (cmd);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1653 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1654 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5796
diff changeset
1655 print_usage ();
5790
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 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1658 }
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 DEFUN_DLD (__gnuplot_set__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1661 "-*- texinfo -*-\n\
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
1662 @deffn {Loadable Function} __gnuplot_set__ options\n\
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1663 Set plotting options for gnuplot\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1664 @end deffn")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1665 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1666 string_vector argv = args.make_argv ("set");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1667
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1668 if (! error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1669 gnuplot::set (argv);
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 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1672 }
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 DEFUN_DLD (__gnuplot_show__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1675 "-*- texinfo -*-\n\
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
1676 @deffn {Loadable Function} __gnuplot_show__ options\n\
5790
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1677 Show plotting options.\n\
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1678 @end deffn")
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 ("show");
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::show (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_plot__, 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 ("plot");
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_splot__, 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 ("splot");
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 DEFUN_DLD (__gnuplot_replot__, args, ,
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1711 "Plot with gnuplot.\n")
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1712 {
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1713 string_vector argv = args.make_argv ("replot");
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1714
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1715 if (! error_state)
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1716 gnuplot::plot (argv);
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1717
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1718 return octave_value_list ();
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1719 }
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1720
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1721 /*
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1722 ;;; Local Variables: ***
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1723 ;;; mode: C++ ***
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1724 ;;; End: ***
60659f01c75b [project @ 2006-05-04 18:33:11 by jwe]
jwe
parents:
diff changeset
1725 */