Changeset 7f3b9d


Ignore:
Timestamp:
May 23, 2008, 9:17:19 AM (17 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
040f93
Parents:
6097ea
Message:

Lots of for loops now count in reverse order where it does not matter, some 3 -> NDIM

for(i=0;i<var;i++) is slower than for (i=var;i--;) if the order of the i's is not important (note: i-- is also a value and it stops when on i == 0 automatically)
in builder.cpp there were some remnant 3 actually meant to be NDIM

Location:
src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • src/analyzer.cpp

    r6097ea r7f3b9d  
    9393  output << endl << "Total Times" << endl << "===============" << endl << Time.Header << endl;
    9494  Time.SetLastMatrix(0., 0);
    95   for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++)
    96     for(int i=0;i<KeySet.FragmentsPerOrder[BondOrder];i++)
    97       for(int j=0;j<Time.RowCounter[Time.MatrixCounter];j++)
    98         for(int k=0;k<Time.ColumnCounter;k++) {
     95  for (int BondOrder=KeySet.Order;BondOrder--;)
     96    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;)
     97      for(int j=Time.RowCounter[Time.MatrixCounter];j--;)
     98        for(int k=Time.ColumnCounter;k--;) {
    9999          Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    100100        }
     
    118118  output << "#Order\tFrag.No.\t" << Time.Header << endl;
    119119  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    120     for(int i=0;i<KeySet.FragmentsPerOrder[BondOrder];i++)
    121       for(int j=0;j<Time.RowCounter[Time.MatrixCounter];j++)
    122         for(int k=0;k<Time.ColumnCounter;k++) {
     120    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;)
     121      for(int j=Time.RowCounter[Time.MatrixCounter];j--;)
     122        for(int k=Time.ColumnCounter;k--;) {
    123123          Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    124124        }
  • src/builder.cpp

    r6097ea r7f3b9d  
    5959 * \param *mol the molecule to add to
    6060 */
    61 void AddAtoms(periodentafel *periode, molecule *mol)
     61static void AddAtoms(periodentafel *periode, molecule *mol)
    6262{
    6363  atom *first, *second, *third, *fourth;
     
    113113          cout << Verbose(0) << "Enter relative coordinates." << endl;
    114114          first->x.AskPosition(mol->cell_size, false);
    115           for (int i=0;i<3;i++) {
     115          for (int i=NDIM;i--;) {
    116116            first->x.x[i] += second->x.x[i];
    117117          }
     
    227227        atoms = new (vector*[128]);
    228228        valid = true;
    229         for(int i=0;i<128;i++)
     229        for(int i=128;i--;)
    230230          atoms[i] = NULL;
    231231        int i=0, j=0;
     
    256256 * \param *mol the molecule with all the atoms
    257257 */
    258 void CenterAtoms(molecule *mol)
     258static void CenterAtoms(molecule *mol)
    259259{
    260260  vector x, y;
     
    285285    case 'c':
    286286      cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
    287       for (int i=0;i<3;i++) {
     287      for (int i=0;i<NDIM;i++) {
    288288        cout << Verbose(0) << "Enter axis " << i << " boundary: ";
    289289        cin >> y.x[i];
     
    295295    case 'd':
    296296      cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
    297       for (int i=0;i<3;i++) {
     297      for (int i=0;i<NDIM;i++) {
    298298        cout << Verbose(0) << "Enter axis " << i << " boundary: ";
    299299        cin >> x.x[i];
     
    311311 * \param *mol the molecule with all the atoms
    312312 */
    313 void AlignAtoms(periodentafel *periode, molecule *mol)
     313static void AlignAtoms(periodentafel *periode, molecule *mol)
    314314{
    315315  atom *first, *second, *third;
     
    359359      cout << Verbose(0) << "Element is " << param.type->name << endl;
    360360      mol->GetAlignVector(&param);
    361       for (int i=0;i<3;i++) {
     361      for (int i=NDIM;i--;) {
    362362        x.x[i] = gsl_vector_get(param.x,i);
    363         n.x[i] = gsl_vector_get(param.x,i+3);
     363        n.x[i] = gsl_vector_get(param.x,i+NDIM);
    364364      }
    365365      gsl_vector_free(param.x);
     
    379379 * \param *mol the molecule with all the atoms
    380380 */
    381 void MirrorAtoms(molecule *mol)
     381static void MirrorAtoms(molecule *mol)
    382382{
    383383  atom *first, *second, *third;
     
    426426 * \param *mol the molecule with all the atoms
    427427 */
    428 void RemoveAtoms(molecule *mol)
     428static void RemoveAtoms(molecule *mol)
    429429{
    430430  atom *first, *second;
     
    484484 * \param *mol the molecule with all the atoms
    485485 */
    486 void MeasureAtoms(periodentafel *periode, molecule *mol)
     486static void MeasureAtoms(periodentafel *periode, molecule *mol)
    487487{
    488488  atom *first, *second, *third;
     
    507507    case 'a':
    508508      first = mol->AskAtom("Enter first atom: ");
    509       for (int i=0;i<256;i++)
     509      for (int i=MAX_ELEMENTS;i--;)
    510510        min[i] = 0.;
    511511       
     
    523523        //cout << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;         
    524524      }
    525       for (int i=0;i<256;i++)
     525      for (int i=MAX_ELEMENTS;i--;)
    526526        if (min[i] != 0.) cout << Verbose(0) << "Minimum Bond length between " << first->type->name << " Atom " << first->nr << " and next Ion of type " << (periode->FindElement(i))->name << ": " << min[i] << " a.u." << endl;
    527527      break;
     
    530530      first = mol->AskAtom("Enter first atom: ");
    531531      second = mol->AskAtom("Enter second atom: ");
    532       for (int i=0;i<NDIM;i++)
     532      for (int i=NDIM;i--;)
    533533        min[i] = 0.;
    534534      x.CopyVector((const vector *)&first->x);
     
    560560 * \param *configuration configuration structure for the to be written config files of all fragments
    561561 */
    562 void FragmentAtoms(molecule *mol, config *configuration)
     562static void FragmentAtoms(molecule *mol, config *configuration)
    563563{
    564564  int Order1;
     
    581581/** Is called always as option 'T' in the menu.
    582582 */
    583 void testroutine(molecule *mol)
     583static void testroutine(molecule *mol)
    584584{
    585585  // the current test routine checks the functionality of the KeySet&Graph concept:
     
    654654 * \param *mol pointer to molecule structure with all the atoms and coordinates
    655655 */
    656 void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol)
     656static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, molecule *mol)
    657657{
    658658  char filename[MAXSTRINGSIZE];
     
    709709 * \return exit code (0 - successful, all else - something's wrong)
    710710 */
    711 int ParseCommandLineOptions(int argc, char **argv, molecule *&mol, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&ElementsFileName)
     711static int ParseCommandLineOptions(int argc, char **argv, molecule *&mol, periodentafel *&periode, config& configuration, char *&ConfigFileName, char *&ElementsFileName)
    712712{
    713713  element *finder;
     
    846846              ExitFlag = 1;
    847847              cout << Verbose(1) << "Translating all ions to new origin." << endl;
    848               for (int i=0;i<3;i++)
     848              for (int i=NDIM;i--;)
    849849                x.x[i] = atof(argv[argptr+i]);
    850850              mol->Translate((const vector *)&x);
     
    855855              cout << Verbose(1) << "Adding new atom." << endl;
    856856              first = new atom;
    857               for (int i=0;i<3;i++)
     857              for (int i=NDIM;i--;)
    858858                first->x.x[i] = atof(argv[argptr+1+i]);
    859859              finder = periode->start;
     
    872872              j = -1;
    873873              cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
    874               factor = (double *) Malloc(sizeof(double)*NDIM, "main: *factor");
     874              factor = new double[NDIM];
    875875              factor[0] = atof(argv[argptr]);
    876876              if (argc > argptr+1)
     
    881881              factor[2] = atof(argv[argptr]);
    882882              mol->Scale(&factor);
    883               for (int i=0;i<3;i++) {
     883              for (int i=0;i<NDIM;i++) {
    884884                j += i+1;
    885                 x.x[i] = atof(argv[3+i]);
     885                x.x[i] = atof(argv[NDIM+i]);
    886886                mol->cell_size[j]*=factor[i];
    887887              }
    888               Free((void **)&factor, "main: *factor");
     888              delete[](factor);
    889889              argptr+=1;
    890890              break;
     
    894894              cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
    895895              j=-1;
    896               for (int i=0;i<3;i++) {
     896              for (int i=0;i<NDIM;i++) {
    897897                j += i+1;
    898898                x.x[i] = atof(argv[argptr++]);
     
    914914              // translate each coordinate by boundary
    915915              j=-1;
    916               for (int i=0;i<3;i++) {
     916              for (int i=0;i<NDIM;i++) {
    917917                j += i+1;
    918918                x.x[i] = atof(argv[argptr++]);
     
    10561056        second = mol->AskAtom("Enter second (shifting) atom: ");
    10571057        min_bond = 0.;
    1058         for (int i=0;i<3;i++)
     1058        for (int i=NDIM;i--;)
    10591059          min_bond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
    10601060        min_bond = sqrt(min_bond);
     
    10621062        cout << Verbose(0) << "Enter new bond length [a.u.]: ";
    10631063        cin >> bond;
    1064         for (int i=0;i<3;i++) {
     1064        for (int i=NDIM;i--;) {
    10651065          second->x.x[i] -= (second->x.x[i]-first->x.x[i])/min_bond*(min_bond-bond);
    10661066        }
     
    11071107          for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    11081108            x.AddVector(&y); // per factor one cell width further
    1109             for (int k=0;k<count;k++) { // go through every atom of the original cell
     1109            for (int k=count;k--;) { // go through every atom of the original cell
    11101110              first = new atom(); // create a new body
    11111111              first->x.CopyVector(Vectors[k]);  // use coordinate of original atom
  • src/config.cpp

    r6097ea r7f3b9d  
    282282        case 'j': // BoxLength
    283283          cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
    284           for (int i=0;i<6;i++) {
     284          for (int i=6;i--;) {
    285285            cout << Verbose(0) << "Cell size" << i << ": ";
    286286            cin >> mol->cell_size[i];
     
    408408
    409409/** Retrieves the path in the given config file name.
    410  * \param *filename config file string
     410 * \param filename config file string
    411411 */
    412 void config::RetrieveConfigPathAndName(char *filename)
     412void config::RetrieveConfigPathAndName(string filename)
    413413{
    414414  char *ptr = NULL;
     415  char *buffer = new char[MAXSTRINGSIZE];
     416  strncpy(buffer, filename.c_str(), MAXSTRINGSIZE);
    415417  int last = -1;
    416   for(int i=0;i<MAXSTRINGSIZE;i++) {
    417     if (filename[i] == '/')
    418       last = i;
    419     if (filename[i] == '\0')
     418  for(last=MAXSTRINGSIZE;last--;) {
     419    if (buffer[last] == '/')
    420420      break;
    421421  }
    422   if (last == -1) { // no path in front, set to local directory.
     422  if (last == 0) { // no path in front, set to local directory.
    423423    strcpy(configpath, "./");
    424     ptr = filename;
     424    ptr = buffer;
    425425  } else {
    426     strncpy(configpath, filename, last+1);
    427     ptr = &filename[last+1];
     426    strncpy(configpath, buffer, last+1);
     427    ptr = &buffer[last+1];
    428428    if (last < 254)
    429429      configpath[last+1]='\0';
     
    431431  strcpy(configname, ptr);
    432432  cout << "Found configpath: " << configpath << ", dir slash was found at " << last << ", config name is " << configname << "." << endl;
     433  delete[](buffer);
    433434};
    434435
     
    824825 
    825826 
    826   for (i=0;i<128;i++) elementhash[i] = NULL;
     827  for (i=MAX_ELEMENTS;i--;)
     828    elementhash[i] = NULL;
    827829  cout << Verbose(0) << "Parsing Ions ..." << endl;
    828830  No=0;
  • src/datacreator.cpp

    r6097ea r7f3b9d  
    4848  output << "#Order\tFrag.No.\t" << Energy.Header << endl;
    4949  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    50     for(int i=0;i<KeySet.FragmentsPerOrder[BondOrder];i++) {
    51       for(int j=0;j<Energy.RowCounter[ KeySet.OrderSet[BondOrder][i] ];j++)
    52         for(int k=0;k<Energy.ColumnCounter;k++)
     50    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) {
     51      for(int j=Energy.RowCounter[ KeySet.OrderSet[BondOrder][i] ];j--;)
     52        for(int k=Energy.ColumnCounter;k--;)
    5353          Energy.Matrix[Energy.MatrixCounter][j][k] -= EnergyFragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    5454    }
     
    8989        }
    9090        if (j != -1)
    91           for(int k=0;k<Force.ColumnCounter;k++) {
     91          for(int k=Force.ColumnCounter;k--;) {
    9292            Force.Matrix[Force.MatrixCounter][j][k] += ForceFragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][l][k];
    9393          }
     
    136136void CreateMaxFragmentOrder(class MatrixContainer &Fragments, class KeySetsContainer &KeySet, int BondOrder)
    137137{
    138   for(int j=0;j<Fragments.RowCounter[ Fragments.MatrixCounter ];j++) {
    139     for(int i=0;i<KeySet.FragmentsPerOrder[BondOrder];i++) {
     138  for(int j=Fragments.RowCounter[ Fragments.MatrixCounter ];j--;) {
     139    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;) {
    140140      if (fabs(Fragments.Matrix[ Fragments.MatrixCounter ][j][1]) < fabs(Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][1])) {
    141         for (int k=0;k<Fragments.ColumnCounter;k++)
     141        for (int k=Fragments.ColumnCounter;k--;)
    142142          Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    143143      }
     
    156156    int i=0;
    157157    do {  // first get a minimum value unequal to 0
    158       for (int k=0;k<Fragments.ColumnCounter;k++)
     158      for (int k=Fragments.ColumnCounter;k--;)
    159159        Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    160160      i++;
     
    162162    for(;i<KeySet.FragmentsPerOrder[BondOrder];i++) { // then find lowest
    163163      if (fabs(Fragments.Matrix[ Fragments.MatrixCounter ][j][1]) > fabs(Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][1])) {
    164         for (int k=0;k<Fragments.ColumnCounter;k++)
     164        for (int k=Fragments.ColumnCounter;k--;)
    165165          Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    166166      }
     
    211211void CreateMinimumForce(class MatrixContainer &Force, int MatrixNumber)
    212212{
    213   for (int l=0;l<Force.ColumnCounter;l++)
     213  for (int l=Force.ColumnCounter;l--;)
    214214    Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
    215215  for (int l=5;l<Force.ColumnCounter;l+=3) {
     
    217217    int k=0;
    218218    do {
    219       for (int m=0;m<3;m++) {
     219      for (int m=NDIM;m--;) {
    220220        stored += Force.Matrix[MatrixNumber][ k ][l+m]
    221221              * Force.Matrix[MatrixNumber][ k ][l+m];
     
    226226    for (;k<Force.RowCounter[MatrixNumber];k++) {
    227227      double tmp = 0;
    228       for (int m=0;m<3;m++)
     228      for (int m=NDIM;m--;)
    229229        tmp += Force.Matrix[MatrixNumber][ k ][l+m]
    230230              * Force.Matrix[MatrixNumber][ k ][l+m];
    231231      if ((fabs(tmp) > MYEPSILON) && (tmp < stored)) {  // current force is greater than stored
    232         for (int m=0;m<3;m++)
     232        for (int m=NDIM;m--;)
    233233          Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m]  = Force.Matrix[MatrixNumber][ k ][l+m];
    234234        stored = tmp;
     
    246246{
    247247  int divisor = 0;
    248   for (int l=0;l<Force.ColumnCounter;l++)
     248  for (int l=Force.ColumnCounter;l--;)
    249249    Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
    250250  for (int l=5;l<Force.ColumnCounter;l+=3) {
    251251    double tmp = 0;
    252     for (int k=0;k<Force.RowCounter[MatrixNumber];k++) {
     252    for (int k=Force.RowCounter[MatrixNumber];k--;) {
    253253      double norm = 0.;
    254       for (int m=0;m<3;m++)
     254      for (int m=NDIM;m--;)
    255255        norm += Force.Matrix[MatrixNumber][ k ][l+m]
    256256              * Force.Matrix[MatrixNumber][ k ][l+m];
     
    272272  for (int l=5;l<Force.ColumnCounter;l+=3) {
    273273    double stored = 0;
    274     for (int k=0;k<Force.RowCounter[MatrixNumber];k++) {
     274    for (int k=Force.RowCounter[MatrixNumber];k--;) {
    275275      double tmp = 0;
    276       for (int m=0;m<3;m++)
     276      for (int m=NDIM;m--;)
    277277        tmp += Force.Matrix[MatrixNumber][ k ][l+m]
    278278              * Force.Matrix[MatrixNumber][ k ][l+m];
    279279      if (tmp > stored) {  // current force is greater than stored
    280         for (int m=0;m<3;m++)
     280        for (int m=NDIM;m--;)
    281281          Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m]  = Force.Matrix[MatrixNumber][ k ][l+m];
    282282        stored = tmp;
     
    293293void CreateVectorSumForce(class MatrixContainer &Force, int MatrixNumber)
    294294{
    295   for (int l=0;l<Force.ColumnCounter;l++)
     295  for (int l=Force.ColumnCounter;l--;)
    296296    Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.;
    297297  for (int l=5;l<Force.ColumnCounter;l++) {
    298     for (int k=0;k<Force.RowCounter[MatrixNumber];k++)
     298    for (int k=Force.RowCounter[MatrixNumber];k--;)
    299299      Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] += Force.Matrix[MatrixNumber][k][l];
    300300  }
     
    423423  line >> item;
    424424  line >> item;
    425   for (int i=7; i< Force.ColumnCounter;i+=3) {
     425  for (int i=7; i< Force.ColumnCounter;i+=NDIM) {
    426426    line >> item;
    427427    item[strlen(item)-1] = '\0';  // kill residual index char (the '0')
     
    452452  line >> item;
    453453  line >> item;
    454   for (int i=7; i< Force.ColumnCounter;i+=3) {
     454  for (int i=7; i< Force.ColumnCounter;i+=NDIM) {
    455455    line >> item;
    456456    item[strlen(item)-1] = '\0';  // kill residual index char (the '0')
     
    482482  line >> item;
    483483  line >> item;
    484   for (int i=7; i< Force.ColumnCounter;i+=3) {
     484  for (int i=7; i< Force.ColumnCounter;i+=NDIM) {
    485485    line >> item;
    486486    item[strlen(item)-1] = '\0';  // kill residual index char (the '0')
     
    512512  line >> item;
    513513  line >> item;
    514   for (int i=7; i< Force.ColumnCounter;i+=3) {
     514  for (int i=7; i< Force.ColumnCounter;i+=NDIM) {
    515515    line >> item;
    516516    item[strlen(item)-1] = '\0';  // kill residual index char (the '0')
  • src/helpers.cpp

    r6097ea r7f3b9d  
    106106  if (buffer == NULL)
    107107    cout << Verbose(0) << output << endl;
    108   for (i=0;i<size;i++)  // reset
     108  for (i=size;i--;)  // reset
    109109    buffer[i] = i % 2 == 0 ? 'p': 'c';
    110110  buffer[size] = '\0'; // and set length marker on its end
     
    147147  int res = 1;
    148148  int j;
    149   for (j=0;j<n;j++)
     149  for (j=n;j--;)
    150150    res *= base;
    151151  return res;
     
    172172  returnstring[order] = '\0';
    173173  number = digits;
    174   for (int i=order-1;i>=0;i--){
     174  for (int i=order-1;i--;){
    175175    returnstring[i] = '0' + (char)(number % 10);
    176176    number = (int)floor(((double)number / 10.));
  • src/helpers.hpp

    r6097ea r7f3b9d  
    266266  int i;
    267267  if (ptr != NULL) {
    268     for(i=0;i<dim;i++)
     268    for(i=dim;i--;)
    269269      if (ptr[i] != NULL)
    270270        free(ptr[i]);
  • src/moleculelist.cpp

    r6097ea r7f3b9d  
    2222{
    2323  ListOfMolecules = (molecule **) Malloc(sizeof(molecule *)*NumMolecules, "MoleculeListClass:MoleculeListClass: **ListOfMolecules");
    24   for (int i=0;i<NumMolecules;i++)
     24  for (int i=NumMolecules;i--;)
    2525    ListOfMolecules[i] = NULL;
    2626  NumberOfMolecules = NumMolecules;
     
    3434{
    3535  cout << Verbose(3) << this << ": Freeing ListOfMolcules." << endl;
    36   for (int i=0;i<NumberOfMolecules;i++) {
     36  for (int i=NumberOfMolecules;i--;) {
    3737    if (ListOfMolecules[i] != NULL) { // if NULL don't free
    3838      cout << Verbose(4) << "ListOfMolecules: Freeing " << ListOfMolecules[i] << "." << endl;
     
    6666    else {
    6767      Count = (**(molecule **)a).AtomCount;
    68       aList = (int *) Malloc(sizeof(int)*Count, "MolCompare: *aList");
    69       bList = (int *) Malloc(sizeof(int)*Count, "MolCompare: *bList");
     68      aList = new int[Count];
     69      bList = new int[Count];
    7070 
    7171      // fill the lists
     
    114114        }
    115115      }
    116       Free((void **)&aList, "MolCompare: *aList");
    117       Free((void **)&bList, "MolCompare: *bList");
     116      delete[](aList);
     117      delete[](bList);
    118118      return flag;
    119119    }
     
    244244    ListOfMolecules[i]->SetBoxDimension(&BoxDimension);  // update Box of atoms by boundary
    245245    int j = -1;
    246     for (int k=0;k<3;k++) {
     246    for (int k=0;k<NDIM;k++) {
    247247      j += k+1;
    248248      BoxDimension.x[k] = 5.;
     
    268268    outputFragment.close();
    269269    outputFragment.clear();
    270     Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber");
     270    delete(FragmentNumber);
     271    //Free((void **)&FragmentNumber, "MoleculeListClass::OutputConfigForListOfFragments: *FragmentNumber");
    271272  }
    272273  cout << " done." << endl;
     
    461462    ListOfLocalAtoms = (atom ***) Malloc(sizeof(atom **)*Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
    462463    if (ListOfLocalAtoms != NULL) {
    463       for (int i=0;i<Counter;i++)
     464      for (int i=Counter;i--;)
    464465        ListOfLocalAtoms[i] = NULL;
    465466      FreeList = FreeList && true;
     
    501502    KeySetCounter = Count();
    502503    FragmentList = (Graph **) Malloc(sizeof(Graph *)*KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
    503     for(int i=0;i<KeySetCounter;i++)
     504    for(int i=KeySetCounter;i--;)
    504505      FragmentList[i] = NULL;
    505506    KeySetCounter = 0;
  • src/molecules.cpp

    r6097ea r7f3b9d  
    2121  int num = par->num;
    2222
    23   for (int i=0;i<num;i++) {
    24     for(int j=0;j<NDIM;j++)
     23  for (int i=num;i--;) {
     24    for(int j=NDIM;j--;)
    2525      sum += (gsl_vector_get(x,j) - (vectors[i])->x[j])*(gsl_vector_get(x,j) - (vectors[i])->x[j]);
    2626  }
     
    5757  NumberOfBondsPerAtom = NULL;
    5858  ElementCount = 0;
    59   for(int i=0;i<MAX_ELEMENTS;i++)
     59  for(int i=MAX_ELEMENTS;i--;)
    6060    ElementsInMolecule[i] = 0;
    6161  cell_size[0] = cell_size[2] = cell_size[5]= 20.;
     
    6969{
    7070  if (ListOfBondsPerAtom != NULL)
    71     for(int i=0;i<AtomCount;i++)
     71    for(int i=AtomCount;i--;)
    7272      Free((void **)&ListOfBondsPerAtom[i], "molecule::~molecule: ListOfBondsPerAtom[i]");
    7373  Free((void **)&ListOfBondsPerAtom, "molecule::~molecule: ListOfBondsPerAtom");
     
    200200//    *out << endl;
    201201    OrthoVector1.Zero();
    202     for (int i=0;i<NDIM;i++) {
     202    for (int i=NDIM;i--;) {
    203203      l = TopReplacement->x.x[i] - TopOrigin->x.x[i];
    204204      if (fabs(l) > BondDistance) { // is component greater than bond distance
     
    312312      FirstOtherAtom->x.Zero();
    313313      SecondOtherAtom->x.Zero();
    314       for(i=0;i<NDIM;i++) { // rotate by half the bond angle in both directions (InBondVector is bondangle = 0 direction)
     314      for(i=NDIM;i--;) { // rotate by half the bond angle in both directions (InBondVector is bondangle = 0 direction)
    315315        FirstOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (sin(bondangle));
    316316        SecondOtherAtom->x.x[i] = InBondVector.x[i] * cos(bondangle) + OrthoVector1.x[i] * (-sin(bondangle));
     
    319319      SecondOtherAtom->x.Scale(&BondRescale);
    320320      //*out << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl;
    321       for(i=0;i<NDIM;i++) { // and make relative to origin atom
     321      for(i=NDIM;i--;) { // and make relative to origin atom
    322322        FirstOtherAtom->x.x[i] += TopOrigin->x.x[i];
    323323        SecondOtherAtom->x.x[i] += TopOrigin->x.x[i];
     
    471471      first->type = elemente->FindElement(1);
    472472    }
    473     for(j=0;j<NDIM;j++)
     473    for(j=NDIM;j--;)
    474474      first->x.x[j] = x[j];
    475475     AddAtom(first);  // add to molecule
     
    612612  ptr = start->next;  // start at first in list
    613613  if (ptr != end) {   //list not empty?
    614     for (int i=0;i<NDIM;i++) {
     614    for (int i=NDIM;i--;) {
    615615      max->x[i] = ptr->x.x[i];
    616616      min->x[i] = ptr->x.x[i];
     
    619619      ptr = ptr->next;
    620620      //ptr->Output(1,1,out);
    621       for (int i=0;i<NDIM;i++) {
     621      for (int i=NDIM;i--;) {
    622622        max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];
    623623        min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];
     
    626626  }
    627627  // sanity check
    628   for(int i=0;i<NDIM;i++) {
     628  for(int i=NDIM;i--;) {
    629629    if (max->x[i] - min->x[i] > BoxLengths->x[i])
    630630      status = false;
     
    637637    while (ptr->next != end) {
    638638      ptr = ptr->next;
    639       for (int i=0;i<NDIM;i++)
     639      for (int i=NDIM;i--;)
    640640        ptr->x.x[i] += -(max->x[i] + min->x[i])/2. + BoxLengths->x[i]/2.; // first term centers molecule at (0,0,0), second shifts to center of new box
    641641    }
     
    659659  atom *ptr = start->next;  // start at first in list
    660660  if (ptr != end) {   //list not empty?
    661     for (int i=0;i<NDIM;i++) {
     661    for (int i=NDIM;i--;) {
    662662      max->x[i] = ptr->x.x[i];
    663663      min->x[i] = ptr->x.x[i];
     
    666666      ptr = ptr->next;
    667667      //ptr->Output(1,1,out);
    668       for (int i=0;i<NDIM;i++) {
     668      for (int i=NDIM;i--;) {
    669669        max->x[i] = (max->x[i] < ptr->x.x[i]) ? ptr->x.x[i] : max->x[i];
    670670        min->x[i] = (min->x[i] > ptr->x.x[i]) ? ptr->x.x[i] : min->x[i];
     
    677677//    *out << endl;
    678678   
    679     for (int i=0;i<NDIM;i++) {
     679    for (int i=NDIM;i--;) {
    680680      min->x[i] *= -1.;
    681681      max->x[i] += min->x[i];
     
    696696  atom *ptr = start->next;  // start at first in list
    697697 
    698   for(int i=0;i<NDIM;i++) // zero center vector
     698  for(int i=NDIM;i--;) // zero center vector
    699699    center->x[i] = 0.;
    700700   
     
    720720  vector tmp;
    721721 
    722   for(int i=0;i<NDIM;i++) // zero center vector
     722  for(int i=NDIM;i--;) // zero center vector
    723723    center->x[i] = 0.;
    724724   
     
    957957  bool result = true;
    958958  int j =-1;
    959   for (int i=0;i<3;i++) {
     959  for (int i=0;i<NDIM;i++) {
    960960    j += i+1;
    961961    result = result && ((x->x[i] >= 0) && (x->x[i] < cell_size[j]));
     
    12071207{
    12081208        int i = 0;
    1209   for(i=0;i<MAX_ELEMENTS;i++)
     1209  for(i=MAX_ELEMENTS;i--;)
    12101210        ElementsInMolecule[i] = 0;
    12111211        ElementCount = 0;
     
    12171217    i++;
    12181218  }
    1219   for(i=0;i<MAX_ELEMENTS;i++)
     1219  for(i=MAX_ELEMENTS;i--;)
    12201220        ElementCount += (ElementsInMolecule[i] != 0 ? 1 : 0);
    12211221};
     
    12821282{
    12831283  configuration.MaxPsiDouble = configuration.PsiMaxNoDown = configuration.PsiMaxNoUp = configuration.PsiType = 0;
    1284   for(int i=0;i<MAX_ELEMENTS;i++) {
     1284  for(int i=MAX_ELEMENTS;i--;) {
    12851285    if (ElementsInMolecule[i] != 0) {
    12861286      //cout << "CalculateOrbitals: " << elemente->FindElement(i)->name << " has a valence of " << (int)elemente->FindElement(i)->Valence << " and there are " << ElementsInMolecule[i] << " of it." << endl;
     
    13521352    *out << Verbose(1) << "Allocating " << NumberCells << " cells." << endl;
    13531353    CellList = (molecule **) Malloc(sizeof(molecule *)*NumberCells, "molecule::CreateAdjacencyList - ** CellList");
    1354     for (int i=0;i<NumberCells;i++)
     1354    for (int i=NumberCells;i--;)
    13551355      CellList[i] = NULL;
    13561356 
     
    13821382     
    13831383    // 3a. go through every cell
    1384     for (N[0]=0;N[0]<divisor[0];N[0]++)
    1385       for (N[1]=0;N[1]<divisor[1];N[1]++)
    1386         for (N[2]=0;N[2]<divisor[2];N[2]++) {
     1384    for (N[0]=divisor[0];N[0]--;)
     1385      for (N[1]=divisor[1];N[1]--;)
     1386        for (N[2]=divisor[2];N[2]--;) {
    13871387          Index = N[2] + (N[1] + N[0] * divisor[1]) * divisor[2];
    13881388          if (CellList[Index] != NULL) { // if there atoms in this cell
     
    14241424        }
    14251425    // 4. free the cell again
    1426     for (int i=0;i<NumberCells;i++)
     1426    for (int i=NumberCells;i--;)
    14271427      if (CellList[i] != NULL) {
    14281428        delete(CellList[i]);
     
    16961696
    16971697  // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
    1698   for (int i=0;i<AtomCount;i++) {
     1698  for (int i=AtomCount;i--;) {
    16991699    PredecessorList[i] = NULL;
    17001700    ShortestPathList[i] = -1;
     
    17021702  }
    17031703  MinimumRingSize = new int[AtomCount];
    1704   for(int i=0;i<AtomCount;i++)
     1704  for(int i=AtomCount;i--;)
    17051705    MinimumRingSize[i] = AtomCount;
    17061706
     
    18911891      Free((void **)&Walker->ComponentNr, "molecule::InitComponentNumbers: **Walker->ComponentNr");
    18921892    Walker->ComponentNr = (int *) Malloc(sizeof(int)*NumberOfBondsPerAtom[Walker->nr], "molecule::InitComponentNumbers: *Walker->ComponentNr");
    1893     for (int i=0;i<NumberOfBondsPerAtom[Walker->nr];i++)
     1893    for (int i=NumberOfBondsPerAtom[Walker->nr];i--;)
    18941894      Walker->ComponentNr[i] = -1;
    18951895  }
     
    22612261
    22622262  // initialize mask list
    2263   for(int i=0;i<AtomCount;i++)
     2263  for(int i=AtomCount;i--;)
    22642264    AtomMask[i] = false;
    22652265 
     
    24142414  }
    24152415  SortIndex = (int *) Malloc(sizeof(int)*AtomCount, "molecule::FragmentMolecule: *SortIndex");
    2416   for(int i=0;i<AtomCount;i++)
     2416  for(int i=AtomCount;i--;)
    24172417    SortIndex[i] = -1;
    24182418  while (runner->next != elemente->end) { // go through every element
     
    25332533 
    25342534  // free the index lookup list
    2535   for (int i=0;i<FragmentCounter;i++)
     2535  for (int i=FragmentCounter;i--;)
    25362536    Free((void **)&ListOfLocalAtoms[i], "molecule::FragmentMolecule - *ListOfLocalAtoms[]");
    25372537  Free((void **)&ListOfLocalAtoms, "molecule::FragmentMolecule - **ListOfLocalAtoms");
     
    26492649
    26502650  *out << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl;
    2651   for(int i=0;i<AtomCount;i++)
     2651  for(int i=AtomCount;i--;)
    26522652    OrderArray[i] = 0;
    26532653  line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
    26542654  file.open(line.str().c_str());
    26552655  if (file != NULL) {
    2656     for (int i=0;i<AtomCount;i++) // initialise with 0
     2656    for (int i=AtomCount;i--;) // initialise with 0
    26572657      OrderArray[i] = 0;
    26582658    while (!file.eof()) { // parse from file
     
    26972697  *out << Verbose(2) << "(Re-)Allocating memory." << endl;
    26982698  if (ListOfBondsPerAtom != NULL) {
    2699     for(int i=0;i<AtomCount;i++)
     2699    for(int i=AtomCount;i--;)
    27002700      Free((void **)&ListOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom[i]");
    27012701    Free((void **)&ListOfBondsPerAtom, "molecule::CreateListOfBondsPerAtom: ListOfBondsPerAtom");
     
    27072707
    27082708  // reset bond counts per atom
    2709   for(int i=0;i<AtomCount;i++)
     2709  for(int i=AtomCount;i--;)
    27102710    NumberOfBondsPerAtom[i] = 0;
    27112711  // count bonds per atom
     
    27162716    NumberOfBondsPerAtom[Binder->rightatom->nr]++;
    27172717  }
    2718   // allocate list of bonds per atom
    2719   for(int i=0;i<AtomCount;i++)
     2718  for(int i=AtomCount;i--;) {
     2719    // allocate list of bonds per atom
    27202720    ListOfBondsPerAtom[i] = (bond **) Malloc(sizeof(bond *)*NumberOfBondsPerAtom[i], "molecule::CreateListOfBondsPerAtom: **ListOfBondsPerAtom[]");
    2721   // clear the list again, now each NumberOfBondsPerAtom marks current free field
    2722   for(int i=0;i<AtomCount;i++)
     2721    // clear the list again, now each NumberOfBondsPerAtom marks current free field
    27232722    NumberOfBondsPerAtom[i] = 0;
     2723  }
    27242724  // fill the list
    27252725  Binder = first;
     
    27742774
    27752775  // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
    2776   for (int i=0;i<AtomCount;i++) {
     2776  for (int i=AtomCount;i--;) {
    27772777    PredecessorList[i] = NULL;
    27782778    ShortestPathList[i] = -1;
     
    28902890  // reset parent list
    28912891  *out << Verbose(3) << "Resetting ParentList." << endl;
    2892   for (int i=0;i<Father->AtomCount;i++)
     2892  for (int i=Father->AtomCount;i--;)
    28932893    ParentList[i] = NULL;
    28942894 
     
    29722972 
    29732973  Leaf->BondDistance = BondDistance;
    2974   for(int i=0;i<NDIM*2;i++)
     2974  for(int i=NDIM*2;i--;)
    29752975    Leaf->cell_size[i] = cell_size[i];
    29762976
    29772977  // initialise SonList (indicates when we need to replace a bond with hydrogen instead)
    2978   for(int i=0;i<AtomCount;i++)
     2978  for(int i=AtomCount;i--;)
    29792979    SonList[i] = NULL;
    29802980
     
    32983298  // initialised touched list (stores added atoms on this level)
    32993299  *out << Verbose(1+verbosity) << "Clearing touched list." << endl;
    3300   for (TouchedIndex=0;TouchedIndex<=SubOrder;TouchedIndex++)  // empty touched list
     3300  for (TouchedIndex=SubOrder+1;TouchedIndex--;)  // empty touched list
    33013301    TouchedList[TouchedIndex] = -1;
    33023302  TouchedIndex = 0;
     
    33073307    // count the set bit of i
    33083308    bits = 0;
    3309     for (int j=0;j<SetDimension;j++)
     3309    for (int j=SetDimension;j--;)
    33103310      bits += (i & (1 << j)) >> j;
    33113311     
     
    33393339        while (Binder->next != FragmentSearch->BondsPerSPList[2*SP+1]) {                // compare to end node of this level
    33403340          Binder = Binder->next;
    3341           for (int k=0;k<TouchedIndex;k++) {
     3341          for (int k=TouchedIndex;k--;) {
    33423342            if (Binder->Contains(TouchedList[k]))   // if we added this very endpiece
    33433343              SubSetDimension++;
     
    34193419  int Counter = FragmentSearch.FragmentCounter;
    34203420
    3421   for (int i=0;i<AtomCount;i++) {
     3421  for (int i=AtomCount;i--;) {
    34223422    PredecessorList[i] = NULL;
    34233423  }
     
    34313431  FragmentSearch.ShortestPathList[RootKeyNr] = 0;
    34323432  // prepare the atom stack counters (number of atoms with certain SP on stack)
    3433   for (int i=0;i<Order;i++)
     3433  for (int i=Order;i--;)
    34343434    NumberOfAtomsSPLevel[i] = 0;
    34353435  NumberOfAtomsSPLevel[0] = 1;  // for root
     
    35283528  }
    35293529 
    3530   // creating fragments with the found edge sets
     3530  // creating fragments with the found edge sets  (may be done in reverse order, faster)
    35313531  SP = 0;
    3532   for(int i=0;i<Order;i++) { // sum up all found edges
     3532  for(int i=Order;i--;) { // sum up all found edges
    35333533    Binder = FragmentSearch.BondsPerSPList[2*i];
    35343534    while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
     
    35763576  // free'ing the bonds lists
    35773577  *out << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl;
    3578   for(int i=0;i<Order;i++) {
     3578  for(int i=Order;i--;) {
    35793579    *out << Verbose(1) << "Current SP level is " << i << ": ";
    35803580    Binder = FragmentSearch.BondsPerSPList[2*i];
     
    36253625  while (flag) {
    36263626    // remove bonds that are beyond bonddistance
    3627     for(int i=0;i<NDIM;i++)
     3627    for(int i=NDIM;i--;)
    36283628      TranslationVector.x[i] = 0.;
    36293629    // scan all bonds
     
    36323632    while ((!flag) && (Binder->next != last)) {
    36333633      Binder = Binder->next;
    3634       for (int i=0;i<NDIM;i++) {
     3634      for (int i=NDIM;i--;) {
    36353635        tmp = fabs(Binder->leftatom->x.x[i] - Binder->rightatom->x.x[i]);
    36363636        //*out << Verbose(3) << "Checking " << i << "th distance of " << *Binder->leftatom << " to " << *Binder->rightatom << ": " << tmp << "." << endl;
     
    36463646    if (flag) {
    36473647      // create translation vector from their periodically modified distance
    3648       for (int i=0;i<NDIM;i++) {
     3648      for (int i=NDIM;i--;) {
    36493649        tmp = Binder->leftatom->x.x[i] - Binder->rightatom->x.x[i];
    36503650        if (fabs(tmp) > BondDistance)
     
    36563656      //*out << endl;
    36573657      // apply to all atoms of first component via BFS
    3658       for (int i=0;i<AtomCount;i++)
     3658      for (int i=AtomCount;i--;)
    36593659        ColorList[i] = white;
    36603660      AtomStack->Push(Binder->leftatom);
     
    38323832  FragmentSearch.FragmentSet = new KeySet;
    38333833  FragmentSearch.Root = FindAtom(RootKeyNr);
    3834   for (int i=0;i<AtomCount;i++) {
     3834  for (int i=AtomCount;i--;) {
    38353835    FragmentSearch.Labels[i] = -1;
    38363836    FragmentSearch.ShortestPathList[i] = -1;
     
    38653865      FragmentSearch.BondsPerSPList = (bond **) Malloc(sizeof(bond *)*Order*2, "molecule::PowerSetGenerator: ***BondsPerSPList");
    38663866      FragmentSearch.BondsPerSPCount = (int *) Malloc(sizeof(int)*Order, "molecule::PowerSetGenerator: *BondsPerSPCount");
    3867       for (int i=0;i<Order;i++) {
     3867      for (int i=Order;i--;) {
    38683868        FragmentSearch.BondsPerSPList[2*i] = new bond();    // start node
    38693869        FragmentSearch.BondsPerSPList[2*i+1] = new bond();  // end node
     
    39333933      // free Order-dependent entries of UniqueFragments structure for next loop cycle
    39343934      Free((void **)&FragmentSearch.BondsPerSPCount, "molecule::PowerSetGenerator: *BondsPerSPCount");
    3935       for (int i=0;i<Order;i++) {
     3935      for (int i=Order;i--;) {
    39363936        delete(FragmentSearch.BondsPerSPList[2*i]);
    39373937        delete(FragmentSearch.BondsPerSPList[2*i+1]);
     
    39893989 * \return <0, \a *a less than \a *b, ==0 if equal, >0 \a *a greater than \a *b
    39903990 */
    3991 int CompareDoubles (const void * a, const void * b)
     3991inline int CompareDoubles (const void * a, const void * b)
    39923992{
    39933993  if (*(double *)a > *(double *)b)
     
    40404040  /// -# ElementsInMolecule
    40414041  if (result) {
    4042     for (flag=0;flag<MAX_ELEMENTS;flag++) {
     4042    for (flag=MAX_ELEMENTS;flag--;) {
    40434043      //*out << Verbose(5) << "Element " <<  flag << ": " << ElementsInMolecule[flag] << " <-> " << OtherMolecule->ElementsInMolecule[flag] << "." << endl;
    40444044      if (ElementsInMolecule[flag] != OtherMolecule->ElementsInMolecule[flag])
     
    40744074    while (Walker->next != end) {
    40754075      Walker = Walker->next;
    4076     //for (i=0;i<AtomCount;i++) {
    40774076      Distances[Walker->nr] = CenterOfGravity.Distance(&Walker->x);
    40784077    }
     
    40914090    PermutationMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    40924091    *out << Verbose(5) << "Combining Permutation Maps" << endl;
    4093     for(int i=0;i<AtomCount;i++)
     4092    for(int i=AtomCount;i--;)
    40944093      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    40954094   
     
    41364135  *out << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
    41374136  int *AtomicMap = (int *) Malloc(sizeof(int)*AtomCount, "molecule::GetAtomicMap: *AtomicMap");  //Calloc
    4138   for (int i=0;i<AtomCount;i++)
     4137  for (int i=AtomCount;i--;)
    41394138    AtomicMap[i] = -1;
    41404139  if (OtherMolecule == this) {  // same molecule
    4141     for (int i=0;i<AtomCount;i++) // no need as -1 means already that there is trivial correspondence
     4140    for (int i=AtomCount;i--;) // no need as -1 means already that there is trivial correspondence
    41424141      AtomicMap[i] = i;
    41434142    *out << Verbose(4) << "Map is trivial." << endl;
  • src/molecules.hpp

    r6097ea r7f3b9d  
    457457  void Load(char *filename, periodentafel *periode, molecule *mol);
    458458  void LoadOld(char *filename, periodentafel *periode, molecule *mol);
    459   void RetrieveConfigPathAndName(char * filename);
     459  void RetrieveConfigPathAndName(string filename);
    460460  bool Save(ofstream *file, periodentafel *periode, molecule *mol) const;
    461461  void Edit(molecule *mol);
  • src/parser.cpp

    r6097ea r7f3b9d  
    6464MatrixContainer::~MatrixContainer() {
    6565  if (Matrix != NULL) {
    66     for(int i=0;i<MatrixCounter;i++) {
     66    for(int i=MatrixCounter;i--;) {
    6767      if (RowCounter != NULL) {
    68           for(int j=0;j<=RowCounter[i];j++)
     68          for(int j=RowCounter[i]+1;j--;)
    6969            Free((void **)&Matrix[i][j], "MatrixContainer::~MatrixContainer: *Matrix[][]");
    7070        Free((void **)&Matrix[i], "MatrixContainer::~MatrixContainer: **Matrix[]");
     
    7272    }
    7373    if ((RowCounter != NULL) && (Matrix[MatrixCounter] != NULL))
    74       for(int j=0;j<=RowCounter[MatrixCounter];j++)
     74      for(int j=RowCounter[MatrixCounter]+1;j--;)
    7575        Free((void **)&Matrix[MatrixCounter][j], "MatrixContainer::~MatrixContainer: *Matrix[MatrixCounter][]");
    7676    if (MatrixCounter != 0)
     
    7979  }
    8080  if (Indices != NULL)
    81     for(int i=0;i<=MatrixCounter;i++) {
     81    for(int i=MatrixCounter+1;i--;) {
    8282      Free((void **)&Indices[i], "MatrixContainer::~MatrixContainer: *Indices[]");
    8383    }
     
    123123  Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: ***Matrix"); // one more each for the total molecule
    124124  RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: *RowCounter");
    125   for(int i=0;i<=MatrixCounter;i++) {
     125  for(int i=MatrixCounter+1;i--;) {
    126126    Matrix[i] = NULL;
    127127    RowCounter[i] = -1;
    128128  }
    129   for(int i=0;i<=MatrixCounter;i++) {
     129  for(int i=MatrixCounter+1;i--;) {
    130130    // open matrix file
    131131    stringstream line;
     
    143143    }
    144144    // skip some initial lines
    145     for (int m=0;m<=skiplines;m++)
     145    for (int m=skiplines+1;m--;)
    146146      input.getline(Header, 1023);
    147147    // scan header for number of columns
    148148    line.str(Header);
    149     for(int k=0;k<skipcolumns;k++)
     149    for(int k=skipcolumns;k--;)
    150150      line >> Header;
    151151    //cout << line.str() << endl;
     
    173173    input.clear();
    174174    input.seekg(ios::beg);
    175     for (int m=0;m<=skiplines;m++)
     175    for (int m=skiplines+1;m--;)
    176176      input.getline(Header, 1023);    // skip header
    177177    line.str(Header);
    178     for(int k=0;k<skipcolumns;k++)  // skip columns in header too
     178    for(int k=skipcolumns;k--;)  // skip columns in header too
    179179      line >> filename;
    180180    strncpy(Header, line.str().c_str(), 1023); 
     
    184184      stringstream line(filename);
    185185      //cout << "Matrix at level " << j << ":";// << filename << endl;
    186       for(int k=0;k<skipcolumns;k++)
     186      for(int k=skipcolumns;k--;)
    187187        line >> filename;
    188188      for(int k=0;(k<ColumnCounter) && (!line.eof());k++) {
     
    193193    }
    194194    Matrix[i][ RowCounter[i] ] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[RowCounter[i]][]");
    195     for(int j=0;j<ColumnCounter;j++)
     195    for(int j=ColumnCounter;j--;)
    196196      Matrix[i][ RowCounter[i] ][j] = 0.;
    197197    input.close();
     
    216216  Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: ***Matrix"); // one more each for the total molecule
    217217  RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: *RowCounter");
    218   for(int i=0;i<=MatrixCounter;i++) {
     218  for(int i=MatrixCounter+1;i--;) {
    219219    RowCounter[i] = RCounter[i];
    220220    Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseMatrix: **Matrix[]"); 
    221     for(int j=0;j<=RowCounter[i];j++) {
     221    for(int j=RowCounter[i]+1;j--;) {
    222222      Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[][]");
    223       for(int k=0;k<ColumnCounter;k++)
     223      for(int k=ColumnCounter;k--;)
    224224        Matrix[i][j][k] = 0.;
    225225    }
     
    233233bool MatrixContainer::ResetMatrix()
    234234{
    235   for(int i=0;i<=MatrixCounter;i++)
    236     for(int j=0;j<=RowCounter[i];j++)
    237       for(int k=0;k<ColumnCounter;k++)
     235  for(int i=MatrixCounter+1;i--;)
     236    for(int j=RowCounter[i]+1;j--;)
     237      for(int k=ColumnCounter;k--;)
    238238        Matrix[i][j][k] = 0.;
    239239   return true;
     
    247247bool MatrixContainer::SetLastMatrix(double value, int skipcolumns)
    248248{
    249   for(int j=0;j<=RowCounter[MatrixCounter];j++)
     249  for(int j=RowCounter[MatrixCounter]+1;j--;)
    250250    for(int k=skipcolumns;k<ColumnCounter;k++)
    251251      Matrix[MatrixCounter][j][k] = value;
     
    260260bool MatrixContainer::SetLastMatrix(double **values, int skipcolumns)
    261261{
    262   for(int j=0;j<=RowCounter[MatrixCounter];j++)
     262  for(int j=RowCounter[MatrixCounter]+1;j--;)
    263263    for(int k=skipcolumns;k<ColumnCounter;k++)
    264264      Matrix[MatrixCounter][j][k] = values[j][k];
     
    301301              }
    302302              if (Order == SubOrder) { // equal order is always copy from Energies
    303                 for(int l=0;l<ColumnCounter;l++) // then adds/subtract each column
     303                for(int l=ColumnCounter;l--;) // then adds/subtract each column
    304304                  Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][m][l] += MatrixValues.Matrix[ KeySet.OrderSet[SubOrder][j] ][k][l];
    305305              } else {
    306                 for(int l=0;l<ColumnCounter;l++)
     306                for(int l=ColumnCounter;l--;)
    307307                  Matrix[ KeySet.OrderSet[Order][CurrentFragment] ][m][l] -= Matrix[ KeySet.OrderSet[SubOrder][j] ][k][l];
    308308              }
     
    392392  cout << "Parsing energy indices." << endl;
    393393  Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "EnergyMatrix::ParseIndices: **Indices");
    394   for(int i=0;i<=MatrixCounter;i++) {
     394  for(int i=MatrixCounter+1;i--;) {
    395395    Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "EnergyMatrix::ParseIndices: *Indices[]");
    396     for(int j=0;j<RowCounter[i];j++)
     396    for(int j=RowCounter[i];j--;)
    397397      Indices[i][j] = j;
    398398  }
     
    410410{
    411411  // sum energy
    412   for(int i=0;i<KeySet.FragmentsPerOrder[Order];i++)
    413     for(int j=0;j<RowCounter[ KeySet.OrderSet[Order][i] ];j++)
    414       for(int k=0;k<ColumnCounter;k++)
     412  for(int i=KeySet.FragmentsPerOrder[Order];i--;)
     413    for(int j=RowCounter[ KeySet.OrderSet[Order][i] ];j--;)
     414      for(int k=ColumnCounter;k--;)
    415415        Matrix[MatrixCounter][j][k] += Fragments.Matrix[ KeySet.OrderSet[Order][i] ][j][k];
    416416  return true;
     
    455455  }
    456456  Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]");
    457   for(int j=0;j<RowCounter[MatrixCounter];j++) {
     457  for(int j=RowCounter[MatrixCounter];j--;) {
    458458    Indices[MatrixCounter][j] = j;
    459459  }
     
    503503 */
    504504KeySetsContainer::~KeySetsContainer() {
    505   for(int i=0;i<FragmentCounter;i++)
     505  for(int i=FragmentCounter;i--;)
    506506    Free((void **)&KeySets[i], "KeySetsContainer::~KeySetsContainer: *KeySets[]");
    507   for(int i=0;i<Order;i++)
     507  for(int i=Order;i--;)
    508508    Free((void **)&OrderSet[i], "KeySetsContainer::~KeySetsContainer: *OrderSet[]");
    509509  Free((void **)&KeySets, "KeySetsContainer::~KeySetsContainer: **KeySets");
     
    528528  cout << "Parsing key sets." << endl;
    529529  KeySets = (int **) Malloc(sizeof(int *)*FragmentCounter, "KeySetsContainer::ParseKeySets: **KeySets");
    530   for(int i=0;i<FragmentCounter;i++)
     530  for(int i=FragmentCounter;i--;)
    531531    KeySets[i] = NULL;
    532532  line << name << FRAGMENTPREFIX << KEYSETFILE;
     
    543543    // parse the values
    544544    KeySets[i] = (int *) Malloc(sizeof(int)*AtomCounter[i], "KeySetsContainer::ParseKeySets: *KeySets[]");
    545     for(int j=0;j<AtomCounter[i];j++)
     545    for(int j=AtomCounter[i];j--;)
    546546      KeySets[i][j] = -1;
    547547    FragmentNumber = FixedDigitNumber(FragmentCounter, i);
     
    570570  // scan through all to determine order
    571571  Order=0;
    572   for(int i=0;i<FragmentCounter;i++) {
     572  for(int i=FragmentCounter;i--;) {
    573573    Counter=0;
    574     for(int j=0;j<AtomCounter[i];j++)
     574    for(int j=AtomCounter[i];j--;)
    575575      if (KeySets[i][j] != -1)
    576576        Counter++;
     
    582582  // scan through all to determine fragments per order
    583583  FragmentsPerOrder = (int *) Malloc(sizeof(int)*Order, "KeySetsContainer::ParseManyBodyTerms: *FragmentsPerOrder");
    584   for(int i=0;i<Order;i++)
     584  for(int i=Order;i--;)
    585585    FragmentsPerOrder[i] = 0;
    586   for(int i=0;i<FragmentCounter;i++) {
     586  for(int i=FragmentCounter;i--;) {
    587587    Counter=0;
    588     for(int j=0;j<AtomCounter[i];j++)
     588    for(int j=AtomCounter[i];j--;)
    589589      if (KeySets[i][j] != -1)
    590590        Counter++;
     
    596596  // scan through all to gather indices to each order set
    597597  OrderSet = (int **) Malloc(sizeof(int *)*Order, "KeySetsContainer::ParseManyBodyTerms: **OrderSet");
    598   for(int i=0;i<Order;i++)
     598  for(int i=Order;i--;)
    599599    OrderSet[i] = (int *) Malloc(sizeof(int)*FragmentsPerOrder[i], "KeySetsContainer::ParseManyBodyTermsKeySetsContainer::ParseManyBodyTerms: *OrderSet[]");
    600   for(int i=0;i<Order;i++)
     600  for(int i=Order;i--;)
    601601    FragmentsPerOrder[i] = 0;
    602   for(int i=0;i<FragmentCounter;i++) {
     602  for(int i=FragmentCounter;i--;) {
    603603    Counter=0;
    604     for(int j=0;j<AtomCounter[i];j++)
     604    for(int j=AtomCounter[i];j--;)
    605605      if (KeySets[i][j] != -1)
    606606        Counter++;
     
    632632  if ((GreaterSet < 0) || (SmallerSet < 0) || (GreaterSet > FragmentCounter) || (SmallerSet > FragmentCounter)) // index out of bounds
    633633    return false;
    634   for(int i=0;i<AtomCounter[SmallerSet];i++) {
     634  for(int i=AtomCounter[SmallerSet];i--;) {
    635635    intermediate = false;
    636     for (int j=0;j<AtomCounter[GreaterSet];j++)
     636    for (int j=AtomCounter[GreaterSet];j--;)
    637637      intermediate = (intermediate || ((KeySets[SmallerSet][i] == KeySets[GreaterSet][j]) || (KeySets[SmallerSet][i] == -1)));
    638638    result = result && intermediate;
  • src/stackclass.hpp

    r6097ea r7f3b9d  
    251251template <typename T> void StackClass<T>::ClearStack()
    252252{
    253   for(int i=0;i<EntryCount; i++)
     253  for(int i=EntryCount; i--;)
    254254    StackList[i] = NULL;
    255255  CurrentFirstEntry = 0;
  • src/vector.cpp

    r6097ea r7f3b9d  
    2525{
    2626  double res = 0.;
    27   for (int i=0;i<NDIM;i++)
     27  for (int i=NDIM;i--;)
    2828    res += (x[i]-y->x[i])*(x[i]-y->x[i]);
    2929  return (res); 
     
    5555        // create the translation vector
    5656        TranslationVector.Zero();
    57         for (int i=0;i<NDIM;i++)
     57        for (int i=NDIM;i--;)
    5858          TranslationVector.x[i] = (double)N[i];
    5959        TranslationVector.MatrixMultiplication(matrix);
     
    8484  TestVector.CopyVector(this);
    8585  TestVector.InverseMatrixMultiplication(matrix);
    86   for(int i=0;i<NDIM;i++) { // correct periodically
     86  for(int i=NDIM;i--;) { // correct periodically
    8787    if (TestVector.x[i] < 0) {  // get every coefficient into the interval [0,1)
    8888      TestVector.x[i] += ceil(TestVector.x[i]);
     
    106106{
    107107  double res = 0.;
    108   for (int i=0;i<NDIM;i++)
     108  for (int i=NDIM;i--;)
    109109    res += x[i]*y->x[i];
    110110  return (res); 
     
    126126{
    127127  double res = 0.;
    128   for (int i=0;i<NDIM;i++)
     128  for (int i=NDIM;i--;)
    129129    res += this->x[i]*this->x[i];
    130130  return (sqrt(res)); 
     
    136136{
    137137  double res = 0.;
    138   for (int i=0;i<NDIM;i++)
     138  for (int i=NDIM;i--;)
    139139    res += this->x[i]*this->x[i];
    140140  res = 1./sqrt(res);
     
    146146void vector::Zero()
    147147{
    148   for (int i=0;i<NDIM;i++)
     148  for (int i=NDIM;i--;)
    149149    this->x[i] = 0.;
    150150};
     
    259259void vector::Scale(double **factor)
    260260{
    261   for (int i=0;i<NDIM;i++)
     261  for (int i=NDIM;i--;)
    262262    x[i] *= (*factor)[i];
    263263};
     
    265265void vector::Scale(double *factor)
    266266{
    267   for (int i=0;i<NDIM;i++)
     267  for (int i=NDIM;i--;)
    268268    x[i] *= *factor;
    269269};
     
    271271void vector::Scale(double factor)
    272272{
    273   for (int i=0;i<NDIM;i++)
     273  for (int i=NDIM;i--;)
    274274    x[i] *= factor;
    275275};
     
    280280void vector::Translate(const vector *trans)
    281281{
    282   for (int i=0;i<NDIM;i++)
     282  for (int i=NDIM;i--;)
    283283    x[i] += trans->x[i];
    284284};
     
    295295  C.x[2] = M[2]*x[0]+M[5]*x[1]+M[8]*x[2];
    296296  // transfer the result into this
    297   for (int i=0;i<NDIM;i++)
     297  for (int i=NDIM;i--;)
    298298    x[i] = C.x[i];
    299299};
     
    327327    C.x[2] = B[2]*x[0]+B[5]*x[1]+B[8]*x[2];
    328328    // transfer the result into this
    329     for (int i=0;i<NDIM;i++)
     329    for (int i=NDIM;i--;)
    330330      x[i] = C.x[i];
    331331  } else {
     
    344344void vector::LinearCombinationOfVectors(const vector *x1, const vector *x2, const vector *x3, double *factors)
    345345{
    346   for(int i=0;i<NDIM;i++)
     346  for(int i=NDIM;i--;)
    347347    x[i] = factors[0]*x1->x[i] + factors[1]*x2->x[i] + factors[2]*x3->x[i];
    348348};
     
    359359  Output((ofstream *)&cout);
    360360  cout << "\t";
    361   for (int i=0;i<NDIM;i++)
     361  for (int i=NDIM;i--;)
    362362    x[i] -= 2.*projection*n->x[i];
    363363  cout << "Projected vector: ";
     
    446446  x1.Scale(x1.Projection(this));
    447447  SubtractVector(&x1);
    448   for (int i=0;i<NDIM;i++)
     448  for (int i=NDIM;i--;)
    449449          result = result || (fabs(x[i]) > MYEPSILON);
    450450
     
    468468  vector->Output((ofstream *)&cout);
    469469  cout << endl;
    470   for (j=0;j<NDIM;j++)
     470  for (j=NDIM;j--;)
    471471    Components[j] = -1;
    472472  // find two components != 0
     
    537537         par.num = num;
    538538       
    539          for (i=0;i<NDIM;i++)
     539         for (i=NDIM;i--;)
    540540                gsl_vector_set(x, i, (vectors[0]->x[i] - vectors[1]->x[i])/2.);
    541541         
     
    573573   while (status == GSL_CONTINUE && iter < 100);
    574574 
    575   for (i=0;i<(size_t)np;i++)
     575  for (i=(size_t)np;i--;)
    576576    this->x[i] = gsl_vector_get(s->x, i);
    577577   gsl_vector_free(x);
     
    587587void vector::AddVector(const vector *y)
    588588{
    589   for (int i=0;i<NDIM;i++)
     589  for (int i=NDIM;i--;)
    590590    this->x[i] += y->x[i];
    591591}
     
    596596void vector::SubtractVector(const vector *y)
    597597{
    598   for (int i=0;i<NDIM;i++)
     598  for (int i=NDIM;i--;)
    599599    this->x[i] -= y->x[i];
    600600}
     
    605605void vector::CopyVector(const vector *y)
    606606{
    607   for (int i=0;i<NDIM;i++)
     607  for (int i=NDIM;i--;)
    608608    this->x[i] = y->x[i];
    609609}
     
    783783    cout << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n";
    784784    // apply sign matrix
    785     for (j=0;j<NDIM;j++)
     785    for (j=NDIM;j--;)
    786786      x[j] *= sign[j];
    787787    // calculate angle and check
     
    792792    }
    793793    // unapply sign matrix (is its own inverse)
    794     for (j=0;j<NDIM;j++)
     794    for (j=NDIM;j--;)
    795795      x[j] *= sign[j];
    796796  }
  • src/verbose.cpp

    r6097ea r7f3b9d  
    77ostream& Verbose::print (ostream &ost) const
    88{
    9   for (int i=0;i<Verbosity;i++)
     9  for (int i=Verbosity;i--;)
    1010    ost.put('\t');
    1111  //cout << "Verbose(.) called." << endl;
Note: See TracChangeset for help on using the changeset viewer.