    	SUBROUTINE COMMAS( TEXT, NK, NF, GF, KF, NLS )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY
C		NOV-1986
C
C	THIS ROUTINE IMPLEMENTS A FREE FORMAT INPUT PROCESSOR.
C
C	TEXT --- INPUT TEXTSTRING IN CHARACTER FORMAT TO BE DECODED.
C	NK ----- SIZE OF THE "TEXT" IN NUMBER OF CHARACTERS.
C	NF ----- NUMBER OF REAL*4 DECIMALS TO BE DECODED FROM THE "TEXT".
C	GF ----- REAL*4 ARRAY TO STORE THE DECODED DECIMALS.
C	KF ----- INTEGER ARRAY TO FLAG WHICH ELEMENT OF THE "GF"
C	         ARRAY GETS AN INPUT: 0=NO, 1=YES.
C	NLS ---- THE POSITION OF THE LAST CHARACTER IN THE "TEXT" 
C	         THAT DOESN'T GET DECODED. IN OTHER WORDS, IT FLAGS
C	         HOW MANY CHARACTERS HAVE BEEN USED, COUNTED FROM
C	         THE LEFT TO RIGHT IN THE "TEXT", TO DECODE THE "NF" 
C	         REAL*4 DECIMALS.
C
C	COMMENTS:
C
C	THE FIELD SEPARATOR CAN BE EITHER A SPACE OR SPACES OR COMMA.
C	TO SKIP A FIELD, YOU HAVE TO USE THE COMMAS AND THE INPUT 
C	PROCESSOR RETURNS WITH ITS "KF" = 0.
C
C	INTEGER FIELDS ARE DECODED AND STORED IN THE "GF" AS DECIMAL 
C	NUMBERS. THEREFORE DECIMAL NUMBERS CAN BE ENTERED AS INTEGERS
C	AND VICE VERSA.
C
C	AN ERROR RESULTS IF THE INPUT PROCESSOR ENCOUNTERS TRAILING
C	TEXT CHARACTERS IN THE "TEXT" BEFORE THE "NF"TH DATA FIELD 
C	GOT DECODED FROM THE "TEXT" AND IT RETURNS WITH "NK" = 0.
C	THEREFORE THE VALUE OF "NK" MUST BE PASSED BY AN ARGUMENT
C	INSTEAD OF THE ACTUAL NUMBER AND THEREFORE THE CALLING ROUTINE 
C	SHOULD ALWAYS CHECK THE RETURNED "NK" FOR POSSIBLE ERROR INPUT.
C	IF THERE IS NO TRAILING TEXT CHARACTERS IN THE "TEXT", THE
C	"TEXT" CAN HAVE FEWER THAN "NF" NUMBER OF DATA FIELDS AND
C	THE REST OF "GF" ARE FILLED WITH VALUES 0.0s AND THEIR "KF"s
C	WITH 0s.
C
    	REAL*4 GF(NF)
    	CHARACTER SYM*1, BEL*1, STRN*40, TEXT(NK)*1
    	DIMENSION KF(NF), NCS(50), NSP(50)

    	NFS = NF
    	DO I=1, NFS
    	   KF(I) = 0
    	   GF(I) = 0.0
    	ENDDO
    	NLS = 0
    	NCH = NK
    	IF( NCH.EQ.0 ) GOTO 999
    	JMS = 1
    	NCS(JMS) = 0
    	NSP(JMS) = 0
    	BEL = ','
    	ICI = 0

    	DO 9 I=1, NCH
    	SYM = TEXT(I)
    	IF( SYM.NE.',' ) GOTO 1
    	    IF( BEL.NE.' ' .OR. ICI.EQ.0 ) THEN
    	        JMS = JMS + 1
    		IF( ICI.EQ.0 ) THEN
    		    NSP(JMS) = I - NCS(JMS-1)
    		ELSE
    		    NSP(JMS) = 0
    		ENDIF
    	    ELSE
    	        NSP(JMS) = I - NCS(JMS)
    	    ENDIF
    	    NCS(JMS) = I
    	    NLS = I + 1
    	    ICI = 0
    	GOTO 6
1	IF( SYM.NE.' ' .OR. BEL.EQ.' ' .OR. BEL.EQ.',' ) GOTO 5
    	    JMS = JMS + 1
    	    NCS(JMS) = I
    	    NSP(JMS) = 0
    	GOTO 8
5	IF( SYM.EQ.' ' ) GOTO 8
    	NLS = I
6	IF( JMS.GT.NFS ) GOTO 10
8	BEL = SYM
    	IF( SYM.NE.' ' .AND. SYM.NE.',' ) ICI = 1
9	CONTINUE

    	NLS = I
    	JMS = JMS + 1
    	NCS(JMS) = I
    	NSP(JMS) = 0

10	DO I=1,JMS-1
    	   I1 = NCS(I) + 1
    	   I2 = NCS(I+1) - 1 - NSP(I+1)
    	   NCH = I2 - I1 + 1
     	   IF( NCH.GT.40 ) GOTO 888
    	   IF( NCH.GT.0 ) THEN
     	       NCH = 0
     	       DO J=I1,I2
     		  NCH = NCH + 1
    	          STRN(NCH:NCH) = TEXT(J)
     	       ENDDO
    	       IDOT = INDEX( STRN(1:NCH), '.' )
    	       IF( IDOT.EQ.0 ) THEN
    		   NCH = NCH + 1
    		   STRN(NCH:NCH) = '.'
    	       ENDIF
    	       DECODE( NCH, 20, STRN, ERR=888 ) GF(I)
    	       KF(I) = 1
    	   ENDIF
    	ENDDO
20	FORMAT(G40.30)
    	GOTO 999
888	NK = 0
999	RETURN
    	END
