    	FUNCTION NALPHA( TEXT, MAX )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY,  MAY-1987
C
C	THIS ROUTINE RETURNS WITH THE LENGTH OF CHARACTER STRING "TEXT"
C	IN NALPHA. IF MAX.LT.0, "TEXT" IS CONVERTED TO UPPERCASES.
C	EMBEDED NON-DISPLAYED CHARACTERS ARE STRIPPED EXCEPT TAB KEY
C	WHICH IS REPLACED BY A NUMBER OF BLANK SPACES.
C
     	COMMON/NALPHA/ NTABS
    	CHARACTER TNEW(132)*1, TEXT(1)*1

    	N = IABS(MAX)
C
C  SEARCH THE LAST NON-BLANK CHARACTER...
C
	DO IK = N, 1, -1
    	   IF( TEXT(IK).NE.' ' ) GO TO 1
    	ENDDO
	IK = 0
    	GOTO 9
C
C  STRIP "TEXT" OF NON-DISPLAYED CHARACTERS...
C
1	K = 0
     	IF( NTABS.EQ.0 ) NTABS = 5
     	DO J=1, IK
     	   N = ICHAR(TEXT(J))
     	   IF( N.LT.32 ) THEN
     	       IF( N.EQ.9 ) THEN	!TAB KEY
     		   DO I=1, NTABS
     		      K = K + 1
     		      TNEW(K) = ' '
     		   ENDDO
     	       ENDIF
     	   ELSE
     	       K = K + 1
     	       TNEW(K) = TEXT(J)
     	   ENDIF
     	ENDDO
     	IK = K
     	DO J=1, IK
     	   TEXT(J) = TNEW(J)
     	ENDDO
     	IF( MAX.GT.0 ) GOTO 9
C
C  CONVERT TO UPPERCASE CHARACTERS...
C
    	DO J=1, IK
    	   N = ICHAR(TEXT(J))
    	   IF( N.GT.96 .AND. N.LT.123 ) N = N - 32
    	   TEXT(J) = CHAR(N)
    	ENDDO

9	NALPHA = IK
    	RETURN
	END
