Last change
on this file since 1021 was
688,
checked in by mhnguyen, 9 years ago
|
Integrating remap library into XIOS
+) Change name of some files of remap library to be compatible with XIOS
+) Implement function to fill in automatically boundary longitude and latitude
Test
+) On Curie
+) test_remap correct
|
File size:
1.1 KB
|
Rev | Line | |
---|
[688] | 1 | #ifndef __MISC_H__ |
---|
| 2 | #define __MISC_H__ |
---|
| 3 | |
---|
| 4 | #include <stdlib.h> // srand |
---|
| 5 | #include <algorithm> // swap |
---|
| 6 | #include <cmath> // pow |
---|
| 7 | #include <vector> // randomizeArray |
---|
| 8 | |
---|
| 9 | namespace sphereRemap { |
---|
| 10 | |
---|
| 11 | // y = b^x |
---|
| 12 | // always round down to integer |
---|
| 13 | |
---|
| 14 | // b unknown |
---|
| 15 | static int iroot(int x, int y) |
---|
| 16 | { |
---|
| 17 | // FIXME: is this save to do? will it work correctly for integer cases like iroot(3, 8)? |
---|
| 18 | // (what if roundoff errors produce pow(3., 1./8.) = 1.99999999999995? ) |
---|
| 19 | return pow(y, 1./x); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | // y unknown |
---|
| 23 | static int ipow(int basis, int exponent) |
---|
| 24 | { |
---|
| 25 | int res = 1; |
---|
| 26 | while (exponent--) res *= basis; |
---|
| 27 | return res; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | // x unknown |
---|
| 31 | // integer logarithm, rounds down |
---|
| 32 | static int ilog(int base, int arg) |
---|
| 33 | { |
---|
| 34 | int x = 0; |
---|
| 35 | for (int y = base; y <= arg; y *= base) |
---|
| 36 | x++; |
---|
| 37 | return x; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | /* provide an array of indices that are in random order but every index appears exatly 1 time */ |
---|
| 42 | static void randomizeArray(std::vector<int>& array) |
---|
| 43 | { |
---|
| 44 | srand (3); |
---|
| 45 | |
---|
| 46 | for (int i = 0; i < array.size(); i++) |
---|
| 47 | array[i] = i; |
---|
| 48 | |
---|
| 49 | for (int i = 0; i < 3 * array.size(); i++) |
---|
| 50 | { |
---|
| 51 | int ind1 = rand() % array.size(); |
---|
| 52 | int ind2 = rand() % array.size(); |
---|
| 53 | std::swap(array[ind1], array[ind2]); |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | } |
---|
| 58 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.