C LAST UPDATE: 
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C**************************
C**     LDM_ERR_I        **
C**************************
C
C
      SUBROUTINE LDM_ERR_I (IVAL, MINVAL, MAXVAL, IERR, ERRSTR)
C
C      INCLUDE 'implicit_none.finc'
C
C Purpose: Check for +ve integer value within range and set error flag and
C          error string for LDM 'set' routines.
C
C ***** 'LDM' SERVICE ROUTINE ONLY *****
C
C Author:  John W. Campbell, June 1993
C
C Arguments:
C
      INTEGER IVAL
      INTEGER MINVAL
      INTEGER MAXVAL
      INTEGER IERR
      CHARACTER*(*) ERRSTR

C IVAL       (R)  The value to be tested
C MINVAL     (R)  The minimum value allowed
C MAXVAL     (R)  The maximum value allowed (0 if no max.)
C IERR       (W)  Error flag 0 = OK
C                            2 = value must be >= 0
C                            3 = value must be >0
C                            6= other out of range value
C ERRSTR     (W)  Error string if error (blank if not)
C
C
C====== LOCALS:
C

C
C-------------------------------------------------------------------------------
C
      IERR = 0
      ERRSTR = ' '
      IF (IVAL.LT.MINVAL) THEN
         IF (MINVAL.EQ.0) THEN
            IERR = 2
            ERRSTR = 'Value must be >= zero'
            RETURN
         ELSE IF (MINVAL.EQ.1) THEN
            IERR = 3
            ERRSTR = 'Value must be > zero'
            RETURN
         ELSE
            IERR = 6
            ERRSTR = 'Value must be >='
            CALL STR_ADDI (STR, MINVAL, 1)
            RETURN
         END IF
      END IF
      IF (MAXVAL.EQ.0) RETURN
      IF (IVAL.LE.MAXVAL) RETURN
      IERR = 6
      ERRSTR = 'Value must be <='
      CALL STR_ADDI (ERRSTR, MAXVAL, 1)
      RETURN
      END
