Go to the documentation of this file.
16 #define BANDINFO_LINE_MAX 255
19 static int numBands = 0;
23 static int *switch_land;
24 static int *lower_land;
25 static int *upper_land;
26 static int *switch_water;
27 static int *lower_water;
28 static int *upper_water;
32 static float *detectorWL;
33 static float *detectorE0;
48 void smile_init(
int num_bands,
int num_detectors,
const char* bandinfo_filename,
49 float* detectorWLs,
float* detectorE0s) {
57 printf(
"-E- %s:%d - Can not re-initialize the smile correction.", __FILE__, __LINE__);
60 if (bandinfo_filename ==
NULL) {
61 printf(
"-E- %s:%d - bandinfo_filename can not be NULL.", __FILE__, __LINE__);
64 if (detectorWLs ==
NULL) {
65 printf(
"-E- %s:%d - detectorWLs can not be NULL.", __FILE__, __LINE__);
68 if (detectorE0s ==
NULL) {
69 printf(
"-E- %s:%d - detectorE0s can not be NULL.", __FILE__, __LINE__);
75 detectorWL = detectorWLs;
76 detectorE0 = detectorE0s;
78 switch_land = (
int*)
allocateMemory(
sizeof (
int)*numBands,
"smile switch_land");
79 lower_land = (
int*)
allocateMemory(
sizeof (
int)*numBands,
"smile lower_land");
80 upper_land = (
int*)
allocateMemory(
sizeof (
int)*numBands,
"smile upper_land");
81 switch_water = (
int*)
allocateMemory(
sizeof (
int)*numBands,
"smile switch_water");
82 lower_water = (
int*)
allocateMemory(
sizeof (
int)*numBands,
"smile lower_water");
83 upper_water = (
int*)
allocateMemory(
sizeof (
int)*numBands,
"smile upper_water");
84 theoWL = (
float*)
allocateMemory(
sizeof (
float)*numBands,
"smile theoWL");
85 theoE0 = (
float*)
allocateMemory(
sizeof (
float)*numBands,
"smile theoE0");
89 if ((fp = fopen(bandinfo_filename,
"r")) ==
NULL) {
91 "-E- %s:%d: unable to open %s for reading\n", __FILE__, __LINE__, bandinfo_filename);
99 fprintf(
stderr,
"-E- %s line %d: unable to read band %d from file %s\n",
100 __FILE__, __LINE__,
band, bandinfo_filename);
103 count = sscanf(
line,
"%d %d %d %d %d %d %d %f %f", &dummy,
104 &switch_water[
band], &lower_water[
band], &upper_water[
band],
105 &switch_land[
band], &lower_land[
band], &upper_land[
band],
109 "-E- %s line %d: unable to read band %d line from file %s, count = %d\n",
110 __FILE__, __LINE__,
band, bandinfo_filename,
count);
124 printf(
"\nSmile corrections enabled.\n\n");
156 double r0, r1, r2,
rc, dl, dr;
159 for (i0 = 0; i0 < numBands; i0++) {
162 r0 = radiances[i0] / detectorE0s[i0];
163 rc = r0 * theoretE0s[i0] * fsol;
164 delta[i0] =
rc - radiances[i0];
165 if (shouldCorrect[i0]) {
169 r1 = radiances[i1] / detectorE0s[i1];
170 r2 = radiances[i2] / detectorE0s[i2];
171 dl = (theoretWLs[i0] - detectorWLs[i0]) / (detectorWLs[i2] - detectorWLs[i1]);
172 dr = (r2 - r1) * dl * theoretE0s[i0] * fsol;
200 int correctionPossible;
211 Ltemp = (
float*)
allocateMemory(
sizeof (
float)*numBands,
"smile temp Lt array");
217 detectorIndex =
l1rec->pixdet[ip];
218 correctionPossible = ((detectorIndex >= 0) && (detectorIndex <
numDetectors));
220 if (correctionPossible) {
222 shouldCorrect = switch_land;
226 shouldCorrect = switch_water;
227 index1 = lower_water;
228 index2 = upper_water;
232 for (ib = 0; ib < numBands; ib++) {
233 ipb = ip *
l1rec->l1file->nbands + ib;
237 Ltemp[ib] =
l1rec->Lt[ipb] * 10.0;
241 float fsol =
l1rec->fsol;
251 &(detectorWL[detectorIndex * numBands]),
252 &(detectorE0[detectorIndex * numBands]),
253 &(
l1rec->radcor[ip *
l1rec->l1file->nbands]));
257 for (ib = 0; ib < numBands; ib++) {
258 ipb = ip *
l1rec->l1file->nbands + ib;
259 l1rec->radcor[ipb] = 0;
void radcor(l1str *l1rec, int32_t ip, int32_t land, int32_t escorrected)
void * allocateMemory(size_t numBytes, const char *name)
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
#define BANDINFO_LINE_MAX
void smile_calc_delta(int *shouldCorrect, int *indexes1, int *indexes2, float *radiances, float *theoretWLs, float *theoretE0s, float fsol, float *detectorWLs, float *detectorE0s, float *delta)
float rc(float x, float y)
void smile_init(int num_bands, int num_detectors, const char *bandinfo_filename, float *detectorWLs, float *detectorE0s)