From c43c9494a12c894162206b473a44855e6247d250 Mon Sep 17 00:00:00 2001 From: ZZHow <109335896+ZZHow1024@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:59:30 +0800 Subject: [PATCH 1/6] refactor: restructure part of the codebase --- src/Main.java | 8 +- .../entity/{DataBody.java => DataTrace.java} | 7 +- src/pojo/entity/SEGY.java | 14 +- src/util/SEGYUtils.java | 239 ++++++++++-------- 4 files changed, 144 insertions(+), 124 deletions(-) rename src/pojo/entity/{DataBody.java => DataTrace.java} (99%) diff --git a/src/Main.java b/src/Main.java index 31b57af..9e7f66f 100644 --- a/src/Main.java +++ b/src/Main.java @@ -17,8 +17,8 @@ public static void main(String[] args) { System.out.println("ZSEGY 1.0.0"); System.out.println("Author: ZZHow"); + // 命令模式 if (args.length != 0) { - switch (args[0]) { case "-head", "head" -> { System.out.println("正在解析中..."); @@ -35,7 +35,7 @@ public static void main(String[] args) { } segy = SEGYUtils.parseSEGY(args[2]); System.out.println("\n@@@第 " + num + " 个数据道@@@"); - System.out.println(segy.getDataBodies().get(num)); + System.out.println(segy.getDataBody().get(num)); System.exit(0); } case "-all", "all" -> { @@ -49,7 +49,7 @@ public static void main(String[] args) { segy = SEGYUtils.parseSEGY(args[2]); System.out.println(segy.getFileHeader()); System.out.println("\n@@@第 " + num + " 个数据道@@@"); - System.out.println(segy.getDataBodies().get(num)); + System.out.println(segy.getDataBody().get(num)); System.exit(0); } case "-i", "i" -> { @@ -111,7 +111,7 @@ public static void main(String[] args) { case "2" -> { System.out.print("数据道数:"); long num = scanner.nextLong(); - System.out.println(segy.getDataBodies().get(num)); + System.out.println(segy.getDataBody().get(num)); } case "3" -> { System.out.println("程序退出..."); diff --git a/src/pojo/entity/DataBody.java b/src/pojo/entity/DataTrace.java similarity index 99% rename from src/pojo/entity/DataBody.java rename to src/pojo/entity/DataTrace.java index c3b5a16..45d0aec 100644 --- a/src/pojo/entity/DataBody.java +++ b/src/pojo/entity/DataTrace.java @@ -6,8 +6,8 @@ * @author ZZHow * @date 2024/11/25 */ -public class DataBody { - /* 数据体第一部分——道头 */ +public class DataTrace { + /* 数据道第一部分——道头 */ // 1-4:测线中道顺序号 private Integer traceSequenceNumberWithinLine; // 5-8:SEG Y文件中道顺序号 @@ -183,9 +183,10 @@ public class DataBody { // 233-240:未赋值――为任选信息预留 /**/ + /* 数据道第二部分——采样数据 */ private float[] samplingData; - public DataBody() { + public DataTrace() { } public Integer getTraceSequenceNumberWithinLine() { diff --git a/src/pojo/entity/SEGY.java b/src/pojo/entity/SEGY.java index 06cab27..143d232 100644 --- a/src/pojo/entity/SEGY.java +++ b/src/pojo/entity/SEGY.java @@ -10,29 +10,29 @@ public class SEGY { // 文件头 private FileHeader fileHeader; // 数据体 - private Map dataBodies; + private Map dataBody; public SEGY() { } - public SEGY(FileHeader fileHeader, Map dataBodies) { + public SEGY(FileHeader fileHeader, Map dataBody) { this.fileHeader = fileHeader; - this.dataBodies = dataBodies; + this.dataBody = dataBody; } public FileHeader getFileHeader() { return fileHeader; } - public Map getDataBodies() { - return dataBodies; + public Map getDataBody() { + return dataBody; } public void setFileHeader(FileHeader fileHeader) { this.fileHeader = fileHeader; } - public void setDataBodies(Map dataBodies) { - this.dataBodies = dataBodies; + public void setDataBody(Map dataBody) { + this.dataBody = dataBody; } } diff --git a/src/util/SEGYUtils.java b/src/util/SEGYUtils.java index a7d364e..325caf7 100644 --- a/src/util/SEGYUtils.java +++ b/src/util/SEGYUtils.java @@ -1,6 +1,6 @@ package util; -import pojo.entity.DataBody; +import pojo.entity.DataTrace; import pojo.entity.FileHeader; import pojo.entity.SEGY; @@ -16,6 +16,22 @@ */ public class SEGYUtils { + /** + * 解析 SEG-Y 文件 + * + * @param file SEG-Y 文件 + * @return SEGY + */ + public static SEGY parseSEGY(File file) { + return parseSEGY(file.getAbsolutePath()); + } + + /** + * 解析 SEG-Y 文件 + * + * @param filePath SEG-Y 文件路径 + * @return SEGY + */ public static SEGY parseSEGY(String filePath) { SEGY segy = new SEGY(); @@ -23,9 +39,9 @@ public static SEGY parseSEGY(String filePath) { long start = System.currentTimeMillis(); FileHeader fileHeader = SEGYUtils.parseFileHeader(filePath); segy.setFileHeader(fileHeader); - Map longDataBodyMap = null; + Map longDataBodyMap = null; longDataBodyMap = SEGYUtils.parseDataBody(filePath, fileHeader, false); - segy.setDataBodies(longDataBodyMap); + segy.setDataBody(longDataBodyMap); long end = System.currentTimeMillis(); System.out.println("文件解析完成,耗时:" + (end - start) + "ms"); System.out.println("文件共有 " + longDataBodyMap.keySet().size() + " 个数据道"); @@ -34,9 +50,9 @@ public static SEGY parseSEGY(String filePath) { } /** - * 解析 SEG Y 文件的的文件头 + * 解析 SEG-Y 文件的文件头 * - * @param filePath SEG Y 文件路径 + * @param filePath SEG-Y 文件路径 * @return FileHeader */ public static FileHeader parseFileHeader(String filePath) { @@ -51,9 +67,9 @@ public static FileHeader parseFileHeader(String filePath) { } /** - * 解析 SEG Y 文件的的文件头 + * 解析 SEG-Y 文件的文件头 * - * @param file SEG Y 文件 + * @param file SEG-Y 文件 * @return FileHeader */ public static FileHeader parseFileHeader(File file) { @@ -104,23 +120,23 @@ public static FileHeader parseFileHeader(File file) { } /** - * 解析 SEG Y 文件的的数据体 + * 解析 SEG-Y 文件的的数据体 * - * @param file SEG Y 文件 - * @return DataBody + * @param file SEG-Y 文件 + * @return DataTrace */ - public static Map parseDataBody(File file, FileHeader fileHeader, boolean processDisplay) { + public static Map parseDataBody(File file, FileHeader fileHeader, boolean processDisplay) { return parseDataBody(file.getAbsolutePath(), fileHeader, processDisplay); } /** - * 解析 SEG Y 文件的数据体 + * 解析 SEG-Y 文件的数据体 * - * @param filePath SEG Y 文件路径 - * @return DataBody + * @param filePath SEG-Y 文件路径 + * @return DataTrace */ - public static Map parseDataBody(String filePath, FileHeader fileHeader, boolean processDisplay) { - Map dataBodyMap = new HashMap<>(); + public static Map parseDataBody(String filePath, FileHeader fileHeader, boolean processDisplay) { + Map dataBodyMap = new HashMap<>(); try (RandomAccessFile file = new RandomAccessFile(filePath, "r")) { long cnt = 0; @@ -130,101 +146,101 @@ public static Map parseDataBody(String filePath, FileHeader file cnt++; if (processDisplay) System.out.println("++第 " + cnt + " 数据道++"); - DataBody dataBody = new DataBody(); + DataTrace dataTrace = new DataTrace(); byte[] bytes = new byte[240]; file.read(bytes, 0, bytes.length); ByteBuffer buffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN); - dataBody.setTraceSequenceNumberWithinLine(buffer.getInt()); - dataBody.setTraceSequenceNumberWithinSEGY(buffer.getInt()); - dataBody.setOriginalFieldRecordNumber(buffer.getInt()); - dataBody.setTraceNumberWithinTheOriginal(buffer.getInt()); - dataBody.setEnergySourcePointNumber(buffer.getInt()); - dataBody.setEnsembleNumber(buffer.getInt()); - dataBody.setTraceNumberWithinTheEnsemble(buffer.getInt()); - dataBody.setTraceIdentificationCode(buffer.getShort()); - dataBody.setVerticallySummedTraces(buffer.getShort()); - dataBody.setHorizontallyStackedTraces(buffer.getShort()); - dataBody.setDataUse(buffer.getShort()); - dataBody.setSourcePointToReceiverGroup(buffer.getInt()); - dataBody.setReceiverGroupElevation(buffer.getInt()); - dataBody.setSurfaceElevationAtSource(buffer.getInt()); - dataBody.setSourceDepthBelowSurface(buffer.getInt()); - dataBody.setDatumElevationAtReceiverGroup(buffer.getInt()); - dataBody.setDatumElevationAtSource(buffer.getInt()); - dataBody.setWaterDepthAtSource(buffer.getInt()); - dataBody.setWaterDepthAtGroup(buffer.getInt()); - dataBody.setScalar1(buffer.getShort()); - dataBody.setScalar2(buffer.getShort()); - dataBody.setSourceCoordinateX(buffer.getInt()); - dataBody.setSourceCoordinateY(buffer.getInt()); - dataBody.setGroupCoordinateX(buffer.getInt()); - dataBody.setGroupCoordinateY(buffer.getInt()); - dataBody.setCoordinateUnits(buffer.getShort()); - dataBody.setWeatheringVelocity(buffer.getShort()); - dataBody.setSubweatheringVelocity(buffer.getShort()); - dataBody.setUpholeTimeAtSourceInMilliseconds(buffer.getShort()); - dataBody.setUpholeTimeAtGroupInMilliseconds(buffer.getShort()); - dataBody.setSourceStaticCorrectionInMilliseconds(buffer.getShort()); - dataBody.setGroupStaticCorrectionInMilliseconds(buffer.getShort()); - dataBody.setTotalStaticAppliedInMilliseconds(buffer.getShort()); - dataBody.setLagTimeA(buffer.getShort()); - dataBody.setLagTimeB(buffer.getShort()); - dataBody.setDelayRecordingTime(buffer.getShort()); - dataBody.setMuteTimeStart(buffer.getShort()); - dataBody.setMuteTimeEnd(buffer.getShort()); - dataBody.setNumberOfSamplesInThisTrace(buffer.getShort()); - dataBody.setSampleIntervalInMicroseconds(buffer.getShort()); - dataBody.setGainTypeOfFieldInstruments(buffer.getShort()); - dataBody.setInstrumentGainConstant(buffer.getShort()); - dataBody.setInstrumentEarlyOrInitialGain(buffer.getShort()); - dataBody.setCorrelated(buffer.getShort()); - dataBody.setSweepFrequencyAtStart(buffer.getShort()); - dataBody.setSweepFrequencyAtEnd(buffer.getShort()); - dataBody.setSweepLengthInMilliseconds(buffer.getShort()); - dataBody.setSweepType(buffer.getShort()); - dataBody.setSweepTraceTaperLengthAtStart(buffer.getShort()); - dataBody.setSweepTraceTaperLengthAtEnd(buffer.getShort()); - dataBody.setTaperType(buffer.getShort()); - dataBody.setAliasFilterFrequency(buffer.getShort()); - dataBody.setAliasFilterSlope(buffer.getShort()); - dataBody.setNotchFilterFrequency(buffer.getShort()); - dataBody.setNotchFilterSlope(buffer.getShort()); - dataBody.setLowCutFrequency(buffer.getShort()); - dataBody.setHighCutFrequency(buffer.getShort()); - dataBody.setLowCutSlope(buffer.getShort()); - dataBody.setHighCutSlope(buffer.getShort()); - dataBody.setYearDataRecorded(buffer.getShort()); - dataBody.setDayOfYear(buffer.getShort()); - dataBody.setHourOfDay(buffer.getShort()); - dataBody.setMinuteOfHour(buffer.getShort()); - dataBody.setSecondOfMinute(buffer.getShort()); - dataBody.setTimeBasisCode(buffer.getShort()); - dataBody.setTraceWeightingFactor(buffer.getShort()); - dataBody.setRollSwitchPositionOne(buffer.getShort()); - dataBody.setTraceNumberOneWithinOriginal(buffer.getShort()); - dataBody.setLastTraceWithinOriginal(buffer.getShort()); - dataBody.setGapSize(buffer.getShort()); - dataBody.setOverTravelAssociated(buffer.getShort()); - dataBody.setxCoordinateOfEnsemble(buffer.getInt()); - dataBody.setyCoordinateOfEnsemble(buffer.getInt()); - dataBody.setInLineNumber(buffer.getInt()); - dataBody.setCrossLineNumber(buffer.getInt()); - dataBody.setShotpointNumber(buffer.getInt()); - dataBody.setScalar3(buffer.getShort()); - dataBody.setTraceValueMeasurementUnit(buffer.getShort()); - dataBody.setTransductionConstant(get6BytesAsLong(buffer)); - dataBody.setTransductionUnits(buffer.getShort()); - dataBody.setDeviceTraceIdentifier(buffer.getShort()); - dataBody.setScalar4(buffer.getShort()); - dataBody.setSourceTypeOrientation(buffer.getShort()); - dataBody.setSourceEnergyDirection(get6BytesAsLong(buffer)); - dataBody.setSourceMeasurement(get6BytesAsLong(buffer)); - dataBody.setSourceMeasurementUnit(buffer.getShort()); + dataTrace.setTraceSequenceNumberWithinLine(buffer.getInt()); + dataTrace.setTraceSequenceNumberWithinSEGY(buffer.getInt()); + dataTrace.setOriginalFieldRecordNumber(buffer.getInt()); + dataTrace.setTraceNumberWithinTheOriginal(buffer.getInt()); + dataTrace.setEnergySourcePointNumber(buffer.getInt()); + dataTrace.setEnsembleNumber(buffer.getInt()); + dataTrace.setTraceNumberWithinTheEnsemble(buffer.getInt()); + dataTrace.setTraceIdentificationCode(buffer.getShort()); + dataTrace.setVerticallySummedTraces(buffer.getShort()); + dataTrace.setHorizontallyStackedTraces(buffer.getShort()); + dataTrace.setDataUse(buffer.getShort()); + dataTrace.setSourcePointToReceiverGroup(buffer.getInt()); + dataTrace.setReceiverGroupElevation(buffer.getInt()); + dataTrace.setSurfaceElevationAtSource(buffer.getInt()); + dataTrace.setSourceDepthBelowSurface(buffer.getInt()); + dataTrace.setDatumElevationAtReceiverGroup(buffer.getInt()); + dataTrace.setDatumElevationAtSource(buffer.getInt()); + dataTrace.setWaterDepthAtSource(buffer.getInt()); + dataTrace.setWaterDepthAtGroup(buffer.getInt()); + dataTrace.setScalar1(buffer.getShort()); + dataTrace.setScalar2(buffer.getShort()); + dataTrace.setSourceCoordinateX(buffer.getInt()); + dataTrace.setSourceCoordinateY(buffer.getInt()); + dataTrace.setGroupCoordinateX(buffer.getInt()); + dataTrace.setGroupCoordinateY(buffer.getInt()); + dataTrace.setCoordinateUnits(buffer.getShort()); + dataTrace.setWeatheringVelocity(buffer.getShort()); + dataTrace.setSubweatheringVelocity(buffer.getShort()); + dataTrace.setUpholeTimeAtSourceInMilliseconds(buffer.getShort()); + dataTrace.setUpholeTimeAtGroupInMilliseconds(buffer.getShort()); + dataTrace.setSourceStaticCorrectionInMilliseconds(buffer.getShort()); + dataTrace.setGroupStaticCorrectionInMilliseconds(buffer.getShort()); + dataTrace.setTotalStaticAppliedInMilliseconds(buffer.getShort()); + dataTrace.setLagTimeA(buffer.getShort()); + dataTrace.setLagTimeB(buffer.getShort()); + dataTrace.setDelayRecordingTime(buffer.getShort()); + dataTrace.setMuteTimeStart(buffer.getShort()); + dataTrace.setMuteTimeEnd(buffer.getShort()); + dataTrace.setNumberOfSamplesInThisTrace(buffer.getShort()); + dataTrace.setSampleIntervalInMicroseconds(buffer.getShort()); + dataTrace.setGainTypeOfFieldInstruments(buffer.getShort()); + dataTrace.setInstrumentGainConstant(buffer.getShort()); + dataTrace.setInstrumentEarlyOrInitialGain(buffer.getShort()); + dataTrace.setCorrelated(buffer.getShort()); + dataTrace.setSweepFrequencyAtStart(buffer.getShort()); + dataTrace.setSweepFrequencyAtEnd(buffer.getShort()); + dataTrace.setSweepLengthInMilliseconds(buffer.getShort()); + dataTrace.setSweepType(buffer.getShort()); + dataTrace.setSweepTraceTaperLengthAtStart(buffer.getShort()); + dataTrace.setSweepTraceTaperLengthAtEnd(buffer.getShort()); + dataTrace.setTaperType(buffer.getShort()); + dataTrace.setAliasFilterFrequency(buffer.getShort()); + dataTrace.setAliasFilterSlope(buffer.getShort()); + dataTrace.setNotchFilterFrequency(buffer.getShort()); + dataTrace.setNotchFilterSlope(buffer.getShort()); + dataTrace.setLowCutFrequency(buffer.getShort()); + dataTrace.setHighCutFrequency(buffer.getShort()); + dataTrace.setLowCutSlope(buffer.getShort()); + dataTrace.setHighCutSlope(buffer.getShort()); + dataTrace.setYearDataRecorded(buffer.getShort()); + dataTrace.setDayOfYear(buffer.getShort()); + dataTrace.setHourOfDay(buffer.getShort()); + dataTrace.setMinuteOfHour(buffer.getShort()); + dataTrace.setSecondOfMinute(buffer.getShort()); + dataTrace.setTimeBasisCode(buffer.getShort()); + dataTrace.setTraceWeightingFactor(buffer.getShort()); + dataTrace.setRollSwitchPositionOne(buffer.getShort()); + dataTrace.setTraceNumberOneWithinOriginal(buffer.getShort()); + dataTrace.setLastTraceWithinOriginal(buffer.getShort()); + dataTrace.setGapSize(buffer.getShort()); + dataTrace.setOverTravelAssociated(buffer.getShort()); + dataTrace.setxCoordinateOfEnsemble(buffer.getInt()); + dataTrace.setyCoordinateOfEnsemble(buffer.getInt()); + dataTrace.setInLineNumber(buffer.getInt()); + dataTrace.setCrossLineNumber(buffer.getInt()); + dataTrace.setShotpointNumber(buffer.getInt()); + dataTrace.setScalar3(buffer.getShort()); + dataTrace.setTraceValueMeasurementUnit(buffer.getShort()); + dataTrace.setTransductionConstant(get6BytesAsLong(buffer)); + dataTrace.setTransductionUnits(buffer.getShort()); + dataTrace.setDeviceTraceIdentifier(buffer.getShort()); + dataTrace.setScalar4(buffer.getShort()); + dataTrace.setSourceTypeOrientation(buffer.getShort()); + dataTrace.setSourceEnergyDirection(get6BytesAsLong(buffer)); + dataTrace.setSourceMeasurement(get6BytesAsLong(buffer)); + dataTrace.setSourceMeasurementUnit(buffer.getShort()); // 处理数据体第二部分 - float[] floats = new float[dataBody.getNumberOfSamplesInThisTrace()]; - for (int i = 0; i < dataBody.getNumberOfSamplesInThisTrace(); i++) { + float[] floats = new float[dataTrace.getNumberOfSamplesInThisTrace()]; + for (int i = 0; i < dataTrace.getNumberOfSamplesInThisTrace(); i++) { switch (fileHeader.getDataSampleFormatCode()) { case 1: // IBM浮点数 floats[i] = convertIbmToFloat(file.readInt()); @@ -239,12 +255,12 @@ public static Map parseDataBody(String filePath, FileHeader file throw new UnsupportedOperationException("Unsupported format code: " + fileHeader.getDataSampleFormatCode()); } } - dataBody.setSamplingData(floats); + dataTrace.setSamplingData(floats); - dataBodyMap.put(cnt, dataBody); + dataBodyMap.put(cnt, dataTrace); if (processDisplay) - System.out.println(dataBody); + System.out.println(dataTrace); } } catch (IOException e) { e.printStackTrace(); @@ -253,6 +269,7 @@ public static Map parseDataBody(String filePath, FileHeader file return dataBodyMap; } + // 6 字节合并为 long 型 private static long combineToLong(byte a, byte b, byte c, byte d, byte e, byte f) { long res = 0; res += (long) a << 40; @@ -265,6 +282,7 @@ private static long combineToLong(byte a, byte b, byte c, byte d, byte e, byte f return res; } + // 4 字节合并为 short 型 private static int combineToInt(byte a, byte b, byte c, byte d) { int res = 0; res += a << 24; @@ -275,6 +293,7 @@ private static int combineToInt(byte a, byte b, byte c, byte d) { return res; } + // 2 字节合并为 short 型 private static short combineToShort(byte a, byte b) { short res = 0; res += (short) (a << 8); @@ -283,7 +302,7 @@ private static short combineToShort(byte a, byte b) { return res; } - // IBM浮点数转换 (实现参考 SEGY 规范) + // IBM 浮点数转换 (实现参考 SEG-Y 规范) private static float convertIbmToFloat(int ibmFloat) { int sign = ((ibmFloat >> 31) == 0) ? 1 : -1; int exponent = ((ibmFloat >> 24) & 0x7F) - 64; @@ -291,8 +310,8 @@ private static float convertIbmToFloat(int ibmFloat) { return (float) (sign * mantissa * Math.pow(16, exponent - 6)); } + // 读取 6 字节为 long 型,按大端序拼接 private static long get6BytesAsLong(ByteBuffer buffer) { - // 读取6字节,按大端序拼接 long value = 0; for (int i = 0; i < 6; i++) { value = (value << 8) | (buffer.get() & 0xFF); From d4878e2915066795828bd84f69793587659e38c3 Mon Sep 17 00:00:00 2001 From: ZZHow <109335896+ZZHow1024@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:05:42 +0800 Subject: [PATCH 2/6] refactor: restructure and add new UI components --- src/META-INF/MANIFEST.MF | 2 +- src/MainClass.java | 11 +++++++++++ src/{Main.java => ui/Application.java} | 17 ++++++++++------- 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 src/MainClass.java rename src/{Main.java => ui/Application.java} (94%) diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF index 37197ef..09ae806 100644 --- a/src/META-INF/MANIFEST.MF +++ b/src/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Main-Class: Main +MainClass-Class: MainClass diff --git a/src/MainClass.java b/src/MainClass.java new file mode 100644 index 0000000..7a57e36 --- /dev/null +++ b/src/MainClass.java @@ -0,0 +1,11 @@ +import ui.Application; + +/** + * @author ZZHow + * @date 2024/11/25 + */ +public class MainClass { + public static void main(String[] args) { + Application.show(args); + } +} \ No newline at end of file diff --git a/src/Main.java b/src/ui/Application.java similarity index 94% rename from src/Main.java rename to src/ui/Application.java index 9e7f66f..b3db6f8 100644 --- a/src/Main.java +++ b/src/ui/Application.java @@ -1,3 +1,5 @@ +package ui; + import pojo.entity.SEGY; import util.SEGYUtils; @@ -6,15 +8,15 @@ /** * @author ZZHow - * @date 2024/11/25 + * @date 2024/11/27 */ -public class Main { - public static void main(String[] args) { +public class Application { + public static void show(String[] args) { Scanner scanner = new Scanner(System.in); SEGY segy = new SEGY(); String filePath = ""; - System.out.println("ZSEGY 1.0.0"); + System.out.println("ZSEGY 1.0.1"); System.out.println("Author: ZZHow"); // 命令模式 @@ -31,7 +33,8 @@ public static void main(String[] args) { num = Long.parseLong(args[1]); } catch (NumberFormatException e) { System.out.println("格式错误,输入 -help 查看提示"); - System.exit(0);; + System.exit(0); + ; } segy = SEGYUtils.parseSEGY(args[2]); System.out.println("\n@@@第 " + num + " 个数据道@@@"); @@ -56,7 +59,7 @@ public static void main(String[] args) { filePath = args[1]; } case "-help", "help" -> { - System.out.println("--- ZSEGY 1.0.0 使用说明 ---"); + System.out.println("--- ZSEGY 1.0.1 使用说明 ---"); System.out.println("java -jar zsegy.jar [-command] [filePath]"); System.out.println("[-command]: "); System.out.println("-head [filePath]:解析并输出文件头"); @@ -128,4 +131,4 @@ public static void main(String[] args) { scanner.nextLine(); } } -} \ No newline at end of file +} From a0d3191ed279b2387fe469a440fbcdef457264bb Mon Sep 17 00:00:00 2001 From: ZZHow <109335896+ZZHow1024@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:13:52 +0800 Subject: [PATCH 3/6] refactor: update MANIFEST.MF --- src/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF index 09ae806..4c1c822 100644 --- a/src/META-INF/MANIFEST.MF +++ b/src/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -MainClass-Class: MainClass +Main-Class: MainClass From 068d278ab69b9f0ee940b93f4ad802cde76a8943 Mon Sep 17 00:00:00 2001 From: ZZHow <109335896+ZZHow1024@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:17:10 +0800 Subject: [PATCH 4/6] fix: revise text prompts --- src/util/SEGYUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/SEGYUtils.java b/src/util/SEGYUtils.java index 325caf7..d4ba8ef 100644 --- a/src/util/SEGYUtils.java +++ b/src/util/SEGYUtils.java @@ -35,7 +35,7 @@ public static SEGY parseSEGY(File file) { public static SEGY parseSEGY(String filePath) { SEGY segy = new SEGY(); - System.out.println("正在解析文件中,请稍后..."); + System.out.println("正在解析中..."); long start = System.currentTimeMillis(); FileHeader fileHeader = SEGYUtils.parseFileHeader(filePath); segy.setFileHeader(fileHeader); From 36ee14f8ce7a9887e8136057b5681d6932e15eef Mon Sep 17 00:00:00 2001 From: ZZHow <109335896+ZZHow1024@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:54:46 +0800 Subject: [PATCH 5/6] feat: add exception handling for input format mismatch and missing files --- src/ui/Application.java | 67 ++++++++++++++++++++++++++++++----------- src/util/SEGYUtils.java | 5 +++ 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/ui/Application.java b/src/ui/Application.java index b3db6f8..1419e05 100644 --- a/src/ui/Application.java +++ b/src/ui/Application.java @@ -1,9 +1,12 @@ package ui; +import pojo.entity.DataTrace; +import pojo.entity.FileHeader; import pojo.entity.SEGY; import util.SEGYUtils; import java.io.File; +import java.util.Map; import java.util.Scanner; /** @@ -23,40 +26,58 @@ public static void show(String[] args) { if (args.length != 0) { switch (args[0]) { case "-head", "head" -> { - System.out.println("正在解析中..."); - System.out.println(SEGYUtils.parseFileHeader(args[1])); + FileHeader fileHeader = null; + try { + fileHeader = SEGYUtils.parseFileHeader(args[1]); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("格式错误,输入 -help 查看提示"); + } + if (fileHeader != null) + System.out.println(fileHeader); System.exit(0); } case "-body", "body" -> { long num = 1; try { num = Long.parseLong(args[1]); - } catch (NumberFormatException e) { + segy = SEGYUtils.parseSEGY(args[2]); + } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { System.out.println("格式错误,输入 -help 查看提示"); System.exit(0); - ; + } catch (UnsupportedOperationException e) { + System.out.println("数据采样格式编码错误,请检查"); + } + if (segy != null) { + System.out.println("\n@@@第 " + num + " 个数据道@@@"); + System.out.println(segy.getDataBody().get(num)); } - segy = SEGYUtils.parseSEGY(args[2]); - System.out.println("\n@@@第 " + num + " 个数据道@@@"); - System.out.println(segy.getDataBody().get(num)); System.exit(0); } case "-all", "all" -> { - long num; + long num = 1; try { num = Long.parseLong(args[1]); + segy = SEGYUtils.parseSEGY(args[2]); + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("格式错误,输入 -help 查看提示"); } catch (NumberFormatException e) { System.out.println("输入格式错误,输入 -help 查看提示"); break; } - segy = SEGYUtils.parseSEGY(args[2]); - System.out.println(segy.getFileHeader()); - System.out.println("\n@@@第 " + num + " 个数据道@@@"); - System.out.println(segy.getDataBody().get(num)); + if (segy != null) { + System.out.println(segy.getFileHeader()); + System.out.println("\n@@@第 " + num + " 个数据道@@@"); + System.out.println(segy.getDataBody().get(num)); + } System.exit(0); } case "-i", "i" -> { - filePath = args[1]; + try { + filePath = args[1]; + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("输入格式错误,输入 -help 查看提示"); + System.exit(0); + } } case "-help", "help" -> { System.out.println("--- ZSEGY 1.0.1 使用说明 ---"); @@ -109,12 +130,24 @@ public static void show(String[] args) { } } case "1" -> { - System.out.println(segy.getFileHeader()); + if (segy != null) + System.out.println(segy.getFileHeader()); + else + System.out.println("文件头为空"); } case "2" -> { - System.out.print("数据道数:"); - long num = scanner.nextLong(); - System.out.println(segy.getDataBody().get(num)); + if (segy != null) { + Map dataBody = segy.getDataBody(); + if (dataBody == null) { + System.out.println("数据体为空"); + } else { + System.out.print("数据道数:"); + long num = scanner.nextLong(); + System.out.println(dataBody.get(num)); + } + } else { + System.out.println("数据体为空"); + } } case "3" -> { System.out.println("程序退出..."); diff --git a/src/util/SEGYUtils.java b/src/util/SEGYUtils.java index d4ba8ef..d1d7e14 100644 --- a/src/util/SEGYUtils.java +++ b/src/util/SEGYUtils.java @@ -33,6 +33,11 @@ public static SEGY parseSEGY(File file) { * @return SEGY */ public static SEGY parseSEGY(String filePath) { + if (!new File(filePath).exists()) { + System.out.println("文件不存在"); + return null; + } + SEGY segy = new SEGY(); System.out.println("正在解析中..."); From 41d19c09a69f05ea0fcf96fd595d0b05a1d74fb6 Mon Sep 17 00:00:00 2001 From: ZZHow <109335896+ZZHow1024@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:01:50 +0800 Subject: [PATCH 6/6] docs: update README with additional references --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 03e04b1..acb31bd 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,12 @@ ZSEGY 是一款跨平台的 SEG-Y 文件解析工具,支持命令模式和交 3. 展示数据体 4. 退出程序 +------ + +## 参考文献 + +- SEG Y rev 1Release 1.02: [library.seg.org](https://library.seg.org/pb-assets/technical-standards/seg_y_rev1-1686080991247.pdf) + --- ## 各版本功能介绍