[786] | 1 | #include "machdefs.h"
|
---|
| 2 |
|
---|
| 3 | #include <math.h>
|
---|
| 4 | #include <iostream.h>
|
---|
| 5 |
|
---|
| 6 | #include "nbrandom.h"
|
---|
| 7 | #include "tarrinit.h"
|
---|
| 8 | #include "tarray.h"
|
---|
[807] | 9 | #include "fioarr.h"
|
---|
[789] | 10 | #include "matharr.h"
|
---|
[786] | 11 | #include "timing.h"
|
---|
| 12 |
|
---|
| 13 |
|
---|
[807] | 14 | void tstioarr(TArray<int_4> & ia, TArray<int_4> & ib, TArray<int_4> & ic);
|
---|
| 15 | void tstmtx();
|
---|
| 16 |
|
---|
[786] | 17 | int main(int narg, char* arg[])
|
---|
| 18 | {
|
---|
| 19 |
|
---|
| 20 | SophyaInit();
|
---|
| 21 | InitTim(); // Initializing the CPU timer
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | int n = 5;
|
---|
| 25 | int i,j,k;
|
---|
| 26 |
|
---|
[807] | 27 | bool tio = false;
|
---|
| 28 | if (narg > 1) tio = true;
|
---|
[786] | 29 |
|
---|
| 30 | try {
|
---|
| 31 | cout << "\n -----> Testing TArray <---- " << endl;
|
---|
[789] | 32 | // We create a integer array SizeX=7, SizeY=5
|
---|
[786] | 33 | TArray<int_4> ia(7,5);
|
---|
[789] | 34 | // We fill it with a sequence of numbers starting at 10., with step = 2.
|
---|
[786] | 35 | ia = Sequence(10., 2.);
|
---|
| 36 | cout << " ----- matrix IA = \n " << ia << endl;
|
---|
[789] | 37 | // sub array extraction, Range(2,3) : starting position=2 , size=3
|
---|
[807] | 38 | TArray<int_4> ic = ia(Range(2,3),Range(1,2),Range(0));
|
---|
[786] | 39 | cout << " ----- matrix IC IA(Range(2,3),Range(1,2)) = \n " << ic << endl;
|
---|
[789] | 40 | // we set the sub-array to zero, this should reflect in the original array
|
---|
| 41 | // sub-arrays share their data with parent array
|
---|
[786] | 42 | ic = 0;
|
---|
| 43 | cout << " ----- matrix IC Apres (=0) = \n " << ic << endl;
|
---|
| 44 | cout << " ----- matrix IA Apres IC=0 = \n " << ia << endl;
|
---|
| 45 |
|
---|
| 46 | cout << " :::: 3 Dim arrays ::::: " << endl;
|
---|
| 47 | TArray<int_4>::SetMaxPrint(1000);
|
---|
[789] | 48 | // Creating 3-dim array (X=8 x Y=7 x Z=2) , filling it with 5
|
---|
[786] | 49 | TArray<int_4> ib(8,7,2);
|
---|
| 50 | ib = 5;
|
---|
| 51 | cout << " ----- matrix IB = \n " << ib << endl;
|
---|
[789] | 52 | // Sub array extraction X from 1 , size 4 - Y from 2 , size 3 , in Z default, from 0, size 1
|
---|
| 53 | // we multiply this sub-array elements by 3
|
---|
[807] | 54 | ib(Range(1,4),Range(2,3), Range(0)) *= 3;
|
---|
[786] | 55 | cout << " -- matrix IB , Apres ib(Range(1,3),Range(2,1))*=3 : " << endl;
|
---|
| 56 | cout << ib;
|
---|
[789] | 57 |
|
---|
| 58 | // Creating a double array X=5 x Y=2
|
---|
| 59 | TArray<r_4> fa(5,2);
|
---|
| 60 | // fill it up with a sequence of 0. to 1.
|
---|
| 61 | fa = Sequence(0.,1./(5*2));
|
---|
| 62 | cout << " ------ TArray<r_4> fa(5,2) = \n" << fa << endl;
|
---|
| 63 | // Create a new array from the original array , multiplying it by 2*Pi
|
---|
| 64 | TArray<r_4> fa2 = fa*(float)(2.*M_PI);
|
---|
| 65 | cout << " ------ TArray<r_4> fa2=fa*2*Pi = \n" << fa2 << endl;
|
---|
| 66 | // Compute sin(fa2) cos(fa2)
|
---|
| 67 | cout << " ------ sin(fa2=fa*2*Pi) = \n" << sin(fa2) << endl;
|
---|
| 68 | cout << " ------ cos(fa2=fa*2*Pi) = \n" << cos(fa2) << endl;
|
---|
[807] | 69 |
|
---|
| 70 | if (tio) tstioarr(ia, ib, ic);
|
---|
| 71 |
|
---|
[786] | 72 | }
|
---|
| 73 | catch (PThrowable exc) {
|
---|
| 74 | cerr << " catched Exception " << exc.Msg() << endl;
|
---|
| 75 | }
|
---|
| 76 | catch (...) {
|
---|
| 77 | cerr << " catched unknown (...) exception " << endl;
|
---|
| 78 | }
|
---|
| 79 | cout << " --------------- END of Programme -------------- " << endl;
|
---|
| 80 | }
|
---|
[807] | 81 |
|
---|
| 82 | void tstioarr(TArray<int_4> & ia, TArray<int_4> & ib, TArray<int_4> & ic)
|
---|
| 83 | {
|
---|
| 84 | cout << " ------ tstioarr(TArray<int_4> & ia, TArray<int_4> & ib, TArray<int_4> & ic) ---- " << endl;
|
---|
| 85 | {
|
---|
| 86 | cout << " >>>>>> Writing in arrt.ppf <<<<<<< " << endl;
|
---|
| 87 | POutPersist pos("arrt.ppf");
|
---|
| 88 | // We write the three arrays in the stream
|
---|
| 89 | pos << ia << ib << ic;
|
---|
| 90 | cout << " >>>>>> Writing in arrtn.ppf with names <<<<<<<" << endl;
|
---|
| 91 | POutPersist posn("arrtn.ppf");
|
---|
| 92 | string tag = "ArrIA";
|
---|
| 93 | posn.PutObject(ia, tag);
|
---|
| 94 | tag = "ArrIB";
|
---|
| 95 | posn.PutObject(ib, tag);
|
---|
| 96 | tag = "ArrIC";
|
---|
| 97 | posn.PutObject(ic, tag);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | {
|
---|
| 101 | cout << " >>>>>>> Reading from arrt.ppf <<<<< " << endl;
|
---|
| 102 | PInPersist pis("arrt.ppf");
|
---|
| 103 | TArray<int_4> iaa, ibb, icc;
|
---|
| 104 | // We read the three arrays from the stream
|
---|
| 105 | pis >> iaa >> ibb >> icc;
|
---|
| 106 | cout << " ----- matrix IAA = \n " << iaa << endl;
|
---|
| 107 | cout << " ----- matrix IBB = \n " << ibb << endl;
|
---|
| 108 | cout << " ----- matrix ICC = \n " << icc << endl;
|
---|
| 109 | icc = 12;
|
---|
| 110 | cout << " ----- matrix ICC (=12) = \n " << icc << endl;
|
---|
| 111 | cout << " ----- matrix IAA (ICC=12) = \n " << iaa << endl;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | {
|
---|
| 115 | cout << " >>>>>>> Reading from arrtn.ppf <<<<< " << endl;
|
---|
| 116 | PInPersist pis("arrtn.ppf");
|
---|
| 117 | TArray<int_4> iaa, ibb, icc;
|
---|
| 118 | // We read the three arrays from the stream
|
---|
| 119 | string tag = "ArrIC";
|
---|
| 120 | pis.GetObject(icc, tag);
|
---|
| 121 | tag = "ArrIB";
|
---|
| 122 | pis.GetObject(ibb, tag);
|
---|
| 123 | tag = "ArrIA";
|
---|
| 124 | pis.GetObject(iaa, tag);
|
---|
| 125 |
|
---|
| 126 | cout << " ----- matrix IAAA = \n " << iaa << endl;
|
---|
| 127 | cout << " ----- matrix IBBB = \n " << ibb << endl;
|
---|
| 128 | cout << " ----- matrix ICCC = \n " << icc << endl;
|
---|
| 129 | icc = 68;
|
---|
| 130 | cout << " ----- matrix ICCC (=12) = \n " << icc << endl;
|
---|
| 131 | cout << " ----- matrix IAAA (ICC=12) = \n " << iaa << endl;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | }
|
---|