0001 function savemphtxt(node, face, elem, filename)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 n_node = size(node,1);
0020 n_face = size(face,1);
0021 n_elem = size(elem,1);
0022
0023 if(min(face(:,4))==0)
0024 face(:,4)=face(:,4)+1;
0025 end
0026 if(min(elem(:,5))==0)
0027 elem(:,5)=elem(:,5)+1;
0028 end
0029
0030 fp = fopen(filename,'w');
0031 fprintf(fp,'# Created by iso2mesh (http://iso2mesh.sf.net)\n');
0032 fprintf(fp,'0 1\n1\n5 mesh1\n1\n3 obj\n\n');
0033 fprintf(fp,'0 0 1\n4 Mesh\n2\n3\n%d\n1\n',n_node);
0034
0035
0036 for i = 1:n_node
0037 fprintf(fp,'%.16f %.16f %.16f\n',node(i,1),node(i,2),node(i,3));
0038 end
0039 fprintf(fp, '\n2\n\n3 tri\n');
0040
0041
0042 fprintf(fp, '\n3\n');
0043 fprintf(fp, '%d\n\n',n_face);
0044 for i = 1:n_face
0045 fprintf(fp,'%d %d %d\n',face(i,1),face(i,2),face(i,3));
0046 end
0047 fprintf(fp, '\n1\n0\n');
0048 fprintf(fp, '%d\n',n_face);
0049 for i = 1:n_face
0050 fprintf(fp,'%d\n',face(i,4));
0051 end
0052 fprintf(fp, '\n%d\n',n_face);
0053 for i = 1:n_face
0054 fprintf(fp,'0 0\n');
0055 end
0056
0057
0058 fprintf(fp, '\n\n3 tet\n4\n\n%d\n', n_elem);
0059 for i = 1:n_elem
0060 fprintf(fp,'%d %d %d %d\n',elem(i,1),elem(i,2),elem(i,3),elem(i,4));
0061 end
0062 fprintf(fp, '\n4\n0\n%d\n%d\n', n_elem);
0063 for i = 1:n_elem
0064 fprintf(fp,'%d\n',elem(i,5));
0065 end
0066 fprintf(fp,'\n0\n');
0067 fclose(fp);
0068