Merge pull request #22 from wirc-sjsu/develop-w21
[WRF-SFIRE.git] / external / io_grib1 / WGRIB / missing.c
blob062b8af116e4faa30e5369eaf86065f22432f962
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "grib.h"
5 /*
6 * number of missing data points w. ebisuzaki
8 * v1.1: just faster my dear
9 * v1.2: just faster my dear
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};
32 int missing_points(unsigned char *bitmap, int n) {
34 int count;
35 unsigned int tmp;
36 if (bitmap == NULL) return 0;
38 count = 0;
39 while (n >= 8) {
40 tmp = *bitmap++;
41 n -= 8;
42 count += bitsum[tmp];
44 tmp = *bitmap | ((1 << (8 - n)) - 1);
45 count += bitsum[tmp];
47 return count;