function [sigmaData, user] = noIz0FilterFun(sigmaData, user, work)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%         noIz0FilterFun.m          %%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%run before uniqueFlagFun
    
    allIndices                              = 1:length(sigmaData);
    decayIndx                               = [];
    decayIndxCount                          = 1;
    decaySupIndx                            = [];
    decaySupIndxCount                       = 1;
    noIzeroIndx                             = [];
    IzeroSupIndx                            = [];

    
    fprintf('\n\nChecking availability of diagonal peak intensities for nomalization\n')

    deleteScreenMsg     = '';

    
for j = 1:length(sigmaData)
        
        
        if (mod(j,50) == 0) || j == length(sigmaData) || j == 1
            screenMsg = sprintf(['\n', num2str(length(sigmaData) + 1 - j), ' sigmaData entries remaining.\n']);
            fprintf([deleteScreenMsg, screenMsg])
            deleteScreenMsg = repmat(sprintf('\b'), 1, length(screenMsg));
            
            if j == length(sigmaData)
                fprintf(deleteScreenMsg)
                fprintf('\nDONE\n')
            end
        end
        
        % Checking for Izeroij
        
        if ~isempty(sigmaData(j).buildups.rawIzero)
            
            if abs(sigmaData(j).buildups.rawIzero) ~= 999;
            
            decayIndx(decayIndxCount)    = j;
            decayIndxCount               = decayIndxCount + 1;
            
            end
        end
end
        

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    decayIndx                               = unique(decayIndx);

    out.noIzeroCount                        = length(sigmaData)- length(decayIndx);
    out.IzeroCount                          = length(decayIndx);
    noIzeroIndx                             = setxor(decayIndx,allIndices);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clearvars D E uniqueIndx

D(1,:)                              = arrayfun(@(x) x.numcode.ASSnorm, sigmaData(noIzeroIndx));
D(2,:)                              = arrayfun(@(x) x.numcode.ATOMnorm, sigmaData(noIzeroIndx));
    
[E, uniqueIndx]                     = unique(D', 'rows', 'first');
    
uniquenoIzeroIndx                   = sort(noIzeroIndx(uniqueIndx));




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    file = fopen (work.NORhoOutLetterCodeFileName, 'w');
    for j = uniquenoIzeroIndx
        fprintf(file, '%5d%5s\n'  , sigmaData(j).ASSnorm, sigmaData(j).ATOMnorm);
    end
    fclose(file);
    
    while (~exist(work.NORhoOutLetterCodeFileName, 'file'))
        sleep(0.5);
    end
    
    % _____ Print missing Iz0 file 'NOrho.txt' ______________
    file = fopen (work.NORhoOutNumCodeFileName, 'w');
    fprintf(file, 'INSTRUCTIONS:\nREPLACE rho WITH YOUR BEST EDUCATED GUESS\n', 'w');
    fprintf(file, 'DO NOT CHANGE THE 999 VALUES\n', 'w');
    fprintf(file, 'Then add the result to your Rho.out file\n', 'w');
    
    for j = uniquenoIzeroIndx
      %fprintf(file, '%6d%8d\n' , sigmaData(j).numcode.ASSi, sigmaData(j).numcode.ATOMi);
      fprintf(file, '%6d%8d%12s%14d%12d\n', sigmaData(j).numcode.ASSnorm, sigmaData(j).numcode.ATOMnorm ...
                                                , 'rho', 999, 999);
      
    end
    fclose(file); 

    while (~exist(work.NORhoOutNumCodeFileName, 'file'))
        sleep(0.5);
    end
    
    %%%%%%%%

    if user.noIz0Filter ==  0

    diary on    
    
    fprintf(['\nThere is/are ', num2str(out.noIzeroCount), ' assignment(s)'...
            ,' with no diagonal out of ', num2str(length(sigmaData))...
            ,' Assignment(s).', '\nListed in: NORhoOutLeterCode.txt and NORhoOutNumCode.txt', '\n'])
    
    diary off

    elseif user.noIz0Filter == 1

    fprintf(['\n\nRemoved ', num2str(out.noIzeroCount),' assignments with no diagonal peak'...
            ,'\nRemaining: ', num2str(out.IzeroCount), '\n'])
    % Remove assignments with no diagonal peak from assignment

    sigmaData                               = sigmaData(decayIndx);
    
    end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%