Exemplo n.º 1
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
}
Exemplo n.º 2
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
}
Exemplo n.º 3
0
func createDataset(id C.hid_t, name string, dtype *Datatype, dspace *Dataspace, dcpl *PropList) (*Dataset, error) {
	dtype, err := dtype.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)
	if err := checkID(hid); err != nil {
		return nil, err
	}
	return newDataset(hid), nil
}
Exemplo n.º 4
0
Arquivo: put.go Projeto: postfix/hdf5
// Put writes data into the file.
func (f *File) Put(name string, something interface{}, dimensions ...uint) error {
	object := newObject()
	defer object.free()

	if err := initializeToPut(object, reflect.ValueOf(something), dimensions...); err != nil {
		return err
	}

	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	one := C.hsize_t(1)
	sid := C.H5Screate_simple(1, (*C.hsize_t)(unsafe.Pointer(&one)), nil)
	if sid < 0 {
		return errors.New("cannot create a data space")
	}
	defer C.H5Sclose(sid)

	if result := C.H5Lexists(f.fid, cname, C.H5P_DEFAULT); result < 0 {
		return errors.New("cannot check if the name already exists")
	} else if result > 0 && C.H5Ldelete(f.fid, cname, C.H5P_DEFAULT) < 0 {
		return errors.New("cannot overwrite an existing dataset")
	}

	did := C.H5Dcreate2(f.fid, cname, object.tid, sid, C.H5P_DEFAULT, C.H5P_DEFAULT, C.H5P_DEFAULT)
	if did < 0 {
		return errors.New("cannot create a dataset")
	}
	defer C.H5Dclose(did)

	if C.H5Dwrite(did, object.tid, C.H5S_ALL, C.H5S_ALL, C.H5P_DEFAULT, object.data) < 0 {
		return errors.New("cannot write the dataset into the file")
	}

	return nil
}