function [rise set day] = sunriseset(lon,lat,alt,time,UTC)
% INPUT
% lon: longitude, latitude [degrees], altitude [m], time [datenum], UTC
% time offset
% OUTPUT
% rise: sunrise interpolated from hourly values of zenith
% set : sunset  interpolated from hourly values of zenith

start_date = min(time);
end_date = max(time);
time_ = time;
day = repmat(0,length(time),1);

location.longitude = lon; 
location.latitude = lat; 
location.altitude = alt;
time.min = 0;
time.sec = 0;
time.UTC = UTC;

counter = 0;
for date = start_date:end_date
counter = counter+1;
date_vec = datevec(date);
time.year = date_vec(1);
time.month = date_vec(2);
time.day = date_vec(3);  

for hour = 1:23
time.hour = hour;
sun = sun_position(time, location);
trash_(hour) = sun.zenith;
end
trash = trash_(1:12);
root = length( find( trash>90 ));
rise(counter) = root + (90 - trash(root)) / (trash(root+1) - trash(root));

trash = trash_(13:23);
root = length( find( trash<90 ));
set(counter) = 12 + root + (90 - trash(root)) / (trash(root+1) - trash(root));

day( time_>rise(counter)/24+datenum(time.year,time.month,time.day)-5/60/24 & time_<set(counter)/24+datenum(time.year,time.month,time.day)+5/60/24 ) = 1;
end