Phrogz
10/17/2007 4:20:00 PM
On Oct 17, 10:03 am, baptiste Augui? <ba...@exeter.ac.uk> wrote:
> > angle value1 value2
>
> > 156.00 3.3688E-03 1.7040E-03
> > 157.00 3.2919E-03 1.7118E-03
> > 158.00 3.2140E-03 1.7190E-03
> > 159.00 3.1354E-03 1.7258E-03
> > 160.00 3.0560E-03 1.7320E-03
> > 161.00 2.9760E-03 1.7378E-03
> > 162.00 2.8956E-03 1.7431E-03
> > 163.00 2.8148E-03 1.7479E-03
> > 164.00 2.7338E-03 1.7523E-03
> > 165.00 2.6526E-03 1.7562E-03
> > 166.00 2.5714E-03 1.7597E-03
> > 167.00 2.4902E-03 1.7628E-03
>
> I would like to extract the 3 columns of data for several consecutive
> lines (say, from angle = 158 to 165). These values should be stored
> in some array or vector. How can I do that in Ruby?
# Make an array of arrays of numbers
# based on scanning for non-whitespace characters
# (all strings will show up as 0.0)
values = IO.readlines( 'input.dat' ).map{ |line|
line.scan( /\S+/ ).map{ |str| str.to_f }
}
my_range = values.select{ |angle, _|
(158..165).include?( angle )
}
require 'pp'
pp my_range
#=> [[158.0, 0.003214, 0.001719],
#=> [159.0, 0.0031354, 0.0017258],
#=> [160.0, 0.003056, 0.001732],
#=> [161.0, 0.002976, 0.0017378],
#=> [162.0, 0.0028956, 0.0017431],
#=> [163.0, 0.0028148, 0.0017479],
#=> [164.0, 0.0027338, 0.0017523],
#=> [165.0, 0.0026526, 0.0017562]]