function [sigmaData, diagDecay] = input2sigmaDataFun(rawData, user)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialize the sigmaData structure

count.countDiag     = 1;
count.countCross    = 1;

for k = 1:length(rawData)
    
    if rawData(k).procAss.ATOMi_pdbSerNo                            == rawData(k).procAss.ATOMj_pdbSerNo
        
        diagDecay(count.countDiag).user                             = user;
        diagDecay(count.countDiag).input                            = rawData(k);
        
        diagDecay(count.countDiag).numcode.ASSi                     = rawData(k).procAss.ASSi;
        diagDecay(count.countDiag).numcode.ATOMi                    = rawData(k).procAss.ATOMi_NUMCODE;
        diagDecay(count.countDiag).numcode.ATOMi_pdbSerNo           = rawData(k).procAss.ATOMi_pdbSerNo;
        
        diagDecay(count.countDiag).ASSi                             = rawData(k).procAss.ASSi;
        diagDecay(count.countDiag).ATOMi                            = rawData(k).procAss.ATOMi;
        diagDecay(count.countDiag).secondStruct                     = [];
        diagDecay(count.countDiag).fullSetmixTimes                  = user.mixing_times;
        diagDecay(count.countDiag).fullSetDPrho                     = rawData(k).procAss.INVintensities;
        diagDecay(count.countDiag).mixTimes                         = user.mixing_times;
        diagDecay(count.countDiag).DPrho                            = rawData(k).procAss.INVintensities;
        diagDecay(count.countDiag).rho                              = [];
        diagDecay(count.countDiag).Const                            = [];
        diagDecay(count.countDiag).chiNRho                          = [];
        diagDecay(count.countDiag).PointtheoRho                     = [];
        diagDecay(count.countDiag).diffRho                          = [];
        diagDecay(count.countDiag).chisqRho                         = [];
        diagDecay(count.countDiag).chisq05Rho                       = [];
        
        count.countDiag                                             = count.countDiag + 1;
        
    else
        
        sigmaData(count.countCross).user                            = user;
        sigmaData(count.countCross).input                       = rawData(k);
 
        sigmaData(count.countCross).ASSnorm                         = [];
        sigmaData(count.countCross).ATOMnorm                        = [];
        
        sigmaData(count.countCross).ASSi                            = rawData(k).procAss.ASSi;
        sigmaData(count.countCross).ATOMi                           = rawData(k).procAss.ATOMi_MARKLEY;
        
        if ~isempty(rawData(k).procAss.ASSi_resName)
            sigmaData(count.countCross).ASSi_resName                = rawData(k).procAss.ASSi_resName;
        else
            sigmaData(count.countCross).ASSi_resName                = [];
        end
        
        sigmaData(count.countCross).ASSj                            = rawData(k).procAss.ASSj;
        sigmaData(count.countCross).ATOMj                           = rawData(k).procAss.ATOMj_MARKLEY;
        
        if ~isempty(rawData(k).procAss.ASSj_resName)
            sigmaData(count.countCross).ASSj_resName                = rawData(k).procAss.ASSj_resName;
        else
            sigmaData(count.countCross).ASSj_resName                = [];
        end
        
        sigmaData(count.countCross).stereoSpec.corrFacFlag          = 0;
        sigmaData(count.countCross).stereoSpec.Assi                 = [];
        sigmaData(count.countCross).stereoSpec.ASSj                 = [];
        sigmaData(count.countCross).stereoSpec.corrFac              = [];
        
        sigmaData(count.countCross).ASSnorm                         = [];
        sigmaData(count.countCross).ATOMnorm                        = [];
        sigmaData(count.countCross).numcode.ASSi                    = rawData(k).procAss.ASSi;
        sigmaData(count.countCross).numcode.ATOMi                   = rawData(k).procAss.ATOMi_NUMCODE;
        sigmaData(count.countCross).numcode.ATOMi_pdbSerNo          = rawData(k).procAss.ATOMi_pdbSerNo;
        sigmaData(count.countCross).numcode.ATOMi_H                 = [];
        sigmaData(count.countCross).numcode.ATOMi_HpdbSerNo         = [];
        
        sigmaData(count.countCross).numcode.ASSnorm                 = [];
        sigmaData(count.countCross).numcode.ATOMnorm                = [];
        sigmaData(count.countCross).numcode.ASSj                    = rawData(k).procAss.ASSj;
        sigmaData(count.countCross).numcode.ATOMj                   = rawData(k).procAss.ATOMj_NUMCODE;
        sigmaData(count.countCross).numcode.ATOMj_pdbSerNo          = rawData(k).procAss.ATOMj_pdbSerNo;
        sigmaData(count.countCross).numcode.ATOMj_H                 = [];
        sigmaData(count.countCross).numcode.ATOMj_HpdbSerNo         = [];
        sigmaData(count.countCross).numcode.ATOMmultiplicity        = [];
        sigmaData(count.countCross).numcode.split                   = [1 1];
        sigmaData(count.countCross).numcode.stereo                  = [0 0];
        sigmaData(count.countCross).numcode.pseudo                  = [0 0];
        
        sigmaData(count.countCross).numcode.sigmaEffScaling         = [];
        sigmaData(count.countCross).numcode.IzeroScaling            = [];
        
        sigmaData(count.countCross).structural.rPdb                 = [];
        sigmaData(count.countCross).structural.ASSi_secondStruct    = [];
        sigmaData(count.countCross).structural.ASSj_secondStruct    = [];
        
        
        sigmaData(count.countCross).buildups.fullSetmixTimes        = user.mixing_times;
        sigmaData(count.countCross).buildups.fullSetDPraw           = rawData(k).procAss.INVintensities;
        sigmaData(count.countCross).buildups.mixTimes               = user.mixing_times;
        sigmaData(count.countCross).buildups.DPraw                  = rawData(k).procAss.INVintensities;
        sigmaData(count.countCross).buildups.exp_build_up_H1H2_norm = [];
        
        sigmaData(count.countCross).buildups.rhoi                   = [];
        sigmaData(count.countCross).buildups.rhoj                   = [];
        
        sigmaData(count.countCross).buildups.rawIzero               = [];
        sigmaData(count.countCross).buildups.Izero                  = [];
        
        sigmaData(count.countCross).buildups.sigmaij                = [];
        sigmaData(count.countCross).buildups.LambdaPlus             = [];
        sigmaData(count.countCross).buildups.LambdaMinus            = [];
        sigmaData(count.countCross).buildups.Pointtheo              = [];
        sigmaData(count.countCross).buildups.diff                   = [];
        sigmaData(count.countCross).buildups.chisq                  = [];
        sigmaData(count.countCross).buildups.chisq05                = [];
        sigmaData(count.countCross).buildups.maxDP                  = [];
        sigmaData(count.countCross).buildups.chiN                   = [];
        
        if user.magNormSpin         == 1
            
            sigmaData(count.countCross).ASSnorm                     = sigmaData(count.countCross).ASSi;
            sigmaData(count.countCross).ATOMnorm                    = sigmaData(count.countCross).ATOMi;
            sigmaData(count.countCross).numcode.ASSnorm             = sigmaData(count.countCross).numcode.ASSi;
            sigmaData(count.countCross).numcode.ATOMnorm            = sigmaData(count.countCross).numcode.ATOMi;
            sigmaData(count.countCross).numcode.ATOMnorm_pdbSerNo  	= sigmaData(count.countCross).numcode.ATOMi_pdbSerNo;

        elseif user.magNormSpin     == 2
            
            sigmaData(count.countCross).ASSnorm                     = sigmaData(count.countCross).ASSj;
            sigmaData(count.countCross).ATOMnorm                    = sigmaData(count.countCross).ATOMj;
            sigmaData(count.countCross).numcode.ASSnorm             = sigmaData(count.countCross).numcode.ASSj;
            sigmaData(count.countCross).numcode.ATOMnorm            = sigmaData(count.countCross).numcode.ATOMj;
            sigmaData(count.countCross).numcode.ATOMnorm_pdbSerNo   = sigmaData(count.countCross).numcode.ATOMj_pdbSerNo;
            
        end
        
        
        sigmaData(count.countCross).decay.fullSetmixTimes           = [];
        sigmaData(count.countCross).decay.fullSetDPrho              = [];
        sigmaData(count.countCross).decay.mixTimes                  = [];
        sigmaData(count.countCross).decay.DPrho                     = [];
        sigmaData(count.countCross).decay.rho                       = [];
        sigmaData(count.countCross).decay.Const                     = [];
        sigmaData(count.countCross).decay.chiNRho                   = [];
        sigmaData(count.countCross).rhoi                            = [];
        sigmaData(count.countCross).rhoj                            = [];
        sigmaData(count.countCross).Izeroij                         = [];
        sigmaData(count.countCross).Izeroji                         = [];
        sigmaData(count.countCross).chisq05                         = [];
        sigmaData(count.countCross).chiN                            = [];
        sigmaData(count.countCross).sigmaij                         = [];
        sigmaData(count.countCross).unique                          = [];
        sigmaData(count.countCross).indxji                          = [];
        sigmaData(count.countCross).sigmaji                         = [];        
         
        count.countCross                                            = count.countCross + 1;
    end
end

count.countDiag                                                     = count.countDiag - 1;
count.countCross                                                    = count.countCross - 1;

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

fprintf('\n\nSorting sigmaData\n\n')
% sort the sigmaData structure entries 
clearvars A B sortIndx
    
A(1,:)          = arrayfun(@(x) x.numcode.ASSi,     sigmaData);
A(2,:)          = arrayfun(@(x) x.numcode.ATOMi,    sigmaData);
A(3,:)          = arrayfun(@(x) x.numcode.ASSj,     sigmaData);
A(4,:)          = arrayfun(@(x) x.numcode.ATOMj,    sigmaData);

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

sigmaData       = sigmaData(sortIndx);

clearvars A B sortIndx
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       