
%% INPUT

dt=minutes(5);
t0=datetime(2000,01,01);
tf=datetime(2000,01,14);

t_start=days(3); %time without change

T=20; %period of floodwave [days]
Q0=2000; %reference discharge [m^3/s]
Qmax=6000; %maximum discharge [m^3/s]

%% CALC

t_sim=tf-t0;
t_wave=t_sim-t_start;
t_wave_d=days(t_wave);
tim_wave=0:days(dt):t_wave_d;
Q_wave=Q0+(Qmax-Q0)*sin(tim_wave.*2*pi/T);

tim=t0:dt:tf;
Q=Q0.*ones(size(tim));
Q(tim>t0+t_start-dt)=Q_wave;

%% PLOT

figure
plot(tim,Q)
ylabel('discharge [m^3/s]')
print(gcf,'bc.png','-dpng','-r300')

%% EXPORT

nt=numel(tim);
fid=fopen('bc.csv','w');
for kt=1:nt
fprintf(fid,'%s, %f \n',datestr(tim(kt),'yyyy/mm/dd HH:MM:ss'),Q(kt));
end
fclose(fid);
