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: Sep 3, 1999 */
26 #include "routines/tsa.h"
28 #define WID_STR "Estimates the autocorrelations of a data set"
30 char *format,*outfile=NULL,stout=1,normalize=1;
31 unsigned int column=1;
32 unsigned int verbosity=0xff;
33 unsigned long tau=100,length=ULONG_MAX,exclude=0;
38 void show_options(char *progname)
40 what_i_do(progname,WID_STR);
41 fprintf(stderr," Usage: %s [Options]\n",progname);
42 fprintf(stderr," Options:\n");
43 fprintf(stderr,"Everything not being a valid option will be interpreted"
45 " datafile.\nIf no datafile is given stdin is read. Just - also"
47 fprintf(stderr,"\t-l length [default is whole file]\n");
48 fprintf(stderr,"\t-x # of lines to be ignored [default 0]\n");
49 fprintf(stderr,"\t-c column to read [default is 1]\n");
50 fprintf(stderr,"\t-D corrlength [default is 100]\n");
51 fprintf(stderr,"\t-n don\'t normalize to the variance"
52 " of the data [not set]\n");
53 fprintf(stderr,"\t-o output_file [default is 'datafile'.cor; no -o"
55 fprintf(stderr,"\t-V verbosity level [default is 1]\n\t\t"
56 "0='only panic messages'\n\t\t"
57 "1='+ input/output messages'\n");
58 fprintf(stderr,"\t-h show these options\n");
63 void scan_options(int argc,char **argv)
67 if ((out=check_option(argv,argc,'l','u')) != NULL)
68 sscanf(out,"%lu",&length);
69 if ((out=check_option(argv,argc,'x','u')) != NULL)
70 sscanf(out,"%lu",&exclude);
71 if ((out=check_option(argv,argc,'c','u')) != NULL)
72 sscanf(out,"%u",&column);
73 if ((out=check_option(argv,argc,'D','u')) != NULL)
74 sscanf(out,"%lu",&tau);
75 if ((out=check_option(argv,argc,'n','n')) != NULL)
77 if ((out=check_option(argv,argc,'V','u')) != NULL)
78 sscanf(out,"%u",&verbosity);
79 if ((out=check_option(argv,argc,'o','o')) != NULL) {
91 for (j=0;j<(length-i);j++)
92 c += array[j]*array[j+i];
97 int main(int argc,char** argv)
103 if (scan_help(argc,argv))
104 show_options(argv[0]);
106 scan_options(argc,argv);
107 #ifndef OMIT_WHAT_I_DO
108 if (verbosity&VER_INPUT)
109 what_i_do(argv[0],WID_STR);
112 infile=search_datafile(argc,argv,&column,verbosity);
116 if (outfile == NULL) {
118 check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
119 strcpy(outfile,infile);
120 strcat(outfile,".cor");
123 check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
124 strcpy(outfile,"stdin.cor");
128 test_outfile(outfile);
130 array=(double*)get_series(infile,&length,exclude,column,verbosity);
135 variance(array,length,&av,&var);
138 for (i=0;i<length;i++)
143 fout=fopen(outfile,"w");
144 if (verbosity&VER_INPUT)
145 fprintf(stderr,"Opened %s for writing\n",outfile);
146 fprintf(fout,"# average=%e\n",av);
147 fprintf(fout,"# standard deviation=%e\n",var);
150 if (verbosity&VER_INPUT)
151 fprintf(stderr,"Writing to stdout\n");
152 fprintf(stdout,"# average=%e\n",av);
153 fprintf(stdout,"# standard deviation=%e\n",var);
162 fprintf(fout,"%ld %e\n",i,corr(i)/var);
166 fprintf(stdout,"%ld %e\n",i,corr(i)/var);