[H5r-commits] r11 - inst inst/h5_files src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 21 03:36:56 CEST 2010


Author: extemporaneousb
Date: 2010-04-21 03:36:54 +0200 (Wed, 21 Apr 2010)
New Revision: 11

Modified:
   inst/.Rhistory
   inst/h5_files/ex_1.h5
   inst/h5_files/makeH5.py
   inst/tests.R
   src/h5_wrap.c
Log:
Some partially broken code for doing hyperslab selection.

Modified: inst/.Rhistory
===================================================================
--- inst/.Rhistory	2010-04-16 01:09:15 UTC (rev 10)
+++ inst/.Rhistory	2010-04-21 01:36:54 UTC (rev 11)
@@ -1,18 +1,4 @@
-.Call("h5R_get_dataset_str", d)
-.Call("_h5R_get_dataset_str", d)
-.Call("_h5R_get_dataset_str", d)
-1
 d = .Call("h5R_get_dataset", g at ePtr, "ds_2")
-.Call("_h5R_get_dataset_str", d)
-.Call("_h5R_get_dataset_str", d)
-1
-d = .Call("h5R_get_dataset", g at ePtr, "ds_2")
-.Call("_h5R_get_dataset_str", d)
-.Call("_h5R_get_dataset_str", d)
-x
-1
-d = .Call("h5R_get_dataset", g at ePtr, "ds_2")
-.Call("_h5R_get_dataset_str", d)
 .Call("__h5R_get_dataset_str", d)
 d = .Call("h5R_get_dataset", g at ePtr, "ds_2")
 .Call("__h5R_get_dataset_str", d)
@@ -34,13 +20,11 @@
 .Call("__h5R_get_dataset_str", d)
 d = .Call("h5R_get_dataset", g at ePtr, "ds_2")
 .Call("__h5R_get_dataset_str", d)
-d = .Call("h5R_get_dataset", g at ePtr, "ds_2")
 .Call("__h5R_get_dataset_str", d)
 .Call("__h5R_get_dataset_str", d)
 .Call("__h5R_get_dataset_str", d)
 .Call("__h5R_get_dataset_str", d)
 .Call("__h5R_get_dataset_str", d)
-.Call("__h5R_get_dataset_str", d)
 d = .Call("h5R_get_dataset", g at ePtr, "ds_2")
 .Call("__h5R_get_dataset_str", d)
 .Call("__h5R_get_dataset_str", d)
@@ -148,3 +132,19 @@
 ?drop
 d[1,1]
 d3[1,1,]
+d
+.Call("h5R_read_slab", d at ePtr, as.integer(0,0), as.integer(5,5))
+4
+.Call("h5R_read_slab", d at ePtr, as.integer(0,0), as.integer(5,5))
+1
+.Call("h5R_read_slab", d at ePtr, as.integer(0,0), as.integer(5,5))
+1
+.Call("h5R_read_slab", d at ePtr, as.integer(0,0), as.integer(5,5))
+1
+d3
+d3[1,,]
+dint
+.Call("h5R_read_slab", dint at ePtr, as.integer(0,0), as.integer(5,5))
+1
+dint[,]
+1

Modified: inst/h5_files/ex_1.h5
===================================================================
(Binary files differ)

Modified: inst/h5_files/makeH5.py
===================================================================
--- inst/h5_files/makeH5.py	2010-04-16 01:09:15 UTC (rev 10)
+++ inst/h5_files/makeH5.py	2010-04-21 01:36:54 UTC (rev 11)
@@ -23,6 +23,8 @@
 
 g.create_dataset("ds_4", data = s.reshape((2, 10)))
 
+g.create_dataset("ds_5", data = a.reshape(21, 9))
+
 f.close()
 
 f = h5py.File("ex_1.h5")

Modified: inst/tests.R
===================================================================
--- inst/tests.R	2010-04-16 01:09:15 UTC (rev 10)
+++ inst/tests.R	2010-04-21 01:36:54 UTC (rev 11)
@@ -8,6 +8,10 @@
 ## ex_1
 f <- H5File(files[1])
 g <- getH5Group(f, "group_1")
+
+dint <- getH5Dataset(g, "ds_5")
+.Call("h5R_read_slab", dint at ePtr, as.integer(c(0,0)), as.integer(c(5,5)), as.integer(c(5,5)))
+
 d <- getH5Dataset(g, "ds_1")
 d[1:10, 1:10]
 d[1:10,]

Modified: src/h5_wrap.c
===================================================================
--- src/h5_wrap.c	2010-04-16 01:09:15 UTC (rev 10)
+++ src/h5_wrap.c	2010-04-21 01:36:54 UTC (rev 11)
@@ -178,17 +178,17 @@
     void* buf; 
 
     switch (INTEGER(h5R_get_type(h5_dataset))[0]) {
-    case H5T_INTEGER : 
+    case H5T_INTEGER: 
 	PROTECT(dta = allocVector(INTSXP, _h5R_get_nelts(h5_dataset)));
 	memtype = H5T_NATIVE_INT;
 	buf = INTEGER(dta);
 	break;
-    case H5T_FLOAT :
+    case H5T_FLOAT:
 	PROTECT(dta = allocVector(REALSXP, _h5R_get_nelts(h5_dataset)));
 	memtype = H5T_NATIVE_DOUBLE;
 	buf = REAL(dta);
 	break;
-    case H5T_STRING :
+    case H5T_STRING:
 	return _h5R_read_vlen_str(h5_dataset);
     default:
 	error("Unsupported class in h5R_read_dataset.");
@@ -198,6 +198,50 @@
 
     return(dta);
 }
+
+SEXP h5R_read_slab(SEXP h5_dataset, SEXP _offsets, SEXP _counts, SEXP _orank) {
+    SEXP dta = R_NilValue;
+    hid_t space, memspace;
+    int ndims, i; 
+
+    int* offsets = INTEGER(_offsets);
+    int* counts  = INTEGER(_counts);
+    int* orank   = INTEGER(_orank);  
+   
+    hsize_t sel[] = {0, 0};
+   
+    int v = 1;
+    for (i = 0; i < length(_orank); i++) {
+	v *= orank[i];
+    }
+
+    switch (INTEGER(h5R_get_type(h5_dataset))[0]) {
+    case H5T_INTEGER: 
+	Rprintf("In H5T_INTEGER with v = %d\n", v);
+
+	space = _h5R_get_space(h5_dataset);
+	H5Sselect_hyperslab(space, H5S_SELECT_SET, (hsize_t*) offsets, NULL, NULL, (hsize_t*) counts);
+
+	/* memspace = H5Screate_simple(length(_orank), (hsize_t*) orank, NULL); */
+	/* H5Sselect_hyperslab(memspace, H5S_SELECT_SET, sel, NULL,  (hsize_t*) counts, NULL); */
+
+	PROTECT(dta = allocVector(INTSXP, v));
+	Rprintf("About to read dataset, v = %d\n", v);
+	Rprintf("offset: %d, %d\n", offsets[0], offsets[1]);
+	Rprintf("counts: %d, %d\n", counts[0], counts[1]);
+
+	H5Dread(HID(h5_dataset), H5T_NATIVE_INT, H5S_ALL, space, H5P_DEFAULT, (void *) INTEGER(dta));
+	break;
+    default:
+	error("Unsupported class in %s\n", __func__);
+	
+    }
+
+    UNPROTECT(1);
+
+    return dta;
+}
+
   
 /** 
  * I am currently keeping read_attr and read_dataset separate because



More information about the H5r-commits mailing list