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