function [value, isterminal, direction] = efun(t,w)
% event function. stop integrating when T-Tdew>tol.

NC = 4;
N = 10;
T = w(2*N+NC*N+1:3*N+N*NC)';
Tdew = -11.1+273.15;
tol = 1e-3;
value = double((T-Tdew < tol));     % cheks that at least one temperature is bellow the dew point
isterminal = ones(1,N);            % stop integrationg
direction = [];                     % all zeros are to be located (the default). A value of +1 locates only zeros where the event function is increasing, and -1 locates only zeros where the event function is decreasing.
end    