module Gnuplot

Methods and variables for interacting with the gnuplot process. Most of these methods are for sending data to a gnuplot process, not for reading from it. Most of the methods are implemented as added methods to the built in classes.

Public Class Methods

gnuplot( persist = true ) click to toggle source

Find the path to the gnuplot executable. The name of the executable can be specified using the RB_GNUPLOT environment variable but will default to the command ‘gnuplot’.

persist [bool] Add the persist flag to the gnuplot executable

Return the path to the gnuplot executable or nil if one cannot be found.

# File lib/graphkit/gnuplot.rb, line 42
def Gnuplot.gnuplot( persist = true )
  cmd = which( ENV['RB_GNUPLOT'] || 'gnuplot' )
              #cmd = "gnuplot"
  #cmd += " -background white"
  cmd += " -persist" if persist
  cmd
end
open( persist=true ) { |STDOUT| ... } click to toggle source

Open a gnuplot process that exists in the current PATH. If the persist flag is true then the -persist flag is added to the command line. The path to the gnuplot executable is determined using the ‘which’ command.

See the gnuplot documentation for information on the persist flag.

todo Add a method to pass the gnuplot path to the function.

# File lib/graphkit/gnuplot.rb, line 58
def Gnuplot.open( persist=true )
  cmd = Gnuplot.gnuplot( persist ) or raise 'gnuplot not found'
              #File.open(".gptemp#{Process.pid}", 'w'){|f| yield f}
              #system "#{cmd} .gptemp#{Process.pid}"
              #FileUtils.rm  ".gptemp#{Process.pid}"


              if $debug_gnuplot
                      #raise "HEELOOE"
             yield(STDOUT)
              else
      IO::popen( cmd, "w") { |io| yield io }
              end
end
which( bin ) click to toggle source

Trivial implementation of the which command that uses the PATH environment variable to attempt to find the given application. The application must be executable and reside in one of the directories in the PATH environment to be found. The first match that is found will be returned.

bin [String] The name of the executable to search for.

Return the full path to the first match or nil if no match is found.

# File lib/graphkit/gnuplot.rb, line 18
def Gnuplot.which ( bin )
  return bin if File::executable? bin

  path = ENV['PATH'] # || ENV['WHAT_EVER_WINDOWS_PATH_VAR_IS']
  path.split(File::PATH_SEPARATOR).each do |dir|
    candidate = File::join dir, bin.strip
    return candidate if File::executable? candidate
  end

  # This is an implementation that works when the which command is
  # available.
  #
  # IO.popen("which #{bin}") { |io| return io.readline.chomp }

  return nil
end