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, 2001 */
26 #include "routines/tsa.h"
28 #define WID_STR "Simple lowpass filter in the time domain"
31 unsigned long length=ULONG_MAX,exclude=0;
32 unsigned int column=1,iterations=1;
33 unsigned int verbosity=0x1;
34 char *outfile=NULL,stdo=1;
39 void show_options(char *progname)
41 what_i_do(progname,WID_STR);
42 fprintf(stderr,"Usage: %s [options]\n",progname);
43 fprintf(stderr,"Options:\n");
44 fprintf(stderr,"Everything not being a valid option will be interpreted"
46 " datafile.\nIf no datafile is given stdin is read. Just - also"
48 fprintf(stderr,"\t-l # of points to use [Default: whole file]\n");
49 fprintf(stderr,"\t-x # of lines to be ignored [Default: 0]\n");
50 fprintf(stderr,"\t-c column to read [Default: 1]\n");
51 fprintf(stderr,"\t-i # of iterations [Default: 1]\n");
52 fprintf(stderr,"\t-V verbosity level [Default: 1]\n\t\t"
53 "0='only panic messages'\n\t\t"
54 "1='+ input/output messages'\n\t\t"
55 "2='+ print each iteration to a separate file\n");
56 fprintf(stderr,"\t-o output file name(s) [Default: 'datafile'.low.n,\n\t\t"
57 "where n is the number of the iteration.\n\t\t"
58 "without -o the last iteration is written to stdout.]\n");
59 fprintf(stderr,"\t-h show these options\n");
63 void scan_options(int n,char **in)
67 if ((out=check_option(in,n,'l','u')) != NULL)
68 sscanf(out,"%lu",&length);
69 if ((out=check_option(in,n,'x','u')) != NULL)
70 sscanf(out,"%lu",&exclude);
71 if ((out=check_option(in,n,'c','u')) != NULL)
72 sscanf(out,"%u",&column);
73 if ((out=check_option(in,n,'i','u')) != NULL)
74 sscanf(out,"%u",&iterations);
75 if ((out=check_option(in,n,'V','d')) != NULL)
76 sscanf(out,"%d",&verbosity);
77 if ((out=check_option(in,n,'o','o')) != NULL) {
84 int main(int argc,char **argv)
92 if (scan_help(argc,argv))
93 show_options(argv[0]);
95 scan_options(argc,argv);
96 #ifndef OMIT_WHAT_I_DO
97 if (verbosity&VER_INPUT)
98 what_i_do(argv[0],WID_STR);
101 infile=search_datafile(argc,argv,&column,verbosity);
105 if (outfile == NULL) {
107 check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
108 check_alloc(ofname=(char*)calloc(strlen(infile)+9,(size_t)1));
109 sprintf(outfile,"%s.low",infile);
112 check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
113 check_alloc(ofname=(char*)calloc((size_t)14,(size_t)1));
114 sprintf(outfile,"stdin.low");
118 check_alloc(ofname=(char*)calloc(strlen(outfile)+10,(size_t)1));
120 series=(double*)get_series(infile,&length,exclude,column,verbosity);
121 check_alloc(new=(double*)malloc(sizeof(double)*length));
123 if (verbosity&VER_USR1) {
124 for (iter=1;iter<=iterations;iter++) {
125 new[0]=(2.0*series[0]+2.0*series[1])/4.0;
126 new[length-1]=(2.0*series[length-1]+2.0*series[length-2])/4.0;
127 for (i=1;i<length-1;i++)
128 new[i]=(series[i-1]+2.0*series[i]+series[i+1])/4.0;
129 sprintf(ofname,"%s.%d",outfile,iter);
130 test_outfile(ofname);
131 file=fopen(ofname,"w");
132 if (verbosity&VER_INPUT)
133 fprintf(stderr,"Opened %s for writing\n",ofname);
134 if (stdo && (iter == iterations)) {
135 if (verbosity&VER_INPUT)
136 fprintf(stderr,"Writing to stdout\n");
138 for (i=0;i<length;i++) {
139 if (stdo && (iter == iterations))
140 fprintf(stdout,"%e\n",series[i]=new[i]);
141 fprintf(file,"%e\n",series[i]=new[i]);
147 for (iter=1;iter<=iterations;iter++) {
148 new[0]=(2.0*series[0]+2.0*series[1])/4.0;
149 new[length-1]=(2.0*series[length-1]+2.0*series[length-2])/4.0;
150 for (i=1;i<length-1;i++)
151 new[i]=(series[i-1]+2.0*series[i]+series[i+1])/4.0;
152 for (i=0;i<length;i++)
156 sprintf(ofname,"%s.%d",outfile,iterations);
157 file=fopen(ofname,"w");
158 if (verbosity&VER_INPUT)
159 fprintf(stderr,"Opened %s for writing\n",ofname);
160 for (i=0;i<length;i++)
161 fprintf(file,"%e\n",series[i]);
165 if (verbosity&VER_INPUT)
166 fprintf(stderr,"Writing to stdout\n");
167 for (i=0;i<length;i++)
168 fprintf(stdout,"%e\n",series[i]);