Mercurial > octave
annotate libinterp/octave-value/ov-str-mat.cc @ 21211:2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
* configure.ac (HAVE_HDF5_INT2FLOAT_CONVERSIONS): AC_DEFINE here.
* ls-hdf5.cc (HAVE_HDF5_INT2FLOAT_CONVERSION): Delete definition.
* ls-hdf5.cc, ls-hdf5.h, ccolamd.cc, dmperm.cc, ov-base-int.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-cell.cc,
ov-class.cc, ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc,
ov-fcn-handle.cc, ov-fcn-inline.cc, ov-float.cc, ov-flt-complex.cc,
ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-java.cc, ov-range.cc,
ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc,
ov-struct.cc, pt-eval.cc:
Use #if defined (HAVE_FOO) instead of #if HAVE_FOO.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Feb 2016 08:48:47 -0500 |
parents | fcac5dbbf9ed |
children | 40de9f8f23a6 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19598
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21124
diff
changeset
|
25 # include <config.h> |
2376 | 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" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21066
diff
changeset
|
41 #include "errwarn.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" |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20218
diff
changeset
|
44 #include "ls-oct-text.h" |
5758 | 45 #include "ls-utils.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
46 #include "ovl.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
47 #include "oct-hdf5.h" |
4944 | 48 #include "oct-stream.h" |
2376 | 49 #include "ops.h" |
5033 | 50 #include "ov-scalar.h" |
2376 | 51 #include "ov-re-mat.h" |
52 #include "ov-str-mat.h" | |
53 #include "pr-output.h" | |
3836 | 54 #include "pt-mat.h" |
5758 | 55 #include "utils.h" |
4687 | 56 |
2376 | 57 |
4612 | 58 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
|
59 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
|
60 "char"); |
2376 | 61 |
5759 | 62 static octave_base_value * |
63 default_numeric_conversion_function (const octave_base_value& a) | |
2376 | 64 { |
5759 | 65 octave_base_value *retval = 0; |
5033 | 66 |
2376 | 67 CAST_CONV_ARG (const octave_char_matrix_str&); |
68 | |
4668 | 69 NDArray nda = v.array_value (true); |
3203 | 70 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
71 if (nda.numel () == 1) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
72 retval = new octave_scalar (nda(0)); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
73 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
74 retval = new octave_matrix (nda); |
5033 | 75 |
76 return retval; | |
2376 | 77 } |
78 | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8168
diff
changeset
|
79 octave_base_value::type_conv_info |
2376 | 80 octave_char_matrix_str::numeric_conversion_function (void) const |
81 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8168
diff
changeset
|
82 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8168
diff
changeset
|
83 octave_matrix::static_type_id ()); |
2376 | 84 } |
85 | |
86 octave_value | |
5400 | 87 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
|
88 bool resize_ok, char type) |
2407 | 89 { |
90 octave_value retval; | |
91 | |
5275 | 92 octave_idx_type len = idx.length (); |
2407 | 93 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
94 // If we catch an indexing error in index_vector, we flag an error in |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
95 // index k. Ensure it is the right value befor each idx_vector call. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
96 // Same variable as used in the for loop in the default case. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
97 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
98 octave_idx_type k = 0; |
2407 | 99 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
100 try |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
101 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
102 switch (len) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
103 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
104 case 0: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
105 retval = octave_value (matrix, type); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
106 break; |
2407 | 107 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
108 case 1: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
109 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
110 idx_vector i = idx (0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
111 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
112 retval = octave_value (charNDArray (matrix.index (i, resize_ok)), |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
113 type); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
114 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
115 break; |
2407 | 116 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
117 case 2: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
118 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
119 idx_vector i = idx (0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
120 k = 1; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
121 idx_vector j = idx (1).index_vector (); |
5539 | 122 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
123 retval = octave_value (charNDArray (matrix.index (i, j, resize_ok)), |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
124 type); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
125 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
126 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
127 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
128 default: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
129 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
130 Array<idx_vector> idx_vec (dim_vector (len, 1)); |
5435 | 131 |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
132 for (k = 0; k < len; k++) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
133 idx_vec(k) = idx(k).index_vector (); |
4513 | 134 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
135 retval = |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
136 octave_value (charNDArray (matrix.index (idx_vec, resize_ok)), |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
137 type); |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
138 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
139 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
140 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
141 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
142 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
143 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
144 // Rethrow to allow more info to be reported later. |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
145 e.set_pos_if_unset (len, k+1); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20449
diff
changeset
|
146 throw; |
2407 | 147 } |
148 | |
149 return retval; | |
150 } | |
151 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
152 octave_value |
5731 | 153 octave_char_matrix_str::resize (const dim_vector& dv, bool fill) const |
154 { | |
155 charNDArray retval (matrix); | |
156 if (fill) | |
14616
13cc11418393
improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
157 retval.resize (dv, 0); |
5731 | 158 else |
159 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
|
160 return octave_value (retval, is_sq_string () ? '\'' : '"'); |
5731 | 161 } |
162 | |
4668 | 163 #define CHAR_MATRIX_CONV(T, INIT, TNAME, FCN) \ |
164 T retval INIT; \ | |
165 \ | |
166 if (! force_string_conv) \ | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21066
diff
changeset
|
167 err_invalid_conversion ("string", TNAME); \ |
4668 | 168 \ |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
169 warning_with_id ("Octave:str-to-num", \ |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
170 "implicit conversion from %s to %s", \ |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
171 "string", TNAME); \ |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
172 \ |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
173 retval = octave_char_matrix::FCN (); \ |
4668 | 174 \ |
175 return retval | |
176 | |
4643 | 177 double |
178 octave_char_matrix_str::double_value (bool force_string_conv) const | |
179 { | |
4668 | 180 CHAR_MATRIX_CONV (double, = 0, "real scalar", double_value); |
181 } | |
4643 | 182 |
4668 | 183 Complex |
184 octave_char_matrix_str::complex_value (bool force_string_conv) const | |
185 { | |
186 CHAR_MATRIX_CONV (Complex, = 0, "complex scalar", complex_value); | |
4643 | 187 } |
188 | |
2376 | 189 Matrix |
190 octave_char_matrix_str::matrix_value (bool force_string_conv) const | |
191 { | |
4668 | 192 CHAR_MATRIX_CONV (Matrix, , "real matrix", matrix_value); |
193 } | |
194 | |
195 ComplexMatrix | |
196 octave_char_matrix_str::complex_matrix_value (bool force_string_conv) const | |
197 { | |
198 CHAR_MATRIX_CONV (ComplexMatrix, , "complex matrix", complex_matrix_value); | |
199 } | |
2376 | 200 |
4668 | 201 NDArray |
202 octave_char_matrix_str::array_value (bool force_string_conv) const | |
203 { | |
21014
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
204 CHAR_MATRIX_CONV (NDArray, , "real N-D array", array_value); |
4668 | 205 } |
2376 | 206 |
4668 | 207 ComplexNDArray |
208 octave_char_matrix_str::complex_array_value (bool force_string_conv) const | |
209 { | |
21014
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
210 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
|
211 complex_array_value); |
2376 | 212 } |
213 | |
2493 | 214 string_vector |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20979
diff
changeset
|
215 octave_char_matrix_str::string_vector_value (bool) const |
2376 | 216 { |
4513 | 217 string_vector retval; |
218 | |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
219 if (matrix.ndims () != 2) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
220 error ("invalid conversion of charNDArray to string_vector"); |
4513 | 221 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
222 charMatrix chm (matrix); |
2493 | 223 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
224 octave_idx_type n = chm.rows (); |
2493 | 225 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
226 retval.resize (n); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
227 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
228 for (octave_idx_type i = 0; i < n; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
229 retval[i] = chm.row_as_string (i); |
2493 | 230 |
231 return retval; | |
2376 | 232 } |
233 | |
3536 | 234 std::string |
4457 | 235 octave_char_matrix_str::string_value (bool) const |
2376 | 236 { |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
237 if (matrix.ndims () != 2) |
4513 | 238 error ("invalid conversion of charNDArray to string"); |
239 | |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
240 charMatrix chm (matrix); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
241 |
21066
258c787cd9ce
maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
242 // FIXME: Is this correct? |
258c787cd9ce
maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
243 return chm.row_as_string (0); |
2376 | 244 } |
245 | |
10729
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
246 Array<std::string> |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
247 octave_char_matrix_str::cellstr_value (void) const |
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 Array<std::string> retval; |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
250 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
251 if (matrix.ndims () != 2) |
10729
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
252 error ("cellstr: cannot convert multidimensional arrays"); |
172253d75d94
implement cellstr extractors for char matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10552
diff
changeset
|
253 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
254 const charMatrix chm (matrix); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
255 octave_idx_type nr = chm.rows (); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
256 retval.clear (nr, 1); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
257 for (octave_idx_type i = 0; i < nr; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
258 retval.xelem (i) = chm.row_as_string (i); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
259 |
10729
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++) | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19863
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 |
20449
df4165dfc676
maint: Fix misspelled word compatibility in code comments.
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
302 // backward compatibility. Makes load_ascii much more complex!! |
4805 | 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 { | |
5099 | 325 string_vector keywords(3); |
326 | |
327 keywords[0] = "ndims"; | |
328 keywords[1] = "elements"; | |
329 keywords[2] = "length"; | |
330 | |
331 std::string kw; | |
332 int val = 0; | |
4687 | 333 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
334 if (! extract_keyword (is, keywords, kw, val, true)) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
335 error ("load: failed to extract number of rows and columns"); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
336 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
337 if (kw == "ndims") |
4687 | 338 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
339 int mdims = val; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
340 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
341 if (mdims < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
342 error ("load: failed to extract matrix size"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
343 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
344 dim_vector dv; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
345 dv.resize (mdims); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
346 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
347 for (int i = 0; i < mdims; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
348 is >> dv(i); |
5099 | 349 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
350 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
351 error ("load: failed to read dimensions"); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
352 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
353 charNDArray tmp(dv); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
354 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
355 if (tmp.is_empty ()) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
356 matrix = tmp; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
357 else |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
358 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
359 char *ftmp = tmp.fortran_vec (); |
4805 | 360 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
361 skip_preceeding_newline (is); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
362 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
363 if (! is.read (ftmp, dv.numel ()) || ! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
364 error ("load: failed to load string constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
365 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
366 matrix = tmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
367 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
368 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
369 else if (kw == "elements") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
370 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
371 int elements = val; |
4687 | 372 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
373 if (elements < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
374 error ("load: failed to extract number of string elements"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
375 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
376 // FIXME: need to be able to get max length before doing anything. |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
377 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
378 charMatrix chm (elements, 0); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
379 int max_len = 0; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
380 for (int i = 0; i < elements; i++) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
381 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
382 int len; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
383 if (! extract_keyword (is, "length", len) || len < 0) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
384 error ("load: failed to extract string length for element %d", |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
385 i+1); |
6717 | 386 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
387 // Use this instead of a C-style character |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
388 // buffer so that we can properly handle |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
389 // embedded NUL characters. |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
390 charMatrix tmp (1, len); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
391 char *ptmp = tmp.fortran_vec (); |
4805 | 392 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
393 if (len > 0 && ! is.read (ptmp, len)) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
394 error ("load: failed to load string constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
395 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
396 if (len > max_len) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
397 { |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
398 max_len = len; |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
399 chm.resize (elements, max_len, 0); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 } |
4687 | 401 |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
402 chm.insert (tmp, i, 0); |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
403 } |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
404 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
405 matrix = chm; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
406 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
407 else if (kw == "length") |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
408 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
409 int len = val; |
6151 | 410 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
411 if (len >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
413 // This is cruft for backward compatibility, |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
414 // but relatively harmless. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
415 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
416 // Use this instead of a C-style character buffer so |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
417 // that we can properly handle embedded NUL characters. |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
418 charMatrix tmp (1, len); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
419 char *ptmp = tmp.fortran_vec (); |
4805 | 420 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
421 if (len > 0 && ! is.read (ptmp, len)) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
422 error ("load: failed to load string constant"); |
20979
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
423 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
424 if (! is) |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
425 error ("load: failed to load string constant"); |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
426 |
0963ed389012
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
427 matrix = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
428 } |
5099 | 429 } |
430 else | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20956
diff
changeset
|
431 panic_impossible (); |
4687 | 432 |
21124
95f8c8cdbffe
maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
433 return true; |
4687 | 434 } |
435 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
436 bool |
4687 | 437 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
|
438 bool& /* save_as_floats */) |
4687 | 439 { |
4805 | 440 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
|
441 if (d.length () < 1) |
4805 | 442 return false; |
443 | |
444 // 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
|
445 int32_t tmp = - d.length (); |
5760 | 446 os.write (reinterpret_cast<char *> (&tmp), 4); |
4805 | 447 for (int i=0; i < d.length (); i++) |
4687 | 448 { |
4805 | 449 tmp = d(i); |
5760 | 450 os.write (reinterpret_cast<char *> (&tmp), 4); |
4687 | 451 } |
4805 | 452 |
453 charNDArray m = char_array_value (); | |
454 os.write (m.fortran_vec (), d.numel ()); | |
4687 | 455 return true; |
456 } | |
457 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
458 bool |
4687 | 459 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
|
460 oct_mach_info::float_format /* fmt */) |
4687 | 461 { |
5828 | 462 int32_t elements; |
5760 | 463 if (! is.read (reinterpret_cast<char *> (&elements), 4)) |
4687 | 464 return false; |
465 if (swap) | |
4944 | 466 swap_bytes<4> (&elements); |
4805 | 467 |
468 if (elements < 0) | |
4687 | 469 { |
5828 | 470 int32_t mdims = - elements; |
471 int32_t di; | |
4805 | 472 dim_vector dv; |
473 dv.resize (mdims); | |
474 | |
475 for (int i = 0; i < mdims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
476 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
477 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
478 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
479 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
480 swap_bytes<4> (&di); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
481 dv(i) = di; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
482 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
483 |
5157 | 484 // Convert an array with a single dimension to be a row vector. |
485 // Octave should never write files like this, other software | |
486 // might. | |
487 | |
488 if (mdims == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
489 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
490 mdims = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
491 dv.resize (mdims); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
492 dv(1) = dv(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
493 dv(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
494 } |
5157 | 495 |
4805 | 496 charNDArray m(dv); |
497 char *tmp = m.fortran_vec (); | |
498 is.read (tmp, dv.numel ()); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
499 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
500 if (! is) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
501 return false; |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
502 |
4805 | 503 matrix = m; |
504 } | |
505 else | |
506 { | |
507 charMatrix chm (elements, 0); | |
508 int max_len = 0; | |
509 for (int i = 0; i < elements; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
510 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
511 int32_t len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
512 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
513 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
514 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
515 swap_bytes<4> (&len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
516 charMatrix btmp (1, len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
517 char *pbtmp = btmp.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 if (! is.read (pbtmp, len)) |
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 (len > max_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
521 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 max_len = len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
523 chm.resize (elements, max_len, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
524 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
525 chm.insert (btmp, i, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
526 } |
4805 | 527 matrix = chm; |
4687 | 528 } |
529 return true; | |
530 } | |
531 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
532 bool |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
533 octave_char_matrix_str::save_hdf5 (octave_hdf5_id loc_id, const char *name, |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
534 bool /* save_as_floats */) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
535 { |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
536 bool retval = false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
537 |
4687 | 538 #if defined (HAVE_HDF5) |
4944 | 539 |
4837 | 540 dim_vector dv = dims (); |
541 int empty = save_hdf5_empty (loc_id, name, dv); | |
542 if (empty) | |
4805 | 543 return (empty > 0); |
4687 | 544 |
4837 | 545 int rank = dv.length (); |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17876
diff
changeset
|
546 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
|
547 space_hid = data_hid = -1; |
4805 | 548 charNDArray m = char_array_value (); |
549 | |
550 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
4687 | 551 |
4805 | 552 // Octave uses column-major, while HDF5 uses row-major ordering |
553 for (int i = 0; i < rank; i++) | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19863
diff
changeset
|
554 hdims[i] = dv(rank-i-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
555 |
4815 | 556 space_hid = H5Screate_simple (rank, hdims, 0); |
4805 | 557 if (space_hid < 0) |
558 return false; | |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
559 #if defined (HAVE_HDF5_18) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
560 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
561 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
562 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
563 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
564 octave_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
|
565 #endif |
4805 | 566 if (data_hid < 0) |
4687 | 567 { |
4805 | 568 H5Sclose (space_hid); |
4687 | 569 return false; |
570 } | |
571 | |
4837 | 572 OCTAVE_LOCAL_BUFFER (char, s, dv.numel ()); |
4687 | 573 |
4837 | 574 for (int i = 0; i < dv.numel (); ++i) |
4805 | 575 s[i] = m(i); |
4687 | 576 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
577 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
578 octave_H5P_DEFAULT, s) >= 0; |
4687 | 579 |
580 H5Dclose (data_hid); | |
581 H5Sclose (space_hid); | |
4837 | 582 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
583 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
584 warn_save ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
585 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
586 |
4687 | 587 return retval; |
588 } | |
589 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
590 bool |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
591 octave_char_matrix_str::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4687 | 592 { |
4837 | 593 bool retval = false; |
594 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
595 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
596 |
4805 | 597 dim_vector dv; |
598 int empty = load_hdf5_empty (loc_id, name, dv); | |
599 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
|
600 matrix.resize (dv); |
4837 | 601 if (empty) |
602 return (empty > 0); | |
4805 | 603 |
21211
2cf8bc5c7017
use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
604 #if defined (HAVE_HDF5_18) |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
605 hid_t data_hid = H5Dopen (loc_id, name, octave_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
|
606 #else |
4687 | 607 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
|
608 #endif |
4687 | 609 hid_t space_hid = H5Dget_space (data_hid); |
610 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); | |
611 hid_t type_hid = H5Dget_type (data_hid); | |
4805 | 612 hid_t type_class_hid = H5Tget_class (type_hid); |
4687 | 613 |
4805 | 614 if (type_class_hid == H5T_INTEGER) |
4687 | 615 { |
4805 | 616 if (rank < 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
617 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
618 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
619 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
620 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
621 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
622 } |
4805 | 623 |
624 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
625 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
626 | |
627 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); | |
628 | |
629 // Octave uses column-major, while HDF5 uses row-major ordering | |
630 if (rank == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
631 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
632 dv.resize (2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
633 dv(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
634 dv(1) = hdims[0]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
635 } |
4687 | 636 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
637 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
638 dv.resize (rank); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
639 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
|
640 dv(j) = hdims[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
641 } |
4805 | 642 |
643 charNDArray m (dv); | |
644 char *str = m.fortran_vec (); | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
645 if (H5Dread (data_hid, H5T_NATIVE_CHAR, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
646 octave_H5P_DEFAULT, str) >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
647 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
648 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
649 matrix = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
650 } |
4805 | 651 |
652 H5Tclose (type_hid); | |
653 H5Sclose (space_hid); | |
654 H5Dclose (data_hid); | |
655 return true; | |
656 } | |
657 else | |
658 { | |
20449
df4165dfc676
maint: Fix misspelled word compatibility in code comments.
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
659 // This is cruft for backward compatibility and easy data |
4805 | 660 // importation |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
661 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
|
662 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
663 // a single string: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
664 int slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
665 if (slen < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
666 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
667 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
668 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
669 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
670 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
671 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
672 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
673 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
674 OCTAVE_LOCAL_BUFFER (char, s, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
675 // create datatype for (null-terminated) string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
676 // to read into: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
677 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
|
678 H5Tset_size (st_id, slen+1); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
679 if (H5Dread (data_hid, st_id, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
680 octave_H5S_ALL, octave_H5P_DEFAULT, s) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
681 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
682 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
683 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
684 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
685 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
686 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
687 } |
4687 | 688 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
689 matrix = charMatrix (s); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
690 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
691 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
692 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
693 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
694 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
695 return true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
696 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
697 } |
4805 | 698 else if (rank == 1) |
10315
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 // string vector |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
701 hsize_t elements, maxdim; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
702 H5Sget_simple_extent_dims (space_hid, &elements, &maxdim); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
703 int slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
704 if (slen < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
705 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
706 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
707 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
708 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
709 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
710 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
711 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
712 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
713 // hdf5 string arrays store strings of all the |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
714 // same physical length (I think), which is |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
715 // slightly wasteful, but oh well. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
716 |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
717 OCTAVE_LOCAL_BUFFER (char, s, elements * (slen+1)); |
4805 | 718 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
719 // create datatype for (null-terminated) string |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
720 // to read into: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
721 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
|
722 H5Tset_size (st_id, slen+1); |
4805 | 723 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
724 if (H5Dread (data_hid, st_id, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
21014
diff
changeset
|
725 octave_H5S_ALL, octave_H5P_DEFAULT, s) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
726 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
727 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
728 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
729 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
731 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
732 } |
4805 | 733 |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
734 charMatrix chm (elements, slen, ' '); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
735 for (hsize_t i = 0; i < elements; ++i) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
736 { |
17643
d0a197b9962a
Fix loading of string arrays from 3rd party hdf5 files (bug #38789)
Markus Appel <masolomaster3000@gmail.com>
parents:
15195
diff
changeset
|
737 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
|
738 } |
4805 | 739 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
740 matrix = chm; |
4805 | 741 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
742 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
743 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
744 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
745 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
746 return true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
747 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
748 } |
4805 | 749 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
750 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
751 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
752 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
754 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
755 } |
4687 | 756 } |
4837 | 757 |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
758 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
759 warn_load ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
760 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
761 |
4837 | 762 return retval; |
4687 | 763 } |