2882
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2882
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
2882
|
29 |
4051
|
30 #include "lo-sstream.h" |
2882
|
31 #include "lo-utils.h" |
|
32 |
4513
|
33 #include "Cell.h" |
2882
|
34 #include "defun.h" |
|
35 #include "error.h" |
4994
|
36 #include "ov.h" |
2882
|
37 #include "ov-list.h" |
|
38 #include "unwind-prot.h" |
|
39 |
4687
|
40 #include "byte-swap.h" |
|
41 #include "ls-oct-ascii.h" |
|
42 #include "ls-oct-binary.h" |
|
43 #include "ls-hdf5.h" |
|
44 #include "ls-utils.h" |
|
45 |
3219
|
46 DEFINE_OCTAVE_ALLOCATOR (octave_list); |
2882
|
47 |
4612
|
48 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_list, "list", "list"); |
2882
|
49 |
4513
|
50 octave_list::octave_list (const Cell& c) |
4591
|
51 : octave_base_value (), data () |
4513
|
52 { |
5275
|
53 octave_idx_type n = c.length (); |
4513
|
54 |
4591
|
55 data.resize (dim_vector (1, n)); |
4513
|
56 |
5275
|
57 for (octave_idx_type i = 0; i < n; i++) |
4591
|
58 data(i) = c(i); |
4513
|
59 } |
|
60 |
4994
|
61 octave_value_list |
4247
|
62 octave_list::subsref (const std::string& type, |
4994
|
63 const std::list<octave_value_list>& idx, int nargout) |
3933
|
64 { |
4994
|
65 octave_value_list retval; |
3933
|
66 |
|
67 switch (type[0]) |
|
68 { |
|
69 case '(': |
|
70 { |
|
71 octave_value_list tmp_idx = idx.front (); |
|
72 |
|
73 if (tmp_idx.length () == 1) |
|
74 { |
|
75 idx_vector i = tmp_idx (0).index_vector (); |
|
76 |
4842
|
77 Cell tmp = data.index (i); |
|
78 |
4994
|
79 retval(0) = octave_value (new octave_list (tmp)); |
3933
|
80 } |
|
81 else |
|
82 error ("only one index allowed for lists"); |
|
83 } |
|
84 break; |
|
85 |
|
86 case '{': |
|
87 { |
|
88 octave_value_list tmp_idx = idx.front (); |
|
89 |
|
90 if (tmp_idx.length () == 1) |
|
91 { |
|
92 idx_vector i = tmp_idx (0).index_vector (); |
|
93 |
4591
|
94 Cell tmp = data.index (i); |
3933
|
95 |
|
96 if (tmp.length () == 1) |
4994
|
97 retval(0) = tmp(0); |
4842
|
98 else |
4994
|
99 retval(0) = octave_value (tmp, true); |
3933
|
100 } |
|
101 else |
|
102 error ("only one index allowed for lists"); |
|
103 } |
|
104 break; |
|
105 |
|
106 case '.': |
|
107 { |
|
108 std::string nm = type_name (); |
|
109 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
110 } |
|
111 break; |
|
112 |
|
113 default: |
|
114 panic_impossible (); |
|
115 } |
|
116 |
4994
|
117 // XXX FIXME XXX -- perhaps there should be an |
|
118 // octave_value_list::next_subsref member function? See also |
|
119 // octave_user_function::subsref. |
|
120 |
|
121 if (idx.size () > 1) |
|
122 retval = retval(0).next_subsref (nargout, type, idx); |
|
123 |
|
124 return retval; |
3933
|
125 } |
|
126 |
|
127 octave_value |
|
128 octave_list::do_index_op (const octave_value_list& idx, int resize_ok) |
2882
|
129 { |
|
130 octave_value retval; |
|
131 |
|
132 if (idx.length () == 1) |
|
133 { |
5759
|
134 idx_vector iidx = idx (0).index_vector (); |
2882
|
135 |
5759
|
136 Cell tcell = data.index (iidx, resize_ok); |
5757
|
137 |
|
138 octave_value_list result; |
|
139 |
|
140 octave_idx_type n = tcell.numel (); |
|
141 |
|
142 result.resize (n); |
|
143 |
|
144 for (octave_idx_type i = 0; i < n; i++) |
|
145 result(i) = tcell(i); |
|
146 |
|
147 retval = result; |
2882
|
148 } |
|
149 else |
5757
|
150 error ("only one index allowed for lists"); |
2882
|
151 |
|
152 return retval; |
|
153 } |
|
154 |
3933
|
155 octave_value |
4247
|
156 octave_list::subsasgn (const std::string& type, |
4219
|
157 const std::list<octave_value_list>& idx, |
3933
|
158 const octave_value& rhs) |
|
159 { |
|
160 octave_value retval; |
|
161 |
5275
|
162 octave_idx_type n = type.length (); |
3933
|
163 |
|
164 octave_value t_rhs = rhs; |
|
165 |
|
166 if (n > 1) |
|
167 { |
|
168 switch (type[0]) |
|
169 { |
|
170 case '(': |
|
171 { |
|
172 octave_value tmp = do_index_op (idx.front (), true); |
|
173 |
|
174 if (! tmp.is_defined ()) |
|
175 tmp = octave_value::empty_conv (type.substr (1), rhs); |
|
176 |
|
177 if (! error_state) |
|
178 { |
4219
|
179 std::list<octave_value_list> next_idx (idx); |
3933
|
180 |
4219
|
181 next_idx.erase (next_idx.begin ()); |
3933
|
182 |
|
183 t_rhs = tmp.subsasgn (type.substr (1), next_idx, rhs); |
|
184 } |
|
185 } |
|
186 break; |
|
187 |
|
188 case '{': |
|
189 case '.': |
|
190 { |
|
191 std::string nm = type_name (); |
|
192 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
193 } |
|
194 break; |
|
195 |
|
196 default: |
|
197 panic_impossible (); |
|
198 } |
|
199 } |
|
200 |
3940
|
201 if (! error_state) |
3933
|
202 { |
3940
|
203 switch (type[0]) |
|
204 { |
|
205 case '(': |
|
206 { |
|
207 octave_value_list i = idx.front (); |
3933
|
208 |
5275
|
209 octave_idx_type len = i.length (); |
4769
|
210 |
5275
|
211 for (octave_idx_type k = 0; k < len; k++) |
4769
|
212 data.set_index (i(k).index_vector ()); |
|
213 |
|
214 ::assign (data, Cell (t_rhs), Cell::resize_fill_value ()); |
3933
|
215 |
5759
|
216 count++; |
|
217 retval = octave_value (this); |
3940
|
218 } |
|
219 break; |
3933
|
220 |
3940
|
221 case '{': |
|
222 case '.': |
|
223 { |
|
224 std::string nm = type_name (); |
|
225 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
226 } |
|
227 break; |
3933
|
228 |
3940
|
229 default: |
|
230 panic_impossible (); |
|
231 } |
3933
|
232 } |
|
233 |
|
234 return retval; |
|
235 } |
|
236 |
2882
|
237 void |
3196
|
238 octave_list::assign (const octave_value_list& idx, const octave_value& rhs) |
|
239 { |
|
240 if (idx.length () == 1) |
|
241 { |
3202
|
242 int i = idx(0).int_value (true); |
3196
|
243 |
|
244 if (! error_state) |
|
245 { |
5275
|
246 octave_idx_type n = data.length (); |
3196
|
247 |
4461
|
248 if (i > 0) |
|
249 { |
|
250 if (Vwarn_resize_on_range_error && i > n) |
|
251 warning ("list index = %d out of range", i); |
|
252 |
4591
|
253 data(i-1) = rhs; |
4461
|
254 } |
3196
|
255 else |
3202
|
256 error ("list index = %d out of range", i); |
3196
|
257 } |
3202
|
258 else |
|
259 error ("list index must be an integer"); |
3196
|
260 } |
|
261 else |
|
262 error ("lists may only be indexed by a single scalar"); |
|
263 } |
|
264 |
4791
|
265 size_t |
|
266 octave_list::byte_size (void) const |
|
267 { |
|
268 size_t retval = 0; |
|
269 |
5275
|
270 for (octave_idx_type i = 0; i < numel (); i++) |
4791
|
271 retval += data(i).byte_size (); |
|
272 |
|
273 return retval; |
|
274 } |
|
275 |
4591
|
276 octave_value_list |
|
277 octave_list::list_value (void) const |
|
278 { |
|
279 octave_value_list retval; |
|
280 |
5275
|
281 octave_idx_type n = data.length (); |
4591
|
282 |
|
283 retval.resize (n); |
|
284 |
5275
|
285 for (octave_idx_type i = 0; i < n; i++) |
4591
|
286 retval(i) = data(i); |
|
287 |
|
288 return retval; |
|
289 } |
|
290 |
3196
|
291 void |
3523
|
292 octave_list::print (std::ostream& os, bool) const |
2901
|
293 { |
|
294 print_raw (os); |
|
295 } |
|
296 |
|
297 void |
3523
|
298 octave_list::print_raw (std::ostream& os, bool) const |
2882
|
299 { |
2985
|
300 unwind_protect::begin_frame ("octave_list_print"); |
2882
|
301 |
5275
|
302 octave_idx_type n = data.length (); |
2882
|
303 |
3196
|
304 if (n > 0) |
2882
|
305 { |
3196
|
306 indent (os); |
|
307 os << "("; |
|
308 newline (os); |
|
309 |
|
310 increment_indent_level (); |
2916
|
311 |
5275
|
312 for (octave_idx_type i = 0; i < n; i++) |
3196
|
313 { |
4051
|
314 OSSTREAM buf; |
|
315 |
|
316 buf << "[" << i+1 << "]" << OSSTREAM_ENDS; |
2882
|
317 |
4591
|
318 octave_value val = data(i); |
2916
|
319 |
4051
|
320 val.print_with_name (os, OSSTREAM_STR (buf)); |
3196
|
321 |
4051
|
322 OSSTREAM_FREEZE (buf); |
3196
|
323 } |
2882
|
324 |
3196
|
325 decrement_indent_level (); |
2882
|
326 |
3196
|
327 indent (os); |
|
328 os << ")"; |
|
329 } |
|
330 else |
|
331 os << "()"; |
|
332 |
2901
|
333 newline (os); |
2882
|
334 |
2985
|
335 unwind_protect::run_frame ("octave_list_print"); |
2882
|
336 } |
|
337 |
2901
|
338 bool |
3523
|
339 octave_list::print_name_tag (std::ostream& os, const std::string& name) const |
2901
|
340 { |
|
341 indent (os); |
4591
|
342 if (data.length () == 0) |
3196
|
343 os << name << " = "; |
|
344 else |
|
345 { |
|
346 os << name << " ="; |
|
347 newline (os); |
|
348 } |
2901
|
349 return false; |
|
350 } |
|
351 |
2993
|
352 DEFUN (list, args, , |
3447
|
353 "-*- texinfo -*-\n\ |
3448
|
354 @deftypefn {Built-in Function} {} list (@var{a1}, @var{a2}, @dots{})\n\ |
3447
|
355 Create a new list with elements given by the arguments @var{a1},\n\ |
|
356 @var{a2}, @dots{}.\n\ |
|
357 @end deftypefn") |
2882
|
358 { |
4591
|
359 static bool warned = false; |
|
360 |
|
361 if (! warned) |
|
362 { |
|
363 warning ("list objects are deprecated; use cell arrays instead"); |
|
364 warned = true; |
|
365 } |
|
366 |
2882
|
367 return octave_value (args); |
|
368 } |
|
369 |
3219
|
370 DEFUN (nth, args, , |
3447
|
371 "-*- texinfo -*-\n\ |
|
372 @deftypefn {Built-in Function} {} nth (@var{list}, @var{n})\n\ |
|
373 Return the @var{n}-th element of @var{list}.\n\ |
|
374 @end deftypefn") |
3219
|
375 { |
|
376 octave_value retval; |
|
377 |
|
378 if (args.length () == 2) |
|
379 { |
|
380 octave_value_list lst = args(0).list_value (); |
|
381 |
|
382 if (! error_state) |
|
383 { |
|
384 int n = args(1).int_value (true); |
|
385 |
|
386 if (! error_state) |
|
387 { |
|
388 if (n > 0 && n <= lst.length ()) |
|
389 retval = lst(n-1); |
|
390 else |
|
391 error ("nth: index = %d out of range", n); |
|
392 } |
|
393 else |
|
394 error ("nth: second argument must be an integer"); |
|
395 } |
|
396 else |
|
397 error ("nth: first argument must be a list"); |
|
398 } |
|
399 else |
|
400 print_usage ("nth"); |
|
401 |
|
402 return retval; |
|
403 } |
|
404 |
2882
|
405 DEFUN (append, args, , |
3447
|
406 "-*- texinfo -*-\n\ |
|
407 @deftypefn {Built-in Function} {} append (@var{list}, @var{a1}, @var{a2}, @dots{})\n\ |
|
408 Return a new list created by appending @var{a1}, @var{a1}, @dots{}, to\n\ |
|
409 @var{list}. If any of the arguments to be appended is a list, its\n\ |
|
410 elements are appended individually. For example,\n\ |
2882
|
411 \n\ |
3447
|
412 @example\n\ |
|
413 x = list (1, 2);\n\ |
|
414 y = list (3, 4);\n\ |
|
415 append (x, y);\n\ |
|
416 @end example\n\ |
3219
|
417 \n\ |
3447
|
418 @noindent\n\ |
|
419 results in the list containing the four elements @samp{(1 2 3 4)}, not\n\ |
|
420 a list containing the three elements @samp{(1 2 (3 4))}.\n\ |
|
421 @end deftypefn") |
2882
|
422 { |
|
423 octave_value retval; |
|
424 |
|
425 int nargin = args.length (); |
|
426 |
|
427 if (nargin > 1) |
|
428 { |
|
429 octave_value_list tmp = args(0).list_value (); |
|
430 |
|
431 if (! error_state) |
|
432 { |
|
433 for (int i = 1; i < nargin; i++) |
3219
|
434 { |
|
435 octave_value ov = args(i); |
|
436 |
|
437 if (ov.is_list ()) |
|
438 tmp.append (ov.list_value ()); |
|
439 else |
|
440 tmp.append (ov); |
|
441 } |
2882
|
442 |
4233
|
443 retval = octave_value (tmp); |
2882
|
444 } |
|
445 } |
|
446 else |
|
447 print_usage ("append"); |
|
448 |
|
449 return retval; |
|
450 } |
|
451 |
|
452 DEFUN (reverse, args, , |
3447
|
453 "-*- texinfo -*-\n\ |
|
454 @deftypefn {Built-in Function} {} reverse (@var{list})\n\ |
|
455 Return a new list created by reversing the elements of @var{list}.\n\ |
|
456 @end deftypefn") |
2882
|
457 { |
|
458 octave_value retval; |
|
459 |
|
460 int nargin = args.length (); |
|
461 |
|
462 if (nargin == 1) |
|
463 { |
|
464 octave_value_list tmp = args(0).list_value (); |
|
465 |
|
466 if (! error_state) |
4233
|
467 retval = octave_value (tmp.reverse ()); |
2882
|
468 } |
|
469 else |
|
470 print_usage ("reverse"); |
|
471 |
|
472 return retval; |
|
473 } |
|
474 |
3196
|
475 DEFUN (splice, args, , |
3447
|
476 "-*- texinfo -*-\n\ |
|
477 @deftypefn {Built-in Function} {} splice (@var{list_1}, @var{offset}, @var{length}, @var{list_2})\n\ |
|
478 Replace @var{length} elements of @var{list_1} beginning at\n\ |
|
479 @var{offset} with the contents of @var{list_2} (if any). If\n\ |
|
480 @var{length} is omitted, all elements from @var{offset} to the end of\n\ |
|
481 @var{list_1} are replaced. As a special case, if @var{offset} is one\n\ |
|
482 greater than the length of @var{list_1} and @var{length} is 0, splice\n\ |
3448
|
483 is equivalent to @code{append (@var{list_1}, @var{list_2})}.\n\ |
3447
|
484 @end deftypefn") |
3196
|
485 { |
|
486 octave_value retval; |
|
487 |
|
488 int nargin = args.length (); |
|
489 |
|
490 if (nargin > 1 && nargin < 5) |
|
491 { |
|
492 octave_value_list list_1 = args(0).list_value (); |
|
493 |
|
494 if (! error_state) |
|
495 { |
3202
|
496 int offset = args(1).int_value (true); |
3196
|
497 |
|
498 if (! error_state) |
|
499 { |
3202
|
500 offset--; |
|
501 |
|
502 int length = 0; |
|
503 |
|
504 octave_value_list list_2; |
3196
|
505 |
3202
|
506 if (nargin < 3) |
|
507 length = list_1.length () - offset; |
|
508 else |
|
509 { |
|
510 length = args(2).int_value (true); |
3196
|
511 |
3202
|
512 if (! error_state) |
3196
|
513 { |
3202
|
514 if (nargin == 4) |
|
515 { |
|
516 list_2 = args(3).list_value (); |
3196
|
517 |
3202
|
518 if (error_state) |
|
519 error ("splice: fourth argument must be a list"); |
3196
|
520 } |
|
521 } |
3202
|
522 else |
|
523 error ("splice: LENGTH must be an integer"); |
|
524 } |
3196
|
525 |
3202
|
526 if (! error_state) |
4233
|
527 retval = octave_value (list_1.splice (offset, length, list_2)); |
3196
|
528 } |
|
529 else |
|
530 error ("splice: OFFSET must be an integer"); |
|
531 } |
|
532 else |
|
533 error ("splice: first argument must be a list"); |
|
534 } |
|
535 else |
|
536 print_usage ("splice"); |
|
537 |
|
538 return retval; |
|
539 } |
|
540 |
4687
|
541 bool |
|
542 octave_list::save_ascii (std::ostream& os, bool& infnan_warned, |
|
543 bool strip_nan_and_inf) |
|
544 { |
|
545 octave_value_list lst = list_value (); |
|
546 os << "# length: " << lst.length () << "\n"; |
|
547 |
|
548 for (int i = 0; i < lst.length (); ++i) |
|
549 { |
|
550 // should we use lst.name_tags () to label the elements? |
5717
|
551 |
|
552 OSSTREAM buf; |
|
553 buf << "_" << i << OSSTREAM_ENDS; |
|
554 std::string s = OSSTREAM_STR (buf); |
|
555 OSSTREAM_FREEZE (buf); |
|
556 |
|
557 bool b = save_ascii_data (os, lst (i), s.c_str (), infnan_warned, |
4687
|
558 strip_nan_and_inf, 0, 0); |
|
559 |
|
560 if (! b) |
|
561 return false; |
|
562 } |
|
563 |
|
564 return true; |
|
565 } |
|
566 |
|
567 bool |
|
568 octave_list::load_ascii (std::istream& is) |
|
569 { |
|
570 int len = 0; |
|
571 bool success = true; |
|
572 |
|
573 if (extract_keyword (is, "length", len) && len >= 0) |
|
574 { |
|
575 if (len > 0) |
|
576 { |
|
577 octave_value_list lst; |
|
578 |
|
579 for (int j = 0; j < len; j++) |
|
580 { |
|
581 octave_value t2; |
|
582 bool dummy; |
|
583 |
|
584 // recurse to read list elements |
|
585 std::string nm |
5757
|
586 = read_ascii_data (is, std::string (), dummy, t2, j); |
4687
|
587 |
|
588 if (!is) |
|
589 break; |
|
590 |
|
591 lst.append (t2); |
|
592 } |
|
593 |
|
594 if (is) |
|
595 data = lst; |
|
596 else |
|
597 { |
|
598 error ("load: failed to load list"); |
|
599 success = false; |
|
600 } |
|
601 } |
|
602 else if (len == 0 ) |
|
603 data = Cell (0, 0); |
|
604 else |
|
605 panic_impossible (); |
|
606 } |
|
607 else { |
|
608 error ("load: failed to extract number of elements in list"); |
|
609 success = false; |
|
610 } |
|
611 |
|
612 return success; |
|
613 } |
|
614 |
|
615 bool |
|
616 octave_list::save_binary (std::ostream& os, bool& save_as_floats) |
|
617 { |
|
618 octave_value_list lst = list_value (); |
|
619 |
|
620 FOUR_BYTE_INT len = lst.length(); |
|
621 os.write (X_CAST (char *, &len), 4); |
|
622 |
|
623 for (int i = 0; i < lst.length (); i++) |
|
624 { |
|
625 // should we use lst.name_tags () to label the elements? |
5717
|
626 |
|
627 OSSTREAM buf; |
|
628 buf << "_" << i << OSSTREAM_ENDS; |
|
629 std::string s = OSSTREAM_STR (buf); |
|
630 OSSTREAM_FREEZE (buf); |
4687
|
631 |
|
632 // Recurse to print sub-value. |
5717
|
633 bool b = save_binary_data (os, lst(i), s.c_str (), "", 0, |
|
634 save_as_floats); |
4687
|
635 |
|
636 if (! b) |
|
637 return false; |
|
638 } |
|
639 |
|
640 return true; |
|
641 } |
|
642 |
|
643 bool |
|
644 octave_list::load_binary (std::istream& is, bool swap, |
|
645 oct_mach_info::float_format fmt) |
|
646 { |
|
647 FOUR_BYTE_INT len; |
|
648 if (! is.read (X_CAST (char *, &len), 4)) |
|
649 return false; |
|
650 if (swap) |
4944
|
651 swap_bytes<4> (&len); |
4687
|
652 |
|
653 if (len > 0) |
|
654 { |
|
655 octave_value_list lst; |
|
656 |
5275
|
657 for (octave_idx_type i = 0; i < len; i++) |
4687
|
658 { |
|
659 octave_value t2; |
|
660 bool dummy; |
|
661 std::string doc; |
|
662 |
|
663 // recurse to read list elements |
|
664 std::string nm = read_binary_data (is, swap, fmt, std::string (), |
|
665 dummy, t2, doc); |
|
666 |
|
667 if (!is) |
|
668 return false; |
|
669 |
|
670 lst.append(t2); |
|
671 } |
|
672 |
|
673 if (is) |
|
674 data = lst; |
|
675 else |
|
676 { |
|
677 error ("load: failed to load list"); |
|
678 return false; |
|
679 } |
|
680 |
|
681 } |
|
682 else if (len == 0 ) |
|
683 data = Cell (0, 0); |
|
684 else |
|
685 return false; |
|
686 |
|
687 return true; |
|
688 } |
|
689 |
|
690 #if defined (HAVE_HDF5) |
4944
|
691 |
4687
|
692 bool |
|
693 octave_list::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) |
|
694 { |
|
695 hid_t data_hid = -1; |
|
696 |
|
697 data_hid = H5Gcreate (loc_id, name, 0); |
|
698 if (data_hid < 0) return false; |
|
699 |
|
700 // recursively add each element of the list to this group |
|
701 octave_value_list lst = list_value (); |
|
702 |
5275
|
703 for (octave_idx_type i = 0; i < lst.length (); ++i) |
4687
|
704 { |
|
705 // should we use lst.name_tags () to label the elements? |
5717
|
706 |
|
707 OSSTREAM buf; |
|
708 buf << "_" << i << OSSTREAM_ENDS; |
|
709 std::string s = OSSTREAM_STR (buf); |
|
710 OSSTREAM_FREEZE (buf); |
|
711 |
|
712 bool retval2 = add_hdf5_data (data_hid, lst (i), s.c_str (), "", |
4687
|
713 false, save_as_floats); |
|
714 if (! retval2) |
|
715 break; |
|
716 } |
|
717 |
|
718 H5Gclose (data_hid); |
4837
|
719 |
4687
|
720 return true; |
|
721 } |
|
722 |
|
723 bool |
|
724 octave_list::load_hdf5 (hid_t loc_id, const char *name, |
|
725 bool have_h5giterate_bug) |
|
726 { |
|
727 bool retval = false; |
|
728 |
|
729 hdf5_callback_data dsub; |
|
730 |
4696
|
731 herr_t retval2 = -1; |
4687
|
732 octave_value_list lst; |
|
733 int current_item = 0; |
4696
|
734 #ifdef HAVE_H5GGET_NUM_OBJS |
|
735 hsize_t num_obj = 0; |
5060
|
736 hid_t group_id = H5Gopen (loc_id, name); |
|
737 H5Gget_num_objs (group_id, &num_obj); |
|
738 H5Gclose (group_id); |
4696
|
739 |
|
740 while (current_item < static_cast<int> (num_obj) |
|
741 && (retval2 = H5Giterate (loc_id, name, ¤t_item, |
|
742 hdf5_read_next_data, &dsub)) > 0) |
|
743 #else |
4687
|
744 while ((retval2 = H5Giterate (loc_id, name, ¤t_item, |
|
745 hdf5_read_next_data, &dsub)) > 0) |
4696
|
746 #endif |
4687
|
747 { |
|
748 lst.append (dsub.tc); |
|
749 |
|
750 if (have_h5giterate_bug) |
|
751 current_item++; // H5Giterate returned the last index processed |
|
752 } |
|
753 |
|
754 if (retval2 >= 0) |
|
755 { |
|
756 data = lst; |
|
757 retval = true; |
|
758 } |
|
759 |
|
760 return retval; |
|
761 } |
4944
|
762 |
4687
|
763 #endif |
|
764 |
2882
|
765 /* |
|
766 ;;; Local Variables: *** |
|
767 ;;; mode: C++ *** |
|
768 ;;; End: *** |
|
769 */ |