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 6, 2005*/
22 12/06/05: shift output x value to center of interval
29 #include "routines/tsa.h"
31 #define WID_STR "Makes a histogram of the data"
33 unsigned long length=ULONG_MAX;
34 unsigned long base=50;
35 unsigned long exclude=0;
36 unsigned int column=1;
37 unsigned int verbosity=0xff;
39 char my_stdout=1,gotsize=0;
48 void show_options(char *progname)
50 what_i_do(progname,WID_STR);
51 fprintf(stderr," Usage: %s [options]\n",progname);
52 fprintf(stderr," options:\n");
53 fprintf(stderr,"Everything not being a valid option will be interpreted as a"
54 " possible datafile.\nIf no datafile is given stdin is read. "
55 " Just - also means stdin\n");
56 fprintf(stderr,"\t-l length of file [default whole file]\n");
57 fprintf(stderr,"\t-x # of lines to ignore [default %ld]\n",exclude);
58 fprintf(stderr,"\t-c column to read [default %d]\n",column);
59 fprintf(stderr,"\t-b # of intervals [default %ld]\n",base);
60 fprintf(stderr,"\t-o output file [default 'datafile'.dat ;"
61 " If no -o is given: stdout]\n");
62 fprintf(stderr,"\t-V verbosity level [default 1]\n\t\t"
63 "0='only panic messages'\n\t\t"
64 "1='+ input/output messages'\n");
65 fprintf(stderr,"\t-h show these options\n");
69 void scan_options(int n,char **str)
73 if ((out=check_option(str,n,'l','u')) != NULL)
74 sscanf(out,"%lu",&length);
75 if ((out=check_option(str,n,'x','u')) != NULL)
76 sscanf(out,"%lu",&exclude);
77 if ((out=check_option(str,n,'c','u')) != NULL)
78 sscanf(out,"%u",&column);
79 if ((out=check_option(str,n,'b','u')) != NULL)
80 sscanf(out,"%lu",&base);
81 if ((out=check_option(str,n,'V','u')) != NULL)
82 sscanf(out,"%u",&verbosity);
83 if ((out=check_option(str,n,'o','o')) != NULL) {
90 int main(int argc,char **argv)
94 double x,norm,size=1.0,size2=1.0;
97 if (scan_help(argc,argv))
98 show_options(argv[0]);
100 scan_options(argc,argv);
101 #ifndef OMIT_WHAT_I_DO
102 if (verbosity&VER_INPUT)
103 what_i_do(argv[0],WID_STR);
106 infile=search_datafile(argc,argv,&column,verbosity);
110 if (outfile == NULL) {
112 check_alloc(outfile=(char*)calloc(strlen(infile)+5,1));
113 strcpy(outfile,infile);
114 strcat(outfile,".his");
117 check_alloc(outfile=(char*)calloc((size_t)10,1));
118 strcpy(outfile,"stdin.his");
122 test_outfile(outfile);
124 series=(double*)get_series(infile,&length,exclude,column,verbosity);
125 variance(series,length,&average,&var);
126 rescale_data(series,length,&min,&max);
130 check_alloc(box=(long*)malloc(sizeof(long)*base));
135 for (i=0;i<length;i++) {
136 if (series[i] > (1.0-size2))
138 j=(long)(series[i]*base);
143 norm=1.0/(double)length;
145 fout=fopen(outfile,"w");
146 if (verbosity&VER_INPUT)
147 fprintf(stderr,"Opened %s for writing\n",outfile);
148 fprintf(fout,"#interval of data: [%e:%e]\n",min,max+min);
149 fprintf(fout,"#average= %e\n",average);
150 fprintf(fout,"#standard deviation= %e\n",var);
151 for (i=0;i<base;i++) {
153 fprintf(fout,"%e %e\n",(x+size2)*max+min,(double)box[i]*norm);
158 if (verbosity&VER_INPUT)
159 fprintf(stderr,"Writing to stdout\n");
160 fprintf(stdout,"#interval of data: [%e:%e]\n",min,max+min);
161 fprintf(stdout,"#average= %e\n",average);
162 fprintf(stdout,"#standard deviation= %e\n",var);
163 for (i=0;i<base;i++) {
165 fprintf(stdout,"%e %e\n",(x+size2)*max+min,(double)box[i]*norm);