Go to the documentation of this file.
26 #include <gsl/gsl_math.h>
27 #include <gsl/gsl_spline.h>
29 static FILE *fp =
NULL;
30 static char current_file[FILENAME_MAX];
49 fseek(fp, 0, SEEK_SET);
51 if (fread(&hdr, 1,
sizeof (hdr), fp) !=
sizeof (hdr)) {
52 printf(
"-E- %s: File read error.\n", __FILE__);
56 if (hdr.length < 0 || hdr.length > 1000000 ||
57 hdr.npix < 0 || hdr.npix > 10000) {
58 printf(
"-E- %s: Header values out of range.\n", __FILE__);
59 printf(
" Record length = %d\n", hdr.length);
60 printf(
" Pixels per scan = %d\n", hdr.npix);
64 file->sensorID = hdr.sensorID;
65 file->length = hdr.length;
66 file->npix = hdr.npix;
67 file->format = hdr.format;
68 file->nscan = hdr.nscan;
80 if (fp ==
NULL || strcmp(
file->name, current_file) != 0) {
82 if ((fp = fopen(
file->name,
"r")) ==
NULL) {
83 printf(
"-E- %s: Error opening %s for reading.\n",
84 __FILE__,
file->name);
89 printf(
"-E- %s: Error reading header for %s.\n",
90 __FILE__,
file->name);
110 printf(
"-E- %s: File open error.\n", __FILE__);
115 printf(
"-I- %s: End of target file %s reached.",
116 __FILE__,
file->name);
120 if (fseek(fp, (
recnum + 1) *
file->length, SEEK_SET) != 0) {
121 printf(
"-E- %s: Error seeking record %d in %s.",
126 if (fread(tgrec->data, 1,
file->length, fp) !=
file->length) {
130 tgrec->sensorID =
file->sensorID;
131 tgrec->length =
file->length;
132 tgrec->npix =
file->npix;
147 int32_t jl = -1, ju =
nbins, jm = 0;
151 while (ju - jl > 1) {
153 if (ascnd == (bin_num >=
bins[jm]))
159 if (bin_num ==
bins[jl])
return (jl);
160 if (jl + 1 <
nbins && bin_num ==
bins[jl + 1])
return (jl + 1);
161 if (jl > 0 && bin_num ==
bins[jl - 1])
return (jl - 1);
162 if (bin_num ==
bins[0])
return (0);
184 row =
MIN(((90 +
lat) * l3bin->nrows / 180.0), l3bin->nrows - 1);
185 col =
MIN(((
lon + 180.0) * l3bin->numbin[row] / 360.0), l3bin->numbin[row]);
187 bin = l3bin->basebin[row] + col;
210 static int firstCall = 1;
211 static l3binstr l3bin;
213 static float *l3wvls;
214 static double *l3wvlinterp;
215 static int *wvlmatch;
216 static int nvisbands;
218 int32_t ip, ib, ipb,
band;
221 static int needBandShift = 0;
223 static float *l3vals;
224 static double *l3valsinterp;
225 static gsl_interp_accel *acc;
226 static gsl_spline *spline_steffen;
230 l3nbands =
rdsensorinfo(tgrec->sensorID, 0,
"fwave", (
void **) &l3wvls);
233 l3nwaves = l3bin.nwave;
234 if ((l3bin.sensorID !=
l1rec->l1file->sensorID) && (
input->band_shift_opt != 2)) {
237 wvlmatch = (
int *) malloc(
l1rec->l1file->nbands * sizeof (
int));
239 for (ib = 0; ib <
l1rec->l1file->nbands; ib++) {
240 wvlmatch[ib] =
windex(
l1rec->l1file->fwave[ib], l3bin.wavelengths, l3nwaves);
241 if (
l1rec->l1file->iwave[ib] < 700) {
245 l3wvlinterp = (
double *) calloc(l3nwaves,
sizeof (
double));
247 l3wvlinterp[
band] = l3bin.wavelengths[
band];
249 l3valsinterp = (
double *) calloc(l3nwaves,
sizeof (
double));
250 l3vals = (
float *) calloc(l3nwaves,
sizeof (
float));
252 acc = gsl_interp_accel_alloc();
253 spline_steffen = gsl_spline_alloc(gsl_interp_steffen, l3nwaves);
257 for (ip = 0; ip <
l1rec->npix; ip++) {
259 for (ib = 0; ib <
nbands; ib++) {
267 if (
input->vcal_depth < 0) {
273 idx =
bin_match(l3bin.nbins, l3bin.bins, bin);
277 chl = l3bin.chl[idx];
278 aot = l3bin.tau[idx];
279 nobs = l3bin.nobs[idx];
282 l3valsinterp[
band] = l3bin.data[idx][
band];
283 l3vals[
band] = l3bin.data[idx][
band];
291 gsl_spline_init(spline_steffen, l3wvlinterp, l3valsinterp, l3nwaves);
293 if (chl <= input->chlthreshold && aot <= input->aotthreshold
296 for (ib = 0; ib < nvisbands; ib++) {
299 if (needBandShift && (l3bin.wavelengths[wvlmatch[ib]] !=
l1rec->l1file->fwave[ib])) {
301 if (
input->band_shift_opt == 0 ||
l1rec->l1file->fwave[ib] > 700) {
302 if (
l1rec->l1file->fwave[ib] > l3bin.wavelengths[0] &&
303 l1rec->l1file->fwave[ib] < l3bin.wavelengths[l3nwaves-1]) {
305 interpband = gsl_spline_eval(spline_steffen,
l1rec->l1file->fwave[ib], acc);
308 interpband = l3bin.data[idx][wvlmatch[ib]];
311 }
else if (
input->band_shift_opt == 1 &&
l1rec->l1file->fwave[ib] <= 700) {
312 interpband =
bioBandShift(l3bin.wavelengths, l3vals, chl, l3nwaves,
l1rec->l1file->fwave[ib]);
314 printf(
"-E- %s:%d: band_shift_opt error.\n", __FILE__, __LINE__);
318 interpband *=
l1rec->Fo[ib];
319 tgrec->nLw[ipb] = interpband;
322 if (l3bin.hasRrs == 0)
323 tgrec->nLw[ipb] /= 10.;
325 if (l3bin.hasRrs == 1)
326 tgrec->nLw[ipb] = l3bin.data[idx][wvlmatch[ib]] *
l1rec->Fo[ib];
328 tgrec->nLw[ipb] = l3bin.data[idx][wvlmatch[ib]] / 10.;
331 for (ib = nvisbands; ib <
nbands; ib++) {
333 tgrec->nLw[ipb] = 0.0;
339 tgrec->sensorID =
l1rec->l1file->sensorID;
340 tgrec->npix =
l1rec->npix;
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 band
int open_target(filehandle *file)
int read_target_l3(filehandle *file, l1str *l1rec, int32_t nbands, tgstr *tgrec)
int32_t bin_match(int32_t nbins, int32_t *bins, int32_t bin_num)
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
int32_t read_l3bin(char *file, l3binstr *l3bin, int32_t nbands)
int read_target(filehandle *file, int32_t recnum, tgstr *tgrec)
int windex(float wave, float twave[], int ntwave)
float bioBandShift(float wvl[], float rrs[], float chla, int nw, float tarWvl)
int32_t rdsensorinfo(int32_t, int32_t, const char *, void **)
int read_targethdr(filehandle *file)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int32_t lonlat2bin(l3binstr *l3bin, float lon, float lat)