Module: Gnuplot

Defined in:
lib/graphkit/gnuplot.rb

Overview

classes.

Class Method Summary collapse

Class Method Details

.gnuplot(persist = true) ⇒ Object

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.



42
43
44
45
46
47
48
# 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) ⇒ Object

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.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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) ⇒ Object

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.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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