      XYZN(I,J)-O.DO
      DOLOOP K=1, 3
	  XYZN(I,J)=XYZ(I,K)*W(K,J)+XYZN(I,J)
      ENDLOOP
      ENDLOOP
      ENDLOOP
      RETURN
      END
C
C
C
      SUBROUTINE MUL(A.B)
CC CALCULATES THE PRODUCT Of TWO MATRICES (3, 3)*(3,1)=(3, 1)
CC I.E B=A*B
CC J.0. 14/20/86
      REAL*8 A(3,3),B(3),C(3)
      DOLOOP I-1,3
	C(I)=0.D0
    	DOLOOP J=1, 3
          C(l)=A(I,J)*B(J)+C(I)
	ENDLOOP
      ENDLOOP
      DOLOOP I-1,3
        B(I)-C(I)
      ENDLOOP
      RETURN
      END


      SUBROUTINE FSSCO
     +(ISTR2,FMTBUF,ATTI,SUN,SRA,SDE,DEBLUR,ATTC,IRET)
C		ORIGINAL VERSION DATE	<870824.1904>
C
CP		FROM THE NOMINAL EXOSAT SPACECRAFT ATTITUDE, IT CALCULATES THE
CP		INSTANTANEOUS ATTITUDE CORRECTED (IF NECESSARY) FOR MOTION
CP		DUE TO USE OF FSS,FOR ATTITUDE CONTROL AND OPTIONALLY FOR MOTION
CP		DUE TO LIMIT CYCLING. IT SHOULD BE USED ONLY FOR STABLE POINTING
CP		PERIODS. (USE SLWAT FOR PERIODS WHEN OUTER LOOP IS OPEN).
CP		ONE MAY CALL FSSCO EVEN IF NOT USING THE FSS - ATTC WILL THEN
CP		JUST BE SET TO ATTI.
C
CC		PROJ-EXO,SUBJ=ATT,UTIL-SPEC,AUTH-A.SCKUETZ, JUNE 84
CC		MODIFIED BY J. STERNBERG TO SPLIT FSS STUFF OFF FROM SLEW STUFF(09/86)
C	ARGUMENTS :
C
CI INPUT			FMTBUF	12	(984) 	TELEMETRY FORMAT - HK RECORD
CI			AT THE TIME FOR WHICH ATTITUDE IS REQUIRED
CI			HALF-WORDS
Cl				0- 39	IDENTIFICATION
CI				40- 71	MODE ANALYSIS RESULTS
CI				72- 583	HX TELEMETRY FORMAT
CI			    584- 711	HK DERIVED PARAMETERS
CI			712- 726		TIME/QUALITY INFORMATION
CI			727- 983	NOT RELEVANT
C
CI	ATTI	R8 (3,3)	3-AXIS ATTITUDE FROM AUX DATA
CI	(I,1) STAR TRACKER X-..XIS
CI	(1,2) STAR TRACKER Y-..XIS
CI	(1,3) STAR TRACKER Z-..XIS
C
C
C
CI	SUN	R8	(3)	S/C TO SUN UNIT VECTOR
C
CI	SRA		RS	(1)	RIGHT ASCENSION OF GUIDE STAR I (RADIANS)
CI	SDE		RS	(1) DECLINATION OF GUIDE STAR I (RADIANS)
CI
C
CI	DEBLUR	L	(1)	A FLAG TO INDICATE WHETHER ATTITUDE
Cl					MATRIX SHOULD IN ADDITION BE CORRECTED
CI					FOR MOTION DUE TO LIMIT CYCLE:
CI						.TRUE.=CORRECT IT
CI						.FALSE.= DON'T CORRECT IT, BECAUSE
CI						THE BLURRING IS EITHER TO BE IGNORED
CI						OR TO BE HANDLED OUTSIDE THIS S/W.
C
CO	OUTPUT ATTC	R8	(3,3)	3-AXIS ATTITUDE AT TIME OF "FMTBUF"
CO					CORRECTED IF NECESSARY FOR FSS/DEBLURRING
C
CO		IRET	I	(1)			RETURN CODE	-
CO					= 0 NO ERROR
CO					BIT 15 (=LSB) SET IT ITERATIONS DON'T
CO							CONVERGE IN "SUNCO" ROUTINE
CO					BIT 14 SET IF UNRECOGNISABLE FORMAT
C
CS	DROTX	ROTATES	AN ATTITUDE MATRIX AROUND X,Y OR Z AXIS
CS	SUNCO	RECOMPUTE THE ATTITUDE MATRIX AS FUNCTION OF
CS	 		STAR REFERENCE POSITION AND FSS MEASUREMENTS
CS	MVW	MOVE n 16-BIT WORDS FROM 2ND ARGUMENT TO 3RD.
C
C
	IMPLICIT REAL*8 (A-H,O-Z)
	LOGICAL DEBLUR,SUMPRE
	INTEGER*2 FMTBUF(l),A5289,AI03,AO59,LI,L2,L3
	INTEGER*4 I4,D32768
	REAL*8 ATTI(3,3),ATTC(3,3),SUN(3),ERR(3)
	INTEGER*2 I2(2)
	EQUIVALENCE (I4,I2)
	DATA D32768/32768/
	DATA SECA/.206264806247096D+06/	!RADS TO ARC SECS
	DATA SECFSH/2417.1656982082/	!RADS TO FSS HIGH-GAIN UNITS (256/3")
	DATA SECFSL/38674.651171331/	!RADS TO FSS LOW-GAIN UNITS (16/3")
	DATA A5289/709/
	DATA A103/182/
	DATA A059/175/
	IRET=0
C COPY ATTI INTO ATTC
	CALL MVW(36,ATTI,ATTC)
C CHECK FOR 2 STAR MODE
	IF(ISTR2.NE.0)THEN
C EXTRACT ICRS, WHICH IS PARAMETER A528. IT IS A 4-BIT PARAMETER, BUT
C HERE ONLY ONE BIT IS USED (THE LSB) CALLED "ICRS1"
C EXTRACT ICFL TOO (A529)
		I=ISHFT(FMTBUF(A5289),-7)
		ICFL-IAND(I,1)
		ICRSI-IAND(I/2,1)
C IF THE MONITORING IS ON ONE STAR AND SUN THE INERTIAL X (ROLL)
C ERROR IS NOT RELIABLE AND NEEDS TO BE RECOMPUTED FROM FSS MEAS.
C ALSO, CHECK SUN PRESENCE INDICATOR FOR FSS IX (AI03, FR 13, WD 10 BT 6)
		SUNPRE=IAND(FMTBUF(AI03),OOIOOOB).NE.0
		IF(ICRSI.EQ.0.AND.ICFL.EQ.O.AND.SUNPRE)THEN
C RETRIEVE FSS GAIN SELECTION (PARAM.AO59, FRAME 12,WORD 13, BIT 0)
			IGAIN=IAND(ISHFT(FMTBUF(A059),-7),I)
C RETRIEVE AND SUM ALL FOUR FSS MEASUREMENTS FROM TLM FORMAT
C PARAM.A163, FRAME 1, WORD 15, BITS 0-7
			JCOUNT=0
			NFSS=0
			L1=88
			L2=472
