-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput.cpp
119 lines (94 loc) · 3.25 KB
/
input.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "input.h"
#include "constants.h"
#include "tinyxml.h"
#include "errorcode.h"
#include "math.h"
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <sstream>
#include <vector>
using namespace std;
int Input::QueryIntAttribute(string obj, TiXmlElement* el) {
TiXmlElement* el1 = el->FirstChildElement(obj.c_str());
int result = -1;
if (el1) el1->QueryIntAttribute("value", &result);
return result;
}
double Input::QueryDoubleAttribute(string obj, TiXmlElement* el) {
TiXmlElement* el1 = el->FirstChildElement(obj.c_str());
double result = -1.0;
if (el1) el1->QueryDoubleAttribute("value", &result);
return result;
}
double Input::QueryDoubleAttributeWithDefault(string obj, TiXmlElement* el, double def) {
TiXmlElement* el1 = el->FirstChildElement(obj.c_str());
double result = def;
if (el1) el1->QueryDoubleAttribute("value", &result);
return result;
}
int Input::LoadFile(const string inputfilename) {
TiXmlDocument* doc = new TiXmlDocument(inputfilename.c_str());
TiXmlElement* el = NULL;
//TiXmlElement* el1 = NULL;
//TiXmlElement* el2 = NULL;
if (doc->LoadFile(inputfilename.c_str(), TIXML_DEFAULT_ENCODING)) {
string gridstr = "Grid";
el = doc->FirstChildElement(gridstr.c_str());
if (el){
string Eminstr = "Emin";
Emin_GeV = QueryDoubleAttribute(Eminstr, el);
string Emaxstr = "Emax";
Emax_GeV = QueryDoubleAttribute(Emaxstr, el);
string nEstr = "nE";
nE = QueryDoubleAttribute(nEstr, el);
deltalogE = log10(Emax_GeV/Emin_GeV)/(nE-1);
cout << "energy vector: " << endl;
for (int ie=0; ie<(nE); ie++) {
E_vec.push_back( Emin_GeV*pow(10.,ie*deltalogE) );
cout << E_vec.back() << " ";
}
cout << endl;
}
string SNRstr = "SNR";
el = doc->FirstChildElement(SNRstr.c_str());
if (el){
string deltatstr = "deltat";
deltat = QueryDoubleAttribute(deltatstr, el);
string SNR_energy_outputstr = "SNRenergy";
SNR_energy_output = QueryDoubleAttribute(SNR_energy_outputstr, el);
string SNR_slope_str = "SNRslope";
SNR_slope = QueryDoubleAttribute(SNR_slope_str, el);
string Nsamples_str = "Nsamples";
Nsamples = QueryIntAttribute(Nsamples_str, el);
}
string propstr = "Propagation";
el = doc->FirstChildElement(propstr.c_str());
if (el){
string deltastr = "delta";
delta = QueryDoubleAttribute(deltastr, el);
string D0str = "D0";
D0 = QueryDoubleAttribute(D0str, el);
string E0str = "E0";
E0 = QueryDoubleAttribute(E0str, el);
string Lstr = "L";
L = QueryDoubleAttribute(Lstr, el);
}
}
delete doc;
cout << "Input file read successfully!" << endl;
return 0;
}
void Input::Print() {
cout << endl;
cout << "************************************** " << endl;
cout << "You selected the following parameters: " << endl;
cout << "Emin [GeV] : " << Emin_GeV << endl;
cout << "Emax [GeV] : " << Emax_GeV << endl;
cout << "number of energy points : " << nE << endl;
cout << "deltat : " << deltat << endl;
cout << "SNR energy output [10^48 GeV] : " << SNR_energy_output << endl;
cout << "inj slope : " << SNR_slope << endl;
cout << "************************************** " << endl;
cout << endl;
}