function [f,F,S,h,H,r]=spol_char(y,char,char_id,fig)

n=length(char);
y=sort(y);

if char_id==1; %zadano S
    S=char;
    for i=1:n-1
        f(i)=-(S(i+1)-S(i))/(y(i+1)-y(i));
        h(i)=f(i)/S(i);
    end;
    f(n)=-(S(n)-S(n-1))/(y(n)-y(n-1));
    h(n)=f(n)/S(n);
    f=f';
    h=h';
    F=1-S;
%     for i=1:n
%         H(i)=sum(h(1:i));
%     end;
%     H=H';
    H=-log(S);
end;

if char_id==2; %zadano f
    f=char;
    F(1)=0;
    for i=2:n
        F(i)=int_obd_form(y(1:i),f(1:i));
    end;
    F=F';
    S=1-F;
    for i=1:n
        h(i)=f(i)/S(i);
    end;
    h=h';
%     for i=1:n
%         H(i)=sum(h(1:i));
%     end;
%     H=H';
    H=-log(S);
end;

if char_id==3; %zadano F
    F=char;
    S=1-F;
    for i=1:n-1
        f(i)=-(S(i+1)-S(i))/(y(i+1)-y(i));
        h(i)=f(i)/S(i);
    end;
    f(n)=-(S(n)-S(n-1))/(y(n)-y(n-1));
    h(n)=f(n)/S(n);
    f=f';
    h=h';
%     for i=1:n
%         H(i)=sum(h(1:i));
%     end;
%     H=H';
    H=-log(S);
end;

if char_id==4; %zadano h
    h=char;
    H(1)=0;
    for i=2:n
        H(i)=int_obd_form(y(1:i),h(1:i));
    end;
    H=H';
    S=exp(-H);
    for i=1:n-1
        f(i)=-(S(i+1)-S(i))/(y(i+1)-y(i));
    end;
    f(n)=-(S(n)-S(n-1))/(y(n)-y(n-1));
    f=f';
    F=1-S;
end;

if char_id==5; %zadano H
    H=char;
    S=exp(-H);
    for i=1:n-1
        f(i)=-(S(i+1)-S(i))/(y(i+1)-y(i));
        h(i)=(H(i+1)-H(i))/(y(i+1)-y(i));
        %h(i)=f(i)/S(i);
    end;
    f(n)=-(S(n)-S(n-1))/(y(n)-y(n-1));
    h(n)=(H(n)-H(n-1))/(y(n)-y(n-1));
    %h(n)=f(n)/S(n);
    f=f';
    h=h';
    F=1-S;
end;

for i=1:n-1
    r(i)=int_obd_form(y(i:n),S(i:n))/S(i);
end;
r(n)=0;
r=r';
    
if fig==1;
    figure;
    subplot(3,2,1);stairs(y,[S F]);title('Spolehlivostní funkce S, Distribuční funkce F');xlabel('t','rotation',0);ylabel('S,F','rotation',0);axis([min(y) max(y) 0 1]);
    subplot(3,2,2);stairs(y,H);title('Cumulative hazard function H');xlabel('t','rotation',0);ylabel('H','rotation',0);axis([min(y) max(y) 0 max(H)+3]);
    %subplot(3,2,3);stem(y,f);title('Probability density function f');
    %subplot(3,2,4);stem(y,h);title('Hazard function h');
    subplot(3,2,3);plot(y,f);title('Probability density function f');xlabel('t','rotation',0);ylabel('f','rotation',0);axis([min(y) max(y) 0 max(f)+0.5*max(f)]);
    subplot(3,2,4);plot(y,h);title('Hazard function h');xlabel('t','rotation',0);ylabel('h','rotation',0);axis([min(y) max(y) 0 max(h)+0.5*max(h)]);
    %subplot(3,2,5);plot(y,r);title('Residual lifetime r');axis([min(y) max(y) 0 max(r)+3]);
    subplot(3,2,5);plot(y,r+y);title('Residual lifetime r');xlabel('t','rotation',0);ylabel('r(t)+t','rotation',0);axis([min(y) max(y) 0 max(r+y)+3]);
end;

    