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 { |
6242
|
37 F77_RET_T |
|
38 F77_FUNC (dpchim, DPCHIM) (const octave_idx_type& n, double *x, double *f, |
|
39 double *d, const octave_idx_type &incfd, |
|
40 octave_idx_type *ierr); |
5837
|
41 } |
|
42 |
|
43 DEFUN_DLD(__pchip_deriv__, args, , |
|
44 "-*- texinfo -*-\n\ |
|
45 @deftypefn {Loadable Function} {} __pchip_deriv__ (@var{x}, @var{y})\n\ |
|
46 Wrapper for SLATEC/PCHIP function DPCHIM to calculate the derivates for\n\ |
5838
|
47 piecewise polynomials. You should be using @code{pchip} function instead.\n\ |
5837
|
48 @end deftypefn") |
|
49 { |
|
50 octave_value retval; |
5838
|
51 const int nargin = args.length (); |
5837
|
52 |
|
53 if (nargin == 2) |
|
54 { |
5838
|
55 ColumnVector xvec (args(0).vector_value ()); |
|
56 Matrix ymat (args(1).matrix_value ()); |
|
57 |
6242
|
58 octave_idx_type nx = xvec.length (); |
|
59 octave_idx_type nyr = ymat.rows (); |
|
60 octave_idx_type nyc = ymat.columns (); |
5837
|
61 |
|
62 if (nx != nyr) |
|
63 { |
5838
|
64 error ("number of rows for x and y must match"); |
5837
|
65 return retval; |
|
66 } |
|
67 |
5838
|
68 ColumnVector dvec (nx), yvec (nx); |
|
69 Matrix dmat (nyr, nyc); |
5837
|
70 |
6242
|
71 octave_idx_type ierr; |
|
72 const octave_idx_type incfd = 1; |
5837
|
73 for (int c = 0; c < nyc; c++) |
|
74 { |
5838
|
75 for (int r = 0; r < nx; r++) |
|
76 yvec(r) = ymat(r,c); |
5837
|
77 |
5838
|
78 F77_FUNC (dpchim, DPCHIM) (nx, xvec.fortran_vec (), |
|
79 yvec.fortran_vec (), |
|
80 dvec.fortran_vec (), incfd, &ierr); |
5837
|
81 |
|
82 if (ierr < 0) |
|
83 { |
5838
|
84 error ("DPCHIM error: %i\n", ierr); |
5837
|
85 return retval; |
|
86 } |
5838
|
87 |
5837
|
88 for (int r=0; r<nx; r++) |
5838
|
89 dmat(r,c) = dvec(r); |
5837
|
90 } |
|
91 |
|
92 retval = dmat; |
|
93 } |
|
94 |
|
95 return retval; |
|
96 } |