Go to the documentation of this file.
20 #define MAXLINESZ 4290
23 static double *lat, *lon;
34 void l_sun_(
int *
iyr,
int *iday,
double *sec,
float *sunr,
float *rs);
40 prism4ocia_t*
data = (prism4ocia_t*) calloc(1,
sizeof (prism4ocia_t));
42 fprintf(
stderr,
"-E- %s line %d: unable to allocate private data for prism\n",
47 data->wave = (
double *) malloc(numBands *
sizeof (
double));
48 data->fwhm = (
double *) malloc(numBands *
sizeof (
double));
49 data->gain = (
double *) malloc(numBands *
sizeof (
double));
51 fprintf(
stderr,
"-E- %s line %d: unable to allocate scale/offset data for prism\n",
70 gsl_interp_accel_free(
data->spl_acc);
89 char *
line, val1[itemSize];
91 int year, month,
day, hour, minute, second;
92 float knts2mps = 0.51444444444;
99 int cnt, linelength, itmp;
104 pos = strlen(inbasename);
106 fprintf(
stderr,
"-E- %s line %d: Not a avalid prism file %s\n",
114 *
data = (prism4ocia_t*) malloc(
sizeof (prism4ocia_t));
116 fprintf(
stderr,
"-E- %s line %d: unable to allocate private data for Prism\n",
121 (*data)->wave = (
double *) malloc(
maxBands *
sizeof (
double));
122 (*data)->fwhm = (
double *) malloc(
maxBands *
sizeof (
double));
123 (*data)->gain = (
double *) malloc(
maxBands *
sizeof (
double));
124 if ((*data)->wave ==
NULL || (*data)->fwhm ==
NULL) {
125 fprintf(
stderr,
"-E- %s line %d: unable to allocate scale/offset data for aviris\n",
132 sscanf(inbasename,
"prm%4d%2d%2dt%2d%2d%2d", &year, &month, &
day, &hour, &minute, &second);
141 &temp->year, &temp->doy, &temp->msec);
144 temp->stime =
ymds2unix(year, month,
day, hour * 3600.0 + minute * 60.0 + second);
146 printf(
"Date of prism flight: %s\n",
unix2isodate(temp->stime,
'G'));
149 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n",
154 int numLinesNeeded = 1;
155 int numSamplesNeeded = 1;
157 int utmZoneNeeded = 1;
158 int eastingNeeded = 1;
159 int northingNeeded = 1;
160 int pixelSizeNeeded = 1;
161 int interleaveNeeded = 1;
162 int rotationAngNeeded = 1;
163 int EndTimeNeeded = 1;
165 int waveLengthNeeded = 1;
169 while (numLinesNeeded ||
185 fprintf(
stderr,
"-E- %s line %d: unable to read all of the required metadata from prism file\n",
194 printf(
"lines=%d\n", temp->nscan);
197 numSamplesNeeded = 0;
199 printf(
"samples=%d\n", temp->npix);
203 temp->alt = atof(val0) * ft2m;
204 printf(
"Altitude=%lf\n", temp->alt);
208 sscanf(val0,
"%2d%2d", &hour, &minute);
209 printf(
"End hour=%d minute=%d\n", hour, minute);
210 temp->etime =
ymds2unix(year, month,
day, hour * 3600.0 + minute * 60.0);
211 printf(
"End Time=%s\n",
unix2isodate(temp->etime,
'G'));
216 temp->numBands = numBands;
218 fprintf(
stderr,
"-E- %s line %d: number of bands (%d) from prism file > maxBands (%d)\n",
219 __FILE__, __LINE__, numBands,
maxBands);
222 printf(
"numBands=%d\n", temp->numBands);
225 interleaveNeeded = 0;
226 if (strstr(val0,
"bip")) {
227 temp->interleave =
BIP;
228 }
else if (strstr(val0,
"bil")) {
229 temp->interleave =
BIL;
231 fprintf(
stderr,
"Interleave = %s is not supported\n", val0);
234 printf(
"Interleave=%d\n", temp->interleave);
237 waveLengthNeeded = 0;
244 temp->wave[
i] = 1000.0 *
tmp;
245 printf(
"i=%d wave=%f\n",
i, temp->wave[
i]);
264 temp->fwhm[
i] = 1000.0 *
tmp;
265 printf(
"i=%d fwhm=%f\n",
i, temp->fwhm[
i]);
276 linelength = strlen(
line);
277 if (dupline) free(dupline);
278 if ((dupline = (
char *) malloc(linelength *
sizeof (
char))) ==
NULL) {
280 "-E- %s line %d: Memory allocation failure.\n",
285 result = strtok(dupline,
",");
289 temp->easting = atof(
result);
293 temp->northing = atof(
result);
297 temp->pixelSize = atof(
result);
301 temp->utmZone = strtol(
result, &iptr, 10);
307 printf(
">>%d) %s\n", cnt,
result);
312 rotationAngNeeded = 0;
313 temp->rotation = atof(val0);
315 printf(
"Rotation angle expected in line: %s\n", val0);
318 printf(
"Rotation/easting/northing/pixsize/utmzone=%f/%lf/%lf/%lf/%d\n", temp->rotation, temp->easting, temp->northing, temp->pixelSize, temp->utmZone);
351 temp->sena = (
float *) malloc(temp->npix * sizeof (
float));
352 temp->senz = (
float *) malloc(temp->npix * sizeof (
float));
353 temp->solz = (
float *) malloc(temp->npix * sizeof (
float));
354 temp->sola = (
float *) malloc(temp->npix * sizeof (
float));
355 temp->utc = (
float *) malloc(temp->npix * sizeof (
float));
356 temp->lon = (
double *) malloc(temp->npix * sizeof (
double));
357 temp->lat = (
double *) malloc(temp->npix * sizeof (
double));
358 temp->Lt = (
float *) malloc(temp->numBands * temp->npix * sizeof (
float));
359 if (temp->sena ==
NULL || temp->senz ==
NULL || temp->sola ==
NULL || temp->solz ==
NULL || temp->Lt ==
NULL || temp->lon ==
NULL || temp->lat ==
NULL) {
360 fprintf(
stderr,
"-E- %s line %d: unable to allocate sensor and solar angle data for AVIRIS\n",
365 for (
i = 0;
i < numBands;
i++) {
370 infile = malloc((
pos + strlen(
"_rdn_ort")) *
sizeof (
char));
372 strcat(
infile,
"_rdn_ort");
373 printf(
"Opening prism image file %s\n",
infile);
375 if ((temp->av_fp = fopen(
infile,
"rb")) ==
NULL) {
376 fprintf(
stderr,
"-E- %s line %d: unable to open %s\n",
377 __FILE__, __LINE__,
infile);
382 sprintf(projStr,
"+proj=utm +zone=%d +ellps=WGS84 +datum=WGS84 +units=m +no_defs ",
385 if (!(temp->pj_ortho = pj_init_plus(projStr))) {
386 printf(
"Error - prism first projection failed to init\n");
389 if (!(temp->pj_latlong = pj_latlong_from_proj(temp->pj_ortho))) {
390 fprintf(
stderr,
"-E- %s line %d: prism latlon projection failed to init\n",
395 lat = (
double *) malloc(temp->npix * sizeof (
double));
396 lon = (
double *) malloc(temp->npix * sizeof (
double));
406 int status, min_msec = 86401 * 1000, max_msec = -1;
408 static double last_good_hour = 18;
409 static int firstCall = 1;
413 int16_t year, doy, month,
day, hour, minute;
432 data->hour = secondOfDay / 3600;
433 data->min = (secondOfDay -
data->hour * 3600) / 60;
434 data->sec = secondOfDay -
data->hour * 3600 -
data->min * 60;
436 for (ip = 0; ip <
npix; ip++) {
447 fprintf(
stderr,
"-E- %s line %d: Don't have sensor latitude for geometry calculation\n",
455 fprintf(
stderr,
"-E- %s line %d: Don't have sensor longitude for geometry calculation\n",
464 iyear = (int32_t) year;
465 idoy = (int32_t) doy;
468 for (
i = 0;
i < 3;
i++) {
473 for (ip = 0; ip <
npix; ip++) {
476 if (isnan(lat[ip])) lat[ip] =
SKIP;
477 if (isnan(lon[ip])) lon[ip] =
SKIP;
478 data->lat[ip] = lat[ip];
479 data->lon[ip] = lon[ip];
498 if (pj_transform(
data->pj_ortho,
data->pj_latlong, numPoints, 1,
x,
y,
NULL)) {
499 fprintf(
stderr,
"-E- %s line %d: AVIRIS proj4 transformation blew up\n",
503 for (
i = 0;
i < numPoints;
i++) {
522 float angle = *fillangle;
524 for (
i = 0;
i <
npix && ang[
i] <= skip;
i++)
541 dist = dist > 1 ? 1 : dist;
542 dist = dist<-1 ? -1 : dist;
551 return (deg *
M_PI / 180);
556 if (pj_transform(
data->pj_ortho,
data->pj_latlong, numPoints, 1,
x,
y,
NULL)) {
557 fprintf(
stderr,
"-E- %s line %d: prism proj4 transformation blew up\n",
561 for (
i = 0;
i < numPoints;
i++) {
void trimBlanks(char *str)
int read_prism(prism4ocia_t *data, int32_t recnum)
prism4ocia_t * createPrivateData_pr(int numBands, int32_t nscan, int32_t npix)
double deg2rad(double deg)
prism4ocia_t * open_prism(char *filename, prism4ocia_t **data)
void get_zenaz(float *pos, float lon, float lat, float *senz, float *sena)
real(single), dimension(:,:), allocatable longitude
char * getinbasename(char *file)
void prism4ocia_proj4_convert(prism4ocia_t *data, int32_t numPoints, double *x, double *y)
real(single), dimension(:,:), allocatable latitude
void unix2ymds(double usec, int16_t *year, int16_t *mon, int16_t *day, double *secs)
void getPosVec(float lat, float lon, float alt, double *pos)
char * checknspTagLine(char *line, char *tag)
int close_prism(prism4ocia_t *data)
void unix2yds(double usec, short *year, short *day, double *secs)
char filename[FILENAME_MAX]
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
float getValidOrcaAngle(float *ang, int32_t npix, int32_t skip, float *fillangle)
int checkTagLine_i(char *linein, char *tag)
void ymdhms2ydmsec(int yy, int mm, int dd, int hh, int mn, int sc, int32_t *year, int32_t *day, int32_t *msec)
char * checkTagLine(char *linein, char *tag)
int readBinScanLine4Ocip_float(float *Lt, int32_t recnum, int32_t npix, double *gain, int nbands, int numBands, int interleave, int swap, FILE *ptr)
char * unix2isodate(double dtime, char zone)
double angular_distance(double lat1, double lon1, double lat2, double lon2)
double ymds2unix(short year, short month, short day, double secs)
int readBinScanLine_float(float *Lt, int32_t recnum, int32_t npix, double *gain, int nbands, int numBands, int interleave, int swap, FILE *ptr)
void prism_proj4_convert(prism4ocia_t *data, int numPoints, double *x, double *y)
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 l_sun_(int *iyr, int *iday, double *sec, float *sunr, float *rs)
void freePrivateData_pr(prism4ocia_t *data)