TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcmisc
halflife.c
Go to the documentation of this file.
1
6
/****************************************************************************/
7
#include "
libtpcmisc.h
"
8
/****************************************************************************/
9
10
/****************************************************************************/
15
static
char
*isotope_code[] = {
16
"Br-75"
,
"Br-76"
,
"Cu-62"
,
"Cu-64"
,
"Fe-52"
,
17
"Ga-68"
,
"Ge-68"
,
"Na-22"
,
"Rb-82"
,
"Zn-62"
,
18
"F-18"
,
"C-11"
,
"N-13"
,
"O-15"
,
"O-14"
,
"I-124"
,
19
0};
21
static
double
isotope_halflife[] = {
22
HL_Br75
,
HL_Br76
,
HL_Cu62
,
HL_Cu64
,
HL_Fe52
,
23
HL_Ga68
,
HL_Ge68
,
HL_Na22
,
HL_Rb82
,
HL_Zn62
,
24
HL_F18
,
HL_C11
,
HL_N13
,
HL_O15
,
HL_O14
,
HL_I124
,
25
0.0
26
};
27
/****************************************************************************/
28
29
/****************************************************************************/
36
char
*
hlIsotopeCode
(
int
isotope) {
37
static
char
unknown_isotope[]=
"unknown"
;
38
int
n=0;
39
40
while
(isotope_code[n]!=0) n++;
41
if
(isotope<0 || isotope>n-1)
return
(unknown_isotope);
42
else
return
(isotope_code[isotope]);
43
}
44
/****************************************************************************/
45
46
/****************************************************************************/
55
double
hlFromIsotope
(
57
char
*isocode
58
) {
59
char
*corrected_isocode;
60
int
i = 0;
61
int
ok = 0;
62
63
/* Validate the isotope string */
64
corrected_isocode=
hlCorrectIsotopeCode
(isocode);
65
if
(corrected_isocode==NULL)
return
(-1.0);
66
67
/* Determine the isotope and return the half-life */
68
while
(isotope_code[i]!=0) {
69
if
(strcmp(isotope_code[i], corrected_isocode)==0) {ok=1;
break
;}
70
i++;
71
}
72
if
(ok==1)
return
(isotope_halflife[i]);
73
else
return
(-2.0);
74
}
75
/****************************************************************************/
76
77
/****************************************************************************/
84
double
hl2lambda
(
double
halflife) {
85
if
(halflife>0.0)
return
(
M_LN2
/halflife);
else
return
(-1.0);
// M_LN2=log(2.0)
86
}
87
/****************************************************************************/
88
89
/****************************************************************************/
98
double
hlLambda2factor
(
double
lambda,
double
frametime,
double
framedur) {
99
double
cf, ff;
100
101
if
(frametime<0)
return
(-1.0);
102
cf=exp(lambda*frametime);
103
if
(framedur>1.0E-5) {
104
ff=fabs(lambda)*framedur/(1.0-exp(-fabs(lambda)*framedur));
105
if
(lambda<0.0) cf/=ff;
else
cf*=ff;
106
}
107
return
(cf);
108
}
109
118
float
hlLambda2factor_float
(
float
lambda,
float
frametime,
float
framedur) {
119
float
cf, ff;
120
121
if
(frametime<0)
return
(-1.0);
122
cf=exp(lambda*frametime);
123
if
(framedur>1.0E-5) {
124
ff=fabs(lambda)*framedur/(1.0-exp(-fabs(lambda)*framedur));
125
if
(lambda<0.0) cf/=ff;
else
cf*=ff;
126
}
127
return
(cf);
128
}
129
/****************************************************************************/
130
131
/****************************************************************************/
141
char
*
hlCorrectIsotopeCode
(
char
*isocode) {
142
int
i, ok=0, n, mass_nr=0, ic_mass_nr=0;
143
char
*cptr, atom[3], ic_atom[3];
144
145
/* Check, if isocode can be found in the list */
146
i=ok=0;
147
while
(isotope_code[i]!=0) {
148
if
(strcasecmp(isotope_code[i], isocode)==0) {
149
ok=1;
150
break
;
151
}
152
i++;
153
}
154
if
(ok==1)
return
(isotope_code[i]);
155
156
/* Try to figure out what it is */
157
/* Separate the atom name and mass number */
158
n=strcspn(isocode,
"-1234567890"
);
159
if
(n>2) {
/* cannot be */
160
return
(NULL);
161
}
else
if
(n>0) {
/* start with atom name */
162
strncpy(atom, isocode, n); atom[n]=(char)0;
163
mass_nr=atoi(isocode+n);
if
(mass_nr<0) mass_nr=-mass_nr;
164
}
else
{
/* starts with mass number */
165
mass_nr=atoi(isocode);
166
cptr=isocode;
while
(isdigit((
int
)cptr[0])) cptr++;
167
if
(strlen(cptr)>2)
return
(NULL);
168
strcpy(atom, cptr);
169
}
170
/* Check if it matches any of the listed isotopes */
171
i=ok=0;
172
while
(isotope_code[i]!=0) {
173
/* Separate the atom name and mass number from the listed isotope */
174
n=strcspn(isotope_code[i],
"-1234567890"
);
175
strncpy(ic_atom, isotope_code[i], n); ic_atom[n]=(char)0;
176
ic_mass_nr=atoi(isotope_code[i]+n+1);
177
/* Check the atom name */
178
if
(strcasecmp(ic_atom, atom)!=0) {i++;
continue
;}
179
/* Check the mass number, if given */
180
if
(mass_nr>0 && ic_mass_nr!=mass_nr) {i++;
continue
;}
181
/* Match was found! */
182
ok=1;
break
;
183
}
184
if
(ok==1)
return
(isotope_code[i]);
else
return
(NULL);
185
}
186
/****************************************************************************/
187
188
/****************************************************************************/
195
int
hlIsotopeFromHalflife
(
double
halflife) {
196
int
i=0, ok=0;
197
if
(halflife<=0.01)
return
(-1);
198
while
(isotope_halflife[i]>0.0) {
199
if
( fabs(halflife/isotope_halflife[i]-1.0)<0.05 ) {ok=1;
break
;}
200
i++;
201
}
202
if
(ok==1)
return
(i);
203
else
return
(-2.0);
204
}
205
/****************************************************************************/
206
207
/****************************************************************************/
208
hl2lambda
double hl2lambda(double halflife)
Definition
halflife.c:84
hlIsotopeCode
char * hlIsotopeCode(int isotope)
Definition
halflife.c:36
hlLambda2factor
double hlLambda2factor(double lambda, double frametime, double framedur)
Definition
halflife.c:98
hlLambda2factor_float
float hlLambda2factor_float(float lambda, float frametime, float framedur)
Definition
halflife.c:118
hlCorrectIsotopeCode
char * hlCorrectIsotopeCode(char *isocode)
Definition
halflife.c:141
hlFromIsotope
double hlFromIsotope(char *isocode)
Definition
halflife.c:55
hlIsotopeFromHalflife
int hlIsotopeFromHalflife(double halflife)
Definition
halflife.c:195
libtpcmisc.h
Header file for libtpcmisc.
HL_F18
#define HL_F18
Definition
libtpcmisc.h:49
HL_Ga68
#define HL_Ga68
Definition
libtpcmisc.h:53
HL_O15
#define HL_O15
Definition
libtpcmisc.h:43
HL_Na22
#define HL_Na22
Definition
libtpcmisc.h:68
HL_N13
#define HL_N13
Definition
libtpcmisc.h:45
HL_C11
#define HL_C11
Definition
libtpcmisc.h:47
HL_Cu64
#define HL_Cu64
Definition
libtpcmisc.h:64
HL_Br75
#define HL_Br75
Definition
libtpcmisc.h:58
HL_Br76
#define HL_Br76
Definition
libtpcmisc.h:60
HL_Fe52
#define HL_Fe52
Definition
libtpcmisc.h:66
HL_Zn62
#define HL_Zn62
Definition
libtpcmisc.h:74
HL_Rb82
#define HL_Rb82
Definition
libtpcmisc.h:72
HL_O14
#define HL_O14
Definition
libtpcmisc.h:70
M_LN2
#define M_LN2
Definition
libtpcmisc.h:90
HL_Ge68
#define HL_Ge68
Definition
libtpcmisc.h:51
HL_I124
#define HL_I124
Definition
libtpcmisc.h:76
HL_Cu62
#define HL_Cu62
Definition
libtpcmisc.h:62
Generated on
for TPCCLIB by
1.17.0