Ejemplo n.º 1
0
func main() {

	displayFlagPtr := flag.Bool("d", false, "Prints autorectification data to screen instead of file")
	manualFlagPtr := flag.Bool("m", false, "Takes optical parameters from user instead of defaults")
	overwriteFlagPtr := flag.Bool("o", false, "Overwrites existing output file")
	flag.Parse()

	//check for correct argument length
	if flag.NArg() != 2 {
		fmt.Println("Expecting two non-flag arguments.")
		fmt.Println("Please see the documentation for details.")
		os.Exit(1)
	}
	inputFilePath := flag.Arg(0)
	outputFilePath := flag.Arg(1)

	//file handling
	//check if input file exists and is correct format

	if _, err := os.Stat(inputFilePath); err != nil {
		fmt.Println("File does not exist at location", inputFilePath)
		os.Exit(1)
	}
	if !hdf5.IsHdf5(inputFilePath) {
		fmt.Println("File is not HDF5(may be corrupted)")
	}
	//input file checks done

	if _, err := os.Stat(outputFilePath); err == nil && !*overwriteFlagPtr {
		fmt.Println("Output file exists and overwrite flag is not set.")
		os.Exit(1)
	}
	//output file checks are done
	//open file
	if inputFile, err := hdf5.OpenFile(inputFile, F_ACC_RDONLY); err !=nil {
		fmt.Println("There was an error opening the input file. Exiting")
		os.Exit(1)
	}

	if imagesGroup, err := hdf5.OpenGroup("images",0)



	if *manualFlagPtr {
		//get optical parameters from input
	} else {
		//get optical parameters from file attribute
	}

	if *displayFlagPtr {
		fmt.Println("Display flag was used")
	}

}
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")
}
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()
}