int main(int argc,char *argv[]) { float srPixSize= -1; /* output pixel size */ char infile[256]; /* Input file name */ char outfile[256]; /* Output file name */ handle_common_asf_args(&argc, &argv, "gr2sr"); if ((argc != 5 && argc != 3) || (argc == 5 && strcmp(argv[1], "-p") != 0)) { usage(argv[0]); } if (strcmp(argv[1],"-p") == 0) { create_name(infile,argv[3],".img"); create_name(outfile,argv[4],".img"); } else { create_name(infile,argv[1],".img"); create_name(outfile,argv[2],".img"); } asfPrintStatus("Converting from ground to slant range...\n"); if (argc == 5) { srPixSize = atof(argv[2]); gr2sr_pixsiz(infile, outfile, srPixSize); } else { gr2sr(infile, outfile); } exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { handle_common_asf_args(&argc, &argv, "ASF CEOS Metadata Viewer"); gchar *glade_xml_file; gtk_init(&argc, &argv); // glade_xml_file = (gchar *) find_in_path("mdv.glade"); glade_xml_file = (gchar *) find_in_share("mdv.glade"); glade_xml = glade_xml_new(glade_xml_file, NULL, NULL); g_free(glade_xml_file); set_app_title(); set_font(); if (argc > 1) add_file(argv[1]); glade_xml_signal_autoconnect(glade_xml); gtk_main (); exit (EXIT_SUCCESS); }
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; }
int main(int argc,char **argv) { char descFile[512], listFile[512]; char *inFile1=NULL,*inFile2=NULL; float bestLocX, bestLocY; handle_common_asf_args(&argc, &argv, "fftMatchGrid"); int descGiven = extract_string_options(&argc, &argv, descFile, "-m", NULL); int listMode = extract_string_options(&argc, &argv, listFile, "-l","-list",NULL); int nArg = 3; if (listMode) nArg = 1; if (argc != nArg) { if (argc > nArg) printf("\nToo many inputs.\n"); if (argc < nArg) printf("\nToo few inputs.\n"); usage(argv[0]); } else if (listMode) { fftMatch_projList(listFile, descGiven ? descFile : NULL); } else { inFile1=argv[1]; inFile2=argv[2]; asfSplashScreen(argc, argv); float certainty; fftMatch_proj(inFile1, inFile2, &bestLocX, &bestLocY, &certainty); asfPrintStatus("\nPixel offsets (projection corrected)\n"); asfPrintStatus("x: %.5f, y: %.5f\n", bestLocX, bestLocY); if (strlen(descFile) > 0) { FILE *fp = FOPEN(descFile, "w"); fprintf(fp, "master,slave,offsetX,offsetY\n"); fprintf(fp, "%s,%s,%.5f,%.5f\n", inFile1, inFile2, bestLocX, bestLocY); FCLOSE(fp); asfPrintStatus("Generated match file (%s)!\n", descFile); } } return (0); }
int main(int argc,char *argv[]) { if (argc > 1) { check_for_help(argc, argv); handle_common_asf_args(&argc, &argv, TOOL_NAME); } if (argc != 4) { usage(); return 1; } float grPixSize= -1; /* output pixel size */ /* Make sure we've got the right amount of arguments */ if (argc != 4) {usage(argv[0]);} asfPrintStatus("Converting from slant to ground range...\n"); /* Get required arguments */ grPixSize = atof(argv[3]); sr2gr_pixsiz(argv[1], argv[2], grPixSize); return 0; }
int main(int argc, char *argv[]) { int extentFlag = FALSE, multiband = FALSE; char *extent = (char *) MALLOC(sizeof(char)*1024); char *outfile = (char *) MALLOC(sizeof(char)*1024); handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); if (argc>1 && (strcmp(argv[1], "-help")==0 || strcmp(argv[1],"--help")==0)) help(); if (argc<3) usage(); double background_val=0; extract_double_options(&argc, &argv, &background_val, "-background", "--background", "-b", NULL); if (extract_string_options(&argc, &argv, extent, "-extent", "--extent", NULL)) extentFlag = TRUE; if (extract_string_options(&argc, &argv, outfile, "-output", "--output", NULL)) multiband = TRUE; char *infile = argv[1]; int i, size_x, size_y, n_inputs=0, start=0, n_bands; double start_x, start_y; double per_x, per_y; asfSplashScreen(argc, argv); char *line = (char *) MALLOC(sizeof(char)*512); FILE *fpList = FOPEN(infile, "r"); while (fgets(line, 512, fpList)) if (strlen(line) > 0) n_inputs++; FCLOSE(fpList); if (extentFlag) { n_inputs++; start = 1; } char **infiles = (char **) MALLOC(sizeof(char *)*n_inputs); if (extentFlag) { infiles[0] = (char *) MALLOC(sizeof(char)*512); strcpy(infiles[0], extent); } fpList = FOPEN(infile, "r"); for (i=start; i<n_inputs; i++) { fgets(line, 512, fpList); chomp(line); infiles[i] = (char *) MALLOC(sizeof(char)*512); strcpy(infiles[i], line); } FCLOSE(fpList); FREE(line); if (multiband) asfPrintStatus("Stacking %d files to produce: %s\n", n_inputs, outfile); else asfPrintStatus("Putting %d files in image stack\n", n_inputs); asfPrintStatus("Input files:\n"); for (i=start; i<n_inputs; ++i) asfPrintStatus(" %d: %s%s\n", i+1, infiles[i], i==0 ? " (reference)" : ""); determine_extents(infiles, n_inputs, &size_x, &size_y, &n_bands, &start_x, &start_y, &per_x, &per_y, extentFlag); asfPrintStatus("\nStacked 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: %.2f,%.2f\n", per_x, per_y); meta_parameters *meta_out = meta_read(infiles[0]); if (multiband) meta_out->general->image_data_type = IMAGE_LAYER_STACK; 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_out->general->no_data = background_val; update_location_block(meta_out); //char *outfile_full = appendExt(outfile, ".img"); char *outfile_full = (char *) MALLOC(sizeof(char)*1024); if (multiband) { sprintf(outfile_full, "%s.img", stripExt(outfile)); meta_write(meta_out, outfile_full); } for (i=start; i<n_inputs; i++) { asfPrintStatus("\nProcessing band %d (%s) ... \n", i, infiles[i]); if (!multiband) { sprintf(outfile_full, "%s_stack.img", stripExt(infiles[i])); meta_write(meta_out, outfile_full); } add_to_stack(outfile_full, i, infiles[i], size_x, size_y, start_x, start_y, per_x, per_y, multiband); } meta_free(meta_out); FREE(outfile_full); for (i=0; i<n_inputs; i++) FREE(infiles[i]); FREE(infiles); FREE(extent); FREE(outfile); asfPrintStatus("Done.\n"); return 0; }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *outFile; int currArg = 1; int NUM_ARGS = 2; // process log/quiet/license/etc options handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); char classFile[255]; int classify = extract_string_options(&argc,&argv,classFile,"-c",NULL); int debug = extract_flag_options(&argc,&argv,"-debug","-d",NULL); int pauli = extract_flag_options(&argc,&argv,"-pauli","-p",NULL); int sinclair = extract_flag_options(&argc,&argv,"-sinclair","-s",NULL); int freeman = extract_flag_options(&argc,&argv,"-freeman","-f",NULL); int sz; int make_boundary_file = extract_int_options(&argc,&argv,&sz,"-make-feasible-boundary",NULL); if (make_boundary_file) { const char *fname = "ea_boundary.txt"; asfPrintStatus("Generating entropy/alpha boundary curve file: %s\n", fname); asfPrintStatus("Number of points: %d\n", sz); make_entropy_alpha_boundary(fname, sz); // if no other arguments were supplied, we are done - can exit // without making a fuss. if (argc==1) { asfPrintStatus("Done.\n"); exit(1); } } if (classify + pauli + sinclair + freeman > 1) { asfPrintError("Use only one of the -pauli, -sinclair, -freeman " "or -c options.\n"); } if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); else if (argc<=2) usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } inFile = argv[currArg]; outFile = argv[currArg+1]; if (debug) { asfPrintError("Debug mode no longer available.\n"); //cpx2debug(inFile,outFile); } else if (classify) { polarimetric_decomp(inFile,outFile,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, classFile,1); } else if (pauli) { cpx2pauli(inFile,outFile,TRUE); } else if (sinclair) { cpx2sinclair(inFile,outFile,FALSE); } else if (freeman) { cpx2freeman_durden(inFile,outFile,TRUE); } else { polarimetric_decomp(inFile,outFile,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,NULL,-1); } asfPrintStatus("Done.\n"); return EXIT_SUCCESS; }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *demFile, *inMaskFile, *outFile; double pixel_size = -1; int dem_grid_size = 20; int currArg = 1; int clean_files = TRUE; int do_resample = TRUE; int do_interp = TRUE; int do_fftMatch_verification = TRUE; int do_corner_matching = FALSE; int generate_water_mask = FALSE; int save_clipped_dem = FALSE; int doRadiometric = FALSE; int update_original_metadata_with_offsets = FALSE; float mask_height_cutoff = 1.0; int mask_height_cutoff_specified = FALSE; int smooth_dem_holes = FALSE; int no_matching = FALSE; int use_gr_dem = FALSE; int add_speckle = TRUE; int if_coreg_fails_use_zero_offsets = FALSE; int save_ground_dem = FALSE; int save_incid_angles = FALSE; int use_nearest_neighbor = FALSE; double range_offset = 0.0; double azimuth_offset = 0.0; char *other_files[MAX_OTHER]; int i,n_other = 0; for (i=0; i<MAX_OTHER; ++i) other_files[i]=NULL; // -1 -> no masking, other values mean fill it with that value int fill_value = 0; handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); inMaskFile = NULL; if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-keep","--keep","-k",NULL)) { clean_files = FALSE; } else if (strmatches(key,"-no-resample","--no-resample",NULL)) { do_resample = FALSE; } else if (strmatches(key,"-no-verify-match","--no-verify-match",NULL)) { do_fftMatch_verification = FALSE; } else if (strmatches(key,"-no-corner-match","--no-corner-match",NULL)) { do_corner_matching = FALSE; } else if (strmatches(key,"-no-interp","--no-interp",NULL)) { do_interp = FALSE; } else if (strmatches(key,"-no-match","--no-match",NULL)) { no_matching = TRUE; } else if (strmatches(key,"-use-gr-dem", "--use-gr-dem",NULL)) { use_gr_dem = TRUE; } else if (strmatches(key,"-use-sr-dem", "--use-sr-dem",NULL)) { use_gr_dem = FALSE; } else if (strmatches(key,"-no-speckle", "--no-speckle",NULL)) { add_speckle = FALSE; } else if (strmatches(key,"-use-zero-offsets-if-match-fails", "--use-zero-offsets-if-match-fails",NULL)) { if_coreg_fails_use_zero_offsets = TRUE; } else if (strmatches(key,"-pixel-size","--pixel-size","-ps",NULL)) { CHECK_ARG(1); pixel_size = atof(GET_ARG(1)); } else if (strmatches(key,"-dem-grid-size","--dem-grid-size",NULL)) { CHECK_ARG(1); dem_grid_size = atoi(GET_ARG(1)); } else if (strmatches(key,"-mask-file","--mask-file",NULL)) { CHECK_ARG(1); inMaskFile = GET_ARG(1); } else if (strmatches(key,"-auto-water-mask","--auto-water-mask",NULL)) { generate_water_mask = TRUE; } else if (strmatches(key,"-mask-height-cutoff","--mask-height-cutoff",NULL)) { CHECK_ARG(1); mask_height_cutoff = atof(GET_ARG(1)); mask_height_cutoff_specified = TRUE; } else if (strmatches(key, "-u", "-update-original-meta", "--update-original-meta", NULL)) { update_original_metadata_with_offsets = TRUE; } else if (strmatches(key,"-fill","--fill",NULL)) { CHECK_ARG(1); fill_value = atoi(GET_ARG(1)); // user requested a specific fill value } else if (strmatches(key,"-offsets","--offsets",NULL)) { CHECK_ARG(2); range_offset = atof(GET_ARG(2)); azimuth_offset = atof(GET_ARG(1)); no_matching = TRUE; } else if (strmatches(key,"-no-fill","--no-fill",NULL)) { // leave masked regions alone - fill with sar data fill_value = LEAVE_MASK; } else if (strmatches(key,"-do-radiometric","--do-radiometric",NULL)) { // for the 3.1 release, we will always do formula #5 // it's the only one we've had time to test. In later releases, // we can switch to the other version ... this does mean // that -do-radiometric will change from a flag to an option with // an argument. #ifndef ALLOW_ALL_RADIOMETRIC_TC_FORMULAS doRadiometric = 5; #else CHECK_ARG(1); char *form = strdup(GET_ARG(1)); doRadiometric = atoi(form); // give the do-radiometric help in here for now, later should be // put into the rest of the help (when it is officially supported) if (strmatches(form, "help", "?", NULL) || doRadiometric==0) { asfPrintStatus( "Specify a radiometric terrain correction formula to use.\n" "Formula numbers are as follows:\n" " 1 : LI\n" " 2 : GO\n" " 3 : SQ\n" " 4 : VX\n" " 5 : 1 - .7*pow(cos(li), 7)\n" "\n" "e.g.,\n" " asf_terrcorr -do-radiometric 1 ...\n\n"); exit(1); } free(form); #endif } else if (strmatches(key,"-smooth-dem-holes","--smooth-dem-holes",NULL)) { smooth_dem_holes = TRUE; } else if (strmatches(key,"-save-ground-range-dem","--save-ground-range-dem", NULL)) { save_ground_dem = TRUE; } else if (strmatches(key,"-use-nearest-neighbor","--use-nearest-neighbor",NULL)) { use_nearest_neighbor = TRUE; } else if (strmatches(key,"-use-bilinear","--use-bilinear",NULL)) { use_nearest_neighbor = FALSE; } else if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-other-file","--other-file",NULL)) { CHECK_ARG(1); if (n_other >= MAX_OTHER) asfPrintError("-other-file option only supported %d times.\n", MAX_OTHER); other_files[n_other++] = STRDUP(GET_ARG(1)); } else { printf( "\n**Invalid option: %s\n", argv[currArg-1]); usage(ASF_NAME_STRING); } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(ASF_NAME_STRING); } if (mask_height_cutoff_specified && !generate_water_mask) { asfPrintWarning("Ignoring -mask-height-cutoff option, as you did not " "request a water mask.\n"); } inFile = argv[currArg]; demFile = argv[currArg+1]; outFile = argv[currArg+2]; int ret = asf_terrcorr_ext(inFile, demFile,inMaskFile,outFile, pixel_size, clean_files, do_resample, do_corner_matching, do_interp, do_fftMatch_verification, dem_grid_size, TRUE, fill_value, generate_water_mask, save_clipped_dem, update_original_metadata_with_offsets, mask_height_cutoff, doRadiometric, smooth_dem_holes, other_files, no_matching, range_offset, azimuth_offset, use_gr_dem, add_speckle, if_coreg_fails_use_zero_offsets, save_ground_dem, save_incid_angles, use_nearest_neighbor); for (i=0; i<MAX_OTHER; ++i) if (other_files[i]) free(other_files[i]); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char *argv[]) { handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); if (argc>1 && (strcmp(argv[1], "-help")==0 || strcmp(argv[1],"--help")==0)) help(); if (argc<3) usage(); projection_type_t projection_type; datum_type_t datum; spheroid_type_t spheroid; double pixel_size, average_height, background_val; resample_method_t resample_method; int force_flag; char band_id[256]=""; project_parameters_t *pp = get_geocode_options (&argc, &argv, &projection_type, &average_height, &pixel_size, &datum, &spheroid, &resample_method, &force_flag, band_id); if (!pp) usage(); extract_double_options(&argc, &argv, &background_val, "--background", "-background", NULL); if (ISNAN(background_val)) background_val = DEFAULT_NO_DATA_VALUE; char *outfile = argv[1]; int i, n_inputs = argc - 2; asfSplashScreen(argc, argv); asfPrintStatus("Projection: "); switch (projection_type) { case UNIVERSAL_TRANSVERSE_MERCATOR: asfPrintStatus("Universal Transverse Mercator\n"); break; case POLAR_STEREOGRAPHIC: asfPrintStatus("Polar Stereographic\n"); break; case ALBERS_EQUAL_AREA: asfPrintStatus("Albers Conical Equal Area\n"); break; case LAMBERT_AZIMUTHAL_EQUAL_AREA: asfPrintStatus("Lambert Azimuthal Equal Area\n"); break; case LAMBERT_CONFORMAL_CONIC: asfPrintStatus("Lambert Conformal Conic\n"); break; case EQUI_RECTANGULAR: asfPrintStatus("Equirectangular\n"); break; default: break; } asfPrintStatus("Output file: %s\n", outfile); //char **infiles = &argv[2]; //asfPrintStatus("Input files:\n"); //for (i = 0; i < n_inputs; ++i) // asfPrintStatus(" %d: %s\n", i+1, infiles[i]); // form array for asf_mosaic char **files = MALLOC(sizeof(char*)*(n_inputs+1)); for (i = 0; i < n_inputs; ++i) { int n = argc-i-1; files[i] = MALLOC(sizeof(char)*(strlen(argv[n])+2)); //printf("File #%d: %s\n", i+1, argv[n]); strcpy(files[i], argv[n]); } files[n_inputs] = NULL; char *outfile_full = appendExt(outfile, ".img"); double lat_min = -999, lon_min = -999; double lat_max = 999, lon_max = 999; int multiband = 1; int band_num = 0; // FIXME: Overlap should be an option. Hardwired for now. char overlap[25]="OVERLAY"; asf_mosaic(pp, projection_type, force_flag, resample_method, average_height, datum, spheroid, pixel_size, multiband, band_num, files, outfile, background_val, lat_min, lat_max, lon_min, lon_max, overlap, FALSE); free(outfile_full); for (i=0; i<n_inputs; ++i) FREE(files[i]); FREE(files); asfPrintStatus("Done.\n"); return 0; }
// Main program body. int main (int argc, char *argv[]) { char *faraday_rotation_file, *tec_map_dir, *output_file; char granule_name[255], data_granule_type[255]; int frame_id, revolution, year, day, hour, minute; double look_angle, center_lat, center_lon, faraday_rotation; int currArg = 1; int NUM_ARGS = 2; // process log/quiet/license/etc options handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); else if (argc<=2) usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } faraday_rotation_file = argv[currArg]; tec_map_dir = argv[currArg+1]; output_file = (char *) MALLOC(sizeof(char)*(strlen(faraday_rotation_file)+9)); sprintf(output_file, "%s_wFR.txt", faraday_rotation_file); char *line = (char *) MALLOC(sizeof(char)*4096); // Read granule information FILE *fpIn = FOPEN(faraday_rotation_file, "r"); FILE *fpOut = FOPEN(output_file, "w"); while (fgets(line, 1024, fpIn)) { sscanf(line, "%s %s %d %lf %d %d %d %d %d %lf %lf", granule_name, data_granule_type, &frame_id, &look_angle, &revolution, &year, &day, &hour, &minute, ¢er_lat, ¢er_lon); // Determine CODG file to read from char *codg_file = (char *) MALLOC(sizeof(char)*strlen(tec_map_dir)+20); sprintf(codg_file, "%s%c%d%cCODG%d0.%02dI", tec_map_dir, DIR_SEPARATOR, year, DIR_SEPARATOR, day, year-2000); if (!fileExists(codg_file)) asfPrintError("CODG file (%s) does not exist.\n" "Could not calculate Faraday rotation\n", codg_file); // Determine Faraday rotation faraday_rotation = faraday_prediction(frame_id, look_angle, year, day, hour, minute, center_lat, center_lon, codg_file); // Drop a line in the output file fprintf(fpOut, "%s\t%d\t%.1lf\t%d\t%d\t%d\t%d\t%.4lf\t%.4lf\t%.2lf\n", granule_name, frame_id, look_angle, year, day, hour, minute, center_lat, center_lon, faraday_rotation); } FCLOSE(fpIn); FCLOSE(fpOut); asfPrintStatus("Done.\n"); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); if (argc>1 && (strcmp(argv[1], "-help")==0 || strcmp(argv[1],"--help")==0)) help(); if (argc<3) usage(); double background_val=0; extract_double_options(&argc, &argv, &background_val, "-background", "--background", "-b", NULL); char *preference = (char *) MALLOC(sizeof(char)*50); sprintf(preference, ""); extract_string_options(&argc, &argv, preference, "-preference", "--preference", "-p", NULL); if (strlen(preference) > 0 && strcmp_case(preference, "north") != 0 && strcmp_case(preference, "south") != 0 && strcmp_case(preference, "east") != 0 && strcmp_case(preference, "west") != 0 && strcmp_case(preference, "old") != 0 && strcmp_case(preference, "new") != 0) asfPrintError("Can't handle this preference (%s)!\n", preference); char *outfile = argv[1]; char **infiles = &argv[2]; int n_inputs = argc - 2; int ret, i, size_x, size_y, n_bands; double start_x, start_y; double per_x, per_y; asfSplashScreen(argc, argv); asfPrintStatus("Combining %d files to produce: %s\n", n_inputs, outfile); // Sort the input files, in case we have a different preference if (strlen(preference) > 0) sort_input_preference(infiles, n_inputs, preference); asfPrintStatus("Input files:\n"); for (i = 0; i < n_inputs; ++i) asfPrintStatus(" %d: %s%s\n", i+1, infiles[i], i==0 ? " (reference)" : ""); // determine image parameters determine_extents(infiles, n_inputs, &size_x, &size_y, &n_bands, &start_x, &start_y, &per_x, &per_y); // float_image will handle cacheing of the large output image asfPrintStatus("\nAllocating space for output image ...\n"); BandedFloatImage *out; if (background_val != 0) out = banded_float_image_new_with_value(n_bands, size_x, size_y, (float)background_val); else out = banded_float_image_new(n_bands, size_x, size_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: %.2f,%.2f\n", per_x, per_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 int n = argc-1; do { char *p = argv[n]; if (p && strlen(p)>0) { asfPrintStatus("\nProcessing %s... \n", p); // add this image's pixels add_pixels(out, p, size_x, size_y, start_x, start_y, per_x, per_y); } } while (--n>1); asfPrintStatus("Combined all images, saving result.\n"); // first the metadata -- use infile1's metadata as the template asfPrintStatus("Writing metadata.\n"); meta_parameters *meta_out = meta_read(argv[2]); 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; // Update location block update_location_block(meta_out); meta_write(meta_out, outfile); char *outfile_full = appendExt(outfile, ".img"); ret = banded_float_image_store(out, outfile_full, fibo_be); if (ret!=0) asfPrintError("Error storing output image!\n"); banded_float_image_free(out); free(outfile_full); meta_free(meta_out); asfPrintStatus("Done.\n"); return 0; }
// Main program body. int main (int argc, char *argv[]) { char *leader_file_list, *output_file, file[255]; struct dataset_sum_rec *dssr; struct att_data_rec *atdr; struct VFDRECV *facdr; int currArg = 1; int NUM_ARGS = 2; // process log/quiet/license/etc options handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); else if (argc<=2) usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } leader_file_list = argv[currArg]; output_file = argv[currArg+1]; // Read granule information FILE *fpIn = FOPEN(leader_file_list, "r"); FILE *fpOut = FOPEN(output_file, "w"); fprintf(fpOut, "Leader_file, Yaw, Doppler_range, Doppler_azimuth\n"); dssr = (struct dataset_sum_rec *) MALLOC(sizeof(struct dataset_sum_rec)); atdr = (struct att_data_rec *) MALLOC(sizeof(struct att_data_rec)); facdr = (struct VFDRECV *) MALLOC(sizeof(struct VFDRECV)); double yaw; while (fgets(file, 1024, fpIn)) { file[strlen(file)-1] = '\0'; if (get_dssr(file, dssr) < 0) { asfPrintWarning("Leader file (%s) does not contain data set summary" " record\n", file); continue; } if (get_atdr(file, atdr) < 0) { asfPrintWarning("Leader file (%s) does not contain attitude data record", "\n", file); continue; } if (get_asf_facdr(file, facdr) < 0) { asfPrintWarning("Leader file (%s) does not contain facility related data" " record\n", file); continue; } yaw = facdr->scyaw; if (FLOAT_EQUIVALENT(yaw, 0.0)) yaw = atdr->data->yaw; fprintf(fpOut, "%s, %.4lf, %.3lf, %.3lf\n", file, yaw, dssr->crt_dopcen[0], dssr->alt_dopcen[0]); } FCLOSE(fpIn); FCLOSE(fpOut); FREE(dssr); FREE(atdr); FREE(facdr); asfPrintStatus("Done.\n"); return EXIT_SUCCESS; }
// The program itself! int main (int argc, char **argv) { struct stat stat_buf; size_t wordsize=0; size_t bytesread=0; size_t byteswritten=0; size_t nitems=0; size_t ret=0; int done=FALSE; char *in_fname=NULL; char *out_fname=NULL; FILE *in_fp=NULL; FILE *out_fp=NULL; void *buf=NULL; void (*byteswap)(unsigned char *); // Search the command line for help & report if requested if (extract_flag_options(&argc, &argv, "-h", "-help", "--help", NULL)) { help(); } // Grab the common asf options (eg -version, -quiet, etc) handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); // Since handle_common_asf_args reduces argc for all the options // we can check argc to see if we've got 3 arguments & the progname if (argc != 4) { usage(); } /* // Make sure data types are of the size we expect asfRequire( sizeof(short) == SHORT_INT_SIZE, "Short integers need to be %d bytes (%d-bits)," " they appear to be %d bytes.\n", SHORT_INT_SIZE, SHORT_INT_SIZE*8, sizeof(short)); asfRequire( sizeof(int) == INT_SIZE, "Regular integers need to be %d bytes (%d-bits)," " they appear to be %d bytes.\n", INT_SIZE, INT_SIZE*8, sizeof(int)); asfRequire( sizeof(long long) == LL_INT_SIZE, "Long long integers need to be %d bytes (%d-bits)," " they appear to be %d bytes.\n", LL_INT_SIZE, LL_INT_SIZE*8, sizeof(long long)); asfRequire( sizeof(long long) == FLOAT_SIZE, "Floats need to be %d bytes (%d-bits)," " they appear to be %d bytes.\n", FLOAT_SIZE, FLOAT_SIZE*8, sizeof(long long)); asfRequire( sizeof(long long) == DOUBLE_SIZE, "Doubles need to be %d bytes (%d-bits)," " they appear to be %d bytes.\n", DOUBLE_SIZE, DOUBLE_SIZE*8, sizeof(long long)); */ // Fetch our required arguments wordsize = atoi(argv[1]); if ( ! (wordsize==16 || wordsize==32 || wordsize==64) ) { asfPrintError("Wordsize must be 16, 32, or 64 bits, you gave " "%d... Exiting.\n", wordsize); } wordsize /= 8; // change wordsize from bits to bytes in_fname = (char*)CALLOC(strlen(argv[2])+3,sizeof(char)); strcpy(in_fname,argv[2]); out_fname = (char*)CALLOC(strlen(argv[3])+3,sizeof(char)); strcpy(out_fname,argv[3]); // Set the byteswap function for the proper number of bytes switch (wordsize) { case 2: byteswap = (void(*)(unsigned char*))swap16; break; case 4: byteswap = (void(*)(unsigned char*))swap32; break; case 8: byteswap = (void(*)(unsigned char*))swap64; break; default: asfPrintError("Unrecognized wordsize %d\n",wordsize*8); } // Open the needed files in_fp = FOPEN(in_fname,"rb"); out_fp = FOPEN(out_fname,"wb"); // Prepare for the byteswapping loop bytesread = byteswritten = ret = 0; nitems = MEGABYTE / wordsize; buf = CALLOC(MEGABYTE,sizeof(char)); done = FALSE; // Actual byteswapping routine asfPrintStatus("Swapping bytes (each '.' represents one megabyte)\n"); while (!done) { int ii; if (nitems != (ret=fread(buf, wordsize, nitems, in_fp))) { if (feof(in_fp)) { done=TRUE; } } bytesread += ret*wordsize; for (ii=0; ii<nitems; ii++) { byteswap((unsigned char *)(buf+ii*wordsize)); } ret = fwrite(buf, wordsize, ret, out_fp); byteswritten += ret*wordsize; asfPrintStatus("."); } // Make sure things look right before quitting stat(in_fname, &stat_buf); asfRequire((long long)bytesread==(long long)stat_buf.st_size, "(%lld==%lld)\n" "Problem likely occurred during file reading.\n", (long long)bytesread, (long long)stat_buf.st_size); asfRequire((long long)bytesread==(long long)byteswritten, "(%lld==%lld)\n" "Problem likely occurred during file writing.\n", (long long)bytesread, (long long)byteswritten); asfPrintStatus("\n" " Successfully wrote file '%s'\n" " in reverse endian order than '%s'.\n", out_fname, in_fname); // Yay, success! exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { if (detect_flag_options(argc, argv, "-help", "--help", NULL)) help(); char band[512], lut[512], mask_file_name[512]; strcpy(band, ""); strcpy(mask_file_name, ""); int band_specified = extract_string_options(&argc, &argv, band, "-band", "--band", "-b", NULL); int lut_specified = extract_string_options(&argc, &argv, lut, "-colormap", "--colormap", "-lut", "--lut", NULL); int planner_mode = extract_flag_options(&argc, &argv, "-plan", "--plan", NULL); int mask_specified = extract_string_options(&argc, &argv, mask_file_name, "-mask", "--mask", "--layover-mask", "--layover-mask", NULL); generic_specified = extract_flag_options(&argc, &argv, "-generic", "--generic", NULL); if (generic_specified) { char type[512]; if (!extract_int_options(&argc, &argv, &generic_bin_width, "-width", "--width", "-cols", "--cols", NULL) || !extract_int_options(&argc, &argv, &generic_bin_height, "-height", "--height", "-rows", "--rows", NULL)) { asfPrintError("When reading generic data, specify the size " "(--width, --height).\n"); } generic_bin_byteswap = extract_flag_options(&argc, &argv, "--byteswap", "-byteswap", NULL); if (extract_string_options(&argc, &argv, type, "-type", "--type", NULL)) { if (strcmp_case(type, "BYTE") == 0 || strcmp_case(type, "INT8") == 0) { generic_bin_datatype = BYTE; } else if (strcmp_case(type, "FLOAT") == 0 || strcmp_case(type, "REAL32") == 0) { generic_bin_datatype = REAL32; } else { asfPrintError("Unknown generic data type: %s\n", type); } } else { asfPrintStatus("Generic binary: assuming REAL32 data.\n"); generic_bin_datatype = REAL32; } } if (planner_mode) { if (detect_flag_options(argc, argv, "-calibrate-reference", NULL)) { calibrate_planner_reference(); exit(EXIT_SUCCESS); } } handle_common_asf_args(&argc, &argv, "ASF View"); // point to "polygon 0" as the one we initially work on g_poly = &g_polys[0]; // set up image array curr = &image_info[0]; curr->data_name = curr->meta_name = NULL; int ii; if (argc < 2) { curr->filename = STRDUP(find_in_share("startup.jpg")); } else { n_images_loaded = 0; for (ii=1; ii<argc; ++ii) { if (strlen(argv[ii]) > 0) { image_info[n_images_loaded].filename = STRDUP(argv[ii]); ++n_images_loaded; } } } if (n_images_loaded == 1) { asfPrintStatus("Loading 1 image: %s\n", image_info[0].filename); } else { asfPrintStatus("Loading %d images:\n", n_images_loaded); for (ii=0; ii<n_images_loaded; ++ii) asfPrintStatus("%d: %s\n", ii+1, image_info[ii].filename); } if (mask_specified) asfPrintStatus("Mask: %s\n", mask_file_name); // we could call load_file() here, but don't because this way we can // interleave the call to gtk_init() with some of the loading code -- // which keeps the window from showing up until after it has been loaded, // which looks much nicer // initialize globals reset_globals(TRUE); // Get rid of leftover (temporary) colormap luts if they exist, say if asf_view errored out // rather than being exited normally char embedded_tiff_lut_file[1024]; char embedded_asf_colormap_file[1024]; char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+64)); sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR); sprintf(embedded_tiff_lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_TIFF_COLORMAP_LUT_FILE); sprintf(embedded_asf_colormap_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_ASF_COLORMAP_LUT_FILE); FREE(lut_loc); if (fileExists(embedded_tiff_lut_file)) remove(embedded_tiff_lut_file); if (fileExists(embedded_asf_colormap_file)) remove(embedded_asf_colormap_file); if (mask_specified) { curr = mask = &mask_info; mask->filename = STRDUP(mask_file_name); if (mask->filename[strlen(mask->filename)-1] == '.') mask->filename[strlen(mask->filename)-1] = '\0'; read_file(mask->filename, NULL, FALSE, TRUE); //set_lut("layover_mask"); } // load the image we're going to actually show last for (ii=n_images_loaded-1; ii>=0; --ii) { curr = &image_info[ii]; // strip off any trailing "." if (curr->filename[strlen(curr->filename)-1] == '.') curr->filename[strlen(curr->filename)-1] = '\0'; read_file(curr->filename, band_specified ? band : NULL, FALSE, TRUE); check_for_embedded_tiff_lut(curr->filename, &lut_specified, lut); if (lut_specified) set_lut(lut); assert(curr->data_name); assert(curr->meta_name); // we load the thumbnail data before bringing up the window, looks // much nicer. When loading an image within the GUI, we don't need // to do get_thumbnail_data() as a separate step. ThumbnailData *thumbnail_data = get_thumbnail_data(curr); // first time through the loop only, set up GTK if (ii == n_images_loaded-1) { gtk_init(&argc, &argv); gchar *glade_xml_file = (gchar *)find_in_share("asf_view.glade"); printf("Found asf_view.glade: %s\n", glade_xml_file); glade_xml = glade_xml_new(glade_xml_file, NULL, NULL); free(glade_xml_file); // set up window title, etc set_button_images(); // set up the acquisition planner, if we are in that mode if (planner_mode) { setup_planner(); // getting rid of the info section makes more room for the found // acquisitions, and isn't really necessary in the planner show_widget("info_hbox", FALSE); } // populate the look up table list, and apply the default // look-up-table, if there is one. In this case, we will need to // apply it retroactively to the thumbnail data we already loaded // (In new.c, this kludge isn't required - we load/apply in the // same pass -- here it is required because we pre-load the thumbnail) populate_lut_combo(); if (check_for_embedded_tiff_lut(curr->filename, &lut_specified, lut)) { GtkWidget *option_menu = get_widget_checked("lut_optionmenu"); gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_tiff_lut_index()); set_current_index(get_tiff_lut_index()); } else if (is_colormap_ASF_file(curr->filename)) { /* * lut_specified = 1; * strcpy(lut, EMBEDDED_ASF_COLORMAP_LUT); * GtkWidget *option_menu = get_widget_checked("lut_optionmenu"); * gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_asf_lut_index()); * set_current_index(get_asf_lut_index()); * check_lut(); * apply_lut_to_data(thumbnail_data); */ } } else if (ii == 0) { set_title(band_specified, band); } if (curr->meta && curr->meta->general) { if (set_lut_based_on_image_type(curr->meta->general->image_data_type)) { check_lut(); // data we loaded needs to be lutted apply_lut_to_data(thumbnail_data); } } // load the metadata & image data, other setup setup_gdk_window_ids(); setup_small_image_size(); fill_small_have_data(thumbnail_data, curr); fill_big(curr); update_pixel_info(curr); update_zoom(); set_font(); fill_meta_info(); update_map_settings(curr); fill_stats(curr); set_mapping_defaults(curr); setup_bands_tab(curr->meta); disable_meta_button_if_necessary(); if (lut_specified) select_lut(lut); } if (n_images_loaded>0) { asfPrintStatus("Currently displaying %d: %s\n", current_image_info_index, curr->filename); } glade_xml_signal_autoconnect(glade_xml); gtk_main (); // If the last viewed file left behind a (temporary) color map lut, // then get rid of it if (fileExists(embedded_tiff_lut_file)) remove(embedded_tiff_lut_file); if (fileExists(embedded_asf_colormap_file)) remove(embedded_asf_colormap_file); image_info_free(curr); free_shapes(); exit (EXIT_SUCCESS); }