V3FIT
vecintrp3d.f
1  subroutine vecintrp3d(ict,ivec,xvec,yvec,zvec,ivd,fval,
2  > nx,xpkg,ny,ypkg,nz,zpkg,jspline,fspl,icoeff,ixdim,iydim,izdim,
3  > iwarn,ier)
4 c
5  implicit NONE
6 c
7 c vectorized hybrid spline evaluation routine -- 3d
8 c 1. call vectorized zone lookup routine
9 c 2. call vectorized hybrid spline evaluation routine
10 c
11 c--------------------------
12 c input:
13  integer ict(10) ! selector:
14 c ict(1)=1 for f (don't evaluate if ict(1)=0)
15 c ict(2)=1 for df/dx (don't evaluate if ict(2)=0)
16 c ict(3)=1 for df/dy (don't evaluate if ict(3)=0)
17 c ict(4)=1 for df/dy (don't evaluate if ict(4)=0)
18 c ict(5)=1 for d2f/dx2 (don't evaluate if ict(5)=0)
19 c ict(6)=1 for d2f/dy2 (don't evaluate if ict(6)=0)
20 c ict(7)=1 for d2f/dz2 (don't evaluate if ict(7)=0)
21 c ict(8)=1 for d2f/dxdy (don't evaluate if ict(8)=0)
22 c ict(9)=1 for d2f/dxdz (don't evaluate if ict(9)=0)
23 c ict(10)=1 for d2f/dydz (don't evaluate if ict(10)=0)
24 c
25 c higher derivatives can be selected by setting ict(1)=3,-3,4,-4,...
26 c see fvtricub.for comments.
27 c
28 c in hybrid spline evaluation, any derivative along a dimension
29 c with zonal interpolation (jspline(i)=-1) gives zero;
30 c
31 c piecewise linear and Hermite interpolation give zero if a 2nd or
32 c higher derivative is sought along any dimension.
33 c
34  integer ivec ! vector dimensioning
35 c
36 c ivec-- number of vector pts (spline values to look up)
37 c
38 c list of (x,y,z) triples:
39 c
40  real xvec(ivec) ! x-locations at which to evaluate
41  real yvec(ivec) ! y-locations at which to evaluate
42  real zvec(ivec) ! z-locations at which to evaluate
43 c
44  integer ivd ! 1st dimension of output array
45 c
46 c ivd -- 1st dimension of fval, .ge.ivec
47 c
48 c output:
49  real fval(ivd,*) ! output array
50 c
51 c fval(1:ivec,1) -- values as per 1st non-zero ict(...) element
52 c fval(1:ivec,2) -- values as per 2nd non-zero ict(...) element
53 c --etc--
54 c
55 c input:
56  integer nx,ny,nz ! dimension of spline grids
57  real xpkg(nx,4) ! x grid "package" (cf genxpkg)
58  real ypkg(ny,4) ! y grid "package" (cf genxpkg)
59  real zpkg(nz,4) ! z grid "package" (cf genxpkg)
60 c
61  integer :: jspline(3) ! interpolation method on each dim:
62 c jspline(1) for x; jspline(2) for y; jspline(3) for z
63 c -1: zonal step fcn; 0: pcwise linear; 1: Hermite; 2: compact spline
64 c
65  integer icoeff ! #coeffs per data node
66  integer ixdim ! x dim for fspl
67  integer iydim ! y dim for fspl
68  integer izdim ! z dim for fspl
69  real fspl(icoeff,ixdim,iydim,izdim) ! hybrid spline coefficients
70 c
71 c ixdim=nx-1 for zonal step function along x dimension; o.w. expect ixdim=nx
72 c iydim=ny-1 for zonal step function along y dimension; o.w. expect iydim=ny
73 c izdim=nz-1 for zonal step function along z dimension; o.w. expect izdim=nz
74 c
75 c output:
76 c condition codes, 0 = normal return
77  integer iwarn ! =1 if an x value was out of range
78  integer ier ! =1 if argument error detected
79 c
80 c---------------------------------------------------------------
81 c local arrays
82 c
83  integer :: iwarn1,iwarn2,iwarn3
84 c
85  integer, dimension(:), allocatable :: ix,iy,iz
86  real, dimension(:), allocatable :: dxn,dyn,dzn
87  real, dimension(:), allocatable :: hx,hxi,hy,hyi,hz,hzi
88 c
89 c---------------------------------------------------------------
90 c
91 c error checks
92 c
93  ier=0
94 c
95  if(nx.lt.2) then
96  write(6,*) .lt.' ?vecintrp3d: nx2: nx = ',nx
97  ier=1
98  endif
99 c
100  if(ny.lt.2) then
101  write(6,*) .lt.' ?vecintrp3d: ny2: ny = ',ny
102  ier=1
103  endif
104 c
105  if(nz.lt.2) then
106  write(6,*) .lt.' ?vecintrp3d: nz2: nz = ',nz
107  ier=1
108  endif
109 c
110  call vecin3d_argchk('vecintrp3d',jspline,
111  > icoeff,nx,ny,nz,ixdim,iydim,izdim,ier)
112 c
113  if(ivec.le.0) then
114  write(6,*) .le.' ?vecintrp3d: vector dimension 0: ivec = ',
115  > ivec
116  ier=1
117  endif
118 c
119  if(ivd.lt.ivec) then
120  write(6,*)
121  > ' ?vecintrp3d: output vector dimension less than input ',
122  > 'vector dimension.'
123  write(6,*) ' ivec=',ivec,' ivd=',ivd
124  ier=1
125  endif
126 c
127  if(ier.ne.0) return
128 c
129  allocate(ix(ivec), iy(ivec), iz(ivec),
130  > dxn(ivec), dyn(ivec), dzn(ivec),
131  > hx(ivec), hy(ivec), hz(ivec),
132  > hxi(ivec), hyi(ivec), hzi(ivec), stat=ier)
133 c
134  if(ier.ne.0) then
135  write(6,*)
136  > ' ?vecintrp3d: memory allocation failure.'
137  ier=99
138  endif
139 c
140  if(ier.ne.0) return
141 c
142 c vectorized lookup
143 c
144  ix=0; iy=0; iz=0
145  call xlookup(ivec,xvec,nx,xpkg,2,ix,dxn,hx,hxi,iwarn1)
146  call xlookup(ivec,yvec,ny,ypkg,2,iy,dyn,hy,hyi,iwarn2)
147  call xlookup(ivec,zvec,nz,zpkg,2,iz,dzn,hz,hzi,iwarn3)
148  iwarn=max(iwarn1,iwarn2,iwarn3)
149 c
150 c vectorized evaluation
151 c
152  call fvintrp3d(ict,ivec,ivd,fval,ix,iy,iz,dxn,dyn,dzn,
153  > hx,hxi,hy,hyi,hz,hzi,jspline,fspl,icoeff,ixdim,iydim,izdim)
154 c
155  deallocate(ix,iy,iz,dxn,dyn,dzn,hx,hy,hz,hxi,hyi,hzi)
156 c
157  return
158  end