[cig-commits] r13718 - cs/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Wed Dec 17 02:32:01 PST 2008


Author: luis
Date: 2008-12-17 02:32:00 -0800 (Wed, 17 Dec 2008)
New Revision: 13718

Modified:
   cs/cigma/trunk/src/io_hdf5.cpp
Log:
Updated read_scalar_attribute<std::string>() so that it works with
fixed length string attributes, as well as variable length string attrs.

Modified: cs/cigma/trunk/src/io_hdf5.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5.cpp	2008-12-17 10:31:58 UTC (rev 13717)
+++ cs/cigma/trunk/src/io_hdf5.cpp	2008-12-17 10:32:00 UTC (rev 13718)
@@ -26,42 +26,79 @@
 
 
 /* specialize read_scalar_attribute for T=std::string */
-/*
 template <>
 int read_scalar_attribute<std::string>(H5::H5File *file, const char *loc, const char *attr_name, std::string& val)
 {
+    TRI_LOG_STR("read_scalar_attribute<std::string>()");
+    TRI_LOG(loc);
+    TRI_LOG(attr_name);
+
     H5::H5Object* obj = 0;
     H5::Attribute* attr = 0;
 
-    if (file)
+    if (file == 0)
     {
-        try
+        return -1;
+    }
+    try
+    {
+        obj = h5_open_object(file, loc);
+
+        if (obj == 0)
         {
-            obj = load_h5obj(file, loc);
-            if (obj == 0) { return -2; }
+            return -2;
+        }
 
-            if (obj == 0)
+        attr = h5_open_attribute(obj, attr_name);
+
+        if (attr == 0)
+        {
+            TRI_LOG_STR("Warning: Attribute not found!");
+            return -3;
+        }
+
+        if (attr->getTypeClass() == H5T_STRING)
+        {
+            H5::DataType datatype = attr->getDataType();
+            TRI_LOG(datatype.getClass());
+            TRI_LOG(datatype.getSize());
+            TRI_LOG(datatype.isVariableStr());
+
+            if (datatype.isVariableStr())
             {
-                return -2;
+                H5::StrType tid(0, H5T_VARIABLE);
+                attr->read(tid, val);
             }
-
-            attr = new H5::Attribute(obj->openAttribute(attr_name));
-            attr->read(predtype_from<T>(), val);
+            else
+            {
+                size_t size = datatype.getSize();
+                char *buf = new char[size+1];
+                attr->read(datatype, buf);
+                buf[size] = '\0';
+                val = buf;
+                delete [] buf;
+            }
         }
-        catch (H5::Exception error)
+        else
         {
-            if (obj) { delete obj; }
-            if (attr) { delete attr; }
-            return -1;
+            TRI_LOG_STR("Attribute found, but belongs to the wrong typeclass");
+            TRI_LOG(attr->getTypeClass());
+            return -4;
         }
-
+    }
+    catch (H5::Exception error)
+    {
         if (obj) { delete obj; }
         if (attr) { delete attr; }
+        //error.printError();
+        return -5;
     }
 
+    if (obj) { delete obj; }
+    if (attr) { delete attr; }
+
     return 0;
 }
-// */
 
 
 /* specialize write_scalar_attribute for T=std::string */
@@ -216,6 +253,7 @@
         }
         catch (H5::Exception error)
         {
+            //error.printError();
         }
     }
 



More information about the CIG-COMMITS mailing list