Changeset d067d45 for src/helpers.cpp


Ignore:
Timestamp:
Jul 23, 2009, 1:45:24 PM (16 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, Candidate_v1.7.0, 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:
51c910
Parents:
ce5ac3 (diff), 437922 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Frederik Heber <heber@…> (07/23/09 12:34:47)
git-committer:
Frederik Heber <heber@…> (07/23/09 13:45:24)
Message:

Merge branch 'MultipleMolecules'

Conflicts:

molecuilder/src/analyzer.cpp
molecuilder/src/atom.cpp
molecuilder/src/boundary.cpp
molecuilder/src/boundary.hpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/datacreator.hpp
molecuilder/src/helpers.cpp
molecuilder/src/joiner.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/molecules.cpp
molecuilder/src/molecules.hpp
molecuilder/src/parser.cpp
molecuilder/src/parser.hpp
molecuilder/src/vector.cpp
molecuilder/src/verbose.cpp

merges:

compilation fixes:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/helpers.cpp

    rce5ac3 rd067d45  
    11/** \file helpers.cpp
    22 *
    3  * Implementation of some auxiliary functions for memory dis-/allocation and so on 
     3 * Implementation of some auxiliary functions for memory dis-/allocation and so on
    44 */
    55
     
    1515double ask_value(const char *text)
    1616{
    17   double test = 0.1439851348959832147598734598273456723948652983045928346598365;
    18   do {
    19     cout << Verbose(0) << text;
    20     cin >> test;
    21   } while (test == 0.1439851348959832147598734598273456723948652983045928346598365);
    22   return test;   
     17        double test = 0.1439851348959832147598734598273456723948652983045928346598365;
     18        do {
     19                cout << Verbose(0) << text;
     20                cin >> test;
     21        } while (test == 0.1439851348959832147598734598273456723948652983045928346598365);
     22        return test;
    2323};
    2424
     
    2929#ifdef HAVE_DEBUG
    3030void debug_in(const char *output, const char *file, const int line) {
    31   if (output) fprintf(stderr,"DEBUG: in %s at line %i: %s\n", file, line, output);
     31        if (output) fprintf(stderr,"DEBUG: in %s at line %i: %s\n", file, line, output);
    3232}
    3333#else
    34 void debug_in(const char *output, const char *file, const int line) {}  // print nothing
     34void debug_in(const char *output, const char *file, const int line) {}  // print nothing
    3535#endif
    3636
     
    4040 * \return pointer to memory range
    4141 */
    42 void * Malloc(size_t size, const char* output) 
     42void * Malloc(size_t size, const char* output)
    4343{
    44   void *buffer = NULL;
    45   buffer = (void *)malloc(size); // alloc
    46   if (buffer == NULL)
    47     cout << Verbose(0) << "Malloc failed - pointer is NULL: " << output << endl;
    48   return(buffer);
     44        void *buffer = NULL;
     45        buffer = (void *)malloc(size); // alloc
     46        if (buffer == NULL)
     47                cout << Verbose(0) << "Malloc failed - pointer is NULL: " << output << endl;
     48        return(buffer);
    4949};
    5050
     
    5454 * \return pointer to memory range
    5555 */
    56 void * Calloc(size_t size, const char* output) 
     56void * Calloc(size_t size, const char* output)
    5757{
    58   void *buffer = NULL;
    59   buffer = (void *)calloc(size, (size_t)0); // alloc
    60   if (buffer == NULL)
    61     cout << Verbose(0) << "Calloc failed - pointer is NULL: " << output << endl;
    62   return(buffer);
     58        void *buffer = NULL;
     59        buffer = (void *)calloc(size, (size_t)0); // alloc
     60        if (buffer == NULL)
     61                cout << Verbose(0) << "Calloc failed - pointer is NULL: " << output << endl;
     62        return(buffer);
    6363};
    6464
     
    6969 * \return pointer to memory range
    7070 */
    71 void * ReAlloc(void * OldPointer, size_t size, const char* output) 
     71void * ReAlloc(void * OldPointer, size_t size, const char* output)
    7272{
    7373  void *buffer = NULL;
     
    8686 * \param *output message if free fails
    8787 */
    88 void Free(void ** buffer, const char* output) 
     88void Free(void ** buffer, const char* output)
    8989{
    90   if (*buffer == NULL) {
    91     //cout << Verbose(5) << "Free not necesary: " << output << endl;
    92   } else {
    93     free(*buffer);
    94     *buffer = NULL;
    95   }
     90        if (*buffer == NULL) {
     91                //cout << Verbose(5) << "Free not necesary: " << output << endl;
     92        } else {
     93                free(*buffer);
     94                *buffer = NULL;
     95        }
    9696};
    9797
     
    101101 * \return pointer to string array
    102102 */
    103 char* MallocString(size_t size, const char* output) 
     103char* MallocString(size_t size, const char* output)
    104104{
    105   size_t i;
    106   char *buffer;
    107   buffer = (char *)malloc(sizeof(char) * (size+1)); // alloc
    108   if (buffer == NULL)
    109     cout << Verbose(0) << output << endl;
    110   for (i=size;i--;)  // reset
    111     buffer[i] = i % 2 == 0 ? 'p': 'c';
    112   buffer[size] = '\0'; // and set length marker on its end
    113   return(buffer);
     105        size_t i;
     106        char *buffer;
     107        buffer = (char *)malloc(sizeof(char) * (size+1)); // alloc
     108        if (buffer == NULL)
     109                cout << Verbose(0) << output << endl;
     110        for (i=size;i--;)       // reset
     111                buffer[i] = i % 2 == 0 ? 'p': 'c';
     112        buffer[size] = '\0'; // and set length marker on its end
     113        return(buffer);
    114114}
    115115
     
    121121void bound(double *b, double lower_bound, double upper_bound)
    122122{
    123   double step = (upper_bound - lower_bound);
    124   while (*b >= upper_bound)
    125     *b -= step;   
    126   while (*b < lower_bound)
    127     *b += step;   
    128 }; 
     123        double step = (upper_bound - lower_bound);
     124        while (*b >= upper_bound)
     125                *b -= step;
     126        while (*b < lower_bound)
     127                *b += step;
     128};
    129129
    130130/** Flips two doubles.
     
    134134void flip(double *x, double *y)
    135135{
    136   double tmp;
    137   tmp = *x;
    138   *x = *y;
    139   *y = tmp;
     136        double tmp;
     137        tmp = *x;
     138        *x = *y;
     139        *y = tmp;
    140140};
    141141
     
    147147int pot(int base, int n)
    148148{
    149   int res = 1;
    150   int j;
    151   for (j=n;j--;)
    152     res *= base;
    153   return res;
     149        int res = 1;
     150        int j;
     151        for (j=n;j--;)
     152                res *= base;
     153        return res;
    154154};
    155155
     
    161161char *FixedDigitNumber(const int FragmentNumber, const int digits)
    162162{
    163   char *returnstring;
    164   int number = FragmentNumber;
    165   int order = 0;
    166   while (number != 0) { // determine number of digits needed
    167     number = (int)floor(((double)number / 10.));
    168     order++;
    169     //cout << "Number is " << number << ", order is " << order << "." << endl;
    170   }
    171   // allocate string
    172   returnstring = (char *) Malloc(sizeof(char)*(order+2), "MoleculeListClass::CreateFragmentNumberForOutput: *returnstring");
    173   // terminate  and fill string array from end backward
    174   returnstring[order] = '\0';
    175   number = digits;
    176   for (int i=order;i--;) {
    177     returnstring[i] = '0' + (char)(number % 10);
    178     number = (int)floor(((double)number / 10.));
    179   }
    180   //cout << returnstring << endl;
    181   return returnstring;
     163        char *returnstring;
     164        int number = FragmentNumber;
     165        int order = 0;
     166        while (number != 0) { // determine number of digits needed
     167                number = (int)floor(((double)number / 10.));
     168                order++;
     169                //cout << "Number is " << number << ", order is " << order << "." << endl;
     170        }
     171        // allocate string
     172        returnstring = (char *) Malloc(sizeof(char)*(order+2), "FixedDigitNumber: *returnstring");
     173        // terminate    and fill string array from end backward
     174        returnstring[order] = '\0';
     175        number = digits;
     176        for (int i=order;i--;) {
     177                returnstring[i] = '0' + (char)(number % 10);
     178                number = (int)floor(((double)number / 10.));
     179        }
     180        //cout << returnstring << endl;
     181        return returnstring;
    182182};
    183183
     
    186186 * \return true - is a number, false - is not a valid number
    187187 */
    188 bool IsValidNumber( const char *string) 
     188bool IsValidNumber( const char *string)
    189189{
    190   int ptr = 0;
    191   if ((string[ptr] == '.') || (string[ptr] == '-')) // number may be negative or start with dot
    192     ptr++;
    193   if ((string[ptr] >= '0') && (string[ptr] <= '9'))
    194     return true;
    195   return false;
     190        int ptr = 0;
     191        if ((string[ptr] == '.') || (string[ptr] == '-')) // number may be negative or start with dot
     192                ptr++;
     193        if ((string[ptr] >= '0') && (string[ptr] <= '9'))
     194                return true;
     195        return false;
    196196};
    197197
Note: See TracChangeset for help on using the changeset viewer.