Category : Miscellaneous Language Source Code
Archive   : AWKDEMO2.ZIP
Filename : LINTERP.AWK
# S.H. Moody, 09-10-89
# Usage: AWK LINTERP INFILE.EXT
# Input file format:
# Table of x, y input data with monotonically increasing x,
# followed by at least one blank line, followed by a single line containing
# the Begin, End and Delta of the range of x-values to be interpolated.
# Interpolates using a straight line through the nearest 2 points:
# Y = A + B * (X - x0)
# where
# A = y0
# B = (y1 - y0) / (x1 - x0)
{
if( ($1 !~ /[0-9-"."]/) && ($2 !~ /[0-9-"."]/) ) {
if(n == 0) {
print;
next;
}
else exit;
}
n++;
x[n] = $1 + 0;
y[n] = $2 + 0;
printf("%10.4f, %10.4f\n", x[n], y[n]);
}
END {
while(NF != 3)
getline;
first = $1;
last = $2;
delta = $3;
printf("\nInterpolated values:\n");
for(xx = first; xx <= last; xx+= delta) {
nn = 1;
tmp = 0;
while ( x[nn] < xx) {
tmp = nn;
if(nn == n)
break;
nn++;
}
if(tmp <= 1) {
n0 = 1;
n1 = 2;
}
else if(tmp >= (n - 1) ) {
n0 = n - 1;
n1 = n;
}
else {
n0 = tmp;
n1 = tmp + 1;
}
Y = y[n0] + ( (y[n1] - y[n0]) / (x[n1] - x[n0]) ) * (xx - x[n0]);
printf("%10.4f %10.4f\n", xx, Y);
# getline;
}
printf("\n");
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/