Mercurial > octave-nkf
annotate libinterp/corefcn/load-save.cc @ 17787:175b392e91fe
Use GNU style coding conventions for code in libinterp/
* libinterp/corefcn/Cell.h, libinterp/corefcn/__contourc__.cc,
libinterp/corefcn/__dispatch__.cc, libinterp/corefcn/__lin_interpn__.cc,
libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc,
libinterp/corefcn/balance.cc, libinterp/corefcn/besselj.cc,
libinterp/corefcn/betainc.cc, libinterp/corefcn/bitfcns.cc,
libinterp/corefcn/bsxfun.cc, libinterp/corefcn/c-file-ptr-stream.cc,
libinterp/corefcn/c-file-ptr-stream.h, libinterp/corefcn/cellfun.cc,
libinterp/corefcn/colloc.cc, libinterp/corefcn/comment-list.h,
libinterp/corefcn/conv2.cc, libinterp/corefcn/daspk.cc,
libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc,
libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc,
libinterp/corefcn/defaults.cc, libinterp/corefcn/defaults.in.h,
libinterp/corefcn/defun-int.h, libinterp/corefcn/defun.cc,
libinterp/corefcn/det.cc, libinterp/corefcn/dirfns.cc,
libinterp/corefcn/display.cc, libinterp/corefcn/dlmread.cc,
libinterp/corefcn/dot.cc, libinterp/corefcn/dynamic-ld.cc,
libinterp/corefcn/dynamic-ld.h, libinterp/corefcn/eig.cc,
libinterp/corefcn/ellipj.cc, libinterp/corefcn/error.cc,
libinterp/corefcn/error.h, libinterp/corefcn/event-queue.h,
libinterp/corefcn/fft.cc, libinterp/corefcn/fft2.cc, libinterp/corefcn/fftn.cc,
libinterp/corefcn/file-io.cc, libinterp/corefcn/filter.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc,
libinterp/corefcn/gcd.cc, libinterp/corefcn/getgrent.cc,
libinterp/corefcn/getpwent.cc, libinterp/corefcn/getrusage.cc,
libinterp/corefcn/givens.cc, libinterp/corefcn/gl-render.cc,
libinterp/corefcn/gl2ps-renderer.cc, libinterp/corefcn/gl2ps-renderer.h,
libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h,
libinterp/corefcn/gripes.cc, libinterp/corefcn/gripes.h,
libinterp/corefcn/help.cc, libinterp/corefcn/hess.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/input.h, libinterp/corefcn/inv.cc,
libinterp/corefcn/jit-ir.h, libinterp/corefcn/jit-typeinfo.cc,
libinterp/corefcn/jit-typeinfo.h, libinterp/corefcn/jit-util.h,
libinterp/corefcn/kron.cc, libinterp/corefcn/load-path.cc,
libinterp/corefcn/load-path.h, libinterp/corefcn/load-save.cc,
libinterp/corefcn/load-save.h, libinterp/corefcn/lookup.cc,
libinterp/corefcn/ls-ascii-helper.cc, libinterp/corefcn/ls-hdf5.cc,
libinterp/corefcn/ls-hdf5.h, libinterp/corefcn/ls-mat-ascii.cc,
libinterp/corefcn/ls-mat-ascii.h, libinterp/corefcn/ls-mat4.cc,
libinterp/corefcn/ls-mat5.cc, libinterp/corefcn/ls-mat5.h,
libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lsode.cc,
libinterp/corefcn/lu.cc, libinterp/corefcn/luinc.cc,
libinterp/corefcn/mappers.cc, libinterp/corefcn/matrix_type.cc,
libinterp/corefcn/max.cc, libinterp/corefcn/md5sum.cc,
libinterp/corefcn/mex.cc, libinterp/corefcn/mexproto.h,
libinterp/corefcn/mgorth.cc, libinterp/corefcn/mxarray.in.h,
libinterp/corefcn/nproc.cc, libinterp/corefcn/oct-hist.cc,
libinterp/corefcn/oct-lvalue.h, libinterp/corefcn/oct-map.cc,
libinterp/corefcn/oct-map.h, libinterp/corefcn/oct-obj.h,
libinterp/corefcn/oct-prcstrm.h, libinterp/corefcn/oct-stdstrm.h,
libinterp/corefcn/oct-stream.cc, libinterp/corefcn/oct-stream.h,
libinterp/corefcn/octave-link.cc, libinterp/corefcn/octave-link.h,
libinterp/corefcn/pager.cc, libinterp/corefcn/pinv.cc,
libinterp/corefcn/pr-output.cc, libinterp/corefcn/procstream.h,
libinterp/corefcn/profiler.cc, libinterp/corefcn/pt-jit.cc,
libinterp/corefcn/pt-jit.h, libinterp/corefcn/quad.cc,
libinterp/corefcn/quadcc.cc, libinterp/corefcn/qz.cc,
libinterp/corefcn/rand.cc, libinterp/corefcn/rcond.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc,
libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sighandlers.h,
libinterp/corefcn/sparse-xdiv.cc, libinterp/corefcn/sparse-xdiv.h,
libinterp/corefcn/sparse-xpow.cc, libinterp/corefcn/sparse.cc,
libinterp/corefcn/spparms.cc, libinterp/corefcn/sqrtm.cc,
libinterp/corefcn/str2double.cc, libinterp/corefcn/strfind.cc,
libinterp/corefcn/strfns.cc, libinterp/corefcn/sub2ind.cc,
libinterp/corefcn/svd.cc, libinterp/corefcn/syl.cc,
libinterp/corefcn/symtab.cc, libinterp/corefcn/symtab.h,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/sysdep.cc,
libinterp/corefcn/sysdep.h, libinterp/corefcn/time.cc,
libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h,
libinterp/corefcn/tril.cc, libinterp/corefcn/txt-eng-ft.cc,
libinterp/corefcn/txt-eng-ft.h, libinterp/corefcn/txt-eng.h,
libinterp/corefcn/typecast.cc, libinterp/corefcn/urlwrite.cc,
libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc,
libinterp/corefcn/variables.h, libinterp/corefcn/xdiv.cc,
libinterp/corefcn/xdiv.h, libinterp/corefcn/xnorm.h, libinterp/corefcn/xpow.cc,
libinterp/corefcn/xpow.h, libinterp/corefcn/zfstream.cc,
libinterp/corefcn/zfstream.h, libinterp/dldfcn/__delaunayn__.cc,
libinterp/dldfcn/__dsearchn__.cc, libinterp/dldfcn/__eigs__.cc,
libinterp/dldfcn/__fltk_uigetfile__.cc, libinterp/dldfcn/__glpk__.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__init_gnuplot__.cc,
libinterp/dldfcn/__magick_read__.cc, libinterp/dldfcn/__voronoi__.cc,
libinterp/dldfcn/amd.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/chol.cc,
libinterp/dldfcn/colamd.cc, libinterp/dldfcn/convhulln.cc,
libinterp/dldfcn/dmperm.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc,
libinterp/dldfcn/symbfact.cc, libinterp/dldfcn/symrcm.cc,
libinterp/dldfcn/tsearch.cc, libinterp/octave-value/ov-base-diag.cc,
libinterp/octave-value/ov-base-diag.h, libinterp/octave-value/ov-base-int.cc,
libinterp/octave-value/ov-base-int.h, libinterp/octave-value/ov-base-mat.h,
libinterp/octave-value/ov-base-scalar.cc,
libinterp/octave-value/ov-base-scalar.h,
libinterp/octave-value/ov-base-sparse.cc,
libinterp/octave-value/ov-base-sparse.h, libinterp/octave-value/ov-base.cc,
libinterp/octave-value/ov-base.h, libinterp/octave-value/ov-bool-mat.cc,
libinterp/octave-value/ov-bool-mat.h, libinterp/octave-value/ov-bool-sparse.cc,
libinterp/octave-value/ov-bool-sparse.h, libinterp/octave-value/ov-bool.cc,
libinterp/octave-value/ov-bool.h, libinterp/octave-value/ov-builtin.cc,
libinterp/octave-value/ov-builtin.h, libinterp/octave-value/ov-cell.cc,
libinterp/octave-value/ov-cell.h, libinterp/octave-value/ov-ch-mat.cc,
libinterp/octave-value/ov-ch-mat.h, libinterp/octave-value/ov-class.cc,
libinterp/octave-value/ov-class.h, libinterp/octave-value/ov-colon.h,
libinterp/octave-value/ov-complex.cc, libinterp/octave-value/ov-complex.h,
libinterp/octave-value/ov-cx-diag.cc, libinterp/octave-value/ov-cx-diag.h,
libinterp/octave-value/ov-cx-mat.cc, libinterp/octave-value/ov-cx-mat.h,
libinterp/octave-value/ov-cx-sparse.cc, libinterp/octave-value/ov-cx-sparse.h,
libinterp/octave-value/ov-dld-fcn.h, libinterp/octave-value/ov-fcn-handle.cc,
libinterp/octave-value/ov-fcn-handle.h,
libinterp/octave-value/ov-fcn-inline.cc,
libinterp/octave-value/ov-fcn-inline.h, libinterp/octave-value/ov-fcn.h,
libinterp/octave-value/ov-float.cc, libinterp/octave-value/ov-float.h,
libinterp/octave-value/ov-flt-complex.cc,
libinterp/octave-value/ov-flt-complex.h,
libinterp/octave-value/ov-flt-cx-diag.cc,
libinterp/octave-value/ov-flt-cx-diag.h,
libinterp/octave-value/ov-flt-cx-mat.cc,
libinterp/octave-value/ov-flt-cx-mat.h,
libinterp/octave-value/ov-flt-re-diag.cc,
libinterp/octave-value/ov-flt-re-diag.h,
libinterp/octave-value/ov-flt-re-mat.cc,
libinterp/octave-value/ov-flt-re-mat.h, libinterp/octave-value/ov-int16.cc,
libinterp/octave-value/ov-int32.cc, libinterp/octave-value/ov-int64.cc,
libinterp/octave-value/ov-int8.cc, libinterp/octave-value/ov-intx.h,
libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-lazy-idx.h,
libinterp/octave-value/ov-mex-fcn.cc, libinterp/octave-value/ov-mex-fcn.h,
libinterp/octave-value/ov-null-mat.cc, libinterp/octave-value/ov-null-mat.h,
libinterp/octave-value/ov-oncleanup.cc, libinterp/octave-value/ov-perm.cc,
libinterp/octave-value/ov-perm.h, libinterp/octave-value/ov-range.cc,
libinterp/octave-value/ov-range.h, libinterp/octave-value/ov-re-diag.cc,
libinterp/octave-value/ov-re-diag.h, libinterp/octave-value/ov-re-mat.cc,
libinterp/octave-value/ov-re-mat.h, libinterp/octave-value/ov-re-sparse.cc,
libinterp/octave-value/ov-re-sparse.h, libinterp/octave-value/ov-scalar.cc,
libinterp/octave-value/ov-scalar.h, libinterp/octave-value/ov-str-mat.cc,
libinterp/octave-value/ov-str-mat.h, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-struct.h, libinterp/octave-value/ov-type-conv.h,
libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov-typeinfo.h,
libinterp/octave-value/ov-uint16.cc, libinterp/octave-value/ov-uint32.cc,
libinterp/octave-value/ov-uint64.cc, libinterp/octave-value/ov-uint8.cc,
libinterp/octave-value/ov-usr-fcn.cc, libinterp/octave-value/ov-usr-fcn.h,
libinterp/octave-value/ov.cc, libinterp/octave-value/ov.h, libinterp/octave.cc,
libinterp/operators/op-b-bm.cc, libinterp/operators/op-b-sbm.cc,
libinterp/operators/op-bm-b.cc, libinterp/operators/op-bm-bm.cc,
libinterp/operators/op-cdm-cdm.cc, libinterp/operators/op-chm.cc,
libinterp/operators/op-class.cc, libinterp/operators/op-cm-cm.cc,
libinterp/operators/op-cm-cs.cc, libinterp/operators/op-cm-s.cc,
libinterp/operators/op-cm-scm.cc, libinterp/operators/op-cm-sm.cc,
libinterp/operators/op-cs-cm.cc, libinterp/operators/op-cs-cs.cc,
libinterp/operators/op-cs-scm.cc, libinterp/operators/op-cs-sm.cc,
libinterp/operators/op-dm-dm.cc, libinterp/operators/op-dm-scm.cc,
libinterp/operators/op-double-conv.cc, libinterp/operators/op-fcdm-fcdm.cc,
libinterp/operators/op-fcm-fcm.cc, libinterp/operators/op-fcm-fcs.cc,
libinterp/operators/op-fcm-fm.cc, libinterp/operators/op-fcm-fs.cc,
libinterp/operators/op-fcs-fcm.cc, libinterp/operators/op-fcs-fcs.cc,
libinterp/operators/op-fcs-fm.cc, libinterp/operators/op-fcs-fs.cc,
libinterp/operators/op-fdm-fdm.cc, libinterp/operators/op-float-conv.cc,
libinterp/operators/op-fm-fcm.cc, libinterp/operators/op-fm-fcs.cc,
libinterp/operators/op-fm-fm.cc, libinterp/operators/op-fm-fs.cc,
libinterp/operators/op-fs-fcm.cc, libinterp/operators/op-fs-fcs.cc,
libinterp/operators/op-fs-fm.cc, libinterp/operators/op-fs-fs.cc,
libinterp/operators/op-m-cm.cc, libinterp/operators/op-m-cs.cc,
libinterp/operators/op-m-m.cc, libinterp/operators/op-m-s.cc,
libinterp/operators/op-m-scm.cc, libinterp/operators/op-m-sm.cc,
libinterp/operators/op-pm-scm.cc, libinterp/operators/op-range.cc,
libinterp/operators/op-s-cm.cc, libinterp/operators/op-s-cs.cc,
libinterp/operators/op-s-scm.cc, libinterp/operators/op-sbm-b.cc,
libinterp/operators/op-sbm-bm.cc, libinterp/operators/op-sbm-sbm.cc,
libinterp/operators/op-scm-cm.cc, libinterp/operators/op-scm-cs.cc,
libinterp/operators/op-scm-m.cc, libinterp/operators/op-scm-s.cc,
libinterp/operators/op-scm-scm.cc, libinterp/operators/op-scm-sm.cc,
libinterp/operators/op-sm-cm.cc, libinterp/operators/op-sm-m.cc,
libinterp/operators/op-sm-s.cc, libinterp/operators/op-sm-scm.cc,
libinterp/operators/op-sm-sm.cc, libinterp/operators/op-str-m.cc,
libinterp/operators/op-str-s.cc, libinterp/operators/op-str-str.cc,
libinterp/operators/ops.h, libinterp/parse-tree/lex.h,
libinterp/parse-tree/parse.h, libinterp/parse-tree/pt-arg-list.cc,
libinterp/parse-tree/pt-arg-list.h, libinterp/parse-tree/pt-assign.cc,
libinterp/parse-tree/pt-assign.h, libinterp/parse-tree/pt-binop.cc,
libinterp/parse-tree/pt-binop.h, libinterp/parse-tree/pt-bp.h,
libinterp/parse-tree/pt-cbinop.cc, libinterp/parse-tree/pt-check.cc,
libinterp/parse-tree/pt-colon.cc, libinterp/parse-tree/pt-colon.h,
libinterp/parse-tree/pt-const.cc, libinterp/parse-tree/pt-decl.cc,
libinterp/parse-tree/pt-decl.h, libinterp/parse-tree/pt-eval.cc,
libinterp/parse-tree/pt-except.h, libinterp/parse-tree/pt-exp.h,
libinterp/parse-tree/pt-fcn-handle.cc, libinterp/parse-tree/pt-id.cc,
libinterp/parse-tree/pt-id.h, libinterp/parse-tree/pt-idx.cc,
libinterp/parse-tree/pt-idx.h, libinterp/parse-tree/pt-loop.h,
libinterp/parse-tree/pt-mat.cc, libinterp/parse-tree/pt-misc.cc,
libinterp/parse-tree/pt-misc.h, libinterp/parse-tree/pt-pr-code.cc,
libinterp/parse-tree/pt-select.h, libinterp/parse-tree/pt-stmt.h,
libinterp/parse-tree/token.h, libinterp/version.cc:
Use GNU style coding conventions for code in libinterp/
author | Rik <rik@octave.org> |
---|---|
date | Mon, 28 Oct 2013 19:51:46 -0700 |
parents | 9c03b071fd7b |
children | 870f3e12e163 |
rev | line source |
---|---|
6763 | 1 /* |
604 | 2 |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17709
diff
changeset
|
3 Copyright (C) 1994-2013 John W. Eaton |
604 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
604 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
604 | 20 |
21 */ | |
22 | |
3911 | 23 // Author: John W. Eaton. |
24 // HDF5 support by Steven G. Johnson <stevenj@alum.mit.edu> | |
25 // Matlab v5 support by James R. Van Zandt <jrv@vanzandt.mv.com> | |
3687 | 26 |
604 | 27 #ifdef HAVE_CONFIG_H |
1192 | 28 #include <config.h> |
604 | 29 #endif |
30 | |
1343 | 31 #include <cfloat> |
32 #include <cstring> | |
33 #include <cctype> | |
34 | |
4249 | 35 #include <fstream> |
3503 | 36 #include <iomanip> |
37 #include <iostream> | |
5765 | 38 #include <sstream> |
1728 | 39 #include <string> |
40 | |
9946 | 41 #include "strftime.h" |
42 | |
1961 | 43 #include "byte-swap.h" |
44 #include "data-conv.h" | |
2926 | 45 #include "file-ops.h" |
6159 | 46 #include "file-stat.h" |
2926 | 47 #include "glob-match.h" |
2890 | 48 #include "lo-mappers.h" |
2318 | 49 #include "mach-info.h" |
3185 | 50 #include "oct-env.h" |
3258 | 51 #include "oct-time.h" |
4171 | 52 #include "quit.h" |
1755 | 53 #include "str-vec.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8110
diff
changeset
|
54 #include "oct-locbuf.h" |
1755 | 55 |
4332 | 56 #include "Cell.h" |
1352 | 57 #include "defun.h" |
604 | 58 #include "error.h" |
777 | 59 #include "gripes.h" |
6159 | 60 #include "load-path.h" |
1352 | 61 #include "load-save.h" |
1750 | 62 #include "oct-obj.h" |
3687 | 63 #include "oct-map.h" |
4332 | 64 #include "ov-cell.h" |
1352 | 65 #include "pager.h" |
1750 | 66 #include "pt-exp.h" |
1352 | 67 #include "symtab.h" |
68 #include "sysdep.h" | |
69 #include "unwind-prot.h" | |
604 | 70 #include "utils.h" |
2371 | 71 #include "variables.h" |
3185 | 72 #include "version.h" |
3688 | 73 #include "dMatrix.h" |
74 | |
4633 | 75 #include "ls-hdf5.h" |
76 #include "ls-mat-ascii.h" | |
77 #include "ls-mat4.h" | |
78 #include "ls-mat5.h" | |
79 #include "ls-oct-ascii.h" | |
80 #include "ls-oct-binary.h" | |
3688 | 81 |
10309 | 82 // Remove gnulib definitions, if any. |
83 #ifdef close | |
84 #undef close | |
85 #endif | |
86 #ifdef open | |
87 #undef open | |
5269 | 88 #endif |
89 | |
10309 | 90 #ifdef HAVE_ZLIB |
91 #include "zfstream.h" | |
10305
d6cdf08d0424
load-save.cc: avoid gnulib definition of close
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
92 #endif |
d6cdf08d0424
load-save.cc: avoid gnulib definition of close
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
93 |
14889
577df411e0c7
rename octave-core file to octave-workspace
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
94 // Write octave-workspace file if Octave crashes or is killed by a signal. |
5794 | 95 static bool Vcrash_dumps_octave_core = true; |
3189 | 96 |
4791 | 97 // The maximum amount of memory (in kilobytes) that we will attempt to |
98 // write to the Octave core file. | |
5794 | 99 static double Voctave_core_file_limit = -1.0; |
4791 | 100 |
101 // The name of the Octave core file. | |
14889
577df411e0c7
rename octave-core file to octave-workspace
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
102 static std::string Voctave_core_file_name = "octave-workspace"; |
4791 | 103 |
3687 | 104 // The default output format. May be one of "binary", "text", |
105 // "mat-binary", or "hdf5". | |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
106 static std::string Vsave_default_options = "-text"; |
2194 | 107 |
5284 | 108 // The output format for Octave core files. |
5794 | 109 static std::string Voctave_core_file_options = "-binary"; |
110 | |
111 static std::string | |
112 default_save_header_format (void) | |
113 { | |
114 return | |
115 std::string ("# Created by Octave " OCTAVE_VERSION | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
116 ", %a %b %d %H:%M:%S %Y %Z <") |
5794 | 117 + octave_env::get_user_name () |
118 + std::string ("@") | |
119 + octave_env::get_host_name () | |
120 + std::string (">"); | |
121 } | |
4788 | 122 |
3709 | 123 // The format string for the comment line at the top of text-format |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
124 // save files. Passed to strftime. Should begin with '#' and contain |
3709 | 125 // no newline characters. |
5794 | 126 static std::string Vsave_header_format_string = default_save_header_format (); |
3709 | 127 |
5369 | 128 static void |
129 gripe_file_open (const std::string& fcn, const std::string& file) | |
130 { | |
131 if (fcn == "load") | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
132 error ("%s: unable to open input file '%s'", fcn.c_str (), file.c_str ()); |
5369 | 133 else if (fcn == "save") |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
134 error ("%s: unable to open output file '%s'", fcn.c_str (), file.c_str ()); |
5369 | 135 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
136 error ("%s: unable to open file '%s'", fcn.c_str (), file.c_str ()); |
5369 | 137 } |
138 | |
7336 | 139 // Install a variable with name NAME and the value VAL in the |
140 // symbol table. If GLOBAL is TRUE, make the variable global. | |
604 | 141 |
142 static void | |
7336 | 143 install_loaded_variable (const std::string& name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
144 const octave_value& val, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
145 bool global, const std::string& /*doc*/) |
604 | 146 { |
147 if (global) | |
148 { | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
149 symbol_table::clear (name); |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
150 symbol_table::mark_global (name); |
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
151 symbol_table::global_assign (name, val); |
604 | 152 } |
153 else | |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
154 symbol_table::assign (name, val); |
604 | 155 } |
156 | |
3019 | 157 // Return TRUE if NAME matches one of the given globbing PATTERNS. |
604 | 158 |
3013 | 159 static bool |
3769 | 160 matches_patterns (const string_vector& patterns, int pat_idx, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
161 int num_pat, const std::string& name) |
604 | 162 { |
1755 | 163 for (int i = pat_idx; i < num_pat; i++) |
604 | 164 { |
1792 | 165 glob_match pattern (patterns[i]); |
3013 | 166 |
1792 | 167 if (pattern.match (name)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
168 return true; |
604 | 169 } |
3688 | 170 |
3013 | 171 return false; |
604 | 172 } |
173 | |
4329 | 174 int |
3523 | 175 read_binary_file_header (std::istream& is, bool& swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
176 oct_mach_info::float_format& flt_fmt, bool quiet) |
604 | 177 { |
3552 | 178 const int magic_len = 10; |
179 char magic[magic_len+1]; | |
5760 | 180 is.read (magic, magic_len); |
604 | 181 magic[magic_len] = '\0'; |
3688 | 182 |
604 | 183 if (strncmp (magic, "Octave-1-L", magic_len) == 0) |
2318 | 184 swap = oct_mach_info::words_big_endian (); |
604 | 185 else if (strncmp (magic, "Octave-1-B", magic_len) == 0) |
2318 | 186 swap = ! oct_mach_info::words_big_endian (); |
604 | 187 else |
188 { | |
189 if (! quiet) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
190 error ("load: unable to read read binary file"); |
604 | 191 return -1; |
192 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
193 |
604 | 194 char tmp = 0; |
5760 | 195 is.read (&tmp, 1); |
604 | 196 |
2318 | 197 flt_fmt = mopt_digit_to_float_format (tmp); |
198 | |
4574 | 199 if (flt_fmt == oct_mach_info::flt_fmt_unknown) |
604 | 200 { |
201 if (! quiet) | |
202 error ("load: unrecognized binary format!"); | |
3688 | 203 |
604 | 204 return -1; |
205 } | |
206 | |
207 return 0; | |
208 } | |
209 | |
5269 | 210 #ifdef HAVE_ZLIB |
211 static bool | |
212 check_gzip_magic (const std::string& fname) | |
213 { | |
214 bool retval = false; | |
215 std::ifstream file (fname.c_str ()); | |
216 OCTAVE_LOCAL_BUFFER (unsigned char, magic, 2); | |
217 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
218 if (file.read (reinterpret_cast<char *> (magic), 2) && magic[0] == 0x1f && |
5269 | 219 magic[1] == 0x8b) |
220 retval = true; | |
221 | |
222 file.close (); | |
223 return retval; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
224 } |
5269 | 225 #endif |
226 | |
604 | 227 static load_save_format |
6625 | 228 get_file_format (std::istream& file, const std::string& filename) |
604 | 229 { |
230 load_save_format retval = LS_UNKNOWN; | |
231 | |
4574 | 232 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown; |
604 | 233 |
3019 | 234 bool swap = false; |
235 | |
236 if (read_binary_file_header (file, swap, flt_fmt, true) == 0) | |
604 | 237 retval = LS_BINARY; |
238 else | |
239 { | |
6202 | 240 file.clear (); |
3538 | 241 file.seekg (0, std::ios::beg); |
604 | 242 |
5828 | 243 int32_t mopt, nr, nc, imag, len; |
1180 | 244 |
16555
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
245 int err = read_mat_file_header (file, swap, mopt, nr, nc, imag, len, |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
246 true); |
1180 | 247 |
248 if (! err) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
249 retval = LS_MAT_BINARY; |
604 | 250 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
251 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
252 file.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
253 file.seekg (0, std::ios::beg); |
604 | 254 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
255 err = read_mat5_binary_file_header (file, swap, true, filename); |
3688 | 256 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
257 if (! err) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
258 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
259 file.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
260 file.seekg (0, std::ios::beg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
261 retval = LS_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
262 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
263 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
264 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
265 file.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
266 file.seekg (0, std::ios::beg); |
3688 | 267 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
268 std::string tmp = extract_keyword (file, "name"); |
4171 | 269 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
270 if (! tmp.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
271 retval = LS_ASCII; |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
272 else |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
273 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
274 file.clear (); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
275 file.seekg (0, std::ios::beg); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
276 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
277 // FIXME: looks_like_mat_ascii_file does not check to see |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
278 // whether the file contains numbers. It just skips comments |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
279 // and checks for the same number of words on each line. We |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
280 // may need a better check here. The best way to do that |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
281 // might be just to try to read the file and see if it works. |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
282 |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
283 if (looks_like_mat_ascii_file (file, filename)) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
284 retval = LS_MAT_ASCII; |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
285 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
286 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
287 } |
604 | 288 } |
289 | |
5269 | 290 return retval; |
291 } | |
5977 | 292 |
5269 | 293 static load_save_format |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
294 get_file_format (const std::string& fname, const std::string& orig_fname, |
16555
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
295 bool &use_zlib, bool quiet = false) |
5269 | 296 { |
297 load_save_format retval = LS_UNKNOWN; | |
298 | |
299 #ifdef HAVE_HDF5 | |
300 // check this before we open the file | |
301 if (H5Fis_hdf5 (fname.c_str ()) > 0) | |
302 return LS_HDF5; | |
303 #endif /* HAVE_HDF5 */ | |
604 | 304 |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
305 #ifdef HAVE_ZLIB |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
306 use_zlib = check_gzip_magic (fname); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
307 #else |
5269 | 308 use_zlib = false; |
5977 | 309 #endif |
5269 | 310 |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
311 if (! use_zlib) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
312 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
313 std::ifstream file (fname.c_str ()); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
314 if (file) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
315 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
316 retval = get_file_format (file, orig_fname); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
317 file.close (); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
318 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
319 else if (! quiet) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
320 gripe_file_open ("load", orig_fname); |
5269 | 321 } |
17183
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
322 #ifdef HAVE_ZLIB |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
323 else |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
324 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
325 gzifstream gzfile (fname.c_str ()); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
326 if (gzfile) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
327 { |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
328 retval = get_file_format (gzfile, orig_fname); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
329 gzfile.close (); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
330 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
331 else if (! quiet) |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
332 gripe_file_open ("load", orig_fname); |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
333 } |
ca5103ab0b21
check_gzip_magic before get_file_format (wrong type detection, bug #39652)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
17170
diff
changeset
|
334 #endif |
604 | 335 |
336 return retval; | |
337 } | |
338 | |
4329 | 339 octave_value |
7336 | 340 do_load (std::istream& stream, const std::string& orig_fname, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
341 load_save_format format, oct_mach_info::float_format flt_fmt, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
342 bool list_only, bool swap, bool verbose, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
343 const string_vector& argv, int argv_idx, int argc, int nargout) |
604 | 344 { |
3727 | 345 octave_value retval; |
346 | |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
347 octave_scalar_map retstruct; |
604 | 348 |
5765 | 349 std::ostringstream output_buf; |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
350 std::list<std::string> symbol_names; |
4051 | 351 |
5754 | 352 octave_idx_type count = 0; |
4051 | 353 |
604 | 354 for (;;) |
355 { | |
3019 | 356 bool global = false; |
2086 | 357 octave_value tc; |
604 | 358 |
4171 | 359 std::string name; |
360 std::string doc; | |
604 | 361 |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
362 switch (format.type) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
363 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
364 case LS_ASCII: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
365 name = read_ascii_data (stream, orig_fname, global, tc, count); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
366 break; |
604 | 367 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
368 case LS_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
369 name = read_binary_data (stream, swap, flt_fmt, orig_fname, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
370 global, tc, doc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
371 break; |
604 | 372 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
373 case LS_MAT_ASCII: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
374 name = read_mat_ascii_data (stream, orig_fname, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
375 break; |
2511 | 376 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
377 case LS_MAT_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
378 name = read_mat_binary_data (stream, orig_fname, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
379 break; |
604 | 380 |
3687 | 381 #ifdef HAVE_HDF5 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
382 case LS_HDF5: |
17709
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
17349
diff
changeset
|
383 name = read_hdf5_data (stream, orig_fname, global, tc, doc, |
5415a9cd61d4
Implement faster partial loading of HDF5 files.
Rik <rik@octave.org>
parents:
17349
diff
changeset
|
384 argv, argv_idx, argc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
385 break; |
3687 | 386 #endif /* HAVE_HDF5 */ |
387 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
388 case LS_MAT5_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
389 case LS_MAT7_BINARY: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
390 name = read_mat5_binary_element (stream, orig_fname, swap, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
391 global, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
392 break; |
3688 | 393 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
394 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
395 gripe_unrecognized_data_fmt ("load"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
396 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
397 } |
604 | 398 |
4171 | 399 if (error_state || stream.eof () || name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
400 break; |
4171 | 401 else if (! error_state && ! name.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
402 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
403 if (tc.is_defined ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
404 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
405 if (format == LS_MAT_ASCII && argv_idx < argc) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
406 warning ("load: loaded ASCII file '%s' -- ignoring extra args", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
407 orig_fname.c_str ()); |
3136 | 408 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
409 if (format == LS_MAT_ASCII |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
410 || argv_idx == argc |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
411 || matches_patterns (argv, argv_idx, argc, name)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
412 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
413 count++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
414 if (list_only) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
415 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
416 if (verbose) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
417 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
418 if (count == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
419 output_buf |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
420 << "type rows cols name\n" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
421 << "==== ==== ==== ====\n"; |
621 | 422 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
423 output_buf |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
424 << std::setiosflags (std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
425 << std::setw (16) << tc.type_name () . c_str () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
426 << std::setiosflags (std::ios::right) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
427 << std::setw (7) << tc.rows () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
428 << std::setw (7) << tc.columns () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
429 << " " << name << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
430 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
431 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
432 symbol_names.push_back (name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
433 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
434 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
435 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
436 if (nargout == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
437 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
438 if (format == LS_MAT_ASCII) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
439 retval = tc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
440 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
441 retstruct.assign (name, tc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
442 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
443 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
444 install_loaded_variable (name, tc, global, doc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
445 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
446 } |
2511 | 447 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
448 // Only attempt to read one item from a headless text file. |
2511 | 449 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
450 if (format == LS_MAT_ASCII) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
451 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
452 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
453 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
454 error ("load: unable to load variable '%s'", name.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
455 } |
604 | 456 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
457 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
458 if (count == 0) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
459 error ("load: are you sure '%s' is an Octave data file?", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
460 orig_fname.c_str ()); |
604 | 461 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
462 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
463 } |
604 | 464 } |
465 | |
621 | 466 if (list_only && count) |
467 { | |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
468 if (verbose) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
469 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
470 std::string msg = output_buf.str (); |
2095 | 471 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
472 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
473 retval = msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
474 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
475 octave_stdout << msg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
476 } |
621 | 477 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
478 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
479 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
480 retval = Cell (string_vector (symbol_names)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
481 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
482 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
483 string_vector names (symbol_names); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
484 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
485 names.list_in_columns (octave_stdout); |
7779
791231dac333
Add regexp matching to Fwho and Fclear
David Bateman <dbateman@free.fr>
parents:
7767
diff
changeset
|
486 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
487 octave_stdout << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
488 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
489 } |
621 | 490 } |
6639 | 491 else if (retstruct.nfields () != 0) |
3727 | 492 retval = retstruct; |
621 | 493 |
863 | 494 return retval; |
495 } | |
496 | |
6159 | 497 std::string |
498 find_file_to_load (const std::string& name, const std::string& orig_name) | |
499 { | |
500 std::string fname = name; | |
501 | |
6838 | 502 if (! (octave_env::absolute_pathname (fname) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
503 || octave_env::rooted_relative_pathname (fname))) |
6159 | 504 { |
505 file_stat fs (fname); | |
506 | |
6584 | 507 if (! (fs.exists () && fs.is_reg ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
508 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
509 std::string tmp |
10250 | 510 = octave_env::make_absolute (load_path::find_file (fname)); |
6159 | 511 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
512 if (! tmp.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
513 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
514 warning_with_id ("Octave:load-file-in-path", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
515 "load: file found in load path"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
516 fname = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
517 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
518 } |
6159 | 519 } |
520 | |
6838 | 521 size_t dot_pos = fname.rfind ("."); |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7819
diff
changeset
|
522 size_t sep_pos = fname.find_last_of (file_ops::dir_sep_chars ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
523 |
8021 | 524 if (dot_pos == std::string::npos |
525 || (sep_pos != std::string::npos && dot_pos < sep_pos)) | |
6159 | 526 { |
6838 | 527 // Either no '.' in name or no '.' appears after last directory |
528 // separator. | |
529 | |
6159 | 530 file_stat fs (fname); |
531 | |
6584 | 532 if (! (fs.exists () && fs.is_reg ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
533 fname = find_file_to_load (fname + ".mat", orig_name); |
6159 | 534 } |
535 else | |
536 { | |
537 file_stat fs (fname); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
538 |
6584 | 539 if (! (fs.exists () && fs.is_reg ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
540 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
541 fname = ""; |
6159 | 542 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
543 error ("load: unable to find file %s", orig_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
544 } |
6159 | 545 } |
546 | |
547 return fname; | |
548 } | |
549 | |
16555
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
550 bool |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
551 is_octave_data_file (const std::string& fname) |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
552 { |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
553 bool use_zlib = false; |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
554 return get_file_format (fname, fname, use_zlib, true) != LS_UNKNOWN; |
04fb96f4bea1
allow double-click in file browser to load data files
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
555 } |
6159 | 556 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8676
diff
changeset
|
557 DEFUN (load, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
558 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
559 @deftypefn {Command} {} load file\n\ |
11547 | 560 @deftypefnx {Command} {} load options file\n\ |
561 @deftypefnx {Command} {} load options file v1 v2 @dots{}\n\ | |
12216
becaa4b96728
load-save.cc (Fload): fix texinfo markup
John W. Eaton <jwe@octave.org>
parents:
12160
diff
changeset
|
562 @deftypefnx {Command} {S =} load (\"options\", \"file\", \"v1\", \"v2\", @dots{})\n\ |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
563 @deftypefnx {Command} {} load file options\n\ |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
564 @deftypefnx {Command} {} load file options v1 v2 @dots{}\n\ |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
565 @deftypefnx {Command} {S =} load (\"file\", \"options\", \"v1\", \"v2\", @dots{})\n\ |
7247 | 566 Load the named variables @var{v1}, @var{v2}, @dots{}, from the file\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
567 @var{file}. If no variables are specified then all variables found in the\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
568 file will be loaded. As with @code{save}, the list of variables to extract\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
569 can be full names or use a pattern syntax. The format of the file is\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
570 automatically detected but may be overridden by supplying the appropriate\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
571 option.\n\ |
863 | 572 \n\ |
5665 | 573 If load is invoked using the functional form\n\ |
574 \n\ | |
575 @example\n\ | |
7247 | 576 load (\"-option1\", @dots{}, \"file\", \"v1\", @dots{})\n\ |
5665 | 577 @end example\n\ |
578 \n\ | |
579 @noindent\n\ | |
580 then the @var{options}, @var{file}, and variable name arguments\n\ | |
581 (@var{v1}, @dots{}) must be specified as character strings.\n\ | |
582 \n\ | |
3372 | 583 If a variable that is not marked as global is loaded from a file when a\n\ |
584 global symbol with the same name already exists, it is loaded in the\n\ | |
585 global symbol table. Also, if a variable is marked as global in a file\n\ | |
586 and a local symbol exists, the local symbol is moved to the global\n\ | |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
587 symbol table and given the value from the file.\n\ |
863 | 588 \n\ |
3727 | 589 If invoked with a single output argument, Octave returns data instead\n\ |
590 of inserting variables in the symbol table. If the data file contains\n\ | |
591 only numbers (TAB- or space-delimited columns), a matrix of values is\n\ | |
592 returned. Otherwise, @code{load} returns a structure with members\n\ | |
593 corresponding to the names of the variables in the file.\n\ | |
594 \n\ | |
3372 | 595 The @code{load} command can read data stored in Octave's text and\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
596 binary formats, and @sc{matlab}'s binary format. If compiled with zlib\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
597 support, it can also load gzip-compressed files. It will automatically\n\ |
3372 | 598 detect the type of file and do conversion from different floating point\n\ |
599 formats (currently only IEEE big and little endian, though other formats\n\ | |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
600 may be added in the future).\n\ |
3372 | 601 \n\ |
602 Valid options for @code{load} are listed in the following table.\n\ | |
863 | 603 \n\ |
3372 | 604 @table @code\n\ |
605 @item -force\n\ | |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
606 This option is accepted for backward compatibility but is ignored.\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
607 Octave now overwrites variables currently in memory with\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
608 those of the same name found in the file.\n\ |
3372 | 609 \n\ |
610 @item -ascii\n\ | |
5938 | 611 Force Octave to assume the file contains columns of numbers in text format\n\ |
612 without any header or other information. Data in the file will be loaded\n\ | |
613 as a single numeric matrix with the name of the variable derived from the\n\ | |
614 name of the file.\n\ | |
5197 | 615 \n\ |
3372 | 616 @item -binary\n\ |
617 Force Octave to assume the file is in Octave's binary format.\n\ | |
618 \n\ | |
3687 | 619 @item -hdf5\n\ |
10840 | 620 Force Octave to assume the file is in @sc{hdf5} format.\n\ |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
621 (@sc{hdf5} is a free, portable binary format developed by the National\n\ |
3687 | 622 Center for Supercomputing Applications at the University of Illinois.)\n\ |
10840 | 623 Note that Octave can read @sc{hdf5} files not created by itself, but may\n\ |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
624 skip some datasets in formats that it cannot support. This format is\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
625 only available if Octave was built with a link to the @sc{hdf5} libraries.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
626 \n\ |
3687 | 627 @item -import\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
628 This option is accepted for backward compatibility but is ignored.\n\ |
4884 | 629 Octave can now support multi-dimensional HDF data and automatically\n\ |
630 modifies variable names if they are invalid Octave identifiers.\n\ | |
3687 | 631 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
632 @item -mat\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
633 @itemx -mat-binary\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
634 @itemx -6\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
635 @itemx -v6\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
636 @itemx -7\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
637 @itemx -v7\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
638 Force Octave to assume the file is in @sc{matlab}'s version 6 or 7 binary\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
639 format.\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
640 \n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
641 @item -mat4-binary\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
642 @itemx -4\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
643 @itemx -v4\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
644 @itemx -V4\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
645 Force Octave to assume the file is in the binary format written by\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
646 @sc{matlab} version 4.\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
647 \n\ |
5198 | 648 @item -text\n\ |
5197 | 649 Force Octave to assume the file is in Octave's text format.\n\ |
3372 | 650 @end table\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
651 @seealso{save, dlmwrite, csvwrite, fwrite}\n\ |
11547 | 652 @end deftypefn") |
863 | 653 { |
2086 | 654 octave_value_list retval; |
863 | 655 |
1755 | 656 int argc = args.length () + 1; |
657 | |
1968 | 658 string_vector argv = args.make_argv ("load"); |
1755 | 659 |
660 if (error_state) | |
661 return retval; | |
863 | 662 |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
663 int i = 1; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
664 std::string orig_fname = ""; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
665 |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
666 // Function called with Matlab-style ["filename", options] syntax |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
667 if (argc > 1 && ! argv[1].empty () && argv[1].at (0) != '-') |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
668 { |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
669 orig_fname = argv[1]; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
670 i++; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
671 } |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
672 |
1358 | 673 // It isn't necessary to have the default load format stored in a |
674 // user preference variable since we can determine the type of file | |
675 // as we are reading. | |
863 | 676 |
677 load_save_format format = LS_UNKNOWN; | |
678 | |
3019 | 679 bool list_only = false; |
680 bool verbose = false; | |
863 | 681 |
13026
9a2a6054460f
maint: Fix 2 compiler warnings
Rik <octave@nomad.inbox5.com>
parents:
12895
diff
changeset
|
682 //for (i; i < argc; i++) |
9a2a6054460f
maint: Fix 2 compiler warnings
Rik <octave@nomad.inbox5.com>
parents:
12895
diff
changeset
|
683 for (; i < argc; i++) |
863 | 684 { |
1755 | 685 if (argv[i] == "-force" || argv[i] == "-f") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
686 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
687 // Silently ignore this |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
688 // warning ("load: -force ignored"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
689 } |
1755 | 690 else if (argv[i] == "-list" || argv[i] == "-l") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
691 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
692 list_only = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
693 } |
1755 | 694 else if (argv[i] == "-verbose" || argv[i] == "-v") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
695 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
696 verbose = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
697 } |
1755 | 698 else if (argv[i] == "-ascii" || argv[i] == "-a") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
699 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
700 format = LS_MAT_ASCII; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
701 } |
1755 | 702 else if (argv[i] == "-binary" || argv[i] == "-b") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
703 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
704 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
705 } |
5269 | 706 else if (argv[i] == "-mat-binary" || argv[i] == "-mat" || argv[i] == "-m" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
707 || argv[i] == "-6" || argv[i] == "-v6") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
708 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
709 format = LS_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
710 } |
7819
b7e8ea6a5143
trivial fix option in Fload
Jaroslav Hajek <highegg@gmail.com>
parents:
7779
diff
changeset
|
711 else if (argv[i] == "-7" || argv[i] == "-v7") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
712 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
713 format = LS_MAT7_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
714 } |
5256 | 715 else if (argv[i] == "-mat4-binary" || argv[i] == "-V4" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
716 || argv[i] == "-v4" || argv[i] == "-4") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
717 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
718 format = LS_MAT_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
719 } |
3687 | 720 else if (argv[i] == "-hdf5" || argv[i] == "-h") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
721 { |
3687 | 722 #ifdef HAVE_HDF5 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
723 format = LS_HDF5; |
3687 | 724 #else /* ! HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
725 error ("load: octave executable was not linked with HDF5 library"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
726 return retval; |
3687 | 727 #endif /* ! HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
728 } |
3687 | 729 else if (argv[i] == "-import" || argv[i] == "-i") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
730 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
731 warning ("load: -import ignored"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
732 } |
5197 | 733 else if (argv[i] == "-text" || argv[i] == "-t") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
734 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
735 format = LS_ASCII; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
736 } |
863 | 737 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
738 break; |
863 | 739 } |
740 | |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
741 if (orig_fname == "") |
863 | 742 { |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
743 if (i == argc) |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
744 { |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
745 print_usage (); |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
746 return retval; |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
747 } |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
748 else |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
749 orig_fname = argv[i]; |
863 | 750 } |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
751 else |
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
752 i--; |
863 | 753 |
4574 | 754 oct_mach_info::float_format flt_fmt = oct_mach_info::flt_fmt_unknown; |
863 | 755 |
3019 | 756 bool swap = false; |
863 | 757 |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
758 if (orig_fname == "-") |
863 | 759 { |
1755 | 760 i++; |
863 | 761 |
3687 | 762 #ifdef HAVE_HDF5 |
763 if (format == LS_HDF5) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
764 error ("load: cannot read HDF5 format from stdin"); |
3687 | 765 else |
766 #endif /* HAVE_HDF5 */ | |
863 | 767 if (format != LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
768 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
769 // FIXME -- if we have already seen EOF on a |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
770 // previous call, how do we fix up the state of std::cin so |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
771 // that we can get additional input? I'm afraid that we |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
772 // can't fix this using std::cin only. |
3531 | 773 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
774 retval = do_load (std::cin, orig_fname, format, flt_fmt, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
775 list_only, swap, verbose, argv, i, argc, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
776 nargout); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
777 } |
863 | 778 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
779 error ("load: must specify file format if reading from stdin"); |
863 | 780 } |
781 else | |
782 { | |
12895
8edece28cf4d
Allow Matlab-style syntax for load command (Bug #33527).
Rik <octave@nomad.inbox5.com>
parents:
12661
diff
changeset
|
783 std::string fname = file_ops::tilde_expand (orig_fname); |
6159 | 784 |
785 fname = find_file_to_load (fname, orig_fname); | |
863 | 786 |
6159 | 787 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
788 return retval; |
6159 | 789 |
790 bool use_zlib = false; | |
5089 | 791 |
863 | 792 if (format == LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
793 format = get_file_format (fname, orig_fname, use_zlib); |
863 | 794 |
3687 | 795 #ifdef HAVE_HDF5 |
796 if (format == LS_HDF5) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
797 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
798 i++; |
3687 | 799 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
800 hdf5_ifstream hdf5_file (fname.c_str ()); |
3687 | 801 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
802 if (hdf5_file.file_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
803 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
804 retval = do_load (hdf5_file, orig_fname, format, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
805 flt_fmt, list_only, swap, verbose, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
806 argv, i, argc, nargout); |
4844 | 807 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
808 hdf5_file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
809 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
810 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
811 gripe_file_open ("load", orig_fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
812 } |
3687 | 813 else |
814 #endif /* HAVE_HDF5 */ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
815 // don't insert any statements here; the "else" above has to |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
816 // go with the "if" below!!!!! |
863 | 817 if (format != LS_UNKNOWN) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
818 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
819 i++; |
863 | 820 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
821 // Always open in binary mode and handle various |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
822 // line-endings explicitly. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
823 std::ios::openmode mode = std::ios::in | std::ios::binary; |
863 | 824 |
5269 | 825 #ifdef HAVE_ZLIB |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
826 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
827 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
828 gzifstream file (fname.c_str (), mode); |
863 | 829 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
830 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
831 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
832 if (format == LS_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
833 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
834 if (read_binary_file_header (file, swap, flt_fmt) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
835 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
836 if (file) file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
837 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
838 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
839 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
840 else if (format == LS_MAT5_BINARY |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
841 || format == LS_MAT7_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
842 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
843 if (read_mat5_binary_file_header (file, swap, false, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
844 orig_fname) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
845 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
846 if (file) file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
847 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
848 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
849 } |
5269 | 850 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
851 retval = do_load (file, orig_fname, format, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
852 flt_fmt, list_only, swap, verbose, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
853 argv, i, argc, nargout); |
5269 | 854 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
855 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
856 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
857 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
858 gripe_file_open ("load", orig_fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
859 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
860 else |
5269 | 861 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
862 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
863 std::ifstream file (fname.c_str (), mode); |
5269 | 864 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
865 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
866 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
867 if (format == LS_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
868 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
869 if (read_binary_file_header (file, swap, flt_fmt) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
870 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
871 if (file) file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
872 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
873 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
874 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
875 else if (format == LS_MAT5_BINARY |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
876 || format == LS_MAT7_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
877 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
878 if (read_mat5_binary_file_header (file, swap, false, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
879 orig_fname) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
880 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
881 if (file) file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
882 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
883 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
884 } |
5269 | 885 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
886 retval = do_load (file, orig_fname, format, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
887 flt_fmt, list_only, swap, verbose, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
888 argv, i, argc, nargout); |
5269 | 889 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
890 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
891 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
892 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
893 error ("load: unable to open input file '%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
894 orig_fname.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
895 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
896 } |
863 | 897 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
898 |
604 | 899 return retval; |
900 } | |
901 | |
3019 | 902 // Return TRUE if PATTERN has any special globbing chars in it. |
903 | |
904 static bool | |
3523 | 905 glob_pattern_p (const std::string& pattern) |
604 | 906 { |
907 int open = 0; | |
908 | |
1755 | 909 int len = pattern.length (); |
910 | |
911 for (int i = 0; i < len; i++) | |
604 | 912 { |
1755 | 913 char c = pattern[i]; |
914 | |
604 | 915 switch (c) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
916 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
917 case '?': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
918 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
919 return true; |
604 | 920 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
921 case '[': // Only accept an open brace if there is a close |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
922 open++; // brace to match it. Bracket expressions must be |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
923 continue; // complete, according to Posix.2 |
604 | 924 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
925 case ']': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
926 if (open) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
927 return true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
928 continue; |
4402 | 929 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
930 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
931 if (i == len - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
932 return false; |
604 | 933 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
934 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
935 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
936 } |
604 | 937 } |
938 | |
3019 | 939 return false; |
604 | 940 } |
941 | |
4791 | 942 static void |
943 do_save (std::ostream& os, const octave_value& tc, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
944 const std::string& name, const std::string& help, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
945 bool global, load_save_format fmt, bool save_as_floats) |
604 | 946 { |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
947 switch (fmt.type) |
604 | 948 { |
949 case LS_ASCII: | |
6974 | 950 save_ascii_data (os, tc, name, global, 0); |
604 | 951 break; |
952 | |
953 case LS_BINARY: | |
630 | 954 save_binary_data (os, tc, name, help, global, save_as_floats); |
604 | 955 break; |
956 | |
5938 | 957 case LS_MAT_ASCII: |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
958 if (! save_mat_ascii_data (os, tc, fmt.opts & LS_MAT_ASCII_LONG ? 16 : 8, |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
959 fmt.opts & LS_MAT_ASCII_TABS)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
960 warning ("save: unable to save %s in ASCII format", name.c_str ()); |
5938 | 961 break; |
962 | |
667 | 963 case LS_MAT_BINARY: |
964 save_mat_binary_data (os, tc, name); | |
965 break; | |
966 | |
3687 | 967 #ifdef HAVE_HDF5 |
968 case LS_HDF5: | |
969 save_hdf5_data (os, tc, name, help, global, save_as_floats); | |
970 break; | |
971 #endif /* HAVE_HDF5 */ | |
972 | |
3688 | 973 case LS_MAT5_BINARY: |
5269 | 974 save_mat5_binary_element (os, tc, name, global, false, save_as_floats); |
975 break; | |
976 | |
977 case LS_MAT7_BINARY: | |
978 save_mat5_binary_element (os, tc, name, global, true, save_as_floats); | |
3688 | 979 break; |
980 | |
604 | 981 default: |
775 | 982 gripe_unrecognized_data_fmt ("save"); |
604 | 983 break; |
984 } | |
985 } | |
986 | |
4791 | 987 // Save the info from SR on stream OS in the format specified by FMT. |
988 | |
989 void | |
7336 | 990 do_save (std::ostream& os, const symbol_table::symbol_record& sr, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
991 load_save_format fmt, bool save_as_floats) |
4791 | 992 { |
7336 | 993 octave_value val = sr.varval (); |
4791 | 994 |
7336 | 995 if (val.is_defined ()) |
4791 | 996 { |
7336 | 997 std::string name = sr.name (); |
998 std::string help; | |
999 bool global = sr.is_global (); | |
4791 | 1000 |
7336 | 1001 do_save (os, val, name, help, global, fmt, save_as_floats); |
4791 | 1002 } |
1003 } | |
1004 | |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1005 // save fields of a scalar structure STR matching PATTERN on stream OS |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1006 // in the format specified by FMT. |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1007 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1008 static size_t |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1009 save_fields (std::ostream& os, const octave_scalar_map& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1010 const std::string& pattern, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1011 load_save_format fmt, bool save_as_floats) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1012 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1013 glob_match pat (pattern); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1014 |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1015 size_t saved = 0; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1016 |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1017 for (octave_scalar_map::const_iterator p = m.begin (); p != m.end (); p++) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1018 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1019 std::string empty_str; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1020 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1021 if (pat.match (m.key (p))) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1022 { |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1023 do_save (os, m.contents (p), m.key (p), empty_str, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1024 0, fmt, save_as_floats); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1025 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1026 saved++; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1027 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1028 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1029 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1030 return saved; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1031 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1032 |
604 | 1033 // Save variables with names matching PATTERN on stream OS in the |
5794 | 1034 // format specified by FMT. |
604 | 1035 |
7336 | 1036 static size_t |
5794 | 1037 save_vars (std::ostream& os, const std::string& pattern, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1038 load_save_format fmt, bool save_as_floats) |
604 | 1039 { |
7336 | 1040 std::list<symbol_table::symbol_record> vars = symbol_table::glob (pattern); |
1041 | |
1042 size_t saved = 0; | |
3355 | 1043 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1044 typedef std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1045 const_vars_iterator; |
3355 | 1046 |
7336 | 1047 for (const_vars_iterator p = vars.begin (); p != vars.end (); p++) |
620 | 1048 { |
7336 | 1049 do_save (os, *p, fmt, save_as_floats); |
620 | 1050 |
1051 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1052 break; |
7336 | 1053 |
1054 saved++; | |
620 | 1055 } |
604 | 1056 |
1057 return saved; | |
1058 } | |
1059 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1060 static string_vector |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1061 parse_save_options (const string_vector &argv, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1062 load_save_format &format, bool &append, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1063 bool &save_as_floats, bool &use_zlib) |
604 | 1064 { |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1065 string_vector retval; |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1066 int argc = argv.length (); |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1067 |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1068 bool do_double = false, do_tabs = false; |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1069 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1070 for (int i = 0; i < argc; i++) |
5284 | 1071 { |
1072 if (argv[i] == "-append") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1073 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1074 append = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1075 } |
5284 | 1076 else if (argv[i] == "-ascii" || argv[i] == "-a") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1077 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1078 format = LS_MAT_ASCII; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1079 } |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1080 else if (argv[i] == "-double") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1081 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1082 do_double = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1083 } |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1084 else if (argv[i] == "-tabs") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1085 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1086 do_tabs = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1087 } |
5284 | 1088 else if (argv[i] == "-text" || argv[i] == "-t") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1089 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1090 format = LS_ASCII; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1091 } |
5284 | 1092 else if (argv[i] == "-binary" || argv[i] == "-b") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1093 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1094 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1095 } |
5284 | 1096 else if (argv[i] == "-hdf5" || argv[i] == "-h") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1097 { |
3687 | 1098 #ifdef HAVE_HDF5 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1099 format = LS_HDF5; |
5284 | 1100 #else /* ! HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1101 error ("save: octave executable was not linked with HDF5 library"); |
5284 | 1102 #endif /* ! HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1103 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1104 else if (argv[i] == "-mat-binary" || argv[i] == "-mat" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1105 || argv[i] == "-m" || argv[i] == "-6" || argv[i] == "-v6" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1106 || argv[i] == "-V6") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1107 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1108 format = LS_MAT5_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1109 } |
5284 | 1110 #ifdef HAVE_ZLIB |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1111 else if (argv[i] == "-mat7-binary" || argv[i] == "-7" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1112 || argv[i] == "-v7" || argv[i] == "-V7") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1113 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1114 format = LS_MAT7_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1115 } |
5284 | 1116 #endif |
1117 else if (argv[i] == "-mat4-binary" || argv[i] == "-V4" | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1118 || argv[i] == "-v4" || argv[i] == "-4") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1119 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1120 format = LS_MAT_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1121 } |
5284 | 1122 else if (argv[i] == "-float-binary" || argv[i] == "-f") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1123 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1124 format = LS_BINARY; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1125 save_as_floats = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1126 } |
5284 | 1127 else if (argv[i] == "-float-hdf5") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1128 { |
5284 | 1129 #ifdef HAVE_HDF5 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1130 format = LS_HDF5; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1131 save_as_floats = true; |
5284 | 1132 #else /* ! HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1133 error ("save: octave executable was not linked with HDF5 library"); |
5284 | 1134 #endif /* ! HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1135 } |
5284 | 1136 #ifdef HAVE_ZLIB |
1137 else if (argv[i] == "-zip" || argv[i] == "-z") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1138 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1139 use_zlib = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1140 } |
5284 | 1141 #endif |
15571
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1142 else if (argv[i] == "-struct") |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1143 { |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1144 retval.append (argv[i]); |
7b9551c65b7b
Don't report '-struct' as an unrecognized option to save().
Rik <rik@octave.org>
parents:
15567
diff
changeset
|
1145 } |
15567
e05eafe7105a
Print an error message if save() called with unrecognized option (bug #37502)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1146 else if (argv[i][0] == '-') |
e05eafe7105a
Print an error message if save() called with unrecognized option (bug #37502)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1147 { |
e05eafe7105a
Print an error message if save() called with unrecognized option (bug #37502)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1148 error ("save: Unrecognized option '%s'", argv[i].c_str ()); |
e05eafe7105a
Print an error message if save() called with unrecognized option (bug #37502)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
1149 } |
5284 | 1150 else |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1151 retval.append (argv[i]); |
5284 | 1152 } |
1153 | |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1154 if (do_double) |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1155 { |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1156 if (format == LS_MAT_ASCII) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1157 format.opts |= LS_MAT_ASCII_LONG; |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1158 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1159 warning ("save: \"-double\" option only has an effect with \"-ascii\""); |
8418
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1160 } |
679c22082ac7
handle -double option for save
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1161 |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1162 if (do_tabs) |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1163 { |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1164 if (format == LS_MAT_ASCII) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1165 format.opts |= LS_MAT_ASCII_TABS; |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1166 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1167 warning ("save: \"-tabs\" option only has an effect with \"-ascii\""); |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1168 } |
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1169 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1170 return retval; |
5284 | 1171 } |
1172 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1173 static string_vector |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1174 parse_save_options (const std::string &arg, load_save_format &format, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1175 bool &append, bool &save_as_floats, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1176 bool &use_zlib) |
5284 | 1177 { |
5765 | 1178 std::istringstream is (arg); |
5284 | 1179 std::string str; |
1180 string_vector argv; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1181 |
5765 | 1182 while (! is.eof ()) |
5284 | 1183 { |
1184 is >> str; | |
1185 argv.append (str); | |
1186 } | |
1187 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1188 return parse_save_options (argv, format, append, save_as_floats, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1189 use_zlib); |
604 | 1190 } |
1191 | |
4329 | 1192 void |
3523 | 1193 write_header (std::ostream& os, load_save_format format) |
863 | 1194 { |
8425
2e777f5135a3
support -tabs option for save -ascii
Jaroslav Hajek <highegg@gmail.com>
parents:
8418
diff
changeset
|
1195 switch (format.type) |
863 | 1196 { |
3185 | 1197 case LS_BINARY: |
1198 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1199 os << (oct_mach_info::words_big_endian () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1200 ? "Octave-1-B" : "Octave-1-L"); |
3185 | 1201 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1202 oct_mach_info::float_format flt_fmt = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1203 oct_mach_info::native_float_format (); |
3185 | 1204 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1205 char tmp = static_cast<char> (float_format_to_mopt_digit (flt_fmt)); |
3185 | 1206 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1207 os.write (&tmp, 1); |
3185 | 1208 } |
3688 | 1209 break; |
1210 | |
1211 case LS_MAT5_BINARY: | |
5269 | 1212 case LS_MAT7_BINARY: |
3688 | 1213 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1214 char const * versionmagic; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1215 int16_t number = *(reinterpret_cast<const int16_t *>("\x00\x01")); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1216 struct tm bdt; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1217 time_t now; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1218 char headertext[128]; |
3688 | 1219 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1220 time (&now); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1221 bdt = *gmtime (&now); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1222 memset (headertext, ' ', 124); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1223 // ISO 8601 format date |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1224 nstrftime (headertext, 124, "MATLAB 5.0 MAT-file, written by Octave " |
9947
31436dcf7d0f
call nstrftime, not my_strftime
John W. Eaton <jwe@octave.org>
parents:
9946
diff
changeset
|
1225 OCTAVE_VERSION ", %Y-%m-%d %T UTC", &bdt, 1, 0); |
3688 | 1226 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1227 // The first pair of bytes give the version of the MAT file |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1228 // format. The second pair of bytes form a magic number which |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1229 // signals a MAT file. MAT file data are always written in |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1230 // native byte order. The order of the bytes in the second |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1231 // pair indicates whether the file was written by a big- or |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1232 // little-endian machine. However, the version number is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1233 // written in the *opposite* byte order from everything else! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1234 if (number == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1235 versionmagic = "\x01\x00\x4d\x49"; // this machine is big endian |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1236 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1237 versionmagic = "\x00\x01\x49\x4d"; // this machine is little endian |
3688 | 1238 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1239 memcpy (headertext+124, versionmagic, 4); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1240 os.write (headertext, 128); |
3688 | 1241 } |
1242 | |
1243 break; | |
3185 | 1244 |
3687 | 1245 #ifdef HAVE_HDF5 |
1246 case LS_HDF5: | |
1247 #endif /* HAVE_HDF5 */ | |
3185 | 1248 case LS_ASCII: |
1249 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1250 octave_localtime now; |
3709 | 1251 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1252 std::string comment_string = now.strftime (Vsave_header_format_string); |
3709 | 1253 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1254 if (! comment_string.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1255 { |
3687 | 1256 #ifdef HAVE_HDF5 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1257 if (format == LS_HDF5) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1258 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1259 hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1260 H5Gset_comment (hs.file_id, "/", comment_string.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1261 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1262 else |
3687 | 1263 #endif /* HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1264 os << comment_string << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1265 } |
3185 | 1266 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1267 break; |
3185 | 1268 |
1269 default: | |
1270 break; | |
863 | 1271 } |
1272 } | |
1273 | |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1274 void |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1275 octave_prepare_hdf5 (void) |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1276 { |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1277 #ifdef HAVE_HDF5 |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1278 H5dont_atexit (); |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1279 #endif |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1280 } |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1281 |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1282 void |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1283 octave_finalize_hdf5 (void) |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1284 { |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1285 #ifdef HAVE_HDF5 |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1286 H5close (); |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1287 #endif |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1288 } |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1289 |
863 | 1290 static void |
3769 | 1291 save_vars (const string_vector& argv, int argv_idx, int argc, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1292 std::ostream& os, load_save_format fmt, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1293 bool save_as_floats, bool write_header_info) |
863 | 1294 { |
3185 | 1295 if (write_header_info) |
1296 write_header (os, fmt); | |
863 | 1297 |
1755 | 1298 if (argv_idx == argc) |
863 | 1299 { |
5794 | 1300 save_vars (os, "*", fmt, save_as_floats); |
863 | 1301 } |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1302 else if (argv[argv_idx] == "-struct") |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1303 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1304 if (++argv_idx >= argc) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1305 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1306 error ("save: missing struct name"); |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1307 return; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1308 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1309 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1310 std::string struct_name = argv[argv_idx]; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1311 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1312 if (! symbol_table::is_variable (struct_name)) |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1313 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1314 error ("save: no such variable: '%s'", struct_name.c_str ()); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1315 return; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1316 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1317 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
15571
diff
changeset
|
1318 octave_value struct_var = symbol_table::varval (struct_name); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1319 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1320 if (! struct_var.is_map () || struct_var.numel () != 1) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1321 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1322 error ("save: '%s' is not a scalar structure", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1323 struct_name.c_str ()); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1324 return; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1325 } |
11059
4ffa19147604
replace Octave_map->octave_scalar_map in help.cc and load-save.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
1326 octave_scalar_map struct_var_map = struct_var.scalar_map_value (); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1327 |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1328 ++argv_idx; |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1329 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1330 if (argv_idx < argc) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1331 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1332 for (int i = argv_idx; i < argc; i++) |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1333 { |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1334 if (! save_fields (os, struct_var_map, argv[i], fmt, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1335 save_as_floats)) |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1336 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1337 warning ("save: no such field '%s.%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1338 struct_name.c_str (), argv[i].c_str ()); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1339 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1340 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1341 } |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1342 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1343 save_fields (os, struct_var_map, "*", fmt, save_as_floats); |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1344 } |
863 | 1345 else |
1346 { | |
1755 | 1347 for (int i = argv_idx; i < argc; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1348 { |
17349
cb27dbf9e4ba
Don't warn about saving empty variable names for Matlab compatibility (bug #34259)
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
1349 if (argv[i] == "") |
cb27dbf9e4ba
Don't warn about saving empty variable names for Matlab compatibility (bug #34259)
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
1350 continue; // Skip empty vars for Matlab compatibility |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1351 if (! save_vars (os, argv[i], fmt, save_as_floats)) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1352 warning ("save: no such variable '%s'", argv[i].c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1353 } |
863 | 1354 } |
1355 } | |
1356 | |
5284 | 1357 static void |
1358 dump_octave_core (std::ostream& os, const char *fname, load_save_format fmt, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1359 bool save_as_floats) |
4791 | 1360 { |
1361 write_header (os, fmt); | |
1362 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1363 std::list<symbol_table::symbol_record> vars |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1364 = symbol_table::all_variables (symbol_table::top_scope (), 0); |
4791 | 1365 |
1366 double save_mem_size = 0; | |
1367 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1368 typedef std::list<symbol_table::symbol_record>::const_iterator |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1369 const_vars_iterator; |
7336 | 1370 |
1371 for (const_vars_iterator p = vars.begin (); p != vars.end (); p++) | |
4791 | 1372 { |
7336 | 1373 octave_value val = p->varval (); |
4791 | 1374 |
7336 | 1375 if (val.is_defined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1376 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1377 std::string name = p->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1378 std::string help; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1379 bool global = p->is_global (); |
4791 | 1380 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1381 double val_size = val.byte_size () / 1024; |
4791 | 1382 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1383 // FIXME: maybe we should try to throw out the largest first... |
4791 | 1384 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1385 if (Voctave_core_file_limit < 0 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1386 || save_mem_size + val_size < Voctave_core_file_limit) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1387 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1388 save_mem_size += val_size; |
4791 | 1389 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1390 do_save (os, val, name, help, global, fmt, save_as_floats); |
7336 | 1391 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1392 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1393 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1394 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1395 } |
4791 | 1396 } |
1397 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1398 message (0, "save to '%s' complete", fname); |
4791 | 1399 } |
1400 | |
1401 void | |
1402 dump_octave_core (void) | |
1380 | 1403 { |
3189 | 1404 if (Vcrash_dumps_octave_core) |
1380 | 1405 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1406 // FIXME: should choose better file name? |
3189 | 1407 |
4791 | 1408 const char *fname = Voctave_core_file_name.c_str (); |
3189 | 1409 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1410 message (0, "attempting to save variables to '%s'...", fname); |
3189 | 1411 |
5284 | 1412 load_save_format format = LS_BINARY; |
1413 | |
1414 bool save_as_floats = false; | |
1415 | |
1416 bool append = false; | |
3189 | 1417 |
5284 | 1418 bool use_zlib = false; |
1419 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1420 parse_save_options (Voctave_core_file_options, format, append, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1421 save_as_floats, use_zlib); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1422 |
5284 | 1423 std::ios::openmode mode = std::ios::out; |
4791 | 1424 |
6625 | 1425 // Matlab v7 files are always compressed |
1426 if (format == LS_MAT7_BINARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1427 use_zlib = false; |
6625 | 1428 |
4791 | 1429 if (format == LS_BINARY |
1430 #ifdef HAVE_HDF5 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1431 || format == LS_HDF5 |
4791 | 1432 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1433 || format == LS_MAT_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1434 || format == LS_MAT5_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1435 || format == LS_MAT7_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1436 mode |= std::ios::binary; |
3189 | 1437 |
5284 | 1438 mode |= append ? std::ios::ate : std::ios::trunc; |
1439 | |
3687 | 1440 #ifdef HAVE_HDF5 |
1441 if (format == LS_HDF5) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1442 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1443 hdf5_ofstream file (fname, mode); |
3687 | 1444 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1445 if (file.file_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1446 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1447 dump_octave_core (file, fname, format, save_as_floats); |
3687 | 1448 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1449 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1450 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1451 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1452 warning ("unable to open '%s' for writing...", fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1453 } |
3189 | 1454 else |
3687 | 1455 #endif /* HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1456 // don't insert any commands here! The open brace below must |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1457 // go with the else above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1458 { |
5284 | 1459 #ifdef HAVE_ZLIB |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1460 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1461 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1462 gzofstream file (fname, mode); |
4791 | 1463 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1464 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1465 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1466 dump_octave_core (file, fname, format, save_as_floats); |
5284 | 1467 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1468 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1469 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1470 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1471 warning ("unable to open '%s' for writing...", fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1472 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1473 else |
5284 | 1474 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1475 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1476 std::ofstream file (fname, mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1477 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1478 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1479 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1480 dump_octave_core (file, fname, format, save_as_floats); |
5284 | 1481 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1482 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1483 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1484 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1485 warning ("unable to open '%s' for writing...", fname); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1486 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1487 } |
1380 | 1488 } |
1489 } | |
1490 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8676
diff
changeset
|
1491 DEFUN (save, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1492 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11547
diff
changeset
|
1493 @deftypefn {Command} {} save file\n\ |
11547 | 1494 @deftypefnx {Command} {} save options file\n\ |
1495 @deftypefnx {Command} {} save options file @var{v1} @var{v2} @dots{}\n\ | |
1496 @deftypefnx {Command} {} save options file -struct @var{STRUCT} @var{f1} @var{f2} @dots{}\n\ | |
7247 | 1497 Save the named variables @var{v1}, @var{v2}, @dots{}, in the file\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1498 @var{file}. The special filename @samp{-} may be used to write\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1499 output to the terminal. If no variable names are listed, Octave saves\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1500 all the variables in the current scope. Otherwise, full variable names or\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1501 pattern syntax can be used to specify the variables to save.\n\ |
10840 | 1502 If the @option{-struct} modifier is used, fields @var{f1} @var{f2} @dots{}\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1503 of the scalar structure @var{STRUCT} are saved as if they were variables\n\ |
7635
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1504 with corresponding names.\n\ |
ba7a3e20ee3d
add -struct modifier to save
Jaroslav Hajek <highegg@gmail.com>
parents:
7336
diff
changeset
|
1505 Valid options for the @code{save} command are listed in the following table.\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1506 Options that modify the output format override the format specified by\n\ |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1507 @code{save_default_options}.\n\ |
3372 | 1508 \n\ |
5665 | 1509 If save is invoked using the functional form\n\ |
1510 \n\ | |
1511 @example\n\ | |
7247 | 1512 save (\"-option1\", @dots{}, \"file\", \"v1\", @dots{})\n\ |
5665 | 1513 @end example\n\ |
1514 \n\ | |
1515 @noindent\n\ | |
1516 then the @var{options}, @var{file}, and variable name arguments\n\ | |
7247 | 1517 (@var{v1}, @dots{}) must be specified as character strings.\n\ |
5665 | 1518 \n\ |
3372 | 1519 @table @code\n\ |
12661
9f91ca870f91
load-save.cc: Document -append option
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
1520 @item -append\n\ |
9f91ca870f91
load-save.cc: Document -append option
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12642
diff
changeset
|
1521 Append to the destination instead of overwriting.\n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13026
diff
changeset
|
1522 \n\ |
3372 | 1523 @item -ascii\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1524 Save a single matrix in a text file without header or any other information.\n\ |
5197 | 1525 \n\ |
3372 | 1526 @item -binary\n\ |
1527 Save the data in Octave's binary data format.\n\ | |
1528 \n\ | |
1529 @item -float-binary\n\ | |
1530 Save the data in Octave's binary data format but only using single\n\ | |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1531 precision. Only use this format if you know that all the\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1532 values to be saved can be represented in single precision.\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1533 \n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1534 @item -hdf5\n\ |
10840 | 1535 Save the data in @sc{hdf5} format.\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1536 (HDF5 is a free, portable binary format developed by the National\n\ |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1537 Center for Supercomputing Applications at the University of Illinois.)\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1538 This format is only available if Octave was built with a link to the\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1539 @sc{hdf5} libraries.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1540 \n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1541 @item -float-hdf5\n\ |
10840 | 1542 Save the data in @sc{hdf5} format but only using single precision.\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1543 Only use this format if you know that all the\n\ |
3372 | 1544 values to be saved can be represented in single precision.\n\ |
1545 \n\ | |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1546 @item -V7\n\ |
5269 | 1547 @itemx -v7\n\ |
1548 @itemx -7\n\ | |
1549 @itemx -mat7-binary\n\ | |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1550 Save the data in @sc{matlab}'s v7 binary data format.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1551 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1552 @item -V6\n\ |
5284 | 1553 @itemx -v6\n\ |
5269 | 1554 @itemx -6\n\ |
1555 @itemx -mat\n\ | |
4884 | 1556 @itemx -mat-binary\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1557 Save the data in @sc{matlab}'s v6 binary data format.\n\ |
3372 | 1558 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1559 @item -V4\n\ |
5256 | 1560 @itemx -v4\n\ |
1561 @itemx -4\n\ | |
1562 @itemx -mat4-binary\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
1563 Save the data in the binary format written by @sc{matlab} version 4.\n\ |
3688 | 1564 \n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1565 @item -text\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1566 Save the data in Octave's text data format. (default).\n\ |
3687 | 1567 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
1568 @item -zip\n\ |
5269 | 1569 @itemx -z\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
1570 Use the gzip algorithm to compress the file. This works equally on files\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
1571 that are compressed with gzip outside of octave, and gzip can equally be\n\ |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1572 used to convert the files for backward compatibility.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1573 This option is only available if Octave was built with a link to the zlib\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1574 libraries.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
1575 @end table\n\ |
604 | 1576 \n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1577 The list of variables to save may use wildcard patterns containing\n\ |
3372 | 1578 the following special characters:\n\ |
14366
b76f0740940e
doc: Periodic grammar check of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14268
diff
changeset
|
1579 \n\ |
3372 | 1580 @table @code\n\ |
1581 @item ?\n\ | |
1582 Match any single character.\n\ | |
1583 \n\ | |
1584 @item *\n\ | |
1585 Match zero or more characters.\n\ | |
1586 \n\ | |
1587 @item [ @var{list} ]\n\ | |
1588 Match the list of characters specified by @var{list}. If the first\n\ | |
1589 character is @code{!} or @code{^}, match all characters except those\n\ | |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1590 specified by @var{list}. For example, the pattern @code{[a-zA-Z]} will\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1591 match all lower and uppercase alphabetic characters.\n\ |
7718
62279ce5654c
save: fix continuation character in doc string
John W. Eaton <jwe@octave.org>
parents:
7635
diff
changeset
|
1592 \n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1593 Wildcards may also be used in the field name specifications when using\n\ |
10840 | 1594 the @option{-struct} modifier (but not in the struct name itself).\n\ |
5197 | 1595 \n\ |
3372 | 1596 @end table\n\ |
1597 \n\ | |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1598 Except when using the @sc{matlab} binary data file format or the\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1599 @samp{-ascii} format, saving global\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1600 variables also saves the global status of the variable. If the variable\n\ |
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1601 is restored at a later time using @samp{load}, it will be restored as a\n\ |
3372 | 1602 global variable.\n\ |
1603 \n\ | |
1604 The command\n\ | |
1605 \n\ | |
1606 @example\n\ | |
1607 save -binary data a b*\n\ | |
1608 @end example\n\ | |
1609 \n\ | |
1610 @noindent\n\ | |
1611 saves the variable @samp{a} and all variables beginning with @samp{b} to\n\ | |
1612 the file @file{data} in Octave's binary format.\n\ | |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1613 @seealso{load, save_default_options, save_header_format_string, dlmread, csvread, fread}\n\ |
11547 | 1614 @end deftypefn") |
604 | 1615 { |
2086 | 1616 octave_value_list retval; |
604 | 1617 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1618 int argc = args.length (); |
1755 | 1619 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1620 string_vector argv = args.make_argv (); |
1755 | 1621 |
1622 if (error_state) | |
1623 return retval; | |
604 | 1624 |
1358 | 1625 // Here is where we would get the default save format if it were |
1626 // stored in a user preference variable. | |
604 | 1627 |
3019 | 1628 bool save_as_floats = false; |
630 | 1629 |
5284 | 1630 load_save_format format = LS_ASCII; |
604 | 1631 |
3185 | 1632 bool append = false; |
1633 | |
5269 | 1634 bool use_zlib = false; |
1635 | |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1636 // get default options |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1637 parse_save_options (Vsave_default_options, format, append, save_as_floats, |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1638 use_zlib); |
5351 | 1639 |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1640 // override from command line |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1641 argv = parse_save_options (argv, format, append, save_as_floats, |
8034
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1642 use_zlib); |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1643 argc = argv.length (); |
f61bd8e0d682
fix default_save_options parsing and allow mixing options with other arguments.
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
1644 int i = 0; |
5197 | 1645 |
5284 | 1646 if (error_state) |
1647 return retval; | |
604 | 1648 |
2057 | 1649 if (i == argc) |
604 | 1650 { |
5823 | 1651 print_usage (); |
604 | 1652 return retval; |
1653 } | |
1654 | |
630 | 1655 if (save_as_floats && format == LS_ASCII) |
1656 { | |
1657 error ("save: cannot specify both -ascii and -float-binary"); | |
1658 return retval; | |
1659 } | |
1660 | |
1755 | 1661 if (argv[i] == "-") |
604 | 1662 { |
1755 | 1663 i++; |
863 | 1664 |
3687 | 1665 #ifdef HAVE_HDF5 |
1666 if (format == LS_HDF5) | |
4687 | 1667 error ("save: cannot write HDF5 format to stdout"); |
3687 | 1668 else |
1669 #endif /* HAVE_HDF5 */ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1670 // don't insert any commands here! the brace below must go |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1671 // with the "else" above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1672 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1673 if (append) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1674 warning ("save: ignoring -append option for output to stdout"); |
6759 | 1675 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1676 // FIXME: should things intended for the screen |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1677 // end up in an octave_value (string)? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1678 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1679 save_vars (argv, i, argc, octave_stdout, format, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1680 save_as_floats, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1681 } |
604 | 1682 } |
1755 | 1683 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14268
diff
changeset
|
1684 // Guard against things like 'save a*', which are probably mistakes... |
1755 | 1685 |
1686 else if (i == argc - 1 && glob_pattern_p (argv[i])) | |
1687 { | |
5823 | 1688 print_usage (); |
604 | 1689 return retval; |
1690 } | |
1691 else | |
1692 { | |
3523 | 1693 std::string fname = file_ops::tilde_expand (argv[i]); |
1755 | 1694 |
1695 i++; | |
604 | 1696 |
6625 | 1697 // Matlab v7 files are always compressed |
1698 if (format == LS_MAT7_BINARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1699 use_zlib = false; |
6625 | 1700 |
6759 | 1701 std::ios::openmode mode |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1702 = append ? (std::ios::app | std::ios::ate) : std::ios::out; |
6759 | 1703 |
4791 | 1704 if (format == LS_BINARY |
1705 #ifdef HAVE_HDF5 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1706 || format == LS_HDF5 |
4791 | 1707 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1708 || format == LS_MAT_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1709 || format == LS_MAT5_BINARY |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1710 || format == LS_MAT7_BINARY) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1711 mode |= std::ios::binary; |
3538 | 1712 |
3687 | 1713 #ifdef HAVE_HDF5 |
1714 if (format == LS_HDF5) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1715 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1716 // FIXME. It should be possible to append to HDF5 files. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1717 if (append) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1718 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1719 error ("save: appending to HDF5 files is not implemented"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1720 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1721 } |
6759 | 1722 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1723 bool write_header_info = ! (append && |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1724 H5Fis_hdf5 (fname.c_str ()) > 0); |
3687 | 1725 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1726 hdf5_ofstream hdf5_file (fname.c_str (), mode); |
6760 | 1727 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1728 if (hdf5_file.file_id != -1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1729 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1730 save_vars (argv, i, argc, hdf5_file, format, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1731 save_as_floats, write_header_info); |
3687 | 1732 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1733 hdf5_file.close (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1734 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1735 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1736 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1737 gripe_file_open ("save", fname); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1738 return retval; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1739 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1740 } |
863 | 1741 else |
3687 | 1742 #endif /* HAVE_HDF5 */ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1743 // don't insert any statements here! The brace below must go |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1744 // with the "else" above! |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1745 { |
5269 | 1746 #ifdef HAVE_ZLIB |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1747 if (use_zlib) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1748 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1749 gzofstream file (fname.c_str (), mode); |
5269 | 1750 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1751 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1752 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1753 bool write_header_info = ! file.tellp (); |
6760 | 1754 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1755 save_vars (argv, i, argc, file, format, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1756 save_as_floats, write_header_info); |
5269 | 1757 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1758 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1759 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1760 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1761 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1762 gripe_file_open ("save", fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1763 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1764 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1765 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1766 else |
5269 | 1767 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1768 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1769 std::ofstream file (fname.c_str (), mode); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
1770 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1771 if (file) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1772 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1773 bool write_header_info = ! file.tellp (); |
6760 | 1774 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1775 save_vars (argv, i, argc, file, format, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1776 save_as_floats, write_header_info); |
5269 | 1777 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1778 file.close (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1779 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1780 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1781 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1782 gripe_file_open ("save", fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1783 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1784 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1785 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10309
diff
changeset
|
1786 } |
604 | 1787 } |
1788 | |
1789 return retval; | |
1790 } | |
1791 | |
5794 | 1792 DEFUN (crash_dumps_octave_core, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1793 "-*- texinfo -*-\n\ |
10840 | 1794 @deftypefn {Built-in Function} {@var{val} =} crash_dumps_octave_core ()\n\ |
5794 | 1795 @deftypefnx {Built-in Function} {@var{old_val} =} crash_dumps_octave_core (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1796 @deftypefnx {Built-in Function} {} crash_dumps_octave_core (@var{new_val}, \"local\")\n\ |
5794 | 1797 Query or set the internal variable that controls whether Octave tries\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1798 to save all current variables to the file @file{octave-workspace} if it\n\ |
5794 | 1799 crashes or receives a hangup, terminate or similar signal.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1800 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1801 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1802 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1803 The original variable value is restored when exiting the function.\n\ |
5794 | 1804 @seealso{octave_core_file_limit, octave_core_file_name, octave_core_file_options}\n\ |
1805 @end deftypefn") | |
2194 | 1806 { |
5794 | 1807 return SET_INTERNAL_VARIABLE (crash_dumps_octave_core); |
2194 | 1808 } |
1809 | |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1810 DEFUN (save_default_options, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1811 "-*- texinfo -*-\n\ |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1812 @deftypefn {Built-in Function} {@var{val} =} save_default_options ()\n\ |
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1813 @deftypefnx {Built-in Function} {@var{old_val} =} save_default_options (@var{new_val})\n\ |
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1814 @deftypefnx {Built-in Function} {} save_default_options (@var{new_val}, \"local\")\n\ |
5794 | 1815 Query or set the internal variable that specifies the default options\n\ |
1816 for the @code{save} command, and defines the default format.\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1817 Typical values include @qcode{\"-ascii\"}, @qcode{\"-text -zip\"}.\n\ |
10840 | 1818 The default value is @option{-text}.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1819 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1820 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1821 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1822 The original variable value is restored when exiting the function.\n\ |
5794 | 1823 @seealso{save}\n\ |
1824 @end deftypefn") | |
4788 | 1825 { |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16555
diff
changeset
|
1826 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (save_default_options); |
4788 | 1827 } |
1828 | |
5794 | 1829 DEFUN (octave_core_file_limit, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1830 "-*- texinfo -*-\n\ |
10840 | 1831 @deftypefn {Built-in Function} {@var{val} =} octave_core_file_limit ()\n\ |
5794 | 1832 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_limit (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1833 @deftypefnx {Built-in Function} {} octave_core_file_limit (@var{new_val}, \"local\")\n\ |
5794 | 1834 Query or set the internal variable that specifies the maximum amount\n\ |
1835 of memory (in kilobytes) of the top-level workspace that Octave will\n\ | |
1836 attempt to save when writing data to the crash dump file (the name of\n\ | |
1837 the file is specified by @var{octave_core_file_name}). If\n\ | |
7001 | 1838 @var{octave_core_file_options} flags specify a binary format,\n\ |
5794 | 1839 then @var{octave_core_file_limit} will be approximately the maximum\n\ |
1840 size of the file. If a text file format is used, then the file could\n\ | |
1841 be much larger than the limit. The default value is -1 (unlimited)\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1842 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1843 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1844 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1845 The original variable value is restored when exiting the function.\n\ |
5794 | 1846 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ |
1847 @end deftypefn") | |
3709 | 1848 { |
5794 | 1849 return SET_INTERNAL_VARIABLE (octave_core_file_limit); |
3709 | 1850 } |
1851 | |
5794 | 1852 DEFUN (octave_core_file_name, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1853 "-*- texinfo -*-\n\ |
10840 | 1854 @deftypefn {Built-in Function} {@var{val} =} octave_core_file_name ()\n\ |
5794 | 1855 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_name (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1856 @deftypefnx {Built-in Function} {} octave_core_file_name (@var{new_val}, \"local\")\n\ |
5794 | 1857 Query or set the internal variable that specifies the name of the file\n\ |
1858 used for saving data from the top-level workspace if Octave aborts.\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1859 The default value is @qcode{\"octave-workspace\"}\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1860 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1861 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1862 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1863 The original variable value is restored when exiting the function.\n\ |
5794 | 1864 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_options}\n\ |
1865 @end deftypefn") | |
2194 | 1866 { |
5794 | 1867 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_name); |
1868 } | |
4791 | 1869 |
5794 | 1870 DEFUN (octave_core_file_options, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1871 "-*- texinfo -*-\n\ |
10840 | 1872 @deftypefn {Built-in Function} {@var{val} =} octave_core_file_options ()\n\ |
5794 | 1873 @deftypefnx {Built-in Function} {@var{old_val} =} octave_core_file_options (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1874 @deftypefnx {Built-in Function} {} octave_core_file_options (@var{new_val}, \"local\")\n\ |
5794 | 1875 Query or set the internal variable that specifies the options used for\n\ |
1876 saving the workspace data if Octave aborts. The value of\n\ | |
1877 @code{octave_core_file_options} should follow the same format as the\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8946
diff
changeset
|
1878 options for the @code{save} function. The default value is Octave's binary\n\ |
5284 | 1879 format.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1880 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1881 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1882 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1883 The original variable value is restored when exiting the function.\n\ |
5642 | 1884 @seealso{crash_dumps_octave_core, octave_core_file_name, octave_core_file_limit}\n\ |
5794 | 1885 @end deftypefn") |
1886 { | |
1887 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (octave_core_file_options); | |
1888 } | |
2194 | 1889 |
5794 | 1890 DEFUN (save_header_format_string, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17755
diff
changeset
|
1891 "-*- texinfo -*-\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1892 @deftypefn {Built-in Function} {@var{val} =} save_header_format_string ()\n\ |
5794 | 1893 @deftypefnx {Built-in Function} {@var{old_val} =} save_header_format_string (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1894 @deftypefnx {Built-in Function} {} save_header_format_string (@var{new_val}, \"local\")\n\ |
5794 | 1895 Query or set the internal variable that specifies the format\n\ |
1896 string used for the comment line written at the beginning of\n\ | |
1897 text-format data files saved by Octave. The format string is\n\ | |
1898 passed to @code{strftime} and should begin with the character\n\ | |
1899 @samp{#} and contain no newline characters. If the value of\n\ | |
1900 @code{save_header_format_string} is the empty string,\n\ | |
3709 | 1901 the header comment is omitted from text-format data files. The\n\ |
1902 default value is\n\ | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
1903 @c Set example in small font to prevent overfull line\n\ |
3709 | 1904 \n\ |
7031 | 1905 @smallexample\n\ |
4060 | 1906 \"# Created by Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ |
7031 | 1907 @end smallexample\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13941
diff
changeset
|
1908 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1909 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1910 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17183
diff
changeset
|
1911 The original variable value is restored when exiting the function.\n\ |
9306
de124edcebf6
Update documentation for load and save
Rik <rdrider0-list@yahoo.com>
parents:
9153
diff
changeset
|
1912 @seealso{strftime, save}\n\ |
5794 | 1913 @end deftypefn") |
1914 { | |
1915 return SET_INTERNAL_VARIABLE (save_header_format_string); | |
2194 | 1916 } |