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