Anonymous avatar Anonymous committed 5190169

updates for go1

Comments (0)

Files changed (25)

Makefile

-# Copyright 2009 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include ${GOROOT}/src/Make.inc
-
-all: install
-
-DIRS=\
-        pkg/hdf5\
-
-
-clean.dirs: $(addsuffix .clean, $(DIRS))
-install.dirs: $(addsuffix .install, $(DIRS))
-nuke.dirs: $(addsuffix .nuke, $(DIRS))
-test.dirs: $(addsuffix .test, $(TEST))
-bench.dirs: $(addsuffix .bench, $(BENCH))
-
-%.clean:
-	+cd $* && $(QUOTED_GOBIN)/gomake clean
-
-%.install:
-	+cd $* && $(QUOTED_GOBIN)/gomake install
-
-clean: clean.dirs
-
-install: install.dirs
-
-#-include ${GOROOT}/src/Make.deps
+go-hdf5
+=======
+
+Naive ``cgo`` bindings for the ``C-API`` of ``hdf5``.
+
+Documentation
+-------------
+
+http://go.pkgdoc.org/bitbucket.org/binet/go-hdf5/pkg/hdf5
+
+Example
+-------
+
+#. Hello world example::
+
+   package main
+   
+   import (
+   	// stdlib
+   	"fmt"
+   
+   	// local
+   	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
+   )
+   
+   func main() {
+   	fmt.Println("=== go-hdf5 ===")
+   	m,n,r,err := hdf5.GetLibVersion()
+   	if err != nil {
+   		fmt.Printf("** error ** %s\n", err)
+   		return
+   	}
+   	fmt.Printf("=== version: %d.%d.%d\n", m, n, r)
+   	fmt.Println("=== bye.")
+   }
+
+
+#. Writing/reading an ``hdf5`` with compound data::
+
+   package main
+
+   import (
+	"fmt"
+   
+	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
+   )
+
+   const (
+   	FNAME string = "SDScompound.h5"
+	DATASET string = "ArrayOfStructures"
+	MEMBER1 string = "A_name"
+	MEMBER2 string = "B_name"
+	MEMBER3 string = "C_name"
+	LENGTH int = 10
+	RANK int = 1
+   )
+
+   type s1_t struct {
+   	a int
+   	b float32
+   	c float64
+	d [3]int
+	e string
+   }
+
+   type s2_t struct {
+   	c float64
+   	a int
+   }
+
+   func main() {
+
+	// initialize data
+	// s1 := make([]s1_t, LENGTH)
+	// for i:=0; i<LENGTH; i++ {
+	// 	s1[i] = s1_t{a:i, b:float32(i*i), c:1./(float64(i)+1)}
+	// }
+	// fmt.Printf(":: data: %v\n", s1)
+	s1 := [LENGTH]s1_t{}
+	for i:=0; i<LENGTH; i++ {
+		s1[i] = s1_t{
+		a:i, 
+		b:float32(i*i), 
+		c:1./(float64(i)+1), 
+		d:[...]int{i,i*2,i*3},
+		e:fmt.Sprintf("--%d--", i),
+		}
+		//s1[i].d = []float64{float64(i), float64(2*i), 3.*i}}
+	}
+	fmt.Printf(":: data: %v\n", s1)
+	
+	// create data space
+	dims := []int{LENGTH}
+	space,err := hdf5.CreateSimpleDataSpace(dims, nil)
+	if err != nil {
+		panic(err)
+	}
+
+	// create the file
+	f,err := hdf5.CreateFile(FNAME, hdf5.F_ACC_TRUNC)
+	if err != nil {
+		panic(err)
+	}
+	defer f.Close()
+	fmt.Printf(":: file [%s] created (id=%d)\n", FNAME, f.Id())
+
+
+	// create the memory data type
+	var dtype *hdf5.DataType = hdf5.NewDataTypeFromValue(s1[0])
+	if dtype == nil {
+		panic("could not create a dtype")
+	}
+
+	// create the dataset
+	dset,err := f.CreateDataSet(DATASET, dtype, space, hdf5.P_DEFAULT)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Printf(":: dset (id=%d)\n", dset.Id())
+
+	// write data to the dataset
+	fmt.Printf(":: dset.Write...\n")
+	err = dset.Write(s1[:], dtype)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Printf(":: dset.Write... [ok]\n")
+
+	// release resources
+	dset.Close()
+	f.Close()
+
+	// open the file and the dataset
+	f, err = hdf5.OpenFile(FNAME, hdf5.F_ACC_RDONLY)
+	if err != nil {
+		panic(err)
+	}
+	dset,err = f.OpenDataSet(DATASET)
+	if err != nil {
+		panic(err)
+	}
+	
+	// read it back into a new slice
+	s2 := make([]s1_t, LENGTH)
+	dset.Read(s2, dtype)
+
+	// display the fields
+	fmt.Printf(":: data: %v\n", s2)
+
+	// release resources
+	dset.Close()
+	f.Close()
+   }
+

cmd/test-go-cpxcmpd.go

-package main
-
-import (
-	"fmt"
-
-	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
-)
-
-const (
-	FNAME string = "SDScompound.h5"
-	DATASET string = "ArrayOfStructures"
-	MEMBER1 string = "A_name"
-	MEMBER2 string = "B_name"
-	MEMBER3 string = "C_name"
-	LENGTH int = 10
-	RANK int = 1
-)
-
-type s1_t struct {
-	a int
-	b float32
-	c float64
-	d [3]int
-	e string
-}
-
-type s2_t struct {
-	c float64
-	a int
-}
-
-func main() {
-
-	// initialize data
-	// s1 := make([]s1_t, LENGTH)
-	// for i:=0; i<LENGTH; i++ {
-	// 	s1[i] = s1_t{a:i, b:float32(i*i), c:1./(float64(i)+1)}
-	// }
-	// fmt.Printf(":: data: %v\n", s1)
-	s1 := [LENGTH]s1_t{}
-	for i:=0; i<LENGTH; i++ {
-		s1[i] = s1_t{
-		a:i, 
-		b:float32(i*i), 
-		c:1./(float64(i)+1), 
-		d:[...]int{i,i*2,i*3},
-		e:fmt.Sprintf("--%d--", i),
-		}
-		//s1[i].d = []float64{float64(i), float64(2*i), 3.*i}}
-	}
-	fmt.Printf(":: data: %v\n", s1)
-	
-	// create data space
-	dims := []int{LENGTH}
-	space,err := hdf5.CreateSimpleDataSpace(dims, nil)
-	if err != nil {
-		panic(err)
-	}
-
-	// create the file
-	f,err := hdf5.CreateFile(FNAME, hdf5.F_ACC_TRUNC)
-	if err != nil {
-		panic(err)
-	}
-	defer f.Close()
-	fmt.Printf(":: file [%s] created (id=%d)\n", FNAME, f.Id())
-
-
-	// create the memory data type
-	var dtype *hdf5.DataType = hdf5.NewDataTypeFromValue(s1[0])
-	if dtype == nil {
-		panic("could not create a dtype")
-	}
-
-	// create the dataset
-	dset,err := f.CreateDataSet(DATASET, dtype, space, hdf5.P_DEFAULT)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf(":: dset (id=%d)\n", dset.Id())
-
-	// write data to the dataset
-	fmt.Printf(":: dset.Write...\n")
-	err = dset.Write(s1, dtype)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf(":: dset.Write... [ok]\n")
-
-	// release resources
-	dset.Close()
-	f.Close()
-
-	// open the file and the dataset
-	f, err = hdf5.OpenFile(FNAME, hdf5.F_ACC_RDONLY)
-	if err != nil {
-		panic(err)
-	}
-	dset,err = f.OpenDataSet(DATASET)
-	if err != nil {
-		panic(err)
-	}
-	
-	// read it back into a new slice
-	s2 := make([]s1_t, LENGTH)
-	dset.Read(s2, dtype)
-
-	// display the fields
-	fmt.Printf(":: data: %v\n", s2)
-
-	// release resources
-	dset.Close()
-	f.Close()
-}

cmd/test-go-cpxcmpd/test-go-cpxcmpd.go

+package main
+
+import (
+	"fmt"
+
+	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
+)
+
+const (
+	FNAME string = "SDScompound.h5"
+	DATASET string = "ArrayOfStructures"
+	MEMBER1 string = "A_name"
+	MEMBER2 string = "B_name"
+	MEMBER3 string = "C_name"
+	LENGTH int = 10
+	RANK int = 1
+)
+
+type s1_t struct {
+	a int
+	b float32
+	c float64
+	d [3]int
+	e string
+}
+
+type s2_t struct {
+	c float64
+	a int
+}
+
+func main() {
+
+	// initialize data
+	// s1 := make([]s1_t, LENGTH)
+	// for i:=0; i<LENGTH; i++ {
+	// 	s1[i] = s1_t{a:i, b:float32(i*i), c:1./(float64(i)+1)}
+	// }
+	// fmt.Printf(":: data: %v\n", s1)
+	s1 := [LENGTH]s1_t{}
+	for i:=0; i<LENGTH; i++ {
+		s1[i] = s1_t{
+		a:i, 
+		b:float32(i*i), 
+		c:1./(float64(i)+1), 
+		d:[...]int{i,i*2,i*3},
+		e:fmt.Sprintf("--%d--", i),
+		}
+		//s1[i].d = []float64{float64(i), float64(2*i), 3.*i}}
+	}
+	fmt.Printf(":: data: %v\n", s1)
+	
+	// create data space
+	dims := []int{LENGTH}
+	space,err := hdf5.CreateSimpleDataSpace(dims, nil)
+	if err != nil {
+		panic(err)
+	}
+
+	// create the file
+	f,err := hdf5.CreateFile(FNAME, hdf5.F_ACC_TRUNC)
+	if err != nil {
+		panic(err)
+	}
+	defer f.Close()
+	fmt.Printf(":: file [%s] created (id=%d)\n", FNAME, f.Id())
+
+
+	// create the memory data type
+	var dtype *hdf5.DataType = hdf5.NewDataTypeFromValue(s1[0])
+	if dtype == nil {
+		panic("could not create a dtype")
+	}
+
+	// create the dataset
+	dset,err := f.CreateDataSet(DATASET, dtype, space, hdf5.P_DEFAULT)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Printf(":: dset (id=%d)\n", dset.Id())
+
+	// write data to the dataset
+	fmt.Printf(":: dset.Write...\n")
+	err = dset.Write(s1[:], dtype)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Printf(":: dset.Write... [ok]\n")
+
+	// release resources
+	dset.Close()
+	f.Close()
+
+	// open the file and the dataset
+	f, err = hdf5.OpenFile(FNAME, hdf5.F_ACC_RDONLY)
+	if err != nil {
+		panic(err)
+	}
+	dset,err = f.OpenDataSet(DATASET)
+	if err != nil {
+		panic(err)
+	}
+	
+	// read it back into a new slice
+	s2 := make([]s1_t, LENGTH)
+	dset.Read(s2, dtype)
+
+	// display the fields
+	fmt.Printf(":: data: %v\n", s2)
+
+	// release resources
+	dset.Close()
+	f.Close()
+}

cmd/test-go-extend-ds.go

-package main
-
-import (
-	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
-
-	"fmt"
-)
-
-func main() {
-	
-	fname := "SDSextendible.h5"
-	//dsname:= "ExtendibleArray"
-	//NX := 10
-	//NY :=  5
-	//RANK:= 2
-
-	//dims := []int{3, 3} // dset dimensions at creation
-	//maxdims:= []int{hdf5.S_UNLIMITED, hdf5.S_UNLIMITED}
-
-	//mspace := hdf5.CreateDataSpace(dims, maxdims)
-
-	// create a new file
-	f,err := hdf5.CreateFile(fname, hdf5.F_ACC_TRUNC)
-	if err != nil {
-		panic(err)
-	}
-
-	fmt.Printf(":: file [%s] created\n", f.Name())
-
-}
-
-// EOF

cmd/test-go-extend-ds/test-go-extend-ds.go

+package main
+
+import (
+	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
+
+	"fmt"
+)
+
+func main() {
+	
+	fname := "SDSextendible.h5"
+	//dsname:= "ExtendibleArray"
+	//NX := 10
+	//NY :=  5
+	//RANK:= 2
+
+	//dims := []int{3, 3} // dset dimensions at creation
+	//maxdims:= []int{hdf5.S_UNLIMITED, hdf5.S_UNLIMITED}
+
+	//mspace := hdf5.CreateDataSpace(dims, maxdims)
+
+	// create a new file
+	f,err := hdf5.CreateFile(fname, hdf5.F_ACC_TRUNC)
+	if err != nil {
+		panic(err)
+	}
+
+	fmt.Printf(":: file [%s] created\n", f.Name())
+
+}
+
+// EOF

cmd/test-go-hdf5.go

-package main
-
-import (
-	// stdlib
-	"fmt"
-
-	// local
-	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
-)
-
-func main() {
-	fmt.Println("=== go-hdf5 ===")
-	m,n,r,err := hdf5.GetLibVersion()
-	if err != nil {
-		fmt.Printf("** error ** %s\n", err)
-		return
-	}
-	fmt.Printf("=== version: %d.%d.%d\n", m, n, r)
-	fmt.Println("=== bye.")
-}

cmd/test-go-hdf5/test-go-hdf5.go

+package main
+
+import (
+	// stdlib
+	"fmt"
+
+	// local
+	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
+)
+
+func main() {
+	fmt.Println("=== go-hdf5 ===")
+	m,n,r,err := hdf5.GetLibVersion()
+	if err != nil {
+		fmt.Printf("** error ** %s\n", err)
+		return
+	}
+	fmt.Printf("=== version: %d.%d.%d\n", m, n, r)
+	fmt.Println("=== bye.")
+}

cmd/test-go-table-01-readback.go

-package main
-
-import (
-	"fmt"
-
-	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
-)
-
-const (
-	FNAME string = "ex_table_01.h5"
-	TABLE_NAME string = "table"
-	NFIELDS int = 5
-	NRECORDS int = 8
-)
-
-type particle_t struct {
-	name string         //"Name"
-	lati int            "Latitude"
-	longi int           "Longitude"
-	pressure float32    "Pressure"
-	temperature float64 "Temperature"
-}
-
-func (p *particle_t) Equal(o *particle_t) bool {
-	return p.name == o.name && p.lati == o.lati && p.longi == o.longi && p.pressure == o.pressure && p.temperature == o.temperature
-}
-
-func main() {
-
-	// define an array of particles
-	p_data := []particle_t{
-		{"zero",   0, 0,  0.0,  0.},
-		{"one",   10, 10, 1.0, 10.},
-		{"two",   20, 20, 2.0, 20.},
-		{"three", 30, 30, 3.0, 30.},
-		{"four",  40, 40, 4.0, 40.},
-		{"five",  50, 50, 5.0, 50.},
-		{"six",   60, 60, 6.0, 60.},
-		{"seven", 70, 70, 7.0, 70.},
-	}
-	fmt.Printf(":: reference data: %v\n", p_data)
-
-	// open a file
-	f,err := hdf5.OpenFile(FNAME, hdf5.F_ACC_RDONLY)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf(":: file [%s] opened (id=%d)\n", f.Name(), f.Id())
-
-
-	// create a fixed-length packet table within the file
-	table, err := f.OpenTable(TABLE_NAME)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf(":: table [%s] opened (id=%d)\n", TABLE_NAME, 3)
-
-	// iterate through packets
-	for i := 0; i != NRECORDS; i++ {
-		//p := []particle_t{{}}
-		p := make([]particle_t, 1)
-		p[0].name = "+++++++    +"
-		err := table.Next(p)
-		if err != nil {
-			panic(err)
-		}
-		fmt.Printf(":: data[%d]: %v -> [%v]\n", i, p, p[0].Equal(&p_data[i]))
-	}
-
-	// reset index
-	table.CreateIndex()
-	dst_buf := make([]particle_t, NRECORDS)
-	err = table.ReadPackets(0, NRECORDS, dst_buf)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf(":: whole data: %v\n", dst_buf)
-
-	fmt.Printf(":: bye.\n")
-}

cmd/test-go-table-01-readback/test-go-table-01-readback.go

+package main
+
+import (
+	"fmt"
+
+	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
+)
+
+const (
+	FNAME string = "ex_table_01.h5"
+	TABLE_NAME string = "table"
+	NFIELDS int = 5
+	NRECORDS int = 8
+)
+
+type particle_t struct {
+	name string         //"Name"
+	lati int            "Latitude"
+	longi int           "Longitude"
+	pressure float32    "Pressure"
+	temperature float64 "Temperature"
+}
+
+func (p *particle_t) Equal(o *particle_t) bool {
+	return p.name == o.name && p.lati == o.lati && p.longi == o.longi && p.pressure == o.pressure && p.temperature == o.temperature
+}
+
+func main() {
+
+	// define an array of particles
+	p_data := []particle_t{
+		{"zero",   0, 0,  0.0,  0.},
+		{"one",   10, 10, 1.0, 10.},
+		{"two",   20, 20, 2.0, 20.},
+		{"three", 30, 30, 3.0, 30.},
+		{"four",  40, 40, 4.0, 40.},
+		{"five",  50, 50, 5.0, 50.},
+		{"six",   60, 60, 6.0, 60.},
+		{"seven", 70, 70, 7.0, 70.},
+	}
+	fmt.Printf(":: reference data: %v\n", p_data)
+
+	// open a file
+	f,err := hdf5.OpenFile(FNAME, hdf5.F_ACC_RDONLY)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Printf(":: file [%s] opened (id=%d)\n", f.Name(), f.Id())
+
+
+	// create a fixed-length packet table within the file
+	table, err := f.OpenTable(TABLE_NAME)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Printf(":: table [%s] opened (id=%d)\n", TABLE_NAME, 3)
+
+	// iterate through packets
+	for i := 0; i != NRECORDS; i++ {
+		//p := []particle_t{{}}
+		p := make([]particle_t, 1)
+		p[0].name = "+++++++    +"
+		err := table.Next(p)
+		if err != nil {
+			panic(err)
+		}
+		fmt.Printf(":: data[%d]: %v -> [%v]\n", i, p, p[0].Equal(&p_data[i]))
+	}
+
+	// reset index
+	table.CreateIndex()
+	dst_buf := make([]particle_t, NRECORDS)
+	err = table.ReadPackets(0, NRECORDS, dst_buf)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Printf(":: whole data: %v\n", dst_buf)
+
+	fmt.Printf(":: bye.\n")
+}

cmd/test-go-table-01.go

-package main
-
-import (
-	"fmt"
-
-	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
-)
-
-const (
-	FNAME string = "ex_table_01.h5"
-	TABLE_NAME string = "table"
-	NFIELDS int = 5
-	NRECORDS int = 8
-)
-
-type particle_t struct {
-	name string         //"Name"
-	lati int            "Latitude"
-	longi int           "Longitude"
-	pressure float32    "Pressure"
-	temperature float64 "Temperature"
-	isthep []int
-	jmohep [2][2]int
-}
-
-func main() {
-
-	// define an array of particles
-	p_data := []particle_t{
-		{"zero",   0, 0,  0.0,  0., []int{0,0}, [2][2]int{{0,0},{0,0}}},
-		{"one",   10, 10, 1.0, 10., []int{0,0}, [2][2]int{{1,0},{0,1}}},
-		{"two",   20, 20, 2.0, 20., []int{0,0}, [2][2]int{{2,0},{0,2}}},
-		{"three", 30, 30, 3.0, 30., []int{0,0}, [2][2]int{{3,0},{0,3}}},
-		{"four",  40, 40, 4.0, 40., []int{0,0}, [2][2]int{{4,0},{0,4}}},
-		{"five",  50, 50, 5.0, 50., []int{0,0}, [2][2]int{{5,0},{0,5}}},
-		{"six",   60, 60, 6.0, 60., []int{0,0}, [2][2]int{{6,0},{0,6}}},
-		{"seven", 70, 70, 7.0, 70., []int{0,0}, [2][2]int{{7,0},{0,7}}},
-	}
-
-	chunk_size := 10
-	compress := 0
-
-	// create a new file using default properties
-	f,err := hdf5.CreateFile(FNAME, hdf5.F_ACC_TRUNC)
-	if err != nil {
-		panic(err)
-	}
-	defer f.Close()
-	fmt.Printf(":: file [%s] created (id=%d)\n", FNAME, f.Id())
-
-
-	// create a fixed-length packet table within the file
-	table, err := f.CreateTableFrom(
-		TABLE_NAME, particle_t{}, chunk_size, compress)
-	if err != nil {
-		panic(err)
-	}
-	defer table.Close()
-	fmt.Printf(":: table [%s] created (id=%d)\n", TABLE_NAME, 3)
-
-	// write one packet to the packet table
-	err = table.Append(p_data[0])
-	if err != nil {
-		panic(err)
-	}
-
-	// write several packets
-	err = table.Append(p_data[1:])
-	if err != nil {
-		panic(err)
-	}
-
-	// get the number of packets
-	n, err := table.NumPackets()
-	if err != nil {
-		panic(err)
-	}
-	// should be NRECORDS
-	fmt.Printf(":: nbr entries: %d\n", n)
-	if n != NRECORDS {
-		panic("inconsistent number of entries")
-	}
-
-	// iterate through packets
-	for i := 0; i != n; i++ {
-		//p := []particle_t{{}}
-		p := make([]particle_t, 1)
-		err := table.Next(p)
-		if err != nil {
-			panic(err)
-		}
-		fmt.Printf(":: data[%d]: %v\n", i, p)
-	}
-
-	// reset index
-	table.CreateIndex()
-	dst_buf := make([]particle_t, NRECORDS)
-	err = table.ReadPackets(0, NRECORDS, dst_buf)
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf(":: whole data: %v\n", dst_buf)
-
-	fmt.Printf(":: bye.\n")
-}

cmd/test-go-table-01/test-go-table-01.go

+package main
+
+import (
+	"fmt"
+
+	"bitbucket.org/binet/go-hdf5/pkg/hdf5"
+)
+
+const (
+	FNAME      string = "ex_table_01.h5"
+	TABLE_NAME string = "table"
+	NFIELDS    int    = 5
+	NRECORDS   int    = 8
+)
+
+type particle_t struct {
+	name        string  //"Name"
+	lati        int     "Latitude"
+	longi       int     "Longitude"
+	pressure    float32 "Pressure"
+	temperature float64 "Temperature"
+	isthep      []int
+	jmohep      [2][2]int
+}
+
+func main() {
+
+	// define an array of particles
+	p_data := []particle_t{
+		{"zero", 0, 0, 0.0, 0., []int{0, 0}, [2][2]int{{0, 0}, {0, 0}}},
+		{"one", 10, 10, 1.0, 10., []int{0, 0}, [2][2]int{{1, 0}, {0, 1}}},
+		{"two", 20, 20, 2.0, 20., []int{0, 0}, [2][2]int{{2, 0}, {0, 2}}},
+		{"three", 30, 30, 3.0, 30., []int{0, 0}, [2][2]int{{3, 0}, {0, 3}}},
+		{"four", 40, 40, 4.0, 40., []int{0, 0}, [2][2]int{{4, 0}, {0, 4}}},
+		{"five", 50, 50, 5.0, 50., []int{0, 0}, [2][2]int{{5, 0}, {0, 5}}},
+		{"six", 60, 60, 6.0, 60., []int{0, 0}, [2][2]int{{6, 0}, {0, 6}}},
+		{"seven", 70, 70, 7.0, 70., []int{0, 0}, [2][2]int{{7, 0}, {0, 7}}},
+	}
+
+	chunk_size := 10
+	compress := 0
+
+	// create a new file using default properties
+	f, err := hdf5.CreateFile(FNAME, hdf5.F_ACC_TRUNC)
+	if err != nil {
+		panic(err)
+	}
+	defer f.Close()
+	fmt.Printf(":: file [%s] created (id=%d)\n", FNAME, f.Id())
+
+	// create a fixed-length packet table within the file
+	table, err := f.CreateTableFrom(
+		TABLE_NAME, particle_t{}, chunk_size, compress)
+	if err != nil {
+		panic(err)
+	}
+	defer table.Close()
+	fmt.Printf(":: table [%s] created (id=%d)\n", TABLE_NAME, table.Id())
+
+	if !table.IsValid() {
+		panic("table is invalid")
+	}
+
+	// write one packet to the packet table
+	err = table.Append(p_data[0])
+	if err != nil {
+		panic(err)
+	}
+
+	// write several packets
+	err = table.Append(p_data[1:])
+	if err != nil {
+		panic(err)
+	}
+
+	// get the number of packets
+	n, err := table.NumPackets()
+	if err != nil {
+		panic(err)
+	}
+	// should be NRECORDS
+	fmt.Printf(":: nbr entries: %d\n", n)
+	if n != NRECORDS {
+		panic("inconsistent number of entries")
+	}
+
+	// iterate through packets
+	for i := 0; i != n; i++ {
+		//p := []particle_t{{}}
+		p := make([]particle_t, 1)
+		err := table.Next(p)
+		if err != nil {
+			panic(err)
+		}
+		fmt.Printf(":: data[%d]: %v\n", i, p)
+	}
+
+	// reset index
+	table.CreateIndex()
+	dst_buf := make([]particle_t, NRECORDS)
+	err = table.ReadPackets(0, NRECORDS, dst_buf)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Printf(":: whole data: %v\n", dst_buf)
+
+	fmt.Printf(":: bye.\n")
+}

pkg/hdf5/Makefile

-# Copyright 2009 The Go Authors.  All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include $(GOROOT)/src/Make.inc
-
-TARG=bitbucket.org/binet/go-hdf5/pkg/hdf5
-
-CGO_LDFLAGS=-lhdf5 -lhdf5_hl
-
-CGOFILES=\
-	hdf5.go\
-    hdf5_hl.go\
-    h5d.go\
-    h5f.go\
-    h5g.go\
-    h5p.go\
-    h5s.go\
-    h5t.go\
-    h5t_shim.go\
-    h5pt.go\
-
-
-
-include $(GOROOT)/src/Make.pkg
-
-%: install %.go
-	$(GC) $*.go
-	$(LD) -o $@ $*.$O

pkg/hdf5/cgoflags.go

+package hdf5
+
+// #cgo LDFLAGS: -lhdf5 -lhdf5_hl
+// #include "hdf5.h"
+import "C"
+
+// EOF
 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5
- #include "hdf5.h"
-
- #include <stdlib.h>
- #include <string.h>
-*/
+// #include "hdf5.h"
+// #include <stdlib.h>
+// #include <string.h>
 import "C"
 
 import (
 	switch v.Kind() {
 
 	case reflect.Slice:
-		slice := (*reflect.SliceHeader)(unsafe.Pointer(v.UnsafeAddr()))
-		addr = slice.Data
+		addr = v.Pointer()
 
 	case reflect.String:
 		str := (*reflect.StringHeader)(unsafe.Pointer(v.UnsafeAddr()))
 	switch v.Kind() {
 
 	case reflect.Slice:
-		slice := (*reflect.SliceHeader)(unsafe.Pointer(v.UnsafeAddr()))
-		addr = slice.Data
+		addr = v.Pointer()
 
 	case reflect.String:
 		str := (*reflect.StringHeader)(unsafe.Pointer(v.UnsafeAddr()))
 	err := togo_err(rc)
 	return err
 }
+
 // EOF
 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5 -lhdf5_hl
- #include "hdf5.h"
- #include "hdf5_hl.h"
-
- #include <stdlib.h>
- #include <string.h>
-*/
+// #include "hdf5.h"
+// #include "hdf5_hl.h"
+// #include <stdlib.h>
+// #include <string.h>
 import "C"
 
 import (
 
 // Creates a packet table to store fixed-length packets.
 // hid_t H5PTcreate_fl( hid_t loc_id, const char * dset_name, hid_t dtype_id, hsize_t chunk_size, int compression )
-func (f *File) CreateTableFrom(name string, dtype interface{}, chunk_size, compression int) (*Table, error) {
+func (f *File) CreateTableFrom(name string, dtype interface{}, chunk_size, compression int) (table *Table, err error) {
 	switch dt := dtype.(type) {
 	case reflect.Type:
 		hdf_dtype := new_dataTypeFromType(dt)
-		return f.CreateTable(name, hdf_dtype, chunk_size, compression)
+		table, err = f.CreateTable(name, hdf_dtype, chunk_size, compression)
+		return
 
 	case *DataType:
-		return f.CreateTable(name, dt, chunk_size, compression)
+		table, err = f.CreateTable(name, dt, chunk_size, compression)
+		return
 
 	default:
 		hdf_dtype := new_dataTypeFromType(reflect.TypeOf(dtype))
-		return f.CreateTable(name, hdf_dtype, chunk_size, compression)
+		table, err = f.CreateTable(name, hdf_dtype, chunk_size, compression)
+		return
 	}
 	panic("unreachable")
 	return nil, errors.New("unreachable")
 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5 -lhdf5_hl
- #include "hdf5.h"
- #include "hdf5_hl.h"
-
- #include <stdlib.h>
- #include <string.h>
-*/
+// #include "hdf5.h"
+// #include "hdf5_hl.h"
+// #include <stdlib.h>
+// #include <string.h>
 import "C"
 
 import (
 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5
- #include "hdf5.h"
-
- #include <stdlib.h>
- #include <string.h>
-
- hid_t _go_hdf5_H5P_DEFAULT() { return H5P_DEFAULT; }
-*/
+// #include "hdf5.h"
+// #include <stdlib.h>
+// #include <string.h>
+// inline static
+// hid_t _go_hdf5_H5P_DEFAULT() { return H5P_DEFAULT; }
 import "C"
 
 import (
 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5 -lhdf5_hl
- #include "hdf5.h"
- #include "hdf5_hl.h"
-
- #include <stdlib.h>
- #include <string.h>
-*/
+// #include "hdf5.h"
+// #include "hdf5_hl.h"
+// #include <stdlib.h>
+// #include <string.h>
 import "C"
 
 import (
 	return false
 }
 
+func (t *Table) Id() int {
+	return int(t.id)
+}
+
 // Reads a number of packets from a packet table.
 // herr_t H5PTread_packets( hid_t table_id, hsize_t start, size_t nrecords, void* data)
 func (t *Table) ReadPackets(start, nrecords int, data interface{}) error {
 		c_data = unsafe.Pointer(v.UnsafeAddr())
 
 	case reflect.Slice:
-		//fmt.Printf("-->slice\n")
+		fmt.Printf("-->slice\n")
 		c_nrecords = C.size_t(v.Len())
 		slice := (*reflect.SliceHeader)(unsafe.Pointer(v.UnsafeAddr()))
 		c_data = unsafe.Pointer(slice.Data)
+		//c_data = unsafe.Pointer(v.Index(0).Addr().UnsafeAddr())
+		//c_data = unsafe.Pointer(&c_data)
 
 	case reflect.String:
 		c_nrecords = C.size_t(v.Len())
 		c_data = unsafe.Pointer(str.Data)
 
 	case reflect.Ptr:
-		//fmt.Printf("-->ptr\n")
+		//fmt.Printf("-->ptr %v\n", v.Elem())
 		c_nrecords = C.size_t(1)
 		c_data = unsafe.Pointer(v.Elem().UnsafeAddr())
 
 		c_data = unsafe.Pointer(v.UnsafeAddr())
 	}
 
-	//fmt.Printf(":: append(%d, %d)\n", c_nrecords, c_data)
+	fmt.Printf(":: append(%d, %d, %v)\n", c_nrecords, c_data, t.id)
 	err := C.H5PTappend(t.id, c_nrecords, c_data)
-	//fmt.Printf(":: append(%d, %d) -> %v\n", c_nrecords, c_data, err)
+	fmt.Printf(":: append(%d, %d) -> %v\n", c_nrecords, c_data, err)
 	return togo_err(err)
 }
 
 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5
- #include "hdf5.h"
-
- #include <stdlib.h>
- #include <string.h>
-*/
+// #include "hdf5.h"
+// #include <stdlib.h>
+// #include <string.h>
 import "C"
 
 import (
 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5
- #include "hdf5.h"
-
- #include <stdlib.h>
- #include <string.h>
-
-*/
+// #include "hdf5.h"
+// #include <stdlib.h>
+// #include <string.h>
 import "C"
 
 import (

pkg/hdf5/h5t_shim.go

 package hdf5
 
 /*
- #cgo LDFLAGS: -lhdf5
  #include "hdf5.h"
 
  #include <stdlib.h>
  hid_t _go_hdf5_H5T_NATIVE_INT64() { return H5T_NATIVE_INT64; }
  hid_t _go_hdf5_H5T_NATIVE_UINT64() { return H5T_NATIVE_UINT64; }
 
- //#cgo CFLAGS: -I/home/binet/dev/atlas/nmssm/ana/src/externals/go-hdf5/pkg
  //#include "cgo_h5t_conv.h"
  */
 import "C"
 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5
- #include "hdf5.h"
-
- #include <stdlib.h>
- #include <string.h>
-*/
+// #include "hdf5.h"
+// #include <stdlib.h>
+// #include <string.h>
 import "C"
 
 import (

pkg/hdf5/hdf5_hl.go

 package hdf5
 
-/*
- #cgo LDFLAGS: -lhdf5 -lhdf5_hl
- #include "hdf5.h"
- #include "hdf5_hl.h"
-
- #include <stdlib.h>
- #include <string.h>
-*/
+// #include "hdf5.h"
+// #include "hdf5_hl.h"
+// #include <stdlib.h>
+// #include <string.h>
 import "C"
 
-import
-
-//"io"
-"reflect"
+import (
+	//"io"
+	"reflect"
+)
 
 type Encoder interface {
 	Encode(v interface{}) error

wscript

-#
-
-top = '.'
-out = '__build__'
-
-def options(ctx):
-    pass
-
-def configure(ctx):
-    ctx.load('go')
-    
-def build(ctx):
-
-    ctx(
-        features='cgopackage',
-        name ='go-hdf5',
-        source='''\
-        pkg/hdf5/hdf5.go
-        pkg/hdf5/hdf5_hl.go
-        pkg/hdf5/h5d.go
-        pkg/hdf5/h5f.go
-        pkg/hdf5/h5g.go
-        pkg/hdf5/h5p.go
-        pkg/hdf5/h5s.go
-        pkg/hdf5/h5t.go
-        pkg/hdf5/h5t_shim.go
-        pkg/hdf5/h5pt.go
-        ''',
-        target='bitbucket.org/binet/go-hdf5/pkg/hdf5',
-        use = [
-            'hdf5',
-            'hdf5_hl',
-            ],
-        )
-
-    ctx(
-        features='go goprogram',
-        name   = 'test-go-hdf5',
-        source ='cmd/test-go-hdf5.go',
-        target = 'test-go-hdf5',
-        use = ['go-hdf5',],
-        )
-
-    ctx(
-        features='go goprogram',
-        name   = 'test-go-cpxcmpd',
-        source ='cmd/test-go-cpxcmpd.go',
-        target = 'test-go-cpxcmpd',
-        use = ['go-hdf5',],
-        )
-
-    ctx(
-        features='go goprogram',
-        name   = 'test-go-extend-ds',
-        source ='cmd/test-go-extend-ds.go',
-        target = 'test-go-extend-ds',
-        use = ['go-hdf5',],
-        )
-
-    ctx(
-        features='go goprogram',
-        name   = 'test-go-table-01',
-        source ='cmd/test-go-table-01.go',
-        target = 'test-go-table-01',
-        use = ['go-hdf5',],
-        )
-
-    ctx(
-        features='go goprogram',
-        name   = 'test-go-table-01-readback',
-        source ='cmd/test-go-table-01-readback.go',
-        target = 'test-go-table-01-readback',
-        use = ['go-hdf5',],
-        )
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.