Exemple #1
0
func main() {
	t := time.Now()
	var l LC
	fn := os.Args[1]
	if err := lineio.Read(fn, &l); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s has %d non-skipped lines (elapsed time:%s)\n", fn, l, time.Since(t))
}
Exemple #2
0
func doOne(infn, outfn string, zmin, zmax float64, dist, fkp *spline.Spline, minpos, maxpos *Pos) error {
	var err error
	var r, theta, phi float64
	var p Pos
	var arr RDZWArr

	if err = lineio.Read(infn, &arr); err != nil {
		return err
	}

	gg, err := os.Create(outfn)
	if err != nil {
		return err
	}
	defer gg.Close()

	ind := 1
	maxz := -1.0
	minz := 10.0
	elim := 0
	for ii := range arr {
		switch {
		case arr[ii].z > maxz:
			maxz = arr[ii].z
		case arr[ii].z < minz:
			minz = arr[ii].z
		}
		if (arr[ii].z < zmin) || (arr[ii].z >= zmax) {
			elim++
			continue
		}
		theta = (math.Pi / 180) * (90 - arr[ii].dec)
		phi = (math.Pi / 180) * arr[ii].ra
		if r, err = dist.Eval(arr[ii].z); err != nil {
			panic("Error in dist spline " + infn)
		}
		if arr[ii].w, err = fkp.Eval(arr[ii].z); err != nil {
			panic("Error in fkp spline in " + infn)
		}
		p[0] = r * math.Sin(theta) * math.Cos(phi)
		p[1] = r * math.Sin(theta) * math.Sin(phi)
		p[2] = r * math.Cos(theta)
		_, err = fmt.Fprintf(gg, "%10.4f %10.4f %10.4f %7.4f %8d\n", p[0], p[1], p[2], arr[ii].w, ind)
		if err != nil {
			panic("Error while writing file")
		}
		minpos.Min(p)
		maxpos.Max(p)
		ind++
	}

	fmt.Printf("%s had zmin, zmax = %f, %f, %d objects removed \n", infn, minz, maxz, elim)
	return nil

}
Exemple #3
0
func main() {
	t := time.Now()
	var wg sync.WaitGroup
	for i := 1; i < len(os.Args); i++ {
		wg.Add(1)
		go func(fn string) {
			var l RDZWArr
			if err := lineio.Read(fn, &l); err != nil {
				log.Fatal(err)
			}
			fmt.Printf("%s has %d records\n", fn, len(l))
			wg.Done()
		}(os.Args[i])
	}
	wg.Wait()
	fmt.Printf("Elapsed time : %s\n", time.Since(t))
}
Exemple #4
0
// The weight file is assumed to have a first header line, and then two columns
// with z and n(z)
func readWeight(wfn string, Pk float64) (*spline.Spline, error) {
	var err error

	fmt.Println("Reading in ", wfn)
	var wstr fkpstruct
	wstr.Pk = Pk
	if err := lineio.Read(wfn, &wstr); err != nil {
		return nil, err
	}

	sp, err := spline.New(spline.Cubic, wstr.zz, wstr.fkp)
	if err != nil {
		return nil, err
	}

	// Test the spline
	plot, err := gnuplot.New(false)
	defer close(plot)
	if err != nil {
		return nil, err
	}
	plot <- "set term pngcairo"
	plot <- "set output 'fkp_test.png'"
	plot <- "plot '-' w points ps 3, '-' w lines lw 2"
	for i := range wstr.zz {
		plot <- fmt.Sprintln(wstr.zz[i], wstr.fkp[i])
	}
	plot <- "e"
	var nz float64
	for z1 := wstr.zz[0]; z1 < wstr.zz[len(wstr.zz)-1]; z1 = z1 + 0.001 {
		if nz, err = sp.Eval(z1); err != nil {
			return nil, err
		}
		plot <- fmt.Sprint(z1, nz)
	}
	plot <- "e"
	plot <- "set output"

	// Return the spline
	return sp, nil

}
Exemple #5
0
func main() {
	var err error

	mpi.Initialize()
	defer mpi.Finalize()

	var rank, size int
	if rank, err = mpi.Rank(mpi.WORLD); err != nil {
		mpi.Abort(mpi.WORLD, -1)
	}
	if size, err = mpi.Size(mpi.WORLD); err != nil {
		mpi.Abort(mpi.WORLD, -1)
	}

	// Define the input and output strings
	if len(os.Args) != 3 {
		fmt.Println("Incorrect number of parameters")
		mpi.Abort(mpi.WORLD, 1)
	}
	infn := os.Args[1]
	outfn := os.Args[2]

	// Open output file
	var outff LogFile
	outff.F, err = os.Create(fmt.Sprintf("%s-%05d.out", outfn, rank))
	if err != nil {
		log.Printf("Unable to open file %s-%05d.out", outfn, rank)
	}
	defer outff.F.Close()
	outff.Rank, outff.Size, outff.linenum = rank, size, 0

	lineio.Read(infn, &outff)

	mpi.Barrier(mpi.WORLD)

}