C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LDM_SET_RFL      **
C**************************
C
C
CD-Doc:
C RFL              SUBROUTINE LDM_SET_RFL (IPACK, IPLATE, IVAL, 
C                 +                        IERR, ERRSTR)
CD-end
      SUBROUTINE LDM_SET_RFL (IPACK, IPLATE, IVAL, IERR, ERRSTR)
C
      INCLUDE 'implicit_none.finc'
C
C Purpose: Set value of plate dependent integer parameter RFL
C
C Author:  John W. Campbell, June 1993
C
C Arguments:
C
      INTEGER IPACK
      INTEGER IPLATE
      INTEGER IVAL
      INTEGER IERR
      CHARACTER*(*) ERRSTR

C  IPACK     (R)   Pack number, 0=all packs
C  IPLATE    (R)   Plate number, 0=all plates
C  IVAL      (R)   Value for the parameter 0=not refined, 1=refined
C  IERR      (W)   Error flag =0 OK
C                             =-1 Invalid pack number
C                             =-2 Invalid plate number
C                             =2 Value must be >=0
C                             =4 Value out of range (other)
C  ERRSTR    (W)   Error description string if error found
C
C====== GLOBALS:
C
      INCLUDE 'ldm_data.finc'
      EXTERNAL LDM_BDAT
C
C====== LOCALS:
C
      INTEGER I
      INTEGER J
C
C-------------------------------------------------------------------------------
C
      IERR = 0
      ERRSTR = ' '
      CALL LDM_CHK_SPL (IPACK, IPLATE, IERR, ERRSTR)
      IF (IERR.NE.0) RETURN
      CALL LDM_ERR_I (IVAL, 0, 1, IERR, ERRSTR)
      IF (IERR.NE.0) RETURN
      IF (IPACK.EQ.0) THEN
         IF (IPLATE.EQ.0) THEN
            DO 100 I = 1, LDM_MAXPK
               DO 50 J = 1, LDM_MAXPL
                  RFL(I,J) = IVAL
                  IS_RFL(I,J) = 2
                  CH_RFL(I,J) = CH_MASK
50             CONTINUE
100         CONTINUE
         ELSE
            DO 150 I = 1, LDM_MAXPK
                RFL(I,IPLATE) = IVAL
                IS_RFL(I,IPLATE) = 2
                CH_RFL(I,IPLATE) = CH_MASK
150         CONTINUE
         END IF
      ELSE
         IF (IPLATE.EQ.0) THEN
            DO 200 J = 1, LDM_MAXPL
               RFL(IPACK,J) = IVAL
               IS_RFL(IPACK,J) = 2
               CH_RFL(IPACK,J) = CH_MASK
200         CONTINUE
         ELSE
            RFL(IPACK,IPLATE) = IVAL
            IS_RFL(IPACK,IPLATE) = 1
            CH_RFL(IPACK,IPLATE) = CH_MASK
         END IF
      END IF
      RETURN
      END
