8#include "tpcclibConfig.h"
23static char *info[] = {
24 "Determines the time when TAC in file 2 crosses over the TAC in file 1.",
25 "The first time point (x) of file 2 after which at least the given nr of",
26 "samples (y values) become all lower or higher than the samples in file 1",
27 "is written to stdout.",
28 "Only the first TAC of data files is used.",
30 "Usage: @P [options] file1 file2 nr",
34 " Cross-over point is written in stdout with explanations.",
38 " @P iea345_lvcav.bld iea345_vena_cava.bld 3",
40 "See also: taccut, tacsplit, tacadd, taccut, tacdel, tacsort",
42 "Keywords: TAC, input, tool",
61int main(
int argc,
char **argv)
63 int ai, help=0, version=0, verbose=1;
65 char *cptr, tacfile1[FILENAME_MAX], tacfile2[FILENAME_MAX];
75 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
77 tacfile1[0]=tacfile2[0]=(char)0;
79 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
81 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
82 if(strcasecmp(cptr,
"IFT")==0) {
83 outputType=1;
continue;
85 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
90 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
96 printf(
"outputType := %d\n", outputType);
104 if(ai<argc)
strlcpy(tacfile1, argv[ai++], FILENAME_MAX);
105 if(ai<argc)
strlcpy(tacfile2, argv[ai++], FILENAME_MAX);
106 if(ai<argc) crossLimit=atoi(argv[ai++]);
107 if(ai<argc) {fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
return(1);}
110 if(!tacfile2[0] || crossLimit<1) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
111 if(crossLimit<1) {fprintf(stderr,
"Error: missing or invalid cross number.\n");
return(1);}
115 for(ai=0; ai<argc; ai++) printf(
"%s ", argv[ai]);
117 printf(
"tacfile1 := %s\n", tacfile1);
118 printf(
"tacfile2 := %s\n", tacfile2);
119 printf(
"crossLimit := %d\n", crossLimit);
127 if(verbose>1) printf(
"reading %s\n", tacfile1);
128 ret=
tacRead(&tac1, tacfile1, &status);
130 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
135 printf(
"tacNr1 := %d\n", tac1.
tacNr);
136 printf(
"sampleNr1 := %d\n", tac1.
sampleNr);
143 if(verbose>1) printf(
"reading %s\n", tacfile2);
144 ret=
tacRead(&tac2, tacfile2, &status);
146 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
151 printf(
"tacNr2 := %d\n", tac2.
tacNr);
152 printf(
"sampleNr2 := %d\n", tac2.
sampleNr);
163 fprintf(stderr,
"Warning: could not convert times from '%s' to '%s'.\n",
168 fprintf(stderr,
"Warning: could not convert concentrations from '%s' to '%s'.\n",
181 fprintf(stderr,
"Error: cannot interpolate data.\n");
189 int i, consecNr=0, crossNr=0, above=0;
190 i=0;
if(tac2.
c[0].
y[i]>tac2.
c[1].
y[i]) above=1;
191 if(verbose>2) printf(
" %d: %d %g %g\n", 1+i, above, tac2.
c[0].
y[i], tac2.
c[1].
y[i]);
193 if(tac2.
c[0].
y[i]>tac2.
c[1].
y[i]) {
194 if(above) {consecNr++;}
else {consecNr=0; crossNr++;}
197 if(!above) {consecNr++;}
else {consecNr=0; crossNr++;}
200 if(verbose>2) printf(
" %d: %d %g %g\n", 1+i, above, tac2.
c[0].
y[i], tac2.
c[1].
y[i]);
201 if(crossNr>0 && consecNr>=crossLimit)
break;
203 if(crossNr==0 || consecNr<crossLimit) {
204 fprintf(stderr,
"Error: cannot determine cross-over time.\n");
208 if(verbose>2) printf(
"cross-over_point := %d\n", 1+i);
210 printf(
"%g\n", tac2.
x[i]);
212 printf(
"x := %g\n", tac2.
x[i]);
213 printf(
"y := %g\n", tac2.
c[0].
y[i]);
214 printf(
"index := %d\n", i);
int liInterpolate(double *x, double *y, const int nr, double *newx, double *newy, double *newyi, double *newyii, const int newnr, const int se, const int ee, const int verbose)
Linear interpolation and/or integration with trapezoidal method.
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 tacAllocateMore(TAC *tac, int tacNr)
int tacRead(TAC *d, const char *fname, TPCSTATUS *status)
char * tacFormattxt(tacformat c)
int tacSortByTime(TAC *d, TPCSTATUS *status)
int tacYUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
int tacXUnitConvert(TAC *tac, const int u, TPCSTATUS *status)
Header file for library libtpcextensions.
char * unitName(int unit_code)
Header file for library libtpcift.
Header file for libtpcli.
Header file for library libtpctac.