【问题标题】:Best way to parse a file (LAS) with differents parts?解析具有不同部分的文件(LAS)的最佳方法?
【发布时间】:2015-05-27 12:52:00
【问题描述】:

我期待解析 LAS 文件(Log ASCII 标准),这种类型的文件具有不同的部分,具有不同的语法,示例如下:

"file.las"
~V
VERS  .   3.00    : Comments
DLM   .   COMMA
~Curve
RHOB.M
~Data
1000.5,  35.2
1001.0,  40.6

这是我目前解析文件的方法,我为每种语法使用不同的 for 循环。

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
}

解析工作正常,我发现其他开发人员很容易理解(这是一件好事)。

有没有更好的方法来解析一个文件,包含具有不同语法的不同部分,然后是我的一系列 For 循环?

编辑:

我已经看到了 while 循环方式,但我不知道如何实现它:

while ( (line = bufRead.readLine()) != null)
{    
    
}

... 在不同位置使用不同语法的文件,而无需添加大量条件。有了 for 循环列表,我不需要为每一行检查很多条件。

【问题讨论】:

  • 如果您不赞成,请告诉我原因,如果没有建议,我将无法改进。我仍在寻找用不同部分解析文件的最佳方法。谢谢
  • 你让它工作了吗?我也在尝试使用 Java 读取 LAS 文件

标签: java file parsing log-ascii-standard


【解决方案1】:

你有这个项目可以帮助你解析 LAS 文件

http://www.jwitsml.org/dlis.html

这是一个使用这个库的例子:

 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)
 }

【讨论】:

  • 您好,该项目不公开,无法下载。此外,它没有回答我关于解析具有不同部分的文件的最佳方法的问题。
  • 该项目是开源的,您可以下载。 jwitsml.org/download.html
  • jwitsml-1.1.jar 不包含“logio.jar”或此处jwitsml.org/dlis/javadoc/index.html 中的任何类,其中包含 LAS 部分。我在哪里可以下载 logio.jar ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-08
  • 1970-01-01
  • 2010-09-06
  • 2011-01-28
  • 1970-01-01
  • 2012-10-12
  • 2010-09-06
相关资源
最近更新 更多