******************************************************************
*
*	TITLE:  CONVERT RECONSTRUCTED DIGITAL VALUES INTO GAMMAS
*
*	FILE NAME:  GS3LFM.FOR
*
*	PURPOSE:  TO CONVERT DIGITAL GS-3 MAG SCIENCE DATA
*
*	HISTORY:
*
*	AUTHOR            DATE            CHANGE
*	--------          ----            -------
*       S. B. KRAMER     01/06/94         ORIGINAL CODE
*                                         (MODE GS-3)
*
*
*	COMMON AREAS:
*
*		SEE UNPACK.INC FOR COMMON AREA DEFINITIONS
*
*	NOTES:
*
*
*	PDL:
*
*	   CALL COMMAND AND STATUS WORD EXTRACTION ROUTINE
*	   CALL FULL WORD RECONSTRUCTION ROUTINE
*	   CALL COUNTS TO GAMMAS CONVERSION ROUTINE
*	   CALL SENSOR ALIGNMENT ROUTINE
*	   CALL BOOM ALIGNMENT ROUTINE
*
*	RETURN
*
******************************************************************
      SUBROUTINE GS3LFM(GAMMA,GAMMA2,BAD,TIME)
C
      INTEGER*2 TIME(6)
      LOGICAL*1 SROTATE,BROTATE
      REAL*4 GAMMA(3,800),GAMMA2(3,400)
C
      INCLUDE 'UNPACK.INC'
C
      DATA SROTATE/.TRUE./,
     &     BROTATE/.TRUE./
C
C SENSOR ROTATION SWITCH
C
      IF ( SYS2(13) ) SROTATE = .FALSE.
C
C BOOM ALIGNMENT ROTATION SWITCH
C
      IF ( SYS2(23) ) BROTATE = .FALSE.
C
C EXTRACT INSTRUMENT STATUS FROM STAT WORDS
C
      CALL MAGSTATUS(TIME,10,10)
C
C RECONSTRUCT PRIMARY FULL WORDS FROM DIFFERENCE WORDS
C
      CALL DIFFERENCE(PDIFF,800,PREF,160,PREC)
C
C RECONSTRUCT SECONDARY FULL WORDS FROM DIFFERENCE WORDS
C
      CALL DIFFERENCE(SDIFF,400,SREF,80,SREC)
C
C CONVERT COUNTS INTO GAMMAS (MODE SENSITIVE)
C
      CALL MAKEGAMMAS(GAMMA,800,GAMMA2,400,10,10,BAD,TIME)
C
C ORTHOGONALIZE DATA WITH SENSOR MATRIX AFTER GAMMAS (MODE SENSITIVE)
C
      IF ( SROTATE ) THEN
       CALL SENSOR_ALIGN(GAMMA,GAMMA2,800,400,10,BAD)
      END IF
C
C ROTATE DATA WITH BOOM ALIGNMENT MATRIX AFTER GAMMAS (MODE SENSITIVE)
C
      IF ( BROTATE ) THEN
       CALL BOOM_ALIGN(GAMMA,GAMMA2,800,400,10,BAD)
      END IF
C
      RETURN
      END
