Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use fgets() results when reading .mesh files, plus language fixes #271

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/mmg2d/inout_2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@
strcpy(chaine,"D");
while(fscanf(inm,"%127s",&chaine[0])!=EOF && strncmp(chaine,"End",strlen("End")) ) {
if ( chaine[0] == '#' ) {
fgets(strskip,MMG5_FILESTR_LGTH,inm);
while(1){ // skip until end of line or file
char *s = fgets(strskip,MMG5_FILESTR_LGTH,inm);

Check warning on line 88 in src/mmg2d/inout_2d.c

View check run for this annotation

Codecov / codecov/patch

src/mmg2d/inout_2d.c#L87-L88

Added lines #L87 - L88 were not covered by tests
if(!s) break; // nothing could be read
if(s[strlen(s)-1]=='\n') break; // end of line
}
continue;
}

Expand Down Expand Up @@ -640,7 +644,7 @@
ier = MMG2D_loadMesh(mesh,tmp);
if ( ier < 1 ) { break; }

/* Facultative metric */
/* Optional metric */
if ( sol ) {
MMG5_SAFE_MALLOC(soltmp,strlen(solnameptr)+1,char,return -1);
strcpy(soltmp,solnameptr);
Expand Down Expand Up @@ -960,7 +964,7 @@
fseek(inm,posnp,SEEK_SET);

if ( sol->ver == 1 ) {
/* Simple precision */
/* Single precision */
for (k=1; k<=sol->np; k++) {
if ( MMG2D_readFloatSol(sol,inm,bin,iswp,k) < 0 ) return -1;
}
Expand Down Expand Up @@ -1041,7 +1045,7 @@
for ( j=0; j<nsols; ++j) {
psl = *sol+j;

/* Give an arbitrary name to the solution because the Medit format has non
/* Give an arbitrary name to the solution because the Medit format has no
* name field */
sprintf(data,"sol_%d",j);
if ( !MMG2D_Set_inputSolName(mesh,psl,data) ) {
Expand All @@ -1059,7 +1063,7 @@
return -1;
}
psl->dim = 2;
/* For binary file, we read the verson inside the file */
/* For binary files, we read the verson inside the file */
if ( ver ) psl->ver = ver;
}
MMG5_SAFE_FREE(type);
Expand All @@ -1069,7 +1073,7 @@
fseek(inm,posnp,SEEK_SET);

if ( (*sol)[0].ver == 1 ) {
/* Simple precision */
/* Single precision */
for (k=1; k<=mesh->np; k++) {
for ( j=0; j<nsols; ++j ) {
psl = *sol+j;
Expand Down
30 changes: 17 additions & 13 deletions src/mmg3d/inout_3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
* \param modeASCII mode in which to open an ascii file ("r","r+","w","w+",...)
* \param modeASCII mode in which to open an ascii file ("r","r+","w","w+",...)
*
* \return 0 if fail to open file, -1 for other errors, 1 if success.
* \return 0 if the file could not be opened, -1 for other errors, 1 if success.
*
* Try to open a Medit file at asked mode (read only, write, etc) and store if
* Try to open a Medit file in the requested mode (read only, write, etc) and store if
* file is binary (depending on the extension).
*
*/
Expand Down Expand Up @@ -145,7 +145,11 @@
strcpy(chaine,"D");
while(fscanf(inm,"%127s",&chaine[0])!=EOF && strncmp(chaine,"End",strlen("End")) ) {
if ( chaine[0] == '#' ) {
fgets(strskip,MMG5_FILESTR_LGTH,inm);
while(1){ // skip until end of line or file
char *s = fgets(strskip,MMG5_FILESTR_LGTH,inm);

Check warning on line 149 in src/mmg3d/inout_3d.c

View check run for this annotation

Codecov / codecov/patch

src/mmg3d/inout_3d.c#L148-L149

Added lines #L148 - L149 were not covered by tests
if(!s) break; // nothing could be read
if(s[strlen(s)-1]=='\n') break; // end of line
}
continue;
}

Expand Down Expand Up @@ -807,7 +811,7 @@
ppt->tag &= ~MG_NUL;
}

/* Possibly switch 2 vertices number so that each tet is positively oriented */
/* Possibly switch 2 vertex numbers so that each tet is positively oriented */
if ( MMG5_orvol(mesh->point,pt->v) < 0.0 ) {
/* mesh->xt temporary used to count reoriented tetra */
mesh->xt++;
Expand Down Expand Up @@ -1233,7 +1237,7 @@
ier = MMG3D_loadMesh(mesh,tmp);
if ( ier < 1 ) { break; }

/* Facultative metric */
/* Optional metric */
if ( sol ) {
MMG5_SAFE_MALLOC(soltmp,strlen(solnameptr)+1,char,return -1);
strcpy(soltmp,solnameptr);
Expand Down Expand Up @@ -1286,7 +1290,7 @@
return 0;
}

/*entete fichier*/
/* file header */
binch=0; bpos=10;
if(!bin) {
strcpy(&chaine[0],"MeshVersionFormatted 2\n");
Expand Down Expand Up @@ -2041,7 +2045,7 @@
}
}

/*fin fichier*/
/* end of file */
if(!bin) {
strcpy(&chaine[0],"\n\nEnd\n");
fprintf(inm,"%s",chaine);
Expand Down Expand Up @@ -2173,13 +2177,13 @@
return ier;
}

/* Allocate and store the header informations for each solution */
/* Allocate and store the header information for each solution */
if ( !MMG3D_Set_solSize(mesh,met,MMG5_Vertex,mesh->np,type[0]) ) {
fclose(inm);
MMG5_SAFE_FREE(type);
return -1;
}
/* For binary file, we read the verson inside the file */
/* For binary files, we read the verson inside the file */
if ( ver ) met->ver = ver;

MMG5_SAFE_FREE(type);
Expand All @@ -2189,7 +2193,7 @@
fseek(inm,posnp,SEEK_SET);

if ( met->ver == 1 ) {
/* Simple precision */
/* Single precision */
for (k=1; k<=mesh->np; k++) {
if ( MMG5_readFloatSol3D(met,inm,bin,iswp,k) < 0 ) return -1;
}
Expand Down Expand Up @@ -2254,7 +2258,7 @@
for ( j=0; j<nsols; ++j ) {
psl = *sol + j;

/* Give an arbitrary name to the solution because the Medit format has non
/* Give an arbitrary name to the solution because the Medit format has no
* name field */
sprintf(data,"sol_%" MMG5_PRId "",j);
if ( !MMG3D_Set_inputSolName(mesh,psl,data) ) {
Expand All @@ -2272,7 +2276,7 @@
return -1;
}

/* For binary file, we read the verson inside the file */
/* For binary file, we read the version inside the file */
if ( ver ) psl->ver = ver;
}
MMG5_SAFE_FREE(type);
Expand All @@ -2282,7 +2286,7 @@
fseek(inm,posnp,SEEK_SET);

if ( (*sol)[0].ver == 1 ) {
/* Simple precision */
/* Single precision */
for (k=1; k<=mesh->np; k++) {
for ( j=0; j<nsols; ++j ) {
psl = *sol + j;
Expand Down
26 changes: 15 additions & 11 deletions src/mmgs/inout_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@
strcpy(chaine,"D");
while(fscanf(inm,"%127s",&chaine[0])!=EOF && strncmp(chaine,"End",strlen("End")) ) {
if ( chaine[0] == '#' ) {
fgets(strskip,MMG5_FILESTR_LGTH,inm);
while(1){ // skip until end of line or file

Check warning on line 104 in src/mmgs/inout_s.c

View check run for this annotation

Codecov / codecov/patch

src/mmgs/inout_s.c#L104

Added line #L104 was not covered by tests
char *s = fgets(strskip,MMG5_FILESTR_LGTH,inm);
if(!s) break; // nothing could be read
if(s[strlen(s)-1]=='\n') break; // end of line
}
continue;
}
if(!strncmp(chaine,"MeshVersionFormatted",strlen("MeshVersionFormatted"))) {
Expand Down Expand Up @@ -393,7 +397,7 @@
}
}

/* read quads: automatic conversion into tria */
/* read quads: automatic conversion to triangles */
if ( nq > 0 ) {
rewind(inm);
fseek(inm,posnq,SEEK_SET);
Expand Down Expand Up @@ -888,7 +892,7 @@
fprintf(stdout," %%%% %s OPENED\n",data);
MMG5_SAFE_FREE(data);

/*entete fichier*/
/* file header */
if(!bin) {
strcpy(&chaine[0],"MeshVersionFormatted 2\n");
fprintf(inm,"%s",chaine);
Expand Down Expand Up @@ -1281,7 +1285,7 @@
if ( nn+ng )
fprintf(stdout," NUMBER OF NORMALS %8" MMG5_PRId " TANGENTS %6" MMG5_PRId "\n",nn,ng);
}
/*fin fichier*/
/* end of file */
if(!bin) {
strcpy(&chaine[0],"\n\nEnd\n");
fprintf(inm,"%s",chaine);
Expand Down Expand Up @@ -1334,7 +1338,7 @@
return -1;
}

/* #MMG5_loadSolHeader function reads only solution at vertices so we don't
/* #MMG5_loadSolHeader function reads only solutions at vertices so we don't
have to check the entites on which the metric applies */
int entities = MMG5_Vertex;
ier = MMG5_chkMetricType(mesh,type,&entities,inm);
Expand All @@ -1343,7 +1347,7 @@
return ier;
}

/* Allocate and store the header informations for each solution */
/* Allocate and store the header information for each solution */
if ( !MMGS_Set_solSize(mesh,met,MMG5_Vertex,mesh->np,type[0]) ) {
fclose(inm);
MMG5_SAFE_FREE(type);
Expand Down Expand Up @@ -1424,7 +1428,7 @@
for ( j=0; j<nsols; ++j ) {
psl = *sol + j;

/* Give an arbitrary name to the solution because the Medit format has non
/* Give an arbitrary name to the solution because the Medit format has no
* name field */
sprintf(data,"sol_%" MMG5_PRId "",j);
if ( !MMGS_Set_inputSolName(mesh,psl,data) ) {
Expand All @@ -1435,13 +1439,13 @@
}
}

/* Allocate and store the header informations for each solution */
/* Allocate and store the header information for each solution */
if ( !MMGS_Set_solSize(mesh,psl,MMG5_Vertex,mesh->np,type[j]) ) {
MMG5_SAFE_FREE(type);
fclose(inm);
return -1;
}
/* For binary file, we read the verson inside the file */
/* For binary files, we read the verson inside the file */
if ( ver ) psl->ver = ver;
}
MMG5_SAFE_FREE(type);
Expand All @@ -1451,7 +1455,7 @@
fseek(inm,posnp,SEEK_SET);

if ( (*sol)[0].ver == 1 ) {
/* Simple precision */
/* Single precision */
for (k=1; k<=mesh->np; k++) {
for ( j=0; j<nsols; ++j ) {
psl = *sol + j;
Expand Down Expand Up @@ -1502,7 +1506,7 @@
fprintf(inm,"\n");
}

/*fin fichier*/
/* end of file */
if(!bin) {
fprintf(inm,"\n\nEnd\n");
} else {
Expand Down