Reputation: 530
I'm looking forward to parsing a LAS file (Log ASCII Standard), this type of file has different parts with different syntax's, example here:
"file.las"
~V
VERS . 3.00 : Comments
DLM . COMMA
~Curve
RHOB.M
~Data
1000.5, 35.2
1001.0, 40.6
Here's what I'm currently doing to parse my file, I'm using different for loop for each Syntax.
BufferedReader file = new BufferedReader(new FileReader(path));
System.out.print("Searching ~V");
for (String line = file.readLine(); line != null; line = file.readLine()) {
if(line.contains("~V")){
System.out.println("Success");
break;
}else{
//Do Nothing
}
}
System.out.print("Searching VERS");
for (String line = file.readLine(); line != null; line = file.readLine()) {
line = line.trim();
if(line.startsWith("VERS.")){
line = line.replaceAll(" ", "");
String lineWithoutComment = line.split(":")[0];
lasFileVO.setVersion(lineWithoutComment);
break;
}else{
//Do Nothing
}
}
if(lasFileVO.getVersion.startWith("3.0")){
System.out.print("Searching DLM");
//For loop
}
The parsing is working, and I find it very easy to understand for the other developers (which is a good thing).
Is there a better way to parse a file, containing different parts with different syntax, then my series of For Loops?
EDIT:
I already saw the while loop way, but I don't see how I could implement that:
while ( (line = bufRead.readLine()) != null)
{
}
... with a file with different syntaxes at different places without adding a tons of conditions. With a list of for loop, I don't need to check a lot of condition for each line.
Upvotes: 0
Views: 1977
Reputation: 938
You have this project that can help you in parsing LAS files
http://www.jwitsml.org/dlis.html
This is an example using this library:
File file = new File("data.las");
// Instantiate a reader and read the LAS file
LasFileReader reader = LasFileReader(file);
LasFile lasFile = reader.readFile();
// Loop over all curves
for (LasCurve curve : lasFile.getCurves()) {
System.out.println("Curve name..: " + curve.getName());
System.out.println("Description.: " + curve.getDescription());
System.out.println("Unit........: " + curve.getUnit());
System.out.println("value type..: " + curve.getValueType());
// The curve values are accessed by curve.getValue(index)
}
Upvotes: -1