TPCCLIB
Loading...
Searching...
No Matches
isotope.c File Reference

Isotope halflife functions. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcisotope.h"

Go to the source code of this file.

Functions

double isotopeHalflife (int isotope_code)
 
double isotopeBranching (int isotope_code)
 
char * isotopeName (int isotope_code)
 
int isotopeIdentifyHalflife (double halflife)
 
int isotopeIdentify (const char *isotope)
 

Detailed Description

Isotope halflife functions.

Definition in file isotope.c.

Function Documentation

◆ isotopeBranching()

double isotopeBranching ( int isotope_code)

Get the branching ratio (fraction) of an isotope spcecified with its isotope_code.

See also
isotopeHalflife, isotopeName, lambdaFromIsotope, decayCorrectionFactorFromIsotope
Returns
branching ratio of the isotope, or NaN if not identified.
Author
Vesa Oikonen
Parameters
isotope_codeisotope_code as enum or the index of isotope in isotope table

Definition at line 81 of file isotope.c.

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}

◆ isotopeHalflife()

double isotopeHalflife ( int isotope_code)

Get the half-life (in minutes) of an isotope specified with its isotope_code.

See also
isotopeBranching, isotopeName, lambdaFromIsotope, decayCorrectionFactorFromIsotope
Returns
halflife of the isotope in minutes, or NaN if not identified.
Author
Vesa Oikonen
Parameters
isotope_codeisotope_code as enum or the index of isotope in isotope table.

Definition at line 62 of file isotope.c.

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}

Referenced by abssWrite(), imgWriteDICOM(), lambdaFromIsotope(), and tacDecayCorrection().

◆ isotopeIdentify()

int isotopeIdentify ( const char * isotope)

Identify the given string representation of isotope, whether it is in format like 'C-11', '11C', '^11^C', or '^11^Carbon'. Even a one-letter symbol like 'C' may be accepted for the most common PET isotopes.

See also
isotopeHalflife, isotopeName, lambdaFromIsotope, decayCorrectionFactorFromIsotope, elementIdentify
Returns
Isotope code, or 0 (enum ISOTOPE_UNKNOWN) if not identified.
Author
Vesa Oikonen
Parameters
isotopeName of isotope to identify.

Definition at line 145 of file isotope.c.

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}
unsigned short int elementIdentify(const char *str)
Definition elements.c:298
size_t strnlen(const char *s, size_t n)
Definition stringext.c:566
isotope
Definition tpcisotope.h:50
@ ISOTOPE_UNKNOWN
Unknown.
Definition tpcisotope.h:51

Referenced by abssWrite(), dcmImgIsotope(), tacGetIsotope(), tacRead4DM(), and tacReadSIF().

◆ isotopeIdentifyHalflife()

int isotopeIdentifyHalflife ( double halflife)

Identify the isotope based on halflife.

Returns
Isotope code, or 0 (enum ISOTOPE_UNKNOWN) if not identified.
See also
isotopeName, lambdaFromIsotope, decayCorrectionFactorFromIsotope
Author
Vesa Oikonen
Parameters
halflifeHalflife in minutes

Definition at line 121 of file isotope.c.

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}

Referenced by dcmImgIsotope().

◆ isotopeName()

char * isotopeName ( int isotope_code)

Get the string representation of an isotope specified with its isotope_code.

See also
isotopeBranching, isotopeHalflife, elementName, elementSymbol
Returns
pointer to string representation of the isotope, "unknown" if not identified.
Author
Vesa Oikonen
Parameters
isotope_codeisotope_code as enum or the index of isotope in isotope table.

Definition at line 101 of file isotope.c.

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}

Referenced by dcmImgIsotope(), imgContents(), imgFillOHeader(), imgReadDICOM(), sifWeight(), tacRead4DM(), tacReadSIF(), tacSetIsotope(), tacSetWeights(), and tacWByFreq().