Saving internal (to a block) variable values to a file

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.

Are you talking about gr.file_sink() ?


View this message in context:
http://gnuradio.4.n7.nabble.com/saving-internal-to-a-block-variable-values-to-a-file-tp38118p38120.html
Sent from the GnuRadio mailing list archive at Nabble.com.

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 [email protected]
To: [email protected]
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-a-block-variable-values-to-a-file-tp38118p38120.html
Sent from the GnuRadio mailing list archive at Nabble.com.

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-a-block-variable-values-to-a-file-tp38118p38123.html
Sent from the GnuRadio mailing list archive at Nabble.com.

I first this question :slight_smile:


From: sumitstop [email protected]
To: [email protected]
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-a-block-variable-values-to-a-file-tp38118p38123.html
Sent from the GnuRadio mailing list archive at Nabble.com.

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 :slight_smile:


View this message in context:
http://gnuradio.4.n7.nabble.com/saving-internal-to-a-block-variable-values-to-a-file-tp38118p38125.html
Sent from the GnuRadio mailing list archive at Nabble.com.

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

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
#include

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 T. Diaz [email protected]
To: sumitstop [email protected]; [email protected]
Cc: [email protected]
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
[email protected] wrote:

Well I am pretty sure that your query is more complicated than what I am

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.

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