%[mso] = moc2mso transforms moc into mso, i.e. rotates around the z-axis so
%that the x-axis points towards the Sun
%
%Initial version: Niklas Edberg, Swedish Institute of Space Physics, Uppsala, Oct 2005

function mso = moc2mso(moc,rs_moc)

    mso=ones(size(moc));
    
    angletosun = atan2(rs_moc(2,:),rs_moc(1,:)); %angle between x-axis and the Sun
    
    for i = 1:length(moc)
        T=R(angletosun(i));
        mso(:,i)=T*moc(:,i);
    end