clear
stacksize('max')
function []= Matrix3DToRAWFile (x,y,z,RawFileName)
// x : x matrix size (1, M)coordinates of the surface
// y : y matrix size (1, N)coordinates of the surface
//z : heigth of the surface size (M,N)
 // RawFileNamefilename (the extension will be automatically added)   ex: 'Mesh.raw'


[xx,yy,zz]=genfac3d([1:length(x)],[1:length(y)],z);
plot3d(xx,yy,zz)
[n,m]=size(xx);

Mesh=[];
for i=1:m
Mesh=[Mesh ; xx(1,i) yy(1,i) zz(1,i) xx(2,i) yy(2,i) zz(2,i) xx(3,i) yy(3,i) zz(3,i) xx(4,i) yy(4,i) zz(4,i) ]
end
write_csv(Mesh, RawFileName+'.raw',' ','.');   //writes raw file in current work directory
endfunction;
/////////////////Main : Function test///////////////////
X=-10:.1:10; //Echelle x de -1 à +1
Y=-10:.1:10; //Echelle y de -1 à +1

//Surface Z = sin(r) /r^.25
for i = 1:length(X)
  for j = 1:length(Y),
   r=(X(i)^2+Y(j)^2);
     if r==0 then Z(i,j)=0 ;else Z(i,j) = sin(r)/(r)^0.25; end; //
        
  end;
end;


Matrix3DToRAWFile(X,Y,Z,'test')
