Ejemplo n.º 1
0
// Adds a new member to a compound datatype.
// herr_t H5Tinsert( hid_t dtype_id, const char * name, size_t offset, hid_t field_id )
func (t *CompType) Insert(name string, offset int, field *DataType) error {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))
	//fmt.Printf("inserting [%s] at offset:%d (id=%d)...\n", name, offset, field.id)
	err := C.H5Tinsert(t.id, c_name, C.size_t(offset), field.id)
	return togo_err(err)
}
Ejemplo n.º 2
0
Archivo: put.go Proyecto: postfix/hdf5
func initializeStructToPut(object *object, value reflect.Value) error {
	typo := value.Type()
	size := C.size_t(typo.Size())

	object.data = C.malloc(size)
	if object.data == nil {
		return errors.New("cannot allocate memory")
	}
	object.flag |= flagOwnedMemory

	object.tid = C.H5Tcreate(C.H5T_COMPOUND, size)
	if object.tid < 0 {
		return errors.New("cannot create a compound datatype")
	}

	count := typo.NumField()

	for i := 0; i < count; i++ {
		field := typo.Field(i)
		if len(field.PkgPath) > 0 {
			continue
		}

		o := object.new()
		if err := initializeToPut(o, value.Field(i)); err != nil {
			return err
		}

		address := unsafe.Pointer(uintptr(object.data) + uintptr(field.Offset))

		if o.flag&flagVariableLength != 0 {
			tid := C.H5Tvlen_create(o.tid)
			if tid < 0 {
				return errors.New("cannnot create a variable-length datatype")
			}

			// NOTE: It is assumed here that sizeof(hvl_t) <= v.Type().Size().
			h := (*C.hvl_t)(address)
			h.len, h.p = 1, o.data

			o = object.new()
			o.tid = tid
		} else {
			C.memcpy(address, o.data, C.size_t(value.Field(i).Type().Size()))
		}

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

		if C.H5Tinsert(object.tid, cname, C.size_t(field.Offset), o.tid) < 0 {
			return errors.New("cannot construct a compound datatype")
		}
	}

	return nil
}
Ejemplo n.º 3
0
// Insert adds a new member to a compound datatype.
func (t *CompoundType) Insert(name string, offset int, field *Datatype) error {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))
	return h5err(C.H5Tinsert(t.id, cname, C.size_t(offset), field.id))
}