Go to the documentation of this file.
12 #include "jplaeriallib.h"
32 aviris_t*
data = (aviris_t*) calloc(1,
sizeof (aviris_t));
34 fprintf(
stderr,
"-E- %s line %d: unable to allocate private data for aviris\n",
39 data->wave = (
double *) malloc(numBands *
sizeof (
double));
40 data->fwhm = (
double *) malloc(numBands *
sizeof (
double));
42 fprintf(
stderr,
"-E- %s line %d: unable to allocate scale/offset data for aviris\n",
62 gsl_interp_accel_free(
data->spl_acc);
76 int16_t
year, hour, minute,
doy;
80 double c0, c1, d0, d1, cov00, cov01, cov11, chisq, dth = 0.00087, th;
81 float xlon,
xlat, vel[3],
pos[3], pview[3], att[3] = {0, 0, 0}, coef[10],
87 "-E- %s line %d: Navigation needs at least 2 scan lines\n",
91 if ((ptr = fopen(navfile,
"r")) ==
NULL) {
92 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n", __FILE__,
98 data->lon = (
double*) malloc(
npix * nscans *
sizeof (
double));
100 data->lat = (
double*) malloc(
npix * nscans *
sizeof (
double));
101 if (!
range)
range = (
double*) malloc(nscans *
sizeof (
double));
102 if (!
lon)
lon = (
double*) malloc(nscans *
sizeof (
double));
103 if (!
lat)
lat = (
double*) malloc(nscans *
sizeof (
double));
104 for (
i = 0;
i < 3;
i++)
105 smat[
i] = (
float*) malloc(3 *
sizeof (
float));
107 while ((
result = fgets(
line, itemSize, ptr)) &&
i < nscans) {
110 "-E- %s line %d: unable to read all of the navigation data from AVIRIS nav file\n",
121 gsl_fit_linear(
range, 1,
lon, 1, nscans, &c0, &c1, &cov00, &cov01, &cov11,
123 gsl_fit_linear(
range, 1,
lat, 1, nscans, &d0, &d1, &cov00, &cov01, &cov11,
127 for (
i = 0;
i < nscans;
i++) {
131 minute = (
data->utc[
i] - hour) * 60;
132 sec = ((
data->utc[
i] - hour) * 60 - minute) * 60;
135 (hour * 3600. + minute * 60. + sec)), &
year, &
doy, &secondOfDay);
138 iyear = (int32_t)
year;
139 idoy = (int32_t)
doy;
141 for (
k = 0;
k < 3;
k++) {
147 for (ip = 0; ip <
npix; ip++) {
148 th = (ip - (
npix - 1) / 2) * dth;
178 char *inbasename, *
infile;
180 double *indata, *elev;
186 int year, month,
day, hour, minute;
193 aviris_t*
data =
file->private_data;
199 pos = strlen(inbasename);
201 fprintf(
stderr,
"-E- %s line %d: Not a avalid AVIRIS file %s\n",
202 __FILE__, __LINE__,
data->hdrfile);
206 data->wave = (
double *) malloc(
maxBands *
sizeof (
double));
207 data->fwhm = (
double *) malloc(
maxBands *
sizeof (
double));
208 data->gain = (
double *) malloc(
maxBands *
sizeof (
double));
210 sscanf(inbasename,
"f%2d%2d%2d", &
year, &month, &
day);
227 data->msec += sec * 1000;
229 printf(
"Date of AVIRIS flight: Y-%d M-%d D-%d\n",
year, month,
day);
231 if ((ptr = fopen(
data->hdrfile,
"r")) ==
NULL) {
232 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n",
233 __FILE__, __LINE__,
data->hdrfile);
238 int numLinesNeeded = 1;
239 int numSamplesNeeded = 1;
241 int waveLengthNeeded = 1;
243 int utmZoneNeeded = 1;
244 int eastingNeeded = 1;
245 int northingNeeded = 1;
246 int pixelSizeNeeded = 1;
247 int interleaveNeeded = 1;
248 int rotationAngNeeded = 1;
252 while ((numLinesNeeded ||
262 interleaveNeeded) &&
result) {
275 file->nscan = atoi(val0);
279 numSamplesNeeded = 0;
280 file->npix = atoi(val0);
285 numBands = atoi(val0);
286 data->numBands = numBands;
288 fprintf(
stderr,
"-E- %s line %d: number of bands (%d) from AVIRIS file > maxBands (%d)\n",
294 interleaveNeeded = 0;
295 if (strstr(val0,
"bip")) {
297 }
else if (strstr(val0,
"bil")) {
300 fprintf(
stderr,
"Interleave = %s is not supported\n", val0);
306 rotationAngNeeded = 0;
310 data->eastbyscan = -1;
312 data->eastbyscan = 1;
314 data->eastbyscan = 0;
319 data->pixelSize = atof(val0);
323 data->northing = atof(val0);
327 data->easting = atof(val0);
331 data->utmZone = atoi(val0);
335 waveLengthNeeded = 0;
349 fprintf(
stderr,
"-E- %s line %d: number of bands (%d) from AVIRIS file > AV_MAXBANDS (%d)\n",
370 fprintf(
stderr,
"-E- %s line %d: number of bands (%d) from AVIRIS file > AV_MAXBANDS (%d)\n",
392 fprintf(
stderr,
"-E- %s line %d: number of bands (%d) from AVIRIS file > AV_MAXBANDS (%d)\n",
401 if ((numLinesNeeded ||
407 fprintf(
stderr,
"-E- %s line %d: unable to read all of the required metadata from AVIRIS file\n",
411 int nscans =
file->nscan;
414 data->sena = (
double *) malloc(nscans *
npix *
sizeof (
double));
415 data->senz = (
double *) malloc(nscans *
npix *
sizeof (
double));
416 data->solz = (
double *) malloc(nscans *
npix *
sizeof (
double));
417 data->sola = (
double *) malloc(nscans *
npix *
sizeof (
double));
418 data->utc = (
double *) malloc(nscans *
npix *
sizeof (
double));
419 data->alt = (
float *) malloc(nscans *
sizeof (
float));
422 fprintf(
stderr,
"-E- %s line %d: unable to allocate sensor and solar angle data for AVIRIS\n",
429 if (
data->gainfile[0] !=
'\0') {
430 if ((ptr = fopen(
data->gainfile,
"r")) ==
NULL) {
431 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n",
432 __FILE__, __LINE__,
data->gainfile);
437 while ((
result = fgets(
line, itemSize, ptr)) &&
i < numBands) {
440 fprintf(
stderr,
"-E- %s line %d: unable to read all of the gain data from AVIRIS gain file\n",
452 if (
data->navfile[0] ==
'\0') {
456 numSamplesNeeded = 1;
458 infile = malloc((
pos + strlen(
"_obs.hdr")) *
sizeof (
char));
460 strcat(
infile,
"_obs.hdr");
463 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n",
464 __FILE__, __LINE__,
infile);
469 while (numLinesNeeded ||
478 if (!strcmp(tag,
"lines")) {
482 if (!strcmp(tag,
"samples")) {
483 numSamplesNeeded = 0;
492 infile = malloc((
pos + strlen(
"_lonlat_eph")) *
sizeof (
char));
494 strcat(
infile,
"_lonlat_eph");
496 printf(
"Reading lon/lat/elev information from file %s\n",
infile);
499 elev = (
double *) malloc(
data->wgs_nscan * sizeof (
double));
500 indata = (
double *) malloc(
data->wgs_nscan * num * sizeof (
double));
502 if (elev ==
NULL || indata ==
NULL) {
503 fprintf(
stderr,
"-E- %s line %d: unable to allocate lat/lon data for aviris\n",
509 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n",
510 __FILE__, __LINE__,
infile);
514 status = fread(indata,
sizeof (
double),
data->wgs_nscan*num, ptr);
516 printf(
"Wrong data read size: want %d got %d in file %s\n",
data->wgs_nscan*num,
status,
infile);
522 gsl_spline *
spline = gsl_spline_alloc(gsl_interp_cspline,
data->wgs_nscan);
524 double *dist = (
double *) calloc(
data->wgs_nscan, sizeof (
double));
525 double *
xlon = (
double *) calloc(
data->wgs_nscan, sizeof (
double));
526 double *
xlat = (
double *) calloc(
data->wgs_nscan, sizeof (
double));
528 data->spl_acc = gsl_interp_accel_alloc();
529 data->lon0 = indata[0];
530 data->lat0 = indata[1];
532 data->distmax = -999;
533 while (i < data->wgs_nscan * num) {
537 elev[
j] = indata[
i + 2];
543 gsl_sort2(dist, 1, elev, 1,
data->wgs_nscan);
544 data->distmin = dist[0];
545 data->distmax = dist[
data->wgs_nscan - 2];
548 gsl_spline_init(
spline, dist, elev,
data->wgs_nscan);
559 indataf = (
float *) malloc(
file->npix * sizeof (
float)*num);
562 fprintf(
stderr,
"-E- %s line %d: unable to allocate sensor and solar angle data for AVIRIS\n",
567 infile = malloc((
pos + strlen(
"_obs_ort")) *
sizeof (
char));
569 strcat(
infile,
"_obs_ort");
571 printf(
"Reading sensor and solar angles information from file %s\n",
infile);
574 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n",
575 __FILE__, __LINE__,
infile);
579 for (
j = 0;
j <
file->nscan;
j++) {
580 status = fread(indataf,
sizeof (
float), num *
file->npix, ptr);
582 fprintf(
stderr,
"-E- %s line %d: AVIRIS Wrong sensor and solar data read size: want %d got %d\n",
587 for (
k = 0;
k <
file->npix;
k++) {
600 sprintf(projStr,
"+proj=utm +zone=%d +ellps=WGS84 +datum=WGS84 +units=m +no_defs ",
604 pj = proj_create_crs_to_crs(PJ_DEFAULT_CTX,
606 "+proj=longlat +ellps=WGS84 +datum=WGS84",
609 printf(
"Error - AVIRIS first PROJ projection failed to init\n");
612 data->pj = proj_normalize_for_visualization(PJ_DEFAULT_CTX, pj);
614 printf(
"Error - AVIRIS visualization PROJ projection failed to init\n");
624 if (!
data->have_gain) {
625 infile = malloc((
pos + strlen(
".gain")) *
sizeof (
char));
629 printf(
"Attempting to read gain information from file %s\n",
infile);
632 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n Will assume gains.\n",
633 __FILE__, __LINE__,
infile);
634 for (
k = 0;
k < numBands;
k++) {
635 if (
k < 110)
data->gain[
i] = 300;
636 else if (
k < 160)
data->gain[
i] = 600;
637 else data->gain[
i] = 1200;
643 fprintf(
stderr,
"-E- %s line %d: unable to allocate gain data for AVIRIS\n",
647 for (
i = 0;
i < numBands && fscanf(ptr,
"%lf %d", (
data->gain +
i), &
k);
i++) {
656 infile = malloc(FILENAME_MAX *
sizeof (
char));
657 if (
data->imgfile[0] ==
'\0') {
659 strcat(
infile,
"_sc01_ort_img");
663 printf(
"Opening AVIRIS image file %s\n",
infile);
666 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n",
667 __FILE__, __LINE__,
infile);
681 static double last_good_hour = 18;
682 static int firstCall = 1;
687 static int swap, *ibndx, *ipbndx;
691 aviris_t*
data = (aviris_t*)
file->private_data;
696 printf(
"l1file->nbands = %d\n", (
int)
file->nbands);
699 for (ip = 0; ip <
npix; ip++) {
700 l1rec->pixnum[ip] = ip;
701 l1rec->flags[ip] = 0;
709 Lt = (
float*) malloc(
npix *
data->numBands * sizeof (
float));
711 fprintf(
stderr,
"-E- %s line %d: Out of Memory allocating buffer array in readl1_aviris.\n",
716 ipbndx = (
int*) malloc(
npix *
file->nbands * sizeof (
int));
718 fprintf(
stderr,
"-E- %s line %d: Out of Memory allocating buffer array in readl1_aviris.\n",
723 ibndx = (
int*) malloc(
file->nbands * sizeof (
int));
725 fprintf(
stderr,
"-E- %s line %d: Out of Memory allocating buffer array in readl1_aviris.\n",
732 for (ib = 0; ib < 31; ib++) {
736 for (ib = 33; ib < 95; ib++) {
740 for (ib = 97; ib < 159; ib++) {
744 for (ib = 161; ib < 206; ib++) {
748 file->fwhm = (
float*) malloc(
data->numBands * sizeof (
float));
750 fprintf(
stderr,
"-E- %s line %d: Out of Memory allocating fwhm array in readl1_aviris.\n",
755 for (ib = 0; ib < ibl1; ib++)
file->fwhm[ib] =
data->fwhm[ibndx[ib]] / 1000.;
758 for (ip = 0; ip <
npix; ip++) {
760 for (ib = 0; ib < 31; ib++) {
761 ipb = ip *
file->nbands + ibl1;
762 switch (
data->interleave) {
764 ipb_av = ip *
data->numBands + ib;
767 ipb_av = ib *
npix + ip;
770 ipbndx[ipb] = ipb_av;
773 for (ib = 33; ib < 95; ib++) {
774 ipb = ip *
file->nbands + ibl1;
775 switch (
data->interleave) {
777 ipb_av = ip *
data->numBands + ib;
780 ipb_av = ib *
npix + ip;
783 ipbndx[ipb] = ipb_av;
786 for (ib = 97; ib < 159; ib++) {
787 ipb = ip *
file->nbands + ibl1;
788 switch (
data->interleave) {
790 ipb_av = ip *
data->numBands + ib;
793 ipb_av = ib *
npix + ip;
796 ipbndx[ipb] = ipb_av;
799 for (ib = 161; ib < 206; ib++) {
800 ipb = ip *
file->nbands + ibl1;
801 switch (
data->interleave) {
803 ipb_av = ip *
data->numBands + ib;
806 ipb_av = ib *
npix + ip;
809 ipbndx[ipb] = ipb_av;
818 l1rec->l1file->sensorID =
file->sensorID;
820 if (!
data->have_nav) {
825 if (hour < 0) hour = last_good_hour;
827 last_good_hour = hour;
840 for (ip = 0; ip <
npix; ip++) {
842 l1rec->pixnum[ip] = ip;
846 c_out = proj_trans(
data->pj, PJ_FWD,
c);
848 if(isfinite(c_out.xy.x) && isfinite(c_out.xy.y)) {
849 l1rec->lon[ip] = c_out.xy.x;
850 l1rec->lat[ip] = c_out.xy.y;
852 l1rec->lon[ip] = -999.0;
853 l1rec->lat[ip] = -999.0;
856 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
857 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0)
858 l1rec->navfail[ip] = 1;
885 if (dist >
data->distmax) {
886 printf(
"lat/lon > range of wgs coordinates - using altitude of nearest neighbor\n");
887 dist =
data->distmax;
888 }
else if (dist < data->distmin) {
889 printf(
"lat/lon < range of wgs coordinates - using altitude of nearest neighbor\n");
890 dist =
data->distmin;
896 for (ip = 0; ip <
npix; ip++) {
903 if (
l1rec->lon[ip] < -181.0 ||
l1rec->lon[ip] > 181.0 ||
904 l1rec->lat[ip] < -91.0 ||
l1rec->lat[ip] > 91.0)
905 l1rec->navfail[ip] = 1;
909 sec = ((
data->utc[
recnum] - hour) * 60 - minute) * 60;
911 (hour * 3600. + minute * 60. + sec));
915 for (ipb = 0; ipb <
npix *
file->nbands; ipb++)
916 l1rec->Lt[ipb] = Lt[ipbndx[ipb]];
922 aviris_t*
data = (aviris_t*)
file->private_data;
927 free(
file->private_data);
real(single), dimension(:,:), allocatable longitude
void nav_gd_orient(float *pos, float *vel, float *att, float *smat[], float *coef)
void nav_get_geonav(float *sunr, float *pos, float *pview, float *coef, float *smat[], float *xlon, float *xlat, float *solz, float *sola, float *senz, float *sena)
void trimBlanks(char *str)
real(single), dimension(:,:), allocatable latitude
subroutine spline(s, x, y, n, in, t, il, iu, vl, vu, e, u)
void readNextLine_jpl(FILE *fp, char *tag, char *val)
int readl1_aviris(filehandle *file, int32_t recnum, l1str *l1rec)
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
int endianess(void)
determine endianess
char * getinbasename_av(char *file)
int readBinScanLine_int2(float *Lt, int32_t recnum, int32_t npix, double *gain, int nbands, int interleave, int swap, FILE *ptr)
void get_aviris_nav_data(char *navfile, int32_t nscans, int32_t npix, aviris_t *data)
void unix2yds(double usec, short *year, short *day, double *secs)
int openl1_aviris(filehandle *file)
integer, parameter double
instead the metadata field ProcessingEnvinronment is filled in from the output of a call to the POSIX compliant function uname from within the L1B code A small bug in L1B_Tables an incorrect comparison of RVS coefficients for TEBs to RVS coefficients for RSBs was being made This was replaced with a comparison between TEB coefficients This error never resulted in an incorrect RVS correction but did lead to recalculating the coefficients for each detector in a thermal band even if the coefficients were the same for all detectors To reduce to overall size of the reflective LUT HDF fill values were eliminated from all LUTs previously dimensioned where and where NUM_TIMES is the number of time dependent table pieces In Preprocess a small error where the trailing dropped scan counter was incremented when the leading dropped scan counter should have been was fixed This counter is internal only and is not yet used for any chiefly to casting of were added to make it LINUX compatible Output of code run on LINUX machines displays differences of at most scaled sector rotation
aviris_t * createPrivateData_aviris(int numBands)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
float xlon[LAC_PIXEL_NUM]
void ymdhms2ydmsec(int yy, int mm, int dd, int hh, int mn, int sc, int32_t *year, int32_t *day, int32_t *msec)
int closel1_aviris(filehandle *file)
char * checkTagLine(char *line, char *tag)
double angular_distance(double lat1, double lon1, double lat2, double lon2)
double ymds2unix(short year, short month, short day, double secs)
for(i=0;i< NROOTS;i++) s[i]
void nav_get_pos(float lat, float lon, float alt, float *p)
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 as required for compatibility with version of the SDP toolkit Corrected test output file names to end in per delivery and then split off a new MYD_PR03 pcf file for Aqua Added AssociatedPlatformInstrumentSensor to the inventory metadata in MOD01 mcf and MOD03 mcf Created new versions named MYD01 mcf and MYD03 where AssociatedPlatformShortName is rather than Terra The program itself has been changed to read the Satellite Instrument validate it against the input L1A and LUT and to use it determine the correct files to retrieve the ephemeris and attitude data from Changed to produce a LocalGranuleID starting with MYD03 if run on Aqua data Added the Scan Type file attribute to the Geolocation copied from the L1A and attitude_angels to radians rather than degrees The accumulation of Cumulated gflags was moved from GEO_validate_earth_location c to GEO_locate_one_scan c
double getValidAngle(double *ang, int32_t npix, int32_t skip)
void freePrivateData_aviris(aviris_t *data)
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
int sunpos(double tjd, double r[3], char **errstr)
void nav_get_vel(float ilat, float mlat, float ilon, float mlon, float *vel)
void l_sun_(int *iyr, int *iday, double *sec, float *sunr, float *rs)
void readWavInfo_jpl(FILE *fp, char *tag, char *val)