0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Gaëtan Rouziès
  • 490
  • 1
  • 3
  • 16

1 Answers1

-1

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)
 }
  • Hi, this project is not public, and you can't download it. Moreover it doesn't answer my question about the best way to parse a file with different part. – Gaëtan Rouziès Apr 02 '15 at 19:02
  • The project is open source and you can download it. http://www.jwitsml.org/download.html – Pablo Gallego Falcón Apr 02 '15 at 19:21
  • 1
    jwitsml-1.1.jar doesn't contain the "logio.jar" or any class from here http://www.jwitsml.org/dlis/javadoc/index.html, which contains the LAS Part. Where can i download logio.jar ? – Gaëtan Rouziès Apr 02 '15 at 20:48