      SUBROUTINE TRAD(XX,CC,NC,XMIN,XMAX)
C
C Traduit le reel xx en une chaine de caractere cc de longueur nc
C
      REAL*8 X,XX,XRAP,XNLIM
cc     &      ,XNLIM2
      CHARACTER*1 C(20),CC(20),CHIFR(10)
      PARAMETER ( NCMAX=7 , XNLIM = 10.**(1+NCMAX) )
cc      PARAMETER ( XNLIM2 = 10.**(-1-NCMAX) )
CC attention pas bon    PARAMETER ( NCMAX=7 , NLIM = 1+10**(NCMAX+1) )
      PARAMETER ( XRAP = 1.D-06 ) 
      DATA CHIFR / '0','1','2','3','4','5','6','7','8','9' /
C
      DO 1 I=1,20
        C(I) = ' '
        CC(I) = ' '
 1    CONTINUE
      NLIM=NINT(XNLIM)
C
      X = DABS(XX)
      IF (X.GT.1.D-30) THEN
        IF ( (X/DBLE(XMAX-XMIN)).LT.XRAP ) THEN
          CC(1) = '0'
          NC = 1
          GOTO 1000
        ENDIF
      ELSE
        CC(1) = '0'
        NC = 1
        GOTO 1000
      ENDIF
C
      ISHIFT = 0
      NN=0
      IF (X.LT.XNLIM) THEN
        NN=0
 100    IF (DNINT(X).LT.NLIM) THEN
          NN = NN+1
          X  = X*10.D0
          GOTO 100
        ENDIF
        NX = DNINT(X)
        DO 20 NC = 1,NCMAX+2
          NPUIS = 10**(NCMAX+2-NC)
          NUM = NX/NPUIS
          C(NC) = CHIFR(NUM+1)
          NX = MOD(NX,NPUIS)
   20   CONTINUE
      ELSE
  101   ISHIFT = ISHIFT+1
        X = X/XNLIM
        IF (X.LT.XNLIM) THEN
          GOTO 100
        ELSE
          GOTO 101
        ENDIF
      ENDIF
C
      NN = -NN + (NCMAX+1)*(1+ISHIFT)
      IF (XX.LT.0.) THEN
        CC(1) = '-'
      ELSE
        CC(1) = ' '
      ENDIF
      IF (NN.GE.0) THEN
        DO 30 I=1,NN+1
          CC(I+1) = C(I)
   30   CONTINUE
        NVIRG = NN+3
        CC(NVIRG) = '.'
        DO 40 I=NN+2,NCMAX+2
          CC(I+2) = C(I)
   40   CONTINUE
      ELSE
C       CC(2) = '.'
C       NVIRG = 2
         CC(2) = '0'
         CC(3) = '.'
         NVIRG = 3
        IF (NN.LT.-1) THEN
          DO 50 I=1,-1-NN
            CC(I+NVIRG) = '0'
   50     CONTINUE
        ENDIF
        J=1
        DO 60 I=-NN,NCMAX+2
          CC(I+NVIRG) = C(J)
          J=J+1
   60   CONTINUE
      ENDIF
C
      NC = 21
  200 NC = NC-1
      IF (CC(NC).EQ.'0' .OR. CC(NC).EQ.' ') GOTO 200
      IF (CC(NC).EQ.'.') NC=NC-1
      IF (CC(1).EQ.' ') THEN
        NC = NC-1
        DO 210 I=1,NC
          CC(I) = CC(I+1)
  210   CONTINUE
      ENDIF
      DO 211 I=NC+1,20
        CC(I) = ' '
  211 CONTINUE
C
 1000 END
C----------------------------------------------------------------------
      SUBROUTINE TRAD2(CC,NC,NC2)
      CHARACTER*1  CC(20),CBID1
      CHARACTER*2  CBID2
      CHARACTER*20 C
C
      IF (CC(1).EQ.'-') THEN
        ISIGN = -1
        NC = NC-1
        DO I=1,NC
          CC(I) = CC(I+1)
        ENDDO
      ELSE
        ISIGN = 1
      ENDIF
C
      IF (CC(2).NE.'.') THEN
        NN = NC+1
   10   NN = NN-1
        IF (CC(NN).EQ.'0'.OR.CC(NN).EQ.' ') GOTO 10
        C(1:1)=CC(1)
        C(2:2)='.'
        IF (NN.GT.1) THEN
          DO I=2,NN
            C(I+1:I+1) = CC(I)
          ENDDO
        ENDIF
        C(NN+2:NN+4) = ' 10'
        NNN = NN+5
        IF ((NC-1).LE.9) THEN
C          ENCODE(1,'(I1)',CBID1) NC-1
          WRITE(CBID1,'(I1)') NC-1
          C(NNN:NNN) = CBID1 
          NC2 = 1
        ELSE
C          ENCODE(2,'(I2)',CBID2) NC-1
          WRITE(CBID2,'(I2)') NC-1
          C(NNN:NNN+1) = CBID2
          NC2 = 2
        ENDIF
        NC = NN+4
      ELSE
        NN = 2
   20   NN = NN+1
        IF (CC(NN).EQ.'0') GOTO 20
        C(1:1) = CC(NN)
        C(2:2)='.'
        IF (NN.LT.NC) THEN
          DO I=NN+1,NC
            C(I-NN+2:I-NN+2) = CC(I)
          ENDDO
        ENDIF
        NC = NC-NN+5 
        C(NC-2:NC+1) = ' 10-'
        NNN = NC+2
        IF ((NN-2).LE.9) THEN
C          ENCODE(1,'(I1)',CBID1) NN-2
          WRITE(CBID1,'(I1)') NN-2
          C(NNN:NNN) = CBID1 
          NC2 = 2
        ELSE
C          ENCODE(2,'(I2)',CBID2) NN-2
          WRITE(CBID2,'(I2)') NN-2
          C(NNN:NNN+1) = CBID2
          NC2 = 3
        ENDIF
      ENDIF
C
      IF (ISIGN.EQ.1) THEN
        DO I=1,NC+NC2
          CC(I) = C(I:I)
        ENDDO
      ELSE
        CC(1) = '-'
        DO I=1,NC+NC2
          CC(I+1) = C(I:I)
        ENDDO
        NC = NC+1
      ENDIF
C
      END
