/[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 1907 by phornby, Wed Oct 22 11:41:18 2008 UTC revision 1919 by phornby, Thu Oct 23 10:03:10 2008 UTC
# Line 275  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 275  Finley_Mesh* Finley_Mesh_read_MPI(char*
275    char error_msg[LenErrorMsg_MAX];    char error_msg[LenErrorMsg_MAX];
276    double time0=Finley_timer();    double time0=Finley_timer();
277    FILE *fileHandle_p = NULL;    FILE *fileHandle_p = NULL;
278    ElementTypeId typeID, faceTypeID, contactTypeID, pointTypeID;    ElementTypeId typeID;
   Finley_TagMap* tag_map;  
   index_t tag_key;  
279    int scan_ret;    int scan_ret;
280    
281    Finley_resetError();    Finley_resetError();
# Line 856  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 854  Finley_Mesh* Finley_Mesh_read_MPI(char*
854        /* get the name tags */        /* get the name tags */
855        if (Finley_noError()) {        if (Finley_noError()) {
856          char *remainder, *ptr;          char *remainder, *ptr;
         int tag_key, error_code;  
857          size_t len;          size_t len;
858          long cur_pos, end_pos;          int tag_key;
859    
860    
861    
862          if (mpi_info->rank == 0) {  /* Master */          if (mpi_info->rank == 0) {  /* Master */
863        /* Read the word 'Tag' */        /* Read the word 'Tag' */
864        if (! feof(fileHandle_p)) {        if (! feof(fileHandle_p)) {
865          scan_ret = fscanf(fileHandle_p, "%s\n", name);          scan_ret = fscanf(fileHandle_p, "%s\n", name);
866          FSCANF_CHECK(scan_ret, "Finley_Mesh_read")          FSCANF_CHECK(scan_ret, "Finley_Mesh_read")
867        }        }
       /* Read rest of file in one chunk, after using seek to find length */  
868    
869  #if defined(_WIN32)  /* windows ftell lies on unix formatted text files */  #if defined(_WIN32)  /* windows ftell lies on unix formatted text files */
870    
# Line 896  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 895  Finley_Mesh* Finley_Mesh_read_MPI(char*
895               len++;               len++;
896            }            }
897  #else  #else
898            cur_pos = ftell(fileHandle_p);        /* Read rest of file in one chunk, after using seek to find length */
899            fseek(fileHandle_p, 0L, SEEK_END);            {
900            end_pos = ftell(fileHandle_p);               long cur_pos, end_pos;
901            fseek(fileHandle_p, (long)cur_pos, SEEK_SET);  
902        remainder = TMPMEMALLOC(end_pos-cur_pos+1, char);               cur_pos = ftell(fileHandle_p);
903        if (! feof(fileHandle_p)) {               fseek(fileHandle_p, 0L, SEEK_END);
904          scan_ret = fread(remainder, (size_t) end_pos-cur_pos, sizeof(char), fileHandle_p);               end_pos = ftell(fileHandle_p);
905              FSCANF_CHECK(scan_ret, "Finley_Mesh_read")               fseek(fileHandle_p, (long)cur_pos, SEEK_SET);
906        }               remainder = TMPMEMALLOC(end_pos-cur_pos+1, char);
907        remainder[end_pos-cur_pos] = 0;               if (! feof(fileHandle_p))
908                 {
909                    scan_ret = fread(remainder, (size_t) end_pos-cur_pos,
910                                     sizeof(char), fileHandle_p);
911    
912                    FSCANF_CHECK(scan_ret, "Finley_Mesh_read")
913                    remainder[end_pos-cur_pos] = 0;
914                }
915              }
916  #endif  #endif
917        len = strlen(remainder);        len = strlen(remainder);
918        while ((--len)>0 && isspace(remainder[len])) remainder[len]=0;        while ((--len)>0 && isspace(remainder[len])) remainder[len]=0;
# Line 913  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 920  Finley_Mesh* Finley_Mesh_read_MPI(char*
920            TMPMEMREALLOC(remainder,remainder,len+1,char);            TMPMEMREALLOC(remainder,remainder,len+1,char);
921          }          }
922  #ifdef PASO_MPI  #ifdef PASO_MPI
923          error_code = MPI_Bcast (&len, 1, MPI_INT,  0, mpi_info->comm);  
924          if (error_code != MPI_SUCCESS) {          if (MPI_Bcast (&len, 1, MPI_INT,  0, mpi_info->comm) != MPI_SUCCESS)
925            Finley_setError(PASO_MPI_ERROR, "Finley_Mesh_read: broadcast of tag len failed");          {
926            return NULL;             Finley_setError(PASO_MPI_ERROR,
927                               "Finley_Mesh_read: broadcast of tag len failed");
928               return NULL;
929          }          }
930      if (mpi_info->rank != 0) {      if (mpi_info->rank != 0) {
931        remainder = TMPMEMALLOC(len+1, char);        remainder = TMPMEMALLOC(len+1, char);
932        remainder[0] = 0;        remainder[0] = 0;
933      }      }
934          error_code = MPI_Bcast (remainder, len+1, MPI_CHAR,  0, mpi_info->comm);  
935          if (error_code != MPI_SUCCESS) {          if (MPI_Bcast (remainder, len+1, MPI_CHAR,  0, mpi_info->comm) !=
936            Finley_setError(PASO_MPI_ERROR, "Finley_Mesh_read: broadcast of tags failed");              MPI_SUCCESS)
937            return NULL;          {
938               Finley_setError(PASO_MPI_ERROR,
939                               "Finley_Mesh_read: broadcast of tags failed");
940               return NULL;
941          }          }
942  #endif  #endif
943      if (remainder[0]) {      if (remainder[0]) {

Legend:
Removed from v.1907  
changed lines
  Added in v.1919

  ViewVC Help
Powered by ViewVC 1.1.26