diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/Demo.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/Demo.java deleted file mode 100644 index 4f129a3b..00000000 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/Demo.java +++ /dev/null @@ -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 10 ? 10 : temp.length(); - for(int i=0; i 10 ? 10 : temp.length(); - for(int i=0; i 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 values = new LinkedList<>(); - for (int i=0; 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; - } - - - -}