class CTioga2::Data::Backends::GnuplotBackend
Public Instance Methods
query_dataset(set)
click to toggle source
This is called by the architecture to get the data. It splits the set name into filename@cols, reads the file if necessary and calls get_data
# File lib/ctioga2/data/backends/backends/gnuplot.rb, line 58 def query_dataset(set) set =~ /^(.*?)(?:@(\d+))?(?::(.*))?$/ filename = $1 if $2 number = $2.to_i - 1 else number = 0 end if $3 overrides = "#{@variable_overrides};#{$3}" else overrides = @variable_overrides end plots = run_gnuplot(filename, overrides) return Dataset.new(set,plots[number]) end
run_gnuplot(filename, overrides = @variables_overrides)
click to toggle source
Runs gnuplot on the file, and returns all datasets found inside it.
# File lib/ctioga2/data/backends/backends/gnuplot.rb, line 77 def run_gnuplot(filename, overrides = @variables_overrides) date = File::mtime(filename) # Get it from the cache ! debug { "Running gnuplot on file #{filename}" } f = Utils::open(filename) # We open a bidirectionnal connection to gnuplot: gnuplot = IO.popen("gnuplot", "r+") output = "" ## \todo determine gnuplot version for choosing which one we ## want to use. # gnuplot.puts "set term table" gnuplot.puts "set table" if @samples overrides ||= "" overrides += ";set samples #{@samples}" end for line in f next if line =~ /set\s+term/ if overrides and line =~ /plot\s+/ debug { "Found a plot, inserting variable overrides: #{overrides}" } line.gsub!(/plot\s+/, "#{overrides};plot ") end if @range and line =~ /plot\s+/ debug { "Found a plot, inserting range: #{@range}" } line.gsub!(/plot\s+(\[[^\]]+\])?/, "plot [#{@range}]") end gnuplot.print line gnuplot.flush output += slurp(gnuplot) end # Output a "\n" in the end. gnuplot.puts "" gnuplot.flush gnuplot.close_write # Then we get all that is remaining: output += gnuplot.read gnuplot.close # Now, interaction with gnuplot is finished, and we want to # parse that: outputs = output.split("\n\n") plots = [] for data in outputs plots << Dvector.fancy_read(StringIO.new(data), [0,1]) end # This block evaluates to plots: return plots end
slurp(f, size = 10240)
click to toggle source
Gets all data from the given file until it blocks, and returns it.
# File lib/ctioga2/data/backends/backends/gnuplot.rb, line 134 def slurp(f, size = 10240) str = "" begin while IO::select([f],[],[],0) ret = f.readpartial(size) if ret.empty? return str end str << ret end end return str end