C
C LAST UPDATE:
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C******************************
C**     LFN_GET_SPOTCODE     **
C******************************
C
CD-Routine: Get Integrated Spot Code - LFN_GET_SPOTCODE
C This routine is used to return the integration code flag of the last 
C integrated spot calculated using the diagnostic option of the routine 
C LFN_SAINT to integrate an individual profile-fitted spot.
CD-end
CD-Fortran:
      SUBROUTINE LFN_GET_SPOTCODE (BAD_SP, I_CODE, IERR, ERRSTR)
CD-end
      INCLUDE 'implicit_none.finc'
C
C PURPOSE: Get integrated spot code calculated by LFN_SAINT
C 
C AUTHOR: J.W. Campbell 
C
C ARGUMENTS:
C
      LOGICAL BAD_SP
      INTEGER I_CODE
      INTEGER IERR
      CHARACTER*(*) ERRSTR
CD-Parameters:
C   BAD_S               l  (W) Bad spot flag =.true. yes, = .false. not
C   I_CODE              i  (W) Integration code flag
C                              =0 clear
C                              Bit 0 set: Bad spot, 
C                                         no non-overlapped pixels in 
C                                         peak - LFN_SAINT returns error
C                              Bit 1 set: Bad spot, 
C                                         <20% non-overlapped pixels in 
C                                         peak
C                              Bit 2 set: Bad spot, 
C                                         <3 non-overlapped pixels in 
C                                         background - LFN_SAINT returns 
C                                         error
C                              Bit 3 set: Bad spot, 
C                                         <20% non-overlapped pixels in 
C                                         background
C   IERR                i  (W) Error flag =0 OK
C                                =1 No spot stored
C   ERRSTR              c  (W) Error message string (max 80 chars) set 
C                              if IERR is non-zero
CD-end
C
C====== Parameter statements
C 
      INCLUDE 'saint_limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'lfn_saint.finc'
C
C====== LOCALS:
C
      INTEGER I

C     INTEGER I       !Temp/loop variable
C
C------------------------------------------------------------------------------- 
C
      IERR = 0
      ERRSTR = ' '
C
C====== Error checks
C
      IF (KSPOT_LAST.LE.0) THEN
         IERR = 1
         ERRSTR = 'No individual spot data currently stored'
         RETURN
      END IF
C
C====== Return data
C
      BAD_SP = BAD
      I_CODE = ICODE
      RETURN
      END
