3 Copyright (C) 2003, 2004, 2005, 2006, 2007 John W. Eaton
5 This file is part of Octave.
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
23 #if !defined (octave_ls_oct_ascii_h)
24 #define octave_ls_oct_ascii_h 1
32 #include "ls-ascii-helper.h"
34 // Flag for cell elements
35 #define CELL_ELT_TAG "<cell-element>"
37 // Used when converting Inf to something that gnuplot can read.
40 #define OCT_RBV DBL_MAX / 100.0
43 extern OCTINTERP_API std::string
44 extract_keyword (std::istream& is, const char *keyword,
45 const bool next_only = false);
47 extern OCTINTERP_API std::string
48 read_ascii_data (std::istream& is, const std::string& filename, bool& global,
49 octave_value& tc, octave_idx_type count);
51 extern OCTINTERP_API bool
52 save_ascii_data (std::ostream& os, const octave_value& val_arg,
53 const std::string& name, bool mark_as_global, int precision);
55 extern OCTINTERP_API bool
56 save_ascii_data_for_plotting (std::ostream& os, const octave_value& t,
57 const std::string& name);
59 extern OCTINTERP_API bool
60 save_three_d (std::ostream& os, const octave_value& t,
61 bool parametric = false);
63 // Match KEYWORD on stream IS, placing the associated value in VALUE,
64 // returning TRUE if successful and FALSE otherwise.
66 // Input should look something like:
68 // [%#][ \t]*keyword[ \t]*int-value.*\n
72 extract_keyword (std::istream& is, const char *keyword, T& value,
73 const bool next_only = false)
81 if (c == '%' || c == '#')
83 std::ostringstream buf;
85 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
86 ; // Skip whitespace and comment characters.
91 while (is.get (c) && isalpha (c))
94 std::string tmp = buf.str ();
95 bool match = (tmp.compare (0, strlen (keyword), keyword) == 0);
99 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
100 ; // Skip whitespace and the colon.
103 if (c != '\n' && c != '\r')
107 // Skip to beginning of next line;
108 skip_until_newline (is, false);
118 // Match one of the elements in KEYWORDS on stream IS, placing the
119 // matched keyword in KW and the associated value in VALUE,
120 // returning TRUE if successful and FALSE otherwise.
122 // Input should look something like:
124 // [%#][ \t]*keyword[ \t]*int-value.*\n
128 extract_keyword (std::istream& is, const string_vector& keywords,
129 std::string& kw, T& value, const bool next_only = false)
138 if (c == '%' || c == '#')
140 std::ostringstream buf;
142 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#'))
143 ; // Skip whitespace and comment characters.
148 while (is.get (c) && isalpha (c))
151 std::string tmp = buf.str ();
153 for (int i = 0; i < keywords.length (); i++)
155 int match = (tmp == keywords[i]);
161 while (is.get (c) && (c == ' ' || c == '\t' || c == ':'))
162 ; // Skip whitespace and the colon.
165 if (c != '\n' && c != '\r')
169 // Skip to beginning of next line;
170 skip_until_newline (is, false);
185 ;;; Local Variables: ***