source: Sophya/trunk/SophyaProg/Tests/arrt.cc@ 789

Last change on this file since 789 was 789, checked in by ansari, 26 years ago

Amelioration, correction prg tests array Reza 20/3/2000

File size: 2.3 KB
Line 
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"
9#include "matharr.h"
10#include "timing.h"
11
12
13int main(int narg, char* arg[])
14{
15
16 SophyaInit();
17 InitTim(); // Initializing the CPU timer
18
19
20 int n = 5;
21 int i,j,k;
22
23 if (narg > 1) n = atoi(arg[1]);
24
25
26 try {
27 cout << "\n -----> Testing TArray <---- " << endl;
28 // We create a integer array SizeX=7, SizeY=5
29 TArray<int_4> ia(7,5);
30 // We fill it with a sequence of numbers starting at 10., with step = 2.
31 ia = Sequence(10., 2.);
32 cout << " ----- matrix IA = \n " << ia << endl;
33 // sub array extraction, Range(2,3) : starting position=2 , size=3
34 TArray<int_4> ic = ia(Range(2,3),Range(1,2));
35 cout << " ----- matrix IC IA(Range(2,3),Range(1,2)) = \n " << ic << endl;
36 // we set the sub-array to zero, this should reflect in the original array
37 // sub-arrays share their data with parent array
38 ic = 0;
39 cout << " ----- matrix IC Apres (=0) = \n " << ic << endl;
40 cout << " ----- matrix IA Apres IC=0 = \n " << ia << endl;
41
42 cout << " :::: 3 Dim arrays ::::: " << endl;
43 TArray<int_4>::SetMaxPrint(1000);
44 // Creating 3-dim array (X=8 x Y=7 x Z=2) , filling it with 5
45 TArray<int_4> ib(8,7,2);
46 ib = 5;
47 cout << " ----- matrix IB = \n " << ib << endl;
48 // Sub array extraction X from 1 , size 4 - Y from 2 , size 3 , in Z default, from 0, size 1
49 // we multiply this sub-array elements by 3
50 ib(Range(1,4),Range(2,3)) *= 3;
51 cout << " -- matrix IB , Apres ib(Range(1,3),Range(2,1))*=3 : " << endl;
52 cout << ib;
53
54 // Creating a double array X=5 x Y=2
55 TArray<r_4> fa(5,2);
56 // fill it up with a sequence of 0. to 1.
57 fa = Sequence(0.,1./(5*2));
58 cout << " ------ TArray<r_4> fa(5,2) = \n" << fa << endl;
59 // Create a new array from the original array , multiplying it by 2*Pi
60 TArray<r_4> fa2 = fa*(float)(2.*M_PI);
61 cout << " ------ TArray<r_4> fa2=fa*2*Pi = \n" << fa2 << endl;
62 // Compute sin(fa2) cos(fa2)
63 cout << " ------ sin(fa2=fa*2*Pi) = \n" << sin(fa2) << endl;
64 cout << " ------ cos(fa2=fa*2*Pi) = \n" << cos(fa2) << endl;
65 }
66 catch (PThrowable exc) {
67 cerr << " catched Exception " << exc.Msg() << endl;
68 }
69 catch (...) {
70 cerr << " catched unknown (...) exception " << endl;
71 }
72 cout << " --------------- END of Programme -------------- " << endl;
73}
Note: See TracBrowser for help on using the repository browser.