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