GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
load-save.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1994-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cstring>
31 
32 #include <fstream>
33 #include <iomanip>
34 #include <iostream>
35 #include <list>
36 #include <sstream>
37 #include <string>
38 
39 #include "byte-swap.h"
40 #include "dMatrix.h"
41 #include "data-conv.h"
42 #include "file-ops.h"
43 #include "file-stat.h"
44 #include "glob-match.h"
45 #include "lo-mappers.h"
46 #include "mach-info.h"
47 #include "oct-env.h"
48 #include "oct-locbuf.h"
49 #include "oct-time.h"
50 #include "quit.h"
51 #include "str-vec.h"
52 #include "strftime-wrapper.h"
53 
54 #include "Cell.h"
55 #include "defun.h"
56 #include "error.h"
57 #include "errwarn.h"
58 #include "interpreter.h"
59 #include "interpreter-private.h"
60 #include "load-path.h"
61 #include "load-save.h"
62 #include "oct-hdf5.h"
63 #include "ovl.h"
64 #include "oct-map.h"
65 #include "ov-cell.h"
66 #include "pager.h"
67 #include "syminfo.h"
68 #include "sysdep.h"
69 #include "unwind-prot.h"
70 #include "utils.h"
71 #include "variables.h"
72 #include "version.h"
73 
74 #include "ls-hdf5.h"
75 #include "ls-mat-ascii.h"
76 #include "ls-mat4.h"
77 #include "ls-mat5.h"
78 #include "ls-oct-text.h"
79 #include "ls-oct-binary.h"
80 
81 // Remove gnulib definitions, if any.
82 #if defined (close)
83 # undef close
84 #endif
85 #if defined (open)
86 # undef open
87 #endif
88 
89 #if defined (HAVE_ZLIB)
90 # include "gzfstream.h"
91 #endif
92 
94 
95 OCTAVE_NORETURN static
96 void
97 err_file_open (const std::string& fcn, const std::string& file)
98 {
99  if (fcn == "load")
100  error ("%s: unable to open input file '%s'", fcn.c_str (), file.c_str ());
101  else if (fcn == "save")
102  error ("%s: unable to open output file '%s'", fcn.c_str (), file.c_str ());
103  else
104  error ("%s: unable to open file '%s'", fcn.c_str (), file.c_str ());
105 }
106 
107 // Return TRUE if NAME matches one of the given globbing PATTERNS.
108 
109 static bool
110 matches_patterns (const string_vector& patterns, int pat_idx,
111  int num_pat, const std::string& name)
112 {
113  for (int i = pat_idx; i < num_pat; i++)
114  {
115  glob_match pattern (patterns[i]);
116 
117  if (pattern.match (name))
118  return true;
119  }
120 
121  return false;
122 }
123 
124 static int
125 read_binary_file_header (std::istream& is, bool& swap,
126  mach_info::float_format& flt_fmt,
127  bool quiet = false)
128 {
129  const int magic_len = 10;
130  char magic[magic_len+1];
131  is.read (magic, magic_len);
132  magic[magic_len] = '\0';
133 
134  if (strncmp (magic, "Octave-1-L", magic_len) == 0)
135  swap = mach_info::words_big_endian ();
136  else if (strncmp (magic, "Octave-1-B", magic_len) == 0)
137  swap = ! mach_info::words_big_endian ();
138  else
139  {
140  if (! quiet)
141  error ("load: unable to read binary file");
142 
143  return -1;
144  }
145 
146  char tmp = 0;
147  is.read (&tmp, 1);
148 
149  flt_fmt = mopt_digit_to_float_format (tmp);
150 
151  if (flt_fmt == mach_info::flt_fmt_unknown)
152  {
153  if (! quiet)
154  error ("load: unrecognized binary format!");
155 
156  return -1;
157  }
158 
159  return 0;
160 }
161 
162 #if defined (HAVE_ZLIB)
163 static bool
164 check_gzip_magic (const std::string& fname)
165 {
166  bool retval = false;
167 
168  std::ifstream file = sys::ifstream (fname.c_str (),
169  std::ios::in | std::ios::binary);
170 
171  unsigned char magic[2];
172  if (file.read (reinterpret_cast<char *> (&magic[0]), 2)
173  && magic[0] == 0x1f && magic[1] == 0x8b)
174  retval = true;
175 
176  file.close ();
177 
178  return retval;
179 }
180 #endif
181 
182 static std::string
183 find_file_to_load (const std::string& name, const std::string& orig_name)
184 {
185  std::string fname = find_data_file_in_load_path ("load", name, true);
186 
187  std::size_t dot_pos = fname.rfind ('.');
188  std::size_t sep_pos = fname.find_last_of (sys::file_ops::dir_sep_chars ());
189 
190  if (dot_pos == std::string::npos
191  || (sep_pos != std::string::npos && dot_pos < sep_pos))
192  {
193  // Either no '.' in name or no '.' appears after last directory
194  // separator.
195 
196  sys::file_stat fs (fname);
197 
198  if (! (fs.exists () && fs.is_reg ()))
199  fname = find_file_to_load (fname + ".mat", orig_name);
200  }
201  else
202  {
203  sys::file_stat fs (fname);
204 
205  if (! (fs.exists () && fs.is_reg ()))
206  {
207  fname = "";
208 
209  error ("load: unable to find file %s", orig_name.c_str ());
210  }
211  }
212 
213  return fname;
214 }
215 
216 // Return TRUE if PATTERN has any special globbing chars in it.
217 
218 static bool
219 glob_pattern_p (const std::string& pattern)
220 {
221  int open = 0;
222 
223  int len = pattern.length ();
224 
225  for (int i = 0; i < len; i++)
226  {
227  char c = pattern[i];
228 
229  switch (c)
230  {
231  case '?':
232  case '*':
233  return true;
234 
235  case '[': // Only accept an open brace if there is a close
236  open++; // brace to match it. Bracket expressions must be
237  continue; // complete, according to Posix.2
238 
239  case ']':
240  if (open)
241  return true;
242  continue;
243 
244  case '\\':
245  if (i == len - 1)
246  return false;
247  continue;
248 
249  default:
250  continue;
251  }
252  }
253 
254  return false;
255 }
256 
258  : m_interpreter (interp),
259  m_crash_dumps_octave_core (true),
260  m_octave_core_file_limit (-1.0),
261  m_octave_core_file_name ("octave-workspace"),
262  m_save_default_options ("-text"),
263  m_octave_core_file_options ("-binary"),
264  m_save_header_format_string (init_save_header_format ())
265 {
266 #if defined (HAVE_HDF5)
267  H5dont_atexit ();
268 #endif
269 }
270 
272 {
273 #if defined (HAVE_HDF5)
274  H5close ();
275 #endif
276 }
277 
280  int nargout)
281 {
282  return set_internal_variable (m_crash_dumps_octave_core, args, nargout,
283  "crash_dumps_octave_core");
284 }
285 
288  int nargout)
289 {
290  return set_internal_variable (m_octave_core_file_limit, args, nargout,
291  "octave_core_file_limit");
292 }
293 
296  int nargout)
297 {
298  return set_internal_variable (m_octave_core_file_name, args, nargout,
299  "octave_core_file_name", false);
300 }
301 
304  int nargout)
305 {
306  return set_internal_variable (m_save_default_options, args, nargout,
307  "save_default_options", false);
308 }
309 
312  int nargout)
313 {
314  return set_internal_variable (m_octave_core_file_options, args, nargout,
315  "octave_core_file_options", false);
316 }
317 
320  int nargout)
321 {
322  return set_internal_variable (m_save_header_format_string, args, nargout,
323  "save_header_format_string");
324 }
325 
327 load_save_system::get_file_format (const std::string& fname,
328  const std::string& orig_fname,
329  bool& use_zlib, bool quiet)
330 {
331  load_save_format retval = UNKNOWN;
332 
333 #if defined (HAVE_HDF5_UTF8)
334  std::string ascii_fname = fname;
335 #else
336  std::string ascii_fname = sys::get_ASCII_filename (fname);
337 #endif
338 
339 #if defined (HAVE_HDF5)
340  // check this before we open the file
341  if (H5Fis_hdf5 (ascii_fname.c_str ()) > 0)
342  return HDF5;
343 #endif
344 
345 #if defined (HAVE_ZLIB)
346  use_zlib = check_gzip_magic (fname);
347 #else
348  use_zlib = false;
349 #endif
350 
351  if (! use_zlib)
352  {
353  std::ifstream file = sys::ifstream (fname.c_str (),
354  std::ios::in | std::ios::binary);
355  if (file)
356  {
357  retval = get_file_format (file, orig_fname);
358  file.close ();
359  }
360  else if (! quiet)
361  err_file_open ("load", orig_fname);
362  }
363 #if defined (HAVE_ZLIB)
364  else
365  {
366  gzifstream gzfile (fname.c_str (), std::ios::in | std::ios::binary);
367  if (gzfile)
368  {
369  retval = get_file_format (gzfile, orig_fname);
370  gzfile.close ();
371  }
372  else if (! quiet)
373  err_file_open ("load", orig_fname);
374  }
375 #endif
376 
377  return retval;
378 }
379 
382  const std::string& orig_fname,
383  const load_save_format& fmt,
384  mach_info::float_format flt_fmt,
385  bool list_only, bool swap, bool verbose,
386  const string_vector& argv, int argv_idx,
387  int argc, int nargout)
388 {
389  octave_value retval;
390 
391  octave_scalar_map retstruct;
392 
393  std::ostringstream output_buf;
394  std::list<std::string> symbol_names;
395 
396  octave_idx_type count = 0;
397 
398  for (;;)
399  {
400  bool global = false;
401  octave_value tc;
402 
403  std::string name;
404  std::string doc;
405 
406  switch (fmt.type ())
407  {
408  case TEXT:
409  name = read_text_data (stream, orig_fname, global, tc, count);
410  break;
411 
412  case BINARY:
413  name = read_binary_data (stream, swap, flt_fmt, orig_fname,
414  global, tc, doc);
415  break;
416 
417  case MAT_ASCII:
418  name = read_mat_ascii_data (stream, orig_fname, tc);
419  break;
420 
421  case MAT_BINARY:
422  name = read_mat_binary_data (stream, orig_fname, tc);
423  break;
424 
425 #if defined (HAVE_HDF5)
426  case HDF5:
427  name = read_hdf5_data (stream, orig_fname, global, tc, doc,
428  argv, argv_idx, argc);
429  break;
430 #endif
431 
432  case MAT5_BINARY:
433  case MAT7_BINARY:
434  name = read_mat5_binary_element (stream, orig_fname, swap,
435  global, tc);
436  break;
437 
438  default:
439  err_unrecognized_data_fmt ("load");
440  break;
441  }
442 
443  if (stream.eof () || name.empty ())
444  break;
445  else
446  {
447  if (! tc.is_defined ())
448  error ("load: unable to load variable '%s'", name.c_str ());
449 
450  if (fmt.type () == MAT_ASCII && argv_idx < argc)
451  warning ("load: loaded ASCII file '%s' -- ignoring extra args",
452  orig_fname.c_str ());
453 
454  if (fmt.type () == MAT_ASCII
455  || argv_idx == argc
456  || matches_patterns (argv, argv_idx, argc, name))
457  {
458  count++;
459  if (list_only)
460  {
461  if (verbose)
462  {
463  if (count == 1)
464  output_buf
465  << "type rows cols name\n"
466  << "==== ==== ==== ====\n";
467 
468  output_buf
469  << std::setiosflags (std::ios::left)
470  << std::setw (16) << tc.type_name ().c_str ()
471  << std::setiosflags (std::ios::right)
472  << std::setw (7) << tc.rows ()
473  << std::setw (7) << tc.columns ()
474  << " " << name << "\n";
475  }
476  else
477  symbol_names.push_back (name);
478  }
479  else
480  {
481  if (nargout == 1)
482  {
483  if (fmt.type () == MAT_ASCII)
484  retval = tc;
485  else
486  retstruct.assign (name, tc);
487  }
488  else
489  install_loaded_variable (name, tc, global, doc);
490  }
491  }
492 
493  // Only attempt to read one item from a headless text file.
494 
495  if (fmt.type () == MAT_ASCII)
496  break;
497  }
498  }
499 
500  if (list_only && count)
501  {
502  if (verbose)
503  {
504  std::string msg = output_buf.str ();
505 
506  if (nargout > 0)
507  retval = msg;
508  else
509  octave_stdout << msg;
510  }
511  else
512  {
513  if (nargout > 0)
514  retval = Cell (string_vector (symbol_names));
515  else
516  {
517  string_vector names (symbol_names);
518 
520 
521  octave_stdout << "\n";
522  }
523  }
524  }
525  else if (retstruct.nfields () != 0)
526  retval = retstruct;
527 
528  return retval;
529 }
530 
533  load_save_format& fmt, bool& append,
534  bool& save_as_floats, bool& use_zlib)
535 {
536 #if ! defined (HAVE_ZLIB)
537  octave_unused_parameter (use_zlib);
538 #endif
539 
540  string_vector retval;
541  int argc = argv.numel ();
542 
543  bool do_double = false;
544  bool do_tabs = false;
545 
546  for (int i = 0; i < argc; i++)
547  {
548  if (argv[i] == "-append")
549  {
550  append = true;
551  }
552  else if (argv[i] == "-ascii" || argv[i] == "-a")
553  {
554  fmt.set_type (MAT_ASCII);
555  }
556  else if (argv[i] == "-double")
557  {
558  do_double = true;
559  }
560  else if (argv[i] == "-tabs")
561  {
562  do_tabs = true;
563  }
564  else if (argv[i] == "-text" || argv[i] == "-t")
565  {
566  fmt.set_type (TEXT);
567  }
568  else if (argv[i] == "-binary" || argv[i] == "-b")
569  {
570  fmt.set_type (BINARY);
571  }
572  else if (argv[i] == "-hdf5" || argv[i] == "-h")
573  {
574 #if defined (HAVE_HDF5)
575  fmt.set_type (HDF5);
576 #else
577  err_disabled_feature ("save", "HDF5");
578 #endif
579  }
580  else if (argv[i] == "-v7.3" || argv[i] == "-V7.3" || argv[i] == "-7.3")
581  {
582  error ("save: Matlab file format -v7.3 is not yet implemented");
583  }
584 #if defined (HAVE_ZLIB)
585  else if (argv[i] == "-v7" || argv[i] == "-V7" || argv[i] == "-7"
586  || argv[i] == "-mat7-binary")
587  {
588  fmt.set_type (MAT7_BINARY);
589  }
590 #endif
591  else if (argv[i] == "-mat" || argv[i] == "-m"
592  || argv[i] == "-v6" || argv[i] == "-V6" || argv[i] == "-6"
593  || argv[i] == "-mat-binary")
594  {
595  fmt.set_type (MAT5_BINARY);
596  }
597  else if (argv[i] == "-v4" || argv[i] == "-V4" || argv[i] == "-4"
598  || argv[i] == "-mat4-binary")
599  {
600  fmt.set_type (MAT_BINARY);
601  }
602  else if (argv[i] == "-float-binary" || argv[i] == "-f")
603  {
604  fmt.set_type (BINARY);
605  save_as_floats = true;
606  }
607  else if (argv[i] == "-float-hdf5")
608  {
609 #if defined (HAVE_HDF5)
610  fmt.set_type (HDF5);
611  save_as_floats = true;
612 #else
613  err_disabled_feature ("save", "HDF5");
614 #endif
615  }
616 #if defined (HAVE_ZLIB)
617  else if (argv[i] == "-zip" || argv[i] == "-z")
618  {
619  use_zlib = true;
620  }
621 #endif
622  else if (argv[i] == "-struct")
623  {
624  retval.append (argv[i]);
625  }
626  else if (argv[i][0] == '-' && argv[i] != "-")
627  {
628  error ("save: Unrecognized option '%s'", argv[i].c_str ());
629  }
630  else
631  retval.append (argv[i]);
632  }
633 
634  if (do_double)
635  {
636  if (fmt.type () == MAT_ASCII)
638  else
639  warning (R"(save: "-double" option only has an effect with "-ascii")");
640  }
641 
642  if (do_tabs)
643  {
644  if (fmt.type () == MAT_ASCII)
646  else
647  warning (R"(save: "-tabs" option only has an effect with "-ascii")");
648  }
649 
650  if (append && use_zlib
651  && (fmt.type () != TEXT && fmt.type () != MAT_ASCII))
652  error ("save: -append and -zip options can only be used together with a text format (-text or -ascii)");
653 
654  return retval;
655 }
656 
658 load_save_system::parse_save_options (const std::string& arg,
659  load_save_format& fmt,
660  bool& append, bool& save_as_floats,
661  bool& use_zlib)
662 {
663  std::istringstream is (arg);
664  std::string str;
665  string_vector argv;
666 
667  while (! is.eof ())
668  {
669  is >> str;
670  argv.append (str);
671  }
672 
673  return parse_save_options (argv, fmt, append, save_as_floats, use_zlib);
674 }
675 
676 void load_save_system::save_vars (const string_vector& argv, int argv_idx,
677  int argc, std::ostream& os,
678  const load_save_format& fmt,
679  bool save_as_floats,
680  bool write_header_info)
681 {
682  if (write_header_info)
683  write_header (os, fmt);
684 
685  if (argv_idx == argc)
686  {
687  save_vars (os, "*", fmt, save_as_floats);
688  }
689  else if (argv[argv_idx] == "-struct")
690  {
691  if (++argv_idx >= argc)
692  error ("save: missing struct name");
693 
694  std::string struct_name = argv[argv_idx];
695 
696  if (! m_interpreter.is_variable (struct_name))
697  error ("save: no such variable: '%s'", struct_name.c_str ());
698 
699  octave_value struct_var = m_interpreter.varval (struct_name);
700 
701  if (! struct_var.isstruct () || struct_var.numel () != 1)
702  error ("save: '%s' is not a scalar structure", struct_name.c_str ());
703 
704  octave_scalar_map struct_var_map = struct_var.scalar_map_value ();
705 
706  ++argv_idx;
707 
708  if (argv_idx < argc)
709  {
710  for (int i = argv_idx; i < argc; i++)
711  {
712  if (! save_fields (os, struct_var_map, argv[i], fmt,
713  save_as_floats))
714  {
715  warning ("save: no such field '%s.%s'",
716  struct_name.c_str (), argv[i].c_str ());
717  }
718  }
719  }
720  else
721  save_fields (os, struct_var_map, "*", fmt, save_as_floats);
722  }
723  else
724  {
725  for (int i = argv_idx; i < argc; i++)
726  {
727  if (argv[i] == "")
728  continue; // Skip empty vars for Matlab compatibility
729  if (! save_vars (os, argv[i], fmt, save_as_floats))
730  warning ("save: no such variable '%s'", argv[i].c_str ());
731  }
732  }
733 }
734 
736 {
738  {
739  // FIXME: should choose better filename?
740 
741  const char *fname = m_octave_core_file_name.c_str ();
742 
743  message (nullptr, "attempting to save variables to '%s'...", fname);
744 
745  load_save_format fmt (BINARY);
746 
747  bool save_as_floats = false;
748 
749  bool append = false;
750 
751  bool use_zlib = false;
752 
754  fmt, append, save_as_floats,
755  use_zlib);
756 
757  std::ios::openmode mode = std::ios::out;
758 
759  // Matlab v7 files are always compressed
760  if (fmt.type () == MAT7_BINARY)
761  use_zlib = false;
762 
763  if (fmt.type () == BINARY
764 #if defined (HAVE_HDF5)
765  || fmt.type () == HDF5
766 #endif
767  || fmt.type () == MAT_BINARY
768  || fmt.type () == MAT5_BINARY
769  || fmt.type () == MAT7_BINARY)
770  mode |= std::ios::binary;
771 
772  mode |= append ? std::ios::ate : std::ios::trunc;
773 
774 #if defined (HAVE_HDF5)
775  if (fmt.type () == HDF5)
776  {
777  hdf5_ofstream file (fname, mode);
778 
779  if (file.file_id >= 0)
780  {
781  dump_octave_core (file, fname, fmt, save_as_floats);
782 
783  file.close ();
784  }
785  else
786  warning ("dump_octave_core: unable to open '%s' for writing...",
787  fname);
788  }
789  else
790 #endif
791  // don't insert any commands here! The open brace below must
792  // go with the else above!
793  {
794 #if defined (HAVE_ZLIB)
795  if (use_zlib)
796  {
797  gzofstream file (fname, mode);
798 
799  if (file)
800  {
801  dump_octave_core (file, fname, fmt, save_as_floats);
802 
803  file.close ();
804  }
805  else
806  warning ("dump_octave_core: unable to open '%s' for writing...",
807  fname);
808  }
809  else
810 #endif
811  {
812  std::ofstream file = sys::ofstream (fname, mode);
813 
814  if (file)
815  {
816  dump_octave_core (file, fname, fmt, save_as_floats);
817 
818  file.close ();
819  }
820  else
821  warning ("dump_octave_core: unable to open '%s' for writing...",
822  fname);
823  }
824  }
825  }
826 }
827 
828 void load_save_system::write_header (std::ostream& os,
829  const load_save_format& fmt)
830 {
831  switch (fmt.type ())
832  {
833  case BINARY:
834  {
836  ? "Octave-1-B" : "Octave-1-L");
837 
839 
840  char tmp = static_cast<char> (float_format_to_mopt_digit (flt_fmt));
841 
842  os.write (&tmp, 1);
843  }
844  break;
845 
846  case MAT5_BINARY:
847  case MAT7_BINARY:
848  {
849  char const *versionmagic;
850  char headertext[128];
851  sys::gmtime now;
852 
853  // ISO 8601 format date
854  const char *matlab_format = "MATLAB 5.0 MAT-file, written by Octave "
855  OCTAVE_VERSION ", %Y-%m-%d %T UTC";
856  std::string comment_string = now.strftime (matlab_format);
857 
858  std::size_t len = std::min (comment_string.length (),
859  static_cast<std::size_t> (124));
860  memset (headertext, ' ', 124);
861  memcpy (headertext, comment_string.data (), len);
862 
863  // The first pair of bytes give the version of the MAT file
864  // format. The second pair of bytes form a magic number which
865  // signals a MAT file. MAT file data are always written in
866  // native byte order. The order of the bytes in the second
867  // pair indicates whether the file was written by a big- or
868  // little-endian machine. However, the version number is
869  // written in the *opposite* byte order from everything else!
871  versionmagic = "\x01\x00\x4d\x49"; // this machine is big endian
872  else
873  versionmagic = "\x00\x01\x49\x4d"; // this machine is little endian
874 
875  memcpy (headertext+124, versionmagic, 4);
876  os.write (headertext, 128);
877  }
878 
879  break;
880 
881 #if defined (HAVE_HDF5)
882  case HDF5:
883 #endif
884  case TEXT:
885  {
886  sys::localtime now;
887 
888  std::string comment_string = now.strftime (m_save_header_format_string);
889 
890  if (! comment_string.empty ())
891  {
892 #if defined (HAVE_HDF5)
893  if (fmt.type () == HDF5)
894  {
895  hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os);
896  H5Gset_comment (hs.file_id, "/", comment_string.c_str ());
897  }
898  else
899 #endif
900  os << comment_string << "\n";
901  }
902  }
903  break;
904 
905  default:
906  break;
907  }
908 }
909 
910 // Save variables with names matching PATTERN on stream OS in the
911 // format specified by FMT.
912 
913 std::size_t load_save_system::save_vars (std::ostream& os,
914  const std::string& pattern,
915  const load_save_format& fmt,
916  bool save_as_floats)
917 {
919 
920  symbol_info_list syminfo_list = tw.glob_symbol_info (pattern);
921 
922  std::size_t saved = 0;
923 
924  for (const auto& syminfo : syminfo_list)
925  {
926  do_save (os, syminfo, fmt, save_as_floats);
927 
928  saved++;
929  }
930 
931  return saved;
932 }
933 
934 void load_save_system::do_save (std::ostream& os, const octave_value& tc,
935  const std::string& name,
936  const std::string& help,
937  bool global, const load_save_format& fmt,
938  bool save_as_floats)
939 {
940  switch (fmt.type ())
941  {
942  case TEXT:
943  save_text_data (os, tc, name, global, 0);
944  break;
945 
946  case BINARY:
947  save_binary_data (os, tc, name, help, global, save_as_floats);
948  break;
949 
950  case MAT_ASCII:
951  if (! save_mat_ascii_data (os, tc,
952  fmt.options () & MAT_ASCII_LONG ? 16 : 8,
953  fmt.options () & MAT_ASCII_TABS))
954  warning ("save: unable to save %s in ASCII format", name.c_str ());
955  break;
956 
957  case MAT_BINARY:
958  save_mat_binary_data (os, tc, name);
959  break;
960 
961 #if defined (HAVE_HDF5)
962  case HDF5:
963  save_hdf5_data (os, tc, name, help, global, save_as_floats);
964  break;
965 #endif
966 
967  case MAT5_BINARY:
968  save_mat5_binary_element (os, tc, name, global, false, save_as_floats);
969  break;
970 
971  case MAT7_BINARY:
972  save_mat5_binary_element (os, tc, name, global, true, save_as_floats);
973  break;
974 
975  default:
976  err_unrecognized_data_fmt ("save");
977  break;
978  }
979 }
980 
981 // Save the info from SR on stream OS in the format specified by FMT.
982 
983 void load_save_system::do_save (std::ostream& os,
984  const symbol_info& syminfo,
985  const load_save_format& fmt,
986  bool save_as_floats)
987 {
988  octave_value val = syminfo.value ();
989 
990  if (val.is_defined ())
991  {
992  std::string name = syminfo.name ();
993  std::string help;
994  bool global = syminfo.is_global ();
995 
996  do_save (os, val, name, help, global, fmt, save_as_floats);
997  }
998 }
999 
1000 // save fields of a scalar structure STR matching PATTERN on stream OS
1001 // in the format specified by FMT.
1002 
1003 std::size_t load_save_system::save_fields (std::ostream& os,
1004  const octave_scalar_map& m,
1005  const std::string& pattern,
1006  const load_save_format& fmt,
1007  bool save_as_floats)
1008 {
1009  glob_match pat (pattern);
1010 
1011  std::size_t saved = 0;
1012 
1013  for (auto it = m.begin (); it != m.end (); it++)
1014  {
1015  std::string empty_str;
1016 
1017  if (pat.match (m.key (it)))
1018  {
1019  do_save (os, m.contents (it), m.key (it), empty_str,
1020  0, fmt, save_as_floats);
1021 
1022  saved++;
1023  }
1024  }
1025 
1026  return saved;
1027 }
1028 
1029 void load_save_system::dump_octave_core (std::ostream& os,
1030  const char *fname,
1031  const load_save_format& fmt,
1032  bool save_as_floats)
1033 {
1034  write_header (os, fmt);
1035 
1037 
1038  symbol_info_list syminfo_list = tw.top_scope_symbol_info ();
1039 
1040  double save_mem_size = 0;
1041 
1042  for (const auto& syminfo : syminfo_list)
1043  {
1044  octave_value val = syminfo.value ();
1045 
1046  std::string name = syminfo.name ();
1047  std::string help;
1048  bool global = syminfo.is_global ();
1049 
1050  double val_size = val.byte_size () / 1024;
1051 
1052  // FIXME: maybe we should try to throw out the largest first...
1053 
1054  if (m_octave_core_file_limit < 0
1055  || save_mem_size + val_size < m_octave_core_file_limit)
1056  {
1057  save_mem_size += val_size;
1058 
1059  do_save (os, val, name, help, global, fmt, save_as_floats);
1060  }
1061  }
1062 
1063  message (nullptr, "save to '%s' complete", fname);
1064 }
1065 
1066 // Install a variable with name NAME and the value VAL in the
1067 // symbol table. If GLOBAL is TRUE, make the variable global.
1068 
1069 void load_save_system::install_loaded_variable (const std::string& name,
1070  const octave_value& val,
1071  bool global,
1072  const std::string& /*doc*/)
1073 {
1074  m_interpreter.install_variable (name, val, global);
1075 }
1076 
1078 {
1079  return
1080  (std::string ("# Created by Octave " OCTAVE_VERSION
1081  ", %a %b %d %H:%M:%S %Y %Z <")
1082  + sys::env::get_user_name ()
1083  + '@'
1084  + sys::env::get_host_name ()
1085  + '>');
1086 }
1087 
1090  const std::string& filename)
1091 {
1093 
1094  mach_info::float_format flt_fmt
1096 
1097  bool swap = false;
1098 
1099  if (read_binary_file_header (file, swap, flt_fmt, true) == 0)
1100  retval = BINARY;
1101  else
1102  {
1103  file.clear ();
1104  file.seekg (0, std::ios::beg);
1105 
1106  int32_t mopt, nr, nc, imag, len;
1107 
1108  int err = read_mat_file_header (file, swap, mopt, nr, nc, imag, len,
1109  true);
1110 
1111  if (! err)
1112  retval = MAT_BINARY;
1113  else
1114  {
1115  file.clear ();
1116  file.seekg (0, std::ios::beg);
1117 
1118  err = read_mat5_binary_file_header (file, swap, true, filename);
1119 
1120  if (! err)
1121  {
1122  file.clear ();
1123  file.seekg (0, std::ios::beg);
1124  retval = MAT5_BINARY;
1125  }
1126  else
1127  {
1128  file.clear ();
1129  file.seekg (0, std::ios::beg);
1130 
1131  std::string name_val = extract_keyword (file, "name");
1132  std::string type_val = extract_keyword (file, "type");
1133 
1134  if (name_val.empty () != true && type_val.empty () != true)
1135  retval = TEXT;
1136  else
1137  {
1138  file.clear ();
1139  file.seekg (0, std::ios::beg);
1140 
1141  // FIXME: looks_like_mat_ascii_file does not check
1142  // to see whether the file contains numbers. It
1143  // just skips comments and checks for the same
1144  // number of words on each line. We may need a
1145  // better check here. The best way to do that might
1146  // be just to try to read the file and see if it
1147  // works.
1148 
1149  if (looks_like_mat_ascii_file (file, filename))
1150  retval = MAT_ASCII;
1151  }
1152  }
1153  }
1154  }
1155 
1156  return retval;
1157 }
1158 
1160 load_save_system::load (const octave_value_list& args, int nargout)
1161 {
1162  octave_value_list retval;
1163 
1164  int argc = args.length () + 1;
1165 
1166  string_vector argv = args.make_argv ("load");
1167 
1168  int i = 1;
1169  std::string orig_fname = "";
1170 
1171  // Function called with Matlab-style ["filename", options] syntax
1172  if (argc > 1 && ! argv[1].empty () && argv[1].at (0) != '-')
1173  {
1174  orig_fname = argv[1];
1175  i++;
1176  }
1177 
1178  // It isn't necessary to have the default load format stored in a
1179  // user preference variable since we can determine the type of file
1180  // as we are reading.
1181 
1183 
1184  bool list_only = false;
1185  bool verbose = false;
1186 
1187  for (; i < argc; i++)
1188  {
1189  if (argv[i] == "-text" || argv[i] == "-t")
1190  {
1191  format = TEXT;
1192  }
1193  else if (argv[i] == "-binary" || argv[i] == "-b")
1194  {
1195  format = BINARY;
1196  }
1197  else if (argv[i] == "-hdf5" || argv[i] == "-h")
1198  {
1199 #if defined (HAVE_HDF5)
1200  format = HDF5;
1201 #else
1202  err_disabled_feature ("load", "HDF5");
1203 #endif
1204  }
1205  else if (argv[i] == "-ascii" || argv[i] == "-a")
1206  {
1207  format = MAT_ASCII;
1208  }
1209  else if (argv[i] == "-v7.3" || argv[i] == "-V7.3" || argv[i] == "-7.3")
1210  {
1211  error ("load: Matlab file format -v7.3 is not yet implemented");
1212  }
1213  else if (argv[i] == "-v7" || argv[i] == "-V7" || argv[i] == "-7"
1214  || argv[i] == "-mat7-binary")
1215  {
1216  format = MAT7_BINARY;
1217  }
1218  else if (argv[i] == "-mat" || argv[i] == "-m"
1219  || argv[i] == "-v6" || argv[i] == "-V6" || argv[i] == "-6"
1220  || argv[i] == "-mat-binary")
1221  {
1222  format = MAT5_BINARY;
1223  }
1224  else if (argv[i] == "-v4" || argv[i] == "-V4" || argv[i] == "-4"
1225  || argv[i] == "-mat4-binary")
1226  {
1227  format = MAT_BINARY;
1228  }
1229  else if (argv[i] == "-force" || argv[i] == "-f")
1230  {
1231  // Silently ignore this
1232  // warning ("load: -force ignored");
1233  }
1234  else if (argv[i] == "-import" || argv[i] == "-i")
1235  {
1236  warning ("load: -import ignored");
1237  }
1238  else if (argv[i] == "-list" || argv[i] == "-l")
1239  {
1240  list_only = true;
1241  }
1242  else if (argv[i] == "-verbose" || argv[i] == "-v")
1243  {
1244  verbose = true;
1245  }
1246  else
1247  break;
1248  }
1249 
1250  if (orig_fname == "")
1251  {
1252  if (i == argc)
1253  print_usage ();
1254 
1255  orig_fname = argv[i];
1256  }
1257  else
1258  i--;
1259 
1261 
1262  bool swap = false;
1263 
1264  if (orig_fname == "-")
1265  {
1266  i++;
1267 
1268 #if defined (HAVE_HDF5)
1269  if (format.type () == HDF5)
1270  error ("load: cannot read HDF5 format from stdin");
1271  else
1272 #endif
1273  if (format.type () != UNKNOWN)
1274  {
1275  // FIXME: if we have already seen EOF on a previous call,
1276  // how do we fix up the state of std::cin so that we can get
1277  // additional input? I'm afraid that we can't fix this
1278  // using std::cin only.
1279 
1280  retval = load_vars (std::cin, orig_fname, format, flt_fmt,
1281  list_only, swap, verbose, argv, i,
1282  argc, nargout);
1283  }
1284  else
1285  error ("load: must specify file format if reading from stdin");
1286  }
1287  else
1288  {
1289  std::string fname = sys::file_ops::tilde_expand (orig_fname);
1290 
1291  fname = find_file_to_load (fname, orig_fname);
1292 
1293  bool use_zlib = false;
1294 
1295  if (format.type () == UNKNOWN)
1296  format = get_file_format (fname, orig_fname, use_zlib);
1297 
1298 #if defined (HAVE_HDF5)
1299  if (format.type () == HDF5)
1300  {
1301  i++;
1302 
1303  hdf5_ifstream hdf5_file (fname.c_str ());
1304 
1305  if (hdf5_file.file_id < 0)
1306  err_file_open ("load", orig_fname);
1307 
1308  retval = load_vars (hdf5_file, orig_fname, format, flt_fmt,
1309  list_only, swap, verbose, argv, i,
1310  argc, nargout);
1311 
1312  hdf5_file.close ();
1313  }
1314  else
1315 #endif
1316  // don't insert any statements here; the "else" above has to
1317  // go with the "if" below!!!!!
1318  if (format.type () != UNKNOWN)
1319  {
1320  i++;
1321 
1322  // Always open in binary mode and handle various
1323  // line-endings explicitly.
1324  std::ios::openmode mode = std::ios::in | std::ios::binary;
1325 
1326 #if defined (HAVE_ZLIB)
1327  if (use_zlib)
1328  {
1329  gzifstream file (fname.c_str (), mode);
1330 
1331  if (! file)
1332  err_file_open ("load", orig_fname);
1333 
1334  if (format.type () == BINARY)
1335  {
1336  if (read_binary_file_header (file, swap, flt_fmt) < 0)
1337  {
1338  if (file) file.close ();
1339  return retval;
1340  }
1341  }
1342  else if (format.type () == MAT5_BINARY
1343  || format.type () == MAT7_BINARY)
1344  {
1345  if (read_mat5_binary_file_header (file, swap, false,
1346  orig_fname) < 0)
1347  {
1348  if (file) file.close ();
1349  return retval;
1350  }
1351  }
1352 
1353  retval = load_vars (file, orig_fname, format, flt_fmt,
1354  list_only, swap, verbose, argv, i,
1355  argc, nargout);
1356 
1357  file.close ();
1358  }
1359  else
1360 #endif
1361  {
1362  std::ifstream file = sys::ifstream (fname.c_str (), mode);
1363 
1364  if (! file)
1365  error ("load: unable to open input file '%s'",
1366  orig_fname.c_str ());
1367 
1368  if (format.type () == BINARY)
1369  {
1370  if (read_binary_file_header (file, swap, flt_fmt) < 0)
1371  {
1372  if (file) file.close ();
1373  return retval;
1374  }
1375  }
1376  else if (format.type () == MAT5_BINARY
1377  || format.type () == MAT7_BINARY)
1378  {
1379  if (read_mat5_binary_file_header (file, swap, false,
1380  orig_fname) < 0)
1381  {
1382  if (file) file.close ();
1383  return retval;
1384  }
1385  }
1386 
1387  retval = load_vars (file, orig_fname, format, flt_fmt,
1388  list_only, swap, verbose, argv, i,
1389  argc, nargout);
1390 
1391  file.close ();
1392  }
1393  }
1394  else
1395  error ("load: unable to determine file format of '%s'",
1396  orig_fname.c_str ());
1397 
1398  }
1399 
1400  return retval;
1401 }
1402 
1404 load_save_system::save (const octave_value_list& args, int nargout)
1405 {
1406  // Here is where we would get the default save format if it were
1407  // stored in a user preference variable.
1409  bool save_as_floats = false;
1410  bool append = false;
1411  bool use_zlib = false;
1412 
1413 
1414  // get default options
1416  save_as_floats, use_zlib);
1417 
1418  // override from command line
1419  string_vector argv = args.make_argv ();
1420 
1421  argv = parse_save_options (argv, format, append, save_as_floats, use_zlib);
1422 
1423  int argc = argv.numel ();
1424  int i = 0;
1425 
1426  if (i == argc)
1427  print_usage ();
1428 
1429  if (save_as_floats && format.type () == TEXT)
1430  error ("save: cannot specify both -text and -float-binary");
1431 
1432  octave_value_list retval;
1433 
1434  if (argv[i] == "-")
1435  {
1436  i++;
1437 
1438 #if defined (HAVE_HDF5)
1439  if (format.type () == HDF5)
1440  error ("save: cannot write HDF5 format to stdout");
1441  else
1442 #endif
1443  // don't insert any commands here! the brace below must go
1444  // with the "else" above!
1445  {
1446  if (append)
1447  warning ("save: ignoring -append option for output to stdout");
1448 
1449  if (nargout == 0)
1450  save_vars (argv, i, argc, octave_stdout, format,
1451  save_as_floats, true);
1452  else
1453  {
1454  std::ostringstream output_buf;
1455  save_vars (argv, i, argc, output_buf, format,
1456  save_as_floats, true);
1457  retval = octave_value (output_buf.str());
1458  }
1459  }
1460  }
1461 
1462  // Guard against things like 'save a*', which are probably mistakes...
1463 
1464  else if (i == argc - 1 && glob_pattern_p (argv[i]))
1465  print_usage ();
1466  else
1467  {
1468  std::string fname = sys::file_ops::tilde_expand (argv[i]);
1469 
1470  i++;
1471 
1472  // Matlab v7 files are always compressed
1473  if (format.type () == MAT7_BINARY)
1474  use_zlib = false;
1475 
1476  std::ios::openmode mode
1477  = (append ? (std::ios::app | std::ios::ate) : std::ios::out);
1478 
1479  // Always open in binary mode to save line endings as is.
1480  mode |= std::ios::binary;
1481 
1482 #if defined (HAVE_HDF5)
1483  if (format.type () == HDF5)
1484  {
1485  // FIXME: It should be possible to append to HDF5 files.
1486  if (append)
1487  error ("save: appending to HDF5 files is not implemented");
1488 
1489 # if defined (HAVE_HDF5_UTF8)
1490  bool write_header_info
1491  = ! (append && H5Fis_hdf5 (fname.c_str ()) > 0);
1492 # else
1493  std::string ascii_fname = sys::get_ASCII_filename (fname);
1494 
1495  bool write_header_info
1496  = ! (append && H5Fis_hdf5 (ascii_fname.c_str ()) > 0);
1497 # endif
1498 
1499  hdf5_ofstream hdf5_file (fname.c_str (), mode);
1500 
1501  if (hdf5_file.file_id == -1)
1502  err_file_open ("save", fname);
1503 
1504  save_vars (argv, i, argc, hdf5_file, format, save_as_floats,
1505  write_header_info);
1506 
1507  hdf5_file.close ();
1508  }
1509  else
1510 #endif
1511  // don't insert any statements here! The brace below must go
1512  // with the "else" above!
1513  {
1514 #if defined (HAVE_ZLIB)
1515  if (use_zlib)
1516  {
1517  gzofstream file (fname.c_str (), mode);
1518 
1519  if (! file)
1520  err_file_open ("save", fname);
1521 
1522  bool write_header_info = ! file.tellp ();
1523 
1524  save_vars (argv, i, argc, file, format, save_as_floats,
1525  write_header_info);
1526 
1527  file.close ();
1528  }
1529  else
1530 #endif
1531  {
1532  std::ofstream file = sys::ofstream (fname.c_str (), mode);
1533 
1534  if (! file)
1535  err_file_open ("save", fname);
1536 
1537  bool write_header_info = ! file.tellp ();
1538 
1539  save_vars (argv, i, argc, file, format, save_as_floats,
1540  write_header_info);
1541 
1542  file.close ();
1543  }
1544  }
1545  }
1546 
1547  return retval;
1548 }
1549 
1550 DEFMETHOD (load, interp, args, nargout,
1551  doc: /* -*- texinfo -*-
1552 @deftypefn {} {} load file
1553 @deftypefnx {} {} load options file
1554 @deftypefnx {} {} load options file v1 v2 @dots{}
1555 @deftypefnx {} {S =} load ("options", "file", "v1", "v2", @dots{})
1556 @deftypefnx {} {} load file options
1557 @deftypefnx {} {} load file options v1 v2 @dots{}
1558 @deftypefnx {} {S =} load ("file", "options", "v1", "v2", @dots{})
1559 Load the named variables @var{v1}, @var{v2}, @dots{}, from the file
1560 @var{file}.
1561 
1562 If no variables are specified then all variables found in the
1563 file will be loaded. As with @code{save}, the list of variables to extract
1564 can be full names or use a pattern syntax. The format of the file is
1565 automatically detected but may be overridden by supplying the appropriate
1566 option.
1567 
1568 If load is invoked using the functional form
1569 
1570 @example
1571 load ("-option1", @dots{}, "file", "v1", @dots{})
1572 @end example
1573 
1574 @noindent
1575 then the @var{options}, @var{file}, and variable name arguments
1576 (@var{v1}, @dots{}) must be specified as character strings.
1577 
1578 If a variable that is not marked as global is loaded from a file when a
1579 global symbol with the same name already exists, it is loaded in the
1580 global symbol table. Also, if a variable is marked as global in a file
1581 and a local symbol exists, the local symbol is moved to the global
1582 symbol table and given the value from the file.
1583 
1584 If invoked with a single output argument, Octave returns data instead
1585 of inserting variables in the symbol table. If the data file contains
1586 only numbers (TAB- or space-delimited columns), a matrix of values is
1587 returned. Otherwise, @code{load} returns a structure with members
1588  corresponding to the names of the variables in the file.
1589 
1590 The @code{load} command can read data stored in Octave's text and
1591 binary formats, and @sc{matlab}'s binary format. If compiled with zlib
1592 support, it can also load gzip-compressed files. It will automatically
1593 detect the type of file and do conversion from different floating point
1594 formats (currently only IEEE big and little endian, though other formats
1595 may be added in the future).
1596 
1597 Valid options for @code{load} are listed in the following table.
1598 
1599 @table @code
1600 @item -force
1601 This option is accepted for backward compatibility but is ignored.
1602 Octave now overwrites variables currently in memory with
1603 those of the same name found in the file.
1604 
1605 @item -ascii
1606 Force Octave to assume the file contains columns of numbers in text format
1607 without any header or other information. Data in the file will be loaded
1608 as a single numeric matrix with the name of the variable derived from the
1609 name of the file.
1610 
1611 @item -binary
1612 Force Octave to assume the file is in Octave's binary format.
1613 
1614 @item -hdf5
1615 Force Octave to assume the file is in @sc{hdf5} format.
1616 (@sc{hdf5} is a free, portable binary format developed by the National
1617 Center for Supercomputing Applications at the University of Illinois.)
1618 Note that Octave can only read @sc{hdf5} files that were created by itself with
1619 @code{save}. This format is only available if Octave was built with a link to
1620 the @sc{hdf5} libraries.
1621 
1622 @item -import
1623 This option is accepted for backward compatibility but is ignored.
1624 Octave can now support multi-dimensional HDF data and automatically
1625 modifies variable names if they are invalid Octave identifiers.
1626 
1627 @item -text
1628 Force Octave to assume the file is in Octave's text format.
1629 
1630 @item -v7.3
1631 @itemx -V7.3
1632 @itemx -7.3
1633 Octave does @strong{not} yet implement @sc{matlab}'s v7.3 binary data format.
1634 
1635 @item -v7
1636 @itemx -V7
1637 @itemx -7
1638 @itemx -mat7-binary
1639 Force Octave to assume the file is in @sc{matlab}'s version 7 binary format.
1640 
1641 @item -v6
1642 @itemx -V6
1643 @itemx -6
1644 @itemx -mat
1645 @itemx -mat-binary
1646 Force Octave to assume the file is in @sc{matlab}'s version 6 binary format.
1647 
1648 @item -v4
1649 @itemx -V4
1650 @itemx -4
1651 @itemx -mat4-binary
1652 Force Octave to assume the file is in @sc{matlab}'s version 4 binary format.
1653 
1654 @end table
1655 @seealso{save, dlmwrite, csvwrite, fwrite}
1656 @end deftypefn */)
1657 {
1658  load_save_system& load_save_sys = interp.get_load_save_system ();
1659 
1660  return load_save_sys.load (args, nargout);
1661 }
1662 
1663 DEFMETHOD (save, interp, args, nargout,
1664  doc: /* -*- texinfo -*-
1665 @deftypefn {} {} save file
1666 @deftypefnx {} {} save options file
1667 @deftypefnx {} {} save options file @var{v1} @var{v2} @dots{}
1668 @deftypefnx {} {} save options file -struct @var{STRUCT}
1669 @deftypefnx {} {} save options file -struct @var{STRUCT} @var{f1} @var{f2} @dots{}
1670 @deftypefnx {} {} save - @var{v1} @var{v2} @dots{}
1671 @deftypefnx {} {@var{str} =} save ("-", @qcode{"@var{v1}"}, @qcode{"@var{v2}"}, @dots{})
1672 Save the named variables @var{v1}, @var{v2}, @dots{}, in the file @var{file}.
1673 
1674 The special filename @samp{-} may be used to return the content of the
1675 variables as a string. If no variable names are listed, Octave saves all the
1676 variables in the current scope. Otherwise, full variable names or pattern
1677 syntax can be used to specify the variables to save. If the @option{-struct}
1678 modifier is used then the fields of the @strong{scalar} struct are saved as if
1679 they were variables with the corresponding field names. The @option{-struct}
1680 option can be combined with specific field names @var{f1}, @var{f2}, @dots{} to
1681 write only certain fields to the file.
1682 
1683 Valid options for the @code{save} command are listed in the following table.
1684 Options that modify the output format override the format specified by
1685 @code{save_default_options}.
1686 
1687 If save is invoked using the functional form
1688 
1689 @example
1690 save ("-option1", @dots{}, "file", "v1", @dots{})
1691 @end example
1692 
1693 @noindent
1694 then the @var{options}, @var{file}, and variable name arguments (@var{v1},
1695 @dots{}) must be specified as character strings.
1696 
1697 If called with a filename of @qcode{"-"}, write the output to stdout if nargout
1698 is 0, otherwise return the output in a character string.
1699 
1700 @table @code
1701 @item -append
1702 Append to the destination instead of overwriting.
1703 
1704 @item -ascii
1705 Save a matrix in a text file without a header or any other information. The
1706 matrix must be 2-D and only the real part of any complex value is written to
1707 the file. Numbers are stored in single-precision format and separated by
1708 spaces. Additional options for the @option{-ascii} format are
1709 
1710 @table @code
1711 @item -double
1712 Store numbers in double-precision format.
1713 
1714 @item -tabs
1715 Separate numbers with tabs.
1716 @end table
1717 
1718 @item -binary
1719 Save the data in Octave's binary data format.
1720 
1721 @item -float-binary
1722 Save the data in Octave's binary data format but using only single precision.
1723 Use this format @strong{only} if you know that all the values to be saved can
1724 be represented in single precision.
1725 
1726 @item -hdf5
1727 Save the data in @sc{hdf5} format.
1728 (HDF5 is a free, portable, binary format developed by the National Center for
1729 Supercomputing Applications at the University of Illinois.) This format is only
1730 available if Octave was built with a link to the @sc{hdf5} libraries.
1731 
1732 @item -float-hdf5
1733 Save the data in @sc{hdf5} format but using only single precision. Use this
1734 format @strong{only} if you know that all the values to be saved can be
1735 represented in single precision.
1736 
1737 @item -text
1738 Save the data in Octave's text data format. (default)
1739 
1740 @item -v7.3
1741 @itemx -V7.3
1742 @itemx -7.3
1743 Octave does @strong{not} yet implement @sc{matlab}'s v7.3 binary data format.
1744 
1745 @item -v7
1746 @itemx -V7
1747 @itemx -7
1748 @itemx -mat7-binary
1749 Save the data in @sc{matlab}'s v7 binary data format.
1750 
1751 @item -v6
1752 @itemx -V6
1753 @itemx -6
1754 @itemx -mat
1755 @itemx -mat-binary
1756 Save the data in @sc{matlab}'s v6 binary data format.
1757 
1758 @item -v4
1759 @itemx -V4
1760 @itemx -4
1761 @itemx -mat4-binary
1762 Save the data in @sc{matlab}'s v4 binary data format.
1763 
1764 @item -zip
1765 @itemx -z
1766 Use the gzip algorithm to compress the file. This works on files that are
1767 compressed with gzip outside of Octave, and gzip can also be used to convert
1768 the files for backward compatibility. This option is only available if Octave
1769 was built with a link to the zlib libraries.
1770 @end table
1771 
1772 The list of variables to save may use wildcard patterns (glob patterns)
1773 containing the following special characters:
1774 
1775 @table @code
1776 @item ?
1777 Match any single character.
1778 
1779 @item *
1780 Match zero or more characters.
1781 
1782 @item [ @var{list} ]
1783 Match the list of characters specified by @var{list}. If the first character
1784 is @code{!} or @code{^}, match all characters except those specified by
1785 @var{list}. For example, the pattern @code{[a-zA-Z]} will match all lower and
1786 uppercase alphabetic characters.
1787 
1788 Wildcards may also be used in the field name specifications when using the
1789 @option{-struct} modifier (but not in the struct name itself).
1790 
1791 @end table
1792 
1793 Except when using the @sc{matlab} binary data file format or the @samp{-ascii}
1794 format, saving global variables also saves the global status of the variable.
1795 If the variable is restored at a later time using @samp{load}, it will be
1796 restored as a global variable.
1797 
1798 Example:
1799 
1800 The command
1801 
1802 @example
1803 save -binary data a b*
1804 @end example
1805 
1806 @noindent
1807 saves the variable @samp{a} and all variables beginning with @samp{b} to the
1808 file @file{data} in Octave's binary format.
1809 @seealso{load, save_default_options, save_header_format_string, save_precision,
1810 dlmread, csvread, fread}
1811 @end deftypefn */)
1812 {
1813  load_save_system& load_save_sys = interp.get_load_save_system ();
1814 
1815  return load_save_sys.save (args, nargout);
1816 }
1817 
1818 /*
1819 ## Save and load strings with "-v6"
1820 %!test
1821 %! A = A2 = "foobar"; # normal string
1822 %! B = B2 = "a"; # short string
1823 %! C = C2 = ["foo"; "bar"]; # character matrix
1824 %! D = D2 = "ab".'; # short character matrix
1825 %! E = E2 = {"foo", "bar"}; # cell string
1826 %! F = F2 = {"Saint Barthélemy", "Saint Kitts and Nevis"}; % non-ASCII
1827 %! mat_file = [tempname(), ".mat"];
1828 %! unwind_protect
1829 %! save (mat_file, "A", "B", "C", "D", "E", "F", "-v6");
1830 %! clear ("A", "B", "C", "D", "E", "F");
1831 %! load (mat_file);
1832 %! unwind_protect_cleanup
1833 %! unlink (mat_file);
1834 %! end_unwind_protect
1835 %! assert (A, A2);
1836 %! assert (B, B2);
1837 %! assert (C, C2);
1838 %! assert (D, D2);
1839 %! assert (E, E2);
1840 %! assert (F, F2);
1841 
1842 ## Save and load strings with "-v7"
1843 %!testif HAVE_ZLIB
1844 %! A = A2 = "foobar"; # normal string
1845 %! B = B2 = "a"; # short string
1846 %! C = C2 = ["foo"; "bar"]; # character matrix
1847 %! D = D2 = "ab".'; # short character matrix
1848 %! E = E2 = {"foo", "bar"}; # cell string
1849 %! F = F2 = {"Saint Barthélemy", "Saint Kitts and Nevis"}; # non-ASCII
1850 %! mat_file = [tempname(), ".mat"];
1851 %! unwind_protect
1852 %! save (mat_file, "A", "B", "C", "D", "E", "F", "-v7");
1853 %! clear ("A", "B", "C", "D", "E", "F");
1854 %! load (mat_file);
1855 %! unwind_protect_cleanup
1856 %! unlink (mat_file);
1857 %! end_unwind_protect
1858 %! assert (A, A2);
1859 %! assert (B, B2);
1860 %! assert (C, C2);
1861 %! assert (D, D2);
1862 %! assert (E, E2);
1863 %! assert (F, F2);
1864 
1865 ## Save and load struct with "-v6"
1866 %!test
1867 %! struc.a = "foobar"; # normal string
1868 %! struc.b = "a"; # short string
1869 %! struc.c = ["foo"; "bar"]; # character matrix
1870 %! struc.d = "ab".'; # short character matrix
1871 %! struc.e = {"foo", "bar"}; # cell string
1872 %! struc.f = {"Saint Barthélemy", "Saint Kitts and Nevis"}; # non-ASCII
1873 %! struc.g = [1 2 3]; # double vector
1874 %! struc.h = 1:5; # range
1875 %! struc2 = struc;
1876 %! mat_file = [tempname(), ".mat"];
1877 %! unwind_protect
1878 %! save (mat_file, "struc", "-v6");
1879 %! clear ("struc");
1880 %! load (mat_file);
1881 %! unwind_protect_cleanup
1882 %! unlink (mat_file);
1883 %! end_unwind_protect
1884 %! assert (struc, struc2);
1885 
1886 ## Save and load struct with "-v7"
1887 %!testif HAVE_ZLIB
1888 %! struc.a = "foobar"; # normal string
1889 %! struc.b = "a"; # short string
1890 %! struc.c = ["foo"; "bar"]; # character matrix
1891 %! struc.d = "ab".'; # short character matrix
1892 %! struc.e = {"foo", "bar"}; # cell string
1893 %! struc.f = {"Saint Barthélemy", "Saint Kitts and Nevis"}; # non-ASCII
1894 %! struc.g = [1 2 3]; # double vector
1895 %! struc.h = 1:5; # range
1896 %! struc2 = struc;
1897 %! mat_file = [tempname(), ".mat"];
1898 %! unwind_protect
1899 %! save (mat_file, "struc", "-v7");
1900 %! clear ("struc");
1901 %! load (mat_file);
1902 %! unwind_protect_cleanup
1903 %! unlink (mat_file);
1904 %! end_unwind_protect
1905 %! assert (struc, struc2);
1906 
1907 ## Test input validation
1908 %!testif HAVE_ZLIB <*59225>
1909 %! fname = tempname ();
1910 %! x = 1;
1911 %! fail ('save ("-append", "-zip", "-binary", fname, "x")',
1912 %! "-append and -zip options .* with a text format");
1913 */
1914 
1915 DEFMETHOD (crash_dumps_octave_core, interp, args, nargout,
1916  doc: /* -*- texinfo -*-
1917 @deftypefn {} {@var{val} =} crash_dumps_octave_core ()
1918 @deftypefnx {} {@var{old_val} =} crash_dumps_octave_core (@var{new_val})
1919 @deftypefnx {} {@var{old_val} =} crash_dumps_octave_core (@var{new_val}, "local")
1920 Query or set the internal variable that controls whether Octave tries
1921 to save all current variables to the file @file{octave-workspace} if it
1922 crashes or receives a hangup, terminate or similar signal.
1923 
1924 When called from inside a function with the @qcode{"local"} option, the
1925 variable is changed locally for the function and any subroutines it calls.
1926 The original variable value is restored when exiting the function.
1927 @seealso{octave_core_file_limit, octave_core_file_name,
1928 octave_core_file_options}
1929 @end deftypefn */)
1930 {
1931  load_save_system& load_save_sys = interp.get_load_save_system ();
1932 
1933  return load_save_sys.crash_dumps_octave_core (args, nargout);
1934 }
1935 
1936 DEFMETHOD (save_default_options, interp, args, nargout,
1937  doc: /* -*- texinfo -*-
1938 @deftypefn {} {@var{val} =} save_default_options ()
1939 @deftypefnx {} {@var{old_val} =} save_default_options (@var{new_val})
1940 @deftypefnx {} {@var{old_val} =} save_default_options (@var{new_val}, "local")
1941 Query or set the internal variable that specifies the default options
1942 for the @code{save} command, and defines the default format.
1943 
1944 The default value is @qcode{"-text"} (Octave's own text-based file format).
1945 See the documentation of the @code{save} command for other choices.
1946 
1947 When called from inside a function with the @qcode{"local"} option, the
1948 variable is changed locally for the function and any subroutines it calls.
1949 The original variable value is restored when exiting the function.
1950 @seealso{save, save_header_format_string, save_precision}
1951 @end deftypefn */)
1952 {
1953  load_save_system& load_save_sys = interp.get_load_save_system ();
1954 
1955  return load_save_sys.save_default_options (args, nargout);
1956 }
1957 
1958 DEFMETHOD (octave_core_file_limit, interp, args, nargout,
1959  doc: /* -*- texinfo -*-
1960 @deftypefn {} {@var{val} =} octave_core_file_limit ()
1961 @deftypefnx {} {@var{old_val} =} octave_core_file_limit (@var{new_val})
1962 @deftypefnx {} {@var{old_val} =} octave_core_file_limit (@var{new_val}, "local")
1963 Query or set the internal variable that specifies the maximum amount of memory
1964 that Octave will save when writing a crash dump file.
1965 
1966 The limit is measured in kilobytes and is applied to the top-level workspace.
1967 The name of the crash dump file is specified by
1968 @var{octave_core_file_name}.
1969 
1970 If @var{octave_core_file_options} flags specify a binary format, then
1971 @var{octave_core_file_limit} will be approximately the maximum size of the
1972 file. If a text file format is used, then the file could be much larger than
1973 the limit. The default value is -1 (unlimited).
1974 
1975 When called from inside a function with the @qcode{"local"} option, the
1976 variable is changed locally for the function and any subroutines it calls.
1977 The original variable value is restored when exiting the function.
1978 @seealso{crash_dumps_octave_core, octave_core_file_name,
1979 octave_core_file_options}
1980 @end deftypefn */)
1981 {
1982  load_save_system& load_save_sys = interp.get_load_save_system ();
1983 
1984  return load_save_sys.octave_core_file_limit (args, nargout);
1985 }
1986 
1987 DEFMETHOD (octave_core_file_name, interp, args, nargout,
1988  doc: /* -*- texinfo -*-
1989 @deftypefn {} {@var{val} =} octave_core_file_name ()
1990 @deftypefnx {} {@var{old_val} =} octave_core_file_name (@var{new_val})
1991 @deftypefnx {} {@var{old_val} =} octave_core_file_name (@var{new_val}, "local")
1992 Query or set the internal variable that specifies the name of the file
1993 used for saving data from the top-level workspace if Octave aborts.
1994 
1995 The default value is @qcode{"octave-workspace"}
1996 
1997 When called from inside a function with the @qcode{"local"} option, the
1998 variable is changed locally for the function and any subroutines it calls.
1999 The original variable value is restored when exiting the function.
2000 @seealso{crash_dumps_octave_core, octave_core_file_name,
2001 octave_core_file_options}
2002 @end deftypefn */)
2003 {
2004  load_save_system& load_save_sys = interp.get_load_save_system ();
2005 
2006  return load_save_sys.octave_core_file_name (args, nargout);
2007 }
2008 
2009 DEFMETHOD (octave_core_file_options, interp, args, nargout,
2010  doc: /* -*- texinfo -*-
2011 @deftypefn {} {@var{val} =} octave_core_file_options ()
2012 @deftypefnx {} {@var{old_val} =} octave_core_file_options (@var{new_val})
2013 @deftypefnx {} {@var{old_val} =} octave_core_file_options (@var{new_val}, "local")
2014 Query or set the internal variable that specifies the options used for
2015 saving the workspace data if Octave aborts.
2016 
2017 The value of @code{octave_core_file_options} should follow the same format
2018 as the options for the @code{save} function. The default value is Octave's
2019 binary format.
2020 
2021 When called from inside a function with the @qcode{"local"} option, the
2022 variable is changed locally for the function and any subroutines it calls.
2023 The original variable value is restored when exiting the function.
2024 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_limit}
2025 @end deftypefn */)
2026 {
2027  load_save_system& load_save_sys = interp.get_load_save_system ();
2028 
2029  return load_save_sys.octave_core_file_options (args, nargout);
2030 }
2031 
2032 DEFMETHOD (save_header_format_string, interp, args, nargout,
2033  doc: /* -*- texinfo -*-
2034 @deftypefn {} {@var{val} =} save_header_format_string ()
2035 @deftypefnx {} {@var{old_val} =} save_header_format_string (@var{new_val})
2036 @deftypefnx {} {@var{old_val} =} save_header_format_string (@var{new_val}, "local")
2037 Query or set the internal variable that specifies the format string used for
2038 the comment line written at the beginning of text-format data files saved by
2039 Octave.
2040 
2041 The format string is passed to @code{strftime} and must begin with the
2042 character @samp{#} and contain no newline characters. If the value of
2043 @code{save_header_format_string} is the empty string, the header comment is
2044 omitted from text-format data files. The default value is
2045 @c Set example in small font to prevent overfull line
2046 
2047 @smallexample
2048 "# Created by Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>"
2049 @end smallexample
2050 
2051 When called from inside a function with the @qcode{"local"} option, the
2052 variable is changed locally for the function and any subroutines it calls.
2053 The original variable value is restored when exiting the function.
2054 @seealso{strftime, save_default_options}
2055 @end deftypefn */)
2056 {
2057  load_save_system& load_save_sys = interp.get_load_save_system ();
2058 
2059  return load_save_sys.save_header_format_string (args, nargout);
2060 }
2061 
2063 
2064 // DEPRECATED in Octave 7
2065 
2066 void
2068 {
2069  octave::load_save_system& load_save_sys = octave::__get_load_save_system__ ();
2070 
2071  load_save_sys.dump_octave_core ();
2072 }
OCTAVE_END_NAMESPACE(octave)
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:207
Definition: Cell.h:43
bool match(const std::string &str) const
Definition: glob-match.cc:35
Gzipped file input stream class.
Definition: gzfstream.h:282
void close()
Close gzipped file.
Definition: gzfstream.cc:566
Gzipped file output stream class.
Definition: gzfstream.h:369
void close()
Close gzipped file.
Definition: gzfstream.cc:615
octave_hdf5_id file_id
Definition: ls-hdf5.h:47
OCTINTERP_API void close(void)
Definition: ls-hdf5.cc:103
octave_value varval(const std::string &name) const
void install_variable(const std::string &name, const octave_value &value, bool global)
tree_evaluator & get_evaluator(void)
bool is_variable(const std::string &name) const
load_save_system::format_type type(void) const
Definition: load-save.h:280
void set_option(load_save_system::format_options option)
Definition: load-save.h:282
void set_type(load_save_system::format_type type)
Definition: load-save.h:278
int options(void) const
Definition: load-save.h:287
std::string m_save_header_format_string
Definition: load-save.h:224
OCTINTERP_API octave_value save_header_format_string(const octave_value_list &args, int nargout)
Definition: load-save.cc:319
double m_octave_core_file_limit
Definition: load-save.h:209
std::string save_header_format_string(void) const
Definition: load-save.h:152
OCTINTERP_API octave_value_list save(const octave_value_list &args=octave_value_list(), int nargout=0)
Definition: load-save.cc:1404
std::string m_octave_core_file_name
Definition: load-save.h:212
OCTINTERP_API octave_value octave_core_file_name(const octave_value_list &args, int nargout)
Definition: load-save.cc:295
OCTINTERP_API void save_vars(const string_vector &argv, int argv_idx, int argc, std::ostream &os, const load_save_format &fmt, bool save_as_floats, bool write_header_info)
Definition: load-save.cc:676
OCTINTERP_API ~load_save_system(void)
Definition: load-save.cc:271
interpreter & m_interpreter
Definition: load-save.h:201
OCTINTERP_API octave_value octave_core_file_options(const octave_value_list &args, int nargout)
Definition: load-save.cc:311
OCTINTERP_API std::size_t save_fields(std::ostream &os, const octave_scalar_map &m, const std::string &pattern, const load_save_format &fmt, bool save_as_floats)
Definition: load-save.cc:1003
OCTINTERP_API octave_value save_default_options(const octave_value_list &args, int nargout)
Definition: load-save.cc:303
OCTINTERP_API void write_header(std::ostream &os, const load_save_format &fmt)
Definition: load-save.cc:828
OCTINTERP_API octave_value crash_dumps_octave_core(const octave_value_list &args, int nargout)
Definition: load-save.cc:279
std::string octave_core_file_options(void) const
Definition: load-save.h:139
std::string octave_core_file_name(void) const
Definition: load-save.h:113
OCTINTERP_API octave_value load_vars(std::istream &stream, const std::string &orig_fname, const load_save_format &fmt, mach_info::float_format flt_fmt, bool list_only, bool swap, bool verbose, const string_vector &argv, int argv_idx, int argc, int nargout)
Definition: load-save.cc:381
std::string m_save_default_options
Definition: load-save.h:216
bool crash_dumps_octave_core(void) const
Definition: load-save.h:87
OCTINTERP_API void install_loaded_variable(const std::string &name, const octave_value &val, bool global, const std::string &)
Definition: load-save.cc:1069
OCTINTERP_API octave_value_list load(const octave_value_list &args=octave_value_list(), int nargout=0)
Definition: load-save.cc:1160
static OCTINTERP_API load_save_format get_file_format(const std::string &fname, const std::string &orig_fname, bool &use_zlib, bool quiet=false)
Definition: load-save.cc:327
static OCTINTERP_API std::string init_save_header_format(void)
Definition: load-save.cc:1077
OCTINTERP_API load_save_system(interpreter &interp)
Definition: load-save.cc:257
double octave_core_file_limit(void) const
Definition: load-save.h:100
OCTINTERP_API void do_save(std::ostream &os, const octave_value &tc, const std::string &name, const std::string &help, bool global, const load_save_format &fmt, bool save_as_floats)
Definition: load-save.cc:934
bool m_crash_dumps_octave_core
Definition: load-save.h:205
std::string m_octave_core_file_options
Definition: load-save.h:219
octave_value octave_core_file_limit(const octave_value_list &args, int nargout)
Definition: load-save.cc:287
OCTINTERP_API void dump_octave_core(void)
Definition: load-save.cc:735
std::string save_default_options(void) const
Definition: load-save.h:126
static OCTINTERP_API string_vector parse_save_options(const string_vector &argv, load_save_format &fmt, bool &append, bool &save_as_floats, bool &use_zlib)
Definition: load-save.cc:532
octave_idx_type nfields(void) const
Definition: oct-map.h:218
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:238
octave_idx_type length(void) const
Definition: ovl.h:113
string_vector make_argv(const std::string &="") const
Definition: ovl.cc:227
OCTINTERP_API octave_scalar_map scalar_map_value(void) const
octave_idx_type rows(void) const
Definition: ov.h:590
octave_idx_type numel(void) const
Definition: ov.h:604
bool is_defined(void) const
Definition: ov.h:637
octave_idx_type columns(void) const
Definition: ov.h:592
bool isstruct(void) const
Definition: ov.h:694
std::size_t byte_size(void) const
Definition: ov.h:607
std::string type_name(void) const
Definition: ov.h:1452
OCTINTERP_API bool eof(void) const
Definition: oct-stream.cc:7300
string_vector & append(const std::string &s)
Definition: str-vec.cc:110
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
Definition: str-vec.cc:201
octave_idx_type numel(void) const
Definition: str-vec.h:100
octave_value value(void) const
Definition: syminfo.h:68
bool is_global(void) const
Definition: syminfo.h:76
std::string name(void) const
Definition: syminfo.h:66
symbol_info_list glob_symbol_info(const std::string &pattern) const
Definition: pt-eval.cc:4559
symbol_info_list top_scope_symbol_info(void) const
Definition: pt-eval.cc:4577
ColumnVector imag(const ComplexColumnVector &a)
Definition: dColVector.cc:143
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
Definition: defun-int.h:72
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:111
void warning(const char *fmt,...)
Definition: error.cc:1054
void error(const char *fmt,...)
Definition: error.cc:979
void message(const char *name, const char *fmt,...)
Definition: error.cc:947
void err_unrecognized_data_fmt(const char *name)
Definition: errwarn.cc:134
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
Definition: errwarn.cc:53
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:283
load_save_system & __get_load_save_system__(void)
std::complex< T > trunc(const std::complex< T > &x)
Definition: lo-mappers.h:111
std::string get_ASCII_filename(const std::string &orig_file_name, const bool allow_locale)
Definition: lo-sysdep.cc:605
std::ofstream ofstream(const std::string &filename, const std::ios::openmode mode)
Definition: lo-sysdep.cc:438
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
Definition: lo-sysdep.cc:424
static bool matches_patterns(const string_vector &patterns, int pat_idx, int num_pat, const std::string &name)
Definition: load-save.cc:110
static int read_binary_file_header(std::istream &is, bool &swap, mach_info::float_format &flt_fmt, bool quiet=false)
Definition: load-save.cc:125
static OCTAVE_NORETURN void err_file_open(const std::string &fcn, const std::string &file)
Definition: load-save.cc:97
static std::string find_file_to_load(const std::string &name, const std::string &orig_name)
Definition: load-save.cc:183
static bool glob_pattern_p(const std::string &pattern)
Definition: load-save.cc:219
static bool check_gzip_magic(const std::string &fname)
Definition: load-save.cc:164
void dump_octave_core(void)
Definition: load-save.cc:2067
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)
Definition: ls-hdf5.cc:1501
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)
Definition: ls-hdf5.cc:1079
bool save_mat_ascii_data(std::ostream &os, const octave_value &val, int precision, bool tabs)
std::string read_mat_ascii_data(std::istream &is, const std::string &filename, octave_value &tc)
bool looks_like_mat_ascii_file(std::istream &is, const std::string &filename)
octave::mach_info::float_format mopt_digit_to_float_format(int mach)
Definition: ls-mat4.cc:174
bool save_mat_binary_data(std::ostream &os, const octave_value &tc, const std::string &name)
Definition: ls-mat4.cc:394
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)
Definition: ls-mat4.cc:107
static void read_mat_binary_data(std::istream &is, double *data, int precision, int len, bool swap, octave::mach_info::float_format flt_fmt)
Definition: ls-mat4.cc:71
int float_format_to_mopt_digit(octave::mach_info::float_format flt_fmt)
Definition: ls-mat4.cc:200
int read_mat5_binary_file_header(std::istream &is, bool &swap, bool quiet, const std::string &filename)
Definition: ls-mat5.cc:1533
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)
Definition: ls-mat5.cc:2321
std::string read_mat5_binary_element(std::istream &is, const std::string &filename, bool swap, bool &global, octave_value &tc)
Definition: ls-mat5.cc:478
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)
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)
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)
Definition: ls-oct-text.cc:286
std::string extract_keyword(std::istream &is, const char *keyword, const bool next_only)
Definition: ls-oct-text.cc:84
bool save_text_data(std::ostream &os, const octave_value &val_arg, const std::string &name, bool mark_global, int precision)
Definition: ls-oct-text.cc:361
bool words_big_endian(void)
Definition: mach-info.cc:72
float_format native_float_format(void)
Definition: mach-info.cc:65
float_format
Definition: mach-info.h:38
@ flt_fmt_unknown
Definition: mach-info.h:42
#define OCTAVE_VERSION
Definition: main.in.cc:63
T octave_idx_type m
Definition: mx-inlines.cc:773
OCTAVE_API 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.
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
#define octave_stdout
Definition: pager.h:314
static int left
Definition: randmtzig.cc:194
static std::string dir_sep_chars
Definition: shared-fcns.h:96
std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file)
Definition: utils.cc:703
std::size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1473
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
Definition: variables.cc:584
F77_RET_T len
Definition: xerbla.cc:61