23 #if defined (HAVE_CONFIG_H) 68 bool have_data =
false;
77 if (
c ==
'\n' ||
c ==
'\r')
84 if (
c ==
'%' ||
c ==
'#')
92 if (! have_data &&
c !=
' ' &&
c !=
'\t')
99 while (! (have_data ||
is.eof ()));
108 bool quiet =
false,
bool check_numeric =
false)
110 std::streampos pos =
is.tellg ();
112 int file_line_number = 0;
125 size_t beg = buf.find_first_not_of (
", \t");
131 if (beg != std::string::npos && buf[beg] ==
'\r' 132 && beg == buf.length () - 1)
136 beg = std::string::npos;
141 while (beg != std::string::npos)
145 size_t end = buf.find_first_of (
", \t", beg);
147 if (end != std::string::npos)
151 std::istringstream tmp_stream (buf.substr (beg, end-beg));
155 if (tmp_stream.fail ())
158 error (
"load: %s: non-numeric data found near line %d",
159 filename.c_str (), file_line_number);
168 beg = buf.find_first_not_of (
", \t", end);
170 if (beg == std::string::npos
171 || (buf[beg] ==
'\r' && beg == buf.length () - 1))
189 else if (nc == tmp_nc)
194 error (
"load: %s: inconsistent number of columns near line %d",
195 filename.c_str (), file_line_number);
205 if (! quiet && (nr == 0 || nc == 0))
206 error (
"load: file '%s' seems to be empty!",
filename.c_str ());
233 if (pos != std::string::npos)
238 pos = varname.rfind (
'.');
240 if (pos != std::string::npos)
241 varname = varname.substr (0, pos);
243 size_t len = varname.length ();
244 for (
size_t i = 0;
i < len;
i++)
247 if (! (isalnum (
c) ||
c ==
'_'))
252 varname.insert (0,
"X");
255 error (
"load: unable to convert filename '%s' to valid identifier",
267 if (nr <= 0 || nc <= 0)
268 error (
"load: unable to extract matrix size from file '%s'",
273 if (nr < 1 || nc < 1)
274 is.clear (std::ios::badbit);
282 std::istringstream tmp_stream (buf);
288 d = octave_read_value<double> (tmp_stream);
290 if (! tmp_stream && ! tmp_stream.eof ())
291 error (
"load: failed to read matrix from file '%s'",
306 if (! (
c ==
' ' ||
c ==
'\t' ||
c ==
','))
308 tmp_stream.putback (
c);
313 if (tmp_stream.eof ())
319 if (!
is && !
is.eof ())
320 error (
"load: failed to read matrix from file '%s'",
330 if (expected != total_count)
331 error (
"load: expected %d elements, found %d",
332 expected, total_count);
341 int precision,
bool tabs)
345 if (
val.iscomplex ())
346 warning (
"save: omitting imaginary part for ASCII file");
348 if (
val.ndims () > 2)
350 warning (
"save: skipping variable which is not a 2-D matrix");
358 m =
val.matrix_value (
true);
360 catch (
const octave::execution_exception&
e)
369 long old_precision =
os.precision ();
371 os.precision (precision);
373 std::ios::fmtflags oflags
374 =
os.flags (static_cast<std::ios::fmtflags> (std::ios::scientific));
383 if (j != 0)
os <<
'\t';
394 os.precision (old_precision);
397 return (
os && success);
408 retval = (nr != 0 && nc != 0);
void octave_write_double(std::ostream &os, double d)
octave_idx_type rows(void) const
double octave_read_double(std::istream &is)
std::string read_mat_ascii_data(std::istream &is, const std::string &filename, octave_value &tc)
static void recover_from_exception(void)
static void get_lines_and_columns(std::istream &is, octave_idx_type &nr, octave_idx_type &nc, const std::string &filename="", bool quiet=false, bool check_numeric=false)
identity matrix If supplied two scalar respectively For allows like xample val
void skip_until_newline(std::istream &is, bool keep_newline)
bool looks_like_mat_ascii_file(std::istream &is, const std::string &filename)
void error(const char *fmt,...)
void skip_preceeding_newline(std::istream &is)
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
octave_idx_type cols(void) const
bool save_mat_ascii_data(std::ostream &os, const octave_value &val, int precision, bool tabs)
bool valid_identifier(const char *s)
bool is_keyword(const std::string &s)
static std::string get_mat_data_input_line(std::istream &is)
void warning(const char *fmt,...)
write the output to stdout if nargout is
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string