8#include "tpcclibConfig.h"
25static char *info[] = {
26 "Move TAC(s) in time with interpolation, keeping the original sample times",
27 "or time frames in TAC file, and cause only minimal bias in AUC.",
29 "Usage: @P [Options] tacfile delay",
33 " TACs are moved in opposite direction as specified in parameter file.",
35 " Simple linear interpolation is always used; possibly higher AUC bias.",
38 "Delay time can be given as positive or negative value directly in the command",
39 "line, or as dT or deltaT in a parameter file for certain TACs if file",
40 "contains more than one TAC.",
42 "See also: tactime, tacframe, fitdelay, taccut, simframe, tacadd",
44 "Keywords: TAC, simulation, time delay",
63int main(
int argc,
char **argv)
65 int ai, help=0, version=0, verbose=1;
66 char tacfile[FILENAME_MAX], parfile[FILENAME_MAX];
75 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
76 tacfile[0]=parfile[0]=(char)0;
78 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
80 char *cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
81 if(strncasecmp(cptr,
"OPPOSITE", 2)==0) {
83 }
else if(strncasecmp(cptr,
"SIMPLE", 4)==0) {
86 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
95 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
100 if(ai<argc) {
strlcpy(tacfile, argv[ai], FILENAME_MAX); ai++;}
101 if(ai<argc) {
strlcpy(parfile, argv[ai], FILENAME_MAX); ai++;}
102 else {fprintf(stderr,
"Error: missing file name.\n");
return(1);}
104 if(ai<argc) {fprintf(stderr,
"Error: extra command-line argument.\n");
return(1);}
108 fprintf(stderr,
"Error: file '%s' does not exist.\n", tacfile);
116 fprintf(stderr,
"Warning: zero delay time; file not modified.\n");
120 fprintf(stderr,
"Error: invalid argument for delay time: '%s'.\n", parfile);
127 printf(
"tacfile := %s\n", tacfile);
128 if(parfile[0]) printf(
"parfile := %s\n", parfile);
129 if(isfinite(delay)) printf(
"delaytime := %g\n", delay);
130 printf(
"opposite := %d\n", opposite);
131 printf(
"simple := %d\n", simple);
139 if(verbose>1) printf(
"reading %s\n", tacfile);
147 printf(
"tacNr := %d\n", tac.
tacNr);
148 printf(
"sampleNr := %d\n", tac.
sampleNr);
149 if(tac.
isframe) printf(
"frames := yes\n");
else printf(
"frames := no\n");
162 fprintf(stderr,
"Error: %s\n",
errorMsg(ret));
171 fprintf(stderr,
"Error: invalid sample range.\n");
174 if(verbose>1) printf(
"x_range: %g - %g\n", xmin, xmax);
175 if(!(xmax>xmin)) {fprintf(stderr,
"Warning: check the sample times.\n"); fflush(stderr);}
184 if(verbose>1) printf(
"reading %s\n", parfile);
191 printf(
"parNr := %d\n", par.
parNr);
192 printf(
"tacNr := %d\n", par.
tacNr);
199 fprintf(stderr,
"Error: cannot find delay time in %s\n", parfile);
202 fprintf(stderr,
"Error: cannot identify delay time in %s\n", parfile);
205 for(
int i=0; i<par.
parNr; i++)
if(par.
n[i].
sw) {dti=i;
break;}
210 for(
int i=0; i<par.
tacNr; i++) par.
r[i].
p[dti]/=60.0;
213 for(
int i=0; i<par.
tacNr; i++) par.
r[i].
p[dti]*=60.0;
217 delay=par.
r[0].
p[dti];
218 if(opposite) delay=-delay;
219 if(verbose>1) printf(
"delaytime := %g\n", delay);
228 if(isfinite(delay)) {
231 fprintf(stderr,
"Error: cannot move TACs.\n");
236 for(
int i=0; i<tac.
tacNr; i++) {
243 for(
int j=0; j<par.
tacNr; j++)
if(par.
r[j].
sw) {pi=j;
break;}
245 for(
int j=0; j<par.
tacNr; j++)
if(par.
r[j].
sw && j==i) {pi=j;
break;}
248 fprintf(stderr,
"Error: cannot identify delay time for %s\n", tac.
c[i].
name);
251 delay=par.
r[pi].
p[dti];
if(opposite) delay=-delay;
252 if(verbose>3) printf(
" Moving %s for %g\n", tac.
c[i].
name, delay);
254 fprintf(stderr,
"Error: cannot move TAC.\n");
260 if(simple) tac.
isframe=origframe;
266 if(verbose>1) printf(
"saving modified data in %s\n", tacfile);
268 FILE *fp; fp=fopen(tacfile,
"w");
270 fprintf(stderr,
"Error: cannot open file for writing\n");
int atofCheck(const char *s, double *v)
int tacDelay(TAC *tac, double dt, int ti, TPCSTATUS *status)
Move TAC y values (concentrations) in time, keeping sample times (x values) intact.
int fileExist(const char *filename)
char * parFormattxt(parformat c)
int parRead(PAR *par, const char *fname, TPCSTATUS *status)
int parSelectTACs(PAR *d, const char *region_name, int reset, TPCSTATUS *status)
int parSelectParameters(PAR *d, const char *par_name, int reset, TPCSTATUS *status)
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)
char name[MAX_TACNAME_LEN+1]
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)
int tacSortByTime(TAC *d, TPCSTATUS *status)
int tacSetXContiguous(TAC *d)
Set PET TAC frame times contiguous, without even tiny overlap or gaps in between.
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.
char * unitName(int unit_code)
Header file for libtpcfileutil.
Header file for library libtpcift.
Header file for library libtpcisotope.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.
Header file for libtpctacmod.