C
C LAST UPDATE:
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C******************************
C**     LFN_GET_INTSPOT      **
C******************************
C
CD-Routine: Get Integrated Spot Data - LFN_GET_INTSPOT
C This routine is used to return the details of the last integrated spot 
C calculated using the diagnostic option of the routine LFN_SAINT to 
C integrate an individual profile-fitted spot.
CD-end
CD-Fortran:
      SUBROUTINE LFN_GET_INTSPOT (MAX_NUMS, KSPOT, KH, KK, KL, 
     +                            XPOS_S, YPOS_S, NUM_S,
     +                            IXP_S, IYP_S, ISHAPE_S, PIXV_S,
     +                            PROF_S, SUBPR_S, IREJ_S, NREJ_S,
     +                            BACK_S, AINTEN_S, SIGI_S, 
     +                            IERR, ERRSTR)
CD-end
      INCLUDE 'implicit_none.finc'
C
C PURPOSE: Get profile details from a profile calculated by LFN_SAINT
C 
C AUTHOR: J.W. Campbell 
C
C ARGUMENTS:
C
      INTEGER MAX_NUMS
      INTEGER KSPOT
      INTEGER KH
      INTEGER KK
      INTEGER KL
      REAL XPOS_S
      REAL YPOS_S
      INTEGER NUM_S
      INTEGER IXP_S(MAX_NUMS)
      INTEGER IYP_S(MAX_NUMS)
      INTEGER ISHAPE_S(MAX_NUMS)
      REAL PIXV_S(MAX_NUMS)
      REAL PROF_S(MAX_NUMS)
      REAL SUBPR_S(MAX_NUMS)
      INTEGER IREJ_S(MAX_NUMS)
      INTEGER NREJ_S
      REAL BACK_S(3)
      REAL AINTEN_S
      REAL SIGI_S
      INTEGER IERR
      CHARACTER*(*) ERRSTR
CD-Parameters:
C   MAX_NUMS            i  (R) Maximum dimension for returned spot arrays
C   KSPOT               i  (W) Spot no. in LRL of last integrated spot
C   KH                  i  (W) 'h' index of last integrated spot
C   KK                  i  (W) 'k' index of last integrated spot
C   KL                  i  (W) 'l' index of last integrated spot
C   XPOS_S              r  (W) Spot 'x' position in rasters
C   YPOS_S              r  (W) Spot 'y' position in rasters
C   NUM_S               i  (W) No. of pixels in spot
C   IXP_S(MAX_NUMS)     i  (W) Pixel 'x' offsets from spot centre
C   IYP_S(MAX_NUMS)     i  (W) Pixel 'y' offsets from spot centre
C   ISHAPE_S(MAX_NUMS)  i  (W) Mask 0,1 = background; 
C                              -1 omitted border pixel;
C                              -2 omitted pixel from overlapped spot;
C                              -3 saturated pixels (omitted)
C                              >=10 peak pixel
C   PIXV_S(MAX_NUMS)    r  (W) Pixel OD values
C   PROF_S(MAX_NUMS)    r  (W) Profile values
C   SUBPR_S(MAX_NUMS)   r  (W) Background subtracted pixel values
C   IREJ_S(MAX_NUMS)    i  (W) Reject pixels flags (=0 OK , =1 rejected)
C   NREJ_S              i  (W) No. of rejected pixels
C   BACK_S(3)           r  (W) Background plane constants
C   AINTEN_S            r  (W) Integrated intensity
C   SIGI_S              r  (W) sig(I)
C   IERR                i  (W) Error flag =0 OK
C                                =1 No spot stored
C                                =2 Spot arrays too small
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
      INTEGER J

C     INTEGER I       !Temp/loop variable
C     INTEGER J       !Temp/loop variable
C
C------------------------------------------------------------------------------- 
C
      IERR = 0
      ERRSTR = ' '
C
C====== Error checks
C
      KSPOT = KSPOT_LAST
      IF (KSPOT.LE.0) THEN
         IERR = 1
         ERRSTR = 'No individual spot data currently stored'
         RETURN
      END IF
      IF (MAX_NUMS.LT.NUM_IN_SPOT) THEN
         IERR = 2
         ERRSTR = 'Spot arrays too small to return data'
         RETURN
      END IF
C
C====== Return data
C
      NUM_S = NUM_IN_SPOT
      DO 20 I= 1, NUM_IN_SPOT
         IXP_S(I) = IXP(I)
         IYP_S(I) = IYP(I)
         ISHAPE_S(I) = SHAPE(I)
         PIXV_S(I) = PIXV(I)
         PROF_S(I) = PROF_IND(I)
         SUBPR_S(I) = SUBPR(I)
         IREJ_S(I) = 0
         DO 10 J = 1, NREJ
            IF (I.EQ.IREJ(J)) IREJ_S(I) = 1
 10      CONTINUE
 20   CONTINUE
      DO 30 I = 1,3 
         BACK_S(I) = BACK(I)
 30   CONTINUE
      KH = I_H
      KK = I_K
      KL = I_L
      XPOS_S = XPOS
      YPOS_S = YPOS
      NREJ_S = NREJ
      AINTEN_S = INTEN
      SIGI_S = SIGI
      RETURN
      END
