source: src/helpers.hpp@ ccd9f5

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
Last change on this file since ccd9f5 was c111db, checked in by Frederik Heber <heber@…>, 16 years ago

Merge branch 'new-delete-conversion' into CodeRefactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/helpers.cpp
molecuilder/src/helpers.hpp
molecuilder/src/memoryusageobserver.cpp

  • FIX: performCriticalExit() was declared static but not defined a such.
  • Merge was basically only due to libmolecuilder which was not used in CodeRefactoring branch before.
  • added ActOnAll Unit test to new unittests sub folder and to Makefile.am
  • Property mode set to 100755
File size: 4.0 KB
Line 
1/** \file helpers.hpp
2 *
3 * Declaration of some auxiliary functions for memory dis-/allocation and so on
4 */
5
6#ifndef HELPERS_HPP_
7#define HELPERS_HPP_
8
9using namespace std;
10
11/*********************************************** includes ***********************************/
12
13// include config.h
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include <fstream>
19
20#include "memoryallocator.hpp"
21
22/********************************************** helpful functions *********************************/
23
24// taken out of TREMOLO
25/*@-namechecks@*/
26#ifndef __GNUC__
27# undef __attribute__
28# define __attribute__(x)
29#endif
30/*@=namechecks@*/
31
32/* Behandelt aufgetretene Fehler. error ist der Fehlertyp(enum Errors)
33 void *SpecialData ist ein untypisierter Zeiger auf Spezielle Daten zur Fehlerbehandlung.
34 Man koennte auch noch einen Zeiger auf eine Funktion uebergeben */
35extern void /*@exits@*/ debug(const char *output);
36 //__attribute__ ((__return__));
37#define debug(data) debug_in((data), __FILE__, __LINE__)
38
39extern void /*@exits@*/ debug_in(const char *output,
40 const char *file, const int line);
41 //__attribute__ ((__return__));
42
43double ask_value(const char *text);
44bool check_bounds(double *x, double *cell_size);
45void bound(double *b, double lower_bound, double upper_bound);
46void flip(double *x, double *y);
47int pot(int base, int n);
48char *FixedDigitNumber(const int FragmentNumber, const int digits);
49bool IsValidNumber( const char *string);
50int CompareDoubles (const void * a, const void * b);
51double * ReturnFullMatrixforSymmetric(double *cell_size);
52static void performCriticalExit();
53
54/********************************************** helpful template functions *********************************/
55
56/** Creates a lookup table for true father's Atom::Nr -> atom ptr.
57 * \param *out output stream for debugging
58 * \param *start begin of chain list
59 * \paran *end end of chain list
60 * \param **Lookuptable pointer to return allocated lookup table (should be NULL on start)
61 * \param count optional predetermined count for table (otherwise we set the count to highest true father id)
62 * \return true - success, false - failure
63 */
64template <typename T> bool CreateFatherLookupTable(ofstream *out, T *start, T *end, T **&LookupTable, int count = 0)
65{
66 bool status = true;
67 T *Walker = NULL;
68 int AtomNo;
69
70 if (LookupTable != NULL) {
71 *out << "Pointer for Lookup table is not NULL! Aborting ..." <<endl;
72 return false;
73 }
74
75 // count them
76 if (count == 0) {
77 Walker = start;
78 while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
79 Walker = Walker->next;
80 count = (count < Walker->GetTrueFather()->nr) ? Walker->GetTrueFather()->nr : count;
81 }
82 }
83 if (count <= 0) {
84 *out << "Count of lookup list is 0 or less." << endl;
85 return false;
86 }
87
88 // allocat and fill
89 LookupTable = Malloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
90 if (LookupTable == NULL) {
91 cerr << "LookupTable memory allocation failed!" << endl;
92 status = false;
93 } else {
94 for (int i=0;i<count;i++)
95 LookupTable[i] = NULL;
96 Walker = start;
97 while (Walker->next != end) { // create a lookup table (Atom::nr -> atom) used as a marker table lateron
98 Walker = Walker->next;
99 AtomNo = Walker->GetTrueFather()->nr;
100 if ((AtomNo >= 0) && (AtomNo < count)) {
101 //*out << "Setting LookupTable[" << AtomNo << "] to " << *Walker << endl;
102 LookupTable[AtomNo] = Walker;
103 } else {
104 *out << "Walker " << *Walker << " exceeded range of nuclear ids [0, " << count << ")." << endl;
105 status = false;
106 break;
107 }
108 }
109 }
110
111 return status;
112};
113
114/** Frees a two-dimensional array.
115 * \param *ptr pointer to array
116 * \param dim first dim of array
117 */
118template <typename X> void Free2DArray(X **ptr, int dim)
119{
120 int i;
121 if (ptr != NULL) {
122 for(i=dim;i--;)
123 if (ptr[i] != NULL)
124 free(ptr[i]);
125 free(ptr);
126 }
127};
128
129template <typename T> void Increment(T *value, T inc)
130{
131 *value += inc;
132};
133
134template <typename T> void AbsoluteValue(T *value, T abs)
135{
136 *value = abs;
137};
138
139
140
141
142#endif /*HELPERS_HPP_*/
Note: See TracBrowser for help on using the repository browser.