-
Notifications
You must be signed in to change notification settings - Fork 16
/
hdf5.go
82 lines (69 loc) · 1.53 KB
/
hdf5.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package hdf5
// #include "hdf5.h"
import "C"
import (
"fmt"
)
// init initializes the hdf5 library
func init() {
err := h5err(C.H5open())
if err != nil {
err_str := fmt.Sprintf("pb calling H5open(): %s", err)
panic(err_str)
}
}
// hdferror wraps hdf5 int-based error codes
type h5error struct {
code int
}
func (h h5error) Error() string {
return fmt.Sprintf("code %d", h.code)
}
func h5err(herr C.herr_t) error {
if herr < 0 {
return h5error{code: int(herr)}
}
return nil
}
func checkID(hid C.hid_t) error {
if hid < 0 {
return h5error{code: int(hid)}
}
return nil
}
// Close flushes all data to disk, closes all open identifiers, and cleans up memory.
// It should generally be called before your application exits.
func Close() error {
return h5err(C.H5close())
}
// Version represents the currently used hdf5 library version
type Version struct {
Major uint
Minor uint
Release uint
}
func (v Version) String() string {
return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Release)
}
// LibVersion returns version information for the HDF5 library.
func LibVersion() (Version, error) {
var maj, min, rel C.uint
var v Version
err := h5err(C.H5get_libversion(&maj, &min, &rel))
if err == nil {
v.Major = uint(maj)
v.Minor = uint(min)
v.Release = uint(rel)
}
return v, err
}
// GarbageCollect collects garbage on all free-lists of all types.
func GarbageCollect() error {
return h5err(C.H5garbage_collect())
}
// Object represents an hdf5 object.
type Object interface {
Name() string
Id() int
File() *File
}