11 #include <sys/types.h>
12 #include <sys/utsname.h>
28 #define PI2 1.570796326794897
29 #define PI 3.141592653589793
31 #define CMD_ARGS "p:r:w:g:"
32 #define BYTE unsigned char
34 #define MAX_NUM_INPUTROW 1000
36 #define VERSION L3M_SOFTVER_VAL
54 extern "C" int getlut_file(
char * lut_file,
short *rlut,
short *glut,
short *blut);
72 unsigned char *map_palette,
82 extern "C" int smigen_input(
int argc,
char **argv, instr *input);
253 printf(
"%s %s (%s %s)\n",
254 progname,
VERSION, __DATE__, __TIME__);
256 printf(
"\nUsage: %s ifile ofile prod-name\n", progname);
257 printf(
" par = parameter filename\n");
258 printf(
" ifile = input bin filename\n");
259 printf(
" ofile = output map filename\n");
260 printf(
" oformat = output format: 1 (HDF4 [default]), 2 (netCDF4), 3 (HDF5)\n");
261 printf(
" deflate = apply internal compression for netCDF output\n");
262 printf(
" prod = product name\n");
263 printf(
" precision = output map precision: 'B' (default), 'I', 'F'\n");
264 printf(
" palfile = palette filename\n");
265 printf(
" pversion = processing version (default is Unspecified)\n");
266 printf(
" datamin = minumum value for data scaling (default is prod-specific)\n");
267 printf(
" datamax = maximum value for data scaling (default is prod-specific)\n");
268 printf(
" stype = scaling type,1=LINEAR,2=LOG (default is prod-specific)\n");
269 printf(
" meas = measurement to map, 1=mean, 2=var, 3=stdev, 4=pixels, 5=scenes (default=1)\n");
270 printf(
" loneast = Easternmost longitude (default=+180)\n");
271 printf(
" lonwest = Westernmost longitude (default=-180)\n");
272 printf(
" latnorth = Northernmost latitude (default=+90)\n");
273 printf(
" latsouth = Southernmost latitude (default=-90)\n");
274 printf(
" projection = SIN | RECT (default=RECT)\n");
275 printf(
" resolution = 36km | 18km | 9km | 4km | 2km | 1km | hkm | qkm\n");
276 printf(
" 1deg (one deg) | hdeg (0.5 deg) | qdeg (0.25 deg)\n");
277 printf(
" 10deg (0.1 deg) |udeg-#.# (#.# deg)| ukm-#.# (#.# km) (default=9km)\n");
278 printf(
" seam_lon = Longitude of Left Edge of Map (default=-180)\n");
279 printf(
" proddesc = Product Description\n");
280 printf(
" units = Product Units\n");
284 int main(
int argc,
char **argv) {
285 int32
i,
j, l, jm1,
tk;
288 int32 prev_input_row;
303 int32 dims_out_sub[2];
314 int32 binindex_buf[4];
318 int32 min_out_col, max_out_col;
319 int32 min_out_row, max_out_row;
320 int32 sub_scan[2] = {0, 0};
323 int32 filled_data_bins = 0;
329 float32 cos_theta_output;
330 float32 cos_theta_input;
334 float32 *sum_buf =
NULL;
342 int32 *input_databuf;
346 int16 *input_databuf_16;
352 uint8 *input_qualbuf;
353 uint8 *qual_buf =
NULL;
356 uint8 *best_qual_rot;
359 uint8 *qual_byt =
NULL;
360 uint16 scale_val_16b;
362 char prodtablename[128];
363 uint8 *binlist_buf =
NULL;
364 uint8 fill_val = 255;
365 uint16 fill_val_int16 = 65535;
366 float32 fill_val_float = -32767.0;
371 uint8 land_input = 0;
372 uint8 hdf4_input = 0;
373 uint8 hdf5_input = 0;
374 uint8 ncdf4_input = 0;
375 uint8 healpix_input = 0;
376 uint8 default_palfile = 0;
381 float32 si_used[2], aminmax[2], dminmax[2] = {+1e10, -1e10},
f32;
394 int16 * mixed_buf[360 * 180];
399 static unsigned int pow2[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256,
400 512, 1024, 2048, 4096, 8192, 16384, 32768};
404 struct utsname u_name;
412 hid_t bin_dataset_idx;
416 int32 *, int32 *, int32 *, int32 *);
423 hid_t * bin_dataset_idx);
426 size_t *
nrows,
int *grpid,
427 int *binindex_id,
int *binlist_id,
428 int *bindata_id,
int *binqual_id,
463 printf(
"%s %s (%s %s)\n", argv[0],
VERSION, __DATE__, __TIME__);
465 strcpy(proc_con, argv[0]);
466 for (
i = 1;
i < argc;
i++) {
467 strcat(proc_con,
" ");
468 strcat(proc_con, argv[
i]);
471 if (
input.loneast < -180 ||
input.loneast > +180) {
472 printf(
"LONEAST must be between -180 and +180.\n");
476 if (
input.lonwest < -180 ||
input.lonwest > +180) {
477 printf(
"LONWEST must be between -180 and +180.\n");
482 if ((tmp_str = getenv(
"OCDATAROOT")) ==
NULL) {
483 printf(
"OCDATAROOT environment variable is not defined.\n");
487 strcat(buf,
"/common/smigen_defaults.par");
488 fp = fopen(buf,
"r");
491 printf(
"SMIGEN defaults file: %s not found.\n", buf);
492 printf(
"Using defaults for product table and palette directory.\n");
494 if (strcmp(
input.palfile,
"DEFAULT") == 0) {
496 strcat(
input.palfile,
"/common/palette");
500 strcpy(prodtablename, tmp_str);
501 strcat(prodtablename,
"/common/smigen_product_table.dat");
505 if (strcmp(
input.palfile,
"DEFAULT") == 0) {
506 buf[strlen(buf) - 1] = 0;
507 cptr = strchr(buf,
'=') + 1;
509 strcat(
input.palfile,
"/");
510 strcat(
input.palfile, cptr);
514 buf[strlen(buf) - 1] = 0;
515 cptr = strchr(buf,
'=') + 1;
516 strcpy(prodtablename, tmp_str);
517 strcat(prodtablename,
"/");
518 strcat(prodtablename, cptr);
523 buf[strlen(buf) - 1] = 0;
524 cptr = strchr(buf,
'=') + 1;
525 input.deflate = atoi(cptr);
531 fp = fopen(prodtablename,
"r");
533 printf(
"SMIGEN product table \"%s\" not found.\n", buf);
536 while (fgets(buf, 128, fp) !=
NULL) {
537 if ((buf[0] >= 0x41) && (buf[0] <= 0x5a))
L3M_PARAMS++;
539 fseek(fp, 0, SEEK_SET);
551 while (fgets(buf, 128, fp) !=
NULL) {
552 if ((buf[0] >= 0x41) && (buf[0] <= 0x5a)) {
554 cptr = strtok(buf,
":");
558 cptr = strtok(
NULL,
":");
562 cptr = strtok(
NULL,
":");
563 unit_list[
i] = (
char*) malloc(strlen(cptr) + 1);
566 cptr = strtok(
NULL,
":");
570 cptr = strtok(
NULL,
":");
573 cptr = strtok(
NULL,
":");
576 cptr = strtok(
NULL,
":");
580 cptr = strtok(
NULL,
"\n");
590 if (strncmp(
input.prod,
"refl", 4) == 0) {
594 if (
input.datamax == 0.0)
input.datamax = 0.394863;
599 }
else if (strncmp(
input.prod,
"rhos", 4) == 0) {
603 if (
input.datamax == 0.0)
input.datamax = 0.394863;
616 if (
input.stype == 1)
strcpy(scale_type,
"linear");
617 if (
input.stype == 2)
strcpy(scale_type,
"logarithmic");
618 if (
input.stype == 3)
strcpy(scale_type,
"arctan");
619 if (
input.stype == 0) {
620 if (strcmp(
"linear", scale_type) == 0) {
622 }
else if (strcmp(
"logarithmic", scale_type) == 0) {
624 }
else if (strcmp(
"arctan", scale_type) == 0) {
632 if (
input.precision[0] == 0)
637 if (strcmp(
input.precision,
"I") == 0) {
643 if (strcmp(scale_type,
"linear") == 0) {
645 strcpy(scale_type,
"LINEAR");
651 if (strcmp(scale_type,
"logarithmic") == 0) {
653 strcpy(scale_type,
"LOG");
659 if (strcmp(scale_type,
"arctan") == 0) {
660 strcpy(scale_type,
"ATAN");
663 if (
input.proddesc[0] == 0)
666 if (
input.units[0] == 0)
670 if (default_palfile) {
671 strcat(
input.palfile,
"/");
673 strcat(
input.palfile,
".pal");
676 if (!(
r = (
short *) calloc(256,
sizeof (
short)))) {
677 fprintf(
stderr,
"smigen: Error allocating space for red.\n");
680 if (!(
g = (
short *) calloc(256,
sizeof (
short)))) {
681 fprintf(
stderr,
"smigen: Error allocating space for green.\n");
684 if (!(
b = (
short *) calloc(256,
sizeof (
short)))) {
685 fprintf(
stderr,
"smigen: Error allocating space for blue.\n");
690 fprintf(
stderr,
"Error reading palette file %s\n",
input.palfile);
696 for (
i = 0;
i < 256;
i++) {
714 if (prod_num == -1) {
715 printf(
"Product: \"%s\" not found in default product list.\n\n",
input.prod);
718 printf(
"Make sure \"datamin\", \"datamax\" and \"stype\"\n");
719 printf(
"are specified on the command line.\n");
725 if (
input.stype == 1)
strcpy(scale_type,
"linear");
726 if (
input.stype == 2)
strcpy(scale_type,
"logarithmic");
727 if (
input.stype == 3)
strcpy(scale_type,
"arctan");
731 if (strcmp(
input.precision,
"I") == 0) {
737 if (strcmp(scale_type,
"linear") == 0) {
739 strcpy(scale_type,
"LINEAR");
745 if (strcmp(scale_type,
"logarithmic") == 0) {
747 strcpy(scale_type,
"LOG");
753 if (strcmp(scale_type,
"arctan") == 0) {
754 strcpy(scale_type,
"ATAN");
759 if (!(
r = (
short *) calloc(256,
sizeof (
short)))) {
760 fprintf(
stderr,
"smigen: Error allocating space for red.\n");
763 if (!(
g = (
short *) calloc(256,
sizeof (
short)))) {
764 fprintf(
stderr,
"smigen: Error allocating space for green.\n");
767 if (!(
b = (
short *) calloc(256,
sizeof (
short)))) {
768 fprintf(
stderr,
"smigen: Error allocating space for blue.\n");
772 if (strstr(
input.palfile,
".pal") ==
NULL) {
773 strcat(
input.palfile,
"/default.pal");
777 fprintf(
stderr,
"Error reading palette file %s\n",
input.palfile);
783 for (
i = 0;
i < 256;
i++) {
793 aminmax[0] =
input.datamin;
794 aminmax[1] =
input.datamax;
795 strcpy(atype, scale_type);
803 if (strcmp(
input.precision,
"F") == 0) {
807 strcpy(scale_type,
"LINEAR");
812 if (strcmp(
input.resolution,
"SMI") == 0) {
815 }
else if (strcmp(
input.resolution,
"SMI4") == 0) {
818 }
else if (strcmp(
input.resolution,
"LAND") == 0) {
821 }
else if (strcmp(
input.resolution,
"9km") == 0) {
824 }
else if (strcmp(
input.resolution,
"4km") == 0) {
827 }
else if (strcmp(
input.resolution,
"2km") == 0) {
828 dims_out[0] = 4320 * 2;
829 dims_out[1] = 8640 * 2;
830 }
else if (strcmp(
input.resolution,
"1km") == 0) {
831 dims_out[0] = 4320 * 4;
832 dims_out[1] = 8640 * 4;
833 }
else if (strcmp(
input.resolution,
"hkm") == 0) {
834 dims_out[0] = 4320 * 8;
835 dims_out[1] = 8640 * 8;
836 }
else if (strcmp(
input.resolution,
"qkm") == 0) {
837 dims_out[0] = 4320 * 16;
838 dims_out[1] = 8640 * 16;
839 }
else if (strcmp(
input.resolution,
"18km") == 0) {
842 }
else if (strcmp(
input.resolution,
"36km") == 0) {
845 }
else if (strcmp(
input.resolution,
"90km") == 0) {
848 }
else if (strcmp(
input.resolution,
"thirddeg") == 0) {
849 dims_out[0] = 180 * 3;
850 dims_out[1] = 360 * 3;
851 }
else if (strcmp(
input.resolution,
"1deg") == 0) {
854 }
else if (strcmp(
input.resolution,
"hdeg") == 0) {
857 }
else if (strcmp(
input.resolution,
"qdeg") == 0) {
860 }
else if (strcmp(
input.resolution,
"10deg") == 0) {
863 }
else if (strncmp(
input.resolution,
"udeg-", 5) == 0) {
864 dims_out[0] = (int32) (180 / atof(&
input.resolution[5]));
865 dims_out[1] = 2 * dims_out[0];
866 }
else if (strncmp(
input.resolution,
"ukm-", 4) == 0) {
867 dims_out[0] = (int32) (4320 * 4 / atof(&
input.resolution[4]) + 0.5);
868 dims_out[1] = 2 * dims_out[0];
870 printf(
"Improper resolution type: %s\n",
input.resolution);
873 printf(
"dims_out: %d x %d\n", dims_out[0], dims_out[1]);
878 void *old_client_data;
879 H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data);
880 H5Eset_auto(H5E_DEFAULT,
NULL,
NULL);
881 htri_t ishdf5 = H5Fis_hdf5(
input.ifile);
883 H5Eset_auto(H5E_DEFAULT, old_func, old_client_data);
885 int ncid, grpid, binindex_id, binlist_id, bindata_id, binqual_id;
898 status = nc_get_att(ncid, NC_GLOBAL,
"Mission", nam_buf);
900 status = nc_get_att(ncid, NC_GLOBAL,
"mission", nam_buf);
901 if ((strcmp(nam_buf,
"SAC-D Aquarius") == 0) ||
902 (strcmp(nam_buf,
"SMAP") == 0)) {
910 &grpid, &binindex_id, &binlist_id,
911 &bindata_id, &binqual_id, &meta_l3b);
913 if ((
nrows % 2) == 1) {
915 printf(
"HEALPIX input\n");
916 nside = (
nrows + 1) / 4;
924 &vgid, vdata_id, &meta_l3b);
928 sds_id = SDselect(sdfid, SDnametoindex(sdfid,
input.prod));
929 if (sds_id != -1) land_input = 1;
932 if (hdf4_input == 1 &&
933 (strcmp(
input.prod,
"pixels") != 0) &&
934 (strcmp(
input.prod,
"scenes") != 0)) {
935 if (VSfind(fid,
input.prod) == 0) {
936 printf(
"Product \"%s\" not found.\n",
input.prod);
942 printf(
"Input file : %s\n",
input.ifile);
943 printf(
"Projection : %s\n",
input.projection);
944 printf(
"Resolution : %s\n",
input.resolution);
945 printf(
"Gap Fill : %d\n",
input.gap_fill);
946 if (
input.minobs != 0) printf(
"Min Obs : %d\n",
input.minobs);
947 if (prod_num >= 0) printf(
"Parameter : %s\n",
parmname_list[prod_num]);
948 if (prod_num == -2) printf(
"Parameter : %s\n",
input.prod);
949 if (prod_num == -3) printf(
"Parameter : %s\n",
input.prod);
951 printf(
"Scale Type : %s\n", scale_type);
952 printf(
"Data Min (abs) : %8.4f\n",
input.datamin);
953 printf(
"Data Max (abs) : %8.4f\n",
input.datamax);
954 printf(
"Precision : %s\n",
input.precision);
955 printf(
"Scale Slope : %8.4f\n", si_used[0]);
956 printf(
"Scale Intercept : %8.4f\n", si_used[1]);
957 printf(
"Palette File : %s\n",
input.palfile);
958 printf(
"Eastmost Long. : %8.3f\n",
input.loneast);
959 printf(
"Westmost Long. : %8.3f\n",
input.lonwest);
960 printf(
"Northmost Lat. : %8.3f\n",
input.latnorth);
961 printf(
"Southmost Lat. : %8.3f\n",
input.latsouth);
962 printf(
"Seam Longitude : %8.3f\n\n",
input.seam_lon);
973 i = SDfindattr(sdfid,
"Pixel size (meters)");
974 if (
i != -1) SDreadattr(sdfid,
i, (VOIDP) & pix_sz);
979 (int32) ((180 * 6371007.181) / (57.29577951308232087684 * pix_sz) + 0.5);
980 dims_in[1] = 2 * dims_in[0];
985 sub_scan[1] = dims_in[0] - 1;
986 sub_pixl[1] = dims_in[1] - 1;
987 i = SDfindattr(sdfid,
"Subset Scan Range");
988 if (
i != -1) SDreadattr(sdfid,
i, (VOIDP) sub_scan);
989 i = SDfindattr(sdfid,
"Subset Pixel Range");
990 if (
i != -1) SDreadattr(sdfid,
i, (VOIDP) sub_pixl);
994 }
else if (hdf4_input == 1) {
1002 dims_in[1] = 2 *
nrows;
1003 printf(
"input dimensions (full map): %d %d\n", dims_in[0], dims_in[1]);
1005 binlist_buf = (uint8 *) calloc(dims_in[1], 12);
1006 sum_buf = (float32 *) calloc(dims_in[1], 2 *
sizeof (float32));
1007 qual_buf = (uint8 *) calloc(dims_in[1],
sizeof (uint8));
1010 strcat(buf,
"_sum,");
1011 strcat(buf,
input.prod);
1012 strcat(buf,
"_sum_sq");
1013 status = VSsetfields(vdata_id[0],
"bin_num,nobs,nscenes,weights");
1014 status = VSsetfields(vdata_id[1],
"start_num,begin,extent,max");
1015 status = VSsetfields(vdata_id[2], buf);
1016 if (vdata_id[3] != -1)
1017 status = VSsetfields(vdata_id[3],
"qual_l3");
1018 }
else if (hdf5_input == 1) {
1022 dims_in[1] = 2 *
nrows;
1023 printf(
"input dimensions (full map): %d %d\n", dims_in[0], dims_in[1]);
1025 binlist_buf = (uint8 *) calloc(dims_in[1], 12);
1026 sum_buf = (float32 *) calloc(dims_in[1], 2 *
sizeof (float32));
1028 binlist_tid = H5Tcreate(H5T_COMPOUND, 12);
1029 H5Tinsert(binlist_tid,
"bin_num", 0, H5T_STD_U32LE);
1030 H5Tinsert(binlist_tid,
"nobs", 4, H5T_NATIVE_USHORT);
1031 H5Tinsert(binlist_tid,
"nscenes", 6, H5T_NATIVE_USHORT);
1032 H5Tinsert(binlist_tid,
"weights", 8, H5T_NATIVE_FLOAT);
1035 binindex_tid = H5Tcreate(H5T_COMPOUND, 16);
1036 H5Tinsert(binindex_tid,
"start_num", 0, H5T_STD_I32LE);
1037 H5Tinsert(binindex_tid,
"begin", 4, H5T_STD_I32LE);
1038 H5Tinsert(binindex_tid,
"extent", 8, H5T_STD_I32LE);
1039 H5Tinsert(binindex_tid,
"max", 12, H5T_STD_I32LE);
1042 bindata_tid = H5Tcreate(H5T_COMPOUND, 2 *
sizeof (H5T_NATIVE_FLOAT));
1045 strcat(buf,
"_sum");
1046 H5Tinsert(bindata_tid, buf, 0, H5T_NATIVE_FLOAT);
1049 H5Tinsert(bindata_tid, buf,
sizeof (H5T_NATIVE_FLOAT), H5T_NATIVE_FLOAT);
1055 dims_in[1] = 2 *
nrows;
1057 binlist_buf = (uint8 *) calloc(dims_in[1], 16);
1058 sum_buf = (float32 *) calloc(dims_in[1], 2 *
sizeof (float32));
1061 if (binqual_id != -1) {
1062 qual_buf = (uint8 *) calloc(dims_in[1],
sizeof (uint8));
1075 if (hdf4_input || hdf5_input) {
1083 &min_out_row, &max_out_row, &min_out_col, &max_out_col);
1085 printf(
"min/max out row/col: %d %d %d %d\n",
1086 min_out_row, max_out_row, min_out_col, max_out_col);
1097 if (hdf4_input || hdf5_input) {
1103 if (land_input && max_out_col < min_out_col) {
1104 printf(
"max_out_col must be greater than min_out_col for land input.\n");
1108 dims_out_sub[0] = max_out_row - min_out_row + 1;
1109 if (max_out_col > min_out_col) {
1110 dims_out_sub[1] = max_out_col - min_out_col + 1;
1112 dims_out_sub[1] = dims_out[1] - (min_out_col - max_out_col + 1);
1115 if (strcmp(
input.precision,
"F") == 0)
1116 par_byt = (uint8 *) calloc(dims_out_sub[0] * dims_out_sub[1],
1117 4 *
sizeof (uint8));
1118 else if (strcmp(
input.precision,
"I") == 0)
1119 par_byt = (uint8 *) calloc(dims_out_sub[0] * dims_out_sub[1],
1120 2 *
sizeof (uint8));
1122 par_byt = (uint8 *) calloc(dims_out_sub[0] * dims_out_sub[1],
1125 if (vdata_id[3] != -1) {
1126 qual_byt = (uint8 *) calloc(dims_out_sub[0] * dims_out_sub[1],
1128 memset(qual_byt, 255, dims_out_sub[0] * dims_out_sub[1]);
1134 out_sum = (int32 *) calloc(dims_out[1],
sizeof (int32));
1135 out_num = (int32 *) calloc(dims_out[1],
sizeof (int32));
1136 best_qual = (uint8 *) calloc(dims_out[1],
sizeof (uint8));
1138 if (
input.seam_lon != -180) {
1139 out_sum_rot = (int32 *) calloc(dims_out[1],
sizeof (int32));
1140 out_num_rot = (int32 *) calloc(dims_out[1],
sizeof (int32));
1141 best_qual_rot = (uint8 *) calloc(dims_out[1],
sizeof (uint8));
1144 ratio = (float32) dims_out[0] / dims_in[0];
1145 max_rowbuf = (int32) (1 / ratio + 1);
1146 if (healpix_input) max_rowbuf *= 2;
1149 input_databuf = (int32 *) calloc(max_rowbuf * dims_in[1],
sizeof (int32));
1150 input_databuf_16 = (
int16 *) calloc(max_rowbuf * dims_in[1],
sizeof (
int16));
1151 input_qualbuf = (uint8 *) calloc(max_rowbuf * dims_in[1],
sizeof (uint8));
1153 in2out = (int32 *) calloc(dims_in[0],
sizeof (int32));
1154 for (
i = 0;
i < dims_in[0];
i++) in2out[
i] = (int32) ((
i + 0.5) * ratio);
1157 edges[1] = sub_pixl[1] - sub_pixl[0] + 1;
1161 int32_t nbinsread = 0;
1163 if (land_input) scl_fac = 10000;
1164 if (hdf4_input || hdf5_input || ncdf4_input) scl_fac = 1000000;
1165 if (strcmp(
input.precision,
"F") == 0 && hdf4_input) scl_fac = 100000;
1166 if (strcmp(
input.precision,
"F") == 0 && hdf5_input) scl_fac = 100000;
1170 for (out_row = 0; out_row < dims_out[0]; out_row++) {
1172 if ((out_row % 500) == 0) {
1174 tmnow = localtime(&tnow);
1175 printf(
"out_row:%6d %s", out_row, asctime(tmnow));
1178 if (healpix_input) {
1179 float cs = cos((out_row + 1)*(180.0 / dims_out[0])*(
PI / 180));
1181 input_row = nside * sqrt(3 * (1 - cs));
1182 else if (cs >= -(2. / 3))
1183 input_row = nside * (2 - 1.5 * cs);
1185 input_row = nside * (4 - sqrt(3 * (1 + cs)));
1186 for (
i = prev_input_row;
i < input_row;
i++)
1187 input_row_array[
i - prev_input_row] =
i;
1190 while (in2out[input_row] == out_row) {
1191 input_row_array[
i++] = input_row;
1194 printf(
"i > MAX_NUM_INPUTROW\n");
1200 start[0] = prev_input_row - sub_scan[0];
1201 edges[0] = input_row - prev_input_row;
1210 if (
start[0] >= 0 &&
start[0] <= sub_scan[1] - sub_scan[0]) {
1212 (VOIDP) & input_databuf_16[sub_pixl[0]]);
1215 input_databuf[sub_pixl[0] +
i] = input_databuf_16[sub_pixl[0] +
i];
1236 for (
i = 0;
i < max_rowbuf * dims_in[1];
i++) input_databuf[
i] = -32767;
1245 VSseek(vdata_id[1],
start[0] +
i);
1246 nread = VSread(vdata_id[1], (uint8 *) binindex_buf,
1250 printf(
"Problem with binindex read: %d\n", out_row);
1253 }
else if (hdf5_input) {
1256 hid_t filespace = H5Dget_space(
dataset);
1257 hsize_t strt =
start[0] +
i;
1258 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, &strt,
NULL,
1260 hid_t dataspace = H5Screate_simple(1, &one,
NULL);
1262 filespace, H5P_DEFAULT, binindex_buf);
1264 H5Sclose(dataspace);
1265 H5Sclose(filespace);
1267 size_t indexp =
start[0] +
i;
1268 status = nc_get_var1(grpid, binindex_id, &indexp, binindex_buf);
1273 if (binindex_buf[1] != 0) {
1276 if (binindex_buf[2] > dims_in[1]) {
1277 printf(
"Bin Index (%d) greater than column dimension (%d) for out row: %d\n",
1278 binindex_buf[2], dims_in[1], out_row);
1279 printf(
"%d %d\n", out_row,
start[0] +
i);
1286 nread = VSread(vdata_id[0], binlist_buf, binindex_buf[2],
1289 printf(
"Problem with binlist read: %d\n", out_row);
1295 if (strcmp(
input.prod,
"pixels") != 0 &&
1296 strcmp(
input.prod,
"scenes") != 0) {
1297 nread = VSread(vdata_id[2], (uint8 *) sum_buf, binindex_buf[2],
1301 printf(
"Problem with sum/sum_sqr read: %d\n", out_row);
1305 if (vdata_id[3] != -1) {
1306 nread = VSread(vdata_id[3], (uint8 *) qual_buf,
1307 binindex_buf[2], FULL_INTERLACE);
1310 printf(
"Problem with qual_l3 read: %d\n", out_row);
1315 }
else if (hdf5_input) {
1318 hsize_t strt = nbinsread;
1319 hsize_t
count = binindex_buf[2];
1323 hid_t filespace = H5Dget_space(
dataset);
1325 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, &strt,
1327 hid_t dataspace = H5Screate_simple(1, &
count,
NULL);
1329 filespace, H5P_DEFAULT, binlist_buf);
1331 H5Sclose(dataspace);
1332 H5Sclose(filespace);
1335 if (strcmp(
input.prod,
"pixels") != 0 &&
1336 strcmp(
input.prod,
"scenes") != 0) {
1340 hid_t filespace = H5Dget_space(
dataset);
1342 status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, &strt,
1344 hid_t dataspace = H5Screate_simple(1, &
count,
NULL);
1346 filespace, H5P_DEFAULT, sum_buf);
1348 H5Sclose(dataspace);
1349 H5Sclose(filespace);
1352 nbinsread += binindex_buf[2];
1355 size_t strt = nbinsread;
1356 size_t count = binindex_buf[2];
1358 status = nc_get_vara(grpid, binlist_id, &strt, &
count,
1361 if (binqual_id != -1) {
1362 status = nc_get_vara(grpid, binqual_id, &strt, &
count,
1366 if (strcmp(
input.prod,
"pixels") != 0 &&
1367 strcmp(
input.prod,
"scenes") != 0) {
1368 status = nc_get_vara(grpid, bindata_id, &strt, &
count, sum_buf);
1371 nbinsread += binindex_buf[2];
1375 if (healpix_input) {
1377 cos((((input_row_array[
i] + 0.5) / dims_in[0]) - 0.5) *
PI);
1378 heal2sin = (dims_in[1] * cos_theta_input) / binindex_buf[3];
1380 offset = (dims_in[1] - binindex_buf[3]) / 2;
1386 for (
k = 0;
k < binindex_buf[2];
k++) {
1387 memcpy(&bin_num, &binlist_buf[
k * binlist_sz], 4);
1388 memcpy(&
nobs, &binlist_buf[
k * binlist_sz + 4], 2);
1389 memcpy(&
nscenes, &binlist_buf[
k * binlist_sz + 6], 2);
1390 memcpy(&wgt, &binlist_buf[
k * binlist_sz + 8], 4);
1394 if (isnan(sum_buf[
k * 2])) {
1400 if (
input.minobs != 0)
1401 if ((uint32_t)
nobs <
input.minobs)
continue;
1403 if (healpix_input) {
1404 int32_t rot_bin_num = ((bin_num - binindex_buf[0]) +
1405 binindex_buf[3] / 2) % binindex_buf[3];
1409 j =
i * dims_in[1] + rot_bin_num * heal2sin
1410 + (dims_in[1] - binindex_buf[3] * heal2sin) / 2;
1413 j =
i * dims_in[1] + (bin_num - binindex_buf[0]) +
offset;
1416 if (
j >= (max_rowbuf * dims_in[1])) {
1417 printf(
"Databuf element (%d) greater than buffer size (%d) for out_row: %d\n",
1418 j, max_rowbuf * dims_in[1], out_row);
1419 printf(
"i: %d k: %d bin_num: %d offset: %d\n",
1421 printf(
"binindex_buf[0]: %d binindex_buf[1]: %d\n",
1422 binindex_buf[0], binindex_buf[1]);
1423 printf(
"binindex_buf[2]: %d binindex_buf[3]: %d\n",
1424 binindex_buf[2], binindex_buf[3]);
1429 printf(
"Databuf element (%d) is negative for out_row: %d\n",
1431 printf(
"i: %d k: %d bin_num: %d offset: %d bin_row: %d\n",
1433 printf(
"bin start number for row: %d data starting bin #: %d\n",
1434 binindex_buf[0], binindex_buf[1]);
1435 printf(
"# of bins in row with data: %d # of bins in row: %d\n",
1436 binindex_buf[2], binindex_buf[3]);
1440 if (vdata_id[3] != -1) input_qualbuf[
j] = qual_buf[
k];
1442 if (
input.meas == 1) {
1444 flt_val = sum_buf[
k * 2] / wgt;
1445 input_databuf[
j] = (int32) (scl_fac * flt_val + 0.5);
1447 }
else if ((
input.meas == 2 ||
input.meas == 3) &&
1450 flt_val = sum_buf[
k * 2] / wgt;
1451 flt_val = (sum_buf[
k * 2 + 1] / wgt) - (flt_val * flt_val);
1453 flt_val = flt_val * wgt * wgt / (wgt * wgt -
nscenes);
1455 if (
input.meas == 3) flt_val = sqrt(flt_val);
1457 input_databuf[
j] = (int32) (scl_fac * flt_val + 0.5);
1459 }
else if (
input.meas == 4) {
1461 input_databuf[
j] = (int32) ((1.0 *
nobs) /
nscenes + 0.5);
1463 }
else if (
input.meas == 5) {
1465 input_databuf[
j] = (int32) (
nscenes);
1474 if (binindex_buf[3] % 2 == 1 &&
1476 getenv(
"SMIGENNOHALF") ==
NULL) {
1482 j =
i * dims_in[1] +
k;
1483 if (
k ==
offset) jm1 =
j + binindex_buf[3] - 1;
1486 if (input_databuf[jm1] != -32767) {
1487 if (input_databuf[
j] != -32767) {
1498 input_databuf[(
i + 1) * dims_in[1] -
offset - 1] = input_databuf[
j];
1505 if (
input.gap_fill >= 1 &&
input.meas <= 3) {
1506 for (
k = 1;
k < max_rowbuf * dims_in[1] - 1;
k++) {
1507 if (input_databuf[
k - 1] != -32767 &&
1508 input_databuf[
k] == -32767 &&
1509 input_databuf[
k + 1] != -32767) {
1510 if ((vdata_id[3] != -1)) {
1511 if (input_qualbuf[
k - 1] == input_qualbuf[
k + 1]) {
1513 input_databuf[
k] = (int32)
1514 (0.5 * (input_databuf[
k - 1] + input_databuf[
k + 1]) + 0.5);
1515 input_qualbuf[
k] = input_qualbuf[
k - 1];
1518 tk = (input_databuf[
k - 1] < input_databuf[
k + 1]) ?
k - 1 :
k + 1;
1519 input_qualbuf[
k] = input_qualbuf[
tk];
1520 input_databuf[
k] = input_databuf[
tk];
1523 input_databuf[
k] = (int32)
1524 (0.5 * (input_databuf[
k - 1] + input_databuf[
k + 1]) + 0.5);
1531 if (
input.gap_fill >= 2 &&
input.meas <= 3) {
1532 for (
k = 1;
k < max_rowbuf * dims_in[1] - 2;
k++) {
1533 if (input_databuf[
k - 1] != -32767 &&
1534 input_databuf[
k] == -32767 &&
1535 input_databuf[
k + 1] == -32767 &&
1536 input_databuf[
k + 2] != -32767) {
1537 if ((vdata_id[3] != -1)) {
1538 if (input_qualbuf[
k - 1] == input_qualbuf[
k + 2]) {
1540 input_databuf[
k] = (int32)
1541 ((input_databuf[
k + 2] + 2 * input_databuf[
k - 1]) / 3 + 0.5);
1542 input_databuf[
k + 1] = (int32)
1543 ((2 * input_databuf[
k + 2] + input_databuf[
k - 1]) / 3 + 0.5);
1544 input_qualbuf[
k] = input_qualbuf[
k - 1];
1545 input_qualbuf[
k + 1] = input_qualbuf[
k - 1];
1548 tk = (input_databuf[
k - 1] < input_databuf[
k + 2]) ?
k - 1 :
k + 2;
1549 input_qualbuf[
k] = input_qualbuf[
tk];
1550 input_databuf[
k] = input_databuf[
tk];
1551 input_qualbuf[
k + 1] = input_qualbuf[
tk];
1552 input_databuf[
k + 1] = input_databuf[
tk];
1555 input_databuf[
k] = (int32)
1556 ((input_databuf[
k + 2] + 2 * input_databuf[
k - 1]) / 3 + 0.5);
1557 input_databuf[
k + 1] = (int32)
1558 ((2 * input_databuf[
k + 2] + input_databuf[
k - 1]) / 3 + 0.5);
1569 prev_input_row = input_row;
1571 if (out_row < min_out_row)
continue;
1572 if (out_row > max_out_row)
break;
1574 for (
i = 0;
i < dims_out[1];
i++) out_sum[
i] = -32767;
1575 for (
i = 0;
i < dims_out[1];
i++) out_num[
i] = 0;
1576 for (
i = 0;
i < dims_out[1];
i++) best_qual[
i] = 255;
1578 cos_theta_output = cos((((out_row + 0.5) / dims_out[0]) - 0.5) *
PI);
1585 cos((((input_row_array[
j] + 0.5) / dims_in[0]) - 0.5) *
PI);
1587 if (strcmp(
input.projection,
"SIN") == 0) {
1588 cos_fac = cos_theta_output / cos_theta_input;
1589 pixmin = (int32) (0.5 * dims_out[1] * (1 - cos_theta_output));
1590 pixmax = (int32) (0.5 * dims_out[1] * (1 + cos_theta_output));
1593 if (strcmp(
input.projection,
"RECT") == 0) {
1594 cos_fac = 1 / cos_theta_input;
1596 pixmax = dims_out[1];
1599 if (pixmin < 0) pixmin = 0;
1600 if (pixmax > dims_out[1]) pixmax = dims_out[1];
1604 for (
i = pixmin;
i < pixmax;
i++) {
1607 (int32) ((((float32) (
i + 0.5) / dims_out[1]) -
1608 0.5 * (1 - cos_fac)) * (dims_in[1] / cos_fac));
1610 input_value = input_databuf[
j * dims_in[1] + input_col];
1612 if (input_value != -32767) {
1614 if ((vdata_id[3] != -1)) {
1615 input_qual = input_qualbuf[
j * dims_in[1] + input_col];
1616 if (input_qual < best_qual[
i]) {
1618 out_sum[
i] = -32767;
1619 best_qual[
i] = input_qual;
1620 }
else if (input_qual > best_qual[
i])
continue;
1625 if (out_sum[
i] != -32767)
1626 out_sum[
i] += input_value;
1628 out_sum[
i] = input_value;
1636 if (
input.seam_lon != -180 && land_input == 0) {
1637 rotate = (int32) ((
input.seam_lon + 180) * (pixmax - pixmin) / 360 + 0.5);
1639 for (
i = pixmin;
i < pixmax;
i++) {
1640 out_sum_rot[
i] = out_sum[(
i +
rotate) % (pixmax - pixmin)];
1641 out_num_rot[
i] = out_num[(
i +
rotate) % (pixmax - pixmin)];
1642 best_qual_rot[
i] = best_qual[(
i +
rotate) % (pixmax - pixmin)];
1645 for (
i = pixmin;
i < pixmax;
i++) {
1646 out_sum[
i] = out_sum_rot[
i];
1647 out_num[
i] = out_num_rot[
i];
1648 best_qual[
i] = best_qual_rot[
i];
1655 if (strncmp(
input.prod,
"refl", 4) == 0 ||
1656 strncmp(
input.prod,
"rhos", 4) == 0) {
1662 for (
i = 0;
i < dims_out[1];
i++) {
1664 if (max_out_col > min_out_col) {
1665 if (i < min_out_col || i > max_out_col)
continue;
1667 if (i < min_out_col && i > max_out_col)
continue;
1670 if (max_out_col > min_out_col) {
1671 if (land_input || healpix_input)
1672 k = (out_row - min_out_row) * dims_out_sub[1] + (
i - min_out_col);
1674 k = (max_out_row - out_row) * dims_out_sub[1] + (
i - min_out_col);
1676 if (land_input || healpix_input)
1677 k = (out_row - min_out_row) * dims_out_sub[1] +
1678 (
i - min_out_col) * (
i >= min_out_col) +
1679 (dims_out[1] - min_out_col +
i - 1) * (
i < max_out_col);
1681 k = (max_out_row - out_row) * dims_out_sub[1] +
1682 (
i - min_out_col) * (
i >= min_out_col) +
1683 (dims_out[1] - min_out_col +
i - 1) * (
i < max_out_col);
1686 if (k < 0 || k >= (dims_out_sub[0] * dims_out_sub[1])) {
1687 printf(
"k: %d i: %d\n", (
int)
k,
i);
1691 if (strcmp(
input.precision,
"F") == 0) {
1692 memcpy(&par_byt[4 *
k], &fill_val_float, 4);
1693 }
else if (strcmp(
input.precision,
"I") == 0) {
1694 memcpy(&par_byt[2 *
k], &fill_val, 1);
1695 memcpy(&par_byt[2 *
k + 1], &fill_val, 1);
1696 }
else if (strcmp(
input.precision,
"B") == 0) {
1697 par_byt[
k] = fill_val;
1703 for (
i = 0;
i < dims_out[1];
i++) {
1705 if (max_out_col > min_out_col) {
1706 if (i < min_out_col || i > max_out_col)
continue;
1708 if (i < min_out_col && i > max_out_col)
continue;
1711 if (max_out_col > min_out_col) {
1712 if (land_input || healpix_input)
1713 k = (out_row - min_out_row) * dims_out_sub[1] + (
i - min_out_col);
1715 k = (max_out_row - out_row) * dims_out_sub[1] + (
i - min_out_col);
1717 if (land_input || healpix_input)
1718 k = (out_row - min_out_row) * dims_out_sub[1] +
1719 (
i - min_out_col) * (
i >= min_out_col) +
1720 (dims_out[1] - min_out_col +
i - 1) * (
i < max_out_col);
1722 k = (max_out_row - out_row) * dims_out_sub[1] +
1723 (
i - min_out_col) * (
i >= min_out_col) +
1724 (dims_out[1] - min_out_col +
i - 1) * (
i < max_out_col);
1727 if (out_sum[
i] != -32767) {
1731 flt_val = (out_sum[
i] / out_num[
i]) / scl_fac;
1733 if (strcmp(
input.precision,
"F") == 0) {
1734 if (flt_val < dminmax[0]) dminmax[0] = flt_val;
1735 if (flt_val > dminmax[1]) dminmax[1] = flt_val;
1736 memcpy(&par_byt[4 *
k], &flt_val, 4);
1737 if (vdata_id[3] != -1) qual_byt[
k] = best_qual[
i];
1741 if (flt_val < dminmax[0]) dminmax[0] = flt_val;
1742 if (flt_val > dminmax[1]) dminmax[1] = flt_val;
1744 if (flt_val <
input.datamin) flt_val =
input.datamin;
1745 if (flt_val >
input.datamax) flt_val =
input.datamax;
1747 if (prod_num == -2) {
1749 if (out_sum[
i] > 0.0) {
1750 flt_val = 396.3 * log10(8.546 * flt_val + 1);
1753 }
else if (prod_num == -3) {
1756 flt_val =
rint((log10(flt_val) + 2.0) / (2.0 / 255));
1760 if (flt_val < 0) flt_val = 0;
1761 if (flt_val > 255) flt_val = 255;
1768 }
else if (strcmp(scale_type,
"LINEAR") == 0) {
1770 }
else if (strcmp(scale_type,
"LOG") == 0) {
1774 if (strcmp(
input.precision,
"I") == 0) {
1775 if (strcmp(
input.prod,
"pixels") == 0 ||
1776 strcmp(
input.prod,
"scenes") == 0) {
1777 scale_val_16b = (uint16) out_sum[
i];
1778 if (scale_val_16b < dminmax[0]) dminmax[0] = scale_val_16b;
1779 if (scale_val_16b > dminmax[1]) dminmax[1] = scale_val_16b;
1781 scale_val_16b = (uint16) (flt_val + 0.5);
1783 memcpy(&par_byt[2 *
k], &scale_val_16b, 2);
1785 par_byt[
k] = (uint8) (flt_val + 0.5);
1790 if (vdata_id[3] != -1) qual_byt[
k] = best_qual[
i];
1797 if (land_input) SDendaccess(sds_id);
1802 if (land_input && strcmp(
input.projection,
"RECT") == 0) {
1804 tmp_str = getenv(
"OCDATAROOT");
1805 if (tmp_str == 0x0) {
1806 printf(
"Environment variable OCDATAROOT not defined.\n");
1810 strcat(buf,
"/common/landmask.dat");
1812 printf(
"Opening: %s for masking\n", buf);
1813 mask_fp = fopen(buf,
"rb");
1815 if (mask_fp == 0x0) {
1816 printf(
"Land mask file: %s not found.\n", buf);
1820 ptr_arr = (uint16 *) calloc(1024 * 64,
sizeof (uint16));
1821 for (
i = 0;
i < 8 * 128;
i++) mixed_buf[
i] =
NULL;
1823 fseek(mask_fp, 1024 * 2, SEEK_SET);
1824 fread(ptr_arr, 2, 1024 * 64, mask_fp);
1829 ptr_i8 = (uint8 *) ptr_arr;
1830 for (
i = 0;
i < 1024 * 64;
i++) {
1831 memcpy(&i8, ptr_i8, 1);
1832 memcpy(ptr_i8, ptr_i8 + 1, 1);
1833 memcpy(ptr_i8 + 1, &i8, 1);
1840 for (out_row = 0; out_row < dims_out[0]; out_row++) {
1842 if ((out_row % 500) == 0) {
1844 tmnow = localtime(&tnow);
1848 if (out_row < min_out_row)
continue;
1849 if (out_row > max_out_row)
break;
1851 if (strcmp(
input.projection,
"RECT") == 0) {
1853 pixmax = dims_out[1];
1856 if (pixmin < 0) pixmin = 0;
1857 if (pixmax > dims_out[1]) pixmax = dims_out[1];
1859 lat = 180 - (int32) (((out_row + 0.5) / dims_out[0]) * 180) - 1;
1860 latf =
lat - (180 - (((out_row + 0.5) / dims_out[0]) * 180) - 1);
1864 for (
i = pixmin;
i < pixmax;
i++) {
1866 if (max_out_col > min_out_col) {
1867 if (i < min_out_col || i > max_out_col)
continue;
1869 if (i < min_out_col && i > max_out_col)
continue;
1872 lon = (int32) (((
i + 0.5) / dims_out[1]) * 360);
1873 lonf = (((
i + 0.5) / dims_out[1]) * 360) -
lon;
1875 cur_ptr = ptr_arr[360 *
lat +
lon];
1880 if (max_out_col > min_out_col) {
1881 k = (out_row - min_out_row) * dims_out_sub[1] + (
i - min_out_col);
1883 k = (out_row - min_out_row) * dims_out_sub[1] +
1884 (
i - min_out_col) * (
i >= min_out_col) +
1885 (dims_out[1] - min_out_col +
i - 1) * (
i < max_out_col);
1888 if (strcmp(
input.precision,
"F") == 0) {
1889 memcpy(&par_byt[4 *
k], &fill_val_float, 4);
1890 }
else if (strcmp(
input.precision,
"I") == 0) {
1891 memcpy(&par_byt[2 *
k], &fill_val, 1);
1892 memcpy(&par_byt[2 *
k + 1], &fill_val, 1);
1893 }
else if (strcmp(
input.precision,
"B") == 0) {
1894 par_byt[
k] = fill_val;
1904 if (cur_ptr > 65 && cur_ptr != last_ptr) {
1906 if (mixed_buf[cur_ptr - 66] ==
NULL) {
1908 fseek(mask_fp, cur_ptr * 1024 * 2, SEEK_SET);
1909 fread(&mixed[0], 2, 1024, mask_fp);
1913 ptr_i8 = (uint8 *) & mixed[0];
1914 for (
k = 0;
k < 1024;
k++) {
1915 memcpy(&i8, ptr_i8, 1);
1916 memcpy(ptr_i8, ptr_i8 + 1, 1);
1917 memcpy(ptr_i8 + 1, &i8, 1);
1922 mixed_buf[cur_ptr - 66] = (
int16 *) calloc(8 * 128, 2);
1923 memcpy(mixed_buf[cur_ptr - 66], &mixed[0], 8 * 128 * 2);
1926 memcpy(&mixed[0], mixed_buf[cur_ptr - 66], 8 * 128 * 2);
1930 j = (int32) (128 * (1 - latf));
1931 l = (int32) (128 * lonf);
1932 if ((mixed[
j][l / 16] & pow2[15 - (l % 16)]) == 0) {
1934 if (max_out_col > min_out_col) {
1935 k = (out_row - min_out_row) * dims_out_sub[1] + (
i - min_out_col);
1937 k = (out_row - min_out_row) * dims_out_sub[1] +
1938 (
i - min_out_col) * (
i >= min_out_col) +
1939 (dims_out[1] - min_out_col +
i - 1) * (
i < max_out_col);
1942 if (strcmp(
input.precision,
"F") == 0) {
1943 memcpy(&par_byt[4 *
k], &fill_val_float, 4);
1944 }
else if (strcmp(
input.precision,
"I") == 0) {
1945 memcpy(&par_byt[2 *
k], &fill_val, 1);
1946 memcpy(&par_byt[2 *
k + 1], &fill_val, 1);
1947 }
else if (strcmp(
input.precision,
"B") == 0) {
1948 par_byt[
k] = fill_val;
1956 if (strcmp(
input.precision,
"B") == 0) {
1958 for (
i = pixmin;
i < pixmax;
i++) {
1959 if (max_out_col > min_out_col) {
1960 if (i < min_out_col || i > max_out_col)
continue;
1962 if (i < min_out_col && i > max_out_col)
continue;
1965 if (max_out_col > min_out_col) {
1966 k = (out_row - min_out_row) * dims_out_sub[1] + (
i - min_out_col);
1968 k = (out_row - min_out_row) * dims_out_sub[1] +
1969 (
i - min_out_col) * (
i >= min_out_col) +
1970 (dims_out[1] - min_out_col +
i - 1) * (
i < max_out_col);
1976 if (
i >= min_out_col + 2 && par_byt[
k] == 0 && par_byt[
k - 1] == 255) {
1977 for (
j =
k + 1;
j < dims_out[1];
j++) {
1978 if (par_byt[
j] != 0) {
1984 for (l =
j - 1; l >=
k; l--) {
1991 if (
i <= max_out_col - 2 && par_byt[
k] == 0 && par_byt[
k + 1] == 255) {
1992 for (
j =
k - 1;
j >= 0;
j--) {
1993 if (par_byt[
j] != 0) {
1999 for (l =
j + 1; l <=
k; l++) {
2010 for (
i = 0;
i < 360 * 180;
i++) {
2011 if (mixed_buf[
i] !=
NULL) free(mixed_buf[
i]);
2019 printf(
"Actual Data Min : %8.4f\n", dminmax[0]);
2020 printf(
"Actual Data Max : %8.4f\n", dminmax[1]);
2022 if (strcmp(
input.precision,
"F") == 0) {
2023 printf(
"\nData is output in float format (unscaled)\n");
2025 printf(
"Scaled Data Min : %8.4f\n", aminmax[0]);
2026 printf(
"Scaled Data Max : %8.4f\n\n", aminmax[1]);
2030 printf(
"\nNumber of input bins : %ld\n", (
long)meta_l3b.
data_bins);
2032 printf(
"Number of filled grid points : %d\n", filled_data_bins);
2034 tgp = dims_out[0] * dims_out[1];
2035 printf(
"Total number of grid points : %u\n", tgp);
2037 printf(
"Percentage of filled grid points: %8.4f%%\n",
2038 (100 * (float32) filled_data_bins) / tgp);
2039 printf(
"Output File : %s\n",
input.ofile);
2045 if (strncmp(
input.prod,
"refl", 4) == 0 ||
2046 strncmp(
input.prod,
"rhos", 4) == 0) {
2047 fp = fopen(
input.ofile,
"wb");
2048 fprintf(fp,
"%s\n",
"P5");
2049 fprintf(fp,
"%d\n", dims_out_sub[1]);
2050 fprintf(fp,
"%d\n", dims_out_sub[0]);
2051 fprintf(fp,
"%d\n", 255);
2052 fwrite(&par_byt[0], 1, dims_out_sub[0] * dims_out_sub[1], fp);
2056 if (strcmp(
input.precision,
"I") == 0) {
2074 if (ncdf4_input)
strcpy(
input.oformat,
"netCDF4");
2076 if (strcmp(
input.oformat,
"HDF5") == 0)
isHDF5 = 1;
2077 if (strcmp(
input.oformat,
"netCDF4") == 0)
isHDF5 = 2;
2082 if (strcmp(
input.precision,
"F") == 0) {
2083 fill = (VOIDP) & fill_val_float;
2084 }
else if (strcmp(
input.precision,
"I") == 0) {
2085 fill = (VOIDP) & fill_val_int16;
2086 }
else if (strcmp(
input.precision,
"B") == 0) {
2087 fill = (VOIDP) & fill_val;
2090 ptr_meta_l3b = &meta_l3b;
2092 ptr_meta_l3b->
data_bins = filled_data_bins;
2094 dims_out_sub, &
input.latnorth, &
input.lonwest,
2096 si_used, aminmax, atype, aopt,
input.ifile, dminmax,
2097 ptr_meta_l3b, (
unsigned char *)
input.palette, softid, proc_con,
2102 free(input_databuf_16);
2103 free(input_databuf);
2104 free(input_qualbuf);
2111 if (
input.seam_lon != -180) {
2114 free(best_qual_rot);
2117 if (binlist_buf !=
NULL) free(binlist_buf);
2118 if (sum_buf !=
NULL) free(sum_buf);
2119 if (qual_buf !=
NULL) free(qual_buf);
2143 int32 *vgid, int32 vdata_id[],
meta_l3bType *meta_l3b) {
2153 if ((*fid = Hopen(hdf_file, DFACC_RDONLY, 0)) < 0) {
2154 fprintf(
stderr,
"Error: Cannot open input HDF file on Hopen - %s\n",
2161 if ((*sdfid = SDstart(hdf_file, DFACC_RDONLY)) < 0) {
2162 fprintf(
stderr,
"Error: Cannot open input HDF file on SDstart- %s\n",
2175 vg_ref = Vfind(*fid,
"Level-3 Binned Data");
2178 *vgid = Vattach(*fid, vg_ref,
"r");
2180 tmp_str = (
char *) malloc(strlen(hdf_file) + 1);
2181 strcpy(tmp_str, hdf_file);
2183 HXsetdir(dirname(tmp_str));
2185 for (
i = 0;
i < Vntagrefs(*vgid);
i++) {
2186 Vgettagref(*vgid,
i, &tag, &
ref);
2187 vdid = VSattach(*fid,
ref,
"r");
2188 VSgetname(vdid, nam_buf);
2189 VSgetclass(vdid, cls_buf);
2191 if (strcmp(cls_buf,
"DataMain") == 0) {
2195 if (strcmp(cls_buf,
"Index") == 0) {
2197 nrows = VSelts(vdata_id[1]);
2200 if (strcmp(cls_buf,
"DataSubordinate") == 0 &&
2201 strcmp(nam_buf, pname) == 0) {
2205 if (strcmp(cls_buf,
"DataQuality") == 0) {
2212 if (vdata_id[0] == -1) {
2213 printf(
"\"DataMain\" Vdata Not Found.\n");
2217 if (vdata_id[1] == -1) {
2218 printf(
"\"Index\" Vdata Not Found.\n");
2228 "Sea-viewing Wide Field-of-view Sensor (SeaWiFS)");
2231 " Level-3 Standard Mapped Image");
2235 strcpy(meta_l3b->
mission_char,
"Nominal orbit: inclination = 98.2 (Sun-synchronous); node = 12 noon local (descending); eccentricity = <0.002; altitude = 705 km; ground speed = 6.75 km/sec");
2239 strcpy(meta_l3b->
sensor_char,
"Number of bands = 8; number of active bands = 8; wavelengths per band (nm) = 412, 443, 490, 510, 555, 670, 765, 865; bits per pixel = 10; instantaneous field-of-view = 1.5835 mrad; pixels per scan = 1285; scan rate = 6/sec; sample rate = 7710/sec");
2248 hid_t *bin_dataset_idx) {
2249 input_binfile->
open(hdf5_file);
2251 if (strcmp(pname,
"pixels") == 0)
2259 H5Iget_name(
dataset, ds_name, 200);
2260 if (strcmp(pname, &ds_name[21]) == 0)
break;
2263 if (
i == input_binfile->
nprod()) {
2264 cout <<
"Input product: \"" << pname
2265 <<
"\" not found in input binfile." << endl;
2270 *bin_dataset_idx =
i;
2275 size_t *
nrows,
int *grpid,
2276 int *binindex_id,
int *binlist_id,
2277 int *bindata_id,
int *binqual_id,
2282 status = nc_inq_ncid(ncid,
"level-3_binned_data", grpid);
2283 status = nc_inq_dimid(*grpid,
"binIndexDim", &dimid);
2286 status = nc_inq_varid(*grpid,
"BinIndex", binindex_id);
2287 status = nc_inq_varid(*grpid,
"BinList", binlist_id);
2289 status = nc_inq_varid(*grpid, pname, bindata_id);
2290 if (
status != NC_NOERR) {
2291 cout <<
"Product \"" << pname <<
"\" not found in input file" << endl;
2295 status = nc_inq_varid(*grpid,
"qual_l3", binqual_id);
2296 if (
status != NC_NOERR) *binqual_id = -1;
2300 int proc_ctl_grp_id;
2301 status = nc_inq_grp_ncid(ncid,
"processing_control", &proc_ctl_grp_id);
2302 status = nc_get_att(proc_ctl_grp_id, NC_GLOBAL,
"l2_flag_names",
2312 VSdetach(vdata_id[0]);
2313 if (vdata_id[2] != -1) VSdetach(vdata_id[2]);
2314 VSdetach(vdata_id[1]);
2325 char* proj_type, int32 out_rows,
2326 int32 *min_out_row, int32 *max_out_row,
2327 int32 *min_out_col, int32 *max_out_col) {
2328 int32 n_w, n_e, s_w, s_e, w_0, e_0;
2330 *min_out_row = (int32) (out_rows * (90 - lat_range[0]) / 180);
2331 *max_out_row = (int32) (out_rows * (90 - lat_range[1]) / 180 - 1);
2334 if (strcmp(proj_type,
"SIN") == 0) {
2335 n_w = (int32) ((cos(lat_range[0] *
PI / 180) * out_rows) * (lon_range[0] / 180) + out_rows);
2336 n_e = (int32) ((cos(lat_range[0] *
PI / 180) * out_rows) * (lon_range[1] / 180) + out_rows);
2337 s_w = (int32) ((cos(lat_range[1] *
PI / 180) * out_rows) * (lon_range[0] / 180) + out_rows);
2338 s_e = (int32) ((cos(lat_range[1] *
PI / 180) * out_rows) * (lon_range[1] / 180) + out_rows);
2339 w_0 = (int32) ((out_rows) * (lon_range[0] / 180) + out_rows);
2340 e_0 = (int32) ((out_rows) * (lon_range[1] / 180) + out_rows);
2343 if (strcmp(proj_type,
"RECT") == 0) {
2344 n_w = (int32) ((out_rows) * (lon_range[0] / 180) + out_rows);
2345 n_e = (int32) ((out_rows) * (lon_range[1] / 180) + out_rows);
2346 s_w = (int32) ((out_rows) * (lon_range[0] / 180) + out_rows);
2347 s_e = (int32) ((out_rows) * (lon_range[1] / 180) + out_rows);
2348 w_0 = (int32) ((out_rows) * (lon_range[0] / 180) + out_rows);
2349 e_0 = (int32) ((out_rows) * (lon_range[1] / 180) + out_rows);
2352 if ((lat_range[0] * lat_range[1]) < 0) {
2353 if (n_w <= s_w && n_w <= w_0) *min_out_col = n_w;
2354 if (s_w <= n_w && s_w <= w_0) *min_out_col = s_w;
2355 if (w_0 <= s_w && w_0 <= n_w) *min_out_col = w_0;
2357 if (n_e >= s_e && n_e >= e_0) *max_out_col = n_e - 1;
2358 if (s_e >= n_e && s_e >= e_0) *max_out_col = s_e - 1;
2359 if (e_0 >= s_e && e_0 >= n_e) *max_out_col = e_0 - 1;
2361 if (n_w <= s_w) *min_out_col = n_w;
2362 if (s_w <= n_w) *min_out_col = s_w;
2364 if (n_e >= s_e) *max_out_col = n_e - 1;
2365 if (s_e >= n_e) *max_out_col = s_e - 1;