function CodeValidity=somecodificationvalidity (TextCode,TextUnitComb)

%  This function check the validity of a given combinations set according to
%  the some codification method. The valididy is related to the unicity of
%  the some of each combination.
%  INPUT:
%
%  TextCode : 
%  TextUnitComb Ç combinations set
%  OUTPUT:
%  CodeValidity: structure
%     CodeValidity.valid : takes 1 for valid code and 0 for invalid code
%     CodeValidity.NumberContiSome : is the number of codes that have 
%     continuese digits like 1,3,4,5,6,8,11 there is 4 digits that are
%     successive.(3,4,5,6)
% 
%  CodeValidity.MaxMinusMin: maxim some minis minimum some
%  CodeValidity.Combinations: The resulting texture units.
%
%Copyright 2011 Abdelmounaime Safia
%Lats Revision December, 12, 2011
 
[NBcomb,~] = size(TextUnitComb);
S=sum(TextUnitComb,2);
Cmin=min(S);
Cmax=max(S);
[a,~]=hist(S',Cmin:Cmax);
if sum(a==1)==NBcomb
    % VecTest=Cmin:Cmax;
    SS=sort(S);
    vj=0;
    Fin_vj=-1;
    for vi=1:length(SS)-1
        if SS(vi)+1==SS(vi+1);
            vj=vj+1;
        else
            if Fin_vj<vj
                Fin_vj=vj;
            end
            vj=0;
        end
    end
    Fin_vj=Fin_vj+1;
    CodeValidity.code=TextCode;
    CodeValidity.valid=1;
    CodeValidity.NumberContiSome=Fin_vj;
    CodeValidity.MaxMinusMin=Cmax-Cmin+1;
    CodeValidity.Combinations=TextUnitComb;
else
    CodeValidity.code=TextCode;
    CodeValidity.valid=0;
    CodeValidity.NumberContiSome=[];
    CodeValidity.MaxMinusMin=[];
    CodeValidity.Combinations=TextUnitComb;
end
end