Changeset 425444 for pcp/src/ions.c


Ignore:
Timestamp:
Aug 6, 2008, 8:35:50 AM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
e6372f
Parents:
7670cab
Message:

ParseIonForce(): Now also deals with force files containing only up to Total Forces fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pcp/src/ions.c

    r7670cab r425444  
    652652  double i1, j1;
    653653  double R[NDIM];
     654  char *ptr = NULL;
    654655 
    655656  if (P->Call.ForcesFile == NULL) return;
     
    658659        if (finput == NULL)
    659660                Error(InitReading, "ForcesFile does not exist.");
    660         fscanf(finput, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line,line);        // skip header line
     661  fgets(line, 1024, finput);  // skip header line
    661662  for (i=0; i < I->Max_Types; i++)
    662663    for (j=0; j < I->I[i].Max_IonsOfType; j++)
     
    664665                                Error(InitReading, "ForcesFile does not contain enough lines.");
    665666                        } else {
    666                                 //fscanf(finput, "%s\n", line);
    667                                 //if (strlen(line) < 100) {
    668                                         //fprintf(stderr, "i %d, j %d, length of line %ld, line %s.\n", i,j, strlen(line), line);
    669                                         //Error(InitReading, "ForcesFile does not contain enough lines or line is faulty.");
    670                                 //} else
     667                          fgets(line, 1024, finput);
     668                                ptr = line;
     669                                i1 = 1.;
     670                                while ((ptr = strchr(ptr, '\t')) != NULL) { // count number of tabs in line
     671                                  if (*ptr == '\t') ptr++;
     672                                  i1++;
     673                                  //fprintf(stderr,"%i tabs\n", (int)i1);
     674                                }
     675                                if (i1 < 8) {
     676                                        fprintf(stderr, "i %d, j %d, fields in %i, line %s.\n", i,j, (int)i1, line);
     677                                        Error(InitReading, "ForcesFile does not contain enough lines or line is faulty.");
     678                                } else {
    671679                                        //fprintf(stderr, "Parsed line: '%s'\n", line);
    672                 fscanf(finput, "%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\n", &i1,&j1,
     680                sscanf(line, "%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\t%le\n", &i1,&j1,
    673681                      &R[0], &R[1], &R[2],
    674682                      &I->I[i].FIon[0+j*NDIM], &I->I[i].FIon[1+j*NDIM], &I->I[i].FIon[2+j*NDIM],
     
    677685                &I->I[i].FMagnetic[0+j*NDIM], &I->I[i].FMagnetic[1+j*NDIM], &I->I[i].FMagnetic[2+j*NDIM],
    678686                      &I->I[i].FEwald[0+j*NDIM], &I->I[i].FEwald[1+j*NDIM], &I->I[i].FEwald[2+j*NDIM]);
    679                                 if ((i != (int)i1) || (j != (int)j1))
     687                                }
     688                                if ((i != (int)i1) || (j != (int)j1)) {
     689                                  fprintf(stderr, "(%i) expecting ion (%i, %i), parsed ion (%le, %le)!\n", P->Par.me, i, j, i1, j1);
    680690                                        Error(InitReading, "Line does not match to desired ion.");
     691                                }
    681692                }
    682693        fclose(finput);
Note: See TracChangeset for help on using the changeset viewer.