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