8#include "tpcclibConfig.h"
21static char *info[] = {
22 "Converts y values in TAC file from percentages to fractions.",
23 "If none of y values exceeds 1 then no conversion is done.",
25 "Usage: @P [options] tacfile [outputfile]",
30 "Example 1. Convert all dat files in current directory in bash shell:",
31 " for file in ./*.dat; do @P $file; done",
33 "Example 2. Convert all dat files in Windows command prompt window:",
34 " for %g in (*.dat) do @P %g",
36 "See also: taccalc, tacunit, tacsety, tac2svg",
38 "Keywords: TAC, tool",
57int main(
int argc,
char **argv)
59 int ai, help=0, version=0, verbose=1;
60 char tacfile[FILENAME_MAX], outfile[FILENAME_MAX];
67 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
68 tacfile[0]=outfile[0]=(char)0;
70 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
73 fprintf(stderr,
"Error: invalid option '%s'\n", argv[ai]);
82 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
87 if(ai<argc) {
strlcpy(tacfile, argv[ai++], FILENAME_MAX);}
88 if(ai<argc) {
strlcpy(outfile, argv[ai++], FILENAME_MAX);}
90 fprintf(stderr,
"Error: too many arguments: '%s'.\n", argv[ai]);
95 if(!tacfile[0]) {
tpcPrintUsage(argv[0], info, stdout);
return(1);}
97 if(!outfile[0]) strcpy(outfile, tacfile);
102 for(ai=0; ai<argc; ai++) printf(
"%s ", argv[ai]);
104 printf(
"tacfile := %s\n", tacfile);
105 printf(
"outfile := %s\n", outfile);
113 if(verbose>1) printf(
"reading %s\n", tacfile);
115 ret=
tacRead(&tac, tacfile, &status);
117 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
122 printf(
"tacNr := %d\n", tac.
tacNr);
123 printf(
"sampleNr := %d\n", tac.
sampleNr);
134 ret=
tacYRange(&tac, -1, NULL, &ymax, NULL, NULL, NULL, NULL);
136 fprintf(stderr,
"Error: cannot determine max value in %s\n", tacfile);
139 if(verbose>1) printf(
"y_max := %g\n", ymax);
147 for(ri=0; ri<tac.
tacNr; ri++) {
149 if(isnan(tac.
c[ri].
y[fi])) {
continue;}
150 tac.
c[ri].
y[fi]*=0.01;
155 if(verbose>0) printf(
"no conversion necessary for %s\n", tacfile);
162 if(verbose>1) printf(
"writing %s\n", outfile);
163 FILE *fp; fp=fopen(outfile,
"w");
165 fprintf(stderr,
"Error: cannot open file for writing (%s)\n", outfile);
171 fprintf(stderr,
"Error (%d): %s\n", ret,
errorMsg(status.
error));
174 if(verbose>=0) printf(
"%s saved.\n", outfile);
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 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.
char * unitName(int unit_code)
Header file for library libtpcift.
Header file for library libtpctac.
@ TAC_FORMAT_UNKNOWN
Unknown format.