function compress1(F,F_bit,filename)

opts.disp=0;
[K,LG]=size(F);
on=ones(1,LG);
v_in=ones(1,K);
mf=round(mean(F,2));
F=F-mf*on;
fv=v_in*F;
v=F*fv';
v=v/sqrt(v'*v);
%[v,V]=eigs(F*F',1,'LM',opts);
T=v'*F;
R=F-v*T;
mT=min(T);
MT=max(T);

Num=13;
t=linspace(mT,MT,Num+1);
M1=zeros(K,Num);
E1=zeros(K,Num);
T_Label=zeros(1,LG);

for k=1:Num
    J=find(T>t(k) & T<=t(k+1));
    T_Label(J)=k;
    M1(:,k)=round(mean(F(:,J),2));
    %m=M1(:,k)*ones(1,length(J));
    G=F(:,J)-M1(:,k)*ones(1,length(J));
    fv=v'*G;
    v1=G*fv';
    E1(:,k)=v1/sqrt(v1'*v1);
    %[v,V]=eigs((F(:,J)-m)*(F(:,J)-m)',1,'LM',opts);
    %E1(:,k)=sign(v(1))*v;
end

[E,E_Label]=float_mean(E1);
E=10^(-4)*round(E*10^4);
[K,num]=size(E)
M=zeros(K,num);
for k=1:num
    ind=zeros(1,LG);
    J_t=find(E_Label==k);
    for n=1:length(J_t)
        J=find(T_Label==J_t(n));
        ind(J)=1;
    end
    M(:,k)=round(mean(F(:,find(ind==1)),2));
end

C=zeros(1,LG);
dD=zeros(num,LG);
for j=1:num
m=M(:,j);
v=E(:,j);
R=F-m*on-v*v'*(F-m*on);
dD(j,:)=sqrt(sum(R.^2,1));
end
[md,Label]=min(dD,[],1);
for j=1:num
J=find(Label==j);    
m=M(:,j);
v=E(:,j);
C(J)=round(v'*(F(:,J)-m*ones(1,length(J))));
R(:,J)=F(:,J)-m*ones(1,length(J))-round(v*C(J));
end

mM=min(M(:));
M_bit=ceil(log2(max(M(:))-mM+1));
mC=min(C(:));
C_bit=ceil(log2(max(C(:))-mC+1));
Label_bit=ceil(log2(num));

[V,W]=eig(R*R');
CC=V'*R;
F1=R;
al=log2(sqrt(2*pi*exp(1)));
B=K*F_bit+num*K*(M_bit+15)+3*Label_bit*LG+C_bit*LG+16*LG+3*128*16;
mc=zeros(1,K);
C1_bit=zeros(1,K);
for j=K:-1:K-30
v=V(:,j);
c=round(CC(j,:));
R=R-round(v*c);
sF(K-j+1)=log2(std(R(:)))+al;
mc(j)=min(c(:));
C1_bit(j)=ceil(log2(max(c(:))-mc(j)+1));
B=B+K*15+LG*C1_bit(j);
sB(K-j+1)=B/(LG*K);
end
[ratio,enum]=max(F_bit./(sF+sB))
V1=10^(-4)*round(V(:,K+1-enum:K)*10^4);
C1=round(CC(K+1-enum:K,:));
C1_bit=C1_bit(K+1-enum:K);
mc=mc(K+1-enum:K);
R=F1-round(V1*C1);

%saving stuff:

mR=min(R(:));
MR=max(R(:));
h_R=hist(R(:),mR:MR);
HL_R=HuffLen(h_R);
HL_bit=ceil(log2(max(HL_R)+1));
HC_R=uint8(HuffCode(HL_R));
ms=zeros(1,LG);
for j=1:LG
ms(j)=sum(HL_R.*hist(R(:,j),mR:MR));
end
ms_min=min(ms);
ms_min_bit=ceil(log2(ms_min+1));
ms=ms-ms_min;
ms_bit=ceil(log2(max(ms)+1));

mem_size=sum(HL_R.*hist(R(:),mR:MR));
A=uint8(zeros(1,mem_size));
pos=0;
for j=1:LG
for k=1:K
    len=HL_R(R(k,j)-mR+1);
    A(pos+1:pos+len)=HC_R(R(k,j)-mR+1,1:len);
    pos=pos+len;
end
end

fid = fopen([filename '.bin'],'w');

nums=[num enum];

for count=1:3
count_bin=fwrite(fid,nums,'ubit5');
end

num_array=[mM mC mc];
bit_array=[F_bit M_bit C_bit Label_bit ms_bit ms_min_bit C1_bit];

for count=1:3
count_bin=fwrite(fid,num_array,'bit16');
count_bin=fwrite(fid,bit_array,'ubit5');
end

Flag_mf=zeros(K,1);
for k=1:K
    Flag_mf(k)=parity_check(mf(k));
end
count_bin=fwrite(fid,Flag_mf,'ubit1');
c=['ubit' num2str(F_bit)];
count_bin=fwrite(fid,mf,c);
count_bin=fwrite(fid,mf,c);

c=['ubit' num2str(M_bit)];
M=M-mM;
Flag_M=zeros(K,num);
for i=1:num
    for k=1:K
        Flag_M(k,i)=parity_check(M(k,i));
    end
end
count_bin=fwrite(fid,Flag_M(:),'ubit1');   
count_bin=fwrite(fid,M(:),c);
count_bin=fwrite(fid,M(:),c);

FlagE=zeros(K,num);
for i=1:num
    for k=1:K
        FlagE(k,i)=parity_check(abs(round(10^4*E(k,i))));
    end
end
count_bin=fwrite(fid,FlagE(:),'ubit1');   
E=E';
count_bin=fwrite(fid,round((10^4)*E(:)),'bit15');

c=['ubit' num2str(Label_bit)];
for count=1:3
count_bin=fwrite(fid,Label-1,c);
end

C=C-mC;
Flag_C=zeros(1,LG);
for k=1:LG
    Flag_C(k)=parity_check(C(k));
end
count_bin=fwrite(fid,Flag_C,'ubit1');
c=['ubit' num2str(C_bit)];
count_bin=fwrite(fid,C,c);
count_bin=fwrite(fid,C,c);

FlagV=zeros(K,enum);
for i=1:enum
    for k=1:K
        FlagV(k,i)=parity_check(abs(round(10^4*V1(k,i))));
    end
end
count_bin=fwrite(fid,FlagV(:),'ubit1');    
V1=V1';
count_bin=fwrite(fid,round((10^4)*V1(:)),'bit15');

for j=1:enum
    c=['ubit' num2str(C1_bit(j))];
    count_bin=fwrite(fid,C1(j,:)-mc(j),c);
end

c=['ubit' num2str(ms_min_bit)];
count_bin=fwrite(fid,ms_min,c);

Flag_ms=zeros(LG,1);
for k=1:LG
    Flag_ms(k)=parity_check(ms(k));
end
count_bin=fwrite(fid,Flag_ms,'ubit1');
c=['ubit' num2str(ms_bit)];
count_bin=fwrite(fid,ms,c);
count_bin=fwrite(fid,ms,c);

huff_nums=[HL_bit -mR MR];
c=['ubit' num2str(F_bit)];
for count=1:3
count_bin=fwrite(fid,huff_nums,c);
end

for count=1:3
c=['ubit' num2str(HL_bit)];
count_bin=fwrite(fid,HL_R,c);
end

code=double(A);
count_bin=fwrite(fid,code,'ubit1');
fclose(fid);