%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
%%%%%%%%%%%%%%%%%%%%% plotting buildups calculated %%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
deleteScreenMsg         = '';

fprintf('\n\nPlotting all buildups: ')

for j = find(ismember([sigmaData.unique], 1))
    
    temp.B1 = 0;
    temp.B2 = 0;
    
    if abs(sigmaData(j).buildups.rawIzero) ~= 999
        
        temp.B1 = j;
        
        figure('visible','off');
        work.numberOfFig = work.numberOfFig + 1;
        prettySigmaLetter
        
        Res = sprintf('%04d_%04d_%04d_%04d'...
            ,sigmaData(temp.B1).numcode.ASSi, sigmaData(temp.B1).numcode.ATOMi...
            ,sigmaData(temp.B1).numcode.ASSj, sigmaData(temp.B1).numcode.ATOMj);
        
            work.figureName = sprintf('./%s/%s.png', work.buildUpPlotDir, Res);
            saveas (gca, work.figureName, 'png');
                
            while (~exist(work.figureName, 'file'))
                sleep(0.5);
            end
            
            close(gcf)
            work.figureName = '';
    end
end



for j = find(ismember([sigmaData.unique], 2));
    
    temp.B1 = 0;
    temp.B2 = 0;
    
    if abs(sigmaData(j).buildups.rawIzero) ~= 999
        temp.B1 = j;
    end
        
    if abs(sigmaData(sigmaData(j).indxji).buildups.rawIzero) ~= 999
        temp.B2 = sigmaData(j).indxji;
    end
                        
    if temp.B1 ~= 0 || temp.B2 ~= 0
        figure('visible','off');
        work.numberOfFig = work.numberOfFig + 1;
        prettySigmaLetter
                
        % both directions are available and good
        if temp.B1 ~= 0
    
            Res = sprintf('%04d_%04d_%04d_%04d'...
                ,sigmaData(temp.B1).numcode.ASSi, sigmaData(temp.B1).numcode.ATOMi...
                ,sigmaData(temp.B1).numcode.ASSj, sigmaData(temp.B1).numcode.ATOMj);
        
            work.figureName = sprintf('./%s/%s.png', work.buildUpPlotDir, Res);
            saveas (gca, work.figureName, 'png');
                
            while (~exist(work.figureName, 'file'))
                sleep(0.5);
            end
            
            close(gcf)
            work.figureName = '';
    
        % first direction not available but second is available and good       
        elseif temp.B1 == 0 && temp.B2 ~= 0
     
            Res = sprintf('%04d_%04d_%04d_%04d'...
                ,sigmaData(temp.B2).numcode.ASSi, sigmaData(temp.B2).numcode.ATOMi...
                ,sigmaData(temp.B2).numcode.ASSj, sigmaData(temp.B2).numcode.ATOMj);
        
            work.figureName = sprintf('./%s/%s.png', work.buildUpPlotDir, Res);
            saveas (gca, work.figureName, 'png');
                
            while (~exist(work.figureName, 'file'))
                sleep(0.5);
            end
            
            close(gcf)
            work.figureName = '';
        
        end
    end
end

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