/[escript]/trunk/finley/src/Mesh_read.c
ViewVC logotype

Diff of /trunk/finley/src/Mesh_read.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1745 by ksteube, Wed Sep 3 00:41:24 2008 UTC revision 1754 by ksteube, Sun Sep 7 22:07:26 2008 UTC
# Line 791  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 791  Finley_Mesh* Finley_Mesh_read_MPI(char*
791        } /* end of Read the nodal element data */        } /* end of Read the nodal element data */
792    
793        /* get the name tags */        /* get the name tags */
794        if (Finley_noError() && ! feof(fileHandle_p)) {        if (Finley_noError()) {
795          char remainder[100000], *ptr;          char *remainder, *ptr;
796          int tag_key, len, error_code;          int tag_key, len, error_code;
797            long cur_pos, end_pos;
798          if (mpi_info->rank == 0) {  /* Master */          if (mpi_info->rank == 0) {  /* Master */
799        /* Read the word 'Tag' */        /* Read the word 'Tag' */
800            fscanf(fileHandle_p, "%s\n", name);        if (! feof(fileHandle_p)) fscanf(fileHandle_p, "%s\n", name);
801        /* Read rest of file in one chunk */        /* Read rest of file in one chunk, after using seek to find length */
802        strcpy(remainder, "");            cur_pos = ftell(fileHandle_p);
803        if (! feof(fileHandle_p)) fread(remainder, 100000, sizeof(char), fileHandle_p);            fseek(fileHandle_p, 0L, SEEK_END);
804            ptr = strrchr(remainder, '\n');            end_pos = ftell(fileHandle_p);
805            if (ptr != NULL) *ptr = '\0';            fseek(fileHandle_p, (long)cur_pos, SEEK_SET);
806          remainder = TMPMEMALLOC(end_pos-cur_pos+1, char);
807          if (! feof(fileHandle_p)) fread(remainder, (size_t) end_pos-cur_pos, sizeof(char), fileHandle_p);
808          remainder[end_pos-cur_pos] = 0;
809          len = strlen(remainder);    
810          while ((--len)>0 && isspace(remainder[len])) remainder[len]=0;
811          len = strlen(remainder);
812          }          }
     len = strlen(remainder);  
813  #ifdef PASO_MPI  #ifdef PASO_MPI
814          error_code = MPI_Bcast (&len, 1, MPI_INT,  0, mpi_info->comm);          error_code = MPI_Bcast (&len, 1, MPI_INT,  0, mpi_info->comm);
815          if (error_code != MPI_SUCCESS) {          if (error_code != MPI_SUCCESS) {
816            Finley_setError(PASO_MPI_ERROR, "Finley_Mesh_read: broadcast of tag len failed");            Finley_setError(PASO_MPI_ERROR, "Finley_Mesh_read: broadcast of tag len failed");
817            return NULL;            return NULL;
818          }          }
819        if (mpi_info->rank != 0) {
820          remainder = TMPMEMALLOC(len+1, char);
821          remainder[0] = 0;
822        }
823          error_code = MPI_Bcast (remainder, len+1, MPI_CHAR,  0, mpi_info->comm);          error_code = MPI_Bcast (remainder, len+1, MPI_CHAR,  0, mpi_info->comm);
824          if (error_code != MPI_SUCCESS) {          if (error_code != MPI_SUCCESS) {
825            Finley_setError(PASO_MPI_ERROR, "Finley_Mesh_read: broadcast of tags failed");            Finley_setError(PASO_MPI_ERROR, "Finley_Mesh_read: broadcast of tags failed");
826            return NULL;            return NULL;
827          }          }
828  #endif  #endif
829          ptr = remainder;      if (remainder[0]) {
830          do {            ptr = remainder;
831            sscanf(ptr, "%s %d\n", name, &tag_key);            do {
832            Finley_Mesh_addTagMap(mesh_p,name,tag_key);              sscanf(ptr, "%s %d\n", name, &tag_key);
833            ptr++;              if (*name) Finley_Mesh_addTagMap(mesh_p,name,tag_key);
834          } while(NULL != (ptr = strchr(ptr, '\n')));              ptr++;
835              } while(NULL != (ptr = strchr(ptr, '\n')) && *ptr);
836              TMPMEMFREE(remainder);
837        }
838        }        }
839    
840       }       }

Legend:
Removed from v.1745  
changed lines
  Added in v.1754

  ViewVC Help
Powered by ViewVC 1.1.26