text-data-tools 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/text-data-tools.rb +179 -0
- data/test/helper.rb +18 -0
- data/test/test_dat.dat +19 -0
- data/test/test_dat_2.dat +20 -0
- data/test/test_text-data-tools.rb +39 -0
- metadata +126 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "> 1.0.0"
|
12
|
+
gem "jeweler", ">= 1.8.4"
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Edmund Highcock
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= text-data-tools
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to text-data-tools
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 Edmund Highcock. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "text-data-tools"
|
18
|
+
gem.homepage = "http://github.com/edmundhighcock/text-data-tools"
|
19
|
+
gem.license = "GPLv3"
|
20
|
+
gem.summary = %Q{A small set of tools for reading text based data files into arrays.}
|
21
|
+
gem.description = %Q{A small set of tools for reading text based data files into arrays. Works ee.g. for simple columnar data with or without headings.}
|
22
|
+
gem.email = "edmundhighcock@sourceforge.net"
|
23
|
+
gem.authors = ["Edmund Highcock"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
#require 'rcov/rcovtask'
|
36
|
+
#Rcov::RcovTask.new do |test|
|
37
|
+
##test.libs << 'test'
|
38
|
+
##test.pattern = 'test/**/test_*.rb'
|
39
|
+
##test.verbose = true
|
40
|
+
##test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
##end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "text-data-tools #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,179 @@
|
|
1
|
+
|
2
|
+
module TextFileTools
|
3
|
+
# Return a one-dimensional array containing data from the file filename,
|
4
|
+
# which may or may not have a line of column headers,
|
5
|
+
# in the column column_header, where column_header maybe either a string
|
6
|
+
# or a regex which matches the title of the column, or an integer
|
7
|
+
# giving the zero-based column number.
|
8
|
+
#
|
9
|
+
# Match is a regexp that matches data items, and header_match is a regexp that
|
10
|
+
# matches items in the headers.
|
11
|
+
#
|
12
|
+
# All data is returned as strings
|
13
|
+
def self.get_1d_array(filename, has_header_line, column_header, match=/\S+/, header_match=/\S+/)
|
14
|
+
raise ArgumentError.new("column_header header should be a string, regex or integer") unless [String, Regexp, Integer].find{|cls| column_header.kind_of? cls}
|
15
|
+
array = []
|
16
|
+
File.open(filename) do |file|
|
17
|
+
headers = file.gets if has_header_line
|
18
|
+
if [String, Regexp].find{|cls| column_header.kind_of? cls}
|
19
|
+
raise ("Header search given but has_header_line = false") if not has_header_line
|
20
|
+
column_header = column_index_from_headers(headers, column_header, header_match)
|
21
|
+
end
|
22
|
+
while line = file.gets
|
23
|
+
values = line.scan(match)
|
24
|
+
array.push values[column_header]
|
25
|
+
#puts line
|
26
|
+
end
|
27
|
+
end
|
28
|
+
array
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Calls get_1d_array and converts all data elements to floats
|
33
|
+
def self.get_1d_array_float(*args)
|
34
|
+
get_1d_array(*args).map{|v| v.to_f}
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return a two-dimensional array containing data from the file filename,
|
38
|
+
# which may or may not have a line of column headers,
|
39
|
+
# in the column column_header, where column_header maybe either a string
|
40
|
+
# or a regex which matches the title of the column, or an integer
|
41
|
+
# giving the zero-based column number.
|
42
|
+
#
|
43
|
+
# It is assumed that two-dimensional array is in one column.
|
44
|
+
# If index_header is nil, data is assumed to be separated by blank lines.
|
45
|
+
# E.g.
|
46
|
+
# 1.2
|
47
|
+
# 4.2
|
48
|
+
# 7.2
|
49
|
+
#
|
50
|
+
# 8.2
|
51
|
+
# 4.2
|
52
|
+
# 2.2
|
53
|
+
# If index_header is an integer or string or regexp, it selects a column
|
54
|
+
# in the manner of column_header, and the data is divided by values of this
|
55
|
+
# column.
|
56
|
+
# E.g.
|
57
|
+
# 1 5.5
|
58
|
+
# 1 3.2
|
59
|
+
# 1 2.6
|
60
|
+
# 2 3.2
|
61
|
+
# 2 2.2
|
62
|
+
# 2 6.3
|
63
|
+
#
|
64
|
+
# Match is a regexp that matches data items, and header_match is a regexp that
|
65
|
+
# matches items in the headers.
|
66
|
+
#
|
67
|
+
# All data is returned as strings
|
68
|
+
def self.get_2d_array(filename, has_header_line, column_header, index_header=nil, match=/\S+/, header_match=/\S+/)
|
69
|
+
raise ArgumentError.new("column_header header should be a string, regex or integer") unless [String, Regexp, Integer].find{|cls| column_header.kind_of? cls}
|
70
|
+
raise ArgumentError.new("index_header should be a string, regex, integer or nil") unless [String, Regexp, Integer, NilClass].find{|cls| column_header.kind_of? cls}
|
71
|
+
array = []
|
72
|
+
File.open(filename) do |file|
|
73
|
+
headers = file.gets if has_header_line
|
74
|
+
if [String, Regexp].find{|cls| column_header.kind_of? cls}
|
75
|
+
raise ("Header search given but has_header_line = false") if not has_header_line
|
76
|
+
column_header = column_index_from_headers(headers, column_header, header_match)
|
77
|
+
end
|
78
|
+
if [String, Regexp].find{|cls| index_header.kind_of? cls}
|
79
|
+
raise ("Header search given but has_header_line = false") if not has_header_line
|
80
|
+
index_header = column_index_from_headers(headers, index_header, header_match)
|
81
|
+
end
|
82
|
+
index_value = false
|
83
|
+
index = 0
|
84
|
+
while line = file.gets
|
85
|
+
if index_header.nil?
|
86
|
+
if line =~ /^\s*$/
|
87
|
+
if array.size == 0 # ignore empty lines at top
|
88
|
+
next
|
89
|
+
else
|
90
|
+
(array.push []; index+=1;next)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
array.push [] if array.size = 0
|
94
|
+
else
|
95
|
+
next if line =~ /^\s*$/
|
96
|
+
end
|
97
|
+
values = line.scan(match)
|
98
|
+
if not index_header.nil?
|
99
|
+
if array.size ==0
|
100
|
+
array.push []
|
101
|
+
index_value = values[index_header]
|
102
|
+
elsif index_value != values[index_header]
|
103
|
+
array.push []
|
104
|
+
index+=1
|
105
|
+
index_value = values[index_header]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
array[index].push values[column_header]
|
109
|
+
#puts line
|
110
|
+
end
|
111
|
+
end
|
112
|
+
array
|
113
|
+
end
|
114
|
+
|
115
|
+
# Calls get_2d_array and converts all data elements to floats
|
116
|
+
def self.get_2d_array_float(*args)
|
117
|
+
get_2d_array(*args).map{|a| a.map{|v| v.to_f}}
|
118
|
+
end
|
119
|
+
|
120
|
+
class NotFoundError < StandardError
|
121
|
+
end
|
122
|
+
|
123
|
+
# Extract a variable value from the given file where the variable is defined
|
124
|
+
# in this form:
|
125
|
+
# name sep value
|
126
|
+
# E.g.
|
127
|
+
# heat = 4.0
|
128
|
+
def self.get_variable_value(filename, name, sep='=')
|
129
|
+
value = nil
|
130
|
+
File.open(filename) do |file|
|
131
|
+
while line= file.gets
|
132
|
+
next unless line =~ Regexp.new("#{Regexp.escape(name)}\\s*#{Regexp.escape(sep)}\\s*(?<value>.*)")
|
133
|
+
value = $~[:value]
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
137
|
+
raise NotFoundError.new("Can't find #{name} in #{filename}") unless value
|
138
|
+
value
|
139
|
+
end
|
140
|
+
def self.column_index_from_headers(line, column_header, header_match)
|
141
|
+
headers = line.scan(header_match)
|
142
|
+
#p headers
|
143
|
+
index_array = headers.map{|head| head =~ (column_header.kind_of?(Regexp) ? column_header : Regexp.new(Regexp.escape(column_header)))}
|
144
|
+
#p index_array
|
145
|
+
raise ArgumentError.new("column_header: #{column_header.inspect} does not match any columns in #{headers.inspect}") if index_array.compact.size == 0
|
146
|
+
raise ArgumentError.new("column_header: #{column_header.inspect} matches more than 1 column in #{headers.inspect}") if index_array.compact.size > 1
|
147
|
+
column_header = index_array.index(index_array.compact[0])
|
148
|
+
end
|
149
|
+
|
150
|
+
# This is a simple class which can interface with the methods of TextFileTools
|
151
|
+
# to prevent the user having to specify the file name for every call. In a
|
152
|
+
# nutshell, create a new instance of this class giving it the filename,
|
153
|
+
# then call methods from TextFileTools omitting the first argument.
|
154
|
+
class TextDataFile
|
155
|
+
def initialize(filename, has_header_line = false, match = /\S+/, header_match = /\S+/)
|
156
|
+
@filename = filename
|
157
|
+
@match = match
|
158
|
+
@header_match = header_match
|
159
|
+
@has_header_line = has_header_line
|
160
|
+
self
|
161
|
+
end
|
162
|
+
def get_1d_array(column_header)
|
163
|
+
TextFileTools.get_1d_array(@filename, @has_header_line, column_header, @match, @header_match)
|
164
|
+
end
|
165
|
+
def get_2d_array(column_header, index_header)
|
166
|
+
TextFileTools.get_2d_array(@filename, @has_header_line, column_header, index_header, @match, @header_match)
|
167
|
+
end
|
168
|
+
def get_variable_value(name, sep)
|
169
|
+
TextFileTools.get_variable_value(@filename, name, sep)
|
170
|
+
end
|
171
|
+
#def method_missing(meth, *args)
|
172
|
+
#if TextFileTools.methods.include? meth
|
173
|
+
#TextFileTools.send(meth, @filename, *args)
|
174
|
+
#else
|
175
|
+
#super
|
176
|
+
#end
|
177
|
+
#end
|
178
|
+
end
|
179
|
+
end # module TextFileTools
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'text-data-tools'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
data/test/test_dat.dat
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# 1: time 2: radius 3: rmajor 4: dens 5: i+ temp 6: e- temp 7: ang mom 8: i+ vnewk 9: e- vnewk 30: time(s) 33: evals
|
2
|
+
0.0000E+00 0.5588E-03 0.3997E+03 0.3050E+03 0.9759E+09 0.9503E+09 0.0000E+00 0.3939E-04 0.9534E-09 0.0000E+00 3
|
3
|
+
0.0000E+00 0.3676E+00 0.3990E+03 0.3050E+03 0.9496E+09 0.9993E+09 0.0000E+00 0.4393E-04 0.3038E-09 0.0000E+00 3
|
4
|
+
0.0000E+00 0.9794E+00 0.3933E+03 0.3050E+03 0.9063E+09 0.9030E+09 0.0000E+00 0.5670E-04 0.3986E-09 0.0000E+00 3
|
5
|
+
0.0000E+00 0.3939E+00 0.3909E+03 0.3050E+03 0.3734E+09 0.3790E+09 0.0000E+00 0.7940E-04 0.5445E-09 0.0000E+00 3
|
6
|
+
0.0000E+00 0.5099E+00 0.3393E+03 0.3050E+03 0.3483E+09 0.3458E+09 0.0000E+00 0.3075E-03 0.7470E-09 0.0000E+00 3
|
7
|
+
0.0000E+00 0.6347E+00 0.3384E+03 0.3050E+03 0.3943E+09 0.3993E+09 0.0000E+00 0.3593E-03 0.3056E-03 0.0000E+00 3
|
8
|
+
0.0000E+00 0.7965E+00 0.3379E+03 0.3050E+03 0.9473E+03 0.9390E+03 0.0000E+00 0.9568E-03 0.3763E-03 0.0000E+00 3
|
9
|
+
0.0000E+00 0.8389E+00 0.3357E+03 0.3050E+03 0.7086E+03 0.7077E+03 0.0000E+00 0.4535E-03 0.3064E-03 0.0000E+00 3
|
10
|
+
0.0000E+00 0.9500E+00 0.3338E+03 0.3039E+03 0.5986E+03 0.5337E+03 0.0000E+00 0.7690E-03 0.5364E-03 0.0000E+00 3
|
11
|
+
0.7833E-03 0.5588E-03 0.3997E+03 0.3050E+03 0.9753E+09 0.9504E+09 0.0000E+00 0.3938E-04 0.9533E-09 0.4905E-03 9
|
12
|
+
0.7833E-03 0.3676E+00 0.3990E+03 0.3050E+03 0.9435E+09 0.9993E+09 0.0000E+00 0.4363E-04 0.3046E-09 0.4905E-03 9
|
13
|
+
0.7833E-03 0.9794E+00 0.3933E+03 0.3050E+03 0.9045E+09 0.9009E+09 0.0000E+00 0.5759E-04 0.4005E-09 0.4905E-03 9
|
14
|
+
0.7833E-03 0.3939E+00 0.3909E+03 0.3050E+03 0.3798E+09 0.3790E+09 0.0000E+00 0.7995E-04 0.5454E-09 0.4905E-03 9
|
15
|
+
0.7833E-03 0.5099E+00 0.3393E+03 0.3050E+03 0.3463E+09 0.3455E+09 0.0000E+00 0.3305E-03 0.7545E-09 0.4905E-03 9
|
16
|
+
0.7833E-03 0.6347E+00 0.3384E+03 0.3050E+03 0.3943E+09 0.3993E+09 0.0000E+00 0.3590E-03 0.3055E-03 0.4905E-03 9
|
17
|
+
0.7833E-03 0.7965E+00 0.3379E+03 0.3050E+03 0.9603E+03 0.9405E+03 0.0000E+00 0.9503E-03 0.3747E-03 0.4905E-03 9
|
18
|
+
0.7833E-03 0.8389E+00 0.3357E+03 0.3050E+03 0.7375E+03 0.7099E+03 0.0000E+00 0.4403E-03 0.3035E-03 0.4905E-03 9
|
19
|
+
0.7833E-03 0.9500E+00 0.3338E+03 0.3039E+03 0.5986E+03 0.5337E+03 0.0000E+00 0.7690E-03 0.5364E-03 0.4905E-03 9
|
data/test/test_dat_2.dat
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Q: 11.989644168449118
|
2
|
+
Fusion power: 484.34196189744871
|
3
|
+
Net power: 138.68949894790680
|
4
|
+
Auxiliary power: 41.749004487647194
|
5
|
+
Alpha power: 116.90499891894469
|
6
|
+
Radiated power: 99.980803847994007
|
7
|
+
|
8
|
+
Core density: 1.0400000000000000
|
9
|
+
Edge density: 1.0116440934700969
|
10
|
+
Core T_i: 91.870761489394619
|
11
|
+
Core T_e: 46.999819474079938
|
12
|
+
Edge T_i: 4.9863981904130986
|
13
|
+
Edge T_e: 4.3171799196418704
|
14
|
+
Core omega: 0.0000000000000000
|
15
|
+
Edge omega: 0.0000000000000000
|
16
|
+
|
17
|
+
Total stored thermal energy (MJ): 414.09910378179146
|
18
|
+
Total stored thermal energy (MJ) from initial condition: 418.74183188999439
|
19
|
+
Incremental stored thermal energy (MJ): 309.80343864467043
|
20
|
+
Incremental stored thermal energy (MJ) from initial condition: 914.46396674694439
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestTextFileTools < Test::Unit::TestCase
|
4
|
+
def test_1d
|
5
|
+
assert_raise(ArgumentError){TextFileTools.get_1d_array('test/test_dat.dat', true, 2.2)}
|
6
|
+
assert_raise(ArgumentError){TextFileTools.get_1d_array('test/test_dat.dat',true, /ii\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)}
|
7
|
+
array = TextFileTools.get_1d_array('test/test_dat.dat', true, /i\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
8
|
+
#puts array
|
9
|
+
assert_equal(array.size, 18)
|
10
|
+
assert_equal(array[9].to_f, 0.9753E+09)
|
11
|
+
array = TextFileTools.get_1d_array_float('test/test_dat.dat', true, /i\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
12
|
+
assert_equal(array[9], 0.9753E+09)
|
13
|
+
end
|
14
|
+
def test_2d
|
15
|
+
array = TextFileTools.get_2d_array('test/test_dat.dat', true, /i\+ temp/, 0, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
16
|
+
assert_equal(array.size, 2)
|
17
|
+
array = TextFileTools.get_2d_array('test/test_dat.dat', true, /i\+ temp/, 1, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
18
|
+
assert_equal(array.size, 18)
|
19
|
+
array = TextFileTools.get_2d_array_float('test/test_dat.dat', true, /i\+ temp/, 0, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
20
|
+
assert_equal(array[0].size, 9)
|
21
|
+
assert_equal(array[1][0], 0.9753E+09)
|
22
|
+
|
23
|
+
#assert_equal(array[9].to_f, 0.9753E+09)
|
24
|
+
|
25
|
+
end
|
26
|
+
def test_get_variable
|
27
|
+
variable = TextFileTools.get_variable_value('test/test_dat_2.dat', 'Q', ':')
|
28
|
+
assert_equal(variable.to_f, 11.989644168449118)
|
29
|
+
variable = TextFileTools.get_variable_value('test/test_dat_2.dat', 'Fusion power', ':')
|
30
|
+
assert_equal(variable.to_f, 484.34196189744871)
|
31
|
+
end
|
32
|
+
def test_texdatafile_class
|
33
|
+
file = TextFileTools::TextDataFile.new('test/test_dat_2.dat')
|
34
|
+
assert_equal(file.get_variable_value('Alpha power', ':').to_f, 116.90499891894469 )
|
35
|
+
file = TextFileTools::TextDataFile.new('test/test_dat.dat', true, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
|
36
|
+
array = file.get_2d_array(/i\+ temp/, /1.*time/)
|
37
|
+
assert_equal(array.size, 2)
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: text-data-tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Edmund Highcock
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shoulda
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>'
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>'
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
description: A small set of tools for reading text based data files into arrays. Works
|
79
|
+
ee.g. for simple columnar data with or without headings.
|
80
|
+
email: edmundhighcock@sourceforge.net
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files:
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.rdoc
|
86
|
+
files:
|
87
|
+
- .document
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.rdoc
|
91
|
+
- Rakefile
|
92
|
+
- VERSION
|
93
|
+
- lib/text-data-tools.rb
|
94
|
+
- test/helper.rb
|
95
|
+
- test/test_dat.dat
|
96
|
+
- test/test_dat_2.dat
|
97
|
+
- test/test_text-data-tools.rb
|
98
|
+
homepage: http://github.com/edmundhighcock/text-data-tools
|
99
|
+
licenses:
|
100
|
+
- GPLv3
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
hash: 2185159197686806665
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.8.23
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: A small set of tools for reading text based data files into arrays.
|
126
|
+
test_files: []
|