~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/interpolate/__fitpack.h

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Python-C wrapper of FITPACK (by P. Dierckx) (in netlib known as dierckx)
3
 
  Author: Pearu Peterson <pearu@ioc.ee>
4
 
  June 1.-4., 1999
5
 
  June 7. 1999
6
 
  $Revision: 1917 $
7
 
  $Date: 2006-05-27 03:51:39 -0600 (Sat, 27 May 2006) $
8
 
 */
9
 
 
10
 
/*  module_methods:
11
 
  {"_curfit", fitpack_curfit, METH_VARARGS, doc_curfit},
12
 
  {"_spl_", fitpack_spl_, METH_VARARGS, doc_spl_},
13
 
  {"_splint", fitpack_splint, METH_VARARGS, doc_splint},
14
 
  {"_sproot", fitpack_sproot, METH_VARARGS, doc_sproot},
15
 
  {"_spalde", fitpack_spalde, METH_VARARGS, doc_spalde},
16
 
  {"_parcur", fitpack_parcur, METH_VARARGS, doc_parcur},
17
 
  {"_surfit", fitpack_surfit, METH_VARARGS, doc_surfit},
18
 
  {"_bispev", fitpack_bispev, METH_VARARGS, doc_bispev},
19
 
 */
20
 
/* link libraries: (one item per line)
21
 
   ddierckx
22
 
 */
23
 
/* python files: (to be imported to Multipack.py)
24
 
   fitpack.py
25
 
 */
26
 
#if defined(NO_APPEND_FORTRAN)
27
 
#define CURFIT curfit
28
 
#define PERCUR percur
29
 
#define SPALDE spalde
30
 
#define SPLDER splder
31
 
#define SPLEV splev
32
 
#define SPLINT splint
33
 
#define SPROOT sproot
34
 
#define PARCUR parcur
35
 
#define CLOCUR clocur
36
 
#define SURFIT surfit
37
 
#define BISPEV bispev
38
 
#define PARDER parder
39
 
#else
40
 
#define CURFIT curfit_
41
 
#define PERCUR percur_
42
 
#define SPALDE spalde_
43
 
#define SPLDER splder_
44
 
#define SPLEV splev_
45
 
#define SPLINT splint_
46
 
#define SPROOT sproot_
47
 
#define PARCUR parcur_
48
 
#define CLOCUR clocur_
49
 
#define SURFIT surfit_
50
 
#define BISPEV bispev_
51
 
#define PARDER parder_
52
 
#endif
53
 
void CURFIT(int*,int*,double*,double*,double*,double*,double*,int*,double*,int*,int*,double*,double*,double*,double*,int*,int*,int*);
54
 
void PERCUR(int*,int*,double*,double*,double*,int*,double*,int*,int*,double*,double*,double*,double*,int*,int*,int*);
55
 
void SPALDE(double*,int*,double*,int*,double*,double*,int*);
56
 
void SPLDER(double*,int*,double*,int*,int*,double*,double*,int*,double*,int*);
57
 
void SPLEV(double*,int*,double*,int*,double*,double*,int*,int*);
58
 
double SPLINT(double*,int*,double*,int*,double*,double*,double*);
59
 
void SPROOT(double*,int*,double*,double*,int*,int*,int*);
60
 
void PARCUR(int*,int*,int*,int*,double*,int*,double*,double*,double*,double*,int*,double*,int*,int*,double*,int*,double*,double*,double*,int*,int*,int*);
61
 
void CLOCUR(int*,int*,int*,int*,double*,int*,double*,double*,int*,double*,int*,int*,double*,int*,double*,double*,double*,int*,int*,int*);
62
 
void SURFIT(int*,int*,double*,double*,double*,double*,double*,double*,double*,double*,int*,int*,double*,int*,int*,int*,double*,int*,double*,int*,double*,double*,double*,double*,int*,double*,int*,int*,int*,int*);
63
 
void BISPEV(double*,int*,double*,int*,double*,int*,int*,double*,int*,double*,int*,double*,double*,int*,int*,int*,int*);
64
 
void PARDER(double*,int*,double*,int*,double*,int*,int*,int*,int*,double*,int*,double*,int*,double*,double*,int*,int*,int*,int*);
65
 
 
66
 
/* Note that curev, cualde need no interface. */
67
 
 
68
 
static char doc_bispev[] = " [z,ier] = _bispev(tx,ty,c,kx,ky,x,y,nux,nuy)";
69
 
static PyObject *fitpack_bispev(PyObject *dummy, PyObject *args) {
70
 
  int nx,ny,kx,ky,mx,my,lwrk,*iwrk,kwrk,ier,lwa,mxy,nux,nuy;
71
 
  double *tx,*ty,*c,*x,*y,*z,*wrk,*wa = NULL;
72
 
  PyArrayObject *ap_x = NULL,*ap_y = NULL,*ap_z = NULL,*ap_tx = NULL,\
73
 
    *ap_ty = NULL,*ap_c = NULL;
74
 
  PyObject *x_py = NULL,*y_py = NULL,*c_py = NULL,*tx_py = NULL,*ty_py = NULL;
75
 
  if (!PyArg_ParseTuple(args, "OOOiiOOii",&tx_py,&ty_py,&c_py,&kx,&ky,
76
 
                        &x_py,&y_py,&nux,&nuy))
77
 
    return NULL;
78
 
  ap_x = (PyArrayObject *)PyArray_ContiguousFromObject(x_py, PyArray_DOUBLE, 0, 1);
79
 
  ap_y = (PyArrayObject *)PyArray_ContiguousFromObject(y_py, PyArray_DOUBLE, 0, 1);
80
 
  ap_c = (PyArrayObject *)PyArray_ContiguousFromObject(c_py, PyArray_DOUBLE, 0, 1);
81
 
  ap_tx = (PyArrayObject *)PyArray_ContiguousFromObject(tx_py, PyArray_DOUBLE, 0, 1);
82
 
  ap_ty = (PyArrayObject *)PyArray_ContiguousFromObject(ty_py, PyArray_DOUBLE, 0, 1);
83
 
  if (ap_x == NULL || ap_y == NULL || ap_c == NULL || ap_tx == NULL \
84
 
      || ap_ty == NULL) goto fail;  
85
 
  x = (double *) ap_x->data;
86
 
  y = (double *) ap_y->data;
87
 
  c = (double *) ap_c->data;
88
 
  tx = (double *) ap_tx->data;
89
 
  ty = (double *) ap_ty->data;
90
 
  nx = ap_tx->dimensions[0];
91
 
  ny = ap_ty->dimensions[0];
92
 
  mx = ap_x->dimensions[0];
93
 
  my = ap_y->dimensions[0];
94
 
  mxy = mx*my;
95
 
  ap_z = (PyArrayObject *)PyArray_FromDims(1,&mxy,PyArray_DOUBLE);
96
 
  z = (double *) ap_z->data;
97
 
  if (nux || nuy) 
98
 
    lwrk = mx*(kx+1-nux)+my*(ky+1-nuy)+(nx-kx-1)*(ny-ky-1);
99
 
  else
100
 
    lwrk = mx*(kx+1)+my*(ky+1);
101
 
  kwrk = mx+my;
102
 
  lwa = lwrk+kwrk;
103
 
  if ((wa = (double *)malloc(lwa*sizeof(double)))==NULL) {
104
 
    PyErr_NoMemory();
105
 
    goto fail;
106
 
  }
107
 
  wrk = wa;
108
 
  iwrk = (int *)(wrk+lwrk);
109
 
  if (nux || nuy)
110
 
    PARDER(tx,&nx,ty,&ny,c,&kx,&ky,&nux,&nuy,x,&mx,y,&my,z,wrk,&lwrk,iwrk,&kwrk,&ier);
111
 
  else
112
 
    BISPEV(tx,&nx,ty,&ny,c,&kx,&ky,x,&mx,y,&my,z,wrk,&lwrk,iwrk,&kwrk,&ier);
113
 
 
114
 
  if (wa) free(wa);
115
 
  Py_DECREF(ap_x);
116
 
  Py_DECREF(ap_y);
117
 
  Py_DECREF(ap_c);
118
 
  Py_DECREF(ap_tx);
119
 
  Py_DECREF(ap_ty);
120
 
  return Py_BuildValue("Ni",PyArray_Return(ap_z),ier);
121
 
  fail:
122
 
  if (wa) free(wa);
123
 
  Py_XDECREF(ap_x);
124
 
  Py_XDECREF(ap_y);
125
 
  Py_XDECREF(ap_z);
126
 
  Py_XDECREF(ap_c);
127
 
  Py_XDECREF(ap_tx);
128
 
  Py_XDECREF(ap_ty);
129
 
  return NULL;
130
 
}
131
 
 
132
 
static char doc_surfit[] = " [tx,ty,c,o] = _surfit(x,y,z,w,xb,xe,yb,ye,kx,ky,iopt,s,eps,tx,ty,nxest,nyest,wrk,lwrk1,lwrk2)";
133
 
static PyObject *fitpack_surfit(PyObject *dummy, PyObject *args) {
134
 
  int iopt,m,kx,ky,nxest,nyest,nx,ny,lwrk1,lwrk2,*iwrk,kwrk,ier,lwa,nxo,nyo,\
135
 
    i,lc,lcest,nmax;
136
 
  double *x,*y,*z,*w,xb,xe,yb,ye,s,*tx,*ty,*c,fp,*wrk1,*wrk2,*wa = NULL,eps;
137
 
  PyArrayObject *ap_x = NULL,*ap_y = NULL,*ap_z,*ap_w = NULL,\
138
 
    *ap_tx = NULL,*ap_ty = NULL,*ap_c = NULL;
139
 
  PyArrayObject *ap_wrk = NULL;
140
 
  PyObject *x_py = NULL,*y_py = NULL,*z_py = NULL,*w_py = NULL,\
141
 
    *tx_py = NULL,*ty_py = NULL;
142
 
  PyObject *wrk_py=NULL;
143
 
  nx=ny=ier=nxo=nyo=0;
144
 
  if (!PyArg_ParseTuple(args, "OOOOddddiiiddOOiiOii",\
145
 
                        &x_py,&y_py,&z_py,&w_py,&xb,&xe,\
146
 
                        &yb,&ye,&kx,&ky,&iopt,&s,&eps,&tx_py,&ty_py,&nxest,&nyest,\
147
 
                        &wrk_py,&lwrk1,&lwrk2)) return NULL;
148
 
  ap_x = (PyArrayObject *)PyArray_ContiguousFromObject(x_py, PyArray_DOUBLE, 0, 1);
149
 
  ap_y = (PyArrayObject *)PyArray_ContiguousFromObject(y_py, PyArray_DOUBLE, 0, 1);
150
 
  ap_z = (PyArrayObject *)PyArray_ContiguousFromObject(z_py, PyArray_DOUBLE, 0, 1);
151
 
  ap_w = (PyArrayObject *)PyArray_ContiguousFromObject(w_py, PyArray_DOUBLE, 0, 1);
152
 
  ap_wrk=(PyArrayObject *)PyArray_ContiguousFromObject(wrk_py, PyArray_DOUBLE, 0, 1);
153
 
  /*ap_iwrk=(PyArrayObject *)PyArray_ContiguousFromObject(iwrk_py, PyArray_INT, 0, 1);*/
154
 
  if (ap_x == NULL || ap_y == NULL || ap_z == NULL || ap_w == NULL \
155
 
      || ap_wrk == NULL) goto fail;
156
 
  x = (double *) ap_x->data;
157
 
  y = (double *) ap_y->data;
158
 
  z = (double *) ap_z->data;
159
 
  w = (double *) ap_w->data;
160
 
  m = ap_x->dimensions[0];
161
 
  nmax=nxest;
162
 
  if (nmax<nyest) nmax=nyest;
163
 
  lcest=(nxest-kx-1)*(nyest-ky-1);
164
 
  kwrk=m+(nxest-2*kx-1)*(nyest-2*ky-1);
165
 
  lwa = 2*nmax+lcest+lwrk1+lwrk2+kwrk;
166
 
  if ((wa = (double *)malloc(lwa*sizeof(double)))==NULL) {
167
 
    PyErr_NoMemory();
168
 
    goto fail;
169
 
  }
170
 
  tx = wa;
171
 
  ty = tx + nmax;
172
 
  c = ty + nmax;
173
 
  wrk1 = c + lcest;
174
 
  iwrk = (int *)(wrk1 + lwrk1);
175
 
  wrk2 = (double *)(iwrk+kwrk);
176
 
  if (iopt) {
177
 
    ap_tx=(PyArrayObject *)PyArray_ContiguousFromObject(tx_py, PyArray_DOUBLE, 0, 1);
178
 
    ap_ty=(PyArrayObject *)PyArray_ContiguousFromObject(ty_py, PyArray_DOUBLE, 0, 1);
179
 
    if (ap_tx == NULL || ap_ty == NULL) goto fail;
180
 
    nx = nxo = ap_tx->dimensions[0];
181
 
    ny = nyo = ap_ty->dimensions[0];
182
 
    memcpy(tx,ap_tx->data,nx*sizeof(double));
183
 
    memcpy(ty,ap_ty->data,ny*sizeof(double));
184
 
  }
185
 
  if (iopt==1) {
186
 
    lc = (nx-kx-1)*(ny-ky-1);
187
 
    memcpy(wrk1,ap_wrk->data,lc*sizeof(double));
188
 
    /*memcpy(iwrk,ap_iwrk->data,n*sizeof(int));*/
189
 
  }
190
 
  SURFIT(&iopt,&m,x,y,z,w,&xb,&xe,&yb,&ye,&kx,&ky,&s,&nxest,&nyest,&nmax,&eps,&nx,tx,&ny,ty,c,&fp,wrk1,&lwrk1,wrk2,&lwrk2,iwrk,&kwrk,&ier);
191
 
  i=0;
192
 
  while ((ier>10) && (i++<5)) {
193
 
    lwrk2=ier;
194
 
    if ((wrk2 = (double *)malloc(lwrk2*sizeof(double)))==NULL) {
195
 
      PyErr_NoMemory();
196
 
      goto fail;
197
 
    }
198
 
    SURFIT(&iopt,&m,x,y,z,w,&xb,&xe,&yb,&ye,&kx,&ky,&s,&nxest,&nyest,&nmax,&eps,&nx,tx,&ny,ty,c,&fp,wrk1,&lwrk1,wrk2,&lwrk2,iwrk,&kwrk,&ier);
199
 
    if (wrk2) free(wrk2);
200
 
  }
201
 
  if (ier==10) {
202
 
          PyErr_SetString(PyExc_ValueError, "Invalid inputs.");
203
 
          goto fail;
204
 
  }
205
 
  lc = (nx-kx-1)*(ny-ky-1);
206
 
  Py_XDECREF(ap_tx);
207
 
  Py_XDECREF(ap_ty);
208
 
  ap_tx = (PyArrayObject *)PyArray_FromDims(1,&nx,PyArray_DOUBLE);
209
 
  ap_ty = (PyArrayObject *)PyArray_FromDims(1,&ny,PyArray_DOUBLE);
210
 
  ap_c = (PyArrayObject *)PyArray_FromDims(1,&lc,PyArray_DOUBLE);
211
 
  if (ap_tx == NULL || ap_ty == NULL || ap_c == NULL) goto fail;
212
 
  if ((iopt==0)||(nx>nxo)||(ny>nyo)) {
213
 
    ap_wrk = (PyArrayObject *)PyArray_FromDims(1,&lc,PyArray_DOUBLE);
214
 
    if (ap_wrk == NULL) goto fail;
215
 
    /*ap_iwrk = (PyArrayObject *)PyArray_FromDims(1,&n,PyArray_INT);*/
216
 
  }
217
 
  memcpy(ap_tx->data,tx,nx*sizeof(double));
218
 
  memcpy(ap_ty->data,ty,ny*sizeof(double));
219
 
  memcpy(ap_c->data,c,lc*sizeof(double));
220
 
  memcpy(ap_wrk->data,wrk1,lc*sizeof(double));
221
 
  /*memcpy(ap_iwrk->data,iwrk,n*sizeof(int));*/
222
 
  if (wa) free(wa);
223
 
  Py_DECREF(ap_x);
224
 
  Py_DECREF(ap_y);
225
 
  Py_DECREF(ap_z);
226
 
  Py_DECREF(ap_w);
227
 
  return Py_BuildValue("NNN{s:N,s:i,s:d}",PyArray_Return(ap_tx),\
228
 
                       PyArray_Return(ap_ty),PyArray_Return(ap_c),\
229
 
                       "wrk",PyArray_Return(ap_wrk),\
230
 
                       "ier",ier,"fp",fp);
231
 
  fail:
232
 
  if (wa) free(wa);
233
 
  Py_XDECREF(ap_x);
234
 
  Py_XDECREF(ap_y);
235
 
  Py_XDECREF(ap_z);
236
 
  Py_XDECREF(ap_w);
237
 
  Py_XDECREF(ap_tx);
238
 
  Py_XDECREF(ap_ty);
239
 
  Py_XDECREF(ap_wrk);
240
 
  /*Py_XDECREF(ap_iwrk);*/
241
 
  if (!PyErr_Occurred()) {
242
 
          PyErr_SetString(PyExc_ValueError, "An error occurred.");
243
 
  }
244
 
  return NULL;
245
 
}
246
 
 
247
 
 
248
 
static char doc_parcur[] = " [t,c,o] = _parcur(x,w,u,ub,ue,k,iopt,ipar,s,t,nest,wrk,iwrk,per)";
249
 
static PyObject *fitpack_parcur(PyObject *dummy, PyObject *args) {
250
 
  int k,iopt,ipar,nest,*iwrk,idim,m,mx,n=0,no=0,nc,ier,lc,lwa,lwrk,i,per;
251
 
  double *x,*w,*u,*c,*t,*wrk,*wa=NULL,ub,ue,fp,s;
252
 
  PyObject *x_py = NULL,*u_py = NULL,*w_py = NULL,*t_py = NULL;
253
 
  PyObject *wrk_py=NULL,*iwrk_py=NULL;
254
 
  PyArrayObject *ap_x = NULL,*ap_u = NULL,*ap_w = NULL,*ap_t = NULL,*ap_c = NULL;
255
 
  PyArrayObject *ap_wrk = NULL,*ap_iwrk = NULL;
256
 
  if (!PyArg_ParseTuple(args, "OOOddiiidOiOOi",&x_py,&w_py,&u_py,&ub,&ue,\
257
 
                        &k,&iopt,&ipar,&s,&t_py,&nest,&wrk_py,&iwrk_py,&per)) return NULL;
258
 
  ap_x = (PyArrayObject *)PyArray_ContiguousFromObject(x_py, PyArray_DOUBLE, 0, 1);
259
 
  ap_u = (PyArrayObject *)PyArray_ContiguousFromObject(u_py, PyArray_DOUBLE, 0, 1);
260
 
  ap_w = (PyArrayObject *)PyArray_ContiguousFromObject(w_py, PyArray_DOUBLE, 0, 1);
261
 
  ap_wrk=(PyArrayObject *)PyArray_ContiguousFromObject(wrk_py, PyArray_DOUBLE, 0, 1);
262
 
  ap_iwrk=(PyArrayObject *)PyArray_ContiguousFromObject(iwrk_py, PyArray_INT, 0, 1);
263
 
  if (ap_x == NULL || ap_u == NULL || ap_w == NULL || ap_wrk == NULL || ap_iwrk == NULL) goto fail;
264
 
  x = (double *) ap_x->data;
265
 
  u = (double *) ap_u->data;
266
 
  w = (double *) ap_w->data;
267
 
  m = ap_w->dimensions[0];
268
 
  mx = ap_x->dimensions[0];
269
 
  idim = mx/m;
270
 
  if (per)
271
 
    lwrk=m*(k+1)+nest*(7+idim+5*k);
272
 
  else
273
 
    lwrk=m*(k+1)+nest*(6+idim+3*k);
274
 
  nc=idim*nest;
275
 
  lwa = nc+2*nest+lwrk;
276
 
  if ((wa = (double *)malloc(lwa*sizeof(double)))==NULL) {
277
 
    PyErr_NoMemory();
278
 
    goto fail;
279
 
  }
280
 
  t = wa;
281
 
  c = t + nest;
282
 
  wrk = c + nc;
283
 
  iwrk = (int *)(wrk + lwrk);
284
 
  if (iopt) {
285
 
    ap_t=(PyArrayObject *)PyArray_ContiguousFromObject(t_py, PyArray_DOUBLE, 0, 1);
286
 
    if (ap_t == NULL) goto fail;
287
 
    n = no = ap_t->dimensions[0];
288
 
    memcpy(t,ap_t->data,n*sizeof(double));
289
 
  }
290
 
  if (iopt==1) {
291
 
    memcpy(wrk,ap_wrk->data,n*sizeof(double));
292
 
    memcpy(iwrk,ap_iwrk->data,n*sizeof(int));
293
 
  }
294
 
  if (per)
295
 
    CLOCUR(&iopt,&ipar,&idim,&m,u,&mx,x,w,&k,&s,&nest,&n,t,&nc,\
296
 
           c,&fp,wrk,&lwrk,iwrk,&ier);
297
 
  else
298
 
    PARCUR(&iopt,&ipar,&idim,&m,u,&mx,x,w,&ub,&ue,&k,&s,&nest,&n,t,&nc,\
299
 
           c,&fp,wrk,&lwrk,iwrk,&ier);
300
 
  if (ier==10) goto fail;
301
 
  if (ier>0 && n==0) n=1;
302
 
  lc = (n-k-1)*idim;
303
 
  ap_t = (PyArrayObject *)PyArray_FromDims(1,&n,PyArray_DOUBLE);
304
 
  ap_c = (PyArrayObject *)PyArray_FromDims(1,&lc,PyArray_DOUBLE);
305
 
  if (ap_t == NULL || ap_c == NULL) goto fail;
306
 
  if ((iopt==0)||(n>no)) {
307
 
    ap_wrk = (PyArrayObject *)PyArray_FromDims(1,&n,PyArray_DOUBLE);
308
 
    ap_iwrk = (PyArrayObject *)PyArray_FromDims(1,&n,PyArray_INT);
309
 
    if (ap_wrk == NULL || ap_iwrk == NULL) goto fail;
310
 
  }
311
 
  memcpy(ap_t->data,t,n*sizeof(double));
312
 
  for (i=0;i<idim;i++)
313
 
    memcpy((double *) ap_c->data+i*(n-k-1),c+i*n,(n-k-1)*sizeof(double));
314
 
  memcpy(ap_wrk->data,wrk,n*sizeof(double));
315
 
  memcpy(ap_iwrk->data,iwrk,n*sizeof(int));  
316
 
  if (wa) free(wa);
317
 
  Py_DECREF(ap_x);
318
 
  Py_DECREF(ap_w);
319
 
  return Py_BuildValue("NN{s:N,s:d,s:d,s:N,s:N,s:i,s:d}",PyArray_Return(ap_t),PyArray_Return(ap_c),"u",PyArray_Return(ap_u),"ub",ub,"ue",ue,"wrk",PyArray_Return(ap_wrk),"iwrk",PyArray_Return(ap_iwrk),"ier",ier,"fp",fp);
320
 
  fail:
321
 
  if (wa) free(wa);
322
 
  Py_XDECREF(ap_x);
323
 
  Py_XDECREF(ap_u);
324
 
  Py_XDECREF(ap_w);
325
 
  Py_XDECREF(ap_t);
326
 
  Py_XDECREF(ap_wrk);
327
 
  Py_XDECREF(ap_iwrk);
328
 
  return NULL;
329
 
}
330
 
 
331
 
static char doc_curfit[] = " [t,c,o] = _curfit(x,y,w,xb,xe,k,iopt,s,t,nest,wrk,iwrk,per)";
332
 
static PyObject *fitpack_curfit(PyObject *dummy, PyObject *args) {
333
 
  int iopt,m,k,nest,n,lwrk,*iwrk,ier,lwa,lc,no=0,per;
334
 
  double *x,*y,*w,xb,xe,s,*t,*c,fp,*wrk,*wa = NULL;
335
 
  PyArrayObject *ap_x = NULL,*ap_y = NULL,*ap_w = NULL,*ap_t = NULL,*ap_c = NULL;
336
 
  PyArrayObject *ap_wrk = NULL,*ap_iwrk = NULL;
337
 
  PyObject *x_py = NULL,*y_py = NULL,*w_py = NULL,*t_py = NULL;
338
 
  PyObject *wrk_py=NULL,*iwrk_py=NULL;
339
 
  if (!PyArg_ParseTuple(args, "OOOddiidOiOOi",&x_py,&y_py,&w_py,&xb,&xe,\
340
 
                        &k,&iopt,&s,&t_py,&nest,&wrk_py,&iwrk_py,&per)) return NULL;
341
 
  ap_x = (PyArrayObject *)PyArray_ContiguousFromObject(x_py, PyArray_DOUBLE, 0, 1);
342
 
  ap_y = (PyArrayObject *)PyArray_ContiguousFromObject(y_py, PyArray_DOUBLE, 0, 1);
343
 
  ap_w = (PyArrayObject *)PyArray_ContiguousFromObject(w_py, PyArray_DOUBLE, 0, 1);
344
 
  ap_wrk=(PyArrayObject *)PyArray_ContiguousFromObject(wrk_py, PyArray_DOUBLE, 0, 1);
345
 
  ap_iwrk=(PyArrayObject *)PyArray_ContiguousFromObject(iwrk_py, PyArray_INT, 0, 1);
346
 
  if (ap_x == NULL || ap_y == NULL || ap_w == NULL || ap_wrk == NULL || ap_iwrk == NULL) goto fail;
347
 
  x = (double *) ap_x->data;
348
 
  y = (double *) ap_y->data;
349
 
  w = (double *) ap_w->data;
350
 
  m = ap_x->dimensions[0];
351
 
  if (per) lwrk = m*(k+1) + nest*(8+5*k);
352
 
  else lwrk = m*(k+1) + nest*(7+3*k);
353
 
  lwa = 3*nest+lwrk;
354
 
  if ((wa = (double *)malloc(lwa*sizeof(double)))==NULL) {
355
 
    PyErr_NoMemory();
356
 
    goto fail;
357
 
  }
358
 
  t = wa;
359
 
  c = t + nest;
360
 
  wrk = c + nest;
361
 
  iwrk = (int *)(wrk + lwrk);
362
 
  if (iopt) {
363
 
    ap_t=(PyArrayObject *)PyArray_ContiguousFromObject(t_py, PyArray_DOUBLE, 0, 1);
364
 
    if (ap_t == NULL) goto fail;
365
 
    n = no = ap_t->dimensions[0];
366
 
    memcpy(t,ap_t->data,n*sizeof(double));
367
 
  }
368
 
  if (iopt==1) {
369
 
    memcpy(wrk,ap_wrk->data,n*sizeof(double));
370
 
    memcpy(iwrk,ap_iwrk->data,n*sizeof(int));
371
 
  }
372
 
  if (per)
373
 
    PERCUR(&iopt,&m,x,y,w,&k,&s,&nest,&n,t,c,&fp,wrk,&lwrk,iwrk,&ier);
374
 
  else
375
 
    CURFIT(&iopt,&m,x,y,w,&xb,&xe,&k,&s,&nest,&n,t,c,&fp,wrk,&lwrk,iwrk,&ier);
376
 
  if (ier==10) {
377
 
          PyErr_SetString(PyExc_ValueError, "Invalid inputs.");
378
 
          goto fail;
379
 
  }
380
 
  lc = n-k-1;
381
 
  if (!iopt) {
382
 
          ap_t = (PyArrayObject *)PyArray_FromDims(1,&n,PyArray_DOUBLE);
383
 
          if (ap_t == NULL) goto fail;
384
 
  }
385
 
  ap_c = (PyArrayObject *)PyArray_FromDims(1,&lc,PyArray_DOUBLE);
386
 
  if (ap_c == NULL) goto fail;
387
 
  if ((iopt==0)||(n>no)) {
388
 
    Py_XDECREF(ap_wrk);
389
 
    Py_XDECREF(ap_iwrk);
390
 
    ap_wrk = (PyArrayObject *)PyArray_FromDims(1,&n,PyArray_DOUBLE);
391
 
    ap_iwrk = (PyArrayObject *)PyArray_FromDims(1,&n,PyArray_INT);
392
 
    if (ap_wrk == NULL || ap_iwrk == NULL) goto fail;
393
 
  }
394
 
  memcpy(ap_t->data,t,n*sizeof(double));
395
 
  memcpy(ap_c->data,c,lc*sizeof(double));
396
 
  memcpy(ap_wrk->data,wrk,n*sizeof(double));
397
 
  memcpy(ap_iwrk->data,iwrk,n*sizeof(int));
398
 
  if (wa) free(wa);
399
 
  Py_DECREF(ap_x);
400
 
  Py_DECREF(ap_y);
401
 
  Py_DECREF(ap_w);
402
 
  return Py_BuildValue("NN{s:N,s:N,s:i,s:d}",PyArray_Return(ap_t),PyArray_Return(ap_c),"wrk",PyArray_Return(ap_wrk),"iwrk",PyArray_Return(ap_iwrk),"ier",ier,"fp",fp);
403
 
  fail:
404
 
  if (wa) free(wa);
405
 
  Py_XDECREF(ap_x);
406
 
  Py_XDECREF(ap_y);
407
 
  Py_XDECREF(ap_w);
408
 
  Py_XDECREF(ap_t);
409
 
  Py_XDECREF(ap_wrk);
410
 
  Py_XDECREF(ap_iwrk);
411
 
  return NULL;
412
 
}
413
 
 
414
 
static char doc_spl_[] = " [y,ier] = _spl_(x,nu,t,c,k )";
415
 
static PyObject *fitpack_spl_(PyObject *dummy, PyObject *args) {
416
 
  int n,nu,m,ier,k;
417
 
  double *x,*y,*t,*c,*wrk = NULL;
418
 
  PyArrayObject *ap_x = NULL,*ap_y = NULL,*ap_t = NULL,*ap_c = NULL;
419
 
  PyObject *x_py = NULL,*t_py = NULL,*c_py = NULL;
420
 
  if (!PyArg_ParseTuple(args, "OiOOi",&x_py,&nu,&t_py,&c_py,&k)) return NULL;
421
 
  ap_x = (PyArrayObject *)PyArray_ContiguousFromObject(x_py, PyArray_DOUBLE, 0, 1);
422
 
  ap_t = (PyArrayObject *)PyArray_ContiguousFromObject(t_py, PyArray_DOUBLE, 0, 1);
423
 
  ap_c = (PyArrayObject *)PyArray_ContiguousFromObject(c_py, PyArray_DOUBLE, 0, 1);
424
 
  if ((ap_x == NULL || ap_t == NULL || ap_c == NULL)) goto fail;
425
 
  x = (double *) ap_x->data;
426
 
  m = ap_x->dimensions[0];
427
 
  t = (double *) ap_t->data;
428
 
  c = (double *) ap_c->data;
429
 
  n = ap_t->dimensions[0];
430
 
  ap_y = (PyArrayObject *)PyArray_FromDims(1,&m,PyArray_DOUBLE);
431
 
  if (ap_y == NULL) goto fail;
432
 
  y = (double *) ap_y->data;
433
 
  if ((wrk = (double *)malloc(n*sizeof(double)))==NULL) {
434
 
    PyErr_NoMemory();
435
 
    goto fail;
436
 
  }
437
 
  if (nu)
438
 
    SPLDER(t,&n,c,&k,&nu,x,y,&m,wrk,&ier);
439
 
  else
440
 
    SPLEV(t,&n,c,&k,x,y,&m,&ier);
441
 
  if (wrk) free(wrk);
442
 
  Py_DECREF(ap_x);
443
 
  Py_DECREF(ap_c);
444
 
  Py_DECREF(ap_t);
445
 
  return Py_BuildValue("Ni",PyArray_Return(ap_y),ier);
446
 
 fail:
447
 
  if (wrk) free(wrk);
448
 
  Py_XDECREF(ap_x);
449
 
  Py_XDECREF(ap_c);
450
 
  Py_XDECREF(ap_t);
451
 
  return NULL;
452
 
}
453
 
 
454
 
static char doc_splint[] = " [aint,wrk] = _splint(t,c,k,a,b)";
455
 
static PyObject *fitpack_splint(PyObject *dummy, PyObject *args) {
456
 
  int n,k;
457
 
  double *t,*c,*wrk = NULL,a,b,aint;
458
 
  PyArrayObject *ap_t = NULL,*ap_c = NULL;
459
 
  PyArrayObject *ap_wrk = NULL;
460
 
  PyObject *t_py = NULL,*c_py = NULL;
461
 
  if (!PyArg_ParseTuple(args, "OOidd",&t_py,&c_py,&k,&a,&b)) return NULL;
462
 
  ap_t = (PyArrayObject *)PyArray_ContiguousFromObject(t_py, PyArray_DOUBLE, 0, 1);
463
 
  ap_c = (PyArrayObject *)PyArray_ContiguousFromObject(c_py, PyArray_DOUBLE, 0, 1);
464
 
  if ((ap_t == NULL || ap_c == NULL)) goto fail;
465
 
  t = (double *) ap_t->data;
466
 
  c = (double *) ap_c->data;
467
 
  n = ap_t->dimensions[0];
468
 
  ap_wrk = (PyArrayObject *)PyArray_FromDims(1,&n,PyArray_DOUBLE);
469
 
  if (ap_wrk == NULL) goto fail;
470
 
  wrk = (double *) ap_wrk->data;
471
 
  aint = SPLINT(t,&n,c,&k,&a,&b,wrk);
472
 
  Py_DECREF(ap_c);
473
 
  Py_DECREF(ap_t);
474
 
  return Py_BuildValue("dN",aint,PyArray_Return(ap_wrk));
475
 
 fail:
476
 
  Py_XDECREF(ap_c);
477
 
  Py_XDECREF(ap_t);
478
 
  return NULL;
479
 
}
480
 
 
481
 
static char doc_sproot[] = " [z,ier] = _sproot(t,c,k,mest)";
482
 
static PyObject *fitpack_sproot(PyObject *dummy, PyObject *args) {
483
 
  int n,k,mest,ier,m;
484
 
  double *t,*c,*z=NULL;
485
 
  PyArrayObject *ap_t = NULL,*ap_c = NULL;
486
 
  PyArrayObject *ap_z = NULL;
487
 
  PyObject *t_py = NULL,*c_py = NULL;
488
 
  if (!PyArg_ParseTuple(args, "OOii",&t_py,&c_py,&k,&mest)) return NULL;
489
 
  ap_t = (PyArrayObject *)PyArray_ContiguousFromObject(t_py, PyArray_DOUBLE, 0, 1);
490
 
  ap_c = (PyArrayObject *)PyArray_ContiguousFromObject(c_py, PyArray_DOUBLE, 0, 1);
491
 
  if ((ap_t == NULL || ap_c == NULL)) goto fail;
492
 
  t = (double *) ap_t->data;
493
 
  c = (double *) ap_c->data;
494
 
  n = ap_t->dimensions[0];
495
 
  if ((z = (double *)malloc(mest*sizeof(double)))==NULL) {
496
 
    PyErr_NoMemory();
497
 
    goto fail;
498
 
  }
499
 
  SPROOT(t,&n,c,z,&mest,&m,&ier);
500
 
  if (ier==10) m=0;
501
 
  ap_z = (PyArrayObject *)PyArray_FromDims(1,&m,PyArray_DOUBLE);
502
 
  if (ap_z == NULL) goto fail;
503
 
  memcpy(ap_z->data,z,m*sizeof(double));
504
 
  if (z) free(z);
505
 
  Py_DECREF(ap_c);
506
 
  Py_DECREF(ap_t);
507
 
  return Py_BuildValue("Ni",PyArray_Return(ap_z),ier);
508
 
 fail:
509
 
  if (z) free(z);
510
 
  Py_XDECREF(ap_c);
511
 
  Py_XDECREF(ap_t);
512
 
  return NULL;
513
 
}
514
 
 
515
 
static char doc_spalde[] = " [d,ier] = _spalde(t,c,k,x)";
516
 
static PyObject *fitpack_spalde(PyObject *dummy, PyObject *args) {
517
 
  int n,k,k1,ier;
518
 
  double *t,*c,*d=NULL,x;
519
 
  PyArrayObject *ap_t = NULL,*ap_c = NULL,*ap_d = NULL;
520
 
  PyObject *t_py = NULL,*c_py = NULL;
521
 
  if (!PyArg_ParseTuple(args, "OOid",&t_py,&c_py,&k,&x)) return NULL;
522
 
  ap_t = (PyArrayObject *)PyArray_ContiguousFromObject(t_py, PyArray_DOUBLE, 0, 1);
523
 
  ap_c = (PyArrayObject *)PyArray_ContiguousFromObject(c_py, PyArray_DOUBLE, 0, 1);
524
 
  if ((ap_t == NULL || ap_c == NULL)) goto fail;
525
 
  t = (double *) ap_t->data;
526
 
  c = (double *) ap_c->data;
527
 
  n = ap_t->dimensions[0];
528
 
  k1=k+1;
529
 
  ap_d = (PyArrayObject *)PyArray_FromDims(1,&k1,PyArray_DOUBLE);
530
 
  if (ap_d == NULL) goto fail;
531
 
  d = (double *) ap_d->data;
532
 
  SPALDE(t,&n,c,&k1,&x,d,&ier);
533
 
  Py_DECREF(ap_c);
534
 
  Py_DECREF(ap_t);
535
 
  return Py_BuildValue("Ni",PyArray_Return(ap_d),ier);
536
 
 fail:
537
 
  Py_XDECREF(ap_c);
538
 
  Py_XDECREF(ap_t);
539
 
  return NULL;
540
 
}
541
 
 
542
 
 
543
 
 
544