8383 switch action
8484
8585 case ' init'
86-
8786 % flag to indicate that this will be an _events file
8887 logFile(1 ).isStim = false ;
8988
9796 logFile = initializeFile(logFile );
9897
9998 case ' init_stim'
100-
10199 % flag to indicate that this will be an _stim file
102100 logFile(1 ).isStim = true ;
103101
111109 logFile = initializeStimFile(logFile );
112110
113111 case ' open'
114-
115112 logFile = openFile(cfg , logFile );
116113
117114 case ' save'
118-
119115 checklLogFile(' checkID' , logFile );
120116 checklLogFile(' type&size' , logFile );
121117
122118 logFile = saveToLogFile(logFile , cfg );
123119
124120 case ' close'
125-
126121 checklLogFile(' checkID' , logFile );
127122
128123 % close txt log file
136131 talkToMe(cfg , message );
137132
138133 otherwise
139-
140134 errorSaveEventsFile(' unknownActionType' );
141135
142136 end
150144 switch action
151145
152146 case ' init'
153-
154147 logFile = struct(' filename' , [], ' extraColumns' , cell(1 ));
155148 logFile(1 ).filename = ' ' ;
156149
157150 case ' checkID'
158-
159151 if ~isfield(logFile(1 ), ' fileID' ) || isempty(logFile(1 ).fileID)
160152 errorSaveEventsFile(' missingFileID' );
161153 end
162154
163155 case ' type&size'
164-
165156 if ~isstruct(logFile ) || size(logFile , 2 ) > 1
166157 errorSaveEventsFile(' wrongLogSize' );
167158 end
168159
169160 case ' fields'
170-
171161 for iFields = {' onset' , ' trial_type' , ' duration' }
172162 if ~isfield(logFile , iFields ) || isempty(logFile(iEvent ).(iFields{1 }))
173163 logFile(iEvent ).(iFields{1 }) = nan ;
207197end
208198
209199function logFile = initializeStimFile(logFile )
210-
211200 logFile = initializeExtraColumns(logFile );
212-
213201end
214202
215203function logFile = openFile(cfg , logFile )
@@ -247,18 +235,14 @@ function printHeaderExtraColumns(logFile)
247235 % print any extra column specified by the user
248236
249237 [namesExtraColumns ] = returnNamesExtraColumns(logFile );
250-
251238 for iExtraColumn = 1 : numel(namesExtraColumns )
252239
253240 nbCol = returnNbColumns(logFile , namesExtraColumns{iExtraColumn });
254241
255242 for iCol = 1 : nbCol
256-
257243 headerName = returnHeaderName(namesExtraColumns{iExtraColumn }, nbCol , iCol );
258-
259244 fprintf(logFile(1 ).fileID, ' \t%s ' , headerName );
260245 fprintf(1 , ' \t%s ' , headerName );
261-
262246 end
263247
264248 end
@@ -272,7 +256,6 @@ function printHeaderExtraColumns(logFile)
272256 % otherwise we write its content
273257
274258 namesExtraColumns = returnNamesExtraColumns(logFile );
275-
276259 for iExtraColumn = 1 : numel(namesExtraColumns )
277260
278261 nbCol = returnNbColumns(logFile , namesExtraColumns{iExtraColumn });
@@ -291,7 +274,6 @@ function printHeaderExtraColumns(logFile)
291274 if ~ischar(data )
292275
293276 warningMessage = [];
294-
295277 if any(isnan(data ))
296278 warningMessage = sprintf( ...
297279 ' Missing some %s data for this event.' , ...
@@ -303,7 +285,6 @@ function printHeaderExtraColumns(logFile)
303285 namesExtraColumns{iExtraColumn });
304286
305287 end
306-
307288 warningSaveEventsFile(cfg , ' missingData' , warningMessage );
308289
309290 if cfg .verbose > 1
@@ -320,7 +301,6 @@ function printHeaderExtraColumns(logFile)
320301 % check the data to write
321302 % default will be 'n/a' for chars and NaN for numeric data
322303 % for numeric data that don't have the expected length, it will be padded with NaNs
323-
324304 if islogical(data ) && data
325305 data = ' true' ;
326306 elseif islogical(data ) && ~data
@@ -346,12 +326,10 @@ function printHeaderExtraColumns(logFile)
346326 if ~isempty(expectedLength ) && isnumeric(data )
347327
348328 if max(size(data )) < expectedLength
349-
350329 padding = expectedLength - max(size(data ));
351330 data(end + 1 : end + padding ) = nan(1 , padding );
352331
353332 elseif max(size(data )) > expectedLength
354-
355333 warningMessage = [' A field for this event is longer than expected.' , ...
356334 ' Truncating extra values.' ];
357335 warningSaveEventsFile(cfg , ' arrayTooLong' , warningMessage );
@@ -416,6 +394,7 @@ function printHeaderExtraColumns(logFile)
416394 warningMessageID = ' emptyEvent' ;
417395 warningMessage = sprintf([' Skipping saving this event. \n ' , ...
418396 ' No values defined. \n ' ]);
397+
419398 elseif any(~isValid )
420399 skipEvent = false ;
421400
@@ -454,36 +433,27 @@ function printToFile(cfg, logFile, skipEvent, iEvent)
454433
455434function printExtraColumns(logFile , iEvent , cfg )
456435 % loops through the extra columns and print them
457-
458436 namesExtraColumns = returnNamesExtraColumns(logFile );
459-
460437 for iExtraColumn = 1 : numel(namesExtraColumns )
461-
462438 data = logFile(iEvent ).(namesExtraColumns{iExtraColumn });
463-
464439 printData(logFile(1 ).fileID, data , cfg );
465-
466440 end
467-
468441end
469442
470443function printData(output , data , cfg )
471444 % write char
472445 % for numeric data we replace any nan by n/a
473446 if ischar(data )
474-
475447 content = sprintf(' %s\t ' , data );
476448 fprintf(output , content );
477449 talkToMe(cfg , content );
478450
479451 else
480-
481452 for i = 1 : numel(data )
482453 if isnan(data(i ))
483454 content = sprintf(' %s\t ' , ' n/a' );
484455 else
485456 content = sprintf(' %f\t ' , data(i ));
486-
487457 end
488458 fprintf(output , content );
489459 talkToMe(cfg , content );
@@ -505,11 +475,9 @@ function printData(output, data, cfg)
505475 namesColumns = cat(2 , namesColumns , namesExtraColumns ' );
506476
507477 for iColumn = 1 : numel(namesColumns )
508-
509478 if isfield(logFile , namesColumns{iColumn })
510479 logFile = rmfield(logFile , namesColumns{iColumn });
511480 end
512-
513481 end
514482
515483end
@@ -534,17 +502,16 @@ function errorSaveEventsFile(identifier)
534502
535503 errorStruct.identifier = [' saveEventsFile:' identifier ];
536504 error(errorStruct );
505+
537506end
538507
539508function warningSaveEventsFile(cfg , identifier , warningMessage )
540-
541509 if cfg .verbose > 0 && ...
542510 nargin == 3 && ...
543511 ~isempty(identifier ) && ...
544512 ~isempty(warningMessage )
545513
546514 warningMessageID = [' saveEventsFile:' identifier ];
547515 warning(warningMessageID , warningMessage );
548-
549516 end
550517end
0 commit comments