Commits

Anonymous committed 6fe3d57

migrate to new exec package + add BSD-style license + restructure. package import is now 'bitbucket.org/binet/go-gnuplot/pkg/gnuplot';

  • Participants
  • Parent commits 2d8066f

Comments (0)

Files changed (16)

 all: install
 
 DIRS=\
-	src\
+	pkg/gnuplot\
 
 
 clean.dirs: $(addsuffix .clean, $(DIRS))

File examples/t001.go

+package main
+
+import "fmt"
+//import "io/ioutil"
+import "bitbucket.org/binet/go-gnuplot/pkg/gnuplot"
+
+func main() {
+	fname := ""
+	persist := false
+	debug := true
+
+	p,err := gnuplot.NewPlotter(fname, persist, debug)
+	if err != nil {
+		err_string := fmt.Sprintf("** err: %v\n", err)
+		panic(err_string)
+	}
+	defer p.Close()
+
+	p.CheckedCmd("plot %f*x", 23.0)
+	p.CheckedCmd("plot %f * cos(%f * x)", 32.0, -3.0)
+	//p.CheckedCmd("save foo.ps")
+	p.CheckedCmd("set terminal pdf")
+	p.CheckedCmd("set output 'plot001.pdf'")
+	p.CheckedCmd("replot")
+
+	p.CheckedCmd("q")
+	//p.proc.Wait(0)
+
+	return
+}
+
+/* EOF */

File examples/t002.go

+package main
+
+import "fmt"
+//import "io/ioutil"
+import "bitbucket.org/binet/go-gnuplot/pkg/gnuplot"
+
+func main() {
+	fname := ""
+	persist := false
+	debug := true
+
+	p,err := gnuplot.NewPlotter(fname, persist, debug)
+	if err != nil {
+		err_string := fmt.Sprintf("** err: %v\n", err)
+		panic(err_string)
+	}
+	defer p.Close()
+
+	p.PlotX([]float64{0,1,2,3,4,5,6,7,8,9,10}, "some data")
+	p.CheckedCmd("set terminal pdf")
+	p.CheckedCmd("set output 'plot002.pdf'")
+	p.CheckedCmd("replot")
+
+
+	p.CheckedCmd("q")
+	return
+}
+
+/* EOF */

File examples/t003.go

+package main
+
+import "fmt"
+import "bitbucket.org/binet/go-gnuplot/pkg/gnuplot"
+
+func main() {
+	fname := ""
+	persist := false
+	debug := true
+
+	p,err := gnuplot.NewPlotter(fname, persist, debug)
+	if err != nil {
+		err_string := fmt.Sprintf("** err: %v\n", err)
+		panic(err_string)
+	}
+	defer p.Close()
+
+	p.PlotXY([]float64{0,1,2,3,4,5,6,7,8,9,10}, 
+		     []float64{0,1,2,3,4,5,6,7,8,9,10}, "some data - x/y")
+	p.SetXLabel("my x data")
+	p.SetYLabel("my y data")
+	p.CheckedCmd("set terminal pdf")
+	p.CheckedCmd("set output 'plot003.pdf'")
+	p.CheckedCmd("replot")
+
+
+	p.CheckedCmd("q")
+	return
+}
+
+/* EOF */

File examples/t004.go

+package main
+
+import "fmt"
+import "bitbucket.org/binet/go-gnuplot/pkg/gnuplot"
+import "math"
+
+func main() {
+	fname := ""
+	persist := false
+	debug := true
+
+	p,err := gnuplot.NewPlotter(fname, persist, debug)
+	if err != nil {
+		err_string := fmt.Sprintf("** err: %v\n", err)
+		panic(err_string)
+	}
+	defer p.Close()
+
+	p.SetStyle("steps")
+	p.PlotFunc([]float64{0,1,2,3,4,5,6,7,8,9,10}, 
+		func (x float64) float64 {return math.Exp(float64(x) + 2.)},
+		"test plot-func")
+	p.SetXLabel("my x data")
+	p.SetYLabel("my y data")
+	p.CheckedCmd("set terminal pdf")
+	p.CheckedCmd("set output 'plot004.pdf'")
+	p.CheckedCmd("replot")
+
+
+	p.CheckedCmd("q")
+	return
+}
+
+/* EOF */

File examples/t005.go

+package main
+
+import "fmt"
+import "bitbucket.org/binet/go-gnuplot/pkg/gnuplot"
+
+func main() {
+	fname := ""
+	persist := false
+	debug := true
+
+	p,err := gnuplot.NewPlotter(fname, persist, debug)
+	if err != nil {
+		err_string := fmt.Sprintf("** err: %v\n", err)
+		panic(err_string)
+	}
+	defer p.Close()
+
+	p.CheckedCmd("set grid x")
+	p.CheckedCmd("set grid y")
+	p.CheckedCmd("set grid z")
+	p.PlotXYZ(
+		[]float64{0,1,2,3,4,5,6,7,8,9,10},
+		[]float64{0,1,2,3,4,5,6,7,8,9,10},
+		[]float64{0,1,2,3,4,5,6,7,8,9,10},
+		"test 3d plot")
+	p.SetLabels("x", "y", "z")
+	p.CheckedCmd("set terminal pdf")
+	p.CheckedCmd("set output 'plot005.pdf'")
+	p.CheckedCmd("replot")
+
+
+	p.CheckedCmd("q")
+	return
+}
+
+/* EOF */

File examples/t006.go

+package main
+
+import "fmt"
+import "bitbucket.org/binet/go-gnuplot/pkg/gnuplot"
+
+func main() {
+	fname := ""
+	persist := false
+	debug := true
+
+	p,err := gnuplot.NewPlotter(fname, persist, debug)
+	if err != nil {
+		err_string := fmt.Sprintf("** err: %v\n", err)
+		panic(err_string)
+	}
+	defer p.Close()
+
+	p.CheckedCmd("set grid x")
+	p.CheckedCmd("set grid y")
+	p.CheckedCmd("set grid z")
+	p.PlotNd(
+		"test Nd plot",
+		[]float64{0,1,2,3,4,5,6,7,8,9,10},
+		[]float64{0,1,2,3,4,5,6,7,8,9,10},
+		[]float64{0,1,2,3,4,5,6,7,8,9,10})
+	p.SetLabels("x", "y", "z")
+	p.CheckedCmd("set terminal pdf")
+	p.CheckedCmd("set output 'plot006.pdf'")
+	p.CheckedCmd("replot")
+
+
+	p.CheckedCmd("q")
+	return
+}
+
+/* EOF */

File pkg/gnuplot/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-gnuplot/pkg/gnuplot
+GOFILES=\
+	gnuplot.go\
+
+
+include ${GOROOT}/src/Make.pkg
+

File pkg/gnuplot/gnuplot.go

 //
 package gnuplot
 
-import "os"
-import "io/ioutil"
-//import "bytes"
-//import "container/vector"
-import "exec"
-import "fmt"
+import (
+	"exec"
+	"fmt"
+	"io"
+	"io/ioutil"
+	"os"
+)
 
 var g_gnuplot_cmd string
 var g_gnuplot_prefix string = "go-gnuplot-"
 }
 type plotter_process struct {
 	handle  *exec.Cmd
+	stdin   io.WriteCloser
 }
 
 func new_plotter_proc(persist bool) (*plotter_process, os.Error) {
-	var proc_args []string
+	proc_args := []string{}
 	if persist {
-		proc_args = []string{"gnuplot", "-persist"}
-	} else {
-		proc_args = []string{"gnuplot"}
+		proc_args = append(proc_args, "-persist")
 	}
 	fmt.Printf("--> [%v] %v\n", g_gnuplot_cmd, proc_args)
-	stdin  := exec.Pipe
-	stdout := exec.Pipe
-	//stdout := exec.PassThrough
-	stderr := exec.MergeWithStdout
-
-	cmd, err := exec.Run(g_gnuplot_cmd, proc_args, os.Environ(), "", 
-		stdin, stdout, stderr)
-
+	cmd := exec.Command(g_gnuplot_cmd, proc_args...)
+	stdin, err := cmd.StdinPipe()
 	if err != nil {
 		return nil, err
 	}
-	return &plotter_process{handle: cmd}, nil
+	return &plotter_process{handle: cmd, stdin: stdin}, cmd.Start()
 }
 
 type tmpfiles_db map[string]*os.File
 
 func (self *Plotter) Cmd(format string, a ...interface{}) os.Error {
 	cmd := fmt.Sprintf(format, a...) + "\n"
-	n,err := self.proc.handle.Stdin.WriteString(cmd)
+	n,err := io.WriteString(self.proc.stdin, cmd)
 	
 	if self.debug {
 		//buf := new(bytes.Buffer)
 
 func (self *Plotter) Close() (err os.Error) {
 	if self.proc != nil && self.proc.handle != nil {
-		err = self.proc.handle.Close()
+		self.proc.stdin.Close()
+		err = self.proc.handle.Wait()
 	}
 	self.ResetPlot()
 	return err

File src/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=gnuplot
-GOFILES=\
-	gnuplot.go\
-
-
-include ${GOROOT}/src/Make.pkg
-

File src/examples/t001.go

-package main
-
-import "fmt"
-//import "io/ioutil"
-import "gnuplot"
-
-func main() {
-	fname := ""
-	persist := false
-	debug := true
-
-	p,err := gnuplot.NewPlotter(fname, persist, debug)
-	if err != nil {
-		err_string := fmt.Sprintf("** err: %v\n", err)
-		panic(err_string)
-	}
-	defer p.Close()
-
-	p.CheckedCmd("plot %f*x", 23.0)
-	p.CheckedCmd("plot %f * cos(%f * x)", 32.0, -3.0)
-	//p.CheckedCmd("save foo.ps")
-	p.CheckedCmd("set terminal pdf")
-	p.CheckedCmd("set output 'plot001.pdf'")
-	p.CheckedCmd("replot")
-
-	p.CheckedCmd("q")
-	//p.proc.Wait(0)
-
-	return
-}
-
-/* EOF */

File src/examples/t002.go

-package main
-
-import "fmt"
-//import "io/ioutil"
-import "gnuplot"
-
-func main() {
-	fname := ""
-	persist := false
-	debug := true
-
-	p,err := gnuplot.NewPlotter(fname, persist, debug)
-	if err != nil {
-		err_string := fmt.Sprintf("** err: %v\n", err)
-		panic(err_string)
-	}
-	defer p.Close()
-
-	p.PlotXY([]float64{0,1,2,3,4,5,6,7,8,9,10}, "some data")
-	p.CheckedCmd("set terminal pdf")
-	p.CheckedCmd("set output 'plot002.pdf'")
-	p.CheckedCmd("replot")
-
-
-	p.CheckedCmd("q")
-	return
-}
-
-/* EOF */

File src/examples/t003.go

-package main
-
-import "fmt"
-import "gnuplot"
-
-func main() {
-	fname := ""
-	persist := false
-	debug := true
-
-	p,err := gnuplot.NewPlotter(fname, persist, debug)
-	if err != nil {
-		err_string := fmt.Sprintf("** err: %v\n", err)
-		panic(err_string)
-	}
-	defer p.Close()
-
-	p.PlotXY([]float64{0,1,2,3,4,5,6,7,8,9,10}, 
-		     []float64{0,1,2,3,4,5,6,7,8,9,10}, "some data - x/y")
-	p.SetXLabel("my x data")
-	p.SetYLabel("my y data")
-	p.CheckedCmd("set terminal pdf")
-	p.CheckedCmd("set output 'plot003.pdf'")
-	p.CheckedCmd("replot")
-
-
-	p.CheckedCmd("q")
-	return
-}
-
-/* EOF */

File src/examples/t004.go

-package main
-
-import "fmt"
-import "gnuplot"
-import "math"
-
-func main() {
-	fname := ""
-	persist := false
-	debug := true
-
-	p,err := gnuplot.NewPlotter(fname, persist, debug)
-	if err != nil {
-		err_string := fmt.Sprintf("** err: %v\n", err)
-		panic(err_string)
-	}
-	defer p.Close()
-
-	p.SetStyle("steps")
-	p.PlotFunc([]float64{0,1,2,3,4,5,6,7,8,9,10}, 
-		func (x float64) float64 {return math.Exp(float64(x) + 2.)},
-		"test plot-func")
-	p.SetXLabel("my x data")
-	p.SetYLabel("my y data")
-	p.CheckedCmd("set terminal pdf")
-	p.CheckedCmd("set output 'plot004.pdf'")
-	p.CheckedCmd("replot")
-
-
-	p.CheckedCmd("q")
-	return
-}
-
-/* EOF */

File src/examples/t005.go

-package main
-
-import "fmt"
-import "gnuplot"
-
-func main() {
-	fname := ""
-	persist := false
-	debug := true
-
-	p,err := gnuplot.NewPlotter(fname, persist, debug)
-	if err != nil {
-		err_string := fmt.Sprintf("** err: %v\n", err)
-		panic(err_string)
-	}
-	defer p.Close()
-
-	p.CheckedCmd("set grid x")
-	p.CheckedCmd("set grid y")
-	p.CheckedCmd("set grid z")
-	p.PlotXYZ(
-		[]float64{0,1,2,3,4,5,6,7,8,9,10},
-		[]float64{0,1,2,3,4,5,6,7,8,9,10},
-		[]float64{0,1,2,3,4,5,6,7,8,9,10},
-		"test 3d plot")
-	p.SetLabels("x", "y", "z")
-	p.CheckedCmd("set terminal pdf")
-	p.CheckedCmd("set output 'plot005.pdf'")
-	p.CheckedCmd("replot")
-
-
-	p.CheckedCmd("q")
-	return
-}
-
-/* EOF */

File src/examples/t006.go

-package main
-
-import "fmt"
-import "gnuplot"
-
-func main() {
-	fname := ""
-	persist := false
-	debug := true
-
-	p,err := gnuplot.NewPlotter(fname, persist, debug)
-	if err != nil {
-		err_string := fmt.Sprintf("** err: %v\n", err)
-		panic(err_string)
-	}
-	defer p.Close()
-
-	p.CheckedCmd("set grid x")
-	p.CheckedCmd("set grid y")
-	p.CheckedCmd("set grid z")
-	p.PlotNd(
-		"test Nd plot",
-		[]float64{0,1,2,3,4,5,6,7,8,9,10},
-		[]float64{0,1,2,3,4,5,6,7,8,9,10},
-		[]float64{0,1,2,3,4,5,6,7,8,9,10})
-	p.SetLabels("x", "y", "z")
-	p.CheckedCmd("set terminal pdf")
-	p.CheckedCmd("set output 'plot006.pdf'")
-	p.CheckedCmd("replot")
-
-
-	p.CheckedCmd("q")
-	return
-}
-
-/* EOF */