1 /******************************************************************************
6 * Author: Kevin Rosenberg
7 * Purpose: Header file containing definitions for numerical app's
14 *****************************************************************************/
22 #define PI 3.14159265358979323846
23 #define HALFPI 1.57079632679489661923 /* PI divided by 2 */
24 #define QUARTPI 0.78539816339744830962 /* PI divided by 4 */
25 #define I_PI 0.31830988618379067154 /* Inverse of PI */
26 #define I_PID2 0.63661977236758134308 /* Inverse of PID2 */
28 #define TWOPI 6.28318530717958647692
29 #define SQRT2 1.414213562373095049
31 #define F_EPSILON 1.0E-6
32 #define D_EPSILON 1.0E-10
34 #define DEG_TO_RAD(x) (x*(PI/180.))
35 #define RAD_TO_DEG(x) (x*(180./PI))
38 #define ASSUMEDZERO 1E-10
40 /* codes for C data types */
49 typedef char *CMTX_1D;
50 typedef CMTX_1D *CMTX_2D;
51 typedef CMTX_2D *CMTX_3D;
54 typedef IMTX_1D *IMTX_2D;
55 typedef IMTX_2D *IMTX_3D;
57 typedef float *FMTX_1D;
58 typedef FMTX_1D *FMTX_2D;
59 typedef FMTX_2D *FMTX_3D;
61 typedef double *DMTX_1D;
62 typedef DMTX_1D *DMTX_2D;
63 typedef DMTX_2D *DMTX_3D;
65 union elem_val_un { /* holds an element value */
73 typedef union elem_val_un MTX_ELEM_VAL;
76 union elem_ptr_un { /* holds a pointer to a 1D vector of any type */
84 typedef union elem_ptr_un MTX_1D;
85 typedef MTX_1D *MTX_2D;
86 typedef MTX_2D *MTX_3D;
88 union mtx_val_ptr_un { /* pointer to matrix values */
94 typedef union mtx_val_ptr_un MTX_PTR;
97 unsigned int order; /* order, or dimension, of matrix */
98 unsigned int elemtype; /* element type */
99 unsigned int elemsize; /* size of element in bytes */
100 unsigned int nx, ny, nz; /* size of matrix in each dimension */
101 MTX_PTR val; /* pointer to matrix values */
104 typedef struct matrix_st MTX;
105 typedef struct matrix_st *MTXP;
107 /* DEFINITION IDENTIFICATION
109 * Definitions to access a matrix element from an matrix
113 (mtx->elemtype == DT_FLOAT ? mtx->val.m1.f[x] :\
114 (mtx->elemtype == DT_DOUBLE ? mtx->val.m1.d[x] :\
115 (mtx->elemtype == DT_INT ? mtx->val.m1.i[x] :\
116 (mtx->elemtype == DT_LONG ? mtx->val.m1.l[x] :\
117 (mtx->elemtype == DT_CHAR ? mtx->val.m1.c[x] :\
121 #define me2(mtx,x,y)\
122 (mtx->elemtype == DT_FLOAT ? mtx->val.m2[x].f[y] :\
123 (mtx->elemtype == DT_DOUBLE ? mtx->val.m2[x].d[y] :\
124 (mtx->elemtype == DT_INT ? mtx->val.m2[x].i[y] :\
125 (mtx->elemtype == DT_LONG ? mtx->val.m2[x].l[y] :\
126 (mtx->elemtype == DT_CHAR ? mtx->val.m2[x].c[y] :\
131 #define me3(mtx,x,y,z)\
132 (mtx->elemtype == DT_FLOAT ? mtx->val.m3[x][y].f[z] :\
133 (mtx->elemtype == DT_DOUBLE ? mtx->val.m3[x][y].d[z] :\
134 (mtx->elemtype == DT_INT ? mtx->val.m3[x][y].i[z] :\
135 (mtx->elemtype == DT_LONG ? mtx->val.m3[x][y].l[z] :\
136 (mtx->elemtype == DT_CHAR ? mtx->val.m3[x][y].c[z] :\
143 int calc_x(double *x, const double xmin, const double xmax, const int n);
145 void calcpoly(const double *a, const int degree, const double *x, double *y, const int n);
147 int gauss(double **a, double *b, double *x, const int num);
149 long int lnearest(double x);
151 int lsfit(double *x, double *y, int n, int degree, double *coeff, FILE *fp);
153 void matprt(const double **m, const int row, const int col, FILE *fp);
155 void mtx_show(const MTX *mtx);
156 void mtx_prt(const MTX *mtx, FILE *fp);
157 int mtx_prt_elem(const MTX *mtx, FILE *fp, unsigned int x, unsigned int y, unsigned int z);
159 int mtx_get_elem(const MTX *mtx, MTX_ELEM_VAL *me, const int x, const int y, const int z);
160 int mtx_put_elem(MTX *mtx, const MTX_ELEM_VAL *me, unsigned int x, unsigned int y, unsigned int z);
162 int mtx_inp_elem(const char *prompt, MTX_ELEM_VAL *mev, const int dtype);
164 MTX *mtx_init(const unsigned int order, const unsigned int elem_type, const unsigned int nx, const unsigned int ny, const unsigned int nz);
165 MTX *mtx_clr(MTX *mtx);
166 int mtx_free(MTX *mtx);
167 int mtx_elem_size(const int dt);
168 int mtx_check(const MTX *mtx, const char *func_name);
170 double norm_ang(double theta);
172 void pntprt(const double *x, const double *y, const int n, FILE *fp);
174 int pntread(double *x, double *y, int *num, const int maxn, FILE *fp);
176 double poly(const double *a, const int degree, const double x);
178 double simpson(const double xmin, const double xmax, const double *y, const int np);
180 double stddev(const double *y1, const double *y2, const int n, const int df_lost);
182 void vectprt(const double *v, const int n, FILE *fp);
184 int vectread(double *v, int *n, const int maxn, FILE *fp);
186 int vectsort(int num_vec, const int dtype, const int num_pts, char *vec1, char *vec2, char *vec3);