%Excitability
% clear
addpath('//your_path/brainstorm3')
if ~brainstorm('status')
    brainstorm server
end

%%
ProtocolName = 'iScience';
% get the protocol index, knowing the name
iProtocol = bst_get('Protocol', ProtocolName);
% set the current protocol
gui_brainstorm('SetCurrentProtocol', iProtocol);
ProtocolInfo=bst_get('ProtocolInfo');
my_subjects = bst_get('ProtocolSubjects');

%for %jh=1:length(my_subjects.Subject)
iSubject=bst_get('Subject',jh);
if isempty(strfind(iSubject.Name, 'Group_analysis'))
    Subject_Studies=bst_get('StudyWithSubject', iSubject.FileName);
    for sd=1:length(Subject_Studies)
        if isempty(strfind(string(Subject_Studies(sd).Condition), 'CAT12'))
            %            try
            [sStudy, iStudy]= bst_get('Study', Subject_Studies(sd).FileName);
            All_sFiles={sStudy.Result.FileName};
            
            All_sFiles = All_sFiles(not(cellfun(@isempty, strfind(All_sFiles, 'link'))));
            
            
            for hs =1:length(All_sFiles)
                
                sFiles=All_sFiles (hs);
                % Start a new report
                % bst_report('Start', sFiles);
                % Process: Excitability Index
                sFiles = bst_process('CallProcess', 'process_mfip_ExcitabilityIndex', sFiles, [], ...
                    'timewindow', [], ...
                        'scouts',     {'Desikan-Killiany', {'bankssts L', 'bankssts R', 'caudalanteriorcingulate L', 'caudalanteriorcingulate R', 'caudalmiddlefrontal L', 'caudalmiddlefrontal R', 'cuneus L', 'cuneus R', 'entorhinal L', 'entorhinal R', 'frontalpole L', 'frontalpole R', 'fusiform L', 'fusiform R', 'inferiorparietal L', 'inferiorparietal R', 'inferiortemporal L', 'inferiortemporal R', 'insula L', 'insula R', 'isthmuscingulate L', 'isthmuscingulate R', 'lateraloccipital L', 'lateraloccipital R', 'lateralorbitofrontal L', 'lateralorbitofrontal R', 'lingual L', 'lingual R', 'medialorbitofrontal L', 'medialorbitofrontal R', 'middletemporal L', 'middletemporal R', 'paracentral L', 'paracentral R', 'parahippocampal L', 'parahippocampal R', 'parsopercularis L', 'parsopercularis R', 'parsorbitalis L', 'parsorbitalis R', 'parstriangularis L', 'parstriangularis R', 'pericalcarine L', 'pericalcarine R', 'postcentral L', 'postcentral R', 'posteriorcingulate L', 'posteriorcingulate R', 'precentral L', 'precentral R', 'precuneus L', 'precuneus R', 'rostralanteriorcingulate L', 'rostralanteriorcingulate R', 'rostralmiddlefrontal L', 'rostralmiddlefrontal R', 'superiorfrontal L', 'superiorfrontal R', 'superiorparietal L', 'superiorparietal R', 'superiortemporal L', 'superiortemporal R', 'supramarginal L', 'supramarginal R', 'temporalpole L', 'temporalpole R', 'transversetemporal L', 'transversetemporal R'}}, ...
               'freqbands',  {'gamma2', '55, 95', 'mean'}, ...
                    'AveFirst',   0, ...
                    'circlesize', 0);
                % Save and display report
                % ReportFile = bst_report('Save', sFiles);
                % bst_report('Open', ReportFile);
                % bst_report('Export', ReportFile, ExportDir);
                
                
                %             catch
                %                 display(['------Problem with ---------->' iSubject.Name '-------------------' Subject_Studies(sd).FileName])
                %             end
            end
        end
    end
end
