From: Logan Capaldo Date: 2006-05-04T10:24:27+09:00 Subject: Re: So I got a binary file... On May 3, 2006, at 3:15 PM, bostonmacosx wrote: > HI all and thanks for the help. > After beating around a little. > > mydata = String.new > f = File.open("WesObs_Sumatra_032805.sac","rb") > newstring = f.read > > newdata = newstring.unpack('f*\n') > fw = File.open("test.txt","wb") > fw.write(newdata[0]) > > Is all I needed to do to extract the floats from the binary data in > the > file. > Was a lot simpler then I though. > I didn't know that unpack stuck things in arrays so that was the > largest > problem I was having. > > Onto problem #2. > > > > > -- > Posted via http://www.ruby-forum.com/. > Please don't forget to close your files. Better than that, use the block form which takes care of closing the file for you. newstring = nil File.open("WesObs_Sumatra_032805.sac","rb") do |f| newstring = f.read end # file is automatically closed at the end of this block, even if an exception is raised also I believe the "\n" in the unpack string is both unnecessary and meaningless.