Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add deflate, add other function calls from the api, fix tag naming #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions h5d.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,69 @@ func (s *Dataset) OpenAttribute(name string) (*Attribute, error) {
return openAttribute(s.id, name)
}

//H5_DLL hid_t H5Dget_space(hid_t dset_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these comments for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the prototype of the function being mapped, from the c header.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's what it is, but why is it here? There should be user-facing documentation (possibly, but by no means guaranteed including such a line) - think about how godoc renders this.

func (s *Dataset) H5Dget_space() (*Dataspace, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to namespace with H5D: it's already a method of Dataset.

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 {
return nil, fmt.Errorf("couldn't open Datatype from Dataset %q", s.Name())
}
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5D.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5D.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5D.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5D.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5D.

return h5err(C.H5Dflush(s.id))
}

//H5_DLL herr_t H5Drefresh(hid_t dset_id);
func (s *Dataset) H5Drefresh() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5D.

return h5err(C.H5Drefresh(s.id))
}

//H5_DLL herr_t H5Ddebug(hid_t dset_id);
func (s *Dataset) H5Ddebug() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5D.

return h5err(C.H5Ddebug(s.id))
}
55 changes: 55 additions & 0 deletions h5p.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import "C"
import (
"fmt"
"runtime"
"unsafe"
)

type PropType C.hid_t
Expand All @@ -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))
Expand All @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the doc comment (function name doesn't match.)

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 {
Expand All @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5P.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5P.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5P.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5P.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5P.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: no need to namespace with H5P.

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)
}
7 changes: 7 additions & 0 deletions h5t.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "C"
import (
"fmt"
"reflect"
"regexp"
"runtime"
"unsafe"
)
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions h5t_shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ var (

//
var h5t_VARIABLE int64 = C.H5T_VARIABLE
var H5S_UNLIMITED int64 = C.H5S_UNLIMITED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lead with lower case please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be exported. For instance, is passed to hdf5.CreateSimpleDataspace() to create an unlimited dataspace.


func makeGoStringDatatype() *Datatype {
dt, err := T_C_S1.Copy()
Expand Down
8 changes: 8 additions & 0 deletions hdf5.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ func init() {
}
}

func H5open() {
err := h5err(C.H5open())
if err != nil {
err_str := fmt.Sprintf("pb calling H5open(): %s", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just lump the lines together:

panic(fmt.Errorf("error calling H5open: %v", err))

why is it required?
func init() already does this (and is automaticlly called when the package is imported)

panic(err_str)
}
}

// hdferror wraps hdf5 int-based error codes
type h5error struct {
code int
Expand Down