TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcisotope
isotope.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <math.h>
10
#include <time.h>
11
#include <string.h>
12
/*****************************************************************************/
13
#include "
tpcisotope.h
"
14
/*****************************************************************************/
15
16
/*****************************************************************************/
19
typedef
struct
TPC_ISOTOPE {
21
char
name[
MAX_ISOTOPE_LEN
];
23
double
hl;
25
double
br;
26
} TPC_ISOTOPE;
27
30
static
TPC_ISOTOPE tpc_isotope[]={
31
{
"unknown"
, 0., 0.},
32
{
"Br-75"
, 98.0, 0.90},
33
{
"Br-76"
, 978.33, 0.62},
34
{
"Cu-62"
, 9.7, 1.0},
35
{
"Cu-64"
, 762.018, 0.174},
36
{
"Fe-52"
, 4980.0, 0.56},
37
{
"Ga-68"
, 68.0, 0.891},
38
{
"Ge-68"
, 396000.0, 0.891},
39
{
"Na-22"
, 1368000.0, 0.906},
40
{
"Rb-82"
, 1.25, 0.950},
41
{
"Sc-44"
, 238.2, 0.94},
42
{
"Tb-152"
,1050.0, 0.17},
43
{
"Zn-62"
, 548.0, 0.18},
44
{
"Zr-89"
, 4704.0, 0.22},
45
{
"C-11"
, 20.4, 0.998},
46
{
"F-18"
, 109.8, 0.967},
47
{
"I-124"
, 6013.44, 0.26},
48
{
"N-13"
, 10.0, 0.998},
49
{
"O-15"
, 2.05, 0.999},
50
{
"O-14"
, 1.1818, 1.0},
51
{
""
, 0., 0.}
52
};
54
/*****************************************************************************/
55
56
/*****************************************************************************/
62
double
isotopeHalflife
(
64
int
isotope_code
65
) {
66
int
n=0;
67
68
while
(strlen(tpc_isotope[n].name)>1) n++;
69
if
(isotope_code<1 || isotope_code>n-1)
return
nan(
""
);
70
else
return
(tpc_isotope[isotope_code].hl);
71
}
72
/*****************************************************************************/
73
74
/*****************************************************************************/
81
double
isotopeBranching
(
83
int
isotope_code
84
) {
85
int
n=0;
86
87
while
(strlen(tpc_isotope[n].name)>1) n++;
88
if
(isotope_code<1 || isotope_code>n-1)
return
nan(
""
);
89
else
if
(tpc_isotope[isotope_code].br<1.0E-10)
return
nan(
""
);
90
else
return
(tpc_isotope[isotope_code].br);
91
}
92
/*****************************************************************************/
93
94
/*****************************************************************************/
101
char
*
isotopeName
(
103
int
isotope_code
104
) {
105
int
n=0;
106
107
while
(strlen(tpc_isotope[n].name)>1) n++;
108
if
(isotope_code<1 || isotope_code>n-1)
109
return
tpc_isotope[
ISOTOPE_UNKNOWN
].name;
110
else
111
return
(tpc_isotope[isotope_code].name);
112
}
113
/*****************************************************************************/
114
115
/*****************************************************************************/
121
int
isotopeIdentifyHalflife
(
123
double
halflife
124
) {
125
if
(halflife<=0.01)
return
ISOTOPE_UNKNOWN
;
126
int
i, n=0;
127
while
(strlen(tpc_isotope[n].name)>1) n++;
128
/* Check, if halflife can be found in the table */
129
for
(i=1; i<n; i++) {
130
if
(fabs(halflife/tpc_isotope[i].hl-1.0)<0.05 )
return
i;
131
}
132
return
ISOTOPE_UNKNOWN
;
133
}
134
/*****************************************************************************/
135
136
/*****************************************************************************/
145
int
isotopeIdentify
(
147
const
char
*
isotope
148
) {
149
if
(
isotope
==NULL ||
strnlen
(
isotope
, 5)<1)
return
ISOTOPE_UNKNOWN
;
150
151
unsigned
short
int
i, n=0;
152
while
(strlen(tpc_isotope[n].name)>1) n++;
153
154
/* Check, if isotope can be found directly in the table */
155
for
(i=0; i<n; i++) {
156
if
(strcasecmp(tpc_isotope[i].name,
isotope
)==0)
return
(i);
157
}
158
159
/* Ok it was not that easy... try to figure out what it is */
160
char
*cptr;
161
int
mass_nr=0, ic_mass_nr=0;
162
/* Find the element */
163
unsigned
short
int
z=
elementIdentify
(
isotope
);
164
if
(z==0)
return
(
ISOTOPE_UNKNOWN
);
165
/* Now find the mass number */
166
cptr=strpbrk(
isotope
,
"123456789"
);
// mass cannot start with zero
167
if
(cptr!=NULL) {
168
mass_nr=atoi(cptr);
169
}
170
//printf("fixed isotope: %s-%d\n", elementSymbol(z), mass_nr);
171
172
/* Check if element and mass matches any of the isotopes in our table */
173
for
(i=1; i<n; i++) {
174
/* check the element */
175
if
(
elementIdentify
(tpc_isotope[i].name)!=z)
continue
;
176
/* check the mass, if found */
177
cptr=strchr(tpc_isotope[i].name,
'-'
);
if
(cptr==NULL)
continue
;
178
ic_mass_nr=atoi(cptr+1);
179
if
(mass_nr>0 && ic_mass_nr!=mass_nr)
continue
;
180
/* Match was found! */
181
return
(i);
182
}
183
184
return
(
ISOTOPE_UNKNOWN
);
185
}
186
/*****************************************************************************/
187
188
/*****************************************************************************/
elementIdentify
unsigned short int elementIdentify(const char *str)
Definition
elements.c:298
isotopeName
char * isotopeName(int isotope_code)
Definition
isotope.c:101
isotopeIdentifyHalflife
int isotopeIdentifyHalflife(double halflife)
Definition
isotope.c:121
isotopeBranching
double isotopeBranching(int isotope_code)
Definition
isotope.c:81
isotopeHalflife
double isotopeHalflife(int isotope_code)
Definition
isotope.c:62
isotopeIdentify
int isotopeIdentify(const char *isotope)
Definition
isotope.c:145
strnlen
size_t strnlen(const char *s, size_t n)
Definition
stringext.c:565
tpcisotope.h
Header file for library libtpcisotope.
MAX_ISOTOPE_LEN
#define MAX_ISOTOPE_LEN
Max string length for PET isotope.
Definition
tpcisotope.h:41
isotope
isotope
Definition
tpcisotope.h:50
ISOTOPE_UNKNOWN
@ ISOTOPE_UNKNOWN
Unknown.
Definition
tpcisotope.h:51
Generated on
for TPCCLIB by
1.17.0