      SUBROUTINE CNEXTR (BSP,XP,XPS,TPS,KOP,IRS,IRSMAX,IRDS,IRGS,IBS, &
                         ILGA,LEVA,ISEC,IRSTMAX)
!-----------------------------------------------------------------------
!     PURPOSE:
!     --------
!     EXTRACTS CHARACTERISTIC NON-DIMENSIONALIZED PARICLE GROWTH CURVES
!     AND LIMITS FOR GIVEN INITIAL PARTICLE SIZE, SUPERSATURATION, AND
!     KOEHLER PARAMETERS.
!
!     HISTORY:
!     --------
!     * JUN 20/2008 - K.VONSAKZEN   BUG FIX FOR XP
!     * APR 20/2006 - K.VONSALZEN   NEW.
!
!-----------------------------------------------------------------------
!
      USE CNPARM
!
      IMPLICIT REAL (A-H,O-Z), INTEGER (I-N)
!
      INTEGER, INTENT(IN) :: ILGA,LEVA,ISEC
      INTEGER, INTENT(IN), DIMENSION(ILGA,LEVA,ISEC) :: IRDS,IRGS,IBS, &
                                                        IRS
      REAL, INTENT(IN), DIMENSION(ILGA,LEVA,ISEC) :: BSP
      INTEGER, INTENT(IN), DIMENSION(LEVA,ISEC) :: IRSMAX
      REAL, INTENT(INOUT), DIMENSION(ILGA,LEVA,ISEC) :: XP
      REAL, INTENT(OUT), DIMENSION(ILGA,LEVA,ISEC,IRSTMAX) :: XPS,TPS
      LOGICAL, INTENT(OUT), DIMENSION(ILGA,LEVA,ISEC) :: KOP
      INTEGER, ALLOCATABLE, DIMENSION(:) :: IRDSL,IRGL,IBSL,IRSL
      INTEGER, ALLOCATABLE, DIMENSION(:,:,:,:) :: IRGT
      REAL, ALLOCATABLE, DIMENSION(:) :: BSPL
!
!-----------------------------------------------------------------------
!
!     * ALLOCATE TEMPORARY ARRAYS.
!
      ALLOCATE(IRDSL (ILGA))
      ALLOCATE(IRGL  (ILGA))
      ALLOCATE(BSPL  (ILGA))
      ALLOCATE(IBSL  (ILGA))
      ALLOCATE(IRSL  (ILGA))
!
      KOP(:,:,:)=.FALSE.
      DO IS=1,ISEC
      DO L=1,LEVA
!
!       * INTERPOLATE TABULATED DATA TO OBTAIN GROWTH CURVE THAT
!       * INCLUDES XP FOR GIVEN BS-PARAMETER. XP IS THE SCALED
!       * PARTICLE SIZE AND TP THE SCALED GROWTH TIME. PNT AND DER
!       * REFER TO THE INTIAL POINT AND DERIVATIVE WITH RESPECT TO BS,
!       * RESPECTIVELY. INDICES IR... AND IB... REFER TO THE KOEHLER
!       * PARAMETER RATIO- AND BS-AXIS OF THE DATA, WITH BS THE
!       * SCALED B-PARAMETER IN THE KOEHLER EQUATION.
!
        IRDSL(:)=IRDS(:,L,IS)
        IRGL(:)=IRGS(:,L,IS)
        BSPL(:)=BSP(:,L,IS)
        IBSL(:)=IBS(:,L,IS)
        IRSL(:)=IRS(:,L,IS)
        DO IR=1,IRSMAX(L,IS)
        DO IL=1,ILGA
          IRGST=IRGL(IL)
          IF ( IRGST /= IDEF .AND. IR <= IRSL(IL) ) THEN
            IRDST=IRDSL(IL)
            IBSTT=IBSL(IL)
            ID=IDPD(IRGST,IRDST,IBSTT,IR)
            XPS(IL,L,IS,IR)=XPPNT(ID)+BSPL(IL)*XPDER(ID)
            TPS(IL,L,IS,IR)=TPPNT(ID)+BSPL(IL)*TPDER(ID)
          ENDIF
        ENDDO
        ENDDO
!
!       * SAVE FLAG TO INDICATE WHETHER THE UPPER BOUNDARY OF THE
!       * DOMAIN IS OPEN TO FURTHER PARTICLE GROWTH.
!
        DO IL=1,ILGA
          IRGST=IRGL(IL)
          IF ( IRGST /= IDEF ) THEN
            IRDST=IRDSL(IL)
            IBSTT=IBSL(IL)
            KOP(IL,L,IS)=RGPN(IRGST)%KOPEN(IBSTT,IRDST)
          ENDIF
        ENDDO
!
!       * MAKE SURE PARTICLE SIZE IS NOT SMALLER THAN SMALLEST PARTICLE
!       * SIZE ACCORDING TO THE GROWTH DATA. THIS COULD HAPPEN BECAUSE
!       * OF TRUNCATION ERRORS.
!
        DO IL=1,ILGA
          IRST=IRSL(IL)
          IF ( IRST > 0 ) THEN
            XP(IL,L,IS)=MAX(XP(IL,L,IS),XPS(IL,L,IS,1))
          ENDIF
        ENDDO
      ENDDO
      ENDDO
!
!-----------------------------------------------------------------------
!     * DEALLOCATE TEMPORARY ARRAYS.
!
      DEALLOCATE(IRDSL)
      DEALLOCATE(IRGL)
      DEALLOCATE(BSPL)
      DEALLOCATE(IBSL)
      DEALLOCATE(IRSL)
!
      END SUBROUTINE CNEXTR
