%..read input data
fn =input('Enter the rootname of the EasyMesh data files: ','s');
fne=strcat(fn,'.e');
fnn=strcat(fn,'.n');
fnd=strcat(fn,'.plt');
if ~exist(fne);
   disp([fne,' does not exist!']);
   exit;
end
 
fid   = fopen(fne,'r');
line  = fgetl(fid);
ncell = sscanf(line,'%d');
for n=1:ncell
  line = fgetl(fid);
  [dis,dat] = strtok(line,':');
  dat = strtrim(dat(2:end));
  data = sscanf(dat,'%d %d %d %d %d %d');
  node(n,1)  = data(1)+1;
  node(n,2)  = data(2)+1;
  node(n,3)  = data(3)+1;
  neigh(n,1) = data(6);
  neigh(n,2) = data(4);
  neigh(n,3) = data(5);
end
fclose(fid);

fid = fopen(fnn,'r');
line  = fgetl(fid);
nnode = sscanf(line,'%d');
for n=1:nnode
  line = fgetl(fid);
  [dis,dat] = strtok(line,':');
  dat = strtrim(dat(2:end));
  data = sscanf(dat,'%e %e %d');
  xy(n,1) = data(1);
  xy(n,2) = data(2);
  ibc(n)  = data(3);
end
fclose(fid);

fid = fopen(fnd, 'w');
fprintf(fid,'VARIABLES= "X","Y" ZONE E=%d N=%d F=FEPOINT ET=TRIANGLE\n',ncell,nnode);
for n = 1:nnode
  fprintf(fid,'%15.7e %15.7e\n',xy(n,1),xy(n,2));
end
for n = 1:ncell
  fprintf(fid,'%6i %6i %6i\n',node(n,1),node(n,2),node(n,3));
end
fclose(fid);
disp('DONE');
exit
