-
Notifications
You must be signed in to change notification settings - Fork 1
/
nuclear_masses.cpp
72 lines (68 loc) · 1.6 KB
/
nuclear_masses.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
#include "nuclear_masses.h"
// constructor
nuclear_masses::nuclear_masses (const char * file_conf_name) :
electron_mass(0.510998918),
UMA_MeV(931.494028)
{
std::string line;
int N,Z,A;
double mass;
char element[2];
std::fstream file_in;
file_in.open(file_conf_name, std::ios::in);
if (!file_in.is_open()) return;
/*allocazione*/
atomic_masses=(double**) new double*[300];
element_names=(char***) new char**[300];
for(int i=0; i<300; i++)
{
atomic_masses[i]=(double*)new double[300];
element_names[i]=(char**) new char*[300];
for(int j=0; j<300; j++)
{
element_names[i][j]=(char*)new char[3]();
}
}
/*lettura file*/
for(int k = 0; getline(file_in,line) ;k++)
{
if(!(line.find('*')==line.npos)) continue;
std::istringstream buffer (line);
buffer>>N>>Z>>A>>element>>mass;
atomic_masses[Z][A]=mass;
strcpy (element_names[Z][A],element);
}
return;
}
// destructor
nuclear_masses::~nuclear_masses()
{
if(atomic_masses)
{
for(int i=0; i<300; i++)
{
delete [] atomic_masses[i];
}
delete [] atomic_masses;
}
if(element_names)
{
for(int i=0; i<300; i++)
{
for(int j=0; j<300; j++)
{
delete [] element_names[i][j];
}
delete [] element_names[i];
}
delete [] element_names;
}
}
double nuclear_masses::get_mass_Z_A(int Z, int A) const
{
return atomic_masses[Z][A]*UMA_MeV-electron_mass*Z;
}
double nuclear_masses::get_mass_Z_A_uma(int Z, int A) const
{
return atomic_masses[Z][A]-electron_mass*Z/UMA_MeV;
}