class TokFile
A class for interacting with files of format ogyropsi, an input format for GENE and GYRO that is output by CHEASE
Public Class Methods
convert(inputfile, outputfiles, copts)
click to toggle source
# File lib/tokfile/commands.rb, line 65 def convert(inputfile, outputfiles, copts) outputfiles = outputfiles.split(/,/) raise "Please specify formats as a comma separated list" unless copts[:f].kind_of? String formats = copts[:f].split(/,/) unless (formats.size==1 or formats.size==outputfiles.size+1) raise "Please specify either one format, or a list of formats the same length as total number of input and output files" end ifile = file_object(inputfile, formats[0]) #ifile.summary_graphkit.gnuplot outputfiles.each_with_index do |ofilename, index| format = formats.size>1 ? formats[index+1] : formats[0] ofileob = ifile.convert(format) ofileob.write_file(ofilename) end end
display_summary_graph(inputfiles, copts)
click to toggle source
Class methods that implement commands
# File lib/tokfile/commands.rb, line 9 def display_summary_graph(inputfiles, copts) summary_graphkit(inputfiles, copts).gnuplot end
file_object(file, format)
click to toggle source
Other class methods
# File lib/tokfile/commands.rb, line 44 def file_object(file, format) case format when 'eqdsk' TokFile::Eqdsk.new(file) when 'ogyropsi' TokFile::Ogyropsi.new(file) else raise "Can't read this file format yet: #{format}" end end
merge(inputfiles, outputfile, copts)
click to toggle source
# File lib/tokfile/commands.rb, line 13 def merge(inputfiles, outputfile, copts) inputfiles = inputfiles.split(/,/) formats = copts[:f].split(/,/) formsize = inputfiles.size + 1 case formats.size when 1 formats = formats * formsize when formsize else raise "Number of formats should be either 1 for all the same or #{formsize}" end raise "Please specify merges as a comma separated list" unless copts[:m].kind_of? String and copts[:m] =~ /,/ merges = copts[:m].split(/,/) raise "Please specify the same number of merges as inputfiles" unless merges.size == inputfiles.size output = file_object(outputfile, formats[inputfiles.size] ) inputfiles.each_with_index do |file,i| input = file_object(file, formats[i]) output.read_data(input, merges[i], copts[:t]) end output.write end
setup(copts)
click to toggle source
This function gets called before every command and allows arbitrary manipulation of the command options (copts) hash
# File lib/tokfile.rb, line 93 def setup(copts) # None neededed end
summary_graphkit(inputfiles, copts)
click to toggle source
# File lib/tokfile/commands.rb, line 55 def summary_graphkit(inputfiles, copts) raise 'Only one format allowed for summary_graphkit ' if copts[:f] =~ /,/ inputfiles = inputfiles.split(',') kit = inputfiles.map{|inputfile| file_object(inputfile, copts[:f]).summary_graphkit }.inject{|o,n| o.merge(n)} kit.instance_eval(copts[:w]) if copts[:w] kit end
verbosity()
click to toggle source
# File lib/tokfile.rb, line 96 def verbosity 2 end
write_summary_graph(inputfiles, graphname, copts)
click to toggle source
# File lib/tokfile/commands.rb, line 35 def write_summary_graph(inputfiles, graphname, copts) summary_graphkit(inputfiles, copts).gnuplot_write graphname end