Browse Source

modify some codes

master
xiaowuler 3 years ago
parent
commit
8b00600b5f
  1. 59
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/custom/ICustomInputStream.java
  2. 116
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/custom/impl/CustomRadarInputStream.java
  3. 2
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/custom/impl/CustomerDataOutputStream.java
  4. 89
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/customer/CustomerDataInputStream.java
  5. 24
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/exceptions/RadarReadException.java
  6. 16
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/CommonBlock.java
  7. 16
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/GenericHeader.java
  8. 8
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/MomentBlock.java
  9. 11
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/MomentData.java
  10. 18
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/MomentHeader.java
  11. 8
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/Radial.java
  12. 8
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/RadialBlock.java
  13. 34
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/RadialHeader.java
  14. 93
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/ScanConfiguration.java
  15. 36
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/SiteConfiguration.java
  16. 38
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/TaskConfiguration.java
  17. 27
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/enums/RadarSuffixEnum.java
  18. 57
      04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/resolver/RadarReader.java
  19. 13
      04.系统编码/03.radar-resolver/src/test/java/com/xiaowuler/radarresolver/RadarResolverApplicationTests.java

59
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/custom/ICustomInputStream.java

@ -0,0 +1,59 @@
package com.xiaowuler.radarresolver.custom;
import java.io.IOException;
/**
* @describe: 自定义读取字节流
* @author: xiaowuler
* @createTime: 2022-03-17 17:07
*/
public interface ICustomInputStream {
/**
* 转换 int
* @return
* @throws IOException
*/
int readInt() throws IOException;
/**
* 转换 short
* @return
* @throws IOException
*/
short readShort() throws IOException;
/**
* 转换 long
* @return
* @throws IOException
*/
long readLong() throws IOException;
/**
* 转换 float
* @return
* @throws IOException
*/
float readFloat() throws IOException;
/**
* 读取 指定个数 字节
* @param len
* @return
* @throws IOException
*/
byte[] readNBytes(int len) throws IOException;
/**
* 判断是否存在字节
* @return
* @throws IOException
*/
int available() throws IOException;
/**
* 释放资源
* @throws IOException
*/
void close() throws IOException;
}

116
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/custom/impl/CustomRadarInputStream.java

@ -0,0 +1,116 @@
package com.xiaowuler.radarresolver.custom.impl;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Locale;
import java.util.Objects;
import org.python.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import com.xiaowuler.radarresolver.custom.ICustomInputStream;
import com.xiaowuler.radarresolver.util.ByteUtils;
/**
* @describe: 自定义 雷达 输入流
* Big-Endian Little-Endian 字节排序
* * Big-Endian 一个Word中的高位的Byte放在内存中这个Word区域的低地址处
* * Little-Endian 一个Word中的低位的Byte放在内存中这个Word区域的低地址处
* * python写入的二进制文件和java二进制文件编码读取顺序不同java 是从左到右编码python是从右到左
* @author: xiaowuler
* @createTime: 2022-03-18 09:09
*/
public class CustomRadarInputStream implements ICustomInputStream, Closeable{
private static final String BZIP_SUFFIX = "bz2";
private static final String BIN_SUFFIX = "bin";
private InputStream inputStream;
private FileInputStream fileInputStream;
public CustomRadarInputStream(String filepath) throws FileNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
String fileSuffix = filepath.substring(filepath.lastIndexOf(".") + 1).trim().toLowerCase(Locale.ROOT);
switch (fileSuffix){
case BIN_SUFFIX:
customRadarInputStream(filepath, DataInputStream.class);
break;
case BZIP_SUFFIX:
customRadarInputStream(filepath, BZip2CompressorInputStream.class);
default:
throw new IllegalAccessException("无效的文件格式类型");
}
}
private <T extends InputStream> void customRadarInputStream(String filepath, Class<T> clazz) throws NoSuchMethodException, FileNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
fileInputStream = new FileInputStream(filepath);
inputStream = clazz.getConstructor(InputStream.class).newInstance(fileInputStream);
}
@Override
public int readInt() throws IOException {
int ch1 = inputStream.read();
int ch2 = inputStream.read();
int ch3 = inputStream.read();
int ch4 = inputStream.read();
if ((ch1 | ch2 | ch3 | ch4) < 0) {
throw new EOFException();
}
return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24));
}
/**
* Big-Endian Little-Endian 字节排序
*
* Big-Endian 一个Word中的高位的Byte放在内存中这个Word区域的低地址处
* Little-Endian 一个Word中的低位的Byte放在内存中这个Word区域的低地址处
* @return
* @throws IOException
*/
@Override
public short readShort() throws IOException{
byte[] bytes = inputStream.readNBytes(2);
return ByteUtils.bytes2Short(bytes);
}
@Override
public long readLong() throws IOException{
byte[] bytes = inputStream.readNBytes(8);
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
return byteBuffer.getLong();
}
@Override
public float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}
@Override
public byte[] readNBytes(int len) throws IOException{
return inputStream.readNBytes(len);
}
@Override
public int available() throws IOException {
return inputStream.available();
}
@Override
public void close() {
if (Objects.nonNull(fileInputStream)){
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (Objects.nonNull(inputStream)){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

2
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/customer/CustomerDataOutputStream.java → 04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/custom/impl/CustomerDataOutputStream.java

@ -1,4 +1,4 @@
package com.xiaowuler.radarresolver.customer; package com.xiaowuler.radarresolver.custom.impl;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;

89
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/customer/CustomerDataInputStream.java

@ -1,89 +0,0 @@
package com.xiaowuler.radarresolver.customer;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import lombok.Data;
import com.xiaowuler.radarresolver.util.ByteUtils;
/**
* @describe: Big-Endian Little-Endian 字节排序
* Big-Endian 一个Word中的高位的Byte放在内存中这个Word区域的低地址处
* Little-Endian 一个Word中的低位的Byte放在内存中这个Word区域的低地址处
* python写入的二进制文件和java二进制文件编码读取顺序不同java 是从左到右编码python是从右到左
* @author: xiaowuler
* @createTime: 2021-05-19 09:01
*/
public class CustomerDataInputStream extends DataInputStream {
// private int pos = 0;
/**
* Creates a DataInputStream that uses the specified
* underlying InputStream.
*
* @param in the specified input stream
*/
public CustomerDataInputStream(InputStream in) {
super(in);
}
public final int readCInt() throws IOException {
// addPos(4);
int ch1 = in.read();
int ch2 = in.read();
int ch3 = in.read();
int ch4 = in.read();
if ((ch1 | ch2 | ch3 | ch4) < 0) {
throw new EOFException();
}
return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24));
}
/**
* Big-Endian Little-Endian 字节排序
*
* Big-Endian 一个Word中的高位的Byte放在内存中这个Word区域的低地址处
* Little-Endian 一个Word中的低位的Byte放在内存中这个Word区域的低地址处
* @return
* @throws IOException
*/
public final short readCShort() throws IOException{
// addPos(2);
byte[] bytes = in.readNBytes(2);
return ByteUtils.bytes2Short(bytes);
}
public final long readCLong() throws IOException{
// addPos(8);
byte[] bytes = in.readNBytes(8);
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
return byteBuffer.getLong();
}
public final float readCFloat() throws IOException {
// addPos(4);
return Float.intBitsToFloat(readCInt());
}
@Override
public byte[] readNBytes(int len) throws IOException{
// addPos(len);
return super.readNBytes(len);
}
public byte readCByte() throws IOException{
// addPos(1);
return super.readByte();
}
// public int getPos() {
// return pos;
// }
//
// private synchronized void addPos(int value) {
// this.pos += value;
// }
}

24
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/exceptions/RadarReadException.java

@ -0,0 +1,24 @@
package com.xiaowuler.radarresolver.exceptions;
/**
* @describe: 雷达读取异常
* @author: xiaowuler
* @createTime: 2022-03-18 09:47
*/
public class RadarReadException extends Exception {
public RadarReadException(){
super();
}
public RadarReadException(String message){
super(message);
}
public RadarReadException(String message, Throwable cause){
super(message, cause);
}
public RadarReadException(Throwable cause){
super(cause);
}
}

16
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/CommonBlock.java

@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
/** /**
* @describe: 公共数据块 * @describe: 公共数据块
@ -18,18 +18,18 @@ public class CommonBlock {
private SiteConfiguration siteConfiguration; private SiteConfiguration siteConfiguration;
private TaskConfiguration taskConfiguration; private TaskConfiguration taskConfiguration;
private List<ScanConfiguration> scanConfigurations; private List<ScanConfiguration> scanConfigurations;
public CommonBlock(CustomerDataInputStream customerDataInputStream) throws IOException { public CommonBlock(ICustomInputStream ICustomInputStream) throws IOException {
this.genericHeader = new GenericHeader(customerDataInputStream); this.genericHeader = new GenericHeader(ICustomInputStream);
this.siteConfiguration = new SiteConfiguration(customerDataInputStream); this.siteConfiguration = new SiteConfiguration(ICustomInputStream);
this.taskConfiguration = new TaskConfiguration(customerDataInputStream); this.taskConfiguration = new TaskConfiguration(ICustomInputStream);
addScanConfigurations(customerDataInputStream); addScanConfigurations(ICustomInputStream);
} }
private void addScanConfigurations(CustomerDataInputStream customerDataInputStream) throws IOException { private void addScanConfigurations(ICustomInputStream ICustomInputStream) throws IOException {
this.scanConfigurations = new ArrayList<>(taskConfiguration.getCutNumber()); this.scanConfigurations = new ArrayList<>(taskConfiguration.getCutNumber());
for(int index = 0; index < taskConfiguration.getCutNumber(); index++){ for(int index = 0; index < taskConfiguration.getCutNumber(); index++){
scanConfigurations.add(new ScanConfiguration(customerDataInputStream)); scanConfigurations.add(new ScanConfiguration(ICustomInputStream));
} }
} }
} }

16
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/GenericHeader.java

@ -3,7 +3,7 @@ package com.xiaowuler.radarresolver.weather.domain;
import java.io.IOException; import java.io.IOException;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
/** /**
* @describe: 通用头块 * @describe: 通用头块
@ -43,12 +43,12 @@ public class GenericHeader {
*/ */
private byte[] reserved; private byte[] reserved;
public GenericHeader(CustomerDataInputStream dataInputStream) throws IOException { public GenericHeader(ICustomInputStream ICustomInputStream) throws IOException {
this.magicNumber = dataInputStream.readCInt(); this.magicNumber = ICustomInputStream.readInt();
this.majorVersion = dataInputStream.readCShort(); this.majorVersion = ICustomInputStream.readShort();
this.minorVersion = dataInputStream.readCShort(); this.minorVersion = ICustomInputStream.readShort();
this.genericType = dataInputStream.readCInt(); this.genericType = ICustomInputStream.readInt();
this.productType = dataInputStream.readCInt(); this.productType = ICustomInputStream.readInt();
this.reserved = dataInputStream.readNBytes(16); this.reserved = ICustomInputStream.readNBytes(16);
} }
} }

8
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/MomentBlock.java

@ -3,7 +3,7 @@ package com.xiaowuler.radarresolver.weather.domain;
import java.io.IOException; import java.io.IOException;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
/** /**
* @describe: 径向数据块 * @describe: 径向数据块
@ -15,8 +15,8 @@ public class MomentBlock {
private MomentHeader momentHeader; private MomentHeader momentHeader;
private MomentData momentData; private MomentData momentData;
public MomentBlock(CustomerDataInputStream customerDataInputStream) throws IOException { public MomentBlock(ICustomInputStream ICustomInputStream) throws IOException {
this.momentHeader = new MomentHeader(customerDataInputStream); this.momentHeader = new MomentHeader(ICustomInputStream);
this.momentData = new MomentData(customerDataInputStream, momentHeader); this.momentData = new MomentData(ICustomInputStream, momentHeader);
} }
} }

11
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/MomentData.java

@ -1,12 +1,9 @@
package com.xiaowuler.radarresolver.weather.domain; package com.xiaowuler.radarresolver.weather.domain;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
import com.xiaowuler.radarresolver.util.ByteUtils; import com.xiaowuler.radarresolver.util.ByteUtils;
/** /**
@ -18,12 +15,12 @@ import com.xiaowuler.radarresolver.util.ByteUtils;
public class MomentData { public class MomentData {
private double[] data; private double[] data;
public MomentData(CustomerDataInputStream customerDataInputStream, MomentHeader momentHeader) throws IOException { public MomentData(ICustomInputStream ICustomInputStream, MomentHeader momentHeader) throws IOException {
if (momentHeader.getBinLength() == 1){ if (momentHeader.getBinLength() == 1){
oneByteConvert(customerDataInputStream.readNBytes(momentHeader.getLength()), momentHeader.getLength(), momentHeader.getScale(), momentHeader.getOffset()); oneByteConvert(ICustomInputStream.readNBytes(momentHeader.getLength()), momentHeader.getLength(), momentHeader.getScale(), momentHeader.getOffset());
return; return;
} }
twoByteConvert(customerDataInputStream.readNBytes(momentHeader.getLength()), momentHeader.getLength() / momentHeader.getBinLength(), momentHeader.getScale(), momentHeader.getOffset()); twoByteConvert(ICustomInputStream.readNBytes(momentHeader.getLength()), momentHeader.getLength() / momentHeader.getBinLength(), momentHeader.getScale(), momentHeader.getOffset());
} }
private void oneByteConvert(byte[] bytes, int length, int scale, int offset){ private void oneByteConvert(byte[] bytes, int length, int scale, int offset){

18
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/MomentHeader.java

@ -3,7 +3,7 @@ package com.xiaowuler.radarresolver.weather.domain;
import java.io.IOException; import java.io.IOException;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
/** /**
* @describe: 径向数据头 * @describe: 径向数据头
@ -20,13 +20,13 @@ public class MomentHeader {
private int length; private int length;
private byte[] reserved; private byte[] reserved;
public MomentHeader(CustomerDataInputStream customerDataInputStream) throws IOException { public MomentHeader(ICustomInputStream ICustomInputStream) throws IOException {
this.dataType = customerDataInputStream.readCInt(); this.dataType = ICustomInputStream.readInt();
this.scale = customerDataInputStream.readCInt(); this.scale = ICustomInputStream.readInt();
this.offset = customerDataInputStream.readCInt(); this.offset = ICustomInputStream.readInt();
this.binLength = customerDataInputStream.readCShort(); this.binLength = ICustomInputStream.readShort();
this.flags = customerDataInputStream.readCShort(); this.flags = ICustomInputStream.readShort();
this.length = customerDataInputStream.readCInt(); this.length = ICustomInputStream.readInt();
this.reserved = customerDataInputStream.readNBytes(12); this.reserved = ICustomInputStream.readNBytes(12);
} }
} }

8
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/Radial.java

@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
/** /**
* @describe: * @describe:
@ -18,12 +18,12 @@ public class Radial {
private RadialHeader radialHeader; private RadialHeader radialHeader;
private List<MomentBlock> momentBlocks; private List<MomentBlock> momentBlocks;
public Radial(CustomerDataInputStream customerDataInputStream) throws IOException { public Radial(ICustomInputStream ICustomInputStream) throws IOException {
this.radialHeader = new RadialHeader(customerDataInputStream); this.radialHeader = new RadialHeader(ICustomInputStream);
this.momentBlocks = new ArrayList<>(radialHeader.getMomentNumber()); this.momentBlocks = new ArrayList<>(radialHeader.getMomentNumber());
for(int index = 0; index < radialHeader.getMomentNumber(); index ++){ for(int index = 0; index < radialHeader.getMomentNumber(); index ++){
momentBlocks.add(new MomentBlock(customerDataInputStream)); momentBlocks.add(new MomentBlock(ICustomInputStream));
} }
} }
} }

8
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/RadialBlock.java

@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
/** /**
* @describe: 径向数据块 * @describe: 径向数据块
@ -17,10 +17,10 @@ public class RadialBlock {
private List<Radial> radials; private List<Radial> radials;
public RadialBlock(CustomerDataInputStream customerDataInputStream) throws IOException { public RadialBlock(ICustomInputStream ICustomInputStream) throws IOException {
this.radials = new ArrayList<>(); this.radials = new ArrayList<>();
while (customerDataInputStream.available() > 0){ while (ICustomInputStream.available() > 0){
this.radials.add(new Radial(customerDataInputStream)); this.radials.add(new Radial(ICustomInputStream));
} }
} }
} }

34
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/RadialHeader.java

@ -3,7 +3,7 @@ package com.xiaowuler.radarresolver.weather.domain;
import java.io.IOException; import java.io.IOException;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
/** /**
* @describe: 径向头 * @describe: 径向头
@ -28,21 +28,21 @@ public class RadialHeader {
private short verticalEstimatedNoise; private short verticalEstimatedNoise;
private byte[] reserved; private byte[] reserved;
public RadialHeader(CustomerDataInputStream customerDataInputStream) throws IOException { public RadialHeader(ICustomInputStream ICustomInputStream) throws IOException {
this.radialState = customerDataInputStream.readCInt(); this.radialState = ICustomInputStream.readInt();
this.spotBlank = customerDataInputStream.readCInt(); this.spotBlank = ICustomInputStream.readInt();
this.sequenceNumber = customerDataInputStream.readCInt(); this.sequenceNumber = ICustomInputStream.readInt();
this.radialNumber = customerDataInputStream.readCInt(); this.radialNumber = ICustomInputStream.readInt();
this.elevationNumber = customerDataInputStream.readCInt(); this.elevationNumber = ICustomInputStream.readInt();
this.azimuth = customerDataInputStream.readCFloat(); this.azimuth = ICustomInputStream.readFloat();
this.elevation = customerDataInputStream.readCFloat(); this.elevation = ICustomInputStream.readFloat();
this.seconds = customerDataInputStream.readCInt(); this.seconds = ICustomInputStream.readInt();
this.microseconds = customerDataInputStream.readCInt(); this.microseconds = ICustomInputStream.readInt();
this.lengthData = customerDataInputStream.readCInt(); this.lengthData = ICustomInputStream.readInt();
this.momentNumber = customerDataInputStream.readCInt(); this.momentNumber = ICustomInputStream.readInt();
this.otherReserved = customerDataInputStream.readNBytes(2); this.otherReserved = ICustomInputStream.readNBytes(2);
this.horizontalEstimatedNoise = customerDataInputStream.readCShort(); this.horizontalEstimatedNoise = ICustomInputStream.readShort();
this.verticalEstimatedNoise = customerDataInputStream.readCShort(); this.verticalEstimatedNoise = ICustomInputStream.readShort();
this.reserved = customerDataInputStream.readNBytes(14); this.reserved = ICustomInputStream.readNBytes(14);
} }
} }

93
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/ScanConfiguration.java

@ -1,10 +1,9 @@
package com.xiaowuler.radarresolver.weather.domain; package com.xiaowuler.radarresolver.weather.domain;
import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
/** /**
* @describe: 扫描配置 * @describe: 扫描配置
@ -58,50 +57,50 @@ public class ScanConfiguration {
private short groundClutterFilterWindow; private short groundClutterFilterWindow;
private byte[] reserved; private byte[] reserved;
public ScanConfiguration(CustomerDataInputStream customerDataInputStream) throws IOException { public ScanConfiguration(ICustomInputStream ICustomInputStream) throws IOException {
this.processMode = customerDataInputStream.readCInt(); this.processMode = ICustomInputStream.readInt();
this.waveForm = customerDataInputStream.readCInt(); this.waveForm = ICustomInputStream.readInt();
this.PRF1 = customerDataInputStream.readCFloat(); this.PRF1 = ICustomInputStream.readFloat();
this.PRF2 = customerDataInputStream.readCFloat(); this.PRF2 = ICustomInputStream.readFloat();
this.dealMode = customerDataInputStream.readCInt(); this.dealMode = ICustomInputStream.readInt();
this.azimuth = customerDataInputStream.readCFloat(); this.azimuth = ICustomInputStream.readFloat();
this.elevation = customerDataInputStream.readCFloat(); this.elevation = ICustomInputStream.readFloat();
this.startAngle = customerDataInputStream.readCFloat(); this.startAngle = ICustomInputStream.readFloat();
this.endAngle = customerDataInputStream.readCFloat(); this.endAngle = ICustomInputStream.readFloat();
this.angularResolution = customerDataInputStream.readCFloat(); this.angularResolution = ICustomInputStream.readFloat();
this.scanSpeed = customerDataInputStream.readCFloat(); this.scanSpeed = ICustomInputStream.readFloat();
this.logResolution = customerDataInputStream.readCInt() * 0.001f; this.logResolution = ICustomInputStream.readInt() * 0.001f;
this.dopplerResolution = customerDataInputStream.readCInt(); this.dopplerResolution = ICustomInputStream.readInt();
this.maximumRange1 = customerDataInputStream.readCInt(); this.maximumRange1 = ICustomInputStream.readInt();
this.maximumRange2 = customerDataInputStream.readCInt(); this.maximumRange2 = ICustomInputStream.readInt();
this.startRange = customerDataInputStream.readCInt(); this.startRange = ICustomInputStream.readInt();
this.sample1 = customerDataInputStream.readCInt(); this.sample1 = ICustomInputStream.readInt();
this.sample2 = customerDataInputStream.readCInt(); this.sample2 = ICustomInputStream.readInt();
this.phaseMode = customerDataInputStream.readCInt(); this.phaseMode = ICustomInputStream.readInt();
this.atmosphericLoss = customerDataInputStream.readCFloat(); this.atmosphericLoss = ICustomInputStream.readFloat();
this.nyquistSpeed = customerDataInputStream.readCFloat(); this.nyquistSpeed = ICustomInputStream.readFloat();
this.momentsMask = customerDataInputStream.readCLong(); this.momentsMask = ICustomInputStream.readLong();
this.momentsSizeMask = customerDataInputStream.readCLong(); this.momentsSizeMask = ICustomInputStream.readLong();
this.miscFilterMask = customerDataInputStream.readCInt(); this.miscFilterMask = ICustomInputStream.readInt();
this.SQIThreshold = customerDataInputStream.readCFloat(); this.SQIThreshold = ICustomInputStream.readFloat();
this.SIGThreshold = customerDataInputStream.readCFloat(); this.SIGThreshold = ICustomInputStream.readFloat();
this.CSRThreshold = customerDataInputStream.readCFloat(); this.CSRThreshold = ICustomInputStream.readFloat();
this.LOGThreshold = customerDataInputStream.readCFloat(); this.LOGThreshold = ICustomInputStream.readFloat();
this.CPAThreshold = customerDataInputStream.readCFloat(); this.CPAThreshold = ICustomInputStream.readFloat();
this.PMIThreshold = customerDataInputStream.readCFloat(); this.PMIThreshold = ICustomInputStream.readFloat();
this.DPLOGThreshold = customerDataInputStream.readCFloat(); this.DPLOGThreshold = ICustomInputStream.readFloat();
this.thresholdsReserved = customerDataInputStream.readNBytes(4); this.thresholdsReserved = ICustomInputStream.readNBytes(4);
this.dBTMask = customerDataInputStream.readCInt(); this.dBTMask = ICustomInputStream.readInt();
this.dBZMask = customerDataInputStream.readCInt(); this.dBZMask = ICustomInputStream.readInt();
this.velocityMask = customerDataInputStream.readCInt(); this.velocityMask = ICustomInputStream.readInt();
this.spectrumWidthMask = customerDataInputStream.readCInt(); this.spectrumWidthMask = ICustomInputStream.readInt();
this.DPMask = customerDataInputStream.readCInt(); this.DPMask = ICustomInputStream.readInt();
this.maskReserved = customerDataInputStream.readNBytes(16); this.maskReserved = ICustomInputStream.readNBytes(16);
this.direction = customerDataInputStream.readCInt(); this.direction = ICustomInputStream.readInt();
this.groundClutterClassifierType = customerDataInputStream.readCShort(); this.groundClutterClassifierType = ICustomInputStream.readShort();
this.groundClutterFilterType = customerDataInputStream.readCShort(); this.groundClutterFilterType = ICustomInputStream.readShort();
this.groundClutterFilterNotchWidth = customerDataInputStream.readCShort(); this.groundClutterFilterNotchWidth = ICustomInputStream.readShort();
this.groundClutterFilterWindow = customerDataInputStream.readCShort(); this.groundClutterFilterWindow = ICustomInputStream.readShort();
this.reserved = customerDataInputStream.readNBytes(72); this.reserved = ICustomInputStream.readNBytes(72);
} }
} }

36
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/SiteConfiguration.java

@ -3,7 +3,7 @@ package com.xiaowuler.radarresolver.weather.domain;
import java.io.IOException; import java.io.IOException;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
import com.xiaowuler.radarresolver.util.ByteUtils; import com.xiaowuler.radarresolver.util.ByteUtils;
/** /**
@ -111,22 +111,22 @@ public class SiteConfiguration {
*/ */
private byte[] reserved = new byte[46]; private byte[] reserved = new byte[46];
public SiteConfiguration(CustomerDataInputStream customerDataInputStream) throws IOException { public SiteConfiguration(ICustomInputStream ICustomInputStream) throws IOException {
this.siteCode = ByteUtils.bytes2String(customerDataInputStream.readNBytes(8)); this.siteCode = ByteUtils.bytes2String(ICustomInputStream.readNBytes(8));
this.siteName = ByteUtils.bytes2String(customerDataInputStream.readNBytes(32)); this.siteName = ByteUtils.bytes2String(ICustomInputStream.readNBytes(32));
this.latitude = customerDataInputStream.readCFloat(); this.latitude = ICustomInputStream.readFloat();
this.longitude = customerDataInputStream.readCFloat(); this.longitude = ICustomInputStream.readFloat();
this.antennaHeight = customerDataInputStream.readCInt(); this.antennaHeight = ICustomInputStream.readInt();
this.groundHeight = customerDataInputStream.readCInt(); this.groundHeight = ICustomInputStream.readInt();
this.frequency = customerDataInputStream.readCFloat(); this.frequency = ICustomInputStream.readFloat();
this.beamWidthHorizontal = customerDataInputStream.readCFloat(); this.beamWidthHorizontal = ICustomInputStream.readFloat();
this.beamWidthVertical = customerDataInputStream.readCFloat(); this.beamWidthVertical = ICustomInputStream.readFloat();
this.RDAVersion = customerDataInputStream.readCInt(); this.RDAVersion = ICustomInputStream.readInt();
this.radarType = customerDataInputStream.readCShort(); this.radarType = ICustomInputStream.readShort();
this.antennaGain = customerDataInputStream.readCShort(); this.antennaGain = ICustomInputStream.readShort();
this.transmittingFeederLoss = customerDataInputStream.readCShort(); this.transmittingFeederLoss = ICustomInputStream.readShort();
this.receivingFeederLoss = customerDataInputStream.readCShort(); this.receivingFeederLoss = ICustomInputStream.readShort();
this.otherLoss = customerDataInputStream.readCShort(); this.otherLoss = ICustomInputStream.readShort();
this.reserved = customerDataInputStream.readNBytes(46); this.reserved = ICustomInputStream.readNBytes(46);
} }
} }

38
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/domain/TaskConfiguration.java

@ -3,7 +3,7 @@ package com.xiaowuler.radarresolver.weather.domain;
import java.io.IOException; import java.io.IOException;
import lombok.Data; import lombok.Data;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.ICustomInputStream;
import com.xiaowuler.radarresolver.util.ByteUtils; import com.xiaowuler.radarresolver.util.ByteUtils;
/** /**
@ -120,23 +120,23 @@ public class TaskConfiguration {
*/ */
private byte[] reserved; private byte[] reserved;
public TaskConfiguration(CustomerDataInputStream customerDataInputStream) throws IOException { public TaskConfiguration(ICustomInputStream ICustomInputStream) throws IOException {
this.taskName = ByteUtils.bytes2String(customerDataInputStream.readNBytes(32)); this.taskName = ByteUtils.bytes2String(ICustomInputStream.readNBytes(32));
this.taskDescription = ByteUtils.bytes2String(customerDataInputStream.readNBytes(128)); this.taskDescription = ByteUtils.bytes2String(ICustomInputStream.readNBytes(128));
this.polarizationType = customerDataInputStream.readCInt(); this.polarizationType = ICustomInputStream.readInt();
this.scanType = customerDataInputStream.readCInt(); this.scanType = ICustomInputStream.readInt();
this.pulseWidth = customerDataInputStream.readCInt(); this.pulseWidth = ICustomInputStream.readInt();
this.scanStartTime = customerDataInputStream.readCInt(); this.scanStartTime = ICustomInputStream.readInt();
this.cutNumber = customerDataInputStream.readCInt(); this.cutNumber = ICustomInputStream.readInt();
this.horizontalNoise = customerDataInputStream.readCFloat(); this.horizontalNoise = ICustomInputStream.readFloat();
this.verticalNoise = customerDataInputStream.readCFloat(); this.verticalNoise = ICustomInputStream.readFloat();
this.horizontalCalibration = customerDataInputStream.readCFloat(); this.horizontalCalibration = ICustomInputStream.readFloat();
this.verticalCalibration = customerDataInputStream.readCFloat(); this.verticalCalibration = ICustomInputStream.readFloat();
this.horizontalNoiseTemperature = customerDataInputStream.readCFloat(); this.horizontalNoiseTemperature = ICustomInputStream.readFloat();
this.verticalNoiseTemperature = customerDataInputStream.readCFloat(); this.verticalNoiseTemperature = ICustomInputStream.readFloat();
this.ZDRCalibration = customerDataInputStream.readCFloat(); this.ZDRCalibration = ICustomInputStream.readFloat();
this.PHIDPCalibration = customerDataInputStream.readCFloat(); this.PHIDPCalibration = ICustomInputStream.readFloat();
this.LDRCalibration = customerDataInputStream.readCFloat(); this.LDRCalibration = ICustomInputStream.readFloat();
this.reserved = customerDataInputStream.readNBytes(40); this.reserved = ICustomInputStream.readNBytes(40);
} }
} }

27
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/enums/RadarSuffixEnum.java

@ -0,0 +1,27 @@
package com.xiaowuler.radarresolver.weather.enums;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
/**
* @describe: 雷达文件枚举
* @author: xiaowuler
* @createTime: 2022-03-18 09:19
*/
@AllArgsConstructor
public enum RadarSuffixEnum {
/**
* 二进制 文件 后缀名
*/
BIN(".bin"),
/**
* 压缩文件 后缀名
*/
BZIP2(".bz2");
@Getter
private final String type;
}

57
04.系统编码/03.radar-resolver/src/main/java/com/xiaowuler/radarresolver/weather/resolver/RadarReader.java

@ -1,17 +1,14 @@
package com.xiaowuler.radarresolver.weather.resolver; package com.xiaowuler.radarresolver.weather.resolver;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import com.xiaowuler.radarresolver.customer.CustomerDataInputStream; import com.xiaowuler.radarresolver.custom.impl.CustomRadarInputStream;
import com.xiaowuler.radarresolver.exceptions.RadarReadException;
import com.xiaowuler.radarresolver.weather.domain.*; import com.xiaowuler.radarresolver.weather.domain.*;
import org.python.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
/** /**
* @describe: radar reader * @describe: radar reader
@ -24,47 +21,23 @@ public class RadarReader {
private static final double DEG2RAD = Math.PI / 180; private static final double DEG2RAD = Math.PI / 180;
private RadarBlock radarBlock; private RadarBlock radarBlock;
public void read(String filepath) { public void read(String filepath) throws RadarReadException {
FileInputStream fileInputStream = null; CustomRadarInputStream customRadarInputStream = null;
CustomerDataInputStream customerDataInputStream = null; try {
try{ customRadarInputStream = new CustomRadarInputStream(filepath);
fileInputStream = new FileInputStream(filepath); CustomRadarInputStream finalCustomRadarInputStream = customRadarInputStream;
customerDataInputStream = new CustomerDataInputStream(fileInputStream);
CustomerDataInputStream finalCustomerDataInputStream = customerDataInputStream;
this.radarBlock = new RadarBlock(){{ this.radarBlock = new RadarBlock(){{
setCommonBlock(new CommonBlock(finalCustomerDataInputStream)); setCommonBlock(new CommonBlock(finalCustomRadarInputStream));
setRadialBlock(new RadialBlock(finalCustomerDataInputStream)); setRadialBlock(new RadialBlock(finalCustomRadarInputStream));
}}; }};
}catch (Exception e){ } catch (Exception e) {
log.error("文件:【{}】解析失败,原因:{}", filepath, e.getMessage()); log.error("雷达文件:[" + filepath + "]读取失败", e);
}finally { throw new RadarReadException(e);
if (Objects.nonNull(fileInputStream)){ } finally {
try { if (Objects.nonNull(customRadarInputStream)){
fileInputStream.close(); customRadarInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (Objects.nonNull(customerDataInputStream)){
try {
customerDataInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} }
} }
public void readBiz2(String filepath){
try{
BZip2CompressorInputStream bis = new BZip2CompressorInputStream(new FileInputStream(filepath));
System.out.println(bis.readAllBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} }
/** /**

13
04.系统编码/03.radar-resolver/src/test/java/com/xiaowuler/radarresolver/RadarResolverApplicationTests.java

@ -6,18 +6,23 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import com.xiaowuler.radarresolver.exceptions.RadarReadException;
import com.xiaowuler.radarresolver.weather.resolver.RadarReader; import com.xiaowuler.radarresolver.weather.resolver.RadarReader;
@SpringBootTest @SpringBootTest
class RadarResolverApplicationTests { class RadarResolverApplicationTests {
@Test @Test
void contextLoads() throws IOException { void contextLoads() throws RadarReadException {
RadarReader radarReader = new RadarReader(); RadarReader radarReader = new RadarReader();
radarReader.read("C:\\Users\\xiaowuler\\Desktop\\Z_RADR_I_Z9551_20210712000134_O_DOR_SA_CAP_FMT.bin"); radarReader.read("C:\\Users\\xiaowuler\\Desktop\\test\\Z_RADR_I_Z9551_20210712000134_O_DOR_SA_CAP_FMT.bin\\Z_RADR_I_Z9551_20210712000134_O_DOR_SA_CAP_FMT.bin");
// double[] latLngs = radarReader.calcLonLat(1839 * 0.25f, 164.5f, 0.68f, 117.23944f, 31.866112f);
List<List<double[]>> coordinate = radarReader.getCoordinate(); // byte[] ss = radarReader.readBiz2("C:\\Users\\xiaowuler\\Desktop\\test\\Z_RADR_I_Z9551_20210712000134_O_DOR_SA_CAP_FMT.bin.bz2");
System.out.println(); System.out.println();
// radarReader.read("C:\\Users\\xiaowuler\\Desktop\\Z_RADR_I_Z9551_20210712000134_O_DOR_SA_CAP_FMT.bin");
// double[] latLngs = radarReader.calcLonLat(1839 * 0.25f, 164.5f, 0.68f, 117.23944f, 31.866112f);
// List<List<double[]>> coordinate = radarReader.getCoordinate();
// System.out.println();
// //
// List<Map<String, Object>> values = new ArrayList<>(){{ // List<Map<String, Object>> values = new ArrayList<>(){{
// add(new HashMap<>(){{ // add(new HashMap<>(){{

Loading…
Cancel
Save