8#include "tpcclibConfig.h"
20static char *info[] = {
21 "Extract specified y (concentration) interval from PET time-activity",
24 "Usage: @P [Options] tacfile lower upper [outputfile]",
29 "See also: taccut, tacblend, tacinv, tacsety, dftmax, tacdel, tacsplit, taclkup",
31 "Keywords: TAC, tool, simulation, cropping",
50int main(
int argc,
char **argv)
52 int ai, help=0, version=0, verbose=1;
54 char dfile1[FILENAME_MAX], dfile2[FILENAME_MAX];
55 double lowerY, upperY;
60 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
61 dfile1[0]=dfile2[0]=(char)0;
62 lowerY=upperY=nan(
"");
64 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
66 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
75 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
80 if(ai<argc) {
strlcpy(dfile1, argv[ai++], FILENAME_MAX);}
83 if(ai<argc) {
strlcpy(dfile2, argv[ai++], FILENAME_MAX);}
85 fprintf(stderr,
"Error: too many arguments: '%s'.\n", argv[ai]);
90 if(!dfile1[0] || isnan(lowerY) || isnan(upperY) || upperY<lowerY) {
95 if(!dfile2[0]) strcpy(dfile2, dfile1);
99 printf(
"dfile1 := %s\n", dfile1);
100 printf(
"dfile2 := %s\n", dfile2);
101 printf(
"lowerY := %g\n", lowerY);
102 printf(
"upperY := %g\n", upperY);
109 if(verbose>1) printf(
"reading %s\n", dfile1);
111 ret=
tacRead(&tac, dfile1, &status);
118 printf(
"tacNr := %d\n", tac.
tacNr);
119 printf(
"sampleNr := %d\n", tac.
sampleNr);
125 ret=
tacYRange(&tac, -1, &ymin, &ymax, NULL, NULL, NULL, NULL);
126 if(ret!=0 || origNr<1) {
127 fprintf(stderr,
"Error: invalid value range in file.\n");
131 printf(
"orig_min := %g\n", ymin);
132 printf(
"orig_max := %g\n", ymax);
135 if(ymin>=lowerY && ymax<=upperY) {
136 if(verbose>1) printf(
"all values are inside required range.\n");
138 if(strcasecmp(dfile1, dfile2)==0) {
139 if(verbose>0) printf(
"nothing done.\n");
143 if(verbose>1) printf(
"writing %s\n", dfile2);
144 FILE *fp; fp=fopen(dfile2,
"w");
146 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", dfile2);
155 if(verbose>0) printf(
"All sample(s) were extracted.\n");
167 for(j=0; j<tac.
tacNr; j++) {
168 if(tac.
c[j].
y[i]<lowerY || tac.
c[j].
y[i]>upperY) tac.
c[j].
y[i]=nan(
"");
169 if(!isnan(tac.
c[j].
y[i])) n++;
172 if(n==0) tac.
x[i]=tac.
x1[i]=tac.
x2[i]=nan(
"");
177 if(verbose>1) printf(
"deleting missing samples\n");
182 printf(
"original_sampleNr := %d\n", origNr);
183 printf(
"final_sampleNr := %d\n", finalNr);
186 fprintf(stderr,
"Error: no data inside the range.\n");
193 if(verbose>1) printf(
"writing %s\n", dfile2);
194 FILE *fp; fp=fopen(dfile2,
"w");
196 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", dfile2);
double atofVerified(const char *s)
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)
int tacNotNaNs(TAC *tac, const int i)
int tacDeleteMissingSamples(TAC *d)
Delete those samples (time frames) from TAC structure, which contain only missing y values,...
int tacYRange(TAC *d, int i, double *ymin, double *ymax, int *smin, int *smax, int *imin, int *imax)
Get the range of y values (concentrations) in TAC struct.
Header file for library libtpcextensions.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.