HC_TITLE   ROTMSP   General 3-dimension rotation matrix geometry package.GC_DESCRIPTION  ROTMSP is a general 3-dimension rotation matrix geometryC package with many routines. *C Argument order is: input _SPACE_ output,MC Angular arguments are in radians; except the pointing triple is in degrees.JC Matrices are assumed stored as:  AA(I,J) = AA(row,column) = A(I+3(J-1)).CBC Output argument may overwrite input argument for routine TRANS3.C:C aa,bb,cc and a,b,c are 3X3 matrices;  u,v are 3-vectors;6C R, are argument scalars; E,F,G are internal scalars.EC ** This is a single precision version; to generate double precision6C **   version, make the following changes throughout:C **  REAL*4  >  REAL*8"C **  ASIN, ATAN2  >  DASIN, DTAN2%C **  E0  >  D0       E15.6  > D22.13#C_HISTORY  H.KIEFFER  85APR17  USGSC_PAUSE%	SUBROUTINE ROTORB (ODE,CLIN,ARGP, A)FC_Titl  ROTORB construct rotation matrix from classic orbital elementsC_Args)	REAL*4 ODE	! in. node of orbit <degrees>1	REAL*4 CLIN	! in. inclination of orbit <degrees>2	REAL*4 ARGP	! in. argument of periapsis <degrees>?	REAL*4 A(9)	! out. rotation matrix, from orbital to reference.C_DescKC does 3  Euler rotations.  ORBITAL elements input must be specified in theGC   cordinate system to be the "to" orientation of the rotation matrix.2C_Hist	87oct11  Hugh_H_Kieffer  U.S.G.S._FlagstaffC_Call  ROTSP systemC_End=	PARAMETER (RPD=.01745329251994329577E0)	! radians per degree4	CALL ROTDIA (1., A)	! initialize as identity matrix&C the 3  Euler rotations required are:=CC A = (-node)Z * (-inclination)X * (-argument of periapsis)Z	CALL ROTAX (3, -ARGP*RPD, A)	CALL ROTAX (1, -CLIN*RPD, A)	CALL ROTAX (3, -ODE*RPD, A)	RETURN	END	SUBROUTINE ROTMAT (V, A);C_Title	ROTMAT Derive rotation matrix from pointing triple.C_Arguments>	REAL*4 V(3)	![I] Pointing triple (RA, DEC, TWIST) in degrees.4	REAL*4 A(9)	![O] Corresponding 3x3 rotation matrix.C_Keys	VECTOR ROTATION MATRIXGC_Description  The subroutine ROTMAT will derive a rotation matrix fromJC a pointing triple.  ROTMAT is a member of the ROTMSP family of programs.C_Calls	ROTDIA ROTAX4C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause=	PARAMETER (RPD=.01745329251994329577E0)	! RADIANS PER DEGREE	CALL ROTDIA (1.E0, A)"	CALL ROTAX  (3,RPD*(V(1)+90.), A)"	CALL ROTAX  (1,RPD*(90.-V(2)), A)1	IF (V(3) .NE. 0.E0) CALL ROTAX (3,RPD*(V(3)), A)	RETURN	END&	SUBROUTINE MEQUAL (B, A)		! [A] = [B]0C_Title	MEQUAL Equate one 3x3 matrix to another.C_Arguments 	REAL*4 B(9) 	![I] Input matrix. 	REAL*4 A(9)	![O] Output matrix.C_Keys	DC_Description  The subroutine MEQUAL will equate one 3x4 matrix with8C another.  It is part of the ROTMSP family of programs.	C_Calls	04C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause		DO I=1,9		A(I)=B(I)		ENDDO	RETURN	END7	SUBROUTINE MPRINT (ID,A,IOP)		! PRINT A MATRIX WITH ID)C_Title	MPRINT Print a 3x3 matrix with IDC_Arguments:	CHARACTER*(*) ID 	![I] Character variable identification.&	REAL*4 A(9)		![I] 3x3 array to print.0	INTEGER	IOP      	![I] Logical unit for printerC_Keys	QC_Description  The subroutine MPRINT will print a 3x3 matrix with identification.	C_Calls	04C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause,	WRITE(IOP,33) ID,(A(J),A(J+3),A(J+6),J=1,3)233	FORMAT('0MPRINT DUMP OF [',A,']',3(/5X,3E15.6))	RETURN	END4	SUBROUTINE MPROD3 (BB,CC, AA)		! [AA] = [BB] * [CC]6C_Title	MPROD3 Matrix product (hard-coded for size=3).C_Arguments.	REAL*4 BB(3,3) 	![I] First matrix of product./	REAL*4 CC(3,3)  ![I] Second matrix of product.&	REAL*4 AA(3,3)  ![O] Resulting matrixC_Keys	EC_Description  The subroutine MPROD3 produces a matrix product (hard-C coded for size=3).  	C_Calls	04C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause	DO 82 I=1,3	  DO 82 J=1,3>82	    AA(I,J)=BB(I,1)*CC(1,J)+BB(I,2)*CC(2,J)+BB(I,3)*CC(3,J)	RETURN	END*	SUBROUTINE ROTATE (B,V, U)		! U = [B] * VC_Title	ROTATE Rotate a vectorC_Arguments&	REAL*4 B(9)	![I] 3x3 Rotation matrix."	REAL*4 V(3)	![I] Original vector.?	REAL*4 U(3) 	![O] Rotated vector, must not be same array as V.C_Keys	BC_Description  The subroutine ROTATE will rotate a vector, rotate 7C  internally treats the rotation matrix as a 9-vector.	C_Calls	04C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause	DO 7 I=1,3)7		U(I)=B(I)*V(1)+B(I+3)*V(2)+B(I+6)*V(3)	RETURN	END0	SUBROUTINE ROTAX  (N,R, B)		! [B] = [R*|N|]*[B]GC_Title	ROTAX Change rotation matrix to include additional rotation 'R'C_Arguments+	INTEGER N	![I] Axis about which to rotate.,	REAL*4 R	![I] Size of rotation, in radians.D	REAL*4 B(9) 	![B] Rotation matrix (treated internally as 9-vector).C_Keys	DC_Description  The subroutine ROTAX will change a rotation matrix to'C include an additional rotation "R".  
C_Calls	0	4C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause
	REAL*4 E,F,G	E = COS(R)	F = SIN(R)	I2=MOD(N,3)	I3=MOD(N+1,3)
	DO 5 I=1,7,3		G=B(I+I2)		B(I+I2)=E*G       +F*B(I+I3)5		B(I+I3)=E*B(I+I3) -F*G	RETURN	END1	SUBROUTINE ROTDIA (R, B)		! [B] = R * [IDENTITY]3C_Title	ROTDIA Form diagonal matrix of magnitude R.C_Arguments#	REAL*4 R	![I] Magnitude of matrix.=	REAL*4 B(9)	![O] Diagonal 3x3 matrix (treated internally as 
			!9-vector)C_Keys	CC_Description  The subroutine ROTDIA will form a diagonal matrix ofC magnitude R.  	C_Calls	04C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause	DO 62 I=1,9
62		B(I)=0.E0 	DO 63 I=1,9,4
63		B(I)=R	RETURN	END	SUBROUTINE ROTRIP (A, V);C_Title	ROTRIP Converts rotation matrix to pointing triple.C_Arguments&	REAL*4 A(9)	![I] 3x3 Rotation matrix.<	REAL*4 V(3)	![O] Pointing triple in astronomic convention, 			!    in degrees.HC              (1) is Right Ascension  (2) is Declination  (3) is Twist.C_Keys	DC_Description  The subroutine ROTRIP converts a rotation matrix to aHC pointing triple.  ROTRIP is a member of the ROTMSP family of programs.	C_Calls	04C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause?	PARAMETER (DPR=57.2957795130823208768E0)  ! DEGREES PER RADIAN1	V(1) = DPR * ATAN2 (A(6),A(3))	! right ascension(	V(2) = DPR * ASIN  (A(9))	! declination'	V(3) = DPR * ATAN2 (A(7),A(8))	! twist	RETURN	END7	SUBROUTINE ROTROW (A,N, V)	! EXTRACT N'TH ROW FROM [A]2C_Title	ROTROW Extract N'th row from a 3x3 matrix.C_Arguments(	REAL*4 A(9)	![I] Rotation (3x3) matrix.%	INTEGER N       ![I] Row to extract. 	REAL*4	V(3)	![O] Row extracted.C_Keys	EC_Description  The subroutine ROTROW will extract the N'th row from aC 3x3 matrix.  	C_Calls	04C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause	V(1) = A(N)	V(2) = A(N+3)	V(3) = A(N+6)	RETURN	END	SUBROUTINE ROTZXM (Z,X, A)OC_Title	ROTZXM Construct rotation matrix from vectors along Z-axis, and in the C X-Z planeC_Arguments?	REAL*4 Z(3)	![I] Vector along Z axis (need not be normalized).D	REAL*4 X(3) 	![I] Vector in the X-Z plane (need not be normalized).?	REAL*4 A(9)	![O] 3x3 Rotation matrix to reference system, from&		 	!orientation specified by Z and X.C_Keys	JC_Description  The subroutine ROTZXM will construct a rotation matrix from3C vectors along the Z-axis, and in the X-Z plane.  C_Calls	VNORM VCROSS4C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_Pause2	CALL VNORM  (Z, A(7))		! unit vector along Z-axis9	CALL VCROSS (Z,X, A(4))		! vector in direction of Y-axis4	CALL VNORM  (A(4), A(4))	! unit vector along Y-axis9	CALL VCROSS (A(4),A(7), A(1))	! unit vector along X-axis	RETURN	END-	SUBROUTINE TRANS3  (B, A)		! A = B_TRANSPOSEAC_Title	TRANS3 Transpose a 3x3 matrix, A and B may be same array.C_Arguments	REAL*4 B(9)	![I] 3x3 matrix.$	REAL*4 A(9)	![O] transposed matrix.C_Keys	EC_Description  The subroutine TRANS3 will transpose a 3x3 matrix; the;C original and the transposed matrix may be the same array.=C TRANS3 is a member of the ROTMSP family of programs, and is.C coded to allow expansion to any size matrix.	C_Calls	04C_History	1985April H.Kieffer argument order revised:C               1985Oct15 H.Kieffer standard documentationC_End		REAL*4 E9	DATA M,MP,MM/3,4,9/	! M = matrix size, MP = M+1, MM=M*M %	DO 44 I=1,MM,MP		! transfer diagonal
44		A(I)=B(I)2	DO 45  II=2,M		! do increasing off-diagonal bands		IOFF=(II-1)*(M-1)		III=M*(MP-II)			DO 45 I=II,III,MP			IT=I+IOFF+			E=B(IT)		! save one element so transpose*			A(IT)=B(I)	!  may overwrite input array45			A(I)=E	RETURN	END