Skip to content

barbell-math/smoothbrain-gnuplot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sbgnuplot

import "github.com/barbell-math/smoothbrain-gnuplot"

A very simple library that aids in creating plots with gnuplot.

Index

Variables

var (
    // The regex that matches strings that need to be replaced in the supplied
    // cmds. The exact contents of the string found by the regular expression
    // will determine what it is replaced with.
    OpRegex = regexp.MustCompile("\\${[^{]*}")

    InvalidOpErr       = errors.New("Invalid op")
    InvalidDatOpErr    = errors.New("Invalid dat op")
    InvalidDatIndexErr = errors.New("Invalid data index")
)

type GnuPlot

The main struct that is used to control plot generation.

type GnuPlot struct {
    // contains filtered or unexported fields
}

func NewGnuPlot(opts GnuPlotOpts) (GnuPlot, error)

Creates a new GnuPlot struct with the supplied options. All data and gnu plot code files will be created. The output file will be created by gnu plot itself when the GnuPlot.Run method is called.

func (*GnuPlot) Cmds

func (g *GnuPlot) Cmds(s ...string) error

Writes cmds to the gnu plot code file. The cmds will be parsed for operations. An operation will replace the given text with a specific value. Valid operations are as follows:

  • {out}: Replaces `{out}` with the path of the out file
  • {dat:#}: Replaces `{dat:#}` with the path of the data file at the index specified by `#`. If `#` is not a valid number, a negative number, or a number outside the range of the data file list an error will be returned and none of the supplied cmds will be added

func (*GnuPlot) DataRow

func (g *GnuPlot) DataRow(file int, data ...string) error

Writes a data row to the data file specified by the `file` index. If the index specified by `file` is invalid a InvalidDatIndexErr will be returned.

To write an empty line call this method with a single empty string as the data arguments.

If no data arguments are provided no work will be done and no error will be returned.

func (*GnuPlot) Run

func (g *GnuPlot) Run(ctxt context.Context) error

Flushes all writers and executes gnuplot with the generated gnu plot code and data files. All open files are closed so the gnuplot object should not be used after calling this method.

type GnuPlotOpts struct {
    // Specifies the file where the generated gnuplot code will go. This
    // path will be relative to the current directory.
    GpltFile string
    // Specifies the files where the data for the plot will be written to.
    // The order of the files matters because methods on [GnuPlot] will
    // reference a data file by index.
    // All paths will be relative to the current directory.
    DatFiles []string
    // Specifies the file where the generated plot will be written to. This
    // path will be relative to the current directory.
    OutFile string
    // The column delimiter character that should be used when writing the
    // data to the dat files.
    CsvSep rune
}

Generated by gomarkdoc

Helpful Developer Cmds

To build the build system:

go build -o ./bs/bs ./bs

The build system can then be used as usual:

./bs/bs --help
./bs/bs buildbs # Builds the build system!

About

A very simple library that aids in creating plots with gnuplot.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages