Hi,
I am running an experiment containing multiple trials.
Data for each trial are logged to a text file (using log() from WriteFile) inside of render().
What is the best approach for creating and closing a separate for each trial?
Currently the files are not closing between trials. We identified the WriteFile::writeAllData() function but it does not appear to write and close the file properly.
I have pasted a minimal example of our current solution below:
WriteFile file1;
void loop(void*) {
// This is the auxilary task function which will read our Trill sensors
// loop
while(!Bela_stopRequested())
{
// newtrial is a variable set to 1 based on user input (code not shown here).
if(newtrial){
file1.setup("out.bin"); //set the file name to write to
file1.setEchoInterval(10000); // only print to the console every 10000 calls to log
file1.setFileType(kBinary);
// set the format that you want to use for your output.
// Please use %f only (with modifiers).
// When in binary mode, this is used only for echoing to console
file1.setFormat("binary: %.4f %.4f %.4f %.4f\n")
}
}
bool setup(BelaContext *context, void *userData)
{
}
void render(BelaContext *context, void *userData)
{
static int count = 0;
for(unsigned int n = 0; n < context->analogFrames; ++n) {
file1.log(somedata); // log an array of values: the first 4 channels from analog input
}
count += context->analogFrames;
}
void cleanup(BelaContext *context, void *userData)
{
}
Thanks in advance,
Annna