Changeset fafb43


Ignore:
Timestamp:
Feb 6, 2009, 9:48:35 AM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
4aef8a
Parents:
d3d15c
Message:

Purely cosmetical changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • util/src/NanoCreator.c

    rd3d15c rfafb43  
    2525 * \return pointer to allocated memory
    2626 */
    27 void * Malloc (size_t size, const char *msg) 
     27void * Malloc (size_t size, const char *msg)
    2828{
    2929  void *ptr = malloc(size);
     
    4545 * \return pointer to allocated memory
    4646 */
    47 void * Calloc (size_t size, double value, const char *msg) 
     47void * Calloc (size_t size, double value, const char *msg)
    4848{
    4949  void *ptr = calloc(size, value);
     
    7676
    7777/** Allocs memory and prints a message on fail.
    78  * \param **old_ptr pointer to old memory range 
     78 * \param **old_ptr pointer to old memory range
    7979 * \param *newsize new size of alloc in bytes
    8080 * \param *msg error msg
    8181 * \return pointer to allocated memory
    8282 */
    83 void * Realloc (void *old_ptr, size_t newsize, const char *msg) 
     83void * Realloc (void *old_ptr, size_t newsize, const char *msg)
    8484{
    8585  if (old_ptr == NULL) {
     
    104104 * \return pointer to allocated segment with contents
    105105 */
    106 char * ReadBuffer (char *filename, int *bufferlength) 
     106char * ReadBuffer (char *filename, int *bufferlength)
    107107{
    108108  if ((filename == NULL) || (bufferlength == NULL)) {
     
    160160 * \param atomicnumber number of atoms in cell
    161161 */
    162 void AddAtomicNumber(char *filename, int atomicnumber, double **Vector, double **Recivector) 
     162void AddAtomicNumber(char *filename, int atomicnumber, double **Vector, double **Recivector)
    163163{
    164164  if ((filename == NULL) || (Vector == NULL) || (Recivector == NULL)) {
     
    175175  double volume = Determinant(Vector);
    176176  time_t now;
    177  
     177
    178178  now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
    179179  // open for writing and prepend
     
    204204 * \param *factors pointer to array with length and radius factor
    205205 * \param seed random number seed
    206  * \param numbercell number of atoms in unit cell, needed as length of \a *randomness 
     206 * \param numbercell number of atoms in unit cell, needed as length of \a *randomness
    207207 * \param *randomness for each atom in unit cell a factor between 0..1, giving its probability of appearance
    208208 */
     
    254254  }
    255255  int i,j;
    256  
     256
    257257  for (i=0;i<NDIM;i++)
    258258    for (j=0;j<NDIM;j++)
    259259      returnvector[j] += matrixref[i][j] * vectorref[i];
    260      
    261   return returnvector; 
     260
     261  return returnvector;
    262262}
    263263double *MatrixTrafoInverse(double *vectorref, double **matrixref)
     
    274274  }
    275275  int i,j;
    276  
     276
    277277  for (i=0;i<NDIM;i++)
    278278    for (j=0;j<NDIM;j++)
    279279      returnvector[i] += matrixref[i][j] * vectorref[j];
    280      
    281   return returnvector; 
     280
     281  return returnvector;
    282282}
    283283
     
    286286 * \param **inverse allocated space for inverse of \a **matrix
    287287 */
    288 void MatrixInversion(double **matrix, double **inverse) 
     288void MatrixInversion(double **matrix, double **inverse)
    289289{
    290290  if ((matrix == NULL) || (inverse == NULL)) {
     
    294294  // determine inverse
    295295  double det = Determinant(matrix);
    296   inverse[0][0] = (matrix[1][1]*matrix[2][2] - matrix[1][2]*matrix[2][1])/det; 
    297   inverse[1][0] = (matrix[0][2]*matrix[2][1] - matrix[0][1]*matrix[2][2])/det; 
    298   inverse[2][0] = (matrix[0][1]*matrix[1][2] - matrix[0][2]*matrix[1][1])/det; 
    299   inverse[0][1] = (matrix[1][2]*matrix[2][0] - matrix[1][0]*matrix[2][2])/det; 
    300   inverse[1][1] = (matrix[0][0]*matrix[2][2] - matrix[0][2]*matrix[2][0])/det; 
    301   inverse[2][1] = (matrix[0][2]*matrix[1][0] - matrix[0][0]*matrix[1][2])/det; 
    302   inverse[0][2] = (matrix[1][0]*matrix[2][1] - matrix[1][1]*matrix[2][0])/det; 
    303   inverse[1][2] = (matrix[0][1]*matrix[2][0] - matrix[0][0]*matrix[2][1])/det; 
     296  inverse[0][0] = (matrix[1][1]*matrix[2][2] - matrix[1][2]*matrix[2][1])/det;
     297  inverse[1][0] = (matrix[0][2]*matrix[2][1] - matrix[0][1]*matrix[2][2])/det;
     298  inverse[2][0] = (matrix[0][1]*matrix[1][2] - matrix[0][2]*matrix[1][1])/det;
     299  inverse[0][1] = (matrix[1][2]*matrix[2][0] - matrix[1][0]*matrix[2][2])/det;
     300  inverse[1][1] = (matrix[0][0]*matrix[2][2] - matrix[0][2]*matrix[2][0])/det;
     301  inverse[2][1] = (matrix[0][2]*matrix[1][0] - matrix[0][0]*matrix[1][2])/det;
     302  inverse[0][2] = (matrix[1][0]*matrix[2][1] - matrix[1][1]*matrix[2][0])/det;
     303  inverse[1][2] = (matrix[0][1]*matrix[2][0] - matrix[0][0]*matrix[2][1])/det;
    304304  inverse[2][2] = (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0])/det;
    305    
     305
    306306  // check inverse
    307   int flag = 0; 
     307  int flag = 0;
    308308  int i,j,k;
    309   double tmp;   
     309  double tmp;
    310310  fprintf(stdout, "Checking inverse ... ");
    311311  for (i=0;i<NDIM;i++)
     
    319319        } else {
    320320          flag = (fabs(tmp) > MYEPSILON) ? 1 : 0;
    321         }       
     321        }
    322322      }
    323323    }
     
    357357      flip(&matrix[i][j],&matrix[j][i]);
    358358}
    359  
     359
    360360
    361361/** Computes the determinant of a NDIMxNDIM matrix.
     
    370370  double det =   matrix[0][0] * (matrix[1][1]*matrix[2][2] - matrix[1][2]*matrix[2][1])
    371371               - matrix[1][1] * (matrix[0][0]*matrix[2][2] - matrix[0][2]*matrix[2][0])
    372                + matrix[2][2] * (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]); 
     372               + matrix[2][2] * (matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0]);
    373373  return det;
    374374}
     
    392392  }
    393393  int i;
    394  
     394
    395395  for (i=0;i<NDIM;i++)
    396396    returnvector[i] = vector1[i] + vector2[i];
    397    
     397
    398398  return returnvector;
    399399}
     
    412412  double betrag;
    413413  int i;
    414  
     414
    415415  // first vector is untouched
    416416  // second vector
    417   betrag = Projection(orthvector[axis[1]], orthvector[axis[0]]); 
     417  betrag = Projection(orthvector[axis[1]], orthvector[axis[0]]);
    418418  fprintf(stdout,"%lg\t",betrag);
    419419  for (i=0;i<NDIM;i++)
    420420     orthvector[axis[1]][i] -= orthvector[axis[0]][i] * betrag;
    421421  // third vector
    422   betrag = Projection(orthvector[axis[0]], orthvector[axis[2]]); 
     422  betrag = Projection(orthvector[axis[0]], orthvector[axis[2]]);
    423423  fprintf(stdout,"%lg\t",betrag);
    424424  for (i=0;i<NDIM;i++)
    425425     orthvector[axis[2]][i] -= orthvector[axis[0]][i] * betrag;
    426   betrag = Projection(orthvector[axis[1]], orthvector[axis[2]]); 
     426  betrag = Projection(orthvector[axis[1]], orthvector[axis[2]]);
    427427  fprintf(stdout,"%lg\n",betrag);
    428428  for (i=0;i<NDIM;i++)
     
    433433 * \param *vector1 reference vector
    434434 * \param *vector2 vector which is projected
    435  * \return projection 
     435 * \return projection
    436436 */
    437437double Projection(double *vector1, double *vector2)
     
    457457  double scp = 0.;
    458458  int i;
    459  
     459
    460460  for (i=0;i<NDIM;i++)
    461461    scp += vector1[i] * vector2[i];
    462    
     462
    463463  return scp;
    464464}
     
    468468 * \return norm of \a *vector
    469469 */
    470 double Norm(double *vector) 
     470double Norm(double *vector)
    471471{
    472472  if (vector == NULL) {
     
    540540  double diameter[2] = {0.,0.};
    541541  int i, biggest;
    542  
     542
    543543  for (i=0;i<NDIM;i++) {
    544544    diameter[0] += (matrix[axis[0]][i]*factors[0] - matrix[axis[1]][i]*factors[1]) * (matrix[axis[0]][i]*factors[0] - matrix[axis[1]][i]*factors[1]);
     
    555555
    556556  return diameter[biggest];
    557 } 
     557}
    558558
    559559/** Determines the center of gravity of atoms in a buffer \a bufptr with given \a number
     
    576576  char name[255], line[255];
    577577  int i,j;
    578  
     578
    579579  // Determine center of gravity
    580580  for (i=0;i<number;i++) {
     
    587587  for (i=0;i<NDIM;i++)
    588588    cog[i] /= -number;
    589    
     589
    590590  Free(atom, "CenterOfGravity: atom");
    591591  return cog;
     
    605605  for (i=0; i<NDIM; i++)
    606606    TempVectors[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: TempVectors");
    607  
     607
    608608  for (i=0; i<NDIM; i++)
    609609    for (j=0; j<NDIM; j++)
     
    618618  for (i=0; i<NDIM; i++)
    619619    OrthoVector[axis[0]][i] = TempVectors[TempAxis[2]][i]*factor;
    620  
     620
    621621  TempAxis[1] = axis[1];
    622622  TempAxis[2] = axis[0];
     
    629629  for (i=0; i<NDIM; i++)
    630630    OrthoVector[axis[1]][i] = TempVectors[TempAxis[2]][i]*factor;
    631  
     631
    632632  for (i=0; i<NDIM; i++)
    633633    OrthoVector[axis[2]][i] = Vector[axis[2]][i];
     
    635635  fprintf(stdout, "Orthogonal vectors are: \n");
    636636  for (i=0; i<NDIM; i++) {
    637     for (j=0; j<NDIM; j++) 
     637    for (j=0; j<NDIM; j++)
    638638      fprintf(stdout, "%lg\t", OrthoVector[axis[i]][j]);
    639639    fprintf(stdout, "\n");
    640640  }
    641  
     641
    642642  // free memory
    643643  Free(TempAxis, "CreateOrthogonalAxisVectors: *TempAxis");
     
    664664// --------------------------------------- M A I N ---------------------------------------------------
    665665int main(int argc, char **argv) {
    666         char *filename = NULL; 
     666        char *filename = NULL;
    667667  char *CellFilename = NULL, *SheetFilename = NULL, *TubeFilename = NULL, *TorusFilename = NULL;
    668668  char *SheetFilenameAligned = NULL, *TubeFilenameAligned = NULL;
     
    678678  int i,j, ggT;
    679679  int length;
    680  
    681         // Read command line arguments 
     680
     681        // Read command line arguments
    682682        if (argc <= 2) {
    683683                fprintf(stdout, "Usage: %s <file> <stage>\n\tWhere <file> specifies a file to start from <stage> or a basename\n\t<stage> is either None, Cell, Sheet, Tube, Torus and specifies where to start the rolling up from.\n\tNote: The .Aligned. files can't be used (rotation is essential).\n", argv[0]);
     
    688688                strncpy(stage, argv[2], 5);
    689689    fprintf(stdout, "I will begin at stage %s.\n", stage);
    690                
     690
    691691                // build filenames
    692692    char *ptr = strrchr(filename, '.');
    693693    length = strlen(filename);
    694694    if (ptr != NULL) {
    695       length = ((int)(ptr-filename) >= length-5) ? (int)(ptr-filename) : length; 
     695      length = ((int)(ptr-filename) >= length-5) ? (int)(ptr-filename) : length;
    696696      filename[length] = '\0'; // eventueller
    697697    }
     
    710710    sprintf(TubeFilenameAligned, "%s.Tube.Aligned.xyz", filename);
    711711        }
    712        
     712
    713713  // Allocating memory
    714714  Debug ("Allocating memory\n");
     
    726726    TubevectorInverse[i] = (double *) Malloc(sizeof(double)*NDIM, "Main: TubevectorInverse");
    727727  }
    728  
     728
    729729  // ======================== STAGE: Cell ==============================
    730730  // The cell is simply created by transforming relative coordinates within the cell
    731731  // into cartesian ones using the unit cell vectors.
    732    
     732
    733733  double volume;
    734734  int numbercell;
     
    740740        fprintf(stdout, "You will give the unit cell of the given substance.\nAfterwards, the programme will create a Sheet, a Tube and a Torus, each with their own xyz-file named accordingly.\n\n");
    741741    fprintf(stdout, "Enter 1st primitive vector: ");
    742     fscanf(stdin, "%lg %lg %lg", &Vector[0][0], &Vector[0][1], &Vector[0][2]); 
     742    fscanf(stdin, "%lg %lg %lg", &Vector[0][0], &Vector[0][1], &Vector[0][2]);
    743743    fprintf(stdout, "Enter 2nd primitive vector: ");
    744     fscanf(stdin, "%lg %lg %lg", &Vector[1][0], &Vector[1][1], &Vector[1][2]); 
     744    fscanf(stdin, "%lg %lg %lg", &Vector[1][0], &Vector[1][1], &Vector[1][2]);
    745745    fprintf(stdout, "Enter 3rd primitive vector: ");
    746746    fscanf(stdin, "%lg %lg %lg", &Vector[2][0], &Vector[2][1], &Vector[2][2]);
    747747    fprintf(stdout,"Unit vectors are\n");
    748     PrintMatrix(stdout, Vector); 
     748    PrintMatrix(stdout, Vector);
    749749        } else {
    750750    char *ptr = NULL;
     
    762762      ptr += strlen(dummy);
    763763      sscanf(ptr, "%lg %lg %lg", &Vector[i][0], &Vector[i][1], &Vector[i][2]);
    764       fprintf(stdout, "%5.5lg %5.5lg %5.5lg\n", Vector[i][0], Vector[i][1], Vector[i][2]); 
     764      fprintf(stdout, "%5.5lg %5.5lg %5.5lg\n", Vector[i][0], Vector[i][1], Vector[i][2]);
    765765    }
    766766        }
     
    768768  volume = Determinant(Vector);
    769769  fprintf(stdout,"Volume is %lg\n", volume);
    770   MatrixInversion(Vector, Recivector); 
     770  MatrixInversion(Vector, Recivector);
    771771  //Transpose(Recivector);   // inverse's got row vectors if normal matrix' got column ones
    772772  fprintf(stdout, "Reciprocal vector is ");
    773773  PrintMatrix(stdout, Recivector);
    774774  fprintf(stdout, "Reciprocal volume is %lg\n", Determinant(Recivector));
    775  
     775
    776776  fprintf(stdout, "Vector magnitudes: %5.5lg %5.5lg %5.5lg\n", Norm(Vector[0]), Norm(Vector[1]), Norm(Vector[2]));
    777    
     777
    778778  Debug ("STAGE: Cell\n");
    779779  if (!strncmp(stage, "Non", 3)) {
     
    793793      fprintf(stdout, "Atom %i: %s %5.5lg %5.5lg %5.5lg\n", i, name, tempvector[0], tempvector[1], tempvector[2]);
    794794      fprintf(stdout, "Probe: %s %5.5lg %5.5lg %5.5lg\n", name,
    795         atom[0]*Vector[0][0]+atom[1]*Vector[1][0]+atom[2]*Vector[2][0],     
    796         atom[0]*Vector[0][1]+atom[1]*Vector[1][1]+atom[2]*Vector[2][1],     
    797         atom[0]*Vector[0][2]+atom[1]*Vector[1][2]+atom[2]*Vector[2][2]   
     795        atom[0]*Vector[0][0]+atom[1]*Vector[1][0]+atom[2]*Vector[2][0],
     796        atom[0]*Vector[0][1]+atom[1]*Vector[1][1]+atom[2]*Vector[2][1],
     797        atom[0]*Vector[0][2]+atom[1]*Vector[1][2]+atom[2]*Vector[2][2]
    798798        );
    799799      fprintf(CellFile, "%s %lg %lg %lg\n", name, tempvector[0], tempvector[1], tempvector[2]);
     
    805805
    806806    CellBuffer = ReadBuffer(CellFilename, &length);
    807        
     807
    808808    sprintf(stage, "Cell");
    809809  } else {
     
    812812    sscanf(line, "%i", &numbercell);
    813813  }
    814  
     814
    815815  fprintf(stdout, "\nThere are %i atoms in the cell.\n", numbercell);
    816    
     816
    817817  // ======================== STAGE: Sheet =============================
    818818  // The sheet is a bit more complex. We read the cell in cartesian coordinates
     
    838838  FILE *SheetFile = NULL;
    839839  FILE *SheetFileAligned = NULL;
    840  
     840
    841841  Debug ("STAGE: Sheet\n");
    842842  if (!strncmp(stage, "Cell", 4)) {
    843843    fprintf(stdout, "\nEnter seed unequal 0 if any of the bonds shall have a randomness in their being: ");
    844844    fscanf(stdin, "%d", &seed);
    845     if (seed != 0) 
     845    if (seed != 0)
    846846      input = 'y';
    847847    randomness = (double *) Malloc(sizeof(double)*numbercell, "Main: at sheet - randomness");
     
    856856      else { randomness[i] = 1.-percentage; }
    857857    };
    858    
     858
    859859    fprintf(stdout, "\nSpecify the axis permutation that is going to be perpendicular to the sheet [tubeaxis, torusaxis, noaxis]: ");
    860860    fscanf(stdin, "%d %d %d", &axis[0], &axis[1], &axis[2]);
    861861    fprintf(stdout, "axis: %d %d %d\n", axis[0], axis[1], axis[2]);
    862    
     862
    863863    // create orthogonal vectors individually for each unit cell vector
    864864    CreateOrthogonalAxisVectors(OrthoVector, Vector, axis);
     
    866866    fprintf(stdout, "Orthogonal vector axis[1] %lg\n", Projection(Vector[axis[1]], OrthoVector[axis[1]]));
    867867
    868     do {     
     868    do {
    869869      fprintf(stdout, "\nNow specify the two natural numbers (m n) defining the chiral angle, \nif the result is crap, try flipping to (m,n): ");
    870870      fscanf(stdin, "%d %d", &chiral[0], &chiral[1]);
     
    879879        Tubevector[axis[1]][i] = (double)chiral[0] * OrthoVector[axis[0]][i] - (double)chiral[1] * OrthoVector[axis[1]][i];
    880880        //Tubevector[axis[1]][i] = (-chiral[0]-2.*chiral[1])/(double)ggT * Vector[axis[0]][i] + (2.*chiral[0]+chiral[1])/(double)ggT * Vector[axis[1]][i];
    881 //        fprintf(stderr, "Tubevector[axis[0]][i] = (double)chiral[0] * Vector[axis[0]][i] + (double)chiral[1] * Vector[axis[1]][i]\n = %lg * %lg + %lg * %lg = %lg + %lg = %lg\n\n", 
    882 //          (double)chiral[0], Vector[axis[0]][i], (double)chiral[1], Vector[axis[1]][i], 
    883 //          (double)chiral[0] * Vector[axis[0]][i], (double)chiral[1] * Vector[axis[1]][i], 
     881//        fprintf(stderr, "Tubevector[axis[0]][i] = (double)chiral[0] * Vector[axis[0]][i] + (double)chiral[1] * Vector[axis[1]][i]\n = %lg * %lg + %lg * %lg = %lg + %lg = %lg\n\n",
     882//          (double)chiral[0], Vector[axis[0]][i], (double)chiral[1], Vector[axis[1]][i],
     883//          (double)chiral[0] * Vector[axis[0]][i], (double)chiral[1] * Vector[axis[1]][i],
    884884//          Tubevector[axis[0]][i]);
    885885        Tubevector[axis[2]][i] = Vector[axis[2]][i];
     
    917917        x1 = gsl_vector_get(u,0)*(double)i;
    918918        x2 = gsl_vector_get(u,1)*(double)i;
    919         x3 = 
     919        x3 =
    920920        fprintf(stdout, "%d: %d\t%d vs. %lg\t%lg\n",i, ((int)(x1+x1/fabs(x1)*.5)), ((int)(x2+x2/fabs(x2)*.5)), (x1), (x2));
    921921        if (( fabs( ((int)(x1+x1/fabs(x1)*.5)) - (x1) ) < 1e-6) && ( fabs( ((int)(x2+x2/fabs(x2)*.5)) - (x2) ) < 1e-6 )) {
     
    956956      gsl_vector_free(u);
    957957      gsl_eigen_symmv_free(w);
    958      
     958
    959959      if (fabs(x1) > 1e-6) {
    960960        fprintf(stderr,"Resulting TubeVectors of axis %d and %d and not orthogonal, aborting.\n", axis[0], axis[1]);
    961961        return(128);
    962962      }
    963        
    964      
     963
     964
    965965      angle = Projection(Tubevector[axis[1]], Vector[axis[0]]);
    966966      fprintf(stdout, "Projection Tubevector1 axis[0] %lg %lg\n", angle, 1./angle);
    967967      angle = Projection(Tubevector[axis[1]], Vector[axis[1]]);
    968968      fprintf(stdout, "Projection Tubevector1 axis[1] %lg %lg\n", angle, 1./angle);
    969      
     969
    970970/*      fprintf(stdout, "Vector\n");
    971971      PrintMatrix(stdout, Vector);
     
    10061006    bufptr += (GetNextline(bufptr, line))*sizeof(char);
    10071007    sscanf(line, "%d", &numbersheet);
    1008    
     1008
    10091009    // retrieve axis permutation
    10101010    sprintf(dummy,  "Axis");
     
    10211021    ptr += strlen(dummy);
    10221022    sscanf(ptr, "%d %d %d", &axis[0], &axis[1], &axis[2]);
    1023     fprintf(stdout, "%d %d %d\n", axis[0], axis[1], axis[2]); 
    1024    
     1023    fprintf(stdout, "%d %d %d\n", axis[0], axis[1], axis[2]);
     1024
    10251025    // retrieve chiral numbers
    10261026    sprintf(dummy,  "(n,m)");
     
    10341034      fprintf(stderr, "ERROR: Main at stage Sheet - could not find %s in %s\n", dummy, SheetFilename);
    10351035      exit(255);
    1036     }     
     1036    }
    10371037    ptr += strlen(dummy);
    10381038    sscanf(ptr, "%d %d", &chiral[0], &chiral[1]);
    1039     fprintf(stdout, "%d %d\n", chiral[0], chiral[1]); 
     1039    fprintf(stdout, "%d %d\n", chiral[0], chiral[1]);
    10401040    ggT = GCD(2*chiral[1]+chiral[0],2*chiral[0]+chiral[1]);
    10411041    fprintf(stdout, "Greatest Common Denominator of (2n+m, 2m+n) is %d\n", ggT);
    1042    
     1042
    10431043    // retrieve length and radius factors
    10441044    sprintf(dummy,  "factors");
     
    10551055    ptr += strlen(dummy);
    10561056    sscanf(ptr, "%d %d %d", &factors[0], &factors[1], &factors[2]);
    1057     fprintf(stdout, "%d %d %d\n", factors[0], factors[1], factors[2]); 
     1057    fprintf(stdout, "%d %d %d\n", factors[0], factors[1], factors[2]);
    10581058
    10591059    // create orthogonal vectors individually for each unit cell vector
     
    11021102      x1 = gsl_vector_get(u,0)*(double)i;
    11031103      x2 = gsl_vector_get(u,1)*(double)i;
    1104       x3 = 
     1104      x3 =
    11051105      fprintf(stdout, "%d: %d\t%d vs. %lg\t%lg\n",i, ((int)(x1+x1/fabs(x1)*.5)), ((int)(x2+x2/fabs(x2)*.5)), (x1), (x2));
    11061106      if (( fabs( ((int)(x1+x1/fabs(x1)*.5)) - (x1) ) < 1e-6) && ( fabs( ((int)(x2+x2/fabs(x2)*.5)) - (x2) ) < 1e-6 )) {
     
    11401140    gsl_vector_free(v);
    11411141    gsl_vector_free(u);
    1142     gsl_eigen_symmv_free(w);   
     1142    gsl_eigen_symmv_free(w);
    11431143
    11441144    if (fabs(x1) > 1e-6) {
     
    11471147    }
    11481148
    1149     // retrieve seed ... 
     1149    // retrieve seed ...
    11501150    randomness = (double *) Calloc(sizeof(double)*numbercell, 0., "Main: at sheet - randomness");
    11511151    sprintf(dummy,  "seed");
     
    11591159      fprintf(stderr, "ERROR: Main at stage Sheet - could not find %s in %s\n", dummy, SheetFilename);
    11601160      exit(255);
    1161     }     
     1161    }
    11621162    ptr += strlen(dummy);
    11631163    sscanf(ptr, "%d", &seed);
    1164     fprintf(stdout, "%d\n", seed); 
     1164    fprintf(stdout, "%d\n", seed);
    11651165
    11661166    // ... and randomness
     
    11871187        sscanf(line, "%d %lg", &j, &dummydouble);
    11881188        randomness[j] = dummydouble;
    1189         fprintf(stdout, "%d %g\n", j, randomness[j]);     
     1189        fprintf(stdout, "%d %g\n", j, randomness[j]);
    11901190      }
    11911191    }
     
    12041204  //angle -= acos(Projection(Vector[axis[0]], Tubevector[axis[0]]));
    12051205  //angle = 30./180.*M_PI - acos(Projection(Vector[axis[0]], Tubevector[axis[0]]));
    1206   angle = -acos(Projection(Tubevector[axis[0]], Vector[axis[0]]));
     1206  //angle = acos(Projection(Tubevector[axis[0]], Vector[axis[0]]));
    12071207  fprintf(stdout, "The relative alignment rotation angle then is %lg\n", angle/M_PI*180.);
    12081208  if (fabs(Tubevector[axis[0]][0]) > MYEPSILON)
    1209     angle = M_PI/2. - acos(Tubevector[axis[0]][0]/Norm(Tubevector[axis[0]]));
     1209    angle = -M_PI/2. + acos(Tubevector[axis[0]][0]/Norm(Tubevector[axis[0]]));
    12101210  else
    12111211    angle = 0.;
     
    12511251      sheetnr[j] = sheetnr[j] > tmp ? sheetnr[j] : tmp;
    12521252    }
    1253   } 
     1253  }
    12541254  fprintf(stdout, "Maximum indices to regard: %d %d %d\n", sheetnr[0], sheetnr[1], sheetnr[2]);
    12551255  for (i=0;i<NDIM;i++) {
     
    12601260    // parse in atoms for quicker processing
    12611261    struct Atoms *atombuffer = malloc(sizeof(struct Atoms)*numbercell);
    1262     bufptr = CellBuffer; 
     1262    bufptr = CellBuffer;
    12631263    bufptr += GetNextline(bufptr, line)*sizeof(char);
    12641264    bufptr += GetNextline(bufptr, line)*sizeof(char);
     
    13011301        for (nr = 0; nr < numbercell; nr++) {
    13021302          percentage = rand()/(RAND_MAX+1.0);
    1303           //fprintf(stdout, "Lucky number for %d is %lg >? %lg\n", nr, percentage, randomness[nr]); 
     1303          //fprintf(stdout, "Lucky number for %d is %lg >? %lg\n", nr, percentage, randomness[nr]);
    13041304          if (percentage >= randomness[nr]) {
    13051305            // Create coordinates at atom site
    13061306            coord = VectorAdd(atombuffer[nr].x, offset);
    1307             //fprintf(stdout, "Atom Nr. %i: ", (numbersheet+1));         
     1307            //fprintf(stdout, "Atom Nr. %i: ", (numbersheet+1));
    13081308            //PrintVector(stdout, coord);
    13091309            // project down on major and minor Tubevectors and check for length if out of sheet
     
    13501350  //}
    13511351  SheetBuffer = ReadBuffer(SheetFilename, &length);
    1352  
    1353  
     1352
     1353
    13541354  // ======================== STAGE: Tube ==============================
    13551355  // The tube starts with the rectangular (due to the orthogonalization) sheet
     
    13651365  FILE *TubeFile = NULL;
    13661366  FILE *TubeFileAligned = NULL;
    1367  
     1367
    13681368  Debug ("STAGE: Tube\n");
    13691369  if (!strncmp(stage, "Sheet", 4)) {
     
    13851385    //cog_projected = MatrixTrafoInverse(cog, TubevectorInverse);
    13861386    //fprintf(stdout, "\nCenter of Gravity at (%5.5lg\t%5.5lg\t%5.5lg) and projected at (%5.5lg\t%5.5lg\t%5.5lg)\n", cog[0], cog[1], cog[2], cog_projected[0], cog_projected[1], cog_projected[2]);
    1387    
     1387
    13881388    // restart
    13891389    bufptr = SheetBuffer;
     
    13951395    for (i=0;i<NDIM;i++)
    13961396      halfaxis[i] = factors[0]*Norm(Tubevector[axis[0]])/Norm(Tubevector[i]);
    1397      
    1398     double arg, radius; 
     1397
     1398    double arg, radius;
    13991399    for (i=0;i<numbersheet;i++) {
    1400       // scan next atom 
     1400      // scan next atom
    14011401      bufptr += GetNextline(bufptr, line);
    14021402      sscanf(line, "%s %lg %lg %lg", name, &atom[0], &atom[1], &atom[2]);
     
    14061406      //x = VectorAdd(y, cog_projected);
    14071407      //free(y);
    1408      
     1408
    14091409      // roll up (project (x,y,z) on cylindrical coordinates (radius,arg,z))
    14101410      arg = 2.*M_PI*x[axis[0]]/(factors[0]) - M_PI;  // is angle
    14111411      radius = 1./(2.*M_PI);  // is length of sheet in units of axis vector, divide by pi to get radius (from circumference)
    14121412      // fprintf(stdout, "arg: %5.2f (c%2.2f,s%2.2f)\t",$arg, cos($arg), sin($arg));
    1413       x[axis[0]] = cos(arg)*halfaxis[axis[0]]*radius; //(radius+x[axis[2]]/halfaxis[axis[2]]); // as both vectors are not normalized additional betrag has to be taken into account!
    1414       x[axis[2]] = sin(arg)*halfaxis[axis[2]]*radius; //(radius+x[axis[2]]/halfaxis[axis[2]]); // due to the back-transformation from eigensystem to cartesian one
     1413      x[axis[0]] = cos(arg)*halfaxis[axis[0]]*(radius+x[axis[2]]/halfaxis[axis[2]]); // as both vectors are not normalized additional betrag has to be taken into account!
     1414      x[axis[2]] = sin(arg)*halfaxis[axis[2]]*(radius+x[axis[2]]/halfaxis[axis[2]]); // due to the back-transformation from eigensystem to cartesian one
    14151415      //fprintf(stdout, "rotated: (%5.2f,%5.2f,%5.2f)\n",x[0],x[1],x[2]);
    14161416      atom_transformed = MatrixTrafo(Tubevector, x);
     
    14231423      //fprintf(stdout, "%s\t%5.5lg\t%5.5lg\t%5.5lg\n", name, atom_transformed[0], atom_transformed[1] ,atom_transformed[2]);
    14241424
    1425       Free(x, "Main: at stage Tube - x"); 
     1425      Free(x, "Main: at stage Tube - x");
    14261426      Free(atom_transformed, "Main: at stage Tube - atom_transformed");
    14271427    }
    14281428
    1429    
     1429
    14301430    fclose(TubeFile);
    14311431    fclose(TubeFileAligned);
     
    14361436    AddSheetInfo(TubeFilename,axis,chiral, factors, seed, numbercell, randomness);
    14371437    fprintf(stdout, "\nThere are %i atoms in the created tube.\n", numbersheet);
    1438    
     1438
    14391439    strncpy(stage, "Tube", 4);
    14401440  } else {
     
    14541454
    14551455  FILE *TorusFile;
    1456  
     1456
    14571457  Debug ("STAGE: Torus\n");
    14581458  if (!strncmp(stage, "Tube", 4)) {
     
    14651465    bufptr += GetNextline(bufptr, line);  // write numbers to file
    14661466    bufptr += GetNextline(bufptr, line);  // write comment to file
    1467    
     1467
    14681468    //cog = CenterOfGravity(bufptr, numbersheet);
    14691469    //cog_projected = MatrixTrafoInverse(cog, TubevectorInverse);
    14701470    //fprintf(stdout, "\nCenter of Gravity at (%5.5lg\t%5.5lg\t%5.5lg) and projected at (%5.5lg\t%5.5lg\t%5.5lg)\n", cog[0], cog[1], cog[2], cog_projected[0], cog_projected[1], cog_projected[2]);
    1471    
     1471
    14721472    // determine half axis as tube vectors not necessarily have same length
    14731473    double halfaxis[NDIM];
    14741474    for (i=0;i<NDIM;i++)
    14751475      halfaxis[i] = Norm(Tubevector[axis[1]])/Norm(Tubevector[i]);
    1476      
    1477     double arg, radius; 
     1476
     1477    double arg, radius;
    14781478    for (i=0;i<numbersheet;i++) {
    1479       // scan next atom 
     1479      // scan next atom
    14801480      bufptr += GetNextline(bufptr, line);
    14811481      sscanf(line, "%s %lg %lg %lg", name, &atom[0], &atom[1], &atom[2]);
     
    14851485      //x = VectorAdd(y, cog_projected);
    14861486      //free(y);
    1487      
     1487
    14881488      // roll up (project (x,y,z) on cylindrical coordinates (radius,arg,z))
    14891489      arg = 2.*M_PI*x[axis[1]]/(factors[1]) - M_PI;  // is angle
     
    14971497      //fprintf(stdout, "%s\t%5.5lg\t%5.5lg\t%5.5lg\n", name, atom_transformed[0], atom_transformed[1] ,atom_transformed[2]);
    14981498
    1499       Free(x, "Main: at stage Torus - x"); 
     1499      Free(x, "Main: at stage Torus - x");
    15001500      Free(atom_transformed, "Main: at stage Torus - atom_transformed");
    15011501    }
    1502    
     1502
    15031503    fclose(TorusFile);
    15041504    //free(cog);
     
    15361536  Free(SheetFilenameAligned, "Main: end of stafes - CellFilename");
    15371537  Free(TubeFilenameAligned, "Main: end of stafes - CellFilename");
    1538  
     1538
    15391539  // exit
    15401540  exit(0);
Note: See TracChangeset for help on using the changeset viewer.