% Script generated by Brainstorm (31-Oct-2023)

% Input files
sFiles = [];
SubjectNames = {...
    'Subject00_1.edf'};
RawFiles = {...
    '/Users/dariomilea/Documents/MATLAB/EEGLAB/sample_locs/Standard-10-20-Cap19.ced'};

% Start a new report
bst_report('Start', sFiles);

% Process: Select data files in: */*
sFiles = bst_process('CallProcess', 'process_select_files_data', sFiles, [], ...
    'subjectname',   SubjectNames{1}, ...
    'condition',     '', ...
    'tag',           '', ...
    'includebad',    0, ...
    'includeintra',  0, ...
    'includecommon', 0);

% Process: Warp default anatomy
sFiles = bst_process('CallProcess', 'process_warp', sFiles, [], ...
    'usedefault', 2, ...  % Warp
    'tolerance',  2);

% Process: Set channel file
sFiles = bst_process('CallProcess', 'process_import_channel', sFiles, [], ...
    'channelfile',  {RawFiles{1}, '4D'}, ...
    'usedefault',   1, ...  % 
    'channelalign', 1, ...
    'fixunits',     1, ...
    'vox2ras',      1);

% Process: Compute head model
sFiles = bst_process('CallProcess', 'process_headmodel', sFiles, [], ...
    'Comment',     '', ...
    'sourcespace', 1, ...  % Cortex surface
    'meg',         1, ...  % 
    'eeg',         2, ...  % 3-shell sphere
    'ecog',        1, ...  % 
    'seeg',        1, ...  % 
    'channelfile', '');

% Process: Compute covariance (noise or data)
sFiles = bst_process('CallProcess', 'process_noisecov', sFiles, [], ...
    'baseline',       [-500, -0.001], ...
    'datatimewindow', [0, 500], ...
    'sensortypes',    'MEG, EEG, SEEG, ECOG', ...
    'target',         1, ...  % Noise covariance     (covariance over baseline time window)
    'dcoffset',       1, ...  % Block by block, to avoid effects of slow shifts in data
    'identity',       0, ...
    'copycond',       0, ...
    'copysubj',       0, ...
    'copymatch',      0, ...
    'replacefile',    1);  % Replace

% Process: Compute sources [2009]
sFiles = bst_process('CallProcess', 'process_inverse', sFiles, [], ...
    'Comment',     '', ...
    'method',      3, ...  % sLORETA
    'wmne',        struct(...
         'NoiseCov',      [], ...
         'InverseMethod', 'wmne', ...
         'ChannelTypes',  {{}}, ...
         'SNR',           3, ...
         'diagnoise',     0, ...
         'SourceOrient',  {{'fixed'}}, ...
         'loose',         0.2, ...
         'depth',         1, ...
         'weightexp',     0.5, ...
         'weightlimit',   10, ...
         'regnoise',      1, ...
         'magreg',        0.1, ...
         'gradreg',       0.1, ...
         'eegreg',        0.1, ...
         'ecogreg',       0.1, ...
         'seegreg',       0.1, ...
         'fMRI',          [], ...
         'fMRIthresh',    [], ...
         'fMRIoff',       0.1, ...
         'pca',           1), ...
    'sensortypes', 'MEG, MEG MAG, MEG GRAD, EEG', ...
    'output',      1);  % Kernel only: shared

% Save and display report
ReportFile = bst_report('Save', sFiles);
bst_report('Open', ReportFile);
% bst_report('Export', ReportFile, ExportDir);
% bst_report('Email', ReportFile, username, to, subject, isFullReport);

% Delete temporary files
% gui_brainstorm('EmptyTempFolder');

