[3803] | 1 | #include "sopnamsp.h"
|
---|
| 2 | #include "machdefs.h"
|
---|
| 3 | #include <iostream>
|
---|
| 4 | #include <stdlib.h>
|
---|
| 5 | #include <stdio.h>
|
---|
| 6 | #include <string.h>
|
---|
| 7 | #include <math.h>
|
---|
| 8 | #include <unistd.h>
|
---|
| 9 | #include "srandgen.h"
|
---|
| 10 | #include "timing.h"
|
---|
| 11 | #include "tvector.h"
|
---|
| 12 | #include "ntuple.h"
|
---|
| 13 |
|
---|
| 14 | #include "geneutils.h"
|
---|
| 15 |
|
---|
| 16 | // test vitesse d'interpolation
|
---|
| 17 |
|
---|
| 18 | int main(int narg,char *arg[])
|
---|
| 19 | {
|
---|
| 20 | unsigned short typint=0; // 0=near 1=linear 2=parab
|
---|
| 21 | int ntry=1000;
|
---|
| 22 | int npt = 1000;
|
---|
| 23 | double xmin=0., xmax=1.;
|
---|
| 24 | if(narg>1) sscanf(arg[1],"%d",&ntry);
|
---|
| 25 | if(narg>2) sscanf(arg[2],"%hu",&typint);
|
---|
| 26 | cout<<"ntry="<<ntry<<" xmin="<<xmin<<" xmax="<<xmax<<" npt="<<npt<<" typint="<<typint<<endl;
|
---|
| 27 | cout<<"total number of calls is: "<<double(npt)*double(ntry)<<endl;
|
---|
| 28 |
|
---|
| 29 | vector<double> X, Y;
|
---|
| 30 | double dx = (xmax-xmin)/npt;
|
---|
| 31 | double lamb = (xmax-xmin)/20.;
|
---|
| 32 | for(int i=0;i<=npt;i++) {
|
---|
| 33 | double x = xmin + dx*i + dx/3.*drandpm1();
|
---|
| 34 | X.push_back(x);
|
---|
| 35 | double y = sin( 2.*M_PI * x / lamb );
|
---|
| 36 | Y.push_back(y);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | const char *vname[2] = {"x","v"};
|
---|
| 40 | NTuple nt(2,vname);
|
---|
| 41 | double xnt[2];
|
---|
| 42 |
|
---|
| 43 | InitTim();
|
---|
| 44 |
|
---|
| 45 | double sumtot = 0.;
|
---|
| 46 | int lptry = ntry/5; if(lptry==0) lptry = 1;
|
---|
| 47 | for(int itry=0;itry<ntry;itry++) {
|
---|
| 48 | bool fill = false;
|
---|
| 49 | if(itry%lptry==0 || itry==ntry-1) fill = true;
|
---|
| 50 | double d = drandpm1()*dx;
|
---|
| 51 | double sum = 0.;
|
---|
| 52 | for(double x=xmin+d;x<xmax+d+dx/5.;x+=dx) {
|
---|
| 53 | double v = InterpTab(x,X,Y,typint);
|
---|
| 54 | sum += v;
|
---|
| 55 | if(fill) {xnt[0] = x; xnt[1] = v; nt.Fill(xnt);}
|
---|
| 56 | }
|
---|
| 57 | sumtot += sum/(double)npt;
|
---|
| 58 | }
|
---|
| 59 | cout<<"sum="<<sumtot/(double)ntry<<endl;
|
---|
| 60 |
|
---|
| 61 | PrtTim("Fin du job");
|
---|
| 62 |
|
---|
| 63 | {
|
---|
| 64 | POutPersist pos("cmvtinttab.ppf");
|
---|
| 65 | TVector<r_8> VX(X);
|
---|
| 66 | TVector<r_8> VY(Y);
|
---|
| 67 | pos.PutObject(VX,"x");
|
---|
| 68 | pos.PutObject(VY,"y");
|
---|
| 69 | pos.PutObject(nt,"nt");
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | return 0;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | /*
|
---|
| 77 | openppf cmvtinttab.ppf
|
---|
| 78 |
|
---|
| 79 | n/plot x.val%n ! ! "plusmarker3"
|
---|
| 80 | n/plot y.val%n ! ! "plusmarker3"
|
---|
| 81 | vecplot x y "plusmarker3"
|
---|
| 82 |
|
---|
| 83 | n/plot nt.v%x ! ! "plusmarker3"
|
---|
| 84 | vecplot x y "circlemarker5 same red"
|
---|
| 85 |
|
---|
| 86 | */
|
---|