diff --git a/h5d.go b/h5d.go index 463bc9f..43961a7 100644 --- a/h5d.go +++ b/h5d.go @@ -177,7 +177,18 @@ func (s *Dataset) OpenAttribute(name string) (*Attribute, error) { return openAttribute(s.id, name) } +//H5_DLL hid_t H5Dget_space(hid_t dset_id); +func (s *Dataset) H5Dget_space() (*Dataspace, error) { + dspace_id := C.H5Dget_space(s.id) + ds := newDataspace(dspace_id) + if ds.id < 0 { + return (ds), fmt.Errorf("couldn't open dataspace from Dataset %q", s.Name()) + } + return (ds), nil +} + // Datatype returns the HDF5 Datatype of the Dataset +//H5_DLL hid_t H5Dget_type(hid_t dset_id); func (s *Dataset) Datatype() (*Datatype, error) { dtype_id := C.H5Dget_type(s.id) if dtype_id < 0 { @@ -185,3 +196,50 @@ func (s *Dataset) Datatype() (*Datatype, error) { } return NewDatatype(dtype_id), nil } + +//H5_DLL hid_t H5Dget_create_plist(hid_t dset_id); +func (s *Dataset) H5Dget_create_plist() (C.hid_t, error) { + plist_id := (C.H5Dget_create_plist(s.id)) + if plist_id < 0 { + return (plist_id), fmt.Errorf("couldn't open access_plist from Dataset %q", s.Name()) + } + return (plist_id), nil +} + +//H5_DLL hid_t H5Dget_access_plist(hid_t dset_id); +func (s *Dataset) H5Dget_access_plist() (C.hid_t, error) { + plist_id := C.H5Dget_access_plist(s.id) + if plist_id < 0 { + return (plist_id), fmt.Errorf("couldn't open access_plist from Dataset %q", s.Name()) + } + return (plist_id), nil +} + +//H5_DLL hsize_t H5Dget_storage_size(hid_t dset_id); +func (s *Dataset) H5Dget_storage_size() (C.hsize_t, error) { + ds_size := C.H5Dget_storage_size(s.id) + if ds_size < 0 { + return (ds_size), fmt.Errorf("couldn't get size from Dataset %q", s.Name()) + } + return (ds_size), nil +} + +//H5_DLL herr_t H5Dset_extent(hid_t dset_id, const hsize_t size[]); +func (s *Dataset) H5Dset_extent(dims []uint) error { + return h5err(C.H5Dset_extent(s.id, (*C.hsize_t)(unsafe.Pointer(&dims[0])))) +} + +//H5_DLL herr_t H5Dflush(hid_t dset_id); +func (s *Dataset) H5Dflush() error { + return h5err(C.H5Dflush(s.id)) +} + +//H5_DLL herr_t H5Drefresh(hid_t dset_id); +func (s *Dataset) H5Drefresh() error { + return h5err(C.H5Drefresh(s.id)) +} + +//H5_DLL herr_t H5Ddebug(hid_t dset_id); +func (s *Dataset) H5Ddebug() error { + return h5err(C.H5Ddebug(s.id)) +} diff --git a/h5p.go b/h5p.go index 55b17e3..89352c6 100644 --- a/h5p.go +++ b/h5p.go @@ -14,6 +14,7 @@ import "C" import ( "fmt" "runtime" + "unsafe" ) type PropType C.hid_t @@ -38,6 +39,12 @@ func (p *PropList) finalizer() { } } +func AttachPropList(id C.hid_t) *PropList { + p := &PropList{Identifier{id}} + runtime.SetFinalizer(p, (*PropList).finalizer) + return p +} + // NewPropList creates a new PropList as an instance of a property list class. func NewPropList(cls_id PropType) (*PropList, error) { hid := C.H5Pcreate(C.hid_t(cls_id)) @@ -47,6 +54,15 @@ func NewPropList(cls_id PropType) (*PropList, error) { return newPropList(hid), nil } +// NewPropList creates a new PropList as an instance of a property list class. +func NewDefaultDatasetPropList() (*PropList, error) { + hid := C.H5Pcreate(C.H5P_CLS_DATASET_CREATE_ID_g) + if err := checkID(hid); err != nil { + return nil, err + } + return newPropList(hid), nil +} + // Close terminates access to a PropList. func (p *PropList) Close() error { if p.id == 0 { @@ -65,3 +81,42 @@ func (p *PropList) Copy() (*PropList, error) { } return newPropList(hid), nil } + +/* Object creation property list (OCPL) routines */ + +//H5_DLL int H5Pget_nfilters(hid_t plist_id); +func (p *PropList) H5Pget_nfilters() int { + return int(C.H5Pget_nfilters(p.id)) +} + +//H5_DLL herr_t H5Pset_deflate(hid_t plist_id, unsigned aggression); +func (p *PropList) H5Pset_deflate(aggression uint) error { + return h5err(C.H5Pset_deflate(p.id, C.uint(aggression))) +} + +/* Dataset creation property list (DCPL) routines */ + +//H5_DLL herr_t H5Pset_layout(hid_t plist_id, H5D_layout_t layout); +func (p *PropList) H5Pset_layout(layout_code uint) error { + return h5err(C.H5Pset_layout(p.id, C.H5D_layout_t(layout_code))) +} + +//H5_DLL H5D_layout_t H5Pget_layout(hid_t plist_id); +func (p *PropList) H5Pget_layout() uint { + return uint(C.H5Pget_layout(p.id)) +} + +//H5_DLL herr_t H5Pset_chunk(hid_t plist_id, int ndims, const hsize_t dim[/*ndims*/]); +func (p *PropList) H5Pset_chunk(ndims uint, dims []uint) error { + return h5err(C.H5Pset_chunk(p.id, C.int(ndims), (*C.hsize_t)(unsafe.Pointer(&dims[0])))) +} + +//H5_DLL int H5Pget_chunk(hid_t plist_id, int max_ndims, hsize_t dim[]/*out*/); +func (p *PropList) H5Pget_chunk() uint { + ndims := uint(0xffff) + dims := []uint{ndims} + c_dims := (*C.hsize_t)(unsafe.Pointer(&dims[0])) + res := C.H5Pget_chunk(p.id, C.int(ndims), c_dims) + + return uint(res) +} diff --git a/h5t.go b/h5t.go index 1fb8c5c..6ddadba 100644 --- a/h5t.go +++ b/h5t.go @@ -12,6 +12,7 @@ import "C" import ( "fmt" "reflect" + "regexp" "runtime" "unsafe" ) @@ -434,6 +435,7 @@ func NewDataTypeFromType(t reflect.Type) (*Datatype, error) { case reflect.Struct: sz := int(t.Size()) cdt, err := NewCompoundType(sz) + re := regexp.MustCompile(`hdf5:\s+\"([a-zA-Z_]+[a-zA-Z0-9_]+)\"`) if err != nil { return nil, err } @@ -452,6 +454,11 @@ func NewDataTypeFromType(t reflect.Type) (*Datatype, error) { field_name := string(f.Tag) if len(field_name) == 0 { field_name = f.Name + } else { + match := re.FindStringSubmatch(field_name) + if len(match) > 0 { + field_name = match[1] + } } err = cdt.Insert(field_name, offset, field_dt) if err != nil { diff --git a/h5t_shim.go b/h5t_shim.go index 202bc06..5b9a362 100644 --- a/h5t_shim.go +++ b/h5t_shim.go @@ -261,6 +261,7 @@ var ( // var h5t_VARIABLE int64 = C.H5T_VARIABLE +var H5S_UNLIMITED int64 = C.H5S_UNLIMITED func makeGoStringDatatype() *Datatype { dt, err := T_C_S1.Copy() diff --git a/hdf5.go b/hdf5.go index ead3d9b..afb82c5 100644 --- a/hdf5.go +++ b/hdf5.go @@ -21,6 +21,14 @@ func init() { } } +func H5open() { + err := h5err(C.H5open()) + if err != nil { + err_str := fmt.Sprintf("pb calling H5open(): %s", err) + panic(err_str) + } +} + // hdferror wraps hdf5 int-based error codes type h5error struct { code int