function encode;

clear;

global znk;
global c;
global matr;
global prag;
global dom;
global M;load M;
global iter;
iter=0;
global rek;
prag=16384;
global M2;
M2=M;

global D;
global pom;
global s;
uvjet=1;
rek= [];
rek=zeros(128,128);
while uvjet
    iter=iter+1;
    rek(:,:,iter)=zeros(128,128);
    
    dom=1;
    c=0;
    matr=zeros(128,128);
    prag=prag/2;
    znk=[];
    blok2(128,1,1);
    dom=0;
    char(znk)
    save(['koef\ed' num2str(iter) '.mat'], 'znk');
    if prag>1
        matr=matr.*(matr~='x');
        rek(:,:,iter)=rek(:,:,iter)+matr*prag;
        
        c=0;
        s=[];
        D=prag/2;
        global I;
        for I=1:iter
            pom=rek(:,:,I);
            pom=pom+sign(pom)*D;
            
            blok2(128,1,1);
        end

        s
        save(['koef\es' num2str(iter) '.mat'], 's');
    else
        uvjet=0;
    end
end