Fix some easy to fix warnings
[scilab.git] / scilab / modules / hdf5 / src / cpp / H5Type.cpp
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15
16 #include "H5Type.hxx"
17
18 namespace org_modules_hdf5
19 {
20
21 std::map<std::string, hid_t> H5Type::nameToType = initMap();
22
23 void H5Type::init()
24 {
25     type = H5Topen(getParent().getH5Id(), name.c_str(), H5P_DEFAULT);
26     if (type < 0)
27     {
28         throw H5Exception(__LINE__, __FILE__, _("Invalid H5Type name: %s."), name.c_str());
29     }
30 }
31
32 H5Type::H5Type(H5Object & _parent, const hid_t _type) : H5Object(_parent), type(_type)
33 {
34
35 }
36
37 H5Type::H5Type(H5Object & _parent, const hid_t _type, const std::string & _name) : H5Object(_parent, _name), type(_type)
38 {
39
40 }
41
42 H5Type::H5Type(H5Object & _parent, const std::string & _name) : H5Object(_parent, _name)
43 {
44     init();
45 }
46
47 H5Type::~H5Type()
48 {
49     if (type >= 0)
50     {
51         H5Tclose(type);
52     }
53 }
54
55 std::string H5Type::getClassName() const
56 {
57     switch (H5Tget_class(type))
58     {
59         case H5T_INTEGER:
60             return "integer";
61         case H5T_FLOAT:
62             return "float";
63         case H5T_TIME:
64             return "time";
65         case H5T_STRING:
66             return "string";
67         case H5T_BITFIELD:
68             return "bitfield";
69         case H5T_OPAQUE:
70             return "opaque";
71         case H5T_COMPOUND:
72             return "compound";
73         case H5T_REFERENCE:
74             return "reference";
75         case H5T_ENUM:
76             return "enum";
77         case H5T_VLEN:
78             return "vlen";
79         case H5T_ARRAY:
80             return "array";
81         default:
82             return "unknown";
83     }
84 }
85
86 unsigned int H5Type::getTypeSize() const
87 {
88     return (unsigned int)H5Tget_size(type);
89 }
90
91 std::string H5Type::getTypeName() const
92 {
93     return getNameFromType(type);
94 }
95
96 unsigned int H5Type::getNativeTypeSize() const
97 {
98     const hid_t nativeType = H5Tget_native_type(type, H5T_DIR_DEFAULT);
99     unsigned int size = (unsigned int)H5Tget_size(nativeType);
100     H5Tclose(nativeType);
101
102     return size;
103 }
104
105 std::string H5Type::getNativeTypeName() const
106 {
107     const hid_t nativeType = H5Tget_native_type(type, H5T_DIR_DEFAULT);
108     std::string name = getNameFromType(nativeType);
109     H5Tclose(nativeType);
110
111     return name;
112 }
113
114 std::string H5Type::getNameFromType(hid_t type)
115 {
116     std::string sorder, ssign;
117     std::ostringstream os;
118     H5T_sign_t sign;
119     H5T_order_t order;
120
121     switch (H5Tget_class(type))
122     {
123         case H5T_INTEGER:
124             if (H5Tequal(type, H5T_STD_I8BE) > 0)
125             {
126                 return "H5T_STD_I8BE";
127             }
128             else if (H5Tequal(type, H5T_STD_I8LE) > 0)
129             {
130                 return "H5T_STD_I8LE";
131             }
132             else if (H5Tequal(type, H5T_STD_I16BE) > 0)
133             {
134                 return "H5T_STD_I16BE";
135             }
136             else if (H5Tequal(type, H5T_STD_I16LE) > 0)
137             {
138                 return "H5T_STD_I16LE";
139             }
140             else if (H5Tequal(type, H5T_STD_I32BE) > 0)
141             {
142                 return "H5T_STD_I32BE";
143             }
144             else if (H5Tequal(type, H5T_STD_I32LE) > 0)
145             {
146                 return "H5T_STD_I32LE";
147             }
148             else if (H5Tequal(type, H5T_STD_I64BE) > 0)
149             {
150                 return "H5T_STD_I64BE";
151             }
152             else if (H5Tequal(type, H5T_STD_I64LE) > 0)
153             {
154                 return "H5T_STD_I64LE";
155             }
156             else if (H5Tequal(type, H5T_STD_U8BE) > 0)
157             {
158                 return "H5T_STD_U8BE";
159             }
160             else if (H5Tequal(type, H5T_STD_U8LE) > 0)
161             {
162                 return "H5T_STD_U8LE";
163             }
164             else if (H5Tequal(type, H5T_STD_U16BE) > 0)
165             {
166                 return "H5T_STD_U16BE";
167             }
168             else if (H5Tequal(type, H5T_STD_U16LE) > 0)
169             {
170                 return "H5T_STD_U16LE";
171             }
172             else if (H5Tequal(type, H5T_STD_U32BE) > 0)
173             {
174                 return "H5T_STD_U32BE";
175             }
176             else if (H5Tequal(type, H5T_STD_U32LE) > 0)
177             {
178                 return "H5T_STD_U32LE";
179             }
180             else if (H5Tequal(type, H5T_STD_U64BE) > 0)
181             {
182                 return "H5T_STD_U64BE";
183             }
184             else if (H5Tequal(type, H5T_STD_U64LE) > 0)
185             {
186                 return "H5T_STD_U64LE";
187             }
188             else if (H5Tequal(type, H5T_NATIVE_SCHAR) > 0)
189             {
190                 return "H5T_NATIVE_SCHAR";
191             }
192             else if (H5Tequal(type, H5T_NATIVE_UCHAR) > 0)
193             {
194                 return "H5T_NATIVE_UCHAR";
195             }
196             else if (H5Tequal(type, H5T_NATIVE_SHORT) > 0)
197             {
198                 return "H5T_NATIVE_SHORT";
199             }
200             else if (H5Tequal(type, H5T_NATIVE_USHORT) > 0)
201             {
202                 return "H5T_NATIVE_USHORT";
203             }
204             else if (H5Tequal(type, H5T_NATIVE_INT) > 0)
205             {
206                 return "H5T_NATIVE_INT";
207             }
208             else if (H5Tequal(type, H5T_NATIVE_UINT) > 0)
209             {
210                 return "H5T_NATIVE_UINT";
211             }
212             else if (H5Tequal(type, H5T_NATIVE_LONG) > 0)
213             {
214                 return "H5T_NATIVE_LONG";
215             }
216             else if (H5Tequal(type, H5T_NATIVE_ULONG) > 0)
217             {
218                 return "H5T_NATIVE_ULONG";
219             }
220             else if (H5Tequal(type, H5T_NATIVE_LLONG) > 0)
221             {
222                 return "H5T_NATIVE_LLONG";
223             }
224             else if (H5Tequal(type, H5T_NATIVE_ULLONG) > 0)
225             {
226                 return "H5T_NATIVE_ULLONG";
227             }
228             else if (H5Tequal(type, H5T_NATIVE_INT8) > 0)
229             {
230                 return "H5T_NATIVE_INT8";
231             }
232             else if (H5Tequal(type, H5T_NATIVE_UINT8) > 0)
233             {
234                 return "H5T_NATIVE_UINT8";
235             }
236             else if (H5Tequal(type, H5T_NATIVE_INT_LEAST8) > 0)
237             {
238                 return "H5T_NATIVE_INT_LEAST8";
239             }
240             else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST8) > 0)
241             {
242                 return "H5T_NATIVE_UINT_LEAST8";
243             }
244             else if (H5Tequal(type, H5T_NATIVE_INT_FAST8) > 0)
245             {
246                 return "H5T_NATIVE_INT_FAST8";
247             }
248             else if (H5Tequal(type, H5T_NATIVE_UINT_FAST8) > 0)
249             {
250                 return "H5T_NATIVE_UINT_FAST8";
251             }
252             else if (H5Tequal(type, H5T_NATIVE_INT16) > 0)
253             {
254                 return "H5T_NATIVE_INT16";
255             }
256             else if (H5Tequal(type, H5T_NATIVE_UINT16) > 0)
257             {
258                 return "H5T_NATIVE_UINT16";
259             }
260             else if (H5Tequal(type, H5T_NATIVE_INT_LEAST16) > 0)
261             {
262                 return "H5T_NATIVE_INT_LEAST16";
263             }
264             else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST16) > 0)
265             {
266                 return "H5T_NATIVE_UINT_LEAST16";
267             }
268             else if (H5Tequal(type, H5T_NATIVE_INT_FAST16) > 0)
269             {
270                 return "H5T_NATIVE_INT_FAST16";
271             }
272             else if (H5Tequal(type, H5T_NATIVE_UINT_FAST16) > 0)
273             {
274                 return "H5T_NATIVE_UINT_FAST16";
275             }
276             else if (H5Tequal(type, H5T_NATIVE_INT32) > 0)
277             {
278                 return "H5T_NATIVE_INT32";
279             }
280             else if (H5Tequal(type, H5T_NATIVE_UINT32) > 0)
281             {
282                 return "H5T_NATIVE_UINT32";
283             }
284             else if (H5Tequal(type, H5T_NATIVE_INT_LEAST32) > 0)
285             {
286                 return "H5T_NATIVE_INT_LEAST32";
287             }
288             else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST32) > 0)
289             {
290                 return "H5T_NATIVE_UINT_LEAST32";
291             }
292             else if (H5Tequal(type, H5T_NATIVE_INT_FAST32) > 0)
293             {
294                 return "H5T_NATIVE_INT_FAST32";
295             }
296             else if (H5Tequal(type, H5T_NATIVE_UINT_FAST32) > 0)
297             {
298                 return "H5T_NATIVE_UINT_FAST32";
299             }
300             else if (H5Tequal(type, H5T_NATIVE_INT64) > 0)
301             {
302                 return "H5T_NATIVE_INT64";
303             }
304             else if (H5Tequal(type, H5T_NATIVE_UINT64) > 0)
305             {
306                 return "H5T_NATIVE_UINT64";
307             }
308             else if (H5Tequal(type, H5T_NATIVE_INT_LEAST64) > 0)
309             {
310                 return "H5T_NATIVE_INT_LEAST64";
311             }
312             else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST64) > 0)
313             {
314                 return "H5T_NATIVE_UINT_LEAST64";
315             }
316             else if (H5Tequal(type, H5T_NATIVE_INT_FAST64) > 0)
317             {
318                 return "H5T_NATIVE_INT_FAST64";
319             }
320             else if (H5Tequal(type, H5T_NATIVE_UINT_FAST64) > 0)
321             {
322                 return "H5T_NATIVE_UINT_FAST64";
323             }
324             else if (H5Tequal(type, H5T_INTEL_I8) > 0)
325             {
326                 return "H5T_INTEL_I8";
327             }
328             else if (H5Tequal(type, H5T_INTEL_I16) > 0)
329             {
330                 return "H5T_INTEL_I16";
331             }
332             else if (H5Tequal(type, H5T_INTEL_I32) > 0)
333             {
334                 return "H5T_INTEL_I32";
335             }
336             else if (H5Tequal(type, H5T_INTEL_I64) > 0)
337             {
338                 return "H5T_INTEL_I64";
339             }
340             else if (H5Tequal(type, H5T_INTEL_U8) > 0)
341             {
342                 return "H5T_INTEL_U8";
343             }
344             else if (H5Tequal(type, H5T_INTEL_U16) > 0)
345             {
346                 return "H5T_INTEL_U16";
347             }
348             else if (H5Tequal(type, H5T_INTEL_U32) > 0)
349             {
350                 return "H5T_INTEL_U32";
351             }
352             else if (H5Tequal(type, H5T_INTEL_U64) > 0)
353             {
354                 return "H5T_INTEL_U64";
355             }
356             else if (H5Tequal(type, H5T_ALPHA_I8) > 0)
357             {
358                 return "H5T_ALPHA_I8";
359             }
360             else if (H5Tequal(type, H5T_ALPHA_I16) > 0)
361             {
362                 return "H5T_ALPHA_I16";
363             }
364             else if (H5Tequal(type, H5T_ALPHA_I32) > 0)
365             {
366                 return "H5T_ALPHA_I32";
367             }
368             else if (H5Tequal(type, H5T_ALPHA_I64) > 0)
369             {
370                 return "H5T_ALPHA_I64";
371             }
372             else if (H5Tequal(type, H5T_ALPHA_U8) > 0)
373             {
374                 return "H5T_ALPHA_U8";
375             }
376             else if (H5Tequal(type, H5T_ALPHA_U16) > 0)
377             {
378                 return "H5T_ALPHA_U16";
379             }
380             else if (H5Tequal(type, H5T_ALPHA_U32) > 0)
381             {
382                 return "H5T_ALPHA_U32";
383             }
384             else if (H5Tequal(type, H5T_ALPHA_U64) > 0)
385             {
386                 return "H5T_ALPHA_U64";
387             }
388             else if (H5Tequal(type, H5T_MIPS_I8) > 0)
389             {
390                 return "H5T_MIPS_I8";
391             }
392             else if (H5Tequal(type, H5T_MIPS_I16) > 0)
393             {
394                 return "H5T_MIPS_I16";
395             }
396             else if (H5Tequal(type, H5T_MIPS_I32) > 0)
397             {
398                 return "H5T_MIPS_I32";
399             }
400             else if (H5Tequal(type, H5T_MIPS_I64) > 0)
401             {
402                 return "H5T_MIPS_I64";
403             }
404             else if (H5Tequal(type, H5T_MIPS_U8) > 0)
405             {
406                 return "H5T_MIPS_U8";
407             }
408             else if (H5Tequal(type, H5T_MIPS_U16) > 0)
409             {
410                 return "H5T_MIPS_U16";
411             }
412             else if (H5Tequal(type, H5T_MIPS_U32) > 0)
413             {
414                 return "H5T_MIPS_U32";
415             }
416             else if (H5Tequal(type, H5T_MIPS_U64) > 0)
417             {
418                 return "H5T_MIPS_U64";
419             }
420             else if (H5Tequal(type, H5T_NATIVE_HADDR) > 0)
421             {
422                 return "H5T_NATIVE_HADDR";
423             }
424             else if (H5Tequal(type, H5T_NATIVE_HSIZE) > 0)
425             {
426                 return "H5T_NATIVE_HSIZE";
427             }
428             else if (H5Tequal(type, H5T_NATIVE_HSSIZE) > 0)
429             {
430                 return "H5T_NATIVE_HSSIZE";
431             }
432             else if (H5Tequal(type, H5T_NATIVE_HERR) > 0)
433             {
434                 return "H5T_NATIVE_HERR";
435             }
436             else if (H5Tequal(type, H5T_NATIVE_HBOOL) > 0)
437             {
438                 return "H5T_NATIVE_HBOOL";
439             }
440             else
441             {
442                 if (H5Tget_size(type) > 1)
443                 {
444                     order = H5Tget_order(type);
445                     if (H5T_ORDER_LE == order)
446                     {
447                         sorder = " little-endian";
448                     }
449                     else if (H5T_ORDER_BE == order)
450                     {
451                         sorder = " big-endian";
452                     }
453                     else if (H5T_ORDER_VAX == order)
454                     {
455                         sorder = " mixed-endian";
456                     }
457                     else
458                     {
459                         sorder = " unknown-byte-order";
460                     }
461                 }
462                 else
463                 {
464                     sorder = "";
465                 }
466
467                 sign = H5Tget_sign(type);
468                 if (sign >= 0)
469                 {
470                     if (sign == H5T_SGN_NONE)
471                     {
472                         ssign = " unsigned";
473                     }
474                     else if (sign == H5T_SGN_2)
475                     {
476                         ssign = "";
477                     }
478                     else
479                     {
480                         ssign = " unknown-sign";
481                     }
482                 }
483                 else
484                 {
485                     ssign = " unknown-sign";
486                 }
487
488                 os << (unsigned long)(8 * H5Tget_size(type)) << "-bit"
489                    << sorder
490                    << ssign
491                    << " integer";
492
493                 return os.str();
494             }
495             break;
496         case H5T_FLOAT:
497             if (H5Tequal(type, H5T_IEEE_F32BE) > 0)
498             {
499                 return "H5T_IEEE_F32BE";
500             }
501             else if (H5Tequal(type, H5T_IEEE_F32LE) > 0)
502             {
503                 return "H5T_IEEE_F32LE";
504             }
505             else if (H5Tequal(type, H5T_IEEE_F64BE) > 0)
506             {
507                 return "H5T_IEEE_F64BE";
508             }
509             else if (H5Tequal(type, H5T_IEEE_F64LE) > 0)
510             {
511                 return "H5T_IEEE_F64LE";
512             }
513             else if (H5Tequal(type, H5T_VAX_F32) > 0)
514             {
515                 return "H5T_VAX_F32";
516             }
517             else if (H5Tequal(type, H5T_VAX_F64) > 0)
518             {
519                 return "H5T_VAX_F64";
520             }
521             else if (H5Tequal(type, H5T_NATIVE_FLOAT) > 0)
522             {
523                 return "H5T_NATIVE_FLOAT";
524             }
525             else if (H5Tequal(type, H5T_NATIVE_DOUBLE) > 0)
526             {
527                 return "H5T_NATIVE_DOUBLE";
528             }
529             else if (H5Tequal(type, H5T_NATIVE_LDOUBLE) > 0)
530             {
531                 return "H5T_NATIVE_LDOUBLE";
532             }
533             else if (H5Tequal(type, H5T_INTEL_F32) > 0)
534             {
535                 return "H5T_INTEL_F32";
536             }
537             else if (H5Tequal(type, H5T_INTEL_F64) > 0)
538             {
539                 return "H5T_INTEL_F64";
540             }
541             else if (H5Tequal(type, H5T_ALPHA_F32) > 0)
542             {
543                 return "H5T_ALPHA_F32";
544             }
545             else if (H5Tequal(type, H5T_ALPHA_F64) > 0)
546             {
547                 return "H5T_ALPHA_F64";
548             }
549             else if (H5Tequal(type, H5T_VAX_F32) > 0)
550             {
551                 return "H5T_VAX_F32";
552             }
553             else if (H5Tequal(type, H5T_VAX_F64) > 0)
554             {
555                 return "H5T_VAX_F64";
556             }
557             else if (H5Tequal(type, H5T_MIPS_F32) > 0)
558             {
559                 return "H5T_MIPS_F32";
560             }
561             else if (H5Tequal(type, H5T_MIPS_F64) > 0)
562             {
563                 return "H5T_MIPS_F64";
564             }
565             else
566             {
567                 if (H5Tget_size(type) > 1)
568                 {
569                     order = H5Tget_order(type);
570                     if (order == H5T_ORDER_LE)
571                     {
572                         sorder = " little-endian";
573                     }
574                     else if (order == H5T_ORDER_BE)
575                     {
576                         sorder = " big-endian";
577                     }
578                     else if (order == H5T_ORDER_VAX)
579                     {
580                         sorder = " mixed-endian";
581                     }
582                     else
583                     {
584                         sorder = " unknown-byte-order";
585                     }
586                 }
587                 else
588                 {
589                     sorder = "";
590                 }
591
592                 os << (unsigned long)(8 * H5Tget_size(type)) << "-bit"
593                    << sorder
594                    << " floating-point";
595
596                 return os.str();
597             }
598             break;
599         case H5T_TIME:
600             if (H5Tequal(type, H5T_UNIX_D32BE) > 0)
601             {
602                 return "H5T_UNIX_D32BE";
603             }
604             else if (H5Tequal(type, H5T_UNIX_D32LE) > 0)
605             {
606                 return "H5T_UNIX_D32LE";
607             }
608             else if (H5Tequal(type, H5T_UNIX_D64BE) > 0)
609             {
610                 return "H5T_UNIX_D64BE";
611             }
612             else if (H5Tequal(type, H5T_UNIX_D64LE) > 0)
613             {
614                 return "H5T_UNIX_D64LE";
615             }
616             else
617             {
618                 return "Unknown time format";
619             }
620             break;
621         case H5T_STRING:
622             return "H5T_STRING";
623         case H5T_BITFIELD:
624             if (H5Tequal(type, H5T_STD_B8BE) > 0)
625             {
626                 return "H5T_STD_B8BE";
627             }
628             else if (H5Tequal(type, H5T_STD_B8LE) > 0)
629             {
630                 return "H5T_STD_B8LE";
631             }
632             else if (H5Tequal(type, H5T_STD_B16BE) > 0)
633             {
634                 return "H5T_STD_B16BE";
635             }
636             else if (H5Tequal(type, H5T_STD_B16LE) > 0)
637             {
638                 return "H5T_STD_B16LE";
639             }
640             else if (H5Tequal(type, H5T_STD_B32BE) > 0)
641             {
642                 return "H5T_STD_B32BE";
643             }
644             else if (H5Tequal(type, H5T_STD_B32LE) > 0)
645             {
646                 return "H5T_STD_B32LE";
647             }
648             else if (H5Tequal(type, H5T_STD_B64BE) > 0)
649             {
650                 return "H5T_STD_B64BE";
651             }
652             else if (H5Tequal(type, H5T_STD_B64LE) > 0)
653             {
654                 return "H5T_STD_B64LE";
655             }
656             else if (H5Tequal(type, H5T_INTEL_B8) > 0)
657             {
658                 return "H5T_INTEL_B8";
659             }
660             else if (H5Tequal(type, H5T_INTEL_B16) > 0)
661             {
662                 return "H5T_INTEL_B16";
663             }
664             else if (H5Tequal(type, H5T_INTEL_B32) > 0)
665             {
666                 return "H5T_INTEL_B32";
667             }
668             else if (H5Tequal(type, H5T_INTEL_B64) > 0)
669             {
670                 return "H5T_INTEL_B64";
671             }
672             else if (H5Tequal(type, H5T_ALPHA_B8) > 0)
673             {
674                 return "H5T_ALPHA_B8";
675             }
676             else if (H5Tequal(type, H5T_ALPHA_B16) > 0)
677             {
678                 return "H5T_ALPHA_B16";
679             }
680             else if (H5Tequal(type, H5T_ALPHA_B32) > 0)
681             {
682                 return "H5T_ALPHA_B32";
683             }
684             else if (H5Tequal(type, H5T_ALPHA_B64) > 0)
685             {
686                 return "H5T_ALPHA_B64";
687             }
688             else if (H5Tequal(type, H5T_MIPS_B8) > 0)
689             {
690                 return "H5T_MIPS_B8";
691             }
692             else if (H5Tequal(type, H5T_MIPS_B16) > 0)
693             {
694                 return "H5T_MIPS_B16";
695             }
696             else if (H5Tequal(type, H5T_MIPS_B32) > 0)
697             {
698                 return "H5T_MIPS_B32";
699             }
700             else if (H5Tequal(type, H5T_MIPS_B64) > 0)
701             {
702                 return "H5T_MIPS_B64";
703             }
704             else
705             {
706                 return "undefined bitfield";
707             }
708         case H5T_OPAQUE:
709             return "H5T_OPAQUE";
710         case H5T_COMPOUND:
711             return "H5T_COMPOUND";
712         case H5T_REFERENCE:
713             if (H5Tequal(type, H5T_STD_REF_DSETREG) > 0)
714             {
715                 return "H5T_STD_REF_DSETREG";
716             }
717             else
718             {
719                 return "H5T_STD_REF_OBJECT";
720             }
721         case H5T_ENUM:
722             return "H5T_ENUM";
723         case H5T_VLEN:
724             return "H5T_VLEN";
725         case H5T_ARRAY:
726             return "H5T_ARRAY";
727         default:
728             return _("Unknown datatype");
729     }
730     return _("Unknown datatype");
731 }
732
733 void H5Type::printComplexNameFromType(std::ostringstream & os, const unsigned int indentLevel, const hid_t type)
734 {
735     std::string indent = H5Object::getIndentString(indentLevel);
736     if (H5Tget_class(type) == H5T_COMPOUND)
737     {
738         unsigned int nmembers = H5Tget_nmembers(type);
739
740         os << indent << "H5T_COMPOUND {" << std::endl;
741
742         for (unsigned int i = 0; i < nmembers; i++)
743         {
744             char * mname = H5Tget_member_name(type, i);
745             hid_t mtype = H5Tget_member_type(type, i);
746
747             os << indent;
748             H5Type::printComplexNameFromType(os, indentLevel + 1, mtype);
749             os << " \"" << mname << "\";" << std::endl;
750             os << std::endl;
751
752             free(mname);
753         }
754
755         os << indent << "}";
756     }
757     else if (H5Tget_class(type) == H5T_ARRAY)
758     {
759         hid_t super = H5Tget_super(type);
760         unsigned int ndims = H5Tget_array_ndims(type);
761         hsize_t * dims = new hsize_t[ndims];
762         H5Tget_array_dims(type, dims);
763
764         os << indent << "H5T_ARRAY { ";
765
766         for (unsigned int i = 0; i < ndims; i++)
767         {
768             os << "[" << (unsigned int)dims[i] << "]";
769         }
770
771         os << " ";
772         H5Type::printComplexNameFromType(os, indentLevel + 1, super);
773         os <<  " }";
774         H5Tclose(super);
775     }
776     else if (H5Tget_class(type) == H5T_VLEN)
777     {
778         hid_t super = H5Tget_super(type);
779         os << indent << "H5T_VLEN { ";
780         H5Type::printComplexNameFromType(os, indentLevel + 1, super);
781         os << " }";
782         H5Tclose(super);
783     }
784     else
785     {
786         os << getNameFromType(type);
787     }
788 }
789
790 void H5Type::getAccessibleAttribute(const std::string & _name, const int pos, void * pvApiCtx) const
791 {
792     SciErr err;
793     std::string lower(_name);
794     std::transform(_name.begin(), _name.end(), lower.begin(), tolower);
795
796     if (lower == "class")
797     {
798         std::string _class = getClassName();
799         const char * __class = _class.c_str();
800         err = createMatrixOfString(pvApiCtx, pos, 1, 1, &__class);
801         if (err.iErr)
802         {
803             throw H5Exception(__LINE__, __FILE__, _("Cannot create a string on the stack."));
804         }
805
806         return;
807     }
808     else if (lower == "type")
809     {
810         std::string type = getTypeName();
811         const char * _type = type.c_str();
812         err = createMatrixOfString(pvApiCtx, pos, 1, 1, &_type);
813         if (err.iErr)
814         {
815             throw H5Exception(__LINE__, __FILE__, _("Cannot create a string on the stack."));
816         }
817
818         return;
819     }
820     else if (lower == "size")
821     {
822         unsigned int size = getTypeSize();
823         err = createMatrixOfUnsignedInteger32(pvApiCtx, pos, 1, 1, &size);
824         if (err.iErr)
825         {
826             throw H5Exception(__LINE__, __FILE__, _("Cannot create an integer on the stack."));
827         }
828
829         return;
830     }
831     else if (lower == "nativetype")
832     {
833         std::string type = getNativeTypeName();
834         const char * _type = type.c_str();
835         err = createMatrixOfString(pvApiCtx, pos, 1, 1, &_type);
836         if (err.iErr)
837         {
838             throw H5Exception(__LINE__, __FILE__, _("Cannot create a string on the stack."));
839         }
840
841         return;
842     }
843     else if (lower == "nativesize")
844     {
845         unsigned int size = getNativeTypeSize();
846         err = createMatrixOfUnsignedInteger32(pvApiCtx, pos, 1, 1, &size);
847         if (err.iErr)
848         {
849             throw H5Exception(__LINE__, __FILE__, _("Cannot create an integer on the stack."));
850         }
851
852         return;
853     }
854
855     H5Object::getAccessibleAttribute(_name, pos, pvApiCtx);
856 }
857
858 std::string H5Type::dump(std::map<haddr_t, std::string> & alreadyVisited, const unsigned int indentLevel) const
859 {
860     std::string sorder, ssign;
861     std::ostringstream os;
862     H5T_sign_t sign;
863     hsize_t * dims = 0;
864     unsigned int ndims;
865     hid_t strType;
866     hid_t super;
867     hid_t native = -1;
868     size_t size;
869     size_t dstSize;
870     unsigned int nmembers;
871     H5T_order_t order;
872     H5T_str_t strpad;
873     H5T_cset_t cset;
874     htri_t isVariableLength;
875     std::string indent;
876     char * opaqueTag = 0;
877     char * value = 0;
878
879     os << H5Object::getIndentString(indentLevel);
880
881     if (!name.empty())
882     {
883         os << "DATATYPE \"" << name << "\" ";
884     }
885     else
886     {
887         os << "DATATYPE ";
888     }
889
890     switch (H5Tget_class(type))
891     {
892         case H5T_INTEGER:
893             if (H5Tequal(type, H5T_STD_I8BE) > 0)
894             {
895                 os << "H5T_STD_I8BE";
896             }
897             else if (H5Tequal(type, H5T_STD_I8LE) > 0)
898             {
899                 os << "H5T_STD_I8LE";
900             }
901             else if (H5Tequal(type, H5T_STD_I16BE) > 0)
902             {
903                 os << "H5T_STD_I16BE";
904             }
905             else if (H5Tequal(type, H5T_STD_I16LE) > 0)
906             {
907                 os << "H5T_STD_I16LE";
908             }
909             else if (H5Tequal(type, H5T_STD_I32BE) > 0)
910             {
911                 os << "H5T_STD_I32BE";
912             }
913             else if (H5Tequal(type, H5T_STD_I32LE) > 0)
914             {
915                 os << "H5T_STD_I32LE";
916             }
917             else if (H5Tequal(type, H5T_STD_I64BE) > 0)
918             {
919                 os << "H5T_STD_I64BE";
920             }
921             else if (H5Tequal(type, H5T_STD_I64LE) > 0)
922             {
923                 os << "H5T_STD_I64LE";
924             }
925             else if (H5Tequal(type, H5T_STD_U8BE) > 0)
926             {
927                 os << "H5T_STD_U8BE";
928             }
929             else if (H5Tequal(type, H5T_STD_U8LE) > 0)
930             {
931                 os << "H5T_STD_U8LE";
932             }
933             else if (H5Tequal(type, H5T_STD_U16BE) > 0)
934             {
935                 os << "H5T_STD_U16BE";
936             }
937             else if (H5Tequal(type, H5T_STD_U16LE) > 0)
938             {
939                 os << "H5T_STD_U16LE";
940             }
941             else if (H5Tequal(type, H5T_STD_U32BE) > 0)
942             {
943                 os << "H5T_STD_U32BE";
944             }
945             else if (H5Tequal(type, H5T_STD_U32LE) > 0)
946             {
947                 os << "H5T_STD_U32LE";
948             }
949             else if (H5Tequal(type, H5T_STD_U64BE) > 0)
950             {
951                 os << "H5T_STD_U64BE";
952             }
953             else if (H5Tequal(type, H5T_STD_U64LE) > 0)
954             {
955                 os << "H5T_STD_U64LE";
956             }
957             else if (H5Tequal(type, H5T_NATIVE_SCHAR) > 0)
958             {
959                 os << "H5T_NATIVE_SCHAR";
960             }
961             else if (H5Tequal(type, H5T_NATIVE_UCHAR) > 0)
962             {
963                 os << "H5T_NATIVE_UCHAR";
964             }
965             else if (H5Tequal(type, H5T_NATIVE_SHORT) > 0)
966             {
967                 os << "H5T_NATIVE_SHORT";
968             }
969             else if (H5Tequal(type, H5T_NATIVE_USHORT) > 0)
970             {
971                 os << "H5T_NATIVE_USHORT";
972             }
973             else if (H5Tequal(type, H5T_NATIVE_INT) > 0)
974             {
975                 os << "H5T_NATIVE_INT";
976             }
977             else if (H5Tequal(type, H5T_NATIVE_UINT) > 0)
978             {
979                 os << "H5T_NATIVE_UINT";
980             }
981             else if (H5Tequal(type, H5T_NATIVE_LONG) > 0)
982             {
983                 os << "H5T_NATIVE_LONG";
984             }
985             else if (H5Tequal(type, H5T_NATIVE_ULONG) > 0)
986             {
987                 os << "H5T_NATIVE_ULONG";
988             }
989             else if (H5Tequal(type, H5T_NATIVE_LLONG) > 0)
990             {
991                 os << "H5T_NATIVE_LLONG";
992             }
993             else if (H5Tequal(type, H5T_NATIVE_ULLONG) > 0)
994             {
995                 os << "H5T_NATIVE_ULLONG";
996             }
997             else if (H5Tequal(type, H5T_NATIVE_INT8) > 0)
998             {
999                 os << "H5T_NATIVE_INT8";
1000             }
1001             else if (H5Tequal(type, H5T_NATIVE_UINT8) > 0)
1002             {
1003                 os << "H5T_NATIVE_UINT8";
1004             }
1005             else if (H5Tequal(type, H5T_NATIVE_INT_LEAST8) > 0)
1006             {
1007                 os << "H5T_NATIVE_INT_LEAST8";
1008             }
1009             else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST8) > 0)
1010             {
1011                 os << "H5T_NATIVE_UINT_LEAST8";
1012             }
1013             else if (H5Tequal(type, H5T_NATIVE_INT_FAST8) > 0)
1014             {
1015                 os << "H5T_NATIVE_INT_FAST8";
1016             }
1017             else if (H5Tequal(type, H5T_NATIVE_UINT_FAST8) > 0)
1018             {
1019                 os << "H5T_NATIVE_UINT_FAST8";
1020             }
1021             else if (H5Tequal(type, H5T_NATIVE_INT16) > 0)
1022             {
1023                 os << "H5T_NATIVE_INT16";
1024             }
1025             else if (H5Tequal(type, H5T_NATIVE_UINT16) > 0)
1026             {
1027                 os << "H5T_NATIVE_UINT16";
1028             }
1029             else if (H5Tequal(type, H5T_NATIVE_INT_LEAST16) > 0)
1030             {
1031                 os << "H5T_NATIVE_INT_LEAST16";
1032             }
1033             else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST16) > 0)
1034             {
1035                 os << "H5T_NATIVE_UINT_LEAST16";
1036             }
1037             else if (H5Tequal(type, H5T_NATIVE_INT_FAST16) > 0)
1038             {
1039                 os << "H5T_NATIVE_INT_FAST16";
1040             }
1041             else if (H5Tequal(type, H5T_NATIVE_UINT_FAST16) > 0)
1042             {
1043                 os << "H5T_NATIVE_UINT_FAST16";
1044             }
1045             else if (H5Tequal(type, H5T_NATIVE_INT32) > 0)
1046             {
1047                 os << "H5T_NATIVE_INT32";
1048             }
1049             else if (H5Tequal(type, H5T_NATIVE_UINT32) > 0)
1050             {
1051                 os << "H5T_NATIVE_UINT32";
1052             }
1053             else if (H5Tequal(type, H5T_NATIVE_INT_LEAST32) > 0)
1054             {
1055                 os << "H5T_NATIVE_INT_LEAST32";
1056             }
1057             else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST32) > 0)
1058             {
1059                 os << "H5T_NATIVE_UINT_LEAST32";
1060             }
1061             else if (H5Tequal(type, H5T_NATIVE_INT_FAST32) > 0)
1062             {
1063                 os << "H5T_NATIVE_INT_FAST32";
1064             }
1065             else if (H5Tequal(type, H5T_NATIVE_UINT_FAST32) > 0)
1066             {
1067                 os << "H5T_NATIVE_UINT_FAST32";
1068             }
1069             else if (H5Tequal(type, H5T_NATIVE_INT64) > 0)
1070             {
1071                 os << "H5T_NATIVE_INT64";
1072             }
1073             else if (H5Tequal(type, H5T_NATIVE_UINT64) > 0)
1074             {
1075                 os << "H5T_NATIVE_UINT64";
1076             }
1077             else if (H5Tequal(type, H5T_NATIVE_INT_LEAST64) > 0)
1078             {
1079                 os << "H5T_NATIVE_INT_LEAST64";
1080             }
1081             else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST64) > 0)
1082             {
1083                 os << "H5T_NATIVE_UINT_LEAST64";
1084             }
1085             else if (H5Tequal(type, H5T_NATIVE_INT_FAST64) > 0)
1086             {
1087                 os << "H5T_NATIVE_INT_FAST64";
1088             }
1089             else if (H5Tequal(type, H5T_NATIVE_UINT_FAST64) > 0)
1090             {
1091                 os << "H5T_NATIVE_UINT_FAST64";
1092             }
1093             else if (H5Tequal(type, H5T_INTEL_I8) > 0)
1094             {
1095                 os << "H5T_INTEL_I8";
1096             }
1097             else if (H5Tequal(type, H5T_INTEL_I16) > 0)
1098             {
1099                 os << "H5T_INTEL_I16";
1100             }
1101             else if (H5Tequal(type, H5T_INTEL_I32) > 0)
1102             {
1103                 os << "H5T_INTEL_I32";
1104             }
1105             else if (H5Tequal(type, H5T_INTEL_I64) > 0)
1106             {
1107                 os << "H5T_INTEL_I64";
1108             }
1109             else if (H5Tequal(type, H5T_INTEL_U8) > 0)
1110             {
1111                 os << "H5T_INTEL_U8";
1112             }
1113             else if (H5Tequal(type, H5T_INTEL_U16) > 0)
1114             {
1115                 os << "H5T_INTEL_U16";
1116             }
1117             else if (H5Tequal(type, H5T_INTEL_U32) > 0)
1118             {
1119                 os << "H5T_INTEL_U32";
1120             }
1121             else if (H5Tequal(type, H5T_INTEL_U64) > 0)
1122             {
1123                 os << "H5T_INTEL_U64";
1124             }
1125             else if (H5Tequal(type, H5T_ALPHA_I8) > 0)
1126             {
1127                 os << "H5T_ALPHA_I8";
1128             }
1129             else if (H5Tequal(type, H5T_ALPHA_I16) > 0)
1130             {
1131                 os << "H5T_ALPHA_I16";
1132             }
1133             else if (H5Tequal(type, H5T_ALPHA_I32) > 0)
1134             {
1135                 os << "H5T_ALPHA_I32";
1136             }
1137             else if (H5Tequal(type, H5T_ALPHA_I64) > 0)
1138             {
1139                 os << "H5T_ALPHA_I64";
1140             }
1141             else if (H5Tequal(type, H5T_ALPHA_U8) > 0)
1142             {
1143                 os << "H5T_ALPHA_U8";
1144             }
1145             else if (H5Tequal(type, H5T_ALPHA_U16) > 0)
1146             {
1147                 os << "H5T_ALPHA_U16";
1148             }
1149             else if (H5Tequal(type, H5T_ALPHA_U32) > 0)
1150             {
1151                 os << "H5T_ALPHA_U32";
1152             }
1153             else if (H5Tequal(type, H5T_ALPHA_U64) > 0)
1154             {
1155                 os << "H5T_ALPHA_U64";
1156             }
1157             else if (H5Tequal(type, H5T_MIPS_I8) > 0)
1158             {
1159                 os << "H5T_MIPS_I8";
1160             }
1161             else if (H5Tequal(type, H5T_MIPS_I16) > 0)
1162             {
1163                 os << "H5T_MIPS_I16";
1164             }
1165             else if (H5Tequal(type, H5T_MIPS_I32) > 0)
1166             {
1167                 os << "H5T_MIPS_I32";
1168             }
1169             else if (H5Tequal(type, H5T_MIPS_I64) > 0)
1170             {
1171                 os << "H5T_MIPS_I64";
1172             }
1173             else if (H5Tequal(type, H5T_MIPS_U8) > 0)
1174             {
1175                 os << "H5T_MIPS_U8";
1176             }
1177             else if (H5Tequal(type, H5T_MIPS_U16) > 0)
1178             {
1179                 os << "H5T_MIPS_U16";
1180             }
1181             else if (H5Tequal(type, H5T_MIPS_U32) > 0)
1182             {
1183                 os << "H5T_MIPS_U32";
1184             }
1185             else if (H5Tequal(type, H5T_MIPS_U64) > 0)
1186             {
1187                 os << "H5T_MIPS_U64";
1188             }
1189             else if (H5Tequal(type, H5T_NATIVE_HADDR) > 0)
1190             {
1191                 os << "H5T_NATIVE_HADDR";
1192             }
1193             else if (H5Tequal(type, H5T_NATIVE_HSIZE) > 0)
1194             {
1195                 os << "H5T_NATIVE_HSIZE";
1196             }
1197             else if (H5Tequal(type, H5T_NATIVE_HSSIZE) > 0)
1198             {
1199                 os << "H5T_NATIVE_HSSIZE";
1200             }
1201             else if (H5Tequal(type, H5T_NATIVE_HERR) > 0)
1202             {
1203                 os << "H5T_NATIVE_HERR";
1204             }
1205             else if (H5Tequal(type, H5T_NATIVE_HBOOL) > 0)
1206             {
1207                 os << "H5T_NATIVE_HBOOL";
1208             }
1209             else
1210             {
1211                 if (H5Tget_size(type) > 1)
1212                 {
1213                     order = H5Tget_order(type);
1214                     if (H5T_ORDER_LE == order)
1215                     {
1216                         sorder = " little-endian";
1217                     }
1218                     else if (H5T_ORDER_BE == order)
1219                     {
1220                         sorder = " big-endian";
1221                     }
1222                     else if (H5T_ORDER_VAX == order)
1223                     {
1224                         sorder = " mixed-endian";
1225                     }
1226                     else
1227                     {
1228                         sorder = " unknown-byte-order";
1229                     }
1230                 }
1231                 else
1232                 {
1233                     sorder = "";
1234                 }
1235
1236                 sign = H5Tget_sign(type);
1237                 if (sign >= 0)
1238                 {
1239                     if (sign == H5T_SGN_NONE)
1240                     {
1241                         ssign = " unsigned";
1242                     }
1243                     else if (sign == H5T_SGN_2)
1244                     {
1245                         ssign = "";
1246                     }
1247                     else
1248                     {
1249                         ssign = " unknown-sign";
1250                     }
1251                 }
1252                 else
1253                 {
1254                     ssign = " unknown-sign";
1255                 }
1256
1257                 os << (unsigned long)(8 * H5Tget_size(type)) << "-bit"
1258                    << sorder
1259                    << ssign
1260                    << " integer";
1261             }
1262             break;
1263         case H5T_FLOAT:
1264             if (H5Tequal(type, H5T_IEEE_F32BE) > 0)
1265             {
1266                 os << "H5T_IEEE_F32BE";
1267             }
1268             else if (H5Tequal(type, H5T_IEEE_F32LE) > 0)
1269             {
1270                 os << "H5T_IEEE_F32LE";
1271             }
1272             else if (H5Tequal(type, H5T_IEEE_F64BE) > 0)
1273             {
1274                 os << "H5T_IEEE_F64BE";
1275             }
1276             else if (H5Tequal(type, H5T_IEEE_F64LE) > 0)
1277             {
1278                 os << "H5T_IEEE_F64LE";
1279             }
1280             else if (H5Tequal(type, H5T_VAX_F32) > 0)
1281             {
1282                 os << "H5T_VAX_F32";
1283             }
1284             else if (H5Tequal(type, H5T_VAX_F64) > 0)
1285             {
1286                 os << "H5T_VAX_F64";
1287             }
1288             else if (H5Tequal(type, H5T_NATIVE_FLOAT) > 0)
1289             {
1290                 os << "H5T_NATIVE_FLOAT";
1291             }
1292             else if (H5Tequal(type, H5T_NATIVE_DOUBLE) > 0)
1293             {
1294                 os << "H5T_NATIVE_DOUBLE";
1295             }
1296             else if (H5Tequal(type, H5T_NATIVE_LDOUBLE) > 0)
1297             {
1298                 os << "H5T_NATIVE_LDOUBLE";
1299             }
1300             else if (H5Tequal(type, H5T_INTEL_F32) > 0)
1301             {
1302                 os << "H5T_INTEL_F32";
1303             }
1304             else if (H5Tequal(type, H5T_INTEL_F64) > 0)
1305             {
1306                 os << "H5T_INTEL_F64";
1307             }
1308             else if (H5Tequal(type, H5T_ALPHA_F32) > 0)
1309             {
1310                 os << "H5T_ALPHA_F32";
1311             }
1312             else if (H5Tequal(type, H5T_ALPHA_F64) > 0)
1313             {
1314                 os << "H5T_ALPHA_F64";
1315             }
1316             else if (H5Tequal(type, H5T_VAX_F32) > 0)
1317             {
1318                 os << "H5T_VAX_F32";
1319             }
1320             else if (H5Tequal(type, H5T_VAX_F64) > 0)
1321             {
1322                 os << "H5T_VAX_F64";
1323             }
1324             else if (H5Tequal(type, H5T_MIPS_F32) > 0)
1325             {
1326                 os << "H5T_MIPS_F32";
1327             }
1328             else if (H5Tequal(type, H5T_MIPS_F64) > 0)
1329             {
1330                 os << "H5T_MIPS_F64";
1331             }
1332             else
1333             {
1334                 if (H5Tget_size(type) > 1)
1335                 {
1336                     order = H5Tget_order(type);
1337                     if (order == H5T_ORDER_LE)
1338                     {
1339                         sorder = " little-endian";
1340                     }
1341                     else if (order == H5T_ORDER_BE)
1342                     {
1343                         sorder = " big-endian";
1344                     }
1345                     else if (order == H5T_ORDER_VAX)
1346                     {
1347                         sorder = " mixed-endian";
1348                     }
1349                     else
1350                     {
1351                         sorder = " unknown-byte-order";
1352                     }
1353                 }
1354                 else
1355                 {
1356                     sorder = "";
1357                 }
1358
1359                 os << (unsigned long)(8 * H5Tget_size(type)) << "-bit"
1360                    << sorder
1361                    << " floating-point";
1362             }
1363             break;
1364         case H5T_TIME:
1365             if (H5Tequal(type, H5T_UNIX_D32BE) > 0)
1366             {
1367                 os << "H5T_UNIX_D32BE";
1368             }
1369             else if (H5Tequal(type, H5T_UNIX_D32LE) > 0)
1370             {
1371                 os << "H5T_UNIX_D32LE";
1372             }
1373             else if (H5Tequal(type, H5T_UNIX_D64BE) > 0)
1374             {
1375                 os << "H5T_UNIX_D64BE";
1376             }
1377             else if (H5Tequal(type, H5T_UNIX_D64LE) > 0)
1378             {
1379                 os << "H5T_UNIX_D64LE";
1380             }
1381             else
1382             {
1383                 os << "Unknown time format";
1384             }
1385             break;
1386         case H5T_STRING:
1387             size = H5Tget_size(type);
1388             strpad = H5Tget_strpad(type);
1389             cset = H5Tget_cset(type);
1390             isVariableLength = H5Tis_variable_str(type);
1391             indent = H5Object::getIndentString(indentLevel + 1);
1392
1393             strType = H5Tcopy(H5T_C_S1);
1394             H5Tset_size(strType, isVariableLength ? H5T_VARIABLE : size);
1395             H5Tset_cset(strType, cset);
1396             H5Tset_strpad(strType, strpad);
1397
1398             os << "H5T_STRING {" << std::endl;
1399             if (isVariableLength)
1400             {
1401                 os << indent << "STRSIZE H5T_VARIABLE;" << std::endl;
1402             }
1403             else
1404             {
1405                 os << indent << "STRSIZE " << (int)size << ";" << std::endl;
1406             }
1407
1408             os << indent << "STRPAD ";
1409             switch (strpad)
1410             {
1411                 case H5T_STR_NULLTERM:
1412                     os << "H5T_STR_NULLTERM;" << std::endl;
1413                     break;
1414                 case H5T_STR_NULLPAD:
1415                     os << "H5T_STR_NULLPAD;" << std::endl;
1416                     break;
1417                 case H5T_STR_SPACEPAD:
1418                     os << "H5T_STR_SPACEPAD;" << std::endl;
1419                     break;
1420                 default:
1421                     os << "H5T_STR_ERROR;" << std::endl;
1422                     break;
1423             }
1424
1425             os << indent << "CSET ";
1426             if (cset == H5T_CSET_ASCII)
1427             {
1428                 os << "H5T_CSET_ASCII;" << std::endl;
1429             }
1430             else if (cset == H5T_CSET_UTF8)
1431             {
1432                 os << "H5T_CSET_UTF8;" << std::endl;
1433             }
1434             else
1435             {
1436                 os << "Unknown charset;" << std::endl;
1437             }
1438
1439             // TODO: modif l'endianess (cf h5dump.c::1068)
1440             os << indent << "CTYPE ";
1441             if (H5Tequal(type, strType) > 0)
1442             {
1443                 H5Tclose(strType);
1444                 os << "H5T_C_S1;" << std::endl;
1445             }
1446             else
1447             {
1448                 H5Tclose(strType);
1449                 strType = H5Tcopy(H5T_FORTRAN_S1);
1450                 H5Tset_size(strType, size);
1451                 H5Tset_cset(strType, cset);
1452                 H5Tset_strpad(strType, strpad);
1453                 if (H5Tequal(type, H5T_FORTRAN_S1) > 0)
1454                 {
1455                     os << "H5T_FORTRAN_S1;" << std::endl;
1456                 }
1457                 else
1458                 {
1459                     os << "Unknown one character type;" << std::endl;
1460                 }
1461             }
1462
1463             os << H5Object::getIndentString(indentLevel) << "}";
1464             break;
1465         case H5T_BITFIELD:
1466             if (H5Tequal(type, H5T_STD_B8BE) > 0)
1467             {
1468                 os << "H5T_STD_B8BE";
1469             }
1470             else if (H5Tequal(type, H5T_STD_B8LE) > 0)
1471             {
1472                 os << "H5T_STD_B8LE";
1473             }
1474             else if (H5Tequal(type, H5T_STD_B16BE) > 0)
1475             {
1476                 os << "H5T_STD_B16BE";
1477             }
1478             else if (H5Tequal(type, H5T_STD_B16LE) > 0)
1479             {
1480                 os << "H5T_STD_B16LE";
1481             }
1482             else if (H5Tequal(type, H5T_STD_B32BE) > 0)
1483             {
1484                 os << "H5T_STD_B32BE";
1485             }
1486             else if (H5Tequal(type, H5T_STD_B32LE) > 0)
1487             {
1488                 os << "H5T_STD_B32LE";
1489             }
1490             else if (H5Tequal(type, H5T_STD_B64BE) > 0)
1491             {
1492                 os << "H5T_STD_B64BE";
1493             }
1494             else if (H5Tequal(type, H5T_STD_B64LE) > 0)
1495             {
1496                 os << "H5T_STD_B64LE";
1497             }
1498             else if (H5Tequal(type, H5T_INTEL_B8) > 0)
1499             {
1500                 os << "H5T_INTEL_B8";
1501             }
1502             else if (H5Tequal(type, H5T_INTEL_B16) > 0)
1503             {
1504                 os << "H5T_INTEL_B16";
1505             }
1506             else if (H5Tequal(type, H5T_INTEL_B32) > 0)
1507             {
1508                 os << "H5T_INTEL_B32";
1509             }
1510             else if (H5Tequal(type, H5T_INTEL_B64) > 0)
1511             {
1512                 os << "H5T_INTEL_B64";
1513             }
1514             else if (H5Tequal(type, H5T_ALPHA_B8) > 0)
1515             {
1516                 os << "H5T_ALPHA_B8";
1517             }
1518             else if (H5Tequal(type, H5T_ALPHA_B16) > 0)
1519             {
1520                 os << "H5T_ALPHA_B16";
1521             }
1522             else if (H5Tequal(type, H5T_ALPHA_B32) > 0)
1523             {
1524                 os << "H5T_ALPHA_B32";
1525             }
1526             else if (H5Tequal(type, H5T_ALPHA_B64) > 0)
1527             {
1528                 os << "H5T_ALPHA_B64";
1529             }
1530             else if (H5Tequal(type, H5T_MIPS_B8) > 0)
1531             {
1532                 os << "H5T_MIPS_B8";
1533             }
1534             else if (H5Tequal(type, H5T_MIPS_B16) > 0)
1535             {
1536                 os << "H5T_MIPS_B16";
1537             }
1538             else if (H5Tequal(type, H5T_MIPS_B32) > 0)
1539             {
1540                 os << "H5T_MIPS_B32";
1541             }
1542             else if (H5Tequal(type, H5T_MIPS_B64) > 0)
1543             {
1544                 os << "H5T_MIPS_B64";
1545             }
1546             else
1547             {
1548                 os << "undefined bitfield";
1549             }
1550             break;
1551         case H5T_OPAQUE:
1552             opaqueTag = H5Tget_tag(type);
1553             os << "H5T_OPAQUE;" << std::endl
1554                << H5Object::getIndentString(indentLevel + 1)
1555                << "OPAQUE TAG \"" << opaqueTag << "\";";
1556
1557             free(opaqueTag);
1558             break;
1559         case H5T_COMPOUND:
1560             nmembers = H5Tget_nmembers(type);
1561             indent = H5Object::getIndentString(indentLevel + 1);
1562             os << "H5T_COMPOUND {" << std::endl;
1563
1564             for (unsigned int i = 0; i < nmembers; i++)
1565             {
1566                 char * mname = H5Tget_member_name(type, i);
1567                 hid_t mtype = H5Tget_member_type(type, i);
1568
1569                 os << indent;
1570                 H5Type::printComplexNameFromType(os, indentLevel + 1, mtype);
1571                 os << " \"" << mname << "\";" << std::endl;
1572
1573                 free(mname);
1574             }
1575
1576             os << H5Object::getIndentString(indentLevel) << "}";
1577             break;
1578         case H5T_REFERENCE:
1579             os << "H5T_REFERENCE";
1580             if (H5Tequal(type, H5T_STD_REF_DSETREG) > 0)
1581             {
1582                 os << " { H5T_STD_REF_DSETREG }";
1583             }
1584             else
1585             {
1586                 os << " { H5T_STD_REF_OBJECT }";
1587             }
1588             break;
1589         case H5T_ENUM:
1590             nmembers = H5Tget_nmembers(type);
1591             indent = H5Object::getIndentString(indentLevel + 1);
1592             size = H5Tget_size(type);
1593             super = H5Tget_super(type);
1594
1595             if (size <= sizeof(long long))
1596             {
1597                 dstSize = sizeof(long long);
1598                 if (H5Tget_sign(type) == H5T_SGN_NONE)
1599                 {
1600                     native = H5T_NATIVE_ULLONG;
1601                 }
1602                 else
1603                 {
1604                     native = H5T_NATIVE_LLONG;
1605                 }
1606             }
1607             else
1608             {
1609                 dstSize = size;
1610             }
1611
1612             os << "H5T_ENUM { " << std::endl
1613                << indent << H5Type(*const_cast<H5Type *>(this), H5Tcopy(super)).dump(alreadyVisited, 0);
1614
1615             value = new char[std::max(size, dstSize)]();
1616
1617             for (unsigned int i = 0; i < nmembers; i++)
1618             {
1619                 char * mname = H5Tget_member_name(type, i);
1620                 std::string _mname = "\"" + std::string(mname) + "\"";
1621                 free(mname);
1622
1623                 H5Tget_member_value(type, i, value);
1624
1625                 if (_mname.length() < 16)
1626                 {
1627                     _mname.resize(16, ' ');
1628                 }
1629
1630                 os << indent << _mname;
1631
1632                 if (native < 0)
1633                 {
1634                     for (size_t j = 0; j < dstSize; j++)
1635                     {
1636                         os << "0x" << std::hex << std::setfill('0') << std::setw(2) << (int)value[j];
1637                     }
1638                 }
1639                 else
1640                 {
1641                     H5Tconvert(super, native, 1, value, 0, H5P_DEFAULT);
1642                     if (H5Tget_sign(type) == H5T_SGN_NONE)
1643                     {
1644                         os << *reinterpret_cast<unsigned long long *>(value);
1645                     }
1646                     else
1647                     {
1648                         os << *reinterpret_cast<long long *>(value);
1649                     }
1650                 }
1651
1652                 os << ";" << std::endl;
1653             }
1654
1655             delete[] value;
1656             H5Tclose(super);
1657             os << H5Object::getIndentString(indentLevel) << "}";
1658             break;
1659         case H5T_VLEN:
1660             super = H5Tget_super(type);
1661             os << "H5T_VLEN { ";
1662
1663             H5Type::printComplexNameFromType(os, indentLevel + 1, super);
1664
1665             os << " }";
1666             break;
1667         case H5T_ARRAY:
1668             super = H5Tget_super(type);
1669             ndims = H5Tget_array_ndims(type);
1670             dims = new hsize_t[ndims];
1671             H5Tget_array_dims(type, dims);
1672
1673             os << "H5T_ARRAY { ";
1674
1675             for (unsigned int i = 0; i < ndims; i++)
1676             {
1677                 os << "[" << (unsigned int)dims[i] << "]";
1678             }
1679
1680             os << " ";
1681             H5Type::printComplexNameFromType(os, indentLevel + 1, super);
1682             os << " }";
1683
1684             H5Tclose(super);
1685             delete[] dims;
1686             break;
1687         default:
1688             os << _("Unknown datatype");
1689             break;
1690     }
1691
1692     os << std::endl;
1693
1694     return os.str();
1695 }
1696
1697 void H5Type::printLsInfo(std::ostringstream & os) const
1698 {
1699     if (!getName().empty())
1700     {
1701         std::string str(getName());
1702         H5Object::getResizedString(str);
1703
1704         os << str << "Type" << std::endl;
1705     }
1706 }
1707
1708 std::string H5Type::ls() const
1709 {
1710     std::ostringstream os;
1711     printLsInfo(os);
1712
1713     return os.str();
1714 }
1715
1716 std::string H5Type::toString(const unsigned int indentLevel) const
1717 {
1718     std::ostringstream os;
1719     std::string indentString = H5Object::getIndentString(indentLevel);
1720
1721     os << indentString << "Filename" << ": " << getFile().getFileName() << std::endl
1722        << indentString << "Name" << ": " << name << std::endl
1723        << indentString << "Class" << ": " << getClassName() << std::endl
1724        << indentString << "Type" << ": " << getTypeName() << std::endl
1725        << indentString << "Size" << ": " << getTypeSize() << std::endl
1726        << indentString << "Nativetype" << ": " << getNativeTypeName() << std::endl
1727        << indentString << "Nativesize" << ": " << getNativeTypeSize();
1728
1729     return os.str();
1730 }
1731 }