Field3D
Hdf5Util.cpp
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------//
00002 
00003 /*
00004  * Copyright (c) 2009 Sony Pictures Imageworks Inc
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * Redistributions of source code must retain the above copyright
00013  * notice, this list of conditions and the following disclaimer.
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the
00017  * distribution.  Neither the name of Sony Pictures Imageworks nor the
00018  * names of its contributors may be used to endorse or promote
00019  * products derived from this software without specific prior written
00020  * permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00031  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00033  * OF THE POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 //----------------------------------------------------------------------------//
00037 
00044 //----------------------------------------------------------------------------//
00045 
00046 #include "Hdf5Util.h"
00047 
00048 #include <iostream>
00049 #include <vector>
00050 
00051 //----------------------------------------------------------------------------//
00052 
00053 using namespace std;
00054 
00055 //----------------------------------------------------------------------------//
00056 
00057 FIELD3D_NAMESPACE_OPEN
00058 
00059 using namespace Exc;
00060 
00061 namespace Hdf5Util {
00062 
00063 //----------------------------------------------------------------------------//
00064 // Implementations
00065 //----------------------------------------------------------------------------//
00066 
00067 bool 
00068 readAttribute(hid_t location, const string& attrName, string& value)
00069 {
00070   H5T_class_t typeClass;
00071   H5A_info_t attrInfo;
00072   hsize_t strLen;
00073 
00074   if (H5Aexists(location, attrName.c_str()) < 1)
00075     throw MissingAttributeException("Couldn't find attribute " + attrName);
00076 
00077   H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
00078   H5ScopedAget_space attrSpace(attr);
00079   H5ScopedAget_type attrType(attr);
00080 
00081   if (H5Aget_info(attr, &attrInfo) < 0) {
00082     throw MissingAttributeException("Couldn't get attribute info " + attrName);
00083   } else {
00084     strLen = attrInfo.data_size;
00085   }
00086 
00087   typeClass = H5Tget_class(attrType);
00088 
00089   if (typeClass != H5T_STRING)
00090     throw MissingAttributeException("Bad attribute type class for " + attrName);
00091 
00092   H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
00093 
00094   std::vector<char> tempString(strLen + 1);
00095 
00096   if (H5Aread(attr, nativeType, &tempString[0]) < 0) 
00097     throw MissingAttributeException("Couldn't read attribute " + attrName);
00098 
00099   value = string(&tempString[0]);
00100 
00101   return true;
00102 
00103 }
00104 
00105 //----------------------------------------------------------------------------//
00106 
00107 bool 
00108 readAttribute(hid_t location, const string& attrName, 
00109               unsigned int attrSize, int &value)
00110 {
00111   H5T_class_t typeClass;
00112 
00113   if (H5Aexists(location, attrName.c_str()) < 1)
00114     throw MissingAttributeException("Couldn't find attribute " + attrName);
00115 
00116   H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
00117   H5ScopedAget_space attrSpace(attr);
00118   H5ScopedAget_type attrType(attr);
00119 
00120   if (H5Sget_simple_extent_ndims(attrSpace) != 1) 
00121     throw MissingAttributeException("Bad attribute rank for attribute " + 
00122                                     attrName);
00123 
00124   hsize_t dims[1];
00125   H5Sget_simple_extent_dims(attrSpace, dims, NULL);
00126 
00127   if (dims[0] != attrSize) 
00128     throw MissingAttributeException("Invalid attribute size for attribute " + 
00129                                     attrName);
00130 
00131   typeClass = H5Tget_class(attrType);
00132 
00133   if (typeClass != H5T_INTEGER) 
00134     throw MissingAttributeException("Bad attribute type class for " + 
00135                                     attrName);
00136 
00137   H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
00138 
00139   if (H5Aread(attr, nativeType, &value) < 0) 
00140     throw MissingAttributeException("Couldn't read attribute " + attrName);
00141 
00142   return true;
00143 
00144 }
00145 
00146 //----------------------------------------------------------------------------//
00147 
00148 bool 
00149 readAttribute(hid_t location, const string& attrName, 
00150              unsigned int attrSize, float &value)
00151 {
00152   H5T_class_t typeClass;
00153 
00154   if (H5Aexists(location, attrName.c_str()) < 1)
00155     throw MissingAttributeException("Couldn't find attribute " + attrName);
00156 
00157   H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
00158   H5ScopedAget_space attrSpace(attr);
00159   H5ScopedAget_type attrType(attr);
00160 
00161   if (H5Sget_simple_extent_ndims(attrSpace) != 1) 
00162     throw MissingAttributeException("Bad attribute rank for attribute " + 
00163                                     attrName);
00164 
00165   hsize_t dims[1];
00166   H5Sget_simple_extent_dims(attrSpace, dims, NULL);
00167 
00168   if (dims[0] != attrSize) 
00169     throw MissingAttributeException("Invalid attribute size for attribute " + 
00170                                     attrName);
00171 
00172   typeClass = H5Tget_class(attrType);
00173 
00174   if (typeClass != H5T_FLOAT)
00175     throw MissingAttributeException("Bad attribute type class for " + 
00176                                     attrName);
00177 
00178   H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
00179 
00180   if (H5Aread(attr, nativeType, &value) < 0) 
00181     throw MissingAttributeException("Couldn't read attribute " + attrName);
00182 
00183   return true;
00184 }
00185 
00186 //----------------------------------------------------------------------------//
00187 
00188 bool 
00189 readAttribute(hid_t location, const string& attrName, 
00190              unsigned int attrSize, double &value)
00191 {
00192   H5T_class_t typeClass;
00193 
00194   if (H5Aexists(location, attrName.c_str()) < 0)
00195     throw MissingAttributeException("Couldn't find attribute " + attrName);
00196 
00197   H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
00198   H5ScopedAget_space attrSpace(attr);
00199   H5ScopedAget_type attrType(attr);
00200 
00201   if (H5Sget_simple_extent_ndims(attrSpace) != 1) 
00202     throw MissingAttributeException("Bad attribute rank for attribute " + 
00203                                     attrName);
00204 
00205   hsize_t dims[1];
00206   H5Sget_simple_extent_dims(attrSpace, dims, NULL);
00207 
00208   if (dims[0] != attrSize) 
00209     throw MissingAttributeException("Invalid attribute size for attribute " + 
00210                                     attrName);
00211 
00212   typeClass = H5Tget_class(attrType);
00213 
00214   if (typeClass != H5T_FLOAT)
00215     throw MissingAttributeException("Bad attribute type class for " + 
00216                                     attrName);
00217 
00218   H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
00219 
00220   if (H5Aread(attr, nativeType, &value) < 0) 
00221     throw MissingAttributeException("Couldn't read attribute " + attrName);
00222 
00223   return true;
00224 }
00225 
00226 //----------------------------------------------------------------------------//
00227 
00228 bool 
00229 readAttribute(hid_t location, const string& attrName, 
00230               std::vector<unsigned int> &attrSize, int &value)
00231 {
00232   H5T_class_t typeClass;
00233   int rank = attrSize.size();
00234 
00235   if (H5Aexists(location, attrName.c_str()) < 0)
00236     throw MissingAttributeException("Couldn't find attribute " + attrName);
00237 
00238   H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
00239   H5ScopedAget_space attrSpace(attr);
00240   H5ScopedAget_type attrType(attr);
00241 
00242 
00243   if (H5Sget_simple_extent_ndims(attrSpace) != rank) 
00244     throw MissingAttributeException("Bad attribute rank for attribute " + 
00245                                     attrName);
00246 
00247   hsize_t dims[rank];
00248   H5Sget_simple_extent_dims(attrSpace, dims, NULL);
00249 
00250   for (int i=0; i < rank; i++) {
00251     if (dims[i] != attrSize[i]) 
00252       throw MissingAttributeException("Invalid attribute size for attribute " + 
00253                                       attrName);
00254   }
00255   
00256   typeClass = H5Tget_class(attrType);
00257 
00258   if (typeClass != H5T_INTEGER) 
00259     throw MissingAttributeException("Bad attribute type class for " + 
00260                                     attrName);
00261 
00262   H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
00263 
00264   if (H5Aread(attr, nativeType, &value) < 0) 
00265     throw MissingAttributeException("Couldn't read attribute " + attrName);
00266 
00267   return true;
00268 }
00269   
00270 //----------------------------------------------------------------------------//
00271 
00272 bool 
00273 readAttribute(hid_t location, const string& attrName, 
00274               std::vector<unsigned int> &attrSize, float &value)
00275 {
00276   H5T_class_t typeClass;
00277   int rank = attrSize.size();
00278 
00279   if (H5Aexists(location, attrName.c_str()) < 0)
00280     throw MissingAttributeException("Couldn't find attribute " + attrName);
00281 
00282   H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
00283   H5ScopedAget_space attrSpace(attr);
00284   H5ScopedAget_type attrType(attr);
00285 
00286 
00287   if (H5Sget_simple_extent_ndims(attrSpace) != rank) 
00288     throw MissingAttributeException("Bad attribute rank for attribute " + 
00289                                     attrName);
00290 
00291   hsize_t dims[rank];
00292   H5Sget_simple_extent_dims(attrSpace, dims, NULL);
00293 
00294   for (int i=0; i < rank; i++) {
00295     if (dims[i] != attrSize[i]) 
00296       throw MissingAttributeException("Invalid attribute size for attribute " + 
00297                                       attrName);
00298   }
00299   
00300   typeClass = H5Tget_class(attrType);
00301 
00302   if (typeClass != H5T_FLOAT)
00303     throw MissingAttributeException("Bad attribute type class for " + 
00304                                     attrName);
00305 
00306   H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
00307 
00308   if (H5Aread(attr, nativeType, &value) < 0) 
00309     throw MissingAttributeException("Couldn't read attribute " + attrName);
00310 
00311   return true;
00312 }
00313   
00314 //----------------------------------------------------------------------------//
00315 
00316 bool 
00317 readAttribute(hid_t location, const string& attrName, 
00318               std::vector<unsigned int> &attrSize, double &value)
00319 {
00320 
00321   H5T_class_t typeClass;
00322   int rank = attrSize.size();
00323 
00324   if (H5Aexists(location, attrName.c_str()) < 0)
00325     throw MissingAttributeException("Couldn't find attribute " + attrName);
00326 
00327   H5ScopedAopen attr(location, attrName.c_str(), H5P_DEFAULT);
00328   H5ScopedAget_space attrSpace(attr);
00329   H5ScopedAget_type attrType(attr);
00330 
00331 
00332   if (H5Sget_simple_extent_ndims(attrSpace) != rank) 
00333     throw MissingAttributeException("Bad attribute rank for attribute " + 
00334                                     attrName);
00335 
00336   hsize_t dims[rank];
00337   H5Sget_simple_extent_dims(attrSpace, dims, NULL);
00338 
00339   for (int i=0; i < rank; i++) {
00340     if (dims[i] != attrSize[i]) 
00341       throw MissingAttributeException("Invalid attribute size for attribute " + 
00342                                       attrName);
00343   }
00344   
00345   typeClass = H5Tget_class(attrType);
00346 
00347   if (typeClass != H5T_FLOAT)
00348     throw MissingAttributeException("Bad attribute type class for " + 
00349                                     attrName);
00350 
00351   H5ScopedTget_native_type nativeType(attrType, H5T_DIR_ASCEND);
00352 
00353   if (H5Aread(attr, nativeType, &value) < 0) 
00354     throw MissingAttributeException("Couldn't read attribute " + attrName);
00355 
00356   return true;
00357 }
00358 
00359 //----------------------------------------------------------------------------//
00360 
00361 bool 
00362 writeAttribute(hid_t location, const string& attrName, const string &value)
00363 {
00364   hid_t attr = -1;
00365   hid_t attrSpace;
00366   hid_t attrType;
00367 
00368   bool success = true;
00369 
00370   attrSpace = H5Screate(H5S_SCALAR);
00371   if (attrSpace == -1)
00372     success = false;
00373 
00374   attrType = H5Tcopy(H5T_C_S1);
00375   if (attrType == -1)
00376     success = false;
00377 
00378   if (value.size()) {
00379     // if the string is null the following will return error
00380     // which we don't want.
00381     if (success && H5Tset_size(attrType, value.size()) == -1){    
00382       success = false;
00383     }
00384   }
00385 
00386   if (success) {
00387     H5Tset_strpad(attrType, H5T_STR_NULLTERM);
00388     attr = H5Acreate(location, attrName.c_str(), attrType, attrSpace, 
00389                      H5P_DEFAULT, H5P_DEFAULT);
00390   }
00391 
00392   if (attr == -1) {
00393     Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
00394     success = false;
00395   }
00396 
00397   if (success && H5Awrite(attr, attrType, value.c_str()) == -1) {
00398     Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
00399     success = false;
00400   }
00401 
00402   H5Aclose(attr);
00403   H5Tclose(attrType);
00404   H5Sclose(attrSpace);
00405 
00406   return success;
00407 
00408 }
00409 
00410 //----------------------------------------------------------------------------//
00411 
00412 bool 
00413 writeAttribute(hid_t location, const string &attrName, 
00414              unsigned int attrSize, const int &value)
00415 {
00416   hid_t attr;
00417   hid_t attrSpace;
00418   hsize_t dims[1];
00419 
00420   dims[0] = attrSize;
00421 
00422   attrSpace = H5Screate(H5S_SIMPLE);
00423   if (attrSpace < 0) 
00424     return false;
00425 
00426   if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
00427     return false;
00428 
00429   attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT, 
00430                    attrSpace, H5P_DEFAULT, H5P_DEFAULT);
00431   if (attr < 0) {
00432     Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
00433     H5Aclose(attr);
00434     H5Sclose(attrSpace);
00435     return false;
00436   }
00437 
00438   if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
00439     Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
00440     H5Aclose(attr);
00441     H5Sclose(attrSpace);
00442     return false;
00443   }
00444 
00445   H5Aclose(attr);
00446   H5Sclose(attrSpace);
00447 
00448   return true;
00449 }
00450 
00451 //----------------------------------------------------------------------------//
00452 
00453 bool 
00454 writeAttribute(hid_t location, const string& attrName, 
00455              unsigned int attrSize, const float &value)
00456 {
00457   hid_t attr;
00458   hid_t attrSpace;
00459   hsize_t dims[1];
00460 
00461   dims[0] = attrSize;
00462 
00463   attrSpace = H5Screate(H5S_SIMPLE);
00464   if (attrSpace < 0) 
00465     return false;
00466 
00467   if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
00468     return false;
00469 
00470   attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT, 
00471                    attrSpace, H5P_DEFAULT, H5P_DEFAULT);
00472   if (attr < 0) {
00473     Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
00474     H5Aclose(attr);
00475     H5Sclose(attrSpace);
00476     return false;
00477   }
00478 
00479   if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
00480     Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
00481     H5Aclose(attr);
00482     H5Sclose(attrSpace);
00483     return false;
00484   }
00485 
00486   H5Aclose(attr);
00487   H5Sclose(attrSpace);
00488 
00489   return true;
00490 }
00491 
00492 //----------------------------------------------------------------------------//
00493 
00494 bool 
00495 writeAttribute(hid_t location, const string& attrName, 
00496              unsigned int attrSize, const double &value)
00497 {
00498   hid_t attr;
00499   hid_t attrSpace;
00500   hsize_t dims[1];
00501 
00502   dims[0] = attrSize;
00503 
00504   attrSpace = H5Screate(H5S_SIMPLE);
00505   if (attrSpace < 0) 
00506     return false;
00507 
00508   if (H5Sset_extent_simple(attrSpace, 1, dims, NULL) < 0)
00509     return false;
00510 
00511   attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE, 
00512                    attrSpace, H5P_DEFAULT, H5P_DEFAULT);
00513   if (attr < 0) {
00514     Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
00515     H5Aclose(attr);
00516     H5Sclose(attrSpace);
00517     return false;
00518   }
00519 
00520   if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
00521     Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
00522     H5Aclose(attr);
00523     H5Sclose(attrSpace);
00524     return false;
00525   }
00526 
00527   H5Aclose(attr);
00528   H5Sclose(attrSpace);
00529 
00530   return true;
00531 }
00532 
00533 
00534 //----------------------------------------------------------------------------//  
00535 
00536 bool 
00537 writeAttribute(hid_t location, const string& attrName,
00538                std::vector<unsigned int> &attrSize, const int &value)
00539 {
00540   hid_t attr;
00541   hid_t attrSpace;
00542   size_t rank = attrSize.size();
00543   hsize_t current_dims[rank];
00544   hsize_t max_dims[rank];
00545 
00546   for (size_t i=0; i < rank; i++)
00547     current_dims[i] = attrSize[i];
00548   
00549   for (size_t i=0; i < rank; i++)
00550     max_dims[i] = H5S_UNLIMITED;
00551 
00552   attrSpace = H5Screate(H5S_SIMPLE);
00553   if (attrSpace < 0) 
00554     return false;
00555 
00556   if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
00557     return false;
00558   }
00559 
00560   attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_INT, 
00561                    attrSpace, H5P_DEFAULT, H5P_DEFAULT);
00562   if (attr < 0) {
00563     Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
00564     H5Aclose(attr);
00565     H5Sclose(attrSpace);
00566     return false;
00567   }
00568 
00569   if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) {
00570     Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
00571     H5Aclose(attr);
00572     H5Sclose(attrSpace);
00573     return false;
00574   }
00575 
00576   H5Aclose(attr);
00577   H5Sclose(attrSpace);
00578 
00579   return true;
00580 }
00581   
00582 //----------------------------------------------------------------------------//  
00583 
00584 bool 
00585 writeAttribute(hid_t location, const string& attrName,
00586                std::vector<unsigned int> &attrSize, const float &value)
00587 {
00588   hid_t attr;
00589   hid_t attrSpace;
00590   size_t rank = attrSize.size();
00591   hsize_t current_dims[rank];
00592   hsize_t max_dims[rank];
00593 
00594   for (size_t i=0; i < rank; i++)
00595     current_dims[i] = attrSize[i];
00596   
00597   for (size_t i=0; i < rank; i++)
00598     max_dims[i] = H5S_UNLIMITED;
00599 
00600   attrSpace = H5Screate(H5S_SIMPLE);
00601   if (attrSpace < 0) 
00602     return false;
00603 
00604   if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
00605     return false;
00606   }
00607 
00608   attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_FLOAT, 
00609                    attrSpace, H5P_DEFAULT, H5P_DEFAULT);
00610   if (attr < 0) {
00611     Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
00612     H5Aclose(attr);
00613     H5Sclose(attrSpace);
00614     return false;
00615   }
00616 
00617   if (H5Awrite(attr, H5T_NATIVE_FLOAT, &value) < 0) {
00618     Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
00619     H5Aclose(attr);
00620     H5Sclose(attrSpace);
00621     return false;
00622   }
00623 
00624   H5Aclose(attr);
00625   H5Sclose(attrSpace);
00626 
00627   return true;
00628 }
00629   
00630 //----------------------------------------------------------------------------//  
00631 
00632 bool 
00633 writeAttribute(hid_t location, const string& attrName,
00634                std::vector<unsigned int> &attrSize, const double &value)
00635 {
00636   hid_t attr;
00637   hid_t attrSpace;
00638   size_t rank = attrSize.size();
00639   hsize_t current_dims[rank];
00640   hsize_t max_dims[rank];
00641 
00642   for (size_t i=0; i < rank; i++)
00643     current_dims[i] = attrSize[i];
00644   
00645   for (size_t i=0; i < rank; i++)
00646     max_dims[i] = H5S_UNLIMITED;
00647 
00648   attrSpace = H5Screate(H5S_SIMPLE);
00649   if (attrSpace < 0) 
00650     return false;
00651 
00652   if (H5Sset_extent_simple(attrSpace, rank, current_dims, max_dims) < 0) {
00653     return false;
00654   }
00655 
00656   attr = H5Acreate(location, attrName.c_str(), H5T_NATIVE_DOUBLE, 
00657                    attrSpace, H5P_DEFAULT, H5P_DEFAULT);
00658   if (attr < 0) {
00659     Msg::print(Msg::SevWarning, "Error creating attribute: " + attrName);
00660     H5Aclose(attr);
00661     H5Sclose(attrSpace);
00662     return false;
00663   }
00664 
00665   if (H5Awrite(attr, H5T_NATIVE_DOUBLE, &value) < 0) {
00666     Msg::print(Msg::SevWarning, "Error writing attribute: " + attrName);
00667     H5Aclose(attr);
00668     H5Sclose(attrSpace);
00669     return false;
00670   }
00671 
00672   H5Aclose(attr);
00673   H5Sclose(attrSpace);
00674 
00675   return true;
00676 }
00677 
00678 //----------------------------------------------------------------------------//
00679 
00680 bool checkHdf5Gzip()
00681 {
00682   htri_t avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
00683   if (!avail)
00684     return false;
00685 
00686   unsigned int filter_info;
00687   herr_t status = H5Zget_filter_info (H5Z_FILTER_DEFLATE, &filter_info);
00688 
00689   if (status < 0)
00690     return false;
00691 
00692   if (!(filter_info & H5Z_FILTER_CONFIG_ENCODE_ENABLED) ||
00693       !(filter_info & H5Z_FILTER_CONFIG_DECODE_ENABLED)) {
00694     return false;
00695   }
00696 
00697   return true;
00698 }
00699 
00700 //----------------------------------------------------------------------------//
00701 
00702 } // namespace Hdf5Util
00703 
00704 //----------------------------------------------------------------------------//
00705 
00706 FIELD3D_NAMESPACE_SOURCE_CLOSE
00707 
00708 //----------------------------------------------------------------------------//