[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[14de469] | 8 | /** \file helpers.cpp
|
---|
| 9 | *
|
---|
[6ac7ee] | 10 | * Implementation of some auxiliary functions for memory dis-/allocation and so on
|
---|
[14de469] | 11 | */
|
---|
| 12 |
|
---|
[bf3817] | 13 | // include config.h
|
---|
| 14 | #ifdef HAVE_CONFIG_H
|
---|
| 15 | #include <config.h>
|
---|
| 16 | #endif
|
---|
| 17 |
|
---|
[ad011c] | 18 | #include "CodePatterns/MemDebug.hpp"
|
---|
[14de469] | 19 |
|
---|
[952f38] | 20 | #include "Helpers/helpers.hpp"
|
---|
[0a4f7f] | 21 | #include "Helpers/fast_functions.hpp"
|
---|
[ad011c] | 22 | #include "CodePatterns/Verbose.hpp"
|
---|
| 23 | #include "CodePatterns/Log.hpp"
|
---|
[6cd79d] | 24 |
|
---|
[986ed3] | 25 | #include <iostream>
|
---|
| 26 |
|
---|
[14de469] | 27 | /********************************************** helpful functions *********************************/
|
---|
| 28 |
|
---|
| 29 |
|
---|
[d3a46d] | 30 | /** Output of a debug message to stderr.
|
---|
| 31 | * \param *P Problem at hand, points to ParallelSimulationData#me
|
---|
| 32 | * \param output output string
|
---|
| 33 | */
|
---|
| 34 | #ifdef HAVE_DEBUG
|
---|
| 35 | void debug_in(const char *output, const char *file, const int line) {
|
---|
[042f82] | 36 | if (output) fprintf(stderr,"DEBUG: in %s at line %i: %s\n", file, line, output);
|
---|
[d3a46d] | 37 | }
|
---|
| 38 | #else
|
---|
[042f82] | 39 | void debug_in(const char *output, const char *file, const int line) {} // print nothing
|
---|
[d3a46d] | 40 | #endif
|
---|
[14de469] | 41 |
|
---|
[5034e1] | 42 |
|
---|
[14de469] | 43 | /** Returns a string with \a i prefixed with 0s to match order of total number of molecules in digits.
|
---|
| 44 | * \param FragmentNumber total number of fragments to determine necessary number of digits
|
---|
| 45 | * \param digits number to create with 0 prefixed
|
---|
| 46 | * \return allocated(!) char array with number in digits, ten base.
|
---|
| 47 | */
|
---|
| 48 | char *FixedDigitNumber(const int FragmentNumber, const int digits)
|
---|
| 49 | {
|
---|
[042f82] | 50 | char *returnstring;
|
---|
| 51 | int number = FragmentNumber;
|
---|
| 52 | int order = 0;
|
---|
| 53 | while (number != 0) { // determine number of digits needed
|
---|
| 54 | number = (int)floor(((double)number / 10.));
|
---|
| 55 | order++;
|
---|
[e138de] | 56 | //Log() << Verbose(0) << "Number is " << number << ", order is " << order << "." << endl;
|
---|
[042f82] | 57 | }
|
---|
| 58 | // allocate string
|
---|
[920c70] | 59 | returnstring = new char[order + 2];
|
---|
[042f82] | 60 | // terminate and fill string array from end backward
|
---|
| 61 | returnstring[order] = '\0';
|
---|
| 62 | number = digits;
|
---|
| 63 | for (int i=order;i--;) {
|
---|
| 64 | returnstring[i] = '0' + (char)(number % 10);
|
---|
| 65 | number = (int)floor(((double)number / 10.));
|
---|
| 66 | }
|
---|
[e138de] | 67 | //Log() << Verbose(0) << returnstring << endl;
|
---|
[042f82] | 68 | return returnstring;
|
---|
[14de469] | 69 | };
|
---|
| 70 |
|
---|
[21b9c3] | 71 | /**
|
---|
[920c70] | 72 | * Calls exit(255).
|
---|
[21b9c3] | 73 | */
|
---|
[6cd79d] | 74 | void performCriticalExit() {
|
---|
[21b9c3] | 75 | exit(255);
|
---|
| 76 | }
|
---|
[f80e20] | 77 |
|
---|
| 78 | sign_t sign(double value){
|
---|
| 79 | if(fabs(value)<MYEPSILON){
|
---|
| 80 | return Zero;
|
---|
| 81 | }
|
---|
| 82 | if(value<0)
|
---|
| 83 | return Minus;
|
---|
| 84 | else
|
---|
| 85 | return Plus;
|
---|
| 86 | }
|
---|