9#include "tpcclibConfig.h"
23static char *info[] = {
24 "Breaks up a TAC file into separate files, each containing one TAC.",
25 "New files will be written in the current working directory by default.",
27 "Usage: @P [options] filename",
30 " -name=<filename_tacid | filename_nr | tacid | nr>",
31 " Set the naming of output files. Options are the name of original",
32 " filename followed by TAC name (default) or number, or just TAC name",
35 " Splitted TACs are saved even when they will overwrite existing files",
36 " or do not contain any data.",
38 " Splitted files are saved in the same folder as the original file.",
42 " @P -name=filename_tacid iea345.tac",
44 "See also: taclist, tacadd, taccut, tacformat, tacren, tacdel, tacsort",
46 "Keywords: TAC, tool",
65int main(
int argc,
char **argv)
67 int ai, help=0, version=0, verbose=1;
73 char *cptr, tacfile[FILENAME_MAX], outfile[FILENAME_MAX];
80 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
84 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
86 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(!*cptr)
continue;
87 if(strcasecmp(cptr,
"FORCE")==0) {
89 }
else if(strncasecmp(cptr,
"KEEPPATH", 2)==0) {
91 }
else if(strncasecmp(cptr,
"NAME=", 5)==0) {
93 if(strcasecmp(cptr,
"filename_tacid")==0) {nameType=0;
continue;}
94 if(strcasecmp(cptr,
"filename_nr")==0) {nameType=1;
continue;}
95 if(strcasecmp(cptr,
"tacid")==0) {nameType=2;
continue;}
96 if(strcasecmp(cptr,
"nr")==0) {nameType=3;
continue;}
97 if(strcasecmp(cptr,
"fn_tacid")==0) {nameType=0;
continue;}
98 if(strcasecmp(cptr,
"fn_nr")==0) {nameType=1;
continue;}
100 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
105 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
114 if(ai<argc) {
strlcpy(tacfile, argv[ai], FILENAME_MAX); ai++;}
115 if(ai<argc) {fprintf(stderr,
"Error: invalid argument '%s'.\n", argv[ai]);
return(1);}
118 if(!tacfile[0]) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
122 for(ai=0; ai<argc; ai++) printf(
"%s ", argv[ai]);
124 printf(
"tacfile := %s\n", tacfile);
125 printf(
"nameType := %d\n", nameType);
126 printf(
"force := %d\n", force);
127 printf(
"keeppath := %d\n", keeppath);
134 if(verbose>1) printf(
"reading %s\n", tacfile);
135 ret=
tacRead(&tac, tacfile, &status);
137 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
142 printf(
"tacNr := %d\n", tac.
tacNr);
143 printf(
"sampleNr := %d\n", tac.
sampleNr);
149 fprintf(stderr,
"Error: %s contains only one TAC.\n", tacfile);
157 if(nameType==0 || nameType==2) {
159 fprintf(stderr,
"Error: %s does not contain individual TAC names.\n", tacfile);
168 if(force==0)
for(
int i=0; i<tac.
tacNr; i++) {
172 if(nameType==0 || nameType==1) {
173 strcat(outfile, tacfile);
176 strcat(outfile,
"_");
177 }
else if(keeppath!=0) {
178 strcpy(outfile, tacfile);
179 char *cptr=strrchr(outfile,
'/');
if(cptr==NULL) cptr=strrchr(outfile,
'\\');
180 if(cptr!=NULL) {cptr++; *cptr=(char)0;}
183 if(nameType==0 || nameType==2) {
184 strncat(outfile, tac.
c[i].
name, FILENAME_MAX-strlen(outfile)-1);
190 if(verbose>2) printf(
" %s\n", outfile);
192 if(access(outfile, 0)==-1)
continue;
193 fprintf(stderr,
"Error: %s exists; use option -force to overwrite.\n", outfile);
201 int origTacNr=tac.
tacNr;
203 for(
int i=0; i<origTacNr; i++) {
207 if(nameType==0 || nameType==1) {
208 strcat(outfile, tacfile);
211 strcat(outfile,
"_");
212 }
else if(keeppath!=0) {
213 strcpy(outfile, tacfile);
215 cptr=strrchr(outfile,
'/');
if(cptr==NULL) cptr=strrchr(outfile,
'\\');
216 if(cptr!=NULL) {cptr++; *cptr=(char)0;}
219 if(nameType==0 || nameType==2) {
220 strncat(outfile, tac.
c[i].
name, FILENAME_MAX-strlen(outfile)-1);
226 if(verbose>2) printf(
" %s\n", outfile);
231 fprintf(stderr,
"Error: cannot process TACs.\n");
236 if(force==0 &&
tacNotNaNs(&tac, -1)<1)
continue;
238 if(verbose>2) printf(
"writing %s\n", outfile);
239 fp=fopen(outfile,
"w");
241 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", outfile);
247 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
char * filenameGetExtensions(const char *s)
Get all extensions of a file name.
void filenameRmPath(char *s)
void filenameRmExtensions(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)
char * strncatIntZ(char *str1, const int n, const int maxn, size_t count)
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 tacCopyTacc(TACC *d1, TACC *d2, int sampleNr)
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 tacIndividualNames(TAC *tac)
int tacNotNaNs(TAC *tac, const int i)
Header file for library libtpcextensions.
char * unitName(int unit_code)
Header file for library libtpcift.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.