V3FIT
setspline.f
1  SUBROUTINE setspline(x,weight,y,h,yfit,y2,wten,tens,nots,nb)
2  USE vspline
3  USE vparams, ONLY: zero
4  IMPLICIT NONE
5 C-----------------------------------------------
6 C D u m m y A r g u m e n t s
7 C-----------------------------------------------
8  INTEGER nots, nb
9  REAL(rprec) tens
10  REAL(rprec), DIMENSION(*) :: x, weight
11  REAL(rprec), DIMENSION(nots) :: y
12  REAL(rprec), DIMENSION(*) :: h
13  REAL(rprec), DIMENSION(nots) :: yfit
14  REAL(rprec), DIMENSION(*) :: y2, wten
15 C-----------------------------------------------
16 C L o c a l V a r i a b l e s
17 C-----------------------------------------------
18  INTEGER :: ioff, info
19  REAL(rprec) :: alsq(nots,nots)
20 C-----------------------------------------------
21 !
22 ! x: independent coordinate array
23 ! y: dependent y(x) array
24 ! yfit: fitted values (under tension) to y array
25 ! h: x(i+1) - x(i) array
26 ! y2: y'' array used for splines
27 ! wten: weight array for tension (changed on EXIT)
28 ! alsq: matrix elements for least squares fit (from s-integrations)
29 ! nots: number of independent coordinates (knots)
30 ! nb: = NATUR, USE natural boundary condition at left knot
31 ! = IDERIV, USE derivative (dy/dx =0) boundary condition at left knot
32 
33 !
34 ! IT IS ASSUMED THAT X,Y,WTEN ARE ALL SORTED (ON X(I) < X(I+1))
35 !
36 
37 !
38 ! INITIALIZE ALSQ TO ZERO, COMPUTE H ELEMENTS
39 !
40  CALL initspline (alsq, x, h, weight, nots)
41 
42 !
43 ! SET UP SPLINE MATRIX ASPLINE AND NON-DIMENSIONLIZE TENSION
44 !
45  ioff = 0
46  CALL add_tension (alsq, wten, h, tens, zero, zero, nots, nb,
47  1 ioff, nots)
48 
49 !
50 ! SOLVE FOR COEFFICIENTS
51 !
52  yfit(:nots) = y(:nots)
53  CALL solver (alsq, yfit, nots, 1, info)
54 !
55 ! OBTAIN Y'' COEFFICIENTS AND STORE IN Y2
56 !
57  CALL gety2 (yfit, y2, h, nots, nb)
58 
59  END SUBROUTINE setspline