function [detect,stopint,direction]=endevent(t,y) 
% Locate the time when height passes through zero
% and stop integration.
detect=y(3); % Detect height = 0
stopint=1; % Stop the integration
direction=0; % Direction does not matter
end