function out_data(outfile,ib,jnt)
% out_dat Writes the mesh file
global  numel
global  numnp
global  meltyp
global  np
global  xord
global  yord
global  edgearray


fid=0;

if (outfile)
    [fid,message] = fopen(outfile,'w');
else
    filename = input('Mesh file name: ','s');
    [fid,message] = fopen(filename,'w');
end
neledg=size(edgearray,2);

fprintf(fid,'%5d %5d %5d %5d %5d\n',numel,numnp,meltyp,ib,neledg);



for ifor = 1:1:numnp
  i1 = jnt(ifor);
  jntinv(i1) = ifor;
end
fprintf(fid,'%15.8e %15.8e\n',[xord;yord]);
   
for ifor = 1:1:numel
    if(meltyp==3)
        n1=np(ifor,1);
        n2=np(ifor,2);
        n3=np(ifor,3);
        fprintf(fid,'%5d %5d %5d %5d\n',ifor,n1,n2,n3);
    end
    if(meltyp==4)
        n1=np(ifor,1);
        n2=np(ifor,2);
        n3=np(ifor,3);
        n4=np(ifor,4);
        fprintf(fid,'%5d %5d %5d %5d %5d\n',ifor,n1,n2,n3,n4);
    end
    if(meltyp==6)
        n1=np(ifor,1);
        n2=np(ifor,2);
        n3=np(ifor,3);
        n4=np(ifor,4);
        n5=np(ifor,5);
        n6=np(ifor,6);
        fprintf(fid,'%5d %5d %5d %5d %5d %5d %5d \n',ifor,n1,n2,n3,n4,n5,n6);
    end
    if(meltyp==9)
        n1=np(ifor,1);
        n2=np(ifor,2);
        n3=np(ifor,3);
        n4=np(ifor,4);
        n5=np(ifor,5);
        n6=np(ifor,6);
        n7=np(ifor,7);
        n8=np(ifor,8);
        n9=np(ifor,9);
        fprintf(fid,'%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d \n',ifor,n1,n2,n3,n4,n5,n6,n7,n8,n9);
    end
end

for ifor = 1:size(edgearray,2)
    n1 = edgearray(1,ifor);
    n2 = edgearray(2,ifor);
    n3 = edgearray(3,ifor);
    n4 = edgearray(4,ifor);
    n5 = edgearray(5,ifor);
    n6 = edgearray(6,ifor);
    n7 = edgearray(7,ifor);

    fprintf(fid,'%5d %5d %5d %5d %5d %5d %5d\n',n1,n2,n3,n4,n5,n6,n7);
end

status = fclose(fid);
