%%%%%%%%%%%%%%%%
%%% Function that creates a 3D matrix (size dimx, dimy, dimz) containing a sphere, centered at (cx,
%%% cy, cz), of radius r
%%% Loriane, oct 2014
%c=128
%r=40
%%%%%%%%%%%%%%%%


r=70
cx=200;
cy=cx;
cz=50;
dimx=400;
dimy=dimx;
dimz=100;
coeff=9.917*10^-7;  % mu ou autre

Sphere=zeros(dimx, dimy, dimz);

for(i=1:dimx)
    for(j=1:dimy)
        for(k=1:dimz)
            if((i-cx)^2+(j-cy)^2+(k-cz)^2 <= r^2)
                Sphere(i,j,k)=1;
            end
        end
    end
end


Sphere=Sphere*coeff;
name='sphere_phase_Mg_19keV'

fid=fopen(strcat(name, '.raw'), 'w')
fwrite(fid, Sphere, 'float32');
fclose(fid);

cmd = ['/data/id19/bones01/bones/program/linux_debian/bin/rawtomhd filein=', strcat(name, '.raw'), ' fileout=', strcat(name, '.mhd'), ' dimx=', num2str(dimx), ' dimy=', num2str(dimy), ' dimz=', num2str(dimz), ' format=FLOAT'];
unix(cmd)

