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: Nov 23, 2000 */
26 #include "routines/tsa.h"
28 #define WID_STR "Rescales the data"
30 unsigned long length=ULONG_MAX,exclude=0;
32 unsigned int verbosity=0xff;
34 char *outfile=NULL,stdo=1,set_av=0,set_var=0,dimset=0;
37 double xmin=0.0,xmax=1.0;
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 data to use [default: whole file]\n");
49 fprintf(stderr,"\t-x # of lines to ignore [default: 0]\n");
50 fprintf(stderr,"\t-m # of components to be read [default: %u]\n",dim);
51 fprintf(stderr,"\t-c columns to read [default: 1,...,# of components]\n");
52 fprintf(stderr,"\t-z minimum of the new series [default: 0.0]\n");
53 fprintf(stderr,"\t-Z maximum of the new series [default: 1.0]\n");
54 fprintf(stderr,"\t-a create a series with average value equals 0\n");
55 fprintf(stderr,"\t-v create a series with variance 1\n");
56 fprintf(stderr,"\t-o output file name [default: 'datafile'.res']\n");
57 fprintf(stderr,"\t-V verbosity level [default: 1]\n\t\t"
58 "0='only panic messages'\n\t\t"
59 "1='+ input/output messages'\n");
60 fprintf(stderr,"\t-h show these options\n");
64 void scan_options(int n,char **in)
68 if ((out=check_option(in,n,'l','u')) != NULL)
69 sscanf(out,"%lu",&length);
70 if ((out=check_option(in,n,'x','u')) != NULL)
71 sscanf(out,"%lu",&exclude);
72 if ((out=check_option(in,n,'m','u')) != NULL) {
73 sscanf(out,"%u",&dim);
76 if ((out=check_option(in,n,'c','s')) != NULL)
78 if ((out=check_option(in,n,'V','u')) != NULL)
79 sscanf(out,"%u",&verbosity);
80 if ((out=check_option(in,n,'z','f')) != NULL)
81 sscanf(out,"%lf",&xmin);
82 if ((out=check_option(in,n,'Z','f')) != NULL)
83 sscanf(out,"%lf",&xmax);
84 if ((out=check_option(in,n,'a','n')) != NULL)
86 if ((out=check_option(in,n,'v','n')) != NULL)
88 if ((out=check_option(in,n,'o','o')) != NULL) {
95 int main(int argc,char **argv)
103 if (scan_help(argc,argv))
104 show_options(argv[0]);
106 scan_options(argc,argv);
107 #ifndef OMIT_WHAT_I_DO
108 if (verbosity&VER_INPUT)
109 what_i_do(argv[0],WID_STR);
112 infile=search_datafile(argc,argv,NULL,verbosity);
116 if (outfile == NULL) {
118 check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
119 strcpy(outfile,infile);
120 strcat(outfile,".res");
123 check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
124 strcpy(outfile,"stdin.res");
128 test_outfile(outfile);
131 fprintf(stderr,"Choosing the minimum larger or equal the maximum\n"
132 "makes no sense. Exiting!\n");
133 exit(RESCALE__WRONG_INTERVAL);
137 series=(double**)get_multi_series(infile,&length,exclude,&dim,"",dimset,
140 series=(double**)get_multi_series(infile,&length,exclude,&dim,column,
143 for (n=0;n<dim;n++) {
144 variance(series[n],length,&av,&varianz);
147 for (i=0;i<length;i++)
151 for (i=0;i<length;i++)
152 series[n][i] /= varianz;
154 if (!set_var && !set_av) {
155 rescale_data(series[n],length,&min,&max);
156 for (i=0;i<length;i++)
157 series[n][i]=series[n][i]*(xmax-xmin)+xmin;
162 if (verbosity&VER_INPUT)
163 fprintf(stderr,"Writing to stdout\n");
164 for (i=0;i<length;i++) {
165 fprintf(stdout,"%e",series[0][i]);
167 fprintf(stdout," %e",series[n][i]);
168 fprintf(stdout,"\n");
172 file=fopen(outfile,"w");
173 if (verbosity&VER_INPUT)
174 fprintf(stderr,"Opened %s for writing\n",outfile);
175 for (i=0;i<length;i++) {
176 fprintf(file,"%e",series[0][i]);
178 fprintf(file," %e",series[n][i]);