2 * This file is part of TISEAN
4 * Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
6 * TISEAN is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * TISEAN is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with TISEAN; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /*Author: Rainer Hegger Last modified: Dec 17, 1999 */
26 #include "routines/tsa.h"
28 #define WID_STR "Determines the maxima (minima) of a possibly multivariate\
32 unsigned long length=ULONG_MAX,exclude=0;
34 unsigned int verbosity=0xff;
44 void show_options(char *progname)
46 what_i_do(progname,WID_STR);
47 fprintf(stderr,"Usage: %s [options]\n",progname);
48 fprintf(stderr,"Options:\n");
49 fprintf(stderr,"Everything not being a valid option will be interpreted"
51 " datafile.\nIf no datafile is given stdin is read. Just - also"
53 fprintf(stderr,"\t-l # of points to use [Default: whole file]\n");
54 fprintf(stderr,"\t-x # of lines to be ignored [Default: 0]\n");
55 fprintf(stderr,"\t-m dimension (# of components) [Default: 1]\n");
56 fprintf(stderr,"\t-c columns to read [Default: 1,...,# of components]\n");
57 fprintf(stderr,"\t-w which component to maxi(mini)mize [Default: 1]\n");
58 fprintf(stderr,"\t-z determine minima instead of maxima [Default: maxima]\n");
59 fprintf(stderr,"\t-t minimal required time between two extrema "
61 fprintf(stderr,"\t-o output file name [Default: 'datafile'.ext,"
62 " without -o: stdout]\n");
63 fprintf(stderr,"\t-V verbosity level [Default: 1]\n\t\t"
64 "0='only panic messages'\n\t\t"
65 "1='+ input/output messages'\n");
66 fprintf(stderr,"\t-h show these options\n");
70 void scan_options(int n,char **in)
74 if ((out=check_option(in,n,'l','u')) != NULL)
75 sscanf(out,"%lu",&length);
76 if ((out=check_option(in,n,'x','u')) != NULL)
77 sscanf(out,"%lu",&exclude);
78 if ((out=check_option(in,n,'m','u')) != NULL) {
79 sscanf(out,"%u",&dim);
82 if ((out=check_option(in,n,'c','s')) != NULL)
84 if ((out=check_option(in,n,'w','u')) != NULL)
85 sscanf(out,"%u",&which);
86 if ((out=check_option(in,n,'z','n')) != NULL)
88 if ((out=check_option(in,n,'t','f')) != NULL)
89 sscanf(out,"%lf",&mintime);
90 if ((out=check_option(in,n,'V','u')) != NULL)
91 sscanf(out,"%u",&verbosity);
92 if ((out=check_option(in,n,'o','o')) != NULL) {
99 int main(int argc,char **argv)
104 double x[3],a,b,c,lasttime,nexttime,time;
107 if (scan_help(argc,argv))
108 show_options(argv[0]);
110 scan_options(argc,argv);
111 #ifndef OMIT_WHAT_I_DO
112 if (verbosity&VER_INPUT)
113 what_i_do(argv[0],WID_STR);
117 if (which > (dim-1)) {
118 fprintf(stderr,"The component to maxi(mini)mize has to be smaller or equal"
119 "to the number\nof components! Exiting\n");
120 exit(EXTREMA_STRANGE_COMPONENT);
122 infile=search_datafile(argc,argv,NULL,verbosity);
126 if (outfile == NULL) {
128 check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
129 sprintf(outfile,"%s.ext",infile);
132 check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
133 sprintf(outfile,"stdin.ext");
138 series=(double**)get_multi_series(infile,&length,exclude,&dim,"",dimset,
141 series=(double**)get_multi_series(infile,&length,exclude,&dim,column,
145 test_outfile(outfile);
146 fout=fopen(outfile,"w");
147 if (verbosity&VER_INPUT)
148 fprintf(stderr,"Opened %s for writing\n",outfile);
151 if (verbosity&VER_INPUT)
152 fprintf(stderr,"Writing to stdout\n");
156 x[0]=series[which][0];
157 x[1]=series[which][1];
158 for (i=2;i<length;i++) {
159 x[2]=series[which][i];
161 if ((x[1] >= x[0]) && (x[1] > x[2])) {
164 c=(x[2]-2.0*x[1]+x[0])/2.0;
166 nexttime=(double)i-1.0+time;
167 if ((nexttime-lasttime) >= mintime) {
168 for (j=0;j<dim;j++) {
170 b=(series[j][i]-series[j][i-2])/2.0;
171 c=(series[j][i]-2.0*series[j][i-1]+series[j][i-2])/2.0;
173 fprintf(fout,"%e ",a+b*time+c*sqr(time));
175 fprintf(stdout,"%e ",a+b*time+c*sqr(time));
178 fprintf(fout,"%e\n",nexttime-lasttime);
180 fprintf(stdout,"%e\n",nexttime-lasttime);
186 if ((x[1] <= x[0]) && (x[1] < x[2])) {
189 c=(x[2]-2.0*x[1]+x[0])/2.0;
191 nexttime=(double)i-1.0+time;
192 if ((nexttime-lasttime) >= mintime) {
193 for (j=0;j<dim;j++) {
195 b=(series[j][i]-series[j][i-2])/2.0;
196 c=(series[j][i]-2.0*series[j][i-1]+series[j][i-2])/2.0;
198 fprintf(fout,"%e ",a+b*time+c*sqr(time));
200 fprintf(stdout,"%e ",a+b*time+c*sqr(time));
203 fprintf(fout,"%e\n",nexttime-lasttime);
205 fprintf(stdout,"%e\n",nexttime-lasttime);