Authored by Anthony Boyer

add struct_fix_events.m for FRE patients

  1 +function [sEvents, isModified] = struct_fix_events(sEvents)
  2 +% STRUCT_FIX_EVENTS: Fix events structures with latest prototype
  3 +
  4 +% @=============================================================================
  5 +% This function is part of the Brainstorm software:
  6 +% https://neuroimage.usc.edu/brainstorm
  7 +%
  8 +% Copyright (c)2000-2019 University of Southern California & McGill University
  9 +% This software is distributed under the terms of the GNU General Public License
  10 +% as published by the Free Software Foundation. Further details on the GPLv3
  11 +% license can be found at http://www.gnu.org/copyleft/gpl.html.
  12 +%
  13 +% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
  14 +% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
  15 +% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
  16 +% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
  17 +% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
  18 +%
  19 +% For more information type "brainstorm license" at command prompt.
  20 +% =============================================================================@
  21 +%
  22 +% Authors: Francois Tadel, 2019
  23 +
  24 +isModified = 0;
  25 +
  26 +% Compare with template structure
  27 +sTemplate = db_template('event');
  28 +% If empty, return the template
  29 +if isempty(sEvents)
  30 + sEvents = repmat(sTemplate, 1, 0);
  31 + return;
  32 +end
  33 +% If the list of fields is different: fix the structure
  34 +missingFields = setdiff(fieldnames(sTemplate), fieldnames(sEvents));
  35 +if ~isequal(fieldnames(sTemplate), fieldnames(sEvents))
  36 + if ~isempty(missingFields)
  37 + disp(['BST> Warning: Adding missing events fields: ' sprintf('%s ', missingFields{:})]);
  38 + else
  39 + disp('BST> Warning: Reordering fields in events structure...');
  40 + end
  41 + sEvents = struct_fix(sTemplate, sEvents);
  42 + isModified = 1;
  43 +end
  44 +% Fix the dimensions of all the fields
  45 +for iEvt = 1:length(sEvents)
  46 + nOcc = size(sEvents(iEvt).times, 2);
  47 + if ~isempty(sEvents(iEvt).reactTimes) && (length(sEvents(iEvt).reactTimes) ~= nOcc)
  48 + sEvents(iEvt).reactTimes = [];
  49 + end
  50 + if (length(sEvents(iEvt).channels) ~= nOcc) || ((nOcc >= 1) && ~iscell(sEvents(iEvt).channels))
  51 + sEvents(iEvt).channels = cell(1, nOcc);
  52 + if ~isModified
  53 + disp('BST> Fixed events structure: Wrong number or type of elements in field "channels".');
  54 + isModified = 1;
  55 + end
  56 + end
  57 + if (length(sEvents(iEvt).notes) ~= nOcc) || ((nOcc >= 1) && ~iscell(sEvents(iEvt).notes))
  58 + sEvents(iEvt).notes = cell(1, nOcc);
  59 + if ~isModified
  60 + disp('BST> Fixed events structure: Wrong number or type of elements in field "notes".');
  61 + isModified = 1;
  62 + end
  63 + end
  64 +end
  65 +