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 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1296
|
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" |
4180
|
34 #include "quit.h" |
3
|
35 #include "sun-utils.h" |
|
36 |
|
37 static integrand_fcn user_fcn; |
|
38 |
260
|
39 // XXX FIXME XXX -- would be nice to not have to have this global |
|
40 // variable. |
|
41 // Nonzero means an error occurred in the calculation of the integrand |
|
42 // function, and the user wants us to quit. |
|
43 int quad_integration_error = 0; |
|
44 |
3507
|
45 typedef int (*quad_fcn_ptr) (double*, int&, double*); |
|
46 |
3
|
47 extern "C" |
4552
|
48 { |
|
49 F77_RET_T |
|
50 F77_FUNC (dqagp, DQAGP) (quad_fcn_ptr, const double&, const double&, |
|
51 const int&, const double*, const double&, |
|
52 const double&, double&, double&, int&, |
|
53 int&, const int&, const int&, int&, int*, |
|
54 double*); |
3
|
55 |
4552
|
56 F77_RET_T |
|
57 F77_FUNC (dqagi, DQAGI) (quad_fcn_ptr, const double&, const int&, |
|
58 const double&, const double&, double&, |
|
59 double&, int&, int&, const int&, |
|
60 const int&, int&, int*, double*); |
|
61 } |
3
|
62 |
3136
|
63 static int |
|
64 user_function (double *x, int& ierr, double *result) |
3
|
65 { |
4180
|
66 BEGIN_INTERRUPT_WITH_EXCEPTIONS; |
|
67 |
3
|
68 #if defined (sun) && defined (__GNUC__) |
|
69 double xx = access_double (x); |
|
70 #else |
|
71 double xx = *x; |
|
72 #endif |
|
73 |
260
|
74 quad_integration_error = 0; |
|
75 |
3136
|
76 double xresult = (*user_fcn) (xx); |
|
77 |
|
78 #if defined (sun) && defined (__GNUC__) |
|
79 assign_double (result, xresult); |
|
80 #else |
|
81 *result = xresult; |
|
82 #endif |
260
|
83 |
|
84 if (quad_integration_error) |
1251
|
85 ierr = -1; |
260
|
86 |
4180
|
87 END_INTERRUPT_WITH_EXCEPTIONS; |
|
88 |
3136
|
89 return 0; |
3
|
90 } |
|
91 |
|
92 double |
3511
|
93 DefQuad::do_integrate (int& ier, int& neval, double& abserr) |
3
|
94 { |
|
95 int npts = singularities.capacity () + 2; |
|
96 double *points = singularities.fortran_vec (); |
|
97 double result = 0.0; |
1935
|
98 |
3
|
99 int leniw = 183*npts - 122; |
1935
|
100 Array<int> iwork (leniw); |
|
101 int *piwork = iwork.fortran_vec (); |
|
102 |
3
|
103 int lenw = 2*leniw - npts; |
1935
|
104 Array<double> work (lenw); |
|
105 double *pwork = work.fortran_vec (); |
|
106 |
3
|
107 user_fcn = f; |
|
108 int last; |
|
109 |
289
|
110 double abs_tol = absolute_tolerance (); |
|
111 double rel_tol = relative_tolerance (); |
|
112 |
1935
|
113 F77_XFCN (dqagp, DQAGP, (user_function, lower_limit, upper_limit, |
|
114 npts, points, abs_tol, rel_tol, result, |
|
115 abserr, neval, ier, leniw, lenw, last, |
|
116 piwork, pwork)); |
3
|
117 |
1935
|
118 if (f77_exception_encountered) |
|
119 (*current_liboctave_error_handler) ("unrecoverable error in dqagp"); |
3
|
120 |
|
121 return result; |
|
122 } |
|
123 |
|
124 double |
3511
|
125 IndefQuad::do_integrate (int& ier, int& neval, double& abserr) |
3
|
126 { |
|
127 double result = 0.0; |
1935
|
128 |
3
|
129 int leniw = 128; |
1935
|
130 Array<int> iwork (leniw); |
|
131 int *piwork = iwork.fortran_vec (); |
|
132 |
3
|
133 int lenw = 8*leniw; |
1935
|
134 Array<double> work (lenw); |
|
135 double *pwork = work.fortran_vec (); |
|
136 |
3
|
137 user_fcn = f; |
|
138 int last; |
|
139 |
|
140 int inf; |
|
141 switch (type) |
|
142 { |
|
143 case bound_to_inf: |
|
144 inf = 1; |
|
145 break; |
1360
|
146 |
3
|
147 case neg_inf_to_bound: |
|
148 inf = -1; |
|
149 break; |
1360
|
150 |
3
|
151 case doubly_infinite: |
|
152 inf = 2; |
|
153 break; |
1360
|
154 |
3
|
155 default: |
|
156 assert (0); |
|
157 break; |
|
158 } |
|
159 |
289
|
160 double abs_tol = absolute_tolerance (); |
|
161 double rel_tol = relative_tolerance (); |
|
162 |
1935
|
163 F77_XFCN (dqagi, DQAGI, (user_function, bound, inf, abs_tol, rel_tol, |
|
164 result, abserr, neval, ier, leniw, lenw, |
|
165 last, piwork, pwork)); |
3
|
166 |
1935
|
167 if (f77_exception_encountered) |
|
168 (*current_liboctave_error_handler) ("unrecoverable error in dqagi"); |
3
|
169 |
|
170 return result; |
|
171 } |
|
172 |
|
173 /* |
|
174 ;;; Local Variables: *** |
|
175 ;;; mode: C++ *** |
|
176 ;;; End: *** |
|
177 */ |