tags:

views:

102

answers:

1

Are there any Open Source Java tools for parsing FORTRAN output? I'd like to be able to write something like

Format format = new Format("(1x, 2(F10.3,I3,' XY ',F7.3))");
String s = " -12345.897    XY 123.456-12345.897*** XY 123.456";
Result result = format.parse(s);   

Note that it's specifically FORTRAN. Note the fun things like concatenated fields, overflows, blank space=0, etc. There are so many gotchas that I don't want to rediscover them myself!

COMMENT. I don't see why this is a wrong way to go. The format is a concise way of generating the reading code. The alternative would be to hardcode a reader for each format. If I have a file with - say 100 different FORMAT outputs then I have to 100 chunks of code. With the iChemLabs approach I write:

List<Object> fields = FortranFormat.read(s, format);

and get back Double Integer String Double Double Integer String Double

UPDATE: I have tested the iChemLabs on a reasonable number of things. With blanks it returns null Integers and Doubles. With * it thows an exception (not unreasonable). It can manage multiple lines

fields = FortranFormat.read("   1\n    2", "(I4/I4)");

returns 2 Integers (1 and 2)

UPDATE: The iChemLabs code specifically allows for blank input (but not asterisks):

public void setReturnZeroForBlanks(boolean returnZeroForBlanks)

    Set whether zeros are returned for blanks.

    Parameters:
        returnZeroForBlanks - the return zero for blanks
+3  A: 

This seems to do it (both output and input). Last updated 1998!

Another one here - looks a bit more polished? from iChemLabs

Paul
Great - exactly what was wanted.
peter.murray.rust
I've chosen the second (especially since it's chemical) but public thanks to Jocelyn Paine for the first. I hope to mavenize the iChemLabs one (the second)
peter.murray.rust
The iChemLabs use a BNF to generate the code using JavaCC. The only drawback is that they don't publish the BNF. So if there is a bug it's impossible to fix. I shall write to them.
peter.murray.rust