24 sd_id = SDstart(
file->name, DFACC_RDONLY);
26 fprintf(
stderr,
"-E- %s line %d: SDstart(%s, %d) failed.\n",
27 __FILE__, __LINE__,
file->name, DFACC_RDONLY);
33 fprintf(
stderr,
"-E- %s line %d: error getting dimension info.\n",
37 if (
getHDFattr(sd_id,
"Number of Pixels",
"", (VOIDP) &
npix) != 0) {
38 fprintf(
stderr,
"-E- %s line %d: error getting dimension info.\n",
58 static int firstCall = 1;
59 static int have_ctl = 0;
60 static int32_t nctlpix = 0;
62 static int32_t *pixnum =
NULL;
63 static float *ctlfpix =
NULL;
64 static int32_t *ctlpix =
NULL;
65 static float *ctllon =
NULL;
66 static float *ctllat =
NULL;
67 static float *ctlsolz =
NULL;
68 static float *ctlsola =
NULL;
69 static float *ctlsenz =
NULL;
70 static float *ctlsena =
NULL;
71 static float *dctllon =
NULL;
72 static float *dctllat =
NULL;
73 static float *dctlsolz =
NULL;
74 static float *dctlsola =
NULL;
75 static float *dctlsenz =
NULL;
76 static float *dctlsena =
NULL;
77 static int16_t factor[8];
78 static char sdsname[32];
79 static int16_t
syear = 0;
80 static int16_t
sday = 0;
81 static int32_t
smsec = 0;
82 static int32_t dmsec = 0;
84 int32_t sd_id =
file->sd_id;
95 if (
getHDFattr(sd_id,
"Number of Pixel Control Points",
"", (VOIDP) & nctlpix) != 0) {
96 fprintf(
stderr,
"-E- %s line %d: error getting dimension info.\n",
100 if (nctlpix !=
npix) {
101 printf(
"Geolocation will be derived from control points.\n");
103 (ctlfpix = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
104 (ctlpix = (int32_t *) calloc(nctlpix,
sizeof (int32_t))) ==
NULL ||
105 (ctllon = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
106 (ctllat = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
107 (ctlsolz = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
108 (ctlsola = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
109 (ctlsenz = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
110 (ctlsena = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
111 (dctllon = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
112 (dctllat = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
113 (dctlsolz = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
114 (dctlsola = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
115 (dctlsenz = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL ||
116 (dctlsena = (
float *) calloc(nctlpix,
sizeof (
float))) ==
NULL) {
118 printf(
"-E- %s line %d: Error allocating control-point space.\n",
122 READ_SDS_ID(sd_id,
"ctlpixl", ctlpix, 0, 0, 0, 0, nctlpix, 1, 1, 1);
123 for (ip = 0; ip < nctlpix; ip++) ctlfpix[ip] = (
float) ctlpix[ip];
128 pixnum = (int32_t *) calloc(
npix,
sizeof (int32_t));
129 READ_SDS_ID(sd_id,
"pixnum", pixnum, 0, 0, 0, 0,
npix, 1, 1, 1);
133 if ((
data = (uint16_t *) calloc(
npix *
l1rec->l1file->nbands, sizeof (uint16_t))) ==
NULL) {
134 printf(
"-E- %s line %d: Error allocating data space.\n",
140 for (ib = 0; ib <
l1rec->l1file->nbands; ib++) {
141 sprintf(sdsname,
"band%1d", ib + 1);
142 if (
getHDFattr(sd_id,
"factor", sdsname, (VOIDP) & factor[ib]) != 0) {
143 fprintf(
stderr,
"-E- %s line %d: error getting dimension info.\n",
151 fprintf(
stderr,
"-E- %s line %d: error getting time info.\n",
156 fprintf(
stderr,
"-E- %s line %d: error getting time info.\n",
161 fprintf(
stderr,
"-E- %s line %d: error getting time info.\n",
165 if (
getHDFattr(sd_id,
"Delta Msec",
"", (VOIDP) & dmsec) != 0) {
166 fprintf(
stderr,
"-E- %s line %d: error getting time info.\n",
176 READ_SDS_ID(sd_id,
"lon", ctllon,
scan, 0, 0, 0, 1, nctlpix, 1, 1);
177 READ_SDS_ID(sd_id,
"lat", ctllat,
scan, 0, 0, 0, 1, nctlpix, 1, 1);
178 READ_SDS_ID(sd_id,
"solz", ctlsolz,
scan, 0, 0, 0, 1, nctlpix, 1, 1);
179 READ_SDS_ID(sd_id,
"sola", ctlsola,
scan, 0, 0, 0, 1, nctlpix, 1, 1);
180 READ_SDS_ID(sd_id,
"senz", ctlsenz,
scan, 0, 0, 0, 1, nctlpix, 1, 1);
181 READ_SDS_ID(sd_id,
"sena", ctlsena,
scan, 0, 0, 0, 1, nctlpix, 1, 1);
183 spline(ctlfpix, ctllon, nctlpix, 1e30, 1e30, dctllon);
184 spline(ctlfpix, ctllat, nctlpix, 1e30, 1e30, dctllat);
185 spline(ctlfpix, ctlsolz, nctlpix, 1e30, 1e30, dctlsolz);
186 spline(ctlfpix, ctlsola, nctlpix, 1e30, 1e30, dctlsola);
187 spline(ctlfpix, ctlsenz, nctlpix, 1e30, 1e30, dctlsenz);
188 spline(ctlfpix, ctlsena, nctlpix, 1e30, 1e30, dctlsena);
190 for (ip = 0; ip <
npix; ip++) {
191 l1rec->pixnum[ip] = pixnum[ip];
192 splint(ctlfpix, ctllon, dctllon, nctlpix, (
float) pixnum[ip], &
l1rec->lon[ip]);
193 splint(ctlfpix, ctllat, dctllat, nctlpix, (
float) pixnum[ip], &
l1rec->lat[ip]);
194 splint(ctlfpix, ctlsolz, dctlsolz, nctlpix, (
float) pixnum[ip], &
l1rec->solz[ip]);
195 splint(ctlfpix, ctlsola, dctlsola, nctlpix, (
float) pixnum[ip], &
l1rec->sola[ip]);
196 splint(ctlfpix, ctlsenz, dctlsenz, nctlpix, (
float) pixnum[ip], &
l1rec->senz[ip]);
197 splint(ctlfpix, ctlsena, dctlsena, nctlpix, (
float) pixnum[ip], &
l1rec->sena[ip]);
201 READ_SDS_ID(sd_id,
"lon",
l1rec->lon,
scan, 0, 0, 0, 1,
npix, 1, 1);
202 READ_SDS_ID(sd_id,
"lat",
l1rec->lat,
scan, 0, 0, 0, 1,
npix, 1, 1);
203 READ_SDS_ID(sd_id,
"solz",
l1rec->solz,
scan, 0, 0, 0, 1,
npix, 1, 1);
204 READ_SDS_ID(sd_id,
"sola",
l1rec->sola,
scan, 0, 0, 0, 1,
npix, 1, 1);
205 READ_SDS_ID(sd_id,
"senz",
l1rec->senz,
scan, 0, 0, 0, 1,
npix, 1, 1);
206 READ_SDS_ID(sd_id,
"sena",
l1rec->sena,
scan, 0, 0, 0, 1,
npix, 1, 1);
212 READ_SDS_ID(sd_id,
"band1", &
data[0 *
npix],
scan, 0, 0, 0, 1,
npix, 1, 1);
213 READ_SDS_ID(sd_id,
"band2", &
data[1 *
npix],
scan, 0, 0, 0, 1,
npix, 1, 1);
214 READ_SDS_ID(sd_id,
"band3", &
data[2 *
npix],
scan, 0, 0, 0, 1,
npix, 1, 1);
215 READ_SDS_ID(sd_id,
"band4", &
data[3 *
npix],
scan, 0, 0, 0, 1,
npix, 1, 1);
216 READ_SDS_ID(sd_id,
"band5", &
data[4 *
npix],
scan, 0, 0, 0, 1,
npix, 1, 1);
217 READ_SDS_ID(sd_id,
"band6", &
data[5 *
npix],
scan, 0, 0, 0, 1,
npix, 1, 1);
218 READ_SDS_ID(sd_id,
"band7", &
data[6 *
npix],
scan, 0, 0, 0, 1,
npix, 1, 1);
219 READ_SDS_ID(sd_id,
"band8", &
data[7 *
npix],
scan, 0, 0, 0, 1,
npix, 1, 1);
221 for (ip = 0; ip <
npix; ip++) {
222 for (ib = 0; ib <
l1rec->l1file->nbands; ib++) {
223 ipb = ip *
l1rec->l1file->nbands + ib;
227 l1rec->Lt[ipb] = 1000.0;
230 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
231 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0)
232 l1rec->navfail[ip] = 1;
243 if (SDend(
file->sd_id)) {
244 fprintf(
stderr,
"-E- %s line %d: SDend(%d) failed for file, %s.\n",
245 __FILE__, __LINE__,
file->sd_id,
file->name);