85 if (next_only && ch !=
'%' && ch !=
'#')
91 if (c ==
'%' || c ==
'#')
93 std::ostringstream buf;
95 while (is.get (c) && (c ==
' ' || c ==
'\t' || c ==
'%' || c ==
'#'))
101 while (is.get (c) && isalpha (c))
104 std::string tmp = buf.str ();
105 bool match = (tmp.compare (0, strlen (keyword), keyword) == 0);
109 std::ostringstream value;
110 while (is.get (c) && (c ==
' ' || c ==
'\t' || c ==
':'))
124 int len = retval.length ();
132 if (c ==
' ' || c ==
'\t')
234 #define SUBSTRING_COMPARE_EQ(s, pos, n, t) (s.substr (pos, n) == t)
247 error (
"load: empty name keyword or no data found in file '%s'",
250 return std::string ();
253 if (! (name ==
".nargin." || name ==
".nargout."
256 error (
"load: bogus identifier '%s' found in file '%s'",
257 name.c_str (), filename.c_str ());
258 return std::string ();
268 size_t pos = tag.rfind (
' ');
270 if (pos != std::string::npos)
274 typ = global ? tag.substr (7) : tag;
286 error (
"load: trouble reading ascii file '%s'", filename.c_str ());
289 error (
"load: failed to extract keyword specifying value type");
293 error (
"load: reading file %s", filename.c_str ());
294 return std::string ();
313 const std::string& name,
bool mark_as_global,
319 os <<
"# name: " << name <<
"\n";
324 os <<
"# type: global " << val.
type_name () <<
"\n";
326 os <<
"# type: " << val.
type_name () <<
"\n";
331 long old_precision = os.precision ();
332 os.precision (precision);
342 os.precision (old_precision);
344 return (os && success);
349 const std::string& name)
370 os <<
"# 3-D data...\n"
371 <<
"# type: matrix\n"
372 <<
"# total rows: " << nr <<
"\n"
373 <<
"# total columns: " << nc <<
"\n";
375 long old_precision = os.precision ();
382 warning (
"ignoring last %d columns", extras);
389 os << tmp.
extract (0, i, nr-1, i+2);
401 os << tmp.
extract (0, i, nr-1, i);
407 os.precision (old_precision);
411 ::error (
"for now, I can only save real matrices in 3-D format");
415 return (os && ! fail);
418 DEFUN (save_precision, args, nargout,
420 @deftypefn {Built-in Function} {@var{val} =} save_precision ()\n\
421 @deftypefnx {Built-in Function} {@var{old_val} =} save_precision (@var{new_val})\n\
422 @deftypefnx {Built-in Function} {} save_precision (@var{new_val}, \"local\")\n\
423 Query or set the internal variable that specifies the number of digits to\n\
424 keep when saving data in text format.\n\
426 When called from inside a function with the @qcode{\"local\"} option, the\n\
427 variable is changed locally for the function and any subroutines it calls.\n\
428 The original variable value is restored when exiting the function.\n\
std::string read_until_newline(std::istream &is, bool keep_newline)
#define SET_INTERNAL_VARIABLE_WITH_LIMITS(NM, MINVAL, MAXVAL)
octave_idx_type rows(void) const
Matrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
void skip_until_newline(std::istream &is, bool keep_newline)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
#define SUBSTRING_COMPARE_EQ(s, pos, n, t)
octave_idx_type rows(void) const
static octave_value lookup_type(const std::string &nm)
octave_idx_type columns(void) const
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
bool save_ascii_data_for_plotting(std::ostream &os, const octave_value &t, const std::string &name)
bool valid_identifier(const char *s)
static int Vsave_precision
bool save_ascii_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_as_global, int precision)
Matrix matrix_value(bool frc_str_conv=false) const
bool save_ascii(std::ostream &os)
void warning(const char *fmt,...)
std::string type_name(void) const
charNDArray max(char d, const charNDArray &m)
bool load_ascii(std::istream &is)
static bool match(const std::string &filename_arg, const std::string &path_elt_arg)
bool save_three_d(std::ostream &os, const octave_value &tc, bool parametric)
bool is_real_matrix(void) const
std::string read_ascii_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)