Allink  v0.1
Matematica.cpp
00001 #include "../include/Matematica.h"
00002 #include <time.h>
00003 void SigErr(int IsWrong,const char * s, ...){
00004 #ifdef DEBUG
00005   if(IsWrong){
00006     va_list args;
00007     va_start(args, s);
00008     fprintf(stderr, "Error: ");
00009     vfprintf(stderr, s, args);
00010     fprintf(stderr, "exiting the program\n");
00011     va_end(args);
00012     abort();
00013   }
00014 #else  
00015   return;
00016 #endif
00017 }
00018 void abort_(const char * s, ...)
00019 {
00020 #ifdef DEBUG
00021   va_list args;
00022   va_start(args, s);
00023   vfprintf(stderr, s, args);
00024   fprintf(stderr, "\n");
00025   va_end(args);
00026   abort();
00027 #else
00028   return;
00029 #endif
00030 }
00031 void Message(const char * s, ...)
00032 {
00033 #ifdef DEBUG
00034   va_list args;
00035   va_start(args, s);
00036   vfprintf(stderr, s, args);
00037   fprintf(stderr, "\n");
00038   va_end(args);
00039 #else
00040   return;
00041 #endif
00042 }
00043 Matematica::Matematica(){
00044   time_t TempoSeme;
00045   (void)time(&TempoSeme);
00046   int seme = (int)(TempoSeme);
00047   //seme = 2351653;
00048   NPassi = (int)1000;
00049   PrecMinimo=1e-6;
00050 #ifdef __GSL__
00051   rng = (gsl_rng *)malloc(sizeof(gsl_rng));
00052   rng = gsl_rng_alloc(gsl_rng_mt19937);
00053  //rng = gsl_rng_alloc(gsl_rng_tt800);
00054   gsl_rng_set(rng, seme);
00055 #else
00056   time_t Now;
00057   time( &Now );
00058   unsigned long Seed = (unsigned long)Now;
00059   init_genrand( Seed ) ; 
00060   seme = (int)TempoSeme;
00061   //  printf("seme %d\n",seme);
00062 #endif
00063   //SeGaussiano = 0;
00064   //fp = new double;
00065   Func = &Matematica::ContactAngle;
00066   //  ElabFunc = &Matematica::Derivata;
00067   Elab = &Matematica::Derivata;
00068   SpMem.a2 = 0.;
00069   SpMem.a1 = 0.;
00070   // NTemp=0;
00071   // Temp=0.;
00072   // casuale=0.;
00073   // segno=1;
00074   // DeltaGauss=0.;
00075   // SeGaussiano=0;
00076   //  matrix <double> F(4,4);
00077 }
00078 Matematica::~Matematica(){
00079 #ifdef __GSL__
00080   gsl_rng_free(rng);
00081 #endif
00082 }
00083 int Matematica::Factorial(int times){
00084   if(times <0)
00085     printf("the number is negative %d\n",times);
00086   int Resp=1;
00087   for(int t=1;t<times;t++){
00088     Resp *= t;
00089   }
00090   return Resp;
00091 }
00092 double Matematica::Binomial(int times,int n){
00093   double Resp=1.;
00094   Resp = (double)Factorial(times)/(double)(Factorial(n)*Factorial(times-n));
00095   return Resp;
00096 }
00097 int NumeroStringa(const char *NumeroC){
00098   int Cifra=0;
00099   int Numero=0;
00100   int FattoreDieci=1;
00101   int Potenza = strlen(NumeroC);
00102   for(int j=0;j<Potenza;j++){
00103     switch (NumeroC[j]){
00104     case '0':
00105       Cifra=0;
00106       break;
00107     case '1':
00108       Cifra=1;
00109       break;
00110     case '2':
00111       Cifra=2;
00112       break;
00113     case '3':
00114       Cifra=3;
00115       break;
00116     case '4':
00117       Cifra=4;
00118       break;
00119     case '5':
00120       Cifra=5;
00121       break;
00122     case '6':
00123       Cifra=6;
00124       break;
00125     case '7':
00126       Cifra=7;
00127       break;
00128     case '8':
00129       Cifra=8;
00130       break;
00131     case '9':
00132       Cifra=9;
00133       break;
00134     }
00135     //    cout << "Cifra " << Cifra << " Numero " << NumeroC[j] << " Potenza " << Potenza << endl;
00136     FattoreDieci=1;
00137     for(int i=Potenza-j;i>1;i--)
00138       FattoreDieci *=10;
00139     Numero+=Cifra*FattoreDieci;
00140   }
00141   return Numero;
00142 }