File: intp.f

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (51 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
      subroutine intp(x,xd,yd,n,nc,y)
c!purpose
c     linear interpolation computes y=F(x) for f a tabulated function
c      from R to R^n 
c!parameters
c     x    : x given point
c     xd   : vector (nc) of abscissae mesh points (xd(i+1)>=xd(i))
c     yd   : matrix (nc x n): yd(i,j)=Fj(x(i))
c     n    : dimension of F image
c     returned values
c     y    : vector (n) :interpolated value of F(x)
c!remarks
c     if x<=xd(1) y=yd(1,:)
c      if x>=xd(nc) y=yd(nc,:)
c!origin
c     Pejman GOHARI 1996
c!
c     Copyright INRIA
      double precision x,xd(*),y(*),yd(nc,*)
      integer n,nc
c     
      if (nc.eq.1) then
         call dcopy(n,yd(1,1),nc,y,1)
      elseif(x.ge.xd(nc)) then 
         call dcopy(n,yd(nc,1),nc,y,1)
      elseif(x.le.xd(1)) then 
         call dcopy(n,yd(1,1),nc,y,1)
      else
c     find x interval
         do 10 i=1,nc
            if (x.lt.xd(i)) then
               inter=i-1
               goto 20
            endif
 10      continue
 20      continue
c     
c     compute interpolated y
c     
         if (xd(inter+1).eq.xd(inter)) then
            call dcopy(n,yd(inter,1),nc,y,1)
         else
            do 40 i=1,n
               y(i)=yd(inter,i)+
     &              (x-xd(inter))*((yd(inter+1,i)-yd(inter,i))/
     &              (xd(inter+1)-xd(inter)))
 40         continue
         endif
      endif
      end