FileDocCategorySizeDatePackage
FortranLineReader.javaAPI DocExample2977Sat Nov 25 12:55:28 GMT 2000None

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, ian@darwinsys.com
version
$Id: FortranLineReader.java,v 1.2 2000/11/25 17:55:29 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
protected static String
sampleTxt
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 static voidmain(java.lang.String[] argv)


	       
		FortranLineReader is = new FortranLineReader(
			new StringReader(sampleTxt));
		String aLine;
		while ((aLine = is.readLine()) != null) {
			if (is.hasStatementNumber())
				System.out.println("\tStatement number: " +
					is.getStatementNumber());
			System.out.println(is.getLineNumber() + ": " + aLine);
		}
		is.close();
	
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();