1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: kmath.h,v 1.3 2000/04/28 14:14:16 kevin Exp $
7 ** Revision 1.3 2000/04/28 14:14:16 kevin
8 ** *** empty log message ***
11 ** This program is free software; you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License (version 2) as
13 ** published by the Free Software Foundation.
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** GNU General Public License for more details.
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ******************************************************************************/
24 /******************************************************************************
29 * Author: Kevin Rosenberg
30 * Purpose: Header file containing definitions for numerical app's
31 * Date Started: Nov 84
37 *****************************************************************************/
45 #define PI 3.14159265358979323846
46 #define HALFPI 1.57079632679489661923 /* PI divided by 2 */
47 #define QUARTPI 0.78539816339744830962 /* PI divided by 4 */
48 #define I_PI 0.31830988618379067154 /* Inverse of PI */
49 #define I_PID2 0.63661977236758134308 /* Inverse of PID2 */
51 #define TWOPI 6.28318530717958647692
52 #define SQRT2 1.414213562373095049
54 #define F_EPSILON 1.0E-6
55 #define D_EPSILON 1.0E-10
57 #define DEG_TO_RAD(x) (x*(PI/180.))
58 #define RAD_TO_DEG(x) (x*(180./PI))
61 #define ASSUMEDZERO 1E-10
63 /* codes for C data types */
72 typedef char *CMTX_1D;
73 typedef CMTX_1D *CMTX_2D;
74 typedef CMTX_2D *CMTX_3D;
77 typedef IMTX_1D *IMTX_2D;
78 typedef IMTX_2D *IMTX_3D;
80 typedef float *FMTX_1D;
81 typedef FMTX_1D *FMTX_2D;
82 typedef FMTX_2D *FMTX_3D;
84 typedef double *DMTX_1D;
85 typedef DMTX_1D *DMTX_2D;
86 typedef DMTX_2D *DMTX_3D;
88 union elem_val_un { /* holds an element value */
96 typedef union elem_val_un MTX_ELEM_VAL;
99 union elem_ptr_un { /* holds a pointer to a 1D vector of any type */
107 typedef union elem_ptr_un MTX_1D;
108 typedef MTX_1D *MTX_2D;
109 typedef MTX_2D *MTX_3D;
111 union mtx_val_ptr_un { /* pointer to matrix values */
117 typedef union mtx_val_ptr_un MTX_PTR;
120 unsigned int order; /* order, or dimension, of matrix */
121 unsigned int elemtype; /* element type */
122 unsigned int elemsize; /* size of element in bytes */
123 unsigned int nx, ny, nz; /* size of matrix in each dimension */
124 MTX_PTR val; /* pointer to matrix values */
127 typedef struct matrix_st MTX;
128 typedef struct matrix_st *MTXP;
130 /* DEFINITION IDENTIFICATION
132 * Definitions to access a matrix element from an matrix
136 (mtx->elemtype == DT_FLOAT ? mtx->val.m1.f[x] :\
137 (mtx->elemtype == DT_DOUBLE ? mtx->val.m1.d[x] :\
138 (mtx->elemtype == DT_INT ? mtx->val.m1.i[x] :\
139 (mtx->elemtype == DT_LONG ? mtx->val.m1.l[x] :\
140 (mtx->elemtype == DT_CHAR ? mtx->val.m1.c[x] :\
144 #define me2(mtx,x,y)\
145 (mtx->elemtype == DT_FLOAT ? mtx->val.m2[x].f[y] :\
146 (mtx->elemtype == DT_DOUBLE ? mtx->val.m2[x].d[y] :\
147 (mtx->elemtype == DT_INT ? mtx->val.m2[x].i[y] :\
148 (mtx->elemtype == DT_LONG ? mtx->val.m2[x].l[y] :\
149 (mtx->elemtype == DT_CHAR ? mtx->val.m2[x].c[y] :\
154 #define me3(mtx,x,y,z)\
155 (mtx->elemtype == DT_FLOAT ? mtx->val.m3[x][y].f[z] :\
156 (mtx->elemtype == DT_DOUBLE ? mtx->val.m3[x][y].d[z] :\
157 (mtx->elemtype == DT_INT ? mtx->val.m3[x][y].i[z] :\
158 (mtx->elemtype == DT_LONG ? mtx->val.m3[x][y].l[z] :\
159 (mtx->elemtype == DT_CHAR ? mtx->val.m3[x][y].c[z] :\
166 long int lnearest(double x);
168 void mtx_show(const MTX *mtx);
169 void mtx_prt(const MTX *mtx, FILE *fp);
170 int mtx_prt_elem(const MTX *mtx, FILE *fp, unsigned int x, unsigned int y, unsigned int z);
172 int mtx_get_elem(const MTX *mtx, MTX_ELEM_VAL *me, const int x, const int y, const int z);
173 int mtx_put_elem(MTX *mtx, const MTX_ELEM_VAL *me, unsigned int x, unsigned int y, unsigned int z);
175 int mtx_inp_elem(const char *prompt, MTX_ELEM_VAL *mev, const int dtype);
177 MTX *mtx_init(const unsigned int order, const unsigned int elem_type, const unsigned int nx, const unsigned int ny, const unsigned int nz);
178 MTX *mtx_clr(MTX *mtx);
179 int mtx_free(MTX *mtx);
180 int mtx_elem_size(const int dt);
181 int mtx_check(const MTX *mtx, const char *func_name);
183 double norm_ang(double theta);
185 double simpson(const double xmin, const double xmax, const double *y, const int np);