% function Actogram2(x,light,NstepsPerHr,T,figurewindow,Tcycle)
%
% Makes a figure with the actogram, including light unless enter light=[]

function Actogram2x(x,light,NstepsPerHr,T,figurewindow,Tcycle)

%graycolor=0.3;
graycolor=0.6;
if strcmp(figurewindow,'new')
    fig0=figure;set(fig0,'OuterPosition',[100 50 600 800]);
end

x=[x;zeros(Tcycle*NstepsPerHr*4,1)];
if ~isempty(light)
    light=[light;zeros(Tcycle*NstepsPerHr*4,1)];
end

days0=ceil(T/Tcycle+1);daylength0=Tcycle*NstepsPerHr;t0=(1:2*daylength0)'/NstepsPerHr;
for day=1:(days0)
    today=x((1+(day-1)*daylength0):((day+1)*daylength0));
    today=day-0.5*today/max(today);
    if ~isempty(light)
        bar(t0,day-light((1+(day-1)*daylength0):((day+1)*daylength0))+1/2,'y','BaseValue',day+1/2,'EdgeColor','y');hold on;
    end
    bar_handle=bar(t0(today>0),today(today>0)+1/2,'FaceColor',graycolor*[1 1 1],'BaseValue',day+1/2,'EdgeColor',graycolor*[1 1 1]);
    
    baseline_handle=get(bar_handle,'BaseLine');
    set(baseline_handle,'Color','w');
    hold on;
    
    plot([0.1 47.9],[day day]+1/2,'w','LineWidth',3);
end

set(gca,'YDir','reverse','FontSize',20,'YTick',0:10:days0,'XTick',0:Tcycle:2*Tcycle);
xlabel('Time in hours (double-plotted) ');
%ylabel('Days ');
axis([0 2*Tcycle 0 days0-1]);
