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 (rewritten in C) Aug 22, 2004*/
26 #include "routines/tsa.h"
28 #define WID_STR "Produces delay vectors"
31 unsigned long length=ULONG_MAX;
32 unsigned long exclude=0;
33 unsigned int verbosity=0xff;
35 unsigned int indim=1,embdim=2;
36 char *column=NULL,*format=NULL,*multidelay=NULL;
39 char dimset=0,formatset=0,embset=0,mdelayset=0,delayset=0;
43 unsigned int *formatlist,*delaylist;
45 void show_options(char *progname)
47 what_i_do(progname,WID_STR);
48 fprintf(stderr,"\nUsage: %s [options]\n",progname);
49 fprintf(stderr,"Options:\n");
50 fprintf(stderr,"Everything not being a valid option will be interpreted as a"
51 " possible datafile.\nIf no datafile is given stdin is read."
52 " Just - also means stdin\n");
53 fprintf(stderr,"\t-l # of data [default: whole file]\n");
54 fprintf(stderr,"\t-x # of rows to ignore [default: 0]\n");
55 fprintf(stderr,"\t-M num. of columns to read [default: %u]\n",indim);
56 fprintf(stderr,"\t-c columns to read [default: 1,...,M]\n");
57 fprintf(stderr,"\t-m dimension [default: 2]\n");
58 fprintf(stderr,"\t-F format of the delay vector (see man page)\n");
59 fprintf(stderr,"\t-d delay [default: 1]\n");
60 fprintf(stderr,"\t-D multi delay list (see man page)\n");
61 fprintf(stderr,"\t-V verbosity level [default: 1]\n\t\t"
62 "0='only panic messages'\n\t\t"
63 "1='+ input/output messages'\n");
64 fprintf(stderr,"\t-o output file [default: 'datafile'.del, "
65 "without -o: stdout]\n");
66 fprintf(stderr,"\t-h show these options\n");
70 void scan_options(int n,char **str)
74 if ((out=check_option(str,n,'l','u')) != NULL)
75 sscanf(out,"%lu",&length);
76 if ((out=check_option(str,n,'x','u')) != NULL)
77 sscanf(out,"%lu",&exclude);
78 if ((out=check_option(str,n,'c','s')) != NULL)
80 if ((out=check_option(str,n,'M','u')) != NULL) {
81 sscanf(out,"%u",&indim);
84 if ((out=check_option(str,n,'F','s')) != NULL) {
88 if ((out=check_option(str,n,'m','u')) != NULL) {
89 sscanf(out,"%u",&embdim);
92 if ((out=check_option(str,n,'d','u')) != NULL) {
93 sscanf(out,"%u",&delay);
96 if ((out=check_option(str,n,'D','s')) != NULL) {
100 if ((out=check_option(str,n,'V','u')) != NULL)
101 sscanf(out,"%u",&verbosity);
102 if ((out=check_option(str,n,'o','o')) != NULL) {
109 void create_format_list(void)
111 unsigned int i=0,num=0,sum=0;
114 if (!(isdigit(format[i])) && !(format[i] == ',')) {
115 fprintf(stderr,"Wrong format of -F parameter. Exiting!\n");
116 exit(DELAY_WRONG_FORMAT_F);
123 if (format[i++] == ',')
127 check_alloc(formatlist=(unsigned int*)malloc(sizeof(int)*(num+1)));
128 for (i=0;i<=num;i++) {
129 sscanf(format,"%d",&formatlist[i]);
131 while ((*format) != ',')
137 if (dimset && ((num+1) != indim)) {
138 fprintf(stderr,"Number of dimensions in -F is not equal to -M. Exiting!\n");
139 exit(DELAY_DIM_NOT_EQUAL_F_M);
143 sum += formatlist[i];
144 if (embset && (sum != embdim)) {
145 fprintf(stderr,"The dimensions given in -m and -F are not equal!"
147 exit(DELAY_DIM_NOT_EQUAL_F_m);
155 void create_delay_list(void)
157 unsigned int i=0,num=0;
159 while (multidelay[i]) {
160 if (!(isdigit(multidelay[i])) && !(multidelay[i] == ',')) {
161 fprintf(stderr,"Wrong format of -D parameter. Exiting!\n");
162 exit(DELAY_WRONG_FORMAT_D);
168 while (multidelay[i]) {
169 if (multidelay[i++] == ',')
173 check_alloc(delaylist=(unsigned int*)malloc(sizeof(int)*(num+1)));
174 for (i=0;i<=num;i++) {
175 sscanf(multidelay,"%d",&delaylist[i]);
177 while ((*multidelay) != ',')
183 if ((num+1) != (embdim-indim)) {
184 fprintf(stderr,"Wrong number of delays. See man page. Exiting!\n");
185 exit(DELAY_WRONG_NUM_D);
189 int main(int argc,char **argv)
194 unsigned int alldim,maxemb,emb,rundel,delsum,runmdel;
195 unsigned int *inddelay;
198 if (scan_help(argc,argv))
199 show_options(argv[0]);
201 scan_options(argc,argv);
202 #ifndef OMIT_WHAT_I_DO
203 if (verbosity&VER_INPUT)
204 what_i_do(argv[0],WID_STR);
208 infile=search_datafile(argc,argv,NULL,verbosity);
212 if (outfile == NULL) {
214 check_alloc(outfile=(char*)calloc(strlen(infile)+5,1));
215 strcpy(outfile,infile);
216 strcat(outfile,".del");
219 check_alloc(outfile=(char*)calloc(10,1));
220 strcpy(outfile,"stdin.del");
224 test_outfile(outfile);
226 if (delayset && mdelayset) {
227 fprintf(stderr,"-d and -D can't be used simultaneously. Exiting!\n");
228 exit(DELAY_INCONS_d_D);
232 fprintf(stderr,"Delay has to be larger than 0. Exiting!\n");
233 exit(DELAY_SMALL_ZERO);
236 if (!formatset && (embdim%indim)) {
237 fprintf(stderr,"Inconsistent -m and -M. Please set -F\n");
238 exit(DELAY_INCONS_m_M);
241 create_format_list();
244 check_alloc(formatlist=(unsigned int*)malloc(sizeof(int)*indim));
245 for (i=0;i<indim;i++) {
246 formatlist[i]=embdim/indim;
251 for (i=0;i<indim;i++)
252 alldim += formatlist[i];
258 check_alloc(inddelay=(unsigned int*)malloc(sizeof(int)*alldim));
262 for (i=0;i<indim;i++) {
264 inddelay[rundel++]=delsum;
265 for (j=1;j<formatlist[i];j++) {
267 inddelay[rundel++]=delsum;
273 for (i=0;i<indim;i++) {
275 inddelay[rundel++]=delsum;
276 for (j=1;j<formatlist[i];j++) {
277 delsum += delaylist[runmdel++];
278 inddelay[rundel++]=delsum;
284 for (i=0;i<alldim;i++)
285 maxemb=(maxemb<inddelay[i])?inddelay[i]:maxemb;
287 if (column == NULL) {
288 series=get_multi_series(infile,&length,exclude,&indim,"",dimset,verbosity);
291 series=get_multi_series(infile,&length,exclude,&indim,column,dimset,
297 fprintf(stderr,"Writing to stdout\n");
298 for (i=maxemb;i<length;i++) {
300 for (j=0;j<indim;j++) {
303 fprintf(stdout,"%e ",series[j][i-inddelay[rundel++]]);
305 fprintf(stdout,"\n");
309 fout=fopen(outfile,"w");
311 fprintf(stderr,"Opened %s for writing\n",outfile);
312 for (i=maxemb;i<length;i++) {
313 for (j=0;j<indim;j++) {
317 fprintf(fout,"%e ",series[j][i-inddelay[rundel++]]);
324 if (formatlist != NULL)
326 if (delaylist != NULL)