FortranLineReaderpublic 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. |
Fields Summary |
---|
public static final char | COMMENT_CHAR | protected boolean | hitEOFEOF flag, needed since we use super.readLine() several places | protected String | statementNumThe 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 int | getLineNumber()Line number of first line in current (possibly continued) line
return firstLineNumber;
| public int | getStatementNumber()Return the statement number of the current logical line.
return Integer.parseInt(statementNum.trim());
| public boolean | hasStatementNumber()Returns true if the current logical line contains a statement #
return statementNum != null &&
statementNum.trim().length() > 0;
| public static void | main(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.String | readLine()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();
|
|