TPCCLIB
Loading...
Searching...
No Matches
ainterp.c
Go to the documentation of this file.
1
7/*****************************************************************************/
8#include "tpcclibConfig.h"
9/*****************************************************************************/
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <math.h>
14/*****************************************************************************/
15#include "libtpcmisc.h"
16#include "libtpcmodel.h"
17#include "libtpccurveio.h"
18#include "libtpcmodext.h"
19/*****************************************************************************/
20
21/*****************************************************************************/
22static char *info[] = {
23 "Interpolation of TAC to an optimal time scale for simulations.",
24 " ",
25 "Usage: @P [options] tacfile endtime newfile",
26 " ",
27 "Options:",
28 " -stdoptions", // List standard options like --help, -v, etc
29 " ",
30 "Endtime is the length of the inter/extrapolated data. To interpolate to",
31 "the end of input data, set it to 0.",
32 " ",
33 "See also: interpol, simframe, tactime, tacframe, avgbolus, dftavg, fit2dat",
34 " ",
35 "Keywords: TAC, simulation, interpolation",
36 0};
37/*****************************************************************************/
38
39/*****************************************************************************/
40/* Turn on the globbing of the command line, since it is disabled by default in
41 mingw-w64 (_dowildcard=0); in MinGW32 define _CRT_glob instead, if necessary;
42 In Unix&Linux wildcard command line processing is enabled by default. */
43/*
44#undef _CRT_glob
45#define _CRT_glob -1
46*/
47int _dowildcard = -1;
48/*****************************************************************************/
49
50/*****************************************************************************/
54int main(int argc, char **argv)
55{
56 int ai, help=0, version=0, verbose=1;
57 int ret;
58 char datfile[FILENAME_MAX], outfile[FILENAME_MAX];
59 DFT dft, dft2;
60 double endtime=-1.0;
61
62 /*
63 * Get arguments
64 */
65 if(argc==1) {tpcPrintUsage(argv[0], info, stderr); return(1);}
66 dftInit(&dft); dftInit(&dft2);
67 datfile[0]=outfile[0]=(char)0;
68 /* Options */
69 for(ai=1; ai<argc; ai++) if(*argv[ai]=='-') {
70 if(tpcProcessStdOptions(argv[ai], &help, &version, &verbose)==0) continue;
71 fprintf(stderr, "Error: invalid option '%s'\n", argv[ai]);
72 return(1);
73 } else break;
74
75 /* Print help or version? */
76 if(help==2) {tpcHtmlUsage(argv[0], info, ""); return(0);}
77 if(help) {tpcPrintUsage(argv[0], info, stdout); return(0);}
78 if(version) {tpcPrintBuild(argv[0], stdout); return(0);}
79
80 /* Process other arguments, starting from the first non-option */
81 for(; ai<argc; ai++) {
82 if(!datfile[0]) {
83 strcpy(datfile, argv[ai]); continue;
84 } else if(endtime<0.0) {
85 endtime=atof_dpi(argv[ai]); if(endtime<0.0) endtime=0.0; continue;
86 } else if(!outfile[0]) {
87 strcpy(outfile, argv[ai]); continue;
88 } else {
89 fprintf(stderr, "Error: invalid argument '%s'\n", argv[ai]);
90 return(1);
91 }
92 }
93
94 /* Is something missing? */
95 if(!outfile[0]) {tpcPrintUsage(argv[0], info, stdout); return(1);}
96
97 /* In verbose mode print arguments and options */
98 if(verbose>1) {
99 printf("datfile := %s\n", datfile);
100 printf("outfile := %s\n", outfile);
101 printf("endtime := %g\n", endtime);
102 }
103
104 /*
105 * Read TAC data
106 */
107 if(verbose>1) printf("reading %s\n", datfile);
108 if(dftRead(datfile, &dft)) {
109 fprintf(stderr, "Error in reading '%s': %s\n", datfile, dfterrmsg);
110 dftEmpty(&dft);
111 return(2);
112 }
113
114
115 /*
116 * Interpolate
117 */
118 if(verbose>1) printf("interpolating\n");
119 /* set the endtime if necessary */
120 if(endtime<=0.0) {
121 if(dft.timetype==DFT_TIME_STARTEND) endtime=dft.x2[dft.frameNr-1];
122 else endtime=dft.x[dft.frameNr-1];
123 }
124 /* interpolate */
125 ret=dftAutointerpolate(&dft, &dft2, endtime, verbose-2);
126 if(ret) {
127 fprintf(stderr, "Error %d in interpolation.\n", ret);
128 dftEmpty(&dft); dftEmpty(&dft2); return(3);
129 }
130 dft2.timetype=dft.timetype;
131 dftEmpty(&dft);
132
133
134 /*
135 * Save TACs
136 */
137 if(verbose>1) printf("saving %s\n", outfile);
138 /* Write DFT file */
139 ret=dftWrite(&dft2, outfile); dftEmpty(&dft2);
140 if(ret) {
141 fprintf(stderr, "Error in writing '%s': %s\n", outfile, dfterrmsg);
142 return(11);
143 }
144
145 return(0);
146}
147/*****************************************************************************/
148
149/*****************************************************************************/
double atof_dpi(char *str)
Definition decpoint.c:59
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 dftAutointerpolate(DFT *dft, DFT *dft2, double endtime, int verbose)
Header file for libtpccurveio.
#define DFT_TIME_STARTEND
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
Definition proginfo.c:40
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
double * x2
int frameNr
double * x