Go to the documentation of this file.
26 #define MERIS_NBANDS 15
28 #define MERIS_BANDINFO_FILENAME "band_info_meris.txt"
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"
36 #define MERIS_FR_DETECTORS 3700
38 #define MERIS_RR_DETECTORS 925
41 #define MERIS_LINE_MAX 1024
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
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
96 static double fileStartTime;
97 static double time_interval;
99 static int fullResolution = 0;
101 static float *detectorWL;
102 static float *detectorE0;
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;
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"};
134 fprintf(
stderr,
"-E- %s line %d: epr_open_product(%s) failed.\n",
135 __FILE__, __LINE__,
file->name);
140 if (band_id ==
NULL) {
141 fprintf(
stderr,
"-E- %s line %d - Can not find \"l1_flags\" in Meris N1 file\n",
148 source_h =
fileID->scene_height;
149 source_w =
fileID->scene_width;
150 file_npix = source_w;
152 printf(
"MERIS Level1B Npix :%u Nscans:%u\n", source_w, source_h);
158 if (record ==
NULL) {
159 fprintf(
stderr,
"-E- %s line %d: epr_get_sph(fileID) failed.\n",
170 "-E- %s line %d: epr_get_field(record,FIRST_LINE_TIME) failed.\n",
177 sscanf(fltime,
"%02d-%3s-%04d %02d:%02d:%f", &
day, monthstr, &
year,
178 &hour, &minute, &fsec);
181 for (
i = 0;
i < 12;
i++)
182 if (strncmp(monthstr, months_list[
i], 3) == 0)
184 fileStartTime =
ymds2unix(
year, month,
day, hour * 3600.0 + minute * 60.0 + fsec);
189 "-E- %s line %d: epr_get_field(record,FIRST_LINE_TIME) failed.\n",
194 time_interval /= 1e6;
197 printf(
"MERIS time interval %lf\n", time_interval);
201 for (
i = 0;
i < nf;
i++) {
205 "-E- %s line %d: epr_get_field(record,%s) failed.\n",
206 __FILE__, __LINE__, sph_names[
i]);
210 printf(
"\t%s = %d\n", sph_names[
i],
222 if (strncmp(fname,
"MER_RR", 6) == 0) {
232 printf(
"-E- PRODUCT field not found in the MPH header.");
242 if ((tmp_spix < source_w) && (tmp_spix < tmp_epix)) {
243 spix = source_w - tmp_epix;
244 source_w = tmp_epix - tmp_spix + 1;
246 printf(
"OBPG Extract - spix=%d, npix=%d\n",
247 spix + 1, (
int) source_w);
252 printf(
"-E- MPH header not found.");
276 static int firstCall = 1;
279 static char *
names[] = {
280 "radiance_1",
"radiance_2",
"radiance_3",
"radiance_4",
281 "radiance_5",
"radiance_6",
"radiance_7",
"radiance_8",
282 "radiance_9",
"radiance_10",
"radiance_11",
"radiance_12",
283 "radiance_13",
"radiance_14",
"radiance_15"
288 EPR_SBandId *band_id =
NULL;
289 EPR_SRaster *temp_raster;
291 static char *invalid_flag;
292 static char *land_flag;
297 invalid_flag = malloc(
sizeof (
char) *
file->npix);
298 land_flag = malloc(
sizeof (
char) *
file->npix);
304 char path[FILENAME_MAX] =
"";
312 if ((tmp_str = getenv(
"OCDATAROOT")) ==
NULL) {
313 printf(
"OCDATAROOT environment variable is not defined.\n");
320 strcat(
path,
"/cal/");
325 printf(
"-E- %s line %d : error allocating memory for detectorWL.\n",
339 "-E- %s line %d: unable to open %s for reading\n", __FILE__, __LINE__,
filename);
347 for (detector = 0; detector <
numDetectors; detector++) {
350 "-E- %s line %d: unable to read detector %d from file %s\n", __FILE__, __LINE__, detector,
filename);
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);
361 "-E- %s line %d: unable to read whole detector %d line from file %s, count = %d\n",
375 printf(
"-E- %s line %d : error allocating memory for detectorE0.\n",
387 "-E- %s line %d: unable to open %s for reading\n", __FILE__, __LINE__,
filename);
395 for (detector = 0; detector <
numDetectors; detector++) {
398 "-E- %s line %d: unable to read detector %d from file %s\n", __FILE__, __LINE__, detector,
filename);
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);
409 "-E- %s line %d: unable to read whole detector %d line from file %s, count = %d\n",
429 l1rec->scantime = fileStartTime + time_interval*
scan;
436 int32_t
msec = (int32_t) (secs * 1000.0);
443 if (band_id ==
NULL) {
444 printf(
"-E- %s line %d: Error finding band_id:l1_flags\n", __FILE__,
449 if (temp_raster ==
NULL) {
450 printf(
"-E- %s line %d: Error allocating raster space.\n", __FILE__,
455 for (ip = 0; ip <
npix; ip++) {
458 invalid_flag[ip] = 1;
460 invalid_flag[ip] = 0;
475 if (band_id ==
NULL) {
476 printf(
"-E- %s line %d: Error finding band_id:latitude\n", __FILE__,
481 if (temp_raster ==
NULL) {
482 printf(
"-E- %s line %d: Error allocating raster space.\n", __FILE__,
487 for (ip = 0; ip <
npix; ip++)
493 if (band_id ==
NULL) {
494 printf(
"-E- %s line %d: Error finding band_id:longitude\n", __FILE__,
499 for (ip = 0; ip <
npix; ip++)
506 if (band_id ==
NULL) {
507 printf(
"-E- %s line %d: Error finding band_id:sun_zenith", __FILE__,
512 if (temp_raster ==
NULL) {
513 printf(
"-E- %s line %d: Error allocating raster space.\n", __FILE__,
518 for (ip = 0; ip <
npix; ip++)
525 if (band_id ==
NULL) {
526 printf(
"-E- %s line %d: Error finding band_id:sun_azimuth", __FILE__,
531 if (temp_raster ==
NULL) {
532 printf(
"-E- %s line %d: Error allocating raster space.\n", __FILE__,
537 for (ip = 0; ip <
npix; ip++)
544 if (band_id ==
NULL) {
545 printf(
"-E- %s line %d: Error finding band_id:view_zenith", __FILE__,
550 if (temp_raster ==
NULL) {
551 printf(
"-E- %s line %d: Error allocating raster space.\n", __FILE__,
556 for (ip = 0; ip <
npix; ip++)
563 if (band_id ==
NULL) {
564 printf(
"-E- %s line %d: Error finding band_id:view_azimuth", __FILE__,
569 if (temp_raster ==
NULL) {
570 printf(
"-E- %s line %d: Error allocating raster space.\n", __FILE__,
575 for (ip = 0; ip <
npix; ip++)
581 for (ip = 0; ip <
npix; 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;
590 if (band_id ==
NULL) {
591 printf(
"-E- %s line %d: Error finding band_id:detector_index\n", __FILE__,
596 if (temp_raster ==
NULL) {
597 printf(
"-E- %s line %d: Error allocating raster space.\n", __FILE__,
602 for (ip = 0; ip <
npix; ip++) {
610 for (ib = 0; ib <
nbands; ib++) {
613 if (band_id ==
NULL) {
614 printf(
"-E- %s line %d: Error finding band_id:%s\n", __FILE__,
615 __LINE__,
names[ib]);
620 if (temp_raster ==
NULL) {
621 printf(
"-E- %s line %d: Error allocating raster space.\n",
631 for (ip = 0; ip <
npix; ip++) {
638 if (invalid_flag[ip])
641 l1rec->Lt[ipb] /= 10.0;
644 if (
l1rec->Lt[ipb] < 0.0)
659 for (ib = 0; ib <
nbands; ib++) {
680 static int firstCall = 1;
684 static EPR_SBandId *lon_band_id;
685 static EPR_SBandId *lat_band_id;
686 static EPR_SRaster *temp_raster;
695 if (lon_band_id ==
NULL) {
696 printf(
"-E- %s line %d: Error finding band_id:longitude\n",
702 if (lat_band_id ==
NULL) {
703 printf(
"-E- %s line %d: Error finding band_id:latitude\n",
709 if (temp_raster ==
NULL) {
710 printf(
"-E- %s line %d: Error allocating raster space.\n",
722 for (ip = 0; ip <
npix; ip++)
728 for (ip = 0; ip <
npix; ip++)
746 "-E- %s line %d: epr_close_product failed for file, %s.\n",
747 __FILE__, __LINE__,
file->name);
const char * sensorId2SensorDir(int sensorId)
#define MERIS_BANDINFO_FILENAME
void radcor(l1str *l1rec, int32_t ip, int32_t land, int32_t escorrected)
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)
epr_uint epr_get_pixel_as_uint(const EPR_SRaster *raster, int x, int y)
void epr_free_raster(EPR_SRaster *raster)
#define MERIS_WAVELENGTH_FR_FILENAME
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
#define MERIS_WAVELENGTH_RR_FILENAME
float epr_get_pixel_as_float(const EPR_SRaster *raster, int x, int y)
int epr_init_api(EPR_ELogLevel log_level, EPR_FLogHandler log_handler, EPR_FErrHandler err_handler)
double esdist_(int32_t *year, int32_t *day, int32_t *msec)
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
const EPR_SField * epr_get_field(const EPR_SRecord *record, const char *field_name)
const char * epr_get_field_elem_as_str(const EPR_SField *field)
#define MERIS_FR_DETECTORS
#define MERIS_L1FLAG_LAND
epr_uint epr_get_field_elem_as_uint(const EPR_SField *field, epr_uint elem_index)
void smile_init(int num_bands, int num_detectors, const char *bandinfo_filename, float *detectorWLs, float *detectorE0s)
void unix2yds(double usec, short *year, short *day, double *secs)
char filename[FILENAME_MAX]
integer, parameter double
EPR_SRecord * epr_get_sph(const EPR_SProductId *product_id)
#define MERIS_L1FLAG_INVALID
int readl1_meris_N1(filehandle *file, int32_t scan, l1str *l1rec)
reads 1 scan line from MERIS file, loads l1rec
int readl1_lonlat_meris_N1(filehandle *file, int32_t scan, l1str *l1rec)
reads 1 scan line from MERIS file, loads l1rec
EPR_SBandId * epr_get_band_id(EPR_SProductId *product_id, const char *band_name)
int closel1_meris_N1(filehandle *file)
closes MERIS file, loads l1rec
#define MERIS_RR_DETECTORS
#define MERIS_SUN_FLUX_RR_FILENAME
real *8 function esdist(iyr, iday, msec)
double ymds2unix(short year, short month, short day, double secs)
EPR_SProductId * epr_open_product(const char *product_file_path)
int epr_read_band_raster(EPR_SBandId *band_id, int offset_x, int offset_y, EPR_SRaster *raster)
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
EPR_SRecord * epr_get_mph(const EPR_SProductId *product_id)
#define MERIS_L1FLAG_SUSPECT
int epr_close_product(EPR_SProductId *product_id)
int openl1_meris_N1(filehandle *file)
opens a MERIS file for reading to load into L1 record