ARTS  2.4.0(git:4fb77825)
test_sorting.cc
Go to the documentation of this file.
1 /* Copyright (C) 2003-2012 Oliver Lemke <olemke@core-dump.info>
2 
3  This program is free software; you can redistribute it and/or
4  modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation; either version 2 of the
6  License, or (at your option) any later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
16  USA. */
17 
18 #include <cstdlib>
19 #include <ctime>
20 #include <iostream>
21 
22 #include "arts.h"
23 
24 #if HAVE_UNISTD_H
25 #include <sys/types.h>
26 #include <unistd.h>
27 #endif
28 
29 #include "matpackI.h"
30 #include "sorting.h"
31 
32 void testVector() {
33  // Array for output of sorted indexes
34  ArrayOfIndex i;
35 
36  Vector v(10);
37  v[0] = 2.2;
38  v[1] = 1.1;
39  v[2] = 3.3;
40  v[3] = 7.7;
41  v[4] = 6.6;
42  v[5] = 9.9;
43  v[6] = 4.4;
44  v[7] = 8.8;
45  v[8] = 5.5;
46  v[9] = 10.01;
47 
48  cout << "Vector before sort: " << v << endl;
49  get_sorted_indexes(i, v);
50  cout << "Index array after sort: " << i << endl;
51  cout << "Sorted Vector: ";
52  for (Index j = 0; j < v.nelem(); j++) cout << " " << setw(3) << v[i[j]];
53  cout << endl << endl;
54 }
55 
56 #ifdef _POSIX_VERSION
57 void testArray() {
58  // Array for output of sorted indexes
59  ArrayOfIndex i;
60 
61  ArrayOfIndex a(10);
62  a[0] = 2;
63  a[1] = 1;
64  a[2] = 3;
65  a[3] = 7;
66  a[4] = 6;
67  a[5] = 9;
68  a[6] = 4;
69  a[7] = 8;
70  a[8] = 5;
71  a[9] = 10;
72 
73  cout << "Array before sort: " << a << endl;
74  get_sorted_indexes(i, a);
75  cout << "Index array after sort: " << i << endl;
76  cout << "Sorted Array: ";
77  for (Index j = 0; j < a.nelem(); j++) cout << " " << setw(3) << a[i[j]];
78  cout << endl << endl;
79 }
80 
81 void profileVector(Index n) {
82  cout << "Creating Vector with random numbers" << endl;
83 
84  srandom((unsigned int)time(NULL));
85  Vector v(n);
86  for (Index i = 0; i < n; i++) v[i] = Numeric(random());
87 
88  cout << "Now sorting" << endl;
89  ArrayOfIndex i;
90  get_sorted_indexes(i, v);
91 }
92 #endif
93 
94 int main(void) {
95 #ifdef _POSIX_VERSION
96  testVector();
97  testArray();
98 #else
99  cerr << "This test is only available when compiled with POSIX support."
100  << endl;
101 #endif
102 
103  // profileVector (100 * 100 * 20 * 20);
104 
105  return (0);
106 }
matpackI.h
Implementation of Matrix, Vector, and such stuff.
Array
This can be used to make arrays out of anything.
Definition: array.h:108
get_sorted_indexes
void get_sorted_indexes(ArrayOfIndex &sorted, const T &data)
get_sorted_indexes
Definition: sorting.h:73
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.cc:51
main
int main(void)
Definition: test_sorting.cc:94
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
ARTS::Var::time
Time time(Workspace &ws) noexcept
Definition: autoarts.h:7043
testVector
void testVector()
Definition: test_sorting.cc:32
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Vector
The Vector class.
Definition: matpackI.h:860
sorting.h
Contains sorting routines.
arts.h
The global header file for ARTS.