I am trying to perform linear interpolation on three columns in a CSV file.
When I run this code, I do not get any changes in the output (see Expected Output).
What am I doing wrong here?
Awk Code
'
function interpolate(lat1, lon1, t1, lat2, lon2, t2, i) {
for (i = 1; i <= (t2 - t1); i++) {
printf "%.2f,%.2f,%d\n",
lat1 + i * (lat2 - lat1) / (t2 - t1),
lon1 + i * (lon2 - lon1) / (t2 - t1),
t1 + i
}
}
NR <= 1 {print}
NR >= 2 {interpolate(lat, lon, t, $1, $2, $3)}
{lat = $1; lon = $2; t = $3}
' file.in.csv > file.out.csv
file.in.csv
22.70,-68.00,0
22.77,-68.13,1
22.83,-68.27,2
22.90,-68.40,3
22.97,-68.53,4
23.03,-68.67,5
Expected Output
22.70,-68.00,0
22.74,-68.07,0.5
22.77,-68.13,1
22.80,-68.20,1.5
22.83,-68.27,2
22.87,-68.34,2.5
22.90,-68.40,3
22.94,-68.47,3.5
22.97,-68.53,4
23.00,-68.60,4.5
23.03,-68.67,5