Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028 #include "defun-dld.h"
00029 #include "error.h"
00030 #include "gripes.h"
00031 #include "oct-obj.h"
00032 #include "utils.h"
00033 #include "f77-fcn.h"
00034
00035 extern "C"
00036 {
00037 F77_RET_T
00038 F77_FUNC (dpchim, DPCHIM) (const octave_idx_type& n, const double *x,
00039 const double *f, double *d,
00040 const octave_idx_type &incfd,
00041 octave_idx_type *ierr);
00042
00043 F77_RET_T
00044 F77_FUNC (pchim, PCHIM) (const octave_idx_type& n, const float *x,
00045 const float *f, float *d,
00046 const octave_idx_type& incfd,
00047 octave_idx_type *ierr);
00048 }
00049
00050
00051
00052
00053 DEFUN_DLD (__pchip_deriv__, args, ,
00054 "-*- texinfo -*-\n\
00055 @deftypefn {Loadable Function} {} __pchip_deriv__ (@var{x}, @var{y}, @var{dim})\n\
00056 Undocumented internal function.\n\
00057 @end deftypefn")
00058 {
00059 octave_value retval;
00060 const int nargin = args.length ();
00061
00062 bool rows = (nargin == 3 && args (2).uint_value() == 2);
00063
00064 if (nargin >= 2)
00065 {
00066 if (args(0).is_single_type () || args(1).is_single_type ())
00067 {
00068 FloatColumnVector xvec (args(0).float_vector_value ());
00069 FloatMatrix ymat (args(1).float_matrix_value ());
00070
00071 octave_idx_type nx = xvec.length ();
00072
00073 if (nx < 2)
00074 {
00075 error ("__pchip_deriv__: X must be at least of length 2");
00076 return retval;
00077 }
00078
00079 octave_idx_type nyr = ymat.rows ();
00080 octave_idx_type nyc = ymat.columns ();
00081
00082 if (nx != (rows ? nyc : nyr))
00083 {
00084 error ("__pchip_deriv__: X and Y dimension mismatch");
00085 return retval;
00086 }
00087
00088 const float *yvec = ymat.data ();
00089 FloatMatrix dmat (nyr, nyc);
00090 float *dvec = dmat.fortran_vec ();
00091
00092 octave_idx_type ierr;
00093 const octave_idx_type incfd = rows ? nyr : 1;
00094 const octave_idx_type inc = rows ? 1 : nyr;
00095
00096 for (octave_idx_type i = (rows ? nyr : nyc); i > 0; i--)
00097 {
00098 F77_FUNC (pchim, PCHIM) (nx, xvec.data (),
00099 yvec, dvec, incfd, &ierr);
00100
00101 yvec += inc;
00102 dvec += inc;
00103
00104 if (ierr < 0)
00105 {
00106 error ("PCHIM: error: %i\n", ierr);
00107 return retval;
00108 }
00109 }
00110
00111 retval = dmat;
00112 }
00113 else
00114 {
00115 ColumnVector xvec (args(0).vector_value ());
00116 Matrix ymat (args(1).matrix_value ());
00117
00118 octave_idx_type nx = xvec.length ();
00119
00120 if (nx < 2)
00121 {
00122 error ("__pchip_deriv__: X must be at least of length 2");
00123 return retval;
00124 }
00125
00126 octave_idx_type nyr = ymat.rows ();
00127 octave_idx_type nyc = ymat.columns ();
00128
00129 if (nx != (rows ? nyc : nyr))
00130 {
00131 error ("__pchip_deriv__: X and Y dimension mismatch");
00132 return retval;
00133 }
00134
00135 const double *yvec = ymat.data ();
00136 Matrix dmat (nyr, nyc);
00137 double *dvec = dmat.fortran_vec ();
00138
00139 octave_idx_type ierr;
00140 const octave_idx_type incfd = rows ? nyr : 1;
00141 const octave_idx_type inc = rows ? 1 : nyr;
00142
00143 for (octave_idx_type i = (rows ? nyr : nyc); i > 0; i--)
00144 {
00145 F77_FUNC (dpchim, DPCHIM) (nx, xvec.data (),
00146 yvec, dvec, incfd, &ierr);
00147
00148 yvec += inc;
00149 dvec += inc;
00150
00151 if (ierr < 0)
00152 {
00153 error ("DPCHIM: error: %i\n", ierr);
00154 return retval;
00155 }
00156 }
00157
00158 retval = dmat;
00159 }
00160 }
00161
00162 return retval;
00163 }
00164
00165
00166
00167
00168
00169
00170