~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to Lib/sandbox/spline/fitpack/polar.f

  • 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
 
      subroutine polar(iopt,m,x,y,z,w,rad,s,nuest,nvest,eps,nu,tu,
2
 
     *  nv,tv,u,v,c,fp,wrk1,lwrk1,wrk2,lwrk2,iwrk,kwrk,ier)
3
 
c  subroutine polar fits a smooth function f(x,y) to a set of data
4
 
c  points (x(i),y(i),z(i)) scattered arbitrarily over an approximation
5
 
c  domain  x**2+y**2 <= rad(atan(y/x))**2. through the transformation
6
 
c    x = u*rad(v)*cos(v) , y = u*rad(v)*sin(v)
7
 
c  the approximation problem is reduced to the determination of a bi-
8
 
c  cubic spline s(u,v) fitting a corresponding set of data points
9
 
c  (u(i),v(i),z(i)) on the rectangle 0<=u<=1,-pi<=v<=pi.
10
 
c  in order to have continuous partial derivatives
11
 
c              i+j
12
 
c             d   f(0,0)
13
 
c    g(i,j) = ----------
14
 
c                i   j
15
 
c              dx  dy
16
 
c
17
 
c  s(u,v)=f(x,y) must satisfy the following conditions
18
 
c
19
 
c    (1) s(0,v) = g(0,0)   -pi <=v<= pi.
20
 
c
21
 
c        d s(0,v)
22
 
c    (2) -------- = rad(v)*(cos(v)*g(1,0)+sin(v)*g(0,1))
23
 
c        d u
24
 
c                                                    -pi <=v<= pi
25
 
c         2
26
 
c        d s(0,v)         2       2             2
27
 
c    (3) -------- = rad(v)*(cos(v)*g(2,0)+sin(v)*g(0,2)+sin(2*v)*g(1,1))
28
 
c           2
29
 
c        d u                                         -pi <=v<= pi
30
 
c
31
 
c  moreover, s(u,v) must be periodic in the variable v, i.e.
32
 
c
33
 
c         j            j
34
 
c        d s(u,-pi)   d s(u,pi)
35
 
c    (4) ---------- = ---------   0 <=u<= 1, j=0,1,2
36
 
c           j           j
37
 
c        d v         d v
38
 
c
39
 
c  if iopt(1) < 0 circle calculates a weighted least-squares spline
40
 
c  according to a given set of knots in u- and v- direction.
41
 
c  if iopt(1) >=0, the number of knots in each direction and their pos-
42
 
c  ition tu(j),j=1,2,...,nu ; tv(j),j=1,2,...,nv are chosen automatical-
43
 
c  ly by the routine. the smoothness of s(u,v) is then achieved by mini-
44
 
c  malizing the discontinuity jumps of the derivatives of the spline
45
 
c  at the knots. the amount of smoothness of s(u,v) is determined  by
46
 
c  the condition that fp = sum((w(i)*(z(i)-s(u(i),v(i))))**2) be <= s,
47
 
c  with s a given non-negative constant.
48
 
c  the bicubic spline is given in its standard b-spline representation
49
 
c  and the corresponding function f(x,y) can be evaluated by means of
50
 
c  function program evapol.
51
 
c
52
 
c calling sequence:
53
 
c     call polar(iopt,m,x,y,z,w,rad,s,nuest,nvest,eps,nu,tu,
54
 
c    *  nv,tv,u,v,wrk1,lwrk1,wrk2,lwrk2,iwrk,kwrk,ier)
55
 
c
56
 
c parameters:
57
 
c  iopt  : integer array of dimension 3, specifying different options.
58
 
c          unchanged on exit.
59
 
c  iopt(1):on entry iopt(1) must specify whether a weighted
60
 
c          least-squares polar spline (iopt(1)=-1) or a smoothing
61
 
c          polar spline (iopt(1)=0 or 1) must be determined.
62
 
c          if iopt(1)=0 the routine will start with an initial set of
63
 
c          knots tu(i)=0,tu(i+4)=1,i=1,...,4;tv(i)=(2*i-9)*pi,i=1,...,8.
64
 
c          if iopt(1)=1 the routine will continue with the set of knots
65
 
c          found at the last call of the routine.
66
 
c          attention: a call with iopt(1)=1 must always be immediately
67
 
c          preceded by another call with iopt(1) = 1 or iopt(1) = 0.
68
 
c  iopt(2):on entry iopt(2) must specify the requested order of conti-
69
 
c          nuity for f(x,y) at the origin.
70
 
c          if iopt(2)=0 only condition (1) must be fulfilled,
71
 
c          if iopt(2)=1 conditions (1)+(2) must be fulfilled and
72
 
c          if iopt(2)=2 conditions (1)+(2)+(3) must be fulfilled.
73
 
c  iopt(3):on entry iopt(3) must specify whether (iopt(3)=1) or not
74
 
c          (iopt(3)=0) the approximation f(x,y) must vanish at the
75
 
c          boundary of the approximation domain.
76
 
c  m     : integer. on entry m must specify the number of data points.
77
 
c          m >= 4-iopt(2)-iopt(3) unchanged on exit.
78
 
c  x     : real array of dimension at least (m).
79
 
c  y     : real array of dimension at least (m).
80
 
c  z     : real array of dimension at least (m).
81
 
c          before entry, x(i),y(i),z(i) must be set to the co-ordinates
82
 
c          of the i-th data point, for i=1,...,m. the order of the data
83
 
c          points is immaterial. unchanged on exit.
84
 
c  w     : real array of dimension at least (m). before entry, w(i) must
85
 
c          be set to the i-th value in the set of weights. the w(i) must
86
 
c          be strictly positive. unchanged on exit.
87
 
c  rad   : real function subprogram defining the boundary of the approx-
88
 
c          imation domain, i.e   x = rad(v)*cos(v) , y = rad(v)*sin(v),
89
 
c          -pi <= v <= pi.
90
 
c          must be declared external in the calling (sub)program.
91
 
c  s     : real. on entry (in case iopt(1) >=0) s must specify the
92
 
c          smoothing factor. s >=0. unchanged on exit.
93
 
c          for advice on the choice of s see further comments
94
 
c  nuest : integer. unchanged on exit.
95
 
c  nvest : integer. unchanged on exit.
96
 
c          on entry, nuest and nvest must specify an upper bound for the
97
 
c          number of knots required in the u- and v-directions resp.
98
 
c          these numbers will also determine the storage space needed by
99
 
c          the routine. nuest >= 8, nvest >= 8.
100
 
c          in most practical situation nuest = nvest = 8+sqrt(m/2) will
101
 
c          be sufficient. see also further comments.
102
 
c  eps   : real.
103
 
c          on entry, eps must specify a threshold for determining the
104
 
c          effective rank of an over-determined linear system of equat-
105
 
c          ions. 0 < eps < 1.  if the number of decimal digits in the
106
 
c          computer representation of a real number is q, then 10**(-q)
107
 
c          is a suitable value for eps in most practical applications.
108
 
c          unchanged on exit.
109
 
c  nu    : integer.
110
 
c          unless ier=10 (in case iopt(1) >=0),nu will contain the total
111
 
c          number of knots with respect to the u-variable, of the spline
112
 
c          approximation returned. if the computation mode iopt(1)=1
113
 
c          is used, the value of nu should be left unchanged between
114
 
c          subsequent calls.
115
 
c          in case iopt(1)=-1,the value of nu must be specified on entry
116
 
c  tu    : real array of dimension at least nuest.
117
 
c          on succesful exit, this array will contain the knots of the
118
 
c          spline with respect to the u-variable, i.e. the position
119
 
c          of the interior knots tu(5),...,tu(nu-4) as well as the
120
 
c          position of the additional knots tu(1)=...=tu(4)=0 and
121
 
c          tu(nu-3)=...=tu(nu)=1 needed for the b-spline representation
122
 
c          if the computation mode iopt(1)=1 is used,the values of
123
 
c          tu(1),...,tu(nu) should be left unchanged between subsequent
124
 
c          calls. if the computation mode iopt(1)=-1 is used,the values
125
 
c          tu(5),...tu(nu-4) must be supplied by the user, before entry.
126
 
c          see also the restrictions (ier=10).
127
 
c  nv    : integer.
128
 
c          unless ier=10 (in case iopt(1)>=0), nv will contain the total
129
 
c          number of knots with respect to the v-variable, of the spline
130
 
c          approximation returned. if the computation mode iopt(1)=1
131
 
c          is used, the value of nv should be left unchanged between
132
 
c          subsequent calls. in case iopt(1)=-1, the value of nv should
133
 
c          be specified on entry.
134
 
c  tv    : real array of dimension at least nvest.
135
 
c          on succesful exit, this array will contain the knots of the
136
 
c          spline with respect to the v-variable, i.e. the position of
137
 
c          the interior knots tv(5),...,tv(nv-4) as well as the position
138
 
c          of the additional knots tv(1),...,tv(4) and tv(nv-3),...,
139
 
c          tv(nv) needed for the b-spline representation.
140
 
c          if the computation mode iopt(1)=1 is used, the values of
141
 
c          tv(1),...,tv(nv) should be left unchanged between subsequent
142
 
c          calls. if the computation mode iopt(1)=-1 is used,the values
143
 
c          tv(5),...tv(nv-4) must be supplied by the user, before entry.
144
 
c          see also the restrictions (ier=10).
145
 
c  u     : real array of dimension at least (m).
146
 
c  v     : real array of dimension at least (m).
147
 
c          on succesful exit, u(i),v(i) contains the co-ordinates of
148
 
c          the i-th data point with respect to the transformed rectan-
149
 
c          gular approximation domain, for i=1,2,...,m.
150
 
c          if the computation mode iopt(1)=1 is used the values of
151
 
c          u(i),v(i) should be left unchanged between subsequent calls.
152
 
c  c     : real array of dimension at least (nuest-4)*(nvest-4).
153
 
c          on succesful exit, c contains the coefficients of the spline
154
 
c          approximation s(u,v).
155
 
c  fp    : real. unless ier=10, fp contains the weighted sum of
156
 
c          squared residuals of the spline approximation returned.
157
 
c  wrk1  : real array of dimension (lwrk1). used as workspace.
158
 
c          if the computation mode iopt(1)=1 is used the value of
159
 
c          wrk1(1) should be left unchanged between subsequent calls.
160
 
c          on exit wrk1(2),wrk1(3),...,wrk1(1+ncof) will contain the
161
 
c          values d(i)/max(d(i)),i=1,...,ncof=1+iopt(2)*(iopt(2)+3)/2+
162
 
c          (nv-7)*(nu-5-iopt(2)-iopt(3)) with d(i) the i-th diagonal el-
163
 
c          ement of the triangular matrix for calculating the b-spline
164
 
c          coefficients.it includes those elements whose square is < eps
165
 
c          which are treated as 0 in the case of rank deficiency(ier=-2)
166
 
c  lwrk1 : integer. on entry lwrk1 must specify the actual dimension of
167
 
c          the array wrk1 as declared in the calling (sub)program.
168
 
c          lwrk1 must not be too small. let
169
 
c            k = nuest-7, l = nvest-7, p = 1+iopt(2)*(iopt(2)+3)/2,
170
 
c            q = k+2-iopt(2)-iopt(3) then
171
 
c          lwrk1 >= 129+10*k+21*l+k*l+(p+l*q)*(1+8*l+p)+8*m
172
 
c  wrk2  : real array of dimension (lwrk2). used as workspace, but
173
 
c          only in the case a rank deficient system is encountered.
174
 
c  lwrk2 : integer. on entry lwrk2 must specify the actual dimension of
175
 
c          the array wrk2 as declared in the calling (sub)program.
176
 
c          lwrk2 > 0 . a save upper bound  for lwrk2 = (p+l*q+1)*(4*l+p)
177
 
c          +p+l*q where p,l,q are as above. if there are enough data
178
 
c          points, scattered uniformly over the approximation domain
179
 
c          and if the smoothing factor s is not too small, there is a
180
 
c          good chance that this extra workspace is not needed. a lot
181
 
c          of memory might therefore be saved by setting lwrk2=1.
182
 
c          (see also ier > 10)
183
 
c  iwrk  : integer array of dimension (kwrk). used as workspace.
184
 
c  kwrk  : integer. on entry kwrk must specify the actual dimension of
185
 
c          the array iwrk as declared in the calling (sub)program.
186
 
c          kwrk >= m+(nuest-7)*(nvest-7).
187
 
c  ier   : integer. unless the routine detects an error, ier contains a
188
 
c          non-positive value on exit, i.e.
189
 
c   ier=0  : normal return. the spline returned has a residual sum of
190
 
c            squares fp such that abs(fp-s)/s <= tol with tol a relat-
191
 
c            ive tolerance set to 0.001 by the program.
192
 
c   ier=-1 : normal return. the spline returned is an interpolating
193
 
c            spline (fp=0).
194
 
c   ier=-2 : normal return. the spline returned is the weighted least-
195
 
c            squares constrained polynomial . in this extreme case
196
 
c            fp gives the upper bound for the smoothing factor s.
197
 
c   ier<-2 : warning. the coefficients of the spline returned have been
198
 
c            computed as the minimal norm least-squares solution of a
199
 
c            (numerically) rank deficient system. (-ier) gives the rank.
200
 
c            especially if the rank deficiency which can be computed as
201
 
c            1+iopt(2)*(iopt(2)+3)/2+(nv-7)*(nu-5-iopt(2)-iopt(3))+ier
202
 
c            is large the results may be inaccurate.
203
 
c            they could also seriously depend on the value of eps.
204
 
c   ier=1  : error. the required storage space exceeds the available
205
 
c            storage space, as specified by the parameters nuest and
206
 
c            nvest.
207
 
c            probably causes : nuest or nvest too small. if these param-
208
 
c            eters are already large, it may also indicate that s is
209
 
c            too small
210
 
c            the approximation returned is the weighted least-squares
211
 
c            polar spline according to the current set of knots.
212
 
c            the parameter fp gives the corresponding weighted sum of
213
 
c            squared residuals (fp>s).
214
 
c   ier=2  : error. a theoretically impossible result was found during
215
 
c            the iteration proces for finding a smoothing spline with
216
 
c            fp = s. probably causes : s too small or badly chosen eps.
217
 
c            there is an approximation returned but the corresponding
218
 
c            weighted sum of squared residuals does not satisfy the
219
 
c            condition abs(fp-s)/s < tol.
220
 
c   ier=3  : error. the maximal number of iterations maxit (set to 20
221
 
c            by the program) allowed for finding a smoothing spline
222
 
c            with fp=s has been reached. probably causes : s too small
223
 
c            there is an approximation returned but the corresponding
224
 
c            weighted sum of squared residuals does not satisfy the
225
 
c            condition abs(fp-s)/s < tol.
226
 
c   ier=4  : error. no more knots can be added because the dimension
227
 
c            of the spline 1+iopt(2)*(iopt(2)+3)/2+(nv-7)*(nu-5-iopt(2)
228
 
c            -iopt(3)) already exceeds the number of data points m.
229
 
c            probably causes : either s or m too small.
230
 
c            the approximation returned is the weighted least-squares
231
 
c            polar spline according to the current set of knots.
232
 
c            the parameter fp gives the corresponding weighted sum of
233
 
c            squared residuals (fp>s).
234
 
c   ier=5  : error. no more knots can be added because the additional
235
 
c            knot would (quasi) coincide with an old one.
236
 
c            probably causes : s too small or too large a weight to an
237
 
c            inaccurate data point.
238
 
c            the approximation returned is the weighted least-squares
239
 
c            polar spline according to the current set of knots.
240
 
c            the parameter fp gives the corresponding weighted sum of
241
 
c            squared residuals (fp>s).
242
 
c   ier=10 : error. on entry, the input data are controlled on validity
243
 
c            the following restrictions must be satisfied.
244
 
c            -1<=iopt(1)<=1 , 0<=iopt(2)<=2 , 0<=iopt(3)<=1 ,
245
 
c            m>=4-iopt(2)-iopt(3) , nuest>=8 ,nvest >=8, 0<eps<1,
246
 
c            0<=teta(i)<=pi, 0<=phi(i)<=2*pi, w(i)>0, i=1,...,m
247
 
c            lwrk1 >= 129+10*k+21*l+k*l+(p+l*q)*(1+8*l+p)+8*m
248
 
c            kwrk >= m+(nuest-7)*(nvest-7)
249
 
c            if iopt(1)=-1:9<=nu<=nuest,9+iopt(2)*(iopt(2)+1)<=nv<=nvest
250
 
c                          0<tu(5)<tu(6)<...<tu(nu-4)<1
251
 
c                          -pi<tv(5)<tv(6)<...<tv(nv-4)<pi
252
 
c            if iopt(1)>=0: s>=0
253
 
c            if one of these conditions is found to be violated,control
254
 
c            is immediately repassed to the calling program. in that
255
 
c            case there is no approximation returned.
256
 
c   ier>10 : error. lwrk2 is too small, i.e. there is not enough work-
257
 
c            space for computing the minimal least-squares solution of
258
 
c            a rank deficient system of linear equations. ier gives the
259
 
c            requested value for lwrk2. there is no approximation re-
260
 
c            turned but, having saved the information contained in nu,
261
 
c            nv,tu,tv,wrk1,u,v and having adjusted the value of lwrk2
262
 
c            and the dimension of the array wrk2 accordingly, the user
263
 
c            can continue at the point the program was left, by calling
264
 
c            polar with iopt(1)=1.
265
 
c
266
 
c further comments:
267
 
c  by means of the parameter s, the user can control the tradeoff
268
 
c   between closeness of fit and smoothness of fit of the approximation.
269
 
c   if s is too large, the spline will be too smooth and signal will be
270
 
c   lost ; if s is too small the spline will pick up too much noise. in
271
 
c   the extreme cases the program will return an interpolating spline if
272
 
c   s=0 and the constrained weighted least-squares polynomial if s is
273
 
c   very large. between these extremes, a properly chosen s will result
274
 
c   in a good compromise between closeness of fit and smoothness of fit.
275
 
c   to decide whether an approximation, corresponding to a certain s is
276
 
c   satisfactory the user is highly recommended to inspect the fits
277
 
c   graphically.
278
 
c   recommended values for s depend on the weights w(i). if these are
279
 
c   taken as 1/d(i) with d(i) an estimate of the standard deviation of
280
 
c   z(i), a good s-value should be found in the range (m-sqrt(2*m),m+
281
 
c   sqrt(2*m)). if nothing is known about the statistical error in z(i)
282
 
c   each w(i) can be set equal to one and s determined by trial and
283
 
c   error, taking account of the comments above. the best is then to
284
 
c   start with a very large value of s ( to determine the least-squares
285
 
c   polynomial and the corresponding upper bound fp0 for s) and then to
286
 
c   progressively decrease the value of s ( say by a factor 10 in the
287
 
c   beginning, i.e. s=fp0/10, fp0/100,...and more carefully as the
288
 
c   approximation shows more detail) to obtain closer fits.
289
 
c   to choose s very small is strongly discouraged. this considerably
290
 
c   increases computation time and memory requirements. it may also
291
 
c   cause rank-deficiency (ier<-2) and endager numerical stability.
292
 
c   to economize the search for a good s-value the program provides with
293
 
c   different modes of computation. at the first call of the routine, or
294
 
c   whenever he wants to restart with the initial set of knots the user
295
 
c   must set iopt(1)=0.
296
 
c   if iopt(1)=1 the program will continue with the set of knots found
297
 
c   at the last call of the routine. this will save a lot of computation
298
 
c   time if polar is called repeatedly for different values of s.
299
 
c   the number of knots of the spline returned and their location will
300
 
c   depend on the value of s and on the complexity of the shape of the
301
 
c   function underlying the data. if the computation mode iopt(1)=1
302
 
c   is used, the knots returned may also depend on the s-values at
303
 
c   previous calls (if these were smaller). therefore, if after a number
304
 
c   of trials with different s-values and iopt(1)=1,the user can finally
305
 
c   accept a fit as satisfactory, it may be worthwhile for him to call
306
 
c   polar once more with the selected value for s but now with iopt(1)=0
307
 
c   indeed, polar may then return an approximation of the same quality
308
 
c   of fit but with fewer knots and therefore better if data reduction
309
 
c   is also an important objective for the user.
310
 
c   the number of knots may also depend on the upper bounds nuest and
311
 
c   nvest. indeed, if at a certain stage in polar the number of knots
312
 
c   in one direction (say nu) has reached the value of its upper bound
313
 
c   (nuest), then from that moment on all subsequent knots are added
314
 
c   in the other (v) direction. this may indicate that the value of
315
 
c   nuest is too small. on the other hand, it gives the user the option
316
 
c   of limiting the number of knots the routine locates in any direction
317
 
c
318
 
c  other subroutines required:
319
 
c    fpback,fpbspl,fppola,fpdisc,fpgivs,fprank,fprati,fprota,fporde,
320
 
c    fprppo
321
 
c
322
 
c  references:
323
 
c   dierckx p.: an algorithm for fitting data over a circle using tensor
324
 
c               product splines,j.comp.appl.maths 15 (1986) 161-173.
325
 
c   dierckx p.: an algorithm for fitting data on a circle using tensor
326
 
c               product splines, report tw68, dept. computer science,
327
 
c               k.u.leuven, 1984.
328
 
c   dierckx p.: curve and surface fitting with splines, monographs on
329
 
c               numerical analysis, oxford university press, 1993.
330
 
c
331
 
c  author:
332
 
c    p.dierckx
333
 
c    dept. computer science, k.u. leuven
334
 
c    celestijnenlaan 200a, b-3001 heverlee, belgium.
335
 
c    e-mail : Paul.Dierckx@cs.kuleuven.ac.be
336
 
c
337
 
c  creation date : june 1984
338
 
c  latest update : march 1989
339
 
c
340
 
c  ..
341
 
c  ..scalar arguments..
342
 
      real*8 s,eps,fp
343
 
      integer m,nuest,nvest,nu,nv,lwrk1,lwrk2,kwrk,ier
344
 
c  ..array arguments..
345
 
      real*8 x(m),y(m),z(m),w(m),tu(nuest),tv(nvest),u(m),v(m),
346
 
     * c((nuest-4)*(nvest-4)),wrk1(lwrk1),wrk2(lwrk2)
347
 
      integer iopt(3),iwrk(kwrk)
348
 
c  ..user specified function
349
 
      real*8 rad
350
 
c  ..local scalars..
351
 
      real*8 tol,pi,dist,r,one
352
 
      integer i,ib1,ib3,ki,kn,kwest,la,lbu,lcc,lcs,lro,j
353
 
     * lbv,lco,lf,lff,lfp,lh,lq,lsu,lsv,lwest,maxit,ncest,ncc,nuu,
354
 
     * nvv,nreg,nrint,nu4,nv4,iopt1,iopt2,iopt3,ipar,nvmin
355
 
c  ..function references..
356
 
      real*8 datan2,sqrt
357
 
      external rad
358
 
c  ..subroutine references..
359
 
c    fppola
360
 
c  ..
361
 
c  set up constants
362
 
      one = 1d0
363
 
c  we set up the parameters tol and maxit.
364
 
      maxit = 20
365
 
      tol = 0.1e-02
366
 
c  before starting computations a data check is made. if the input data
367
 
c  are invalid,control is immediately repassed to the calling program.
368
 
      ier = 10
369
 
      if(eps.le.0. .or. eps.ge.1.) go to 60
370
 
      iopt1 = iopt(1)
371
 
      if(iopt1.lt.(-1) .or. iopt1.gt.1) go to 60
372
 
      iopt2 = iopt(2)
373
 
      if(iopt2.lt.0 .or. iopt2.gt.2) go to 60
374
 
      iopt3 = iopt(3)
375
 
      if(iopt3.lt.0 .or. iopt3.gt.1) go to 60
376
 
      if(m.lt.(4-iopt2-iopt3)) go to 60
377
 
      if(nuest.lt.8 .or. nvest.lt.8) go to 60
378
 
      nu4 = nuest-4
379
 
      nv4 = nvest-4
380
 
      ncest = nu4*nv4
381
 
      nuu = nuest-7
382
 
      nvv = nvest-7
383
 
      ipar = 1+iopt2*(iopt2+3)/2
384
 
      ncc = ipar+nvv*(nuest-5-iopt2-iopt3)
385
 
      nrint = nuu+nvv
386
 
      nreg = nuu*nvv
387
 
      ib1 = 4*nvv
388
 
      ib3 = ib1+ipar
389
 
      lwest = ncc*(1+ib1+ib3)+2*nrint+ncest+m*8+ib3+5*nuest+12*nvest
390
 
      kwest = m+nreg
391
 
      if(lwrk1.lt.lwest .or. kwrk.lt.kwest) go to 60
392
 
      if(iopt1.gt.0) go to 40
393
 
      do 10 i=1,m
394
 
        if(w(i).le.0.) go to 60
395
 
        dist = x(i)**2+y(i)**2
396
 
        u(i) = 0.
397
 
        v(i) = 0.
398
 
        if(dist.le.0.) go to 10
399
 
        v(i) = datan2(y(i),x(i))
400
 
        r = rad(v(i))
401
 
        if(r.le.0.) go to 60
402
 
        u(i) = sqrt(dist)/r
403
 
        if(u(i).gt.one) go to 60
404
 
  10  continue
405
 
      if(iopt1.eq.0) go to 40
406
 
      nuu = nu-8
407
 
      if(nuu.lt.1 .or. nu.gt.nuest) go to 60
408
 
      tu(4) = 0.
409
 
      do 20 i=1,nuu
410
 
         j = i+4
411
 
         if(tu(j).le.tu(j-1) .or. tu(j).ge.one) go to 60
412
 
  20  continue
413
 
      nvv = nv-8
414
 
      nvmin = 9+iopt2*(iopt2+1)
415
 
      if(nv.lt.nvmin .or. nv.gt.nvest) go to 60
416
 
      pi = datan2(0d0,-one)
417
 
      tv(4) = -pi
418
 
      do 30 i=1,nvv
419
 
         j = i+4
420
 
         if(tv(j).le.tv(j-1) .or. tv(j).ge.pi) go to 60
421
 
  30  continue
422
 
      go to 50
423
 
  40  if(s.lt.0.) go to 60
424
 
  50  ier = 0
425
 
c  we partition the working space and determine the spline approximation
426
 
      kn = 1
427
 
      ki = kn+m
428
 
      lq = 2
429
 
      la = lq+ncc*ib3
430
 
      lf = la+ncc*ib1
431
 
      lff = lf+ncc
432
 
      lfp = lff+ncest
433
 
      lco = lfp+nrint
434
 
      lh = lco+nrint
435
 
      lbu = lh+ib3
436
 
      lbv = lbu+5*nuest
437
 
      lro = lbv+5*nvest
438
 
      lcc = lro+nvest
439
 
      lcs = lcc+nvest
440
 
      lsu = lcs+nvest*5
441
 
      lsv = lsu+m*4
442
 
      call fppola(iopt1,iopt2,iopt3,m,u,v,z,w,rad,s,nuest,nvest,eps,tol,
443
 
     *
444
 
     * maxit,ib1,ib3,ncest,ncc,nrint,nreg,nu,tu,nv,tv,c,fp,wrk1(1),
445
 
     * wrk1(lfp),wrk1(lco),wrk1(lf),wrk1(lff),wrk1(lro),wrk1(lcc),
446
 
     * wrk1(lcs),wrk1(la),wrk1(lq),wrk1(lbu),wrk1(lbv),wrk1(lsu),
447
 
     * wrk1(lsv),wrk1(lh),iwrk(ki),iwrk(kn),wrk2,lwrk2,ier)
448
 
  60  return
449
 
      end
450