%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%read out sigmaData

if user.isoAniso == 1

    fid = fopen(sprintf('./%s/sigmaDataOutIso.txt', work.finalCollected),'wt');
    
    fprintf(fid, '%s\t\n\n', 'RESULTS ARE DERIVED FROM ISOTROPIC CALCULATIONS');
    
elseif user.isoAniso == 2
    
    fid = fopen(sprintf('./%s/sigmaDataOutAnIso.txt', work.finalCollected),'wt');
    
    fprintf(fid, '%s\t\n\n', 'RESULTS ARE DERIVED FROM ANISOTROPIC CALCULATIONS');
    
end
    
    fprintf(fid, '%5s%6s%5s%6s%12s%9s%14s%14s%16s%16s%9s%9s%10s%10s%12s%12s%9s%9s%20s%20s\r\n',...
        'ASSi', 'ATOMi', 'ASSj','ATOMj', 'AvgSigma', 'AvgrEff', 'chiNormij', 'chiNormji' ,...
        'SigmaExpCorrij', 'SigmaExpCorrji', 'rEffij', 'rEffji' , 'Pcorrij','Pcorrji', ...
        'SigmaPredij','SigmaPredji', 'rPdbij', 'rPdbji', 'normij', 'normji');

    for j = find(ismember([sigmaData.unique], [1 2]))
            
            fprintf(fid, '%5d', sigmaData(j).numcode.ASSi);
            fprintf(fid, '%6s', sigmaData(j).ATOMi);
            fprintf(fid, '%5d', sigmaData(j).numcode.ASSj);
            fprintf(fid, '%6s', sigmaData(j).ATOMj);
            
            if sigmaData(j).unique == 2
                fprintf(fid, '%12.4f', sigmaData(j).avgSigma);
            else
                fprintf(fid, '%12s', 'NA');
            end
            
            if sigmaData(j).unique == 2
                fprintf(fid, '%9.2f', sigmaData(j).avgrEff);
            else
                fprintf(fid, '%9s', 'NA');
            end
            
            fprintf(fid, '%14.4d', sigmaData(j).chiN);
            
            if sigmaData(j).unique == 2
                fprintf(fid, '%14.4d', sigmaData(sigmaData(j).indxji).chiN);
            else
                fprintf(fid, '%14s', 'NA');
            end
            
            fprintf(fid, '%16.4f', sigmaData(j).sigmaCorrij);
            
            if sigmaData(j).unique == 2
                fprintf(fid, '%16.4f', sigmaData(sigmaData(j).indxji).sigmaCorrij);
            else
                fprintf(fid, '%16s', 'NA');
            end
            
            fprintf(fid, '%9.2f', sigmaData(j).rEffij);
            
            if sigmaData(j).unique == 2
                fprintf(fid, '%9.2f', sigmaData(j).rEffji);
            else
                fprintf(fid, '%9s', 'NA');
            end
            
            if ~isempty(sigmaData(j).spinDiff)
                
                if sigmaData(j).unique == 2
                    fprintf(fid, '%10.2f', sigmaData(j).spinDiff.PROCcorrFactor);     %%%fix this to the avg wanted
                    fprintf(fid, '%10.2f', sigmaData(sigmaData(j).indxji).spinDiff.PROCcorrFactor);     %%%fix this to the avg wanted
                    fprintf(fid, '%12.4f', sigmaData(j).spinDiff.PROCsigmaDir);       %%%fix this to the avg wanted
                    fprintf(fid, '%12.4f', sigmaData(sigmaData(j).indxji).spinDiff.PROCsigmaDir);       %%%fix this to the avg wanted
                    fprintf(fid, '%9.2f',  sigmaData(j).spinDiff.PROCrPdb);           %%%fix this to the avg wanted
                    fprintf(fid, '%9.2f',  sigmaData(sigmaData(j).indxji).spinDiff.PROCrPdb);           %%%fix this to the avg wanted
                else
                    fprintf(fid, '%10.2f', sigmaData(j).spinDiff.PROCcorrFactor);     %%%fix this to the avg wanted
                    fprintf(fid, '%10s', 'NA');
                    fprintf(fid, '%12.4f', sigmaData(j).spinDiff.PROCsigmaDir);       %%%fix this to the avg wanted
                    fprintf(fid, '%12s', 'NA');
                    fprintf(fid, '%9.2f',  sigmaData(j).spinDiff.PROCrPdb);           %%%fix this to the avg wanted
                    fprintf(fid, '%9s', 'NA');
                end
                    
            elseif isempty(sigmaData(j).spinDiff)
                fprintf(fid, '%10s', 'NA');
                fprintf(fid, '%10s', 'NA');
                fprintf(fid, '%12s', 'NA');
                fprintf(fid, '%12s', 'NA');
                fprintf(fid, '%9s',  'NA');
                fprintf(fid, '%9s',  'NA');
            end
            
            if abs(sigmaData(j).buildups.rawIzero) == 999
                fprintf(fid, '%20s', 'ij NOT NORMALIZED');
            else
                fprintf(fid, '%20s', 'ij normalized');
            end
            
            if sigmaData(j).unique == 2
                if abs(sigmaData(sigmaData(j).indxji).buildups.rawIzero) == 999
                    fprintf(fid, '%20s', 'ji NOT NORMALIZED');
                else
                    fprintf(fid, '%20s', 'ji normalized');
                end
            end
           
            fprintf(fid, '\r\n');
    end

    fclose(fid);