function printBuildupResults(sigmaData, diagDecay, work)

% _____ Print data into 'RhoOutFileName.txt' ______________
RhoPrint                                 	= [];

for i = 1:length(diagDecay) 
    
    RhoPrint(i,1)                         	= diagDecay(i).numcode.ASSi;
    RhoPrint(i,2)                         	= diagDecay(i).numcode.ATOMi;
    RhoPrint(i,3)                         	= diagDecay(i).rho;
    RhoPrint(i,4)                        	= diagDecay(i).Const;
    RhoPrint(i,5)                         	= diagDecay(i).chiNRho;
    
end

clearvars A B sortIndx

A(1,:)          = RhoPrint(:,1);
A(2,:)          = RhoPrint(:,2);

[B, sortIndx]   = sortrows(A', [1 2]);

RhoPrint       = RhoPrint(sortIndx,:);

file = fopen (work.RhoOutFileName, 'w');

fprintf(file, 'INSTRUCTIONS:\nCheck rho decays (plots) and keep only the good ones\n', 'w');
fprintf(file, 'For bad ones, replace the experimental rho with your best educated guess\n', 'w');
fprintf(file, 'And replace the Const with the value 999\n', 'w');
fprintf(file, 'Delete all instructions and headers before using the file as input file\n', 'w');


fprintf(file, '%6s%8s%12s%14s%12s\r\n\n', 'ASS', 'ATOM', 'rho', 'Const', 'chiNRho');
fprintf (file,'%6d%8d%12.3f%14.2e%12.4f\n', RhoPrint');
fclose(file);

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

SigmaPrint = [];

for i = 1:length(sigmaData)
    
    SigmaPrint(i, 1)                        = sigmaData(i).numcode.ASSi;
    SigmaPrint(i, 2)                        = sigmaData(i).numcode.ATOMi;
    SigmaPrint(i, 3)                        = sigmaData(i).numcode.ASSj;
    SigmaPrint(i, 4)                        = sigmaData(i).numcode.ATOMj;
    SigmaPrint(i, 5)                        = sigmaData(i).sigmaij;
    
% % %     if ~isempty(sigmaData(i).sigmaCorrD2Oij)
% % %         SigmaPrint(i, 6)                    = sigmaData(i).sigmaCorrD2Oij;
% % %     else 
% % %         SigmaPrint(i, 6)                    = 0;
% % %     end
    
    if ~isempty(sigmaData(i).sigmaji)
        SigmaPrint(i, 6)                    = sigmaData(i).sigmaji;
    else
        SigmaPrint(i, 6)                    = 0;
    end
    
% % %     if ~isempty(sigmaData(i).sigmaCorrD2Oji)
% % %         SigmaPrint(i, 8)                    = sigmaData(i).sigmaCorrD2Oji;
% % %     else
% % %         SigmaPrint(i, 8)                    = 0;
% % %     end
    
    SigmaPrint(i,7)                         = sigmaData(i).buildups.rhoi;
    SigmaPrint(i,8)                         = sigmaData(i).buildups.rhoj;
    SigmaPrint(i,9)                         = sigmaData(i).buildups.Izero;
    SigmaPrint(i,10)                        = sigmaData(i).buildups.chisq05;
    SigmaPrint(i,11)                        = sigmaData(i).buildups.chiN;
    
end

file = fopen (work.SigmaOutFileName, 'w');

fprintf(file, '%5s%6s%5s%6s%12s%12s%10s%10s%14s%14s%14s\r\n', 'ASSi', 'ATOMi'...
            , 'ASSj','ATOMj', 'sigmaij', 'sigmaji'...
            , 'rhoi', 'rhoj', 'Izero', 'chisq05', 'chiN');
    
fprintf (file, '%5d%6d%5d%6d%12.4f%12.4f%10.4f%10.4f%14.4e%14.4e%14.4e\n', SigmaPrint');
fclose(file);

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