9#include "tpcclibConfig.h"
23static char *info[] = {
24 "This program replaces the TAC frame start and end times with mid times,",
25 "and the y values with estimates that aim to conserve the AUC.",
26 "The concentrations (y values) in PET TACs with frame start and end times",
27 "represent the average concentration during the frame duration (fdur).",
28 "For each frame AUC=y*fdur. However, AUC is usually needed at frame mid time",
29 "and frame AUC at frame mid time as AUC=y*fdur/2, or calculating area under",
30 "curve formed by joining TAC data points with lines, will lead to biased AUCs.",
32 "Not to be used in actual data analyses!",
34 "Usage: @P [Options] tacfile newfile",
39 "See also: tacframe, simframe, tacsetx, tacadd0, tacformat",
41 "Keywords: TAC, tool, software testing",
60int main(
int argc,
char **argv)
62 int ai, help=0, version=0, verbose=1;
65 char tacfile1[FILENAME_MAX], tacfile2[FILENAME_MAX];
71 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
72 tacInit(&tac); tacfile1[0]=tacfile2[0]=(char)0;
74 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
77 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
86 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
91 for(; ai<argc; ai++) {
93 strlcpy(tacfile1, argv[ai], FILENAME_MAX);
continue;
94 }
else if(!tacfile2[0]) {
95 strlcpy(tacfile2, argv[ai], FILENAME_MAX);
continue;
97 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
101 if(!tacfile2[0]) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
105 for(ai=0; ai<argc; ai++)
106 printf(
"%s ", argv[ai]);
108 printf(
"tacfile1 := %s\n", tacfile1);
109 printf(
"tacfile2 := %s\n", tacfile2);
115 if(verbose>1) printf(
"reading %s\n", tacfile1);
116 ret=
tacRead(&tac, tacfile1, &status);
118 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
123 printf(
"tacNr := %d\n", tac.
tacNr);
124 printf(
"sampleNr := %d\n", tac.
sampleNr);
130 fprintf(stderr,
"Error: file does not contain frame start and end times.\n");
134 fprintf(stderr,
"Error: missing sample times in TAC file.\n");
139 fprintf(stderr,
"Warning: TAC contains only %d sample(s).\n", tac.
sampleNr);
148 for(
int i=0; i<tac.
tacNr && !ret; i++) {
149 ret=liFrameMidValue(tac.
x1, tac.
x2, tac.
c[i].
y, tac.
sampleNr, y2, verbose-2);
150 for(
int j=0; j<tac.
sampleNr; j++) tac.
c[i].
y[j]=y2[j];
153 fprintf(stderr,
"Error: cannot calculate y values.\n");
154 if(verbose>0) printf(
"ret := %d\n", ret);
163 if(verbose>2) printf(
"writing %s\n", tacfile2);
164 FILE *fp; fp=fopen(tacfile2,
"w");
166 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", tacfile2);
172 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
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)
int verbose
Verbose level, used by statusPrint() etc.
tpcerror error
Error code.
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)
Header file for library libtpcextensions.
char * unitName(int unit_code)
Header file for libtpcli.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.