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