      SUBROUTINE ARONDI(XMIN,XMAX,XX,LXX,NDX,ILOGX,NTMAX,IARON,NDXMIN)

      PARAMETER (NPUIMAXI=20)
      REAL*8 X,DX,LOGDX,XX(*),PUIS(-NPUIMAXI:NPUIMAXI),XMIN2,XMAX2
      REAL*8 ECHEL
      LOGICAL*4 LXX(*),TRUE,FALSE
C
C Determination de l'echelle a afficher en fonction des bornes
C
      TRUE  = .TRUE.
      FALSE = .FALSE.
      DO I=-NPUIMAXI,NPUIMAXI
        PUIS(I) = 10.D0**I
      ENDDO
      DX = DBLE(XMAX-XMIN)
      LOGDX = DLOG10(DX)
      MANT = INT(LOGDX)
      IF (LOGDX.LT.0.) MANT = MANT-1
C
      NDX = 0
      XMIN2 = XMIN - .5D0*DX
      XMAX2 = XMAX + .5D0*DX
      N0 = DNINT(XMIN2*PUIS(-MANT))
      N1 = DNINT(XMAX2*PUIS(-MANT))
      ECHEL = PUIS(MANT)
      XMIN2 = ECHEL*DBLE(N0)
      XMAX2 = ECHEL*DBLE(N1)
      IF (ILOGX.GE.0) THEN
        DO I=N0,N1-1
          X = DBLE(I)*ECHEL
          CALL LETEST(X,XMIN2,XMAX2,XX,LXX,NDX,TRUE)
          DO J=1,4
            X = (DBLE(I) + 0.2D0*DBLE(J))*ECHEL
            CALL LETEST(X,XMIN2,XMAX2,XX,LXX,NDX,FALSE)
          ENDDO
        ENDDO
        CALL LETEST(XMAX2,XMIN2,XMAX2,XX,LXX,NDX,TRUE)
C
        IF (NDX.LT.NDXMIN) THEN
          DO I=N0,N1-1
            DO J=1,9,2
              X = (DBLE(I) + 0.1D0*DBLE(J))*ECHEL
              IF (J.NE.5) THEN
                CALL LETEST(X,XMIN2,XMAX2,XX,LXX,NDX,FALSE)
              ELSE
                CALL LETEST(X,XMIN2,XMAX2,XX,LXX,NDX,TRUE)
              ENDIF
            ENDDO
          ENDDO
        ENDIF
C
        DIFMAX = 1000.D0*DX
        DIFMIN = 1000.D0*DX
        EPSEPS = (XMAX-XMIN)*1.E-5
C       XMIN3=XMIN+1.D-6*ABS(XMIN)
C       XMAX3=XMAX-1.D-6*ABS(XMAX)
        NMIN = 0
        NMAX = 0
        DO I=1,NDX
          IF (ABS(REAL(XX(I))-XMIN).LT.EPSEPS) NMIN = I
          IF (ABS(REAL(XX(I))-XMAX).LT.EPSEPS) NMAX = I
        ENDDO
        IF (NMIN.EQ.0) THEN
          DO I=1,NDX
            IF ((XMIN-XX(I)).LT.DIFMIN.AND.XX(I).LE.XMIN) THEN
              DIFMIN = XMIN-XX(I)
              NMIN = I
            ENDIF
          ENDDO
          IF (IARON.EQ.0) XMIN = XX(NMIN)
        ENDIF
        IF (NMAX.EQ.0) THEN
          DO I=1,NDX
            IF ((XX(I)-XMAX).LT.DIFMAX.AND.XX(I).GE.XMAX) THEN
              DIFMAX = XX(I)-XMAX
              NMAX = I
            ENDIF
          ENDDO
          IF (IARON.EQ.0) XMAX = XX(NMAX)
        ENDIF
      ELSE
        NXMIN2 = INT(XMIN2)
        NXMAX2 = INT(XMAX2)+1
C
C Partie entiere des nombres negatifs, bizarre en fortran
C
        IF (INT(-0.5).NE.-1) THEN
          IF (XMIN2.LT.0.) NXMIN2 = NXMIN2-1
          IF (XMAX2.LT.0.) NXMAX2 = NXMAX2-1
        ENDIF
        NDX = MAX(1,NXMAX2-NXMIN2+1)
        NMIN = 0
        NMAX = 0
        NDX2 = MAX(1,NINT(XMAX-XMIN))
        IF (NDX2.GT.15) THEN
          IF (NDX2.GT.NDXMIN) THEN
            NNMOD = 10
          ELSE
            NNMOD = 5
          ENDIF
        ELSE
          NNMOD = 1
        ENDIF
        DO I=1,NDX
          XX(I) = DBLE(NXMIN2 + I-1)
          IF (MOD(NINT(XX(I)),NNMOD).EQ.0) THEN
            LXX(I) = .TRUE.
          ELSE
            LXX(I) = .FALSE.
          ENDIF
        ENDDO
        IF (NNMOD.EQ.1) CALL INTERLOG(XX,LXX,NDX)
        DO I=1,NDX
          IF (XX(I).LE.XMIN) NMIN = I
          IF (XX(I).GT.XMAX) THEN
            IF (NMAX.EQ.0) THEN
              NMAX = I
              XMAMA = XX(I)
            ELSEIF (XX(I).LT.XMAMA) THEN
              NMAX = I
              XMAMA = XX(I)
            ENDIF
          ENDIF
        ENDDO
        IF (IARON.EQ.0) THEN
          NMIN = MAX(NMIN,1)
          NMAX = MIN(NMAX,NDX)
          XMIN = XX(NMIN)
          XMAX = XX(NMAX)
        ENDIF
      ENDIF
      IF (NDX.GT.NTMAX) THEN
        PRINT*,'BUGBUG',NDX,NTMAX
        STOP
      ENDIF
C
      END
C---------------------------------------------------------------------
      SUBROUTINE LETEST(X,XMIN,XMAX,XX,LXX,NDX,LOGIC)
      REAL*8 X,XX(*),XMIN,XMAX
      LOGICAL*4 LXX(*),LOGIC
C BIDON ...
      IF (X.GE.XMIN.AND.X.LE.XMAX) THEN
        NDX = NDX+1
        XX(NDX)  = X
        LXX(NDX) = LOGIC
      ENDIF
      END
