Beispiel #1
0
// Creates a new simple dataspace and opens it for access.
// hid_t H5Screate_simple( int rank, const hsize_t * current_dims, const hsize_t * maximum_dims )
func CreateSimpleDataSpace(dims, maximum_dims []int) (*DataSpace, error) {

	var c_dims *C.hsize_t = nil
	var c_maxdims *C.hsize_t = nil

	rank := C.int(0)
	if dims != nil {
		rank = C.int(len(dims))
		// FIXME: size of C.hsize_t and go.int !!
		c_dims = (*C.hsize_t)(unsafe.Pointer(&dims[0]))

	}
	if maximum_dims != nil {
		rank = C.int(len(maximum_dims))
		// FIXME: size of C.hsize_t and go.int !!
		c_maxdims = (*C.hsize_t)(unsafe.Pointer(&maximum_dims[0]))

	}
	if len(dims) != len(maximum_dims) && (dims != nil && maximum_dims != nil) {
		return nil, errors.New("sizes of 'dims' and 'maximum_dims' dont match")
	}

	hid := C.H5Screate_simple(rank, c_dims, c_maxdims)
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	ds := new_dataspace(hid)
	return ds, err
}
Beispiel #2
0
// copyDatatype should be called by any function wishing to return
// an existing Datatype from a Dataset or Attribute.
func copyDatatype(id C.hid_t) (*Datatype, error) {
	hid := C.H5Tcopy(id)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	return NewDatatype(hid), nil
}
Beispiel #3
0
// Returns a new identifier for a previously-opened HDF5 file.
func (self *File) ReOpen() (*File, error) {
	hid := C.H5Freopen(self.id)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	return newFile(hid), nil
}
Beispiel #4
0
// Type returns an identifier for a copy of the datatype for a dataset.
func (t *Table) Type() (*Datatype, error) {
	hid := C.H5Dget_type(t.id)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	return copyDatatype(hid)
}
Beispiel #5
0
// MemberType returns the datatype of the specified member.
func (t *CompoundType) MemberType(mbr_idx int) (*Datatype, error) {
	hid := C.H5Tget_member_type(t.id, C.uint(mbr_idx))
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	return copyDatatype(hid)
}
Beispiel #6
0
// Copy creates an exact copy of a dataspace.
func (s *Dataspace) Copy() (*Dataspace, error) {
	hid := C.H5Scopy(s.id)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	o := newDataspace(hid)
	return o, err
}
Beispiel #7
0
// CreateDataspace creates a new dataspace of a specified type.
func CreateDataspace(class SpaceClass) (*Dataspace, error) {
	hid := C.H5Screate(C.H5S_class_t(class))
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	ds := newDataspace(hid)
	return ds, nil
}
Beispiel #8
0
// Copies an existing datatype.
func (t *Datatype) Copy() (*Datatype, error) {
	hid := C.H5Tcopy(t.id)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	o := NewDatatype(hid, t.rt)
	return o, err
}
Beispiel #9
0
// Creates a new property as an instance of a property list class.
// hid_t H5Pcreate(hid_t cls_id )
func NewPropList(cls_id PropType) (*PropList, error) {
	hid := C.H5Pcreate(C.hid_t(cls_id))
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	p := new_proplist(hid)
	return p, err
}
Beispiel #10
0
// Returns an identifier for a copy of the datatype for a dataset.
// hid_t H5Dget_type(hid_t dataset_id )
func (s *Dataset) Type() (*Datatype, error) {
	hid := C.H5Dget_type(s.id)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	dt := NewDatatype(hid, nil)
	return dt, err
}
Beispiel #11
0
func createDataset(id C.hid_t, name string, dtype *Datatype, dspace *Dataspace, dcpl *PropList) (*Dataset, error) {
	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)
	if err := h5err(C.herr_t(int(hid))); err != nil {
		return nil, err
	}
	return newDataset(hid), nil
}
Beispiel #12
0
// Copies an existing datatype.
// hid_t H5Tcopy( hid_t dtype_id )
func (t *DataType) Copy() (*DataType, error) {
	hid := C.H5Tcopy(t.id)
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	o := new_dtype(hid, t.rt)
	return o, err
}
Beispiel #13
0
// Returns an identifier for a copy of the datatype for a dataset.
// hid_t H5Dget_type(hid_t dataset_id )
func (t *Table) Type() (*DataType, error) {
	hid := C.H5Dget_type(t.id)
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	dt := new_dtype(hid, nil)
	return dt, err
}
Beispiel #14
0
func NewVarLenType(base_type *DataType) (*VarLenType, error) {
	hid := C.H5Tvlen_create(base_type.id)
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	dt := new_vltype(hid)
	return dt, err
}
Beispiel #15
0
// Returns the datatype of the specified member.
// hid_t H5Tget_member_type( hid_t dtype_id, unsigned field_idx )
func (t *CompType) MemberType(mbr_idx int) (*DataType, error) {
	hid := C.H5Tget_member_type(t.id, C.uint(mbr_idx))
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	dt := new_dtype(hid, t.rt.Field(mbr_idx).Type)
	return dt, nil
}
Beispiel #16
0
// Copy copies an existing PropList to create a new PropList.
func (p *PropList) Copy() (*PropList, error) {
	hid := C.H5Pcopy(p.id)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	o := newPropList(hid)
	return o, err
}
Beispiel #17
0
func openAttribute(id C.hid_t, name string) (*Attribute, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	hid := C.H5Aopen(id, c_name, P_DEFAULT.id)
	if err := h5err(C.herr_t(int(hid))); err != nil {
		return nil, err
	}
	return newAttribute(hid), nil
}
Beispiel #18
0
func openDataset(id C.hid_t, name string) (*Dataset, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	hid := C.H5Dopen2(id, c_name, P_DEFAULT.id)
	if err := h5err(C.herr_t(int(hid))); err != nil {
		return nil, err
	}
	return newDataset(hid), nil
}
Beispiel #19
0
// NewVarLenType creates a new VarLenType.
// base_type specifies the element type of the VarLenType.
func NewVarLenType(base_type *Datatype) (*VarLenType, error) {
	id := C.H5Tvlen_create(base_type.id)
	err := h5err(C.herr_t(int(id)))
	if err != nil {
		return nil, err
	}
	t := &VarLenType{Datatype{Location{Identifier{id}}}}
	runtime.SetFinalizer(t, (*VarLenType).finalizer)
	return t, err
}
Beispiel #20
0
// SimpleExtentDims returns dataspace dimension size and maximum size.
func (s *Dataspace) SimpleExtentDims() (dims, maxdims []uint, err error) {
	rank := s.SimpleExtentNDims()
	dims = make([]uint, rank)
	maxdims = make([]uint, rank)

	c_dims := (*C.hsize_t)(unsafe.Pointer(&dims[0]))
	c_maxdims := (*C.hsize_t)(unsafe.Pointer(&maxdims[0]))
	rc := C.H5Sget_simple_extent_dims(s.id, c_dims, c_maxdims)
	err = h5err(C.herr_t(rc))
	return
}
Beispiel #21
0
// Creates a new dataset at this location.
// hid_t H5Dcreate2( hid_t loc_id, const char *name, hid_t dtype_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id )
func (f *File) CreateDataSet(name string, dtype *DataType, dspace *DataSpace, dcpl *PropList) (*DataSet, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))
	hid := C.H5Dcreate2(f.id, c_name, dtype.id, dspace.id, P_DEFAULT.id, dcpl.id, P_DEFAULT.id)
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	dset := new_dataset(hid)
	return dset, err
}
Beispiel #22
0
func openGroup(id C.hid_t, name string, gapl_flag C.hid_t) (*Group, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	hid := C.H5Gopen2(id, c_name, gapl_flag)
	if err := h5err(C.herr_t(int(hid))); err != nil {
		return nil, err
	}
	g := &Group{Location{hid}}
	runtime.SetFinalizer(g, (*Group).finalizer)
	return g, nil
}
Beispiel #23
0
func createGroup(id C.hid_t, name string, link_flags, grp_c_flags, grp_a_flags int) (*Group, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	hid := C.H5Gcreate2(id, c_name, C.hid_t(link_flags), C.hid_t(grp_c_flags), P_DEFAULT.id)
	if err := h5err(C.herr_t(int(hid))); err != nil {
		return nil, err
	}
	g := &Group{Location{hid}}
	runtime.SetFinalizer(g, (*Group).finalizer)
	return g, nil
}
Beispiel #24
0
// OpenGroup opens an existing child group from this Group.
func (g *CommonFG) OpenGroup(name string) (*Group, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	hid := C.H5Gopen2(g.id, c_name, P_DEFAULT.id)
	if err := h5err(C.herr_t(int(hid))); err != nil {
		return nil, err
	}
	group := &Group{CommonFG{Location{Identifier{hid}}}}
	runtime.SetFinalizer(group, (*Group).finalizer)
	return group, nil
}
Beispiel #25
0
func openTable(id C.hid_t, name string) (*Table, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	hid := C.H5PTopen(id, c_name)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	table := newPacketTable(hid)
	return table, err
}
Beispiel #26
0
func NewArrayType(base_type *DataType, dims []int) (*ArrayType, error) {
	ndims := C.uint(len(dims))
	c_dims := (*C.hsize_t)(unsafe.Pointer(&dims[0]))

	hid := C.H5Tarray_create2(base_type.id, ndims, c_dims)
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	t := new_array_type(hid)
	return t, err
}
Beispiel #27
0
// Returns a new identifier for a previously-opened HDF5 file.
func (self *File) ReOpen() (f *File, err error) {
	f = nil
	err = nil

	hid := C.H5Freopen(self.id)
	err = togo_err(C.herr_t(int(hid)))
	if err != nil {
		return
	}
	f = new_file(hid)
	return
}
Beispiel #28
0
// Creates a new datatype.
// hid_t H5Tcreate( H5T_class_t class, size_tsize )
func CreateDataType(class TypeClass, size int) (t *DataType, err error) {
	t = nil
	err = nil

	hid := C.H5Tcreate(C.H5T_class_t(class), C.size_t(size))
	err = togo_err(C.herr_t(int(hid)))
	if err != nil {
		return
	}
	t = new_dtype(hid, _type_cls_to_go_type[class])
	return
}
Beispiel #29
0
// Opens an existing HDF5 file.
func OpenFile(name string, flags int) (*File, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	// FIXME: file props
	hid := C.H5Fopen(c_name, C.uint(flags), P_DEFAULT.id)
	err := h5err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	return newFile(hid), nil
}
Beispiel #30
0
// Opens an existing dataset.
// hid_t H5Dopen( hid_t loc_id, const char *name, hid_t dapl_id )
func (f *File) OpenDataSet(name string) (*DataSet, error) {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	hid := C.H5Dopen2(f.id, c_name, P_DEFAULT.id)
	err := togo_err(C.herr_t(int(hid)))
	if err != nil {
		return nil, err
	}
	dset := new_dataset(hid)
	return dset, err
}