27 #if defined (HAVE_CONFIG_H)
90 #if defined (HAVE_ZLIB)
116 ", %a %b %d %H:%M:%S %Y %Z <")
128 OCTAVE_NORETURN
static
133 error (
"%s: unable to open input file '%s'", fcn.c_str (), file.c_str ());
134 else if (fcn ==
"save")
135 error (
"%s: unable to open output file '%s'", fcn.c_str (), file.c_str ());
137 error (
"%s: unable to open file '%s'", fcn.c_str (), file.c_str ());
164 for (
int i = pat_idx;
i < num_pat;
i++)
168 if (pattern.
match (name))
179 const int magic_len = 10;
180 char magic[magic_len+1];
181 is.read (magic, magic_len);
182 magic[magic_len] =
'\0';
184 if (
strncmp (magic,
"Octave-1-L", magic_len) == 0)
186 else if (
strncmp (magic,
"Octave-1-B", magic_len) == 0)
191 error (
"load: unable to read binary file");
204 error (
"load: unrecognized binary format!");
212 #if defined (HAVE_ZLIB)
218 std::ifstream
file (fname.c_str (), std::ios::in | std::ios::binary);
221 if (
file.read (reinterpret_cast<char *> (magic), 2) && magic[0] == 0x1f
244 file.seekg (0, std::ios::beg);
246 int32_t mopt, nr, nc,
imag, len;
256 file.seekg (0, std::ios::beg);
263 file.seekg (0, std::ios::beg);
269 file.seekg (0, std::ios::beg);
274 if (name_val.empty () !=
true && type_val.empty () !=
true)
279 file.seekg (0, std::ios::beg);
303 #if defined (HAVE_HDF5)
305 if (H5Fis_hdf5 (fname.c_str ()) > 0)
309 #if defined (HAVE_ZLIB)
317 std::ifstream
file (fname.c_str (), std::ios::in | std::ios::binary);
326 #if defined (HAVE_ZLIB)
329 gzifstream gzfile (fname.c_str (), std::ios::in | std::ios::binary);
353 std::ostringstream output_buf;
354 std::list<std::string> symbol_names;
385 #if defined (HAVE_HDF5)
388 argv, argv_idx, argc);
403 if (stream.eof () || name.empty ())
408 error (
"load: unable to load variable '%s'", name.c_str ());
411 warning (
"load: loaded ASCII file '%s' -- ignoring extra args",
412 orig_fname.c_str ());
425 <<
"type rows cols name\n"
426 <<
"==== ==== ==== ====\n";
430 << std::setw (16) << tc.
type_name ().c_str ()
432 << std::setw (7) << tc.
rows ()
433 << std::setw (7) << tc.
columns ()
434 <<
" " << name <<
"\n";
437 symbol_names.push_back (name);
446 retstruct.
assign (name, tc);
460 if (list_only && count)
485 else if (retstruct.
nfields () != 0)
496 size_t dot_pos = fname.rfind (
".");
499 if (dot_pos == std::string::npos
500 || (sep_pos != std::string::npos && dot_pos < sep_pos))
518 error (
"load: unable to find file %s", orig_name.c_str ());
641 if (argc > 1 && ! argv[1].
empty () && argv[1].
at (0) !=
'-')
643 orig_fname = argv[1];
658 if (argv[i] ==
"-force" || argv[i] ==
"-f")
663 else if (argv[i] ==
"-list" || argv[i] ==
"-l")
667 else if (argv[i] ==
"-verbose" || argv[i] ==
"-v")
671 else if (argv[i] ==
"-ascii" || argv[i] ==
"-a")
675 else if (argv[i] ==
"-binary" || argv[i] ==
"-b")
679 else if (argv[i] ==
"-mat-binary" || argv[i] ==
"-mat" || argv[i] ==
"-m"
680 || argv[i] ==
"-6" || argv[i] ==
"-v6")
684 else if (argv[i] ==
"-7" || argv[i] ==
"-v7")
688 else if (argv[i] ==
"-mat4-binary" || argv[i] ==
"-V4"
689 || argv[i] ==
"-v4" || argv[i] ==
"-4")
693 else if (argv[i] ==
"-hdf5" || argv[i] ==
"-h")
695 #if defined (HAVE_HDF5)
701 else if (argv[i] ==
"-import" || argv[i] ==
"-i")
703 warning (
"load: -import ignored");
705 else if (argv[i] ==
"-text" || argv[i] ==
"-t")
713 if (orig_fname ==
"")
718 orig_fname = argv[
i];
727 if (orig_fname ==
"-")
731 #if defined (HAVE_HDF5)
733 error (
"load: cannot read HDF5 format from stdin");
743 retval =
do_load (std::cin, orig_fname, format, flt_fmt,
744 list_only, swap, verbose, argv, i, argc,
748 error (
"load: must specify file format if reading from stdin");
761 #if defined (HAVE_HDF5)
768 if (hdf5_file.file_id < 0)
771 retval =
do_load (hdf5_file, orig_fname, format,
772 flt_fmt, list_only, swap, verbose,
787 std::ios::openmode
mode = std::ios::in | std::ios::binary;
789 #if defined (HAVE_ZLIB)
817 flt_fmt, list_only, swap, verbose,
825 std::ifstream
file (fname.c_str (),
mode);
828 error (
"load: unable to open input file '%s'",
829 orig_fname.c_str ());
851 flt_fmt, list_only, swap, verbose,
858 error (
"load: unable to determine file format of '%s'",
859 orig_fname.c_str ());
873 int len = pattern.length ();
875 for (
int i = 0; i < len; i++)
924 warning (
"save: unable to save %s in ASCII format", name.c_str ());
931 #if defined (HAVE_HDF5)
965 do_save (os, val, name, help, global, fmt, save_as_floats);
1008 typedef std::list<symbol_table::symbol_record>::const_iterator
1009 const_vars_iterator;
1011 for (const_vars_iterator
p = vars.begin ();
p != vars.end ();
p++)
1013 do_save (os, *
p, fmt, save_as_floats);
1026 #if ! defined (HAVE_ZLIB)
1027 octave_unused_parameter (use_zlib);
1031 int argc = argv.
numel ();
1033 bool do_double =
false;
1034 bool do_tabs =
false;
1036 for (
int i = 0; i <
argc; i++)
1038 if (argv[i] ==
"-append")
1042 else if (argv[i] ==
"-ascii" || argv[i] ==
"-a")
1046 else if (argv[i] ==
"-double")
1050 else if (argv[i] ==
"-tabs")
1054 else if (argv[i] ==
"-text" || argv[i] ==
"-t")
1058 else if (argv[i] ==
"-binary" || argv[i] ==
"-b")
1062 else if (argv[i] ==
"-hdf5" || argv[i] ==
"-h")
1064 #if defined (HAVE_HDF5)
1070 else if (argv[i] ==
"-mat-binary" || argv[i] ==
"-mat"
1071 || argv[i] ==
"-m" || argv[i] ==
"-6" || argv[i] ==
"-v6"
1072 || argv[i] ==
"-V6")
1076 #if defined (HAVE_ZLIB)
1077 else if (argv[i] ==
"-mat7-binary" || argv[i] ==
"-7"
1078 || argv[i] ==
"-v7" || argv[i] ==
"-V7")
1083 else if (argv[i] ==
"-mat4-binary" || argv[i] ==
"-V4"
1084 || argv[i] ==
"-v4" || argv[i] ==
"-4")
1088 else if (argv[i] ==
"-float-binary" || argv[i] ==
"-f")
1091 save_as_floats =
true;
1093 else if (argv[i] ==
"-float-hdf5")
1095 #if defined (HAVE_HDF5)
1097 save_as_floats =
true;
1102 #if defined (HAVE_ZLIB)
1103 else if (argv[i] ==
"-zip" || argv[i] ==
"-z")
1108 else if (argv[i] ==
"-struct")
1112 else if (argv[i][0] ==
'-' && argv[i] !=
"-")
1114 error (
"save: Unrecognized option '%s'", argv[i].c_str ());
1125 warning (
"save: \"-double\" option only has an effect with \"-ascii\"");
1133 warning (
"save: \"-tabs\" option only has an effect with \"-ascii\"");
1143 std::istringstream
is (arg);
1159 switch (format.
type)
1164 ?
"Octave-1-B" :
"Octave-1-L");
1178 char const * versionmagic;
1179 int16_t
number = *(
reinterpret_cast<const int16_t *
>(
"\x00\x01"));
1180 char headertext[128];
1184 const char *matlab_format =
"MATLAB 5.0 MAT-file, written by Octave "
1188 size_t len =
std::min (comment_string.length (),
static_cast<size_t> (124));
1189 memset (headertext,
' ', 124);
1190 memcpy (headertext, comment_string.data (), len);
1200 versionmagic =
"\x01\x00\x4d\x49";
1202 versionmagic =
"\x00\x01\x49\x4d";
1204 memcpy (headertext+124, versionmagic, 4);
1205 os.write (headertext, 128);
1210 #if defined (HAVE_HDF5)
1219 if (! comment_string.empty ())
1221 #if defined (HAVE_HDF5)
1225 H5Gset_comment (hs.
file_id,
"/", comment_string.c_str ());
1229 os << comment_string <<
"\n";
1242 #if defined (HAVE_HDF5)
1250 #if defined (HAVE_HDF5)
1260 if (write_header_info)
1263 if (argv_idx == argc)
1265 save_vars (os,
"*", fmt, save_as_floats);
1267 else if (argv[argv_idx] ==
"-struct")
1269 if (++argv_idx >= argc)
1270 error (
"save: missing struct name");
1275 error (
"save: no such variable: '%s'", struct_name.c_str ());
1279 if (! struct_var.is_map () || struct_var.numel () != 1)
1280 error (
"save: '%s' is not a scalar structure", struct_name.c_str ());
1286 if (argv_idx < argc)
1288 for (
int i = argv_idx; i <
argc; i++)
1290 if (!
save_fields (os, struct_var_map, argv[i], fmt,
1293 warning (
"save: no such field '%s.%s'",
1294 struct_name.c_str (), argv[
i].c_str ());
1299 save_fields (os, struct_var_map,
"*", fmt, save_as_floats);
1303 for (
int i = argv_idx; i <
argc; i++)
1307 if (!
save_vars (os, argv[i], fmt, save_as_floats))
1308 warning (
"save: no such variable '%s'", argv[i].c_str ());
1319 std::list<symbol_table::symbol_record>
vars
1322 double save_mem_size = 0;
1324 typedef std::list<symbol_table::symbol_record>::const_iterator
1325 const_vars_iterator;
1327 for (const_vars_iterator
p = vars.begin ();
p != vars.end ();
p++)
1335 bool global =
p->is_global ();
1337 double val_size = val.
byte_size () / 1024;
1344 save_mem_size += val_size;
1346 do_save (os, val, name, help, global, fmt, save_as_floats);
1351 message (0,
"save to '%s' complete", fname);
1357 if (Vcrash_dumps_octave_core)
1363 message (0,
"attempting to save variables to '%s'...", fname);
1371 bool use_zlib =
false;
1374 save_as_floats, use_zlib);
1376 std::ios::openmode
mode = std::ios::out;
1389 mode |= std::ios::binary;
1393 #if defined (HAVE_HDF5)
1405 warning (
"dump_octave_core: unable to open '%s' for writing...",
1413 #if defined (HAVE_ZLIB)
1425 warning (
"dump_octave_core: unable to open '%s' for writing...",
1431 std::ofstream
file (fname, mode);
1440 warning (
"dump_octave_core: unable to open '%s' for writing...",
1583 bool use_zlib =
false;
1594 int argc = argv.
numel ();
1600 if (save_as_floats && format ==
LS_TEXT)
1601 error (
"save: cannot specify both -text and -float-binary");
1609 #if defined (HAVE_HDF5)
1611 error (
"save: cannot write HDF5 format to stdout");
1618 warning (
"save: ignoring -append option for output to stdout");
1621 save_vars (argv, i, argc, std::cout, format, save_as_floats,
true);
1624 std::ostringstream output_buf;
1625 save_vars (argv, i, argc, output_buf, format, save_as_floats,
true);
1645 std::ios::openmode
mode
1646 = append ? (std::ios::app | std::ios::ate) : std::ios::out;
1655 mode |= std::ios::binary;
1657 #if defined (HAVE_HDF5)
1662 error (
"save: appending to HDF5 files is not implemented");
1664 bool write_header_info
1665 = ! (append && H5Fis_hdf5 (fname.c_str ()) > 0);
1669 if (hdf5_file.file_id == -1)
1672 save_vars (argv, i, argc, hdf5_file, format,
1673 save_as_floats, write_header_info);
1682 #if defined (HAVE_ZLIB)
1690 bool write_header_info = !
file.tellp ();
1693 save_as_floats, write_header_info);
1700 std::ofstream
file (fname.c_str (),
mode);
1705 bool write_header_info = !
file.tellp ();
1708 save_as_floats, write_header_info);
octave_value do_load(std::istream &stream, const std::string &orig_fname, load_save_format format, octave::mach_info::float_format flt_fmt, bool list_only, bool swap, bool verbose, const string_vector &argv, int argv_idx, int argc, int nargout)
static std::string Voctave_core_file_name
static std::string default_save_header_format(void)
static void do_save(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &help, bool global, load_save_format fmt, bool save_as_floats)
octave_idx_type nfields(void) const
For example cd octave end example noindent changes the current working directory to file
static bool Vcrash_dumps_octave_core
std::string read_mat_ascii_data(std::istream &is, const std::string &filename, octave_value &tc)
int read_binary_file_header(std::istream &is, bool &swap, octave::mach_info::float_format &flt_fmt, bool quiet)
octave_idx_type rows(void) const
std::string read_hdf5_data(std::istream &is, const std::string &, bool &global, octave_value &tc, std::string &doc, const string_vector &argv, int argv_idx, int argc)
void octave_prepare_hdf5(void)
bool is_octave_data_file(const std::string &fname)
OCTINTERP_API void print_usage(void)
static OCTAVE_NORETURN void err_file_open(const std::string &fcn, const std::string &file)
octave_idx_type numel(void) const
Number of elements in the array.
static std::string dir_sep_chars(void)
identity matrix If supplied two scalar respectively For allows like xample val
static std::list< symbol_record > all_variables(scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool defined_only=true, unsigned int exclude=symbol_record::hidden)
const octave_value & contents(const_iterator p) const
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
bool is_defined(void) const
void err_unrecognized_data_fmt(const char *name)
bool looks_like_mat_ascii_file(std::istream &is, const std::string &filename)
Gzipped file output stream class.
#define DEFUN(name, args_name, nargout_name, doc)
#define SET_INTERNAL_VARIABLE(NM)
octave_value varval(context_id context=xdefault_context) const
static std::map< std::string, std::string > vars
static std::string Voctave_core_file_options
static bool glob_pattern_p(const std::string &pattern)
bool save_mat5_binary_element(std::ostream &os, const octave_value &tc, const std::string &name, bool mark_as_global, bool mat7_format, bool save_as_floats, bool compressing)
octave::mach_info::float_format flt_fmt
static void clear(const std::string &name)
std::string read_mat5_binary_element(std::istream &is, const std::string &filename, bool swap, bool &global, octave_value &tc)
in this the arguments are accumulated from left to right
static std::string tilde_expand(const std::string &)
static octave_value varval(const std::string &name, scope_id scope=xcurrent_scope, context_id context=xdefault_context)
else error("load: unable to determine file format of '%s'", orig_fname.c_str())
static scope_id top_scope(void)
bool save_mat_ascii_data(std::ostream &os, const octave_value &val, int precision, bool tabs)
int read_mat_file_header(std::istream &is, bool &swap, int32_t &mopt, int32_t &nr, int32_t &nc, int32_t &imag, int32_t &len, int quiet)
void message(const char *name, const char *fmt,...)
octave_idx_type columns(void) const
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are empty
static bool check_gzip_magic(const std::string &fname)
octave_fields::const_iterator const_iterator
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
static size_t save_fields(std::ostream &os, const octave_scalar_map &m, const std::string &pattern, load_save_format fmt, bool save_as_floats)
static bool words_big_endian(void)
const_iterator begin(void) const
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_as_global, int precision)
std::string key(const_iterator p) const
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
int float_format_to_mopt_digit(octave::mach_info::float_format flt_fmt)
bool is_global(void) const
nd deftypefn *octave_map m
static std::string get_host_name(void)
static void global_assign(const std::string &name, const octave_value &value=octave_value())
string_vector & append(const std::string &s)
static std::string get_user_name(void)
std::string read_binary_data(std::istream &is, bool swap, octave::mach_info::float_format fmt, const std::string &filename, bool &global, octave_value &tc, std::string &doc)
const_iterator end(void) const
void close()
Close gzipped file.
bool match(const std::string &str) const
static string_vector parse_save_options(const string_vector &argv, load_save_format &format, bool &append, bool &save_as_floats, bool &use_zlib)
static void assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool force_add=false)
OCTAVE_EXPORT octave_value_list at
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
int read_mat5_binary_file_header(std::istream &is, bool &swap, bool quiet, const std::string &filename)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
#define SET_NONEMPTY_INTERNAL_STRING_VARIABLE(NM)
static double Voctave_core_file_limit
static void install_loaded_variable(const std::string &name, const octave_value &val, bool global, const std::string &)
bool save_hdf5_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
Gzipped file input stream class.
octave::mach_info::float_format mopt_digit_to_float_format(int mach)
static bool is_variable(const std::string &name, scope_id scope=xcurrent_scope)
static float_format native_float_format(void)
void warning(const char *fmt,...)
std::string type_name(void) const
defaults to zero A value of zero computes the digamma a value the trigamma and so on The digamma function is defined
static std::list< symbol_record > glob(const std::string &pattern, scope_id scope=xcurrent_scope)
OCTINTERP_API std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file=false)
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_as_global, bool save_as_floats)
=val(i)}if ode{val(i)}occurs in table i
is longer than or if then or only for unique occurrences of the complete pattern(false).The default is true.If a cell array of strings ar
bool save_mat_binary_data(std::ostream &os, const octave_value &tc, const std::string &name)
void octave_finalize_hdf5(void)
void assign(const std::string &k, const octave_value &val)
std::string read_text_data(std::istream &is, const std::string &filename, bool &global, octave_value &tc, octave_idx_type count)
static void read_mat_binary_data(std::istream &is, double *data, int precision, int len, bool swap, octave::mach_info::float_format flt_fmt)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
octave::sys::file_stat fs(filename)
ColumnVector imag(const ComplexColumnVector &a)
std::string find_file_to_load(const std::string &name, const std::string &orig_name)
void write_header(std::ostream &os, load_save_format format)
OCTAVE_EXPORT octave_value_list error nd deftypefn *const octave_scalar_map err
bool strncmp(const T &str_a, const T &str_b, const typename T::size_type n)
True if the first N characters are the same.
write the output to stdout if nargout is
static load_save_format get_file_format(std::istream &file, const std::string &filename)
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
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
static std::string Vsave_header_format_string
static size_t save_vars(std::ostream &os, const std::string &pattern, load_save_format fmt, bool save_as_floats)
static void mark_global(const std::string &name, scope_id scope=xcurrent_scope)
std::string strftime(const std::string &fmt) const
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
static void dump_octave_core(std::ostream &os, const char *fname, load_save_format fmt, bool save_as_floats)
charNDArray min(char d, const charNDArray &m)
static bool matches_patterns(const string_vector &patterns, int pat_idx, int num_pat, const std::string &name)
size_t byte_size(void) const
static std::string Vsave_default_options
const std::string & name(void) const