function indir_dyALFF_4D(indir_FunImg,outfodr_DyALFF,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_DyALFF,'MakeCurrentDir');
SubfodrList=dir_NameList(indir_FunImg);
[FunDir,FunName] = fileparts(indir_FunImg);
TDAPath = [outfodr_DyALFF filesep 'TemporalDynamics' filesep 'TDA_4D' filesep 'ALFF_' FunName];
TDAMPath = [outfodr_DyALFF filesep 'TemporalDynamics' filesep 'TDA_Metrics' filesep 'ALFF_' FunName];
inpath_Misc(TDAPath,'MakeCurrentDir');
inpath_Misc(TDAMPath,'MakeCurrentDir');

% if matlabpool('size')>0 
if ~isempty(gcp('nocreate'))
    parfor i=1:length(SubfodrList)
        [ALFFBrain_AllWindow, Header] = infodr_dyALFF_4D([indir_FunImg filesep SubfodrList{i}],...
                     [TDAPath filesep 'ALFF_' SubfodrList{i} '.nii'],...
                     infile_Mask,Parameter);
        MeanOut = [TDAMPath filesep 'MeanALFF' filesep 'MeanALFF_' SubfodrList{i} '.nii'];
        StdOut = [TDAMPath filesep 'StdALFF' filesep 'StdALFF_' SubfodrList{i} '.nii'];
        CVOut = [TDAMPath filesep 'CVALFF' filesep 'CVALFF_' SubfodrList{i} '.nii'];
        tda_GetTDAMetrics(ALFFBrain_AllWindow,Header, MeanOut, StdOut, CVOut)
    end
else
    for i=1:length(SubfodrList)
        [ALFFBrain_AllWindow, Header] = infodr_dyALFF_4D([indir_FunImg filesep SubfodrList{i}],...
                     [TDAPath filesep 'ALFF_' SubfodrList{i} '.nii'],...
                     infile_Mask,Parameter);
        MeanOut = [TDAMPath filesep 'MeanALFF' filesep 'MeanALFF_' SubfodrList{i} '.nii'];
        StdOut = [TDAMPath filesep 'StdALFF' filesep 'StdALFF_' SubfodrList{i} '.nii'];
        CVOut = [TDAMPath filesep 'CVALFF' filesep 'CVALFF_' SubfodrList{i} '.nii'];
        tda_GetTDAMetrics(ALFFBrain_AllWindow,Header, MeanOut, StdOut, CVOut)
                 
    end
end

end