Class: TokFile

Inherits:
Object
  • Object
show all
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

Classes: Eqdsk, Ogyropsi

Class Method Summary collapse

Class Method Details

.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



92
93
94
# File 'lib/tokfile.rb', line 92

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

.verbosityObject

None neededed



95
96
97
# File 'lib/tokfile.rb', line 95

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