theDir = uigetdir('~/', 'Pick a Directory');
Nt = input('number of time points :');
Nscan = input('number of scans: ');
filePrefix = input('file prefix :');

on=[];off=[];

for j=0:Nscan-1
on = [on; (2*j*Nt+[1:2:2*Nt])];
off =[off;(2*j*Nt+[2:2:2*Nt+1])];
end

outDir=strcat(theDir,'/Output');
mkdir(outDir);
dir(strcat(outDir));
for j=1:Nt
    ImOn= sumImages(on(:,j)',theDir,filePrefix);
    ImOff=sumImages(off(:,j)',theDir,filePrefix);
    imagewrite(ImOn, strcat(outDir,'/Zsum',sprintf('%d',10000+2*j-1)), 'tif', '', 32);
    imagewrite(ImOff, strcat(outDir,'/Zsum',sprintf('%d',10000+2*j)), 'tif', '', 32);
    fprintf('writing file: %s\n',strcat(outDir,'/Zsum',sprintf('%d',10000+2*j-1)));  
    fprintf('writing file: %s\n',strcat(outDir,'/Zsum',sprintf('%d',10000+2*j)));
    
end