Problem: Reading a file

I have a problem reading an ascii file. I tried reading it using
gr_file_soucrce and extracted it using gr_vector_sink_f. Then I tried
extracting the data by using .data(); or in short, by using its
data member. Unfortunately, I always get an empty list. Why is this so?

Here’s a snippet of code to clarify things:

FALSE = bool(0)
yrx1_real = gr.file_source(gr.sizeof_float,{file location},FALSE)
Rx1_real = gr.vector_sink_f()

FLOW GRAPH CREATION

fg = gr.flow_graph ()
fg.connect (yrx1_real, Rx1_real)
fg.wait() # Ends the flowgraph… as stated in one of the replies

Calling the data extracted

Rx1 = Rx1_real.data()
print ‘After Data extraction!’
for i in range(0,1):
print Rx1[i] # I always get an empty list here.
Why?

Jason,

I think you need to start the flowgraph first.

For example

fg.connect()
fg.start()
time.sleep(1)
fg.stop()
fg.wait()

now you can grab the data from vector_sink

Because you are have repeat set to false you should also be able to try

fg.connect()
fg.run()

and again grab data from vector_sink

Thanks for your help! (Yey!) But I have another problem. It doesn’t read
the
file correctly.

For your info, the file has been generated by MATLAB using the “-ascii”
setting. Therefore the file contents look something like this.

1.7011476e+000 -1.6834541e+000 2.6309809e+000 2.1425840e+000 -
2.0272687e+000 -2.0880410e+000 2.0832361e+000 -1.8686237e+000
1.9233531e+000 3.0267080e+000

Should I change the contents of the input file so that GNU Radio can
read it
properly?

Thanks!

Jason,

I don’t have a copy of matlab with me so this is going by memory. Try
this
in matlab to generate
a file of floats

my_data = rand(1000,1);
fid = fopen(“foo.dat”,“w”);
fwrite(fid, my_data, “float32”);
fclose(fid)

Tim

Tim M. wrote:

I don’t have a copy of matlab with me so this is going by memory. Try
this in matlab to generate
a file of floats

my_data = rand(1000,1);
fid = fopen(“foo.dat”,“w”);
fwrite(fid, my_data, “float32”);
fclose(fid)

So close :wink: matlab uses ’ instead of "

my_data = rand(1000,1);
fid = fopen(‘foo.dat’,‘w’);
fwrite(fid, my_data, ‘float32’);
fclose(fid)

Write your data to your file using this method, Jonas.

Thanks Tim.

  • George

Thanks for your replies! It was helpful!

:slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs