function [R,Rt] = gse2gsm(dn);
%   Re-Created October 29, 2002 after loss in disk crash last summer
%       dn      =       the datenumber of the event
%       R       =       the forward transformatio from GSE to GSM
%       Rt      =       the inverse transform from GSM to GSE
%       Both matrices are 9-column arrays for use with mat9vec3.m
%           geocentric solar ecliptic (gse)
%           geocentric solar magnetospheric (gsm)
% GSE is used for solar wind studies because it uses the normal to the
%       Earth's orbital plane as Z and Sun vector (inverse radius vector to
%       Earth) as the X axis
% GSM is used for magnetospheric studies because it uses the Sun vector as
%       X axis and the plane containing the dipole as the X-Z plane. This
%       makes the tail current parallel to the Ygsm axis
% This transform must come out to be a rotation about their joint  X axes
%       (Sun vector)

% CREATE THE DIFFERENT TRANSFOMATION MATRICES
[R1,R1t]    = gei2gse(dn);              %R1t contains the GSE to GEI
[R2,R2t]    = gei2geo(dn);              %R2  contains the GEI to GEO
[R3,R3t]    = geo2gsm(dn);              %R3  contains the GEO to GSM

% MULTIPLY THE MATRICES TOGETHER
R2R1t       = matmul9(R2,R1t);
R           = matmul9(R3,R2R1t);

% CREATE THE INVERSE Rt AS 9-COL ARRAY
Rt	= [R(:,1),R(:,4),R(:,7),R(:,2),R(:,5),R(:,8),R(:,3),R(:,6),R(:,9)]; 
return



)
