TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
halflife
halflife.c
Go to the documentation of this file.
1
7
/*****************************************************************************/
8
#include "tpcclibConfig.h"
9
/*****************************************************************************/
10
#include <stdio.h>
11
#include <stdlib.h>
12
#include <math.h>
13
#include <time.h>
14
#include <string.h>
15
/*****************************************************************************/
16
#include "
tpcextensions.h
"
17
#include "
tpcisotope.h
"
18
/*****************************************************************************/
19
20
/*****************************************************************************/
21
/* Local functions */
22
23
/*****************************************************************************/
24
25
/*****************************************************************************/
26
static
char
*info[] = {
27
"List the PET isotopes and their half-lives (min) that are identified by"
,
28
"most TPC software."
,
29
" "
,
30
"Usage: @P [options] [> outputfile]"
,
31
" "
,
32
"Options:"
,
33
" -i=<Isotope code>"
,
34
" Show only the given isotope."
,
35
" -lambda"
,
36
" Lambda value (1/min) is listed."
,
37
" -pf"
,
38
" Positron fraction (branching ratio) is listed."
,
39
" -sec"
,
40
" Half-lives are listed in seconds and lambdas 1/sec."
,
41
" -stdoptions"
,
// List standard options like --help, -v, etc
42
" "
,
43
"See also: tacdecay, imgdecay, tactime, ecattime, dcftime"
,
44
" "
,
45
"Keywords: physical decay, decay correction, halflife, isotope"
,
46
0};
47
/*****************************************************************************/
48
49
/*****************************************************************************/
50
/* Turn on the globbing of the command line, since it is disabled by default in
51
mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
52
In Unix&Linux wildcard command line processing is enabled by default. */
53
/*
54
#undef _CRT_glob
55
#define _CRT_glob -1
56
*/
57
int
_dowildcard = -1;
58
/*****************************************************************************/
59
60
/*****************************************************************************/
64
int
main(
int
argc,
char
**argv)
65
{
66
int
ai, help=0, version=0, verbose=1;
67
int
do_lambda=0;
68
int
do_br=0;
69
int
tunit=
UNIT_MIN
,
isotope
=
ISOTOPE_UNKNOWN
;
70
double
f;
71
72
73
/*
74
* Get arguments
75
*/
76
/* Options */
77
for
(ai=1; ai<argc; ai++)
if
(*argv[ai]==
'-'
) {
78
if
(
tpcProcessStdOptions
(argv[ai], &help, &version, &verbose)==0)
continue
;
79
char
*cptr=argv[ai]+1;
80
if
(strncasecmp(cptr,
"I="
, 2)==0) {
81
cptr+=2;
isotope
=
isotopeIdentify
(cptr);
82
if
(
isotope
!=
ISOTOPE_UNKNOWN
)
continue
;
83
fprintf(stderr,
"Error: invalid isotope '%s'\n"
, cptr);
return
(1);
84
}
else
if
(strncasecmp(cptr,
"LAMBDA"
, 3)==0) {
85
do_lambda=1;
continue
;
86
}
else
if
(strcasecmp(cptr,
"PF"
)==0 || strcasecmp(cptr,
"BR"
)==0) {
87
do_br=1;
continue
;
88
}
else
if
(strncasecmp(cptr,
"SECONDS"
, 3)==0) {
89
tunit=
UNIT_SEC
;
continue
;
90
}
91
fprintf(stderr,
"Error: invalid option '%s'\n"
, argv[ai]);
92
return
(1);
93
}
94
/* Non-options */
95
for
(ai=1; ai<argc; ai++)
if
(*argv[ai]!=
'-'
) {
96
fprintf(stderr,
"Error: invalid argument '%s'\n"
, argv[ai]);
97
return
(1);
98
}
99
/* Print help or version? */
100
if
(help==2) {
tpcHtmlUsage
(argv[0], info,
""
);
return
(0);}
101
if
(help) {
tpcPrintUsage
(argv[0], info, stdout);
return
(0);}
102
if
(version) {
tpcPrintBuild
(argv[0], stdout);
return
(0);}
103
/* In verbose mode print arguments and options */
104
if
(verbose>1) {
105
for
(ai=0; ai<argc; ai++) printf(
"%s "
, argv[ai]);
106
printf(
"\n"
);
107
printf(
"do_lambda := %d\n"
, do_lambda);
108
printf(
"do_br := %d\n"
, do_br);
109
printf(
"isotope := %s\n"
,
isotopeName
(
isotope
));
110
printf(
"tunit := %d\n"
, tunit);
111
}
112
113
/* Print specified isotope, or all isotopes */
114
f=1.0;
if
(tunit==
UNIT_SEC
) f=60.0;
115
if
(
isotope
!=
ISOTOPE_UNKNOWN
) {
116
fprintf(stdout,
"isotope := %s\n"
,
isotopeName
(
isotope
));
117
fprintf(stdout,
"halflife := %g\n"
, f*
isotopeHalflife
(
isotope
));
118
if
(do_lambda!=0) fprintf(stdout,
"lambda := %.3e\n"
,
lambdaFromIsotope
(
isotope
)/f);
119
if
(do_br!=0) fprintf(stdout,
"positron_fraction := %g\n"
,
isotopeBranching
(
isotope
));
120
}
else
{
121
int
i=1;
122
while
(!isnan(
isotopeHalflife
(i))) {
123
fprintf(stdout,
"isotope := %s\n"
,
isotopeName
(i));
124
fprintf(stdout,
"halflife := %g\n"
, f*
isotopeHalflife
(i));
125
if
(do_lambda!=0) fprintf(stdout,
"lambda := %.3e\n"
,
lambdaFromIsotope
(i)/f);
126
if
(do_br!=0) fprintf(stdout,
"positron_fraction := %g\n"
,
isotopeBranching
(i));
127
i++;
128
}
129
}
130
return
(0);
131
}
132
/*****************************************************************************/
133
134
/*****************************************************************************/
lambdaFromIsotope
double lambdaFromIsotope(int isotope)
Definition
decay.c:63
isotopeName
char * isotopeName(int isotope_code)
Definition
isotope.c:101
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
tpcProcessStdOptions
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition
proginfo.c:47
tpcHtmlUsage
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition
proginfo.c:169
tpcPrintBuild
void tpcPrintBuild(const char *program, FILE *fp)
Definition
proginfo.c:339
tpcPrintUsage
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition
proginfo.c:114
tpcextensions.h
Header file for library libtpcextensions.
UNIT_MIN
@ UNIT_MIN
minutes
Definition
tpcextensions.h:90
UNIT_SEC
@ UNIT_SEC
seconds
Definition
tpcextensions.h:89
tpcisotope.h
Header file for library libtpcisotope.
isotope
isotope
Definition
tpcisotope.h:50
ISOTOPE_UNKNOWN
@ ISOTOPE_UNKNOWN
Unknown.
Definition
tpcisotope.h:51
Generated on
for TPCCLIB by
1.17.0