FileDocCategorySizeDatePackage
FortranLineReader.javaAPI DocExample2405Sun Feb 29 19:42:20 GMT 2004None

FortranLineReader

public class FortranLineReader extends ContLineReader
Subclass of LineNumberReader to read Fortran-style lines. Fortran statements, as well as I can remember them, are like: NNNNNXDDDDDDDDDDDDDDDDDD C........................... where NNNNN is a 1-5 digit statement number, or spaces X is a continuation character, which must be in column 6 DDD is executable statement ... is commentary.
author
Ian Darwin, http://www.darwinsys.com/
version
$Id: FortranLineReader.java,v 1.4 2004/03/01 01:42:20 ian Exp $

Fields Summary
public static final char
COMMENT_CHAR
protected boolean
hitEOF
EOF flag, needed since we use super.readLine() several places
protected String
statementNum
The statement number portion
Constructors Summary
public FortranLineReader(Reader in)
Construct a FortranLineReader with the default input-buffer size.

		super(in);
	
public FortranLineReader(Reader in, int sz)
Construct a FortranLineReader using the given input-buffer size.

		super(in, sz);
	
Methods Summary
public intgetLineNumber()
Line number of first line in current (possibly continued) line


	           
	   
		return firstLineNumber;
	
public intgetStatementNumber()
Return the statement number of the current logical line.

		return Integer.parseInt(statementNum.trim());
	
public booleanhasStatementNumber()
Returns true if the current logical line contains a statement #

		return	statementNum != null &&
			statementNum.trim().length() > 0;
	
public java.lang.StringreadLine()
Read one (possibly continued) line, save its text (columns 6-71) in the StringBuffer, its statement number in statementNum, and its line number in firstLineNumber.


	                        	 
	     
		// Read the first line. 
		String s = readPhysicalLine();
		if (s == null)
			hitEOF = true;
		if (hitEOF)
			return null;
		if (s.charAt(0) == COMMENT_CHAR) {
			statementNum = null;
			return s;
		}

		statementNum = s.substring(0,5);
		StringBuffer sb = new StringBuffer(s.substring(6));
		firstLineNumber = super.getLineNumber();

		// Now read as many continued lines as there are.
		while (s.charAt(5) != ' ") {
			s = readPhysicalLine();
			if (s == null) {
				hitEOF = true;
				return sb.toString();	// Gak! EOF within continued line
			}
			// add rest of line.
			sb.append(' ").append(s.substring(6));
		}
		return sb.toString();