00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <ctime>
00019 #include <cstdlib>
00020 #include <iostream>
00021
00022 #if HAVE_CONFIG_H
00023 #include <config.h>
00024 #else
00025 #error "Please run ./configure in the top arts directory before compiling."
00026 #endif
00027
00028 #if HAVE_UNISTD_H
00029 # include <sys/types.h>
00030 # include <unistd.h>
00031 #endif
00032
00033 #include "matpackI.h"
00034 #include "sorting.h"
00035
00036 void
00037 testVector ()
00038 {
00039
00040 ArrayOfIndex i;
00041
00042 Vector v (10);
00043 v [0] = 2.2;
00044 v [1] = 1.1;
00045 v [2] = 3.3;
00046 v [3] = 7.7;
00047 v [4] = 6.6;
00048 v [5] = 9.9;
00049 v [6] = 4.4;
00050 v [7] = 8.8;
00051 v [8] = 5.5;
00052 v [9] = 10.01;
00053
00054 cout << "Vector before sort: " << v << endl;
00055 get_sorted_indexes (i, v);
00056 cout << "Index array after sort: " << i << endl;
00057 cout << "Sorted Vector: ";
00058 for (Index j = 0; j < v.nelem (); j++)
00059 cout << " " << setw (3) << v[i[j]];
00060 cout << endl << endl;
00061
00062 }
00063
00064 #ifdef _POSIX_VERSION
00065 void
00066 testArray ()
00067 {
00068
00069 ArrayOfIndex i;
00070
00071 ArrayOfIndex a (10);
00072 a [0] = 2;
00073 a [1] = 1;
00074 a [2] = 3;
00075 a [3] = 7;
00076 a [4] = 6;
00077 a [5] = 9;
00078 a [6] = 4;
00079 a [7] = 8;
00080 a [8] = 5;
00081 a [9] = 10;
00082
00083 cout << "Array before sort: " << a << endl;
00084 get_sorted_indexes (i, a);
00085 cout << "Index array after sort: " << i << endl;
00086 cout << "Sorted Array: ";
00087 for (Index j = 0; j < a.nelem (); j++)
00088 cout << " " << setw (3) << a[i[j]];
00089 cout << endl << endl;
00090 }
00091
00092 void
00093 profileVector (Index n)
00094 {
00095 cout << "Creating Vector with random numbers" << endl;
00096
00097 srandom ((unsigned int)time (NULL));
00098 Vector v(n);
00099 for (Index i = 0; i < n; i++)
00100 v[i] = Numeric (random ());
00101
00102 cout << "Now sorting" << endl;
00103 ArrayOfIndex i;
00104 get_sorted_indexes (i, v);
00105 }
00106 #endif
00107
00108 int
00109 main (void)
00110 {
00111 #ifdef _POSIX_VERSION
00112 testVector ();
00113 testArray ();
00114 #else
00115 cerr << "This test is only available when compiled with POSIX support."
00116 << endl;
00117 #endif
00118
00119
00120
00121 return (0);
00122 }
00123