function [struct,stopFlag] = ass2numCodeFun(struct, lib)
% % struct = nmrDrawTabUnique;
% % lib = libAss;

% This program converts the letter code to the numerical code used internally 

for j = 1:length(struct)
    
    struct(j).procAss.ATOMi_NUMCODE = [];
    struct(j).procAss.ATOMi_MARKLEY = [];
    struct(j).procAss.ATOMj_NUMCODE = [];
    struct(j).procAss.ATOMj_MARKLEY = [];
    
    for i = 1:length(lib)
    
        if strcmp(struct(j).procAss.ASSi_resName, lib(i).RESIDUE)
            
            numcodeIndx = 0;
% % %             numcodeIndx = find(~cellfun('isempty', strfind(lib(i).ATOMS, struct(j).procAss.ATOMi)),1);
            for k = 1:length(lib(i).ATOMS)
                if strcmp(lib(i).ATOMS(k), struct(j).procAss.ATOMi)
                    numcodeIndx = k;
                end
            end

            struct(j).procAss.ATOMi_NUMCODE = lib(i).ATOMNUMCODES(numcodeIndx);
            struct(j).procAss.ATOMi_MARKLEY = lib(i).ATOMTMARKLEY{numcodeIndx};
        end
        
        if strcmp(struct(j).procAss.ASSj_resName, lib(i).RESIDUE)
            
            numcodeIndx = 0;
% % %             numcodeIndx = find(~cellfun('isempty', strfind(lib(i).ATOMS, struct(j).procAss.ATOMj)),1);
            for k = 1:length(lib(i).ATOMS)
                if strcmp(lib(i).ATOMS(k), struct(j).procAss.ATOMj)
                    numcodeIndx = k;
                end
            end

            struct(j).procAss.ATOMj_NUMCODE = lib(i).ATOMNUMCODES(numcodeIndx);
            struct(j).procAss.ATOMj_MARKLEY = lib(i).ATOMTMARKLEY{numcodeIndx};
            
        end
    end
end

stopFlag                            = 0;

for j = 1:length(struct)
    
            if isempty(struct(j).procAss.ATOMi_NUMCODE)
                stopFlag = 1;
                fprintf(['\nNOT all assignments have been matched to the library file'...
             '\nInspect: ', num2str(struct(j).procAss.ASSi), ' ', struct(j).procAss.ATOMi, ' ' ...
                          , num2str(struct(j).procAss.ASSj), ' ', struct(j).procAss.ATOMj ...
             '\nSee if your assignment standard you chose matches your asssignment' ...             
             '\n'])
            end
            
            if isempty(struct(j).procAss.ATOMj_NUMCODE)
                stopFlag = 1;
                fprintf(['\nNOT all assignments have been matched to the library file'...
             '\nInspect: ', num2str(struct(j).procAss.ASSi), ' ', struct(j).procAss.ATOMi, ' ' ...
                          , num2str(struct(j).procAss.ASSj), ' ', struct(j).procAss.ATOMj ...
             '\nSee if your assignment standard you chose matches your asssignment' ...
             '\n'])
            end
end