OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
landtimebin.c
Go to the documentation of this file.
1 /*
2  Modification history:
3  Programmer Organization Date Description of change
4  -------------- ------------ -------- ---------------------
5  Joel Gales Futuretech 05/07/01 Original Development
6 
7  */
8 
9 
10 #include <stdio.h>
11 #include <math.h>
12 #include <string.h>
13 #include <time.h>
14 #include "hdf.h"
15 #include "mfhdf.h"
16 
17 int main(int argc, char *argv[]) {
18 
19  int32 i;
20  int32 j;
21  int32 k;
22  int32 sds_id;
23  int32 dims[8];
24  int32 rank;
25  int32 dtype;
26  int32 nattrs;
27 
28  static char buffer[2048];
29  static char attr_buf[2048];
30  char *data;
31  char *data_w;
32  char *str_ptr;
33  char *comma;
34  char *tmp_str;
35  int16 *eval_flds;
36  int16 * fileindex[3];
37  unsigned char *n_water_pix;
38 
39  int32 nfiles;
40  int32 scan;
41  int32 nscan;
42  int32 ncol;
43  int32 offset;
44  int32 *HDFfid_r;
45  int32 *sd_id_r;
46  int32 HDFfid_w;
47  int32 sd_id_w;
48  int32 sds_id_w;
49  int32 ndatasets;
50  int32 nglobal_attr;
51  int32 count;
52  int32 dim_id_r;
53  int32 dim_id_w;
54  int32 start[2] = {0, 0};
55  int32 edges[2] = {0, 0};
56  int32 mask_row_off = 0;
57  int32 mask_col_off = 0;
58  int32 sub_scan[2] = {0, 0};
59  int32 sub_pixl[2] = {0, 0};
60  int32 water_min = 1000;
61 
62  int16 fillvalue = -32767;
63  int16 water_val = -16384;
64  int16 eval_flds_flag=0;
65 
66  int16 f_index;
67  int16 f_ndvi;
68  int16 f_blue;
69 
70  int16 icol, irow;
71  float32 NIRreldiff, NIRness;
72  float64 val1, val2, sum, weigh;
73  float64 v1, v2;
74 
75 
76  int16 maxNDVI = 0;
77  int16 minBLUE = 1;
78 
79  int16 RADIUS = 2;
80  int16 NEVALFLD = 4;
81  int16 FILE_BSIZ = NEVALFLD * (2 * RADIUS + 1);
82  int16 FIELD_BSIZ = 2 * RADIUS + 1;
83 
84  int16 NDVI = 0 * FIELD_BSIZ;
85  int16 BLUE = 1 * FIELD_BSIZ;
86  int16 RED = 2 * FIELD_BSIZ;
87  int16 NIR = 3 * FIELD_BSIZ;
88 
89  int32 eval_flds_index[NEVALFLD];
90 
91  time_t tnow;
92  struct tm *tmnow;
93 
94  FILE *fp, *mask_4km;
95 
96  double R3(double x);
97 
99 
100  printf("landtimebin V2.31 (02/12/02)\n");
101 
102  if (argc == 1) {
103  printf("landtimebin <File containing list of input landbin files> <Output landbin file> <NDVI/BLUE/HYBRID>");
104  return 0;
105  }
106 
107  /* Determine number of input files */
108  /* ------------------------------- */
109  nfiles = 0;
110  fp = fopen(argv[1], "r");
111  if (fp == NULL) {
112  printf("Input listing file: \"%s\" not found.\n", argv[1]);
113  return -1;
114  }
115  while (fgets(buffer, 256, fp) != NULL) nfiles++;
116  fclose(fp);
117  printf("%d input files\n", nfiles);
118 
119 
120  /* Open input files and initialize HDF interface */
121  /* --------------------------------------------- */
122  HDFfid_r = (int32 *) calloc(nfiles, sizeof (int32));
123  sd_id_r = (int32 *) calloc(nfiles, sizeof (int32));
124 
125  fp = fopen(argv[1], "r");
126  for (i = 0; i < nfiles; i++) {
127  fgets(buffer, 256, fp);
128  buffer[strlen(buffer) - 1] = 0;
129  HDFfid_r[i] = Hopen(buffer, DFACC_READ, 0);
130  if (HDFfid_r[i] == -1) {
131  printf("Input file: \"%s\" not found.\n", buffer);
132  return -1;
133  }
134  Vstart(HDFfid_r[i]);
135  sd_id_r[i] = SDstart(buffer, DFACC_RDONLY);
136 
137  j = SDfindattr(sd_id_r[i], "Subset Scan Range");
138  if (j != -1) SDreadattr(sd_id_r[i], j, (VOIDP) & sub_scan);
139 
140  j = SDfindattr(sd_id_r[i], "Subset Pixel Range");
141  if (j != -1) SDreadattr(sd_id_r[i], j, (VOIDP) & sub_pixl);
142  }
143  fclose(fp);
144 
145 
146  /* Create output HDF file */
147  /* ---------------------- */
148  HDFfid_w = Hopen(argv[2], DFACC_CREATE, 0);
149  Vstart(HDFfid_w);
150  sd_id_w = SDstart(argv[2], DFACC_RDWR);
151 
152 
153  /* Set compositing flag */
154  /* -------------------- */
155  if (argc == 3 || (strcmp(argv[3], "NDVI") == 0))
156  eval_flds_flag = 0;
157  else if (strcmp(argv[3], "BLUE") == 0)
158  eval_flds_flag = 1;
159  else if (strcmp(argv[3], "HYBRID") == 0)
160  eval_flds_flag = 2;
161 
162  printf("eval_flds_flag: %d\n", eval_flds_flag);
163 
164 
165  /* Get # of scans and allocate dynamic arrays */
166  /* ------------------------------------------ */
167  sds_id = SDselect(sd_id_r[0], 0);
168  SDgetinfo(sds_id, buffer, &rank, dims, &dtype, &nattrs);
169  SDendaccess(sds_id);
170  nscan = dims[0];
171  ncol = dims[1];
172  data = (char *) calloc(nfiles * ncol * 2, sizeof (char));
173  data_w = (char *) calloc(ncol * 2, sizeof (char));
174  eval_flds = (int16 *) calloc(nfiles * ncol * FILE_BSIZ, sizeof (int16));
175 
176  n_water_pix = (unsigned char *) calloc(8640 * FIELD_BSIZ, sizeof (unsigned char));
177 
178  printf("%d\n", argc);
179  if (argc > 4) {
180  water_min = atol(argv[4]);
181  }
182  printf("water_min: %4d\n", water_min);
183 
184  fileindex[0] = (int16 *) calloc(ncol*FIELD_BSIZ, sizeof (int16));
185  fileindex[1] = (int16 *) calloc(ncol*FIELD_BSIZ, sizeof (int16));
186  fileindex[2] = (int16 *) calloc(ncol*FIELD_BSIZ, sizeof (int16));
187 
188 
189  /* Determine number of datasets in input files */
190  /* ------------------------------------------- */
191  SDfileinfo(sd_id_r[0], &ndatasets, &nglobal_attr);
192 
193 
194  /* For each dataset in input file, create corresponding dataset in output file */
195  /* --------------------------------------------------------------------------- */
196  for (j = 0; j < ndatasets; j++) {
197  sds_id = SDselect(sd_id_r[0], j);
198  SDgetinfo(sds_id, buffer, &rank, dims, &dtype, &nattrs);
199  sds_id_w = SDcreate(sd_id_w, buffer, dtype, rank, dims);
200 
201 
202  /* Find index number of compositing dataset */
203  /* ---------------------------------------- */
204  if (strcmp(buffer, "NDVI") == 0) eval_flds_index[0] = j;
205  if (strcmp(buffer, "refl_443") == 0) eval_flds_index[1] = j;
206  if (strcmp(buffer, "refl_670") == 0) eval_flds_index[2] = j;
207  if (strcmp(buffer, "refl_865") == 0) eval_flds_index[3] = j;
208  //if (strcmp(buffer, "input_file") == 0) input_file_index = j;
209 
210 
211  /* Copy dataset attributes */
212  /* ----------------------- */
213  for (i = 0; i < nattrs; i++) {
214  SDreadattr(sds_id, i, (VOIDP) attr_buf);
215  SDattrinfo(sds_id, i, buffer, &dtype, &count);
216  SDsetattr(sds_id_w, buffer, dtype, count, (VOIDP) attr_buf);
217  }
218 
219 
220  /* Set output file dim names */
221  /* ------------------------- */
222  for (i = 0; i < rank; i++) {
223  dim_id_r = SDgetdimid(sds_id, i);
224  dim_id_w = SDgetdimid(sds_id_w, i);
225  SDdiminfo(dim_id_r, buffer, &count, &dtype, &nattrs);
226  SDsetdimname(dim_id_w, buffer);
227  }
228 
229  SDendaccess(sds_id_w);
230  SDendaccess(sds_id);
231  }
232 
233 
234  /* Open 4km water pixel mask */
235  /* ------------------------- */
236  i = SDfindattr(sd_id_r[0], "Projection");
237  SDattrinfo(sd_id_r[0], i, buffer, &dtype, &count);
238  SDreadattr(sd_id_r[0], i, (VOIDP) attr_buf);
239 
240  tmp_str = getenv("OCDATAROOT");
241  if (tmp_str == 0x0) {
242  printf("Environment variable OCDATAROOT not defined.\n");
243  exit(1);
244  }
245  strcpy(buffer, tmp_str);
246 
247  if (strcmp(attr_buf, "Plate Carree") == 0) {
248  strcat(buffer, "/common/water_pix_4km_platte_carre.dat");
249  mask_4km = fopen(buffer, "rb");
250  if (mask_4km == 0x0) {
251  printf("Water mask file: %s not found.\n", buffer);
252  exit(1);
253  }
254  }
255 
256  if (strcmp(attr_buf, "Sinusoidal") == 0) {
257  strcat(buffer, "/common/water_pix_4km_sinusoidal.dat");
258  mask_4km = fopen(buffer, "rb");
259  if (mask_4km == 0x0) {
260  printf("Water mask file: %s not found.\n", buffer);
261  exit(1);
262  }
263  }
264 
265 
266  i = SDfindattr(sd_id_r[0], "Command line");
267  SDattrinfo(sd_id_r[0], i, buffer, &dtype, &count);
268  SDreadattr(sd_id_r[0], i, (VOIDP) attr_buf);
269  str_ptr = strstr(attr_buf, "-box");
270  if (str_ptr != 0x0) {
271  str_ptr += 5;
272  comma = strstr(str_ptr, ",");
273  *comma = 0;
274  mask_col_off = atoi(str_ptr);
275  str_ptr = comma + 1;
276  comma = strstr(str_ptr, ",");
277  *comma = 0;
278  mask_row_off = atoi(str_ptr);
279  }
280 
281 
282  /* For each scan ... */
283  /* ----------------- */
284  offset = RADIUS;
285  edges[1] = ncol;
286 
287  for (scan = 0; scan < nscan; scan++) {
288 
289  if ((scan % 200) == 0) {
290  time(&tnow);
291  tmnow = localtime(&tnow);
292  printf("Scan:%6d %s", scan, asctime(tmnow));
293  }
294 
295  /* Read compositing dataset from each input file */
296  /* --------------------------------------------- */
297  if (scan == 0) {
298  start[0] = scan;
299  edges[0] = RADIUS + 1;
300  } else if (scan < nscan - 2) {
301  start[0] = scan + RADIUS;
302  edges[0] = 1;
303  } else {
304  goto DATA_WRITE;
305  }
306 
307  for (i = 0; i < nfiles; i++) {
308  for (j = 0; j < NEVALFLD; j++) {
309  sds_id = SDselect(sd_id_r[i], eval_flds_index[j]);
310  SDgetinfo(sds_id, buffer, &rank, dims, &dtype, &nattrs);
311 
312  SDreaddata(sds_id, start, NULL, edges,
313  (VOIDP) & eval_flds[(FILE_BSIZ * i + FIELD_BSIZ * j + offset) * ncol]);
314  }
315  } /* file loop */
316 
317 
318 
319  /* Read 4km land/water/mixed mask */
320  /* ------------------------------ */
321  fseek(mask_4km, (mask_row_off + start[0]) * 8640, SEEK_SET);
322  fread(&n_water_pix[8640 * offset], edges[0] * 8640, 1, mask_4km);
323 
324 
325  /* Determine file index for compositing */
326  /* ------------------------------------ */
327  for (k = offset; k < FIELD_BSIZ; k++) {
328  for (j = 0; j < ncol; j++) {
329  fileindex[maxNDVI][ncol * k + j] = 0;
330  fileindex[minBLUE][ncol * k + j] = 0;
331  }
332  }
333 
334 
335  /* Max NDVI fileindex */
336  /* ------------------ */
337  for (k = offset; k < FIELD_BSIZ; k++) {
338  for (i = 1; i < nfiles; i++) {
339  for (j = 0; j < ncol; j++) {
340  f_index = fileindex[maxNDVI][ncol * k + j];
341  if (eval_flds[ncol * (FILE_BSIZ * i + NDVI + k) + j] >
342  eval_flds[ncol * (FILE_BSIZ * f_index + NDVI + k) + j])
343  fileindex[maxNDVI][ncol * k + j] = i;
344  }
345  }
346  }
347 
348  /* Min Blue fileindex */
349  /* ------------------ */
350  for (k = offset; k < FIELD_BSIZ; k++) {
351  for (i = 1; i < nfiles; i++) {
352  for (j = 0; j < ncol; j++) {
353  f_index = fileindex[minBLUE][ncol * k + j];
354 
355  if (eval_flds[ncol * (FILE_BSIZ * f_index + BLUE + k) + j] < 0 &&
356  eval_flds[ncol * (FILE_BSIZ * i + BLUE + k) + j] >= 0)
357  fileindex[minBLUE][ncol * k + j] = i;
358 
359  if (eval_flds[ncol * (FILE_BSIZ * f_index + BLUE + k) + j] >= 0 &&
360  eval_flds[ncol * (FILE_BSIZ * i + BLUE + k) + j] >= 0 &&
361  eval_flds[ncol * (FILE_BSIZ * i + RED + k) + j] >= 0 &&
362  (eval_flds[ncol * (FILE_BSIZ * i + BLUE + k) + j] <
363  eval_flds[ncol * (FILE_BSIZ * f_index + BLUE + k) + j]))
364  fileindex[minBLUE][ncol * k + j] = i;
365 
366  if (eval_flds[ncol * (FILE_BSIZ * f_index + RED + k) + j] < 0 &&
367  eval_flds[ncol * (FILE_BSIZ * i + RED + k) + j] < 0 &&
368  (eval_flds[ncol * (FILE_BSIZ * i + RED + k) + j] >
369  eval_flds[ncol * (FILE_BSIZ * f_index + RED + k) + j]))
370  fileindex[minBLUE][ncol * k + j] = i;
371 
372  }
373  }
374  }
375 
376 
377  /* Fill Value Handling */
378  /* ------------------- */
379  for (k = offset; k < FIELD_BSIZ; k++) {
380  for (j = 0; j < ncol; j++) {
381 
382  f_index = fileindex[maxNDVI][ncol * k + j];
383  if (eval_flds[ncol * (FILE_BSIZ * f_index + NDVI + k) + j] == -32767)
384  fileindex[maxNDVI][ncol * k + j] = fillvalue;
385 
386  f_index = fileindex[minBLUE][ncol * k + j];
387  if (eval_flds[ncol * (FILE_BSIZ * f_index + BLUE + k) + j] < 0)
388  fileindex[minBLUE][ncol * k + j] = fillvalue;
389  }
390  }
391 
392 
393 
394  if (eval_flds_flag != 2) goto DATA_WRITE;
395 
396 
397  /* HYBRID */
398  /* ------ */
399  for (j = 0; j < ncol; j++) {
400 
401  f_ndvi = fileindex[maxNDVI][ncol * RADIUS + j];
402  f_blue = fileindex[minBLUE][ncol * RADIUS + j];
403 
404  fileindex[2][ncol * RADIUS + j] = f_blue;
405 
406  if (f_blue != fillvalue &&
407  f_ndvi != fillvalue &&
408  n_water_pix[(8640 * offset)+(mask_col_off + j)] == 0 &&
409  eval_flds[ncol * (FILE_BSIZ * f_ndvi + NIR + RADIUS) + j] != fillvalue &&
410  eval_flds[ncol * (FILE_BSIZ * f_blue + NIR + RADIUS) + j] != fillvalue &&
411  eval_flds[ncol * (FILE_BSIZ * f_ndvi + BLUE + RADIUS) + j] != fillvalue) {
412 
413  if (eval_flds[ncol * (FILE_BSIZ * f_blue + NIR + RADIUS) + j] != 0) {
414  NIRreldiff = ((eval_flds[ncol * (FILE_BSIZ * f_ndvi + NIR + RADIUS) + j] -
415  eval_flds[ncol * (FILE_BSIZ * f_blue + NIR + RADIUS) + j]) /
416  abs(eval_flds[ncol * (FILE_BSIZ * f_blue + NIR + RADIUS) + j]));
417  } else {
418  NIRreldiff = 1.0;
419  }
420 
421  if (eval_flds[ncol * (FILE_BSIZ * f_blue + BLUE + RADIUS) + j] != 0 &&
422  eval_flds[ncol * (FILE_BSIZ * f_ndvi + BLUE + RADIUS) + j] != 0) {
423 
424  if (NIRreldiff > 0.10) {
425  val1 = 0;
426  val2 = 0;
427  sum = 0;
428 
429  for (irow = 0; irow < 2 * RADIUS + 1; irow++) {
430 
431  for (icol = j - RADIUS; icol <= j + RADIUS; icol++) {
432  if (icol < 0 || icol > ncol) break;
433 
434  weigh = R3(fabs(0.5 * (irow - RADIUS))) * R3(fabs(0.5 * (icol - j)));
435  sum += weigh;
436 
437  f_ndvi = fileindex[maxNDVI][ncol * irow + icol];
438  f_blue = fileindex[minBLUE][ncol * irow + icol];
439 
440  if (f_ndvi != fillvalue)
441  v1 = weigh * eval_flds[ncol * (FILE_BSIZ * f_ndvi + NIR + irow) + icol];
442  else
443  v1 = 0.0;
444 
445  if (f_blue != fillvalue)
446  v2 = weigh * eval_flds[ncol * (FILE_BSIZ * f_blue + NIR + irow) + icol];
447  else
448  v2 = 0.0;
449 
450  if (v1 < 0.0) v1 = 0.0;
451  if (v2 < 0.0) v2 = 0.0;
452 
453  val1 += v1;
454  val2 += v2;
455 
456  } /* icol loop */
457  } /* irow loop */
458 
459  if (sum > 0) {
460  val1 /= sum;
461  val2 /= sum;
462  }
463 
464 
465  f_ndvi = fileindex[maxNDVI][ncol * RADIUS + j];
466  f_blue = fileindex[minBLUE][ncol * RADIUS + j];
467 
468  NIRness = (eval_flds[ncol * (FILE_BSIZ * f_ndvi + NIR + RADIUS) + j] -
469  eval_flds[ncol * (FILE_BSIZ * f_ndvi + BLUE + RADIUS) + j]) /
470  abs(eval_flds[ncol * (FILE_BSIZ * f_ndvi + BLUE + RADIUS) + j]);
471 
472  if (fabs(NIRness) > 0.2 &&
473  eval_flds[ncol * (FILE_BSIZ * f_ndvi + BLUE + RADIUS) + j] < 2500 &&
474  fabs(val1 - eval_flds[ncol * (FILE_BSIZ * f_ndvi + NIR + RADIUS) + j]) <=
475  fabs(val2 - eval_flds[ncol * (FILE_BSIZ * f_blue + NIR + RADIUS) + j]) &&
476 
477  (eval_flds[ncol * (FILE_BSIZ * f_ndvi + NDVI + RADIUS) + j] < 3000 ||
478  eval_flds[ncol * (FILE_BSIZ * f_ndvi + BLUE + RADIUS) + j] < 500 ||
479  eval_flds[ncol * (FILE_BSIZ * f_blue + NIR + RADIUS) + j] == 0)) {
480  fileindex[2][ncol * RADIUS + j] = f_ndvi;
481  }
482 
483  } /* (NIRreldiff > 0.10) */
484  }
485  }
486 
487  } /* HYBRID col loop */
488 
489 
490 
491  DATA_WRITE:
492 
493  start[0] = scan;
494  edges[0] = 1;
495 
496  /* For each dataset ... */
497  /* -------------------- */
498  for (j = 0; j < ndatasets; j++) {
499  sds_id = SDselect(sd_id_r[0], j);
500  SDgetinfo(sds_id, buffer, &rank, dims, &dtype, &nattrs);
501  SDendaccess(sds_id);
502 
503  if (strcmp(buffer, "input_file") == 0) {
504  memcpy(&data_w[0], &fileindex[eval_flds_flag][ncol * RADIUS], 2 * ncol);
505  } else {
506  /* For each file read dataset */
507  /* -------------------------- */
508  for (i = 0; i < nfiles; i++) {
509  sds_id = SDselect(sd_id_r[i], j);
510  edges[1] = ncol;
511  SDreaddata(sds_id, start, NULL, edges,
512  (VOIDP) & data[2 * i * ncol]);
513  SDendaccess(sds_id);
514  }
515 
516  /* Store compositing data in write buffer */
517  /* -------------------------------------- */
518  for (i = 0; i < ncol; i++) {
519  if (fileindex[eval_flds_flag][ncol * RADIUS + i] == fillvalue) {
520  memcpy(&data_w[2 * i], &fillvalue, 2);
521  }
522  /* mask water and mixed with water val = -16384 (JMG) */
523 
524  else if (n_water_pix[(8640 * offset)+(mask_col_off + i)] >= water_min) {
525  memcpy(&data_w[2 * i], &water_val, 2);
526  } else {
527  memcpy(&data_w[2 * i], &data[2 * (fileindex[eval_flds_flag][ncol * RADIUS + i] * ncol + i)], 2);
528  }
529  }
530  } /* if "input_file" */
531 
532  /* Write to output file */
533  sds_id_w = SDselect(sd_id_w, j);
534  SDwritedata(sds_id_w, start, NULL, edges, (VOIDP) data_w);
535  SDendaccess(sds_id_w);
536  } /* dataset loop */
537 
538 
539  /* Rotate Arrays */
540  /* ------------- */
541  for (k = 1; k < FIELD_BSIZ; k++) {
542  for (i = 0; i < nfiles; i++) {
543  memcpy(&eval_flds[ncol * (FILE_BSIZ * i + NDVI + (k - 1))],
544  &eval_flds[ncol * (FILE_BSIZ * i + NDVI + k)],
545  ncol * sizeof (int16));
546 
547  memcpy(&eval_flds[ncol * (FILE_BSIZ * i + BLUE + (k - 1))],
548  &eval_flds[ncol * (FILE_BSIZ * i + BLUE + k)],
549  ncol * sizeof (int16));
550 
551  memcpy(&eval_flds[ncol * (FILE_BSIZ * i + NIR + (k - 1))],
552  &eval_flds[ncol * (FILE_BSIZ * i + NIR + k)],
553  ncol * sizeof (int16));
554  }
555 
556  memcpy(&fileindex[maxNDVI][ncol * (k - 1)],
557  &fileindex[maxNDVI][ncol * k],
558  ncol * sizeof (int16));
559 
560  memcpy(&fileindex[minBLUE][ncol * (k - 1)],
561  &fileindex[minBLUE][ncol * k],
562  ncol * sizeof (int16));
563 
564  memcpy(&n_water_pix[8640 * (k - 1)],
565  &n_water_pix[8640 * k],
566  8640 * sizeof (int16));
567  }
568 
569  offset = 2 * RADIUS;
570 
571 
572  } /* scan loop */
573 
574 
575  /* Write Global Attributes */
576  /* ----------------------- */
577  i = SDfindattr(sd_id_r[0], "Projection");
578  SDattrinfo(sd_id_r[0], i, buffer, &dtype, &count);
579  SDreadattr(sd_id_r[0], i, (VOIDP) attr_buf);
580  SDsetattr(sd_id_w, buffer, dtype, count, (VOIDP) attr_buf);
581 
582  i = SDfindattr(sd_id_r[0], "Pixel size (meters)");
583  SDattrinfo(sd_id_r[0], i, buffer, &dtype, &count);
584  SDreadattr(sd_id_r[0], i, (VOIDP) attr_buf);
585  SDsetattr(sd_id_w, buffer, dtype, count, (VOIDP) attr_buf);
586 
587  i = SDfindattr(sd_id_r[0], "Compositing criterion");
588  SDattrinfo(sd_id_r[0], i, buffer, &dtype, &count);
589  SDreadattr(sd_id_r[0], i, (VOIDP) attr_buf);
590  SDsetattr(sd_id_w, buffer, dtype, count, (VOIDP) attr_buf);
591 
592  if ((sub_scan[0] != 0) || (sub_scan[1] != 0) ||
593  (sub_pixl[0] != 0) || (sub_pixl[1] != 0)) {
594  SDsetattr(sd_id_w, "Subset Scan Range", DFNT_INT32, 2, sub_scan);
595  SDsetattr(sd_id_w, "Subset Pixel Range", DFNT_INT32, 2, &sub_pixl);
596  }
597 
598  fp = fopen(argv[1], "r");
599  attr_buf[0] = 0;
600  while (fgets(buffer, 256, fp) != NULL) {
601  buffer[strlen(buffer) - 1] = 0;
602  strcat(buffer, "\n,");
603  strcat(attr_buf, buffer);
604  }
605  fclose(fp);
606  attr_buf[strlen(attr_buf) - 1] = 0;
607  SDsetattr(sd_id_w, "File list", DFNT_CHAR8, (int) strlen(attr_buf) + 1, attr_buf);
608 
609 
610 
611  /* Close input files */
612  /* ----------------- */
613  for (i = 0; i < nfiles; i++) {
614  SDend(sd_id_r[i]);
615  Hclose(HDFfid_r[i]);
616  Vend(HDFfid_r[i]);
617  }
618  free(HDFfid_r);
619  free(sd_id_r);
620  free(data);
621  free(data_w);
622  free(eval_flds);
623  free(fileindex[0]);
624  free(fileindex[1]);
625  free(fileindex[2]);
626  free(n_water_pix);
627 
628 
629  /* Close output file */
630  /* ----------------- */
631  SDend(sd_id_w);
632  Hclose(HDFfid_w);
633  Vend(HDFfid_w);
634 
635  fclose(mask_4km);
636 
637  return 0;
638 }
639 
640 double R3(double x) {
641  if (x < 0 || x >= 2)
642  return 0;
643  else if (x <= 1) /* 0 <= x <= 1 */
644  return 2 / 3. + x * x * x / 2. - x * x;
645  else /* 1 <= x <= 2 */
646  return (2 - x) * (2 - x) * (2 - x) / 6;
647 }
648 
649 
#define NDVI
Definition: maplists.h:21
integer, parameter int16
Definition: cubeio.f90:3
int j
Definition: decode_rs.h:73
double R3(double x)
Definition: landtimebin.c:640
@ NIR
Definition: hybrid.c:24
#define NULL
Definition: decode_rs.h:63
MOD_PR01 Production producing one five minute granule of output data in each run It can be configured to produce as many as three five minute granules per run Each execution with one construction record and one date file for each dataset In normal these are created by which splits them out of the hour datasets For LANCE they are created by which merges all session MODIS L0 datasets overlapping the requested time and extracts from the merged data those packets which fall within that time period Each scan of data is stored in the L1A granule that covers the start time of that scan
Definition: MOD_PR01_pr.txt:19
float tm[MODELMAX]
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
int32 nscan
Definition: l1_czcs_hdf.c:19
int setlinebuf(FILE *stream)
@ RED
Definition: hybrid.c:24
@ maxNDVI
Definition: hybrid.c:20
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
@ BLUE
Definition: hybrid.c:24
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame the required RAM for each execution is MB on the DEC ALPHA and MB on the SGI Octane v2
Definition: HISTORY.txt:728
#define RADIUS
Definition: hybrid.c:14
dtype
Definition: DDataset.hpp:31
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that and then aggregated up to Resolved feature request Bug by adding three new int8 SDSs for each high resolution offsets between the high resolution geolocation and a bi linear interpolation extrapolation of the positions This can be used to reconstruct the high resolution geolocation Resolved Bug by delaying cumulation of gflags until after validation of derived products Resolved Bug by setting Latitude and Longitude to the correct fill resolving to support Near Real Time because they may be unnecessary if use of entrained ephemeris and attitude data is turned resolving bug report Corrected to filter out Aqua attitude records with missing status helping resolve bug MOD_PR03 will still correctly write scan and pixel data that does not depend upon the start time
Definition: HISTORY.txt:248
#define fabs(a)
Definition: misc.h:93
Extra metadata that will be written to the HDF4 file l2prod rank
l2prod offset
#define abs(a)
Definition: misc.h:90
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int k
Definition: decode_rs.h:73
int main(int argc, char *argv[])
Definition: landtimebin.c:17
int count
Definition: decode_rs.h:79