Go to the documentation of this file.
6 #define NITEMPTR 1024 * 64
8 #define MAX_PIX_PER_SCENE MAXPIX*20000
10 static FILE *stream[2] = {
NULL,
NULL};
15 static int access_cnt[2] = {0, 0};
16 static int last_box_num[2] = {-1, -1};
17 static int boxes_active[2] = {0, 0};
28 static box_info_t* box_info;
57 box_info = (box_info_t*)
allocateMemory(2 *
sizeof (box_info_t),
"box_info");
65 if (msknum < 0 || msknum > 1) {
66 fprintf(
stderr,
"b128_msk_init: Fatal error. only mask 0 or 1 can be used\n");
67 fprintf(
stderr,
" current mask: %d\n", msknum);
68 fprintf(
stderr,
"Exiting\n");
74 if ((stream[msknum] = fopen(landfile,
"rb")) ==
NULL) {
75 fprintf(
stderr,
"b128_msk_init: Fatal error. failed to open mask file # %d:\n",
77 fprintf(
stderr,
" '%s'\n", landfile);
78 fprintf(
stderr,
"Exiting\n");
84 if (fread(rec_arr,
sizeof (
short), 1024, stream[msknum]) != 1024) {
85 fprintf(
stderr,
"b128_msk_init: read error for first record of file # %d:\n",
87 fprintf(
stderr,
" '%s'\n", landfile);
88 fprintf(
stderr,
"Exiting\n");
95 if (rec_arr[0] != 128 || rec_arr[2] != 2048 ||
96 rec_arr[3] != -180 || rec_arr[4] != 180 ||
97 rec_arr[5] != -90 || rec_arr[6] != 90) {
98 fprintf(
stderr,
"b128_msk_init: header record does not match expected values\n");
99 fprintf(
stderr,
" for mask # %d\n", msknum);
100 fprintf(
stderr,
"\nvalue expected read\n");
101 fprintf(
stderr,
"0 128 %d\n", rec_arr[0]);
102 fprintf(
stderr,
"2 2048 %d\n", rec_arr[2]);
103 fprintf(
stderr,
"3 -180 %d\n", rec_arr[3]);
104 fprintf(
stderr,
"4 180 %d\n", rec_arr[4]);
105 fprintf(
stderr,
"5 -90 %d\n", rec_arr[5]);
106 fprintf(
stderr,
"6 90 %d\n\n", rec_arr[6]);
107 fprintf(
stderr,
"Exiting\n");
114 if (fread(ptr_arr[msknum],
sizeof (
short),
NITEMPTR, stream[msknum]) !=
116 fprintf(
stderr,
"b128_msk_init: read error for pointer array of file:\n");
117 fprintf(
stderr,
" '%s'\n", landfile);
118 fprintf(
stderr,
" mask # %d\n", msknum);
119 fprintf(
stderr,
"Exiting\n");
129 access_cnt[msknum] = 0;
130 boxes_active[msknum] = 0;
166 if (len > 399) len = 399;
172 strcpy(landfile, flandfile);
174 strncpy(landfile, flandfile, len);
175 strtok(landfile,
" ");
209 int land_fl,
box_num, box_index, low_access_cnt,
210 low_access_index,
i, box_wd, box_bit;
211 float lat_off, lon_off;
212 unsigned short mask[16] = {0x8000, 0x4000, 0x2000, 0x1000,
213 0x800, 0x400, 0x200, 0x100,
214 0x80, 0x40, 0x20, 0x10,
216 static int last_box_index[2];
224 if (msknum < 0 || msknum > 1) {
225 fprintf(
stderr,
"b128_msk_init: Fatal error. only mask 0 or 1 can be used\n");
226 fprintf(
stderr,
" current mask: %d\n", msknum);
227 fprintf(
stderr,
"Exiting\n");
233 access_cnt[msknum]++;
236 printf(
"b128_msk_get: Pixels Per Scene Count Exceeded.\n");
240 if (stream[msknum] ==
NULL) {
241 fprintf(
stderr,
"b128_msk_get: routine b128_msk_init not called yet\n");
242 fprintf(
stderr,
" for mask # %d\n", msknum);
243 fprintf(
stderr,
"Exiting\n");
254 if (*(ptr_arr[msknum] +
box_num) < 2) {
255 land_fl = *(ptr_arr[msknum] +
box_num);
260 if (
box_num == last_box_num[msknum]) {
261 box_index = last_box_index[msknum];
268 low_access_index = -1;
270 for (
i = 0;
i < boxes_active[msknum];
i++) {
276 box_info[msknum][
i].last_access_cnt = access_cnt[msknum];
280 low_access_cnt = box_info[msknum][
i].last_access_cnt;
281 low_access_index =
i;
288 if (box_index == -1) {
292 if (boxes_active[msknum] <
BOX_MAX - 1) {
293 boxes_active[msknum]++;
294 box_index = boxes_active[msknum] - 1;
295 box_info[msknum][box_index].box_ptr =
296 (
unsigned short *) malloc(1024 *
sizeof (
short));
305 box_index = low_access_index;
314 box_info[msknum][box_index].box_num =
box_num;
315 box_info[msknum][box_index].last_access_cnt = access_cnt[msknum];
316 if (fseek(stream[msknum],
317 ptr_arr[msknum][
box_num] * 1024 *
sizeof (
short), SEEK_SET)
319 fprintf(
stderr,
"b128_msk_get: Failure on mask file record seek\n");
320 fprintf(
stderr,
" record # %d mask # %d\n",
321 ptr_arr[msknum][
box_num ], msknum);
322 fprintf(
stderr,
" Exiting\n");
325 if (fread(box_info[msknum][box_index].
box_ptr,
sizeof (
short),
326 1024, stream[msknum]) != 1024) {
327 fprintf(
stderr,
"b128_msk_get: Failure on mask record read\n");
328 fprintf(
stderr,
" record # %d mask # %d\n",
329 ptr_arr[msknum][
box_num ], msknum);
330 fprintf(
stderr,
" Exiting\n");
345 land_fl = ((*(box_info[msknum][ box_index ].box_ptr + box_wd) &
346 mask[ box_bit ]) == 0) ? 0 : 1;
347 last_box_index[msknum] = box_index;
348 last_box_num[msknum] =
box_num;
int b128_msk_get_(float *flat, float *flon, int *msknum)
void * allocateMemory(size_t numBytes, const char *name)
int b128_wd_bit(float lat_off, float lon_off, int *box_wd, int *box_bit)
int endianess(void)
determine endianess
int swapc_bytes(char *in, int nbyte, int ntime)
#define MAX_PIX_PER_SCENE
a context in which it is NOT documented to do so subscript which cannot be easily calculated when extracting TONS attitude data from the Terra L0 files Corrected several defects in extraction of entrained ephemeris and and as HDF file for both the L1A and Geolocation enabling retrieval of South Polar DEM data Resolved Bug by changing to opent the geolocation file only after a successful read of the L1A and also by checking for fatal errors from not restoring C5 and to report how many of those high resolution values were water in the new WaterPresent SDS Added valid_range attribute to Land SeaMask Changed to bilinearly interpolate the geoid_height to remove artifacts at one degree lines Made corrections to const qualification of pointers allowed by new version of M API library Removed casts that are no longer for same not the geoid Corrected off by one error in calculation of high resolution offsets Corrected parsing of maneuver list configuration parameter Corrected to set Height SDS to fill values when geolocation when for elevation and land water mask
int b128_msk_init(char *landfile, int msknum)
int b128_box_num(float lat, float lon, float *lat_off, float *lon_off)
PARAM_TYPE_NONE Default value No parameter is buried in the product name name_prefix is case insensitive string compared to the product name PARAM_TYPE_VIS_WAVE The visible wavelength bands from the sensor are buried in the product name The product name is compared by appending and name_suffix ie aph_412_giop where prod_ix will be set to PARAM_TYPE_IR_WAVE same search method as PARAM_TYPE_VIS_WAVE except only wavelength above are looped through but prod_ix is still based ie aph_2_giop for the second and prod_ix set to PARAM_TYPE_INT name_prefix is compared with the beginning of the product name If name_suffix is not empty the it must match the end of the product name The characters right after the prefix are read as an integer and prod_ix is set to that number strncpy(l2prod->name_prefix, "myprod", UNITLEN)
short ptr_arr_t[NITEMPTR]
int b128_msk_get(float lat, float lon, int msknum)
int b128_msk_init_(char *flandfile, int *msknum, int len)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")