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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
3
|
21 |
|
22 */ |
|
23 |
238
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
3
|
26 #endif |
|
27 |
|
28 #include "Quad.h" |
1847
|
29 #include "f77-fcn.h" |
2292
|
30 #include "lo-error.h" |
4180
|
31 #include "quit.h" |
3
|
32 #include "sun-utils.h" |
|
33 |
|
34 static integrand_fcn user_fcn; |
|
35 |
5775
|
36 // FIXME -- would be nice to not have to have this global |
260
|
37 // variable. |
|
38 // Nonzero means an error occurred in the calculation of the integrand |
|
39 // function, and the user wants us to quit. |
|
40 int quad_integration_error = 0; |
|
41 |
5275
|
42 typedef octave_idx_type (*quad_fcn_ptr) (double*, int&, double*); |
3507
|
43 |
3
|
44 extern "C" |
4552
|
45 { |
|
46 F77_RET_T |
|
47 F77_FUNC (dqagp, DQAGP) (quad_fcn_ptr, const double&, const double&, |
5275
|
48 const octave_idx_type&, const double*, const double&, |
|
49 const double&, double&, double&, octave_idx_type&, |
|
50 octave_idx_type&, const octave_idx_type&, const octave_idx_type&, octave_idx_type&, octave_idx_type*, |
4552
|
51 double*); |
3
|
52 |
4552
|
53 F77_RET_T |
5275
|
54 F77_FUNC (dqagi, DQAGI) (quad_fcn_ptr, const double&, const octave_idx_type&, |
4552
|
55 const double&, const double&, double&, |
5275
|
56 double&, octave_idx_type&, octave_idx_type&, const octave_idx_type&, |
|
57 const octave_idx_type&, octave_idx_type&, octave_idx_type*, double*); |
4552
|
58 } |
3
|
59 |
5275
|
60 static octave_idx_type |
3136
|
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 |
5275
|
90 DefQuad::do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) |
3
|
91 { |
5275
|
92 octave_idx_type npts = singularities.capacity () + 2; |
3
|
93 double *points = singularities.fortran_vec (); |
|
94 double result = 0.0; |
1935
|
95 |
5275
|
96 octave_idx_type leniw = 183*npts - 122; |
|
97 Array<octave_idx_type> iwork (leniw); |
|
98 octave_idx_type *piwork = iwork.fortran_vec (); |
1935
|
99 |
5275
|
100 octave_idx_type lenw = 2*leniw - npts; |
1935
|
101 Array<double> work (lenw); |
|
102 double *pwork = work.fortran_vec (); |
|
103 |
3
|
104 user_fcn = f; |
5275
|
105 octave_idx_type last; |
3
|
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 |
5275
|
122 IndefQuad::do_integrate (octave_idx_type& ier, octave_idx_type& neval, double& abserr) |
3
|
123 { |
|
124 double result = 0.0; |
1935
|
125 |
5275
|
126 octave_idx_type leniw = 128; |
|
127 Array<octave_idx_type> iwork (leniw); |
|
128 octave_idx_type *piwork = iwork.fortran_vec (); |
1935
|
129 |
5275
|
130 octave_idx_type lenw = 8*leniw; |
1935
|
131 Array<double> work (lenw); |
|
132 double *pwork = work.fortran_vec (); |
|
133 |
3
|
134 user_fcn = f; |
5275
|
135 octave_idx_type last; |
3
|
136 |
5275
|
137 octave_idx_type inf; |
3
|
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 */ |