Field3D
Hdf5Util.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------//
2 
3 /*
4  * Copyright (c) 2009 Sony Pictures Imageworks Inc
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution. Neither the name of Sony Pictures Imageworks nor the
18  * names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior written
20  * permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 //----------------------------------------------------------------------------//
37 
44 //----------------------------------------------------------------------------//
45 
46 #include "Hdf5Util.h"
47 
48 #include <iostream>
49 #include <vector>
50 #include <boost/scoped_array.hpp>
51 
52 
53 //----------------------------------------------------------------------------//
54 
55 using namespace std;
56 
57 //----------------------------------------------------------------------------//
58 
60 
61 using namespace Exc;
62 
63 //----------------------------------------------------------------------------//
64 // Implementations
65 //----------------------------------------------------------------------------//
66 
67 boost::recursive_mutex g_hdf5Mutex;
68 
69 //----------------------------------------------------------------------------//
70 
71 namespace Hdf5Util {
72 
73 //----------------------------------------------------------------------------//
74 // Implementations
75 //----------------------------------------------------------------------------//
76 
77 bool
78 readAttribute(hid_t location, const string& attrName, string& value)
79 {
80  GlobalLock lock(g_hdf5Mutex);
81 
82  H5T_class_t typeClass;
83  H5A_info_t attrInfo;
84  hsize_t strLen;
85 
86  if (H5Aexists(location, attrName.c_str()) < 1)
87  throw MissingAttributeException("Couldn't find attribute " + attrName);
88 
89  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
90  H5ScopedAget_space attrSpace(attr);
91  H5ScopedAget_type attrType(attr);
92 
93  if (H5Aget_info(attr, &attrInfo) < 0) {
94  throw MissingAttributeException("Couldn't get attribute info " + attrName);
95  } else {
96  strLen = attrInfo.data_size;
97  }
98 
99  typeClass = H5Tget_class(attrType);
100 
101  if (typeClass != H5T_STRING)
102  throw MissingAttributeException("Bad attribute type class for " + attrName);
103 
104  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
105 
106  std::vector<char> tempString(strLen + 1);
107 
108  if (H5Aread(attr, nativeType, &tempString[0]) < 0)
109  throw MissingAttributeException("Couldn't read attribute " + attrName);
110 
111  value = string(&tempString[0]);
112 
113  return true;
114 
115 }
116 
117 //----------------------------------------------------------------------------//
118 
119 bool
120 readAttribute(hid_t location, const string& attrName,
121  unsigned int attrSize, int &value)
122 {
123  GlobalLock lock(g_hdf5Mutex);
124 
125  H5T_class_t typeClass;
126 
127  if (H5Aexists(location, attrName.c_str()) < 1)
128  throw MissingAttributeException("Couldn't find attribute " + attrName);
129 
130  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
131  H5ScopedAget_space attrSpace(attr);
132  H5ScopedAget_type attrType(attr);
133 
134  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
135  throw MissingAttributeException("Bad attribute rank for attribute " +
136  attrName);
137 
138  hsize_t dims[1];
139  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
140 
141  if (dims[0] != attrSize)
142  throw MissingAttributeException("Invalid attribute size for attribute " +
143  attrName);
144 
145  typeClass = H5Tget_class(attrType);
146 
147  if (typeClass != H5T_INTEGER)
148  throw MissingAttributeException("Bad attribute type class for " +
149  attrName);
150 
151  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
152 
153  if (H5Aread(attr, nativeType, &value) < 0)
154  throw MissingAttributeException("Couldn't read attribute " + attrName);
155 
156  return true;
157 
158 }
159 
160 //----------------------------------------------------------------------------//
161 
162 bool
163 readAttribute(hid_t location, const string& attrName,
164  unsigned int attrSize, float &value)
165 {
166  GlobalLock lock(g_hdf5Mutex);
167 
168  H5T_class_t typeClass;
169 
170  if (H5Aexists(location, attrName.c_str()) < 1)
171  throw MissingAttributeException("Couldn't find attribute " + attrName);
172 
173  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
174  H5ScopedAget_space attrSpace(attr);
175  H5ScopedAget_type attrType(attr);
176 
177  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
178  throw MissingAttributeException("Bad attribute rank for attribute " +
179  attrName);
180 
181  hsize_t dims[1];
182  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
183 
184  if (dims[0] != attrSize)
185  throw MissingAttributeException("Invalid attribute size for attribute " +
186  attrName);
187 
188  typeClass = H5Tget_class(attrType);
189 
190  if (typeClass != H5T_FLOAT)
191  throw MissingAttributeException("Bad attribute type class for " +
192  attrName);
193 
194  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
195 
196  if (H5Aread(attr, nativeType, &value) < 0)
197  throw MissingAttributeException("Couldn't read attribute " + attrName);
198 
199  return true;
200 }
201 
202 //----------------------------------------------------------------------------//
203 
204 bool
205 readAttribute(hid_t location, const string& attrName,
206  unsigned int attrSize, double &value)
207 {
208  GlobalLock lock(g_hdf5Mutex);
209 
210  H5T_class_t typeClass;
211 
212  if (H5Aexists(location, attrName.c_str()) < 0)
213  throw MissingAttributeException("Couldn't find attribute " + attrName);
214 
215  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
216  H5ScopedAget_space attrSpace(attr);
217  H5ScopedAget_type attrType(attr);
218 
219  if (H5Sget_simple_extent_ndims(attrSpace) != 1)
220  throw MissingAttributeException("Bad attribute rank for attribute " +
221  attrName);
222 
223  hsize_t dims[1];
224  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
225 
226  if (dims[0] != attrSize)
227  throw MissingAttributeException("Invalid attribute size for attribute " +
228  attrName);
229 
230  typeClass = H5Tget_class(attrType);
231 
232  if (typeClass != H5T_FLOAT)
233  throw MissingAttributeException("Bad attribute type class for " +
234  attrName);
235 
236  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
237 
238  if (H5Aread(attr, nativeType, &value) < 0)
239  throw MissingAttributeException("Couldn't read attribute " + attrName);
240 
241  return true;
242 }
243 
244 //----------------------------------------------------------------------------//
245 
246 bool
247 readAttribute(hid_t location, const string& attrName,
248  std::vector<unsigned int> &attrSize, int &value)
249 {
250  GlobalLock lock(g_hdf5Mutex);
251 
252  H5T_class_t typeClass;
253  size_t rank = attrSize.size();
254 
255  if (H5Aexists(location, attrName.c_str()) < 0)
256  throw MissingAttributeException("Couldn't find attribute " + attrName);
257 
258  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
259  H5ScopedAget_space attrSpace(attr);
260  H5ScopedAget_type attrType(attr);
261 
262 
263  if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
264  throw MissingAttributeException("Bad attribute rank for attribute " +
265  attrName);
266 
267  boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
268  H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
269 
270  for (size_t i=0; i < rank; i++) {
271  if (dims[i] != attrSize[i])
272  throw MissingAttributeException("Invalid attribute size for attribute " +
273  attrName);
274  }
275 
276  typeClass = H5Tget_class(attrType);
277 
278  if (typeClass != H5T_INTEGER)
279  throw MissingAttributeException("Bad attribute type class for " +
280  attrName);
281 
282  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
283 
284  if (H5Aread(attr, nativeType, &value) < 0)
285  throw MissingAttributeException("Couldn't read attribute " + attrName);
286 
287  return true;
288 }
289 
290 //----------------------------------------------------------------------------//
291 
292 bool
293 readAttribute(hid_t location, const string& attrName,
294  std::vector<unsigned int> &attrSize, float &value)
295 {
296  GlobalLock lock(g_hdf5Mutex);
297 
298  H5T_class_t typeClass;
299  size_t rank = attrSize.size();
300 
301  if (H5Aexists(location, attrName.c_str()) < 0)
302  throw MissingAttributeException("Couldn't find attribute " + attrName);
303 
304  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
305  H5ScopedAget_space attrSpace(attr);
306  H5ScopedAget_type attrType(attr);
307 
308 
309  if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
310  throw MissingAttributeException("Bad attribute rank for attribute " +
311  attrName);
312 
313  boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
314  H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
315 
316  for (size_t i=0; i < rank; i++) {
317  if (dims[i] != attrSize[i])
318  throw MissingAttributeException("Invalid attribute size for attribute " +
319  attrName);
320  }
321 
322  typeClass = H5Tget_class(attrType);
323 
324  if (typeClass != H5T_FLOAT)
325  throw MissingAttributeException("Bad attribute type class for " +
326  attrName);
327 
328  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
329 
330  if (H5Aread(attr, nativeType, &value) < 0)
331  throw MissingAttributeException("Couldn't read attribute " + attrName);
332 
333  return true;
334 }
335 
336 //----------------------------------------------------------------------------//
337 
338 bool
339 readAttribute(hid_t location, const string& attrName,
340  std::vector<unsigned int> &attrSize, double &value)
341 {
342  GlobalLock lock(g_hdf5Mutex);
343 
344  H5T_class_t typeClass;
345  size_t rank = attrSize.size();
346 
347  if (H5Aexists(location, attrName.c_str()) < 0)
348  throw MissingAttributeException("Couldn't find attribute " + attrName);
349 
350  H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
351  H5ScopedAget_space attrSpace(attr);
352  H5ScopedAget_type attrType(attr);
353 
354 
355  if (H5Sget_simple_extent_ndims(attrSpace) != (int) rank)
356  throw MissingAttributeException("Bad attribute rank for attribute " +
357  attrName);
358 
359  boost::scoped_array<hsize_t> dims(new hsize_t[rank]);
360  H5Sget_simple_extent_dims(attrSpace, dims.get(), NULL);
361 
362  for (size_t i=0; i < rank; i++) {
363  if (dims[i] != attrSize[i])
364  throw MissingAttributeException("Invalid attribute size for attribute " +
365  attrName);
366  }
367 
368  typeClass = H5Tget_class(attrType);
369 
370  if (typeClass != H5T_FLOAT)
371  throw MissingAttributeException("Bad attribute type class for " +
372  attrName);
373 
374  H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
375 
376  if (H5Aread(attr, nativeType, &value) < 0)
377  throw MissingAttributeException("Couldn't read attribute " + attrName);
378 
379  return true;
380 }
381 
382 //----------------------------------------------------------------------------//
383 
384 bool
385 writeAttribute(hid_t location, const string& attrName, const string &value)
386 {
387  GlobalLock lock(g_hdf5Mutex);
388 
389  hid_t attr = -1;
390  hid_t attrSpace;
391  hid_t attrType;
392 
393  bool success = true;
394 
395  attrSpace = H5Screate(H5S_SCALAR);
396  if (attrSpace == -1)
397  success = false;
398 
399  attrType = H5Tcopy(H5T_C_S1);
400  if (attrType == -1)
401  success = false;
402 
403  if (value.size()) {
404  // if the string is null the following will return error
405  // which we don't want.
406  if (success && H5Tset_size(attrType, value.size()) == -1){
407  success = false;
408  }
409  }
410 
411  if (success) {
412  H5Tset_strpad(attrType, H5T_STR_NULLTERM);
413  attr = H5Acreate(location, attrName.c_str(), attrType, attrSpace,
414  H5P_DEFAULT, H5P_DEFAULT);
415  }
416 
417  if (attr == -1) {
418  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
419  success = false;
420  }
421 
422  if (success && H5Awrite(attr, attrType, value.c_str()) == -1) {
423  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
424  success = false;
425  }
426 
427  H5Aclose(attr);
428  H5Tclose(attrType);
429  H5Sclose(attrSpace);
430 
431  return success;
432 
433 }
434 
435 //----------------------------------------------------------------------------//
436 
437 bool
438 writeAttribute(hid_t location, const string &attrName,
439  unsigned int attrSize, const int &value)
440 {
441  GlobalLock lock(g_hdf5Mutex);
442 
443  hid_t attr;
444  hid_t attrSpace;
445  hsize_t dims[1];
446 
447  dims[0] = attrSize;
448 
449  attrSpace = H5Screate(H5S_SIMPLE);
450  if (attrSpace < 0)
451  return false;
452 
453  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
454  return false;
455 
456  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
457  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
458  if (attr < 0) {
459  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
460  H5Aclose(attr);
461  H5Sclose(attrSpace);
462  return false;
463  }
464 
465  if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
466  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
467  H5Aclose(attr);
468  H5Sclose(attrSpace);
469  return false;
470  }
471 
472  H5Aclose(attr);
473  H5Sclose(attrSpace);
474 
475  return true;
476 }
477 
478 //----------------------------------------------------------------------------//
479 
480 bool
481 writeAttribute(hid_t location, const string& attrName,
482  unsigned int attrSize, const float &value)
483 {
484  GlobalLock lock(g_hdf5Mutex);
485 
486  hid_t attr;
487  hid_t attrSpace;
488  hsize_t dims[1];
489 
490  dims[0] = attrSize;
491 
492  attrSpace = H5Screate(H5S_SIMPLE);
493  if (attrSpace < 0)
494  return false;
495 
496  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
497  return false;
498 
499  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
500  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
501  if (attr < 0) {
502  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
503  H5Aclose(attr);
504  H5Sclose(attrSpace);
505  return false;
506  }
507 
508  if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
509  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
510  H5Aclose(attr);
511  H5Sclose(attrSpace);
512  return false;
513  }
514 
515  H5Aclose(attr);
516  H5Sclose(attrSpace);
517 
518  return true;
519 }
520 
521 //----------------------------------------------------------------------------//
522 
523 bool
524 writeAttribute(hid_t location, const string& attrName,
525  unsigned int attrSize, const double &value)
526 {
527  GlobalLock lock(g_hdf5Mutex);
528 
529  hid_t attr;
530  hid_t attrSpace;
531  hsize_t dims[1];
532 
533  dims[0] = attrSize;
534 
535  attrSpace = H5Screate(H5S_SIMPLE);
536  if (attrSpace < 0)
537  return false;
538 
539  if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
540  return false;
541 
542  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
543  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
544  if (attr < 0) {
545  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
546  H5Aclose(attr);
547  H5Sclose(attrSpace);
548  return false;
549  }
550 
551  if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
552  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
553  H5Aclose(attr);
554  H5Sclose(attrSpace);
555  return false;
556  }
557 
558  H5Aclose(attr);
559  H5Sclose(attrSpace);
560 
561  return true;
562 }
563 
564 
565 //----------------------------------------------------------------------------//
566 
567 bool
568 writeAttribute(hid_t location, const string& attrName,
569  std::vector<unsigned int> &attrSize, const int &value)
570 {
571  GlobalLock lock(g_hdf5Mutex);
572 
573  hid_t attr;
574  hid_t attrSpace;
575  size_t rank = attrSize.size();
576 
577  boost::scoped_array<hsize_t> current_dims(new hsize_t[rank]);
578  boost::scoped_array<hsize_t> max_dims(new hsize_t[rank]);
579 
580  for (size_t i=0; i < rank; i++)
581  current_dims[i] = attrSize[i];
582 
583  for (size_t i=0; i < rank; i++)
584  max_dims[i] = H5S_UNLIMITED;
585 
586  attrSpace = H5Screate(H5S_SIMPLE);
587  if (attrSpace < 0)
588  return false;
589 
590  if (H5Sset_extent_simple(attrSpace, (int)rank,
591  current_dims.get(), max_dims.get()) < 0) {
592  return false;
593  }
594 
595  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT,
596  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
597  if (attr < 0) {
598  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
599  H5Aclose(attr);
600  H5Sclose(attrSpace);
601  return false;
602  }
603 
604  if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
605  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
606  H5Aclose(attr);
607  H5Sclose(attrSpace);
608  return false;
609  }
610 
611  H5Aclose(attr);
612  H5Sclose(attrSpace);
613 
614  return true;
615 }
616 
617 //----------------------------------------------------------------------------//
618 
619 bool
620 writeAttribute(hid_t location, const string& attrName,
621  std::vector<unsigned int> &attrSize, const float &value)
622 {
623  GlobalLock lock(g_hdf5Mutex);
624 
625  hid_t attr;
626  hid_t attrSpace;
627  size_t rank = attrSize.size();
628 
629  boost::scoped_array<hsize_t> current_dims(new hsize_t[rank]);
630  boost::scoped_array<hsize_t> max_dims(new hsize_t[rank]);
631 
632  for (size_t i=0; i < rank; i++)
633  current_dims[i] = attrSize[i];
634 
635  for (size_t i=0; i < rank; i++)
636  max_dims[i] = H5S_UNLIMITED;
637 
638  attrSpace = H5Screate(H5S_SIMPLE);
639  if (attrSpace < 0)
640  return false;
641 
642  if (H5Sset_extent_simple(attrSpace, (int)rank,
643  current_dims.get(), max_dims.get()) < 0) {
644  return false;
645  }
646 
647  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT,
648  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
649  if (attr < 0) {
650  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
651  H5Aclose(attr);
652  H5Sclose(attrSpace);
653  return false;
654  }
655 
656  if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
657  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
658  H5Aclose(attr);
659  H5Sclose(attrSpace);
660  return false;
661  }
662 
663  H5Aclose(attr);
664  H5Sclose(attrSpace);
665 
666  return true;
667 }
668 
669 //----------------------------------------------------------------------------//
670 
671 bool
672 writeAttribute(hid_t location, const string& attrName,
673  std::vector<unsigned int> &attrSize, const double &value)
674 {
675  GlobalLock lock(g_hdf5Mutex);
676 
677  hid_t attr;
678  hid_t attrSpace;
679  size_t rank = attrSize.size();
680  boost::scoped_array<hsize_t> current_dims(new hsize_t[rank]);
681  boost::scoped_array<hsize_t> max_dims(new hsize_t[rank]);
682 
683  for (size_t i=0; i < rank; i++)
684  current_dims[i] = attrSize[i];
685 
686  for (size_t i=0; i < rank; i++)
687  max_dims[i] = H5S_UNLIMITED;
688 
689  attrSpace = H5Screate(H5S_SIMPLE);
690  if (attrSpace < 0)
691  return false;
692 
693  if (H5Sset_extent_simple(attrSpace, (int)rank,
694  current_dims.get(), max_dims.get()) < 0) {
695  return false;
696  }
697 
698  attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE,
699  attrSpace, H5P_DEFAULT, H5P_DEFAULT);
700  if (attr < 0) {
701  Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
702  H5Aclose(attr);
703  H5Sclose(attrSpace);
704  return false;
705  }
706 
707  if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
708  Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
709  H5Aclose(attr);
710  H5Sclose(attrSpace);
711  return false;
712  }
713 
714  H5Aclose(attr);
715  H5Sclose(attrSpace);
716 
717  return true;
718 }
719 
720 //----------------------------------------------------------------------------//
721 
723 {
724  GlobalLock lock(g_hdf5Mutex);
725 
726  htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
727  if (!avail)
728  return false;
729 
730  unsigned int filter_info;
731  herr_t status = H5Zget_filter_info (H5Z_FILTER_DEFLATE, &filter_info);
732 
733  if (status < 0)
734  return false;
735 
736  if (!(filter_info & H5Z_FILTER_CONFIG_ENCODE_ENABLED) ||
737  !(filter_info & H5Z_FILTER_CONFIG_DECODE_ENABLED)) {
738  return false;
739  }
740 
741  return true;
742 }
743 
744 //----------------------------------------------------------------------------//
745 
746 } // namespace Hdf5Util
747 
748 //----------------------------------------------------------------------------//
749 
751 
752 //----------------------------------------------------------------------------//
Hdf5Util::H5ScopedTget_native_type
Scoped object - opens an native type id on creation and closes it on destruction.
Definition: Hdf5Util.h:334
Msg::SevWarning
@ SevWarning
Definition: Log.h:68
g_hdf5Mutex
boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
Hdf5Util::readAttribute
bool readAttribute(hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, double &value)
Definition: Hdf5Util.cpp:339
Hdf5Util.h
Contains various utility functions for Hdf5.
Hdf5Util::writeAttribute
bool writeAttribute(hid_t location, const string &attrName, std::vector< unsigned int > &attrSize, const double &value)
Definition: Hdf5Util.cpp:672
Hdf5Util::H5ScopedAget_space
Scoped object - opens an attribute data space on creation and closes it on destruction.
Definition: Hdf5Util.h:288
FIELD3D_NAMESPACE_SOURCE_CLOSE
#define FIELD3D_NAMESPACE_SOURCE_CLOSE
Definition: ns.h:60
Exc
Namespace for Exception objects.
Definition: Exception.h:57
GlobalLock
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
Hdf5Util
Contains utility functions and classes for Hdf5 files.
Definition: Hdf5Util.h:86
Hdf5Util::H5ScopedAopen
Scoped object - Opens attribute by name and closes it on destruction.
Definition: Hdf5Util.h:114
Hdf5Util::checkHdf5Gzip
FIELD3D_API bool checkHdf5Gzip()
Checks whether gzip is available in the current hdf5 library.
Definition: Hdf5Util.cpp:722
FIELD3D_NAMESPACE_OPEN
Definition: FieldMapping.cpp:74
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition: Log.cpp:70
Hdf5Util::H5ScopedAget_type
Scoped object - opens an attribute data type on creation and closes it on destruction.
Definition: Hdf5Util.h:311