
C LAST UPDATE:
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++C
C***************************
C**     LSM_NUM_REFOBS   **
C***************************
C
C **** LSM SERVICE ROUTINE ONLY ****
C
      INTEGER FUNCTION LSM_NUM_REFOBS (LINDX, REFERENCE)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Gets the number of scaling refinement observations for currently
C          selected reflection types (see LSM_SELECT_PKPL, LSM_SELECT_SCREFS)
C
C Author:  Steffi Arzt, John Campbell, July 1997
C
C Arguments:
C
      INTEGER LINDX
      LOGICAL REFERENCE
C
C  Parameters:
C  LINDX       i (R)   The index of the Laue Integrated Reflections List
C  REFRENCE    i (R)   This must be .TRUE. if refining against reference
C                      intensities (REFERENCE must also have been .TRUE.
C                      when LSM_SELECT_SCREFS was called) or .FALSE. for
C                      internal refinement.
C
C         Returns >=0   the number of reflections in the set
C                  -1   if 'markup_required' flag or 'select_required'
C                       flag found to be set.
C                  -100 if invalid LINDX
C
C Implementation note: Checks that 'markup required' flag not set
C
C
C====== Parameter statements
C 
      INCLUDE 'limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'lsm_flags.finc'

C
C====== FUNCTION TYPES:
C
      INTEGER LSM_NEXT_REFLN 
c>>>>>
C      integer lsm_indx
C
C====== LOCALS:
C
      INTEGER N
      INTEGER IERR
      INTEGER NOBS

C     INTEGER N             !No. of reflections in next set
C     INTEGER IERR          !Error flag
C     INTEGER NOBS          !No. of observations counter
C
C------------------------------------------------------------------------------
C
      CALL LSM_TOP_LIRL (LINDX, IERR)

      IF (IERR.NE.0) THEN
          LSM_NUM_REFOBS = -100
          RETURN
      END IF
      IF (MARKUP_REQUIRED.OR.SELECT_REQUIRED) THEN
         LSM_NUM_REFOBS = -1
         RETURN
      END IF
      NOBS = 0
10    N = LSM_NEXT_REFLN(IERR) 
      IF (N.LT.0) THEN
         LSM_NUM_REFOBS = NOBS
         RETURN
      END IF
      IF (.NOT.REFERENCE.AND.N.LE.1) GO TO 10
      NOBS = NOBS + N
      GO TO 10
      END
