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