|
73 | 73 | % |
74 | 74 |
|
75 | 75 | if nargin < 2 |
76 | | - error(['Missing arguments. Please specify <action input> ',... |
| 76 | + error(['Missing arguments. Please specify <action input> ', ... |
77 | 77 | 'and <cfg file> as the first two arguments']); |
78 | 78 | end |
79 | 79 |
|
|
86 | 86 | case 'init' |
87 | 87 |
|
88 | 88 | % flag to indicate that this will be an _events file |
89 | | - logFile(1).isStim = false; |
| 89 | + logFile(1).isStim = false; |
90 | 90 |
|
91 | | - if isfield(cfg,'fileName') && ... |
92 | | - isfield(cfg.fileName,'events') && ... |
| 91 | + if isfield(cfg, 'fileName') && ... |
| 92 | + isfield(cfg.fileName, 'events') && ... |
93 | 93 | ~isempty(cfg.fileName.events) |
94 | 94 | logFile(1).filename = cfg.fileName.events; |
95 | 95 | else |
96 | | - logFile(1).filename = ''; |
| 96 | + logFile(1).filename = ''; |
97 | 97 | end |
98 | 98 | logFile = initializeFile(logFile); |
99 | | - |
| 99 | + |
100 | 100 | case 'init_stim' |
101 | 101 |
|
102 | 102 | % flag to indicate that this will be an _stim file |
103 | | - logFile(1).isStim = true; |
104 | | - |
105 | | - if isfield(cfg,'fileName') && ... |
106 | | - isfield(cfg.fileName,'stim') && ... |
| 103 | + logFile(1).isStim = true; |
| 104 | + |
| 105 | + if isfield(cfg, 'fileName') && ... |
| 106 | + isfield(cfg.fileName, 'stim') && ... |
107 | 107 | ~isempty(cfg.fileName.stim) |
108 | 108 | logFile(1).filename = cfg.fileName.stim; |
109 | 109 | else |
110 | | - logFile(1).filename = ''; |
| 110 | + logFile(1).filename = ''; |
111 | 111 | end |
112 | 112 | logFile = initializeStimFile(logFile); |
113 | 113 |
|
114 | 114 | case 'open' |
115 | 115 |
|
116 | 116 | logFile = openFile(cfg, logFile); |
117 | 117 |
|
118 | | - |
119 | 118 | case 'save' |
120 | 119 |
|
121 | 120 | checklLogFile('checkID', logFile); |
|
178 | 177 | end |
179 | 178 |
|
180 | 179 | function logFile = initializeFile(logFile) |
181 | | -% This function creates the bids field structure for json files for the |
182 | | -% three basic bids event columns, and for all requested extra columns. |
183 | | -% |
184 | | -% Note that subfields (e.g. unit, levels etc. can be changed by the user |
185 | | -% before calling openFile. |
| 180 | + % This function creates the bids field structure for json files for the |
| 181 | + % three basic bids event columns, and for all requested extra columns. |
| 182 | + % |
| 183 | + % Note that subfields (e.g. unit, levels etc. can be changed by the user |
| 184 | + % before calling openFile. |
186 | 185 |
|
187 | 186 | % initialize holy trinity (onset, trial_type, duration) columns |
188 | 187 | logFile(1).columns = struct( ... |
189 | | - 'onset', struct( ... |
190 | | - 'Description', 'time elapsed since experiment start', ... |
191 | | - 'Units', 's'), ... |
192 | | - 'trial_type', struct( ... |
193 | | - 'Description', 'types of trial', ... |
194 | | - 'Levels', ''), ... |
195 | | - 'duration', struct( ... |
196 | | - 'Description', 'duration of the event or the block', ... |
197 | | - 'Units', 's') ... |
198 | | - ); |
199 | | - |
| 188 | + 'onset', struct( ... |
| 189 | + 'Description', ... |
| 190 | + 'time elapsed since experiment start', ... |
| 191 | + 'Units', 's'), ... |
| 192 | + 'trial_type', struct( ... |
| 193 | + 'Description', 'types of trial', ... |
| 194 | + 'Levels', ''), ... |
| 195 | + 'duration', struct( ... |
| 196 | + 'Description', ... |
| 197 | + 'duration of the event or the block', ... |
| 198 | + 'Units', 's') ... |
| 199 | + ); |
200 | 200 |
|
201 | 201 | logFile = initializeExtraColumns(logFile); |
202 | 202 |
|
203 | 203 | end |
204 | 204 |
|
205 | 205 | function logFile = initializeStimFile(logFile) |
206 | | - |
| 206 | + |
207 | 207 | logFile = initializeExtraColumns(logFile); |
208 | 208 |
|
209 | 209 | end |
|
231 | 231 | % next line so we start printing at the right place |
232 | 232 | fprintf(logFile(1).fileID, '\n'); |
233 | 233 | fprintf(1, '\n'); |
234 | | - |
| 234 | + |
235 | 235 | elseif logFile(1).isStim |
236 | 236 | % don't print column headers for _stim.tsv |
237 | | - |
| 237 | + |
238 | 238 | end |
239 | 239 |
|
240 | 240 | end |
@@ -266,7 +266,7 @@ function printHeaderExtraColumns(logFile) |
266 | 266 | % if the field we are looking for does not exist or is empty in the |
267 | 267 | % action logFile structure we will write a n/a |
268 | 268 | % otherwise we write its content |
269 | | - |
| 269 | + |
270 | 270 | namesExtraColumns = returnNamesExtraColumns(logFile); |
271 | 271 |
|
272 | 272 | for iExtraColumn = 1:numel(namesExtraColumns) |
@@ -294,7 +294,7 @@ function printHeaderExtraColumns(logFile) |
294 | 294 |
|
295 | 295 | elseif ~ischar(data) && all(isnan(data)) |
296 | 296 | warning('Missing %s data for this event.', namesExtraColumns{iExtraColumn}); |
297 | | - |
| 297 | + |
298 | 298 | if cfg.verbose > 1 |
299 | 299 | disp(logFile(iEvent)); |
300 | 300 | end |
@@ -344,86 +344,85 @@ function printHeaderExtraColumns(logFile) |
344 | 344 |
|
345 | 345 | function logFile = saveToLogFile(logFile, cfg) |
346 | 346 |
|
347 | | - |
348 | 347 | % appends to the logfile all the data stored in the structure |
349 | 348 | % first with the standard BIDS data and then any extra things |
350 | 349 | for iEvent = 1:size(logFile, 1) |
351 | 350 |
|
352 | 351 | logFile = checklLogFile('fields', logFile, iEvent, cfg); |
353 | 352 |
|
354 | 353 | % check if this event should be skipped |
355 | | - skipEvent = false; |
356 | | - |
357 | | - % if this is _events file, we skip events with onset or duration |
358 | | - % that are empty, nan or char. |
| 354 | + skipEvent = false; |
| 355 | + |
| 356 | + % if this is _events file, we skip events with onset or duration |
| 357 | + % that are empty, nan or char. |
359 | 358 | if ~logFile(1).isStim |
360 | | - |
| 359 | + |
361 | 360 | onset = logFile(iEvent).onset; |
362 | 361 | duration = logFile(iEvent).duration; |
363 | 362 | trial_type = logFile(iEvent).trial_type; |
364 | 363 |
|
365 | 364 | if any(cell2mat(cellfun(@isnan, {onset duration}, 'UniformOutput', false))) || ... |
366 | 365 | any(cellfun(@ischar, {onset duration})) || ... |
367 | | - any(isempty({onset duration})) |
| 366 | + any(isempty({onset duration})) |
368 | 367 |
|
369 | | - skipEvent = true; |
| 368 | + skipEvent = true; |
370 | 369 |
|
371 | | - warningMessageID = 'saveEventsFile:emptyEvent'; |
| 370 | + warningMessageID = 'saveEventsFile:emptyEvent'; |
372 | 371 | warningMessage = sprintf(['Skipping saving this event. \n '... |
373 | 372 | 'onset: %s \n duration: %s \n'], ... |
374 | 373 | onset, ... |
375 | 374 | duration); |
376 | 375 | end |
377 | | - |
378 | | - % if this is _stim file, we skip missing events (i.e. events where |
379 | | - % all extra columns have NO values) |
| 376 | + |
| 377 | + % if this is _stim file, we skip missing events (i.e. events where |
| 378 | + % all extra columns have NO values) |
380 | 379 | elseif logFile(1).isStim |
381 | | - |
| 380 | + |
382 | 381 | namesExtraColumns = returnNamesExtraColumns(logFile); |
383 | | - isValid = ones(1,numel(namesExtraColumns)); |
| 382 | + isValid = ones(1, numel(namesExtraColumns)); |
384 | 383 | for iExtraColumn = 1:numel(namesExtraColumns) |
385 | | - data = logFile(iEvent).(namesExtraColumns{iExtraColumn}); |
386 | | - if isempty(data) || isnan(data) || ( ischar(data) && strcmp(data,'n/a') ) |
387 | | - isValid(iExtraColumn) = 0; |
| 384 | + data = logFile(iEvent).(namesExtraColumns{iExtraColumn}); |
| 385 | + if isempty(data) || isnan(data) || (ischar(data) && strcmp(data, 'n/a')) |
| 386 | + isValid(iExtraColumn) = 0; |
388 | 387 | end |
389 | 388 | end |
390 | | - if all(~isValid) |
391 | | - skipEvent = true; |
392 | | - |
393 | | - warningMessageID = 'saveEventsFile:emptyEvent'; |
| 389 | + if all(~isValid) |
| 390 | + skipEvent = true; |
| 391 | + |
| 392 | + warningMessageID = 'saveEventsFile:emptyEvent'; |
394 | 393 | warningMessage = sprintf(['Skipping saving this event. \n', ... |
395 | | - 'No values defined. \n']); |
396 | | - elseif any(~isValid) |
397 | | - skipEvent = false; |
398 | | - |
399 | | - warningMessageID = 'saveEventsFile:missingData'; |
| 394 | + 'No values defined. \n']); |
| 395 | + elseif any(~isValid) |
| 396 | + skipEvent = false; |
| 397 | + |
| 398 | + warningMessageID = 'saveEventsFile:missingData'; |
400 | 399 | warningMessage = sprintf('Missing some %s data for this event. \n', ... |
401 | | - namesExtraColumns{find(isValid)}); |
| 400 | + namesExtraColumns{find(isValid)}); |
402 | 401 | end |
403 | 402 | end |
404 | | - |
| 403 | + |
405 | 404 | % now save the event to log file (if not skipping) |
406 | | - if skipEvent |
407 | | - |
408 | | - warning(warningMessageID, warningMessage); |
409 | | - |
| 405 | + if skipEvent |
| 406 | + |
| 407 | + warning(warningMessageID, warningMessage); |
| 408 | + |
410 | 409 | else |
411 | | - |
| 410 | + |
412 | 411 | if ~logFile(1).isStim |
413 | | - |
| 412 | + |
414 | 413 | printData(logFile(1).fileID, onset, cfg); |
415 | 414 | printData(logFile(1).fileID, duration, cfg); |
416 | 415 | printData(logFile(1).fileID, trial_type, cfg); |
417 | 416 |
|
418 | 417 | end |
419 | | - |
| 418 | + |
420 | 419 | printExtraColumns(logFile, iEvent, cfg); |
421 | 420 |
|
422 | 421 | fprintf(logFile(1).fileID, '\n'); |
423 | 422 | fprintf(1, '\n'); |
424 | 423 |
|
425 | 424 | end |
426 | | - |
| 425 | + |
427 | 426 | end |
428 | 427 |
|
429 | 428 | end |
|
0 commit comments