/* * This file is part of TISEAN * * Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber * * TISEAN is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * TISEAN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TISEAN; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /*Author: Rainer Hegger. Last modified: Sep 3, 1999*/ #include #include #include #include #include #include "routines/tsa.h" #define WID_STR "Estimates the maximal Lyapunov exponent using the Kantz\n\t\ algorithm" #define BOX 128 const unsigned int ibox=BOX-1; unsigned long length=ULONG_MAX; unsigned long exclude=0; unsigned long reference=ULONG_MAX; unsigned int maxdim=2; unsigned int mindim=2; unsigned int delay=1; unsigned int column=1; unsigned int epscount=5; unsigned int maxiter=50; unsigned int window=0; unsigned int verbosity=0xff; double epsmin=1.e-3,epsmax=1.e-2; char eps0set=0,eps1set=0; char *outfile=NULL; char *infile=NULL; double *series,**lyap; long box[BOX][BOX],*liste,**lfound,*found,**count; double max,min; void show_options(char *progname) { what_i_do(progname,WID_STR); fprintf(stderr," Usage: %s [options]\n",progname); fprintf(stderr," Options:\n"); fprintf(stderr,"Everything not being a valid option will be " "interpreted as a possible datafile.\nIf no datafile " "is given stdin is read. Just - also means stdin\n"); fprintf(stderr,"\t-l # of data [default: whole file]\n"); fprintf(stderr,"\t-x # of lines to be ignored [default: 0]\n"); fprintf(stderr,"\t-c column to read [default: 1]\n"); fprintf(stderr,"\t-M maxdim [default: 2]\n"); fprintf(stderr,"\t-m mindim [default: 2]\n"); fprintf(stderr,"\t-d delay [default: 1]\n"); fprintf(stderr,"\t-r mineps [default: (data interval)/1000]\n"); fprintf(stderr,"\t-R maxeps [default: (data interval)/100]\n"); fprintf(stderr,"\t-# # of eps [default: 5]\n"); fprintf(stderr,"\t-n # of reference points [default: # of data]\n"); fprintf(stderr,"\t-s # of iterations [default: 50]\n"); fprintf(stderr,"\t-t time window [default: 0]\n"); fprintf(stderr,"\t-o outfile [default: 'datafile'.lyap]\n"); fprintf(stderr,"\t-V verbosity level [default: 3]\n\t\t" "0='only panic messages'\n\t\t" "1='+ input/output messages'\n\t\t" "2='+ plus statistics'\n"); fprintf(stderr,"\t-h show these options\n"); exit(0); } void scan_options(int n,char **str) { char *out; if ((out=check_option(str,n,'l','u')) != NULL) sscanf(out,"%lu",&length); if ((out=check_option(str,n,'x','u')) != NULL) sscanf(out,"%lu",&exclude); if ((out=check_option(str,n,'c','u')) != NULL) sscanf(out,"%u",&column); if ((out=check_option(str,n,'M','u')) != NULL) sscanf(out,"%u",&maxdim); if ((out=check_option(str,n,'m','u')) != NULL) sscanf(out,"%u",&mindim); if ((out=check_option(str,n,'d','u')) != NULL) sscanf(out,"%u",&delay); if ((out=check_option(str,n,'r','f')) != NULL) { eps0set=1; sscanf(out,"%lf",&epsmin); } if ((out=check_option(str,n,'R','f')) != NULL) { eps1set=1; sscanf(out,"%lf",&epsmax); } if ((out=check_option(str,n,'#','u')) != NULL) sscanf(out,"%u",&epscount); if ((out=check_option(str,n,'n','u')) != NULL) sscanf(out,"%lu",&reference); if ((out=check_option(str,n,'s','u')) != NULL) sscanf(out,"%u",&maxiter); if ((out=check_option(str,n,'t','u')) != NULL) sscanf(out,"%u",&window); if ((out=check_option(str,n,'V','u')) != NULL) sscanf(out,"%u",&verbosity); if ((out=check_option(str,n,'o','o')) != NULL) if (strlen(out) > 0) outfile=out; } void put_in_boxes(double eps) { unsigned long i; long j,k; static unsigned long blength; blength=length-(maxdim-1)*delay-maxiter; for (i=0;i (act+lwindow))) { dx=sqr(series[act]-series[element]); if (dx <= eps2) { for (k=1;k 0.0){ lcount[j][i]++; lfactor[j][i] += dx[i]; } } } for (i=mindim-2;i= epsmax) { epsmax=epsmin; epscount=1; } if (reference > (length-maxiter-(maxdim-1)*delay)) reference=length-maxiter-(maxdim-1)*delay; if ((maxiter+(maxdim-1)*delay) >= length) { fprintf(stderr,"Too few points to handle these parameters!\n"); exit(LYAP_K__MAXITER_TOO_LARGE); } if (maxdim < 2) maxdim=2; if (mindim < 2) mindim=2; if (mindim > maxdim) maxdim=mindim; check_alloc(liste=(long*)malloc(sizeof(long)*(length))); check_alloc(found=(long*)malloc(sizeof(long)*(maxdim-1))); check_alloc(lfound=(long**)malloc(sizeof(long*)*(maxdim-1))); for (i=0;i