Class: TokFile
- Inherits:
-
Object
- Object
- TokFile
- Defined in:
- lib/tokfile/ogyropsi.rb,
lib/tokfile.rb,
lib/tokfile/commands.rb
Overview
A class for interacting with files of format ogyropsi, an input format for GENE and GYRO that is output by CHEASE
Defined Under Namespace
Class Method Summary collapse
- .convert(inputfile, outputfiles, copts) ⇒ Object
-
.display_summary_graph(inputfiles, copts) ⇒ Object
Class methods that implement commands.
- .file_object(file, format) ⇒ Object
- .merge(inputfiles, outputfile, copts) ⇒ Object
-
.setup(copts) ⇒ Object
This function gets called before every command and allows arbitrary manipulation of the command options (copts) hash.
- .summary_graphkit(inputfiles, copts) ⇒ Object
-
.verbosity ⇒ Object
None neededed.
- .write_summary_graph(inputfiles, graphname, copts) ⇒ Object
Class Method Details
.convert(inputfile, outputfiles, copts) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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) ⇒ Object
Class methods that implement commands
9 10 11 |
# File 'lib/tokfile/commands.rb', line 9 def display_summary_graph(inputfiles, copts) summary_graphkit(inputfiles, copts).gnuplot end |
.file_object(file, format) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# 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) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
This function gets called before every command and allows arbitrary manipulation of the command options (copts) hash
93 94 95 |
# File 'lib/tokfile.rb', line 93 def setup(copts) # None neededed end |
.summary_graphkit(inputfiles, copts) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object
None neededed
96 97 98 |
# File 'lib/tokfile.rb', line 96 def verbosity 2 end |
.write_summary_graph(inputfiles, graphname, copts) ⇒ Object
35 36 37 |
# File 'lib/tokfile/commands.rb', line 35 def write_summary_graph(inputfiles, graphname, copts) summary_graphkit(inputfiles, copts).gnuplot_write graphname end |