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> |
5765
|
29 #include <sstream> |
2882
|
30 |
|
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 { |
5765
|
314 std::ostringstream buf; |
4051
|
315 |
5765
|
316 buf << "[" << i+1 << "]"; |
2882
|
317 |
4591
|
318 octave_value val = data(i); |
2916
|
319 |
5765
|
320 val.print_with_name (os, buf.str ()); |
3196
|
321 } |
2882
|
322 |
3196
|
323 decrement_indent_level (); |
2882
|
324 |
3196
|
325 indent (os); |
|
326 os << ")"; |
|
327 } |
|
328 else |
|
329 os << "()"; |
|
330 |
2901
|
331 newline (os); |
2882
|
332 |
2985
|
333 unwind_protect::run_frame ("octave_list_print"); |
2882
|
334 } |
|
335 |
2901
|
336 bool |
3523
|
337 octave_list::print_name_tag (std::ostream& os, const std::string& name) const |
2901
|
338 { |
|
339 indent (os); |
4591
|
340 if (data.length () == 0) |
3196
|
341 os << name << " = "; |
|
342 else |
|
343 { |
|
344 os << name << " ="; |
|
345 newline (os); |
|
346 } |
2901
|
347 return false; |
|
348 } |
|
349 |
2993
|
350 DEFUN (list, args, , |
3447
|
351 "-*- texinfo -*-\n\ |
3448
|
352 @deftypefn {Built-in Function} {} list (@var{a1}, @var{a2}, @dots{})\n\ |
3447
|
353 Create a new list with elements given by the arguments @var{a1},\n\ |
|
354 @var{a2}, @dots{}.\n\ |
|
355 @end deftypefn") |
2882
|
356 { |
4591
|
357 static bool warned = false; |
|
358 |
|
359 if (! warned) |
|
360 { |
|
361 warning ("list objects are deprecated; use cell arrays instead"); |
|
362 warned = true; |
|
363 } |
|
364 |
2882
|
365 return octave_value (args); |
|
366 } |
|
367 |
3219
|
368 DEFUN (nth, args, , |
3447
|
369 "-*- texinfo -*-\n\ |
|
370 @deftypefn {Built-in Function} {} nth (@var{list}, @var{n})\n\ |
|
371 Return the @var{n}-th element of @var{list}.\n\ |
|
372 @end deftypefn") |
3219
|
373 { |
|
374 octave_value retval; |
|
375 |
|
376 if (args.length () == 2) |
|
377 { |
|
378 octave_value_list lst = args(0).list_value (); |
|
379 |
|
380 if (! error_state) |
|
381 { |
|
382 int n = args(1).int_value (true); |
|
383 |
|
384 if (! error_state) |
|
385 { |
|
386 if (n > 0 && n <= lst.length ()) |
|
387 retval = lst(n-1); |
|
388 else |
|
389 error ("nth: index = %d out of range", n); |
|
390 } |
|
391 else |
|
392 error ("nth: second argument must be an integer"); |
|
393 } |
|
394 else |
|
395 error ("nth: first argument must be a list"); |
|
396 } |
|
397 else |
|
398 print_usage ("nth"); |
|
399 |
|
400 return retval; |
|
401 } |
|
402 |
2882
|
403 DEFUN (append, args, , |
3447
|
404 "-*- texinfo -*-\n\ |
|
405 @deftypefn {Built-in Function} {} append (@var{list}, @var{a1}, @var{a2}, @dots{})\n\ |
|
406 Return a new list created by appending @var{a1}, @var{a1}, @dots{}, to\n\ |
|
407 @var{list}. If any of the arguments to be appended is a list, its\n\ |
|
408 elements are appended individually. For example,\n\ |
2882
|
409 \n\ |
3447
|
410 @example\n\ |
|
411 x = list (1, 2);\n\ |
|
412 y = list (3, 4);\n\ |
|
413 append (x, y);\n\ |
|
414 @end example\n\ |
3219
|
415 \n\ |
3447
|
416 @noindent\n\ |
|
417 results in the list containing the four elements @samp{(1 2 3 4)}, not\n\ |
|
418 a list containing the three elements @samp{(1 2 (3 4))}.\n\ |
|
419 @end deftypefn") |
2882
|
420 { |
|
421 octave_value retval; |
|
422 |
|
423 int nargin = args.length (); |
|
424 |
|
425 if (nargin > 1) |
|
426 { |
|
427 octave_value_list tmp = args(0).list_value (); |
|
428 |
|
429 if (! error_state) |
|
430 { |
|
431 for (int i = 1; i < nargin; i++) |
3219
|
432 { |
|
433 octave_value ov = args(i); |
|
434 |
|
435 if (ov.is_list ()) |
|
436 tmp.append (ov.list_value ()); |
|
437 else |
|
438 tmp.append (ov); |
|
439 } |
2882
|
440 |
4233
|
441 retval = octave_value (tmp); |
2882
|
442 } |
|
443 } |
|
444 else |
|
445 print_usage ("append"); |
|
446 |
|
447 return retval; |
|
448 } |
|
449 |
|
450 DEFUN (reverse, args, , |
3447
|
451 "-*- texinfo -*-\n\ |
|
452 @deftypefn {Built-in Function} {} reverse (@var{list})\n\ |
|
453 Return a new list created by reversing the elements of @var{list}.\n\ |
|
454 @end deftypefn") |
2882
|
455 { |
|
456 octave_value retval; |
|
457 |
|
458 int nargin = args.length (); |
|
459 |
|
460 if (nargin == 1) |
|
461 { |
|
462 octave_value_list tmp = args(0).list_value (); |
|
463 |
|
464 if (! error_state) |
4233
|
465 retval = octave_value (tmp.reverse ()); |
2882
|
466 } |
|
467 else |
|
468 print_usage ("reverse"); |
|
469 |
|
470 return retval; |
|
471 } |
|
472 |
3196
|
473 DEFUN (splice, args, , |
3447
|
474 "-*- texinfo -*-\n\ |
|
475 @deftypefn {Built-in Function} {} splice (@var{list_1}, @var{offset}, @var{length}, @var{list_2})\n\ |
|
476 Replace @var{length} elements of @var{list_1} beginning at\n\ |
|
477 @var{offset} with the contents of @var{list_2} (if any). If\n\ |
|
478 @var{length} is omitted, all elements from @var{offset} to the end of\n\ |
|
479 @var{list_1} are replaced. As a special case, if @var{offset} is one\n\ |
|
480 greater than the length of @var{list_1} and @var{length} is 0, splice\n\ |
3448
|
481 is equivalent to @code{append (@var{list_1}, @var{list_2})}.\n\ |
3447
|
482 @end deftypefn") |
3196
|
483 { |
|
484 octave_value retval; |
|
485 |
|
486 int nargin = args.length (); |
|
487 |
|
488 if (nargin > 1 && nargin < 5) |
|
489 { |
|
490 octave_value_list list_1 = args(0).list_value (); |
|
491 |
|
492 if (! error_state) |
|
493 { |
3202
|
494 int offset = args(1).int_value (true); |
3196
|
495 |
|
496 if (! error_state) |
|
497 { |
3202
|
498 offset--; |
|
499 |
|
500 int length = 0; |
|
501 |
|
502 octave_value_list list_2; |
3196
|
503 |
3202
|
504 if (nargin < 3) |
|
505 length = list_1.length () - offset; |
|
506 else |
|
507 { |
|
508 length = args(2).int_value (true); |
3196
|
509 |
3202
|
510 if (! error_state) |
3196
|
511 { |
3202
|
512 if (nargin == 4) |
|
513 { |
|
514 list_2 = args(3).list_value (); |
3196
|
515 |
3202
|
516 if (error_state) |
|
517 error ("splice: fourth argument must be a list"); |
3196
|
518 } |
|
519 } |
3202
|
520 else |
|
521 error ("splice: LENGTH must be an integer"); |
|
522 } |
3196
|
523 |
3202
|
524 if (! error_state) |
4233
|
525 retval = octave_value (list_1.splice (offset, length, list_2)); |
3196
|
526 } |
|
527 else |
|
528 error ("splice: OFFSET must be an integer"); |
|
529 } |
|
530 else |
|
531 error ("splice: first argument must be a list"); |
|
532 } |
|
533 else |
|
534 print_usage ("splice"); |
|
535 |
|
536 return retval; |
|
537 } |
|
538 |
4687
|
539 bool |
|
540 octave_list::save_ascii (std::ostream& os, bool& infnan_warned, |
|
541 bool strip_nan_and_inf) |
|
542 { |
|
543 octave_value_list lst = list_value (); |
|
544 os << "# length: " << lst.length () << "\n"; |
|
545 |
|
546 for (int i = 0; i < lst.length (); ++i) |
|
547 { |
|
548 // should we use lst.name_tags () to label the elements? |
5717
|
549 |
5765
|
550 std::ostringstream buf; |
|
551 buf << "_" << i; |
|
552 std::string s = buf.str (); |
5717
|
553 |
|
554 bool b = save_ascii_data (os, lst (i), s.c_str (), infnan_warned, |
4687
|
555 strip_nan_and_inf, 0, 0); |
|
556 |
|
557 if (! b) |
|
558 return false; |
|
559 } |
|
560 |
|
561 return true; |
|
562 } |
|
563 |
|
564 bool |
|
565 octave_list::load_ascii (std::istream& is) |
|
566 { |
|
567 int len = 0; |
|
568 bool success = true; |
|
569 |
|
570 if (extract_keyword (is, "length", len) && len >= 0) |
|
571 { |
|
572 if (len > 0) |
|
573 { |
|
574 octave_value_list lst; |
|
575 |
|
576 for (int j = 0; j < len; j++) |
|
577 { |
|
578 octave_value t2; |
|
579 bool dummy; |
|
580 |
|
581 // recurse to read list elements |
|
582 std::string nm |
5757
|
583 = read_ascii_data (is, std::string (), dummy, t2, j); |
4687
|
584 |
|
585 if (!is) |
|
586 break; |
|
587 |
|
588 lst.append (t2); |
|
589 } |
|
590 |
|
591 if (is) |
|
592 data = lst; |
|
593 else |
|
594 { |
|
595 error ("load: failed to load list"); |
|
596 success = false; |
|
597 } |
|
598 } |
|
599 else if (len == 0 ) |
|
600 data = Cell (0, 0); |
|
601 else |
|
602 panic_impossible (); |
|
603 } |
|
604 else { |
|
605 error ("load: failed to extract number of elements in list"); |
|
606 success = false; |
|
607 } |
|
608 |
|
609 return success; |
|
610 } |
|
611 |
|
612 bool |
|
613 octave_list::save_binary (std::ostream& os, bool& save_as_floats) |
|
614 { |
|
615 octave_value_list lst = list_value (); |
|
616 |
|
617 FOUR_BYTE_INT len = lst.length(); |
5760
|
618 os.write (reinterpret_cast<char *> (&len), 4); |
4687
|
619 |
|
620 for (int i = 0; i < lst.length (); i++) |
|
621 { |
|
622 // should we use lst.name_tags () to label the elements? |
5717
|
623 |
5765
|
624 std::ostringstream buf; |
|
625 buf << "_" << i; |
|
626 std::string s = buf.str (); |
4687
|
627 |
|
628 // Recurse to print sub-value. |
5717
|
629 bool b = save_binary_data (os, lst(i), s.c_str (), "", 0, |
|
630 save_as_floats); |
4687
|
631 |
|
632 if (! b) |
|
633 return false; |
|
634 } |
|
635 |
|
636 return true; |
|
637 } |
|
638 |
|
639 bool |
|
640 octave_list::load_binary (std::istream& is, bool swap, |
5760
|
641 oct_mach_info::float_format fmt) |
4687
|
642 { |
|
643 FOUR_BYTE_INT len; |
5760
|
644 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
4687
|
645 return false; |
|
646 if (swap) |
4944
|
647 swap_bytes<4> (&len); |
4687
|
648 |
|
649 if (len > 0) |
|
650 { |
|
651 octave_value_list lst; |
|
652 |
5275
|
653 for (octave_idx_type i = 0; i < len; i++) |
4687
|
654 { |
|
655 octave_value t2; |
|
656 bool dummy; |
|
657 std::string doc; |
|
658 |
|
659 // recurse to read list elements |
|
660 std::string nm = read_binary_data (is, swap, fmt, std::string (), |
|
661 dummy, t2, doc); |
|
662 |
|
663 if (!is) |
|
664 return false; |
|
665 |
|
666 lst.append(t2); |
|
667 } |
|
668 |
|
669 if (is) |
|
670 data = lst; |
|
671 else |
|
672 { |
|
673 error ("load: failed to load list"); |
|
674 return false; |
|
675 } |
|
676 |
|
677 } |
|
678 else if (len == 0 ) |
|
679 data = Cell (0, 0); |
|
680 else |
|
681 return false; |
|
682 |
|
683 return true; |
|
684 } |
|
685 |
|
686 #if defined (HAVE_HDF5) |
4944
|
687 |
4687
|
688 bool |
|
689 octave_list::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) |
|
690 { |
|
691 hid_t data_hid = -1; |
|
692 |
|
693 data_hid = H5Gcreate (loc_id, name, 0); |
|
694 if (data_hid < 0) return false; |
|
695 |
|
696 // recursively add each element of the list to this group |
|
697 octave_value_list lst = list_value (); |
|
698 |
5275
|
699 for (octave_idx_type i = 0; i < lst.length (); ++i) |
4687
|
700 { |
|
701 // should we use lst.name_tags () to label the elements? |
5717
|
702 |
5765
|
703 std::ostringstream buf; |
|
704 buf << "_" << i; |
|
705 std::string s = buf.str (); |
5717
|
706 |
|
707 bool retval2 = add_hdf5_data (data_hid, lst (i), s.c_str (), "", |
4687
|
708 false, save_as_floats); |
|
709 if (! retval2) |
|
710 break; |
|
711 } |
|
712 |
|
713 H5Gclose (data_hid); |
4837
|
714 |
4687
|
715 return true; |
|
716 } |
|
717 |
|
718 bool |
|
719 octave_list::load_hdf5 (hid_t loc_id, const char *name, |
|
720 bool have_h5giterate_bug) |
|
721 { |
|
722 bool retval = false; |
|
723 |
|
724 hdf5_callback_data dsub; |
|
725 |
4696
|
726 herr_t retval2 = -1; |
4687
|
727 octave_value_list lst; |
|
728 int current_item = 0; |
4696
|
729 #ifdef HAVE_H5GGET_NUM_OBJS |
|
730 hsize_t num_obj = 0; |
5060
|
731 hid_t group_id = H5Gopen (loc_id, name); |
|
732 H5Gget_num_objs (group_id, &num_obj); |
|
733 H5Gclose (group_id); |
4696
|
734 |
|
735 while (current_item < static_cast<int> (num_obj) |
|
736 && (retval2 = H5Giterate (loc_id, name, ¤t_item, |
|
737 hdf5_read_next_data, &dsub)) > 0) |
|
738 #else |
4687
|
739 while ((retval2 = H5Giterate (loc_id, name, ¤t_item, |
|
740 hdf5_read_next_data, &dsub)) > 0) |
4696
|
741 #endif |
4687
|
742 { |
|
743 lst.append (dsub.tc); |
|
744 |
|
745 if (have_h5giterate_bug) |
|
746 current_item++; // H5Giterate returned the last index processed |
|
747 } |
|
748 |
|
749 if (retval2 >= 0) |
|
750 { |
|
751 data = lst; |
|
752 retval = true; |
|
753 } |
|
754 |
|
755 return retval; |
|
756 } |
4944
|
757 |
4687
|
758 #endif |
|
759 |
2882
|
760 /* |
|
761 ;;; Local Variables: *** |
|
762 ;;; mode: C++ *** |
|
763 ;;; End: *** |
|
764 */ |