Пример #1
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
}
Пример #2
0
// NewArrayType creates a new ArrayType.
// base_type specifies the element type of the array.
// dims specify the dimensions of the array.
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)
	if err := checkID(hid); err != nil {
		return nil, err
	}
	t := &ArrayType{Datatype{Location{Identifier{hid}}}}
	runtime.SetFinalizer(t, (*ArrayType).finalizer)
	return t, nil
}
Пример #3
0
func initializeScalarToPut(object *object, value reflect.Value) error {
	pointer := reflect.New(value.Type())
	reflect.Indirect(pointer).Set(value)

	object.data = unsafe.Pointer(pointer.Pointer())

	bid, ok := kindTypeMapping[value.Kind()]
	if !ok {
		return errors.New("encountered an unsupported datatype")
	}

	one := C.hsize_t(1)
	object.tid = C.H5Tarray_create2(bid, 1, (*C.hsize_t)(unsafe.Pointer(&one)))
	if object.tid < 0 {
		return errors.New("cannot create an array datatype")
	}

	return nil
}
Пример #4
0
func initializeSliceToPut(object *object, value reflect.Value, dimensions ...uint) error {
	object.data = unsafe.Pointer(value.Pointer())
	object.flag |= flagVariableLength

	bid, ok := kindTypeMapping[value.Type().Elem().Kind()]
	if !ok {
		return errors.New("encountered an unsupported datatype")
	}

	nd := len(dimensions)

	if nd == 0 {
		nd, dimensions = 1, []uint{uint(value.Len())}
	}

	length := uint(1)
	for i := range dimensions {
		length *= dimensions[i]
	}
	if length != uint(value.Len()) {
		return errors.New("the dimensions do not match")
	}

	// NOTE: The C version of HDF5 adheres to the row-major order. This
	// packages, however, favors the column-major order.
	//
	// http://www.hdfgroup.org/HDF5/doc/UG/UG_frame12Dataspaces.html
	for i := 0; i < nd/2; i++ {
		dimensions[i], dimensions[nd-1-i] = dimensions[nd-1-i], dimensions[i]
	}

	object.tid = C.H5Tarray_create2(bid, C.uint(nd), (*C.hsize_t)(unsafe.Pointer(&dimensions[0])))
	if object.tid < 0 {
		return errors.New("cannot create an array datatype")
	}

	return nil
}