TPCCLIB
Loading...
Searching...
No Matches
dftdblf.c
Go to the documentation of this file.
1
8/*****************************************************************************/
9#include "tpcclibConfig.h"
10/*****************************************************************************/
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <math.h>
15#include <string.h>
16/*****************************************************************************/
17#include "libtpcmisc.h"
18#include "libtpccurveio.h"
19#include "libtpcmodel.h"
20#include "libtpcmodext.h"
21/*****************************************************************************/
22
23/*****************************************************************************/
24static char *info[] = {
25 "Doubles the TAC sample number by making each sample/frame into two",
26 "by means of linear interpolation. This is mainly for simulation",
27 "and software testing purposes.",
28 " ",
29 "Usage: @P tacfile outputfile",
30 " ",
31 "Options:",
32 " -mid",
33 " Mid frame times are used even if frame start and end times are",
34 " available.",
35 " -stdoptions", // List standard options like --help, -v, etc
36 " ",
37 "See also: interpol, tacsetx, simframe, tacframe, dftinteg, taccat",
38 " ",
39 "Keywords: TAC, simulation, time frame",
40 0};
41/*****************************************************************************/
42
43/*****************************************************************************/
44/* Turn on the globbing of the command line, since it is disabled by default in
45 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
46 In Unix&Linux wildcard command line processing is enabled by default. */
47/*
48#undef _CRT_glob
49#define _CRT_glob -1
50*/
51int _dowildcard = -1;
52/*****************************************************************************/
53
54/*****************************************************************************/
58int main(int argc, char **argv)
59{
60 int ai, help=0, version=0, verbose=1;
61 int ret;
62 int mid_always=0;
63 char dfile[FILENAME_MAX], rfile[FILENAME_MAX], *cptr;
64 DFT dft, dft2;
65
66
67 /*
68 * Get arguments
69 */
70 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
71 dfile[0]=rfile[0]=(char)0;
72 dftInit(&dft); dftInit(&dft2);
73 /* Options */
74 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
75 cptr=argv[ai]+1; if(*cptr=='-') cptr++; if(cptr==NULL) continue;
76 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
77 if(strncasecmp(cptr, "MID", 3)==0) {
78 mid_always=1; continue;
79 }
80 fprintf(stderr, "Error: unknown option '%s'.\n", argv[ai]);
81 return(1);
82 } else break;
83
84 /* Print help or version? */
85 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
86 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
87 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
88
89 /* Process other arguments, starting from the first non-option */
90 for(; ai<argc; ai++) {
91 if(!dfile[0]) {strlcpy(dfile, argv[ai], FILENAME_MAX); continue;}
92 else if(!rfile[0]) {strlcpy(rfile, argv[ai], FILENAME_MAX); continue;}
93 fprintf(stderr, "Error: too many arguments: '%s'.\n", argv[ai]);
94 return(1);
95 }
96
97 /* Is something missing? */
98 if(!rfile[0]) {
99 fprintf(stderr, "Error: missing command-line argument; use option --help\n");
100 return(1);
101 }
102
103 /* In verbose mode print arguments and options */
104 if(verbose>1) {
105 printf("dfile := %s\n", dfile);
106 printf("rfile := %s\n", rfile);
107 printf("mid_always := %d\n", mid_always);
108 }
109
110 /*
111 * Read data file
112 */
113 if(verbose>1) printf("reading %s\n", dfile);
114 if(dftRead(dfile, &dft)) {
115 fprintf(stderr, "Error in reading '%s': %s\n", dfile, dfterrmsg);
116 return(2);
117 }
118 /* If using frame mid times was required, then do it */
119 if(mid_always) {
121 if(verbose>1) printf("timetype is set to 0.\n");
122 }
123
124 /*
125 * Double the frame number
126 */
127 if(verbose>1) printf("doubling frames\n");
128 ret=dftDoubleFrames(&dft, &dft2);
129 if(ret!=0) {
130 fprintf(stderr, "Error: cannot double the frame number (%d).\n", ret);
131 dftEmpty(&dft); dftEmpty(&dft2); return(8);
132 }
133 dftEmpty(&dft);
134
135 /*
136 * Save TACs
137 */
138 if(verbose>1) printf("writing %s\n", rfile);
139 ret=dftWrite(&dft2, rfile); dftEmpty(&dft2);
140 if(ret) {
141 fprintf(stderr, "Error in writing '%s': %s\n", rfile, dfterrmsg);
142 return(11);
143 }
144 if(verbose>0) printf(" %s written.\n", rfile);
145 return(0);
146}
147/*****************************************************************************/
148
149/*****************************************************************************/
void dftInit(DFT *data)
Definition dft.c:38
char dfterrmsg[64]
Definition dft.c:6
void dftEmpty(DFT *data)
Definition dft.c:20
int dftRead(char *filename, DFT *data)
Definition dftio.c:22
int dftWrite(DFT *data, char *filename)
Definition dftio.c:594
int dftDoubleFrames(DFT *dft, DFT *dft2)
Header file for libtpccurveio.
#define DFT_TIME_MIDDLE
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition strext.c:245
int tpcHtmlUsage(const char *program, char *text[], const char *path)
Definition proginfo.c:213
void tpcPrintBuild(const char *program, FILE *fp)
Definition proginfo.c:383
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Definition proginfo.c:158
Header file for libtpcmodel.
Header file for libtpcmodext.
int timetype