I'm experiencing an issue with Brainstorm when using a loop to create multiple files under the same subject and condition within a minute. For instance, when I subtract a specific time series from all trials using the difference function, I typically use a loop like the one below, as batch processing from the process tab isn't an option:
for file = 1:length(action_files_sub)
% Process: Difference: A-B
sFiles = bst_process('CallProcess', 'process_diff_ab', action_files_sub{file}, tone_files_sub);
% Process: Add tag: base_f_tone_2_45
sFiles = bst_process('CallProcess', 'process_add_tag', sFiles, [], ...
'tag', 'tone_subtracted', ...
'output', 'name_path'); % Add to file name and file path
%pause(60);
end
Brainstorm typically names each file based on the clock. Despite changing the name by adding a tag, files get replaced if they are processed within the same minute. To avoid this, I had to use pause(60)
, which significantly increases the script's runtime.
To address this, I modified the following naming scheme in the GetNewFilename function of the bst_process.m file to include seconds in the timestamp, allowing me to reduce the pause to just 1 second:
Before:
if isTimestamp
c = clock;
strTime = sprintf('_%02.0f%02.0f%02.0f_%02.0f%02.0f', c(1)-2000, c(2:5));
else
strTime = '';
end
After:
if isTimestamp
c = ceil(clock);
strTime = sprintf('_%02.0f%02.0f%02.0f_%02.0f%02.0f%02.0f', c(1)-2000, c(2:6));
else
strTime = '';
end
This change has significantly improved the runtime. While I haven't encountered any issues so far, I'm uncertain if this modification might affect other Brainstorm functionalities. It would be great if you could review and potentially implement this change on your end, considering any necessary additional adjustments.
Thanks in advance,
Sainath Murali