|
47 | 47 | end |
48 | 48 |
|
49 | 49 | if nargin < 3 || isempty(logFile) |
50 | | - logFile = struct('filename', [], 'extraColumns', cell(1)); |
51 | | - logFile(1).filename = ''; |
| 50 | + logFile = checklLogFile('init'); |
52 | 51 | end |
53 | 52 |
|
54 | 53 | switch action |
|
67 | 66 |
|
68 | 67 | case 'save' |
69 | 68 |
|
70 | | - if ~isstruct(logFile) || size(logFile, 2) > 1 |
71 | | - error('The variable containing the n events to save must be a nx1 structure.'); |
72 | | - end |
| 69 | + checklLogFile('checkID', logFile); |
| 70 | + checklLogFile('type&size', logFile); |
73 | 71 |
|
74 | 72 | % appends to the logfile all the data stored in the structure |
75 | 73 | % first with the standard BIDS data and then any extra things |
|
103 | 101 |
|
104 | 102 | case 'close' |
105 | 103 |
|
| 104 | + checklLogFile('checkID', logFile); |
| 105 | + |
106 | 106 | % close txt log file |
107 | 107 | fclose(logFile(1).fileID); |
108 | 108 |
|
|
113 | 113 | logFile.filename)); |
114 | 114 |
|
115 | 115 | otherwise |
116 | | - errorStruct.message = 'unknown action for saveEventsFile'; |
117 | | - errorStruct.identifier = 'saveEventsFile:unknownActionType'; |
118 | | - error(errorStruct); |
| 116 | + |
| 117 | + errorSaveEventsFile('unknownActionType'); |
119 | 118 |
|
120 | 119 | end |
121 | 120 |
|
122 | 121 | logFile = resetLogFileVar(logFile); |
123 | 122 |
|
124 | 123 | end |
125 | 124 |
|
| 125 | +function logFile = checklLogFile(action, logFile) |
| 126 | + |
| 127 | + switch action |
| 128 | + |
| 129 | + case 'init' |
| 130 | + |
| 131 | + logFile = struct('filename', [], 'extraColumns', cell(1)); |
| 132 | + logFile(1).filename = ''; |
| 133 | + |
| 134 | + case 'checkID' |
| 135 | + |
| 136 | + if ~isfield(logFile(1), 'fileID') || isempty(logFile(1).fileID) |
| 137 | + errorSaveEventsFile('missingFileID'); |
| 138 | + end |
| 139 | + |
| 140 | + case 'type&size' |
| 141 | + |
| 142 | + if ~isstruct(logFile) || size(logFile, 2) > 1 |
| 143 | + errorSaveEventsFile('wrongFileID'); |
| 144 | + end |
| 145 | + |
| 146 | + end |
| 147 | + |
| 148 | +end |
| 149 | + |
126 | 150 | function logFile = initializeFile(expParameters, logFile) |
127 | 151 |
|
128 | 152 | % Initialize txt logfiles and empty fields for the standard BIDS |
@@ -285,3 +309,21 @@ function printExtraColumns(logFile, iEvent) |
285 | 309 | end |
286 | 310 |
|
287 | 311 | end |
| 312 | + |
| 313 | +function errorSaveEventsFile(identifier) |
| 314 | + |
| 315 | + switch identifier |
| 316 | + case 'unknownActionType' |
| 317 | + errorStruct.message = 'unknown action for saveEventsFile'; |
| 318 | + |
| 319 | + case 'missingFileID' |
| 320 | + errorStruct.message = 'logFile must contain a valid fileID field'; |
| 321 | + |
| 322 | + case 'wrongFileID' |
| 323 | + errorStruct.message = 'logFile must be a nx1 structure'; |
| 324 | + |
| 325 | + end |
| 326 | + |
| 327 | + errorStruct.identifier = ['saveEventsFile:' unknownActionType]; |
| 328 | + error(errorStruct); |
| 329 | +end |
0 commit comments