[3852] | 1 | #include <iostream>
|
---|
| 2 | #include <fstream>
|
---|
| 3 | #include <math.h>
|
---|
| 4 | #include <vector>
|
---|
| 5 | #include <string>
|
---|
| 6 | #include <stdexcept>
|
---|
| 7 |
|
---|
| 8 | #include "slininterp.h"
|
---|
| 9 |
|
---|
| 10 | using namespace std;
|
---|
| 11 |
|
---|
| 12 | #include "array.h"
|
---|
| 13 | #include "tarrinit.h"
|
---|
| 14 | #include "sopnamsp.h"
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | //-------------------------------------------
|
---|
| 18 | // --- Test program for class SLinInterp1D :
|
---|
| 19 | //-------------------------------------------
|
---|
| 20 |
|
---|
| 21 | int main(int narg, char* arg[])
|
---|
| 22 | {
|
---|
| 23 | cout << " +++++++ Programme test de la classe SLinInterp1D +++++++ " << endl;
|
---|
| 24 | // To compile without SOPHYA : Comment the following line
|
---|
| 25 | TArrayInitiator arrinit_;
|
---|
| 26 | try {
|
---|
| 27 | vector<double> xs;
|
---|
| 28 | vector<double> ys;
|
---|
| 29 | vector<double> yreg;
|
---|
| 30 |
|
---|
| 31 | double lesx[6] = {2.,3.,5.,9.5,11.,14.};
|
---|
| 32 | for(int i=0;i<6; i++) {
|
---|
| 33 | xs.push_back(lesx[i]);
|
---|
| 34 | ys.push_back(lesx[i]*lesx[i]);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | double xmin = 0.5;
|
---|
| 38 | double xmax = 0.;
|
---|
| 39 | for(int i=0; i<=12; i++) {
|
---|
| 40 | xmax = xmin+i*0.05;
|
---|
| 41 | yreg.push_back(sin(xmax)*cos(2.2*xmax));
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | {
|
---|
| 45 | cout << " --- Creating file finterpXY.dat from xs,ys vectors ..." << endl;
|
---|
| 46 | ofstream ofxy("finterpXY.dat");
|
---|
[3880] | 47 | ofxy << "# Test file finterpXY.dat for SLinInterp1D class " << endl;
|
---|
| 48 | for(size_t i=0; i<xs.size(); i++) {
|
---|
| 49 | if (i%5==0) ofxy << "# --- " << i << endl;
|
---|
[3852] | 50 | ofxy << xs[i] << " " << ys[i] << " " << endl;
|
---|
[3880] | 51 | }
|
---|
[3852] | 52 | cout << " --- Creating file finterpYR.dat from yreg vector ..." << endl;
|
---|
| 53 | ofstream ofy("finterpYR.dat");
|
---|
[3880] | 54 | ofy << "# Test file finterpYR.dat for SLinInterp1D class " << endl;
|
---|
| 55 | for(size_t i=0; i<yreg.size(); i++) {
|
---|
| 56 | if (i%5==0) ofy << "# --- " << i << endl;
|
---|
[3852] | 57 | ofy << " " << yreg[i] << endl;
|
---|
[3880] | 58 | }
|
---|
[3852] | 59 | }
|
---|
| 60 | SLinInterp1D interp(xs, ys); // sans utilisation de X regularly spaced
|
---|
| 61 | SLinInterp1D interpR(xs, ys, 200); // avec utilisation de X regularly spaced
|
---|
| 62 | SLinInterp1D interpYR(xmin, xmax, yreg);
|
---|
| 63 | interp.Print(2);
|
---|
| 64 | interpR.Print(2);
|
---|
| 65 | interpYR.Print(2);
|
---|
| 66 |
|
---|
| 67 | cout << " ++++++++++++++++ From file +++++++++++++++++ " << endl;
|
---|
| 68 | SLinInterp1D interpxyf, interpyf;
|
---|
| 69 | string fname="finterpXY.dat";
|
---|
[3880] | 70 | size_t cnt_fxy = interpxyf.ReadXYFromFile(fname);
|
---|
[3852] | 71 | fname="finterpYR.dat";
|
---|
[3880] | 72 | size_t cnt_fy = interpyf.ReadYFromFile(fname,xmin,xmax);
|
---|
| 73 | cout << " Read from file, Count_FXY= " << cnt_fxy << " Count_FY=" << cnt_fy << endl;
|
---|
[3852] | 74 | interpxyf.Print(2);
|
---|
| 75 | interpyf.Print(2);
|
---|
| 76 | cout << " ++++++++++++++++ Checking from file - without file +++++++++++++++++ " << endl;
|
---|
| 77 | cout << " ++++++++++++ Interp With YRegular +++++++++++++ " << endl;
|
---|
| 78 |
|
---|
| 79 | for(int j=-3; j<=27; j++) {
|
---|
| 80 | double x=j*0.025+xmin;
|
---|
| 81 | double y = sin(x)*cos(2.2*x);
|
---|
| 82 | cout << " sin()cos() - J=" << j << " x=" << x << " y=" << y << " yIterpolYR=" << interpYR(x)
|
---|
| 83 | << " interpYFile= " << interpyf(x) << endl;
|
---|
| 84 | }
|
---|
| 85 | cout << " ++++++++++++++++ Interp With list of X,Y +++++++++++++++ " << endl;
|
---|
| 86 | for(int j=0; j<40; j++) {
|
---|
| 87 | double x=j*0.5;
|
---|
| 88 | cout << " J=" << j << " x=" << x << " y=" << x*x << " yIterpol=" << interp(x)
|
---|
| 89 | << " interpxyf=" << interpxyf(x) << " yIterpolR=" << interpR(x) << endl;
|
---|
| 90 | }
|
---|
| 91 | cout << " +++++++++++++++++++++++++++++++++++++++++++++++++++ " << endl;
|
---|
| 92 |
|
---|
| 93 | }
|
---|
| 94 | catch(std::exception& exc) {
|
---|
| 95 | cout << " Catched execption - msg=" << exc.what() << endl;
|
---|
| 96 | }
|
---|
| 97 | cout << " ---- FIN du programme test de la classe SLinInterp1D ---- " << endl;
|
---|
| 98 |
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 |
|
---|