9#include "tpcclibConfig.h"
24static char *info[] = {
25 "Correction of PET TAC files for physical decay, or removing decay correction.",
27 "Usage: @P [Options] tacfile [outputfile]",
31 " Correct the data for radioactive decay (on, default), or remove",
32 " decay correction (off).",
34 " Most TAC files do not contain the isotope code, thus it can be",
35 " specified with this option.",
36 " Accepted isotope codes are for example F-18, C-11, and O-15.",
38 " Sample times are known to be in seconds or minutes, but is not",
39 " specified or is wrong in TAC file.",
42 "Example 1: remove the correction for physical decay from a F-18 study,",
43 " writing non-corrected data into a new file.",
44 " @P -decay=off -i=F-18 a123ap.bld a123ap_nodecay.bld",
46 "Example 2: correct the TAC data for radioactive decay, overwriting the data.",
47 " @P -decay=on -i=C-11 ia456dy1.tac",
49 "See also: tactime, tacframe, tacunit, tacformat, imgdecay, dcftime",
51 "Keywords: TAC, physical decay, halflife, isotopes, simulation",
70int main(
int argc,
char **argv)
72 int ai, help=0, version=0, verbose=1;
76 char tacfile1[FILENAME_MAX], tacfile2[FILENAME_MAX];
82 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
83 tacfile1[0]=tacfile2[0]=(char)0;
85 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
87 char *cptr=argv[ai]+1;
88 if(strncasecmp(cptr,
"I=", 2)==0) {
91 fprintf(stderr,
"Error: invalid isotope '%s'.\n", cptr);
95 }
else if(strncasecmp(cptr,
"DECAY=", 6)==0) {
97 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
101 }
else if(strncasecmp(cptr,
"MINUTES", 3)==0) {
103 }
else if(strncasecmp(cptr,
"SECONDS", 3)==0) {
106 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
116 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
121 if(ai<argc)
strlcpy(tacfile1, argv[ai++], FILENAME_MAX);
122 if(ai<argc)
strlcpy(tacfile2, argv[ai++], FILENAME_MAX);
124 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
130 fprintf(stderr,
"Error: missing file name; use option --help\n");
134 if(!tacfile2[0]) strcpy(tacfile2, tacfile1);
139 printf(
"tacfile1 := %s\n", tacfile1);
140 printf(
"tacfile2 := %s\n", tacfile2);
141 printf(
"correct := %d\n", correct);
152 if(verbose>1) {fprintf(stdout,
"reading %s\n", tacfile1); fflush(stdout);}
155 fprintf(stderr,
"Error: %s (%s)\n",
errorMsg(status.
error), tacfile1);
160 printf(
"tacNr := %d\n", tac.
tacNr);
161 printf(
"sampleNr := %d\n", tac.
sampleNr);
162 if(tac.
isframe) printf(
"frames := yes\n");
else printf(
"frames := no\n");
167 tac.
tunit=knownTimeunit;
171 fprintf(stderr,
"Error: invalid sample times.\n");
176 fprintf(stderr,
"Warning: assuming that sample times are in seconds.\n");
179 fprintf(stderr,
"Warning: assuming that sample times are in minutes.\n");
191 if(verbose>3) {printf(
"tac.isotope := %s\n",
isotopeName(fisot)); fflush(stdout);}
193 fprintf(stderr,
"Error: valid isotope not specified.\n");
198 if(verbose>1) printf(
"isotope := %s\n",
isotopeName(isot));
202 if(verbose>1) printf(
"isotope := %s\n",
isotopeName(isot));
205 fprintf(stderr,
"Error: different isotope in %s\n", tacfile1);
214 if(verbose>1) printf(
"Note: status of current decay correction is not known.\n");
216 fprintf(stderr,
"Error: physical decay is already corrected in %s.\n", tacfile1);
219 fprintf(stderr,
"Error: physical decay is not corrected in %s.\n", tacfile1);
228 fprintf(stderr,
"Error: %s (%s)\n",
errorMsg(status.
error), tacfile1);
240 if(verbose>1) printf(
"saving %s\n", tacfile2);
242 FILE *fp; fp=fopen(tacfile2,
"w");
244 fprintf(stderr,
"Error: cannot open file for writing\n");
256 if(correct) printf(
" data was corrected for decay with half-life of");
257 else printf(
" decay correction was removed from data with half-life of");
double lambdaFromIsotope(int isotope)
char * isotopeName(int isotope_code)
int isotopeIdentify(const char *isotope)
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
int tpcYesNo(const char *s)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
void statusInit(TPCSTATUS *s)
char * errorMsg(tpcerror e)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
IFT h
Optional (but often useful) header information.
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
int tacGetIsotope(TAC *tac)
int tacDecayCorrection(TAC *tac, int isotope, int mode, TPCSTATUS *status)
void tacSetIsotope(TAC *tac, int isotope)
decaycorrection tacGetHeaderDecayCorrection(IFT *h)
int tacSetHeaderDecayCorrection(IFT *h, decaycorrection dc)
int tacRead(TAC *d, const char *fname, TPCSTATUS *status)
char * tacFormattxt(tacformat c)
int tacWrite(TAC *tac, FILE *fp, tacformat format, int extra, TPCSTATUS *status)
int tacXRange(TAC *d, double *xmin, double *xmax)
Get the range of x values (times) in TAC structure.
Header file for library libtpccsv.
Header file for library libtpcextensions.
@ UNIT_UNKNOWN
Unknown unit.
char * unitName(int unit_code)
Header file for library libtpcift.
Header file for library libtpcisotope.
@ DECAY_UNKNOWN
Not known; usually assumed that data is corrected.
@ DECAY_NOTCORRECTED
Data is not corrected for physical decay.
@ DECAY_CORRECTED
Data is corrected for physical decay.
@ ISOTOPE_UNKNOWN
Unknown.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.