discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] How to use the read_float_binary.m function


From: Marcus D. Leech
Subject: Re: [Discuss-gnuradio] How to use the read_float_binary.m function
Date: Thu, 27 Oct 2011 22:19:54 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Fedora/3.0.10-1.fc12 Thunderbird/3.0.10

On 27/10/11 10:09 PM, hasanimam wrote:
> Well, I have been able to run the program somehow. The following code is what
> I used.
>
> import numpy
>
> numpy.fromfile("observed_data", dtype=float, count=-1, sep='')
>
> Now, the problem is that the file I am getting does not show anything. I
> mean the characters in the file are still unreadable.
>
> I want numpy to convert the binary file to a readable one.
>
> Any idea?
>
>
>   
numpy.fromfile returns an array of "floats" within Python.  It doesn't
convert your input file, merely
  make it convenient to manipulate the contents as a Python array of floats.

Once its in that format, you can use Python to format it for you:

thingy = numpy.fromfile("observed_data", dtype=float, count=-1, sep='')

Thingy is now an array of floats.  You might, for example:

file = open ("outputfile", "w")

for n in range(0,len(thingy)):
    outstr = ("%f" % thingy[n]) + "\n"
    file.write (outstr)

file.close()

But there are lots of other, likely more efficient ways to do that in
Python.

-- 
Principal Investigator
Shirleys Bay Radio Astronomy Consortium
http://www.sbrac.org





reply via email to

[Prev in Thread] Current Thread [Next in Thread]