int main(int argc, char *argv[]) { // Allocate some memory char *inFile = (char *) MALLOC(sizeof(char)*512); char *outFile = (char *) MALLOC(sizeof(char)*512); // Parse command line if (argc < 3) { printf("Insufficient arguments.\n"); usage(argv[0]); } strcpy(inFile, argv[1]); strcpy(outFile, argv[2]); int grid_line_count = atoi(argv[3]); asfSplashScreen (argc, argv); // Deal with metadata meta_parameters *metaIn = meta_read(inFile); meta_parameters *metaOut = meta_read(inFile); int nl = metaIn->general->line_count; int ns = metaIn->general->sample_count; metaOut->general->data_type = ASF_BYTE; meta_write(metaOut, outFile); // Replace image with grid float on_grid = 0.0; float off_grid = 255.0; float *outLine = (float *) MALLOC(sizeof(float)*ns); float *inLine = (float *) MALLOC(sizeof(float)*ns); FILE *fpIn = FOPEN(appendExt(inFile, ".img"), "rb"); FILE *fpOut = FOPEN(appendExt(outFile, ".img"), "wb"); int ii, kk;; for (ii=0; ii<nl; ii++) { get_float_line(fpIn, metaIn, ii, inLine); for (kk=0; kk<ns; kk++) { if (ii == 0 || ii == nl -1 || ii % (ns/grid_line_count) == 0) outLine[kk] = on_grid; else if (kk % (ns/grid_line_count) == 0) outLine[kk] = on_grid; else outLine[kk] = off_grid; } outLine[0] = outLine[ns-1] = on_grid; put_float_line(fpOut, metaOut, ii, outLine); asfLineMeter(ii, nl); } // Clean up FREE(inFile); FREE(outFile); meta_free(metaIn); meta_free(metaOut); exit(0); }
int dem_to_mask(char *inDemFile, char *outMaskFile, float cutoff) { meta_parameters *inDemMeta = meta_read(inDemFile); meta_parameters *outDemMeta = meta_read(inDemFile); // out metadata will differ from in only in the data type outDemMeta->general->data_type = ASF_BYTE; int x_size = inDemMeta->general->sample_count; int y_size = inDemMeta->general->line_count; float *maskbuffer = MALLOC(sizeof(float) * x_size); float *floatbuffer = MALLOC(sizeof(float) * x_size); FILE *in = fopenImage(inDemFile, "rb"); FILE *out = fopenImage(outMaskFile, "wb"); float mv = masked_value(); float umv = unmasked_value(); int y,x; for (y=0; y<y_size; y++) { get_float_line(in, inDemMeta, y, floatbuffer); for (x=0; x < x_size; x++) maskbuffer[x] = floatbuffer[x] <= cutoff ? mv : umv; put_float_line(out, outDemMeta, y, maskbuffer); asfLineMeter(y, y_size); } FCLOSE(in); FCLOSE(out); FREE(floatbuffer); FREE(maskbuffer); meta_write(outDemMeta, outMaskFile); meta_free(inDemMeta); meta_free(outDemMeta); asfPrintStatus("Created Mask file '%s' from DEM '%s'.\n", outMaskFile, inDemFile); return 0; }
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); }
void calc_minmax_polsarpro(const char *inFile, double *min, double *max) { int ii,jj; *min = 999999; *max = -999999; char *enviName = (char *) MALLOC(sizeof(char)*(strlen(inFile) + 10)); sprintf(enviName, "%s.hdr", inFile); envi_header *envi = read_envi(enviName); meta_parameters *meta = envi2meta(envi); float *data = MALLOC(sizeof(float) * meta->general->sample_count); FILE *fp = FOPEN(inFile, "rb"); asfPrintStatus("\nCalculating min and max ...\n"); for (ii=0; ii<meta->general->line_count; ++ii) { asfPercentMeter(((double)ii/(double)meta->general->line_count)); get_float_line(fp, meta, ii, data); for (jj=0; jj<meta->general->sample_count; ++jj) { ieee_big32(data[jj]); if (data[jj] < *min) *min = data[jj]; if (data[jj] > *max) *max = data[jj]; } } asfPercentMeter(1.0); FCLOSE(fp); FREE(data); meta_free(meta); FREE(envi); FREE(enviName); }
END_TEST START_TEST(test_ps) /* Polar Stereo */ { char error_string[256]; char in_file[512]; meta_parameters *meta; sprintf(in_file,"%s/new_style_ps.meta",_TEST_DATA_DIR); meta = meta_read(in_file); meta_write(meta,"test_output/out_ps.meta"); /* look at a couple fields real quick */ sprintf(error_string,"meta->sar->dopRangeQuad is %-16.11g, should be 0.0001246",meta->sar->range_doppler_coefficients[2]); fail_unless(UNIT_TESTS_FLOAT_COMPARE(meta->sar->range_doppler_coefficients[2],0.0001246),error_string); sprintf(error_string,"meta->sar->dopAzQuad is %-16.11g, should be 2e-07",meta->sar->azimuth_doppler_coefficients[2]); fail_unless(UNIT_TESTS_FLOAT_COMPARE(meta->sar->azimuth_doppler_coefficients[2],2e-07),error_string); /* look at the good stuff */ sprintf(error_string,"meta->projection->param.ps.slat is %-16.11g, should be 72.374152778",meta->projection->param.ps.slat); fail_unless(UNIT_TESTS_FLOAT_COMPARE(meta->projection->param.ps.slat,72.374152778),error_string); sprintf(error_string,"meta->geo->proj->param.ps.slat is %-16.11g, should be 72.374152778",meta->geo->proj->param.ps.slat); fail_unless(UNIT_TESTS_FLOAT_COMPARE(meta->geo->proj->param.ps.slat,72.374152778),error_string); sprintf(error_string,"meta->projection->param.ps.slon is %-16.11g, should be -158.3591",meta->projection->param.ps.slon); fail_unless(UNIT_TESTS_FLOAT_COMPARE(meta->projection->param.ps.slon,-158.3591),error_string); sprintf(error_string,"meta->geo->proj->param.ps.slon is %-16.11g, should be -158.3591",meta->geo->proj->param.ps.slon); fail_unless(UNIT_TESTS_FLOAT_COMPARE(meta->geo->proj->param.ps.slon,-158.3591),error_string); meta_free(meta); }
END_TEST /* Test the part of meta_read that parses old files. */ START_TEST(test_meta_read_old_format) { char in_file[512]; meta_parameters *meta; sprintf(in_file,"%s/test_file_old_style.meta",_TEST_DATA_DIR); meta = meta_read(in_file); /* Check a random fields to make sure things are working. */ fail_unless(meta->sar->azimuth_time_per_pixel == 0.015099817313, "azPixTime field from geo block not read correctly"); fail_unless(meta->general->line_count == 8262, "nl from ddr read incorrectly"); /* Check a not-so-random field: things from projection params block are currently partly holdover from deprecated code and use a union. */ fail_unless(meta->projection->type == 'P' && meta->projection->param.ps.slon == -158.3591, "ps_lon field from param->ps block not read correctly"); /* Another not-so-random field check: state vector blocks currently use wierd field names in the data file and map strangely into a dynamicly allocated internal structure, lots of possibility for error. */ fail_unless(UNIT_TESTS_FLOAT_COMPARE(meta->state_vectors->vecs[1].vec.pos.y,-359150.94171), "Y position element of second state vector not read correctly"); meta_free(meta); }
int main(int argc, char **argv) { char las_name[256]; char meta_name[256]; meta_parameters *meta; /* Parse command line */ currArg=1; if (argc-currArg < 2) {printf("Insufficient arguments.\n"); usage(argv[0]);} if (argc-currArg > 2) {printf("Excessive arguments.\n"); usage(argv[0]);} strcpy(las_name, argv[currArg]); strcpy(meta_name,argv[currArg+1]); /* Read .ddr & .meta file info & put into meta structures */ meta = meta_read(las_name); meta->general->image_data_type = IMAGE; /* write it out new style */ meta_write(meta, meta_name); /* Clean and report */ meta_free(meta); printf("***Wrote %s.meta from %s.ddr and %s.meta.\n", meta_name,las_name,las_name); 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; }
void closeCeos(CEOS_FILE *in) { FCLOSE(in->f_in); in->f_in=NULL; meta_free(in->meta); FREE((void *)in); }
void meta_destroy(meta_t *m) { if (m == NULL) return; sdsdel(m->key); meta_free(m); }
void floats_to_bytes_from_file_ext(const char *inFile, const char *outFile, char *band, float mask, scale_t scaling, float scale_factor) { FILE *fp; meta_parameters *meta; float *float_data; unsigned char *byte_data; int ii, band_number; long long pixel_count; long offset; meta = meta_read(inFile); band_number = (!band || strlen(band) == 0 || strcmp(band, "???")==0) ? 0 : get_band_number(meta->general->bands, meta->general->band_count, band); pixel_count = meta->general->line_count * meta->general->sample_count; offset = meta->general->line_count * band_number; float_data = (float *) MALLOC(sizeof(float) * pixel_count); fp = FOPEN(inFile, "rb"); get_float_lines(fp, meta, offset, meta->general->line_count, float_data); FCLOSE(fp); byte_data = floats_to_bytes_ext(float_data, pixel_count, mask, scaling, scale_factor); for (ii=0; ii<pixel_count; ii++) float_data[ii] = (float) byte_data[ii]; meta->general->data_type = ASF_BYTE; meta_write(meta, outFile); fp = FOPEN(outFile, "wb"); put_float_lines(fp, meta, offset, meta->general->line_count, float_data); FCLOSE(fp); FREE(float_data); FREE(byte_data); meta_free(meta); }
void sst_free(struct sst *sst) { if (sst) { meta_free(sst->meta); free(sst); } }
void debugWritePatch_Line(int lineNo, complexFloat *line, char *basename, int n_range, int n_az) { FILE *fp; meta_parameters *meta; char outname[320],name[320]; char *mode; strcpy(outname,g.out); strcat(strcat(outname,"_"),basename); strcat(strcpy(name,outname),".img"); if (lineNo == 0) { meta = meta_read(g.in1); meta->general->line_count = n_range; meta->general->sample_count = n_az; meta->general->data_type = COMPLEX_REAL32; meta->general->image_data_type = COMPLEX_IMAGE; meta_write(meta, name); } else { meta = meta_read(name); } mode = lineNo == 0 ? "wb" : "ab"; fp = fopenImage(name,mode); put_complexFloat_line(fp, meta, lineNo, line); FCLOSE(fp); if (lineNo == meta->general->line_count - 1) patchToRGBImage(outname, TRUE); meta_free(meta); }
/* DebugWritePatch: Outputs the current patch trans array, and converts it to amplitude and phase. */ void debugWritePatch(const patch *p,char *basename) { FILE *fp; char name[1024],outname[1024]; meta_parameters *meta; int i; strcpy(outname,g.out); strcat(strcat(outname,"_"),basename); strcat(strcpy(name,outname),".img"); meta = meta_read(g.in1); meta->general->line_count = p->n_range; meta->general->sample_count = p->n_az; meta->general->data_type = COMPLEX_REAL32; meta->general->image_data_type = COMPLEX_IMAGE; meta_write(meta, name); fp = fopenImage(name,"wb"); for (i=0; i<p->n_range; ++i) put_complexFloat_line(fp, meta, i, p->trans+i*p->n_az); FCLOSE(fp); meta_free(meta); patchToRGBImage(outname, TRUE); }
int main(int argc, char **argv) { char meta_name[255]; char envi_name[255]; meta_parameters *meta=NULL; envi_header *envi=NULL; extern int currArg; /* from cla.h in asf.h... initialized to 1 */ logflag = 0; if (argc > 1) { check_for_help(argc, argv); handle_license_and_version_args(argc, argv, TOOL_NAME); } if (argc < 3) { asfPrintStatus("\nNot enough arguments.\n"); usage(); return 1; } /* Parse command line args */ while (currArg < (argc-2)) { char *key=argv[currArg++]; if (strmatch(key,"-log")) { sprintf(logFile, "%s", argv[currArg]); logflag = 1; } else { printf("\n ***Invalid option: %s\n\n", argv[currArg-1]); usage(argv[0]); } } if ((argc-currArg) < 2) { printf("Insufficient arguments.\n"); usage(argv[0]); } create_name(envi_name, argv[currArg], ".hdr"); create_name(meta_name, argv[currArg+1], ".meta"); asfSplashScreen(argc, argv); // Read ENVI header envi = read_envi(envi_name); // Fill metadata structure with valid data meta = envi2meta(envi); // Write metadata file meta_write(meta, meta_name); // Clean and report meta_free(meta); asfPrintStatus(" Converted ENVI header (%s) to metadata file (%s)\n\n", envi_name, meta_name); return 0; }
void image_info_free(ImageInfo *ii) { if (ii->data_ci) cached_image_free(ii->data_ci); if (ii->meta) meta_free(ii->meta); if (ii->filename) free(ii->filename); if (ii->data_name) free(ii->meta_name); if (ii->meta_name) free(ii->data_name); }
void silopit_free(struct silopit *silopit) { if (silopit) { meta_free(silopit->meta); hiraishin_free(silopit->hiraishin); buffer_free(silopit->buf); free(silopit); } }
index_t *index_load(int32_t fd, int32_t offset, int32_t size) { int32_t id; int32_t len; index_t *l; int8_t *buffer, *ptr; meta_t *o; if (fd < 0 || offset < 0 || size < 0) return(NULL); if ((l = index_new()) == NULL) return(NULL); if ((buffer = malloc(size)) == NULL) __ERROR_LOG(B_ERROR); lseek(fd,offset,SEEK_SET); if (size != read(fd,buffer,size)) __ERROR_LOG(R_ERROR); ptr = buffer; l->magic = *(uint64_t *)ptr; ptr = ptr + sizeof(uint64_t); if (l->magic != crc32_encode(ptr,size - sizeof(uint64_t))) __ERROR_LOG(C_ERROR); id = 0; /* inode id */ while (ptr - buffer < size) { if ((o = meta_new()) == NULL) break; o->offset = *(int32_t *)ptr; ptr = ptr + sizeof(int32_t); o->blocksize = *(int32_t *)ptr; ptr = ptr + sizeof(int32_t); len = *(int32_t *)ptr; ptr = ptr + sizeof(int32_t); o->key = sdsnnew(ptr,len); ptr = ptr + len; if (o->key == NULL) { meta_free(o); continue; } o->id = id++; index_add(l,o); } free(buffer); return(l); C_ERROR: R_ERROR: free(buffer); B_ERROR: index_free(l); return(NULL); }
static int is_asf_complex_data(const char *meta_file) { char *ext = findExt(meta_file); if (ext && strcmp_case(ext, ".meta")==0) { meta_parameters *meta = meta_read(meta_file); if (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) { meta_free(meta); return 1; } meta_free(meta); } return 0; }
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); }
static void ingest_polarimetry_data(char *inFile, char *inBaseName, char *outFile, char band, int create) { FILE *fpIn, *fpOut; meta_parameters *meta = NULL; char tmp[10]; int ii, kk; float *power = NULL; char *byteBuf = NULL; fpIn = FOPEN(inFile, "rb"); append_ext_if_needed(outFile, ".img", NULL); if (create) fpOut = FOPEN(outFile, "wb"); else fpOut = FOPEN(outFile, "ab"); if (create) { meta = import_airsar_meta(inFile, inBaseName, TRUE); meta->general->data_type = REAL32; meta->general->band_count = 1; sprintf(meta->general->bands, "AMP-%c", band); meta->general->image_data_type = IMAGE_LAYER_STACK; } else { meta = meta_read(outFile); meta->general->band_count += 1; sprintf(tmp, ",AMP-%c", band); strcat(meta->general->bands, tmp); } power = (float *) MALLOC(sizeof(float)*meta->general->sample_count); byteBuf = (char *) MALLOC(sizeof(char)*10); airsar_header *header = read_airsar_header(inFile); long offset = header->first_data_offset; FSEEK(fpIn, offset, SEEK_SET); for (ii=0; ii<meta->general->line_count; ii++) { for (kk=0; kk<meta->general->sample_count; kk++) { FREAD(byteBuf, sizeof(char), 10, fpIn); power[kk] = sqrt(((float)byteBuf[1]/254.0 + 1.5) * pow(2, byteBuf[0])); } put_float_line(fpOut, meta, ii, power); asfLineMeter(ii, meta->general->line_count); } FCLOSE(fpIn); FCLOSE(fpOut); meta_write(meta, outFile); if (power) FREE(power); if (byteBuf) FREE(byteBuf); if (meta) meta_free(meta); }
// Convert metadata to text // NOTE: inFile will either be a leader data file, a geotiff, // or an ASF metadata file void meta2text(char *inFile, FILE *outFP) { double ulLong=0.0, urLong=0.0, lrLong=0.0, llLong=0.0; // Clockwise polygon double ulLat=0.0, urLat=0.0, lrLat=0.0, llLat=0.0; int no_location_info=1; meta_parameters *meta = NULL; if (isgeotiff(inFile)) { int i, ignore[MAX_BANDS]; for (i=0; i<MAX_BANDS; i++) ignore[i] = 0; // Default to ignoring no bands meta = read_generic_geotiff_metadata(inFile, ignore, NULL); } else if (isleader(inFile)) { meta = meta_create(inFile); } else if (ismetadata(inFile)) { meta = meta_read(inFile); } if (meta && meta->location) { meta_location *ml = meta->location; // Convenience pointer no_location_info = 0; // false ...location info was found ulLong = ml->lon_start_near_range; ulLat = ml->lat_start_near_range; urLong = ml->lon_start_far_range; urLat = ml->lat_start_far_range; lrLong = ml->lon_end_far_range; lrLat = ml->lat_end_far_range; llLong = ml->lon_end_near_range; llLat = ml->lat_end_near_range; } meta_free(meta); if (no_location_info) asfPrintWarning("No location coordinates found in %s\n", inFile); fprintf(outFP, "# File type , polygon\n"); // Use inFile for name ...for lack of a better idea fprintf(outFP, "# Polygon ID (name), %s\n", inFile); fprintf(outFP, "#\n"); fprintf(outFP, "# Latitude, Longitude\n"); if (no_location_info) { fprintf(outFP, "# WARNING: No location information found in " "source file (%s)\n", inFile); fprintf(outFP, "# Values shown below are invalid\n"); } fprintf(outFP, "%f, %f\n", ulLat, ulLong); fprintf(outFP, "%f, %f\n", urLat, urLong); fprintf(outFP, "%f, %f\n", lrLat, lrLong); fprintf(outFP, "%f, %f\n", llLat, llLong); fprintf(outFP, "\n"); // FCLOSE() is called by the calling function return; }
static void *meta_realloc(void *oldBuffer, size_t newSize) { void *newBuffer = meta_malloc(newSize); if ( newBuffer && oldBuffer ) { /*Preserve old buffer contents*/ Slot *o=Slot_fmUser(oldBuffer); size_t size=o->userSize; if (size>newSize) size=newSize; if (size > 0) memcpy(newBuffer, oldBuffer, size); } if (oldBuffer) meta_free(oldBuffer); return newBuffer; }
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; }
void free_files() { if(allFiles) { int i; for(i = 0; i < files; i++) { if(allFiles[i].meta) { if(allFiles[i].meta->banner) { free(allFiles[i].meta->banner); allFiles[i].meta->banner = NULL; } memset(allFiles[i].meta, 0, sizeof(file_meta)); meta_free(allFiles[i].meta); allFiles[i].meta = NULL; } } free(allFiles); allFiles = NULL; files = 0; } }
/************************************************************************** * atct_init_from_leader: * calculates alpha1, alpha2, and alpha3, which are some sort of coordinate * rotation amounts, in degrees. This creates a latitude/longitude-style * coordinate system centered under the satellite at the start of imaging. * Rather than using a passed-in state vector, the initial state vector is * read from the leader file. */ void atct_init_from_leader(const char *leaderName, meta_projection *proj) { struct dataset_sum_rec *dssr = NULL; meta_parameters *meta = raw_init(); stateVector st_start; ceos_description *ceos = get_ceos_description_ext(leaderName, REPORT_LEVEL_NONE, FALSE); // Azimuth time per pixel need to be known for state vector propagation dssr = &ceos->dssr; ceos_init_sar_general(ceos, leaderName, meta, TRUE); ceos_read_stVecs(leaderName, ceos, meta); st_start = meta_get_stVec(meta, 0.0); fixed2gei(&st_start,0.0);/* Remove earth's spin JPL's AT/CT projection requires this */ atct_init(proj, st_start); meta_free(meta); }
/* Function 'readSubset' returning a subset of image. The data type of the output image is float, regardless what the input data type is. It errors on complex data. The function expects to have the memory for the returning image array already allocated. */ void readSubset(char *fileName, int width, int height, int posX, int posY, float *subset) { FILE *fp; char dataFileName[255]; int ii, kk; float *buffer; meta_parameters *meta = meta_read(fileName); int lines = meta->general->line_count; int samples = meta->general->sample_count; /* Check whether input parameters are feasible */ assert (width > 0); assert (height > 0); assert (width < lines); assert (height < samples); assert (posX > 0); assert (posY > 0); assert ((posX+width) < samples); assert ((posY+height) < lines); if (meta->general->data_type > 5) printErr(" ERROR: 'readSubset' does not work on complex data!\n"); /* Allocate memory for buffers */ buffer = (float *) MALLOC(height*samples*sizeof(float)); /* Open image file */ create_name(dataFileName, fileName, ".img"); fp = FOPEN(dataFileName, "rb"); /* Read the appropriate data chunk */ get_float_lines(fp, meta, posY, height, buffer); /* Fill in the subset buffer */ for (ii=0; ii<height; ii++) for (kk=0; kk<width; kk++) subset[ii*width+kk] = buffer[ii*samples+posX+kk]; /* Clean up */ FCLOSE(fp); FREE(buffer); meta_free(meta); }
void freeFiles() { if(curDirEntries) { int i; for(i = 0; i < curDirEntryCount; i++) { if(curDirEntries[i].meta) { if(curDirEntries[i].meta->banner) { free(curDirEntries[i].meta->banner); curDirEntries[i].meta->banner = NULL; } memset(curDirEntries[i].meta, 0, sizeof(file_meta)); meta_free(curDirEntries[i].meta); curDirEntries[i].meta = NULL; } } free(curDirEntries); curDirEntries = NULL; curDirEntryCount = 0; } }
// if a file is a .img file, test it for overlap, otherwise do nothing static void process_file(const char *file, int level, char *overlapping_dems[], int *next_dem_number, meta_parameters *meta, int *n_dems_total) { char *base = get_filename(file); char *ext = findExt(base); if (ext && strcmp_case(ext, ".img") == 0) { char *does; ++(*n_dems_total); char *meta_filename = appendExt(file, ".meta"); meta_parameters *meta_dem = meta_read(meta_filename); if (meta_dem->general->image_data_type != DEM) { does = "Not a DEM"; } else if (test_overlap(meta, meta_dem)) { // overlaps! overlapping_dems[*next_dem_number] = STRDUP(file); ++(*next_dem_number); does = "Overlaps"; } else { does = "No"; } free(meta_filename); meta_free(meta_dem); asfPrintStatus(" %s%s - %s\n", spaces(level), base, does); } else if (ext && (strcmp_case(ext, ".meta") == 0 || strcmp_case(ext, ".ddr") == 0)) { // silently ignore the .meta, etc files -- they will be picked up // when processing the corresponding .img file ; } else { // loudly ignore other stuff in the directory asfPrintStatus(" %s%s (ignored)\n", spaces(level), base); } FREE(base); }
int main (int argc, char **argv) { char ceosName[256]; char metaName[256]; meta_parameters *meta; /* Parse command line */ if (argc-currArg < 2) {printf("Insufficient arguments.\n"); usage(argv[0]);} if (argc-currArg > 2) {printf("Excessive arguments.\n"); usage(argv[0]);} strcpy(ceosName,argv[currArg]); strcpy(metaName,argv[currArg+1]); meta = meta_create(ceosName); meta_write(meta,metaName); meta_free(meta); exit(EXIT_SUCCESS); }