36 void usage(
const char *progname) {
37 printf(
"%s %s (%s %s)\n", progname,
VERSION, __DATE__, __TIME__);
39 printf(
"\nUsage: %s input_meris_binfile output_hdf4_binfile meris_prodname hdf4_prodname\n",
45 int main(
int argc,
char **argv) {
47 int row_varid, col_varid, binid;
48 int rowid, lon_varid, lat_varid, lon_step_varid;
52 float *
lon, *
lat, *lon_step;
54 char ncbin_filename[256];
59 if (argc == 1)
usage(
"l3rebin_meris");
61 strcpy(ncbin_filename, argv[1]);
62 printf(
"Reading product: %s in %s\n", argv[3], ncbin_filename);
65 nc_open(ncbin_filename, NC_NOWRITE, &ncid);
67 nc_inq_dimid(ncid,
"bin", &binid);
68 nc_inq_dimlen(ncid, binid, &
nbins);
69 nc_inq_dimid(ncid,
"row", &rowid);
70 nc_inq_dimlen(ncid, rowid, &
nrows);
72 row = (
short int *) calloc(
nbins,
sizeof (
short int));
73 col = (
short int *) calloc(
nbins,
sizeof (
short int));
75 lon = (
float *) calloc(
nrows,
sizeof (
float));
76 lat = (
float *) calloc(
nrows,
sizeof (
float));
77 lon_step = (
float *) calloc(
nrows,
sizeof (
float));
82 nc_inq_varid(ncid,
"row", &row_varid);
83 nc_inq_varid(ncid,
"col", &col_varid);
84 nc_get_var_short(ncid, row_varid, row);
85 nc_get_var_short(ncid, col_varid, col);
87 nc_inq_varid(ncid,
"center_lon", &lon_varid);
88 nc_inq_varid(ncid,
"center_lat", &lat_varid);
89 nc_inq_varid(ncid,
"lon_step", &lon_step_varid);
90 nc_get_var_float(ncid, lon_varid,
lon);
91 nc_get_var_float(ncid, lat_varid,
lat);
92 nc_get_var_float(ncid, lon_step_varid, lon_step);
94 int prod_varid, nobs_varid;
95 float *prod = (
float *) calloc(
nbins,
sizeof (
float));
96 short int *
nobs = (
short int *) calloc(
nbins,
sizeof (
short int));
99 nc_inq_nvars(ncid, &nvars);
104 varname.append(
"_mean");
106 cntname.append(
"_count");
108 nc_inq_varid(ncid, varname.c_str(), &prod_varid);
109 nc_inq_varid(ncid, cntname.c_str(), &nobs_varid);
111 nc_get_var_float(ncid, prod_varid, prod);
112 nc_get_var_short(ncid, nobs_varid,
nobs);
117 printf(
"Creating product: %s in %s\n\n", argv[4], argv[2]);
118 output_binfile->
create(argv[2], 4320);
123 float out_sum_buf[2 * 2 * 4320];
125 int32_t tot_write = 0;
126 int32_t row_off = row[0];
128 if ((
i % 1000000) == 0) cout <<
i <<
" out of " <<
nbins << endl;
132 int32_t
r = row[
i] - row_off;
137 if (
i == 0) last_row = irow;
139 if (irow != last_row) {
141 int32_t kbin_max = output_binfile->
get_numbin(last_row);
142 for (int32_t kbin = 0; kbin <= kbin_max; kbin++) {
149 memcpy(&out_sum_buf[2 * n_write], &out_sum_buf[2 * kbin], 8);
164 output_binfile->
writeSums(&out_sum_buf[0], n_write, argv[4]);
170 int64_t basebin = output_binfile->
get_basebin(irow);
171 int32_t
offset = bin_num - basebin;
173 cout <<
"Negative offset: " <<
offset <<
174 " for bin_num: " << bin_num << endl;
184 out_sum_buf[2 * icol] = prod[
i] *
nobs[
i];
185 out_sum_buf[2 * icol + 1] = 0.0;
217 int32_t yy, mm, dd, hh, mn, sc;
220 nc_get_att_text(ncid, NC_GLOBAL,
"start_time", buf);
223 istr.str(
str.substr(0, 4));
226 istr.str(
str.substr(4, 2));
229 istr.str(
str.substr(6, 2));
232 istr.str(
str.substr(9, 2));
235 istr.str(
str.substr(11, 2));
238 istr.str(
str.substr(13, 2));
245 nc_get_att_text(ncid, NC_GLOBAL,
"end_time", buf);
248 istr.str(
str.substr(0, 4));
251 istr.str(
str.substr(4, 2));
254 istr.str(
str.substr(6, 2));
257 istr.str(
str.substr(9, 2));
260 istr.str(
str.substr(11, 2));
263 istr.str(
str.substr(13, 2));
274 output_binfile->
close();