/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /** \file helpers.cpp * * Implementation of some auxiliary functions for memory dis-/allocation and so on */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Helpers/helpers.hpp" #include "Helpers/fast_functions.hpp" #include "CodePatterns/Verbose.hpp" #include "CodePatterns/Log.hpp" #include /********************************************** helpful functions *********************************/ /** Output of a debug message to stderr. * \param *P Problem at hand, points to ParallelSimulationData#me * \param output output string */ #ifdef HAVE_DEBUG void debug_in(const char *output, const char *file, const int line) { if (output) fprintf(stderr,"DEBUG: in %s at line %i: %s\n", file, line, output); } #else void debug_in(const char *output, const char *file, const int line) {} // print nothing #endif /** Returns a string with \a i prefixed with 0s to match order of total number of molecules in digits. * \param FragmentNumber total number of fragments to determine necessary number of digits * \param digits number to create with 0 prefixed * \return allocated(!) char array with number in digits, ten base. */ char *FixedDigitNumber(const int FragmentNumber, const int digits) { char *returnstring; int number = FragmentNumber; int order = 0; while (number != 0) { // determine number of digits needed number = (int)floor(((double)number / 10.)); order++; //Log() << Verbose(0) << "Number is " << number << ", order is " << order << "." << endl; } // allocate string returnstring = new char[order + 2]; // terminate and fill string array from end backward returnstring[order] = '\0'; number = digits; for (int i=order;i--;) { returnstring[i] = '0' + (char)(number % 10); number = (int)floor(((double)number / 10.)); } //Log() << Verbose(0) << returnstring << endl; return returnstring; }; /** * Calls exit(255). */ void performCriticalExit() { exit(255); } sign_t sign(double value){ if(fabs(value)