#!/bin/sh
# computes piecewise interpolation with derivatives, based on 5-tupels
# NEW (2009/10/07: start/end point using 4-tupels) 
TMP=`mktemp`

awk '{if (($1!="#")&&(NF>2)) {n++; x[n]=$1; y[n]=$2; dy[n]=$3}}END{filen="'${TMP}'"; for (i=2; i<=n-1; i++) {if(i==2) min=-1; else min=-2; if (i==n-1) max=1; else max=2; for (j=min;j<=max;j++) print x[i+j]-x[i], dy[i+j], y[i+j] >> filen; printf ("%g  ", x[i]); system ("cat " filen " | polyfit -llllllll"); system ("echo \"\" >" filen)}}'
