-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (38 loc) · 889 Bytes
/
main.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
// Package mat provides a reader and writer of MATLAB MAT-files.
//
// http://www.mathworks.com/help/pdf_doc/matlab/apiext.pdf
package mat
// #cgo LDFLAGS: -lmat -lmx
// #include <string.h>
// #include <mat.h>
import "C"
import (
"errors"
"unsafe"
)
const (
is64bit = uint64(^uint(0)) == ^uint64(0)
)
// File represents a file.
type File struct {
mat *C.MATFile
}
// Open opens a file for reading and writing.
//
// http://www.mathworks.com/help/matlab/apiref/matopen.html
func Open(path string, mode string) (*File, error) {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
cmode := C.CString(mode)
defer C.free(unsafe.Pointer(cmode))
file := &File{mat: C.matOpen(cpath, cmode)}
if file.mat == nil {
return nil, errors.New("cannot open the file")
}
return file, nil
}
// Close closes the file.
func (f *File) Close() {
C.matClose(f.mat)
f.mat = nil
}