修改读取Spc文件方法
修改Extrapolation分析接口中返回内容字母大小写问题
This commit is contained in:
parent
6a456f7b8f
commit
191bff95ab
|
@ -1,91 +0,0 @@
|
|||
package org.jeecg.modules.base.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SpcHead1 {
|
||||
|
||||
public SpcHead1() {
|
||||
// 需根据谱改变
|
||||
EngPrNum = 3;
|
||||
EffNum = 0;
|
||||
SpcRecNum = 0;
|
||||
SpcChnNum = 0;
|
||||
|
||||
// 重要指针
|
||||
AcqInfRP = 2;
|
||||
CalRP1 = 5;
|
||||
CalRP2 = 7;
|
||||
EffRP = 14;
|
||||
EngPrRP = 11;
|
||||
SpcFirstRP = 68;
|
||||
|
||||
Inftyp = 1;
|
||||
Filtyp = 1;
|
||||
Reserved1 = 1;
|
||||
Reserved2 = 0;
|
||||
SamDesRP = 3;
|
||||
DetDesRP = 4;
|
||||
EbrDesRP = 0;
|
||||
AnaRP1 = 31;
|
||||
AnaRP2 = 37;
|
||||
AnaRP3 = 46;
|
||||
AnaRP4 = 56;
|
||||
SrpDesRP = 0;
|
||||
IeqDesRP = 0;
|
||||
GeoDesRP = 0;
|
||||
MpcDesRP = 0;
|
||||
CalDesRP = 10;
|
||||
ROI1 = 65;
|
||||
Reserved3 = 0;
|
||||
DDP = 0;
|
||||
ActUnit = 0;
|
||||
LabPerRP = 55;
|
||||
MaxNumE = 323;
|
||||
MaxNumU = 323;
|
||||
Abstch = 0;
|
||||
AcqTime = 12631.7f;
|
||||
AcqTime8 = 12631.7;
|
||||
}
|
||||
|
||||
public short Inftyp; //1:整形SPC文件的标志 必须为“1”
|
||||
public short Filtyp; //2:整形SPC文件的标志 必须为“1”
|
||||
public short Reserved1; //3:Reserved
|
||||
public short Reserved2; //4:Reserved
|
||||
public short AcqInfRP; //5:Acquisition Information Record pointer
|
||||
public short SamDesRP; //6:Sample Description Record pointer
|
||||
public short DetDesRP; //7:Detector Description Record pointer
|
||||
public short EbrDesRP; //8:EBAR Description Record
|
||||
|
||||
public short AnaRP1; //9:First Analysis Parameters Record pointer
|
||||
public short AnaRP2; //10:Second Analysis Parameters Record pointer
|
||||
public short AnaRP3; //11:Third Analysis Parameters Record pointer
|
||||
public short AnaRP4; //12:Fourth Analysis Parameters Record pointer
|
||||
public short SrpDesRP; //13:Absorption Correction Description Record pointer
|
||||
public short IeqDesRP; //14:IEQ Description Record pointer
|
||||
public short GeoDesRP; //15:Geometry Correction Description Record pointer
|
||||
public short MpcDesRP; //16:MPC Description Record pointer
|
||||
|
||||
public short CalDesRP; //17:Calibration Description Record pointer
|
||||
public short CalRP1; //18:First Calibration Data Record pointer
|
||||
public short CalRP2; //19:Second Calibration Data Record pointer
|
||||
public short EffRP; //20:Efficiency Pairs Record pointer(first record)
|
||||
public short ROI1; //21:Record Number of the first of the two ROI records
|
||||
public short EngPrRP; //22:Energe pairs record pointer
|
||||
public short EngPrNum; //23:Number of energy pair records
|
||||
public short Reserved3; //24:Reserved
|
||||
|
||||
public short DDP; //25:Disable deconvolution of unknown peaks
|
||||
public short ActUnit; //26:True=microCuries,false=becquerels
|
||||
public short LabPerRP; //27:Laboratory and operator name record pointer
|
||||
public short MaxNumE; //28:Maximum Record Number Ever Used
|
||||
public short MaxNumU; //29:Maximum Record Number In Use
|
||||
public short EffNum; //30:Number of Efficiency Pairs Records(See public short 20)
|
||||
public short SpcFirstRP; //31:Spectrum Record pointer (pointer to first record)
|
||||
public short SpcRecNum; //32:Number of records in the spectrum
|
||||
|
||||
public short SpcChnNum; //33:Number of channels in spectrum
|
||||
public short Abstch; //34:Physical start channel for data
|
||||
public float AcqTime; //35,36:Date and Time of acquisition start in DECDAY format
|
||||
public double AcqTime8; //37,40:Date and Time as double precision DECDAY
|
||||
}
|
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.enums.FtransitEnum;
|
||||
import org.jeecg.modules.entity.vo.FileData;
|
||||
import org.jeecg.modules.entity.vo.SpcHead1;
|
||||
import org.jeecg.modules.entity.vo.SpcHead2;
|
||||
import org.jeecg.modules.native_jni.EnergySpectrumHandler;
|
||||
import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
|
@ -54,9 +54,9 @@ public class GammaFileUtil extends AbstractLogOrReport {
|
|||
private SpectrumPathProperties spectrumPathProperties;
|
||||
@Autowired
|
||||
private NameStandUtil nameStandUtil;
|
||||
|
||||
@Autowired
|
||||
private AnalysisProcess analysisProcess;
|
||||
|
||||
public boolean loadFile(String pathName, String fileName, PHDFile phd, Result result) {
|
||||
phd.setFilepath(pathName);
|
||||
phd.setFilename(fileName);
|
||||
|
@ -1366,7 +1366,7 @@ public class GammaFileUtil extends AbstractLogOrReport {
|
|||
try {
|
||||
String phdStr = mapper.writeValueAsString(phd);
|
||||
String nuclideLinesMap = mapper.writeValueAsString(mapLines);
|
||||
String strValue = CalValuesHandler.analyseSpectrum(phdStr, nuclideLinesMap, tmpFile.getAbsolutePath(), null);
|
||||
String strValue = CalValuesHandler.analyseSpectrum(phdStr, nuclideLinesMap, tmpFile.getAbsolutePath(), analysisProcess);
|
||||
Map<String, Object> parseMap = JSON.parseObject(strValue, Map.class);
|
||||
for (Map.Entry<String, Object> entry:parseMap.entrySet()) {
|
||||
if (entry.getKey().equalsIgnoreCase("bAnalyed")) {
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
package org.jeecg.modules.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SpcHead1 {
|
||||
|
||||
public SpcHead1() {
|
||||
// 需根据谱改变
|
||||
EngPrNum = 3;
|
||||
EffNum = 0;
|
||||
SpcRecNum = 0;
|
||||
SpcChnNum = 0;
|
||||
|
||||
// 重要指针
|
||||
AcqInfRP = 2;
|
||||
CalRP1 = 5;
|
||||
CalRP2 = 7;
|
||||
EffRP = 14;
|
||||
EngPrRP = 11;
|
||||
SpcFirstRP = 68;
|
||||
|
||||
Inftyp = 1;
|
||||
Filtyp = 1;
|
||||
Reserved1 = 1;
|
||||
Reserved2 = 0;
|
||||
SamDesRP = 3;
|
||||
DetDesRP = 4;
|
||||
EbrDesRP = 0;
|
||||
AnaRP1 = 31;
|
||||
AnaRP2 = 37;
|
||||
AnaRP3 = 46;
|
||||
AnaRP4 = 56;
|
||||
SrpDesRP = 0;
|
||||
IeqDesRP = 0;
|
||||
GeoDesRP = 0;
|
||||
MpcDesRP = 0;
|
||||
CalDesRP = 10;
|
||||
ROI1 = 65;
|
||||
Reserved3 = 0;
|
||||
DDP = 0;
|
||||
ActUnit = 0;
|
||||
LabPerRP = 55;
|
||||
MaxNumE = 323;
|
||||
MaxNumU = 323;
|
||||
Abstch = 0;
|
||||
AcqTime = 12631.7f;
|
||||
AcqTime8 = 12631.7;
|
||||
}
|
||||
|
||||
public short Inftyp; //1:整形SPC文件的标志 必须为“1”
|
||||
public short Filtyp; //2:整形SPC文件的标志 必须为“1”
|
||||
public short Reserved1; //3:Reserved
|
||||
public short Reserved2; //4:Reserved
|
||||
public short AcqInfRP; //5:Acquisition Information Record pointer
|
||||
public short SamDesRP; //6:Sample Description Record pointer
|
||||
public short DetDesRP; //7:Detector Description Record pointer
|
||||
public short EbrDesRP; //8:EBAR Description Record
|
||||
|
||||
public short AnaRP1; //9:First Analysis Parameters Record pointer
|
||||
public short AnaRP2; //10:Second Analysis Parameters Record pointer
|
||||
public short AnaRP3; //11:Third Analysis Parameters Record pointer
|
||||
public short AnaRP4; //12:Fourth Analysis Parameters Record pointer
|
||||
public short SrpDesRP; //13:Absorption Correction Description Record pointer
|
||||
public short IeqDesRP; //14:IEQ Description Record pointer
|
||||
public short GeoDesRP; //15:Geometry Correction Description Record pointer
|
||||
public short MpcDesRP; //16:MPC Description Record pointer
|
||||
|
||||
public short CalDesRP; //17:Calibration Description Record pointer
|
||||
public short CalRP1; //18:First Calibration Data Record pointer
|
||||
public short CalRP2; //19:Second Calibration Data Record pointer
|
||||
public short EffRP; //20:Efficiency Pairs Record pointer(first record)
|
||||
public short ROI1; //21:Record Number of the first of the two ROI records
|
||||
public short EngPrRP; //22:Energe pairs record pointer
|
||||
public short EngPrNum; //23:Number of energy pair records
|
||||
public short Reserved3; //24:Reserved
|
||||
|
||||
public short DDP; //25:Disable deconvolution of unknown peaks
|
||||
public short ActUnit; //26:True=microCuries,false=becquerels
|
||||
public short LabPerRP; //27:Laboratory and operator name record pointer
|
||||
public short MaxNumE; //28:Maximum Record Number Ever Used
|
||||
public short MaxNumU; //29:Maximum Record Number In Use
|
||||
public short EffNum; //30:Number of Efficiency Pairs Records(See public short 20)
|
||||
public short SpcFirstRP; //31:Spectrum Record pointer (pointer to first record)
|
||||
public short SpcRecNum; //32:Number of records in the spectrum
|
||||
|
||||
public short SpcChnNum; //33:Number of channels in spectrum
|
||||
public short Abstch; //34:Physical start channel for data
|
||||
public float AcqTime; //35,36:Date and Time of acquisition start in DECDAY format
|
||||
public double AcqTime8; //37,40:Date and Time as double precision DECDAY
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.jeecg.modules.base.entity;
|
||||
package org.jeecg.modules.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
|
@ -1,73 +1,133 @@
|
|||
package org.jeecg.modules.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.jeecg.common.constant.DateConstant;
|
||||
import org.jeecg.modules.base.entity.SpcHead1;
|
||||
import org.jeecg.modules.base.entity.SpcHead2;
|
||||
import org.jeecg.modules.entity.vo.SpcHead1;
|
||||
import org.jeecg.modules.entity.vo.SpcHead2;
|
||||
import org.jeecg.modules.entity.vo.FileData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.*;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static java.lang.Math.pow;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Demo {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
FileData fileData = new FileData();
|
||||
String filePath = "C:\\Users\\a\\Desktop\\shift\\standard.SPC";
|
||||
String filePath = "D:\\ARMD\\材料\\201809160001P.SPC";
|
||||
// r:只读 rw:读写
|
||||
RandomAccessFile SpcFile = new RandomAccessFile(filePath, "r");
|
||||
short Inftyp;
|
||||
short Filtyp;
|
||||
byte[] buffer = new byte[2];
|
||||
SpcFile.read(buffer);
|
||||
Inftyp = byteToShort(buffer);
|
||||
SpcFile.read(buffer);
|
||||
Filtyp = byteToShort(buffer);
|
||||
if (Inftyp != 1 || Filtyp != 1) return;
|
||||
//读取第一个数据
|
||||
byte[] first = new byte[2];
|
||||
SpcFile.read(first);
|
||||
short Inftyp = Short.valueOf(convert(first, "short"));
|
||||
//读取第二个数据
|
||||
byte[] second = new byte[2];
|
||||
SpcFile.read(second);
|
||||
short Filtyp = Short.valueOf(convert(second, "short"));
|
||||
if (Inftyp != 1 || Filtyp != 1) {
|
||||
return;
|
||||
}
|
||||
// 读入整形spc文件的头记录(第一个记录)-128字节
|
||||
SpcHead1 head1 = new SpcHead1();
|
||||
SpcHead2 head2 = new SpcHead2();
|
||||
SpcFile.seek(0);
|
||||
//头部信息需要读取的字节数
|
||||
byte[] headByte1 = new byte[80];
|
||||
SpcFile.read(headByte1);
|
||||
//读取后赋值
|
||||
head1.setInftyp(Short.valueOf(convert(Arrays.copyOfRange(headByte1, 0, 2), "short")));
|
||||
head1.setFiltyp(Short.valueOf(convert(Arrays.copyOfRange(headByte1, 2, 4), "short")));
|
||||
head1.setReserved1(Short.valueOf(convert(Arrays.copyOfRange(headByte1, 4, 6), "short")));
|
||||
head1.setReserved2( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 6, 8), "short")) );
|
||||
head1.setAcqInfRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 8, 10), "short")) );
|
||||
head1.setSamDesRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 10, 12), "short")) );
|
||||
head1.setDetDesRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 12, 14), "short")) );
|
||||
head1.setEbrDesRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 14, 16), "short")) );
|
||||
head1.setAnaRP1( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 16, 18), "short")) );
|
||||
head1.setAnaRP2( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 18, 20), "short")) );
|
||||
head1.setAnaRP3( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 20, 22), "short")) );
|
||||
head1.setAnaRP4( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 22, 24), "short")) );
|
||||
head1.setSrpDesRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 24, 26), "short")) );
|
||||
head1.setIeqDesRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 26, 28), "short")) );
|
||||
head1.setGeoDesRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 28, 30), "short")) );
|
||||
head1.setMpcDesRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 30, 32), "short")) );
|
||||
head1.setCalDesRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 32, 34), "short")) );
|
||||
head1.setCalRP1( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 34, 36), "short")) );
|
||||
head1.setCalRP2( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 36, 38), "short")) );
|
||||
head1.setEffRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 38, 40), "short")) );
|
||||
head1.setROI1( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 40, 42), "short")) );
|
||||
head1.setEngPrRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 42, 44), "short")) );
|
||||
head1.setEngPrNum( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 44, 46), "short")) );
|
||||
head1.setReserved3( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 46, 48), "short")) );
|
||||
head1.setDDP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 48, 50), "short")) );
|
||||
head1.setActUnit( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 50, 52), "short")) );
|
||||
head1.setLabPerRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 52, 54), "short")) );
|
||||
head1.setMaxNumE( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 54, 56), "short")) );
|
||||
head1.setMaxNumU( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 56, 58), "short")) );
|
||||
head1.setEffNum( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 58, 60), "short")) );
|
||||
head1.setSpcFirstRP( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 60, 62), "short")) );
|
||||
head1.setSpcRecNum( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 62, 64), "short")) );
|
||||
head1.setSpcChnNum( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 64, 66), "short")) );
|
||||
head1.setAbstch( Short.valueOf(convert(Arrays.copyOfRange(headByte1, 66, 68), "short")) );
|
||||
head1.setAcqTime( Float.valueOf(convert(Arrays.copyOfRange(headByte1, 68, 72), "float")));
|
||||
head1.setAcqTime8( Double.valueOf(convert(Arrays.copyOfRange(headByte1, 72, 80), "double")));
|
||||
SpcFile.seek(78);
|
||||
byte[] headByte2 = new byte[20];
|
||||
SpcFile.read(headByte2);
|
||||
head2.setAddRAM( Short.valueOf(convert(Arrays.copyOfRange(headByte2, 0, 2), "short")) );
|
||||
head2.setSeqnum( Short.valueOf(convert(Arrays.copyOfRange(headByte2, 2, 4), "short")) );
|
||||
head2.setMcanu( Short.valueOf(convert(Arrays.copyOfRange(headByte2, 4, 6), "short")) );
|
||||
head2.setSegnum( Short.valueOf(convert(Arrays.copyOfRange(headByte2, 6, 8), "short")) );
|
||||
head2.setMcadvt( Short.valueOf(convert(Arrays.copyOfRange(headByte2, 8, 10), "short")) );
|
||||
head2.setChnsrt( Short.valueOf( convert(Arrays.copyOfRange(headByte2, 10, 12), "short")) );
|
||||
head2.setRealTime( Float.valueOf(convert(Arrays.copyOfRange(headByte2, 12, 16), "float") ) );
|
||||
head2.setLiveTime( Float.valueOf(convert(Arrays.copyOfRange(headByte2, 16, 20), "float")) );
|
||||
|
||||
// Acquisition
|
||||
// 从intspc能谱中读取能谱开测时间
|
||||
int AcqY, AcqM, AcqD, AcqH, AcqMin;
|
||||
float AcqS, AcqRT, AcqLT;
|
||||
byte[] temByte = new byte[200 * 2];
|
||||
//从intspc能谱中读取能谱开测时间
|
||||
int AcqY,AcqM,AcqD,AcqH,AcqMin;
|
||||
float AcqS,AcqRT,AcqLT;
|
||||
char[] temchar = new char[200];
|
||||
int lOffset;
|
||||
lOffset = (head1.AcqInfRP - 1) * 128;
|
||||
SpcFile.seek((lOffset + 16) * 2);
|
||||
SpcFile.read(temByte, 0, 12 * 2);
|
||||
char[] temchar = byteToChar(temByte);
|
||||
char char1, char2;
|
||||
char1 = temchar[7];
|
||||
char2 = temchar[8];
|
||||
if (temchar[9] == '0') {
|
||||
temchar[7] = '1';
|
||||
temchar[8] = '9';
|
||||
} else {
|
||||
temchar[7] = '2';
|
||||
temchar[8] = '0';
|
||||
}
|
||||
temchar[9] = char1;
|
||||
temchar[10] = char2;
|
||||
temchar[11] = '\0';
|
||||
|
||||
AcqY = 0;
|
||||
for (int i = 7; i < 11; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
AcqY = (int) (AcqY + temchar[i] * pow(10, 10 - i));
|
||||
lOffset=(head1.AcqInfRP-1)*128;
|
||||
SpcFile.seek(lOffset+16);
|
||||
byte[] charByte1 = new byte[12];
|
||||
SpcFile.read(charByte1);
|
||||
for (int i=0; i<charByte1.length; i++) {
|
||||
char charAt = convert(Arrays.copyOfRange(charByte1, i, i + 1), "char").charAt(0);
|
||||
temchar[i] = charAt;
|
||||
}
|
||||
char char1,char2;
|
||||
char1=temchar[7];
|
||||
char2=temchar[8];
|
||||
if('0'==temchar[9]) {
|
||||
temchar[7]='1'; //19xx<EFBFBD><EFBFBD>
|
||||
temchar[8]='9';
|
||||
} else {
|
||||
temchar[7]='2'; //20xx<EFBFBD><EFBFBD>
|
||||
temchar[8]='0';
|
||||
}
|
||||
temchar[9]=char1;
|
||||
temchar[10]=char2;
|
||||
temchar[11]='\0';
|
||||
|
||||
AcqY=0;
|
||||
for(int i=7;i<11;i++) {
|
||||
temchar[i]= (char) (temchar[i]-48);
|
||||
AcqY= (int) (AcqY+temchar[i]*Math.pow(10,10-i));
|
||||
}
|
||||
|
||||
AcqM = 0;
|
||||
|
@ -87,49 +147,62 @@ public class Demo {
|
|||
AcqD = 0;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
AcqD = (int) (AcqD + temchar[i] * pow(10, 1 - i));
|
||||
AcqD = (int) (AcqD + temchar[i] * Math.pow(10, 1 - i));
|
||||
}
|
||||
|
||||
SpcFile.read(temByte, 0 ,10 * 2);
|
||||
temchar = byteToChar(temByte);
|
||||
byte[] charByte2 = new byte[10];
|
||||
SpcFile.read(charByte2);
|
||||
for (int i=0; i<charByte2.length; i++) {
|
||||
char charAt = convert(Arrays.copyOfRange(charByte2, i, i + 1), "char").charAt(0);
|
||||
temchar[i] = charAt;
|
||||
}
|
||||
temchar[9] = '\0';
|
||||
|
||||
AcqH = 0;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
AcqH = (int) (AcqH + temchar[i] * pow(10, 1 - i));
|
||||
AcqH = (int) (AcqH + temchar[i] * Math.pow(10, 1 - i));
|
||||
}
|
||||
AcqMin = 0;
|
||||
for (int i = 3; i < 5; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
AcqMin = (int) (AcqMin + temchar[i] * pow(10, 4 - i));
|
||||
AcqMin = (int) (AcqMin + temchar[i] * Math.pow(10, 4 - i));
|
||||
}
|
||||
AcqS = 0;
|
||||
for (int i = 6; i < 8; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
AcqS = (float) (AcqS + temchar[i] * pow(10, 7 - i));
|
||||
AcqS = (float) (AcqS + temchar[i] * Math.pow(10, 7 - i));
|
||||
}
|
||||
AcqLT = 0;
|
||||
SpcFile.read(temByte, 0, 10 * 2);
|
||||
temchar = byteToChar(temByte);
|
||||
byte[] charByte3 = new byte[10];
|
||||
SpcFile.read(charByte3);
|
||||
for (int i=0; i<charByte3.length; i++) {
|
||||
char charAt = convert(Arrays.copyOfRange(charByte3, i, i + 1), "char").charAt(0);
|
||||
temchar[i] = charAt;
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (temchar[i] == 32) {
|
||||
temchar[i] = 0;
|
||||
} else {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
}
|
||||
AcqLT = (float) (AcqLT + temchar[i] * pow(10, 9 - i));
|
||||
AcqLT = (float) (AcqLT + temchar[i] * Math.pow(10, 9 - i));
|
||||
}
|
||||
|
||||
AcqRT = 0;
|
||||
SpcFile.read(temByte, 0, 10 * 2);
|
||||
temchar = byteToChar(temByte);
|
||||
byte[] charByte4 = new byte[10];
|
||||
SpcFile.read(charByte4);
|
||||
for (int i=0; i<charByte4.length; i++) {
|
||||
char charAt = convert(Arrays.copyOfRange(charByte4, i, i + 1), "char").charAt(0);
|
||||
temchar[i] = charAt;
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (temchar[i] == 32)
|
||||
if (temchar[i] == 32) {
|
||||
temchar[i] = 0;
|
||||
else
|
||||
} else {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
AcqRT = (float) (AcqRT + temchar[i] * pow(10, 9 - i));
|
||||
}
|
||||
AcqRT = (float) (AcqRT + temchar[i] * Math.pow(10, 9 - i));
|
||||
}
|
||||
|
||||
int seconds = (int) AcqS;
|
||||
|
@ -147,11 +220,14 @@ public class Demo {
|
|||
// 从intspc能谱中读取能谱刻度时间
|
||||
int CalY, CalM, CalD, CalH, CalMin;
|
||||
float CalS;
|
||||
|
||||
lOffset = (head1.CalRP2 - 1) * 128;
|
||||
SpcFile.seek((lOffset + 32) * 2);
|
||||
SpcFile.read(temByte, 0, 10 * 2);
|
||||
temchar = byteToChar(temByte);
|
||||
SpcFile.seek(lOffset + 32);
|
||||
byte[] charByte5 = new byte[10];
|
||||
SpcFile.read(charByte5);
|
||||
for (int i=0; i<charByte5.length; i++) {
|
||||
char charAt = convert(Arrays.copyOfRange(charByte5, i, i + 1), "char").charAt(0);
|
||||
temchar[i] = charAt;
|
||||
}
|
||||
char1 = temchar[7];
|
||||
char2 = temchar[8];
|
||||
if (temchar[9] == '0') {
|
||||
|
@ -168,9 +244,10 @@ public class Demo {
|
|||
CalY = 0;
|
||||
for (int i = 7; i < 11; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
CalY = (int) (CalY + temchar[i] * pow(10, 10 - i));
|
||||
CalY = (int) (CalY + temchar[i] * Math.pow(10, 10 - i));
|
||||
}
|
||||
|
||||
CalM = 0;
|
||||
if (temchar[3] == 'J' && temchar[4] == 'a' && temchar[5] == 'n') CalM = 1;
|
||||
if (temchar[3] == 'F' && temchar[4] == 'e' && temchar[5] == 'b') CalM = 2;
|
||||
if (temchar[3] == 'M' && temchar[4] == 'a' && temchar[5] == 'r') CalM = 3;
|
||||
|
@ -187,28 +264,31 @@ public class Demo {
|
|||
CalD = 0;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
CalD = (int) (CalD + temchar[i] * pow(10, 1 - i));
|
||||
CalD = (int) (CalD + temchar[i] * Math.pow(10, 1 - i));
|
||||
}
|
||||
|
||||
CalM = 0;
|
||||
SpcFile.read(temByte, 0, 10 * 2);
|
||||
temchar = byteToChar(temByte);
|
||||
byte[] charByte6 = new byte[10];
|
||||
SpcFile.read(charByte6);
|
||||
for (int i=0; i<charByte6.length; i++) {
|
||||
char charAt = convert(Arrays.copyOfRange(charByte6, i, i + 1), "char").charAt(0);
|
||||
temchar[i] = charAt;
|
||||
}
|
||||
temchar[9] = '\0';
|
||||
|
||||
CalH = 0;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
CalH = (int) (CalH + temchar[i] * pow(10, 1 - i));
|
||||
CalH = (int) (CalH + temchar[i] * Math.pow(10, 1 - i));
|
||||
}
|
||||
CalMin = 0;
|
||||
for (int i = 3; i < 5; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
CalMin = (int) (CalMin + temchar[i] * pow(10, 4 - i));
|
||||
CalMin = (int) (CalMin + temchar[i] * Math.pow(10, 4 - i));
|
||||
}
|
||||
CalS = 0;
|
||||
for (int i = 6; i < 8; i++) {
|
||||
temchar[i] = (char) (temchar[i] - 48);
|
||||
CalS = (float) (CalS + temchar[i] * pow(10, 7 - i));
|
||||
CalS = (float) (CalS + temchar[i] * Math.pow(10, 7 - i));
|
||||
}
|
||||
|
||||
int cal_s = (int) CalS;
|
||||
|
@ -218,114 +298,178 @@ public class Demo {
|
|||
fileData.setCalibra_time(calibra_time);
|
||||
|
||||
// g_Energy g_Resolution
|
||||
if (head1.EngPrRP > 0) // 存在能量刻度
|
||||
{
|
||||
// 从intspc能谱中读取能谱刻度信息
|
||||
byte[] cerByte = new byte[32 * 4];
|
||||
byte[] engByte = new byte[32 * 4];
|
||||
byte[] fWHMByte = new byte[32 * 4];
|
||||
if (head1.EngPrRP > 0) { // 存在能量刻度
|
||||
//从intspc能谱中读取能谱刻度信息
|
||||
float[] Eng = new float[32];
|
||||
float[] Cer = new float[32];
|
||||
float[] FWHM = new float[32];
|
||||
|
||||
lOffset = (head1.EngPrRP - 1) * 128;
|
||||
SpcFile.seek(lOffset * 2L);
|
||||
SpcFile.read(cerByte, 0, 128 * 2);
|
||||
float[] Cer = byteToFloats(cerByte);
|
||||
SpcFile.read(engByte, 0, 128 * 2);
|
||||
float[] Eng = byteToFloats(engByte);
|
||||
SpcFile.read(fWHMByte, 0, 128 * 2);
|
||||
float[] FWHM = byteToFloats(fWHMByte);
|
||||
|
||||
short EngNum;
|
||||
byte[] engNumByte = new byte[4];
|
||||
lOffset = (head1.CalRP1 - 1) * 128;
|
||||
SpcFile.seek((lOffset + 74) * 2L);
|
||||
SpcFile.read(engNumByte, 0, 2 * 2);
|
||||
EngNum = byteToShort(engNumByte);
|
||||
|
||||
float CerUnc = 0.5F;
|
||||
for (int i = 0; i < EngNum; i++) {
|
||||
fileData.getVvEner().get(0).add((double) Eng[i]);
|
||||
fileData.getVvEner().get(1).add((double) Cer[i]);
|
||||
fileData.getVvEner().get(2).add((double) CerUnc);
|
||||
lOffset=(head1.EngPrRP-1)*128;
|
||||
SpcFile.seek(lOffset);
|
||||
byte[] cerByte = new byte[128];
|
||||
byte[] engByte = new byte[128];
|
||||
byte[] fwhmByte = new byte[128];
|
||||
SpcFile.read(cerByte);
|
||||
int j = 0;
|
||||
for (int i=0; i<cerByte.length; i+=4) {
|
||||
Float value = Float.valueOf(convert(Arrays.copyOfRange(cerByte, i, i+4), "float"));
|
||||
Cer[j] = value;
|
||||
j++;
|
||||
}
|
||||
if (EngNum > 1) {
|
||||
int i1 = 1, i2 = EngNum - 2;
|
||||
if (EngNum < 4) {
|
||||
SpcFile.read(engByte);
|
||||
j = 0;
|
||||
for (int i=0; i<engByte.length; i+=4) {
|
||||
Float value = Float.valueOf(convert(Arrays.copyOfRange(engByte, i, i+4), "float"));
|
||||
Eng[j] = value;
|
||||
j++;
|
||||
}
|
||||
SpcFile.read(fwhmByte);
|
||||
j = 0;
|
||||
for (int i=0; i<fwhmByte.length; i+=4) {
|
||||
Float value = Float.valueOf(convert(Arrays.copyOfRange(fwhmByte, i, i+4), "float"));
|
||||
FWHM[j] = value;
|
||||
j++;
|
||||
}
|
||||
short EngNum;
|
||||
lOffset=(head1.CalRP1-1)*128;
|
||||
SpcFile.seek( lOffset+74 );
|
||||
byte[] engNumByte = new byte[2];
|
||||
SpcFile.read(engNumByte);
|
||||
EngNum = Short.valueOf(convert(engNumByte, "short"));
|
||||
|
||||
float CerUnc= 0.5f;
|
||||
for(int i=0; i<EngNum; i++) {
|
||||
fileData.getVvEner().get(0).add(Double.valueOf(Eng[i]));
|
||||
fileData.getVvEner().get(1).add(Double.valueOf(Cer[i]));
|
||||
fileData.getVvEner().get(2).add(Double.valueOf(CerUnc));
|
||||
}
|
||||
if(EngNum > 1) {
|
||||
int i1 = 1;
|
||||
int i2 = EngNum - 2;
|
||||
if(EngNum < 4) {
|
||||
i1 = 0;
|
||||
i2 = EngNum - 1;
|
||||
}
|
||||
fileData.setEner_slope((double) ((Eng[i2] - Eng[i1]) / (Cer[i2] - Cer[i1])));
|
||||
double v1 = fileData.getVvEner().get(0).get(i1) * fileData.getVvEner().get(1).get(i2);
|
||||
double v2 = fileData.getVvEner().get(0).get(i2) * fileData.getVvEner().get(1).get(i1);
|
||||
double v3 = fileData.getVvEner().get(1).get(i2) - fileData.getVvEner().get(1).get(i1);
|
||||
fileData.setEner_intercept((v1 - v2) / v3);
|
||||
fileData.setEner_slope(Double.valueOf(Eng[i2]-Eng[i1])/(Cer[i2]-Cer[i1]));
|
||||
fileData.setEner_intercept(Double.valueOf(fileData.getVvEner().get(0).get(i1) * fileData.getVvEner().get(1).get(i2) - fileData.getVvEner().get(0).get(i2) * fileData.getVvEner().get(1).get(i1)) / (fileData.getVvEner().get(1).get(i2) - fileData.getVvEner().get(1).get(i1)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < EngNum; i++) {
|
||||
fileData.getVvReso().get(0).add((double) Eng[i]);
|
||||
fileData.getVvReso().get(1).add(FWHM[i] * fileData.getEner_slope());
|
||||
fileData.getVvReso().get(2).add((double) CerUnc);
|
||||
for(int i=0; i<EngNum; i++) {
|
||||
fileData.getVvReso().get(0).add(Double.valueOf(Eng[i]));
|
||||
fileData.getVvReso().get(1).add(Double.valueOf(FWHM[i]*fileData.getEner_slope()));
|
||||
fileData.getVvReso().get(2).add(Double.valueOf(CerUnc));
|
||||
}
|
||||
}
|
||||
|
||||
// g_Efficiency
|
||||
if (head1.EffRP > 0) { // 存在效率刻度
|
||||
byte[] effNumByte = new byte[4];
|
||||
lOffset = (head1.CalRP1 - 1) * 128;
|
||||
SpcFile.seek((lOffset + 4) * 2L);
|
||||
SpcFile.read(effNumByte,0,2);
|
||||
short EffNum = byteToShort(effNumByte);
|
||||
if(head1.EffRP>0) { //存在效率刻度
|
||||
short EffNum = 0;
|
||||
lOffset=(head1.CalRP1-1)*128;
|
||||
SpcFile.seek( lOffset+4 );
|
||||
byte[] effByte = new byte[2];
|
||||
SpcFile.read(effByte);
|
||||
EffNum = Short.valueOf(convert(effByte, "short"));
|
||||
|
||||
// 0,2,4等偶数存放能量,1,3,5等奇数存放效率
|
||||
byte[] effByte = new byte[32 * 4];
|
||||
float EffUnc = 0.5F;
|
||||
float[] Eff = new float[32];//0,2,4等偶数存放能量,1,3,5等奇数存放效率
|
||||
float EffUnc=0.5f;
|
||||
|
||||
lOffset = (head1.EffRP - 1) * 128;
|
||||
SpcFile.seek(lOffset * 2L);
|
||||
SpcFile.read(effByte, 0, 128 * 2);
|
||||
float[] Eff = byteToFloats(effByte);
|
||||
lOffset=(head1.EffRP-1)*128;
|
||||
SpcFile.seek( lOffset );
|
||||
byte[] effByte2 = new byte[128];
|
||||
SpcFile.read(effByte2);
|
||||
int j=0;
|
||||
for (int i=0; i<effByte2.length; i+=4) {
|
||||
Float value = Float.valueOf(convert(Arrays.copyOfRange(effByte2, i, i+4), "float"));
|
||||
Eff[j] = value;
|
||||
j++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < EffNum; i++) {
|
||||
fileData.getVvEffi().get(0).add((double) Eff[i * 2]);
|
||||
fileData.getVvEffi().get(1).add((double) Eff[i * 2 + 1]);
|
||||
fileData.getVvEffi().get(2).add((double) EffUnc);
|
||||
for(int i=0; i<EffNum; i++) {
|
||||
fileData.getVvEffi().get(0).add(Double.valueOf(Eff[i*2]));
|
||||
fileData.getVvEffi().get(1).add(Double.valueOf(Eff[i*2+1]));
|
||||
fileData.getVvEffi().get(2).add(Double.valueOf(EffUnc));
|
||||
}
|
||||
}
|
||||
|
||||
// Spectrum
|
||||
byte[] SpcDataByte = new byte[100000];
|
||||
int[] SpcData = new int[100000];
|
||||
|
||||
fileData.setNum_count(head1.SpcChnNum);
|
||||
fileData.setStart_chan(head2.Chnsrt);
|
||||
|
||||
float EngA, EngB, EngC;
|
||||
byte[] engAByte = new byte[8];
|
||||
byte[] engBByte = new byte[8];
|
||||
byte[] engCByte = new byte[8];
|
||||
lOffset = (head1.CalRP1 - 1) * 128;
|
||||
SpcFile.seek((lOffset + 20) * 2L);
|
||||
SpcFile.read(engAByte,0, 4 * 2);
|
||||
SpcFile.read(engBByte,0, 4 * 2);
|
||||
SpcFile.read(engCByte,0, 4 * 2);
|
||||
EngA = byteToFloat(engAByte);
|
||||
EngB = byteToFloat(engBByte);
|
||||
EngC = byteToFloat(engCByte);
|
||||
int numCount = fileData.getNum_count();
|
||||
int max_energy = (int) (EngA + EngB * numCount +
|
||||
EngC * pow(numCount, 2));
|
||||
fileData.setMax_energy(max_energy);
|
||||
float EngA,EngB,EngC;
|
||||
lOffset=(head1.CalRP1-1)*128;
|
||||
SpcFile.seek( lOffset+20 );
|
||||
|
||||
lOffset = (head1.SpcFirstRP - 1) * 128;
|
||||
SpcFile.seek(lOffset * 2L);
|
||||
SpcFile.read(SpcDataByte, 0, numCount * 4 * 2);
|
||||
int[] SpcData = byteToInts(SpcDataByte);
|
||||
byte[] engAByte = new byte[4];
|
||||
SpcFile.read(engAByte);
|
||||
EngA = Float.valueOf(convert(engAByte, "float"));
|
||||
|
||||
for (int i = 0; i < numCount; i++) {
|
||||
fileData.getVCounts().add((long) SpcData[i]);
|
||||
byte[] engBByte = new byte[4];
|
||||
SpcFile.read(engBByte);
|
||||
EngB = Float.valueOf(convert(engBByte, "float"));
|
||||
|
||||
byte[] engCByte = new byte[4];
|
||||
SpcFile.read(engCByte);
|
||||
EngC = Float.valueOf(convert(engCByte, "float"));
|
||||
|
||||
fileData.setMax_energy((int) (EngA + EngB * fileData.getNum_count() + EngC * Math.pow(fileData.getNum_count(), 2)));
|
||||
|
||||
lOffset=(head1.SpcFirstRP-1)*128;
|
||||
SpcFile.seek( lOffset );
|
||||
byte[] spcDataByte = new byte[fileData.getNum_count()*4];
|
||||
SpcFile.read(spcDataByte);
|
||||
int j=0;
|
||||
for (int i=0; i<spcDataByte.length; i+=4) {
|
||||
Integer value = Integer.valueOf(convert(Arrays.copyOfRange(spcDataByte, i, i + 4), "int"));
|
||||
SpcData[j] = value;
|
||||
j++;
|
||||
}
|
||||
|
||||
for(int i=0; i<fileData.getNum_count(); i++) {
|
||||
fileData.getVCounts().add(Long.valueOf(SpcData[i]));
|
||||
}
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String writeValueAsString = mapper.writeValueAsString(fileData);
|
||||
System.out.println(writeValueAsString);
|
||||
SpcFile.close();
|
||||
}
|
||||
|
||||
public static String convert(byte[] bytes, String type) {
|
||||
List<String> values = new LinkedList<>();
|
||||
for (int i=0; i<bytes.length; i++) {
|
||||
byte b = bytes[i];
|
||||
int decimalValue = Byte.toUnsignedInt(b); // 将byte转换为十进制
|
||||
String hexString = Integer.toHexString(decimalValue);// 十进制转十六进制
|
||||
values.add(hexString);
|
||||
}
|
||||
String index = "";
|
||||
for (int i=values.size()-1; i>=0; i--) {
|
||||
if (values.get(i).equals("0")) {
|
||||
index+="00";
|
||||
} else {
|
||||
index+=values.get(i);
|
||||
}
|
||||
}
|
||||
if (type.equalsIgnoreCase("short")) {
|
||||
short shortValue = new BigInteger(index, 16).shortValue();
|
||||
return String.valueOf(shortValue);
|
||||
} else if (type.equalsIgnoreCase("int")) {
|
||||
int intValue = new BigInteger(index, 16).intValue();
|
||||
return String.valueOf(intValue);
|
||||
} else if (type.equalsIgnoreCase("char")) {
|
||||
int decimal = Integer.parseInt(index, 16);
|
||||
char charValue = (char) decimal;
|
||||
return String.valueOf(charValue);
|
||||
} else if (type.equalsIgnoreCase("float")){
|
||||
float floatValue = Float.intBitsToFloat(new BigInteger(index, 16).intValue());
|
||||
return String.valueOf(floatValue);
|
||||
} else if (type.equalsIgnoreCase("double")) {
|
||||
double doubleValue = Double.longBitsToDouble(Long.parseLong(index, 16));
|
||||
return String.valueOf(doubleValue);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static char[] byteToChar(byte[] data) throws CharacterCodingException {
|
||||
/*return new String(data, StandardCharsets.UTF_16).toCharArray();*/
|
||||
|
@ -377,4 +521,5 @@ public class Demo {
|
|||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
return buffer.getShort();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2290,9 +2290,9 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
|
|||
right.setY(rData.get(0));
|
||||
line_serise_data.add(left);
|
||||
line_serise_data.add(right);
|
||||
functionFit = "Y = A*X + B ";
|
||||
functionFit = "y = a*x + b ";
|
||||
if (scatter_serise_data.size()>1) {
|
||||
functionFit = String.format("Y = %f*X + %f ", fittingPara.get(0), fittingPara.get(1));
|
||||
functionFit = String.format("y = %f*x + %f ", fittingPara.get(0), fittingPara.get(1));
|
||||
}
|
||||
} else if(fittype.equals("poly2")) {
|
||||
for(int i=1;i<51;i++) {
|
||||
|
@ -2305,12 +2305,12 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
|
|||
temp.setY(rData.get(0));
|
||||
line_serise_data.add(temp);
|
||||
}
|
||||
functionFit = "Y = A+ B*X + C*X^2 ";
|
||||
functionFit = "y = a+ b*x + c*x^2 ";
|
||||
if (scatter_serise_data.size()>1) {
|
||||
functionFit = String.format("Y = %f+ %f*X + C*%f^2 ",fittingPara.get(0),fittingPara.get(1),fittingPara.get(2));
|
||||
functionFit = String.format("y = %f+ %f*x + %f*x^2 ",fittingPara.get(0),fittingPara.get(1),fittingPara.get(2));
|
||||
}
|
||||
} else if(fittype.equals("poly3")) {
|
||||
functionFit = "Y = A+ B*X + C*X^2 +D*X^3 ";
|
||||
functionFit = "y = a+ b*x + c*x^2 +d*x^3 ";
|
||||
}
|
||||
List<TableExtData> extDataList = new LinkedList<>();
|
||||
for(int i=0;i<Nx.size()&&i<Ny.size()&&i<Eb.size();i++) {
|
||||
|
@ -2321,11 +2321,11 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService {
|
|||
extData.setNy( Double.valueOf(NumberFormatUtil.numberFormat(String.valueOf(Ny.get(i)))) );
|
||||
extDataList.add(extData);
|
||||
}
|
||||
String refTime = "Reference Time: ";
|
||||
String xeAct = "Xe Activity (Bq): ";
|
||||
String refTime = "";
|
||||
String xeAct = "";
|
||||
if (scatter_serise_data.size()>1) {
|
||||
refTime = String.format("Reference Time: %s ",sampleTmp.acquisition_start_date+" "+sampleTmp.acquisition_start_time);
|
||||
xeAct = String.format("Xe Activity (Bq): %f", Xe_activity);
|
||||
refTime = sampleTmp.acquisition_start_date+" "+sampleTmp.acquisition_start_time;
|
||||
xeAct = String.valueOf(Xe_activity);
|
||||
}
|
||||
map.put("tableData", extDataList);
|
||||
map.put("functionFit", functionFit);
|
||||
|
|
Loading…
Reference in New Issue
Block a user