******************************************************************
*
*	TITLE:  CONVERT RECONSTRUCTED DIGITAL VALUES INTO GAMMAS
*
*	FILE NAME:  CR3LFM.FOR
*
*	PURPOSE:  TO CONVERT DIGITAL CR-3 MAG SCIENCE DATA
*
*	HISTORY:
*
*	AUTHOR            DATE            CHANGE
*	--------          ----            -------
*       S. B. KRAMER     03/25/96         ORIGINAL CODE
*                                         (MODE CR-3)
*
*
*	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 CR3LFM(GAMMA,GAMMA2,BAD,TIME)
C
      INTEGER*2 TIME(6)
      LOGICAL*1 SROTATE,BROTATE
      REAL*4 GAMMA(3,400),GAMMA2(3,100)
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,2)
C
C CONVERT COUNTS INTO GAMMAS (MODE SENSITIVE)
C
      DO I = 1,400
       PREC(1,I) = PREF(1,I)
       PREC(2,I) = PREF(2,I)
       PREC(3,I) = PREF(3,I)
       IF ( I.LE.100 ) THEN
        SREC(1,I) = SREF(1,I)
        SREC(2,I) = SREF(2,I)
        SREC(3,I) = SREF(3,I)
       END IF
      END DO
      CALL MAKEGAMMAS(GAMMA,400,GAMMA2,100,10,2,BAD,TIME)
C
C ORTHOGONALIZE DATA WITH SENSOR MATRIX AFTER GAMMAS (MODE SENSITIVE)
C
      IF ( SROTATE ) THEN
       CALL SENSOR_ALIGN(GAMMA,GAMMA2,800,800,2,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,2,BAD)
      END IF
C
      RETURN
      END
