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

all: moves to camel case naming #38

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
6 changes: 3 additions & 3 deletions cmd/test-go-cpxcmpd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ func main() {
fmt.Printf(":: file [%s] created (id=%d)\n", fname, f.ID())

// create the memory data type
dtype, err := hdf5.NewDatatypeFromValue(s1[0])
typ, err := hdf5.NewDatatypeFromValue(s1[0])
if err != nil {
panic("could not create a dtype")
panic("could not create a typ")
}

// create the dataset
dset, err := f.CreateDataset(dsname, dtype, space)
dset, err := f.CreateDataset(dsname, typ, space)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/test-go-extend-ds/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func main() {
//RANK:= 2

//dims := []int{3, 3} // dset dimensions at creation
//maxdims:= []int{hdf5.S_UNLIMITED, hdf5.S_UNLIMITED}
//maxDims:= []int{hdf5.S_UNLIMITED, hdf5.S_UNLIMITED}

//mspace := hdf5.CreateDataspace(dims, maxdims)
//mSpace := hdf5.CreateDataspace(dims, maxDims)

// create a new file
f, err := hdf5.CreateFile(fname, hdf5.F_ACC_TRUNC)
Expand Down
22 changes: 11 additions & 11 deletions h5a_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ func newAttribute(id C.hid_t) *Attribute {
return &Attribute{Identifier{id}}
}

func createAttribute(id C.hid_t, name string, dtype *Datatype, dspace *Dataspace, acpl *PropList) (*Attribute, error) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
hid := C.H5Acreate2(id, c_name, dtype.id, dspace.id, acpl.id, P_DEFAULT.id)
func createAttribute(id C.hid_t, name string, typ *Datatype, spc *Dataspace, acpl *PropList) (*Attribute, error) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
hid := C.H5Acreate2(id, cName, typ.id, spc.id, acpl.id, P_DEFAULT.id)
if err := checkID(hid); err != nil {
return nil, err
}
return newAttribute(hid), nil
}

func openAttribute(id C.hid_t, name string) (*Attribute, error) {
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))

hid := C.H5Aopen(id, c_name, P_DEFAULT.id)
hid := C.H5Aopen(id, cName, P_DEFAULT.id)
if err := checkID(hid); err != nil {
return nil, err
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func (s *Attribute) Space() *Dataspace {
}

// Read reads raw data from a attribute into a buffer.
func (s *Attribute) Read(data interface{}, dtype *Datatype) error {
func (s *Attribute) Read(data interface{}, typ *Datatype) error {
var addr unsafe.Pointer
v := reflect.ValueOf(data)

Expand All @@ -88,13 +88,13 @@ func (s *Attribute) Read(data interface{}, dtype *Datatype) error {
addr = unsafe.Pointer(v.UnsafeAddr())
}

rc := C.H5Aread(s.id, dtype.id, addr)
rc := C.H5Aread(s.id, typ.id, addr)
err := h5err(rc)
return err
}

// Write writes raw data from a buffer to an attribute.
func (s *Attribute) Write(data interface{}, dtype *Datatype) error {
func (s *Attribute) Write(data interface{}, typ *Datatype) error {
var addr unsafe.Pointer
v := reflect.Indirect(reflect.ValueOf(data))
switch v.Kind() {
Expand All @@ -114,7 +114,7 @@ func (s *Attribute) Write(data interface{}, dtype *Datatype) error {
addr = unsafe.Pointer(v.UnsafeAddr())
}

rc := C.H5Awrite(s.id, dtype.id, addr)
rc := C.H5Awrite(s.id, typ.id, addr)
err := h5err(rc)
return err
}
8 changes: 4 additions & 4 deletions h5a_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ func TestWriteAttribute(t *testing.T) {
}

for name, v := range attrs {
dtype, err := NewDataTypeFromType(v.Type)
typ, err := NewDataTypeFromType(v.Type)
if err != nil {
t.Fatalf("NewDatatypeFromValue failed: %s\n", err)
}
defer dtype.Close()
defer typ.Close()

attr, err := dset.CreateAttribute(name, dtype, scalar)
attr, err := dset.CreateAttribute(name, typ, scalar)
if err != nil {
t.Fatalf("CreateAttribute failed: %s\n", err)
}
defer attr.Close()

if err := attr.Write(v.Value, dtype); err != nil {
if err := attr.Write(v.Value, typ); err != nil {
t.Fatalf("Attribute write failed: %s\n", err)
}
}
Expand Down
62 changes: 31 additions & 31 deletions h5d_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func newDataset(id C.hid_t, typ *Datatype) *Dataset {
return &Dataset{Identifier: Identifier{id}, typ: typ}
}

func createDataset(id C.hid_t, name string, dtype *Datatype, dspace *Dataspace, dcpl *PropList) (*Dataset, error) {
dtype, err := dtype.Copy() // For safety
func createDataset(id C.hid_t, name string, typ *Datatype, spc *Dataspace, dcpl *PropList) (*Dataset, error) {
typ, err := typ.Copy() // For safety
if err != nil {
return nil, err
}
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_name))
hid := C.H5Dcreate2(id, c_name, dtype.id, dspace.id, P_DEFAULT.id, dcpl.id, P_DEFAULT.id)
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
hid := C.H5Dcreate2(id, cName, typ.id, spc.id, P_DEFAULT.id, dcpl.id, P_DEFAULT.id)
if err := checkID(hid); err != nil {
return nil, err
}
return newDataset(hid, dtype), nil
return newDataset(hid, typ), nil
}

// Close releases and terminates access to a dataset.
Expand All @@ -59,9 +59,9 @@ func (s *Dataset) Space() *Dataspace {
}

// ReadSubset reads a subset of raw data from a dataset into a buffer.
func (s *Dataset) ReadSubset(data interface{}, memspace, filespace *Dataspace) error {
dtype, err := s.Datatype()
defer dtype.Close()
func (s *Dataset) ReadSubset(data interface{}, memSpace, fileSpace *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.

These are good though.

typ, err := s.Datatype()
defer typ.Close()
if err != nil {
return err
}
Expand Down Expand Up @@ -89,14 +89,14 @@ func (s *Dataset) ReadSubset(data interface{}, memspace, filespace *Dataspace) e
addr = unsafe.Pointer(v.UnsafeAddr())
}

var filespace_id, memspace_id C.hid_t = 0, 0
if memspace != nil {
memspace_id = memspace.id
var fileSpaceID, memSpaceID C.hid_t
if memSpace != nil {
memSpaceID = memSpace.id
}
if filespace != nil {
filespace_id = filespace.id
if fileSpace != nil {
fileSpaceID = fileSpace.id
}
rc := C.H5Dread(s.id, dtype.id, memspace_id, filespace_id, 0, addr)
rc := C.H5Dread(s.id, typ.id, memSpaceID, fileSpaceID, 0, addr)
err = h5err(rc)
return err
}
Expand All @@ -107,9 +107,9 @@ func (s *Dataset) Read(data interface{}) error {
}

// WriteSubset writes a subset of raw data from a buffer to a dataset.
func (s *Dataset) WriteSubset(data interface{}, memspace, filespace *Dataspace) error {
dtype, err := s.Datatype()
defer dtype.Close()
func (s *Dataset) WriteSubset(data interface{}, memSpace, fileSpace *Dataspace) error {
typ, err := s.Datatype()
defer typ.Close()
if err != nil {
return err
}
Expand Down Expand Up @@ -137,14 +137,14 @@ func (s *Dataset) WriteSubset(data interface{}, memspace, filespace *Dataspace)
addr = unsafe.Pointer(v.UnsafeAddr())
}

var filespace_id, memspace_id C.hid_t = 0, 0
if memspace != nil {
memspace_id = memspace.id
var fileSpaceID, memSpaceID C.hid_t
if memSpace != nil {
memSpaceID = memSpace.id
}
if filespace != nil {
filespace_id = filespace.id
if fileSpace != nil {
fileSpaceID = fileSpace.id
}
rc := C.H5Dwrite(s.id, dtype.id, memspace_id, filespace_id, 0, addr)
rc := C.H5Dwrite(s.id, typ.id, memSpaceID, fileSpaceID, 0, addr)
err = h5err(rc)
return err
}
Expand All @@ -156,14 +156,14 @@ func (s *Dataset) Write(data interface{}) error {

// Creates a new attribute at this location. The returned attribute
// must be closed by the user when it is no longer needed.
func (s *Dataset) CreateAttribute(name string, dtype *Datatype, dspace *Dataspace) (*Attribute, error) {
return createAttribute(s.id, name, dtype, dspace, P_DEFAULT)
func (s *Dataset) CreateAttribute(name string, typ *Datatype, spc *Dataspace) (*Attribute, error) {
return createAttribute(s.id, name, typ, spc, P_DEFAULT)
}

// Creates a new attribute at this location. The returned
// attribute must be closed by the user when it is no longer needed.
func (s *Dataset) CreateAttributeWith(name string, dtype *Datatype, dspace *Dataspace, acpl *PropList) (*Attribute, error) {
return createAttribute(s.id, name, dtype, dspace, acpl)
func (s *Dataset) CreateAttributeWith(name string, typ *Datatype, spc *Dataspace, acpl *PropList) (*Attribute, error) {
return createAttribute(s.id, name, typ, spc, acpl)
}

// Opens an existing attribute. The returned attribute must be closed
Expand All @@ -176,11 +176,11 @@ func (s *Dataset) OpenAttribute(name string) (*Attribute, error) {
// Datatype returns the HDF5 Datatype of the Dataset. The returned
// datatype must be closed by the user when it is no longer needed.
func (s *Dataset) Datatype() (*Datatype, error) {
dtype_id := C.H5Dget_type(s.id)
if dtype_id < 0 {
typID := C.H5Dget_type(s.id)
if typID < 0 {
return nil, fmt.Errorf("couldn't open Datatype from Dataset %q", s.Name())
}
return NewDatatype(dtype_id), nil
return NewDatatype(typID), nil
}

// hasIllegalGoPointer returns whether the Dataset is known to have
Expand Down
32 changes: 16 additions & 16 deletions h5d_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func createDataset1(t *testing.T) error {
}

dims := []uint{20, 5}
dspace, err := CreateSimpleDataspace(dims, dims)
spc, err := CreateSimpleDataspace(dims, dims)
if err != nil {
t.Fatal(err)
return err
}

dset, err := f.CreateDataset("dset", T_NATIVE_USHORT, dspace)
dset, err := f.CreateDataset("dset", T_NATIVE_USHORT, spc)
if err != nil {
t.Fatal(err)
return err
Expand Down Expand Up @@ -78,20 +78,20 @@ func TestReadSubset(t *testing.T) {
t.Fatal(err)
}

// get the filespace and select the subset
filespace := dset.Space()
// get the fileSpace and select the subset
fileSpace := dset.Space()
offset, stride, count, block := [2]uint{5, 1}, [2]uint{1, 1}, [2]uint{5, 2}, [2]uint{1, 1}
err = filespace.SelectHyperslab(offset[:], stride[:], count[:], block[:])
err = fileSpace.SelectHyperslab(offset[:], stride[:], count[:], block[:])
if err != nil {
t.Fatal(err)
}

// create the memory space for the subset
dims, maxdims := [2]uint{2, 5}, [2]uint{2, 5}
dims, maxDims := [2]uint{2, 5}, [2]uint{2, 5}
if err != nil {
t.Fatal(err)
}
memspace, err := CreateSimpleDataspace(dims[:], maxdims[:])
memSpace, err := CreateSimpleDataspace(dims[:], maxDims[:])
if err != nil {
t.Fatal(err)
}
Expand All @@ -104,7 +104,7 @@ func TestReadSubset(t *testing.T) {
data := [10]uint16{}

// read the subset
err = dset.ReadSubset(&data, memspace, filespace)
err = dset.ReadSubset(&data, memSpace, fileSpace)
if err != nil {
t.Fatal(err)
}
Expand All @@ -120,7 +120,7 @@ func TestReadSubset(t *testing.T) {
data := make([]uint16, 10)

// read the subset
err = dset.ReadSubset(&data, memspace, filespace)
err = dset.ReadSubset(&data, memSpace, fileSpace)
if err != nil {
t.Fatal(err)
}
Expand All @@ -142,7 +142,7 @@ func TestWriteSubset(t *testing.T) {
t.Fatal(err)
}
mdims := []uint{2, 6}
mspace, err := CreateSimpleDataspace(mdims, nil)
mSpace, err := CreateSimpleDataspace(mdims, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -167,7 +167,7 @@ func TestWriteSubset(t *testing.T) {

data := make([]uint16, mdims[0]*mdims[1])

if err = dset.WriteSubset(&data, mspace, fspace); err != nil {
if err = dset.WriteSubset(&data, mSpace, fspace); err != nil {
t.Fatal(err)
}
}
Expand All @@ -177,21 +177,21 @@ func TestSelectHyperslab(t *testing.T) {
defer DisplayErrors(false)

dims := []uint{12, 4}
dspace, err := CreateSimpleDataspace(dims, nil)
spc, err := CreateSimpleDataspace(dims, nil)
if err != nil {
t.Fatal(err)
}
offset, stride, count, block := []uint{1, 2}, []uint{2, 1}, []uint{4, 2}, []uint{1, 1}
if err = dspace.SelectHyperslab(offset, stride, count, block); err != nil {
if err = spc.SelectHyperslab(offset, stride, count, block); err != nil {
t.Fatal(err)
}
if err = dspace.SelectHyperslab(offset, nil, count, block); err != nil {
if err = spc.SelectHyperslab(offset, nil, count, block); err != nil {
t.Fatal(err)
}
if err = dspace.SelectHyperslab(offset, stride, count, nil); err != nil {
if err = spc.SelectHyperslab(offset, stride, count, nil); err != nil {
t.Fatal(err)
}
if err = dspace.SelectHyperslab(offset, nil, count, nil); err != nil {
if err = spc.SelectHyperslab(offset, nil, count, nil); err != nil {
t.Fatal(err)
}
}
Loading