예제 #1
0
파일: h5t.go 프로젝트: pombredanne/go-hdf5
// Determines whether datatype is a variable-length string.
// htri_t H5Tis_variable_str( hid_t dtype_id )
func (vl *VarLenType) IsVariableStr() bool {
	o := int(C.H5Tis_variable_str(vl.id))
	if o > 0 {
		return true
	}
	return false
}
예제 #2
0
파일: h5d.go 프로젝트: pauh/go-hdf5
// Reads raw data from a dataset into a buffer.
// herr_t H5Dread(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, void * buf )
func (s *Dataset) Read(data interface{}, dtype *Datatype) error {
	var addr uintptr
	var tmp_slice []byte
	post_process := false
	v := reflect.ValueOf(data)

	//fmt.Printf(":: read[%s]...\n", v.Kind())
	switch v.Kind() {

	case reflect.Array:
		addr = v.UnsafeAddr()

	case reflect.Slice:
		if v.Index(0).Kind() == reflect.String && C.H5Tis_variable_str(dtype.id) == 0 {
			tmp_slice = make([]byte, v.Len()*int(dtype.Size()))
			addr = reflect.ValueOf(tmp_slice).Pointer()
			post_process = true
		} else {
			addr = v.Pointer()
		}

	case reflect.String:
		str := (*reflect.StringHeader)(unsafe.Pointer(v.UnsafeAddr()))
		addr = str.Data

	case reflect.Ptr:
		addr = v.Pointer()

	default:
		addr = v.UnsafeAddr()
	}

	rc := C.H5Dread(s.id, dtype.id, 0, 0, 0, unsafe.Pointer(addr))
	err := h5err(rc)

	if err == nil && post_process {
		str_len := int(dtype.Size())
		p := 0
		for i := 0; i < v.Len(); i++ {
			str := tmp_slice[p : p+str_len]
			n := bytes.Index(str, []byte{0})
			if n < 0 {
				n = str_len
			}
			v.Index(i).SetString(string(str[:n]))
			p += str_len
		}
	}

	return err
}
예제 #3
0
파일: h5t.go 프로젝트: jonlawlor/go-hdf5
// IsVariableStr determines whether the VarLenType is a string.
func (vl *VarLenType) IsVariableStr() bool {
	return C.H5Tis_variable_str(vl.id) > 0
}