function [R, F1]=GOES_R(bit_F,F,T_E1,T_E2,T_v,T_e)

[K,ij]=size(F);
I=90;
J=135;

mn=round(mean(F'));
F1=F-mn'*ones(1,I*J);
mF=min(F1(:));
MF=max(F1(:));
h=hist(F1(:),mF:MF)/(K*ij);
i=find(h~=0);
e=-sum((h(i)).*log2(h(i)));
d_e=abs(T_E1-e);
i=find(d_e==min(d_e));
vnum=T_v(i);

if vnum~=1
   b=round(vector_quant(F1,vnum));
   d=zeros(1,vnum);
   Label=zeros(1,I*J);

   for j=1:I*J 
       for i=1:vnum
           d(i)=sqrt(sum((F1(:,j)-b(:,i)).^2)/K);
       end
       k=min(find(d==min(d)));
       Label(j)=k;
       F1(:,j)=F1(:,j)-b(:,k);
   end
end

mF=min(F1(:));
MF=max(F1(:));
h=hist(F1(:),mF:MF)/(K*ij);
i=find(h~=0);
e=-sum((h(i)).*log2(h(i)));
d_e=abs(T_E2-e);
i=find(d_e==min(d_e));
enum=T_e(i);

Cov=F1*F1';
[V,D]=eig(Cov);
V=V(:,K+1-enum:K);
V=10^(-4)*round(10^4*V);
C=round(V'*F1);
bit_coef=0;
for ic=1:enum
   bit_coef=bit_coef+ceil(log2(max(C(ic,:))-min(C(ic,:))));
end
F1=F1-round(V*C);

mF=min(F1(:));
MF=max(F1(:));
st=std(F1(:));
h=hist(F1(:),mF:1:MF);
e=exp(-(mF:1:MF).^2/(2*st^2));
HL=HuffLen(e);
S=sum(HL.*h);

if vnum~=1
%R=bit_F*I*J*K/(log2(vnum)*I*J+bit_F*(2+K*(1+vnum))+enum*(14*K+4)+32+I*J*bit_coef+S);
R=bit_F*I*J*K/(log2(vnum)*I*J+bit_F*(2+K*(1+vnum))+enum*(14*K+4)+32+I*J*bit_coef);
else
%R=bit_F*I*J*K/(bit_F*(K+2)+enum*(14*K+4)+32+I*J*bit_coef+S);
R=bit_F*I*J*K/(bit_F*(K+2)+enum*(14*K+4)+32+I*J*bit_coef);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
F1=F-F1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
