5837
|
1 /* |
|
2 |
|
3 Copyright (C) 2002 Kai Habel |
|
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 |
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "defun-dld.h" |
|
29 #include "error.h" |
|
30 #include "gripes.h" |
|
31 #include "oct-obj.h" |
|
32 #include "utils.h" |
|
33 #include "f77-fcn.h" |
|
34 |
5838
|
35 extern "C" |
|
36 { |
5837
|
37 extern int F77_FUNC (dpchim, DPCHIM) |
5838
|
38 (const int &n, double *x, double *f, double *d, const int &incfd, |
|
39 int *ierr); |
5837
|
40 } |
|
41 |
|
42 DEFUN_DLD(__pchip_deriv__, args, , |
|
43 "-*- texinfo -*-\n\ |
|
44 @deftypefn {Loadable Function} {} __pchip_deriv__ (@var{x}, @var{y})\n\ |
|
45 Wrapper for SLATEC/PCHIP function DPCHIM to calculate the derivates for\n\ |
5838
|
46 piecewise polynomials. You should be using @code{pchip} function instead.\n\ |
5837
|
47 @end deftypefn") |
|
48 { |
|
49 octave_value retval; |
5838
|
50 const int nargin = args.length (); |
5837
|
51 |
|
52 if (nargin == 2) |
|
53 { |
5838
|
54 ColumnVector xvec (args(0).vector_value ()); |
|
55 Matrix ymat (args(1).matrix_value ()); |
|
56 |
|
57 int nx = xvec.length (); |
|
58 int nyr = ymat.rows (); |
|
59 int nyc = ymat.columns (); |
5837
|
60 |
|
61 if (nx != nyr) |
|
62 { |
5838
|
63 error ("number of rows for x and y must match"); |
5837
|
64 return retval; |
|
65 } |
|
66 |
5838
|
67 ColumnVector dvec (nx), yvec (nx); |
|
68 Matrix dmat (nyr, nyc); |
5837
|
69 |
|
70 int ierr; |
|
71 const int incfd = 1; |
|
72 for (int c = 0; c < nyc; c++) |
|
73 { |
5838
|
74 for (int r = 0; r < nx; r++) |
|
75 yvec(r) = ymat(r,c); |
5837
|
76 |
5838
|
77 F77_FUNC (dpchim, DPCHIM) (nx, xvec.fortran_vec (), |
|
78 yvec.fortran_vec (), |
|
79 dvec.fortran_vec (), incfd, &ierr); |
5837
|
80 |
|
81 if (ierr < 0) |
|
82 { |
5838
|
83 error ("DPCHIM error: %i\n", ierr); |
5837
|
84 return retval; |
|
85 } |
5838
|
86 |
5837
|
87 for (int r=0; r<nx; r++) |
5838
|
88 dmat(r,c) = dvec(r); |
5837
|
89 } |
|
90 |
|
91 retval = dmat; |
|
92 } |
|
93 |
|
94 return retval; |
|
95 } |