function indir_dyGSCorr_4D(indir_FunImg,outfodr_DyGSCorr,infile_Mask,Parameter)
%-----------------------------------------------------------
%   Written by SUN Jia-Wei 200413.
%   Mail to Authors: jiaweisun0512@163.com
%
%   Copyright(c) 2015
%	Center for Cognition and Brain Disorders, Hangzhou Normal University, Hangzhou 310015, China
%	Written by JIA Xi-Ze 201412
%	http://www.restfmri.net/
% 	Mail to Authors: jxz.rest@gmail.com, jiaxize@foxmail.com
%   Modified by Li Zi-Qi and Jia Xi-Ze 191113
%   Shirui technology co., LTD
%   Center for Cognition and Brain Disorders, Hangzhou Normal University, Hangzhou 310015, China




inpath_Misc(outfodr_DyGSCorr,'MakeCurrentDir');
SubfodrList=dir_NameList(indir_FunImg);
[FunDir,FunName] = fileparts(indir_FunImg);
TDAPath = [outfodr_DyGSCorr filesep 'TemporalDynamics' filesep 'TDA_4D' filesep 'GSCorr_' FunName];
TDAMPath = [outfodr_DyGSCorr filesep 'TemporalDynamics' filesep 'TDA_Metrics' filesep 'GSCorr_' FunName];
inpath_Misc(TDAPath,'MakeCurrentDir');
inpath_Misc(TDAMPath,'MakeCurrentDir');

% if matlabpool('size')>0 
if ~isempty(gcp('nocreate'))
    parfor i=1:length(SubfodrList)
        [FCBrain_AllWindow, zFCBrain_AllWindow, Header] = infodr_dyGSCorr_4D([indir_FunImg filesep SubfodrList{i}],...
                     [TDAPath filesep 'GSCorr_' SubfodrList{i} '.nii'],...
                     infile_Mask,Parameter);
        MeanOut = [TDAMPath filesep 'MeanzGSCorr' filesep 'MeanzGSCorr_' SubfodrList{i} '.nii'];
        StdOut = [TDAMPath filesep 'StdzGSCorr_'  filesep 'StdzGSCorr' SubfodrList{i} '.nii'];
        CVOut = [TDAMPath filesep 'CVzGSCorr'  filesep 'CVzGSCorr_' SubfodrList{i} '.nii'];
        tda_GetTDAMetrics(zFCBrain_AllWindow,Header, MeanOut, StdOut, CVOut)
    end
else
    for i=1:length(SubfodrList)
        [FCBrain_AllWindow, zFCBrain_AllWindow, Header] = infodr_dyGSCorr_4D([indir_FunImg filesep SubfodrList{i}],...
                     [TDAPath filesep 'GSCorr_' SubfodrList{i} '.nii'],...
                     infile_Mask,Parameter);
        MeanOut = [TDAMPath filesep 'MeanzGSCorr' filesep 'MeanzGSCorr_' SubfodrList{i} '.nii'];
        StdOut = [TDAMPath filesep 'StdzGSCorr_'  filesep 'StdzGSCorr' SubfodrList{i} '.nii'];
        CVOut = [TDAMPath filesep 'CVzGSCorr'  filesep 'CVzGSCorr_' SubfodrList{i} '.nii'];
        tda_GetTDAMetrics(zFCBrain_AllWindow,Header, MeanOut, StdOut, CVOut)
    end
end



end