All, I have a custom block and some internal variables within it. I want to save one (or more) of those variables into a file for offline plotting. I know there are gnuradio examples which does this. Can someone point me where to look at? Thanks, Yu.
on 2012-10-23 19:04
on 2012-10-23 21:33
Are you talking about gr.file_sink() ? -- View this message in context: http://gnuradio.4.n7.nabble.com/saving-internal-to... Sent from the GnuRadio mailing list archive at Nabble.com.
on 2012-10-23 21:57
No. I have written work function for a custom block. Inside that work function, I have a local variable "temp" which updates very less frequently. Since the output of the block updates at a different (higher) rate, I can't pull out temp to make it an output. How should I go about saving the values of temp? ________________________________ From: sumitstop <sumit.kumar@research.iiit.ac.in> To: Discuss-gnuradio@gnu.org Sent: Tuesday, October 23, 2012 2:32 PM Subject: Re: [Discuss-gnuradio] saving internal (to a block) variable values to a file Are you talking about gr.file_sink() ? -- View this message in context: http://gnuradio.4.n7.nabble.com/saving-internal-to... Sent from the GnuRadio mailing list archive at Nabble.com.
on 2012-10-23 22:24
Although I have not done that much work on work() so far but out of curiosity am asking : can't we write temp to some file , inside the block of work() itself so we need not to make it as output. -- View this message in context: http://gnuradio.4.n7.nabble.com/saving-internal-to... Sent from the GnuRadio mailing list archive at Nabble.com.
on 2012-10-23 22:32
I first this question :) ________________________________ From: sumitstop <sumit.kumar@research.iiit.ac.in> To: Discuss-gnuradio@gnu.org Sent: Tuesday, October 23, 2012 3:23 PM Subject: Re: [Discuss-gnuradio] saving internal (to a block) variable values to a file Although I have not done that much work on work() so far but out of curiosity am asking : can't we write temp to some file , inside the block of work() itself so we need not to make it as output. -- View this message in context: http://gnuradio.4.n7.nabble.com/saving-internal-to... Sent from the GnuRadio mailing list archive at Nabble.com.
on 2012-10-23 23:10
Well I am pretty sure that your query is more complicated than what I am
thinking, but I did the following just to check. Inside the work
function of
howto_square_ff.cc
I pasted following lines
ofstream outdata;
int i; // loop index
int num[5] = {4, 3, 6, 7, 12}; // list of output values
outdata.open("/home/sumit/example2.dat");
for (i=0; i<5; ++i)
outdata << num[i] << std::endl;
outdata.close();
compiled it ...
And I got them written in example2.dat
Anyways I am curious to see if you get some effective reply :)
--
View this message in context:
http://gnuradio.4.n7.nabble.com/saving-internal-to...
Sent from the GnuRadio mailing list archive at Nabble.com.
on 2012-10-24 02:02
Hi,
Also I'm saving some variables into a file. What I did:
Before the work function:
myfile.open ("/home/Desktop/examples/variables_from_block");
Then, inside the work function:
myfile << _msg.key; //Save the variable value
myfile << std::flush;
I've found that I have to std::flush the file, because if I close it
(myfile.close()), I cannot access the file anymore and the variable is
saved once only.
Hope this helps,
Cheers,
Jose
On Wed, Oct 24, 2012 at 7:37 AM, sumitstop
on 2012-10-25 20:02
All,
Just for future reference, below is the summary of what I did:
In my .cc file:
Added these lines at the top:
using namespace std;
#include <fstream>
#include <iostream>
std::ofstream myfileobj;
Added this line into my constructor definition:
myfileobj.open("/home/temp-values.txt");
Added this line into my work function:
myfileobj<< temp << std::endl; // temp is a float variable
Finally, added this line into my destructor definition:
myfileobj.close();
Now, the only issue I am having is that if I save my file as .dat and
then use read_float_binary to read the values then it gives me garbage
values instead of actual ones. Moreover, the file size is larger than
expected, i.e., number of items is more than expected, and the item size
is 8 bytes instead of 4 bytes (for float).
Nevertheless, I can live with using the .txt file for now and will work
on using .dat later. Meanwhile, if someone finds some obvious mistake in
my approach, please let me know.
Thanks Sumit and Jose.
________________________________
From: Jose Torres Diaz <torresdiaz.jose@gmail.com>
To: sumitstop <sumit.kumar@research.iiit.ac.in>; zing.yu@yahoo.com
Cc: Discuss-gnuradio@gnu.org
Sent: Tuesday, October 23, 2012 7:01 PM
Subject: Re: [Discuss-gnuradio] saving internal (to a block) variable
values to a file
Hi,
Also I'm saving some variables into a file. What I did:
Before the work function:
myfile.open ("/home/Desktop/examples/variables_from_block");
Then, inside the work function:
myfile << _msg.key; //Save the variable value
myfile << std::flush;
I've found that I have to std::flush the file, because if I close it
(myfile.close()), I cannot access the file anymore and the variable is
saved once only.
Hope this helps,
Cheers,
Jose
On Wed, Oct 24, 2012 at 7:37 AM, sumitstop
<sumit.kumar@research.iiit.ac.in> wrote:
Well I am pretty sure that your query is more complicated than what I am
on 2012-10-25 21:54
You have to open the file in "binary" mode to write binary data, otherwise it is in text mode by default. Doesn't matter what the extension is - txt or dat or anything else - what matters is how you are opening the file in fstream::open. Hope that helps.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.