From 80d99cc8df6ecd5e0b630cb1b45526c003c20a3c Mon Sep 17 00:00:00 2001 From: yucheng Date: Fri, 13 Sep 2019 16:01:36 -0400 Subject: [PATCH 1/2] Added Resize functionality for the chuncked datasets --- h5d_dataset.go | 17 ++++++++++++++ h5d_dataset_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/h5d_dataset.go b/h5d_dataset.go index 7bb8715..5ba2f2e 100644 --- a/h5d_dataset.go +++ b/h5d_dataset.go @@ -189,3 +189,20 @@ func (s *Dataset) Datatype() (*Datatype, error) { func (s *Dataset) hasIllegalGoPointer() bool { return s.typ.hasIllegalGoPointer() } + +// Resize a dataset +func (s *Dataset) Resize(dims []uint) error { + var c_dims *C.hsize_t + if dims == nil { + return fmt.Errorf("dims are nil") + } + rank := s.Space().SimpleExtentNDims() + if rank != len(dims) { + return fmt.Errorf("Resize can't change the rank of the dataset space") + } + c_dims = (*C.hsize_t)(unsafe.Pointer(&dims[0])) + + rc := C.H5Dset_extent(s.id, c_dims) + err := h5err(rc) + return err +} diff --git a/h5d_dataset_test.go b/h5d_dataset_test.go index 28e76dd..9c6adab 100644 --- a/h5d_dataset_test.go +++ b/h5d_dataset_test.go @@ -195,3 +195,60 @@ func TestSelectHyperslab(t *testing.T) { t.Fatal(err) } } + +func TestDatasetResize(t *testing.T) { + f, err := CreateFile(fname, F_ACC_TRUNC) + if err != nil { + t.Fatalf("CreateFile failed: %s", err) + } + defer os.Remove(fname) + defer f.Close() + + dtype, err := NewDataTypeFromType(reflect.TypeOf(1)) + if err != nil { + t.Fatal(err) + } + initdims := []uint{4, 4} + maxdims := []uint{12, 4} + chunkDims := []uint{2, 4} + resizedDims := []uint{8, 4} + space, err := CreateSimpleDataspace(initdims, maxdims) + if err != nil { + t.Fatal(err) + } + defer space.Close() + + dcpl, err := NewPropList(P_DATASET_CREATE) + if err != nil { + t.Fatal(err) + } + defer dcpl.Close() + err = dcpl.SetChunk(chunkDims) + if err != nil { + t.Fatal(err) + } + dset, err := f.CreateDatasetWith("dsetchunked", dtype, space, dcpl) + if err != nil { + t.Fatal(err) + } + defer dset.Close() + + dimsGot, maxdimsGot, err := dset.Space().SimpleExtentDims() + if !reflect.DeepEqual(dimsGot, initdims) || !reflect.DeepEqual(maxdimsGot, maxdims) { + t.Fatal("Dimension not correct when creating chunked dataset") + } + if err != nil { + t.Fatal(err) + } + err = dset.Resize(resizedDims) + if err != nil { + t.Fatal(err) + } + dimsGot, maxdimsGot, err = dset.Space().SimpleExtentDims() + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(dimsGot, resizedDims) || !reflect.DeepEqual(maxdimsGot, maxdims) { + t.Fatal("Resized dimension not as expected") + } +} From 697e7f23cd6f8e205e50e860c624a74fd0aa3472 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Wed, 18 Sep 2019 08:02:42 +0930 Subject: [PATCH 2/2] golangci: install libhdf5 dependency --- .golangci.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b7679c8 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,3 @@ +service: + prepare: + - apt-get update && apt-get install -y libhdf5-serial-dev