5837
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 2002, 2006, 2007 Kai Habel |
5837
|
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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
5837
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
5837
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "defun-dld.h" |
|
28 #include "error.h" |
|
29 #include "gripes.h" |
|
30 #include "oct-obj.h" |
|
31 #include "utils.h" |
|
32 #include "f77-fcn.h" |
|
33 |
5838
|
34 extern "C" |
|
35 { |
6242
|
36 F77_RET_T |
|
37 F77_FUNC (dpchim, DPCHIM) (const octave_idx_type& n, double *x, double *f, |
|
38 double *d, const octave_idx_type &incfd, |
|
39 octave_idx_type *ierr); |
5837
|
40 } |
|
41 |
6945
|
42 // Wrapper for SLATEC/PCHIP function DPCHIM to calculate the derivates |
|
43 // for piecewise polynomials. |
|
44 |
6549
|
45 DEFUN_DLD (__pchip_deriv__, args, , |
5837
|
46 "-*- texinfo -*-\n\ |
|
47 @deftypefn {Loadable Function} {} __pchip_deriv__ (@var{x}, @var{y})\n\ |
6945
|
48 Undocumented internal function.\n\ |
5837
|
49 @end deftypefn") |
|
50 { |
|
51 octave_value retval; |
5838
|
52 const int nargin = args.length (); |
5837
|
53 |
|
54 if (nargin == 2) |
|
55 { |
5838
|
56 ColumnVector xvec (args(0).vector_value ()); |
|
57 Matrix ymat (args(1).matrix_value ()); |
|
58 |
6242
|
59 octave_idx_type nx = xvec.length (); |
|
60 octave_idx_type nyr = ymat.rows (); |
|
61 octave_idx_type nyc = ymat.columns (); |
5837
|
62 |
|
63 if (nx != nyr) |
|
64 { |
5838
|
65 error ("number of rows for x and y must match"); |
5837
|
66 return retval; |
|
67 } |
|
68 |
5838
|
69 ColumnVector dvec (nx), yvec (nx); |
|
70 Matrix dmat (nyr, nyc); |
5837
|
71 |
6242
|
72 octave_idx_type ierr; |
|
73 const octave_idx_type incfd = 1; |
5837
|
74 for (int c = 0; c < nyc; c++) |
|
75 { |
5838
|
76 for (int r = 0; r < nx; r++) |
|
77 yvec(r) = ymat(r,c); |
5837
|
78 |
5838
|
79 F77_FUNC (dpchim, DPCHIM) (nx, xvec.fortran_vec (), |
|
80 yvec.fortran_vec (), |
|
81 dvec.fortran_vec (), incfd, &ierr); |
5837
|
82 |
|
83 if (ierr < 0) |
|
84 { |
5838
|
85 error ("DPCHIM error: %i\n", ierr); |
5837
|
86 return retval; |
|
87 } |
5838
|
88 |
5837
|
89 for (int r=0; r<nx; r++) |
5838
|
90 dmat(r,c) = dvec(r); |
5837
|
91 } |
|
92 |
|
93 retval = dmat; |
|
94 } |
|
95 |
|
96 return retval; |
|
97 } |