  
C LAST UPDATE:
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C*******************************
C**  LSM_SELECT_SCREFS_LSP    **
C*******************************
C
C
CD-Routine: Select reflection types - LSM_SELECT_SCREFS_LSP
C This routine calls LSM_SELECT_SCREFS with its parameters derived from the LSP
C parameter set.
CD-end
CD-Fortran:
      SUBROUTINE LSM_SELECT_SCREFS_LSP (IERR, REFERENCE, ERRSTR)
CD-end
C
      INCLUDE 'implicit_none.finc'
C
      INTEGER IERR
      LOGICAL REFERENCE
      CHARACTER*(*) ERRSTR
C
CD-Parameters:
C  IERR      i (W)   Error flag = 0 OK
C                               = 1 Error
C  REFERENCE l (R)   If .true. then only reflections which have a
C                    reference intensity stored will be returned;
C                    if .false., reflections will be returned whether
C                    or not a reference intensity is present.
C  ERRSTR    c (W)   Error string if IERR is non-zero (max 80 characters)
CD-end
C
C====== PARAMETERS:
C
      INCLUDE 'limits.finc'
C
C====== GLOBALS:
C
      INCLUDE 'lsm_flags.finc'
      INCLUDE 'ref_ctrl.finc'

C
C====== FUNCTION TYPES:
C

      INTEGER KDMSTR
      INTEGER LENSTR

C
C====== LOCALS:
C
C     
      INTEGER KERR              
      INTEGER MAXE
      INTEGER IVAL(10)
      INTEGER NUM_INP
      INTEGER ISTAT 
      INTEGER ND(MAXCOEFFS)
      INTEGER ITYP                
      REAL FVAL(MAXVARR)
      REAL SIGMA_CUT
      LOGICAL SIGN_SEP
      LOGICAL SPOV
      LOGICAL OVLD
      CHARACTER*80 STR   
      CHARACTER*20 VALSTR
C     INTEGER  KERR                ! Error return flag
C     INTEGER MAXE                 ! Max length for error string
C     INTEGER IVAL(10)             ! Integer values array
C     INTEGER NUM_INP              ! No. of input values for a variable 
C                                  ! array param.
C     INTEGER ISTAT                ! Parameter status flag
C     INTEGER ND(MAXCOEFFS)        ! No. of decimal places flags array
C     INTEGER ITYP                 ! Parameter type
C     REAL FVAL(MAXVARR)           ! Real values array
C     CHARACTER*80 STR             ! Temporary string
C     CHARACTER*20 VALSTR          ! Dummy value string
C  SIGN_SEP    l (R)   If .true. the I+ and I- measurements will be returned
C                      as separate reflection sets; if .false. all symmetry
C                      equivalents bot I+ and I- will be returned together.
C  SIGMA_CUT   r (R)   Omit reflections for which the intensity I is
C                      less than SIGMA_CUT*sig(I).
C  SPOV        l (R)   Flag = .true.  include spatially overlapped
C                                     reflections which have been
C                                     integrated,
C                           = .false. do not.
C  OVLD        l (R)   Flag = .true.  include intensity overloads,
C                           = .false. do not.

C
C====== Set 'markup-required' flag
C
      KERR = 0
      IERR = 0
      ERRSTR = ' '
      MARKUP_REQUIRED = .TRUE.

      MAXE = 80

      STR = 'MULTIPLES'
      CALL KDMF_GETVALUE (KINDX, KDMSTR(STR),LENSTR(STR), 
     +                 1, 1, 2, KDMSTR(VALSTR), FVAL, ND, IVAL, 
     +                 NUM_INP, ISTAT, ITYP, KDMSTR(ERRSTR), 
     +                 MAXE, KERR)  
      IF (KERR.NE.0) GOTO 810   

      STR = 'SIGN_SEP'
      CALL KDMF_GETVALUE (KINDX, KDMSTR(STR),LENSTR(STR), 
     +                 1, 1, 2, KDMSTR(VALSTR), FVAL, ND, IVAL, 
     +                 NUM_INP, ISTAT, ITYP, KDMSTR(ERRSTR), 
     +                 MAXE, KERR)  
      IF (KERR.NE.0) GOTO 810   
      IF (IVAL(1).EQ.1) SIGN_SEP = .TRUE.
      IF (IVAL(1).EQ.0) SIGN_SEP = .FALSE.

      STR = 'SPATOV'
      CALL KDMF_GETVALUE (KINDX, KDMSTR(STR),LENSTR(STR), 
     +                 1, 1, 2, KDMSTR(VALSTR), FVAL, ND, IVAL, 
     +                 NUM_INP, ISTAT, ITYP, KDMSTR(ERRSTR), 
     +                 MAXE, KERR)  
      IF (KERR.NE.0) GOTO 810   
      IF (IVAL(1).EQ.1) SPOV = .TRUE.
      IF (IVAL(1).EQ.0) SPOV = .FALSE.

      STR = 'OVERLD'
      CALL KDMF_GETVALUE (KINDX, KDMSTR(STR),LENSTR(STR), 
     +                 1, 1, 2, KDMSTR(VALSTR), FVAL, ND, IVAL, 
     +                 NUM_INP, ISTAT, ITYP, KDMSTR(ERRSTR), 
     +                 MAXE, KERR)  
      IF (KERR.NE.0) GOTO 810   
      IF (IVAL(1).EQ.1) OVLD = .TRUE.
      IF (IVAL(1).EQ.0) OVLD = .FALSE.

      STR = 'FILETYP_INPUT'
      CALL KDMF_GETVALSTR (KINDX, KDMSTR(STR), LENSTR(STR), 1, 1, 
     +                 3, KDMSTR(VALSTR), ISTAT,
     +                 ITYP, KDMSTR(ERRSTR), MAXE, KERR)
      IF (KERR.NE.0) GOTO 810 
      CALL CCPUPC(VALSTR)
      FTYP_IN = VALSTR
      IF(VALSTR.EQ.'GE') OVLD = .FALSE.


      STR = 'SIGREJ_EX'
      CALL KDMF_GETVALUE (KINDX, KDMSTR(STR),LENSTR(STR), 
     +                 1, 1, 2, KDMSTR(VALSTR), FVAL, ND, IVAL, 
     +                 NUM_INP, ISTAT, ITYP, KDMSTR(ERRSTR), 
     +                 MAXE, KERR)  
      IF (KERR.NE.0) GOTO 810   
      SIGMA_CUT = FVAL(1)

      CALL LSM_SELECT_SCREFS (SIGN_SEP, REFERENCE, SIGMA_CUT,
     +                              SPOV, OVLD) 

      RETURN

810   ERRSTR = 'Error code'
      CALL STR_ADDI (ERRSTR, KERR, 1)
      CALL STR_ADDS (ERRSTR, 'getting refinement option flag',1)
      CALL STR_ADDS (ERRSTR, STR, 1)
      IERR = 1

      RETURN

      END
