Esempio n. 1
0
func main() {
	pp, err := gnuplot.New(false)
	if err != nil {
		log.Fatal(err)
	}

	pp <- "set term png"
	pp <- "set output \"sin.png\""
	pp <- "plot sin(x)"
	pp <- "set term pdfcairo"
	pp <- "set output \"cos.pdf\""
	pp <- "plot cos(x) lw 5"
	pp <- "set output"
	close(pp)

}
Esempio n. 2
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

}