function RotMati2e = Ri2e(grace_gps_time)

% RI2E returns the rotation matrix from inertial frame to an Earth-fixed
% Earth-centered coordinate system. The rotation matrix is a simple Z-rotation,
% in which the rotation axes (Z) of the inertial and the Earth-fixed frames
% coincide. It is an approximation of a realistic rotation matrix, by
% neglecting the contribution of the Precession, Nutation and polar motion.
%
%
% Input:        grace_gps_time = time (or times) in GRACE GPS seconds [Nx1]
%
% Outputs:      RotMati2e = Rotation martrix from inertial to Earth-fixed frame [Nx3x3]
%
% Example:      grace_gps_time = 281361600
%               RotMati2e = [0.341262285804206   0.939968112378121   0
%                           -0.939968112378121   0.341262285804206   0
%                                            0                   0   1]
%
% Remark:       This matrix shall be used only for simulation purposes, in
%               particular along with the simulated data available at:
%               https://www.geoq.uni-hannover.de/mock.html
%
% Written by Majid Naeimi, IfE, Hannover, 2015-08

%%

Tjd = round( (grace_gps_time/86400 + 2451545), 7);
sdt = (Tjd-2453491.5) * 86400 * 7.29211514670698e-05 - 2.46276246875459;
rot_mat = [cos(sdt) -sin(sdt) zeros(length(sdt),1)...
    sin(sdt) cos(sdt) zeros(length(sdt),1)...
    zeros(length(sdt),1) zeros(length(sdt),1) ones(length(sdt),1)];

RotMati2e = reshape(rot_mat',3,3,[]);
