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 ());
176 for (
int i = pat_idx;
i < num_pat;
i++)
191 const int magic_len = 10;
192 char magic[magic_len+1];
193 is.read (magic, magic_len);
194 magic[magic_len] =
'\0';
196 if (
strncmp (magic,
"Octave-1-L", magic_len) == 0)
198 else if (
strncmp (magic,
"Octave-1-B", magic_len) == 0)
203 error (
"load: unable to read binary file");
216 error (
"load: unrecognized binary format!");
224 #if defined (HAVE_ZLIB) 230 std::ifstream
file (
fname.c_str (), std::ios::in | std::ios::binary);
232 unsigned char magic[2];
233 if (
file.read (reinterpret_cast<char *> (&magic[0]), 2)
234 && magic[0] == 0x1f && magic[1] == 0x8b)
257 file.seekg (0, std::ios::beg);
259 int32_t mopt, nr, nc,
imag, len;
269 file.seekg (0, std::ios::beg);
276 file.seekg (0, std::ios::beg);
282 file.seekg (0, std::ios::beg);
287 if (name_val.empty () !=
true && type_val.empty () !=
true)
292 file.seekg (0, std::ios::beg);
316 #if defined (HAVE_HDF5) 318 if (H5Fis_hdf5 (
fname.c_str ()) > 0)
322 #if defined (HAVE_ZLIB) 330 std::ifstream
file (
fname.c_str (), std::ios::in | std::ios::binary);
339 #if defined (HAVE_ZLIB) 366 std::ostringstream output_buf;
367 std::list<std::string> symbol_names;
398 #if defined (HAVE_HDF5) 416 if (stream.eof () ||
name.empty ())
421 error (
"load: unable to load variable '%s'",
name.c_str ());
424 warning (
"load: loaded ASCII file '%s' -- ignoring extra args",
438 <<
"type rows cols name\n" 439 <<
"==== ==== ==== ====\n";
443 << std::setw (16) << tc.
type_name ().c_str ()
445 << std::setw (7) << tc.
rows ()
446 << std::setw (7) << tc.
columns ()
447 <<
" " <<
name <<
"\n";
450 symbol_names.push_back (
name);
498 else if (retstruct.
nfields () != 0)
509 size_t dot_pos =
fname.rfind (
'.');
512 if (dot_pos == std::string::npos
513 || (sep_pos != std::string::npos && dot_pos < sep_pos))
531 error (
"load: unable to find file %s", orig_name.c_str ());
676 else if (
argv[
i] ==
"-list" ||
argv[
i] ==
"-l")
680 else if (
argv[
i] ==
"-verbose" ||
argv[
i] ==
"-v")
684 else if (
argv[
i] ==
"-ascii" ||
argv[
i] ==
"-a")
688 else if (
argv[
i] ==
"-binary" ||
argv[
i] ==
"-b")
692 else if (
argv[
i] ==
"-mat-binary" ||
argv[
i] ==
"-mat" ||
argv[
i] ==
"-m" 701 else if (
argv[
i] ==
"-mat4-binary" ||
argv[
i] ==
"-V4" 706 else if (
argv[
i] ==
"-hdf5" ||
argv[
i] ==
"-h")
708 #if defined (HAVE_HDF5) 714 else if (
argv[
i] ==
"-import" ||
argv[
i] ==
"-i")
716 warning (
"load: -import ignored");
718 else if (
argv[
i] ==
"-text" ||
argv[
i] ==
"-t")
744 #if defined (HAVE_HDF5) 746 error (
"load: cannot read HDF5 format from stdin");
761 error (
"load: must specify file format if reading from stdin");
774 #if defined (HAVE_HDF5) 781 if (hdf5_file.file_id < 0)
800 std::ios::openmode
mode = std::ios::in | std::ios::binary;
802 #if defined (HAVE_ZLIB) 841 error (
"load: unable to open input file '%s'",
871 error (
"load: unable to determine file format of '%s'",
888 for (
int i = 0;
i < len;
i++)
938 warning (
"save: unable to save %s in ASCII format",
name.c_str ());
945 #if defined (HAVE_HDF5) 974 if (
val.is_defined ())
1042 #if ! defined (HAVE_ZLIB) 1043 octave_unused_parameter (
use_zlib);
1049 bool do_double =
false;
1050 bool do_tabs =
false;
1052 for (
int i = 0;
i <
argc;
i++)
1054 if (
argv[
i] ==
"-append")
1058 else if (
argv[
i] ==
"-ascii" ||
argv[
i] ==
"-a")
1062 else if (
argv[
i] ==
"-double")
1066 else if (
argv[
i] ==
"-tabs")
1070 else if (
argv[
i] ==
"-text" ||
argv[
i] ==
"-t")
1074 else if (
argv[
i] ==
"-binary" ||
argv[
i] ==
"-b")
1078 else if (
argv[
i] ==
"-hdf5" ||
argv[
i] ==
"-h")
1080 #if defined (HAVE_HDF5) 1086 else if (
argv[
i] ==
"-mat-binary" ||
argv[
i] ==
"-mat" 1088 ||
argv[
i] ==
"-V6")
1092 #if defined (HAVE_ZLIB) 1093 else if (
argv[
i] ==
"-mat7-binary" ||
argv[
i] ==
"-7" 1099 else if (
argv[
i] ==
"-mat4-binary" ||
argv[
i] ==
"-V4" 1104 else if (
argv[
i] ==
"-float-binary" ||
argv[
i] ==
"-f")
1109 else if (
argv[
i] ==
"-float-hdf5")
1111 #if defined (HAVE_HDF5) 1118 #if defined (HAVE_ZLIB) 1119 else if (
argv[
i] ==
"-zip" ||
argv[
i] ==
"-z")
1124 else if (
argv[
i] ==
"-struct")
1128 else if (
argv[
i][0] ==
'-' &&
argv[
i] !=
"-")
1130 error (
"save: Unrecognized option '%s'",
argv[
i].c_str ());
1141 warning (R
"(save: "-double" option only has an effect with "-ascii")"); 1149 warning (R
"(save: "-tabs" option only has an effect with "-ascii")"); 1159 std::istringstream
is (
arg);
1180 ?
"Octave-1-B" :
"Octave-1-L");
1194 char const *versionmagic;
1195 char headertext[128];
1199 const char *matlab_format =
"MATLAB 5.0 MAT-file, written by Octave " 1203 size_t len =
std::min (comment_string.length (),
static_cast<size_t> (124));
1204 memset (headertext,
' ', 124);
1205 memcpy (headertext, comment_string.data (), len);
1215 versionmagic =
"\x01\x00\x4d\x49";
1217 versionmagic =
"\x00\x01\x49\x4d";
1219 memcpy (headertext+124, versionmagic, 4);
1225 #if defined (HAVE_HDF5) 1234 if (! comment_string.empty ())
1236 #if defined (HAVE_HDF5) 1240 H5Gset_comment (hs.
file_id,
"/", comment_string.c_str ());
1244 os << comment_string <<
"\n";
1257 #if defined (HAVE_HDF5) 1265 #if defined (HAVE_HDF5) 1275 if (write_header_info)
1278 if (argv_idx ==
argc)
1282 else if (
argv[argv_idx] ==
"-struct")
1284 if (++argv_idx >=
argc)
1285 error (
"save: missing struct name");
1296 error (
"save: no such variable: '%s'", struct_name.c_str ());
1298 struct_var = scope.
varval (struct_name);
1302 error (
"save: '%s' is not a scalar structure", struct_name.c_str ());
1308 if (argv_idx <
argc)
1310 for (
int i = argv_idx;
i <
argc;
i++)
1315 warning (
"save: no such field '%s.%s'",
1316 struct_name.c_str (),
argv[
i].c_str ());
1325 for (
int i = argv_idx;
i <
argc;
i++)
1330 warning (
"save: no such variable '%s'",
argv[
i].c_str ());
1350 double save_mem_size = 0;
1356 if (
val.is_defined ())
1360 bool global =
var.is_global ();
1362 double val_size =
val.byte_size () / 1024;
1369 save_mem_size += val_size;
1388 message (
nullptr,
"attempting to save variables to '%s'...",
fname);
1401 std::ios::openmode
mode = std::ios::out;
1414 mode |= std::ios::binary;
1418 #if defined (HAVE_HDF5) 1423 if (
file.file_id >= 0)
1430 warning (
"dump_octave_core: unable to open '%s' for writing...",
1438 #if defined (HAVE_ZLIB) 1450 warning (
"dump_octave_core: unable to open '%s' for writing...",
1465 warning (
"dump_octave_core: unable to open '%s' for writing...",
1637 error (
"save: cannot specify both -text and -float-binary");
1645 #if defined (HAVE_HDF5) 1647 error (
"save: cannot write HDF5 format to stdout");
1654 warning (
"save: ignoring -append option for output to stdout");
1660 std::ostringstream output_buf;
1681 std::ios::openmode
mode 1682 = (
append ? (std::ios::app | std::ios::ate) : std::ios::out);
1691 mode |= std::ios::binary;
1693 #if defined (HAVE_HDF5) 1698 error (
"save: appending to HDF5 files is not implemented");
1700 bool write_header_info
1705 if (hdf5_file.file_id == -1)
1718 #if defined (HAVE_ZLIB) 1726 bool write_header_info = !
file.tellp ();
1741 bool write_header_info = !
file.tellp ();
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
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)
symbol_scope top_scope(void)
For example cd octave end example noindent changes the current working directory to file
bool is_global(void) const
static bool Vcrash_dumps_octave_core
std::string read_mat_ascii_data(std::istream &is, const std::string &filename, octave_value &tc)
void assign(const std::string &name, const octave_value &value, bool force_add)
int read_binary_file_header(std::istream &is, bool &swap, octave::mach_info::float_format &flt_fmt, bool quiet)
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)
symbol_scope global_scope(void)
bool is_octave_data_file(const std::string &fname)
OCTINTERP_API void print_usage(void)
std::string dir_sep_chars(void)
static OCTAVE_NORETURN void err_file_open(const std::string &fcn, const std::string &file)
identity matrix If supplied two scalar respectively For allows like xample val
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
symbol_record find_symbol(const std::string &name)
static std::map< std::string, std::string > vars
void err_unrecognized_data_fmt(const char *name)
std::string tilde_expand(const std::string &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)
Macro to define a builtin function.
#define SET_INTERNAL_VARIABLE(NM)
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
void bind_fwd_rep(const std::shared_ptr< symbol_scope_rep > &fwd_scope, const symbol_record &sr)
static std::string Voctave_core_file_options
static bool glob_pattern_p(const std::string &pattern)
octave::mach_info::float_format flt_fmt
bool is_defined(void) const
static llvm::LLVMContext & context
symbol_scope __get_current_scope__(const std::string &who)
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
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
else error("load: unable to determine file format of '%s'", orig_fname.c_str())
bool save_mat_ascii_data(std::ostream &os, const octave_value &val, int precision, bool tabs)
std::list< symbol_record > all_variables(bool defined_only=true, unsigned int exclude=symbol_record::hidden) const
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,...)
symbol_table & __get_symbol_table__(const std::string &who)
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
nd deftypefn *std::string name
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)
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
octave_idx_type numel(const octave_value_list &idx)
std::string name(void) const
int float_format_to_mopt_digit(octave::mach_info::float_format flt_fmt)
std::list< symbol_record > glob(const std::string &pattern, bool vars_only=false) const
symbol_record::context_id current_context(void) const
bool save_hdf5_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
octave_idx_type columns(void) const
bool match(const std::string &str) const
std::shared_ptr< symbol_scope_rep > get_rep(void) const
float_format native_float_format(void)
const_iterator end(void) const
static std::string get_host_name(void)
bool save_mat5_binary_element(std::ostream &os, const octave_value &tc, const std::string &name, bool mark_global, bool mat7_format, bool save_as_floats, bool compressing)
string_vector & append(const std::string &s)
static std::string get_user_name(void)
const_iterator begin(void) const
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)
std::complex< T > trunc(const std::complex< T > &x)
write the output to stdout if nargout otherwise return the output in a character string able ode tem append Append to the destination instead of overwriting tem ascii Save a matrix in a text file without a header or any other information The matrix must be D and only the real part of any complex value is written to the file Numbers are stored in single precision format and separated by spaces Additional options for the and gzip can also be used to convert the files for backward compatibility This option is only available if Octave was built with a link to the zlib libraries end table The list of variables to save may use wildcard patterns containing the following special match all characters except those specified by var
octave_idx_type rows(void) const
static string_vector parse_save_options(const string_vector &argv, load_save_format &format, bool &append, bool &save_as_floats, bool &use_zlib)
OCTAVE_EXPORT octave_value_list at
int read_mat5_binary_file_header(std::istream &is, bool &swap, bool quiet, const std::string &filename)
symbol_scope require_current_scope(const std::string &who)
bool isstruct(void) const
std::string key(const_iterator p) const
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 words_big_endian(void)
#define SET_NONEMPTY_INTERNAL_STRING_VARIABLE(NM)
octave_value varval(const std::string &name) const
static std::string find_file_to_load(const std::string &name, const std::string &orig_name)
static double Voctave_core_file_limit
static void install_loaded_variable(const std::string &name, const octave_value &val, bool global, const std::string &)
Gzipped file input stream class.
octave::mach_info::float_format mopt_digit_to_float_format(int mach)
void warning(const char *fmt,...)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
defaults to zero A value of zero computes the digamma a value the trigamma and so on The digamma function is defined
octave_scalar_map scalar_map_value(void) const
const octave_value & contents(const_iterator p) const
OCTINTERP_API std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file=false)
symbol_scope __require_current_scope__(const std::string &who)
bool is_variable(const std::string &name) const
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)
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
octave::sys::file_stat fs(filename)
ColumnVector imag(const ComplexColumnVector &a)
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.
octave_value varval(context_id context) const
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type nfields(void) const
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)
std::string type_name(void) const
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
bool save_binary_data(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &doc, bool mark_global, bool save_as_floats)
static size_t save_vars(std::ostream &os, const std::string &pattern, load_save_format fmt, bool save_as_floats)
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)
static std::string Vsave_default_options