-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutines.h
129 lines (118 loc) · 5.66 KB
/
routines.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*! \file routines.h
* \brief Declarations for a variety of utility routines.
*/
#ifndef BRANT_ROUTINES
#define BRANT_ROUTINES
#include<stdio.h>
#include<gsl/gsl_spline.h>
#include<time.h>
/*! \fn void check_args(int argc, char **argv, int num_args)
* \brief Ensures that the number of command line arguements equals num_args.
*/
void check_args(int argc, char **argv, int num_args);
/*! \fn int check_file(char fname[]);
* \brief Check to see if a file exists.
*/
int check_file(char fname[]);
/*! \fn FILE *fopen_brant(char fname[], const char *mode)
* \brief Safe method for opening a FILE pointer.
*/
FILE *fopen_brant(char fname[], const char *mode);
/*! \fn double *calloc_double_array(int n)
* \brief Safe method for callocing a double array
*/
double *calloc_double_array(int n);
/*! \fn float *calloc_float_array(int n)
* \brief Safe method for callocing a float array
*/
float *calloc_float_array(int n);
/*! \fn int *calloc_int_array(int n)
* \brief Safe method for callocing an int array
*/
int *calloc_int_array(int n);
/*! \fn size_t *calloc_size_t_array(int n)
* \brief Safe method for callocing a size_t array
*/
size_t *calloc_size_t_array(int n);
/*! \fn double **two_dimensional_array(int n, int l)
* \brief Allocate a two dimensional (n x l) array
*/
double **two_dimensional_array(int n, int l);
float **two_dimensional_float_array(int n, int l);
/*! \fn void deallocate_two_dimensional_array(double **x, int n, int l)
* \brief De-allocate a two dimensional (n x l) array
*/
void deallocate_two_dimensional_array(double **x, int n, int l);
void deallocate_two_dimensional_float_array(float **x, int n, int l);
/*! \fn double ***three_dimensional_array(int n, int l, int m)
* \brief Allocate a three dimensional (n x l x m) array
*/
double ***three_dimensional_array(int n, int l, int m);
/*! \fn void deallocate_three_dimensional_array(double ***x, int n, int l, int m)
* \brief De-allocate a three dimensional (n x l x m) array
*/
void deallocate_three_dimensional_array(double ***x, int n, int l, int m);
/*! \fn int ***three_dimensional_int_array(int n, int l, int m)
* \brief Allocate a three dimensional (n x l x m) int array
*/
double ****four_dimensional_array(int n, int l, int m, int p);
/*! \fn void deallocate_four_dimensional_array(double ****x, int n, int l, int m, int p)
* \brief De-allocate a four dimensional (n x l x m x p) array
*/
void deallocate_four_dimensional_array(double ****x, int n, int l, int m, int p);
/*! \fn int ***three_dimensional_int_array(int n, int l, int m, int p)
* \brief Allocate a three dimensional (n x l x m) int array
*/
int ***three_dimensional_int_array(int n, int l, int m);
/*! \fn void deallocate_three_int_dimensional_array(int ***x, int n, int l, int m)
* \brief De-allocate a three dimensional (n x l x m) int array.
*/
void deallocate_three_dimensional_int_array(int ***x, int n, int l, int m);
/*! \fn double max_three(double a, double b, double c)
* \brief Returns the max of 3 numbers */
double max_three(double a, double b, double c);
/*! \fn int compare_doubles(const void *a, const void *b)
* \brief Function to compare doubles, for use with qsort.
*/
int compare_doubles(const void *a, const void *b);
/*! \fn double time_in_seconds(clock_t A, clock_t B)
* \brief Returns time difference B-A in seconds for two clock_t
*/
double time_in_seconds(clock_t A, clock_t B);
/*! \fn double double double_linear_index(int i, int n, double xmin, double xmax)
* \brief Provides the i^th out of n linear incremented value between xmin and xmax.
* Useful for creating a ordinate array for an interpolation.
*/
double double_linear_index(int i, int n, double xmin, double xmax);
/*! \fn double double_log10_index(int i, int n, double xmin, double xmax)
* \brief Provides the i^th out of n log10 incremented value between xmin and xmax.
* Useful for creating a ordinate array for an interpolation.
*/
double double_log10_index(int i, int n, double xmin, double xmax);
/*! \fn void create_linear_spline(double (*func)(double, void *), double *x, double *&y, int n, double *params, gsl_spline *&spline, gsl_interp_accel *&acc)
* \brief Routine to create a spline, interpolated linear.
*/
void create_linear_spline(double (*func)(double, void *), double *x, double *&y, int n, double *params, gsl_spline *spline, gsl_interp_accel *acc);
/*! \fn void create_log10_spline(double (*func)(double, void *), double *log10x, double *&log10y, int n, double *params, gsl_spline *&spline, gsl_interp_accel *&acc)
* \brief Routine to make a spline, interpolating in log10.
*/
void create_log10_spline(double (*func)(double, void *), double *log10x, double *&log10y, int n, double *params, gsl_spline *&spline, gsl_interp_accel *&acc);
/*! \fn double array_max(double *x, int n)
* \brief Find the maximum of array x */
double array_max(double *x, int n);
/*! \fn double array_min(double *x, int n)
* \brief Find the minimum of array x */
double array_min(double *x, int n);
/*! \fn double vector_dot_product(double *x, double *y, int n);
* \brief Find the dot product of x * y */
double vector_dot_product(double *x, double *y, int n);
/*! \fn double vector_magnitude(double *x, int n)
* \brief Find the magnitude of x */
double vector_magnitude(double *x, int n);
/*! \fn double vector_cross_product(double *x, double *y, int n);
* \brief Find the cross product of x x y */
double *vector_cross_product(double *x, double *y, int n);
/*! \fn double **tensor_transformation(double **a, double **sigma, int ndim)
* \brief Apply transformation a to tensor sigma */
double **tensor_transformation(double **a, double **sigma, int ndim);
#endif //BRANT_ROUTINES