0

So I write a log file containing 16 bit integer data. Using the following way.

std::ofstream waveform;
waveform.open("waveform.iq");
cout << "Opening file for waveform " << endl;
LOOP WRITING BUFFER VALUES TO THE FILE
waveform  << R0 << std::endl; // Write Sample
LOOP END
waveform.close();

At the end I have an iq file containing samples like

0
16343
30000
.....

And so on.

How do I read this long file in such a way that I take blocks of 8192 samples once in an array and then again until the whole file ends. If at the end the file does not have sufficient samples to fill 8192 samples then it repeats the waveform.

Can I implement this reading of file using vector class ?

Is writing done in an efficient manner ?

Thank YOu.

jav321
  • 151
  • 2
  • 11
  • 1
    Have you tried to write this? Shouldn't you try to complete it before you ask people here to do it for you? – Fantastic Mr Fox Jan 25 '17 at 18:55
  • 2
    "How do I read this long file in such a way that I take blocks of 8192 samples once " You can't - you need to write out your integers in unformatted mode using the write() function, rather than using formatted output. –  Jan 25 '17 at 18:58
  • You need to be clear if you are trying to write a binary file or human-readable ASCII file. Have you got, or can you get, a file that works which contains 8192 samples of 16-bit data? If your file is binary, it will have 2 bytes (16-bits) for each sample and no carriage returns or line feeds, so it will have exactly 16384 bytes and you will not be able to look at it in the Terminal with `more FILENAME.IQ`. If your file should be in ASCII, it will have more than 16384 bytes, and it will have newlines after each value and be readable with `more FILENAME.IQ`. – Mark Setchell Jan 25 '17 at 20:28
  • See also... http://stackoverflow.com/a/15274953/2836621 – Mark Setchell Jan 25 '17 at 20:35
  • So I understood. Yes, I tried but I just needed hints. So now I know that the better way is to write the data as in binary with no carriage returns. In this way, it is possible for me to acquire data in the form of blocks of 8192 samples of 16bit integers. If on the other hand, I have samples written in human readable format in a "text file" then the thing gets much more complicated. Am I right here ? I will try my code and post it in comments. Thank you all. – jav321 Jan 25 '17 at 20:58
  • OS file access routines support block reading of "any" size but for that you need to specify OS and compiler/IDE. You can do this on both binary and text files but in case of text you need to write it formated so each number has exact the same amount of BYTES. The text files are slower as you need to convert between text and binary form in booth reading and writing operations (but are easily updated/viewed by human for debugging purposes). – Spektre Feb 10 '17 at 10:00

0 Answers0