Mercurial > octave-nkf
annotate libinterp/octave-value/ov-str-mat.cc @ 19632:76478d2da117
unconditionally disable the octave_allocator class
* configure.ac: Delete the --enable-octave-allocator option.
* oct-alloc.h: Delete octave_allocator class. Warn if file is
included. Unconditionally define macros to be empty.
* NEWS: Make note of these changes.
* oct-alloc.cc: Delete.
* liboctave/util/module.mk (UTIL_SRC): Remove it from the list.
* make_int.cc, Cell.h, oct-obj.cc, oct-obj.h, audiodevinfo.cc,
ov-base-int.h, ov-base-scalar.h, ov-bool-mat.cc, ov-bool-mat.h,
ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc, ov-bool.h,
ov-builtin.cc, ov-builtin.h, ov-cell.cc, ov-cell.h, ov-ch-mat.h,
ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc,
ov-complex.h, ov-cs-list.cc, ov-cs-list.h, ov-cx-diag.cc,
ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc,
ov-cx-sparse.h, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc,
ov-fcn-handle.h, ov-fcn-inline.cc, ov-fcn-inline.h, ov-fcn.cc,
ov-fcn.h, ov-float.cc, ov-float.h, ov-flt-complex.cc,
ov-flt-complex.h, ov-flt-cx-diag.cc, ov-flt-cx-diag.h,
ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-diag.cc,
ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-intx.h, ov-java.cc,
ov-java.h, ov-mex-fcn.cc, ov-mex-fcn.h, ov-perm.cc, ov-perm.h,
ov-range.cc, ov-range.h, ov-re-diag.cc, ov-re-diag.h, ov-re-mat.cc,
ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.cc,
ov-scalar.h, ov-str-mat.cc, ov-str-mat.h, ov-struct.cc, ov-struct.h,
ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc,
ov-usr-fcn.h, ov.cc, ov.h, pt-const.cc, pt-const.h, idx-vector.cc,
idx-vector.h: Delete uses of oct-alloc.h and OCTAVE_ALLOCATOR macros.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 13:43:29 -0500 |
parents | 6c9ea5be96bf |
children | 4197fc428c7d |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17643
diff
changeset
|
3 Copyright (C) 1996-2013 John W. Eaton |
11523 | 4 Copyright (C) 2009-2010 VZLU Prague |
2376 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
7528
26d8a92644de
try to avoid ctype macro problems
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
28 #include <cctype> |
26d8a92644de
try to avoid ctype macro problems
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
29 |
3503 | 30 #include <iostream> |
4726 | 31 #include <vector> |
2901 | 32 |
4944 | 33 #include "data-conv.h" |
2376 | 34 #include "lo-ieee.h" |
4944 | 35 #include "mach-info.h" |
2376 | 36 #include "mx-base.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
37 #include "oct-locbuf.h" |
2376 | 38 |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
39 #include "byte-swap.h" |
5758 | 40 #include "defun.h" |
41 #include "gripes.h" | |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
42 #include "ls-ascii-helper.h" |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
43 #include "ls-hdf5.h" |
5758 | 44 #include "ls-oct-ascii.h" |
45 #include "ls-utils.h" | |
2407 | 46 #include "oct-obj.h" |
4944 | 47 #include "oct-stream.h" |
2376 | 48 #include "ops.h" |
5033 | 49 #include "ov-scalar.h" |
2376 | 50 #include "ov-re-mat.h" |
51 #include "ov-str-mat.h" | |
52 #include "pr-output.h" | |
3836 | 53 #include "pt-mat.h" |
5758 | 54 #include "utils.h" |
4687 | 55 |
2376 | 56 |
4612 | 57 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_char_matrix_str, "string", "char"); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_char_matrix_sq_str, "sq_string", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 "char"); |
2376 | 60 |
5759 | 61 static octave_base_value * |
62 default_numeric_conversion_function (const octave_base_value& a) | |
2376 | 63 { |
5759 | 64 octave_base_value *retval = 0; |
5033 | 65 |
2376 | 66 CAST_CONV_ARG (const octave_char_matrix_str&); |
67 | |
4668 | 68 NDArray nda = v.array_value (true); |
3203 | 69 |
9071
034800482c79
fix default string->real array conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
70 if (! error_state) |
034800482c79
fix default string->real array conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
71 { |
034800482c79
fix default string->real array conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
72 if (nda.numel () == 1) |
034800482c79
fix default string->real array conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
73 retval = new octave_scalar (nda(0)); |
034800482c79
fix default string->real array conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
74 else |
034800482c79
fix default string->real array conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
75 retval = new octave_matrix (nda); |
034800482c79
fix default string->real array conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
76 } |
5033 | 77 |
78 return retval; | |
2376 | 79 } |
80 | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8168
diff
changeset
|
81 octave_base_value::type_conv_info |
2376 | 82 octave_char_matrix_str::numeric_conversion_function (void) const |
83 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8168
diff
changeset
|
84 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8168
diff
changeset
|
85 octave_matrix::static_type_id ()); |
2376 | 86 } |
87 | |
88 octave_value | |
5400 | 89 octave_char_matrix_str::do_index_op_internal (const octave_value_list& idx, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
90 bool resize_ok, char type) |
2407 | 91 { |
92 octave_value retval; | |
93 | |
5275 | 94 octave_idx_type len = idx.length (); |
2407 | 95 |
96 switch (len) | |
97 { | |
5539 | 98 case 0: |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9071
diff
changeset
|
99 retval = octave_value (matrix, type); |
2407 | 100 break; |
101 | |
102 case 1: | |
103 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
104 idx_vector i = idx (0).index_vector (); |
2407 | 105 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
107 retval = octave_value (charNDArray (matrix.index (i, resize_ok)), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
108 type); |
2407 | 109 } |
110 break; | |
111 | |
5539 | 112 case 2: |
113 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
114 idx_vector i = idx (0).index_vector (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
115 idx_vector j = idx (1).index_vector (); |
5539 | 116 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
117 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 retval = octave_value (charNDArray (matrix.index (i, j, resize_ok)), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
119 type); |
5539 | 120 } |
5435 | 121 break; |
122 | |
2407 | 123 default: |
4513 | 124 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
125 Array<idx_vector> idx_vec (dim_vector (len, 1)); |
4513 | 126 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
127 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
128 idx_vec(i) = idx(i).index_vector (); |
4513 | 129 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
130 if (! error_state) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
131 retval = |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
132 octave_value (charNDArray (matrix.index (idx_vec, resize_ok)), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
133 type); |
4513 | 134 } |
2407 | 135 break; |
136 } | |
137 | |
138 return retval; | |
139 } | |
140 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
141 octave_value |
5731 | 142 octave_char_matrix_str::resize (const dim_vector& dv, bool fill) const |
143 { | |
144 charNDArray retval (matrix); | |
145 if (fill) | |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
146 retval.resize (dv, 0); |
5731 | 147 else |
148 retval.resize (dv); | |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9071
diff
changeset
|
149 return octave_value (retval, is_sq_string () ? '\'' : '"'); |
5731 | 150 } |
151 | |
4668 | 152 #define CHAR_MATRIX_CONV(T, INIT, TNAME, FCN) \ |
153 T retval INIT; \ | |
154 \ | |
155 if (! force_string_conv) \ | |
156 gripe_invalid_conversion ("string", TNAME); \ | |
157 else \ | |
158 { \ | |
5878 | 159 warning_with_id ("Octave:str-to-num", \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 "implicit conversion from %s to %s", \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
161 "string", TNAME); \ |
4668 | 162 \ |
163 retval = octave_char_matrix::FCN (); \ | |
164 } \ | |
165 \ | |
166 return retval | |
167 | |
4643 | 168 double |
169 octave_char_matrix_str::double_value (bool force_string_conv) const | |
170 { | |
4668 | 171 CHAR_MATRIX_CONV (double, = 0, "real scalar", double_value); |
172 } | |
4643 | 173 |
4668 | 174 Complex |
175 octave_char_matrix_str::complex_value (bool force_string_conv) const | |
176 { | |
177 CHAR_MATRIX_CONV (Complex, = 0, "complex scalar", complex_value); | |
4643 | 178 } |
179 | |
2376 | 180 Matrix |
181 octave_char_matrix_str::matrix_value (bool force_string_conv) const | |
182 { | |
4668 | 183 CHAR_MATRIX_CONV (Matrix, , "real matrix", matrix_value); |
184 } | |
185 | |
186 ComplexMatrix | |
187 octave_char_matrix_str::complex_matrix_value (bool force_string_conv) const | |
188 { | |
189 CHAR_MATRIX_CONV (ComplexMatrix, , "complex matrix", complex_matrix_value); | |
190 } | |
2376 | 191 |
4668 | 192 NDArray |
193 octave_char_matrix_str::array_value (bool force_string_conv) const | |
194 { | |
195 CHAR_MATRIX_CONV (NDArray, , "real N-d array", array_value); | |
196 } | |
2376 | 197 |
4668 | 198 ComplexNDArray |
199 octave_char_matrix_str::complex_array_value (bool force_string_conv) const | |
200 { | |
201 CHAR_MATRIX_CONV (ComplexNDArray, , "complex N-d array", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
202 complex_array_value); |
2376 | 203 } |
204 | |
2493 | 205 string_vector |
5715 | 206 octave_char_matrix_str::all_strings (bool) const |
2376 | 207 { |
4513 | 208 string_vector retval; |
209 | |
210 if (matrix.ndims () == 2) | |
211 { | |
19350
6c9ea5be96bf
Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents:
18099
diff
changeset
|
212 charMatrix chm (matrix); |
4513 | 213 |
6816 | 214 octave_idx_type n = chm.rows (); |
2493 | 215 |
6816 | 216 retval.resize (n); |
2493 | 217 |
6816 | 218 for (octave_idx_type i = 0; i < n; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
219 retval[i] = chm.row_as_string (i); |
4513 | 220 } |
221 else | |
222 error ("invalid conversion of charNDArray to string_vector"); | |
2493 | 223 |
224 return retval; | |
2376 | 225 } |
226 | |
3536 | 227 std::string |
4457 | 228 octave_char_matrix_str::string_value (bool) const |
2376 | 229 { |
4513 | 230 std::string retval; |
231 | |
232 if (matrix.ndims () == 2) | |
233 { | |
19350
6c9ea5be96bf
Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents:
18099
diff
changeset
|
234 charMatrix chm (matrix); |
4513 | 235 |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17825
diff
changeset
|
236 retval = chm.row_as_string (0); // FIXME? |
4513 | 237 } |
238 else | |
239 error ("invalid conversion of charNDArray to string"); | |
240 | |
241 return retval; | |
2376 | 242 } |
243 | |
10729
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
244 Array<std::string> |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
245 octave_char_matrix_str::cellstr_value (void) const |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
246 { |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
247 Array<std::string> retval; |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
248 |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
249 if (matrix.ndims () == 2) |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
250 { |
19350
6c9ea5be96bf
Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents:
18099
diff
changeset
|
251 const charMatrix chm (matrix); |
10729
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
252 octave_idx_type nr = chm.rows (); |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
253 retval.clear (nr, 1); |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
254 for (octave_idx_type i = 0; i < nr; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
255 retval.xelem (i) = chm.row_as_string (i); |
10729
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
256 } |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
257 else |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
258 error ("cellstr: cannot convert multidimensional arrays"); |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
259 |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
260 return retval; |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
261 } |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
262 |
2376 | 263 void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
264 octave_char_matrix_str::print_raw (std::ostream& os, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
265 bool pr_as_read_syntax) const |
2376 | 266 { |
3219 | 267 octave_print_internal (os, matrix, pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 current_print_indent_level (), true); |
2376 | 269 } |
270 | |
17870 | 271 void |
272 octave_char_matrix_str::short_disp (std::ostream& os) const | |
17825
53f433bae63b
display (possibly truncated) values of strings in workspace view
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
273 { |
53f433bae63b
display (possibly truncated) values of strings in workspace view
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
274 if (matrix.ndims () == 2 && numel () > 0) |
53f433bae63b
display (possibly truncated) values of strings in workspace view
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
275 { |
17870 | 276 std::string tmp = string_value (); |
17825
53f433bae63b
display (possibly truncated) values of strings in workspace view
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
277 |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17825
diff
changeset
|
278 // FIXME: should this be configurable? |
17870 | 279 size_t max_len = 100; |
17825
53f433bae63b
display (possibly truncated) values of strings in workspace view
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
280 |
17876
b951a8351fd7
Fix display of char arrays in GUI Variable window.
Rik <rik@octave.org>
parents:
17870
diff
changeset
|
281 os << (tmp.length () > max_len ? tmp.substr (0, 100) : tmp); |
17825
53f433bae63b
display (possibly truncated) values of strings in workspace view
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
282 } |
53f433bae63b
display (possibly truncated) values of strings in workspace view
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
283 } |
53f433bae63b
display (possibly truncated) values of strings in workspace view
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
284 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
285 bool |
6974 | 286 octave_char_matrix_str::save_ascii (std::ostream& os) |
4687 | 287 { |
4805 | 288 dim_vector d = dims (); |
289 if (d.length () > 2) | |
290 { | |
291 charNDArray tmp = char_array_value (); | |
292 os << "# ndims: " << d.length () << "\n"; | |
293 for (int i=0; i < d.length (); i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 os << " " << d (i); |
4805 | 295 os << "\n"; |
5760 | 296 os.write (tmp.fortran_vec (), d.numel ()); |
4805 | 297 os << "\n"; |
298 } | |
299 else | |
4687 | 300 { |
4805 | 301 // Keep this case, rather than use generic code above for |
302 // backward compatiability. Makes load_ascii much more complex!! | |
303 charMatrix chm = char_matrix_value (); | |
5275 | 304 octave_idx_type elements = chm.rows (); |
4805 | 305 os << "# elements: " << elements << "\n"; |
5275 | 306 for (octave_idx_type i = 0; i < elements; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
307 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
308 unsigned len = chm.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
309 os << "# length: " << len << "\n"; |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10729
diff
changeset
|
310 std::string tstr = chm.row_as_string (i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 const char *tmp = tstr.data (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 if (tstr.length () > len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 os.write (tmp, len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
316 } |
4687 | 317 } |
318 | |
319 return true; | |
320 } | |
321 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
322 bool |
4687 | 323 octave_char_matrix_str::load_ascii (std::istream& is) |
324 { | |
325 bool success = true; | |
5099 | 326 |
327 string_vector keywords(3); | |
328 | |
329 keywords[0] = "ndims"; | |
330 keywords[1] = "elements"; | |
331 keywords[2] = "length"; | |
332 | |
333 std::string kw; | |
334 int val = 0; | |
4687 | 335 |
5099 | 336 if (extract_keyword (is, keywords, kw, val, true)) |
4687 | 337 { |
5099 | 338 if (kw == "ndims") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
339 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
340 int mdims = val; |
5099 | 341 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
342 if (mdims >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
343 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
344 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
345 dv.resize (mdims); |
4805 | 346 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
347 for (int i = 0; i < mdims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
348 is >> dv(i); |
4687 | 349 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
350 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
351 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
352 charNDArray tmp(dv); |
6717 | 353 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
354 if (tmp.is_empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
355 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
356 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
357 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
358 char *ftmp = tmp.fortran_vec (); |
5099 | 359 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
360 skip_preceeding_newline (is); |
4805 | 361 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
362 if (! is.read (ftmp, dv.numel ()) || !is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
363 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
364 error ("load: failed to load string constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
365 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
366 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
367 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
368 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
369 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
370 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
371 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
373 error ("load: failed to read dimensions"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
375 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
376 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
377 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
378 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
379 error ("load: failed to extract matrix size"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
380 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
381 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
382 } |
5099 | 383 else if (kw == "elements") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
384 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
385 int elements = val; |
4805 | 386 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
387 if (elements >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
388 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
389 // FIXME: need to be able to get max length before doing anything. |
4687 | 390 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
391 charMatrix chm (elements, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
392 int max_len = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
393 for (int i = 0; i < elements; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
394 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
395 int len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
396 if (extract_keyword (is, "length", len) && len >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
397 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
398 // Use this instead of a C-style character |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 // buffer so that we can properly handle |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 // embedded NUL characters. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
401 charMatrix tmp (1, len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 char *ptmp = tmp.fortran_vec (); |
6151 | 403 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
404 if (len > 0 && ! is.read (ptmp, len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
405 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 error ("load: failed to load string constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
407 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
408 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
409 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
410 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
411 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 if (len > max_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
413 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
414 max_len = len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
415 chm.resize (elements, max_len, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
416 } |
6151 | 417 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
418 chm.insert (tmp, i, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
419 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
420 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
421 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
422 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
423 error ("load: failed to extract string length for element %d", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
424 i+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
425 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
426 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
427 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
428 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
429 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
430 matrix = chm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
431 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
432 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
433 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
434 error ("load: failed to extract number of string elements"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
435 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
436 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
437 } |
5099 | 438 else if (kw == "length") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
439 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
440 int len = val; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
441 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
442 if (len >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
443 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
444 // This is cruft for backward compatiability, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
445 // but relatively harmless. |
4805 | 446 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
447 // Use this instead of a C-style character buffer so |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
448 // that we can properly handle embedded NUL characters. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
449 charMatrix tmp (1, len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
450 char *ptmp = tmp.fortran_vec (); |
4805 | 451 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
452 if (len > 0 && ! is.read (ptmp, len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
453 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
454 error ("load: failed to load string constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
455 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
456 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
457 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
458 if (is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
459 matrix = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
460 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
461 error ("load: failed to load string constant"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
462 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
463 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
464 } |
5099 | 465 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
466 panic_impossible (); |
5099 | 467 } |
468 else | |
469 { | |
470 error ("load: failed to extract number of rows and columns"); | |
471 success = false; | |
4687 | 472 } |
473 | |
474 return success; | |
475 } | |
476 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
477 bool |
4687 | 478 octave_char_matrix_str::save_binary (std::ostream& os, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
479 bool& /* save_as_floats */) |
4687 | 480 { |
4805 | 481 dim_vector d = dims (); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14616
diff
changeset
|
482 if (d.length () < 1) |
4805 | 483 return false; |
484 | |
485 // Use negative value for ndims to differentiate with old format!! | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14616
diff
changeset
|
486 int32_t tmp = - d.length (); |
5760 | 487 os.write (reinterpret_cast<char *> (&tmp), 4); |
4805 | 488 for (int i=0; i < d.length (); i++) |
4687 | 489 { |
4805 | 490 tmp = d(i); |
5760 | 491 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687 | 492 } |
4805 | 493 |
494 charNDArray m = char_array_value (); | |
495 os.write (m.fortran_vec (), d.numel ()); | |
4687 | 496 return true; |
497 } | |
498 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
499 bool |
4687 | 500 octave_char_matrix_str::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
501 oct_mach_info::float_format /* fmt */) |
4687 | 502 { |
5828 | 503 int32_t elements; |
5760 | 504 if (! is.read (reinterpret_cast<char *> (&elements), 4)) |
4687 | 505 return false; |
506 if (swap) | |
4944 | 507 swap_bytes<4> (&elements); |
4805 | 508 |
509 if (elements < 0) | |
4687 | 510 { |
5828 | 511 int32_t mdims = - elements; |
512 int32_t di; | |
4805 | 513 dim_vector dv; |
514 dv.resize (mdims); | |
515 | |
516 for (int i = 0; i < mdims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
517 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
519 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
520 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
521 swap_bytes<4> (&di); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 dv(i) = di; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
523 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
524 |
5157 | 525 // Convert an array with a single dimension to be a row vector. |
526 // Octave should never write files like this, other software | |
527 // might. | |
528 | |
529 if (mdims == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
530 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
531 mdims = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
532 dv.resize (mdims); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
533 dv(1) = dv(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
534 dv(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
535 } |
5157 | 536 |
4805 | 537 charNDArray m(dv); |
538 char *tmp = m.fortran_vec (); | |
539 is.read (tmp, dv.numel ()); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
540 |
4805 | 541 if (error_state || ! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
542 return false; |
4805 | 543 matrix = m; |
544 } | |
545 else | |
546 { | |
547 charMatrix chm (elements, 0); | |
548 int max_len = 0; | |
549 for (int i = 0; i < elements; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
550 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
551 int32_t len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
552 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
553 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
554 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
555 swap_bytes<4> (&len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
556 charMatrix btmp (1, len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
557 char *pbtmp = btmp.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
558 if (! is.read (pbtmp, len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
559 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
560 if (len > max_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
561 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
562 max_len = len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
563 chm.resize (elements, max_len, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
564 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
565 chm.insert (btmp, i, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
566 } |
4805 | 567 matrix = chm; |
4687 | 568 } |
569 return true; | |
570 } | |
571 | |
572 #if defined (HAVE_HDF5) | |
4944 | 573 |
4687 | 574 bool |
575 octave_char_matrix_str::save_hdf5 (hid_t loc_id, const char *name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
576 bool /* save_as_floats */) |
4687 | 577 { |
4837 | 578 dim_vector dv = dims (); |
579 int empty = save_hdf5_empty (loc_id, name, dv); | |
580 if (empty) | |
4805 | 581 return (empty > 0); |
4687 | 582 |
4837 | 583 int rank = dv.length (); |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17876
diff
changeset
|
584 hid_t space_hid, data_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17876
diff
changeset
|
585 space_hid = data_hid = -1; |
4805 | 586 bool retval = true; |
587 charNDArray m = char_array_value (); | |
588 | |
589 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
4687 | 590 |
4805 | 591 // Octave uses column-major, while HDF5 uses row-major ordering |
592 for (int i = 0; i < rank; i++) | |
4837 | 593 hdims[i] = dv (rank-i-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
594 |
4815 | 595 space_hid = H5Screate_simple (rank, hdims, 0); |
4805 | 596 if (space_hid < 0) |
597 return false; | |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
598 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
599 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
600 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
601 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
602 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
603 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
604 #endif |
4805 | 605 if (data_hid < 0) |
4687 | 606 { |
4805 | 607 H5Sclose (space_hid); |
4687 | 608 return false; |
609 } | |
610 | |
4837 | 611 OCTAVE_LOCAL_BUFFER (char, s, dv.numel ()); |
4687 | 612 |
4837 | 613 for (int i = 0; i < dv.numel (); ++i) |
4805 | 614 s[i] = m(i); |
4687 | 615 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
616 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
617 H5P_DEFAULT, s) >= 0; |
4687 | 618 |
619 H5Dclose (data_hid); | |
620 H5Sclose (space_hid); | |
4837 | 621 |
4687 | 622 return retval; |
623 } | |
624 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
625 bool |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9689
diff
changeset
|
626 octave_char_matrix_str::load_hdf5 (hid_t loc_id, const char *name) |
4687 | 627 { |
4837 | 628 bool retval = false; |
629 | |
4805 | 630 dim_vector dv; |
631 int empty = load_hdf5_empty (loc_id, name, dv); | |
632 if (empty > 0) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
633 matrix.resize (dv); |
4837 | 634 if (empty) |
635 return (empty > 0); | |
4805 | 636 |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
637 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
638 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
639 #else |
4687 | 640 hid_t data_hid = H5Dopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
641 #endif |
4687 | 642 hid_t space_hid = H5Dget_space (data_hid); |
643 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); | |
644 hid_t type_hid = H5Dget_type (data_hid); | |
4805 | 645 hid_t type_class_hid = H5Tget_class (type_hid); |
4687 | 646 |
4805 | 647 if (type_class_hid == H5T_INTEGER) |
4687 | 648 { |
4805 | 649 if (rank < 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
650 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
651 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
652 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
653 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
654 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
655 } |
4805 | 656 |
657 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
658 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
659 | |
660 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
661 | |
662 // Octave uses column-major, while HDF5 uses row-major ordering | |
663 if (rank == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
664 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
665 dv.resize (2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
666 dv(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
667 dv(1) = hdims[0]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
668 } |
4687 | 669 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
670 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
671 dv.resize (rank); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
672 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
673 dv(j) = hdims[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
674 } |
4805 | 675 |
676 charNDArray m (dv); | |
677 char *str = m.fortran_vec (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
678 if (H5Dread (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
679 H5P_DEFAULT, str) >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
680 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
681 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
682 matrix = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
683 } |
4805 | 684 |
685 H5Tclose (type_hid); | |
686 H5Sclose (space_hid); | |
687 H5Dclose (data_hid); | |
688 return true; | |
689 } | |
690 else | |
691 { | |
692 // This is cruft for backward compatiability and easy data | |
693 // importation | |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
694 if (rank == 0) //FIXME: Does rank==0 even exist for strings in HDF5? |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
695 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
696 // a single string: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
697 int slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
698 if (slen < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
699 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
700 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
701 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
702 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
703 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
704 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
705 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
706 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
707 OCTAVE_LOCAL_BUFFER (char, s, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
708 // create datatype for (null-terminated) string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
709 // to read into: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
710 hid_t st_id = H5Tcopy (H5T_C_S1); |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
711 H5Tset_size (st_id, slen+1); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
712 if (H5Dread (data_hid, st_id, H5S_ALL, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
713 H5S_ALL, H5P_DEFAULT, s) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
714 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
715 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
716 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
717 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
718 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
719 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
720 } |
4687 | 721 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
722 matrix = charMatrix (s); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
723 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
724 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
725 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
726 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
727 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
728 return true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
729 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 } |
4805 | 731 else if (rank == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
732 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
733 // string vector |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
734 hsize_t elements, maxdim; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
735 H5Sget_simple_extent_dims (space_hid, &elements, &maxdim); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
736 int slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
737 if (slen < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
738 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
739 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
740 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
741 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
742 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
743 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
744 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
745 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
746 // hdf5 string arrays store strings of all the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
747 // same physical length (I think), which is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
748 // slightly wasteful, but oh well. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
749 |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
750 OCTAVE_LOCAL_BUFFER (char, s, elements * (slen+1)); |
4805 | 751 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
752 // create datatype for (null-terminated) string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 // to read into: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
754 hid_t st_id = H5Tcopy (H5T_C_S1); |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
755 H5Tset_size (st_id, slen+1); |
4805 | 756 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
757 if (H5Dread (data_hid, st_id, H5S_ALL, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
758 H5S_ALL, H5P_DEFAULT, s) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
759 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
760 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
761 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
762 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
763 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
764 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
765 } |
4805 | 766 |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
767 charMatrix chm (elements, slen, ' '); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
768 for (hsize_t i = 0; i < elements; ++i) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
769 { |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
770 chm.insert (s + i*(slen+1), i, 0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
771 } |
4805 | 772 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
773 matrix = chm; |
4805 | 774 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
775 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
776 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
777 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
779 return true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
780 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
781 } |
4805 | 782 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
783 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
784 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
785 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
786 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
787 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
788 } |
4687 | 789 } |
4837 | 790 |
791 return retval; | |
4687 | 792 } |
4944 | 793 |
4687 | 794 #endif |