123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- #include "stdafx.h"
- #include "BrukerSPXFileMgr.h"
- #include "ControllerHelper.h"
- namespace OTSController {
- #pragma warning(disable: 4835)
- std::vector<SPXLine> CBrukerSPXFileMgr::m_vSpxFileLines = {
- { ("<?xml version=\"1.0\" encoding=\"WINDOWS - 1252\" standalone=\"yes\"?>") },
- { ("<TRTSpectrum>") },
- { (" <RTHeader/>") },
- { (" <ClassInstance Type=\"TRTSpectrum\" Name=\"Pyrite real\">"), SPXLineType::NAME },
- { (" <TRTHeaderedClass>") },
- { (" <ClassInstance Type=\"TRTSpectrumHardwareHeader\">") },
- { (" <TRTKnownHeader>") },
- { (" <Type>RTHardware</Type>") },
- { (" <Size>137</Size>") },
- { (" </TRTKnownHeader>") },
- { (" <RealTime>9627</RealTime>") },
- { (" <LifeTime>8658</LifeTime>") },
- { (" <DeadTime>1E1</DeadTime>") },
- { (" <ZeroPeakPosition>96</ZeroPeakPosition>") },
- { (" <ZeroPeakFrequency>25000</ZeroPeakFrequency>") },
- { (" <PulseDensity>113189</PulseDensity>") },
- { (" <Amplification>2E4</Amplification>") },
- { (" <ShapingTime>400000</ShapingTime>") },
- { (" </ClassInstance>") },
- { (" <ClassInstance Type=\"TRTDetectorHeader\">") },
- { (" <TRTKnownHeader>") },
- { (" <Type>RTDetector</Type>") },
- { (" <Version>5</Version>") },
- { (" <Size>9932</Size>") },
- { (" </TRTKnownHeader>") },
- { (" <Technology>SD3pr</Technology>") },
- { (" <Serial>5322</Serial>") },
- { (" <Type>XFlash 6|10</Type>") },
- { (" <DetectorThickness>0.45</DetectorThickness>") },
- { (" <SiDeadLayerThickness>0.029</SiDeadLayerThickness>") },
- { (" <DetLayers>eJyzcUkt8UmsTC0qtrMB0wYKjiX5ubZKhsZKCiEZmcnZeanFxbZKpq66xkr6UDWGUDXmKEos9ICKjOCKjKCKTFEUmSGbYwxVYoZbiQlUiQWqErhV+gj3AwCpRT07</DetLayers>") },
- { (" <WindowType>slew AP3.3</WindowType>") },
- { (" <WindowLayers>") },
- { (" <Layer0 Atom=\"5\" Thickness=\"1.3E-2\"/>") },
- { (" <Layer1 Atom=\"6\" Thickness=\"1.45E-1\"/>") },
- { (" <Layer2 Atom=\"7\" Thickness=\"4.5E-2\"/>") },
- { (" <Layer3 Atom=\"8\" Thickness=\"8.5E-2\"/>") },
- { (" <Layer4 Atom=\"13\" Thickness=\"3.5E-2\"/>") },
- { (" <Layer5 Atom=\"14\" Thickness=\"3.8E2\" RelativeArea=\"2.3E-1\"/>") },
- { (" </WindowLayers>") },
- { (" <Corrections>") },
- { (" <Escape/>") },
- { (" <Tail>") },
- { (" <FormulaType>Internal</FormulaType>") },
- { (" <MainCorrection>1</MainCorrection>") },
- { (" </Tail>") },
- { (" <Shelf>") },
- { (" <FormulaType>Internal</FormulaType>") },
- { (" <RangeStart>8E-2</RangeStart>") },
- { (" <RangeEnd>1E1</RangeEnd>") },
- { (" <MainCorrection>1</MainCorrection>") },
- { (" <Coefficient0>1</Coefficient0>") },
- { (" </Shelf>") },
- { (" <Shift>") },
- { (" <FormulaType>Internal</FormulaType>") },
- { (" <RangeStart>8E-2</RangeStart>") },
- { (" <RangeEnd>5.55E-1</RangeEnd>") },
- { (" <MainCorrection>1</MainCorrection>") },
- { (" </Shift>") },
- { (" <FWHMShift/>") },
- { (" </Corrections>") },
- { (" <CorrectionType>3</CorrectionType>") },
- { (" <ResponseFunctionCount>21</ResponseFunctionCount>") },
- { (" <SampleCount>5</SampleCount>") },
- { (" <SampleOffset>-3</SampleOffset>") },
- { (" <PulsePairResTimeCount>0</PulsePairResTimeCount>") },
- { (" <PileUpMinEnergy>1</PileUpMinEnergy>") },
- { (" <PileUpWithBG>False</PileUpWithBG>") },
- { (" <TailFactor>1</TailFactor>") },
- { (" <ShelfFactor>1</ShelfFactor>") },
- { (" <ShiftFactor>1.106</ShiftFactor>") },
- { (" <ShiftFactor2>-8.95E-1</ShiftFactor2>") },
- { (" <ShiftData>0.07,0.0058,0.183,0.0078,0.277,0.0058,0.555,0,1.1,0,3.293,0.0064,5.89,0,0,0,0,0,</ShiftData>") },
- { (" <ResponseFunction>0,0.01,0.000801,0.01,0.00298,0.01,0.008902,0.01,0.025,0.010046,0.041098,0.013475,0.04702,0.017302,0.049199,0.019237,0.05,0.02,</ResponseFunction>") },
- { (" <ResponseFunction>0,0.03,0.00444,0.03,0.01651,0.03,0.049318,0.03,0.1385,0.03023,0.227682,0.047375,0.26049,0.06651,0.27256,0.076185,0.277,0.08,</ResponseFunction>") },
- { (" <ResponseFunction>0,0.03,0.006283,0.03,0.023364,0.03,0.069793,0.03,0.196,0.030228,0.322207,0.047377,0.368636,0.066512,0.385717,0.076186,0.392,0.08,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.008415,0,0.031291,0,0.093473,0,0.2625,0,0.431527,0.000035,0.493709,0.000073,0.516585,0.000092,0.525,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.010836,0,0.040291,0,0.120357,0,0.338,0,0.555643,0.000035,0.635709,0.000073,0.665164,0.000092,0.676,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.016687,0,0.062045,0,0.185343,0,0.5205,0,0.855657,0.000035,0.978955,0.000073,1.024313,0.000092,1.041,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.020101,0,0.07474,0,0.223266,0,0.627,0,1.030734,0.000035,1.17926,0.000073,1.233899,0.000092,1.254,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.023836,0,0.088627,0,0.26475,0,0.7435,0,1.22225,0.000035,1.398373,0.000073,1.463164,0.000092,1.487,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.027891,0,0.103707,0,0.309795,0,0.87,0,1.430205,0.000035,1.636293,0.000073,1.712109,0.000092,1.74,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.030776,0,0.114435,0,0.341842,0,0.96,0,1.578158,0.000035,1.805565,0.000073,1.889224,0.000092,1.92,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.032283,0,0.120037,0,0.358578,0,1.007,0,1.655422,0.000035,1.893963,0.000073,1.981717,0.000092,2.014,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.036996,0,0.13756,0,0.410923,0,1.154,0,1.897077,0.000035,2.17044,0.000073,2.271004,0.000092,2.308,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.05918,0,0.220049,0,0.657334,0,1.846,0,3.034665,0.000035,3.471952,0.000073,3.63282,0.000092,3.692,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.079378,0,0.295146,0,0.881668,0,2.476,0,4.070332,0.000035,4.656854,0.000073,4.872623,0.000092,4.952,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.119867,0,0.445699,0,1.331404,0,3.739,0,6.146595,0.000035,7.0323,0.000073,7.358133,0.000092,7.478,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.148303,0,0.551433,0,1.647253,0,4.626,0,7.604747,0.000035,8.700567,0.000073,9.103698,0.000092,9.252,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.176322,0,0.655616,0,1.958472,0,5.5,0,9.041529,0.000035,10.344384,0.000073,10.823678,0.000092,11,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.208381,0,0.774819,0,2.314557,0,6.5,0,10.685443,0.000035,12.225181,0.000073,12.791619,0.000092,13,0.0001,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.24044,0,0.894022,0,2.670643,0,7.5,0,12.329357,0,14.105978,0,14.759561,0,15,0,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,0.320586,0,1.192029,0,3.560857,0,10,0,16.439142,0,18.80797,0,19.679415,0,20,0,</ResponseFunction>") },
- { (" <ResponseFunction>0,0,1.60293,0,5.960146,0,17.804287,0,50,0,82.195709,0,94.039856,0,98.397072,0,100,0,</ResponseFunction>") },
- { (" </ClassInstance>") },
- { (" <ClassInstance Type=\"TRTESMAHeader\">") },
- { (" <TRTKnownHeader>") },
- { (" <Type>RTESMA</Type>") },
- { (" <Size>662</Size>") },
- { (" </TRTKnownHeader>") },
- { (" <PrimaryEnergy>2E1</PrimaryEnergy>") },
- { (" <ReferenceFactor>-1</ReferenceFactor>") },
- { (" <ReferenceStdDev>-1</ReferenceStdDev>") },
- { (" <BaseRefStdDev>2.000100008E-3</BaseRefStdDev>") },
- { (" <ElevationAngle>3.5E1</ElevationAngle>") },
- { (" <CoatCorrection/>") },
- { (" </ClassInstance>") },
- { (" </TRTHeaderedClass>") },
- { (" <ClassInstance Type=\"TRTSpectrumHeader\">") },
- { (" <Size>82</Size>") },
- { (" <Date>9.12.2015</Date>") },
- { (" <Time>11:41:21</Time>") },
- { (" <ChannelCount>2000</ChannelCount>")/*, SPXLineType::CHANNEL_COUNT*/ },
- //{ (" <CalibAbs>0</CalibAbs>"), SPXLineType::CALIB_ABS },
- { (" <CalibLin>0.01</CalibLin>")/*, SPXLineType::CALIB_LIN*/ },
- { (" <SigmaAbs>7.756682035E-4</SigmaAbs>")/*, SPXLineType::SIGMA_ABS*/ },
- { (" <SigmaLin>6.874358396E-4</SigmaLin>")/*, SPXLineType::SIGMA_LIN*/ },
- { (" </ClassInstance>") },
- { (" <Channels></Channels>"), SPXLineType::CHANNELS },
- { (" <ClassInstance Type=\"TRTResult\" Name=\"Results\">") },
- { (" <Result>") },
- { (" <Atom>16</Atom>") },
- { (" <XLine>K-Serie</XLine>") },
- { (" <AtomPercent>6.494736045E-1</AtomPercent>") },
- { (" <MassPercent>3.709764752E-1</MassPercent>") },
- { (" <NetIntens>445355</NetIntens>") },
- { (" <Background>1512</Background>") },
- { (" <Sigma>3.644878792E-2</Sigma>") },
- { (" </Result>") },
- { (" <Result>") },
- { (" <Atom>26</Atom>") },
- { (" <XLine>K-Serie</XLine>") },
- { (" <AtomPercent>3.505263955E-1</AtomPercent>") },
- { (" <MassPercent>3.487069895E-1</MassPercent>") },
- { (" <NetIntens>142063</NetIntens>") },
- { (" <Background>462</Background>") },
- { (" <Sigma>2.732743857E-2</Sigma>") },
- { (" </Result>") },
- { (" <ExtResults>") },
- { (" <Atom>26</Atom>") },
- { (" <FCorrection>1.029448986</FCorrection>") },
- { (" </ExtResults>") },
- { (" <ExtResults>") },
- { (" <Atom>16</Atom>") },
- { (" <FCorrection>1.007593036</FCorrection>") },
- { (" </ExtResults>") },
- { (" </ClassInstance>") },
- { (" <ClassInstance Type=\"TRTPSEElementList\" Name=\"Elements\">") },
- { (" <ChildClassInstances>") },
- { (" <ClassInstance Type=\"TRTPSEElement\" Name=\"Fe\">") },
- { (" <Element>26</Element>") },
- { (" <Color>65280</Color>") },
- { (" <AutomaticMode>1</AutomaticMode>") },
- { (" </ClassInstance>") },
- { (" <ClassInstance Type=\"TRTPSEElement\" Name=\"S\">") },
- { (" <Element>16</Element>") },
- { (" <Color>16711680</Color>") },
- { (" <AutomaticMode>1</AutomaticMode>") },
- { (" </ClassInstance>") },
- { (" </ChildClassInstances>") },
- { (" </ClassInstance>") },
- { (" <ChildClassInstances>") },
- { (" <ClassInstance Type=\"TRTSpectrumChartConfigurationData\">") },
- { (" <TRTChartConfigurationData>") },
- { (" <XMin>0.09784126</XMin>") },
- { (" <XMax>20.00089226</XMax>") },
- { (" <YMin>0</YMin>") },
- { (" <YMax>366.03007760028</YMax>") },
- { (" <XAxisLog>0</XAxisLog>") },
- { (" <YAxisLog>0</YAxisLog>") },
- { (" <YAxisSqrt>0</YAxisSqrt>") },
- { (" <LegendeVisible>0</LegendeVisible>") },
- { (" <GridStyle>Lines</GridStyle>") },
- { (" <GridColor>223,223,223</GridColor>") },
- { (" <MinXTicks>5</MinXTicks>") },
- { (" <MinYTicks>5</MinYTicks>") },
- { (" <SeriesScaling>0</SeriesScaling>") },
- { (" <AxisFont>") },
- { (" <Name>Verdana</Name>") },
- { (" <Size>11</Size>") },
- { (" <Color>8,0,0</Color>") },
- { (" <Style/>") },
- { (" </AxisFont>") },
- { (" <LegendeFont>") },
- { (" <Name>Verdana</Name>") },
- { (" <Size>11</Size>") },
- { (" <Color>8,0,0</Color>") },
- { (" <Style/>") },
- { (" </LegendeFont>") },
- { (" <SeriesProperties>") },
- { (" <ClassInstance Type=\"TRTChartSeriesConfigurationData\">") },
- { (" <Name>Acquisition</Name>") },
- { (" <Description>Acquisition</Description>") },
- { (" <Visible>1</Visible>") },
- { (" <LineColor>194,9,0</LineColor>") },
- { (" <FillColor>194,9,0</FillColor>") },
- { (" <Filled>1</Filled>") },
- { (" <LineStyle>Solid</LineStyle>") },
- { (" <LineWidth>1</LineWidth>") },
- { (" <Mark>-1</Mark>") },
- { (" <Factor>1</Factor>") },
- { (" <Offset>0</Offset>") },
- { (" </ClassInstance>") },
- { (" </SeriesProperties>") },
- { (" </TRTChartConfigurationData>") },
- { (" <EnergyMode>1</EnergyMode>") },
- { (" <YAxisMode>Hertz</YAxisMode>") },
- { (" <RescaleStrength>0</RescaleStrength>") },
- { (" <InterpolateType>None</InterpolateType>") },
- { (" <ForegroundRegion>1</ForegroundRegion>") },
- { (" <BackgroundRegion>1</BackgroundRegion>") },
- { (" <CurrentSpectrum>0</CurrentSpectrum>") },
- { (" <CurrentSpectrumInFront>1</CurrentSpectrumInFront>") },
- { (" <ElementLinesVisible>1</ElementLinesVisible>") },
- { (" <ElementTextVisible>1</ElementTextVisible>") },
- { (" <TransparentText>0</TransparentText>") },
- { (" <EscLinesVisible>0</EscLinesVisible>") },
- { (" <NegativeCountsAllowed>0</NegativeCountsAllowed>") },
- { (" <DynamicLineMarkerHeight>0</DynamicLineMarkerHeight>") },
- { (" <CoatingElement>-1</CoatingElement>") },
- { (" <LabelFont>") },
- { (" <Name>Verdana</Name>") },
- { (" <Size>11</Size>") },
- { (" <Color>8,0,0</Color>") },
- { (" <Style/>") },
- { (" </LabelFont>") },
- { (" </ClassInstance>") },
- { (" </ChildClassInstances>") },
- { (" </ClassInstance>") },
- { ("</TRTSpectrum>") },
- };
- #pragma warning(default: 4835)
- BOOL CBrukerSPXFileMgr::ExportXrayPoints(LPCTSTR a_sPath, LPCTSTR a_sName, const std::vector<CPosXray*>& a_xrayPoints)
- {
- ASSERT(a_sPath);
- if (!a_sPath)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoints:invalid path"));
- return FALSE;
- }
- for (size_t i = 0; i < a_xrayPoints.size(); i++)
- {
- auto* pXrayPoint = a_xrayPoints[i];
- std::stringstream fileNameStream;
- char sPath[MAX_PATH];
- CControllerHelper::WCharToChar((const wchar_t*)a_sPath, sPath);
- char sName[MAX_PATH] = { "Spectrum" };
- if (a_sName)
- {
- CControllerHelper::WCharToChar((const wchar_t*)a_sName, sName);
- }
- fileNameStream << sPath << "\\" << sName << i << "_" << pXrayPoint->GetPosition().x << "_" << pXrayPoint->GetPosition().y << ".spx";
- std::stringstream xrayNameStream;
- xrayNameStream << sName << i;
- if (!ExportXrayPoint(fileNameStream.str().c_str(), xrayNameStream.str().c_str(), pXrayPoint))
- {
- CString sName = CControllerHelper::CharToString(fileNameStream.str().c_str());
- LogErrorTrace(__FILE__,__LINE__,_T("Export spectrum(%d) to %s failed."), i, sName);
- }
- }
- return TRUE;
- }
- BOOL CBrukerSPXFileMgr::ExportXrayPoint(const char* a_sFilePathName, const char* a_sName, CPosXray* a_pXrayPoint)
- {
-
- ASSERT(a_sFilePathName);
- if (!a_sFilePathName)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid path"));
- return FALSE;
- }
- ASSERT(a_pXrayPoint);
- if (!a_pXrayPoint)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid x-ray point"));
- return FALSE;
- }
- std::ofstream out(a_sFilePathName);
- for (auto& spxLine : m_vSpxFileLines)
- {
- switch (spxLine.m_nLineType)
- {
- case SPXLineType::NAME:
- {
- out << " <ClassInstance Type=\"TRTSpectrum\" Name=\"" << a_sName << "\">" << std::endl;
- }
- break;
- //case SPXLineType::CHANNEL_COUNT:
- //{
- // out << " <ChannelCount>2000</ChannelCount>" << std::endl;
- //}
- //break;
- case SPXLineType::CHANNELS:
- {
- out << " <Channels>";
- auto* pXrayData = a_pXrayPoint->GetXrayData();
- out << pXrayData[0];
- for (long i = 1; i < GENERALXRAYCHANNELS; i++)
- {
- out << "," << pXrayData[i];
- }
- out << "</Channels>" << std::endl;
- }
- break;
- //case SPXLineType::CALIB_ABS:
- //{
- // continue;
- // //out << " <CalibAbs>";
- // //out << m_spectrumHeader.CalibrationAbs;
- // //out << "</CalibAbs>" << std::endl;
- //}
- //break;
- //case SPXLineType::CALIB_LIN:
- //{
- // continue;
- // //out << " <CalibLin>";
- // //out << m_spectrumHeader.CalibrationLin;
- // //out << "</CalibLin>" << std::endl;
- //}
- //break;
- //case SPXLineType::SIGMA_ABS:
- //{
- // out << " <SigmaAbs>";
- // out << m_spectrumHeader.SigmaAbs;
- // out << "</SigmaAbs>" << std::endl;
- //}
- //break;
- //case SPXLineType::SIGMA_LIN:
- //{
- // out << " <SigmaLin>";
- // out << m_spectrumHeader.SigmaLin;
- // out << "</SigmaLin>" << std::endl;
- //}
- //break;
- default:
- {
- out << spxLine.m_sLineString << std::endl;
- }
- break;
- }
- }
- out.flush();
- out.close();
- return true;
- }
- BOOL CBrukerSPXFileMgr::ExportXrayPoints(LPCTSTR a_sPath, LPCTSTR a_sName, const CPosXrayList& a_xrayPoints)
- {
- std::vector<CPosXray*> xrayPoints;
- for (auto& pXray : a_xrayPoints)
- {
- xrayPoints.push_back(pXray.get());
- }
- return ExportXrayPoints(a_sPath, a_sName, xrayPoints);
- }
- /*BOOL CBrukerSPXFileMgr::ExportXrayPoint(LPCTSTR a_sFilePathName, LPCTSTR a_sSpectrumName, CPosXray* a_pXrayPoint)
- {
- ASSERT(a_sFilePathName);
- if (!a_sFilePathName)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid path"));
- return FALSE;
- }
- ASSERT(a_pXrayPoint);
- if (!a_pXrayPoint)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid x-ray point"));
- return FALSE;
- }
- char sPathName[MAX_PATH];
- CControllerHelper::WCharToChar((const wchar_t*)a_sFilePathName, sPathName);
- char sName[MAX_PATH] = { "Spectrum" };
- if (a_sSpectrumName)
- {
- CControllerHelper::WCharToChar((const wchar_t*)a_sSpectrumName, sName);
- }
- return ExportXrayPoint(sPathName, sName, a_pXrayPoint);
- }*/
- BOOL CBrukerSPXFileMgr::LoadSpectrumHeader(LPCTSTR a_sFilePathName)
- {
- ASSERT(a_sFilePathName);
- if (!a_sFilePathName)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("ExportXrayPoint:invalid path"));
- return FALSE;
- }
- /* if (!FS::Exists(a_sFilePathName))
- {
- return FALSE;
- }*/
- CFile file;
- CFileException ex;
- if (!file.Open(a_sFilePathName, CFile::modeRead, &ex))
- {
- TCHAR strError[512] = _T("");
- ex.GetErrorMessage(strError, lstrlen(strError));
- LogErrorTrace(__FILE__,__LINE__,_T("Open file(%s) failed: %s"), a_sFilePathName, strError);
- return FALSE;
- }
- auto nReadSize = file.Read(&m_spectrumHeader, sizeof(RTSpectrumHeaderRec));
- file.Close();
- return nReadSize == sizeof(RTSpectrumHeaderRec);
- }
- BOOL CBrukerSPXFileMgr::SaveSpectrumHeader(LPCTSTR a_sFilePathName)
- {
- ASSERT(a_sFilePathName);
- if (!a_sFilePathName)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("SaveSpectrumHeader:invalid path"));
- return FALSE;
- }
- // Open the file
- CFile file;
- CFileException ex;
- if (!file.Open(a_sFilePathName, CFile::modeCreate | CFile::modeWrite, &ex))
- {
- TCHAR szCause[255];
- ex.GetErrorMessage(szCause, 255);
- LogErrorTrace(__FILE__,__LINE__,_T("Create file %s failed:\r\n %s"), a_sFilePathName, szCause);
- return FALSE;
- }
- file.Write(&m_spectrumHeader, sizeof(RTSpectrumHeaderRec));
- file.Close();
- return TRUE;
- }
- BOOL CBrukerSPXFileMgr::SetSpectrumHeader(RTSpectrumHeaderRec* m_pSpectrumHeader)
- {
- ASSERT(m_pSpectrumHeader);
- if (!m_pSpectrumHeader)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("SetSpectrumHeader:invalid spectrum header"));
- return FALSE;
- }
- memcpy_s(&m_spectrumHeader, sizeof(RTSpectrumHeaderRec), m_pSpectrumHeader, sizeof(RTSpectrumHeaderRec));
- return TRUE;
- }
- void CBrukerSPXFileMgr::Init()
- {
- InitSpectrumHeader(&m_spectrumHeader);
- }
- void CBrukerSPXFileMgr::InitSpectrumHeader(RTSpectrumHeaderRec* a_pHeader)
- {
- if (!a_pHeader)
- {
- return;
- }
- memset(a_pHeader, 0, sizeof(RTSpectrumHeaderRec));
- std::string sName = "Rontec XRay spectrum";
- a_pHeader->IDStringLength = (BYTE)sName.size();
- memcpy_s(a_pHeader->IDString, 25, sName.c_str(), sName.size());
- a_pHeader->ChannelCount = GENERALXRAYCHANNELS;
- a_pHeader->CalibrationAbs = 1;
- a_pHeader->CalibrationLin = 0.01;
- a_pHeader->SigmaAbs = 0.000752;
- a_pHeader->SigmaLin = 0.000687;
- }
- bool CBrukerSPXFileMgr::InitSpectrumBuffer(char* a_pBuffer, CPosXray* a_pXrayPoint)
- {
-
- ASSERT(a_pBuffer);
- if (!a_pBuffer)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("InitSpectrumBuffer:invalid buffer"));
- return FALSE;
- }
- ASSERT(a_pXrayPoint);
- if (!a_pXrayPoint)
- {
- LogErrorTrace(__FILE__, __LINE__, _T("InitSpectrumBuffer:invalid x-ray point"));
- return FALSE;
- }
- RTSpectrumHeaderRec* pHeader = (RTSpectrumHeaderRec*)a_pBuffer;
- CBrukerSPXFileMgr::InitSpectrumHeader(pHeader);
- auto* pXrayData = a_pXrayPoint->GetXrayData();
- char* pXrayBuffer = a_pBuffer + sizeof(RTSpectrumHeaderRec);
- size_t nBufferSize = sizeof(long) * GENERALXRAYCHANNELS;
- LogTrace(__FILE__,__LINE__,_T("Copy xray buffer size %d"), nBufferSize);
- memcpy(pXrayBuffer, pXrayData, nBufferSize);
- return true;
- }
- }
|