54 char *modeASCII,
char* modeBIN) {
58 out = (strchr(modeASCII,
'w') != NULL) ? 1 : 0;
65 ptr = strstr(data,
".mesh");
69 strcat(data,
".meshb");
70 if( !(*inm = fopen(data,modeBIN)) ) {
72 ptr = strstr(data,
".mesh");
75 if( !(*inm = fopen(data,modeASCII)) ) {
83 ptr = strstr(data,
".meshb");
86 if( !(*inm = fopen(data,modeBIN)) ) {
88 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
95 if( !(*inm = fopen(data,modeASCII)) ) {
97 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
106 fprintf(stdout,
" %%%% %s OPENED\n",data);
122 long posnp,posnt,posne,posned,posncor,posnpreq,posntreq,posnereq,posnedreq;
123 long posnr,posnprism,posnormal,posnc1,posnq,posnqreq;
124 long posnppar,posntpar,posnepar,posnedpar,posnqpar;
125 MMG5_int npreq,ntreq,nereq,nedreq,nqreq,ncor,ned,ng;
126 MMG5_int nppar,nedpar,ntpar,nqpar,nepar;
128 int i,bdim,binch,iswp,bpos;
129 MMG5_int na,nr,ia,aux,nref,ref;
132 posnp = posnt = posne = posncor = 0;
133 posnpreq = posntreq = posnereq = posnqreq = posned = posnedreq = posnr = 0;
134 posnprism = posnormal= posnc1 = posnq = 0;
135 posnppar = posnedpar = posntpar = posnqpar = posnepar = 0;
136 ncor = ned = npreq = ntreq = nqreq = nereq = nedreq = nr = ng = 0;
137 nppar = nedpar = ntpar = nqpar = nepar = 0;
145 while(fscanf(inm,
"%127s",&chaine[0])!=EOF && strncmp(chaine,
"End",strlen(
"End")) ) {
146 if ( chaine[0] ==
'#' ) {
151 if(!strncmp(chaine,
"MeshVersionFormatted",strlen(
"MeshVersionFormatted"))) {
154 }
else if(!strncmp(chaine,
"Dimension",strlen(
"Dimension"))) {
157 fprintf(stderr,
"BAD DIMENSION : %d\n",
mesh->
dim);
161 }
else if(!strncmp(chaine,
"Vertices",strlen(
"Vertices"))) {
165 }
else if(!strncmp(chaine,
"RequiredVertices",strlen(
"RequiredVertices"))) {
167 posnpreq = ftell(inm);
169 }
else if(!strncmp(chaine,
"ParallelVertices",strlen(
"ParallelVertices"))) {
171 posnppar = ftell(inm);
173 }
else if(!strncmp(chaine,
"Triangles",strlen(
"Triangles"))) {
174 if ( !strncmp(chaine,
"TrianglesP",strlen(
"TrianglesP")) )
continue;
178 }
else if(!strncmp(chaine,
"RequiredTriangles",strlen(
"RequiredTriangles"))) {
180 posntreq = ftell(inm);
182 }
else if(!strncmp(chaine,
"ParallelTriangles",strlen(
"ParallelTriangles"))) {
184 posntpar = ftell(inm);
187 else if(!strncmp(chaine,
"Quadrilaterals",strlen(
"Quadrilaterals"))) {
191 }
else if(!strncmp(chaine,
"RequiredQuadrilaterals",strlen(
"RequiredQuadrilaterals"))) {
193 posnqreq = ftell(inm);
195 }
else if(!strncmp(chaine,
"ParallelQuadrilaterals",strlen(
"ParallelQuadrilaterals"))) {
197 posnqpar = ftell(inm);
199 }
else if(!strncmp(chaine,
"Tetrahedra",strlen(
"Tetrahedra"))) {
200 if ( !strncmp(chaine,
"TetrahedraP",strlen(
"TetrahedraP")) )
continue;
204 }
else if((!strncmp(chaine,
"Prisms",strlen(
"Prisms")))||
205 (!strncmp(chaine,
"Pentahedra",strlen(
"Pentahedra")))) {
207 posnprism = ftell(inm);
209 }
else if(!strncmp(chaine,
"RequiredTetrahedra",strlen(
"RequiredTetrahedra"))) {
211 posnereq = ftell(inm);
213 }
else if(!strncmp(chaine,
"ParallelTetrahedra",strlen(
"ParallelTetrahedra"))) {
215 posnepar = ftell(inm);
217 }
else if(!strncmp(chaine,
"Corners",strlen(
"Corners"))) {
219 posncor = ftell(inm);
221 }
else if(!strncmp(chaine,
"Edges",strlen(
"Edges"))) {
225 }
else if(!strncmp(chaine,
"RequiredEdges",strlen(
"RequiredEdges"))) {
227 posnedreq = ftell(inm);
229 }
else if(!strncmp(chaine,
"ParallelEdges",strlen(
"ParallelEdges"))) {
231 posnedpar = ftell(inm);
233 }
else if(!strncmp(chaine,
"Ridges",strlen(
"Ridges"))) {
237 }
else if(!ng && !strncmp(chaine,
"Normals",strlen(
"Normals"))) {
239 posnormal = ftell(inm);
241 }
else if(!strncmp(chaine,
"NormalAtVertices",strlen(
"NormalAtVertices"))) {
254 fprintf(stderr,
"BAD FILE ENCODING\n");
258 while(fread(&binch,
MMG5_SW,1,inm)!=0 && binch!=54 ) {
261 if(!bdim && binch==3) {
268 fprintf(stderr,
"BAD MESH DIMENSION : %d\n",
mesh->
dim);
269 fprintf(stderr,
" Exit program.\n");
273 }
else if(!
mesh->
npi && binch==4) {
280 fseek(inm,bpos,SEEK_SET);
282 }
else if(binch==15) {
286 if(iswp) npreq=MMG5_SWAPBIN(npreq);
287 posnpreq = ftell(inm);
289 fseek(inm,bpos,SEEK_SET);
291 }
else if(!
mesh->
nti && binch==6) {
298 fseek(inm,bpos,SEEK_SET);
300 }
else if(binch==17) {
304 if(iswp) ntreq=MMG5_SWAPBIN(ntreq);
305 posntreq = ftell(inm);
307 fseek(inm,bpos,SEEK_SET);
317 fseek(inm,bpos,SEEK_SET);
319 }
else if(binch==18) {
323 if(iswp) nqreq=MMG5_SWAPBIN(nqreq);
324 posnqreq = ftell(inm);
326 fseek(inm,bpos,SEEK_SET);
328 }
else if(!
mesh->
nei && binch==8) {
335 fseek(inm,bpos,SEEK_SET);
342 posnprism = ftell(inm);
344 fseek(inm,bpos,SEEK_SET);
346 }
else if(binch==12) {
350 if(iswp) nereq=MMG5_SWAPBIN(nereq);
351 posnereq = ftell(inm);
353 fseek(inm,bpos,SEEK_SET);
355 }
else if(!ncor && binch==13) {
359 if(iswp) ncor=MMG5_SWAPBIN(ncor);
360 posncor = ftell(inm);
362 fseek(inm,bpos,SEEK_SET);
364 }
else if(!
mesh->
nai && binch==5) {
371 fseek(inm,bpos,SEEK_SET);
373 }
else if(binch==16) {
377 if(iswp) nedreq=MMG5_SWAPBIN(nedreq);
378 posnedreq = ftell(inm);
380 fseek(inm,bpos,SEEK_SET);
382 }
else if(binch==14) {
386 if(iswp) nr=MMG5_SWAPBIN(nr);
389 fseek(inm,bpos,SEEK_SET);
391 }
else if(!ng && binch==60) {
395 if(iswp) ng=MMG5_SWAPBIN(ng);
396 posnormal = ftell(inm);
398 fseek(inm,bpos,SEEK_SET);
400 }
else if(binch==20) {
407 fseek(inm,bpos,SEEK_SET);
414 fseek(inm,bpos,SEEK_SET);
420 fprintf(stderr,
" ** MISSING DATA.\n");
421 fprintf(stderr,
" Check that your mesh contains points and tetrahedra.\n");
422 fprintf(stderr,
" Exit program.\n");
436 fseek(inm,posnp,SEEK_SET);
437 for (k=1; k<=
mesh->
np; k++) {
441 for (i=0 ; i<3 ; i++) {
443 ppt->
c[i] = (double) fc;
447 for (i=0 ; i<3 ; i++) {
450 ppt->
c[i] = (double) fc;
453 if(iswp) ppt->
ref=MMG5_SWAPBIN(ppt->
ref);
457 MMG_FSCANF(inm,
"%lf %lf %lf %" MMG5_PRId
"",&ppt->
c[0],&ppt->
c[1],&ppt->
c[2],&ppt->
ref);
460 for (i=0 ; i<3 ; i++) {
465 if(iswp) ppt->
ref=MMG5_SWAPBIN(ppt->
ref);
469 if ( ppt->
ref < 0 ) {
480 fseek(inm,posnpreq,SEEK_SET);
481 for (k=1; k<=npreq; k++) {
490 fprintf(stderr,
"\n ## Warning: %s: required Vertices number %8d"
491 " ignored.\n",__func__,i);
502 fseek(inm,posnppar,SEEK_SET);
503 for (k=1; k<=nppar; k++) {
512 fprintf(stderr,
"\n ## Warning: %s: parallel Vertices number %8d"
513 " ignored.\n",__func__,i);
525 fseek(inm,posncor,SEEK_SET);
526 for (k=1; k<=ncor; k++) {
535 fprintf(stderr,
"\n ## Warning: %s: corner number %8d ignored.\n",
547 fseek(inm,posnt,SEEK_SET);
549 for (k=1; k<=
mesh->
nt; k++) {
552 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&pt1->
v[0],&pt1->
v[1],&pt1->
v[2],&pt1->
ref);
555 for (i=0 ; i<3 ; i++) {
557 if(iswp) pt1->
v[i]=MMG5_SWAPBIN(pt1->
v[i]);
560 if(iswp) pt1->
ref=MMG5_SWAPBIN(pt1->
ref);
562 if ( pt1->
ref < 0 ) {
570 fseek(inm,posntreq,SEEK_SET);
571 for (k=1; k<=ntreq; k++) {
580 fprintf(stderr,
"\n ## Warning: %s: required triangle number %8d"
581 " ignored.\n",__func__,i);
593 fseek(inm,posntpar,SEEK_SET);
594 for (k=1; k<=ntpar; k++) {
603 fprintf(stderr,
"\n ## Warning: %s: parallel triangle number %8d"
604 " ignored.\n",__func__,i);
618 fseek(inm,posnq,SEEK_SET);
623 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&pq1->
v[0],&pq1->
v[1],&pq1->
v[2],
624 &pq1->
v[3],&pq1->
ref);
627 for (i=0 ; i<4 ; i++) {
629 if(iswp) pq1->
v[i]=MMG5_SWAPBIN(pq1->
v[i]);
632 if(iswp) pq1->
ref=MMG5_SWAPBIN(pq1->
ref);
634 if ( pq1->
ref < 0 ) {
643 fseek(inm,posnqreq,SEEK_SET);
644 for (k=1; k<=nqreq; k++) {
653 fprintf(stderr,
"\n ## Warning: %s: required quadrilaterals number"
654 " %8d ignored.\n",__func__,i);
668 fseek(inm,posnqpar,SEEK_SET);
669 for (k=1; k<=nqpar; k++) {
678 fprintf(stderr,
"\n ## Warning: %s: parallel quadrilaterals number"
679 " %8d ignored.\n",__func__,i);
696 fseek(inm,posned,SEEK_SET);
698 for (k=1; k<=na; k++) {
701 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&pa->
a,&pa->
b,&pa->
ref);
705 if(iswp) pa->
a=MMG5_SWAPBIN(pa->
a);
707 if(iswp) pa->
b=MMG5_SWAPBIN(pa->
b);
709 if(iswp) pa->
ref=MMG5_SWAPBIN(pa->
ref);
721 fseek(inm,posnr,SEEK_SET);
722 for (k=1; k<=nr; k++) {
728 if(iswp) ia=MMG5_SWAPBIN(ia);
731 fprintf(stderr,
"\n ## Warning: %s: ridge number %8" MMG5_PRId
" ignored.\n",
742 fseek(inm,posnedreq,SEEK_SET);
743 for (k=1; k<=nedreq; k++) {
749 if(iswp) ia=MMG5_SWAPBIN(ia);
752 fprintf(stderr,
"\n ## Warning: %s: required Edges number %8" MMG5_PRId
"/%8" MMG5_PRId
""
753 " ignored.\n",__func__,ia,na);
763 fseek(inm,posnedpar,SEEK_SET);
764 for (k=1; k<=nedpar; k++) {
770 if(iswp) ia=MMG5_SWAPBIN(ia);
773 fprintf(stderr,
"\n ## Warning: %s: parallel Edges number %8" MMG5_PRId
"/%8" MMG5_PRId
""
774 " ignored.\n",__func__,ia,na);
785 fseek(inm,posne,SEEK_SET);
787 for (k=1; k<=
mesh->
ne; k++) {
790 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&pt->
v[0],&pt->
v[1],&pt->
v[2],&pt->
v[3],&ref);
793 for (i=0 ; i<4 ; i++) {
795 if(iswp) pt->
v[i]=MMG5_SWAPBIN(pt->
v[i]);
798 if(iswp) ref=MMG5_SWAPBIN(ref);
803 pt->
ref = MMG5_abs(ref);
804 for (i=0; i<4; i++) {
819 fprintf(stderr,
"\n $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
820 fprintf(stderr,
" BAD ORIENTATION : vol < 0 -- %8" MMG5_PRId
" tetra reoriented\n",
mesh->
xt);
821 fprintf(stderr,
" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n\n");
827 fseek(inm,posnereq,SEEK_SET);
828 for (k=1; k<=nereq; k++) {
837 fprintf(stderr,
"\n ## Warning: %s: required Tetra number %8d"
838 " ignored.\n",__func__,i);
848 fseek(inm,posnepar,SEEK_SET);
849 for (k=1; k<=nepar; k++) {
858 fprintf(stderr,
"\n ## Warning: %s: parallel Tetra number %8d"
859 " ignored.\n",__func__,i);
868 fseek(inm,posnprism,SEEK_SET);
872 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&pp->
v[0],&pp->
v[1],&pp->
v[2],
873 &pp->
v[3],&pp->
v[4],&pp->
v[5],&ref);
876 for (i=0 ; i<6 ; i++) {
878 if(iswp) pp->
v[i]=MMG5_SWAPBIN(pp->
v[i]);
881 if(iswp) ref=MMG5_SWAPBIN(ref);
884 if ( pp-> ref < 0 ) {
888 for (i=0; i<6; i++) {
895 fprintf(stdout,
"\n $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
896 fprintf(stdout,
" WARNING : %" MMG5_PRId
" entities with unexpected refs (ref< 0).\n",nref);
897 fprintf(stdout,
" We take their absolute values.\n");
898 fprintf(stdout,
" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n\n");
904 fprintf(stderr,
"\n ## Warning: %s: your mesh don't contains Normals but contains"
905 " NormalAtVertices. The NormalAtVertices are deleted. \n",__func__);
913 fseek(inm,posnormal,SEEK_SET);
914 for (k=1; k<=ng; k++) {
915 n = &norm[3*(k-1)+1];
918 for (i=0 ; i<3 ; i++) {
923 for (i=0 ; i<3 ; i++) {
932 MMG_FSCANF(inm,
"%lf %lf %lf",&n[0],&n[1],&n[2]);
935 for (i=0 ; i<3 ; i++) {
941 dd = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
951 fseek(inm,posnc1,SEEK_SET);
955 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
"",&ip,&idn);
959 if(iswp) ip=MMG5_SWAPBIN(ip);
961 if(iswp) idn=MMG5_SWAPBIN(idn);
963 if ( idn > 0 && ip < mesh->np+1 ) {
968 memcpy(&
mesh->
point[ip].
n,&norm[3*(idn-1)+1],3*
sizeof(
double));
976 for (k=1; k<=
mesh->
np; k++) {
984 fprintf(stdout,
" NUMBER OF VERTICES %8" MMG5_PRId
"\n",
mesh->
np);
985 fprintf(stdout,
" NUMBER OF TETRAHEDRA %8" MMG5_PRId
"\n",
mesh->
ne);
987 fprintf(stdout,
" NUMBER OF PRISMS %8" MMG5_PRId
"\n",
mesh->
nprism);
990 fprintf(stdout,
" NUMBER OF EDGES %8" MMG5_PRId
"\n",
mesh->
na);
992 fprintf(stdout,
" NUMBER OF RIDGES %8" MMG5_PRId
"\n",nr);
995 fprintf(stdout,
" NUMBER OF TRIANGLES %8" MMG5_PRId
"\n",
mesh->
nt);
997 fprintf(stdout,
" NUMBER OF QUADRILATERALS %8" MMG5_PRId
"\n",
mesh->
nquad);
1000 if ( npreq || nedreq || ntreq || nereq || nqreq ) {
1001 fprintf(stdout,
" NUMBER OF REQUIRED ENTITIES: \n");
1003 fprintf(stdout,
" VERTICES %8" MMG5_PRId
" \n",npreq);
1005 fprintf(stdout,
" EDGES %8" MMG5_PRId
" \n",nedreq);
1007 fprintf(stdout,
" TRIANGLES %8" MMG5_PRId
" \n",ntreq);
1009 fprintf(stdout,
" QUADRILATERALS %8" MMG5_PRId
" \n",nqreq);
1011 fprintf(stdout,
" TETRAHEDRA %8" MMG5_PRId
" \n",nereq);
1014 fprintf(stdout,
" NUMBER OF CORNERS %8" MMG5_PRId
" \n",ncor);
1016 if ( nppar || nedpar || ntpar || nepar || nqpar ) {
1017 fprintf(stdout,
" NUMBER OF PARALLEL ENTITIES: \n");
1019 fprintf(stdout,
" VERTICES %8" MMG5_PRId
" \n",nppar);
1021 fprintf(stdout,
" EDGES %8" MMG5_PRId
" \n",nedpar);
1023 fprintf(stdout,
" TRIANGLES %8" MMG5_PRId
" \n",ntpar);
1025 fprintf(stdout,
" QUADRILATERALS %8" MMG5_PRId
" \n",nqpar);
1027 fprintf(stdout,
" TETRAHEDRA %8" MMG5_PRId
" \n",nepar);
1049 if(
ier < 1 )
return ier;
1051 if(
ier < 1 )
return ier;
1061 long posNodes,posElts,*posNodeData;
1069 &posNodes,&posElts,&posNodeData,
1070 &bin,&iswp,&nelts,&nsols);
1071 if (
ier < 1 )
return (
ier);
1074 fprintf(stderr,
"Error: SEVERAL SOLUTIONS FOUND (%d)\n",nsols);
1093 fprintf(stderr,
" ** MISSING DATA.\n");
1094 fprintf(stderr,
" Check that your mesh contains tetrahedra.\n");
1095 fprintf(stderr,
" Exit program.\n");
1102 posNodes,posElts,posNodeData,
1103 bin,iswp,nelts,nsols);
1106 fprintf(stderr,
" ** ERROR WHEN PARSING THE INPUT FILE\n");
1121 long posNodes,posElts,*posNodeData;
1129 &posNodes,&posElts,&posNodeData,
1130 &bin,&iswp,&nelts,&nsols);
1131 if (
ier < 1 )
return (
ier);
1137 printf(
" Exit program.\n"); fclose(inm);
1155 fprintf(stderr,
" ** MISSING DATA.\n");
1156 fprintf(stderr,
" Check that your mesh contains tetrahedra.\n");
1157 fprintf(stderr,
" Exit program.\n");
1164 posNodes,posElts,posNodeData,
1165 bin,iswp,nelts,nsols);
1168 fprintf(stderr,
" ** ERROR WHEN PARSING THE INPUT FILE\n");
1178 const char *filenameptr,*solnameptr;
1195 fprintf(stderr,
" ## Error: %s: please provide input file name"
1196 " (either in the mesh structure or as function argument).\n",
1202 strcpy(
tmp,filenameptr);
1224 if (
ier < 1 ) {
break; }
1229 strcpy(soltmp,solnameptr);
1232 fprintf(stderr,
"\n ## ERROR: WRONG DATA TYPE OR WRONG SOLUTION NUMBER.\n");
1267 MMG5_int k,na,nc,np,ne,nn,nr,nre,npar,nedreq,nedpar,ntreq,ntpar,nt,nereq,nepar;
1268 MMG5_int npr,nq,nqreq,nqpar,bpos;
1271 static int8_t parWarn = 0;
1282 strcpy(&chaine[0],
"MeshVersionFormatted 2\n");
1283 fprintf(inm,
"%s",chaine);
1284 strcpy(&chaine[0],
"\n\nDimension 3\n");
1285 fprintf(inm,
"%s ",chaine);
1300 np = nc = na = nr = nre = npar = 0;
1303 fprintf(stderr,
"\n ## Error: %s: points array not allocated.\n",
1310 for (k=1; k<=
mesh->
np; k++) {
1322 strcpy(&chaine[0],
"\n\nVertices\n");
1323 fprintf(inm,
"%s",chaine);
1324 fprintf(inm,
"%" MMG5_PRId
"\n",np);
1332 for (k=1; k<=
mesh->
np; k++) {
1336 fprintf(inm,
"%.15lg %.15lg %.15lg %" MMG5_PRId
"\n",
1337 ppt->
c[0],ppt->
c[1],ppt->
c[2],MMG5_abs(ppt->
ref));
1339 fwrite((
unsigned char*)&ppt->
c[0],
MMG5_SD,1,inm);
1340 fwrite((
unsigned char*)&ppt->
c[1],
MMG5_SD,1,inm);
1341 fwrite((
unsigned char*)&ppt->
c[2],
MMG5_SD,1,inm);
1342 ppt->
ref = MMG5_abs(ppt->
ref);
1343 fwrite((
unsigned char*)&ppt->
ref,
MMG5_SW,1,inm);
1351 strcpy(&chaine[0],
"\n\nCorners\n");
1352 fprintf(inm,
"%s",chaine);
1353 fprintf(inm,
"%" MMG5_PRId
"\n",nc);
1362 for (k=1; k<=
mesh->
np; k++) {
1366 fprintf(inm,
"%" MMG5_PRId
"\n",ppt->
tmp);
1375 strcpy(&chaine[0],
"\n\nRequiredVertices\n");
1376 fprintf(inm,
"%s",chaine);
1377 fprintf(inm,
"%" MMG5_PRId
"\n",nre);
1385 for (k=1; k<=
mesh->
np; k++) {
1389 fprintf(inm,
"%" MMG5_PRId
"\n",ppt->
tmp);
1398 strcpy(&chaine[0],
"\n\nParallelVertices\n");
1399 fprintf(inm,
"%s",chaine);
1400 fprintf(inm,
"%" MMG5_PRId
"\n",npar);
1405 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1406 " saved at binary format. Ignored.\n",
1411 for (k=1; k<=
mesh->
np; k++) {
1415 fprintf(inm,
"%" MMG5_PRId
"\n",ppt->
tmp);
1422 ne = nereq = nepar = 0;
1424 for (k=1; k<=
mesh->
ne; k++) {
1439 fprintf(stderr,
"\n ## Warning: %s: tetra array not allocated.\n",
1444 strcpy(&chaine[0],
"\n\nTetrahedra\n");
1445 fprintf(inm,
"%s",chaine);
1446 fprintf(inm,
"%" MMG5_PRId
"\n",ne);
1452 fwrite((
unsigned char*)&ne,
MMG5_SW,1,inm);
1454 for (k=1; k<=
mesh->
ne; k++) {
1457 if ( !
MG_EOK(pt) ) {
continue; }
1468 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",
mesh->
point[pt->
v[0]].
tmp,
mesh->
point[pt->
v[1]].
tmp
1481 strcpy(&chaine[0],
"\n\nRequiredTetrahedra\n");
1482 fprintf(inm,
"%s",chaine);
1483 fprintf(inm,
"%" MMG5_PRId
"\n",nereq);
1492 for (k=1; k<=
mesh->
ne; k++) {
1494 if ( !
MG_EOK(pt) )
continue;
1498 fprintf(inm,
"%" MMG5_PRId
"\n",ne);
1508 strcpy(&chaine[0],
"\n\nParallelTetrahedra\n");
1509 fprintf(inm,
"%s",chaine);
1510 fprintf(inm,
"%" MMG5_PRId
"\n",nepar);
1514 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1515 " saved at binary format. Ignored.\n",
1521 for (k=1; k<=
mesh->
ne; k++) {
1523 if ( !
MG_EOK(pt) )
continue;
1527 fprintf(inm,
"%" MMG5_PRId
"\n",ne);
1537 if ( !
MG_EOK(pp) )
continue;
1543 strcpy(&chaine[0],
"\n\nPrisms\n");
1544 fprintf(inm,
"%s",chaine);
1545 fprintf(inm,
"%" MMG5_PRId
"\n",npr);
1551 fwrite((
unsigned char*)&npr,
MMG5_SW,1,inm);
1555 if ( !
MG_EOK(pp) )
continue;
1558 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n"
1578 for (k=1; k<=
mesh->
np; k++) {
1599 strcpy(&chaine[0],
"\n\nNormals\n");
1600 fprintf(inm,
"%s",chaine);
1601 fprintf(inm,
"%" MMG5_PRId
"\n",nn);
1602 }
else { binch = 60;
1609 for (k=1; k<=
mesh->
np; k++) {
1618 fprintf(inm,
"%.15lg %.15lg %.15lg \n",pxp->
n1[0],pxp->
n1[1],pxp->
n1[2]);
1620 fwrite((
unsigned char*)&pxp->
n1[0],
MMG5_SD,1,inm);
1621 fwrite((
unsigned char*)&pxp->
n1[1],
MMG5_SD,1,inm);
1622 fwrite((
unsigned char*)&pxp->
n1[2],
MMG5_SD,1,inm);
1628 strcpy(&chaine[0],
"\n\nNormalAtVertices\n");
1629 fprintf(inm,
"%s",chaine);
1630 fprintf(inm,
"%" MMG5_PRId
"\n",nn);
1639 for (k=1; k<=
mesh->
np; k++) {
1647 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
"\n",ppt->
tmp,++nn);
1659 strcpy(&chaine[0],
"\n\nTangents\n");
1660 fprintf(inm,
"%s",chaine);
1661 fprintf(inm,
"%" MMG5_PRId
"\n",nt);
1670 for (k=1; k<=
mesh->
np; k++) {
1677 fprintf(inm,
"%.15lg %.15lg %.15lg \n",ppt->
n[0],ppt->
n[1],ppt->
n[2]);
1679 fwrite((
unsigned char*)&ppt->
n[0],
MMG5_SD,1,inm);
1680 fwrite((
unsigned char*)&ppt->
n[1],
MMG5_SD,1,inm);
1681 fwrite((
unsigned char*)&ppt->
n[2],
MMG5_SD,1,inm);
1688 strcpy(&chaine[0],
"\n\nTangentAtVertices\n");
1689 fprintf(inm,
"%s",chaine);
1690 fprintf(inm,
"%" MMG5_PRId
"\n",nt);
1699 for (k=1; k<=
mesh->
np; k++) {
1706 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
"\n",ppt->
tmp,++nt);
1723 strcpy(&chaine[0],
"\n\nTriangles\n");
1724 fprintf(inm,
"%s",chaine);
1725 fprintf(inm,
"%" MMG5_PRId
"\n",
mesh->
nt);
1733 for (k=1; k<=
mesh->
nt; k++) {
1742 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",
mesh->
point[ptt->
v[0]].
tmp,
mesh->
point[ptt->
v[1]].
tmp
1753 strcpy(&chaine[0],
"\n\nRequiredTriangles\n");
1754 fprintf(inm,
"%s",chaine);
1755 fprintf(inm,
"%" MMG5_PRId
"\n",ntreq);
1763 for (k=0; k<=
mesh->
nt; k++) {
1768 fprintf(inm,
"%" MMG5_PRId
"\n",k);
1777 strcpy(&chaine[0],
"\n\nParallelTriangles\n");
1778 fprintf(inm,
"%s",chaine);
1779 fprintf(inm,
"%" MMG5_PRId
"\n",ntpar);
1783 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1784 " saved at binary format. Ignored.\n",
1788 for (k=0; k<=
mesh->
nt; k++) {
1793 fprintf(inm,
"%" MMG5_PRId
"\n",k);
1801 nq = nqreq = nqpar = 0;
1824 strcpy(&chaine[0],
"\n\nQuadrilaterals\n");
1825 fprintf(inm,
"%s",chaine);
1826 fprintf(inm,
"%" MMG5_PRId
"\n",nq);
1836 if ( !
MG_EOK(pq) )
continue;
1839 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",
mesh->
point[pq->
v[0]].
tmp,
1852 strcpy(&chaine[0],
"\n\nRequiredQuadrilaterals\n");
1853 fprintf(inm,
"%s",chaine);
1854 fprintf(inm,
"%" MMG5_PRId
"\n",nqreq);
1867 fprintf(inm,
"%" MMG5_PRId
"\n",k);
1876 strcpy(&chaine[0],
"\n\nParallelQuadrilaterals\n");
1877 fprintf(inm,
"%s",chaine);
1878 fprintf(inm,
"%" MMG5_PRId
"\n",nqpar);
1882 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1883 " saved at binary format. Ignored.\n",
1892 fprintf(inm,
"%" MMG5_PRId
"\n",k);
1899 nr = nedreq = nedpar = 0;
1902 strcpy(&chaine[0],
"\n\nEdges\n");
1903 fprintf(inm,
"%s",chaine);
1904 fprintf(inm,
"%" MMG5_PRId
"\n",
mesh->
na);
1912 for (k=1; k<=
mesh->
na; k++) {
1928 strcpy(&chaine[0],
"\n\nRidges\n");
1929 fprintf(inm,
"%s",chaine);
1930 fprintf(inm,
"%" MMG5_PRId
"\n",nr);
1939 for (k=1; k<=
mesh->
na; k++) {
1943 fprintf(inm,
"%" MMG5_PRId
"\n",na);
1953 strcpy(&chaine[0],
"\n\nRequiredEdges\n");
1954 fprintf(inm,
"%s",chaine);
1955 fprintf(inm,
"%" MMG5_PRId
"\n",nedreq);
1961 fwrite(&nedreq,
MMG5_SW,1,inm);
1964 for (k=1; k<=
mesh->
na; k++) {
1968 fprintf(inm,
"%" MMG5_PRId
"\n",na);
1977 strcpy(&chaine[0],
"\n\nParallelEdges\n");
1978 fprintf(inm,
"%s",chaine);
1979 fprintf(inm,
"%" MMG5_PRId
"\n",nedpar);
1983 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1984 " saved at binary format. Ignored.\n",
1989 for (k=1; k<=
mesh->
na; k++) {
1993 fprintf(inm,
"%" MMG5_PRId
"\n",na);
2002 fprintf(stdout,
" NUMBER OF VERTICES %8" MMG5_PRId
" CORNERS %8" MMG5_PRId
""
2003 " REQUIRED %8" MMG5_PRId
"\n",np,nc,nre);
2004 fprintf(stdout,
" NUMBER OF TETRAHEDRA %8" MMG5_PRId
" REQUIRED %8" MMG5_PRId
"\n",
2007 fprintf(stdout,
" NUMBER OF PRISMS %8" MMG5_PRId
"\n",npr);
2010 fprintf(stdout,
" NUMBER OF EDGES %8" MMG5_PRId
" RIDGES %8" MMG5_PRId
""
2011 " REQUIRED %8" MMG5_PRId
"\n",na,nr,nedreq);
2013 fprintf(stdout,
" NUMBER OF TRIANGLES %8" MMG5_PRId
" REQUIRED %8" MMG5_PRId
"\n",
2016 fprintf(stdout,
" NUMBER OF QUADRILATERALS %8" MMG5_PRId
" REQUIRED %8" MMG5_PRId
"\n",
2019 if ( npar || nedpar || ntpar || nepar || nqpar ) {
2020 fprintf(stdout,
" NUMBER OF PARALLEL ENTITIES: \n");
2022 fprintf(stdout,
" VERTICES %8" MMG5_PRId
" \n",npar);
2024 fprintf(stdout,
" EDGES %8" MMG5_PRId
" \n",nedpar);
2026 fprintf(stdout,
" TRIANGLES %8" MMG5_PRId
" \n",ntpar);
2028 fprintf(stdout,
" QUADRILATERALS %8" MMG5_PRId
" \n",nqpar);
2030 fprintf(stdout,
" TETRAHEDRA %8" MMG5_PRId
" \n",nepar);
2036 strcpy(&chaine[0],
"\n\nEnd\n");
2037 fprintf(inm,
"%s",chaine);
2050 const char *filenameptr,*solnameptr;
2067 fprintf(stderr,
" ## Error: %s: please provide input file name"
2068 " (either in the mesh structure or as function argument).\n",
2074 strcpy(
tmp,filenameptr);
2080 int8_t savesolFile = 0;
2102 if (
ier && savesolFile ) {
2106 strcpy(soltmp,solnameptr);
2109 fprintf(stderr,
"\n ## ERROR: WRONG DATA TYPE OR WRONG SOLUTION NUMBER.\n");
2132 int iswp,
ier,ver,bin,*type,nsols,dim;
2138 if (
ier < 1 )
return ier;
2141 fprintf(stderr,
"Error: SEVERAL SOLUTIONS FOUND (%d)\n",nsols);
2148 fprintf(stderr,
" ** MISMATCHES DATA: THE NUMBER OF VERTICES IN "
2149 "THE MESH (%" MMG5_PRId
") DIFFERS FROM THE NUMBER OF VERTICES IN "
2150 "THE SOLUTION (%" MMG5_PRId
") \n",
mesh->
np,np);
2173 if ( ver ) met->
ver = ver;
2179 fseek(inm,posnp,SEEK_SET);
2181 if ( met->
ver == 1 ) {
2183 for (k=1; k<=
mesh->
np; k++) {
2189 for (k=1; k<=
mesh->
np; k++) {
2206 int iswp,
ier,ver,bin,*type,nsols,dim;
2209 static char mmgWarn = 0;
2214 if (
ier < 1 )
return ier;
2217 fprintf(stderr,
" ** MISMATCHES DATA: THE NUMBER OF VERTICES IN "
2218 "THE MESH (%" MMG5_PRId
") DIFFERS FROM THE NUMBER OF VERTICES IN "
2219 "THE SOLUTION (%" MMG5_PRId
") \n",
mesh->
np,np);
2229 fprintf(stderr,
"\n ## Error: %s: unexpected number of data (%d).\n",
2239 printf(
" Exit program.\n"); fclose(inm);
2244 for ( j=0; j<nsols; ++j ) {
2249 sprintf(data,
"sol_%" MMG5_PRId
"",j);
2253 fprintf(stderr,
"\n ## Warning: %s: unable to set solution name for"
2254 " at least 1 solution.\n",__func__);
2266 if ( ver ) psl->
ver = ver;
2272 fseek(inm,posnp,SEEK_SET);
2274 if ( (*
sol)[0].ver == 1 ) {
2276 for (k=1; k<=
mesh->
np; k++) {
2277 for ( j=0; j<nsols; ++j ) {
2285 for (k=1; k<=
mesh->
np; k++) {
2286 for ( j=0; j<nsols; ++j ) {
2307 fprintf(stderr,
"\n ## Warning: %s: no metric data to save.\n",__func__);
2317 if (
ier < 1 )
return ier;
2319 for (k=1; k<=
mesh->
np; k++) {
2321 if ( !
MG_VOK(ppt) )
continue;
2329 fprintf(inm,
"\n\nEnd\n");
2343 int binch,bin,
ier,npointSols,ncellSols;
2345 int *type,*entities,*size;
2347 if ( !(*
sol)[0].m )
return -1;
2366 printf(
"\n ## Warning: %s: unexpected entity type for solution %" MMG5_PRId
": %s."
2370 type[k] = (*sol)[k].type;
2371 size[k] = (*sol)[k].size;
2372 entities[k] = (*sol)[k].entities;
2379 if (
ier < 1 )
return ier;
2381 for (k=1; k<=
mesh->
np; k++) {
2383 if ( !
MG_VOK(ppt) )
continue;
2396 ncellSols,entities,type,size );
2398 for (k=1; k<=
mesh->
ne; k++) {
2400 if ( !
MG_EOK(pt) )
continue;
2418 fprintf(inm,
"\n\nEnd\n");
2442 printf(
"\n ## Error: %s: unable to save a file without a valid filename\n.",
2450 ptr = strstr(data,
".node");
2456 strcat(data,
".ele");
2457 if( !(inm = fopen(data,
"wb")) ) {
2458 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2463 fprintf(stdout,
" %%%% %s OPENED\n",data);
2467 for (k=1; k<=
mesh->
ne; k++) {
2469 if ( !
MG_EOK(pt) )
continue;
2474 fprintf(inm,
"%" MMG5_PRId
" %d %d\n\n",ne,
mesh->
dim+1,1);
2477 for ( k=1; k<=
mesh->
ne; ++k ) {
2481 fprintf(inm,
"%" MMG5_PRId
" ",++ne);
2484 for ( i=0; i<=
mesh->
dim; ++i ) {
2489 fprintf(inm,
"%" MMG5_PRId
"\n",pt->
ref);
2492 fprintf(stdout,
" NUMBER OF ELEMENT %8" MMG5_PRId
"\n",ne);
2515 printf(
"\n ## Error: %s: unable to save a file without a valid filename\n.",
2523 ptr = strstr(data,
".node");
2529 strcat(data,
".neigh");
2530 if( !(inm = fopen(data,
"wb")) ) {
2531 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2536 fprintf(stdout,
" %%%% %s OPENED\n",data);
2541 printf(
"\n ## Error: %s: unable to compute triangle adjacencies\n.",__func__);
2547 for (k=1; k<=
mesh->
ne; k++) {
2549 if ( !
MG_EOK(pt) )
continue;
2554 fprintf(inm,
"%" MMG5_PRId
" %d\n\n",ne,
mesh->
dim+1);
2557 for ( k=1; k<=
mesh->
ne; ++k ) {
2561 fprintf(inm,
"%" MMG5_PRId
" ",++ne);
2564 for ( i=1; i<=
mesh->
dim+1; ++i ) {
2567 fprintf(inm,
"%"MMG5_PRId
" ",idx);
2594 printf(
"\n ## Error: %s: unable to save a file without a valid filename\n.",
2602 ptr = strstr(data,
".node");
2608 strcat(data,
".face");
2609 if( !(inm = fopen(data,
"wb")) ) {
2610 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2615 fprintf(stdout,
" %%%% %s OPENED\n",data);
2619 fprintf(inm,
"%" MMG5_PRId
" %d\n\n",
mesh->
nt,1);
2621 for ( k=1; k<=
mesh->
nt; ++k ) {
2625 fprintf(inm,
"%" MMG5_PRId
" ",k);
2628 for ( i=0; i<
mesh->
dim; ++i ) {
2633 fprintf(inm,
"%" MMG5_PRId
"\n",pt->
ref);
2636 fprintf(stdout,
" NUMBER OF TRIANGLES %8" MMG5_PRId
"\n",
mesh->
nt);
const char * MMG5_Get_formatName(enum MMG5_Format fmt)
const char * MMG5_Get_entitiesName(enum MMG5_entities ent)
int MMG5_Get_format(char *ptr, int fmt)
char * MMG5_Get_filenameExt(char *filename)
int MMG3D_Set_inputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solin)
int MMG3D_Set_solSize(MMG5_pMesh mesh, MMG5_pSol sol, int typEntity, MMG5_int np, int typSol)
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh char * filename
int MMG3D_hashTetra(MMG5_pMesh mesh, int pack)
int MMG5_readDoubleSol3D(MMG5_pSol sol, FILE *inm, int bin, int iswp, MMG5_int pos)
int MMG5_chkMetricType(MMG5_pMesh mesh, int *type, int *entities, FILE *inm)
void MMG5_printSolStats(MMG5_pMesh mesh, MMG5_pSol *sol)
float MMG5_swapf(float sbin)
int MMG5_saveNode(MMG5_pMesh mesh, const char *filename)
int MMG5_saveEdge(MMG5_pMesh mesh, const char *filename, const char *ext)
int MMG5_saveSolHeader(MMG5_pMesh mesh, const char *filename, FILE **inm, int ver, int *bin, MMG5_int *bpos, MMG5_int np, int dim, int nsols, int *entities, int *type, int *size)
int MMG5_loadMshMesh_part1(MMG5_pMesh mesh, const char *filename, FILE **inm, long *posNodes, long *posElts, long **posNodeData, int *bin, int *iswp, MMG5_int *nelts, int *nsols)
void MMG5_writeDoubleSol3D(MMG5_pMesh mesh, MMG5_pSol sol, FILE *inm, int bin, MMG5_int pos, int metricData)
int MMG5_saveSolAtTetrahedraHeader(MMG5_pMesh mesh, FILE *inm, int ver, int bin, MMG5_int *bpos, int nsols, int nsolsAtTetra, int *entities, int *type, int *size)
int MMG5_readFloatSol3D(MMG5_pSol sol, FILE *inm, int bin, int iswp, int pos)
double MMG5_swapd(double sbin)
int MMG5_loadMshMesh_part2(MMG5_pMesh mesh, MMG5_pSol *sol, FILE **inm, const long posNodes, const long posElts, const long *posNodeData, const int bin, const int iswp, const MMG5_int nelts, const int nsols)
int MMG5_saveMshMesh(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename, int metricData)
void MMG5_printMetStats(MMG5_pMesh mesh, MMG5_pSol met)
int MMG5_loadSolHeader(const char *filename, int meshDim, FILE **inm, int *ver, int *bin, int *iswp, MMG5_int *np, int *dim, int *nsols, int **type, long *posnp, int imprim)
int MMG5_swapbin(int sbin)
int MMG3D_saveMshMesh_and_allData(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
int MMG3D_openMesh(int imprim, const char *filename, FILE **inm, int *bin, char *modeASCII, char *modeBIN)
int MMG3D_saveMesh(MMG5_pMesh mesh, const char *filename)
int MMG3D_loadGenericMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
int MMG3D_saveGenericMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
int MMG3D_loadSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
int MMG3D_loadMesh(MMG5_pMesh mesh, const char *filename)
int MMG3D_loadAllSols(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
int MMG3D_loadMshMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
int MMG3D_saveTetgenMesh(MMG5_pMesh mesh, const char *filename)
static int MMG3D_saveEle(MMG5_pMesh mesh, const char *filename)
static int MMG3D_saveNeigh(MMG5_pMesh mesh, const char *filename)
int MMG3D_loadMshMesh_and_allData(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
static int MMG3D_saveFace(MMG5_pMesh mesh, const char *filename)
int MMG3D_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
int MMG3D_saveMshMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
int MMG3D_loadMesh_opened(MMG5_pMesh mesh, FILE *inm, int bin)
int MMG3D_saveAllSols(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
int MMG3D_loadVtkMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
int MMG3D_loadVtuMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
int MMG3D_saveVtkMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
int MMG3D_saveVtuMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
API headers for the mmg3d library.
int MMG3D_zaldy(MMG5_pMesh mesh)
#define MMG5_SAFE_CALLOC(ptr, size, type, law)
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MG_EDG_OR_NOM(tag)
#define MMG_FREAD(ptr, size, count, stream)
double MMG5_orvol(MMG5_pPoint point, MMG5_int *v)
#define MMG5_SAFE_MALLOC(ptr, size, type, law)
#define MMG5_FILESTR_LGTH
#define MMG5_SAFE_FREE(ptr)
#define MMG_FSCANF(stream, format,...)
#define MMG5_DEL_MEM(mesh, ptr)
Structure to store edges of a MMG mesh.
Structure to store points of a MMG mesh.
Structure to store surface points of a MMG mesh.