discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] saving internal (to a block) variable values to a


From: Zing Yu
Subject: Re: [Discuss-gnuradio] saving internal (to a block) variable values to a file
Date: Thu, 25 Oct 2012 11:01:23 -0700 (PDT)

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 <address@hidden>
To: sumitstop <address@hidden>; address@hidden
Cc: address@hidden
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 <address@hidden> wrote:
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-a-block-variable-values-to-a-file-tp38118p38125.html
Sent from the GnuRadio mailing list archive at Nabble.com.

_______________________________________________
Discuss-gnuradio mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio






reply via email to

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