Class: Grada::Gnuplot
- Inherits:
-
Object
show all
- Defined in:
- lib/grada/types/gnuplot.rb
Defined Under Namespace
Classes: DataSet, Plot, Style
Class Method Summary
collapse
Class Method Details
.candidate?(candidate) ⇒ Boolean
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/grada/types/gnuplot.rb', line 8
def self.candidate?(candidate)
return candidate if File::executable? candidate
ENV['PATH'].split(File::PATH_SEPARATOR).each do |dir|
possible_candidate = File::join dir, candidate.strip
return possible_candidate if File::executable? possible_candidate
end
nil
end
|
.find_exec(bin) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/grada/types/gnuplot.rb', line 20
def self.find_exec(bin)
bin_list = RUBY_PLATFORM =~ /mswin|mingw/ ? [bin, "#{bin}.exe"] : [bin]
bin_list.each do |c|
exec = candidate?(c)
return exec if exec
end
nil
end
|
.gnuplot ⇒ Object
31
32
33
34
35
|
# File 'lib/grada/types/gnuplot.rb', line 31
def self.gnuplot
gnu_exec = find_exec( ENV['RB_GNUPLOT'] || 'gnuplot' )
raise Grada::NoGnuPlotExecutableFound unless gnu_exec
gnu_exec
end
|
.open(persist = true, &block) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/grada/types/gnuplot.rb', line 37
def self.open(persist = true, &block)
gnuplot_cmd = gnuplot
commands = yield
output = StringIO.new
Open3::popen3(gnuplot_cmd, '-persist') do |data_in, data_out, stderr, wait_th|
data_in << commands[:plot_settings]
data_in << commands[:plot_data]
data_in.flush
sleep 1
while true do
window = IO::popen('xprop -name "Gnuplot" WM_NAME 2>/dev/null').gets
break unless window
sleep 1
end
data_in.close
data_out.close
stderr.close
output.write(wait_th.value.exitstatus)
end
output.string
end
|