8#include "tpcclibConfig.h"
20static char *info[] = {
21 "Adds specified TAC from file2 as x (time) column to file1, or if not given,",
22 "then copy sample times from file2.",
23 "Files must have the same number of samples (time frames).",
24 "If file1 contains only one data column, that is assumed to represent y",
25 "values, and x values are added as new column to the left.",
27 "Usage: @P [Options] tacfile1 tacfile2 [tacid]",
32 "See also: tacmultx, tacsety, taclist, tacadd0, tacframe, addtimes, tacformat",
34 "Keywords: TAC, tool, time, simulation",
53int main(
int argc,
char **argv)
55 int ai, help=0, version=0, verbose=1;
57 char tacfile1[FILENAME_MAX], tacfile2[FILENAME_MAX], rname[
MAX_TACNAME_LEN];
63 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
65 tacfile1[0]=tacfile2[0]=rname[0]=(char)0;
67 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
70 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
79 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
84 if(ai<argc) {
strlcpy(tacfile1, argv[ai++], FILENAME_MAX);}
85 if(ai<argc) {
strlcpy(tacfile2, argv[ai++], FILENAME_MAX);}
86 for(
int n=0; ai<argc; ai++, n++) {
88 fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
94 if(!tacfile2[0]) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
98 for(ai=0; ai<argc; ai++) printf(
"%s ", argv[ai]);
100 printf(
"tacfile1 := %s\n", tacfile1);
101 printf(
"tacfile2 := %s\n", tacfile2);
102 if(rname[0]) printf(
"rname := %s\n", rname);
110 if(verbose>1) printf(
"reading %s\n", tacfile1);
111 ret=
tacRead(&tac1, tacfile1, &status);
113 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
118 printf(
"tacNr1 := %d\n", tac1.
tacNr);
119 printf(
"sampleNr1 := %d\n", tac1.
sampleNr);
122 printf(
"isframe1 := %d\n", tac1.
isframe);
125 if(verbose>1) printf(
"reading %s\n", tacfile2);
126 ret=
tacRead(&tac2, tacfile2, &status);
128 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
133 printf(
"tacNr2 := %d\n", tac2.
tacNr);
134 printf(
"sampleNr2 := %d\n", tac2.
sampleNr);
137 printf(
"isframe2 := %d\n", tac2.
isframe);
142 if(verbose>0) {printf(
"Note: initially no x column.\n"); fflush(stdout);}
144 for(
int i=0; i<tac1.
sampleNr; i++) {
145 tac1.
c[0].
y[i]=tac1.
x[i];
152 fprintf(stderr,
"Error: datafiles have different sample nr.\n");
158 if(verbose>1) printf(
"selecting TAC to be copied as x.\n");
161 fprintf(stderr,
"Error: no match found for '%s'.\n", rname);
165 fprintf(stderr,
"Error: more than one TAC matches '%s'.\n", rname);
168 for(
int i=0; i<tac2.
tacNr; i++)
if(tac2.
c[i].
sw) {voi=i;
break;}
174 if(verbose>1) printf(
"adding region '%s' as x\n", tac1.
c[voi].
name);
176 tac1.
x[i]=tac1.
x1[i]=tac1.
x2[i]=tac2.
c[voi].
y[i];
181 if(verbose>1) printf(
"adding x from '%s'\n", tacfile2);
182 for(
int i=0; i<tac1.
sampleNr; i++) {
183 tac1.
x[i]=tac2.
x[i]; tac1.
x1[i]=tac2.
x1[i]; tac1.
x2[i]=tac2.
x2[i];
194 if(verbose>2) printf(
"writing %s\n", tacfile1);
195 FILE *fp; fp=fopen(tacfile1,
"w");
197 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", tacfile1);
203 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)
char * roinameAddField(char *roiname, const char *field, const unsigned int in, const unsigned int count)
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 tacYNaNs(TAC *tac, const int i)
int tacSelectTACs(TAC *d, const char *region_name, int reset, TPCSTATUS *status)
Header file for library libtpcextensions.
#define MAX_TACNAME_LEN
Max length of TAC ID name (not including trailing zero).
char * unitName(int unit_code)
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.