******************************************************************
*
*	TITLE:  CONVERT RECONSTRUCTED DIGITAL VALUES INTO GAMMAS
*
*	FILE NAME:  CR1LFM.FOR
*
*	PURPOSE:  TO CONVERT DIGITAL CR-1 MAG SCIENCE DATA
*
*	HISTORY:
*
*	AUTHOR            DATE            CHANGE
*	--------          ----            -------
*       S. B. KRAMER     10/03/95         ORIGINAL CODE
*                                         (MODE CR-1)
*
*
*	COMMON AREAS:
*
*		SEE UNPACK.INC FOR COMMON AREA DEFINITIONS
*
*	NOTES:
*
*
*	PDL:
*
*	   CALL COMMAND AND STATUS WORD EXTRACTION ROUTINE
*	   CALL COUNTS TO GAMMAS CONVERSION ROUTINE
*	   CALL SENSOR ALIGNMENT ROUTINE
*	   CALL BOOM ALIGNMENT ROUTINE
*
*	RETURN
*
******************************************************************
      SUBROUTINE CR1LFM(GAMMA,GAMMA2,BAD,TIME)
C
      INTEGER*2 TIME(6)
      LOGICAL*1 SROTATE,BROTATE
      REAL*4 GAMMA(3,800),GAMMA2(3,800)
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,8,8)
C
C CONVERT COUNTS INTO GAMMAS (MODE SENSITIVE)
C
      DO I = 1,800
       PREC(1,I) = PREF(1,I)
       PREC(2,I) = PREF(2,I)
       PREC(3,I) = PREF(3,I)
       SREC(1,I) = SREF(1,I)
       SREC(2,I) = SREF(2,I)
       SREC(3,I) = SREF(3,I)
      END DO
      CALL MAKEGAMMAS(GAMMA,800,GAMMA2,800,8,8,BAD,TIME)
C
C ORTHOGONALIZE DATA WITH SENSOR MATRIX AFTER GAMMAS (MODE SENSITIVE)
C
      IF ( SROTATE ) THEN
       CALL SENSOR_ALIGN(GAMMA,GAMMA2,800,800,8,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,800,8,BAD)
      END IF
C
      RETURN
      END
