sbgnuplot

package module
v0.0.0-...-b74f0a8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2025 License: MIT Imports: 10 Imported by: 0

README

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
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

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!

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
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")
)

Functions

This section is empty.

Types

type GnuPlot

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

The main struct that is used to control plot generation.

func NewGnuPlot

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

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL