删除Demo文件

This commit is contained in:
qiaoqinzheng 2023-10-20 10:30:34 +08:00
parent b9f5e68f9e
commit a692442c22

View File

@ -1,579 +0,0 @@
package org.jeecg.modules.controller;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jeecg.common.constant.DateConstant;
import org.jeecg.common.util.FileFtransitUtil;
import org.jeecg.modules.entity.vo.*;
import org.jeecg.modules.native_jni.CalValuesHandler;
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.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class Demo {
public static void main(String[] args) throws IOException {
System.loadLibrary("ReadPHDFile");
System.loadLibrary("GammaAnaly");
FileData datas = new FileData();
File imsFile = new File("D:\\ARMD\\材料\\spc-ims\\201809160001P.Ims");
FileFtransitUtil.ReadIMS(imsFile, datas);
File spcFile = new File("D:\\ARMD\\材料\\spc-ims\\test.SPC");
// r:只读 rw:读写
RandomAccessFile SpcFile = new RandomAccessFile(spcFile.getAbsolutePath(), "rw");
//分析SPC文件并创建所需要的spc文件的基础内容
SpcHead1 m_head1 = new SpcHead1();
SpcHead2 m_head2 = new SpcHead2();
GermaniumCalib m_calibParam = new GermaniumCalib();
byte[] m_totalContents = AnalyseSPC(m_head1, m_head2, m_calibParam);
if(m_totalContents.length<=0) {
String Warning = "The file standard.spc isn't exist or it's format is invalid.";
}
//SpcFile写入内容
SpcFile.write(m_totalContents);
// 写第1个128字节头部指针信息
{
MakeSpcHead(datas, m_head1, m_head2);
SpcFile.seek(0);
byte[] head1 = new byte[80];
//使用系统的赋值数组 来源数组 开始下标 目标数组 开始下标 长度
System.arraycopy(writeShort(m_head1.Inftyp), 0, head1, 0, 2);
System.arraycopy(writeShort(m_head1.Filtyp), 0, head1, 2, 2);
System.arraycopy(writeShort(m_head1.Reserved1), 0, head1, 4, 2);
System.arraycopy(writeShort(m_head1.Reserved2), 0, head1, 6, 2);
System.arraycopy(writeShort(m_head1.AcqInfRP), 0, head1, 8, 2);
System.arraycopy(writeShort(m_head1.SamDesRP), 0, head1, 10, 2);
System.arraycopy(writeShort(m_head1.DetDesRP), 0, head1, 12, 2);
System.arraycopy(writeShort(m_head1.EbrDesRP), 0, head1, 14, 2);
System.arraycopy(writeShort(m_head1.AnaRP1), 0, head1, 16, 2);
System.arraycopy(writeShort(m_head1.AnaRP2), 0, head1, 18, 2);
System.arraycopy(writeShort(m_head1.AnaRP3), 0, head1, 20, 2);
System.arraycopy(writeShort(m_head1.AnaRP4), 0, head1, 22, 2);
System.arraycopy(writeShort(m_head1.SrpDesRP), 0, head1, 24, 2);
System.arraycopy(writeShort(m_head1.IeqDesRP), 0, head1, 26, 2);
System.arraycopy(writeShort(m_head1.GeoDesRP), 0, head1, 28, 2);
System.arraycopy(writeShort(m_head1.MpcDesRP), 0, head1, 30, 2);
System.arraycopy(writeShort(m_head1.CalDesRP), 0, head1, 32, 2);
System.arraycopy(writeShort(m_head1.CalRP1), 0, head1, 34, 2);
System.arraycopy(writeShort(m_head1.CalRP2), 0, head1, 36, 2);
System.arraycopy(writeShort(m_head1.EffRP), 0, head1, 38, 2);
System.arraycopy(writeShort(m_head1.ROI1), 0, head1, 40, 2);
System.arraycopy(writeShort(m_head1.EngPrRP), 0, head1, 42, 2);
System.arraycopy(writeShort(m_head1.EngPrNum), 0, head1, 44, 2);
System.arraycopy(writeShort(m_head1.Reserved3), 0, head1, 46, 2);
System.arraycopy(writeShort(m_head1.DDP), 0, head1, 48, 2);
System.arraycopy(writeShort(m_head1.ActUnit), 0, head1, 50, 2);
System.arraycopy(writeShort(m_head1.LabPerRP), 0, head1, 52, 2);
System.arraycopy(writeShort(m_head1.MaxNumE), 0, head1, 54, 2);
System.arraycopy(writeShort(m_head1.MaxNumU), 0, head1, 56, 2);
System.arraycopy(writeShort(m_head1.EffNum), 0, head1, 58, 2);
System.arraycopy(writeShort(m_head1.SpcFirstRP), 0, head1, 60, 2);
System.arraycopy(writeShort(m_head1.SpcRecNum), 0, head1, 62, 2);
System.arraycopy(writeShort(m_head1.SpcChnNum), 0, head1, 64, 2);
System.arraycopy(writeShort(m_head1.Abstch), 0, head1, 66, 2);
System.arraycopy(writeFloat(m_head1.AcqTime), 0, head1, 68, 4);
System.arraycopy(writeDouble(m_head1.AcqTime8), 0, head1, 72, 8);
SpcFile.write(head1);
SpcFile.seek(78);
byte[] head2 = new byte[20];
System.arraycopy(writeShort(m_head2.AddRAM), 0, head2, 0, 2);
System.arraycopy(writeShort(m_head2.Seqnum), 0, head2, 2, 2);
System.arraycopy(writeShort(m_head2.Mcanu), 0, head2, 4, 2);
System.arraycopy(writeShort(m_head2.Segnum), 0, head2, 6, 2);
System.arraycopy(writeShort(m_head2.Mcadvt), 0, head2, 8, 2);
System.arraycopy(writeShort(m_head2.Chnsrt), 0, head2, 10, 2);
System.arraycopy(writeFloat(m_head2.RealTime), 0, head2, 12, 4);
System.arraycopy(writeFloat(m_head2.LiveTime), 0, head2, 16, 4);
SpcFile.write(head2);
}
// 写第2个128字节Acquisition信息
{
char[] acq_info = new char[128];
acq_info[0] = ' ';
int offset = 16; // 16 Bytes Spectrum file name
String temp = GetDate(datas.getAcq_date());
for(int i=0; i<temp.length(); i++) {
acq_info[i+offset] = temp.charAt(i);
}
offset += 12; // 12 Bytes Acq_Date
temp = datas.getAcq_time().substring(0, 8); // HH:mm:ss
for(int i=0; i<temp.length(); i++) {
acq_info[i+offset] = temp.charAt(i);
}
offset += 10; // 10 Bytes Acq_Time
temp = String.format("%10.0f", datas.getAcq_live());
int size = temp.length() > 10 ? 10 : temp.length();
for(int i=0; i<size; i++) {
acq_info[offset+i] = temp.charAt(i);
}
offset += 10;
temp = String.format("%10.0f", datas.getAcq_real());
size = temp.length() > 10 ? 10 : temp.length();
for(int i=0; i<size; i++) {
acq_info[offset+i] = temp.charAt(i);
}
byte[] acqInfo = new byte[128];
for (int i=0; i<acq_info.length; i++) {
System.arraycopy(writeChar(acq_info[i]), 0, acqInfo, i, 1);
}
SpcFile.seek((m_head1.AcqInfRP - 1) * 128);
SpcFile.write(acqInfo);
}
// 写第5个128字节Germanium Calibration
{
MakeCalibParam(datas, m_calibParam);
SpcFile.seek((m_head1.CalRP1-1)*128);
byte[] calByte = new byte[128];
System.arraycopy(writeShort(m_calibParam.Afit), 0, calByte, 0, 2);
System.arraycopy(writeShort(m_calibParam.Bfit), 0, calByte, 2, 2);
System.arraycopy(writeShort(m_calibParam.EffPairs), 0, calByte, 4, 2);
System.arraycopy(writeShort(m_calibParam.NumOfChan), 0, calByte, 6, 2);
System.arraycopy(writeFloat(m_calibParam.Knee), 0, calByte, 8, 4);
System.arraycopy(writeFloat(m_calibParam.Asig), 0, calByte, 12, 4);
System.arraycopy(writeFloat(m_calibParam.Bsig), 0, calByte, 16, 4);
System.arraycopy(writeFloat(m_calibParam.EnerCoefA), 0, calByte, 20, 4);
System.arraycopy(writeFloat(m_calibParam.EnerCoefB), 0, calByte, 24, 4);
System.arraycopy(writeFloat(m_calibParam.EnerCoefC), 0, calByte, 28, 4);
System.arraycopy(writeFloat(m_calibParam.FwhmCoefA), 0, calByte, 32, 4);
System.arraycopy(writeFloat(m_calibParam.FwhmCoefB), 0, calByte, 36, 4);
System.arraycopy(writeFloat(m_calibParam.FwhmCoefC), 0, calByte, 40, 4);
System.arraycopy(writeFloat(m_calibParam.AboveEffiCoefA), 0, calByte, 44, 4);
System.arraycopy(writeFloat(m_calibParam.AboveEffiCoefB), 0, calByte, 48, 4);
System.arraycopy(writeFloat(m_calibParam.AboveEffiCoefC), 0, calByte, 52, 4);
System.arraycopy(writeFloat(m_calibParam.BelowEffiCoefA), 0, calByte, 56, 4);
System.arraycopy(writeFloat(m_calibParam.BelowEffiCoefB), 0, calByte, 60, 4);
System.arraycopy(writeFloat(m_calibParam.BelowEffiCoefC), 0, calByte, 64, 4);
System.arraycopy(writeShort(m_calibParam.FwhmTyp), 0, calByte, 68, 2);
System.arraycopy(writeShort(m_calibParam.PeType), 0, calByte, 70, 2);
System.arraycopy(writeShort(m_calibParam.MaestroPSS), 0 ,calByte, 72, 2);
System.arraycopy(writeShort(m_calibParam.EngPairs), 0, calByte, 74, 2);
System.arraycopy(writeShort(m_calibParam.DetectorNum), 0, calByte, 76, 2);
System.arraycopy(writeShort(m_calibParam.NumBelowKnee), 0, calByte, 78, 2);
System.arraycopy(writeFloat(m_calibParam.ENA2), 0, calByte, 80, 4);
System.arraycopy(writeFloat(m_calibParam.ENB2), 0, calByte, 84, 4);
System.arraycopy(writeFloat(m_calibParam.ENC2), 0, calByte, 88, 4);
System.arraycopy(writeFloat(m_calibParam.CalUncert), 0, calByte, 92, 4);
System.arraycopy(writeFloat(m_calibParam.CalDif), 0, calByte, 96, 4);
System.arraycopy(writeFloat(m_calibParam.PolyCoef7), 0, calByte, 100, 4);
System.arraycopy(writeFloat(m_calibParam.PolyCoef8), 0, calByte, 104, 4);
System.arraycopy(writeFloat(m_calibParam.PolyCoef9), 0, calByte, 108, 4);
System.arraycopy(writeFloat(m_calibParam.PolyCoef10), 0, calByte, 112, 4);
System.arraycopy(writeFloat(m_calibParam.LowChanFwhmErr), 0, calByte, 116, 4);
System.arraycopy(writeFloat(m_calibParam.HighChanFwhmErr), 0, calByte, 120, 4);
System.arraycopy(writeShort(m_calibParam.CalibLimit), 0, calByte, 124, 2);
System.arraycopy(writeShort(m_calibParam.STypeFlag), 0, calByte, 126, 2);
SpcFile.write(calByte);
}
// 写第7个128字节Calibration DateTime
{
char[] cal_info = new char[128];
cal_info[0] = '0';
int offset = 32; // 32 Bytes Calibration file name
String temp = GetDate(datas.getCalibra_time().substring(0, 10));
for(int i=0; i<temp.length(); ++i) {
cal_info[i+offset] = temp.charAt(i);
}
offset += 10; // 10 Bytes Cal_Date
String str = datas.getCalibra_time().substring(datas.getCalibra_time().length()-10).substring(0, 8);
for(int i=0; i<str.length(); ++i) {
cal_info[i+offset] = str.charAt(i);
}
byte[] calInfo = new byte[128];
for (int i=0; i<cal_info.length; i++) {
System.arraycopy(writeChar(cal_info[i]), 0, calInfo, i, 1);
}
SpcFile.seek((m_head1.CalRP2 - 1) * 128);
SpcFile.write(calInfo);
}
// 写第1113个128字节能量半高宽刻度数据
{
int pairs_num = 96*1;
float[] pairs = new float[pairs_num];
Arrays.fill(pairs, 0.0f);
int size = m_calibParam.EngPairs;
int adjust = 0;
for(int i=0; i<size; ++i) {
adjust = i / 32 * 96 + i % 32;
pairs[adjust] = Float.valueOf(String.valueOf(datas.getVvEner().get(1).get(i)));
pairs[adjust+32] = Float.valueOf(String.valueOf(datas.getVvEner().get(0).get(i)));
pairs[adjust+64] = Float.valueOf(String.valueOf(datas.getVvReso().get(1).get(i)/datas.getEner_slope()));
}
byte[] pairInfo = new byte[pairs_num*4];
int j=0;
for (int i=0; i<pairs.length; i++) {
System.arraycopy(writeFloat(pairs[i]), 0, pairInfo, j, 4);
j+=4;
}
SpcFile.seek((m_head1.EngPrRP-1)*128);
SpcFile.write(pairInfo);
}
// 写第14个128字节效率刻度数据
{
int size = m_calibParam.EffPairs;
float[] Efficiency = new float[4*size*2];
for(int i=0; i<size; ++i) {
Efficiency[i*2] = Float.valueOf(String.valueOf(datas.getVvEffi().get(0).get(i)));
Efficiency[i*2+1] = Float.valueOf(String.valueOf(datas.getVvEffi().get(1).get(i)));
}
byte[] effInfo = new byte[4*4*size*2];
int j=0;
for (int i=0; i<Efficiency.length; i++) {
System.arraycopy(writeFloat(Efficiency[i]), 0, effInfo, j, 4);
j+=4;
}
SpcFile.seek((m_head1.EffRP - 1) * 128);
SpcFile.write(effInfo);
}
//写第68个128字节Spectrum
{
int count_size = datas.getNum_count();
int[] SpcData = new int[count_size];
for(int i=0; i<count_size; ++i) {
SpcData[i] = Integer.valueOf(String.valueOf(datas.getVCounts().get(i)));
}
byte[] spcDataInfo = new byte[count_size*4];
int j=0;
for (int i=0; i<SpcData.length; i++) {
System.arraycopy(writeInt(SpcData[i]), 0, spcDataInfo, j, 4);
j+=4;
}
SpcFile.seek((m_head1.SpcFirstRP-1)*128);
SpcFile.write(spcDataInfo);
}
SpcFile.close();
}
public static byte[] AnalyseSPC(SpcHead1 m_head1, SpcHead2 m_head2, GermaniumCalib m_calibParam) {
String standard_spc = "D:\\ARMD\\材料\\spc-ims\\standard.SPC";
File standardSpc = new File(standard_spc);
if(!standardSpc.exists()) {
String Warning = standard_spc + " isn't exist.";
return new byte[0];
}
RandomAccessFile SpcFile = null;
try {
SpcFile = new RandomAccessFile(standard_spc, "r");
short Inftyp = 0;
short Filtyp = 0;
//读取第一个数据
byte[] first = new byte[2];
SpcFile.read(first);
Inftyp = Short.valueOf(convert(first, "short"));
//读取第二个数据
byte[] second = new byte[2];
SpcFile.read(second);
Filtyp = Short.valueOf(convert(second, "short"));
if(Inftyp != 1 || Filtyp != 1) {
String Warning = "The Format of "+standardSpc+" is Error!";
return new byte[0];
}
int length = (int) SpcFile.length();
byte[] m_totalContents = new byte[length];
SpcFile.seek(0);
SpcFile.read(m_totalContents);
// 读入整形spc文件的头记录第一个记录128字节
SpcFile.seek(0);
//头部信息需要读取的字节数
byte[] headByte1 = new byte[80];
SpcFile.read(headByte1);
//读取后赋值
m_head1.Inftyp = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 0, 2), "short"));
m_head1.Filtyp = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 2, 4), "short"));
m_head1.Reserved1 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 4, 6), "short"));
m_head1.Reserved2 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 6, 8), "short"));
m_head1.AcqInfRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 8, 10), "short"));
m_head1.SamDesRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 10, 12), "short"));
m_head1.DetDesRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 12, 14), "short"));
m_head1.EbrDesRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 14, 16), "short"));
m_head1.AnaRP1 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 16, 18), "short"));
m_head1.AnaRP2 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 18, 20), "short"));
m_head1.AnaRP3 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 20, 22), "short"));
m_head1.AnaRP4 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 22, 24), "short"));
m_head1.SrpDesRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 24, 26), "short"));
m_head1.IeqDesRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 26, 28), "short"));
m_head1.GeoDesRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 28, 30), "short"));
m_head1.MpcDesRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 30, 32), "short"));
m_head1.CalDesRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 32, 34), "short"));
m_head1.CalRP1 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 34, 36), "short"));
m_head1.CalRP2 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 36, 38), "short"));
m_head1.EffRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 38, 40), "short"));
m_head1.ROI1 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 40, 42), "short"));
m_head1.EngPrRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 42, 44), "short"));
m_head1.EngPrNum = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 44, 46), "short"));
m_head1.Reserved3 = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 46, 48), "short"));
m_head1.DDP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 48, 50), "short"));
m_head1.ActUnit = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 50, 52), "short"));
m_head1.LabPerRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 52, 54), "short"));
m_head1.MaxNumE = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 54, 56), "short"));
m_head1.MaxNumU = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 56, 58), "short"));
m_head1.EffNum = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 58, 60), "short"));
m_head1.SpcFirstRP = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 60, 62), "short"));
m_head1.SpcRecNum = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 62, 64), "short"));
m_head1.SpcChnNum = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 64, 66), "short"));
m_head1.Abstch = Short.valueOf(convert(Arrays.copyOfRange(headByte1, 66, 68), "short"));
m_head1.AcqTime = Float.valueOf(convert(Arrays.copyOfRange(headByte1, 68, 72), "float"));
m_head1.AcqTime8 = Double.valueOf(convert(Arrays.copyOfRange(headByte1, 72, 80), "double"));
SpcFile.seek(78);
byte[] headByte2 = new byte[20];
SpcFile.read(headByte2);
m_head2.AddRAM = Short.valueOf(convert(Arrays.copyOfRange(headByte2, 0, 2), "short"));
m_head2.Seqnum = Short.valueOf(convert(Arrays.copyOfRange(headByte2, 2, 4), "short"));
m_head2.Mcanu = Short.valueOf(convert(Arrays.copyOfRange(headByte2, 4, 6), "short"));
m_head2.Segnum = Short.valueOf(convert(Arrays.copyOfRange(headByte2, 6, 8), "short"));
m_head2.Mcadvt = Short.valueOf(convert(Arrays.copyOfRange(headByte2, 8, 10), "short"));
m_head2.Chnsrt = Short.valueOf(convert(Arrays.copyOfRange(headByte2, 10, 12), "short"));
m_head2.RealTime = Float.valueOf(convert(Arrays.copyOfRange(headByte2, 12, 16), "float"));
m_head2.LiveTime = Float.valueOf(convert(Arrays.copyOfRange(headByte2, 16, 20), "float"));
// Germanium Calibration
SpcFile.seek((m_head1.CalRP1-1)*128);
byte[] charByte = new byte[128];
SpcFile.read(charByte);
m_calibParam.Afit = Short.valueOf(convert(Arrays.copyOfRange(charByte, 0, 2) , "short"));
m_calibParam.Bfit = Short.valueOf(convert(Arrays.copyOfRange(charByte, 2, 4), "short"));
m_calibParam.EffPairs = Short.valueOf(convert(Arrays.copyOfRange(charByte, 4, 6), "short"));
m_calibParam.NumOfChan = Short.valueOf(convert(Arrays.copyOfRange(charByte, 6, 8), "short"));
m_calibParam.Knee = Float.valueOf(convert(Arrays.copyOfRange(charByte, 8, 12), "float"));
m_calibParam.Asig = Float.valueOf(convert(Arrays.copyOfRange(charByte, 12, 16), "float"));
m_calibParam.Bsig = Float.valueOf(convert(Arrays.copyOfRange(charByte, 16, 20), "float"));
m_calibParam.EnerCoefA = Float.valueOf(convert(Arrays.copyOfRange(charByte, 20, 24), "float"));
m_calibParam.EnerCoefB = Float.valueOf(convert(Arrays.copyOfRange(charByte, 24, 28), "float"));
m_calibParam.EnerCoefC = Float.valueOf(convert(Arrays.copyOfRange(charByte, 28, 32), "float"));
m_calibParam.FwhmCoefA = Float.valueOf(convert(Arrays.copyOfRange(charByte, 32, 36), "float"));
m_calibParam.FwhmCoefB = Float.valueOf(convert(Arrays.copyOfRange(charByte, 36, 40), "float"));
m_calibParam.FwhmCoefC = Float.valueOf(convert(Arrays.copyOfRange(charByte, 40, 44), "float"));
m_calibParam.AboveEffiCoefA = Float.valueOf(convert(Arrays.copyOfRange(charByte, 44, 48), "float"));
m_calibParam.AboveEffiCoefB = Float.valueOf(convert(Arrays.copyOfRange(charByte, 48, 52), "float"));
m_calibParam.AboveEffiCoefC = Float.valueOf(convert(Arrays.copyOfRange(charByte, 52, 56), "float"));
m_calibParam.BelowEffiCoefA = Float.valueOf(convert(Arrays.copyOfRange(charByte, 56, 60), "float"));
m_calibParam.BelowEffiCoefB = Float.valueOf(convert(Arrays.copyOfRange(charByte, 60, 64), "float"));
m_calibParam.BelowEffiCoefC = Float.valueOf(convert(Arrays.copyOfRange(charByte, 64, 68), "float"));
m_calibParam.FwhmTyp = Short.valueOf(convert(Arrays.copyOfRange(charByte, 68, 70), "short"));
m_calibParam.PeType = Short.valueOf(convert(Arrays.copyOfRange(charByte, 70, 72), "short"));
m_calibParam.MaestroPSS = Short.valueOf(convert(Arrays.copyOfRange(charByte, 72, 74), "short"));
m_calibParam.EngPairs = Short.valueOf(convert(Arrays.copyOfRange(charByte, 74, 76), "short"));
m_calibParam.DetectorNum = Short.valueOf(convert(Arrays.copyOfRange(charByte, 76, 78), "short"));
m_calibParam.NumBelowKnee = Short.valueOf(convert(Arrays.copyOfRange(charByte, 78, 80), "short"));
m_calibParam.ENA2 = Float.valueOf(convert(Arrays.copyOfRange(charByte, 80, 84), "float"));
m_calibParam.ENB2 = Float.valueOf(convert(Arrays.copyOfRange(charByte, 84, 88), "float"));
m_calibParam.ENC2 = Float.valueOf(convert(Arrays.copyOfRange(charByte, 88, 92), "float"));
m_calibParam.CalUncert = Float.valueOf(convert(Arrays.copyOfRange(charByte, 92, 96), "float"));
m_calibParam.CalDif = Float.valueOf(convert(Arrays.copyOfRange(charByte, 96, 100), "float"));
m_calibParam.PolyCoef7 = Float.valueOf(convert(Arrays.copyOfRange(charByte, 100, 104), "float"));
m_calibParam.PolyCoef8 = Float.valueOf(convert(Arrays.copyOfRange(charByte, 104, 108), "float"));
m_calibParam.PolyCoef9 = Float.valueOf(convert(Arrays.copyOfRange(charByte, 108, 112), "float"));
m_calibParam.PolyCoef10 = Float.valueOf(convert(Arrays.copyOfRange(charByte, 112, 116), "float"));
m_calibParam.LowChanFwhmErr = Float.valueOf(convert(Arrays.copyOfRange(charByte, 116, 120), "float"));
m_calibParam.HighChanFwhmErr = Float.valueOf(convert(Arrays.copyOfRange(charByte, 120, 124), "float"));
m_calibParam.CalibLimit = Short.valueOf(convert(Arrays.copyOfRange(charByte, 124, 126), "short"));
m_calibParam.STypeFlag = Short.valueOf(convert(Arrays.copyOfRange(charByte, 126, 128), "short"));
SpcFile.close();
return m_totalContents;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void MakeSpcHead(FileData datas, SpcHead1 m_head1, SpcHead2 m_head2) {
m_head1.Inftyp = 1;
m_head1.Filtyp = 1;
if(datas.getVvEner().size() > 0 && datas.getVvReso().size() > 0) {
int size = Math.min(datas.getVvEner().get(0).size(), datas.getVvReso().get(0).size());
if(size > 32*1) {
size = 32*1;
}
m_head1.EngPrNum = (short) size;
}
if(datas.getVvEffi().size() > 0) {
m_head1.EffNum = (short) datas.getVvEffi().get(0).size();
}
m_head1.SpcRecNum = (short) (datas.getNum_count()/32);
m_head1.SpcChnNum = (short) datas.getNum_count();
m_head1.AcqTime = 12631.7f;
m_head1.AcqTime8 = 12631.7;
m_head2.Chnsrt = (short) datas.getStart_chan();
m_head2.RealTime = datas.getAcq_real();
m_head2.LiveTime = datas.getAcq_live();
}
public static void MakeCalibParam(FileData datas, GermaniumCalib m_calibParam) {
if(datas.getVvEffi().size() < 3 || datas.getVvEner().size() < 3 || datas.getVvReso().size() < 3) {
return;
}
m_calibParam.NumOfChan = (short) datas.getNum_count();
if(datas.getVvEner().size() > 0 && datas.getVvReso().size() > 0) {
int size = Math.min(datas.getVvEner().get(0).size(), datas.getVvReso().get(0).size());
if(size > 32*1) {
size = 32*1;
}
m_calibParam.EngPairs = (short) size;
}
if(datas.getVvEffi().size() > 0) {
m_calibParam.EffPairs = (short) datas.getVvEffi().get(0).size();
}
ParameterInfo ener_para = new ParameterInfo();
ener_para.setP(CalValuesHandler.calFitPara("Cal_Energy", 2, datas.getVvEner().get(1), datas.getVvEner().get(0), datas.getVvEner().get(2)));
ParameterInfo reso_para = new ParameterInfo();
reso_para.setP(CalValuesHandler.calFitPara("Cal_Resolution", 2, datas.getVvReso().get(0), datas.getVvReso().get(1), datas.getVvReso().get(2)));
if(ener_para.getP().size() < 3) {
return;
} else if(ener_para.getP().size() == 3) {
ener_para.getP().add(0.0);
}
if(reso_para.getP().size() < 3) {
return;
} else if(reso_para.getP().size() == 3) {
reso_para.getP().add(0.0);
}
m_calibParam.EnerCoefA = Float.valueOf(String.valueOf(ener_para.getP().get(1)));
m_calibParam.EnerCoefB = Float.valueOf(String.valueOf(ener_para.getP().get(2)));
m_calibParam.EnerCoefC = Float.valueOf(String.valueOf(ener_para.getP().get(3)));
m_calibParam.FwhmCoefA = Float.valueOf(String.valueOf(reso_para.getP().get(1)));
m_calibParam.FwhmCoefB = Float.valueOf(String.valueOf(reso_para.getP().get(2)));
m_calibParam.FwhmCoefC = Float.valueOf(String.valueOf(reso_para.getP().get(3)));
}
public static String GetDate(String str) {
str = str.substring(0, 10); // YYYY/MM/DD
String temp = str.substring(str.length()-2)+ StringPool.DASH; // DD-
int month = Integer.valueOf(str.substring(5, 7));
switch(month) { // DD-MMM
case 1: temp+="Jan"; break;
case 2: temp+="Feb"; break;
case 3: temp+="Mar"; break;
case 4: temp+="Apr"; break;
case 5: temp+="May"; break;
case 6: temp+="Jun"; break;
case 7: temp+="Jul"; break;
case 8: temp+="Aug"; break;
case 9: temp+="Sep"; break;
case 10: temp+="Oct"; break;
case 11: temp+="Nov"; break;
case 12: temp+="Dec"; break;
default: temp+="Jan"; break;
}
temp+=String.format("-%s", str.substring(2, 4)); // DD-MMM-YY
if(str.substring(0, 2) == "20") { // DD-MMM-YY*
temp+="1";
} else {
temp+="0";
}
return temp;
}
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).length() == 1) {
index+="0"+values.get(i);
} 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 byte[] writeShort(int v) {
byte[] byteArr = new byte[2];
byteArr[0] = (byte) ((v >>> 0) & 0xFF);
byteArr[1] = (byte) ((v >>> 8) & 0xFF);
return byteArr;
}
public static byte[] writeChar(int v) {
byte[] byteArr = new byte[2];
byteArr[0] = (byte) ((v >>> 0) & 0xFF);
byteArr[1] = (byte) ((v >>> 8) & 0xFF);
return byteArr;
}
public static byte[] writeInt(int v) {
byte[] byteArr = new byte[4];
byteArr[0] = (byte) ((v >>> 0) & 0xFF);
byteArr[1] = (byte) ((v >>> 8) & 0xFF);
byteArr[2] = (byte) ((v >>> 16) & 0xFF);
byteArr[3] = (byte) ((v >>> 24) & 0xFF);
return byteArr;
}
public static byte[] writeLong(long v) {
byte[] byteArr = new byte[8];
byteArr[0] = (byte) ((v >>> 0) & 0xFF);
byteArr[1] = (byte) ((v >>> 8) & 0xFF);
byteArr[2] = (byte) ((v >>> 16) & 0xFF);
byteArr[3] = (byte) ((v >>> 24) & 0xFF);
byteArr[4] = (byte) ((v >>> 32) & 0xFF);
byteArr[5] = (byte) ((v >>> 40) & 0xFF);
byteArr[6] = (byte) ((v >>> 48) & 0xFF);
byteArr[7] = (byte) ((v >>> 56) & 0xFF);
return byteArr;
}
public static byte[] writeFloat(float v) {
byte[] byteArr = writeInt(Float.floatToIntBits(v));
return byteArr;
}
public static byte[] writeDouble(double v) {
byte[] byteArr = writeLong(Double.doubleToLongBits(v));
return byteArr;
}
}