3
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
3
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
3
|
20 |
|
21 */ |
|
22 |
1296
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
238
|
27 #ifdef HAVE_CONFIG_H |
1192
|
28 #include <config.h> |
3
|
29 #endif |
|
30 |
|
31 #include "Quad.h" |
1847
|
32 #include "f77-fcn.h" |
2292
|
33 #include "lo-error.h" |
3
|
34 #include "sun-utils.h" |
|
35 |
|
36 static integrand_fcn user_fcn; |
|
37 |
260
|
38 // XXX FIXME XXX -- would be nice to not have to have this global |
|
39 // variable. |
|
40 // Nonzero means an error occurred in the calculation of the integrand |
|
41 // function, and the user wants us to quit. |
|
42 int quad_integration_error = 0; |
|
43 |
3
|
44 extern "C" |
|
45 { |
3136
|
46 int F77_FCN (dqagp, DQAGP) (int (*)(double*, int&, double*), |
1253
|
47 const double&, const double&, |
|
48 const int&, const double*, |
|
49 const double&, const double&, double&, |
|
50 double&, int&, int&, const int&, |
|
51 const int&, int&, int*, double*); |
3
|
52 |
3136
|
53 int F77_FCN (dqagi, DQAGI) (int (*)(double*, int&, double*), |
1253
|
54 const double&, const int&, |
|
55 const double&, const double&, double&, |
|
56 double&, int&, int&, const int&, |
|
57 const int&, int&, int*, double*); |
3
|
58 } |
|
59 |
3136
|
60 static int |
|
61 user_function (double *x, int& ierr, double *result) |
3
|
62 { |
|
63 #if defined (sun) && defined (__GNUC__) |
|
64 double xx = access_double (x); |
|
65 #else |
|
66 double xx = *x; |
|
67 #endif |
|
68 |
260
|
69 quad_integration_error = 0; |
|
70 |
3136
|
71 double xresult = (*user_fcn) (xx); |
|
72 |
|
73 #if defined (sun) && defined (__GNUC__) |
|
74 assign_double (result, xresult); |
|
75 #else |
|
76 *result = xresult; |
|
77 #endif |
260
|
78 |
|
79 if (quad_integration_error) |
1251
|
80 ierr = -1; |
260
|
81 |
3136
|
82 return 0; |
3
|
83 } |
|
84 |
|
85 double |
|
86 DefQuad::integrate (int& ier, int& neval, double& abserr) |
|
87 { |
|
88 int npts = singularities.capacity () + 2; |
|
89 double *points = singularities.fortran_vec (); |
|
90 double result = 0.0; |
1935
|
91 |
3
|
92 int leniw = 183*npts - 122; |
1935
|
93 Array<int> iwork (leniw); |
|
94 int *piwork = iwork.fortran_vec (); |
|
95 |
3
|
96 int lenw = 2*leniw - npts; |
1935
|
97 Array<double> work (lenw); |
|
98 double *pwork = work.fortran_vec (); |
|
99 |
3
|
100 user_fcn = f; |
|
101 int last; |
|
102 |
289
|
103 double abs_tol = absolute_tolerance (); |
|
104 double rel_tol = relative_tolerance (); |
|
105 |
1935
|
106 F77_XFCN (dqagp, DQAGP, (user_function, lower_limit, upper_limit, |
|
107 npts, points, abs_tol, rel_tol, result, |
|
108 abserr, neval, ier, leniw, lenw, last, |
|
109 piwork, pwork)); |
3
|
110 |
1935
|
111 if (f77_exception_encountered) |
|
112 (*current_liboctave_error_handler) ("unrecoverable error in dqagp"); |
3
|
113 |
|
114 return result; |
|
115 } |
|
116 |
|
117 double |
|
118 IndefQuad::integrate (int& ier, int& neval, double& abserr) |
|
119 { |
|
120 double result = 0.0; |
1935
|
121 |
3
|
122 int leniw = 128; |
1935
|
123 Array<int> iwork (leniw); |
|
124 int *piwork = iwork.fortran_vec (); |
|
125 |
3
|
126 int lenw = 8*leniw; |
1935
|
127 Array<double> work (lenw); |
|
128 double *pwork = work.fortran_vec (); |
|
129 |
3
|
130 user_fcn = f; |
|
131 int last; |
|
132 |
|
133 int inf; |
|
134 switch (type) |
|
135 { |
|
136 case bound_to_inf: |
|
137 inf = 1; |
|
138 break; |
1360
|
139 |
3
|
140 case neg_inf_to_bound: |
|
141 inf = -1; |
|
142 break; |
1360
|
143 |
3
|
144 case doubly_infinite: |
|
145 inf = 2; |
|
146 break; |
1360
|
147 |
3
|
148 default: |
|
149 assert (0); |
|
150 break; |
|
151 } |
|
152 |
289
|
153 double abs_tol = absolute_tolerance (); |
|
154 double rel_tol = relative_tolerance (); |
|
155 |
1935
|
156 F77_XFCN (dqagi, DQAGI, (user_function, bound, inf, abs_tol, rel_tol, |
|
157 result, abserr, neval, ier, leniw, lenw, |
|
158 last, piwork, pwork)); |
3
|
159 |
1935
|
160 if (f77_exception_encountered) |
|
161 (*current_liboctave_error_handler) ("unrecoverable error in dqagi"); |
3
|
162 |
|
163 return result; |
|
164 } |
|
165 |
|
166 /* |
|
167 ;;; Local Variables: *** |
|
168 ;;; mode: C++ *** |
|
169 ;;; End: *** |
|
170 */ |