[H5r-commits] r22 - / src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 13 01:54:20 CEST 2010


Author: extemporaneousb
Date: 2010-05-13 01:54:20 +0200 (Thu, 13 May 2010)
New Revision: 22

Added:
   INSTALL
Modified:
   NEWS
   src/h5_wrap.c
Log:


Added: INSTALL
===================================================================
--- INSTALL	                        (rev 0)
+++ INSTALL	2010-05-12 23:54:20 UTC (rev 22)
@@ -0,0 +1,26 @@
+INSTALLATION INSTRUCTIONS FOR THE h5r R PACKAGE
+
+Currently, this package works and has been tested with hdf5-1.8.4 on
+Mac OSX and Linux. The package will most likely work on most POSIX
+systems where R works. Windows support should be forthcoming and
+anyone who has experience there and would like to help please contact
+me: jbullard at pacificbiosciences.com. 
+
+To install, a working hdf5 installation must exist. This can be
+downloaded at: http://www.hdfgroup.org/downloads/index.html#hdf5
+
+If the hdf5 libraries and header files are installed in standard
+places (/usr, /usr/local) then the configure script should pick them
+up and have no problem. If you have not installed hdf5 in a standard
+place, but instead installed it in HDF5_HOME then you can install the
+R package in the following way:
+
+R CMD INSTALL --configure-args="--with-hdf5=$HDF5_HOME" h5r
+
+If you install to a non-standard location like this, then you must set
+your LD_LIBRARY_PATH environment variable to contain the directory:
+$HDF5_HOME/libs, otherwise, at run-time, there will be no means to
+find the hdf5.so. 
+
+Please contact jbullard at pacificbiosciences.com if you have any
+questions.

Modified: NEWS
===================================================================
--- NEWS	2010-05-04 21:58:29 UTC (rev 21)
+++ NEWS	2010-05-12 23:54:20 UTC (rev 22)
@@ -15,3 +15,4 @@
     o Added support for 1-d attributes of type: String, Float, and Integer.
 
 BUG FIXES
+    o Allowed fixed-length strings.

Modified: src/h5_wrap.c
===================================================================
--- src/h5_wrap.c	2010-05-04 21:58:29 UTC (rev 21)
+++ src/h5_wrap.c	2010-05-12 23:54:20 UTC (rev 22)
@@ -132,34 +132,87 @@
     return res;
 }
 
-SEXP _h5R_read_vlen_str(SEXP h5_obj) {
-    int i;
+int _h5R_is_vlen (SEXP h5_obj) {
+    hid_t dtype;
 
-    SEXP res  = R_NilValue;
-    int nelts = _h5R_get_nelts(h5_obj);
+    switch (H5Iget_type(HID(h5_obj))) {
+    case H5I_DATASET:
+	dtype = H5Dget_type(HID(h5_obj));
+	break;
+    case H5I_ATTR:
+	dtype = H5Aget_type(HID(h5_obj));
+	break;
+    default:
+	error("Unknown object in %s.\n", __func__);
+    }
+    return H5Tis_variable_str(dtype);
+}
 
+int _h5R_get_size (SEXP h5_obj) {
+    int s = -1;
+
+    switch (H5Iget_type(HID(h5_obj))) {
+    case H5I_DATASET:
+	s = H5Tget_size(H5Dget_type(HID(h5_obj)));
+	break;
+    case H5I_ATTR:
+	s = H5Tget_size(H5Aget_type(HID(h5_obj)));
+	break;
+    default:
+	error("Unknown object in %s.\n", __func__);
+    }
+    return s;
+}
+
+
+SEXP _h5R_read_vlen_str(SEXP h5_obj) {
+    int i = -1;
+    SEXP res = R_NilValue;
+    void* buf;
+    
+    int nelts     = _h5R_get_nelts(h5_obj);
     char** rdata  = (char **) Calloc(nelts, char*);
     hid_t memtype = H5Tcopy (H5T_C_S1);
-    H5Tset_size (memtype, H5T_VARIABLE);
+
+    if (! _h5R_is_vlen(h5_obj)) {
+	H5Tset_size(memtype, _h5R_get_size(h5_obj) + 1);
+	for (i = 0; i < nelts; i++) {
+	    rdata[i] = (char *) Calloc(_h5R_get_size(h5_obj) + 1, char*);
+	}
+	buf = rdata[0];
+    }
+    else {
+	H5Tset_size(memtype, H5T_VARIABLE);
+	buf = rdata;
+    }
     
     switch (H5Iget_type(HID(h5_obj))) {
     case H5I_DATASET:
-	H5Dread(HID(h5_obj), memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
+	H5Dread(HID(h5_obj), memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
 	break;
     case H5I_ATTR:
-	H5Aread(HID(h5_obj), memtype, rdata);
+	H5Aread(HID(h5_obj), memtype, buf);
 	break;
     default:
 	error("Unsupported class in %s.\n", __func__);
     }
     
     PROTECT(res = allocVector(STRSXP, nelts));
-    for (i = 0; i < nelts; i++)
-	if (rdata[i])
+    for (i = 0; i < nelts; i++) {
+	if (rdata[i]) {
      	    SET_STRING_ELT(res, i, mkChar(rdata[i])); 
+	}
+    }
     UNPROTECT(1); 
 
-    H5Dvlen_reclaim (memtype, _h5R_get_space(h5_obj), H5P_DEFAULT, rdata);
+    if (_h5R_is_vlen(h5_obj)) {
+	H5Dvlen_reclaim (memtype, _h5R_get_space(h5_obj), H5P_DEFAULT, rdata);
+    } 
+    else {
+	for (i = 0; i < nelts; i++)
+	    Free(rdata[i]);
+    }
+
     Free(rdata);
     H5Tclose(memtype);
 
@@ -170,6 +223,7 @@
     SEXP dta = R_NilValue;
     hid_t memtype = -1;
     void* buf = NULL; 
+    
 
     switch (INTEGER(h5R_get_type(h5_dataset))[0]) {
     case H5T_INTEGER: 



More information about the H5r-commits mailing list