function [NUM,len] = tag2num(tag)

    if isempty(tag)
        NUM = 0;
        len = 0; 
        return;
    end

    A = regexp(tag,'(?<=L{).*(?=}M{)','match');
    len = str2num ( A{1} );

    errors = char(regexp(tag,'(?<=M{).*(?=})','match'));

    IX = find(errors==',');

    % this is very clumsy but it works
    switch numel(IX)
        case 0, NUM(1)=str2num(errors);

        case 1, NUM(1)=str2num(errors(1:IX-1)); 
                NUM(2)=str2num(errors(IX+1:end)); 

        case 2, NUM(1)=str2num(errors(1:IX(1)-1)); 
                NUM(2)=str2num(errors(IX(1)+1:IX(2)-1));
                NUM(3)=str2num(errors(IX(2)+1:end));

        case 3, NUM(1)=str2num(errors(1:IX(1)-1)); 
                NUM(2)=str2num(errors(IX(1)+1:IX(2)-1));           
                NUM(3)=str2num(errors(IX(2)+1:IX(3)-1));
                NUM(4)=str2num(errors(IX(3)+1:end));
    end

end