[2759] | 1 | #include <stdio.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include "grib.h" |
---|
| 4 | |
---|
| 5 | /* |
---|
| 6 | * number of missing data points w. ebisuzaki |
---|
| 7 | * |
---|
| 8 | * v1.1: just faster my dear |
---|
| 9 | * v1.2: just faster my dear |
---|
| 10 | * |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | static int bitsum[256] = { |
---|
| 14 | 8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, |
---|
| 15 | 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, |
---|
| 16 | 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, |
---|
| 17 | 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, |
---|
| 18 | 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, |
---|
| 19 | 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, |
---|
| 20 | 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, |
---|
| 21 | 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, |
---|
| 22 | 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, |
---|
| 23 | 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, |
---|
| 24 | 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, |
---|
| 25 | 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, |
---|
| 26 | 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, |
---|
| 27 | 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, |
---|
| 28 | 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, |
---|
| 29 | 4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0}; |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | int missing_points(unsigned char *bitmap, int n) { |
---|
| 33 | |
---|
| 34 | int count; |
---|
| 35 | unsigned int tmp; |
---|
| 36 | if (bitmap == NULL) return 0; |
---|
| 37 | |
---|
| 38 | count = 0; |
---|
| 39 | while (n >= 8) { |
---|
| 40 | tmp = *bitmap++; |
---|
| 41 | n -= 8; |
---|
| 42 | count += bitsum[tmp]; |
---|
| 43 | } |
---|
| 44 | tmp = *bitmap | ((1 << (8 - n)) - 1); |
---|
| 45 | count += bitsum[tmp]; |
---|
| 46 | |
---|
| 47 | return count; |
---|
| 48 | } |
---|