% get all coordinates in a given file
% and write them out in small file, good for ExceltoTD
% before and after mni2tal conversion
P = spm_get(1, '.img', 'Select image files.');
V= spm_vol(P);

% read volume and return mm and intensities, without masking
[Y,XYZmm] = spm_read_vols(V,0);

% remove the masked out voxels
XYZmm = XYZmm(:,find(Y));

XYZmm=XYZmm';


unix('mkdir mni');
cd mni;

for file=1:25517
fid=fopen(sprintf('2_2_4.mni%d',file),'w');
for i=1:10
      fprintf(fid,'%5.0f\t%5.0f\t%5.0f\n',XYZmm(i+((file-1)*10),:));
         end
fclose(fid);
end


XYZmm=round(mni2tal(XYZmm));

cd ..
unix('mkdir tal');
cd tal;

for file=1:25517
fid=fopen(sprintf('2_2_4.tal%d',file),'w');
for i=1:10
      fprintf(fid,'%5.0f\t%5.0f\t%5.0f\n',XYZmm(i+((file-1)*10),:));
         end
fclose(fid);
end



