1fefa7ef9090c0381d6c7d315fc4c9788b256754
[jabaws.git] / website / archive / binaries / mac / src / disembl / Tisean_3.0.1 / source_c / polypar.c
1 /*
2  *   This file is part of TISEAN
3  *
4  *   Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
5  *
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.
10  *
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.
15  *
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
19  */
20 /*Author: Rainer Hegger. Last modified: Sep 4, 1999 */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <limits.h>
25 #include "routines/tsa.h"
26
27 #define WID_STR "Creates a parameter file containing all terms\n\t\
28 for a polynomial"
29
30
31 char *outfile=NULL;
32 unsigned int dim=2,order=3;
33 unsigned int verbosity=0xff;
34 FILE *file=NULL;
35
36 void make_parameter(unsigned int*,unsigned int, unsigned int);
37
38 void show_options(char *progname)
39 {
40   what_i_do(progname,WID_STR);
41   fprintf(stderr," Usage: %s [Options]\n",progname);
42   fprintf(stderr," Options:\n");
43   fprintf(stderr,"\t-m embedding dimension [Default: %u]\n",dim);
44   fprintf(stderr,"\t-p order of the polynomial [Default: %u]\n",order);
45   fprintf(stderr,"\t-o parameter file [Default: parameter.pol]\n");
46   fprintf(stderr,"\t-V verbosity level [Default: 1]\n\t\t"
47           "0='only panic messages'\n\t\t"
48           "1='+ input/output messages'\n");
49   fprintf(stderr,"\t-h show these options\n");
50   exit(0);
51 }
52
53 void scan_options(int n,char **in)
54 {
55   char *out;
56
57   if ((out=check_option(in,n,'m','u')) != NULL)
58     sscanf(out,"%u",&dim);
59   if ((out=check_option(in,n,'p','u')) != NULL)
60     sscanf(out,"%u",&order);
61   if ((out=check_option(in,n,'V','u')) != NULL)
62     sscanf(out,"%u",&verbosity);
63   if ((out=check_option(in,n,'o','o')) != NULL) {
64     if (strlen(out) > 0)
65       outfile=out;
66   }
67 }
68
69 void make_parameter(unsigned int *par,unsigned int d,unsigned int sum)
70 {
71   int i,j;
72   
73   for (i=0;i<=order;i++) {
74     sum += i;
75     if (sum <= order) {
76       par[d]=i;
77       if (d == 0) {
78         for (j=0;j<dim;j++)
79           fprintf(file,"%u ",par[j]);
80         fprintf(file,"\n");
81       }
82       else
83         make_parameter(par,d-1,sum);
84     }
85     sum -= i;
86   }
87   par[d]=0;
88 }
89
90 int main(int argc,char **argv)
91 {
92   unsigned int i,*params;
93
94   if (scan_help(argc,argv))
95     show_options(argv[0]);
96
97   scan_options(argc,argv);
98 #ifndef OMIT_WHAT_I_DO
99   if (verbosity&VER_INPUT)
100     what_i_do(argv[0],WID_STR);
101 #endif
102
103   
104   if (outfile == NULL) {
105     check_alloc(outfile=(char*)calloc((size_t)14,(size_t)1));
106     sprintf(outfile,"parameter.pol");
107   }
108   test_outfile(outfile);
109
110   check_alloc(params=(unsigned int*)malloc(sizeof(unsigned int)*dim));
111   for (i=0;i<dim;i++)
112     params[i]=0;
113
114   file=fopen(outfile,"w");
115   if (verbosity&VER_INPUT)
116     fprintf(stderr,"Opened %s for writing\n",outfile);
117   make_parameter(params,dim-1,0);
118   fclose(file);
119
120   return 0;
121 }