1 /* 2 * util.h 3 * 4 * 5 * Part of TREE-PUZZLE 5.2 (July 2004) 6 * 7 * (c) 2003-2004 by Heiko A. Schmidt, Korbinian Strimmer, and Arndt von Haeseler 8 * (c) 1999-2003 by Heiko A. Schmidt, Korbinian Strimmer, 9 * M. Vingron, and Arndt von Haeseler 10 * (c) 1995-1999 by Korbinian Strimmer and Arndt von Haeseler 11 * 12 * All parts of the source except where indicated are distributed under 13 * the GNU public licence. See http://www.opensource.org for details. 14 * 15 * ($Id$) 16 * 17 */ 18 19 20 #ifndef _UTIL_ 21 #define _UTIL_ 22 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <math.h> 26 #include <time.h> 27 28 29 /* 30 * general definitions 31 */ 32 33 #define TRUE 1 34 #define FALSE 0 35 36 #ifdef PARALLEL 37 extern long int PP_randn; 38 extern long int PP_rand; 39 #endif 40 41 /* 42 * type definitions 43 */ 44 45 typedef unsigned long int uli; 46 47 typedef double *dvector, **dmatrix, ***dcube; 48 typedef char *cvector, **cmatrix, ***ccube; 49 typedef int *ivector, **imatrix, ***icube; 50 typedef uli *ulivector, **ulimatrix, ***ulicube; 51 52 53 /* 54 * prototypes of functions defined in util.c 55 */ 56 57 void maerror(char *message); 58 59 dvector new_dvector(int n); 60 dmatrix new_dmatrix(int nrow, int ncol); 61 dcube new_dcube(int ntri, int nrow, int ncol); 62 void free_dvector(dvector v); 63 void free_dmatrix(dmatrix m); 64 void free_dcube(dcube c); 65 66 cvector new_cvector(int n); 67 cmatrix new_cmatrix(int nrow, int ncol); 68 ccube new_ccube(int ntri, int nrow, int ncol); 69 void free_cvector(cvector v); 70 void free_cmatrix(cmatrix m); 71 void free_ccube(ccube c); 72 73 ivector new_ivector(int n); 74 imatrix new_imatrix(int nrow, int ncol); 75 icube new_icube(int ntri, int nrow, int ncol); 76 void free_ivector(ivector v); 77 void free_imatrix(imatrix m); 78 void free_icube(icube c); 79 80 ulivector new_ulivector(int n); 81 ulimatrix new_ulimatrix(int nrow, int ncol); 82 ulicube new_ulicube(int ntri, int nrow, int ncol); 83 void free_ulivector(ulivector v); 84 void free_ulimatrix(ulimatrix m); 85 void free_ulicube(ulicube c); 86 87 /* check timer and generate message roughly every 15 minutes */ 88 void checktime(time_t *starttime, /* starttime of overall part */ 89 time_t *lasttime, /* lasttime of print out */ 90 time_t *nowtime, /* current time (taken inside) */ 91 uli done, /* number of tasks done */ 92 uli sumtodo, /* sum of task todo */ 93 int *mflag); /* LF needed to end line? */ 94 95 96 double randomunitintervall(void); 97 int initrandom(int seed); 98 int randominteger(int n); 99 void chooser(int t, int s, ivector slist); 100 void fixedchooser(int t, int s, ivector slist); 101 void *myrealloc(void *, size_t); 102 cvector mygets(void); 103 104 #define MAXITS 10 /* maximum number of iterations in twoedimenmin */ 105 double onedimenmin(double, double, double, double (*f )(double ), double, double *, double *); 106 void twodimenmin(double, int, double, double *, double, double (*func1 )(double ), double *, int, double, double *, double, double (*func2 )(double ), double *); 107 108 109 110 #endif 111