#ifndef init_h #define init_h /** \file init.h * Header file for \ref init.c * * Contains declarations of the functions implemented in \ref init.c, * enumeration value_type which is needed for ParseForParameters() and * one inline function tpow() realising a "x to the power of n" where n * may be also arbitrary (also negative) integer. * Project: ParallelCarParrinello \authors Jan Hamaekers, Frederik Heber \date 2000, 2006 File: init.h $Id: init.h,v 1.17 2007/02/09 09:13:48 foo Exp $ */ // Specifting whether a value in the parameter file must be specified or is optional enum necessity { optional, //!< parameter is optional, if not given sensible value is chosen critical //!< parameter must be given or programme won't initiate }; // Specifying the cast type to be read of a parameter, see ParseForParameter() enum value_type { string_type, double_type, int_type, row_int, row_double, grid, lower_trigrid, upper_trigrid}; /* Bereite mainname vor: loescht von filename von rechts nach links bis zu erstem "/" oder ganz */ void CreateMainname(struct Problem *const P, const char* const filename); /* Einlesen der Parameterdatei */ int ParseForParameter(int verbose, FILE *file, const char *const name, int sequential, int const xth, int const yth, enum value_type type, void *value, int repetition, enum necessity critical); void ReadParameters(struct Problem *const P, const char *const filename); void WriteParameters(struct Problem *const P, const char *const filename); void Init(struct Problem *const P); void InitPerturbation(struct Problem *P); void InitPsisValue(struct Problem *const P, int start, int end); /** Calculate the value \a x to the power of \a n. * \param x value * \param n power * \return \f$x^n\f$ */ static inline double tpow(double x, int n) { double y = 1; int neg = (n < 0); if (neg) n = -n; while (n) { // go through every bit of the integer number n if (n & 1) y *= x; // if bit set, multiply x *= x; // go to next power of 2 n >>= 1; // and to the next bit } return neg ? 1.0/y : y; // if n was negative, return reciprocal value } #endif