
clear
%
overwrite = 1;

subject = [10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 ]
%% DELETING DATA FROM EXPERIMENT 1
for isubj = subject
    %isubj = 10;
    
    
    % Define globals
    global G;
    G = [];
    % First load the data file
    G.data_file_name = ['dformat_s',num2str(isubj)];
    
    %% General paths
    exp_main_path = '/project/3018029.06';
    
    SUBJS = {['0',num2str(isubj)]}
    curSubj = SUBJS{1}
    
    %addpath(genpath( [exp_main_path , filesep 'MEG_analysis' filesep 'AVE_MEG' filesep 'scripts'])); % general processing scripts in this exp.
    G.subjPath = [exp_main_path filesep 'MEG' filesep curSubj filesep]; % main subject folder
    
    G.preprocPath = [exp_main_path filesep 'Preproc' filesep curSubj filesep]; % main subject folder
    
    G.outputPath = [G.subjPath ,'func', filesep]; % subject saving artifact and preprocessing matrixes
   
    %G.cfgbehavPath = [exp_main_path filesep 'Behavioral' filesep curSubj filesep] ; % behavioral data of participant
    
    subjscriptsPath = [G.subjPath ,'analysis', filesep]; %  participant specific scripts
    
    addpath(genpath('/project/3018029.06/Matlab/MEG_scripts/'));
    %rmdir([G.subjPath,'func/univ_results'], 's')
    %rmdir([G.subjPath,'func/deci_results'], 's')
    %rmdir([G.subjPath,'func/TFR_results'], 's')
    rmdir([G.subjPath,'func/behav_meg_results'], 's')
    

 
end


subject = [47 48 49 50 51 52 53 55 56  57 58 59 60 61 62 63 64 65 66 67 68 69 70 71]
%% DELETING DATA FROM EXPERIMENT 2
for isubj = subject
    %isubj = 10;
    
    
    % Define globals
    global G;
    G = [];
    % First load the data file
    G.data_file_name = ['dformat_s',num2str(isubj)];
    
    %% General paths
    exp_main_path = '/project/3018029.06';
    
    SUBJS = {['0',num2str(isubj)]}
    curSubj = SUBJS{1}
    
    %addpath(genpath( [exp_main_path , filesep 'MEG_analysis' filesep 'AVE_MEG' filesep 'scripts'])); % general processing scripts in this exp.
    G.subjPath = [exp_main_path filesep 'MEG' filesep 'AVE_MEG3' filesep curSubj filesep]; % main subject folder
    
  
    G.outputPath = [G.subjPath ,'func', filesep]; % subject saving artifact and preprocessing matrixes
   
    %G.cfgbehavPath = [exp_main_path filesep 'Behavioral' filesep curSubj filesep] ; % behavioral data of participant
    
    subjscriptsPath = [G.subjPath ,'analysis', filesep]; %  participant specific scripts
    
    addpath(genpath('/project/3018029.06/Matlab/MEG_scripts/'));
    rmdir([G.subjPath,'func/univ_results'], 's')
    rmdir([G.subjPath,'func/multiv_results'], 's')
    %rmdir([G.subjPath,'func/deci_results'], 's')
    %rmdir([G.subjPath,'func/TFR_results'], 's')
    rmdir([G.subjPath,'func/behav_meg_results'], 's')
    

 
end


%% MOVING DATA FROM EXPERIMENT 1
%% Select your parameters to select the data where you want to perform the analysis

format.baseline = [-0.2 0];
format.lpfreq = 30;
%format.hpfreq = 2;
format.resamplefs = 200;
format.detrend = 'no';
format.trigger_ref = 'target'; % what is the trigger used as a reference

%% Select your parameters to identify the analysis that you want to perform. Change everytime accordingly


param.trials_sel = 'all' %? correct/all % {'MEG'} what trials go in the analysis?
param.channels_sel = {'allchan'}; %{'MEG', 'UADC007'} ; % all, {'MLO*','MRO*','MZO*'}  % {'MEG', 'UADC007'} what channels go in the analyses ,'UADC007'
subject = [10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 ]

for isubj = subject
    %isubj = 11;
    
    
    % Define globals
    global G;
    G = [];
    % First load the data file
    G.data_file_name = ['dformat_s',num2str(isubj)];
    
    %% General paths
    exp_main_path = '/project/3018029.06';
    
    SUBJS = {['0',num2str(isubj)]}
    curSubj = SUBJS{1}
    
    %addpath(genpath( [exp_main_path , filesep 'MEG_analysis' filesep 'AVE_MEG' filesep 'scripts'])); % general processing scripts in this exp.
    G.subjPath = [exp_main_path filesep 'MEG' filesep curSubj filesep]; % main subject folder
    
    G.preprocPath = [exp_main_path filesep 'Preproc' filesep curSubj filesep]; % main subject folder
    
    G.outputPath = [G.subjPath ,'func', filesep]; % subject saving artifact and preprocessing matrixes
   
    %G.cfgbehavPath = [exp_main_path filesep 'Behavioral' filesep curSubj filesep] ; % behavioral data of participant
    
    subjscriptsPath = [G.subjPath ,'analysis', filesep]; %  participant specific scripts
    
    addpath(genpath('/project/3018029.06/Matlab/MEG_scripts/'));
  

    
    if ~exist( G.preprocPath,'dir')
        mkdir( G.preprocPath);
    end
    infile = fullfile(G.outputPath, filesep, [G.data_file_name, '.mat']);
    outfile = fullfile(G.preprocPath, filesep);
    
    copyfile(infile, outfile)
    
end


%% MOVING DATA FROM EXPERIMENT 2

param.trials_sel = 'all' %? correct/all % {'MEG'} what trials go in the analysis?
param.channels_sel = {'allchan'}; %{'MEG', 'UADC007'} ; % all, {'MLO*','MRO*','MZO*'}  % {'MEG', 'UADC007'} what channels go in the analyses ,'UADC007'
subject = [47 48 49 50 51 52 53 55 56  57 58 59 60 61 62 63 64 65 66 67 68 69 70 71]

for isubj = subject
    %isubj = 47;
    
    
    % Define globals
    global G;
    G = [];
    % First load the data file
    G.data_file_name = ['dformat_s',num2str(isubj)];
    
    %% General paths
    exp_main_path = '/project/3018029.06';
    
    SUBJS = {['0',num2str(isubj)]}
    curSubj = SUBJS{1}
    
    %addpath(genpath( [exp_main_path , filesep 'MEG_analysis' filesep 'AVE_MEG' filesep 'scripts'])); % general processing scripts in this exp.
    G.subjPath = [exp_main_path filesep 'MEG' filesep 'AVE_MEG3' filesep curSubj filesep]; % main subject folder
    
    G.preprocPath = [exp_main_path filesep 'Preproc' filesep curSubj filesep]; % main subject folder
    
    G.outputPath = [G.subjPath ,'func', filesep]; % subject saving artifact and preprocessing matrixes
   
    %G.cfgbehavPath = [exp_main_path filesep 'Behavioral' filesep curSubj filesep] ; % behavioral data of participant
    
    subjscriptsPath = [G.subjPath ,'analysis', filesep]; %  participant specific scripts
    
    addpath(genpath('/project/3018029.06/Matlab/MEG_scripts/'));
  

    
    if ~exist( G.preprocPath,'dir')
        mkdir( G.preprocPath);
    end
    infile = fullfile(G.outputPath, filesep, [G.data_file_name, '.mat']);
    outfile = fullfile(G.preprocPath, filesep);
    
    copyfile(infile, outfile)
    
end