%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                        %
%                              CCSDS_Blok                                %
%                                                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%vstupne premenne:
%data - data z prenosoveho kanala [double]
%blok - velkost bloku [int]
%rate - rate kodera [double]
%vystupna premenna:
%out - data rozdelene do blokov [double]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out = CCSDS_Blok(data,blok,punc)

y = [];                                                                     
table = [1784 8 223;3568 8 446;7136 8 892;8920 8 1115];                     %povolene hodnoty blokov               
[r, s] = find(table(:,1)==blok);

if (~isempty(r)&&~isempty(s))
    %%RATE 1/6
    if (punc == 1/6)                                                        
        b = blok*6;                                                         %0a, 1a, 2a, 3a, 1b, 3b
        it = floor(length(data)/b);                                         
        for i = 1:it     
            y(i,:) = data(1,(i*b-b)+1:i*b);                                           
        end
    %RATE 1/4
    elseif (punc == 1/4)                                                                        
        b = blok*4;                                                         %0a, 2a, 3a, 1b
        it = floor(length(data)/b);
        for i = 1:it
            y(i,:) = data(1,(i*b-b)+1:i*b);
        end
    %RATE 1/3
    elseif (punc == 1/3)
        b = blok*3;                                                         %0a, 1a, 1b
        it = floor(length(data)/b);
        for i = 1:it
            y(i,:) = data(1,(i*b-b)+1:i*b);
        end
    %RATE 1/2
    elseif (punc == 1/2)
        b = blok*2;                                                         % 0a, 1a, 1b - len polovice s par.
        it = floor(length(data)/b);
        for i = 1:it
            y(i,:) = data(1,(i*b-b)+1:i*b);
        end
    else
        fpintf('Nepovolene dierovanie.');
    end
else
    error('Nespravna velkost bloku.');
end
out = y;                                                                    %vystup funkcie
end