-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetrekPowderPeaksInt.cpp
More file actions
executable file
·94 lines (73 loc) · 2.8 KB
/
detrekPowderPeaksInt.cpp
File metadata and controls
executable file
·94 lines (73 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/** @author Yao-Wang Li
* @date 2018-10-26
* @email: liyaowang2911@gmail.com
* @version: 0.1
* @brief convert the rigaku image to conversional one dimensional power diffraction data.
* @the center blank nad beam stop will be excluded during process.
*/
#include <cstdlib>
#include "detrek.h"
#include "functions.h"
int main (int argc, char ** argv)
{
if (argc != 3)
{
std::cout<<"I need the detrek image file name and std for peak determination, thank you."<<std::endl;
exit(1);
}
string fileName=string(argv[1]);
int position=fileName.find_last_of(".");
if (fileName.substr(position+1)!="img")
{
std::cout<<"it is not an image with the extension 'img'."<<std::endl;
exit(2);
}
string baseName=fileName.substr(0, position);
string outFileName=baseName + ".tif";
float std = atof(argv[2]);
std::cout<<"This program can convert the rigaku two dimensional diffraction image to tiff format image."<<std::endl;
std::cout<<"Have fun with this program, good luck to you. from Yao-Wang. "<<std::endl;
detrek rigakuImg(fileName);
//rigakuImg.printHeaderInfo();
rigakuImg.maskBeamAndGap();
rigakuImg.convert();
// rigakuImg.printPowderData();
vector<float> slopeValues;
//powderData is contains the d value and corresponding intensity value.
calculateSlope(rigakuImg.powderData, slopeValues);
vector<int> peaksPosition;
vector<vector<float>> peaksRes;
//the gap of detector start from 195 and end at 211.
int gapStart=195;
float beamY = rigakuImg.getBeamY();
findPeaks(rigakuImg.powderData, peaksPosition, beamY, gapStart, std);
float pixelsize = rigakuImg.getPixelSize();
float distance = rigakuImg.getDistance();
float wavelength = rigakuImg.getWaveLength();
for (int i=0; i<peaksPosition.size(); i++)
{
vector<float> tmp(4,0);
float d = calculateDValue(peaksPosition[i], pixelsize, distance, wavelength);
tmp[0] = peaksPosition[i];
tmp[1] = d;
tmp[2] = 1/d;
tmp[3] = 2*asin(wavelength/(2*d))*180/3.1415926;
peaksRes.push_back(tmp);
}
vector<vector<int>> peakTwoEnds;
findPeaksRange(slopeValues, peaksPosition, peakTwoEnds);
vector<float> area;
integralForPeaks(rigakuImg.powderData, peakTwoEnds, area);
string outSlope = baseName + "_slope.txt";
writeVec2File<float>(slopeValues, outSlope.c_str());
string outPeaks = baseName + "_peaks.txt";
// writeVec2File<int>(peaksPosition, outPeaks.c_str());
writeMatrix2File<float>(peaksRes, outPeaks.c_str());
string outPowderData = baseName + "_powderData.txt";
writePoints2File<float>(rigakuImg.powderData, outPowderData.c_str());
string outPeaksRange = baseName + "_peaksRange.txt";
writePoints2File<int>(peakTwoEnds, outPeaksRange.c_str());
string outArea = baseName + "_area.txt";
writeVec2File<float>(area, outArea.c_str());
return 0;
}