Skip to content

Commit

Permalink
Merge pull request #215 from MmgTools/feature/fix-sol-name
Browse files Browse the repository at this point in the history
Feature/fix sol name
  • Loading branch information
Algiane committed Jun 8, 2023
2 parents a940c30 + 8043f3f commit 7d71f1b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
41 changes: 30 additions & 11 deletions src/common/API_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,24 @@ int MMG5_Set_inputSolName(MMG5_pMesh mesh,MMG5_pSol sol, const char* solin) {
int mesh_len = strlen(mesh->namein)+1;
MMG5_SAFE_CALLOC(sol->namein,mesh_len,char,return 0);
strcpy(sol->namein,mesh->namein);
ptr = strstr(sol->namein,".mesh");

/* Get last dot character to avoid issues with <basename>.mesh.mesh files */
char *dot = strrchr(sol->namein,'.');
ptr = NULL;
if ( dot) {
ptr = strstr(dot,".mesh");
}
if ( ptr ) {
/* the sol file is renamed with the meshfile without extension */
/* the sol file is renamed concatening the mesh basename and the sol extension */
*ptr = '\0';
MMG5_SAFE_REALLOC(sol->namein,mesh_len,(strlen(sol->namein)+1),char,
"input sol name",return 0);
}
MMG5_ADD_MEM(mesh,(strlen(sol->namein)+1)*sizeof(char),"input sol name",
MMG5_SAFE_REALLOC(sol->namein,mesh_len,(strlen(sol->namein)+5),char,
"input sol name",return 0);

MMG5_ADD_MEM(mesh,(strlen(sol->namein)+5)*sizeof(char),"input sol name",
fprintf(stderr," Exit program.\n");
return 0);
strcat(sol->namein,".sol");
}
else {
MMG5_ADD_MEM(mesh,9*sizeof(char),"input sol name",
Expand Down Expand Up @@ -393,7 +401,12 @@ int MMG5_Set_outputSolName(MMG5_pMesh mesh,MMG5_pSol sol, const char* solout) {
}
else {
if ( mesh->nameout && strlen(mesh->nameout) ) {
ptr = strstr(mesh->nameout,".mesh");
/* Get last dot character to avoid issues with <basename>.mesh.mesh files */
char *dot = strrchr(mesh->nameout,'.');
ptr = NULL;
if ( dot) {
ptr = strstr(dot,".mesh");
}
if ( ptr ) {
MMG5_SAFE_CALLOC(sol->nameout,strlen(mesh->nameout)+1,char,return 0);
oldsize = strlen(mesh->nameout)+1;
Expand All @@ -403,16 +416,22 @@ int MMG5_Set_outputSolName(MMG5_pMesh mesh,MMG5_pSol sol, const char* solout) {
oldsize = strlen(mesh->nameout)+6;
}
strcpy(sol->nameout,mesh->nameout);
ptr = strstr(sol->nameout,".mesh");
dot = strrchr(sol->nameout,'.');
ptr = NULL;
if ( dot) {
ptr = strstr(dot,".mesh");
}
if ( ptr )
/* the sol file is renamed with the meshfile without extension */
/* the sol file is renamed with the meshfile basename and .sol ext */
*ptr = '\0';
strcat(sol->nameout,".sol");
MMG5_ADD_MEM(mesh,(strlen(sol->nameout)+1)*sizeof(char),"output sol name",

MMG5_ADD_MEM(mesh,(strlen(sol->nameout)+5)*sizeof(char),"output sol name",
fprintf(stderr," Exit program.\n");
return 0);
MMG5_SAFE_REALLOC(sol->nameout,oldsize,(strlen(sol->nameout)+1),char,
MMG5_SAFE_REALLOC(sol->nameout,oldsize,(strlen(sol->nameout)+5),char,
"output sol name",return 0);
strcat(sol->nameout,".sol");

}
else {
fprintf(stderr,"\n ## Error: %s: no name for output mesh. please, use",
Expand Down
8 changes: 7 additions & 1 deletion src/common/inout.c
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,13 @@ int MMG5_loadSolHeader( const char *filename,int meshDim,FILE **inm,int *ver,
MMG5_SAFE_CALLOC(data,strlen(filename)+6,char,return -1);
strcpy(data,filename);

ptr = strstr(data,".mesh");
/* Get last dot character to avoid issues with <basename>.mesh.mesh files */
char *dot = strrchr(data,'.');

ptr = NULL;
if ( dot) {
ptr = strstr(dot,".mesh");
}
if ( ptr ) *ptr = '\0';

ptr = strstr(data,".sol");
Expand Down

0 comments on commit 7d71f1b

Please sign in to comment.