Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/toolx/hdf5/T_tools

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/toolx/hdf5/T_tools (Version 11.3.0) and /externals/g4tools/include/toolx/hdf5/T_tools (Version 11.1)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef toolx_hdf5_T_tools                          4 #ifndef toolx_hdf5_T_tools
  5 #define toolx_hdf5_T_tools                          5 #define toolx_hdf5_T_tools
  6                                                     6 
  7 #include "hdf5_h"                                   7 #include "hdf5_h"
  8                                                     8 
  9 #include <tools/typedefs>                           9 #include <tools/typedefs>
 10 #include <tools/forit>                             10 #include <tools/forit>
 11 #include <tools/num2s>                             11 #include <tools/num2s>
 12 #include <tools/vdata>                             12 #include <tools/vdata>
 13 //#include <map>                                   13 //#include <map>
 14                                                    14 
 15 namespace toolx {                                  15 namespace toolx {
 16 namespace hdf5 {                                   16 namespace hdf5 {
 17                                                    17 
 18 inline hid_t to_T_file_type(char)           {r     18 inline hid_t to_T_file_type(char)           {return H5T_STD_I8LE;}    //H5T_STD_I8XX()
 19 inline hid_t to_T_file_type(short)          {r     19 inline hid_t to_T_file_type(short)          {return H5T_STD_I16LE;}   //HST_STD_I16XX()
 20 inline hid_t to_T_file_type(int)            {r     20 inline hid_t to_T_file_type(int)            {return H5T_STD_I32LE;}   //H5T_STD_I32XX()
 21 inline hid_t to_T_file_type(tools::int64)   {r     21 inline hid_t to_T_file_type(tools::int64)   {return H5T_STD_I64LE;}   //H5T_STD_I64XX()
 22                                                    22 
 23 inline hid_t to_T_file_type(float)          {r     23 inline hid_t to_T_file_type(float)          {return H5T_IEEE_F32LE;}  //H5T_IEEE_F32XX()
 24 inline hid_t to_T_file_type(double)         {r     24 inline hid_t to_T_file_type(double)         {return H5T_IEEE_F64LE;}  //H5T_IEEE_F64XX()
 25                                                    25 
 26 inline hid_t to_T_file_type(unsigned char)  {r     26 inline hid_t to_T_file_type(unsigned char)  {return H5T_STD_U8LE;}
 27 inline hid_t to_T_file_type(unsigned short) {r     27 inline hid_t to_T_file_type(unsigned short) {return H5T_STD_U16LE;}
 28 inline hid_t to_T_file_type(unsigned int)   {r     28 inline hid_t to_T_file_type(unsigned int)   {return H5T_STD_U32LE;}
 29 inline hid_t to_T_file_type(tools::uint64)  {r     29 inline hid_t to_T_file_type(tools::uint64)  {return H5T_STD_U64LE;}
 30                                                    30 
 31 inline hid_t to_T_mem_type(char)           {re     31 inline hid_t to_T_mem_type(char)           {return H5T_NATIVE_CHAR;}
 32 inline hid_t to_T_mem_type(short)          {re     32 inline hid_t to_T_mem_type(short)          {return H5T_NATIVE_SHORT;}
 33 inline hid_t to_T_mem_type(int)            {re     33 inline hid_t to_T_mem_type(int)            {return H5T_NATIVE_INT;}
 34 inline hid_t to_T_mem_type(tools::int64)   {re     34 inline hid_t to_T_mem_type(tools::int64)   {return H5T_NATIVE_INT64;}
 35                                                    35 
 36 inline hid_t to_T_mem_type(float)          {re     36 inline hid_t to_T_mem_type(float)          {return H5T_NATIVE_FLOAT;}
 37 inline hid_t to_T_mem_type(double)         {re     37 inline hid_t to_T_mem_type(double)         {return H5T_NATIVE_DOUBLE;}
 38                                                    38 
 39 inline hid_t to_T_mem_type(unsigned char)  {re     39 inline hid_t to_T_mem_type(unsigned char)  {return H5T_NATIVE_UCHAR;}
 40 inline hid_t to_T_mem_type(unsigned short) {re     40 inline hid_t to_T_mem_type(unsigned short) {return H5T_NATIVE_USHORT;}
 41 inline hid_t to_T_mem_type(unsigned int)   {re     41 inline hid_t to_T_mem_type(unsigned int)   {return H5T_NATIVE_UINT;}
 42 inline hid_t to_T_mem_type(tools::uint64)  {re     42 inline hid_t to_T_mem_type(tools::uint64)  {return H5T_NATIVE_UINT64;}
 43                                                    43 
 44 template <class T>                                 44 template <class T>
 45 inline bool write_array(hid_t a_loc,const std:     45 inline bool write_array(hid_t a_loc,const std::string& a_name,
 46                         hid_t a_file_type,hid_     46                         hid_t a_file_type,hid_t a_mem_type,
 47                         unsigned int a_chunked     47                         unsigned int a_chunked,unsigned int a_compress,
 48                         unsigned int a_size,co     48                         unsigned int a_size,const T a_array[]) {
 49   if(!a_size) return false;                        49   if(!a_size) return false;
 50                                                    50 
 51   hid_t cpt = -1;                                  51   hid_t cpt = -1;
 52   if(a_compress || a_chunked) {                    52   if(a_compress || a_chunked) {
 53     cpt = ::H5Pcreate(H5P_DATASET_CREATE);         53     cpt = ::H5Pcreate(H5P_DATASET_CREATE);
 54     if(cpt<0) return false;                        54     if(cpt<0) return false;
 55     if(a_chunked) {                                55     if(a_chunked) {
 56       if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {       56       if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
 57         ::H5Pclose(cpt);                           57         ::H5Pclose(cpt);
 58         return false;                              58         return false;
 59       }                                            59       }
 60       hsize_t cdims[1];                            60       hsize_t cdims[1];
 61       cdims[0] = a_chunked;                        61       cdims[0] = a_chunked;
 62       if(H5Pset_chunk(cpt,1,cdims)<0) {            62       if(H5Pset_chunk(cpt,1,cdims)<0) {
 63         ::H5Pclose(cpt);                           63         ::H5Pclose(cpt);
 64         return false;                              64         return false;
 65       }                                            65       }
 66     } else {                                       66     } else {
 67       if(H5Pset_layout(cpt,H5D_COMPACT)<0) {       67       if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
 68         ::H5Pclose(cpt);                           68         ::H5Pclose(cpt);
 69         return false;                              69         return false;
 70       }                                            70       }
 71     }                                              71     }
 72     if(a_compress) {                               72     if(a_compress) {
 73       if(H5Pset_deflate(cpt,a_compress>9?9:a_c     73       if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
 74         ::H5Pclose(cpt);                           74         ::H5Pclose(cpt);
 75         return false;                              75         return false;
 76       }                                            76       }
 77     }                                              77     }
 78   } else {                                         78   } else {
 79     cpt = H5P_DEFAULT;                             79     cpt = H5P_DEFAULT;
 80   }                                                80   }
 81                                                    81 
 82   hid_t dataset = -1;                              82   hid_t dataset = -1;
 83                                                    83 
 84  {hsize_t dims[1];                                 84  {hsize_t dims[1];
 85   dims[0] = a_size;                                85   dims[0] = a_size;
 86   hid_t file_space = -1;                           86   hid_t file_space = -1;
 87   if(a_chunked) {                                  87   if(a_chunked) {
 88     hsize_t mx_dims[1];                            88     hsize_t mx_dims[1];
 89     mx_dims[0] = H5S_UNLIMITED; //extendable.      89     mx_dims[0] = H5S_UNLIMITED; //extendable.
 90     file_space = ::H5Screate_simple(1,dims,mx_     90     file_space = ::H5Screate_simple(1,dims,mx_dims);
 91   } else {                                         91   } else {
 92     file_space = ::H5Screate_simple(1,dims,NUL     92     file_space = ::H5Screate_simple(1,dims,NULL);
 93   }                                                93   }
 94   if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt)     94   if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);return false;}
 95   dataset = toolx_H5Dcreate(a_loc,a_name.c_str     95   dataset = toolx_H5Dcreate(a_loc,a_name.c_str(),a_file_type,file_space,cpt);
 96   if(cpt>=0) ::H5Pclose(cpt);                      96   if(cpt>=0) ::H5Pclose(cpt);
 97   ::H5Sclose(file_space);                          97   ::H5Sclose(file_space);
 98   if(dataset<0) return false;}                     98   if(dataset<0) return false;}
 99                                                    99 
100   if(H5Dwrite(dataset,a_mem_type,H5S_ALL,H5S_A    100   if(H5Dwrite(dataset,a_mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_array)<0) {
101     ::H5Dclose(dataset);                          101     ::H5Dclose(dataset);
102     return false;                                 102     return false;
103   }                                               103   }
104   ::H5Dclose(dataset);                            104   ::H5Dclose(dataset);
105                                                   105 
106   return true;                                    106   return true;
107 }                                                 107 }
108                                                   108 
109 template <class T>                                109 template <class T>
110 inline bool write_vlen(hid_t a_loc,const std::    110 inline bool write_vlen(hid_t a_loc,const std::string& a_name,
111                        hid_t a_file_type,hid_t    111                        hid_t a_file_type,hid_t a_mem_type,
112                        unsigned int a_chunked,    112                        unsigned int a_chunked,unsigned int a_compress,
113                        unsigned int a_size,con    113                        unsigned int a_size,const T a_array[]) {
114   hid_t cpt = -1;                                 114   hid_t cpt = -1;
115   if(a_compress || a_chunked) {                   115   if(a_compress || a_chunked) {
116     cpt = ::H5Pcreate(H5P_DATASET_CREATE);        116     cpt = ::H5Pcreate(H5P_DATASET_CREATE);
117     if(cpt<0) return false;                       117     if(cpt<0) return false;
118     if(a_chunked) {                               118     if(a_chunked) {
119       if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {      119       if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
120         ::H5Pclose(cpt);                          120         ::H5Pclose(cpt);
121         return false;                             121         return false;
122       }                                           122       }
123       hsize_t cdims[1];                           123       hsize_t cdims[1];
124       cdims[0] = a_chunked;                       124       cdims[0] = a_chunked;
125       if(H5Pset_chunk(cpt,1,cdims)<0) {           125       if(H5Pset_chunk(cpt,1,cdims)<0) {
126         ::H5Pclose(cpt);                          126         ::H5Pclose(cpt);
127         return false;                             127         return false;
128       }                                           128       }
129     } else {                                      129     } else {
130       if(H5Pset_layout(cpt,H5D_COMPACT)<0) {      130       if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
131         ::H5Pclose(cpt);                          131         ::H5Pclose(cpt);
132         return false;                             132         return false;
133       }                                           133       }
134     }                                             134     }
135     if(a_compress) {                              135     if(a_compress) {
136       if(H5Pset_deflate(cpt,a_compress>9?9:a_c    136       if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
137         ::H5Pclose(cpt);                          137         ::H5Pclose(cpt);
138         return false;                             138         return false;
139       }                                           139       }
140     }                                             140     }
141   } else {                                        141   } else {
142     cpt = H5P_DEFAULT;                            142     cpt = H5P_DEFAULT;
143   }                                               143   }
144                                                   144 
145   hid_t dataset = -1;                             145   hid_t dataset = -1;
146                                                   146 
147  {hsize_t dims[1];                                147  {hsize_t dims[1];
148   dims[0] = 1;                                    148   dims[0] = 1;
149   hid_t file_space = -1;                          149   hid_t file_space = -1;
150   if(a_chunked) {                                 150   if(a_chunked) {
151     hsize_t mx_dims[1];                           151     hsize_t mx_dims[1];
152     mx_dims[0] = H5S_UNLIMITED; //extendable.     152     mx_dims[0] = H5S_UNLIMITED; //extendable.
153     file_space = ::H5Screate_simple(1,dims,mx_    153     file_space = ::H5Screate_simple(1,dims,mx_dims);
154   } else {                                        154   } else {
155     file_space = ::H5Screate_simple(1,dims,NUL    155     file_space = ::H5Screate_simple(1,dims,NULL);
156   }                                               156   }
157   if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt)    157   if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);return false;}
158                                                   158 
159   hid_t file_type = ::H5Tvlen_create(a_file_ty    159   hid_t file_type = ::H5Tvlen_create(a_file_type);
160                                                   160 
161   dataset = toolx_H5Dcreate(a_loc,a_name.c_str    161   dataset = toolx_H5Dcreate(a_loc,a_name.c_str(),file_type,file_space,cpt);
162   if(cpt>=0) ::H5Pclose(cpt);                     162   if(cpt>=0) ::H5Pclose(cpt);
163   ::H5Sclose(file_space);                         163   ::H5Sclose(file_space);
164   ::H5Tclose(file_type);                          164   ::H5Tclose(file_type);
165   if(dataset<0) return false;}                    165   if(dataset<0) return false;}
166                                                   166 
167   hid_t mem_type = ::H5Tvlen_create(a_mem_type    167   hid_t mem_type = ::H5Tvlen_create(a_mem_type);
168                                                   168 
169   hvl_t wdata[1];                                 169   hvl_t wdata[1];
170   wdata[0].len = a_size;                          170   wdata[0].len = a_size;
171   wdata[0].p = (void*)a_array;                    171   wdata[0].p = (void*)a_array;
172                                                   172 
173   if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL    173   if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) {
174     ::H5Tclose(mem_type);                         174     ::H5Tclose(mem_type);
175     ::H5Dclose(dataset);                          175     ::H5Dclose(dataset);
176     return false;                                 176     return false;
177   }                                               177   }
178   ::H5Tclose(mem_type);                           178   ::H5Tclose(mem_type);
179   ::H5Dclose(dataset);                            179   ::H5Dclose(dataset);
180                                                   180 
181   return true;                                    181   return true;
182 }                                                 182 }
183                                                   183 
184 template <class T>                                184 template <class T>
185 inline bool write_sub_array(hid_t a_loc,const     185 inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
186                             hid_t a_file_type,    186                             hid_t a_file_type,hid_t a_mem_type,
187                             bool a_create,        187                             bool a_create,
188                             unsigned int a_chu    188                             unsigned int a_chunked,unsigned int a_compress, // used if a_creat = true;
189                             unsigned int a_siz    189                             unsigned int a_size,
190                             unsigned int a_off    190                             unsigned int a_offset,unsigned int a_number,const T a_array[]) {
191                                                   191 
192   int remain = a_size-a_offset;                   192   int remain = a_size-a_offset;
193   int number = (int(a_number)<=remain) ? int(a    193   int number = (int(a_number)<=remain) ? int(a_number) : remain;
194   if(number<=0) return false;                     194   if(number<=0) return false;
195                                                   195 
196   hid_t cpt = -1;                                 196   hid_t cpt = -1;
197                                                   197 
198   if(a_create) {                                  198   if(a_create) {
199     if(a_compress || a_chunked) {                 199     if(a_compress || a_chunked) {
200       cpt = ::H5Pcreate(H5P_DATASET_CREATE);      200       cpt = ::H5Pcreate(H5P_DATASET_CREATE);
201       if(cpt<0) return false;                     201       if(cpt<0) return false;
202       if(a_chunked) {                             202       if(a_chunked) {
203         if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {    203         if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
204           ::H5Pclose(cpt);                        204           ::H5Pclose(cpt);
205           return false;                           205           return false;
206         }                                         206         }
207         hsize_t cdims[1];                         207         hsize_t cdims[1];
208       //cdims[0] = (a_size<=32?a_size:32);        208       //cdims[0] = (a_size<=32?a_size:32);
209         cdims[0] = a_chunked;                     209         cdims[0] = a_chunked;
210         if(H5Pset_chunk(cpt,1,cdims)<0) {         210         if(H5Pset_chunk(cpt,1,cdims)<0) {
211           ::H5Pclose(cpt);                        211           ::H5Pclose(cpt);
212           return false;                           212           return false;
213         }                                         213         }
214       } else {                                    214       } else {
215         if(H5Pset_layout(cpt,H5D_COMPACT)<0) {    215         if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
216           ::H5Pclose(cpt);                        216           ::H5Pclose(cpt);
217           return false;                           217           return false;
218         }                                         218         }
219       }                                           219       }
220       if(a_compress) {                            220       if(a_compress) {
221         if(H5Pset_deflate(cpt,a_compress>9?9:a    221         if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
222           ::H5Pclose(cpt);                        222           ::H5Pclose(cpt);
223           return false;                           223           return false;
224         }                                         224         }
225       }                                           225       }
226     } else {                                      226     } else {
227       cpt = H5P_DEFAULT;                          227       cpt = H5P_DEFAULT;
228     }                                             228     }
229   }                                               229   }
230                                                   230 
231   hid_t dataset = -1;                             231   hid_t dataset = -1;
232                                                   232 
233   hid_t file_space = -1;                          233   hid_t file_space = -1;
234                                                   234 
235   if(a_create) {                                  235   if(a_create) {
236     hsize_t dims[1];                              236     hsize_t dims[1];
237     dims[0] = a_size;                             237     dims[0] = a_size;
238     file_space = ::H5Screate_simple(1,dims,NUL    238     file_space = ::H5Screate_simple(1,dims,NULL);
239     if(file_space<0) {                            239     if(file_space<0) {
240       if(cpt>=0) ::H5Pclose(cpt);                 240       if(cpt>=0) ::H5Pclose(cpt);
241       return false;                               241       return false;
242     }                                             242     }
243                                                   243 
244    {hsize_t offset[1];                            244    {hsize_t offset[1];
245     offset[0] = a_offset;                         245     offset[0] = a_offset;
246     hsize_t count[1];                             246     hsize_t count[1];
247     count[0] = number;                            247     count[0] = number;
248     if(H5Sselect_hyperslab(file_space,H5S_SELE    248     if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
249       ::H5Sclose(file_space);                     249       ::H5Sclose(file_space);
250       if(cpt>=0) ::H5Pclose(cpt);                 250       if(cpt>=0) ::H5Pclose(cpt);
251       return false;                               251       return false;
252     }}                                            252     }}
253                                                   253 
254     dataset = toolx_H5Dcreate(a_loc,a_name.c_s    254     dataset = toolx_H5Dcreate(a_loc,a_name.c_str(),a_file_type,file_space,cpt);
255     if(dataset<0) {                               255     if(dataset<0) {
256       ::H5Sclose(file_space);                     256       ::H5Sclose(file_space);
257       if(cpt>=0) ::H5Pclose(cpt);                 257       if(cpt>=0) ::H5Pclose(cpt);
258       return false;                               258       return false;
259     }                                             259     }
260                                                   260 
261   } else { //open an existing dataset :           261   } else { //open an existing dataset :
262     dataset = toolx_H5Dopen(a_loc,a_name.c_str    262     dataset = toolx_H5Dopen(a_loc,a_name.c_str());
263     if(dataset<0) {                               263     if(dataset<0) {
264       if(cpt>=0) ::H5Pclose(cpt);                 264       if(cpt>=0) ::H5Pclose(cpt);
265       return false;                               265       return false;
266     }                                             266     }
267                                                   267 
268     file_space = H5Dget_space(dataset);           268     file_space = H5Dget_space(dataset);
269     if(file_space<0) {                            269     if(file_space<0) {
270       ::H5Dclose(dataset);                        270       ::H5Dclose(dataset);
271       if(cpt>=0) ::H5Pclose(cpt);                 271       if(cpt>=0) ::H5Pclose(cpt);
272       return false;                               272       return false;
273     }                                             273     }
274                                                   274 
275    {hsize_t offset[1];                            275    {hsize_t offset[1];
276     offset[0] = a_offset;                         276     offset[0] = a_offset;
277     hsize_t count[1];                             277     hsize_t count[1];
278     count[0] = number;                            278     count[0] = number;
279     if(H5Sselect_hyperslab(file_space,H5S_SELE    279     if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
280       ::H5Sclose(file_space);                     280       ::H5Sclose(file_space);
281       ::H5Dclose(dataset);                        281       ::H5Dclose(dataset);
282       if(cpt>=0) ::H5Pclose(cpt);                 282       if(cpt>=0) ::H5Pclose(cpt);
283       return false;                               283       return false;
284     }}                                            284     }}
285                                                   285 
286   }                                               286   }
287                                                   287 
288   hsize_t dims[1];                                288   hsize_t dims[1];
289   dims[0] = number;                               289   dims[0] = number;
290   hid_t mem_space = ::H5Screate_simple(1,dims,    290   hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
291   if(mem_space<0) {                               291   if(mem_space<0) {
292     ::H5Sclose(file_space);                       292     ::H5Sclose(file_space);
293     ::H5Dclose(dataset);                          293     ::H5Dclose(dataset);
294     if(cpt>=0) ::H5Pclose(cpt);                   294     if(cpt>=0) ::H5Pclose(cpt);
295     return false;                                 295     return false;
296   }                                               296   }
297                                                   297 
298   if(H5Dwrite(dataset,a_mem_type,mem_space,fil    298   if(H5Dwrite(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
299     ::H5Sclose(file_space);                       299     ::H5Sclose(file_space);
300     ::H5Dclose(dataset);                          300     ::H5Dclose(dataset);
301     if(cpt>=0) ::H5Pclose(cpt);                   301     if(cpt>=0) ::H5Pclose(cpt);
302     return false;                                 302     return false;
303   }                                               303   }
304                                                   304 
305   ::H5Sclose(file_space);                         305   ::H5Sclose(file_space);
306   ::H5Dclose(dataset);                            306   ::H5Dclose(dataset);
307   if(cpt>=0) ::H5Pclose(cpt);                     307   if(cpt>=0) ::H5Pclose(cpt);
308                                                   308 
309   return true;                                    309   return true;
310 }                                                 310 }
311                                                   311 
312 template <class T>                                312 template <class T>
313 inline bool write_append_array_dataset(hid_t a    313 inline bool write_append_array_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid_t a_mem_type,
314                                        unsigne    314                                        unsigned int a_number,const T a_array[]) {
315   hsize_t old_size = 0;                           315   hsize_t old_size = 0;
316                                                   316 
317  {hid_t dataspace = H5Dget_space(a_dataset);      317  {hid_t dataspace = H5Dget_space(a_dataset);
318   if(dataspace<0) return false;                   318   if(dataspace<0) return false;
319   hsize_t dims[1];                                319   hsize_t dims[1];
320   if(H5Sget_simple_extent_dims(dataspace,dims,    320   if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
321     ::H5Sclose(dataspace);                        321     ::H5Sclose(dataspace);
322     return false;                                 322     return false;
323   }                                               323   }
324   old_size = dims[0];                             324   old_size = dims[0];
325   ::H5Sclose(dataspace);}                         325   ::H5Sclose(dataspace);}
326                                                   326 
327  {hsize_t exts[1];                                327  {hsize_t exts[1];
328   exts[0] = old_size+a_number;                    328   exts[0] = old_size+a_number;
329 //  if(H5Dextend(dataset,exts)<0) {               329 //  if(H5Dextend(dataset,exts)<0) {
330   if(H5Dset_extent(a_dataset,exts)<0) return f    330   if(H5Dset_extent(a_dataset,exts)<0) return false;}
331                                                   331 
332   hid_t file_space = H5Dget_space(a_dataset);     332   hid_t file_space = H5Dget_space(a_dataset);
333   if(file_space<0) return false;                  333   if(file_space<0) return false;
334                                                   334 
335  {hsize_t offset[1];                              335  {hsize_t offset[1];
336   offset[0] = old_size;                           336   offset[0] = old_size;
337   hsize_t count[1];                               337   hsize_t count[1];
338   count[0] = a_number;                            338   count[0] = a_number;
339   if(H5Sselect_hyperslab(file_space,H5S_SELECT    339   if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
340     ::H5Sclose(file_space);                       340     ::H5Sclose(file_space);
341     return false;                                 341     return false;
342   }}                                              342   }}
343                                                   343 
344   hsize_t dims[1];                                344   hsize_t dims[1];
345   dims[0] = a_number;                             345   dims[0] = a_number;
346   hid_t mem_space = ::H5Screate_simple(1,dims,    346   hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
347   if(mem_space<0) {                               347   if(mem_space<0) {
348     ::H5Sclose(file_space);                       348     ::H5Sclose(file_space);
349     return false;                                 349     return false;
350   }                                               350   }
351                                                   351 
352   if(H5Dwrite(a_dataset,a_mem_type,mem_space,f    352   if(H5Dwrite(a_dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
353     ::H5Sclose(mem_space);                        353     ::H5Sclose(mem_space);
354     ::H5Sclose(file_space);                       354     ::H5Sclose(file_space);
355     return false;                                 355     return false;
356   }                                               356   }
357                                                   357 
358   ::H5Sclose(mem_space);                          358   ::H5Sclose(mem_space);
359   ::H5Sclose(file_space);                         359   ::H5Sclose(file_space);
360                                                   360 
361   return true;                                    361   return true;
362 }                                                 362 }
363                                                   363 
364 template <class T>                                364 template <class T>
365 inline bool write_append_vlen_dataset(hid_t a_    365 inline bool write_append_vlen_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid_t a_mem_type,
366                                       unsigned    366                                       unsigned int a_number,const T a_array[]) {
367   hsize_t old_size = 0;                           367   hsize_t old_size = 0;
368                                                   368 
369  {hid_t dataspace = H5Dget_space(a_dataset);      369  {hid_t dataspace = H5Dget_space(a_dataset);
370   if(dataspace<0) return false;                   370   if(dataspace<0) return false;
371   hsize_t dims[1];                                371   hsize_t dims[1];
372   if(H5Sget_simple_extent_dims(dataspace,dims,    372   if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
373     ::H5Sclose(dataspace);                        373     ::H5Sclose(dataspace);
374     return false;                                 374     return false;
375   }                                               375   }
376   old_size = dims[0];                             376   old_size = dims[0];
377   ::H5Sclose(dataspace);}                         377   ::H5Sclose(dataspace);}
378                                                   378 
379  {hsize_t exts[1];                                379  {hsize_t exts[1];
380   exts[0] = old_size+1;                           380   exts[0] = old_size+1;
381 //  if(H5Dextend(dataset,exts)<0) {               381 //  if(H5Dextend(dataset,exts)<0) {
382   if(H5Dset_extent(a_dataset,exts)<0) return f    382   if(H5Dset_extent(a_dataset,exts)<0) return false;}
383                                                   383 
384   hid_t file_space = H5Dget_space(a_dataset);     384   hid_t file_space = H5Dget_space(a_dataset);
385   if(file_space<0) return false;                  385   if(file_space<0) return false;
386                                                   386 
387  {hsize_t offset[1];                              387  {hsize_t offset[1];
388   offset[0] = old_size;                           388   offset[0] = old_size;
389   hsize_t count[1];                               389   hsize_t count[1];
390   count[0] = 1;                                   390   count[0] = 1;
391   if(H5Sselect_hyperslab(file_space,H5S_SELECT    391   if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
392     ::H5Sclose(file_space);                       392     ::H5Sclose(file_space);
393     return false;                                 393     return false;
394   }}                                              394   }}
395                                                   395 
396   hsize_t dims[1];                                396   hsize_t dims[1];
397   dims[0] = 1;                                    397   dims[0] = 1;
398   hid_t mem_space = ::H5Screate_simple(1,dims,    398   hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
399   if(mem_space<0) {                               399   if(mem_space<0) {
400     ::H5Sclose(file_space);                       400     ::H5Sclose(file_space);
401     return false;                                 401     return false;
402   }                                               402   }
403                                                   403 
404   hid_t mem_type = ::H5Tvlen_create(a_mem_type    404   hid_t mem_type = ::H5Tvlen_create(a_mem_type);
405                                                   405 
406   hvl_t wdata[1];                                 406   hvl_t wdata[1];
407   wdata[0].len = a_number;                        407   wdata[0].len = a_number;
408   wdata[0].p = (void*)a_array;                    408   wdata[0].p = (void*)a_array;
409                                                   409 
410   if(H5Dwrite(a_dataset,mem_type,mem_space,fil    410   if(H5Dwrite(a_dataset,mem_type,mem_space,file_space,H5P_DEFAULT,wdata)<0) {
411     ::H5Tclose(mem_type);                         411     ::H5Tclose(mem_type);
412     ::H5Sclose(mem_space);                        412     ::H5Sclose(mem_space);
413     ::H5Sclose(file_space);                       413     ::H5Sclose(file_space);
414     return false;                                 414     return false;
415   }                                               415   }
416                                                   416 
417   ::H5Tclose(mem_type);                           417   ::H5Tclose(mem_type);
418   ::H5Sclose(mem_space);                          418   ::H5Sclose(mem_space);
419   ::H5Sclose(file_space);                         419   ::H5Sclose(file_space);
420                                                   420 
421   return true;                                    421   return true;
422 }                                                 422 }
423                                                   423 
424 template <class T>                                424 template <class T>
425 inline bool write_append_array(hid_t a_loc,con    425 inline bool write_append_array(hid_t a_loc,const std::string& a_name,hid_t a_file_type,hid_t a_mem_type,
426                                unsigned int a_    426                                unsigned int a_number,const T a_array[]) {
427   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c    427   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c_str());
428   if(dataset<0) return false;                     428   if(dataset<0) return false;
429   bool status = write_append_array_dataset(dat    429   bool status = write_append_array_dataset(dataset,a_file_type,a_mem_type,a_number,a_array);
430   ::H5Dclose(dataset);                            430   ::H5Dclose(dataset);
431   return status;                                  431   return status;
432 }                                                 432 }
433                                                   433 
434 /*                                                434 /*
435 template <class T>                                435 template <class T>
436 inline bool write_array_struct(                   436 inline bool write_array_struct(
437  hid_t a_loc                                      437  hid_t a_loc
438 ,const std::string& a_name                        438 ,const std::string& a_name
439 ,hid_t a_create_type                              439 ,hid_t a_create_type
440 ,hid_t aWriteType                                 440 ,hid_t aWriteType
441 ,unsigned int a_size                              441 ,unsigned int a_size
442 ,const T a_array[]                                442 ,const T a_array[]
443 ){                                                443 ){
444   hsize_t dims[1];                                444   hsize_t dims[1];
445   dims[0] = a_size;                               445   dims[0] = a_size;
446   hid_t dataspace = ::H5Screate_simple(1,dims,    446   hid_t dataspace = ::H5Screate_simple(1,dims,NULL);
447   if(dataspace<0) return false;                   447   if(dataspace<0) return false;
448                                                   448 
449   hid_t dataset = toolx_H5Dcreate(a_loc,a_name    449   hid_t dataset = toolx_H5Dcreate(a_loc,a_name.c_str(),a_create_type,dataspace,H5P_DEFAULT);
450   if(dataset<0) {                                 450   if(dataset<0) {
451     ::H5Sclose(dataspace);                        451     ::H5Sclose(dataspace);
452     return false;                                 452     return false;
453   }                                               453   }
454                                                   454 
455   if(H5Dwrite(dataset,aWriteType,H5S_ALL,H5S_A    455   if(H5Dwrite(dataset,aWriteType,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_array)<0) {
456     ::H5Dclose(dataset);                          456     ::H5Dclose(dataset);
457     ::H5Sclose(dataspace);                        457     ::H5Sclose(dataspace);
458     return false;                                 458     return false;
459   }                                               459   }
460                                                   460 
461   ::H5Dclose(dataset);                            461   ::H5Dclose(dataset);
462   ::H5Sclose(dataspace);                          462   ::H5Sclose(dataspace);
463                                                   463 
464   return true;                                    464   return true;
465 }                                                 465 }
466 */                                                466 */
467                                                   467 
468 template <class T>                                468 template <class T>
469 inline bool read_scalar(hid_t a_loc,const std:    469 inline bool read_scalar(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,T& a_data) {
470   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c    470   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c_str());
471   if(dataset<0) return false;                     471   if(dataset<0) return false;
472                                                   472 
473   hid_t file_space = H5Dget_space(dataset);       473   hid_t file_space = H5Dget_space(dataset);
474   if(file_space<0) {                              474   if(file_space<0) {
475     ::H5Dclose(dataset);                          475     ::H5Dclose(dataset);
476     return false;                                 476     return false;
477   }                                               477   }
478                                                   478 
479   hid_t mem_space = ::H5Screate(H5S_SCALAR);      479   hid_t mem_space = ::H5Screate(H5S_SCALAR);
480   if(mem_space<0) {                               480   if(mem_space<0) {
481     ::H5Sclose(file_space);                       481     ::H5Sclose(file_space);
482     ::H5Dclose(dataset);                          482     ::H5Dclose(dataset);
483     return false;                                 483     return false;
484   }                                               484   }
485                                                   485 
486   if(H5Dread(dataset,a_mem_type,mem_space,file    486   if(H5Dread(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,&a_data)<0) {
487     ::H5Sclose(mem_space);                        487     ::H5Sclose(mem_space);
488     ::H5Sclose(file_space);                       488     ::H5Sclose(file_space);
489     ::H5Dclose(dataset);                          489     ::H5Dclose(dataset);
490     return false;                                 490     return false;
491   }                                               491   }
492                                                   492 
493   ::H5Sclose(mem_space);                          493   ::H5Sclose(mem_space);
494   ::H5Sclose(file_space);                         494   ::H5Sclose(file_space);
495   ::H5Dclose(dataset);                            495   ::H5Dclose(dataset);
496                                                   496 
497   return true;                                    497   return true;
498 }                                                 498 }
499                                                   499 
500 template <class T>                                500 template <class T>
501 inline bool read_array(hid_t a_loc,const std::    501 inline bool read_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,unsigned int& a_size,T*& a_array,bool a_alloc = true) {
502   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c    502   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c_str());
503   if(dataset<0) {                                 503   if(dataset<0) {
504     a_size = 0;                                   504     a_size = 0;
505     if(a_alloc) a_array = 0;                      505     if(a_alloc) a_array = 0;
506     return false; // data set not found.          506     return false; // data set not found.
507   }                                               507   }
508                                                   508 
509   hid_t file_space = H5Dget_space(dataset);       509   hid_t file_space = H5Dget_space(dataset);
510   if(file_space<0) {                              510   if(file_space<0) {
511     ::H5Dclose(dataset);                          511     ::H5Dclose(dataset);
512     a_size = 0;                                   512     a_size = 0;
513     if(a_alloc) a_array = 0;                      513     if(a_alloc) a_array = 0;
514     return false;                                 514     return false;
515   }                                               515   }
516                                                   516 
517  {int dimn = H5Sget_simple_extent_ndims(file_s    517  {int dimn = H5Sget_simple_extent_ndims(file_space);
518   if(dimn<0) {                                    518   if(dimn<0) {
519     ::H5Sclose(file_space);                       519     ::H5Sclose(file_space);
520     ::H5Dclose(dataset);                          520     ::H5Dclose(dataset);
521     a_size = 0;                                   521     a_size = 0;
522     if(a_alloc) a_array = 0;                      522     if(a_alloc) a_array = 0;
523     return false;                                 523     return false;
524   }                                               524   }
525   if(dimn!=1) {                                   525   if(dimn!=1) {
526     ::H5Sclose(file_space);                       526     ::H5Sclose(file_space);
527     ::H5Dclose(dataset);                          527     ::H5Dclose(dataset);
528     a_size = 0;                                   528     a_size = 0;
529     if(a_alloc) a_array = 0;                      529     if(a_alloc) a_array = 0;
530     return false;                                 530     return false;
531   }                                               531   }
532   //printf("debug : read dimn %d\n",dimn);        532   //printf("debug : read dimn %d\n",dimn);
533   }                                               533   }
534                                                   534 
535   hsize_t dims[1];                                535   hsize_t dims[1];
536  {if(H5Sget_simple_extent_dims(file_space,dims    536  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
537     ::H5Sclose(file_space);                       537     ::H5Sclose(file_space);
538     ::H5Dclose(dataset);                          538     ::H5Dclose(dataset);
539     a_size = 0;                                   539     a_size = 0;
540     if(a_alloc) a_array = 0;                      540     if(a_alloc) a_array = 0;
541     return false;                                 541     return false;
542   }}                                              542   }}
543                                                   543 
544   a_size = (unsigned int)dims[0];                 544   a_size = (unsigned int)dims[0];
545   if(!a_size) {                                   545   if(!a_size) {
546     ::H5Sclose(file_space);                       546     ::H5Sclose(file_space);
547     ::H5Dclose(dataset);                          547     ::H5Dclose(dataset);
548     a_size = 0;                                   548     a_size = 0;
549     if(a_alloc) a_array = 0;                      549     if(a_alloc) a_array = 0;
550     return true; //It is ok.                      550     return true; //It is ok.
551   }                                               551   }
552                                                   552 
553   hid_t mem_space = ::H5Screate_simple(1,dims,    553   hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
554   if(mem_space<0) {                               554   if(mem_space<0) {
555     ::H5Sclose(file_space);                       555     ::H5Sclose(file_space);
556     ::H5Dclose(dataset);                          556     ::H5Dclose(dataset);
557     a_size = 0;                                   557     a_size = 0;
558     if(a_alloc) a_array = 0;                      558     if(a_alloc) a_array = 0;
559     return false;                                 559     return false;
560   }                                               560   }
561                                                   561 
562   if(a_alloc) a_array = new T[a_size];            562   if(a_alloc) a_array = new T[a_size];
563   if(H5Dread(dataset,a_mem_type,mem_space,file    563   if(H5Dread(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
564     if(a_alloc) delete [] a_array;                564     if(a_alloc) delete [] a_array;
565     ::H5Sclose(mem_space);                        565     ::H5Sclose(mem_space);
566     ::H5Sclose(file_space);                       566     ::H5Sclose(file_space);
567     ::H5Dclose(dataset);                          567     ::H5Dclose(dataset);
568     a_size = 0;                                   568     a_size = 0;
569     if(a_alloc) a_array = 0;                      569     if(a_alloc) a_array = 0;
570     return false;                                 570     return false;
571   }                                               571   }
572                                                   572 
573                                                   573 
574   ::H5Sclose(mem_space);                          574   ::H5Sclose(mem_space);
575   ::H5Sclose(file_space);                         575   ::H5Sclose(file_space);
576   ::H5Dclose(dataset);                            576   ::H5Dclose(dataset);
577                                                   577 
578   return true;                                    578   return true;
579 }                                                 579 }
580                                                   580 
581 /*                                                581 /*
582 template <class T>                                582 template <class T>
583 inline bool read_vlen(hid_t a_loc,const std::s    583 inline bool read_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,unsigned int& a_size,T*& a_array) {
584   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c    584   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c_str());
585   if(dataset<0) {                                 585   if(dataset<0) {
586     a_size = 0;                                   586     a_size = 0;
587     a_array = 0;                                  587     a_array = 0;
588     return false; // data set not found.          588     return false; // data set not found.
589   }                                               589   }
590                                                   590 
591   hid_t file_space = H5Dget_space(dataset);       591   hid_t file_space = H5Dget_space(dataset);
592   if(file_space<0) {                              592   if(file_space<0) {
593     ::H5Dclose(dataset);                          593     ::H5Dclose(dataset);
594     a_size = 0;                                   594     a_size = 0;
595     a_array = 0;                                  595     a_array = 0;
596     return false;                                 596     return false;
597   }                                               597   }
598                                                   598 
599  {int dimn = H5Sget_simple_extent_ndims(file_s    599  {int dimn = H5Sget_simple_extent_ndims(file_space);
600   if(dimn<0) {                                    600   if(dimn<0) {
601     ::H5Sclose(file_space);                       601     ::H5Sclose(file_space);
602     ::H5Dclose(dataset);                          602     ::H5Dclose(dataset);
603     a_size = 0;                                   603     a_size = 0;
604     a_array = 0;                                  604     a_array = 0;
605     return false;                                 605     return false;
606   }                                               606   }
607   if(dimn!=1) {                                   607   if(dimn!=1) {
608     ::H5Sclose(file_space);                       608     ::H5Sclose(file_space);
609     ::H5Dclose(dataset);                          609     ::H5Dclose(dataset);
610     a_size = 0;                                   610     a_size = 0;
611     a_array = 0;                                  611     a_array = 0;
612     return false;                                 612     return false;
613   }                                               613   }
614   //printf("debug : read dimn %d\n",dimn);        614   //printf("debug : read dimn %d\n",dimn);
615   }                                               615   }
616                                                   616 
617   hsize_t dims[1];                                617   hsize_t dims[1];
618  {if(H5Sget_simple_extent_dims(file_space,dims    618  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
619     ::H5Sclose(file_space);                       619     ::H5Sclose(file_space);
620     ::H5Dclose(dataset);                          620     ::H5Dclose(dataset);
621     a_size = 0;                                   621     a_size = 0;
622     a_array = 0;                                  622     a_array = 0;
623     return false;                                 623     return false;
624   }}                                              624   }}
625                                                   625 
626   unsigned int _size = (unsigned int)dims[0];     626   unsigned int _size = (unsigned int)dims[0];
627   if(_size!=1) {                                  627   if(_size!=1) {
628     ::H5Sclose(file_space);                       628     ::H5Sclose(file_space);
629     ::H5Dclose(dataset);                          629     ::H5Dclose(dataset);
630     a_size = 0;                                   630     a_size = 0;
631     a_array = 0;                                  631     a_array = 0;
632     return false;                                 632     return false;
633   }                                               633   }
634                                                   634 
635   hid_t mem_space = ::H5Screate_simple(1,dims,    635   hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
636   if(mem_space<0) {                               636   if(mem_space<0) {
637     ::H5Sclose(file_space);                       637     ::H5Sclose(file_space);
638     ::H5Dclose(dataset);                          638     ::H5Dclose(dataset);
639     a_size = 0;                                   639     a_size = 0;
640     a_array = 0;                                  640     a_array = 0;
641     return false;                                 641     return false;
642   }                                               642   }
643                                                   643 
644   hid_t mem_type = ::H5Tvlen_create(a_mem_type    644   hid_t mem_type = ::H5Tvlen_create(a_mem_type);
645                                                   645 
646   hvl_t rdata[1];                                 646   hvl_t rdata[1];
647   if(H5Dread(dataset,mem_type,mem_space,file_s    647   if(H5Dread(dataset,mem_type,mem_space,file_space,H5P_DEFAULT,rdata)<0) {
648     //::H5Dvlen_reclaim(mem_type,mem_space,H5P    648     //::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata); ???
649     ::H5Tclose(mem_type);                         649     ::H5Tclose(mem_type);
650     ::H5Sclose(mem_space);                        650     ::H5Sclose(mem_space);
651     ::H5Sclose(file_space);                       651     ::H5Sclose(file_space);
652     ::H5Dclose(dataset);                          652     ::H5Dclose(dataset);
653     a_size = 0;                                   653     a_size = 0;
654     a_array = 0;                                  654     a_array = 0;
655     return false;                                 655     return false;
656   }                                               656   }
657                                                   657 
658   hsize_t len = rdata[0].len;                     658   hsize_t len = rdata[0].len;
659   if(!len) {                                      659   if(!len) {
660     //a_array = new T[1];                         660     //a_array = new T[1];
661     a_array = 0; //it is ok.                      661     a_array = 0; //it is ok.
662   } else {                                        662   } else {
663     a_array = new T[len];                         663     a_array = new T[len];
664     T* _data = (T*)rdata[0].p;                    664     T* _data = (T*)rdata[0].p;
665     T* pos = a_array;                             665     T* pos = a_array;
666     for(hsize_t index=0;index<len;index++,pos+    666     for(hsize_t index=0;index<len;index++,pos++,_data++) *pos = *_data;
667   }                                               667   }
668   a_size = len;                                   668   a_size = len;
669                                                   669 
670   ::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEF    670   ::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata);
671                                                   671 
672   ::H5Tclose(mem_type);                           672   ::H5Tclose(mem_type);
673   ::H5Sclose(mem_space);                          673   ::H5Sclose(mem_space);
674   ::H5Sclose(file_space);                         674   ::H5Sclose(file_space);
675   ::H5Dclose(dataset);                            675   ::H5Dclose(dataset);
676                                                   676 
677   return true;                                    677   return true;
678 }                                                 678 }
679 */                                                679 */
680                                                   680 
681 template <class T>                                681 template <class T>
682 inline bool read_sub_array(hid_t a_loc,const s    682 inline bool read_sub_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,
683                            unsigned int a_offs    683                            unsigned int a_offset,unsigned int a_number,
684                            unsigned int& a_siz    684                            unsigned int& a_size,T*& a_array) {
685   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c    685   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c_str());
686   if(dataset<0) {                                 686   if(dataset<0) {
687     a_size = 0;                                   687     a_size = 0;
688     a_array = 0;                                  688     a_array = 0;
689     return false; // data set not found.          689     return false; // data set not found.
690   }                                               690   }
691                                                   691 
692   hid_t file_space = H5Dget_space(dataset);       692   hid_t file_space = H5Dget_space(dataset);
693   if(file_space<0) {                              693   if(file_space<0) {
694     ::H5Dclose(dataset);                          694     ::H5Dclose(dataset);
695     a_size = 0;                                   695     a_size = 0;
696     a_array = 0;                                  696     a_array = 0;
697     return false;                                 697     return false;
698   }                                               698   }
699                                                   699 
700  {int dimn = H5Sget_simple_extent_ndims(file_s    700  {int dimn = H5Sget_simple_extent_ndims(file_space);
701   if(dimn<0) {                                    701   if(dimn<0) {
702     ::H5Sclose(file_space);                       702     ::H5Sclose(file_space);
703     ::H5Dclose(dataset);                          703     ::H5Dclose(dataset);
704     a_size = 0;                                   704     a_size = 0;
705     a_array = 0;                                  705     a_array = 0;
706     return false;                                 706     return false;
707   }                                               707   }
708   if(dimn!=1) {                                   708   if(dimn!=1) {
709     ::H5Sclose(file_space);                       709     ::H5Sclose(file_space);
710     ::H5Dclose(dataset);                          710     ::H5Dclose(dataset);
711     a_size = 0;                                   711     a_size = 0;
712     a_array = 0;                                  712     a_array = 0;
713     return false;                                 713     return false;
714   }                                               714   }
715   //printf("debug : read dimn %d\n",dimn);        715   //printf("debug : read dimn %d\n",dimn);
716   }                                               716   }
717                                                   717 
718   hsize_t dims[1];                                718   hsize_t dims[1];
719  {if(H5Sget_simple_extent_dims(file_space,dims    719  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
720     ::H5Sclose(file_space);                       720     ::H5Sclose(file_space);
721     ::H5Dclose(dataset);                          721     ::H5Dclose(dataset);
722     a_size = 0;                                   722     a_size = 0;
723     a_array = 0;                                  723     a_array = 0;
724     return false;                                 724     return false;
725   }}                                              725   }}
726                                                   726 
727   unsigned int sz = (unsigned int)dims[0];        727   unsigned int sz = (unsigned int)dims[0];
728   if(!sz) {                                       728   if(!sz) {
729     ::H5Sclose(file_space);                       729     ::H5Sclose(file_space);
730     ::H5Dclose(dataset);                          730     ::H5Dclose(dataset);
731     a_size = 0;                                   731     a_size = 0;
732     a_array = 0;                                  732     a_array = 0;
733     return true; //It is ok.                      733     return true; //It is ok.
734   }                                               734   }
735                                                   735 
736   //  abcdef                                      736   //  abcdef
737   //  012345                                      737   //  012345
738   int remain = sz-a_offset;                       738   int remain = sz-a_offset;
739   if(remain<=0) {                                 739   if(remain<=0) {
740     ::H5Sclose(file_space);                       740     ::H5Sclose(file_space);
741     ::H5Dclose(dataset);                          741     ::H5Dclose(dataset);
742     a_size = 0;                                   742     a_size = 0;
743     a_array = 0;                                  743     a_array = 0;
744     return a_number?false:true;                   744     return a_number?false:true;
745   }                                               745   }
746                                                   746 
747   int number = (int(a_number)<=remain) ? int(a    747   int number = (int(a_number)<=remain) ? int(a_number) : remain;
748   if(number<=0) {                                 748   if(number<=0) {
749     ::H5Sclose(file_space);                       749     ::H5Sclose(file_space);
750     ::H5Dclose(dataset);                          750     ::H5Dclose(dataset);
751     a_size = 0;                                   751     a_size = 0;
752     a_array = 0;                                  752     a_array = 0;
753     return true; //It is ok.                      753     return true; //It is ok.
754   }                                               754   }
755                                                   755 
756  {hsize_t offset[1];                              756  {hsize_t offset[1];
757   offset[0] = a_offset;                           757   offset[0] = a_offset;
758   hsize_t count[1];                               758   hsize_t count[1];
759   count[0] = number;                              759   count[0] = number;
760   if(H5Sselect_hyperslab(file_space,H5S_SELECT    760   if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
761     ::H5Sclose(file_space);                       761     ::H5Sclose(file_space);
762     ::H5Dclose(dataset);                          762     ::H5Dclose(dataset);
763     a_size = 0;                                   763     a_size = 0;
764     a_array = 0;                                  764     a_array = 0;
765     return false;                                 765     return false;
766   }}                                              766   }}
767                                                   767 
768   dims[0] = number;                               768   dims[0] = number;
769   hid_t mem_space = ::H5Screate_simple(1,dims,    769   hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
770   if(mem_space<0) {                               770   if(mem_space<0) {
771     ::H5Sclose(file_space);                       771     ::H5Sclose(file_space);
772     ::H5Dclose(dataset);                          772     ::H5Dclose(dataset);
773     a_size = 0;                                   773     a_size = 0;
774     a_array = 0;                                  774     a_array = 0;
775     return false;                                 775     return false;
776   }                                               776   }
777                                                   777 
778   a_array = new T[number];                        778   a_array = new T[number];
779   if(H5Dread(dataset,a_mem_type,mem_space,file    779   if(H5Dread(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
780     delete [] a_array;                            780     delete [] a_array;
781     ::H5Sclose(mem_space);                        781     ::H5Sclose(mem_space);
782     ::H5Sclose(file_space);                       782     ::H5Sclose(file_space);
783     ::H5Dclose(dataset);                          783     ::H5Dclose(dataset);
784     a_array = 0;                                  784     a_array = 0;
785     return false;                                 785     return false;
786   }                                               786   }
787                                                   787 
788   ::H5Sclose(mem_space);                          788   ::H5Sclose(mem_space);
789   ::H5Sclose(file_space);                         789   ::H5Sclose(file_space);
790   ::H5Dclose(dataset);                            790   ::H5Dclose(dataset);
791                                                   791 
792   a_size = number;                                792   a_size = number;
793                                                   793 
794   return true;                                    794   return true;
795 }                                                 795 }
796                                                   796 
797 template <class T>                                797 template <class T>
798 inline bool read_sub_vlen(hid_t a_loc,const st    798 inline bool read_sub_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,
799                           unsigned int a_offse    799                           unsigned int a_offset,
800                           unsigned int& a_size    800                           unsigned int& a_size,T*& a_array) {
801   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c    801   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c_str());
802   if(dataset<0) {                                 802   if(dataset<0) {
803     a_size = 0;                                   803     a_size = 0;
804     a_array = 0;                                  804     a_array = 0;
805     return false; // data set not found.          805     return false; // data set not found.
806   }                                               806   }
807                                                   807 
808   hid_t file_space = H5Dget_space(dataset);       808   hid_t file_space = H5Dget_space(dataset);
809   if(file_space<0) {                              809   if(file_space<0) {
810     ::H5Dclose(dataset);                          810     ::H5Dclose(dataset);
811     a_size = 0;                                   811     a_size = 0;
812     a_array = 0;                                  812     a_array = 0;
813     return false;                                 813     return false;
814   }                                               814   }
815                                                   815 
816  {int dimn = H5Sget_simple_extent_ndims(file_s    816  {int dimn = H5Sget_simple_extent_ndims(file_space);
817   if(dimn<0) {                                    817   if(dimn<0) {
818     ::H5Sclose(file_space);                       818     ::H5Sclose(file_space);
819     ::H5Dclose(dataset);                          819     ::H5Dclose(dataset);
820     a_size = 0;                                   820     a_size = 0;
821     a_array = 0;                                  821     a_array = 0;
822     return false;                                 822     return false;
823   }                                               823   }
824   if(dimn!=1) {                                   824   if(dimn!=1) {
825     ::H5Sclose(file_space);                       825     ::H5Sclose(file_space);
826     ::H5Dclose(dataset);                          826     ::H5Dclose(dataset);
827     a_size = 0;                                   827     a_size = 0;
828     a_array = 0;                                  828     a_array = 0;
829     return false;                                 829     return false;
830   }                                               830   }
831   //printf("debug : read dimn %d\n",dimn);        831   //printf("debug : read dimn %d\n",dimn);
832   }                                               832   }
833                                                   833 
834   hsize_t dims[1];                                834   hsize_t dims[1];
835  {if(H5Sget_simple_extent_dims(file_space,dims    835  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
836     ::H5Sclose(file_space);                       836     ::H5Sclose(file_space);
837     ::H5Dclose(dataset);                          837     ::H5Dclose(dataset);
838     a_size = 0;                                   838     a_size = 0;
839     a_array = 0;                                  839     a_array = 0;
840     return false;                                 840     return false;
841   }}                                              841   }}
842                                                   842 
843   unsigned int sz = (unsigned int)dims[0];        843   unsigned int sz = (unsigned int)dims[0];
844   if(!sz) {                                       844   if(!sz) {
845     ::H5Sclose(file_space);                       845     ::H5Sclose(file_space);
846     ::H5Dclose(dataset);                          846     ::H5Dclose(dataset);
847     a_size = 0;                                   847     a_size = 0;
848     a_array = 0;                                  848     a_array = 0;
849     return true; //It is ok.                      849     return true; //It is ok.
850   }                                               850   }
851                                                   851 
852   //  abcdef                                      852   //  abcdef
853   //  012345                                      853   //  012345
854   int remain = sz-a_offset;                       854   int remain = sz-a_offset;
855   if(remain<=0) {                                 855   if(remain<=0) {
856     ::H5Sclose(file_space);                       856     ::H5Sclose(file_space);
857     ::H5Dclose(dataset);                          857     ::H5Dclose(dataset);
858     a_size = 0;                                   858     a_size = 0;
859     a_array = 0;                                  859     a_array = 0;
860     return false;                                 860     return false;
861   }                                               861   }
862                                                   862 
863  {hsize_t offset[1];                              863  {hsize_t offset[1];
864   offset[0] = a_offset;                           864   offset[0] = a_offset;
865   hsize_t count[1];                               865   hsize_t count[1];
866   count[0] = 1;                                   866   count[0] = 1;
867   if(H5Sselect_hyperslab(file_space,H5S_SELECT    867   if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
868     ::H5Sclose(file_space);                       868     ::H5Sclose(file_space);
869     ::H5Dclose(dataset);                          869     ::H5Dclose(dataset);
870     a_size = 0;                                   870     a_size = 0;
871     a_array = 0;                                  871     a_array = 0;
872     return false;                                 872     return false;
873   }}                                              873   }}
874                                                   874 
875   dims[0] = 1;                                    875   dims[0] = 1;
876   hid_t mem_space = ::H5Screate_simple(1,dims,    876   hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
877   if(mem_space<0) {                               877   if(mem_space<0) {
878     ::H5Sclose(file_space);                       878     ::H5Sclose(file_space);
879     ::H5Dclose(dataset);                          879     ::H5Dclose(dataset);
880     a_size = 0;                                   880     a_size = 0;
881     a_array = 0;                                  881     a_array = 0;
882     return false;                                 882     return false;
883   }                                               883   }
884                                                   884 
885   hid_t mem_type = ::H5Tvlen_create(a_mem_type    885   hid_t mem_type = ::H5Tvlen_create(a_mem_type);
886                                                   886 
887   hvl_t rdata[1];                                 887   hvl_t rdata[1];
888   if(H5Dread(dataset,mem_type,mem_space,file_s    888   if(H5Dread(dataset,mem_type,mem_space,file_space,H5P_DEFAULT,rdata)<0) {
889     //::H5Dvlen_reclaim(mem_type,mem_space,H5P    889     //::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata); ???
890     ::H5Tclose(mem_type);                         890     ::H5Tclose(mem_type);
891     ::H5Sclose(mem_space);                        891     ::H5Sclose(mem_space);
892     ::H5Sclose(file_space);                       892     ::H5Sclose(file_space);
893     ::H5Dclose(dataset);                          893     ::H5Dclose(dataset);
894     a_size = 0;                                   894     a_size = 0;
895     a_array = 0;                                  895     a_array = 0;
896     return false;                                 896     return false;
897   }                                               897   }
898                                                   898 
899   hsize_t len = rdata[0].len;                     899   hsize_t len = rdata[0].len;
900   if(!len) {                                      900   if(!len) {
901     //a_array = new T[1];                         901     //a_array = new T[1];
902     a_array = 0; //it is ok.                      902     a_array = 0; //it is ok.
903   } else {                                        903   } else {
904     a_array = new T[len];                         904     a_array = new T[len];
905     T* _data = (T*)rdata[0].p;                    905     T* _data = (T*)rdata[0].p;
906     T* pos = a_array;                             906     T* pos = a_array;
907     for(hsize_t index=0;index<len;index++,pos+    907     for(hsize_t index=0;index<len;index++,pos++,_data++) *pos = *_data;
908   }                                               908   }
909   a_size = len;                                   909   a_size = len;
910                                                   910 
911   ::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEF    911   ::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata);
912                                                   912 
913   ::H5Tclose(mem_type);                           913   ::H5Tclose(mem_type);
914   ::H5Sclose(mem_space);                          914   ::H5Sclose(mem_space);
915   ::H5Sclose(file_space);                         915   ::H5Sclose(file_space);
916   ::H5Dclose(dataset);                            916   ::H5Dclose(dataset);
917                                                   917 
918   return true;                                    918   return true;
919 }                                                 919 }
920                                                   920 
921 template <class TYPE>                             921 template <class TYPE>
922 inline bool read_scalar(hid_t a_loc,const std:    922 inline bool read_scalar(hid_t a_loc,const std::string& a_name,TYPE& aValue) {
923   return read_scalar<TYPE>(a_loc,a_name,to_T_m    923   return read_scalar<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),aValue);
924 }                                                 924 }
925                                                   925 
926 template <class T>                                926 template <class T>
927 inline bool read_std_vec(hid_t a_loc,const std    927 inline bool read_std_vec(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,std::vector<T>& a_vec) {
928   tools::uint64 sz;                               928   tools::uint64 sz;
929   if(!read_scalar<tools::uint64>(a_loc,a_name+    929   if(!read_scalar<tools::uint64>(a_loc,a_name+"_size",sz)) return false;
930   if(!sz) {a_vec.clear();return true;} //it is    930   if(!sz) {a_vec.clear();return true;} //it is ok.
931   a_vec.resize((size_t)sz);                       931   a_vec.resize((size_t)sz);
932   T* data = tools::vec_data(a_vec);               932   T* data = tools::vec_data(a_vec);
933   unsigned int _sz;                               933   unsigned int _sz;
934   if(!read_array(a_loc,a_name,a_mem_type,_sz,d    934   if(!read_array(a_loc,a_name,a_mem_type,_sz,data,false)) return false; //false = do not alloc.
935   if(tools::uint64(_sz)!=sz) {a_vec.clear();re    935   if(tools::uint64(_sz)!=sz) {a_vec.clear();return false;}
936   return true;                                    936   return true;
937 }                                                 937 }
938                                                   938 
939 template <class TYPE>                             939 template <class TYPE>
940 inline bool read_std_vec_vec(hid_t a_loc,const    940 inline bool read_std_vec_vec(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,std::vector< std::vector<TYPE> >& a_vec_vec) {
941   tools::uint64 sz;                               941   tools::uint64 sz;
942   if(!read_scalar<tools::uint64>(a_loc,a_name+    942   if(!read_scalar<tools::uint64>(a_loc,a_name+"_size",sz)) {a_vec_vec.clear();return false;}
943   a_vec_vec.resize((size_t)sz);                   943   a_vec_vec.resize((size_t)sz);
944   std::string scount;                             944   std::string scount;
945   for(size_t count=0;count<(size_t)sz;count++)    945   for(size_t count=0;count<(size_t)sz;count++) {
946     tools::num2s(tools::uint64(count),scount);    946     tools::num2s(tools::uint64(count),scount);
947     if(!read_std_vec<TYPE>(a_loc,a_name+"_elem    947     if(!read_std_vec<TYPE>(a_loc,a_name+"_elem_"+scount,a_mem_type,a_vec_vec[count])) {a_vec_vec.clear();return false;}
948   }                                               948   }
949   return true;                                    949   return true;
950 }                                                 950 }
951                                                   951 
952 /*                                                952 /*
953 template <class T>                                953 template <class T>
954 inline bool read_array_struct(                    954 inline bool read_array_struct(
955  hid_t a_loc                                      955  hid_t a_loc
956 ,const std::string& a_name                        956 ,const std::string& a_name
957 ,hid_t aReadType                                  957 ,hid_t aReadType
958 ,unsigned int& a_size                             958 ,unsigned int& a_size
959 ,T*& a_array                                      959 ,T*& a_array
960 ){                                                960 ){
961   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c    961   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c_str());
962   if(dataset<0) {                                 962   if(dataset<0) {
963     a_size = 0;                                   963     a_size = 0;
964     a_array = 0;                                  964     a_array = 0;
965     return false; // data set not found.          965     return false; // data set not found.
966   }                                               966   }
967                                                   967 
968   hid_t dataspace = H5Dget_space(dataset);        968   hid_t dataspace = H5Dget_space(dataset);
969   if(dataspace<0) {                               969   if(dataspace<0) {
970     ::H5Dclose(dataset);                          970     ::H5Dclose(dataset);
971     a_size = 0;                                   971     a_size = 0;
972     a_array = 0;                                  972     a_array = 0;
973     return false;                                 973     return false;
974   }                                               974   }
975                                                   975 
976   int dimn = H5Sget_simple_extent_ndims(datasp    976   int dimn = H5Sget_simple_extent_ndims(dataspace);
977   if(dimn<0) {                                    977   if(dimn<0) {
978     ::H5Sclose(dataspace);                        978     ::H5Sclose(dataspace);
979     ::H5Dclose(dataset);                          979     ::H5Dclose(dataset);
980     a_size = 0;                                   980     a_size = 0;
981     a_array = 0;                                  981     a_array = 0;
982     return false;                                 982     return false;
983   }                                               983   }
984   //printf("debug : read dimn %d\n",dimn);        984   //printf("debug : read dimn %d\n",dimn);
985                                                   985 
986   hsize_t* dims = new hsize_t[dimn];              986   hsize_t* dims = new hsize_t[dimn];
987  {int rdimn = H5Sget_simple_extent_dims(datasp    987  {int rdimn = H5Sget_simple_extent_dims(dataspace,dims,NULL);
988   if(rdimn<0) {                                   988   if(rdimn<0) {
989     delete [] dims;                               989     delete [] dims;
990     ::H5Sclose(dataspace);                        990     ::H5Sclose(dataspace);
991     ::H5Dclose(dataset);                          991     ::H5Dclose(dataset);
992     a_size = 0;                                   992     a_size = 0;
993     a_array = 0;                                  993     a_array = 0;
994     return false;                                 994     return false;
995   }}                                              995   }}
996                                                   996 
997   hid_t memspace = ::H5Screate_simple(dimn,dim    997   hid_t memspace = ::H5Screate_simple(dimn,dims,NULL);
998   if(memspace<0) {                                998   if(memspace<0) {
999     delete [] dims;                               999     delete [] dims;
1000     ::H5Sclose(dataspace);                       1000     ::H5Sclose(dataspace);
1001     ::H5Dclose(dataset);                         1001     ::H5Dclose(dataset);
1002     a_size = 0;                                  1002     a_size = 0;
1003     a_array = 0;                                 1003     a_array = 0;
1004     return false;                                1004     return false;
1005   }                                              1005   }
1006                                                  1006 
1007   a_size = (unsigned int)dims[0];                1007   a_size = (unsigned int)dims[0];
1008   delete [] dims;                                1008   delete [] dims;
1009   if(!a_size) {                                  1009   if(!a_size) {
1010     ::H5Sclose(memspace);                        1010     ::H5Sclose(memspace);
1011     ::H5Sclose(dataspace);                       1011     ::H5Sclose(dataspace);
1012     ::H5Dclose(dataset);                         1012     ::H5Dclose(dataset);
1013     a_size = 0;                                  1013     a_size = 0;
1014     a_array = 0;                                 1014     a_array = 0;
1015     return false;                                1015     return false;
1016   }                                              1016   }
1017                                                  1017 
1018   a_array = new T[a_size];                       1018   a_array = new T[a_size];
1019   if(H5Dread(dataset,aReadType,memspace,datas    1019   if(H5Dread(dataset,aReadType,memspace,dataspace,H5P_DEFAULT,a_array)<0) {
1020     delete [] a_array;                           1020     delete [] a_array;
1021     ::H5Sclose(memspace);                        1021     ::H5Sclose(memspace);
1022     ::H5Sclose(dataspace);                       1022     ::H5Sclose(dataspace);
1023     ::H5Dclose(dataset);                         1023     ::H5Dclose(dataset);
1024     a_size = 0;                                  1024     a_size = 0;
1025     a_array = 0;                                 1025     a_array = 0;
1026     return false;                                1026     return false;
1027   }                                              1027   }
1028                                                  1028 
1029   ::H5Sclose(memspace);                          1029   ::H5Sclose(memspace);
1030   ::H5Sclose(dataspace);                         1030   ::H5Sclose(dataspace);
1031   ::H5Dclose(dataset);                           1031   ::H5Dclose(dataset);
1032                                                  1032 
1033   return true;                                   1033   return true;
1034 }                                                1034 }
1035 */                                               1035 */
1036                                                  1036 
1037 template <class T>                               1037 template <class T>
1038 inline bool read_struct(hid_t a_loc,const std    1038 inline bool read_struct(hid_t a_loc,const std::string& a_name,hid_t aReadType,T& a_data) {
1039   hid_t dataset = toolx_H5Dopen(a_loc,a_name.    1039   hid_t dataset = toolx_H5Dopen(a_loc,a_name.c_str());
1040   if(dataset<0) return false;                    1040   if(dataset<0) return false;
1041                                                  1041 
1042   hid_t file_space = H5Dget_space(dataset);      1042   hid_t file_space = H5Dget_space(dataset);
1043   if(file_space<0) {                             1043   if(file_space<0) {
1044     ::H5Dclose(dataset);                         1044     ::H5Dclose(dataset);
1045     return false;                                1045     return false;
1046   }                                              1046   }
1047                                                  1047 
1048   hid_t mem_space = ::H5Screate(H5S_SCALAR);     1048   hid_t mem_space = ::H5Screate(H5S_SCALAR);
1049   if(mem_space<0) {                              1049   if(mem_space<0) {
1050     ::H5Sclose(file_space);                      1050     ::H5Sclose(file_space);
1051     ::H5Dclose(dataset);                         1051     ::H5Dclose(dataset);
1052     return false;                                1052     return false;
1053   }                                              1053   }
1054                                                  1054 
1055   if(H5Dread(dataset,aReadType,mem_space,file    1055   if(H5Dread(dataset,aReadType,mem_space,file_space,H5P_DEFAULT,&a_data)<0) {
1056     ::H5Sclose(mem_space);                       1056     ::H5Sclose(mem_space);
1057     ::H5Sclose(file_space);                      1057     ::H5Sclose(file_space);
1058     ::H5Dclose(dataset);                         1058     ::H5Dclose(dataset);
1059     return false;                                1059     return false;
1060   }                                              1060   }
1061                                                  1061 
1062   ::H5Sclose(mem_space);                         1062   ::H5Sclose(mem_space);
1063   ::H5Sclose(file_space);                        1063   ::H5Sclose(file_space);
1064   ::H5Dclose(dataset);                           1064   ::H5Dclose(dataset);
1065   return true;                                   1065   return true;
1066 }                                                1066 }
1067                                                  1067 
1068 template <class TYPE>                            1068 template <class TYPE>
1069 inline bool write_scalar(hid_t a_loc,const st    1069 inline bool write_scalar(hid_t a_loc,const std::string& a_name,const TYPE& aData) {
1070   hid_t scalar = ::H5Screate(H5S_SCALAR);        1070   hid_t scalar = ::H5Screate(H5S_SCALAR);
1071   if(scalar<0) return false;                     1071   if(scalar<0) return false;
1072                                                  1072 
1073   hid_t compact = ::H5Pcreate(H5P_DATASET_CRE    1073   hid_t compact = ::H5Pcreate(H5P_DATASET_CREATE);
1074   if(compact<0) {                                1074   if(compact<0) {
1075     ::H5Sclose(scalar);                          1075     ::H5Sclose(scalar);
1076     return false;                                1076     return false;
1077   }                                              1077   }
1078                                                  1078 
1079   if(H5Pset_layout(compact,H5D_COMPACT)<0) {     1079   if(H5Pset_layout(compact,H5D_COMPACT)<0) {
1080     ::H5Pclose(compact);                         1080     ::H5Pclose(compact);
1081     ::H5Sclose(scalar);                          1081     ::H5Sclose(scalar);
1082     return false;                                1082     return false;
1083   }                                              1083   }
1084                                                  1084 
1085   hid_t dataset = toolx_H5Dcreate(a_loc,a_nam    1085   hid_t dataset = toolx_H5Dcreate(a_loc,a_name.c_str(),to_T_file_type(TYPE()),scalar,compact);
1086   if(dataset<0) {                                1086   if(dataset<0) {
1087     ::H5Pclose(compact);                         1087     ::H5Pclose(compact);
1088     ::H5Sclose(scalar);                          1088     ::H5Sclose(scalar);
1089     return false;                                1089     return false;
1090   }                                              1090   }
1091                                                  1091 
1092   if(::H5Dwrite(dataset,to_T_mem_type(TYPE())    1092   if(::H5Dwrite(dataset,to_T_mem_type(TYPE()),H5S_ALL,H5S_ALL,H5P_DEFAULT,&aData)<0) {
1093     ::H5Pclose(compact);                         1093     ::H5Pclose(compact);
1094     ::H5Sclose(scalar);                          1094     ::H5Sclose(scalar);
1095     ::H5Dclose(dataset);                         1095     ::H5Dclose(dataset);
1096     return false;                                1096     return false;
1097   }                                              1097   }
1098                                                  1098 
1099   ::H5Pclose(compact);                           1099   ::H5Pclose(compact);
1100   ::H5Sclose(scalar);                            1100   ::H5Sclose(scalar);
1101   ::H5Dclose(dataset);                           1101   ::H5Dclose(dataset);
1102   return true;                                   1102   return true;
1103 }                                                1103 }
1104                                                  1104 
1105 template <class T>                               1105 template <class T>
1106 inline bool write_struct(hid_t a_loc,const st    1106 inline bool write_struct(hid_t a_loc,const std::string& a_name,
1107                          hid_t a_create_type,    1107                          hid_t a_create_type,hid_t aWriteType,const T& aData) {
1108   hid_t scalar = ::H5Screate(H5S_SCALAR);        1108   hid_t scalar = ::H5Screate(H5S_SCALAR);
1109   if(scalar<0) return false;                     1109   if(scalar<0) return false;
1110                                                  1110 
1111   hid_t compact = ::H5Pcreate(H5P_DATASET_CRE    1111   hid_t compact = ::H5Pcreate(H5P_DATASET_CREATE);
1112   if(compact<0) {                                1112   if(compact<0) {
1113     ::H5Sclose(scalar);                          1113     ::H5Sclose(scalar);
1114     return false;                                1114     return false;
1115   }                                              1115   }
1116                                                  1116 
1117   if(H5Pset_layout(compact,H5D_COMPACT)<0) {     1117   if(H5Pset_layout(compact,H5D_COMPACT)<0) {
1118     ::H5Pclose(compact);                         1118     ::H5Pclose(compact);
1119     ::H5Sclose(scalar);                          1119     ::H5Sclose(scalar);
1120     return false;                                1120     return false;
1121   }                                              1121   }
1122                                                  1122 
1123   hid_t dataset = toolx_H5Dcreate(a_loc,a_nam    1123   hid_t dataset = toolx_H5Dcreate(a_loc,a_name.c_str(),a_create_type,scalar,compact);
1124   if(dataset<0) {                                1124   if(dataset<0) {
1125     ::H5Pclose(compact);                         1125     ::H5Pclose(compact);
1126     ::H5Sclose(scalar);                          1126     ::H5Sclose(scalar);
1127     return false;                                1127     return false;
1128   }                                              1128   }
1129                                                  1129 
1130   if(H5Dwrite(dataset,aWriteType,H5S_ALL,H5S_    1130   if(H5Dwrite(dataset,aWriteType,H5S_ALL,H5S_ALL,H5P_DEFAULT,&aData)<0) {
1131     ::H5Pclose(compact);                         1131     ::H5Pclose(compact);
1132     ::H5Sclose(scalar);                          1132     ::H5Sclose(scalar);
1133     ::H5Dclose(dataset);                         1133     ::H5Dclose(dataset);
1134     return false;                                1134     return false;
1135   }                                              1135   }
1136                                                  1136 
1137   ::H5Pclose(compact);                           1137   ::H5Pclose(compact);
1138   ::H5Sclose(scalar);                            1138   ::H5Sclose(scalar);
1139   ::H5Dclose(dataset);                           1139   ::H5Dclose(dataset);
1140   return true;                                   1140   return true;
1141 }                                                1141 }
1142                                                  1142 
1143 /////////////////////////////////////////////    1143 //////////////////////////////////////////////////////////////////////////////
1144 /////////////////////////////////////////////    1144 //////////////////////////////////////////////////////////////////////////////
1145 /////////////////////////////////////////////    1145 //////////////////////////////////////////////////////////////////////////////
1146 template <class TYPE>                            1146 template <class TYPE>
1147 inline bool write_array(hid_t a_loc,const std    1147 inline bool write_array(hid_t a_loc,const std::string& a_name,
1148                         unsigned int a_size,c    1148                         unsigned int a_size,const TYPE a_array[],
1149                         unsigned int a_chunke    1149                         unsigned int a_chunked = 0,unsigned int a_compress = 0) {
1150   return hdf5::write_array<TYPE>(a_loc,a_name    1150   return hdf5::write_array<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),
1151                                  a_chunked,a_    1151                                  a_chunked,a_compress,a_size,a_array);
1152 }                                                1152 }
1153                                                  1153 
1154 template <class TYPE>                            1154 template <class TYPE>
1155 inline bool write_vlen(hid_t a_loc,const std:    1155 inline bool write_vlen(hid_t a_loc,const std::string& a_name,
1156                        unsigned int a_size,co    1156                        unsigned int a_size,const TYPE a_array[],
1157                        unsigned int a_chunked    1157                        unsigned int a_chunked = 0,unsigned int a_compress = 0) {
1158   return hdf5::write_vlen<TYPE>(a_loc,a_name,    1158   return hdf5::write_vlen<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),
1159                                 a_chunked,a_c    1159                                 a_chunked,a_compress,a_size,a_array);
1160 }                                                1160 }
1161                                                  1161 
1162 template <class T>                               1162 template <class T>
1163 inline bool write_std_vec(hid_t a_loc,const s    1163 inline bool write_std_vec(hid_t a_loc,const std::string& a_name,
1164                           hid_t a_file_type,h    1164                           hid_t a_file_type,hid_t a_mem_type,
1165                           unsigned int a_chun    1165                           unsigned int a_chunked,unsigned int a_compress,
1166                           const std::vector<T    1166                           const std::vector<T>& a_vec) {
1167   if(!write_scalar<tools::uint64>(a_loc,a_nam    1167   if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_vec.size())) return false;
1168   if(a_vec.empty()) return true; //it is ok.     1168   if(a_vec.empty()) return true; //it is ok.
1169   const T* data = tools::vec_data(a_vec);        1169   const T* data = tools::vec_data(a_vec);
1170   return write_array(a_loc,a_name,a_file_type    1170   return write_array(a_loc,a_name,a_file_type,a_mem_type,a_chunked,a_compress,a_vec.size(),data);
1171 }                                                1171 }
1172                                                  1172 
1173 template <class TYPE>                            1173 template <class TYPE>
1174 inline bool write_std_vec(hid_t a_loc,const s    1174 inline bool write_std_vec(hid_t a_loc,const std::string& a_name,const std::vector<TYPE>& a_array,
1175                           unsigned int a_chun    1175                           unsigned int a_chunked = 0,unsigned int a_compress = 0) {
1176   return hdf5::write_std_vec<TYPE>(a_loc,a_na    1176   return hdf5::write_std_vec<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_chunked,a_compress,a_array);
1177 }                                                1177 }
1178                                                  1178 
1179 template <class TYPE>                            1179 template <class TYPE>
1180 inline bool write_std_vec_vec(hid_t a_loc,con    1180 inline bool write_std_vec_vec(hid_t a_loc,const std::string& a_name,const std::vector< std::vector<TYPE> >& a_vec_vec,
1181                               unsigned int /*    1181                               unsigned int /*a_chunked*/ = 0,unsigned int /*a_compress*/ = 0) {
1182   if(!write_scalar<tools::uint64>(a_loc,a_nam    1182   if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_vec_vec.size())) return false;
1183   unsigned int count = 0; //uint for num2s.      1183   unsigned int count = 0; //uint for num2s.
1184   std::string scount;                            1184   std::string scount;
1185   tools_typename_vforcit(std::vector<TYPE>,a_    1185   tools_typename_vforcit(std::vector<TYPE>,a_vec_vec,it) {
1186     tools::num2s(count,scount);                  1186     tools::num2s(count,scount);
1187     if(!write_std_vec<TYPE>(a_loc,a_name+"_el    1187     if(!write_std_vec<TYPE>(a_loc,a_name+"_elem_"+scount,*it)) return false;
1188     count++;                                     1188     count++;
1189   }                                              1189   }
1190   return true;                                   1190   return true;
1191 }                                                1191 }
1192                                                  1192 
1193 //template <class TKEY,class TVALUE>             1193 //template <class TKEY,class TVALUE>
1194 //inline bool write_std_map(hid_t a_loc,const    1194 //inline bool write_std_map(hid_t a_loc,const std::string& a_name,const std::map<TKEY,TVALUE>& a_map,
1195 //                          unsigned int a_ch    1195 //                          unsigned int a_chunked = 0,unsigned int a_compress = 0) {
1196 //  if(!write_scalar<tools::uint64>(a_loc,a_n    1196 //  if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_map.size())) return false;
1197 //  unsigned int count = 0; //uint for num2s.    1197 //  unsigned int count = 0; //uint for num2s.
1198 //  std::string scount;                          1198 //  std::string scount;
1199 //  tools_typename_mforcit(TKEY,TVALUE,a_map,    1199 //  tools_typename_mforcit(TKEY,TVALUE,a_map,it) {
1200 //    tools::num2s(count,scount);                1200 //    tools::num2s(count,scount);
1201 //    if(!write_scalar<TKEY>(a_loc,a_name+"_e    1201 //    if(!write_scalar<TKEY>(a_loc,a_name+"_elem_"+scount+"_first",(*it).first)) return false;
1202 //    if(!write_scalar<TVALUE>(a_loc,a_name+"    1202 //    if(!write_scalar<TVALUE>(a_loc,a_name+"_elem_"+scount+"_secon",(*it).second)) return false;
1203 //    count++;                                   1203 //    count++;
1204 //  }                                            1204 //  }
1205 //  return true;                                 1205 //  return true;
1206 //}                                              1206 //}
1207                                                  1207 
1208 template <class TYPE>                            1208 template <class TYPE>
1209 inline bool write_sub_array(hid_t a_loc,const    1209 inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
1210                      unsigned int a_size,unsi    1210                      unsigned int a_size,unsigned int a_offset,unsigned int a_number,const TYPE a_array[],
1211                      bool a_create = true,uns    1211                      bool a_create = true,unsigned int a_chunked = 0,unsigned int a_compress = 0) {
1212   return hdf5::write_sub_array<TYPE>(a_loc,a_    1212   return hdf5::write_sub_array<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),
1213                                      a_create    1213                                      a_create,a_chunked,a_compress,
1214                                      a_size,a    1214                                      a_size,a_offset,a_number,a_array);
1215 }                                                1215 }
1216                                                  1216 
1217 template <class TYPE>                            1217 template <class TYPE>
1218 inline bool write_append_array_dataset(hid_t     1218 inline bool write_append_array_dataset(hid_t a_dataset,unsigned int a_number,const TYPE a_array[]) {
1219   return hdf5::write_append_array_dataset<TYP    1219   return hdf5::write_append_array_dataset<TYPE>(a_dataset,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
1220 }                                                1220 }
1221                                                  1221 
1222 template <class TYPE>                            1222 template <class TYPE>
1223 inline bool write_append_vlen_dataset(hid_t a    1223 inline bool write_append_vlen_dataset(hid_t a_dataset,unsigned int a_number,const TYPE a_array[]) {
1224   return hdf5::write_append_vlen_dataset<TYPE    1224   return hdf5::write_append_vlen_dataset<TYPE>(a_dataset,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
1225 }                                                1225 }
1226                                                  1226 
1227 template <class TYPE>                            1227 template <class TYPE>
1228 inline bool write_append_array(hid_t a_loc,co    1228 inline bool write_append_array(hid_t a_loc,const std::string& a_name,unsigned int a_number,const TYPE a_array[]) {
1229   return hdf5::write_append_array<TYPE>(a_loc    1229   return hdf5::write_append_array<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
1230 }                                                1230 }
1231                                                  1231 
1232 template <class TYPE>                            1232 template <class TYPE>
1233 inline bool read_array(hid_t a_loc,const std:    1233 inline bool read_array(hid_t a_loc,const std::string& a_name,unsigned int& a_size,TYPE*& a_array) {
1234   return read_array<TYPE>(a_loc,a_name,to_T_m    1234   return read_array<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_size,a_array);
1235 }                                                1235 }
1236                                                  1236 
1237 //template <class TYPE>                          1237 //template <class TYPE>
1238 //inline bool read_vlen(hid_t a_loc,const std    1238 //inline bool read_vlen(hid_t a_loc,const std::string& a_name,unsigned int& a_size,TYPE*& a_array) {
1239 //  return read_vlen<TYPE>(a_loc,a_name,to_T_    1239 //  return read_vlen<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_size,a_array);
1240 //}                                              1240 //}
1241                                                  1241 
1242 template <class TYPE>                            1242 template <class TYPE>
1243 inline bool read_std_vec(hid_t a_loc,const st    1243 inline bool read_std_vec(hid_t a_loc,const std::string& a_name,std::vector<TYPE>& a_vec) {
1244   return read_std_vec<TYPE>(a_loc,a_name,to_T    1244   return read_std_vec<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_vec);
1245 }                                                1245 }
1246                                                  1246 
1247 template <class TYPE>                            1247 template <class TYPE>
1248 inline bool read_std_vec_vec(hid_t a_loc,cons    1248 inline bool read_std_vec_vec(hid_t a_loc,const std::string& a_name,std::vector< std::vector<TYPE> >& a_vec_vec) {
1249   return read_std_vec_vec<TYPE>(a_loc,a_name,    1249   return read_std_vec_vec<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_vec_vec);
1250 }                                                1250 }
1251                                                  1251 
1252 template <class TYPE>                            1252 template <class TYPE>
1253 inline bool read_sub_array(hid_t a_loc,const     1253 inline bool read_sub_array(hid_t a_loc,const std::string& a_name,unsigned int a_offset,unsigned int a_number,
1254                            unsigned int& a_si    1254                            unsigned int& a_size,TYPE*& a_array) {
1255   return read_sub_array<TYPE>(a_loc,a_name,to    1255   return read_sub_array<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_offset,a_number,a_size,a_array);
1256 }                                                1256 }
1257                                                  1257 
1258 template <class TYPE>                            1258 template <class TYPE>
1259 inline bool read_sub_vlen(hid_t a_loc,const s    1259 inline bool read_sub_vlen(hid_t a_loc,const std::string& a_name,unsigned int a_offset,
1260                           unsigned int& a_siz    1260                           unsigned int& a_size,TYPE*& a_array) {
1261   return read_sub_vlen<TYPE>(a_loc,a_name,to_    1261   return read_sub_vlen<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_offset,a_size,a_array);
1262 }                                                1262 }
1263                                                  1263 
1264 inline bool read_bool(hid_t a_loc,const std::    1264 inline bool read_bool(hid_t a_loc,const std::string& a_name,bool& aValue) {
1265   unsigned char value = 0;                       1265   unsigned char value = 0;
1266   if(!read_scalar<unsigned char>(a_loc,a_name    1266   if(!read_scalar<unsigned char>(a_loc,a_name,H5T_NATIVE_UCHAR,value)) {
1267     aValue = false;                              1267     aValue = false;
1268     return false;                                1268     return false;
1269   }                                              1269   }
1270   if((value!=0) && (value!=1)) {                 1270   if((value!=0) && (value!=1)) {
1271     aValue = false;                              1271     aValue = false;
1272     return false;                                1272     return false;
1273   }                                              1273   }
1274   aValue = (value==1?true:false);                1274   aValue = (value==1?true:false);
1275   return true;                                   1275   return true;
1276 }                                                1276 }
1277                                                  1277 
1278 }}                                               1278 }}
1279                                                  1279 
1280 #include "atb"                                   1280 #include "atb"
1281                                                  1281 
1282 namespace toolx {                                1282 namespace toolx {
1283 namespace hdf5 {                                 1283 namespace hdf5 {
1284                                                  1284 
1285 template <class TYPE>                            1285 template <class TYPE>
1286 inline bool write_scalar_atb(hid_t aDS,const     1286 inline bool write_scalar_atb(hid_t aDS,const std::string& a_name,const TYPE& aData) {
1287   int has_attr = H5LT_find_attribute(aDS,a_na    1287   int has_attr = H5LT_find_attribute(aDS,a_name.c_str());
1288   if(has_attr==1)  {                             1288   if(has_attr==1)  {
1289     if(H5Adelete(aDS,a_name.c_str())<0) retur    1289     if(H5Adelete(aDS,a_name.c_str())<0) return false;
1290   }                                              1290   }
1291                                                  1291 
1292   hid_t scalar = ::H5Screate(H5S_SCALAR);        1292   hid_t scalar = ::H5Screate(H5S_SCALAR);
1293   if(scalar<0) return false;                     1293   if(scalar<0) return false;
1294                                                  1294 
1295   hid_t aid = toolx_H5Acreate(aDS,a_name.c_st    1295   hid_t aid = toolx_H5Acreate(aDS,a_name.c_str(),to_T_file_type(TYPE()),scalar,H5P_DEFAULT);
1296   if(aid<0) {                                    1296   if(aid<0) {
1297     ::H5Sclose(scalar);                          1297     ::H5Sclose(scalar);
1298     return false;                                1298     return false;
1299   }                                              1299   }
1300                                                  1300 
1301   if(H5Awrite(aid,to_T_mem_type(TYPE()),&aDat    1301   if(H5Awrite(aid,to_T_mem_type(TYPE()),&aData)<0) {
1302     ::H5Sclose(scalar);                          1302     ::H5Sclose(scalar);
1303     ::H5Aclose(aid);                             1303     ::H5Aclose(aid);
1304     return false;                                1304     return false;
1305   }                                              1305   }
1306                                                  1306 
1307   ::H5Sclose(scalar);                            1307   ::H5Sclose(scalar);
1308   ::H5Aclose(aid);                               1308   ::H5Aclose(aid);
1309                                                  1309 
1310   return true;                                   1310   return true;
1311 }                                                1311 }
1312                                                  1312 
1313 }}                                               1313 }}
1314                                                  1314 
1315 /*                                               1315 /*
1316 #include <tools/buf2lines>                       1316 #include <tools/buf2lines>
1317                                                  1317 
1318 namespace toolx {                                1318 namespace toolx {
1319 namespace hdf5 {                                 1319 namespace hdf5 {
1320                                                  1320 
1321 inline bool write_strings(hid_t a_loc,const s    1321 inline bool write_strings(hid_t a_loc,const std::string& a_name,
1322                           size_t a_number,con    1322                           size_t a_number,const char** a_strings,
1323                           unsigned int a_chun    1323                           unsigned int a_chunked = 0,unsigned int a_compress = 0) {
1324   size_t sz;char* buffer;                        1324   size_t sz;char* buffer;
1325   if(!tools::strings2buf(a_number,a_strings,s    1325   if(!tools::strings2buf(a_number,a_strings,sz,buffer)) return false;
1326   sz--;                                          1326   sz--;
1327   bool status = hdf5::write_array<char>(a_loc    1327   bool status = hdf5::write_array<char>(a_loc,a_name,to_T_file_type(char()),to_T_mem_type(char()),
1328                                         a_chu    1328                                         a_chunked,a_compress,(unsigned int)sz,buffer);
1329   delete [] buffer;                              1329   delete [] buffer;
1330   return status;                                 1330   return status;
1331 }                                                1331 }
1332                                                  1332 
1333 inline bool write_strings(hid_t a_loc,const s    1333 inline bool write_strings(hid_t a_loc,const std::string& a_name,
1334                           const std::vector<s    1334                           const std::vector<std::string>& a_strings,
1335                           unsigned int a_chun    1335                           unsigned int a_chunked = 0,unsigned int a_compress = 0) {
1336   size_t sz;char* buffer;                        1336   size_t sz;char* buffer;
1337   if(!tools::strings2buf(a_strings,sz,buffer)    1337   if(!tools::strings2buf(a_strings,sz,buffer)) return false;
1338   sz--;                                          1338   sz--;
1339   bool status = hdf5::write_array<char>(a_loc    1339   bool status = hdf5::write_array<char>(a_loc,a_name,to_T_file_type(char()),to_T_mem_type(char()),
1340                                         a_chu    1340                                         a_chunked,a_compress,(unsigned int)sz,buffer);
1341   delete [] buffer;                              1341   delete [] buffer;
1342   return status;                                 1342   return status;
1343 }                                                1343 }
1344                                                  1344 
1345 inline bool write_append_strings(hid_t a_loc,    1345 inline bool write_append_strings(hid_t a_loc,const std::string& a_name,size_t a_number,const char** a_strings) {
1346   size_t sz;char* buffer;                        1346   size_t sz;char* buffer;
1347   if(!tools::strings2buf(a_number,a_strings,s    1347   if(!tools::strings2buf(a_number,a_strings,sz,buffer)) return false;
1348   sz--;                                          1348   sz--;
1349   bool status = hdf5::write_append_array<char    1349   bool status = hdf5::write_append_array<char>(a_loc,a_name,to_T_file_type(char()),to_T_mem_type(char()),(unsigned int)sz,buffer);
1350   delete [] buffer;                              1350   delete [] buffer;
1351   return status;                                 1351   return status;
1352 }                                                1352 }
1353                                                  1353 
1354 inline bool write_append_strings(hid_t a_loc,    1354 inline bool write_append_strings(hid_t a_loc,const std::string& a_name,const std::vector<std::string>& a_strings) {
1355   size_t sz;char* buffer;                        1355   size_t sz;char* buffer;
1356   if(!tools::strings2buf(a_strings,sz,buffer)    1356   if(!tools::strings2buf(a_strings,sz,buffer)) return false;
1357   sz--;                                          1357   sz--;
1358   bool status = hdf5::write_append_array<char    1358   bool status = hdf5::write_append_array<char>(a_loc,a_name,to_T_file_type(char()),to_T_mem_type(char()),(unsigned int)sz,buffer);
1359   delete [] buffer;                              1359   delete [] buffer;
1360   return status;                                 1360   return status;
1361 }                                                1361 }
1362                                                  1362 
1363 }}                                               1363 }}
1364 */                                               1364 */
1365                                                  1365 
1366 #endif                                           1366 #endif