[Commits] [svn:einsteintoolkit] Multipole/trunk/src/ (Rev. 87)

ian.hinder at aei.mpg.de ian.hinder at aei.mpg.de
Wed Nov 21 10:12:15 CST 2012


User: hinder
Date: 2012/11/21 10:12 AM

Modified:
 /trunk/src/
  utils.cc

Log:
 utils.cc: Add error checking to HDF5 calls

File Changes:

Directory: /trunk/src/
======================

File [modified]: utils.cc
Delta lines: +28 -13
===================================================================
--- trunk/src/utils.cc	2012-11-21 16:12:07 UTC (rev 86)
+++ trunk/src/utils.cc	2012-11-21 16:12:15 UTC (rev 87)
@@ -25,6 +25,22 @@
 #include "utils.hh"
 #include "integrate.hh"
 
+// check return code of HDF5 call abort with an error message if there was an error.
+// adapted from CarpetIOHDF5/src/CarpetIOHDF5.hh.
+#define HDF5_ERROR(fn_call)                                                   \
+        do {                                                                  \
+          int _error_code = fn_call;                                          \
+                                                                              \
+                                                                              \
+          if (_error_code < 0)                                                \
+          {                                                                   \
+            CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,              \
+                        "HDF5 call '%s' returned error code %d",              \
+                        #fn_call, _error_code);                               \
+          }                                                                   \
+        } while (0)
+
+
 using namespace std;
 
 ////////////////////////////////////////////////////////////////////////
@@ -188,7 +204,6 @@
   DECLARE_CCTK_PARAMETERS;
 
   string output_name = out_dir + string("/") + basename;
-  int status = 0;
   static map<string,bool> checked; // Has the given file been checked
                                    // for truncation? map<*,bool>
                                    // defaults to false
@@ -221,7 +236,7 @@
     hid_t cparms = -1;
     hsize_t chunk_dims[2] = {hdf5_chunk_size,3};
     cparms = H5Pcreate (H5P_DATASET_CREATE);
-    status = H5Pset_chunk(cparms, 2, chunk_dims);
+    HDF5_ERROR(H5Pset_chunk(cparms, 2, chunk_dims));
 
     dataset = H5Dcreate(file, datasetname.c_str(), H5T_NATIVE_DOUBLE, dataspace, cparms);
     H5Pclose(cparms);
@@ -230,33 +245,33 @@
   hid_t filespace = H5Dget_space (dataset);
   hsize_t filedims[2];
   hsize_t maxdims[2];
-  status = H5Sget_simple_extent_dims(filespace, filedims, maxdims);
+  HDF5_ERROR(H5Sget_simple_extent_dims(filespace, filedims, maxdims));
 
   filedims[0] += 1;
   hsize_t size[2] = {filedims[0], filedims[1]};
-  status = H5Dextend (dataset, size);
-  H5Sclose(filespace);
+  HDF5_ERROR(H5Dextend (dataset, size));
+  HDF5_ERROR(H5Sclose(filespace));
 
   /* Select a hyperslab  */
   hsize_t offset[2] = {filedims[0]-1, 0};
   hsize_t dims2[2] = {1,3};
   filespace = H5Dget_space (dataset);
-  status = H5Sselect_hyperslab (filespace, H5S_SELECT_SET, offset, NULL,
-                                dims2, NULL);
+  HDF5_ERROR(H5Sselect_hyperslab (filespace, H5S_SELECT_SET, offset, NULL,
+                                  dims2, NULL));
 
   CCTK_REAL data[] = {cctk_time, redata, imdata};
 
   hid_t memdataspace = H5Screate_simple(2, dims2, NULL);
 
   /* Write the data to the hyperslab  */
-  status = H5Dwrite (dataset, H5T_NATIVE_DOUBLE, memdataspace, filespace,
-                     H5P_DEFAULT, data);
+  HDF5_ERROR(H5Dwrite (dataset, H5T_NATIVE_DOUBLE, memdataspace, filespace,
+                       H5P_DEFAULT, data));
 
-  H5Dclose(dataset);
-  H5Sclose(filespace);
-  H5Sclose(memdataspace);
+  HDF5_ERROR(H5Dclose(dataset));
+  HDF5_ERROR(H5Sclose(filespace));
+  HDF5_ERROR(H5Sclose(memdataspace));
 
-  status = H5Fclose(file);
+  HDF5_ERROR(H5Fclose(file));
 }
 
 #else



More information about the Commits mailing list