function Curent_CTU_code=get_exact_code(base,NBposition)

% This function loads exact codes related to the inputs (base,NBposition)
%
%
% Inputs:
%   base                : Requested spectral resolution
%   NBposition          : Requested spatial resolution
%
%
% Output:
%   Curent_CTU_code    : takes tow values: 
%                            1- Structure containing CTU codes for
%                               the requested spectral and spatial
%                               resolutions
%                            2- NaN if there is no existing solution (codes)  


% Copyright 2015 Abdelmounaime Safia
% Last Revision January, 4, 2015



CTU_Codes_Loaded=loadexistingcodes();

Curent_CTU_code=NaN;
[~, nb_spec_res]=size(CTU_Codes_Loaded);
i=1;
if base ==2
    
    Curent_CTU_code = struct('valid',-909,'SpatialRes',-909,'SpectralRes',-909,'HistResol',-909,'code',-909);
    Curent_CTU_code.valid=1;
    Curent_CTU_code.SpatialRes=NBposition;
    Curent_CTU_code.SpectralRes=base;
    Curent_CTU_code.HistResol=tu_and_ctu_histogram_resolution(base,NBposition,2);
    Curent_CTU_code.code=[0 1];
else
    while i<=nb_spec_res
        if (CTU_Codes_Loaded(i).SpectralRes==base)
            [~, spat_res]=find(CTU_Codes_Loaded(i).SpatialRes==NBposition);
            if ~isempty (spat_res)
                Curent_CTU_code = struct('valid',-909,'SpatialRes',-909,'SpectralRes',-909,'HistResol',-909,'code',-909);
                Curent_CTU_code.valid=1;
                Curent_CTU_code.SpatialRes=CTU_Codes_Loaded(i).SpatialRes(spat_res);
                Curent_CTU_code.SpectralRes=CTU_Codes_Loaded(i).SpectralRes;
                Curent_CTU_code.HistResol=CTU_Codes_Loaded(i).HistResol(spat_res);
                Curent_CTU_code.code=CTU_Codes_Loaded(i).Codes(spat_res,:);
                i=nb_spec_res;
            else
            end
        end
        i=i+1;
    end
end

end