13 static int16_t nline,
npix;
15 static int32_t spix = 0;
17 static double *scan_start_tai, *scan_stop_tai;
18 static double time_interval;
23 size_t source_w, source_h, source_b;
26 int fileID, xid, yid, band_id, retval, grp_id, sds_id;
33 retval = nc_open(
file->name, NC_NOWRITE, &
fileID);
34 if (retval != NC_NOERR) {
35 fprintf(
stderr,
"-E- %s line %d: nc_open(%s) failed.\n",
36 __FILE__, __LINE__,
file->name);
41 retval = nc_inq_dimid(
fileID,
"number_of_lines", &yid);
42 retval = nc_inq_dimid(
fileID,
"pixels_per_line", &xid);
43 retval = nc_inq_dimid(
fileID,
"number_of_bands", &band_id);
44 retval = nc_inq_dimlen(
fileID, xid, &source_w);
45 retval = nc_inq_dimlen(
fileID, yid, &source_h);
46 retval = nc_inq_dimlen(
fileID, band_id, &source_b);
49 printf(
"AVIRIS L1B Npix :%d Nscans:%d\n", (
int) source_w,
52 npix = (int32_t) source_w;
53 nscan = (int32_t) source_h;
59 file->nbands = source_b;
62 scan_start_tai = (
double *) calloc(
nscan,
sizeof (
double));
63 scan_stop_tai = (
double *) calloc(
nscan,
sizeof (
double));
64 alt = (
short *) calloc(
nscan,
sizeof (
short));
73 nc_inq_ncid(
file->sd_id,
"scan_line_attributes", &grp_id);
75 retval = nc_inq_varid(grp_id,
"altitude", &sds_id);
76 retval = nc_get_vara_short(grp_id, sds_id,
start,
count, alt);
77 if (retval != NC_NOERR) {
79 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
80 __FILE__, __LINE__,
file->name,
"altitude");
84 retval = nc_inq_varid(grp_id,
"scan_start_time", &sds_id);
85 retval = nc_get_vara_double(grp_id, sds_id,
start,
count, scan_start_tai);
86 if (retval != NC_NOERR) {
88 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
89 __FILE__, __LINE__,
file->name,
"scan_start_time");
101 int iscan = 0, i1, i2;
104 if (scan_start_tai[
iscan] > 0) {
105 if (starttime > scan_start_tai[
iscan])starttime = scan_start_tai[
iscan];
118 if (scan_start_tai[
iscan] > 0) {
126 time_interval = (
stoptime - starttime) / ((i2 - i1) + 1);
134 file->fwhm = (
float *) calloc(source_b,
sizeof (
float));
135 float *
fwhm = (
float *) calloc(source_b,
sizeof (
float));
137 retval = nc_inq_ncid(
file->sd_id,
"sensor_band_parameters", &grp_id);
138 if (retval != NC_NOERR) {
140 "-E- %s line %d: nc_inq failed for file, %s group does not exist: %s.\n",
141 __FILE__, __LINE__,
file->name,
"sensor_band_parameters");
145 retval = nc_inq_varid(grp_id,
"fwhm", &sds_id);
146 if (retval != NC_NOERR) {
148 "-E- %s line %d: nc_inq failed for file, %s field, variable %s does not exist.\n",
149 __FILE__, __LINE__,
file->name,
"fwhm");
155 for (
i = 0;
i < source_b;
i++)
162 static int firstCall = 1;
166 int32_t ip, ib, ipb, Ibp;
174 printf(
"file->nbands = %d, l1rec->nbands = %d\n",
175 (
int)
file->nbands, (
int)
l1rec->l1file->nbands);
178 for (ip = 0; ip <
npix; ip++) {
179 l1rec->pixnum[ip] = ip;
180 l1rec->flags[ip] = 0;
199 retval = nc_inq_ncid(
file->sd_id,
"navigation_data", &grp_id);
200 if (retval != NC_NOERR) {
202 "-E- %s line %d: nc_inq_ncid failed for file, %s group, %s.\n",
203 __FILE__, __LINE__,
file->name,
"navigation_data");
214 lon = (
float *) calloc(
npix,
sizeof (
float));
215 lat = (
float *) calloc(
npix,
sizeof (
float));
216 senz = (
float *) calloc(
npix,
sizeof (
float));
217 sena = (
float *) calloc(
npix,
sizeof (
float));
218 solz = (
float *) calloc(
npix,
sizeof (
float));
219 sola = (
float *) calloc(
npix,
sizeof (
float));
221 retval = nc_inq_varid(grp_id,
"lon", &band_id);
222 if (retval != NC_NOERR) {
224 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
225 __FILE__, __LINE__,
file->name,
"lon");
228 retval = nc_get_vara_float(grp_id, band_id,
start,
count,
lon);
229 if (retval != NC_NOERR) {
231 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
232 __FILE__, __LINE__,
file->name,
"lon");
235 retval = nc_inq_varid(grp_id,
"lat", &band_id);
236 if (retval != NC_NOERR) {
238 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
239 __FILE__, __LINE__,
file->name,
"lon");
242 retval = nc_get_vara_float(grp_id, band_id,
start,
count,
lat);
243 if (retval != NC_NOERR) {
245 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
246 __FILE__, __LINE__,
file->name,
"lat");
250 for (ip = spix; ip <
npix; ip++) {
253 l1rec->solz[ip] = -999;
254 l1rec->sola[ip] = -999;
255 l1rec->senz[ip] = -999;
256 l1rec->sena[ip] = -999;
259 retval = nc_inq_varid(grp_id,
"sena", &band_id);
261 if (retval != NC_NOERR) {
263 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
264 __FILE__, __LINE__,
file->name,
"sena");
267 retval = nc_inq_varid(grp_id,
"senz", &band_id);
269 if (retval != NC_NOERR) {
271 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
272 __FILE__, __LINE__,
file->name,
"senz");
275 retval = nc_inq_varid(grp_id,
"sola", &band_id);
277 if (retval != NC_NOERR) {
279 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
280 __FILE__, __LINE__,
file->name,
"sola");
283 retval = nc_inq_varid(grp_id,
"solz", &band_id);
285 if (retval != NC_NOERR) {
287 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
288 __FILE__, __LINE__,
file->name,
"solz");
292 for (ip = spix; ip <
npix; ip++) {
303 rad_data = (
float *) calloc(
npix*
nbands,
sizeof (
float));
312 nc_inq_ncid(
file->sd_id,
"observation_data", &grp_id);
314 retval = nc_inq_varid(grp_id,
"Lt", &band_id);
315 retval = nc_get_vara_float(grp_id, band_id,
start,
count, rad_data);
316 if (retval != NC_NOERR) {
318 "-E- %s line %d: nc_get_vara_float failed for file, %s field, %s.\n",
319 __FILE__, __LINE__,
file->name,
"Lt_visnir");
323 for (ib = 0; ib <
nbands; ib++) {
326 for (ip = spix; ip <
npix; ip++) {
328 Ibp = ib *
npix + ip;
329 l1rec->Lt[ipb] = rad_data[Ibp];
333 if (
l1rec->Lt[ipb] < 0.0) {
334 l1rec->Lt[ipb] = 0.0001;
336 }
else if (
l1rec->Lt[ipb] > 0) {
352 l1rec->l1file->sensorID =
file->sensorID;
360 aviris_t *
data =
file->private_data;
362 retval = nc_close(
file->sd_id);
363 if (retval != NC_NOERR) {
364 fprintf(
stderr,
"-E- %s line %d: nc_close failed for file, %s.\n",
365 __FILE__, __LINE__,
file->name);
368 free(scan_start_tai);
370 free(
file->private_data);