V3FIT
r8pc1ev.f
1  subroutine r8pc1ev(xget,x,nx,ilinx,f,ict,fval,ier)
2 C
3 C evaluate a 1d piecewise linear interpolant -- this is C0.
4 C ...a derivative can be evaluated but it is not continuous.
5 C
6 C this subroutine calls two subroutines:
7 C herm1x -- find cell containing (xget,yget)
8 C pc1fcn -- evaluate interpolant function and (optionally) derivatives
9 C
10 C input arguments:
11 C ================
12 C
13 !============
14 ! idecl: explicitize implicit INTEGER declarations:
15  IMPLICIT NONE
16  INTEGER, PARAMETER :: R8=selected_real_kind(12,100)
17  INTEGER nx
18 !============
19  real*8 xget ! target of this interpolation
20  real*8 x(nx) ! ordered x grid
21  integer ilinx ! ilinx=1 => assume x evenly spaced
22 C
23  real*8 f(nx) ! function data
24 C
25 C contents of f:
26 C
27 C f(i) = f @ x(i)
28 C
29  integer ict(2) ! code specifying output desired
30 C
31 C ict(1)=1 -- return f (0, don't)
32 C ict(2)=1 -- return df/dx (0, don't)
33 C
34 C output arguments:
35 C =================
36 C
37  real*8 fval(*) ! output data
38  integer ier ! error code =0 ==> no error
39 C
40 C fval(1) receives the first output (depends on ict(...) spec)
41 C fval(2) receives the second output (depends on ict(...) spec)
42 C
43 C examples:
44 C on input ict = [1,1]
45 C on output fval= [f,df/dx]
46 C
47 C on input ict = [1,0]
48 C on output fval= [f] ... element 2 never referenced
49 C
50 C on input ict = [0,1]
51 C on output fval= [df/dx] ... element 2 never referenced
52 C
53 C ier -- completion code: 0 means OK
54 C-------------------
55 C local:
56 C
57  integer :: i=0 ! cell index
58 c
59 C normalized displacement from (x(i)) corner of cell.
60 C xparam=0 @x(i) xparam=1 @x(i+1)
61 C
62  real*8 xparam
63 C
64 C cell dimensions and
65 C inverse cell dimensions hxi = 1/(x(i+1)-x(i))
66 C
67  real*8 hx
68  real*8 hxi
69 C
70 C 0 .le. xparam .le. 1
71 C
72 C---------------------------------------------------------------------
73 C
74  call r8herm1x(xget,x,nx,ilinx,i,xparam,hx,hxi,ier)
75  if(ier.ne.0) return
76 c
77  call r8pc1fcn(ict,1,1,fval,i,xparam,hx,hxi,f,nx)
78 C
79  return
80  end
81 C---------------------------------------------------------------------
82 C evaluate C0 piecewise linear function interpolation -- 1d fcn
83 C --vectorized-- dmc 10 Feb 1999
84 C
85  subroutine r8pc1fcn(ict,ivec,ivecd,
86  > fval,ii,xparam,hx,hxi,fin,nx)
87 C
88 C input:
89 C
90 !============
91 ! idecl: explicitize implicit INTEGER declarations:
92  IMPLICIT NONE
93  INTEGER, PARAMETER :: R8=selected_real_kind(12,100)
94  INTEGER nx,i,iadr
95 !============
96 ! idecl: explicitize implicit REAL declarations:
97  real*8 xp,xpi
98 !============
99  integer ict(2) ! requested output control
100  integer ivec ! vector length
101  integer ivecd ! vector dimension (1st dim of fval)
102 C
103  integer ii(ivec) ! target cells
104  real*8 xparam(ivec)
105  ! normalized displacements in cells
106 C
107  real*8 hx(ivec) ! grid spacing, and
108  real*8 hxi(ivec) ! inverse grid spacing 1/(x(i+1)-x(i))
109 C
110  real*8 fin(nx) ! the data
111 C
112 C output:
113 C
114  real*8 fval(ivecd,*) ! interpolation results
115 C
116 C for detailed description of fin, ict and fval see subroutine
117 C pc1ev comments. Note ict is not vectorized -- the same output
118 C is expected to be returned for all input vector data points.
119 C
120 C note that the index inputs ii, and parameter inputs
121 C xparam,hx,hxi,are vectorized, and the
122 C
123 C output array fval has a vector ** 1st dimension ** whose
124 C size must be given as a separate argument; ivecd.ge.ivec
125 C expected!
126 C
127 C to use this routine in scalar mode, pass in ivec=ivecd=1
128 C
129 C---------------
130 C
131  integer v
132 C
133  do v=1,ivec
134  i=ii(v)
135  xp=xparam(v)
136  xpi=1.0_r8-xp
137 C
138  iadr=0
139 C
140 C get desired values:
141 C
142  if(ict(1).eq.1) then
143 C
144 C function value:
145 C
146  iadr=iadr+1
147  fval(v,iadr)=xpi*fin(i)+xp*fin(i+1)
148 C
149  endif
150 C
151  if(ict(2).eq.1) then
152 C
153 C df/dx:
154 C
155  iadr=iadr+1
156 C
157  fval(v,iadr)=(fin(i+1)-fin(i))*hxi(v)
158  endif
159 C
160  enddo ! vector loop
161 C
162  return
163  end