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 "Smoothes the output of the d2 program"
30 #define MAXLENGTH 1000
32 unsigned int maxdim=UINT_MAX,mindim=1;
33 unsigned int verbosity=0xff;
40 void show_options(char *progname)
42 what_i_do(progname,WID_STR);
43 fprintf(stderr,"Usage: %s [options]\n",progname);
44 fprintf(stderr,"Options:\n");
45 fprintf(stderr,"Everything not being a valid option will be interpreted"
46 " as a possible datafile.\nStdin does NOT work.\n");
47 fprintf(stderr,"\t-m dimension to start with [Default: 1]\n");
48 fprintf(stderr,"\t-M dimension to end with [Default: whole file]\n");
49 fprintf(stderr,"\t-a n average over (2n+1) values [Default: 1]\n");
50 fprintf(stderr,"\t-E use rescaled data for the length scales\n\t\t"
51 "[Default: use units of data]\n");
52 fprintf(stderr,"\t-o name of output file [Default: stdout,\n\t\t"
53 "-o without value means 'datafile'.av]\n");
54 fprintf(stderr,"\t-V verbosity level [Default: 1]\n\t\t"
55 "0='only panic messages'\n\t\t"
56 "1='+ input/output messages'\n");
57 fprintf(stderr,"\t-h show these options\n");
61 void scan_options(int n,char **in)
65 if ((out=check_option(in,n,'m','u')) != NULL)
66 sscanf(out,"%u",&mindim);
67 if ((out=check_option(in,n,'M','u')) != NULL)
68 sscanf(out,"%u",&maxdim);
69 if ((out=check_option(in,n,'a','u')) != NULL)
70 sscanf(out,"%u",&aver);
71 if ((out=check_option(in,n,'V','u')) != NULL)
72 sscanf(out,"%u",&verbosity);
73 if ((out=check_option(in,n,'E','n')) != NULL)
75 if ((out=check_option(in,n,'o','o')) != NULL) {
82 int main(int argc,char **argv)
85 char *form1="%lf%lf",*form2="%*lf%lf%lf";
87 unsigned int howmany,size=1;
91 double avy,aveps,norm;
92 FILE *file,*fout=NULL;
94 if ((argc < 2) || scan_help(argc,argv))
95 show_options(argv[0]);
97 scan_options(argc,argv);
98 #ifndef OMIT_WHAT_I_DO
99 if (verbosity&VER_INPUT)
100 what_i_do(argv[0],WID_STR);
103 infile=search_datafile(argc,argv,0L,verbosity);
104 if (infile == NULL) {
105 fprintf(stderr,"You have to give a datafile. Exiting!\n");
108 if (outfile == NULL) {
109 check_alloc(outfile=(char*)calloc(strlen(infile)+4,(size_t)1));
110 sprintf(outfile,"%s.av",infile);
113 check_alloc(eps=(double*)malloc(sizeof(double)*MAXLENGTH));
114 check_alloc(y=(double*)malloc(sizeof(double)*MAXLENGTH));
116 file=fopen(infile,"r");
119 test_outfile(outfile);
120 fout=fopen(outfile,"w");
121 if (verbosity&VER_INPUT)
122 fprintf(stderr,"Opened %s for writing\n",outfile);
125 if (verbosity&VER_INPUT)
126 fprintf(stderr,"Writing to stdout\n");
133 while (fgets(instr,1024,file) != NULL) {
134 if (strlen(instr) != 1) {
135 if (instr[0] == '#') {
136 if (strstr(instr,"m= ") != NULL) {
137 sscanf(instr,"%*s %ld",&dim);
138 if ((dim >= mindim) && (dim <= maxdim)) {
142 if (fgets(instr,1024,file) == NULL)
144 if (strlen(instr) == 1)
146 if (!empty && (instr[0] != '#')) {
148 sscanf(instr,form1,&eps[howmany],&y[howmany]);
150 sscanf(instr,form2,&y[howmany],&eps[howmany]);
152 if (!(howmany%MAXLENGTH)) {
153 check_alloc(realloc(eps,size*MAXLENGTH*sizeof(double)));
154 check_alloc(realloc(y,size*MAXLENGTH*sizeof(double)));
159 for (k=aver;k<howmany-aver;k++) {
161 for (j= -aver;j<=aver;j++) {
166 fprintf(fout,"%e %e\n",aveps/norm,avy/norm);
168 fprintf(stdout,"%e %e\n",aveps/norm,avy/norm);
173 fprintf(stdout,"\n");