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;
139 bpos = ia = idn = ip = 0;
146 while(fscanf(inm,
"%127s",&chaine[0])!=EOF && strncmp(chaine,
"End",strlen(
"End")) ) {
147 if ( chaine[0] ==
'#' ) {
151 if(s[strlen(s)-1]==
'\n')
break;
156 if(!strncmp(chaine,
"MeshVersionFormatted",strlen(
"MeshVersionFormatted"))) {
159 }
else if(!strncmp(chaine,
"Dimension",strlen(
"Dimension"))) {
162 fprintf(stderr,
"BAD DIMENSION : %d\n",
mesh->
dim);
166 }
else if(!strncmp(chaine,
"Vertices",strlen(
"Vertices"))) {
170 }
else if(!strncmp(chaine,
"RequiredVertices",strlen(
"RequiredVertices"))) {
172 posnpreq = ftell(inm);
174 }
else if(!strncmp(chaine,
"ParallelVertices",strlen(
"ParallelVertices"))) {
176 posnppar = ftell(inm);
178 }
else if(!strncmp(chaine,
"Triangles",strlen(
"Triangles"))) {
179 if ( !strncmp(chaine,
"TrianglesP",strlen(
"TrianglesP")) )
continue;
183 }
else if(!strncmp(chaine,
"RequiredTriangles",strlen(
"RequiredTriangles"))) {
185 posntreq = ftell(inm);
187 }
else if(!strncmp(chaine,
"ParallelTriangles",strlen(
"ParallelTriangles"))) {
189 posntpar = ftell(inm);
192 else if(!strncmp(chaine,
"Quadrilaterals",strlen(
"Quadrilaterals"))) {
196 }
else if(!strncmp(chaine,
"RequiredQuadrilaterals",strlen(
"RequiredQuadrilaterals"))) {
198 posnqreq = ftell(inm);
200 }
else if(!strncmp(chaine,
"ParallelQuadrilaterals",strlen(
"ParallelQuadrilaterals"))) {
202 posnqpar = ftell(inm);
204 }
else if(!strncmp(chaine,
"Tetrahedra",strlen(
"Tetrahedra"))) {
205 if ( !strncmp(chaine,
"TetrahedraP",strlen(
"TetrahedraP")) )
continue;
209 }
else if((!strncmp(chaine,
"Prisms",strlen(
"Prisms")))||
210 (!strncmp(chaine,
"Pentahedra",strlen(
"Pentahedra")))) {
212 posnprism = ftell(inm);
214 }
else if(!strncmp(chaine,
"RequiredTetrahedra",strlen(
"RequiredTetrahedra"))) {
216 posnereq = ftell(inm);
218 }
else if(!strncmp(chaine,
"ParallelTetrahedra",strlen(
"ParallelTetrahedra"))) {
220 posnepar = ftell(inm);
222 }
else if(!strncmp(chaine,
"Corners",strlen(
"Corners"))) {
224 posncor = ftell(inm);
226 }
else if(!strncmp(chaine,
"Edges",strlen(
"Edges"))) {
230 }
else if(!strncmp(chaine,
"RequiredEdges",strlen(
"RequiredEdges"))) {
232 posnedreq = ftell(inm);
234 }
else if(!strncmp(chaine,
"ParallelEdges",strlen(
"ParallelEdges"))) {
236 posnedpar = ftell(inm);
238 }
else if(!strncmp(chaine,
"Ridges",strlen(
"Ridges"))) {
242 }
else if(!ng && !strncmp(chaine,
"Normals",strlen(
"Normals"))) {
244 posnormal = ftell(inm);
246 }
else if(!strncmp(chaine,
"NormalAtVertices",strlen(
"NormalAtVertices"))) {
259 fprintf(stderr,
"BAD FILE ENCODING\n");
263 while(fread(&binch,
MMG5_SW,1,inm)!=0 && binch!=54 ) {
266 if(!bdim && binch==3) {
273 fprintf(stderr,
"BAD MESH DIMENSION : %d\n",
mesh->
dim);
274 fprintf(stderr,
" Exit program.\n");
278 }
else if(!
mesh->
npi && binch==4) {
285 fseek(inm,bpos,SEEK_SET);
287 }
else if(binch==15) {
292 posnpreq = ftell(inm);
294 fseek(inm,bpos,SEEK_SET);
296 }
else if(!
mesh->
nti && binch==6) {
303 fseek(inm,bpos,SEEK_SET);
305 }
else if(binch==17) {
310 posntreq = ftell(inm);
312 fseek(inm,bpos,SEEK_SET);
322 fseek(inm,bpos,SEEK_SET);
324 }
else if(binch==18) {
329 posnqreq = ftell(inm);
331 fseek(inm,bpos,SEEK_SET);
333 }
else if(!
mesh->
nei && binch==8) {
340 fseek(inm,bpos,SEEK_SET);
347 posnprism = ftell(inm);
349 fseek(inm,bpos,SEEK_SET);
351 }
else if(binch==12) {
356 posnereq = ftell(inm);
358 fseek(inm,bpos,SEEK_SET);
360 }
else if(!ncor && binch==13) {
365 posncor = ftell(inm);
367 fseek(inm,bpos,SEEK_SET);
369 }
else if(!
mesh->
nai && binch==5) {
376 fseek(inm,bpos,SEEK_SET);
378 }
else if(binch==16) {
383 posnedreq = ftell(inm);
385 fseek(inm,bpos,SEEK_SET);
387 }
else if(binch==14) {
394 fseek(inm,bpos,SEEK_SET);
396 }
else if(!ng && binch==60) {
401 posnormal = ftell(inm);
403 fseek(inm,bpos,SEEK_SET);
405 }
else if(binch==20) {
412 fseek(inm,bpos,SEEK_SET);
419 fseek(inm,bpos,SEEK_SET);
425 fprintf(stderr,
" ** MISSING DATA.\n");
426 fprintf(stderr,
" Check that your mesh contains points and tetrahedra.\n");
427 fprintf(stderr,
" Exit program.\n");
441 fseek(inm,posnp,SEEK_SET);
442 for (k=1; k<=
mesh->
np; k++) {
446 for (i=0 ; i<3 ; i++) {
448 ppt->
c[i] = (double) fc;
452 for (i=0 ; i<3 ; i++) {
455 ppt->
c[i] = (double) fc;
462 MMG_FSCANF(inm,
"%lf %lf %lf %" MMG5_PRId
"",&ppt->
c[0],&ppt->
c[1],&ppt->
c[2],&ppt->
ref);
465 for (i=0 ; i<3 ; i++) {
474 if ( ppt->
ref < 0 ) {
485 fseek(inm,posnpreq,SEEK_SET);
486 for (k=1; k<=npreq; k++) {
495 fprintf(stderr,
"\n ## Warning: %s: required Vertices number %8d"
496 " ignored.\n",__func__,i);
507 fseek(inm,posnppar,SEEK_SET);
508 for (k=1; k<=nppar; k++) {
517 fprintf(stderr,
"\n ## Warning: %s: parallel Vertices number %8d"
518 " ignored.\n",__func__,i);
530 fseek(inm,posncor,SEEK_SET);
531 for (k=1; k<=ncor; k++) {
540 fprintf(stderr,
"\n ## Warning: %s: corner number %8d ignored.\n",
552 fseek(inm,posnt,SEEK_SET);
554 for (k=1; k<=
mesh->
nt; k++) {
557 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&pt1->
v[0],&pt1->
v[1],&pt1->
v[2],&pt1->
ref);
560 for (i=0 ; i<3 ; i++) {
567 if ( pt1->
ref < 0 ) {
575 fseek(inm,posntreq,SEEK_SET);
576 for (k=1; k<=ntreq; k++) {
585 fprintf(stderr,
"\n ## Warning: %s: required triangle number %8d"
586 " ignored.\n",__func__,i);
598 fseek(inm,posntpar,SEEK_SET);
599 for (k=1; k<=ntpar; k++) {
608 fprintf(stderr,
"\n ## Warning: %s: parallel triangle number %8d"
609 " ignored.\n",__func__,i);
623 fseek(inm,posnq,SEEK_SET);
628 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&pq1->
v[0],&pq1->
v[1],&pq1->
v[2],
629 &pq1->
v[3],&pq1->
ref);
632 for (i=0 ; i<4 ; i++) {
639 if ( pq1->
ref < 0 ) {
648 fseek(inm,posnqreq,SEEK_SET);
649 for (k=1; k<=nqreq; k++) {
658 fprintf(stderr,
"\n ## Warning: %s: required quadrilaterals number"
659 " %8d ignored.\n",__func__,i);
673 fseek(inm,posnqpar,SEEK_SET);
674 for (k=1; k<=nqpar; k++) {
683 fprintf(stderr,
"\n ## Warning: %s: parallel quadrilaterals number"
684 " %8d ignored.\n",__func__,i);
701 fseek(inm,posned,SEEK_SET);
703 for (k=1; k<=na; k++) {
706 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"",&pa->
a,&pa->
b,&pa->
ref);
726 fseek(inm,posnr,SEEK_SET);
727 for (k=1; k<=nr; k++) {
736 fprintf(stderr,
"\n ## Warning: %s: ridge number %8" MMG5_PRId
" ignored.\n",
747 fseek(inm,posnedreq,SEEK_SET);
748 for (k=1; k<=nedreq; k++) {
757 fprintf(stderr,
"\n ## Warning: %s: required Edges number %8" MMG5_PRId
"/%8" MMG5_PRId
""
758 " ignored.\n",__func__,ia,na);
768 fseek(inm,posnedpar,SEEK_SET);
769 for (k=1; k<=nedpar; k++) {
778 fprintf(stderr,
"\n ## Warning: %s: parallel Edges number %8" MMG5_PRId
"/%8" MMG5_PRId
""
779 " ignored.\n",__func__,ia,na);
790 fseek(inm,posne,SEEK_SET);
792 for (k=1; k<=
mesh->
ne; k++) {
795 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);
798 for (i=0 ; i<4 ; i++) {
808 pt->
ref = MMG5_abs(ref);
809 for (i=0; i<4; i++) {
824 fprintf(stderr,
"\n $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
825 fprintf(stderr,
" BAD ORIENTATION : vol < 0 -- %8" MMG5_PRId
" tetra reoriented\n",
mesh->
xt);
826 fprintf(stderr,
" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n\n");
832 fseek(inm,posnereq,SEEK_SET);
833 for (k=1; k<=nereq; k++) {
842 fprintf(stderr,
"\n ## Warning: %s: required Tetra number %8d"
843 " ignored.\n",__func__,i);
853 fseek(inm,posnepar,SEEK_SET);
854 for (k=1; k<=nepar; k++) {
863 fprintf(stderr,
"\n ## Warning: %s: parallel Tetra number %8d"
864 " ignored.\n",__func__,i);
873 fseek(inm,posnprism,SEEK_SET);
877 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],
878 &pp->
v[3],&pp->
v[4],&pp->
v[5],&ref);
881 for (i=0 ; i<6 ; i++) {
889 if ( pp-> ref < 0 ) {
893 for (i=0; i<6; i++) {
900 fprintf(stdout,
"\n $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
901 fprintf(stdout,
" WARNING : %" MMG5_PRId
" entities with unexpected refs (ref< 0).\n",nref);
902 fprintf(stdout,
" We take their absolute values.\n");
903 fprintf(stdout,
" $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n\n");
909 fprintf(stderr,
"\n ## Warning: %s: your mesh don't contains Normals but contains"
910 " NormalAtVertices. The NormalAtVertices are deleted. \n",__func__);
918 fseek(inm,posnormal,SEEK_SET);
919 for (k=1; k<=ng; k++) {
920 n = &norm[3*(k-1)+1];
923 for (i=0 ; i<3 ; i++) {
928 for (i=0 ; i<3 ; i++) {
937 MMG_FSCANF(inm,
"%lf %lf %lf",&n[0],&n[1],&n[2]);
940 for (i=0 ; i<3 ; i++) {
946 dd = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
956 fseek(inm,posnc1,SEEK_SET);
960 MMG_FSCANF(inm,
"%" MMG5_PRId
" %" MMG5_PRId
"",&ip,&idn);
968 if ( idn > 0 && ip < mesh->np+1 ) {
973 memcpy(&
mesh->
point[ip].
n,&norm[3*(idn-1)+1],3*
sizeof(
double));
981 for (k=1; k<=
mesh->
np; k++) {
989 fprintf(stdout,
" NUMBER OF VERTICES %8" MMG5_PRId
"\n",
mesh->
np);
990 fprintf(stdout,
" NUMBER OF TETRAHEDRA %8" MMG5_PRId
"\n",
mesh->
ne);
992 fprintf(stdout,
" NUMBER OF PRISMS %8" MMG5_PRId
"\n",
mesh->
nprism);
995 fprintf(stdout,
" NUMBER OF EDGES %8" MMG5_PRId
"\n",
mesh->
na);
997 fprintf(stdout,
" NUMBER OF RIDGES %8" MMG5_PRId
"\n",nr);
1000 fprintf(stdout,
" NUMBER OF TRIANGLES %8" MMG5_PRId
"\n",
mesh->
nt);
1002 fprintf(stdout,
" NUMBER OF QUADRILATERALS %8" MMG5_PRId
"\n",
mesh->
nquad);
1005 if ( npreq || nedreq || ntreq || nereq || nqreq ) {
1006 fprintf(stdout,
" NUMBER OF REQUIRED ENTITIES: \n");
1008 fprintf(stdout,
" VERTICES %8" MMG5_PRId
" \n",npreq);
1010 fprintf(stdout,
" EDGES %8" MMG5_PRId
" \n",nedreq);
1012 fprintf(stdout,
" TRIANGLES %8" MMG5_PRId
" \n",ntreq);
1014 fprintf(stdout,
" QUADRILATERALS %8" MMG5_PRId
" \n",nqreq);
1016 fprintf(stdout,
" TETRAHEDRA %8" MMG5_PRId
" \n",nereq);
1019 fprintf(stdout,
" NUMBER OF CORNERS %8" MMG5_PRId
" \n",ncor);
1021 if ( nppar || nedpar || ntpar || nepar || nqpar ) {
1022 fprintf(stdout,
" NUMBER OF PARALLEL ENTITIES: \n");
1024 fprintf(stdout,
" VERTICES %8" MMG5_PRId
" \n",nppar);
1026 fprintf(stdout,
" EDGES %8" MMG5_PRId
" \n",nedpar);
1028 fprintf(stdout,
" TRIANGLES %8" MMG5_PRId
" \n",ntpar);
1030 fprintf(stdout,
" QUADRILATERALS %8" MMG5_PRId
" \n",nqpar);
1032 fprintf(stdout,
" TETRAHEDRA %8" MMG5_PRId
" \n",nepar);
1054 if(
ier < 1 )
return ier;
1056 if(
ier < 1 )
return ier;
1066 long posNodes,posElts,*posNodeData;
1074 &posNodes,&posElts,&posNodeData,
1075 &bin,&iswp,&nelts,&nsols);
1076 if (
ier < 1 )
return (
ier);
1079 fprintf(stderr,
"Error: SEVERAL SOLUTIONS FOUND (%d)\n",nsols);
1098 fprintf(stderr,
" ** MISSING DATA.\n");
1099 fprintf(stderr,
" Check that your mesh contains tetrahedra.\n");
1100 fprintf(stderr,
" Exit program.\n");
1107 posNodes,posElts,posNodeData,
1108 bin,iswp,nelts,nsols);
1111 fprintf(stderr,
" ** ERROR WHEN PARSING THE INPUT FILE\n");
1135 long posNodes,posElts,*posNodeData;
1143 &posNodes,&posElts,&posNodeData,
1144 &bin,&iswp,&nelts,&nsols);
1145 if (
ier < 1 )
return (
ier);
1151 printf(
" Exit program.\n"); fclose(inm);
1169 fprintf(stderr,
" ** MISSING DATA.\n");
1170 fprintf(stderr,
" Check that your mesh contains tetrahedra.\n");
1171 fprintf(stderr,
" Exit program.\n");
1178 posNodes,posElts,posNodeData,
1179 bin,iswp,nelts,nsols);
1182 fprintf(stderr,
" ** ERROR WHEN PARSING THE INPUT FILE\n");
1192 const char *filenameptr,*solnameptr;
1209 fprintf(stderr,
" ## Error: %s: please provide input file name"
1210 " (either in the mesh structure or as function argument).\n",
1216 strcpy(
tmp,filenameptr);
1238 if (
ier < 1 ) {
break; }
1243 strcpy(soltmp,solnameptr);
1246 fprintf(stderr,
"\n ## ERROR: WRONG DATA TYPE OR WRONG SOLUTION NUMBER.\n");
1281 MMG5_int k,na,nc,np,ne,nn,nr,nre,npar,nedreq,nedpar,ntreq,ntpar,nt,nereq,nepar;
1282 MMG5_int npr,nq,nqreq,nqpar,bpos;
1285 static int8_t parWarn = 0;
1296 strcpy(&chaine[0],
"MeshVersionFormatted 2\n");
1297 fprintf(inm,
"%s",chaine);
1298 strcpy(&chaine[0],
"\n\nDimension 3\n");
1299 fprintf(inm,
"%s ",chaine);
1314 np = nc = na = nr = nre = npar = 0;
1317 fprintf(stderr,
"\n ## Error: %s: points array not allocated.\n",
1324 for (k=1; k<=
mesh->
np; k++) {
1336 strcpy(&chaine[0],
"\n\nVertices\n");
1337 fprintf(inm,
"%s",chaine);
1338 fprintf(inm,
"%" MMG5_PRId
"\n",np);
1346 for (k=1; k<=
mesh->
np; k++) {
1350 fprintf(inm,
"%.15lg %.15lg %.15lg %" MMG5_PRId
"\n",
1351 ppt->
c[0],ppt->
c[1],ppt->
c[2],MMG5_abs(ppt->
ref));
1353 fwrite((
unsigned char*)&ppt->
c[0],
MMG5_SD,1,inm);
1354 fwrite((
unsigned char*)&ppt->
c[1],
MMG5_SD,1,inm);
1355 fwrite((
unsigned char*)&ppt->
c[2],
MMG5_SD,1,inm);
1356 ppt->
ref = MMG5_abs(ppt->
ref);
1357 fwrite((
unsigned char*)&ppt->
ref,
MMG5_SW,1,inm);
1365 strcpy(&chaine[0],
"\n\nCorners\n");
1366 fprintf(inm,
"%s",chaine);
1367 fprintf(inm,
"%" MMG5_PRId
"\n",nc);
1376 for (k=1; k<=
mesh->
np; k++) {
1380 fprintf(inm,
"%" MMG5_PRId
"\n",ppt->
tmp);
1389 strcpy(&chaine[0],
"\n\nRequiredVertices\n");
1390 fprintf(inm,
"%s",chaine);
1391 fprintf(inm,
"%" MMG5_PRId
"\n",nre);
1399 for (k=1; k<=
mesh->
np; k++) {
1403 fprintf(inm,
"%" MMG5_PRId
"\n",ppt->
tmp);
1412 strcpy(&chaine[0],
"\n\nParallelVertices\n");
1413 fprintf(inm,
"%s",chaine);
1414 fprintf(inm,
"%" MMG5_PRId
"\n",npar);
1419 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1420 " saved at binary format. Ignored.\n",
1425 for (k=1; k<=
mesh->
np; k++) {
1429 fprintf(inm,
"%" MMG5_PRId
"\n",ppt->
tmp);
1436 ne = nereq = nepar = 0;
1438 for (k=1; k<=
mesh->
ne; k++) {
1453 fprintf(stderr,
"\n ## Warning: %s: tetra array not allocated.\n",
1458 strcpy(&chaine[0],
"\n\nTetrahedra\n");
1459 fprintf(inm,
"%s",chaine);
1460 fprintf(inm,
"%" MMG5_PRId
"\n",ne);
1466 fwrite((
unsigned char*)&ne,
MMG5_SW,1,inm);
1468 for (k=1; k<=
mesh->
ne; k++) {
1471 if ( !
MG_EOK(pt) ) {
continue; }
1482 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
1495 strcpy(&chaine[0],
"\n\nRequiredTetrahedra\n");
1496 fprintf(inm,
"%s",chaine);
1497 fprintf(inm,
"%" MMG5_PRId
"\n",nereq);
1506 for (k=1; k<=
mesh->
ne; k++) {
1508 if ( !
MG_EOK(pt) )
continue;
1512 fprintf(inm,
"%" MMG5_PRId
"\n",ne);
1522 strcpy(&chaine[0],
"\n\nParallelTetrahedra\n");
1523 fprintf(inm,
"%s",chaine);
1524 fprintf(inm,
"%" MMG5_PRId
"\n",nepar);
1528 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1529 " saved at binary format. Ignored.\n",
1535 for (k=1; k<=
mesh->
ne; k++) {
1537 if ( !
MG_EOK(pt) )
continue;
1541 fprintf(inm,
"%" MMG5_PRId
"\n",ne);
1551 if ( !
MG_EOK(pp) )
continue;
1557 strcpy(&chaine[0],
"\n\nPrisms\n");
1558 fprintf(inm,
"%s",chaine);
1559 fprintf(inm,
"%" MMG5_PRId
"\n",npr);
1565 fwrite((
unsigned char*)&npr,
MMG5_SW,1,inm);
1569 if ( !
MG_EOK(pp) )
continue;
1572 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n"
1592 for (k=1; k<=
mesh->
np; k++) {
1613 strcpy(&chaine[0],
"\n\nNormals\n");
1614 fprintf(inm,
"%s",chaine);
1615 fprintf(inm,
"%" MMG5_PRId
"\n",nn);
1616 }
else { binch = 60;
1623 for (k=1; k<=
mesh->
np; k++) {
1632 fprintf(inm,
"%.15lg %.15lg %.15lg \n",pxp->
n1[0],pxp->
n1[1],pxp->
n1[2]);
1634 fwrite((
unsigned char*)&pxp->
n1[0],
MMG5_SD,1,inm);
1635 fwrite((
unsigned char*)&pxp->
n1[1],
MMG5_SD,1,inm);
1636 fwrite((
unsigned char*)&pxp->
n1[2],
MMG5_SD,1,inm);
1642 strcpy(&chaine[0],
"\n\nNormalAtVertices\n");
1643 fprintf(inm,
"%s",chaine);
1644 fprintf(inm,
"%" MMG5_PRId
"\n",nn);
1653 for (k=1; k<=
mesh->
np; k++) {
1661 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
"\n",ppt->
tmp,++nn);
1673 strcpy(&chaine[0],
"\n\nTangents\n");
1674 fprintf(inm,
"%s",chaine);
1675 fprintf(inm,
"%" MMG5_PRId
"\n",nt);
1684 for (k=1; k<=
mesh->
np; k++) {
1691 fprintf(inm,
"%.15lg %.15lg %.15lg \n",ppt->
n[0],ppt->
n[1],ppt->
n[2]);
1693 fwrite((
unsigned char*)&ppt->
n[0],
MMG5_SD,1,inm);
1694 fwrite((
unsigned char*)&ppt->
n[1],
MMG5_SD,1,inm);
1695 fwrite((
unsigned char*)&ppt->
n[2],
MMG5_SD,1,inm);
1702 strcpy(&chaine[0],
"\n\nTangentAtVertices\n");
1703 fprintf(inm,
"%s",chaine);
1704 fprintf(inm,
"%" MMG5_PRId
"\n",nt);
1713 for (k=1; k<=
mesh->
np; k++) {
1720 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
"\n",ppt->
tmp,++nt);
1737 strcpy(&chaine[0],
"\n\nTriangles\n");
1738 fprintf(inm,
"%s",chaine);
1739 fprintf(inm,
"%" MMG5_PRId
"\n",
mesh->
nt);
1747 for (k=1; k<=
mesh->
nt; k++) {
1756 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",
mesh->
point[ptt->
v[0]].
tmp,
mesh->
point[ptt->
v[1]].
tmp
1767 strcpy(&chaine[0],
"\n\nRequiredTriangles\n");
1768 fprintf(inm,
"%s",chaine);
1769 fprintf(inm,
"%" MMG5_PRId
"\n",ntreq);
1777 for (k=0; k<=
mesh->
nt; k++) {
1782 fprintf(inm,
"%" MMG5_PRId
"\n",k);
1791 strcpy(&chaine[0],
"\n\nParallelTriangles\n");
1792 fprintf(inm,
"%s",chaine);
1793 fprintf(inm,
"%" MMG5_PRId
"\n",ntpar);
1797 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1798 " saved at binary format. Ignored.\n",
1802 for (k=0; k<=
mesh->
nt; k++) {
1807 fprintf(inm,
"%" MMG5_PRId
"\n",k);
1815 nq = nqreq = nqpar = 0;
1838 strcpy(&chaine[0],
"\n\nQuadrilaterals\n");
1839 fprintf(inm,
"%s",chaine);
1840 fprintf(inm,
"%" MMG5_PRId
"\n",nq);
1850 if ( !
MG_EOK(pq) )
continue;
1853 fprintf(inm,
"%" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
" %" MMG5_PRId
"\n",
mesh->
point[pq->
v[0]].
tmp,
1866 strcpy(&chaine[0],
"\n\nRequiredQuadrilaterals\n");
1867 fprintf(inm,
"%s",chaine);
1868 fprintf(inm,
"%" MMG5_PRId
"\n",nqreq);
1881 fprintf(inm,
"%" MMG5_PRId
"\n",k);
1890 strcpy(&chaine[0],
"\n\nParallelQuadrilaterals\n");
1891 fprintf(inm,
"%s",chaine);
1892 fprintf(inm,
"%" MMG5_PRId
"\n",nqpar);
1896 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1897 " saved at binary format. Ignored.\n",
1906 fprintf(inm,
"%" MMG5_PRId
"\n",k);
1913 nr = nedreq = nedpar = 0;
1916 strcpy(&chaine[0],
"\n\nEdges\n");
1917 fprintf(inm,
"%s",chaine);
1918 fprintf(inm,
"%" MMG5_PRId
"\n",
mesh->
na);
1926 for (k=1; k<=
mesh->
na; k++) {
1942 strcpy(&chaine[0],
"\n\nRidges\n");
1943 fprintf(inm,
"%s",chaine);
1944 fprintf(inm,
"%" MMG5_PRId
"\n",nr);
1953 for (k=1; k<=
mesh->
na; k++) {
1957 fprintf(inm,
"%" MMG5_PRId
"\n",na);
1967 strcpy(&chaine[0],
"\n\nRequiredEdges\n");
1968 fprintf(inm,
"%s",chaine);
1969 fprintf(inm,
"%" MMG5_PRId
"\n",nedreq);
1975 fwrite(&nedreq,
MMG5_SW,1,inm);
1978 for (k=1; k<=
mesh->
na; k++) {
1982 fprintf(inm,
"%" MMG5_PRId
"\n",na);
1991 strcpy(&chaine[0],
"\n\nParallelEdges\n");
1992 fprintf(inm,
"%s",chaine);
1993 fprintf(inm,
"%" MMG5_PRId
"\n",nedpar);
1997 fprintf(stderr,
"\n ## Warning: %s: parallel entities can't be"
1998 " saved at binary format. Ignored.\n",
2003 for (k=1; k<=
mesh->
na; k++) {
2007 fprintf(inm,
"%" MMG5_PRId
"\n",na);
2016 fprintf(stdout,
" NUMBER OF VERTICES %8" MMG5_PRId
" CORNERS %8" MMG5_PRId
""
2017 " REQUIRED %8" MMG5_PRId
"\n",np,nc,nre);
2018 fprintf(stdout,
" NUMBER OF TETRAHEDRA %8" MMG5_PRId
" REQUIRED %8" MMG5_PRId
"\n",
2021 fprintf(stdout,
" NUMBER OF PRISMS %8" MMG5_PRId
"\n",npr);
2024 fprintf(stdout,
" NUMBER OF EDGES %8" MMG5_PRId
" RIDGES %8" MMG5_PRId
""
2025 " REQUIRED %8" MMG5_PRId
"\n",na,nr,nedreq);
2027 fprintf(stdout,
" NUMBER OF TRIANGLES %8" MMG5_PRId
" REQUIRED %8" MMG5_PRId
"\n",
2030 fprintf(stdout,
" NUMBER OF QUADRILATERALS %8" MMG5_PRId
" REQUIRED %8" MMG5_PRId
"\n",
2033 if ( npar || nedpar || ntpar || nepar || nqpar ) {
2034 fprintf(stdout,
" NUMBER OF PARALLEL ENTITIES: \n");
2036 fprintf(stdout,
" VERTICES %8" MMG5_PRId
" \n",npar);
2038 fprintf(stdout,
" EDGES %8" MMG5_PRId
" \n",nedpar);
2040 fprintf(stdout,
" TRIANGLES %8" MMG5_PRId
" \n",ntpar);
2042 fprintf(stdout,
" QUADRILATERALS %8" MMG5_PRId
" \n",nqpar);
2044 fprintf(stdout,
" TETRAHEDRA %8" MMG5_PRId
" \n",nepar);
2050 strcpy(&chaine[0],
"\n\nEnd\n");
2051 fprintf(inm,
"%s",chaine);
2064 const char *filenameptr,*solnameptr;
2081 fprintf(stderr,
" ## Error: %s: please provide input file name"
2082 " (either in the mesh structure or as function argument).\n",
2088 strcpy(
tmp,filenameptr);
2094 int8_t savesolFile = 0;
2116 if (
ier && savesolFile ) {
2120 strcpy(soltmp,solnameptr);
2123 fprintf(stderr,
"\n ## ERROR: WRONG DATA TYPE OR WRONG SOLUTION NUMBER.\n");
2146 int iswp,
ier,ver,bin,*type,nsols,dim;
2152 if (
ier < 1 )
return ier;
2155 fprintf(stderr,
"Error: SEVERAL SOLUTIONS FOUND (%d)\n",nsols);
2162 fprintf(stderr,
" ** MISMATCHES DATA: THE NUMBER OF VERTICES IN "
2163 "THE MESH (%" MMG5_PRId
") DIFFERS FROM THE NUMBER OF VERTICES IN "
2164 "THE SOLUTION (%" MMG5_PRId
") \n",
mesh->
np,np);
2187 if ( ver ) met->
ver = ver;
2193 fseek(inm,posnp,SEEK_SET);
2195 if ( met->
ver == 1 ) {
2197 for (k=1; k<=
mesh->
np; k++) {
2203 for (k=1; k<=
mesh->
np; k++) {
2220 int iswp,
ier,ver,bin,*type,nsols,dim;
2223 static char mmgWarn = 0;
2228 if (
ier < 1 )
return ier;
2231 fprintf(stderr,
" ** MISMATCHES DATA: THE NUMBER OF VERTICES IN "
2232 "THE MESH (%" MMG5_PRId
") DIFFERS FROM THE NUMBER OF VERTICES IN "
2233 "THE SOLUTION (%" MMG5_PRId
") \n",
mesh->
np,np);
2243 fprintf(stderr,
"\n ## Error: %s: unexpected number of data (%d).\n",
2253 printf(
" Exit program.\n"); fclose(inm);
2258 for ( j=0; j<nsols; ++j ) {
2263 sprintf(data,
"sol_%" MMG5_PRId
"",j);
2267 fprintf(stderr,
"\n ## Warning: %s: unable to set solution name for"
2268 " at least 1 solution.\n",__func__);
2280 if ( ver ) psl->
ver = ver;
2286 fseek(inm,posnp,SEEK_SET);
2288 if ( (*
sol)[0].ver == 1 ) {
2290 for (k=1; k<=
mesh->
np; k++) {
2291 for ( j=0; j<nsols; ++j ) {
2299 for (k=1; k<=
mesh->
np; k++) {
2300 for ( j=0; j<nsols; ++j ) {
2321 fprintf(stderr,
"\n ## Warning: %s: no metric data to save.\n",__func__);
2331 if (
ier < 1 )
return ier;
2333 for (k=1; k<=
mesh->
np; k++) {
2335 if ( !
MG_VOK(ppt) )
continue;
2343 fprintf(inm,
"\n\nEnd\n");
2357 int binch,bin,
ier,npointSols,ncellSols;
2359 int *type,*entities,*size;
2361 if ( !(*
sol)[0].m )
return -1;
2380 printf(
"\n ## Warning: %s: unexpected entity type for solution %" MMG5_PRId
": %s."
2384 type[k] = (*sol)[k].type;
2385 size[k] = (*sol)[k].size;
2386 entities[k] = (*sol)[k].entities;
2393 if (
ier < 1 )
return ier;
2395 for (k=1; k<=
mesh->
np; k++) {
2397 if ( !
MG_VOK(ppt) )
continue;
2410 ncellSols,entities,type,size );
2412 for (k=1; k<=
mesh->
ne; k++) {
2414 if ( !
MG_EOK(pt) )
continue;
2432 fprintf(inm,
"\n\nEnd\n");
2456 printf(
"\n ## Error: %s: unable to save a file without a valid filename\n.",
2464 ptr = strstr(data,
".node");
2470 strcat(data,
".ele");
2471 if( !(inm = fopen(data,
"wb")) ) {
2472 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2477 fprintf(stdout,
" %%%% %s OPENED\n",data);
2481 for (k=1; k<=
mesh->
ne; k++) {
2483 if ( !
MG_EOK(pt) )
continue;
2488 fprintf(inm,
"%" MMG5_PRId
" %d %d\n\n",ne,
mesh->
dim+1,1);
2491 for ( k=1; k<=
mesh->
ne; ++k ) {
2495 fprintf(inm,
"%" MMG5_PRId
" ",++ne);
2498 for ( i=0; i<=
mesh->
dim; ++i ) {
2503 fprintf(inm,
"%" MMG5_PRId
"\n",pt->
ref);
2506 fprintf(stdout,
" NUMBER OF ELEMENT %8" MMG5_PRId
"\n",ne);
2529 printf(
"\n ## Error: %s: unable to save a file without a valid filename\n.",
2537 ptr = strstr(data,
".node");
2543 strcat(data,
".neigh");
2544 if( !(inm = fopen(data,
"wb")) ) {
2545 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2550 fprintf(stdout,
" %%%% %s OPENED\n",data);
2555 printf(
"\n ## Error: %s: unable to compute triangle adjacencies\n.",__func__);
2561 for (k=1; k<=
mesh->
ne; k++) {
2563 if ( !
MG_EOK(pt) )
continue;
2568 fprintf(inm,
"%" MMG5_PRId
" %d\n\n",ne,
mesh->
dim+1);
2571 for ( k=1; k<=
mesh->
ne; ++k ) {
2575 fprintf(inm,
"%" MMG5_PRId
" ",++ne);
2578 for ( i=1; i<=
mesh->
dim+1; ++i ) {
2581 fprintf(inm,
"%"MMG5_PRId
" ",idx);
2608 printf(
"\n ## Error: %s: unable to save a file without a valid filename\n.",
2616 ptr = strstr(data,
".node");
2622 strcat(data,
".face");
2623 if( !(inm = fopen(data,
"wb")) ) {
2624 fprintf(stderr,
" ** UNABLE TO OPEN %s.\n",data);
2629 fprintf(stdout,
" %%%% %s OPENED\n",data);
2633 fprintf(inm,
"%" MMG5_PRId
" %d\n\n",
mesh->
nt,1);
2635 for ( k=1; k<=
mesh->
nt; ++k ) {
2639 fprintf(inm,
"%" MMG5_PRId
" ",k);
2642 for ( i=0; i<
mesh->
dim; ++i ) {
2647 fprintf(inm,
"%" MMG5_PRId
"\n",pt->
ref);
2650 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)
Set the name of input solution file.
int MMG3D_Set_solSize(MMG5_pMesh mesh, MMG5_pSol sol, int typEntity, MMG5_int np, int typSol)
Initialize a solution field.
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh char * filename
int MMG3D_hashTetra(MMG5_pMesh mesh, int pack)
Create array of adjacency.
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)
Save a mesh and data in MSH format, ascii or binary depending on the filename extension.
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)
Save a mesh in .mesh/.meshb format.
int MMG3D_saveGenericMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save mesh data in a file whose format depends on the filename extension.
int MMG3D_loadSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Load a metric field (or other solution).
int MMG3D_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
int MMG3D_loadAllSols(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
Load one or more solutions in a solution file in medit file format.
int MMG3D_loadMshMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Load a mesh and possibly a solution in .msh format from file.
int MMG3D_saveTetgenMesh(MMG5_pMesh mesh, const char *filename)
Save data in Tetgen's Triangle format.
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)
Load a mesh and all data from a file in MSH format.
static int MMG3D_saveFace(MMG5_pMesh mesh, const char *filename)
int MMG3D_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Write isotropic or anisotropic metric.
int MMG3D_saveMshMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save a mesh in MSH format, ascii or binary depending on the filename extension.
int MMG3D_loadMesh_opened(MMG5_pMesh mesh, FILE *inm, int bin)
int MMG3D_loadGenericMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol sol, const char *filename)
Read mesh data in a format determined by the filename extension.
int MMG3D_saveAllSols(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
Save 1 or more solutions in medit solution file format.
int MMG3D_loadVtkMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol sol, const char *filename)
Load a mesh and possibly a solution from a file in VTK format.
int MMG3D_saveVtkMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save a mesh and optionally one solution in VTK format.
int MMG3D_loadVtuMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol sol, const char *filename)
Load a mesh and possibly a solution in VTU (VTK) format from file.
int MMG3D_saveVtuMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save a mesh and optionally one data field in VTU format.
API headers and documentation for the mmg3d library, for volumetric meshes in 3D.
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 am MMG mesh.
Structure to store vertices of an MMG mesh.
Structure to store prsim of a MMG mesh.
Structure to store quadrangles of an MMG mesh.
Structure to store tetrahedra of an MMG mesh.
Structure to store triangles of a MMG mesh.
Structure to store surface vertices of an MMG mesh.