#ifndef _SIMUTILS_H #define _SIMUTILS_H /*============================================== SIMULATION LIBRARY UTILITY MODULE HEADER ===============================================*/ //============================================================================= // macros //============================================================================= #define max(a,b) (((a) > (b)) ? (a) : (b)) #define min(a,b) (((a) < (b)) ? (a) : (b)) //============================================================================= // miscellaneous defines //============================================================================= #define TRUE 1 #define FALSE 0 #ifndef tab // &&&& JC 99.06.07 #define tab "\t" #endif // &&&& JC 99.06.07 //============================================================================= // typedefs //============================================================================= typedef short boolean; //============================================================================= // global flag class (only one instance of it) //============================================================================= class global_flags { boolean conv_corr_byFFT; // TRUE by def. public: global_flags(); void print_features(); boolean convcorr_byFFT(); void set_convcorr_byFFT(boolean); }; extern class global_flags features; //============================================================================= // error handling //============================================================================= extern void error(char*); //============================================================================= // primitive timing //============================================================================= // from ANSI K&R (2nd Edition) p. 255 // returns number of seconds since program began extern unsigned long elapsed_time(); //============================================================================= // random number class (only one instance of it) //============================================================================= class random { long seed; // seed for the random number generator // corresponds to the "idum" variable in the // Numerical Recipes in C (NRinC) code public: random(long); // constructor with a starting seed ~random(){}; // destructor long get_seed(); // returns the current seed void set_seed(long); // sets the seed double uniform(); // returns a uniform deviate between 0.0 and 1.0 // basically the NRinC rand1 routine double gaussian(); // returns a normally distributed deviate with // zero mean and unit variance basically the NRinC gasdev routine long int uniformint(long int i); // returns an int, uniformly // distributed on the interval [0,i-1] long int uniformint(long int i1, long int i2); // really returns a // random integer in the expressed interval [i1,i2] (inclusive) long int integer(long int i1, long int i2); // supposed to do // what int(long int,long int) does, but it doesn't do it // correctly. This is kept merely for backward // compatibility. What it does is it returns a number in the // range [0,i2-i1+1]. boolean binary(); // returns TRUE and FALSE with equal prob }; extern class random rnd; // GLOBAL random object inline boolean random::binary() { if(rnd.uniform() >= 0.5) return TRUE; else return FALSE; } #endif