Changeset 18d065


Ignore:
Timestamp:
Apr 21, 2008, 7:47:06 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
da4244
Parents:
4d4fc1
Message:

ReadSrcIons(): suffix is used

Using suffix char array (malloc'd and free'd) instead of define directly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pcp/src/output.c

    r4d4fc1 r18d065  
    13011301  int is,ia,i;
    13021302  FILE *SrcIonDoc, *SrcIonData;
     1303  char suffix[255];
    13031304
    13041305  if (!(P->Par.me == 0)) return;
    13051306 
    13061307  // output of ion types and numbers per type
    1307   OpenFile(P, &SrcIonDoc, suffixsrciondoc, "w",P->Call.out[ReadOut]);
     1308  sprintf(suffix, ".L%i%s", P->Lat.Lev[STANDARTLEVEL].LevelNo, suffixsrciondoc);
     1309  OpenFile(P, &SrcIonDoc, suffix, "w",P->Call.out[ReadOut]);
    13081310  fprintf(SrcIonDoc,"%i\n", I->Max_Types);
    13091311  for (is=0; is < I->Max_Types; is++)
     
    13111313  fclose(SrcIonDoc);
    13121314
    1313   OpenFile(P, &SrcIonData, suffixsrciondat, "wb",P->Call.out[ReadOut]);
     1315  sprintf(suffix, ".L%i%s", P->Lat.Lev[STANDARTLEVEL].LevelNo, suffixsrciondat);
     1316  OpenFile(P, &SrcIonData, suffix, "wb",P->Call.out[ReadOut]);
    13141317  (void)fwrite(P->Lat.RealBasis, sizeof(double), (size_t)(NDIM_NDIM), SrcIonData);
    13151318  for (is=0; is < I->Max_Types; is++) {
     
    13461349  double RealBasis[NDIM_NDIM];
    13471350  FILE *SrcIonDoc, *SrcIonData;
     1351  char *suffix;
    13481352  // read the doc file and check
    1349   if (OpenFile(P, &SrcIonDoc, suffixsrciondoc, "r",P->Call.out[ReadOut])) {
    1350     if (fscanf(SrcIonDoc,"%i", &Max_Types) != 1)
     1353  suffix = (char *)
     1354    Malloc(strlen(suffixsrciondoc) + 3 + 1,"ReadSrcIons: suffix");
     1355  sprintf(suffix, ".L%i%s", P->Lat.Lev[STANDARTLEVEL].LevelNo, suffixsrciondoc);
     1356  if (OpenFile(P, &SrcIonDoc, suffix, "r",P->Call.out[ReadOut])) {
     1357    if (fscanf(SrcIonDoc,"%i", &Max_Types) != 1) {
    13511358      //Error(SomeError, "ReadSrcIons: read error");
     1359      Free(suffix, "ReadSrcIons: suffix");
    13521360      return 0;
    1353     if (Max_Types != I->Max_Types)
     1361    }
     1362    if (Max_Types != I->Max_Types) {
    13541363      //Error(SomeError, "ReadSrcIons: srcion file does not fit to system, MaxTypes");
     1364      Free(suffix, "ReadSrcIons: suffix");
    13551365      return 0;
     1366    }
    13561367    Max_IonsOfType = (int *) Malloc(Max_Types*sizeof(int), "ReadSrcIons: Max_IonsOfType");
    13571368    for (is=0; is < Max_Types; is++) {
    1358       if (fscanf(SrcIonDoc,"%i", &Max_IonsOfType[is]) != 1)
     1369      if (fscanf(SrcIonDoc,"%i", &Max_IonsOfType[is]) != 1) {
    13591370        //Error(SomeError, "ReadSrcIons: read error");
    1360       return 0;
    1361       if (Max_IonsOfType[is] != I->I[is].Max_IonsOfType)
     1371        Free(suffix, "ReadSrcIons: suffix");
     1372          return 0;
     1373      }
     1374      if (Max_IonsOfType[is] != I->I[is].Max_IonsOfType) {
    13621375        //Error(SomeError, "ReadSrcIons: srcion file does not fit to system, Max_IonsOfType");
    1363       return 0;
     1376        Free(suffix, "ReadSrcIons: suffix");
     1377            return 0;
     1378            }
    13641379    }
    13651380    fclose(SrcIonDoc);
    13661381    // read basis, then positions and speeds of ions
    13671382    if (OpenFile(P, &SrcIonData, suffixsrciondat, "rb",P->Call.out[ReadOut])) {
    1368       if (fread(RealBasis, sizeof(double), (size_t)(NDIM_NDIM), SrcIonData) != NDIM_NDIM)
     1383      if (fread(RealBasis, sizeof(double), (size_t)(NDIM_NDIM), SrcIonData) != NDIM_NDIM) {
    13691384        //Error(SomeError, "ReadSrcIons: read error");
     1385        Free(suffix, "ReadSrcIons: suffix");
    13701386        return 0;
     1387      }
    13711388      for (i=0; i < NDIM_NDIM; i++)
    1372         if (RealBasis[i] != P->Lat.RealBasis[i])
     1389        if (RealBasis[i] != P->Lat.RealBasis[i]) {
    13731390          //Error(SomeError, "ReadSrcIons: srcion file does not fit to system, RealBasis");
     1391                Free(suffix, "ReadSrcIons: suffix");
    13741392          return 0;
     1393        }
    13751394      for (is=0; is < I->Max_Types; is++) {
    13761395        for (ia=0; ia < I->I[is].Max_IonsOfType; ia++) {
    1377           if (fread(&data, sizeof(double), (size_t)(2*NDIM), SrcIonData) != 2*NDIM)
     1396          if (fread(&data, sizeof(double), (size_t)(2*NDIM), SrcIonData) != 2*NDIM) {
    13781397                //Error(SomeError, "ReadSrcIons: read error");
     1398                        Free(suffix, "ReadSrcIons: suffix");
    13791399            return 0;
     1400          }
    13801401          U = &I->I[is].U[NDIM*ia];
    13811402          pos = &I->I[is].R[NDIM*ia];
     
    13901411    if (Max_IonsOfType != NULL) Free(Max_IonsOfType, "Max_IonsOfType");
    13911412  }
     1413    Free(suffix, "ReadSrcIons: suffix");
    13921414  return 1;
    13931415}
Note: See TracChangeset for help on using the changeset viewer.