/[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 1811 by ksteube, Thu Sep 25 23:11:13 2008 UTC revision 1876 by phornby, Mon Oct 13 10:19:17 2008 UTC
# Line 793  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 793  Finley_Mesh* Finley_Mesh_read_MPI(char*
793        /* get the name tags */        /* get the name tags */
794        if (Finley_noError()) {        if (Finley_noError()) {
795          char *remainder, *ptr;          char *remainder, *ptr;
796          int tag_key, len, error_code;          int tag_key, error_code;
797            size_t len;
798          long cur_pos, end_pos;          long cur_pos, end_pos;
799          if (mpi_info->rank == 0) {  /* Master */          if (mpi_info->rank == 0) {  /* Master */
800        /* Read the word 'Tag' */        /* Read the word 'Tag' */
801        if (! feof(fileHandle_p)) fscanf(fileHandle_p, "%s\n", name);        if (! feof(fileHandle_p)) fscanf(fileHandle_p, "%s\n", name);
802        /* Read rest of file in one chunk, after using seek to find length */        /* Read rest of file in one chunk, after using seek to find length */
803    
804    #if defined(_WIN32)  /* windows ftell lies on unix formatted text files */
805    
806          remainder = NULL;
807              len=0;
808          while (1)
809              {
810                 size_t MALLOC_CHUNK = 1024;
811                 size_t buff_size = 0;
812                 int ch;
813    
814                 ch = fgetc(fileHandle_p);
815                 if( ch == '\r' )
816                 {
817                    continue;
818                 }
819                 if( len+1 > buff_size )
820                 {
821                    TMPMEMREALLOC(remainder,remainder,buff_size+MALLOC_CHUNK,char);
822                 }
823                 if( ch == EOF )
824                 {
825                    /* hit EOF */
826                    remainder[len] = (char)0;
827                    break;
828                 }
829                 remainder[len] = (char)ch;
830                 len++;
831              }
832    #else
833            cur_pos = ftell(fileHandle_p);            cur_pos = ftell(fileHandle_p);
834            fseek(fileHandle_p, 0L, SEEK_END);            fseek(fileHandle_p, 0L, SEEK_END);
835            end_pos = ftell(fileHandle_p);            end_pos = ftell(fileHandle_p);
# Line 806  Finley_Mesh* Finley_Mesh_read_MPI(char* Line 837  Finley_Mesh* Finley_Mesh_read_MPI(char*
837        remainder = TMPMEMALLOC(end_pos-cur_pos+1, char);        remainder = TMPMEMALLOC(end_pos-cur_pos+1, char);
838        if (! feof(fileHandle_p)) fread(remainder, (size_t) end_pos-cur_pos, sizeof(char), fileHandle_p);        if (! feof(fileHandle_p)) fread(remainder, (size_t) end_pos-cur_pos, sizeof(char), fileHandle_p);
839        remainder[end_pos-cur_pos] = 0;        remainder[end_pos-cur_pos] = 0;
840        len = strlen(remainder);      #endif
841          len = strlen(remainder);
842        while ((--len)>0 && isspace(remainder[len])) remainder[len]=0;        while ((--len)>0 && isspace(remainder[len])) remainder[len]=0;
843        len = strlen(remainder);        len = strlen(remainder);
844              TMPMEMREALLOC(remainder,remainder,len+1,char);
845          }          }
846  #ifdef PASO_MPI  #ifdef PASO_MPI
847          error_code = MPI_Bcast (&len, 1, MPI_INT,  0, mpi_info->comm);          error_code = MPI_Bcast (&len, 1, MPI_INT,  0, mpi_info->comm);

Legend:
Removed from v.1811  
changed lines
  Added in v.1876

  ViewVC Help
Powered by ViewVC 1.1.26