      SUBROUTINE NDIGIT(NDIG,NDEC,VAL,UNIT)     
C     
C     THIS ROUTINE USES THE TICK MARK UNIT TO DETERMINE     
C     HOW MANY DECIMAL DIGITS TO PLOT USING NUMBER TOGETHER 
C     WITH HOW MANY PLACES TO THE RIGHT OF THE DECIMAL POINT
C     THERE ARE.  
C     
      CHARACTER NUMBER*20     
      DATA OLDUNT/0.0/,NDCOLD/0/,OLDVAL/0.0/
      ABSVAL=ABS(VAL)   
      NDIG=0
    1 NDIG=NDIG+1 
      IF(ABSVAL.GE.10.0**NDIG)GO TO 1     
      IF(VAL.LT.0.0)NDIG=NDIG+1     
      IF(ABS(UNIT).LT.0.0001)THEN   
        NDEC=6    
        RETURN    
      END IF
      IF(UNIT.EQ.OLDUNT.AND.VAL.EQ.OLDVAL)THEN  
        NDEC=NDCOLD     
        RETURN    
      END IF
      WRITE(NUMBER,'(F20.4)')UNIT   
C     
C     NOW SCAN BACKWARDS FOR TRAILING ZEROES    
C     
      NDEC=4
      DO 2 J=20,18,-1   
        IF(NUMBER(J:J).NE.'0')GO TO 3     
        NDEC=NDEC-1     
    2 CONTINUE    
    3 WRITE(NUMBER,'(F20.4)')VAL    
C     
C     NOW DO THE SAME THING WITH VAL AND THE TRAILING ZEROES
C     
      NDEC1=4     
      DO 4 J=20,18,-1   
        IF(NUMBER(J:J).NE.'0')GO TO 5     
        NDEC1=NDEC1-1   
    4 CONTINUE    
C     
C     CHOOSE THE BIGGER OF NDEC AND NDEC1 
C     
    5 NDEC=MAX0(NDEC,NDEC1)   
      NDCOLD=NDEC 
      OLDUNT=UNIT 
      OLDVAL=VAL
      RETURN
      END   
