39
|
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: Fri Sep 23 16:32:20 2011
|
|
5 |
# (c) 2000 A.M. Thurnherr
|
|
6 |
# uE-Info: 62 0 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 |
# Sep 23, 2011: - added support for xfnr==-1 (%RECNO)
|
|
18 |
|
|
19 |
# NOTES:
|
|
20 |
# - the [.interp.*] routines assume that x increases strictly monotonically;
|
|
21 |
# for utilities dealing with non-monotonic data, use [.nminterp.*] instead
|
|
22 |
# - the [.interp.*] routines are written to work on multiple buffers,
|
|
23 |
# rather than just @ants_; this implies that data created by IS_init()
|
|
24 |
# must be stored separately for each buffer
|
|
25 |
|
|
26 |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
27 |
#
|
|
28 |
# THE FOLLOWING VARIABLES MUST BE SET GLOBALLY (i.e. during loading)
|
|
29 |
#
|
|
30 |
# $IS_opts string of allowed options
|
|
31 |
# $IS_optsUsage usage information string for options
|
|
32 |
#
|
|
33 |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
34 |
|
|
35 |
$IS_opts = "";
|
|
36 |
$IS_optsUsage = "";
|
|
37 |
|
|
38 |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
39 |
#
|
|
40 |
# &IS_usage() mangle parameters (options, really)
|
|
41 |
#
|
|
42 |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
43 |
|
|
44 |
sub IS_usage() {}
|
|
45 |
|
|
46 |
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
47 |
#
|
|
48 |
# &IS_init(br,f,xf) init interpolation of field f
|
|
49 |
# br data buffer reference
|
|
50 |
# idr init-data reference
|
|
51 |
# f field number
|
|
52 |
# xf x field number or -1 for %RECNO
|
|
53 |
# <ret val> none
|
|
54 |
#
|
|
55 |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
56 |
|
|
57 |
sub IS_init($$$$) {}
|
|
58 |
|
|
59 |
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
60 |
#
|
|
61 |
# &IS_interpolate(bR,idR,xf,xv,xi,f) interpolate field f
|
|
62 |
# bR data buffer reference
|
|
63 |
# idR init-data reference
|
|
64 |
# xf x field or -1 for %RECNO
|
|
65 |
# xv x value
|
|
66 |
# xi index of last record with x-value <= x
|
|
67 |
# f field number to interpolate
|
|
68 |
# <ret val> interpolated value
|
|
69 |
#
|
|
70 |
# NB:
|
|
71 |
# - handle f == xf
|
|
72 |
# - return NaN if any of the y values required is NaN
|
|
73 |
#
|
|
74 |
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
75 |
|
|
76 |
sub IS_interpolate($$$$$$)
|
|
77 |
{
|
|
78 |
my($bR,$idR,$xf,$xv,$xi,$f) = @_;
|
|
79 |
return $xv if ($xf == $f);
|
|
80 |
return nan unless (numberp($bR->[$xi][$f]) && numberp($bR->[$xi+1][$f]));
|
|
81 |
|
|
82 |
my($sc) = ($xf < 0)
|
|
83 |
? ($xv - $bR->[$xi][$xf]) / ($bR->[$xi+1][$xf] - $bR->[$xi][$xf]);
|
|
84 |
: ($xv - $bR->[$xi][$xf]) / ($bR->[$xi+1][$xf] - $bR->[$xi][$xf]);
|
|
85 |
return $bR->[$xi][$f] + $sc * ($bR->[$xi+1][$f] - $bR->[$xi][$f]);
|
|
86 |
}
|
|
87 |
|
|
88 |
#----------------------------------------------------------------------
|
|
89 |
|
|
90 |
1;
|