%###############################################################################################

% stündliche Regendaten einer Woche (erfunden da alle bisherigen Daten ohne Regen)
precip_day0 = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
precip_day1 = [0;0;2;15;10;11;1;0;0;4;2;0;0;9;22;13;0;0;0;4;0;0;0;0];
precip_day2 = [0;0;0;0;5;4;6;5;3;0;0;0;0;0;0;0;0;0;1;0;0;0;0;0];
precip_day3 = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
precip_day4 = [0;0;2;0;0;0;1;0;0;0;0;0;0;0;0;1;0;2;1;0;0;0;0;2];
precip_day5 = [10;30;29;33;20;5;9;16;22;10;8;0;0;0;0;0;0;0;0;0;0;0;0;0];
precip_day6 = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
precip_day7 = [0;0;0;0;0;1;1;4;1;0;0;0;0;0;0;0;0;0;3;0;1;1;0;0];

precip_days = [precip_day0,precip_day1,precip_day2,precip_day3,precip_day4, ...
               precip_day5,precip_day6,precip_day7]
size_precip_days = size(precip_days); % ~(1): # Messwerte pro Tag ;~(2): # Tage

precip_week = [precip_day1;precip_day2;precip_day3;precip_day4;precip_day5; ... 
               precip_day6;precip_day7];
size_precip_week = size(precip_week);

%-----------------------------------------------------------------------------------------------
%###############################################################################################
%---------- kumulierter täglicher Regen --------------------------------------------------------

daily_precip = [];

for i=1:size_precip_days(2) % alle Tage
	daily_precip = [daily_precip,0];
	for j=1:24 % alle 24 Stunden pro Tag
		daily_precip(i) = daily_precip(i) + precip_days(j,i);
	end
end

daily_precip % ~(x): kumulierter Niederschlag an Tag x

%-----------------------------------------------------------------------------------------------
%###############################################################################################

%###############################################################################################
%--------- Tage seit letztem Regentag ----------------------------------------------------------

rdt = 10;	% 'RainDayThreshold': kumulierter Niederschlagswert, ab dem ein Tag als Regentag eingestuft wird

raindays = find(daily_precip >= rdt)
x=-1; % zählt Tage seit letztem Regentag (bis zum 1. Regentag ist Index unbrauchbar --> x=-1)
y=0; % auf 1 erhöht sobalt erster Regentag vorbei, ab dann ist der Index brauchbar

days_since_rain = [];

for i=1:size_precip_days(2)
	if daily_precip(i) < rdt % Niederschlag an Tag i unter Grenzwert --> kein Regentag
		if y==1
			x = x+1;
		end
	else % Niederschlag an Tag i gleich/über Grenzwert --> Regentag
		y = 1;
		x = 0;
	end	
	days_since_rain = [days_since_rain,x];
end

days_since_rain

x = 1:size_precip_days(2);

[AX,H1,H2] = plotyy(x,days_since_rain,x,daily_precip);

set(H1,'LineWidth',2)

ha=findobj(gcf,'type','axes'); % ha(1): rechte Achse; ha(2): linke Achse ('days since rain')

set(ha(2),'ylim',[0 max(days_since_rain)+1])

for j=1:i % rote vertikale Linie bei erstem Regentag (Start 'days since rain'-Index)
	if days_since_rain(j) ~= -1
		line([j j],[0 max(days_since_rain)+1],'Color','red');  
		break
	end 
end 

%-----------------------------------------------------------------------------------------------
%###############################################################################################
