
C LAST UPDATE:
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C*****************************
C**     LSM_MISSING_RFLAGS  **
C*****************************
C
C **** LSM SERVICE ROUTINE ONLY ****
C
      SUBROUTINE  LSM_MISSING_RFLAGS
C
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Clear refinement flags associated with packs and plates
C          for which no data found.
C
C Author:  Steffi Arzt, John Campbell, July 1997
C
C Arguments:
C
C none
C
C Parameters:
C
C none
C
C====== PARAMETERS:
C
      INCLUDE 'limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'ref_flags.finc'
      INCLUDE 'scps_counters.finc'
      INCLUDE 'scp.finc'
      INCLUDE 'other_scale.finc'
      INCLUDE 'found_pkpl.finc'
C
C====== LOCALS:
C
      LOGICAL PK_FOUND(MAXPACK)
      INTEGER I, J, K, IC
     
C          
C-------------------------------------------------------------------------------
C
C
C====== Reset omitted plate scale flags 
C
      IC = MAXRANGE*MAXPACK*MAXPLATES

      DO 80 I = 1, MAXRANGE
         IF (PLSCRAN(I)) THEN
            DO 60 J = 1, NPK
               DO 70 K = 2, NPL(J)
                  IF (.NOT.FOUND_PKPL(J,K)) THEN
	             REFLAGS(IC+(I-1)*MAXPACK*MAXPLATES+
     +                          (J-1)*MAXPLATES+K) = .FALSE.
                  END IF
70             CONTINUE
60          CONTINUE
         END IF
80    CONTINUE 
C
C====== Find list of packs with data present
C
      DO 100 I = 1, NPK
         PK_FOUND(I) = .FALSE.
         DO 90 J = 1, NPL(I)
            IF (FOUND_PKPL(I,J)) PK_FOUND(I) = .TRUE. 
 90      CONTINUE
 100  CONTINUE
C        
C====== Reset omitted pack scale refinement flags
C
      DO 110 I = 2, NPK
	 IF (.NOT.PK_FOUND(I)) REFLAGS(NCSCP(2)+I) = .FALSE.
 110  CONTINUE

C
C====== Reset omitted pack BFAC refinement flags
C
      DO 120 I = 2, NPK
	 IF (.NOT.PK_FOUND(I)) REFLAGS(NCSCP(3)+I) = .FALSE.
120    CONTINUE
      IF (ABSCORLOC) THEN
         DO 150 I = 1, NPK
            IF (.NOT.PK_FOUND(I)) THEN
               DO 140 J = 1, NABSL(I)*MABSL(I)-1
                  REFLAGSLOC(I,J) = .FALSE.
 140           CONTINUE
            END IF
 150     CONTINUE
      END IF

      RETURN
      END
