[H5r-commits] r18 - inst src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Apr 30 19:04:56 CEST 2010
Author: extemporaneousb
Date: 2010-04-30 19:04:56 +0200 (Fri, 30 Apr 2010)
New Revision: 18
Modified:
inst/testSlab.R
src/h5_wrap.c
Log:
Added support for String hyperslab selection.
Modified: inst/testSlab.R
===================================================================
--- inst/testSlab.R 2010-04-30 00:14:37 UTC (rev 17)
+++ inst/testSlab.R 2010-04-30 17:04:56 UTC (rev 18)
@@ -54,3 +54,18 @@
d3[1,1,1]
d3[1,,]
d3[,,1]
+
+
+dStr <- getH5Dataset(g, "ds_2", inMemory = FALSE)
+dStrM <- getH5Dataset(g, "ds_2", inMemory = TRUE)
+all(dStr[1:2] == dStrM[1:2])
+all(dStr[1:2] == dStrM[1:2])
+
+
+dStr <- getH5Dataset(g, "ds_4", inMemory = FALSE)
+dStrM <- getH5Dataset(g, "ds_4", inMemory = TRUE)
+all(dStr[1:2,] == dStrM[1:2,])
+all(dStr[,1:2] == dStrM[,1:2])
+
+x = replicate(1000000, dStr[,1:5])
+
Modified: src/h5_wrap.c
===================================================================
--- src/h5_wrap.c 2010-04-30 00:14:37 UTC (rev 17)
+++ src/h5_wrap.c 2010-04-30 17:04:56 UTC (rev 18)
@@ -206,7 +206,7 @@
/** I'm surprised I have to do this, but it seems to be necessary. **/
hsize_t* _h_offsets = (hsize_t*) Calloc(length(_counts), hsize_t);
hsize_t* _h_counts = (hsize_t*) Calloc(length(_counts), hsize_t);
-
+
int v = 1;
for (i = 0; i < length(_counts); i++) {
v *= counts[i];
@@ -214,6 +214,10 @@
_h_counts[i] = counts[i];
}
+ space = _h5R_get_space(h5_dataset);
+ H5Sselect_hyperslab(space, H5S_SELECT_SET, _h_offsets, NULL, _h_counts, NULL);
+ memspace = H5Screate_simple(length(_counts), _h_counts, NULL);
+
switch (INTEGER(h5R_get_type(h5_dataset))[0]) {
case H5T_INTEGER:
PROTECT(dta = allocVector(INTSXP, v));
@@ -226,17 +230,31 @@
buf = REAL(dta);
break;
case H5T_STRING:
- error("String slab selection not yet supported.\n");
+ buf = (char **) Calloc(v, char*);
+ memtype = H5Tcopy (H5T_C_S1);
+ H5Tset_size (memtype, H5T_VARIABLE);
+ break;
default:
error("Unsupported class in %s\n", __func__);
}
- space = _h5R_get_space(h5_dataset);
- H5Sselect_hyperslab(space, H5S_SELECT_SET, _h_offsets, NULL, _h_counts, NULL);
- memspace = H5Screate_simple(length(_counts), _h_counts, NULL);
- H5Dread(HID(h5_dataset), memtype, memspace, space,
- H5P_DEFAULT, buf);
+ H5Dread(HID(h5_dataset), memtype, memspace, space, H5P_DEFAULT, buf);
+ /** There requires a little more with strings. **/
+ if (H5T_STRING == INTEGER(h5R_get_type(h5_dataset))[0]) {
+ PROTECT(dta = allocVector(STRSXP, v));
+ for (i = 0; i < v; i++)
+ if (((char **) buf)[i]) {
+ SET_STRING_ELT(dta, i, mkChar( ((char **) buf)[i] ));
+ }
+
+ H5Dvlen_reclaim (memtype, memspace, H5P_DEFAULT, buf);
+
+ H5Tclose(memtype);
+ Free(buf);
+ }
+
+
/** clean up. **/
Free(_h_offsets);
Free(_h_counts);
More information about the H5r-commits
mailing list