12 #define PI 3.141592653589793
18 static int64_t *BASEBIN;
19 static int64_t *NUMBIN;
20 static double *LATBIN;
21 static int64_t TOTBINS;
22 static int32_t NUMROWS;
23 static float SEAM_LON;
30 void bin_init(int32_t nrow, int64_t **nbin, int64_t **bbin,
double **lbin,
50 NUMBIN = (int64_t *) calloc(NUMROWS,
sizeof (int64_t));
51 BASEBIN = (int64_t *) calloc(NUMROWS,
sizeof (int64_t));
52 LATBIN = (
double *) calloc(NUMROWS,
sizeof (
double));
56 for (
i = 0;
i < NUMROWS;
i++) {
57 *(LATBIN +
i) = (
i + 0.5) * (180.0 / NUMROWS) - 90.0;
58 *(NUMBIN +
i) = (int64_t) (cos(*(LATBIN +
i) * radfac) * (2.0 * NUMROWS)
64 for (
i = 1;
i < NUMROWS;
i++)
65 *(BASEBIN +
i) = *(BASEBIN +
i - 1) + *(NUMBIN +
i - 1);
67 TOTBINS = *(BASEBIN + NUMROWS - 1) + *(NUMBIN + NUMROWS - 1) - 1;
71 printf(
"-E- %s:%d - bin_init - num rows (%d) not equal to previous num rows (%d)\n",
72 __FILE__, __LINE__, nrow, NUMROWS);
88 int32_t row, rlow, rhi, rmid;
89 static int32_t old_row = 0;
91 if (old_row > 0 && *(BASEBIN + old_row - 1) <= bin
92 && *(BASEBIN + old_row) > bin) {
104 rmid = (rlow + rhi - 1) / 2;
105 if (*(BASEBIN + rmid) > bin)
118 *
lat = *(LATBIN + row - 1);
119 *
lon = 360.0 * (bin - *(BASEBIN + row - 1) + 0.5) / *(NUMBIN + row - 1);
130 row = (int64_t) ((90.0 +
lat) * (
double) NUMROWS / 180.0);
131 col = (int64_t) ((
double) (*(NUMBIN + row)) * (
lon - SEAM_LON) / 360.0);
132 *bin = *(BASEBIN + row) + col;
143 *row = (int32_t) ((90.0 + (
double)
lat) * (
double) NUMROWS / 180.0);
144 *col = (int32_t) ((
double) (*(NUMBIN + (*row))) * ((
double)
lon - SEAM_LON)
154 *
lat = *(LATBIN + row - 1);
155 *
lon = SEAM_LON + (360.0 * (col - 0.5) / *(NUMBIN + row - 1));
161 void rc2bin(int32_t row, int32_t col, int64_t *bin) {
162 *bin = *(BASEBIN + (int64_t) row - 1) + (int64_t) col - 1;
169 void bin2rc(int64_t bin, int32_t *row, int32_t *col) {
170 int32_t rlow, rhi, rmid;
171 static int32_t old_row = 0;
173 if (old_row > 0 && *(BASEBIN + old_row - 1) <= bin
174 && *(BASEBIN + old_row) > bin) {
186 rmid = (rlow + rhi - 1) / 2;
187 if (*(BASEBIN + rmid) > bin)
200 *col = bin - *(BASEBIN + (*row) - 1) + 1;