global ParentDir StatDir DirMat Smooth SmoothStr MaskStr a b c
NDir=size(DirMat,1)
Mask=[MaskStr,'*.img']
NSess=NDir./2;
NSess2=NSess./2;
%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.                                                                      
NSessOnes=ones(1,NSess);
NSessZeros=zeros(1,NSess);
if (round(NSess2)-NSess2)==0
    NSess2Ones=ones(1,NSess2);
    NSess2Zeros=zeros(1,NSess2);
end
for DirInd=1:NDir/2
    Folder0=DirMat(DirInd.*2,:)
    if strcmp(Folder0(end),filesep)
        Folder0=Folder0(1:end-1);
    end
    F0=spm_get('Files',Folder0,Mask);
    NScan0=size(F0,1)
    
    Folder1=DirMat(DirInd.*2-1,:)
    if strcmp(Folder1(end),filesep)
        Folder1=Folder1(1:end-1);
    end
    F1=spm_get('Files',Folder1,Mask);
    NScan1=size(F1,1)
    NScan0Vec(DirInd)=NScan0;
    NScan1Vec(DirInd)=NScan1;
    NScanVec(DirInd)=NScan0+NScan1;
    F=[F1;F0];
    eval(['FA',int2str((DirInd)),'=F;'])
end

%---------------------------------------------------------------
% batch variables defined here for analysis 'model'
%---------------------------------------------------------------

model(1) = struct( ...
 'types',          4, ...
 'global_effects', {'None'}, ...
 'burst_mode',     0, ...
 'HF_fil',         'none',  ...
 'HF_cut',         [], ...
 'LF_fil',         'none', ...
 'LF_cut',         [], ...
 'int_corr',       'none', ... 
 'now_later',      1, ...
 'stop_writing',   0, ...
 'trial_fcon',     0, ...
 'RT',             1, ...
 'replicated',     0, ...
 'same_time_param',0, ...
 'nsess',          NSess, ...
 'nscans',         NScanVec, ...
 'files',          {{...
         FA1 FA2 FA3 FA4 FA5 FA6 FA7 FA8 FA9 FA10 FA11 FA12 FA13 FA14 FA15 FA16 FA17 FA18 FA19 FA20...
     }}, ...
 'conditions_nb',  NSessOnes, ...     
 'conditions',     [1:NDir./2], ...
 'regressors_nb',  NSessZeros, ...
 'regressors',     [], ...
 'parametrics_type', {{ 'none','none','none','none','none','none','none','none','none','none', ...
                    'none','none','none','none','none','none','none','none','none','none', ...
                }}, ...
 'parametrics',    [], ...
 'stochastics_flag',NSessZeros, ...
 'stochastics',    []);
      
 %  FA15 FA16 FA17 FA18 FA19 FA20 FA21 FA22 FA23 FA24 FA25 FA26 FA27 FA28
 %  'none','none','none','none','none','none', ...
 %                      'none','none','none','none','none','none','none','none', ...
 
conditions(1) = struct( ...
 'names',   {{'NegHigh','Neutral'}}, ...
 'onsets',{{0,NScan1Vec(1)}}, ...   
 'types',    {{'epochs','epochs'}}, ...   
 'bf_ep',   [1 NDir./2+1], ...                  
 'volterra',  0, ...
 'variable_dur',0);

for i=2:NDir./2
    conditions(i)=conditions(1);
    conditions(i).onsets=[0,NScan1Vec(i)];
    conditions(i).bf_ep=[i NDir./2+i]
end
%-------------------------------------------
%-------------------------------------------

bf_ep(1) = struct( ...
  'ep_type',4, ...
  'length',NScan1Vec(1), ...
  'conv',0, ...  
  'deriv',0);

for i=2:NDir./2
    bf_ep(i) = bf_ep(1);
    bf_ep(i).length=NScan1Vec(i)
end

bf_ep(NDir./2+1) = struct( ...
  'ep_type',4, ...
  'length',NScan0Vec(1), ...
  'conv',0, ...  
  'deriv',0);

j=1;
for i=NDir./2+2:NDir
    j=j+1;
    bf_ep(i) = bf_ep(1);
    bf_ep(i).length=NScan0Vec(j)
end

%-------------------------------------------
%-------------------------------------------
NDirZeros=zeros(1,NSess.*2);

CNegHiGTNeut=NDirZeros;
CNegHiGTNeut(1:NSess)=NSessOnes;
CNegHiLTNeut=-CNegHiGTNeut;

if (round(NSess2)-NSess2)==0
    CKonGTPat=NDirZeros;
    CKonGTPat(1:NSess2)=NSess2Ones;
    CKonGTPat(NSess2+1:NSess)=NSess2Ones;
    CKonLTPat=-CKonGTPat;
end

if (round(NSess2)-NSess2)==0
    contrasts(1) = struct( ...
        'names',  {{...
                'CNegHiGTNeut','CNegHiLTNeut','CKonGTPat','CKonLTPat'}}, ...
        'types',   {{'T','T','T','T', ...
            }}, ...
        'values',  {{...
                CNegHiGTNeut,CNegHiLTNeut,CKonGTPat,CKonLTPat, ...
            }} ...
        );
else
    contrasts(1) = struct( ...
        'names',  {{...
                'CNegHiGTNeut','CNegHiLTNeut'}}, ...
        'types',   {{'T','T', ...
            }}, ...
        'values',  {{...
                CNegHiGTNeut,CNegHiLTNeut, ...
            }} ...
        ); 
end