Scanf failing(?) for floats read from a file

I’m beginning to use scanf (thanks David, Hal, Noland, and Jason!) to
read some floats.

However, I am getting some bad data from it when using it to read
data from a file.

For example, simply varying the trailing spaces,

require ‘scanf’

File.open ‘temp’, ‘w’ do |f|
f.puts '0.0 1.23’
f.puts '1.1 1.23 '
f.puts '2.2 1.23 '
end

File.open ‘temp’ do |f|
6.times{ puts f.scanf ‘%f’ }
end

produces,

0.0
1.23
1.1
0.23
2.2
23.0

Any ideas? Am I supposed to be using something else?

This is for scanf 1.1.1 and ruby 1.7.2 (2002-05-29) and 1.6.8 (2003-03-26)
on i686-linux.

Thanks,

···


Bil Kleb
NASA Langley Research Center
Hampton, Virginia, USA

Hi –

I’m beginning to use scanf (thanks David, Hal, Noland, and Jason!) to
read some floats.

However, I am getting some bad data from it when using it to read
data from a file.

For example, simply varying the trailing spaces,

require ‘scanf’

File.open ‘temp’, ‘w’ do |f|
f.puts ‘0.0 1.23’
f.puts '1.1 1.23 ’
f.puts '2.2 1.23 ’
end

File.open ‘temp’ do |f|
6.times{ puts f.scanf ‘%f’ }
end

produces,

0.0
1.23
1.1
0.23
2.2
23.0

Any ideas? Am I supposed to be using something else?

Yes. Rewind to scanf-1.1.0 :frowning: I fear I’ve introduced a glitch
somewhere in 1.1.1. (It passes all the tests but apparently we need
some more tests :slight_smile: This is my fault – I did what I thought was some
successful refactoring but apparently it wasn’t entirely.

If you need me to I can mail you 1.1.0, and I’ll talk to Hal about
putting it back on the site.

Thanks for reporting it –

David

···

On Sat, 29 Mar 2003, Bil Kleb wrote:


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

I’m beginning to use scanf (thanks David, Hal, Noland, and Jason!) to
read some floats.

However, I am getting some bad data from it when using it to read
data from a file.

[snip]

This is for scanf 1.1.1 and ruby 1.7.2 (2002-05-29) and 1.6.8 (2003-03-26)
on i686-linux.

Sorry for the problem, Bil.

I think 1.1.1 is buggy. We discovered it only after
deploying it a two days ago.

Did you try running the test cases that come with
it?

David told me this would happen. :slight_smile: He asked if we
could roll back to 1.1.0, and I said it was a lot of
trouble to do that, as I hadn’t saved my old files.

I argued that he could just refrain from announcing
it, and the chances of anyone downloading 1.1.1 in
the next day or two were minimal.

So congratulations, Bil! You win a prize for exposing
our carelessness.

No promises on when this can be fixed… but I can
at least dig up the old .tgz file and make it available
also on the site (v 1.0.0). Expect that soon.

Cheers,
Hal

···

----- Original Message -----
From: “Bil Kleb” William.L.Kleb@NASA.Gov
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, March 28, 2003 2:09 PM
Subject: scanf failing(?) for floats read from a file

Hal E. Fulton wrote:

No promises on when this can be fixed… but I can
at least dig up the old .tgz file and make it available
also on the site (v 1.0.0). Expect that soon.

That would be cool. I’m using Ruby to repair one of our
simulation grids for our aerothermal contribution to the
STS-107 investigation.

···


Bil Kleb
NASA Langley Research Center
Hampton, Virginia, USA

Hal E. Fulton wrote:

No promises on when this can be fixed… but I can
at least dig up the old .tgz file and make it available
also on the site (v 1.0.0). Expect that soon.

OK, I’ve put a link to version 1.1.0 on
the page.

That would be cool. I’m using Ruby to repair one of our
simulation grids for our aerothermal contribution to the
STS-107 investigation.

I’m glad to know that. That certainly
makes it worthwhile.

Hal

···

----- Original Message -----
From: “Bil Kleb” William.L.Kleb@NASA.Gov
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, March 28, 2003 3:11 PM
Subject: Re: scanf failing(?) for floats read from a file

Hal E. Fulton wrote:

OK, I’ve put a link to version 1.1.0 on
the page.

And it works great!

Thanks,

···


Bil