function vals = point_interpolate(lattice, points, volumes, time)
% Gives the interpolating spline of the point values.
%
% lattice has two parts, lattice.points is an array of points (rowwise)
% lattice.cells is an array of cells (rowwise pointids)
% points contains the prescribed point values in the form
% (pointid, value, timeofmeasurement)
%
% We return a vals array, which contains in vals.points the values at the
% points to be interpolated and at vals.centers the values at the centers to
% be interpolated
weightfunction = @(t) (t>=0).*exp(-t).*(t<=5);
% kill "future" and irrelevant values":
idx = find(weightfunction(time-points(:,3))>0);
points = points(idx, :);
idx = find(weightfunction(time-volumes(:,3))>0);
volumes = volumes(idx,:);
% for each pointid, we form the weightted average of the measurements
vals.points = zeros(size(lattice.points, 1), 1);
for i = 1:length(vals.points)
idx = find(points(:,1) == i);
weights = weightfunction(points(idx, 3));
vals.points(i) = (weights .* points(idx, 2)) / sum(weights);
end;
% for each cellid, we form the weighted average of the measurements
vals.centers = zeros(size(lattice.cells, 1), 1);
for i = 1:length(vals.centers)
idx = find(volumes(:, 1) == i);
weights = weightfunction(volumes(idx, 3));
vals.centers(i) = (weights .* volumes(idx, 2)) / sum(weights);
end;