| 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"); | 
|---|
| 47 | for(size_t i=0; i<xs.size(); i++) | 
|---|
| 48 | ofxy << xs[i] << " " << ys[i] << " " << endl; | 
|---|
| 49 |  | 
|---|
| 50 | cout << " --- Creating file finterpYR.dat from yreg vector ..."  << endl; | 
|---|
| 51 | ofstream ofy("finterpYR.dat"); | 
|---|
| 52 | for(size_t i=0; i<yreg.size(); i++) | 
|---|
| 53 | ofy << "  " << yreg[i] << endl; | 
|---|
| 54 | } | 
|---|
| 55 | SLinInterp1D interp(xs, ys);  // sans utilisation de X regularly spaced | 
|---|
| 56 | SLinInterp1D interpR(xs, ys, 200);   // avec utilisation de X regularly spaced | 
|---|
| 57 | SLinInterp1D interpYR(xmin, xmax, yreg); | 
|---|
| 58 | interp.Print(2); | 
|---|
| 59 | interpR.Print(2); | 
|---|
| 60 | interpYR.Print(2); | 
|---|
| 61 |  | 
|---|
| 62 | cout << " ++++++++++++++++ From file +++++++++++++++++ " << endl; | 
|---|
| 63 | SLinInterp1D interpxyf, interpyf; | 
|---|
| 64 | string fname="finterpXY.dat"; | 
|---|
| 65 | interpxyf.ReadXYFromFile(fname); | 
|---|
| 66 | fname="finterpYR.dat"; | 
|---|
| 67 | interpyf.ReadYFromFile(fname,xmin,xmax); | 
|---|
| 68 | interpxyf.Print(2); | 
|---|
| 69 | interpyf.Print(2); | 
|---|
| 70 | cout << " ++++++++++++++++ Checking from file - without file +++++++++++++++++ " << endl; | 
|---|
| 71 | cout << " ++++++++++++ Interp With YRegular +++++++++++++ " << endl; | 
|---|
| 72 |  | 
|---|
| 73 | for(int j=-3; j<=27; j++) { | 
|---|
| 74 | double x=j*0.025+xmin; | 
|---|
| 75 | double y = sin(x)*cos(2.2*x); | 
|---|
| 76 | cout << " sin()cos() -  J=" << j << " x=" << x << " y=" << y << "  yIterpolYR=" << interpYR(x) | 
|---|
| 77 | << "  interpYFile=  " << interpyf(x) << endl; | 
|---|
| 78 | } | 
|---|
| 79 | cout << " ++++++++++++++++ Interp With list of X,Y  +++++++++++++++ " << endl; | 
|---|
| 80 | for(int j=0; j<40; j++) { | 
|---|
| 81 | double x=j*0.5; | 
|---|
| 82 | cout << " J=" << j << " x=" << x << " y=" << x*x << "  yIterpol=" << interp(x) | 
|---|
| 83 | << "  interpxyf=" << interpxyf(x)  << "  yIterpolR=" << interpR(x) << endl; | 
|---|
| 84 | } | 
|---|
| 85 | cout << " +++++++++++++++++++++++++++++++++++++++++++++++++++ " << endl; | 
|---|
| 86 |  | 
|---|
| 87 | } | 
|---|
| 88 | catch(std::exception& exc) { | 
|---|
| 89 | cout << " Catched execption - msg=" << exc.what() << endl; | 
|---|
| 90 | } | 
|---|
| 91 | cout << " ---- FIN du programme test de la classe SLinInterp1D ---- " << endl; | 
|---|
| 92 |  | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 |  | 
|---|