2376
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2376
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2376
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
3503
|
31 #include <iostream> |
4726
|
32 #include <vector> |
2901
|
33 |
2376
|
34 #include "lo-ieee.h" |
|
35 #include "mx-base.h" |
|
36 |
2407
|
37 #include "oct-obj.h" |
2376
|
38 #include "ops.h" |
|
39 #include "ov-re-mat.h" |
|
40 #include "ov-str-mat.h" |
|
41 #include "gripes.h" |
|
42 #include "pr-output.h" |
3836
|
43 #include "pt-mat.h" |
2376
|
44 |
4687
|
45 #include "byte-swap.h" |
|
46 #include "ls-oct-ascii.h" |
|
47 #include "ls-hdf5.h" |
|
48 #include "ls-utils.h" |
|
49 |
3219
|
50 DEFINE_OCTAVE_ALLOCATOR (octave_char_matrix_str); |
2376
|
51 |
4612
|
52 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_char_matrix_str, "string", "char"); |
2376
|
53 |
|
54 static octave_value * |
|
55 default_numeric_conversion_function (const octave_value& a) |
|
56 { |
|
57 CAST_CONV_ARG (const octave_char_matrix_str&); |
|
58 |
4668
|
59 NDArray nda = v.array_value (true); |
3203
|
60 |
4668
|
61 return error_state ? 0 : new octave_matrix (nda); |
2376
|
62 } |
|
63 |
2427
|
64 type_conv_fcn |
2376
|
65 octave_char_matrix_str::numeric_conversion_function (void) const |
|
66 { |
|
67 return default_numeric_conversion_function; |
|
68 } |
|
69 |
|
70 octave_value |
3933
|
71 octave_char_matrix_str::do_index_op (const octave_value_list& idx, |
|
72 int resize_ok) |
2407
|
73 { |
|
74 octave_value retval; |
|
75 |
|
76 int len = idx.length (); |
|
77 |
|
78 switch (len) |
|
79 { |
|
80 case 2: |
|
81 { |
|
82 idx_vector i = idx (0).index_vector (); |
|
83 idx_vector j = idx (1).index_vector (); |
|
84 |
4513
|
85 retval = octave_value (charNDArray (matrix.index (i, j, resize_ok)), |
3933
|
86 true); |
2407
|
87 } |
|
88 break; |
|
89 |
|
90 case 1: |
|
91 { |
|
92 idx_vector i = idx (0).index_vector (); |
|
93 |
4513
|
94 retval = octave_value (charNDArray (matrix.index (i, resize_ok)), |
|
95 true); |
2407
|
96 } |
|
97 break; |
|
98 |
|
99 default: |
4513
|
100 { |
|
101 Array<idx_vector> idx_vec (len); |
|
102 |
|
103 for (int i = 0; i < len; i++) |
|
104 idx_vec(i) = idx(i).index_vector (); |
|
105 |
|
106 retval = octave_value (charNDArray (matrix.index (idx_vec, resize_ok)), |
|
107 true); |
|
108 } |
2407
|
109 break; |
|
110 } |
|
111 |
|
112 return retval; |
|
113 } |
|
114 |
|
115 void |
|
116 octave_char_matrix_str::assign (const octave_value_list& idx, |
|
117 const charMatrix& rhs) |
|
118 { |
|
119 int len = idx.length (); |
|
120 |
2571
|
121 // XXX FIXME XXX |
|
122 charMatrix tmp = rhs; |
|
123 if (tmp.rows () == 1 && tmp.columns () == 0) |
|
124 tmp.resize (0, 0); |
|
125 |
4513
|
126 for (int i = 0; i < len; i++) |
|
127 matrix.set_index (idx(i).index_vector ()); |
2407
|
128 |
4513
|
129 ::assign (matrix, tmp, Vstring_fill_char); |
2407
|
130 } |
|
131 |
2376
|
132 bool |
|
133 octave_char_matrix_str::valid_as_scalar_index (void) const |
|
134 { |
|
135 bool retval = false; |
|
136 error ("octave_char_matrix_str::valid_as_scalar_index(): not implemented"); |
|
137 return retval; |
|
138 } |
|
139 |
4668
|
140 #define CHAR_MATRIX_CONV(T, INIT, TNAME, FCN) \ |
|
141 T retval INIT; \ |
|
142 \ |
|
143 if (! force_string_conv) \ |
|
144 gripe_invalid_conversion ("string", TNAME); \ |
|
145 else \ |
|
146 { \ |
|
147 if (Vwarn_str_to_num) \ |
|
148 gripe_implicit_conversion ("string", TNAME); \ |
|
149 \ |
|
150 retval = octave_char_matrix::FCN (); \ |
|
151 } \ |
|
152 \ |
|
153 return retval |
|
154 |
4643
|
155 double |
|
156 octave_char_matrix_str::double_value (bool force_string_conv) const |
|
157 { |
4668
|
158 CHAR_MATRIX_CONV (double, = 0, "real scalar", double_value); |
|
159 } |
4643
|
160 |
4668
|
161 Complex |
|
162 octave_char_matrix_str::complex_value (bool force_string_conv) const |
|
163 { |
|
164 CHAR_MATRIX_CONV (Complex, = 0, "complex scalar", complex_value); |
4643
|
165 } |
|
166 |
2376
|
167 Matrix |
|
168 octave_char_matrix_str::matrix_value (bool force_string_conv) const |
|
169 { |
4668
|
170 CHAR_MATRIX_CONV (Matrix, , "real matrix", matrix_value); |
|
171 } |
|
172 |
|
173 ComplexMatrix |
|
174 octave_char_matrix_str::complex_matrix_value (bool force_string_conv) const |
|
175 { |
|
176 CHAR_MATRIX_CONV (ComplexMatrix, , "complex matrix", complex_matrix_value); |
|
177 } |
2376
|
178 |
4668
|
179 NDArray |
|
180 octave_char_matrix_str::array_value (bool force_string_conv) const |
|
181 { |
|
182 CHAR_MATRIX_CONV (NDArray, , "real N-d array", array_value); |
|
183 } |
2376
|
184 |
4668
|
185 ComplexNDArray |
|
186 octave_char_matrix_str::complex_array_value (bool force_string_conv) const |
|
187 { |
|
188 CHAR_MATRIX_CONV (ComplexNDArray, , "complex N-d array", |
|
189 complex_array_value); |
2376
|
190 } |
|
191 |
2493
|
192 string_vector |
4457
|
193 octave_char_matrix_str::all_strings (bool, bool) const |
2376
|
194 { |
4513
|
195 string_vector retval; |
|
196 |
|
197 if (matrix.ndims () == 2) |
|
198 { |
|
199 charMatrix chm = matrix.matrix_value (); |
|
200 |
|
201 int n = chm.rows (); |
2493
|
202 |
4513
|
203 retval.resize (n); |
2493
|
204 |
4513
|
205 for (int i = 0; i < n; i++) |
|
206 retval[i] = chm.row_as_string (i, true); |
|
207 } |
|
208 else |
|
209 error ("invalid conversion of charNDArray to string_vector"); |
2493
|
210 |
|
211 return retval; |
2376
|
212 } |
|
213 |
3536
|
214 std::string |
4457
|
215 octave_char_matrix_str::string_value (bool) const |
2376
|
216 { |
4513
|
217 std::string retval; |
|
218 |
|
219 if (matrix.ndims () == 2) |
|
220 { |
|
221 charMatrix chm = matrix.matrix_value (); |
|
222 |
|
223 retval = chm.row_as_string (0); // XXX FIXME??? XXX |
|
224 } |
|
225 else |
|
226 error ("invalid conversion of charNDArray to string"); |
|
227 |
|
228 return retval; |
2376
|
229 } |
|
230 |
|
231 void |
3523
|
232 octave_char_matrix_str::print_raw (std::ostream& os, bool pr_as_read_syntax) const |
2376
|
233 { |
3219
|
234 octave_print_internal (os, matrix, pr_as_read_syntax, |
|
235 current_print_indent_level (), true); |
2376
|
236 } |
|
237 |
4687
|
238 bool |
|
239 octave_char_matrix_str::save_ascii (std::ostream& os, |
|
240 bool& /* infnan_warned */, |
|
241 bool /* strip_nan_and_inf */) |
|
242 { |
4805
|
243 dim_vector d = dims (); |
|
244 if (d.length () > 2) |
|
245 { |
|
246 charNDArray tmp = char_array_value (); |
|
247 os << "# ndims: " << d.length () << "\n"; |
|
248 for (int i=0; i < d.length (); i++) |
|
249 os << " " << d (i); |
|
250 os << "\n"; |
|
251 os.write (X_CAST (char *, tmp.fortran_vec ()), d.numel ()); |
|
252 os << "\n"; |
|
253 } |
|
254 else |
4687
|
255 { |
4805
|
256 // Keep this case, rather than use generic code above for |
|
257 // backward compatiability. Makes load_ascii much more complex!! |
|
258 charMatrix chm = char_matrix_value (); |
|
259 int elements = chm.rows (); |
|
260 os << "# elements: " << elements << "\n"; |
|
261 for (int i = 0; i < elements; i++) |
|
262 { |
|
263 unsigned len = chm.cols (); |
|
264 os << "# length: " << len << "\n"; |
|
265 std::string tstr = chm.row_as_string (i, false, true); |
|
266 const char *tmp = tstr.data (); |
|
267 if (tstr.length () > len) |
|
268 panic_impossible (); |
|
269 os.write (X_CAST (char *, tmp), len); |
|
270 os << "\n"; |
|
271 } |
4687
|
272 } |
|
273 |
|
274 return true; |
|
275 } |
|
276 |
|
277 bool |
|
278 octave_char_matrix_str::load_ascii (std::istream& is) |
|
279 { |
4805
|
280 int mdims = 0; |
4687
|
281 bool success = true; |
|
282 std::streampos pos = is.tellg (); |
|
283 |
4805
|
284 if (extract_keyword (is, "ndims", mdims, true)) |
4687
|
285 { |
4805
|
286 if (mdims >= 0) |
4687
|
287 { |
4805
|
288 dim_vector dv; |
|
289 dv.resize (mdims); |
|
290 |
|
291 for (int i = 0; i < mdims; i++) |
|
292 is >> dv(i); |
4687
|
293 |
4805
|
294 charNDArray tmp(dv); |
|
295 char *ftmp = tmp.fortran_vec (); |
|
296 |
|
297 // Skip the return line |
|
298 if (! is.read (ftmp, 1)) |
|
299 return false; |
|
300 |
|
301 if (! is.read (ftmp, dv.numel ()) || !is) |
4687
|
302 { |
4805
|
303 error ("load: failed to load string constant"); |
|
304 success = false; |
4687
|
305 } |
4805
|
306 else |
|
307 matrix = tmp; |
4687
|
308 } |
|
309 else |
|
310 { |
4805
|
311 error ("load: failed to extract matrix size"); |
4687
|
312 success = false; |
|
313 } |
|
314 } |
|
315 else |
|
316 { |
4805
|
317 int elements; |
|
318 |
4687
|
319 // re-read the same line again |
|
320 is.clear (); |
|
321 is.seekg (pos); |
|
322 |
4805
|
323 if (extract_keyword (is, "elements", elements, true)) |
4687
|
324 { |
4805
|
325 |
|
326 if (elements >= 0) |
|
327 { |
|
328 // XXX FIXME XXX -- need to be able to get max length |
|
329 // before doing anything. |
4687
|
330 |
4805
|
331 charMatrix chm (elements, 0); |
|
332 int max_len = 0; |
|
333 for (int i = 0; i < elements; i++) |
|
334 { |
|
335 int len; |
|
336 if (extract_keyword (is, "length", len) && len >= 0) |
|
337 { |
|
338 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); |
|
339 |
|
340 if (len > 0 && ! |
|
341 is.read (X_CAST (char *, tmp), len)) |
|
342 { |
|
343 error ("load: failed to load string constant"); |
|
344 success = false; |
|
345 break; |
|
346 } |
|
347 else |
|
348 { |
|
349 tmp [len] = '\0'; |
|
350 if (len > max_len) |
|
351 { |
|
352 max_len = len; |
|
353 chm.resize (elements, max_len, 0); |
|
354 } |
|
355 chm.insert (tmp, i, 0); |
|
356 } |
|
357 } |
|
358 else |
|
359 { |
|
360 error ("load: failed to extract string length for element %d", |
|
361 i+1); |
|
362 success = false; |
|
363 } |
|
364 } |
|
365 |
|
366 if (! error_state) |
|
367 matrix = chm; |
|
368 |
4687
|
369 } |
|
370 else |
|
371 { |
4805
|
372 error ("load: failed to extract number of string elements"); |
|
373 success = false; |
|
374 } |
|
375 } |
|
376 else |
|
377 { |
|
378 // re-read the same line again |
|
379 is.clear (); |
|
380 is.seekg (pos); |
4687
|
381 |
4805
|
382 int len; |
|
383 |
|
384 if (extract_keyword (is, "length", len) && len >= 0) |
|
385 { |
|
386 // This is cruft for backward compatiability, |
|
387 // but relatively harmless. |
|
388 |
|
389 OCTAVE_LOCAL_BUFFER (char, tmp, len+1); |
|
390 |
|
391 if (len > 0 && ! is.read (X_CAST (char *, tmp), len)) |
|
392 { |
|
393 error ("load: failed to load string constant"); |
|
394 } |
4687
|
395 else |
4805
|
396 { |
|
397 tmp [len] = '\0'; |
|
398 |
|
399 if (is) |
|
400 matrix = charMatrix (tmp); |
|
401 else |
|
402 error ("load: failed to load string constant"); |
|
403 } |
4687
|
404 } |
|
405 } |
|
406 } |
|
407 |
|
408 return success; |
|
409 } |
|
410 |
|
411 bool |
|
412 octave_char_matrix_str::save_binary (std::ostream& os, |
|
413 bool& /* save_as_floats */) |
|
414 { |
4805
|
415 dim_vector d = dims (); |
|
416 if (d.length() < 1) |
|
417 return false; |
|
418 |
|
419 // Use negative value for ndims to differentiate with old format!! |
|
420 FOUR_BYTE_INT tmp = - d.length(); |
|
421 os.write (X_CAST (char *, &tmp), 4); |
|
422 for (int i=0; i < d.length (); i++) |
4687
|
423 { |
4805
|
424 tmp = d(i); |
|
425 os.write (X_CAST (char *, &tmp), 4); |
4687
|
426 } |
4805
|
427 |
|
428 charNDArray m = char_array_value (); |
|
429 os.write (m.fortran_vec (), d.numel ()); |
4687
|
430 return true; |
|
431 } |
|
432 |
|
433 bool |
|
434 octave_char_matrix_str::load_binary (std::istream& is, bool swap, |
|
435 oct_mach_info::float_format /* fmt */) |
|
436 { |
|
437 FOUR_BYTE_INT elements; |
|
438 if (! is.read (X_CAST (char *, &elements), 4)) |
|
439 return false; |
|
440 if (swap) |
|
441 swap_4_bytes (X_CAST (char *, &elements)); |
4805
|
442 |
|
443 if (elements < 0) |
4687
|
444 { |
4805
|
445 FOUR_BYTE_INT mdims = - elements; |
|
446 FOUR_BYTE_INT di; |
|
447 dim_vector dv; |
|
448 dv.resize (mdims); |
|
449 |
|
450 for (int i = 0; i < mdims; i++) |
|
451 { |
|
452 if (! is.read (X_CAST (char *, &di), 4)) |
|
453 return false; |
|
454 if (swap) |
|
455 swap_4_bytes (X_CAST (char *, &di)); |
|
456 dv(i) = di; |
|
457 } |
|
458 |
|
459 charNDArray m(dv); |
|
460 char *tmp = m.fortran_vec (); |
|
461 is.read (tmp, dv.numel ()); |
|
462 |
|
463 if (error_state || ! is) |
4687
|
464 return false; |
4805
|
465 matrix = m; |
|
466 } |
|
467 else |
|
468 { |
|
469 charMatrix chm (elements, 0); |
|
470 int max_len = 0; |
|
471 for (int i = 0; i < elements; i++) |
4687
|
472 { |
4805
|
473 FOUR_BYTE_INT len; |
|
474 if (! is.read (X_CAST (char *, &len), 4)) |
|
475 return false; |
|
476 if (swap) |
|
477 swap_4_bytes (X_CAST (char *, &len)); |
|
478 OCTAVE_LOCAL_BUFFER (char, btmp, len+1); |
|
479 if (! is.read (X_CAST (char *, btmp), len)) |
|
480 return false; |
|
481 if (len > max_len) |
|
482 { |
|
483 max_len = len; |
|
484 chm.resize (elements, max_len, 0); |
|
485 } |
|
486 btmp [len] = '\0'; |
|
487 chm.insert (btmp, i, 0); |
4687
|
488 } |
4805
|
489 matrix = chm; |
4687
|
490 } |
|
491 return true; |
|
492 } |
|
493 |
|
494 #if defined (HAVE_HDF5) |
|
495 bool |
|
496 octave_char_matrix_str::save_hdf5 (hid_t loc_id, const char *name, |
|
497 bool /* save_as_floats */) |
|
498 { |
4805
|
499 dim_vector d = dims (); |
|
500 int empty = save_hdf5_empty (loc_id, name, d); |
|
501 if (empty != 0) |
|
502 return (empty > 0); |
4687
|
503 |
4805
|
504 int rank = d.length (); |
|
505 hid_t space_hid = -1, data_hid = -1; |
|
506 bool retval = true; |
|
507 charNDArray m = char_array_value (); |
|
508 |
|
509 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
4687
|
510 |
4805
|
511 // Octave uses column-major, while HDF5 uses row-major ordering |
|
512 for (int i = 0; i < rank; i++) |
|
513 hdims[i] = d (rank-i-1); |
|
514 |
4815
|
515 space_hid = H5Screate_simple (rank, hdims, 0); |
4805
|
516 if (space_hid < 0) |
|
517 return false; |
4687
|
518 |
4805
|
519 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_CHAR, space_hid, |
|
520 H5P_DEFAULT); |
|
521 if (data_hid < 0) |
4687
|
522 { |
4805
|
523 H5Sclose (space_hid); |
4687
|
524 return false; |
|
525 } |
|
526 |
4805
|
527 OCTAVE_LOCAL_BUFFER (char, s, d.numel ()); |
4687
|
528 |
4805
|
529 for (int i = 0; i < d.numel(); ++i) |
|
530 s[i] = m(i); |
4687
|
531 |
4805
|
532 retval = H5Dwrite (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, |
4815
|
533 H5P_DEFAULT, s) >= 0; |
4687
|
534 |
|
535 H5Dclose (data_hid); |
|
536 H5Sclose (space_hid); |
|
537 return retval; |
|
538 } |
|
539 |
|
540 bool |
|
541 octave_char_matrix_str::load_hdf5 (hid_t loc_id, const char *name, |
|
542 bool /* have_h5giterate_bug */) |
|
543 { |
4805
|
544 dim_vector dv; |
|
545 int empty = load_hdf5_empty (loc_id, name, dv); |
|
546 if (empty > 0) |
|
547 matrix.resize(dv); |
|
548 if (empty != 0) |
|
549 return (empty > 0); |
|
550 |
4687
|
551 hid_t data_hid = H5Dopen (loc_id, name); |
|
552 hid_t space_hid = H5Dget_space (data_hid); |
|
553 hsize_t rank = H5Sget_simple_extent_ndims (space_hid); |
|
554 hid_t type_hid = H5Dget_type (data_hid); |
4805
|
555 hid_t type_class_hid = H5Tget_class (type_hid); |
4687
|
556 |
4805
|
557 if (type_class_hid == H5T_INTEGER) |
4687
|
558 { |
4805
|
559 bool retval = false; |
|
560 if (rank < 1) |
4687
|
561 { |
|
562 H5Tclose (type_hid); |
|
563 H5Sclose (space_hid); |
|
564 H5Dclose (data_hid); |
|
565 return false; |
|
566 } |
4805
|
567 |
|
568 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
|
569 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); |
|
570 |
|
571 H5Sget_simple_extent_dims (space_hid, hdims, maxdims); |
|
572 |
|
573 // Octave uses column-major, while HDF5 uses row-major ordering |
|
574 if (rank == 1) |
|
575 { |
|
576 dv.resize (2); |
|
577 dv(0) = 1; |
|
578 dv(1) = hdims[0]; |
|
579 } |
4687
|
580 else |
|
581 { |
4805
|
582 dv.resize (rank); |
4815
|
583 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) |
4805
|
584 dv(j) = hdims[i]; |
|
585 } |
|
586 |
|
587 charNDArray m (dv); |
|
588 char *str = m.fortran_vec (); |
|
589 if (H5Dread (data_hid, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, |
4815
|
590 H5P_DEFAULT, str) >= 0) |
4805
|
591 { |
|
592 retval = true; |
|
593 matrix = m; |
|
594 } |
|
595 |
|
596 H5Tclose (type_hid); |
|
597 H5Sclose (space_hid); |
|
598 H5Dclose (data_hid); |
|
599 return true; |
|
600 } |
|
601 else |
|
602 { |
|
603 // This is cruft for backward compatiability and easy data |
|
604 // importation |
|
605 if (rank == 0) |
|
606 { |
|
607 // a single string: |
|
608 int slen = H5Tget_size (type_hid); |
|
609 if (slen < 0) |
4687
|
610 { |
|
611 H5Tclose (type_hid); |
|
612 H5Sclose (space_hid); |
|
613 H5Dclose (data_hid); |
|
614 return false; |
|
615 } |
4805
|
616 else |
|
617 { |
|
618 OCTAVE_LOCAL_BUFFER (char, s, slen); |
|
619 // create datatype for (null-terminated) string |
|
620 // to read into: |
|
621 hid_t st_id = H5Tcopy (H5T_C_S1); |
|
622 H5Tset_size (st_id, slen); |
|
623 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, |
|
624 H5P_DEFAULT, (void *) s) < 0) |
|
625 { |
|
626 H5Tclose (st_id); |
|
627 H5Tclose (type_hid); |
|
628 H5Sclose (space_hid); |
|
629 H5Dclose (data_hid); |
|
630 return false; |
|
631 } |
4687
|
632 |
4805
|
633 matrix = charMatrix (s); |
4687
|
634 |
4805
|
635 H5Tclose (st_id); |
|
636 H5Tclose (type_hid); |
|
637 H5Sclose (space_hid); |
|
638 H5Dclose (data_hid); |
|
639 return true; |
|
640 } |
4687
|
641 } |
4805
|
642 else if (rank == 1) |
|
643 { |
|
644 // string vector |
|
645 hsize_t elements, maxdim; |
|
646 H5Sget_simple_extent_dims (space_hid, &elements, &maxdim); |
|
647 int slen = H5Tget_size (type_hid); |
|
648 if (slen < 0) |
|
649 { |
|
650 H5Tclose (type_hid); |
|
651 H5Sclose (space_hid); |
|
652 H5Dclose (data_hid); |
|
653 return false; |
|
654 } |
|
655 else |
|
656 { |
|
657 // hdf5 string arrays store strings of all the |
|
658 // same physical length (I think), which is |
|
659 // slightly wasteful, but oh well. |
|
660 |
|
661 OCTAVE_LOCAL_BUFFER (char, s, elements * slen); |
|
662 |
|
663 // create datatype for (null-terminated) string |
|
664 // to read into: |
|
665 hid_t st_id = H5Tcopy (H5T_C_S1); |
|
666 H5Tset_size (st_id, slen); |
|
667 |
|
668 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, |
|
669 H5P_DEFAULT, (void *) s) < 0) |
|
670 { |
|
671 H5Tclose (st_id); |
|
672 H5Tclose (type_hid); |
|
673 H5Sclose (space_hid); |
|
674 H5Dclose (data_hid); |
|
675 return false; |
|
676 } |
|
677 |
|
678 charMatrix chm (elements, slen - 1); |
|
679 for (hsize_t i = 0; i < elements; ++i) |
|
680 { |
|
681 chm.insert (s + i*slen, i, 0); |
|
682 } |
|
683 |
|
684 matrix = chm; |
|
685 |
|
686 H5Tclose (st_id); |
|
687 H5Tclose (type_hid); |
|
688 H5Sclose (space_hid); |
|
689 H5Dclose (data_hid); |
|
690 return true; |
|
691 } |
|
692 } |
|
693 else |
4687
|
694 { |
|
695 H5Tclose (type_hid); |
|
696 H5Sclose (space_hid); |
|
697 H5Dclose (data_hid); |
|
698 return false; |
|
699 } |
|
700 } |
|
701 } |
|
702 #endif |
|
703 |
2376
|
704 /* |
|
705 ;;; Local Variables: *** |
|
706 ;;; mode: C++ *** |
|
707 ;;; End: *** |
|
708 */ |