OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1_meris_N1.c
Go to the documentation of this file.
1 
8 /* ============================================================================ */
9 /* module l1_meris_N1.c - functions to read MERIS Reduced RES L2 for MSL12 */
10 /* NOTE!! THIS IS A TEMPORARY READER FOR L2 FILES, INTO L1 SEADAS RECORD */
11 /* Written By: Paul E. Lyon NRL, Oct. 2006. */
12 /* */
13 /* ============================================================================ */
14 
15 #include "l1_meris_N1.h"
16 #include "epr_api.h"
17 #include "epr_field.h"
18 #include <math.h>
19 #include "smile.h"
20 #include <libnav.h>
21 
22 #include "l1.h"
23 
24 #include <stdbool.h>
25 
26 #define MERIS_NBANDS 15
27 
28 #define MERIS_BANDINFO_FILENAME "band_info_meris.txt"
29 
30 #define MERIS_WAVELENGTH_FR_FILENAME "central_wavelen_fr.txt"
31 #define MERIS_WAVELENGTH_RR_FILENAME "central_wavelen_rr.txt"
32 #define MERIS_SUN_FLUX_FR_FILENAME "sun_spectral_flux_fr.txt"
33 #define MERIS_SUN_FLUX_RR_FILENAME "sun_spectral_flux_rr.txt"
34 
35 // # of detectors in a full resolution scan line
36 #define MERIS_FR_DETECTORS 3700
37 // # of detectors in a full resolution scan line
38 #define MERIS_RR_DETECTORS 925
39 
40 // max line length in a config table file
41 #define MERIS_LINE_MAX 1024
42 
43 /* ------------------------------------------------------------------------ */
44 /* These L1 flag values were derrived from the MERIS specification */
45 /* */
46 /* http://earth.esa.int/pub/ESA_DOC/ENVISAT/Vol11_Meris_5b.pdf */
47 /* page 64, Table 11.4.1.7.4.2-3 MER_RR__1P - Quality Flag Coding */
48 /* */
49 /* dshea */
50 /* ------------------------------------------------------------------------ */
51 #define MERIS_L1FLAG_COSMETIC 0x01
52 #define MERIS_L1FLAG_DUPLICATED 0x02
53 #define MERIS_L1FLAG_GLINT 0x04
54 #define MERIS_L1FLAG_SUSPECT 0x08
55 #define MERIS_L1FLAG_LAND 0x10
56 #define MERIS_L1FLAG_BRIGHT 0x20
57 #define MERIS_L1FLAG_COASTLINE 0x40
58 #define MERIS_L1FLAG_INVALID 0x80
59 
60 /* ------------------------------------------------------------------------ */
61 /* These L2 flag values were derrived from the MERIS specification */
62 /* */
63 /* http://earth.esa.int/pub/ESA_DOC/ENVISAT/Vol11_Meris_5b.pdf */
64 /* page 105, Table 11.5.1.7.4.8-2 Description of the Flag Coding */
65 /* */
66 /* dshea */
67 /* ------------------------------------------------------------------------ */
68 #define MERIS_L2FLAG_WHITE_SCATTER 0x000001
69 #define MERIS_L2FLAG_PRESSURE_CONF 0x000002
70 #define MERIS_L2FLAG_HIGH_GLINT 0x000004
71 #define MERIS_L2FLAG_DDV 0x000008
72 #define MERIS_L2FLAG_MEDIUM_GLINT 0x000010
73 #define MERIS_L2FLAG_ICE_HAZE 0x000020
74 #define MERIS_L2FLAG_CASE2_Y 0x000040
75 #define MERIS_L2FLAG_CASE2_ANOM 0x000080
76 #define MERIS_L2FLAG_CASE2_S 0x000100
77 #define MERIS_L2FLAG_ABSOA_DUST 0x000200
78 #define MERIS_L2FLAG_OOADB 0x000400
79 #define MERIS_L2FLAG_SUSPECT 0x000800
80 #define MERIS_L2FLAG_COSMETIC 0x001000
81 #define MERIS_L2FLAG_COASTLINE 0x002000
82 #define MERIS_L2FLAG_PCD_19 0x004000
83 #define MERIS_L2FLAG_PCD_18 0x008000
84 #define MERIS_L2FLAG_PCD_17 0x010000
85 #define MERIS_L2FLAG_PCD_16 0x020000
86 #define MERIS_L2FLAG_PCD_15 0x040000
87 #define MERIS_L2FLAG_PCD_14 0x080000
88 #define MERIS_L2FLAG_PCD_1_13 0x100000
89 #define MERIS_L2FLAG_WATER 0x200000
90 #define MERIS_L2FLAG_CLOUD 0x400000
91 #define MERIS_L2FLAG_LAND 0x800000
92 
93 static EPR_SProductId *fileID = NULL;
94 static int spix = 0;
95 static int file_npix;
96 static double fileStartTime; // first scan time in unix seconds
97 static double time_interval; // scan interval in seconds
98 
99 static int fullResolution = 0;
100 static int numDetectors;
101 static float *detectorWL;
102 static float *detectorE0;
103 
111 int
112 openl1_meris_N1(filehandle * file) {
113  const char *fltime;
114  const char *fname;
115  char monthstr[10];
116  static char months_list[12][4] ={"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL",
117  "AUG", "SEP", "OCT", "NOV", "DEC"};
118  unsigned int source_w, source_h;
119  int minute, hour, month, i;
120  float fsec;
121  const EPR_SRecord *record;
122  const EPR_SField *field;
123  EPR_SBandId *band_id = NULL;
124  char *sph_names[] ={"NUM_BANDS", "LINE_TIME_INTERVAL", "NUM_SLICES"};
125  int nf = 3;
126 
127  // Initialize the API
129 
130  // Open the N1 input file
131 
132  fileID = epr_open_product(file->name);
133  if (fileID == NULL) {
134  fprintf(stderr, "-E- %s line %d: epr_open_product(%s) failed.\n",
135  __FILE__, __LINE__, file->name);
136  return (1);
137  }
138 
139  band_id = epr_get_band_id(fileID, "l1_flags");
140  if (band_id == NULL) {
141  fprintf(stderr, "-E- %s line %d - Can not find \"l1_flags\" in Meris N1 file\n",
142  __FILE__, __LINE__);
143  return (1);
144  }
145 
146  // Get pixel and scan dimensions
147 
148  source_h = fileID->scene_height;
149  source_w = fileID->scene_width;
150  file_npix = source_w;
151  if (want_verbose) {
152  printf("MERIS Level1B Npix :%u Nscans:%u\n", source_w, source_h);
153  } // want_verbose
154 
155  // get specific product header (SPH)
156 
157  record = epr_get_sph(fileID);
158  if (record == NULL) {
159  fprintf(stderr, "-E- %s line %d: epr_get_sph(fileID) failed.\n",
160  __FILE__, __LINE__);
161  return (1);
162  }
163 
164 
165  // get first scan time
166 
167  field = epr_get_field(record, "FIRST_LINE_TIME");
168  if (field == NULL) {
169  fprintf(stderr,
170  "-E- %s line %d: epr_get_field(record,FIRST_LINE_TIME) failed.\n",
171  __FILE__, __LINE__);
172  return (1);
173  }
174 
175  int year, day;
176  fltime = epr_get_field_elem_as_str(field);
177  sscanf(fltime, "%02d-%3s-%04d %02d:%02d:%f", &day, monthstr, &year,
178  &hour, &minute, &fsec);
179  monthstr[4] = '\0';
180  month = 1;
181  for (i = 0; i < 12; i++)
182  if (strncmp(monthstr, months_list[i], 3) == 0)
183  month = i + 1;
184  fileStartTime = ymds2unix(year, month, day, hour * 3600.0 + minute * 60.0 + fsec);
185 
186  field = epr_get_field(record, "LINE_TIME_INTERVAL");
187  if (field == NULL) {
188  fprintf(stderr,
189  "-E- %s line %d: epr_get_field(record,FIRST_LINE_TIME) failed.\n",
190  __FILE__, __LINE__);
191  return (1);
192  }
193  time_interval = (double) epr_get_field_elem_as_uint(field, 0); // microseconds;
194  time_interval /= 1e6; // change to seconds
195 
196  if (want_verbose)
197  printf("MERIS time interval %lf\n", time_interval);
198 
199  // dump a few more items for infomational purposes
200 
201  for (i = 0; i < nf; i++) {
202  field = epr_get_field(record, sph_names[i]);
203  if (field == NULL) {
204  fprintf(stderr,
205  "-E- %s line %d: epr_get_field(record,%s) failed.\n",
206  __FILE__, __LINE__, sph_names[i]);
207  return (1);
208  }
209  if (want_verbose)
210  printf("\t%s = %d\n", sph_names[i],
211  (int) epr_get_field_elem_as_uint(field, 0));
212  }
213 
214  // get the START_PIXEL and END_PIXEL that were injected into the MPH
215  // by the extractor. START_PIXEL and END_PIXEL are 1 based. The epr
216  // api reverses the pixels on a line, so spix = source_w - epix.
217  record = epr_get_mph(fileID);
218  if (record) {
219  field = epr_get_field(record, "PRODUCT");
220  if (field) {
221  fname = epr_get_field_elem_as_str(field);
222  if (strncmp(fname, "MER_RR", 6) == 0) {
223  fullResolution = 0;
225  strcpy(file->spatialResolution, "1.2 km");
226  } else {
227  fullResolution = 1;
229  strcpy(file->spatialResolution, "300 m");
230  }
231  } else {
232  printf("-E- PRODUCT field not found in the MPH header.");
233  exit(1);
234  }
235 
236  field = epr_get_field(record, "END_PIXEL");
237  if (field) {
238  int tmp_epix = epr_get_field_elem_as_uint(field, 0);
239  field = epr_get_field(record, "START_PIXEL");
240  if (field) {
241  int tmp_spix = epr_get_field_elem_as_uint(field, 0);
242  if ((tmp_spix < source_w) && (tmp_spix < tmp_epix)) {
243  spix = source_w - tmp_epix;
244  source_w = tmp_epix - tmp_spix + 1; // spix and epix are inclusive
245  if (want_verbose)
246  printf("OBPG Extract - spix=%d, npix=%d\n",
247  spix + 1, (int) source_w);
248  } // spix, epix reasonable
249  } // spix good
250  } // epix good
251  } else { // found the MPH
252  printf("-E- MPH header not found.");
253  exit(1);
254  }
255 
256  // define number of input products
257 
258  file->nbands = MERIS_NBANDS;
259  file->npix = (int) source_w;
260  file->nscan = (int) source_h;
261 
262  return (LIFE_IS_GOOD);
263 }
264 
275 int readl1_meris_N1(filehandle *file, int32_t scan, l1str *l1rec) {
276  static int firstCall = 1;
277  int err_code;
278 
279  static char *names[] = {
280  "radiance_1", "radiance_2", "radiance_3", "radiance_4", // 412.7, 442.6, 489.9, 509.8
281  "radiance_5", "radiance_6", "radiance_7", "radiance_8", // 559.7, 619.6, 664.5, 680.8
282  "radiance_9", "radiance_10", "radiance_11", "radiance_12", // 708.3, 753.4, 761.5, 778.4
283  "radiance_13", "radiance_14", "radiance_15" // 864.9, 884.9, 900.0
284  };
285  int32_t npix;
286  int32_t nbands;
287  int32_t ip, ib, ipb;
288  EPR_SBandId *band_id = NULL;
289  EPR_SRaster *temp_raster;
290  epr_uint flag;
291  static char *invalid_flag;
292  static char *land_flag;
293 
294 
295  if (firstCall) {
296  firstCall = 0;
297  invalid_flag = malloc(sizeof (char) * file->npix);
298  land_flag = malloc(sizeof (char) * file->npix);
299 
300  if (l1_input->rad_opt != 0) {
301  // setup the smile correction
302  char *tmp_str;
303  char line[MERIS_LINE_MAX];
304  char path[FILENAME_MAX] = "";
305  char filename[FILENAME_MAX] = "";
306  FILE *fp = NULL;
307  int count;
308  int dummy;
309  int detector;
310  float *floatp;
311 
312  if ((tmp_str = getenv("OCDATAROOT")) == NULL) {
313  printf("OCDATAROOT environment variable is not defined.\n");
314  exit(1);
315  }
316 
317  strcpy(path, tmp_str);
318  strcat(path, "/");
319  strcat(path, sensorId2SensorDir(l1rec->l1file->sensorID));
320  strcat(path, "/cal/");
321 
322  /*-------------------------------------------------------------*/
323  detectorWL = (float*) malloc(sizeof (float)*MERIS_NBANDS * numDetectors);
324  if (!detectorWL) {
325  printf("-E- %s line %d : error allocating memory for detectorWL.\n",
326  __FILE__, __LINE__);
327  exit(1);
328  }
329 
330  /*-------------------------------------------------------------*/
331  // read the central wavelength table
332  strcpy(filename, path);
333  if (fullResolution)
335  else
337  if ((fp = fopen(filename, "r")) == NULL) {
338  fprintf(stderr,
339  "-E- %s line %d: unable to open %s for reading\n", __FILE__, __LINE__, filename);
340  exit(1);
341  }
342 
343  // discard the first line of column labels
344  fgets(line, MERIS_LINE_MAX, fp);
345 
346  floatp = detectorWL;
347  for (detector = 0; detector < numDetectors; detector++) {
348  if (!fgets(line, MERIS_LINE_MAX, fp)) {
349  fprintf(stderr,
350  "-E- %s line %d: unable to read detector %d from file %s\n", __FILE__, __LINE__, detector, filename);
351  exit(1);
352  }
353 
354  /* I really should read all of the bands defined by MERIS_NBANDS, but I am just reading
355  15 bands for now. dshea */
356  count = sscanf(line, "%d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", &dummy, floatp, floatp + 1,
357  floatp + 2, floatp + 3, floatp + 4, floatp + 5, floatp + 6, floatp + 7, floatp + 8, floatp + 9,
358  floatp + 10, floatp + 11, floatp + 12, floatp + 13, floatp + 14);
359  if (count != 16) {
360  fprintf(stderr,
361  "-E- %s line %d: unable to read whole detector %d line from file %s, count = %d\n",
362  __FILE__, __LINE__, detector, filename, count);
363  exit(1);
364  }
365 
366  floatp += MERIS_NBANDS;
367  } // for detector
368  fclose(fp);
369 
370 
371  /*-------------------------------------------------------------*/
372  // read solar flux table
373  detectorE0 = (float*) malloc(sizeof (float)*MERIS_NBANDS * numDetectors);
374  if (!detectorE0) {
375  printf("-E- %s line %d : error allocating memory for detectorE0.\n",
376  __FILE__, __LINE__);
377  exit(1);
378  }
379 
380  strcpy(filename, path);
381  if (fullResolution)
383  else
385  if ((fp = fopen(filename, "r")) == NULL) {
386  fprintf(stderr,
387  "-E- %s line %d: unable to open %s for reading\n", __FILE__, __LINE__, filename);
388  exit(1);
389  }
390 
391  // discard the first line of column labels
392  fgets(line, MERIS_LINE_MAX, fp);
393 
394  floatp = detectorE0;
395  for (detector = 0; detector < numDetectors; detector++) {
396  if (!fgets(line, MERIS_LINE_MAX, fp)) {
397  fprintf(stderr,
398  "-E- %s line %d: unable to read detector %d from file %s\n", __FILE__, __LINE__, detector, filename);
399  exit(1);
400  }
401 
402  /* I really should read all of the bands defined by MERIS_NBANDS, but I am just reading
403  15 bands for now. dshea */
404  count = sscanf(line, "%d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f", &dummy, floatp, floatp + 1,
405  floatp + 2, floatp + 3, floatp + 4, floatp + 5, floatp + 6, floatp + 7, floatp + 8, floatp + 9,
406  floatp + 10, floatp + 11, floatp + 12, floatp + 13, floatp + 14);
407  if (count != 16) {
408  fprintf(stderr,
409  "-E- %s line %d: unable to read whole detector %d line from file %s, count = %d\n",
410  __FILE__, __LINE__, detector, filename, count);
411  exit(1);
412  }
413 
414  floatp += MERIS_NBANDS;
415  } // for detector
416  fclose(fp);
417 
418  strcpy(filename, path);
420  smile_init(MERIS_NBANDS, numDetectors, filename, detectorWL, detectorE0);
421 
422  } // if input->rad_opt
423 
424  } // first call
425 
426  nbands = file->nbands;
427  npix = file->npix;
428 
429  l1rec->scantime = fileStartTime + time_interval*scan;
430  int16_t syear, sday;
431  double secs;
432  unix2yds(l1rec->scantime, &syear, &sday, &secs);
433 
434  int32_t yr = syear;
435  int32_t dy = sday;
436  int32_t msec = (int32_t) (secs * 1000.0);
437  double esdist = esdist_(&yr, &dy, &msec);
438 
439  l1rec->fsol = pow(1.0 / esdist, 2);
440  // read L1 flags and set invalid_flag if suspect or invalid set
441 
442  band_id = epr_get_band_id(fileID, "l1_flags");
443  if (band_id == NULL) {
444  printf("-E- %s line %d: Error finding band_id:l1_flags\n", __FILE__,
445  __LINE__);
446  return (1);
447  }
448  temp_raster = epr_create_compatible_raster(band_id, file_npix, 1, 1, 1);
449  if (temp_raster == NULL) {
450  printf("-E- %s line %d: Error allocating raster space.\n", __FILE__,
451  __LINE__);
452  return (1);
453  }
454  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
455  for (ip = 0; ip < npix; ip++) {
456  flag = epr_get_pixel_as_uint(temp_raster, spix + ip, 0);
457  if ((flag & MERIS_L1FLAG_SUSPECT) || (flag & MERIS_L1FLAG_INVALID)) {
458  invalid_flag[ip] = 1;
459  } else {
460  invalid_flag[ip] = 0;
461  }
462  if (flag & MERIS_L1FLAG_LAND){
463  land_flag[ip] = 1;
464  } else{
465  land_flag[ip] = 0;
466  }
467  }
468 
469  epr_free_raster(temp_raster);
470 
471 
472  // read latitude
473 
474  band_id = epr_get_band_id(fileID, "latitude");
475  if (band_id == NULL) {
476  printf("-E- %s line %d: Error finding band_id:latitude\n", __FILE__,
477  __LINE__);
478  return (1);
479  }
480  temp_raster = epr_create_compatible_raster(band_id, file_npix, 1, 1, 1);
481  if (temp_raster == NULL) {
482  printf("-E- %s line %d: Error allocating raster space.\n", __FILE__,
483  __LINE__);
484  return (1);
485  }
486  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
487  for (ip = 0; ip < npix; ip++)
488  l1rec->lat[ip] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
489 
490  // read longitude
491 
492  band_id = epr_get_band_id(fileID, "longitude");
493  if (band_id == NULL) {
494  printf("-E- %s line %d: Error finding band_id:longitude\n", __FILE__,
495  __LINE__);
496  return (1);
497  }
498  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
499  for (ip = 0; ip < npix; ip++)
500  l1rec->lon[ip] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
501  epr_free_raster(temp_raster);
502 
503  // read sun zenith
504 
505  band_id = epr_get_band_id(fileID, "sun_zenith");
506  if (band_id == NULL) {
507  printf("-E- %s line %d: Error finding band_id:sun_zenith", __FILE__,
508  __LINE__);
509  return (1);
510  }
511  temp_raster = epr_create_compatible_raster(band_id, file_npix, 1, 1, 1);
512  if (temp_raster == NULL) {
513  printf("-E- %s line %d: Error allocating raster space.\n", __FILE__,
514  __LINE__);
515  return (1);
516  }
517  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
518  for (ip = 0; ip < npix; ip++)
519  l1rec->solz[ip] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
520  epr_free_raster(temp_raster);
521 
522  // read sun azimuth
523 
524  band_id = epr_get_band_id(fileID, "sun_azimuth");
525  if (band_id == NULL) {
526  printf("-E- %s line %d: Error finding band_id:sun_azimuth", __FILE__,
527  __LINE__);
528  return (1);
529  }
530  temp_raster = epr_create_compatible_raster(band_id, file_npix, 1, 1, 1);
531  if (temp_raster == NULL) {
532  printf("-E- %s line %d: Error allocating raster space.\n", __FILE__,
533  __LINE__);
534  return (1);
535  }
536  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
537  for (ip = 0; ip < npix; ip++)
538  l1rec->sola[ip] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
539  epr_free_raster(temp_raster);
540 
541  // read view zenith
542 
543  band_id = epr_get_band_id(fileID, "view_zenith");
544  if (band_id == NULL) {
545  printf("-E- %s line %d: Error finding band_id:view_zenith", __FILE__,
546  __LINE__);
547  return (1);
548  }
549  temp_raster = epr_create_compatible_raster(band_id, file_npix, 1, 1, 1);
550  if (temp_raster == NULL) {
551  printf("-E- %s line %d: Error allocating raster space.\n", __FILE__,
552  __LINE__);
553  return (1);
554  }
555  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
556  for (ip = 0; ip < npix; ip++)
557  l1rec->senz[ip] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
558  epr_free_raster(temp_raster);
559 
560  // read view azimuth
561 
562  band_id = epr_get_band_id(fileID, "view_azimuth");
563  if (band_id == NULL) {
564  printf("-E- %s line %d: Error finding band_id:view_azimuth", __FILE__,
565  __LINE__);
566  return (1);
567  }
568  temp_raster = epr_create_compatible_raster(band_id, file_npix, 1, 1, 1);
569  if (temp_raster == NULL) {
570  printf("-E- %s line %d: Error allocating raster space.\n", __FILE__,
571  __LINE__);
572  return (1);
573  }
574  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
575  for (ip = 0; ip < npix; ip++)
576  l1rec->sena[ip] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
577  epr_free_raster(temp_raster);
578 
579  // set pixnum and check for navigation failure
580 
581  for (ip = 0; ip < npix; ip++) {
582  l1rec->pixnum[ip] = spix + ip;
583  if (l1rec->lon[ip] < -181.0 || l1rec->lon[ip] > 181.0 ||
584  l1rec->lat[ip] < -91.0 || l1rec->lat[ip] > 91.0)
585  l1rec->navfail[ip] = 1;
586  }
587 
588  // read detector_index
589  band_id = epr_get_band_id(fileID, "detector_index");
590  if (band_id == NULL) {
591  printf("-E- %s line %d: Error finding band_id:detector_index\n", __FILE__,
592  __LINE__);
593  return (1);
594  }
595  temp_raster = epr_create_compatible_raster(band_id, file_npix, 1, 1, 1);
596  if (temp_raster == NULL) {
597  printf("-E- %s line %d: Error allocating raster space.\n", __FILE__,
598  __LINE__);
599  return (1);
600  }
601  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
602  for (ip = 0; ip < npix; ip++) {
603  l1rec->pixdet[ip] = epr_get_pixel_as_uint(temp_raster, spix + ip, 0);
604  }
605  epr_free_raster(temp_raster);
606 
607 
608  // read in data
609 
610  for (ib = 0; ib < nbands; ib++) {
611 
612  band_id = epr_get_band_id(fileID, names[ib]);
613  if (band_id == NULL) {
614  printf("-E- %s line %d: Error finding band_id:%s\n", __FILE__,
615  __LINE__, names[ib]);
616  return (1);
617 
618  } else {
619  temp_raster = epr_create_compatible_raster(band_id, file_npix, 1, 1, 1);
620  if (temp_raster == NULL) {
621  printf("-E- %s line %d: Error allocating raster space.\n",
622  __FILE__, __LINE__);
623  return (1);
624  }
625  err_code = epr_read_band_raster(band_id, 0, scan, temp_raster);
626  if (!err_code) {
627 
628  // copy to Lt record. Note that this might actually be Rrs
629  // if the input file is a MERIS L2 file
630 
631  for (ip = 0; ip < npix; ip++) {
632 
633  ipb = ip * nbands + ib;
634  l1rec->Lt[ipb] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
635 
636  // set the value of all of the bands to BAD_FLT if
637  // navfail has been flagged.
638  if (invalid_flag[ip])
639  l1rec->Lt[ipb] = BAD_FLT;
640  else
641  l1rec->Lt[ipb] /= 10.0; // units conversion
642 
643  // mark negative input data as HILT
644  if (l1rec->Lt[ipb] < 0.0)
645  l1rec->hilt[ip] = 1;
646 
647  }
648  }
649  epr_free_raster(temp_raster);
650 
651  } // if band_id found
652 
653  } // for ib
654  // radcor needs all Lts populated before running so...one more time around the block...
655  if (l1_input->rad_opt != 0) {
656  for (ip = spix; ip < npix; ip++) {
657  // es not corrected f0, so setting 0 as 4 element - seemed silly to make a variable for it
658  radcor(l1rec, ip, land_flag[ip], 0);
659  for (ib = 0; ib < nbands; ib++) {
660  ipb = ip * nbands + ib;
661  l1rec->Lt[ipb] += l1rec->radcor[ipb];
662  }
663  }
664  }
665  l1rec->npix = file->npix;
666 
667  return (LIFE_IS_GOOD);
668 }
669 
679 int readl1_lonlat_meris_N1(filehandle *file, int32_t scan, l1str *l1rec) {
680  static int firstCall = 1;
681 
682  int32_t npix;
683  int32_t ip;
684  static EPR_SBandId *lon_band_id;
685  static EPR_SBandId *lat_band_id;
686  static EPR_SRaster *temp_raster;
687 
688 
689  npix = file->npix;
690 
691 
692  if (firstCall) {
693 
694  lon_band_id = epr_get_band_id(fileID, "longitude");
695  if (lon_band_id == NULL) {
696  printf("-E- %s line %d: Error finding band_id:longitude\n",
697  __FILE__, __LINE__);
698  return (1);
699  }
700 
701  lat_band_id = epr_get_band_id(fileID, "latitude");
702  if (lat_band_id == NULL) {
703  printf("-E- %s line %d: Error finding band_id:latitude\n",
704  __FILE__, __LINE__);
705  return (1);
706  }
707 
708  temp_raster = epr_create_compatible_raster(lat_band_id, file_npix, 1, 1, 1);
709  if (temp_raster == NULL) {
710  printf("-E- %s line %d: Error allocating raster space.\n",
711  __FILE__, __LINE__);
712  return (1);
713  }
714 
715  firstCall = 0;
716  }
717 
718 
719  // read latitude
720 
721  epr_read_band_raster(lat_band_id, 0, scan, temp_raster);
722  for (ip = 0; ip < npix; ip++)
723  l1rec->lat[ip] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
724 
725  // read longitude
726 
727  epr_read_band_raster(lon_band_id, 0, scan, temp_raster);
728  for (ip = 0; ip < npix; ip++)
729  l1rec->lon[ip] = epr_get_pixel_as_float(temp_raster, spix + ip, 0);
730 
731 
732  return (LIFE_IS_GOOD);
733 }
734 
742 int
743 closel1_meris_N1(filehandle *file) {
744  if (epr_close_product(fileID)) {
745  fprintf(stderr,
746  "-E- %s line %d: epr_close_product failed for file, %s.\n",
747  __FILE__, __LINE__, file->name);
748  return (1);
749  }
750 
751  if (detectorWL)
752  free(detectorWL);
753  if (detectorE0)
754  free(detectorE0);
755 
756  return (LIFE_IS_GOOD);
757 }
758 
const char * sensorId2SensorDir(int sensorId)
Definition: sensorInfo.c:240
#define MERIS_BANDINFO_FILENAME
Definition: l1_meris_N1.c:28
@ e_log_debug
Definition: epr_api.h:125
void radcor(l1str *l1rec, int32_t ip, int32_t land, int32_t escorrected)
Definition: smile.c:195
MERIS reader.
int32_t day
EPR_SRaster * epr_create_compatible_raster(EPR_SBandId *band_id, epr_uint source_width, epr_uint source_height, epr_uint source_step_x, epr_uint source_step_y)
Definition: epr_band.c:549
epr_uint epr_get_pixel_as_uint(const EPR_SRaster *raster, int x, int y)
Definition: epr_bitmask.c:736
unsigned int epr_uint
Definition: epr_api.h:188
void epr_free_raster(EPR_SRaster *raster)
Definition: epr_band.c:568
int16_t fileID
#define MERIS_WAVELENGTH_FR_FILENAME
Definition: l1_meris_N1.c:30
#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
read l1rec
#define MERIS_WAVELENGTH_RR_FILENAME
Definition: l1_meris_N1.c:31
int32 * msec
Definition: l1_czcs_hdf.c:31
float epr_get_pixel_as_float(const EPR_SRaster *raster, int x, int y)
Definition: epr_bitmask.c:789
int epr_init_api(EPR_ELogLevel log_level, EPR_FLogHandler log_handler, EPR_FErrHandler err_handler)
Definition: epr_api.c:40
double esdist_(int32_t *year, int32_t *day, int32_t *msec)
int syear
Definition: l1_czcs_hdf.c:15
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
const EPR_SField * epr_get_field(const EPR_SRecord *record, const char *field_name)
Definition: epr_field.c:247
#define LIFE_IS_GOOD
Definition: passthebuck.h:4
int sday
Definition: l1_czcs_hdf.c:15
const char * epr_get_field_elem_as_str(const EPR_SField *field)
Definition: epr_typconv.c:624
#define MERIS_FR_DETECTORS
Definition: l1_meris_N1.c:36
string path
Definition: color_dtdb.py:221
#define MERIS_L1FLAG_LAND
Definition: l1_meris_N1.c:55
epr_uint epr_get_field_elem_as_uint(const EPR_SField *field, epr_uint elem_index)
Definition: epr_typconv.c:363
l1_input_t * l1_input
Definition: l1_options.c:9
int want_verbose
void smile_init(int num_bands, int num_detectors, const char *bandinfo_filename, float *detectorWLs, float *detectorE0s)
Definition: smile.c:48
void unix2yds(double usec, short *year, short *day, double *secs)
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
integer, parameter double
#define MERIS_NBANDS
Definition: l1_meris_N1.c:26
EPR_SRecord * epr_get_sph(const EPR_SProductId *product_id)
Definition: epr_product.c:388
#define MERIS_L1FLAG_INVALID
Definition: l1_meris_N1.c:58
Definition: names.f90:1
#define BAD_FLT
Definition: jplaeriallib.h:19
int32_t nbands
int32 spix
Definition: l1_czcs_hdf.c:21
int readl1_meris_N1(filehandle *file, int32_t scan, l1str *l1rec)
reads 1 scan line from MERIS file, loads l1rec
Definition: l1_meris_N1.c:275
int readl1_lonlat_meris_N1(filehandle *file, int32_t scan, l1str *l1rec)
reads 1 scan line from MERIS file, loads l1rec
Definition: l1_meris_N1.c:679
EPR_SBandId * epr_get_band_id(EPR_SProductId *product_id, const char *band_name)
Definition: epr_band.c:237
int closel1_meris_N1(filehandle *file)
closes MERIS file, loads l1rec
Definition: l1_meris_N1.c:743
#define MERIS_RR_DETECTORS
Definition: l1_meris_N1.c:38
#define MERIS_SUN_FLUX_RR_FILENAME
Definition: l1_meris_N1.c:33
real *8 function esdist(iyr, iday, msec)
Definition: esdist.f:3
double ymds2unix(short year, short month, short day, double secs)
EPR_SProductId * epr_open_product(const char *product_file_path)
Definition: epr_product.c:54
#define MERIS_LINE_MAX
Definition: l1_meris_N1.c:41
int epr_read_band_raster(EPR_SBandId *band_id, int offset_x, int offset_y, EPR_SRaster *raster)
Definition: epr_band.c:593
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")
#define MERIS_SUN_FLUX_FR_FILENAME
Definition: l1_meris_N1.c:32
EPR_SRecord * epr_get_mph(const EPR_SProductId *product_id)
Definition: epr_product.c:399
#define MERIS_L1FLAG_SUSPECT
Definition: l1_meris_N1.c:54
int npix
Definition: get_cmp.c:27
int epr_close_product(EPR_SProductId *product_id)
Definition: epr_product.c:231
#define numDetectors
int openl1_meris_N1(filehandle *file)
opens a MERIS file for reading to load into L1 record
Definition: l1_meris_N1.c:112
int count
Definition: decode_rs.h:79