/[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 2052 by phornby, Mon Nov 17 11:15:07 2008 UTC
# Line 37  Finley_Mesh* Finley_Mesh_read(char* fnam Line 37  Finley_Mesh* Finley_Mesh_read(char* fnam
37    Finley_Mesh *mesh_p=NULL;    Finley_Mesh *mesh_p=NULL;
38    char name[LenString_MAX],element_type[LenString_MAX],frm[20];    char name[LenString_MAX],element_type[LenString_MAX],frm[20];
39    char error_msg[LenErrorMsg_MAX];    char error_msg[LenErrorMsg_MAX];
40      #ifdef Finley_TRACE
41    double time0=Finley_timer();    double time0=Finley_timer();
42      #endif
43    FILE *fileHandle_p = NULL;    FILE *fileHandle_p = NULL;
44    ElementTypeId typeID, faceTypeID, contactTypeID, pointTypeID;    ElementTypeId typeID=0, faceTypeID, contactTypeID, pointTypeID;
45    int scan_ret;    int scan_ret;
46        
47    Finley_resetError();    Finley_resetError();
# Line 273  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 275  Finley_Mesh* Finley_Mesh_read_MPI(char*
275    Finley_Mesh *mesh_p=NULL;    Finley_Mesh *mesh_p=NULL;
276    char name[LenString_MAX],element_type[LenString_MAX],frm[20];    char name[LenString_MAX],element_type[LenString_MAX],frm[20];
277    char error_msg[LenErrorMsg_MAX];    char error_msg[LenErrorMsg_MAX];
278      #ifdef Finley_TRACE
279    double time0=Finley_timer();    double time0=Finley_timer();
280      #endif
281    FILE *fileHandle_p = NULL;    FILE *fileHandle_p = NULL;
282    ElementTypeId typeID, faceTypeID, contactTypeID, pointTypeID;    ElementTypeId typeID=0;
   Finley_TagMap* tag_map;  
   index_t tag_key;  
283    int scan_ret;    int scan_ret;
284    
285    Finley_resetError();    Finley_resetError();
# Line 855  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 857  Finley_Mesh* Finley_Mesh_read_MPI(char*
857    
858        /* get the name tags */        /* get the name tags */
859        if (Finley_noError()) {        if (Finley_noError()) {
860          char *remainder, *ptr;          char *remainder=0, *ptr;
         int tag_key, error_code;  
861          size_t len;          size_t len;
862          long cur_pos, end_pos;          int tag_key;
863    
864    
865    
866          if (mpi_info->rank == 0) {  /* Master */          if (mpi_info->rank == 0) {  /* Master */
867        /* Read the word 'Tag' */        /* Read the word 'Tag' */
868        if (! feof(fileHandle_p)) {        if (! feof(fileHandle_p)) {
869          scan_ret = fscanf(fileHandle_p, "%s\n", name);          scan_ret = fscanf(fileHandle_p, "%s\n", name);
870          FSCANF_CHECK(scan_ret, "Finley_Mesh_read")          FSCANF_CHECK(scan_ret, "Finley_Mesh_read")
871        }        }
       /* Read rest of file in one chunk, after using seek to find length */  
872    
873  #if defined(_WIN32)  /* windows ftell lies on unix formatted text files */  #if defined(_WIN32)  /* windows ftell lies on unix formatted text files */
874    
# Line 873  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 876  Finley_Mesh* Finley_Mesh_read_MPI(char*
876            len=0;            len=0;
877        while (1)        while (1)
878            {            {
879               size_t MALLOC_CHUNK = 1024;               size_t malloc_chunk = 1024;
880               size_t buff_size = 0;               size_t buff_size = 0;
881               int ch;               int ch;
882    
# Line 884  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 887  Finley_Mesh* Finley_Mesh_read_MPI(char*
887               }               }
888               if( len+1 > buff_size )               if( len+1 > buff_size )
889               {               {
890                  TMPMEMREALLOC(remainder,remainder,buff_size+MALLOC_CHUNK,char);                  TMPMEMREALLOC(remainder,remainder,buff_size+malloc_chunk,char);
891               }               }
892               if( ch == EOF )               if( ch == EOF )
893               {               {
# Line 896  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 899  Finley_Mesh* Finley_Mesh_read_MPI(char*
899               len++;               len++;
900            }            }
901  #else  #else
902            cur_pos = ftell(fileHandle_p);        /* Read rest of file in one chunk, after using seek to find length */
903            fseek(fileHandle_p, 0L, SEEK_END);            {
904            end_pos = ftell(fileHandle_p);               long cur_pos, end_pos;
905            fseek(fileHandle_p, (long)cur_pos, SEEK_SET);  
906        remainder = TMPMEMALLOC(end_pos-cur_pos+1, char);               cur_pos = ftell(fileHandle_p);
907        if (! feof(fileHandle_p)) {               fseek(fileHandle_p, 0L, SEEK_END);
908          scan_ret = fread(remainder, (size_t) end_pos-cur_pos, sizeof(char), fileHandle_p);               end_pos = ftell(fileHandle_p);
909              FSCANF_CHECK(scan_ret, "Finley_Mesh_read")               fseek(fileHandle_p, (long)cur_pos, SEEK_SET);
910        }               remainder = TMPMEMALLOC(end_pos-cur_pos+1, char);
911        remainder[end_pos-cur_pos] = 0;               if (! feof(fileHandle_p))
912                 {
913                    scan_ret = fread(remainder, (size_t) end_pos-cur_pos,
914                                     sizeof(char), fileHandle_p);
915    
916                    FSCANF_CHECK(scan_ret, "Finley_Mesh_read")
917                    remainder[end_pos-cur_pos] = 0;
918                }
919              }
920  #endif  #endif
921        len = strlen(remainder);        len = strlen(remainder);
922        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 924  Finley_Mesh* Finley_Mesh_read_MPI(char*
924            TMPMEMREALLOC(remainder,remainder,len+1,char);            TMPMEMREALLOC(remainder,remainder,len+1,char);
925          }          }
926  #ifdef PASO_MPI  #ifdef PASO_MPI
927          error_code = MPI_Bcast (&len, 1, MPI_INT,  0, mpi_info->comm);  
928          if (error_code != MPI_SUCCESS) {          if (MPI_Bcast (&len, 1, MPI_INT,  0, mpi_info->comm) != MPI_SUCCESS)
929            Finley_setError(PASO_MPI_ERROR, "Finley_Mesh_read: broadcast of tag len failed");          {
930            return NULL;             Finley_setError(PASO_MPI_ERROR,
931                               "Finley_Mesh_read: broadcast of tag len failed");
932               return NULL;
933          }          }
934      if (mpi_info->rank != 0) {      if (mpi_info->rank != 0) {
935        remainder = TMPMEMALLOC(len+1, char);        remainder = TMPMEMALLOC(len+1, char);
936        remainder[0] = 0;        remainder[0] = 0;
937      }      }
938          error_code = MPI_Bcast (remainder, len+1, MPI_CHAR,  0, mpi_info->comm);  
939          if (error_code != MPI_SUCCESS) {          if (MPI_Bcast (remainder, len+1, MPI_CHAR,  0, mpi_info->comm) !=
940            Finley_setError(PASO_MPI_ERROR, "Finley_Mesh_read: broadcast of tags failed");              MPI_SUCCESS)
941            return NULL;          {
942               Finley_setError(PASO_MPI_ERROR,
943                               "Finley_Mesh_read: broadcast of tags failed");
944               return NULL;
945          }          }
946  #endif  #endif
947      if (remainder[0]) {      if (remainder[0]) {

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

  ViewVC Help
Powered by ViewVC 1.1.26