TPCCLIB
Loading...
Searching...
No Matches
halflife.c
Go to the documentation of this file.
1
6/****************************************************************************/
7#include "libtpcmisc.h"
8/****************************************************************************/
9
10/****************************************************************************/
15static 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",
190};
21static double isotope_halflife[] = {
25 0.0
26};
27/****************************************************************************/
28
29/****************************************************************************/
36char *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/****************************************************************************/
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/****************************************************************************/
84double 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/****************************************************************************/
98double 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}
118float 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/****************************************************************************/
141char *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/****************************************************************************/
195int 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
double hl2lambda(double halflife)
Definition halflife.c:84
char * hlIsotopeCode(int isotope)
Definition halflife.c:36
double hlLambda2factor(double lambda, double frametime, double framedur)
Definition halflife.c:98
float hlLambda2factor_float(float lambda, float frametime, float framedur)
Definition halflife.c:118
char * hlCorrectIsotopeCode(char *isocode)
Definition halflife.c:141
double hlFromIsotope(char *isocode)
Definition halflife.c:55
int hlIsotopeFromHalflife(double halflife)
Definition halflife.c:195
Header file for libtpcmisc.
#define HL_F18
Definition libtpcmisc.h:49
#define HL_Ga68
Definition libtpcmisc.h:53
#define HL_O15
Definition libtpcmisc.h:43
#define HL_Na22
Definition libtpcmisc.h:68
#define HL_N13
Definition libtpcmisc.h:45
#define HL_C11
Definition libtpcmisc.h:47
#define HL_Cu64
Definition libtpcmisc.h:64
#define HL_Br75
Definition libtpcmisc.h:58
#define HL_Br76
Definition libtpcmisc.h:60
#define HL_Fe52
Definition libtpcmisc.h:66
#define HL_Zn62
Definition libtpcmisc.h:74
#define HL_Rb82
Definition libtpcmisc.h:72
#define HL_O14
Definition libtpcmisc.h:70
#define M_LN2
Definition libtpcmisc.h:90
#define HL_Ge68
Definition libtpcmisc.h:51
#define HL_I124
Definition libtpcmisc.h:76
#define HL_Cu62
Definition libtpcmisc.h:62