|
1 #====================================================================== |
|
2 # . I N T E R P . L I N E A R |
|
3 # doc: Wed Nov 22 21:01:09 2000 |
|
4 # dlm: Tue Aug 5 14:13:14 2008 |
|
5 # (c) 2000 A.M. Thurnherr |
|
6 # uE-Info: 23 47 NIL 0 0 72 2 2 4 NIL ofnI |
|
7 #====================================================================== |
|
8 |
|
9 # linear interpolation |
|
10 |
|
11 # HISTORY: |
|
12 # Nov 22, 2000: - created |
|
13 # Jul 28, 2006: - Version 3.3 [HISTORY] |
|
14 # - added xf to ISInit() args |
|
15 # Aug 22, 2006: - modified to allow use with [match] |
|
16 # Aug 5, 2008: - added idr param to IS_init() |
|
17 |
|
18 # NOTES: |
|
19 # - the [.interp.*] routines assume that x increases strictly monotonically; |
|
20 # for utilities dealing with non-monotonic data, use [.nminterp.*] instead |
|
21 # - the [.interp.*] routines are written to work on multiple buffers, |
|
22 # rather than just @ants_; this implies that data created by IS_init() |
|
23 # must be stored separately for each buffer |
|
24 |
|
25 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
26 # |
|
27 # THE FOLLOWING VARIABLES MUST BE SET GLOBALLY (i.e. during loading) |
|
28 # |
|
29 # $IS_opts string of allowed options |
|
30 # $IS_optsUsage usage information string for options |
|
31 # |
|
32 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
33 |
|
34 $IS_opts = ""; |
|
35 $IS_optsUsage = ""; |
|
36 |
|
37 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
38 # |
|
39 # &IS_usage() mangle parameters (options, really) |
|
40 # |
|
41 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
42 |
|
43 sub IS_usage() {} |
|
44 |
|
45 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
46 # |
|
47 # &IS_init(br,f,xf) init interpolation of field f |
|
48 # br data buffer reference |
|
49 # idr init-data reference |
|
50 # f field number |
|
51 # xf x field number |
|
52 # <ret val> none |
|
53 # |
|
54 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
55 |
|
56 sub IS_init($$$$) {} |
|
57 |
|
58 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
59 # |
|
60 # &IS_interpolate(br,idr,xf,xv,xi,f) interpolate field f |
|
61 # br data buffer reference |
|
62 # idr init-data reference |
|
63 # xf x field |
|
64 # xv x value |
|
65 # xi index of last record with x-value <= x |
|
66 # f field number to interpolate |
|
67 # <ret val> interpolated value |
|
68 # |
|
69 # NB: |
|
70 # - handle f == xf |
|
71 # - return NaN if any of the y values required is NaN |
|
72 # |
|
73 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
74 |
|
75 sub IS_interpolate($$$$$$) |
|
76 { |
|
77 my($bR,$idR,$xf,$xv,$xi,$f) = @_; |
|
78 return $xv if ($xf == $f); |
|
79 return nan unless (numberp($bR->[$xi][$f]) && numberp($bR->[$xi+1][$f])); |
|
80 |
|
81 my($sc) = ($xv - $bR->[$xi][$xf]) / ($bR->[$xi+1][$xf] - $bR->[$xi][$xf]); |
|
82 return $bR->[$xi][$f] + $sc * ($bR->[$xi+1][$f] - $bR->[$xi][$f]); |
|
83 } |
|
84 |
|
85 #---------------------------------------------------------------------- |
|
86 |
|
87 1; |