26#if defined (HAVE_CONFIG_H)
74static int Vsave_precision = 17;
91 if (next_only && ch !=
'%' && ch !=
'#')
97 if (c ==
'%' || c ==
'#')
99 std::ostringstream buf;
101 while (is.get (c) && (c ==
' ' || c ==
'\t' || c ==
'%' || c ==
'#'))
107 while (is.get (c) && isalpha (c))
110 std::string tmp = buf.str ();
111 bool match = (tmp.substr (0,
strlen (keyword)) == keyword);
115 std::ostringstream value;
116 while (is.get (c) && (c ==
' ' || c ==
'\t' || c ==
':'))
120 retval = octave::read_until_newline (is,
false);
126 octave::skip_until_newline (is,
false);
130 int len = retval.length ();
138 if (c ==
' ' || c ==
'\t')
239#define SUBSTRING_COMPARE_EQ(s, pos, n, t) (s.substr (pos, n) == (t))
242load_inline_fcn (std::istream& is,
const std::string& filename)
249 for (
int i = 0; i < nargs; i++)
259 octave::skip_preceeding_newline (is);
268 buf = octave::read_until_newline (is,
true);
273 args(0) = std::string (buf);
275 octave::interpreter& interp = octave::__get_interpreter__ ();
284 error (
"load: trouble reading ascii file '%s'", filename.c_str ());
290 const bool do_name_validation)
298 error (
"load: empty name keyword or no data found in file '%s'",
305 && do_name_validation && ! octave::valid_identifier (name))
306 error (
"load: invalid identifier '%s' found in file '%s'",
307 name.c_str (), filename.c_str ());
314 error (
"load: failed to extract keyword specifying value type");
317 std::size_t pos = tag.rfind (
' ');
319 if (pos != std::string::npos)
323 typ = (global ? tag.substr (7) : tag);
335 tc = load_inline_fcn (is, filename);
343 if (class_nm.empty ())
344 error (
"load: failed to extract keyword specifying classdef class");
346 octave::cdef_class cls = octave::lookup_class (class_nm,
false,
true);
348 if (! cls.ok () || (cls.get_name () != class_nm))
349 error (
"load: no definition for classdef '%s' available",
352 bool skip_constructor = ! cls.get (
"ConstructOnLoad").bool_value ();
357 octave::type_info&
type_info = octave::__get_type_info__ ();
363 error (
"load: trouble reading ascii file '%s'", filename.c_str ());
381 const std::string& name,
bool mark_global,
388 "Saving classdef objects is not supported. "
389 "Attempting to save object as struct.");
396 os <<
"# name: " << name <<
"\n";
400 os <<
"# type: global ";
407 precision = Vsave_precision;
409 long old_precision = os.precision ();
410 os.precision (precision);
420 os.precision (old_precision);
422 return (os && success);
427 const std::string& name)
445 error (
"for now, I can only save real matrices in 3-D format");
447 os <<
"# 3-D data...\n"
448 <<
"# type: matrix\n"
449 <<
"# total rows: " << nr <<
"\n"
450 <<
"# total columns: " << nc <<
"\n";
452 long old_precision = os.precision ();
459 warning (
"ignoring last %" OCTAVE_IDX_TYPE_FORMAT
" columns", extras);
466 os << tmp.
extract (0, i, nr-1, i+2);
478 os << tmp.
extract (0, i, nr-1, i);
484 os.precision (old_precision);
486 return (
static_cast<bool> (os));
491DEFUN (save_precision, args, nargout,
513 "save_precision", -1,
514 std::numeric_limits<int>::max ());
517OCTAVE_END_NAMESPACE(octave)
octave_idx_type rows() const
Matrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
octave_map map_value() const
octave_idx_type length() const
bool is_classdef_object() const
octave_classdef * classdef_object_value(bool silent=false) const
octave_idx_type rows() const
bool save_ascii(std::ostream &os)
bool load_ascii(std::istream &is)
bool is_real_matrix() const
std::string type_name() const
octave_idx_type columns() const
Matrix matrix_value(bool frc_str_conv=false) const
octave_value lookup_type(const std::string &nm)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void error(const char *fmt,...)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count, const bool do_name_validation)
bool save_text_data_for_plotting(std::ostream &os, const octave_value &t, const std::string &name)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
bool save_three_d(std::ostream &os, const octave_value &tc, bool parametric)
#define SUBSTRING_COMPARE_EQ(s, pos, n, t)
T::size_type strlen(const typename T::value_type *str)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)