r24: Set up include files for conditional INTERACTIVE_GRAPHICS
[ctsim.git] / include / kmath.h
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: kmath.h,v 1.4 2000/04/30 19:17:35 kevin Exp $
6 **  $Log: kmath.h,v $
7 **  Revision 1.4  2000/04/30 19:17:35  kevin
8 **  Set up include files for conditional INTERACTIVE_GRAPHICS
9 **
10 **  Revision 1.3  2000/04/28 14:14:16  kevin
11 **  *** empty log message ***
12 **
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27 /******************************************************************************
28  *
29  * FILE IDENTIFICATION
30  *
31  *      File Name:      NUMR.H
32  *      Author:         Kevin Rosenberg
33  *      Purpose:        Header file containing definitions for numerical app's
34  *      Date Started:   Nov 84
35  *
36  * DESCRIPTION
37  *
38  * MODIFICATION LOG
39  *
40  *****************************************************************************/
41
42 #ifndef _H_kmath
43 #define _H_kmath
44
45 #include <stdio.h>
46 #include <math.h>
47
48 #define PI      3.14159265358979323846
49 #define HALFPI  1.57079632679489661923  /* PI divided by 2 */
50 #define QUARTPI 0.78539816339744830962  /* PI divided by 4 */
51 #define I_PI    0.31830988618379067154  /* Inverse of PI */
52 #define I_PID2  0.63661977236758134308  /* Inverse of PID2 */
53  
54 #define TWOPI   6.28318530717958647692
55 #define SQRT2   1.414213562373095049
56
57 #define F_EPSILON       1.0E-6
58 #define D_EPSILON       1.0E-10
59
60 #define DEG_TO_RAD(x)   (x*(PI/180.))
61 #define RAD_TO_DEG(x)   (x*(180./PI))
62
63
64 #define ASSUMEDZERO  1E-10
65
66 /* codes for C data types */
67
68 #define DT_CHAR         1
69 #define DT_INT          2
70 #define DT_LONG         3
71 #define DT_FLOAT        4
72 #define DT_DOUBLE       5
73 #define DT_STRING  6
74
75 typedef char     *CMTX_1D;
76 typedef CMTX_1D  *CMTX_2D;
77 typedef CMTX_2D  *CMTX_3D;
78
79 typedef int      *IMTX_1D;
80 typedef IMTX_1D  *IMTX_2D;
81 typedef IMTX_2D  *IMTX_3D;
82
83 typedef float    *FMTX_1D;
84 typedef FMTX_1D  *FMTX_2D;
85 typedef FMTX_2D  *FMTX_3D;
86
87 typedef double   *DMTX_1D;
88 typedef DMTX_1D  *DMTX_2D;
89 typedef DMTX_2D  *DMTX_3D;
90
91 typedef double GRFMTX_2D[3][3];
92 typedef double GRFMTX_3D[4][4];
93
94 union elem_val_un {     /* holds an element value */
95         char      c;
96         int       i;
97         long int  l;
98         float     f;
99         double    d;
100 };
101
102 typedef union elem_val_un  MTX_ELEM_VAL;
103
104
105 union elem_ptr_un {     /* holds a pointer to a 1D vector of any type */
106         char      *c;
107         int       *i;
108         long int  *l;
109         float     *f;
110         double    *d;
111 };
112
113 typedef union elem_ptr_un  MTX_1D;
114 typedef MTX_1D            *MTX_2D;
115 typedef MTX_2D            *MTX_3D;
116
117 union mtx_val_ptr_un {                  /* pointer to matrix values */
118     MTX_1D  m1;
119     MTX_2D  m2;
120     MTX_3D  m3;
121 };
122
123 typedef union mtx_val_ptr_un  MTX_PTR;
124
125 struct matrix_st {
126     unsigned int order;                 /* order, or dimension, of matrix */
127     unsigned int elemtype;              /* element type */
128     unsigned int elemsize;              /* size of element in bytes */
129     unsigned int nx, ny, nz;            /* size of matrix in each dimension */
130     MTX_PTR val;                        /* pointer to matrix values */
131 };
132
133 typedef struct matrix_st MTX;
134 typedef struct matrix_st *MTXP;
135
136 /* DEFINITION IDENTIFICATION
137  *
138  *      Definitions to access a matrix element from an matrix
139  *
140
141 #define me1(mtx,x)\
142   (mtx->elemtype == DT_FLOAT ? mtx->val.m1.f[x] :\
143     (mtx->elemtype == DT_DOUBLE ? mtx->val.m1.d[x] :\
144       (mtx->elemtype == DT_INT ? mtx->val.m1.i[x] :\
145         (mtx->elemtype == DT_LONG ? mtx->val.m1.l[x] :\
146           (mtx->elemtype == DT_CHAR ? mtx->val.m1.c[x] :\
147              0\
148               )))))
149
150 #define me2(mtx,x,y)\
151   (mtx->elemtype == DT_FLOAT ? mtx->val.m2[x].f[y] :\
152     (mtx->elemtype == DT_DOUBLE ? mtx->val.m2[x].d[y] :\
153       (mtx->elemtype == DT_INT ? mtx->val.m2[x].i[y] :\
154         (mtx->elemtype == DT_LONG ? mtx->val.m2[x].l[y] :\
155           (mtx->elemtype == DT_CHAR ? mtx->val.m2[x].c[y] :\
156             0\
157               )))))
158
159
160 #define me3(mtx,x,y,z)\
161   (mtx->elemtype == DT_FLOAT ? mtx->val.m3[x][y].f[z] :\
162     (mtx->elemtype == DT_DOUBLE ? mtx->val.m3[x][y].d[z] :\
163       (mtx->elemtype == DT_INT ? mtx->val.m3[x][y].i[z] :\
164         (mtx->elemtype == DT_LONG ? mtx->val.m3[x][y].l[z] :\
165           (mtx->elemtype == DT_CHAR ? mtx->val.m3[x][y].c[z] :\
166             0\
167                )))))
168 */
169
170
171 /* cliprect.c */
172 int cliprect(double *x1, double *y1, double *x2, double *y2, const double rect[4]);
173 /* lnearest.c */
174 long int lnearest(double x);
175 /* mtx_disp.c */
176 void mtx_show(const MTX *mtx);
177 void mtx_prt(const MTX *mtx, FILE *fp);
178 int mtx_prt_elem(const MTX *mtx, FILE *fp, unsigned int x, unsigned int y, unsigned int z);
179 /* mtx_elem.c */
180 int mtx_get_elem(const MTX *mtx, MTX_ELEM_VAL *me, const int x, const int y, const int z);
181 int mtx_put_elem(MTX *mtx, const MTX_ELEM_VAL *me, unsigned int x, unsigned int y, unsigned int z);
182 /* mtx_inp.c */
183 int mtx_inp_elem(const char *prompt, MTX_ELEM_VAL *mev, const int dtype);
184 /* mtx_main.c */
185 MTX *mtx_init(const unsigned int order, const unsigned int elem_type, const unsigned int nx, const unsigned int ny, const unsigned int nz);
186 MTX *mtx_clr(MTX *mtx);
187 int mtx_free(MTX *mtx);
188 int mtx_elem_size(const int dt);
189 int mtx_check(const MTX *mtx, const char *func_name);
190 /* norm_ang.c */
191 double norm_ang(double theta);
192 /* simpson.c */
193 double simpson(const double xmin, const double xmax, const double *y, const int np);
194
195 #endif