8787 checklLogFile(' checkID' , logFile );
8888 checklLogFile(' type&size' , logFile );
8989
90- logFile = saveToLogFile(logFile );
90+ logFile = saveToLogFile(logFile , cfg );
9191
9292 case ' close'
9393
108108
109109end
110110
111- function logFile = checklLogFile(action , logFile , iEvent )
111+ function logFile = checklLogFile(action , logFile , iEvent , cfg )
112112
113113 switch action
114114
137137 end
138138 end
139139
140- logFile = checkExtracolumns(logFile , iEvent );
140+ logFile = checkExtracolumns(logFile , iEvent , cfg );
141141
142142 end
143143
@@ -192,7 +192,7 @@ function printHeaderExtraColumns(logFile)
192192
193193end
194194
195- function logFile = checkExtracolumns(logFile , iEvent )
195+ function logFile = checkExtracolumns(logFile , iEvent , cfg )
196196 % loops through the extra columns
197197 % if the field we are looking for does not exist or is empty in the
198198 % action logFile structure we will write a n/a
@@ -216,11 +216,19 @@ function printHeaderExtraColumns(logFile)
216216 logFile(iEvent ).(namesExtraColumns{iExtraColumn }) = data ;
217217
218218 if any(isnan(data ))
219- warning(' Missing some %s data for this event.' , namesExtraColumns{iExtraColumn });
220- disp(logFile(iEvent ));
221- elseif all(isnan(data ))
219+ warning(' saveEventsFile:missingData' , ...
220+ ' Missing some %s data for this event.' , namesExtraColumns{iExtraColumn });
221+
222+ if cfg .verbose
223+ disp(logFile(iEvent ));
224+ end
225+
226+ elseif all(isnan(data ))
222227 warning(' Missing %s data for this event.' , namesExtraColumns{iExtraColumn });
223- disp(logFile(iEvent ));
228+
229+ if cfg .verbose
230+ disp(logFile(iEvent ));
231+ end
224232 end
225233
226234 end
@@ -258,30 +266,34 @@ function printHeaderExtraColumns(logFile)
258266 padding = expectedLength - max(size(data ));
259267 data(end + 1 : end + padding ) = nan(1 , padding );
260268 elseif ~isempty(expectedLength ) && isnumeric(data ) && max(size(data )) > expectedLength
261- warning(' A field for this event is longer than expected. Truncating the extra values.' );
269+ warning(' saveEventsFile:arrayTooLong' , ...
270+ ' A field for this event is longer than expected. Truncating the extra values.' );
262271 data = data(1 : expectedLength );
263272 end
264273
265274end
266275
267- function logFile = saveToLogFile(logFile )
276+ function logFile = saveToLogFile(logFile , cfg )
268277
269278 % appends to the logfile all the data stored in the structure
270279 % first with the standard BIDS data and then any extra things
271280 for iEvent = 1 : size(logFile , 1 )
272281
273- logFile = checklLogFile(' fields' , logFile , iEvent );
282+ logFile = checklLogFile(' fields' , logFile , iEvent , cfg );
274283
275284 onset = logFile(iEvent ).onset;
276285 duration = logFile(iEvent ).duration;
277286 trial_type = logFile(iEvent ).trial_type;
278287
279- if isnan(onset ) || ischar(onset ) || any(isempty({onset trial_type })) || ...
280- strcmp(trial_type , ' n/a' )
288+ % we skip events with onset or duration that are empty, nan or char
289+ if any(cell2mat(cellfun(@isnan , {onset duration }, ' UniformOutput' , false ))) || ...
290+ any(cellfun(@ischar , {onset duration })) || ...
291+ any(isempty({onset duration }))
281292
282- warning(' \n Skipping saving this event.\n onset: %f \n trial_type: %s\n ' , ...
293+ warning(' saveEventsFile:emptyEvent' , ...
294+ ' \n Skipping saving this event.\n onset: %s \n duration: %s\n ' , ...
283295 onset , ...
284- trial_type );
296+ duration );
285297
286298 else
287299
0 commit comments