int main (int argc, char *argv[]) { char inDataName[255], inMetaName[255], *baseName; /* cla parsing */ handle_common_asf_args(&argc, &argv, "c2p"); /* After extracting the optional flags, should have 2 args left */ if (argc != 3) usage(argv[0]); /* Make sure input and output names are different */ if (strcmp(argv[1],argv[2])==SAME) { printf("c2p: Input and output names cannot be the same. Exiting.\n"); exit(EXIT_FAILURE); } // Assign filenames and check their existence baseName = (char *) MALLOC(sizeof(char)*255); baseName = get_basename(argv[1]); sprintf(inDataName, "%s.img", baseName); if (!fileExists(inDataName)) asfPrintError("Data file (%s) does not exist.\n", inDataName); sprintf(inMetaName, "%s.meta", baseName); if (!fileExists(inMetaName)) asfPrintError("Metadata file (%s) does not exist.\n", inMetaName); /* Do it! */ c2p_ext(inDataName, inMetaName, argv[2], FALSE, FALSE); if (logflag) FCLOSE(fLog); return 0; }
size_t FREAD_CHECKED(void *ptr, size_t size, size_t nitems, FILE *stream, int short_ok) { size_t ret = 0; if (ptr == NULL || ptr < 0) { asfPrintError("Programmer error: Invalid data pointer passed to FREAD_CHECKED\n"); } if (stream == NULL || stream < 0) { asfPrintError("Programmer error: Invalid FILE stream passed to FREAD_CHECKED\n"); } if (size < 1) { asfPrintError("Programmer error: Invalid data size (%d) passed to FREAD_CHECKED\n", size); } if (nitems < 0) { asfPrintError("Programmer error: Invalid number of items (%d) to FREAD_CHECKED\n", nitems); } ret = fread(ptr, size, nitems, stream); if (ret < nitems && !short_ok) { asfPrintError("File too short. FREAD_CHECKED attempted to read %d bytes past end of file\n", (nitems * size) - ret); } return ret; }
static void add_pixels(FloatImage *out, char *file, double start_x, double start_y, double per_x, double per_y) { meta_parameters *meta = meta_read(file); if (!meta) { asfPrintError("Couldn't read metadata for: %s!\n", file); } // figure out where in the giant image these pixels will go int start_line, start_sample; // this should work even if per_x / per_y are negative... start_sample = (int) ((meta->projection->startX - start_x) / per_x + .5); start_line = (int) ((meta->projection->startY - start_y) / per_y + .5); int ns = meta->general->sample_count; int nl = meta->general->line_count; asfPrintStatus(" Location in combined is S:%d-%d, L:%d-%d\n", start_sample, start_sample + ns, start_line, start_line + nl); if (start_sample + ns > out->size_x || start_line + nl > out->size_y) { asfPrintError("Image extents were not calculated correctly!\n"); } FILE *img = fopenImage(file, "rb"); if (!img) { asfPrintError("Couldn't open image file: %s!\n", file); } float *line = MALLOC(sizeof(float)*ns); int y; for (y=0; y<nl; ++y) { get_float_line(img, meta, y, line); int x; for (x=0; x<ns; ++x) { float v = line[x]; // don't write out "no data" values if (v != meta->general->no_data) float_image_set_pixel(out, x + start_sample, y + start_line, v); } asfLineMeter(y, nl); } fclose(img); free(line); meta_free(meta); }
void filter_srfs(char *sensor, char *beam_mode, char *input_dir, char *output_dir) { struct dirent *dp; struct stat statbuf; DIR *dir; int nFiles= 0; char file_name[25], source[1024], target[1024]; // Some more error checking on beam modes if (strcmp_case(sensor, "R1") == 0) { if (strcmp_case(beam_mode, "FN1") != 0 && strcmp_case(beam_mode, "FN2") != 0 && strcmp_case(beam_mode, "FN3") != 0 && strcmp_case(beam_mode, "FN4") != 0 && strcmp_case(beam_mode, "FN5") != 0 && strcmp_case(beam_mode, "ST1") != 0 && strcmp_case(beam_mode, "ST2") != 0 && strcmp_case(beam_mode, "ST3") != 0 && strcmp_case(beam_mode, "ST4") != 0 && strcmp_case(beam_mode, "ST5") != 0 && strcmp_case(beam_mode, "ST6") != 0 && strcmp_case(beam_mode, "ST7") != 0) asfPrintError("Unknown beam mode '%s' for sensor '%s'.\n", beam_mode, sensor); } else if (strcmp_case(sensor, "E1") == 0 || strcmp_case(sensor, "E2") == 0 || strcmp_case(sensor, "J1") == 0) { if (strcmp_case(beam_mode, "STD") != 0) asfPrintError("Unknown beam mode '%s' for sensor '%s'.\n", beam_mode, sensor); } // Read directory for scan results files of sensor + beam mode asfPrintStatus("Filtering scan results file directory ...\n\n"); chdir(input_dir); dir = opendir(input_dir); while ((dp = readdir(dir)) != NULL) { if (stat(dp->d_name, &statbuf) == -1) continue; sprintf(file_name, "%s", dp->d_name); if (get_basic_info(file_name, sensor, beam_mode) && !S_ISDIR(statbuf.st_mode)) { sprintf(source, "%s/%s", input_dir, file_name); sprintf(target, "%s/%s", output_dir, file_name); fileCopy(source, target); nFiles++; asfPrintStatus("\rNumber of scan results files read: %6d", nFiles); } } closedir(dir); printf("\n"); }
static GdkPixbuf * make_small_image(int force, ThumbnailData *tdata, ImageInfo *ii) { if (!pixbuf_small || force) { if (pixbuf_small) { g_object_unref(pixbuf_small); pixbuf_small = NULL; } if (!tdata) tdata = get_thumbnail_data(ii); int tsx = tdata->size_x; int tsy = tdata->size_y; // Create the pixbuf GdkPixbuf *pb = gdk_pixbuf_new_from_data(tdata->data, GDK_COLORSPACE_RGB, FALSE, 8, tsx, tsy, tsx*3, destroy_pb_data, NULL); if (!pb) asfPrintError("Failed to create the small pixbuf.\n"); // Scale down to the size we actually want, using the built-in Gdk // scaling method, much nicer than what we did above // Must ensure we scale the same in each direction double scale_y = (double)tsy / THUMB_SIZE; double scale_x = (double)tsx / THUMB_SIZE; double scale = scale_y > scale_x ? scale_y : scale_x; small_image_x_dim = tsx / scale; small_image_y_dim = tsy / scale; //printf("Scaling to %dx%d\n", small_image_x_dim, small_image_y_dim); pixbuf_small = gdk_pixbuf_scale_simple(pb, small_image_x_dim, small_image_y_dim, GDK_INTERP_BILINEAR); gdk_pixbuf_unref(pb); if (!pixbuf_small) asfPrintError("Failed to allocate scaled thumbnail pixbuf\n"); free(tdata); } GdkPixbuf *pb2 = gdk_pixbuf_copy(pixbuf_small); put_bounding_box(pb2, ii); return pb2; }
int fftMatch_proj(char *inFile1, char *inFile2, float *offsetX, float *offsetY, float *certainty) { // Determine the offsets based on metadata meta_parameters *refMeta = meta_read(inFile1); if (!refMeta->projection) asfPrintError("File (%s) is not map projected!\n", inFile1); meta_parameters *testMeta = meta_read(inFile2); if (!testMeta->projection) asfPrintError("File (%s) is not map projected!\n", inFile2); double testStartX = testMeta->projection->startX + testMeta->general->start_sample*testMeta->projection->perX; double testStartY = testMeta->projection->startY + testMeta->general->start_line*testMeta->projection->perY; double refStartX = refMeta->projection->startX + refMeta->general->start_sample*refMeta->projection->perX; double refStartY = refMeta->projection->startY + refMeta->general->start_line*refMeta->projection->perY; float diffX = (testStartX - refStartX) / testMeta->projection->perX; float diffY = (testStartY - refStartY) / testMeta->projection->perY; meta_free(refMeta); meta_free(testMeta); // Figure out what FFT parameters are going to be int size = 512; double tol = -1; float diff; if (fabs(diffX) > fabs(diffY)) diff = fabs(diffX); else diff = fabs(diffY); while ((size/4) < diff) { size *= 2; } int overlap = size / 2; // Determine the offsets based on mapping float offX, offY, cert; asfPrintStatus("Determing offsets by FFT matching\n\n"); fftMatch_gridded(inFile1, inFile2, NULL, &offX, &offY, &cert, size, tol, overlap); *certainty = cert; // Compare both offsets *offsetX = diffX - offX; *offsetY = diffY - offY; return (0); }
int to_sr_pixsiz(const char *infile, const char *outfile, double pixel_size) { meta_parameters *inMeta = meta_read(infile); int ret; if (inMeta->sar && inMeta->sar->image_type == 'G') { // ground range image ret = gr2sr_pixsiz(infile, outfile, pixel_size); } else if (inMeta->sar && inMeta->sar->image_type == 'S') { // already a slant range image, just copy it copyImgAndMeta(infile, outfile); ret = 0; // success } else if ((inMeta->sar && inMeta->sar->image_type == 'P') || (inMeta->projection)) { // projected image ret = proj_to_sr(infile, outfile, pixel_size); } else if (inMeta->sar && inMeta->transform && inMeta->sar->image_type == 'R') { // georeferenced, ALOS most likely ret = proj_to_sr(infile, outfile, pixel_size); } else { asfPrintError("Couldn't figure out what kind of image this is.\n"); ret = 1; } meta_free(inMeta); return ret; }
static void check(int num, double a, double b) { if (a==b || fabs(a-b)<0.0000001) return; asfPrintError("Failed test %d -- %f %f\n", num, a, b); }
/****************************************************************************** * fileCopy: * Copy the file specified by "src" to the file specified by "dst". Error * checking is taken care of by the caplib functions (ie FOPEN, FWRITE, etc) */ void fileCopy(const char *src, const char *dst) { char buffer[BUFFER_SIZE]; FILE *srcFp; FILE *dstFp; unsigned int amount; srcFp = FOPEN( src, "rb" ); dstFp = FOPEN( dst, "wb" ); do { amount = fread( buffer, sizeof(char), BUFFER_SIZE, srcFp ); if (amount) { int a = fwrite( buffer, sizeof(char), amount, dstFp ); if (a<amount) { asfPrintError("Error copying file %s -> %s\n" "Only %d of %d bytes written.\n%s\n", src, dst, a, amount, strerror(errno)); } } /* when amount read is < BUFSZ, copy is done */ } while (amount == BUFFER_SIZE); FCLOSE(srcFp); FCLOSE(dstFp); }
int ll2rb(double lon_r, double lat_r, double lon_t, double lat_t, double *range, double *bearing) { double radius = 1.0; double x1, y1, z1, x2, y2, z2, x3, y3, z3; // Fix for someone who passed in longitudes that go from -180 to +180 instead of 0-360 double _lon_r = (lon_r < 0.0) ? lon_r + 360.0 : lon_r; double _lon_t = (lon_t < 0.0) ? lon_t + 360.0 : lon_t; if (lat_r < -90.0 || lat_r > 90.0 || lat_t < -90.0 || lat_t > 90.0 || _lon_r < 0.0 || lon_r >= 360.0 || _lon_t < 0.0 || lon_t >= 360.0) { asfPrintError("ll2rb() latitude/longitude out of range. Found:\n" " (lat_r, lon_r) = (%0.2f, %0.2f)\n" " (lat_t, lon_t) = (%0.2f, %0.2f)\n", lat_r, lon_r, lat_t, lon_t); } polrec3d(radius, (90.0 - lat_t) * D2R, _lon_t * D2R, &x1, &y1, &z1); rot_3d(Z_AXIS, x1, y1, z1, -(180.0 - _lon_r) * D2R, &x2, &y2, &z2); rot_3d(Y_AXIS, x2, y2, z2, -(90.0 - lat_r) * D2R, &x3, &y3, &z3); recpol3d(x3, y3, z3, &radius, range, bearing); g_assert(*bearing > 0.0); // Should never happen. Drill down to recpol() below. g_assert((*bearing * R2D) <= 360.0); // Ditto... *bearing = fmod(360.0 - (*bearing * R2D), 360.0); return 0; }
// Assumes angle is in radians. Axis is defined by X = 1, Y = 2, and Z = 3 int rot_3d(int axis, double x, double y, double z, double angle, double *xrot, double *yrot, double *zrot) { double c = cos(angle); double s = sin(angle); switch (axis) { case 1: // Rotate around the X-Axis *xrot = x; *yrot = c*y + s*z; *zrot = -s*y + c*z; break; case 2: // Rotate around the Y-Axis *xrot = c*x - s*z; *yrot = y; *zrot = s*x + c*z; break; case 3: // Rotate around the Z-Axis *xrot = c*x + s*y; *yrot = -s*x + c*y; *zrot = z; break; default: // Should never reach here (duhhhh) asfPrintError("Bad axis number (%d). Use 1 for X axis, 2 for Y axis, and 3 for Z axis.\n", axis); break; } return 0; }
// Fit a polynomial to a function using linear least-squares // Unlike the IDL function poly_fit, this routine is limited to degree==2 double *poly_fit(double *y, double *x, int ix1, int ix2, int ix3, int degree, double *fit) { g_assert(y != NULL && x != NULL); if (degree != 2) asfPrintError("poly_fit() only supports 2nd degree polynomial fits...\n"); double *coeffs = (double *)MALLOC(3 * sizeof(double)); double x1 = x[ix1]; double x2 = x[ix2]; double x3 = x[ix3]; double y1 = y[ix1]; double y2 = y[ix2]; double y3 = y[ix3]; double M = y1 - y2; double N = y3 - y2; double P = x1 - x2; double Q = x3 - x1; double R = x3 - x2; double S = x2*x2 - x1*x1; coeffs[0] = (N/(R*Q)) - (M/(P*Q)); // a coeffs[1] = (M + coeffs[0]*S)/P; // b coeffs[2] = y1 - coeffs[0]*x1*x1 - coeffs[1]*x1; // c return coeffs; }
static float interp_demData(float *demData, int nl, int ns, double l, double s) { if (l<0 || l>=nl-1 || s<0 || s>=ns-1) { return 0; } int ix = (int)s; int iy = (int)l; int bilinear = l<3 || l>=nl-3 || s<3 || s>=ns-3; //int bilinear = 1; if (bilinear) { float p00 = demData[ix + ns*(iy )]; float p10 = demData[ix+1 + ns*(iy )]; float p01 = demData[ix + ns*(iy+1)]; float p11 = demData[ix+1 + ns*(iy+1)]; return (float)bilinear_interp_fn(s-ix, l-iy, p00, p10, p01, p11); } else { double ret, x[4], y[4], xi[4], yi[4]; int ii; for (ii=0; ii<4; ++ii) { y[0] = demData[ix-1 + ns*(iy+ii-1)]; y[1] = demData[ix + ns*(iy+ii-1)]; y[2] = demData[ix+1 + ns*(iy+ii-1)]; y[3] = demData[ix+2 + ns*(iy+ii-1)]; x[0] = ix - 1; x[1] = ix; x[2] = ix + 1; x[3] = ix + 2; gsl_interp_accel *acc = gsl_interp_accel_alloc (); gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, 4); gsl_spline_init (spline, x, y, 4); yi[ii] = gsl_spline_eval_check(spline, s, acc); gsl_spline_free (spline); gsl_interp_accel_free (acc); xi[ii] = iy + ii - 1; } gsl_interp_accel *acc = gsl_interp_accel_alloc (); gsl_spline *spline = gsl_spline_alloc (gsl_interp_cspline, 4); gsl_spline_init (spline, xi, yi, 4); ret = gsl_spline_eval_check(spline, l, acc); gsl_spline_free (spline); gsl_interp_accel_free (acc); return (float)ret; } asfPrintError("Impossible."); }
/******************************************************* * slantRange2groundPixel: * Calculate the ground range pixel from the total slant * range*/ int slantRange2groundPixel(meta_parameters *meta,double slant) { double a,x,y,Gr0, GrX; double Rsc, Re; int groundPixel; Rsc = meta_get_sat_height(meta, meta->general->line_count/2, 0); Re = meta_get_earth_radius(meta, meta->general->line_count/2, 0); a = (Rsc-Re)/Re; x = 1+a; y = meta->sar->slant_range_first_pixel / Re; Gr0 = Re * acos((1.0 + x*x - y*y) / (2.0 * x)); y = slant/Re; GrX = Re * acos((1.0 + x*x - y*y) / (2.0 * x)); if (!meta_is_valid_double(Gr0) || !meta_is_valid_double(GrX)) { asfPrintError("Cannot convert slant range to ground range.\n"); } if (meta && meta->projection && meta_is_valid_double(meta->projection->perX)) { groundPixel = (int) ((GrX-Gr0)/meta->projection->perX)+0.5; // printf("Slant %f :: ",slant); // printf("GP = (%f-%f) / %f = %i\n",GrX,Gr0,meta->projection->perX,groundPixel); } else if (meta && meta->general->data_type != COMPLEX_BYTE && meta->general->data_type != COMPLEX_INTEGER16 && meta->general->data_type != COMPLEX_INTEGER32 && meta->general->data_type != COMPLEX_REAL32 && meta->general->data_type != COMPLEX_REAL64 ) { groundPixel = (int) ((GrX-Gr0)/meta->general->x_pixel_size)+0.5; // printf("Slant %f :: ",slant); // printf("GP = (%f-%f) / %f = %i\n",GrX,Gr0,meta->general->x_pixel_size,groundPixel); } else { groundPixel=0; // just to quiet the compiler warning asfPrintError("Cannot convert slant range to ground range without a valid perX size.\n"); } return(groundPixel);}
static char *get_arclist_from_settings(char *sensor) { if (strcmp_case(sensor, "ERS-1") == 0 || strcmp_case(sensor, "ERS-2") == 0) { char *settings_file = find_in_share("mapready_settings.cfg"); if (!settings_file) { asfPrintWarning("Could not find mapready_settings.cfg"); return NULL; } char match_str[256]; char *arclist = NULL; sprintf(match_str, "precise orbits %s", sensor); FILE *fSettings = FOPEN(settings_file, "r"); if (fSettings) { char line[1024]; while (fgets(line, 1024, fSettings) != NULL) { if (strncmp(line, match_str, strlen(match_str)) == 0) { arclist = read_str(line, match_str); if (strcmp_case(arclist, "<location of arclist file>") == 0) strcpy(arclist, ""); break; } } FCLOSE(fSettings); if (!arclist || strlen(arclist) == 0) { // not an error, user probably does not have precision state vectors asfPrintStatus("No precise orbits found in mapready_settings.cfg for %s\n", sensor); } FREE(settings_file); return arclist; } else { asfPrintError("Could not open mapready_settings.cfg"); return NULL; } } else { asfPrintError("Internal error, bad sensor: %s\n", sensor); return NULL; } // not reached return NULL; }
void ddr2hdr(struct DDR *ddr, jpl_header *hdr) { // Make sure we've got allocated stuctures if (ddr == NULL) { asfPrintError("%s: ddr structure has not been allocated!", __func__); } if (hdr == NULL) { asfPrintError("%s: hdr structure has not been allocated!", __func__); } // Initialize just for fun hdr->magnitude_bytes = 0; hdr->elevation_bytes = 0; strcpy(hdr->data_type, "0"); hdr->elevation_scale = 0; hdr->elevation_shift = 0; hdr->line_increment = 0.0; hdr->sample_increment = 0.0; hdr->start_lat = 0.0; hdr->start_lon = 0.0; hdr->line_count = 0; hdr->sample_count = 0; // Okay lets put some believable stuff in there hdr->magnitude_bytes = 4; hdr->elevation_bytes = 4; strcpy(hdr->data_type, "EQA"); hdr->elevation_scale = 1; hdr->elevation_shift = 0; if (ddr->valid[DDINCV] == VALID) { hdr->line_increment = ddr->line_inc / 1200; hdr->sample_increment = ddr->sample_inc / 1200; } else if (ddr->valid[DDPDV] == VALID) { hdr->line_increment = ddr->pdist_y / 3600; hdr->sample_increment = ddr->pdist_x / 3600; } if (ddr->valid[DDPUV] == VALID) { hdr->start_lat = ddr->upleft[0] / 3600; hdr->start_lon = ddr->upleft[1] / 3600; } hdr->line_count = ddr->nl; hdr->sample_count = ddr->ns; }
static void print_proj_info(meta_parameters *meta) { project_parameters_t pp = meta->projection->param; switch (meta->projection->type) { case LAT_LONG_PSEUDO_PROJECTION: asfPrintStatus(" Projection: Geographic Lat/Lon\n"); break; case UNIVERSAL_TRANSVERSE_MERCATOR: asfPrintStatus(" Projection: UTM\n Zone: %d\n\n", pp.utm.zone); break; case POLAR_STEREOGRAPHIC: asfPrintStatus( " Projection: Polar Stereographic\n" " Standard parallel: %.4f\n" " Central meridian: %.4f\n" " Hemisphere: %c\n\n", pp.ps.slat, pp.ps.slon, pp.ps.is_north_pole ? 'N' : 'S'); break; case ALBERS_EQUAL_AREA: asfPrintStatus( " Projection: Albers Equal Area Conic\n" " First standard parallel: %.4f\n" " Second standard parallel: %.4f\n" " Central meridian: %.4f\n" " Latitude of origin: %.4f\n\n", pp.albers.std_parallel1, pp.albers.std_parallel2, pp.albers.center_meridian, pp.albers.orig_latitude); break; case LAMBERT_CONFORMAL_CONIC: asfPrintStatus( " Projection: Lambert Conformal Conic\n" " First standard parallel: %.4f\n" " Second standard parallel: %.4f\n" " Central meridian: %.4f\n" " Latitude of origin: %.4f\n\n", pp.lamcc.plat1, pp.lamcc.plat2, pp.lamcc.lon0, pp.lamcc.lat0); break; case LAMBERT_AZIMUTHAL_EQUAL_AREA: asfPrintStatus( " Projection: Lambert Azimuthal Equal Area\n" " Latitude of origin: %.4f\n" " Central meridian: %.4f\n\n", pp.lamaz.center_lat, pp.lamaz.center_lon); break; default: asfPrintError("Projection type not supported!\n"); break; } }
GtkWidget *get_widget_checked(const char *widget_name) { GtkWidget *w = glade_xml_get_widget(glade_xml, widget_name); if (!w) { asfPrintError("get_widget_checked() failed: " "The widget %s was not found.\n", widget_name); } return w; }
static void sar_to_dem(meta_parameters *meta_sar, meta_parameters *meta_dem, double line_sar, double samp_sar, double *line_dem, double *samp_dem) { double lat, lon; int ret; ret = meta_get_latLon(meta_sar, line_sar, samp_sar, 0, &lat, &lon); if (ret != 0) { asfPrintError("meta_get_latLon error: line = %f, samp = %f\n", line_sar, samp_sar); } ret = meta_get_lineSamp(meta_dem, lat, lon, 0, line_dem, samp_dem); if (ret != 0) { asfPrintError("meta_get_lineSamp error: lat = %f, lon = %f\n", lat, lon); } }
int get_band_float_line(FILE *file, meta_parameters *meta, int band_number, int line_number_in_band, float *dest) { if (band_number > meta->general->band_count) asfPrintError("Requested a band (%d) larger than the number of bands in\n" "the file (%d).\n", band_number, meta->general->band_count); int line_number = meta->general->line_count * band_number + line_number_in_band; return get_data_lines(file, meta, line_number, 1, 0, meta->general->sample_count, dest, REAL32); }
/*Convert projection units (meters) to geodetic latitude and longitude (degrees).*/ void proj_to_latlon(meta_projection *proj, double x, double y, double z, double *lat, double *lon, double *height) { if (proj==NULL) bail("NULL projection parameter structure passed to proj_to_latlon!\n"); switch(proj->type) { case ALBERS_EQUAL_AREA: project_albers_inv(&(proj->param), x, y, z, lat, lon, height, proj->datum); break; case LAMBERT_AZIMUTHAL_EQUAL_AREA: project_lamaz_inv(&(proj->param), x, y, z, lat, lon, height, proj->datum); break; case LAMBERT_CONFORMAL_CONIC: project_lamcc_inv(&(proj->param), x, y, z, lat, lon, height, proj->datum); break; case POLAR_STEREOGRAPHIC: project_ps_inv(&(proj->param), x, y, z, lat, lon, height, proj->datum); break; case UNIVERSAL_TRANSVERSE_MERCATOR: project_utm_inv(&(proj->param), x, y, z, lat, lon, height, proj->datum); break; case MERCATOR: project_mer_inv(&(proj->param), x, y, z, lat, lon, height, proj->datum); break; case EQUI_RECTANGULAR: project_eqr_inv(&(proj->param), x, y, z, lat, lon, height, proj->datum); break; case EQUIDISTANT: project_eqc_inv(&(proj->param), x, y, z, lat, lon, height, proj->datum); break; case SINUSOIDAL: project_sin_inv(&(proj->param), x, y, z, lat, lon, height); break; case SCANSAR_PROJECTION: asfPrintError("'proj_to_latlon' not defined for SCANSAR_PROJECTION.\n" "Use 'scan_latlon' instead.\n"); break; case LAT_LONG_PSEUDO_PROJECTION: *lat = y*D2R; *lon = x*D2R; break; case STATE_PLANE: // temporary hack *lat = 0.0; *lon = 0.0; break; case UNKNOWN_PROJECTION: default: printf("Unrecognized map projection '%c' passed to proj_to_latlon!\n", proj->type); exit(1); } }
void open_baseline_shape(char *inFile, DBFHandle *dbase, SHPHandle *shape) { char *dbaseFile; // Open database for adding values dbaseFile = (char *) MALLOC(sizeof(char)*(strlen(inFile)+5)); sprintf(dbaseFile, "%s.dbf", inFile); *dbase = DBFOpen(dbaseFile, "r+b"); if (*dbase == NULL) asfPrintError("Could not open database file '%s'\n", dbaseFile); // Open shapefile for adding values *shape = SHPOpen(inFile, "r+b"); if (*shape == NULL) asfPrintError("Could not open shapefile '%s\n", inFile); FREE(dbaseFile); return; }
static void img_to_latlon(meta_parameters *meta, double line, double samp, double *lat, double *lon) { int ret = meta_get_latLon(meta, line, samp, 0, lat, lon); if (ret != 0) { asfPrintError("meta_get_latLon error: line = %f, samp = %f\n", line, samp); } }
/********************************************************** * slant_from_incide: Calculate the slant range, if we know * the incidence angle, the earth radius, and the satellite height * incid should be in radians */ double slant_from_incid(double incid,double er,double ht) { double i=PI-incid; double D=SQR(ht) - SQR(er*sin(i)); double sr=er*cos(i) + sqrt(D); // check degenerate cases if (D<0 || sr<0 || er*cos(i) - sqrt(D) > 0) asfPrintError("Satellite orbit is below the Earth's surface!\n"); return sr; }
PRC_REC *fetch_prc_rec(char *file, int recnum) { FILE *fp; char buf[131]; PRC_REC *tmp; int offset, i; char tmpbuf[20][20]; /* Add null strings to end of temporary buffer */ for (i=0; i< 20; i++) tmpbuf[i][19]='\0'; /* Create structure & Add null characters to string fields */ tmp = (PRC_REC *) MALLOC (sizeof(PRC_REC)); tmp->reckey[6]='\0'; tmp->spare[2]='\0'; /* Open file, skip id and header, seek to recnum record */ fp = FOPEN(file,"r"); offset = 130 + 130 + 130 * recnum; if (fseek(fp,offset,0)!=0) asfPrintError("No state vector found - read past end of file \n"); /* Read the current record */ FREAD(buf,130,1,fp); FCLOSE(fp); /* Convert the buffer */ sscanf(buf,"%6c%7c%c%6c%11c%12c%12c%12c%11c%11c%11c%6c%6c%6c%2c%3c%c%4c%2c", tmp->reckey, tmpbuf[0], &tmp->orbtyp, tmpbuf[1],tmpbuf[2], tmpbuf[3], tmpbuf[4], tmpbuf[5], tmpbuf[6], tmpbuf[7], tmpbuf[8], tmpbuf[9], tmpbuf[10], tmpbuf[11], tmpbuf[12], tmpbuf[13], &tmp->quali, tmpbuf[14], tmp->spare); /* Convert tmpbuf strings into numeric values */ tmp->satid = atoi(tmpbuf[0]); tmp->ttagd = atof(tmpbuf[1]) / 10.0; /* Units are 0.1 days */ tmp->ttagms = strtoll(tmpbuf[2], (char **)NULL, 10); tmp->xsat = strtoll(tmpbuf[3], (char **)NULL, 10); tmp->ysat = strtoll(tmpbuf[4], (char **)NULL, 10); tmp->zsat = strtoll(tmpbuf[5], (char **)NULL, 10); tmp->xdsat = strtoll(tmpbuf[6], (char **)NULL, 10); tmp->ydsat = strtoll(tmpbuf[7], (char **)NULL, 10); tmp->zdsat = strtoll(tmpbuf[8], (char **)NULL, 10); tmp->roll = atof(tmpbuf[9])/1000.0; /* Units are 0.001 degrees */ tmp->pitch = atof(tmpbuf[10])/1000.0; /* Units are 0.001 degrees */ tmp->yaw = atof(tmpbuf[11])/1000.0; /* Units are 0.001 degrees */ tmp->ascarc = atoi(tmpbuf[12]); tmp->check = atoi(tmpbuf[13]); tmp->radcor = atoi(tmpbuf[14]); return(tmp); }
void find_prc_file(char *prc_path,int requested_date, int orbit, char *prc_file) { struct stat buf; DIR *dirp; struct dirent *dent; //int tmpRequest; int minDiff = 1000000; char saveName[256]; /* Make sure given path is valid ------------------------------*/ if (stat(prc_path, &buf)==-1) { perror("stat"); exit(EXIT_FAILURE); } if (!(S_ISDIR(buf.st_mode))) asfPrintError(" ERROR: '%s' is not a directory\n",prc_path); /* Open the directory structure -----------------------------*/ if ((dirp = opendir(prc_path))==NULL) { perror("opendir"); exit(1); } //tmpRequest = requested_date - ((requested_date/1000000)*1000000); while ((dent=readdir(dirp)) != 0) { char tmpName[256]; //int tmpDate; int tmpOrbit; strcpy(tmpName,dent->d_name); if (strncmp(tmpName,"PRC_",4)==0) { //tmpDate = atoi(&(tmpName[4])); tmpOrbit = atoi(&(tmpName[11])); /* Calculation by orbit number */ if ( (tmpOrbit < orbit) && ((orbit - tmpOrbit) < minDiff)) { minDiff = (orbit-tmpOrbit); strcpy(saveName,tmpName); } } } (void)closedir(dirp); asfPrintStatus(" Closest file found is %s\n",saveName); strcpy(prc_file,prc_path); strcat(prc_file,"/"); strcat(prc_file,saveName); }
void test_geoid(void) { float f = get_geoid_height(0,0); if (fabs(f - 17.16) > .0001) asfPrintWarning("Unexpected value at 0,0 should be 17.15: %f\n", f); int w = geoid_get_width(); int h = geoid_get_height(); float *geoid_heights = geoid_get_height_array(); int i, j; for (i=0; i<w; ++i) { for (j=0; j<h; ++j) { float a0 = *(geoid_heights + j*w + i); float a1 = geoid_height_at(i,j); if (fabs(a0-a1) > .0001) asfPrintWarning("test_geoid #1 failed: %d %d %f %f\n", i, j, a0, a1); CU_ASSERT(fabs(a0-a1)<.0001); if (i<w-1 && j<h-1) { double ii = i+.5; double jj = j+.5; double lat = 90.0 - jj/4.0; double lon = ii/4.0; float b0 = get_geoid_height(lat,lon); float b1 = .25*(geoid_height_at(i,j)+geoid_height_at(i+1,j)+ geoid_height_at(i,j+1)+geoid_height_at(i+1,j+1)); if (fabs(b0-b1) > .0001) asfPrintWarning("test_geoid #2 failed: %d %d %f %f\n", i, j, b0, b1); CU_ASSERT(fabs(b0-b1)<.0001); ii = i+.25; jj = j+.75; lat = 90.0 - jj/4.0; lon = ii/4.0; float c0 = get_geoid_height(lat,lon); float u = .75*geoid_height_at(i,j) + .25*geoid_height_at(i+1,j); float v = .75*geoid_height_at(i,j+1) + .25*geoid_height_at(i+1,j+1); float c1 = .25*u + .75*v; if (fabs(c0-c1) > .0001) asfPrintError("test_geoid #3 failed: %d %d %f %f\n", i, j, c0, c1); CU_ASSERT(fabs(c0-c1)<.0001); } } } }
static void banded_image_self_test(BandedFloatImage *self) { if (!do_self_tests) return; if (self->nbands <= 1) { return; } int nl = self->images[0]->size_y; int ns = self->images[0]->size_x; int i; for (i=1; i < self->nbands; ++i) { if (nl != self->images[i]->size_y) asfPrintError("BandedFloatImage y consistency check failed!" "band #%d size=%d: band0_size=%d\n", i, self->images[i]->size_y, nl); if (ns != self->images[i]->size_x) asfPrintError("BandedFloatImage x consistency check failed!" "band #%d size=%d: band0_size=%d\n", i, self->images[i]->size_x, ns); } }
int combine(char **infiles, int n_inputs, char *outfile) { int ret, ii, size_x, size_y; double start_x, start_y; double per_x, per_y; // Determine image parameters determine_extents(infiles, n_inputs, &size_x, &size_y, &start_x, &start_y, &per_x, &per_y); asfPrintStatus("\nCombined image size: %dx%d LxS\n", size_y, size_x); asfPrintStatus(" Start X,Y: %f,%f\n", start_x, start_y); asfPrintStatus(" Per X,Y: %lg,%lg\n", per_x, per_y); // float_image will handle cacheing of the large output image FloatImage *out = float_image_new(size_x, size_y); // loop over the input images, last to first, so that the files listed // first have their pixels overwrite files listed later on the command line for (ii=n_inputs-1; ii>=0; ii--) { asfPrintStatus("\nProcessing %s... \n", infiles[ii]); // Add this image's pixels add_pixels(out, infiles[ii], start_x, start_y, per_x, per_y); } asfPrintStatus("Writing metadata.\n"); meta_parameters *meta_out = meta_read(infiles[0]); meta_out->projection->startX = start_x; meta_out->projection->startY = start_y; meta_out->general->line_count = size_y; meta_out->general->sample_count = size_x; meta_write(meta_out, outfile); meta_free(meta_out); char *outfile_full = appendExt(outfile, ".img"); asfPrintStatus("Saving image (%s).\n", outfile_full); ret = float_image_store(out, outfile_full, fibo_be); if (ret!=0) asfPrintError("Error storing output image!\n"); float_image_free(out); free(outfile_full); return ret; }
static char *findInArcList(char *acquisition_time, char *arclist) { char line[1024]; char *odr = NULL; // ODR files will be in the same directory as arclist char *dir = get_dirname(arclist); FILE *fp = FOPEN(arclist, "r"); if (!fp) { asfPrintError("Failed to open: %s\n", arclist); } ymd_date ymd; hms_time hms; parse_DMYdate(acquisition_time, &ymd, &hms); // YYYYMMDD as an integer int scene_time = ymd.year * 10000 + ymd.month * 100 + ymd.day; while (fgets(line, 1024, fp) != NULL) { if (isdigit(line[0])) { int arc, start, end, junk, n; n = sscanf(line, "%d %d %d:%d - %d %d:%d", &arc, &start, &junk, &junk, &end, &junk, &junk); start = arclist_time_fudge(start); end = arclist_time_fudge(end); if (n == 7) { if (scene_time > start && scene_time < end) { odr = MALLOC(sizeof(char)*(strlen(dir)+64)); sprintf(odr, "%sODR.%03d", dir, arc); break; } } } } FCLOSE(fp); if (!odr) odr = STRDUP(""); FREE(dir); return odr; }