/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /** \file parsing.cpp * * Declarations of various class functions for the parsing of value files. * */ // ======================================= INCLUDES ========================================== // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include #include #include "CodePatterns/Log.hpp" #include "Helpers/defs.hpp" #include "Fragmentation/helpers.hpp" // ======================================= FUNCTIONS ========================================== /** Test if given filename can be opened. * \param filename name of file * \param test true - no error message, false - print error * \return given file exists */ bool FilePresent(const char *filename, bool test) { std::ifstream input; input.open(filename, ios::in); if (input.fail()) { if (!test) LOG(0, endl << "FilePresent: Unable to open " << filename << ", is the directory correct?"); return false; } input.close(); return true; }; /** Test the given parameters. * \param argc argument count * \param **argv arguments array * \return given inputdir is valid */ bool TestParams(int argc, char **argv) { std::ifstream input; stringstream line; line << argv[1] << FRAGMENTPREFIX << KEYSETFILE; return FilePresent(line.str().c_str(), false); }; /** 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(0, "Number is " << number << ", order is " << order << "."); } // 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(0, returnstring); return returnstring; };