9#include "tpcclibConfig.h"
23static char *info[] = {
24 "Calculation of an AUC (integral over time) from regional or plasma TACs.",
26 "Usage: @P [Options] tacfile starttime integrationtime aucfile",
28 "Enter the start time and integration time in the same units that are used",
29 "in the TAC file. Note that 3rd argument is not the integration end time.",
30 "Program will automatically set the integration start time and duration",
31 "based on the time range in the TAC file, if both are set to zero.",
32 "AUC/mean is by default written in DFT format, or in RES format if filename",
33 "has extension .res.",
37 " Average during specified range is calculated instead of AUC.",
40 "Example 1: calculate AUC(32-302) with command",
41 " @P s5998dy1.dft 32 270 s5998int.dft",
42 "Example 2: integrate the regional TACs from a static or dynamic study",
43 "from the start time of the first frame to the end of the last frame:",
44 " @P a773dy1.dft 0 0 a773int.dft",
45 "Example 3: mean between 0 and 10 is calculated and saved in result format:",
46 " @P -avg ec4568.dft 0 10 ec4568_mean0-10.res",
48 "See also: interpol, dftratio, dftsuv, regfur, tacunit, imginteg, tac2suv",
50 "Keywords: TAC, modelling, AUC, autoradiography",
69int main(
int argc,
char **argv)
71 int ai, help=0, version=0, verbose=1;
73 char *cptr, dftfile[FILENAME_MAX], outfile[FILENAME_MAX], tmp[512];
76 double tstart, tstop, tdur;
82 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
83 dftfile[0]=outfile[0]=(char)0;
84 tstart=tdur=tstop=-1.0;
87 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
88 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
90 if(strcasecmp(cptr,
"AVG")==0) {
92 }
else if(strcasecmp(cptr,
"MEAN")==0) {
95 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
100 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
105 for(; ai<argc; ai++) {
107 strlcpy(dftfile, argv[ai], FILENAME_MAX);
continue;
108 }
else if(tstart<0) {
112 }
else if(!outfile[0]) {
113 strlcpy(outfile, argv[ai], FILENAME_MAX);
continue;
115 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
121 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
128 printf(
"dftfile := %s\n", dftfile);
129 printf(
"outfile := %s\n", outfile);
130 printf(
"calc_avg := %d\n", calc_avg);
131 if(tstart>=1.0E-03 || tdur>=1.0E-02) printf(
"tstart := %g\ntstop := %g\n", tstart, tstop);
139 fprintf(stderr,
"Error in reading '%s': %s\n", dftfile,
dfterrmsg);
144 fprintf(stderr,
"Error: missing values in %s.\n", dftfile);
149 if(verbose>1) fprintf(stdout,
"checking frame overlap in %s\n", dftfile);
152 fprintf(stderr,
"Error: %s has overlapping frame times.\n", dftfile);
158 if(tstart<1.0E-03 && tdur<1.0E-02) {
162 tstart=dft.
x[0]; tstop=dft.
x[dft.
frameNr-1];
166 printf(
"tstart := %g\n", tstart);
167 printf(
"tstop := %g\n", tstop);
168 printf(
"tdur := %g\n", tdur);
176 ret=
dftTimeIntegral(&dft, tstart, tstop, &idft, calc_avg, tmp, verbose-2);
178 fprintf(stderr,
"Error: %s\n", tmp);
187 if(calc_avg==0) printf(
"writing AUC in %s\n", outfile);
188 else printf(
"writing mean in %s\n", outfile);
190 cptr=strrchr(outfile,
'.');
if(cptr!=NULL) cptr++;
191 if(strcasecmp(cptr,
"RES")==0) {
196 fprintf(stderr,
"Error in making results: %s\n", tmp);
199 if(calc_avg==0) {strcpy(res.
parname[0],
"AUC");}
206 if(
resWrite(&res, outfile, verbose-3)) {
207 fprintf(stderr,
"Error in writing '%s': %s\n", outfile,
reserrmsg);
214 fprintf(stderr,
"Error in writing %s: %s\n", outfile,
dfterrmsg);
218 if(verbose>0) printf(
"%s written.\n", outfile);
int atof_with_check(char *double_as_string, double *result_value)
int dftDeleteFrameOverlap(DFT *dft)
void dftSetComments(DFT *dft)
int dftTimeIntegral(DFT *dft, double t1, double t2, DFT *idft, int calc_mode, char *status, int verbose)
int dftRead(char *filename, DFT *data)
int dftWrite(DFT *data, char *filename)
int dftToResult(DFT *dft, RES *res, char *status)
Header file for libtpccurveio.
int resWrite(RES *res, char *filename, int verbose)
#define DFT_TIME_STARTEND
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
void tpcProgramName(const char *program, int version, int copyright, char *prname, int n)
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)
Header file for libtpcmodel.
Header file for libtpcmodext.
char unit[MAX_UNITS_LEN+1]
char parname[MAX_RESPARAMS][MAX_RESPARNAME_LEN+1]
char datafile[FILENAME_MAX]
char parunit[MAX_RESPARAMS][MAX_RESPARNAME_LEN+1]