23 #if defined (HAVE_CONFIG_H)
74 bool have_data =
false;
83 if (c ==
'\n' || c ==
'\r')
90 if (c ==
'%' || c ==
'#')
98 if (! have_data && c !=
' ' && c !=
'\t')
105 while (! (have_data || is.eof ()));
114 bool quiet =
false,
bool check_numeric =
false)
116 std::streampos pos = is.tellg ();
118 int file_line_number = 0;
131 size_t beg = buf.find_first_not_of (
", \t");
137 if (beg != std::string::npos && buf[beg] ==
'\r'
138 && beg == buf.length () - 1)
142 beg = std::string::npos;
147 while (beg != std::string::npos)
151 size_t end = buf.find_first_of (
", \t", beg);
153 if (end != std::string::npos)
157 std::istringstream tmp_stream (buf.substr (beg, end-beg));
161 if (tmp_stream.fail ())
164 error (
"load: %s: non-numeric data found near line %d",
165 filename.c_str (), file_line_number);
174 beg = buf.find_first_not_of (
", \t", end);
176 if (beg == std::string::npos
177 || (buf[beg] ==
'\r' && beg == buf.length () - 1))
196 else if (nc == tmp_nc)
201 error (
"load: %s: inconsistent number of columns near line %d",
202 filename.c_str (), file_line_number);
212 if (! quiet && (nr == 0 || nc == 0))
213 error (
"load: file '%s' seems to be empty!",
filename.c_str ());
238 size_t pos = filename.rfind (
'/');
240 if (pos != std::string::npos)
241 varname = filename.substr (pos+1);
245 pos = varname.rfind (
'.');
247 if (pos != std::string::npos)
248 varname = varname.substr (0, pos);
250 size_t len = varname.length ();
251 for (
size_t i = 0;
i < len;
i++)
254 if (! (isalnum (c) || c ==
'_'))
259 varname.insert (0,
"X");
262 error (
"load: unable to convert filename '%s' to valid identifier",
274 if (nr <= 0 || nc <= 0)
275 error (
"load: unable to extract matrix size from file '%s'",
280 if (nr < 1 || nc < 1)
281 is.clear (std::ios::badbit);
289 std::istringstream tmp_stream (buf);
295 d = octave_read_value<double> (tmp_stream);
297 if (! tmp_stream && ! tmp_stream.eof ())
298 error (
"load: failed to read matrix from file '%s'",
313 if (! (c ==
' ' || c ==
'\t' || c ==
','))
315 tmp_stream.putback (c);
320 if (tmp_stream.eof ())
326 if (! is && ! is.eof ())
327 error (
"load: failed to read matrix from file '%s'",
337 if (expected != total_count)
338 error (
"load: expected %d elements, found %d",
339 expected, total_count);
348 int precision,
bool tabs)
353 warning (
"save: omitting imaginary part for ASCII file");
361 catch (
const octave::execution_exception&
e)
370 long old_precision = os.precision ();
372 os.precision (precision);
374 std::ios::fmtflags oflags
375 = os.flags (static_cast<std::ios::fmtflags> (std::ios::scientific));
384 if (j != 0) os <<
'\t';
395 os.precision (old_precision);
398 return (os && success);
409 retval = (nr != 0 && nc != 0);
void octave_write_double(std::ostream &os, double d)
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 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)
octave_idx_type rows(void) const
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
bool save_mat_ascii_data(std::ostream &os, const octave_value &val, int precision, bool tabs)
bool valid_identifier(const char *s)
nd deftypefn *octave_map m
bool is_complex_type(void) const
bool is_keyword(const std::string &s)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Matrix matrix_value(bool frc_str_conv=false) const
static std::string get_mat_data_input_line(std::istream &is)
void warning(const char *fmt,...)
void recover_from_exception(void)
=val(i)}if ode{val(i)}occurs in table i
octave_idx_type cols(void) const
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