function CreateEasyMesh(name,xy,len)
#[...] = CreateEasyMesh(...)
# generate a mesh using EasyMesh
#
# CreateEasyMesh(name,xy,len)
#  name the base filename: the file name.d will be generated
#       then EasyMesh will generate files name.* with the mesh
#
#  xy   vector containing the coordinates of the nodes forming the 
#       outer boundary. Currently no holes can be generated. The format is
#       [x1,y1,t1;x2,y2,t2;...;xn,yn,tn] where
#       xi x-coordinate of node i
#       yi x-coordinate of node i
#       ti boundary marker for segment from node i to node i+1
#         bi=1  Dirichlet condition
#         bi=2  Neumann condition
#       the last given node will be connected to the first given node 
#       to create a closed curve
#
#  len  vector with the typical length of triangle side at a point
#       if len is a scalar the same length will be used for all points
#
#  The information can then be read and used by 
#     [nodes,elem,edges]=ReadMesh("name");

if (nargin!=3) 
  usage("CreateEasyMesh(name,xy,len)");
endif


n=length(xy);

if (length(len)==1) len=len*ones(n,1);endif

[fid,msg]=fopen(strcat(name,".d"),"w");
fprintf(fid,"%i\n",n);
fprintf(fid,"%i: %g %g %g  %d\n",...
         0,xy(1,1),xy(1,2),len(1),min(xy(1,3),xy(n,3)));
for k=2:n
  fprintf(fid,"%i: %g %g %g %d\n",...
         k-1,xy(k,1),xy(k,2),len(k),min(xy(k,3),xy(k-1,3)));
endfor

fprintf(fid,"\n");

fprintf(fid,"%i\n",n);
for k=1:n-1
  fprintf(fid,"%i: %i %i %i\n",k-1,k-1,k,xy(k,3));
endfor
fprintf(fid,"%i: %i %i %i\n\n",n-1,n-1,0,xy(n,3));

fclose(fid);

system(strcat("EasyMesh ",name,".d"));
endfunction




