Ejemplo n.º 1
0
func main() {
	flag.Parse()
	f, err := hdf5.CreateFile("event.h5", hdf5.F_ACC_TRUNC)
	if err != nil {
		panic(err)
	}
	tree0(f)
	f.Close()
}
Ejemplo n.º 2
0
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())

}
Ejemplo n.º 3
0
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()
}
Ejemplo n.º 4
0
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")
}