// Main program body. int main (int argc, char *argv[]) { char *inFile, *maskFile, *outFile; int currArg = 1; int NUM_ARGS = 3; handle_license_and_version_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(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } 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]; maskFile = argv[currArg+1]; outFile = argv[currArg+2]; char *in_base = get_basename(inFile); char *out_base = get_basename(outFile); asfPrintStatus("Clipping image: %s -> %s\n", in_base, out_base); clip(inFile, maskFile, outFile); asfPrintStatus("Done.\n"); free(in_base); free(out_base); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int addSpeckle = TRUE; int water = FALSE; char *inFile, *outFile; handle_license_and_version_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(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-water","--water",NULL)) { water = TRUE; } 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); } inFile = argv[currArg]; outFile = argv[currArg+1]; shaded_relief(inFile, outFile, addSpeckle, water); exit(EXIT_SUCCESS); }
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; }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *outFile; int currArg = 1; int NUM_ARGS = 2; int insar=FALSE, polarimetry=FALSE; handle_license_and_version_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(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else if (strmatches(key,"-insar_stack","--insar_stack","-i",NULL)) { insar = TRUE; } else if (strmatches(key,"-polarimetry_stack","--polarimetry_stack","-p",NULL)) { polarimetry = TRUE; } 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]; asf_airsar_import(inFile, outFile, insar, polarimetry); asfPrintStatus("\nDone.\n"); return EXIT_SUCCESS; }
// Main program body. int main (int argc, char *argv[]) { int currArg = 1; int NUM_ARGS = 2; char *inFile, *outFile; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc >= 2 && strmatches(argv[1],"-help","--help",NULL)) print_help(); if (argc<2) scale_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 if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments. Expected %d, got %d.\n", NUM_ARGS, argc-currArg); scale_usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); scale_usage(argv[0]); } inFile = argv[currArg]; outFile = argv[currArg+1]; int fail = asf_logscale(inFile, outFile); int ok = !fail; asfPrintStatus(ok ? "Done.\n" : "Failed.\n"); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
// Main program body. int main (int argc, char *argv[]) { int currArg = 1; int NUM_ARGS = 4; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc >= 2 && strmatches(argv[1],"-help","--help",NULL)) print_help(); if (argc<3) rtc_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 if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strncpy_safe(logFile,GET_ARG(1),256); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments. Expected %d, got %d.\n", NUM_ARGS, argc-currArg); rtc_usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); rtc_usage(argv[0]); } int fail = uavsar_rtc(argv[currArg], argv[currArg+1], argv[currArg+2], argv[currArg+3]); asfPrintStatus(fail ? "Failed.\n" : "Done.\n"); return fail ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc,char *argv[]) { char infile[255], outfile[255]; if (argc > 1) { check_for_help(argc, argv); handle_license_and_version_args(argc, argv, TOOL_NAME); } if (argc != 3) { usage(); exit(1); } create_name(infile, argv[1], ".img"); create_name(outfile, argv[2], ".img"); deskew(infile, outfile); return 0; }
int main(int argc, char *argv[]) { char inFile[512], *configFile=NULL, type[10]; const int pid = getpid(); extern int logflag, quietflag; int quiet_f; /* log_f is a static global */ int createFlag = FLAG_NOT_SET; // create configuration file flag int configFlag = FLAG_NOT_SET; // use configuration file flag logflag = quietflag = FALSE; log_f = quiet_f = FLAG_NOT_SET; // Begin command line parsing *********************************************** if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } get_asf_share_dir_with_argv0(argv[0]); handle_license_and_version_args(argc, argv, ASF_NAME_STRING); // Check which options were provided log_f = checkForOption("-log", argc, argv); quiet_f = checkForOption("-quiet", argc, argv); createFlag = checkForOption("-create", argc, argv); configFlag = checkForOption("-config", argc, argv); // We need to make sure the user specified the proper number of arguments int needed_args = 1 + REQUIRED_ARGS; // command & REQUIRED_ARGS int num_flags = 0; if (log_f != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (quiet_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option if (createFlag != FLAG_NOT_SET) {needed_args += 3; num_flags++;} // option & params if (configFlag != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param // Make sure we have the right number of args if(argc != needed_args) { print_usage(); } // Make sure all options occur before the config file name argument if (num_flags == 1 && (log_f > 1 || quiet_f > 1)) { print_usage(); } else if (num_flags > 1 && (log_f >= argc - REQUIRED_ARGS - 1 || quiet_f >= argc - REQUIRED_ARGS - 1)) { print_usage(); } // Make sure that only one option is used if (createFlag != FLAG_NOT_SET && configFlag != FLAG_NOT_SET) asfPrintError("The tool can either create or use the " "configuration file, not both!\n"); // Do the actual flagging & such for each flag if (createFlag != FLAG_NOT_SET) { sprintf(type, "%s", argv[createFlag+1]); configFile = (char *) MALLOC(sizeof(char)*1024); sprintf(configFile, "%s", argv[createFlag+2]); } if (configFlag != FLAG_NOT_SET) { configFile = (char *) MALLOC(sizeof(char)*1024); sprintf(configFile, "%s", argv[configFlag+1]); } if (log_f != FLAG_NOT_SET) { strcpy(logFile, argv[log_f+1]); } else { // default behavior: log to tmp<pid>.log sprintf(logFile, "tmp%i.log", pid); } logflag = TRUE; fLog = FOPEN(logFile, "a"); // Set old school quiet flag (for use in our libraries) quietflag = quiet_f != FLAG_NOT_SET; // Fetch required arguments strcpy(inFile, argv[argc-1]); // Report the command line asfSplashScreen(argc, argv); // Initialze structure dataset_t *data = (dataset_t *) MALLOC(sizeof(dataset_t)); strcpy(data->dataset_id, MAGIC_UNSET_STRING); strcpy(data->origin, MAGIC_UNSET_STRING); strcpy(data->title, MAGIC_UNSET_STRING); strcpy(data->online_link, MAGIC_UNSET_STRING); data->west_bounding = MAGIC_UNSET_DOUBLE; data->east_bounding = MAGIC_UNSET_DOUBLE; data->north_bounding = MAGIC_UNSET_DOUBLE; data->south_bounding = MAGIC_UNSET_DOUBLE; data->near_start_lat = MAGIC_UNSET_DOUBLE; data->near_start_lon = MAGIC_UNSET_DOUBLE; data->far_start_lat = MAGIC_UNSET_DOUBLE; data->far_start_lon = MAGIC_UNSET_DOUBLE; data->far_end_lat = MAGIC_UNSET_DOUBLE; data->far_end_lon = MAGIC_UNSET_DOUBLE; data->near_end_lat = MAGIC_UNSET_DOUBLE; data->near_end_lon = MAGIC_UNSET_DOUBLE; data->center_lat = MAGIC_UNSET_DOUBLE; data->center_lon = MAGIC_UNSET_DOUBLE; strcpy(data->processing_level, MAGIC_UNSET_STRING); strcpy(data->platform, MAGIC_UNSET_STRING); strcpy(data->instrument, MAGIC_UNSET_STRING); data->band_count = MAGIC_UNSET_INT; data->browse_location = NULL; data->browse_format = NULL; strcpy(data->access, MAGIC_UNSET_STRING); strcpy(data->copyright, MAGIC_UNSET_STRING); data->start_time = NULL; data->center_time = NULL; data->end_time = NULL; strcpy(data->orbit_direction, MAGIC_UNSET_STRING); strcpy(data->mode, MAGIC_UNSET_STRING); strcpy(data->spatial_reference, MAGIC_UNSET_STRING); strcpy(data->cell_value, MAGIC_UNSET_STRING); strcpy(data->raster_object, MAGIC_UNSET_STRING); data->row_count = MAGIC_UNSET_INT; data->col_count = MAGIC_UNSET_INT; strcpy(data->format, MAGIC_UNSET_STRING); data->fees = MAGIC_UNSET_DOUBLE; // Open XML for reading xmlDoc *doc = xmlReadFile(inFile, NULL, 0); if (!doc) asfPrintError("Could not parse metadata file (%s)\n", inFile); // Read in all parameters and perform error checking char string[512], tmp[255], errorMessage[8192]="Metadata parsing errors:\n"; int nValue, error = FALSE; double fValue; // Dataset ID strcpy(string, xml_get_string_value(doc, "metadata.idinfo.datsetid")); if (strlen(string) > MAX_DATASET_ID) { error = TRUE; sprintf(tmp, "Dataset ID - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_DATASET_ID); strcat(errorMessage, tmp); } else { strcpy(data->dataset_id, xml_get_string_value(doc, "metadata.idinfo.datsetid")); //printf("Dataset ID: %s\n", data->dataset_id); } // Origin strcpy(string, xml_get_string_value(doc, "metadata.idinfo.citation.citeinfo.origin")); if (strlen(string) > MAX_ORIGIN) { error = TRUE; sprintf(tmp, "Origin - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_ORIGIN); strcat(errorMessage, tmp); } else { strcpy(data->origin, xml_get_string_value(doc, "metadata.idinfo.citation.citeinfo.origin")); //printf("Origin: %s\n", data->origin); } // Title strcpy(string, xml_get_string_value(doc, "metadata.idinfo.citation.citeinfo.title")); if (strlen(string) > MAX_TITLE) { error = TRUE; sprintf(tmp, "Title - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_TITLE); strcat(errorMessage, tmp); } else { strcpy(data->title, xml_get_string_value(doc, "metadata.idinfo.citation.citeinfo.title")); //printf("Title: %s\n", data->title); } // Online link strcpy(string, xml_get_string_value(doc, "metadata.idinfo.citation.citeinfo.onlink")); if (strlen(string) > MAX_ONLINE_LINK) { error = TRUE; sprintf(tmp, "Online link - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_ONLINE_LINK); strcat(errorMessage, tmp); } else { strcpy(data->online_link, xml_get_string_value(doc, "metadata.idinfo.citation.citeinfo.onlink")); //printf("Online link: %s\n", data->online_link); } // West bounding coordinate fValue = xml_get_double_value(doc, "metadata.idinfo.spdom.bounding.westbc"); if (fValue < -180.0 || fValue > 180.0) { error = TRUE; sprintf(tmp, "West bounding coordinate - Value (%.4lf) outside the " "expected value range (-180.0 < value < 180.0)\n", fValue); strcat(errorMessage, tmp); } else { data->west_bounding = xml_get_double_value(doc, "metadata.idinfo.spdom.bounding.westbc"); //printf("West bounding coordinate: %.4lf\n", data->west_bounding); } // East bounding coordinate fValue = xml_get_double_value(doc, "metadata.idinfo.spdom.bounding.eastbc"); if (fValue < -180.0 || fValue > 180.0) { error = TRUE; sprintf(tmp, "East bounding coordinate - Value (%.4lf) outside the " "expected value range (-180.0 < value < 180.0)\n", fValue); strcat(errorMessage, tmp); } else { data->east_bounding = xml_get_double_value(doc, "metadata.idinfo.spdom.bounding.eastbc"); //printf("East bounding coordinate: %.4lf\n", data->east_bounding); } // North bounding coordinate fValue = xml_get_double_value(doc, "metadata.idinfo.spdom.bounding.northbc"); if (fValue < -90.0 || fValue > 90.0) { error = TRUE; sprintf(tmp, "West bounding coordinate - Value (%.4lf) outside the " "expected value range (-90.0 < value < 90.0)\n", fValue); strcat(errorMessage, tmp); } else { data->north_bounding = xml_get_double_value(doc, "metadata.idinfo.spdom.bounding.northbc"); //printf("West bounding coordinate: %.4lf\n", data->north_bounding); } // South bounding coordinate fValue = xml_get_double_value(doc, "metadata.idinfo.spdom.bounding.southbc"); if (fValue < -90.0 || fValue > 90.0) { error = TRUE; sprintf(tmp, "South bounding coordinate - Value (%.4lf) outside the " "expected value range (-90.0 < value < 90.0)\n", fValue); strcat(errorMessage, tmp); } else { data->south_bounding = xml_get_double_value(doc, "metadata.idinfo.spdom.bounding.southbc"); //printf("South bounding coordinate: %.4lf\n", data->south_bounding); } // Open KML for reading char centerFile[512], boundaryFile[512], *baseName; char coordStr[50]; float height; baseName = get_basename(inFile); sprintf(boundaryFile, "%s_boundary.kml", baseName); sprintf(centerFile, "%s_center.kml", baseName); xmlDoc *xmlBoundary = xmlReadFile(boundaryFile, NULL, 0); if (!xmlBoundary) asfPrintError("Could not parse boundary file (%s)\n", boundaryFile); else { strcpy(coordStr, xml_get_string_value(xmlBoundary, "kml.Document.Placemark.Polygon.outerBoundaryIs.LinearRing.coordinates")); sscanf(coordStr, "%f,%f,%f\n%f,%f,%f\n%f,%f,%f\n%f,%f", &data->near_start_lat, &data->near_start_lon, &height, &data->near_end_lat, &data->near_end_lon, &height, &data->far_end_lat, &data->far_end_lon, &height, &data->far_start_lat, &data->far_start_lon); //printf("Near start latitude: %.4f\n", data->near_start_lat); //printf("Near start longitude: %.4f\n", data->near_start_lon); //printf("Near end latitude: %.4f\n", data->near_end_lat); //printf("Near end longitude: %.4f\n", data->near_end_lon); //printf("Far start latitude: %.4f\n", data->far_start_lat); //printf("Far start longitude: %.4f\n", data->far_start_lon); //printf("Far end latitude: %.4f\n", data->far_end_lat); //printf("Far end longitude: %.4f\n", data->far_end_lon); } xmlFreeDoc(xmlBoundary); xmlDoc *xmlCenter = xmlReadFile(centerFile, NULL, 0); if (!xmlCenter) asfPrintWarning("Could not parse center point file (%s)\n", centerFile); else { strcpy(coordStr, xml_get_string_value(xmlCenter, "kml.Document.Placemark.Point.coordinates")); sscanf(coordStr, "%f,%f", &data->center_lat, &data->center_lon); //printf("Center latitude: %.4f\n", data->center_lat); //printf("Center longitude: %.4f\n", data->center_lon); } xmlFreeDoc(xmlCenter); // Processing level strcpy(string, xml_get_string_value(doc, "metadata.idinfo.proclevl.prolevid")); if (strlen(string) > MAX_PROCESSING_LEVEL) { error = TRUE; sprintf(tmp, "Processing level - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_PROCESSING_LEVEL); strcat(errorMessage, tmp); } else { strcpy(data->processing_level, xml_get_string_value(doc, "metadata.idinfo.proclevl.prolevid")); //printf("Processing level: %s\n", data->processing_level); } // Place strcpy(string, xml_get_string_value(doc, "metadata.idinfo.keywords.place.placekey[0]")); if (strlen(string) > MAX_PLACE) { error = TRUE; sprintf(tmp, "Place - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_PLACE); strcat(errorMessage, tmp); } else { data->place = (char *) MALLOC(sizeof(char)*MAX_PLACE); strcpy(data->place, xml_get_string_value(doc, "metadata.idinfo.keywords.place.placekey[0]")); //printf("Place: %s\n", data->place); } // Platform strcpy(string, xml_get_string_value(doc, "metadata.idinfo.plainsid.platflnm")); if (strlen(string) > MAX_PLATFORM) { error = TRUE; sprintf(tmp, "Platform - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_PLATFORM); strcat(errorMessage, tmp); } else { strcpy(data->platform, xml_get_string_value(doc, "metadata.idinfo.plainsid.platflnm")); //printf("Platform: %s\n", data->platform); } // Instrument strcpy(string, xml_get_string_value(doc, "metadata.idinfo.plainsid.instflnm")); if (strlen(string) > MAX_INSTRUMENT) { error = TRUE; sprintf(tmp, "Instrument - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_INSTRUMENT); strcat(errorMessage, tmp); } else { strcpy(data->instrument, xml_get_string_value(doc, "metadata.idinfo.plainsid.instflnm")); //printf("Instrument: %s\n", data->instrument); } // Number of bands nValue = xml_get_int_value(doc, "metadata.idinfo.bandidnt.numbands"); if (nValue < 0) { error = TRUE; sprintf(tmp, "Number of bands - Value (%i) outside the " "expected value range (value > 0)\n", nValue); strcat(errorMessage, tmp); } else { data->band_count = xml_get_int_value(doc, "metadata.idinfo.bandidnt.numbands"); //printf("Number of bands: %i\n", data->band_count); } // Browse image location strcpy(string, xml_get_string_value(doc, "metadata.idinfo.browse.browsen")); if (strlen(string) > MAX_BROWSE_LOCATION) { error = TRUE; sprintf(tmp, "Browse image location - String length: %d, allowed " "characters: %d\n", (int) strlen(string), MAX_BROWSE_LOCATION); strcat(errorMessage, tmp); } else if (strcmp_case(string, MAGIC_UNSET_STRING) != 0) { data->browse_location = (char *) MALLOC(sizeof(char)*MAX_BROWSE_LOCATION); strcpy(data->browse_location, xml_get_string_value(doc, "metadata.idinfo.browse.browsen")); //printf("Browse image location: %s\n", data->browse_location); } // Browse image format strcpy(string, xml_get_string_value(doc, "metadata.idinfo.browse.browset")); if (strlen(string) > MAX_BROWSE_FORMAT) { error = TRUE; sprintf(tmp, "Browse image format - String length: %d, allowed characters:" " %d\n", (int) strlen(string), MAX_BROWSE_FORMAT); strcat(errorMessage, tmp); } else if (strcmp_case(string, MAGIC_UNSET_STRING) != 0) { data->browse_format = (char *) MALLOC(sizeof(char)*MAX_BROWSE_FORMAT); strcpy(data->browse_format, xml_get_string_value(doc, "metadata.idinfo.browse.browset")); //printf("Browse format: %s\n", data->browse_format); } // Data access level strcpy(string, xml_get_string_value(doc, "metadata.idinfo.secinfo.secclass")); if (strlen(string) > MAX_ACCESS) { error = TRUE; sprintf(tmp, "Data access level - String length: %d, allowed characters: " "%d\n", (int) strlen(string), MAX_ACCESS); strcat(errorMessage, tmp); } else { strcpy(data->access, xml_get_string_value(doc, "metadata.idinfo.secinfo.secclass")); //printf("Data access level: %s\n", data->access); } // Copyright strcpy(string, xml_get_string_value(doc, "metadata.idinfo.copyright")); if (strlen(string) > MAX_COPYRIGHT) { error = TRUE; sprintf(tmp, "Copyright - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_COPYRIGHT); strcat(errorMessage, tmp); } else { strcpy(data->copyright, xml_get_string_value(doc, "metadata.idinfo.copyright")); //printf("Copyright: %s\n", data->copyright); } // Start time char dateStr[25], timeStr[25], *message; int year, month, day, hour, minute, second; strcpy(dateStr, xml_get_string_value(doc, "metadata.idinfo.timeperd.timeinfo.rngdates.begdate")); year = subStr(0, 4, dateStr); month = subStr(4, 2, dateStr); day = subStr(6, 2, dateStr); strcpy(timeStr, xml_get_string_value(doc, "metadata.idinfo.timeperd.timeinfo.rngdates.begtime")); hour = subStr(0, 2, timeStr); minute = subStr(2, 2, timeStr); second = subStr(4, 2, timeStr); if (strcmp_case(dateStr, MAGIC_UNSET_STRING) != 0 && strcmp_case(timeStr, MAGIC_UNSET_STRING) != 0) { if (isNumeric(dateStr) && isNumeric(timeStr)) { message = checkTime(year, month, day, hour, minute, second); if (message) { error = TRUE; sprintf(tmp, "Start time - %s", message); strcat(errorMessage, tmp); } else { data->start_time = (char *) MALLOC(sizeof(char)*MAX_START_TIME); sprintf(data->start_time, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second); //printf("Start time: %s\n", data->start_time); } } } // Center time strcpy(dateStr, xml_get_string_value(doc, "metadata.idinfo.timeperd.timeinfo.sngdate.caldate")); year = subStr(0, 4, dateStr); month = subStr(4, 2, dateStr); day = subStr(6, 2, dateStr); strcpy(timeStr, xml_get_string_value(doc, "metadata.idinfo.timeperd.timeinfo.sngdate.time")); hour = subStr(0, 2, timeStr); minute = subStr(2, 2, timeStr); second = subStr(4, 2, timeStr); if (strcmp_case(dateStr, MAGIC_UNSET_STRING) != 0 && strcmp_case(timeStr, MAGIC_UNSET_STRING) != 0) { if (isNumeric(dateStr) && isNumeric(timeStr)) { message = checkTime(year, month, day, hour, minute, second); if (message) { error = TRUE; sprintf(tmp, "Center time - %s", message); strcat(errorMessage, tmp); } else { data->center_time = (char *) MALLOC(sizeof(char)*MAX_CENTER_TIME); sprintf(data->center_time, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second); //printf("Center time: %s\n", data->center_time); } } } // End time strcpy(dateStr, xml_get_string_value(doc, "metadata.idinfo.timeperd.timeinfo.rngdates.enddate")); year = subStr(0, 4, dateStr); month = subStr(4, 2, dateStr); day = subStr(6, 2, dateStr); strcpy(timeStr, xml_get_string_value(doc, "metadata.idinfo.timeperd.timeinfo.rngdates.endtime")); hour = subStr(0, 2, timeStr); minute = subStr(2, 2, timeStr); second = subStr(4, 2, timeStr); if (strcmp_case(dateStr, MAGIC_UNSET_STRING) != 0 && strcmp_case(timeStr, MAGIC_UNSET_STRING) != 0) { if (isNumeric(dateStr) && isNumeric(timeStr)) { message = checkTime(year, month, day, hour, minute, second); if (message) { error = TRUE; sprintf(tmp, "End time - %s", message); strcat(errorMessage, tmp); } else { data->end_time = (char *) MALLOC(sizeof(char)*MAX_END_TIME); sprintf(data->end_time, "%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second); //printf("End time: %s\n", data->end_time); } } } // Orbit direction nValue = xml_get_int_value(doc, "metadata.dataqual.acqinfo.ascdscin"); if (nValue != MAGIC_UNSET_INT) { if (nValue < 0 || nValue > 1) { error = TRUE; sprintf(tmp, "Orbit direction - Value (%i) outside the " "expected value range (0 <= value <= 1)\n", nValue); strcat(errorMessage, tmp); } else { if (nValue == 0) strcpy(data->orbit_direction, "Ascending"); else if (nValue == 1) strcpy(data->orbit_direction, "Descending"); //printf("Orbit direction: %s\n", data->orbit_direction); } } else strcpy(data->orbit_direction, "Unknown"); // Imaging mode strcpy(string, xml_get_string_value(doc, "metadata.idinfo.plainsid.mode")); if (strcmp_case(string, MAGIC_UNSET_STRING) != 0) { if (strlen(string) > MAX_MODE) { error = TRUE; sprintf(tmp, "Imaging mode - String length: %d, allowed characters: %d" "\n", (int) strlen(string), MAX_MODE); strcat(errorMessage, tmp); } else { strcpy(data->mode, xml_get_string_value(doc, "metadata.idinfo.plainsid.mode")); //printf("Imaging mode: %s\n", data->mode); } } else strcpy(data->mode, "Unknown"); // Spatial reference strcpy(string, xml_get_string_value(doc, "metadata.spdoinfo.direct")); if (strcmp_case(string, "Point") != 0 && strcmp_case(string, "Vector") != 0 && strcmp_case(string, "Raster") != 0) { error = TRUE; sprintf(tmp, "Spatial reference - String (%s) not valid; expected " "\"Point\", \"Vector\" or \"Raster\"\n", string); strcat(errorMessage, tmp); } else { strcpy(data->spatial_reference, xml_get_string_value(doc, "metadata.spdoinfo.direct")); //printf("Spatial reference: %s\n", data->spatial_reference); } // Cell value type strcpy(string, xml_get_string_value(doc, "metadata.spdoinfo.rastinfo.cvaltype")); if (strlen(string) > MAX_CELL_VALUE) { error = TRUE; sprintf(tmp, "Cell value type - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_CELL_VALUE); strcat(errorMessage, tmp); } else { strcpy(data->cell_value, xml_get_string_value(doc, "metadata.spdoinfo.rastinfo.cvaltype")); //printf("Cell value type: %s\n", data->cell_value); } // Raster object type strcpy(string, xml_get_string_value(doc, "metadata.spdoinfo.rastinfo.rasttype")); if (strcmp_case(string, "Point") != 0 && strcmp_case(string, "Pixel") != 0 && strcmp_case(string, "Grid Cell") != 0 && strcmp_case(string, "Voxel") != 0 && strcmp_case(string, "Swath") != 0) { error = TRUE; sprintf(tmp, "Raster object type - String (%s) not valid; expected " "\"Point\", \"Pixel\", \"Grid Cell\", \"Voxel\" or \"Swath\".\n", string); strcat(errorMessage, tmp); } else { strcpy(data->raster_object, xml_get_string_value(doc, "metadata.spdoinfo.rastinfo.rasttype")); //printf("Raster object type: %s\n", data->raster_object); } // Number of rows nValue = xml_get_int_value(doc, "metadata.spdoinfo.rastinfo.rowcount"); if (nValue < 0) { error = TRUE; sprintf(tmp, "Number of rows - Value (%i) outside the " "expected value range (value > 0)\n", nValue); strcat(errorMessage, tmp); } else { data->row_count = xml_get_int_value(doc, "metadata.spdoinfo.rastinfo.rowcount"); //printf("Number of rows: %i\n", data->row_count); } // Number of columns nValue = xml_get_int_value(doc, "metadata.spdoinfo.rastinfo.colcount"); if (nValue < 0) { error = TRUE; sprintf(tmp, "Number of columns - Value (%i) outside the " "expected value range (value > 0)\n", nValue); strcat(errorMessage, tmp); } else { data->col_count = xml_get_int_value(doc, "metadata.spdoinfo.rastinfo.colcount"); //printf("Number of columns: %i\n", data->col_count); } // Format name strcpy(string, xml_get_string_value(doc, "metadata.distinfo.stdorder.digform.digtinfo.formname")); if (strlen(string) > MAX_FORMAT) { error = TRUE; sprintf(tmp, "Format name - String length: %d, allowed characters: %d\n", (int) strlen(string), MAX_FORMAT); strcat(errorMessage, tmp); } else { strcpy(data->format, xml_get_string_value(doc, "metadata.distinfo.stdorder.digform.digtinfo.formname")); //printf("Format name: %s\n", data->format); } // Fees fValue = xml_get_double_value(doc, "metadata.distinfo.stdorder.fees"); if (fValue < 0.0) { error = TRUE; sprintf(tmp, "Fees - Value (%.2lf) outside the expected value range " "(value >= 0.0)\n", fValue); strcat(errorMessage, tmp); } else { data->fees = xml_get_double_value(doc, "metadata.distinfo.stdorder.fees"); //printf("Fees: %.2lf\n", data->fees); } if (error) asfPrintError("%s", errorMessage); xmlFreeDoc(doc); xmlCleanupParser(); FREE(configFile); FCLOSE(fLog); remove(logFile); // Add dataset to database addData(data); FREE(data); asfPrintStatus("\nSuccessful completion!\n\n"); return(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { char inFile[512], outFile[512], *projFile=NULL, type[10]; const int pid = getpid(); extern int logflag, quietflag; int quiet_f; /* log_f is a static global */ int proj_f, pixel_f, list_f, ii, file_count, list=FALSE; char **import_files; double pixel_size = -99; logflag = quietflag = FALSE; log_f = quiet_f = FLAG_NOT_SET; // Begin command line parsing *********************************************** if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } get_asf_share_dir_with_argv0(argv[0]); handle_license_and_version_args(argc, argv, ASF_NAME_STRING); // Check which options were provided log_f = checkForOption("-log", argc, argv); quiet_f = checkForOption("-quiet", argc, argv); proj_f = checkForOption("-proj", argc, argv); pixel_f = checkForOption("-pixel-size", argc, argv); list_f = checkForOption("-list", argc, argv); // We need to make sure the user specified the proper number of arguments int needed_args = 3 + REQUIRED_ARGS; // command & REQUIRED_ARGS int num_flags = 0; if (log_f != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (quiet_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option if (proj_f != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (pixel_f != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (list_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option // Make sure we have the right number of args if(argc != needed_args) { print_usage(); } // Make sure all options occur before the config file name argument if (num_flags == 1 && (log_f > 1 || quiet_f > 1)) { print_usage(); } else if (num_flags > 1 && (log_f >= argc - REQUIRED_ARGS - 1 || quiet_f >= argc - REQUIRED_ARGS - 1)) { print_usage(); } if (proj_f != FLAG_NOT_SET) { projFile = (char *) MALLOC(sizeof(char)*512); strcpy(projFile, argv[proj_f+1]); } if (pixel_f != FLAG_NOT_SET) { pixel_size = atof(argv[pixel_f+1]); } if (list_f != FLAG_NOT_SET) { list = TRUE; } if (log_f != FLAG_NOT_SET) { strcpy(logFile, argv[log_f+1]); } else { // default behavior: log to tmp<pid>.log sprintf(logFile, "tmp%i.log", pid); } logflag = TRUE; fLog = FOPEN(logFile, "a"); // Set old school quiet flag (for use in our libraries) quietflag = quiet_f != FLAG_NOT_SET; // Fetch required arguments strcpy(inFile, argv[argc-3]); strcpy(outFile, argv[argc-2]); strcpy(type, argv[argc-1]); // Report the command line asfSplashScreen(argc, argv); char *tmp_dir = (char *) MALLOC(sizeof(char)*512); char *tmpFile = (char *) MALLOC(sizeof(char)*512); if (projFile || list || (strcmp_case(type, "ASTER") == 0 && strcmp_case(findExt(inFile), ".ZIP") == 0)) { strcpy(tmp_dir, "tmp_dem-"); strcat(tmp_dir, time_stamp_dir()); create_clean_dir(tmp_dir); sprintf(tmpFile, "%s%cimport", tmp_dir, DIR_SEPARATOR); import_dem(inFile, list, tmpFile, type, tmp_dir, &import_files, &file_count); } else { strcpy(tmp_dir, "./"); import_dem(inFile, list, outFile, type, tmp_dir, &import_files, &file_count); } if (projFile) { project_parameters_t pps; projection_type_t proj_type; datum_type_t datum; spheroid_type_t spheroid; if (fileExists(projFile)) read_proj_file(projFile, &pps, &proj_type, &datum, &spheroid); else { projFile = get_proj_file(projFile); read_proj_file(projFile, &pps, &proj_type, &datum, &spheroid); } if (file_count > 1) asf_mosaic(&pps, proj_type, FALSE, RESAMPLE_BILINEAR, 0.0, datum, spheroid, pixel_size, FALSE, 0, import_files, outFile, 0.0, -999, 999, -999, 999, "OVERLAY", FALSE); else asf_geocode(&pps, proj_type, FALSE, RESAMPLE_BILINEAR, 0.0, datum, pixel_size, NULL, tmpFile, outFile, 0.0, FALSE); } else if (strlen(tmp_dir) > 2) { /* char *imgFile = (char *) MALLOC(sizeof(char)*512); char *metaFile = (char *) MALLOC(sizeof(char)*512); for (ii=0; ii<file_count; ii++) { sprintf(imgFile, "%s.img", get_basename(import_files[ii])); fileCopy(import_files[ii], imgFile); sprintf(metaFile, "%s.meta", get_basename(import_files[ii])); sprintf(tmpFile, "%s%c%s.meta", tmp_dir, DIR_SEPARATOR, get_basename(import_files[ii])); fileCopy(tmpFile, metaFile); } FREE(imgFile); FREE(metaFile); */ combine(import_files, file_count, outFile); } for (ii=0; ii<file_count; ii++) FREE(import_files[ii]); FREE(import_files); if (strlen(tmp_dir) > 2) remove_dir(tmp_dir); FREE(tmp_dir); FREE(tmpFile); asfPrintStatus("\nSuccessful completion!\n\n"); FCLOSE(fLog); remove(logFile); return(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { char inBaseName[256]=""; char outBaseName[256]=""; char *colormapName = NULL; char band_id[256]=""; double wind_dir = 315.0; // Default to wind from the NW int cmod4 = 0; char *landmaskFile = NULL; double landmaskHeight = atof(DEFAULT_LANDMASK_HEIGHT); platform_type_t platform_type; char *demFile = NULL; int ii; int flags[NUM_WINDSPEED_FLAGS]; /* Set all flags to 'not set' */ for (ii=0; ii<NUM_WINDSPEED_FLAGS; ii++) { flags[ii] = FLAG_NOT_SET; } /**********************BEGIN COMMAND LINE PARSING STUFF**********************/ if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } handle_license_and_version_args(argc, argv, ASF_NAME_STRING); /*Check to see if any options were provided*/ flags[f_LOG] = checkForOption("-log", argc, argv); flags[f_QUIET] = checkForOption("-quiet", argc, argv); flags[f_REAL_QUIET] = checkForOption("-real-quiet", argc, argv); flags[f_BAND] = checkForOption("-band", argc, argv); flags[f_COLORMAP] = checkForOption("-colormap", argc, argv); flags[f_WINDDIR] = checkForOption("-wind-dir", argc, argv); flags[f_CMOD4] = checkForOption("-cmod4", argc, argv); flags[f_LANDMASK] = checkForOption("-landmask", argc, argv); flags[f_LANDMASK_HEIGHT] = checkForOption("-landmask-height", argc, argv); flags[f_DEM] = checkForOption("-dem", argc, argv); { /*We need to make sure the user specified the proper number of arguments*/ int needed_args = 1 + REQUIRED_ARGS; /*command + REQUIRED_ARGS*/ if(flags[f_LOG] != FLAG_NOT_SET) needed_args += 2;/*option & parameter*/ if(flags[f_QUIET] != FLAG_NOT_SET) needed_args += 1;/*option*/ if(flags[f_REAL_QUIET] != FLAG_NOT_SET) needed_args += 1;/*option*/ if(flags[f_BAND] != FLAG_NOT_SET) needed_args += 2;/*option & parameter*/ if(flags[f_COLORMAP] != FLAG_NOT_SET) needed_args += 2; /*option & parameter*/ if(flags[f_WINDDIR] != FLAG_NOT_SET) needed_args += 2; /*option & parameter*/ if(flags[f_CMOD4] != FLAG_NOT_SET) needed_args += 2; /*option & parameter*/ if(flags[f_LANDMASK] != FLAG_NOT_SET) needed_args += 2; /*option & parameter*/ if(flags[f_LANDMASK_HEIGHT] != FLAG_NOT_SET) needed_args += 2; /*option & parameter*/ if(flags[f_DEM] != FLAG_NOT_SET) needed_args += 2; /*option & parameter*/ /*Make sure we have enough arguments*/ if(argc != needed_args) print_usage();/*This exits with a failure*/ } if(flags[f_LOG] != FLAG_NOT_SET) /*Make sure the field following -log isn't another option*/ if( argv[flags[f_LOG]+1][0] == '-' || flags[f_LOG] >= argc-REQUIRED_ARGS) print_usage(); if(flags[f_BAND] != FLAG_NOT_SET) /*Make sure the field following -format isn't another option*/ if( argv[flags[f_BAND]+1][0] == '-' || flags[f_BAND] >= argc-REQUIRED_ARGS) print_usage(); if(flags[f_COLORMAP] != FLAG_NOT_SET) /*Make sure the field following -colormap isn't another option*/ if( argv[flags[f_COLORMAP]+1][0] == '-' || flags[f_COLORMAP] >= argc-REQUIRED_ARGS) print_usage(); if(flags[f_WINDDIR] != FLAG_NOT_SET) if( argv[flags[f_WINDDIR]+1][0] == '-' || flags[f_WINDDIR] >= argc-REQUIRED_ARGS) print_usage(); if(flags[f_CMOD4] != FLAG_NOT_SET) if( argv[flags[f_CMOD4]+1][0] == '-' || flags[f_CMOD4] >= argc-REQUIRED_ARGS) print_usage(); if(flags[f_LANDMASK] != FLAG_NOT_SET) if( argv[flags[f_LANDMASK]+1][0] == '-' || flags[f_LANDMASK] >= argc-REQUIRED_ARGS) print_usage(); if(flags[f_LANDMASK_HEIGHT] != FLAG_NOT_SET) if( argv[flags[f_LANDMASK_HEIGHT]+1][0] == '-' || flags[f_LANDMASK_HEIGHT] >= argc-REQUIRED_ARGS) print_usage(); if(flags[f_DEM] != FLAG_NOT_SET) if( argv[flags[f_DEM]+1][0] == '-' || flags[f_DEM] >= argc-REQUIRED_ARGS) print_usage(); /* Be sure to open log ASAP */ if(flags[f_LOG] != FLAG_NOT_SET) strcpy(logFile, argv[flags[f_LOG] + 1]); else /*default behavior: log to tmp<pid>.log*/ sprintf(logFile, "tmp%i.log", (int)getpid()); logflag = TRUE; /* Since we always log, set the old school logflag to true */ // Open log file in output folder char path[1024], tmp[1024]; split_dir_and_file(argv[argc-1], path, tmp); strcpy(tmp, logFile); sprintf(logFile, "%s%s", path, tmp); fLog = fopen(logFile, "a"); if ( fLog == NULL ) { logflag = FALSE; } /* Set old school quiet flag (for use in our libraries) */ quietflag = flags[f_QUIET] != FLAG_NOT_SET; if (flags[f_REAL_QUIET] != FLAG_NOT_SET) quietflag = 2; /* We must be close to good enough at this point... log & quiet flags are set Report what was retrieved at the command line */ asfSplashScreen(argc, argv); if(flags[f_COLORMAP] != FLAG_NOT_SET) { colormapName = (char *) MALLOC(sizeof(char)*1024); strcpy(colormapName, argv[flags[f_COLORMAP] + 1]); } if (flags[f_WINDDIR] != FLAG_NOT_SET) { wind_dir = atof(argv[flags[f_WINDDIR]+1]); } if (flags[f_LANDMASK] != FLAG_NOT_SET) { landmaskFile = (char *) MALLOC(sizeof(char)*1024); strncpy(landmaskFile, argv[flags[f_LANDMASK]], 8); } if (flags[f_LANDMASK_HEIGHT] != FLAG_NOT_SET) { landmaskHeight = atof(argv[flags[f_LANDMASK_HEIGHT]]); } if (flags[f_DEM] != FLAG_NOT_SET) { demFile = (char *) MALLOC(sizeof(char)*1024); strncpy(demFile, argv[flags[f_DEM]], 8); } // Check validity if (flags[f_LANDMASK] != FLAG_NOT_SET && (flags[f_LANDMASK_HEIGHT] != FLAG_NOT_SET || flags[f_DEM] != FLAG_NOT_SET)) { asfPrintStatus("\nCannot use the -landmask option together with -landmask-height\n" "or -dem.\n\n"); print_usage(); } if (wind_dir < 0.0 || wind_dir >= 360.0) { asfPrintError("Wind direction specified with the -wind-dir argument must range\n" "from 0.0 up to, but not including, 360.0. Wind direction is specified\n" "as being the direction the wind blows FROM in degrees clockwise from\n" "North, with North being 0.0 degrees.\n"); } if (landmaskHeight <= 0.0) { asfPrintStatus("\nLandmask height set with -landmask-height must be a positive height\n\n"); print_usage(); } if(flags[f_BAND] != FLAG_NOT_SET) { strcpy(band_id, argv[flags[f_BAND] + 1]); if (strlen(band_id) && strcmp("ALL", uc(band_id)) == 0) { strcpy(band_id, ""); } } /* Fetch required arguments */ strcpy(inBaseName, argv[argc - 2]); strcpy(outBaseName, argv[argc - 1]); /***********************END COMMAND LINE PARSING STUFF***********************/ asfSplashScreen (argc, argv); // Check the metadata to find out if this is data we an process meta_parameters *md = meta_read(inBaseName); meta_general *mg = md->general; // convenience ptr meta_sar *ms = md->sar; // convenience ptr if ((strncmp(mg->sensor, "RSAT-1", 6) != 0 && strncmp(mg->sensor, "ERS1", 4) != 0 && strncmp(mg->sensor, "ALOS", 4) != 0 && strncmp(mg->sensor, "TSX-1", 5) != 0) || strncmp(mg->sensor_name, "SAR", 3) != 0) { asfPrintError("Only SAR products from RSAT1, ERS1, ALOS PALSAR, and TERRASAR\n" "are supported. Found sensor %s, sensor_name %s in metadata.\n", mg->sensor, mg->sensor_name); } if (mg->radiometry != r_SIGMA) { asfPrintError("Only sigma-nought products (not in decibels) are currently supported.\n" "See asf_import -help for more info on how to produce these from \n" "original format data.\n"); } if (!strstr(mg->bands, "HH") && !strstr(mg->bands, "VV")) { asfPrintError("Only HH and VV polarizations are supported. Found bands %s\n", mg->bands); } if (ms->image_type != 'G') { asfPrintError("Only ground range images are currently supported. Found %s image\n", (ms->image_type == 'R') ? "GEOREFERENCED" : (ms->image_type == 'S') ? "SLANT RANGE" : (ms->image_type == 'P') ? "MAP PROJECTED" : "UNKNOWN TYPE"); } // As-yet unimplemented feature bail-outs... if (strncmp(mg->sensor, "RSAT-1", 6) != 0) { // Temporary bail-out until we add the other platforms asfPrintError("Platforms other than RSAT1 not yet supported...\n"); } if (flags[f_COLORMAP] != FLAG_NOT_SET || flags[f_CMOD4] != FLAG_NOT_SET || flags[f_LANDMASK] != FLAG_NOT_SET || flags[f_LANDMASK_HEIGHT] != FLAG_NOT_SET || flags[f_DEM] != FLAG_NOT_SET) { asfPrintError("The following options are not yet supported:\n" " -colormap\n" " -cmod4\n" " -landmask\n" " -landmask-height\n" " -dem\n"); } // Determine platform type // RSAT-1 (C-band), ERS1 (C-band), ALOS (L-band), TSX-1 (X-band) platform_type = (strncmp(mg->sensor, "RSAT-1", 6) == 0) ? p_RSAT1 : (strncmp(mg->sensor, "ERS1", 4) == 0) ? p_ERS1 : (strncmp(mg->sensor, "ALOS", 4) == 0) ? p_PALSAR : (strncmp(mg->sensor, "TSX-1", 5) == 0) ? p_TERRASARX : 0; meta_free(md); asf_windspeed(platform_type, band_id, wind_dir, cmod4, landmaskHeight, landmaskFile, demFile, inBaseName, colormapName, outBaseName); FREE(colormapName); FREE(landmaskFile); FREE(demFile); /* If the user didn't ask for a log file then we can nuke the one that we've been keeping since we've finished everything */ if (logflag) { fclose (fLog); remove(logFile); } exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { double min, max; /* Minimum & maximum sample values */ double sum_of_samples=0.0; /* Sum of all samples accounted for */ double sum_of_squared_samples=0.0; /* Sum of all squared samples accounted for*/ double trim_fraction; /* Fraction used to trim the histogram */ int ii; /* Loop index */ long samples_counted=0; /* Number of all samples accounted for */ float *data_line; /* Buffer for a line of samples */ long line, sample; /* Line and sample indices */ long num_lines, num_samples; /* Number of lines and samples */ int percent_complete=0; /* Percent of data sweep completed */ int overmeta_flag=FALSE; /* If TRUE write over current .meta file */ int overstat_flag=FALSE; /* If TRUE write over current .stat file */ int nometa_flag=FALSE; /* If TRUE do not write .meta file */ int nostat_flag=FALSE; /* If TRUE do not write .stat file */ int mask_flag=FALSE; /* TRUE if user specifies a mask value */ int trim_flag=FALSE; /* If TRUE trim histogram */ double mask=NAN; /* Value to ignore while caculating stats*/ char meta_name[261]; /* Meta file name */ meta_parameters *meta; /* SAR meta data structure */ char sar_name[256]; /* SAR file name WITH extention */ FILE *sar_file; /* SAR data file pointer to take stats on*/ stat_parameters *stats; /* Statistics structure */ char stat_name[261]; /* Stats file name */ extern int currArg; /* Pre-initialized to 1 */ /* We initialize these to a magic number for checking. */ long start_line = -1; /* Window starting line. */ long start_sample = -1; /* Window starting sample. */ long window_height = -1; /* Window height in lines. */ long window_width = -1; /* Window width in samples. */ /* parse command line */ handle_license_and_version_args(argc, argv, "stats"); logflag=quietflag=FALSE; while (currArg < (argc-1)) { char *key = argv[currArg++]; if (strmatch(key,"-quiet")) { quietflag=TRUE; } else if (strmatch(key,"-log")) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag=TRUE; } else if (strmatch(key,"-mask")) { CHECK_ARG(1); mask = atof(GET_ARG(1)); mask_flag=TRUE; } else if (strmatch(key,"-overmeta")) { overmeta_flag=TRUE; } else if (strmatch(key,"-overstat")) { overstat_flag=TRUE; } else if (strmatch(key,"-nometa")) { nometa_flag=TRUE; } else if (strmatch(key,"-nostat")) { nostat_flag=TRUE; } else if (strmatch(key,"-startline")) { CHECK_ARG(1); nometa_flag=TRUE; /* Implied. */ start_line = atol(GET_ARG(1)); if ( start_line < 0 ) { printf("error: -startline argument must be greater than or equal to zero\n"); usage(argv[0]); } } else if (strmatch(key,"-startsample")) { CHECK_ARG(1); nometa_flag=TRUE; /* Implied. */ start_sample = atol(GET_ARG(1)); if ( start_sample < 0 ) { printf("error: -startsample argument must be greater than or equal to zero\n"); usage(argv[0]); } } else if (strmatch(key,"-width")) { CHECK_ARG(1); nometa_flag=TRUE; /* Implied. */ window_width = atol(GET_ARG(1)); if ( window_width < 0 ) { printf("error: -width argument must be greater than or equal to zero\n"); usage(argv[0]); } } else if (strmatch(key,"-height")) { CHECK_ARG(1); nometa_flag=TRUE; /* Implied. */ window_height = atol(GET_ARG(1)); if ( window_height < 0 ) { printf("error: -height argument must be greater than or equal to zero\n"); usage(argv[0]); } } else if (strmatch(key,"-trim")) { CHECK_ARG(1); trim_flag=TRUE; /* Implied. */ trim_fraction = atof(GET_ARG(1)); } else {printf( "\n**Invalid option: %s\n",argv[currArg-1]); usage(argv[0]);} } if ((argc-currArg)<1) {printf("Insufficient arguments.\n"); usage(argv[0]);} strcpy (sar_name, argv[currArg]); char *ext = findExt(sar_name); if (ext == NULL || strcmp("IMG", uc(ext)) != 0) { strcpy(sar_name, appendExt(sar_name, ".img")); } create_name(meta_name, sar_name, ".meta"); create_name(stat_name, sar_name, ".stat"); printf("\nProgram: stats\n\n"); if (logflag) { fprintf(fLog, "\nProgram: stats\n\n"); } printf("\nCalculating statistics for %s\n\n", sar_name); if (logflag) { fprintf(fLog,"\nCalculating statistics for %s\n\n", sar_name); } meta = meta_read(meta_name); num_lines = meta->general->line_count; num_samples = meta->general->sample_count; if ( start_line == -1 ) start_line = 0; if ( start_line > num_lines ) { printf("error: -startline argument is larger than index of last line in image\n"); exit(EXIT_FAILURE); } if ( start_sample == -1 ) start_sample = 0; if ( start_sample > num_samples ) { printf("error: -startsample argument is larger than index of last sample in image\n"); exit(EXIT_FAILURE); } if ( window_height == -1 ) window_height = num_lines; if ( start_line + window_height > num_lines ) { printf("warning: window specified with -startline, -height options doesn't fit in image\n"); } if ( window_width == -1 ) window_width = num_samples; if ( start_sample + window_width > num_samples ) { printf("warning: window specified with -startsample, -width options doesn't fit in image\n"); } /* Make sure we don't over write any files that we don't want to */ if (meta->stats && !overmeta_flag && !nometa_flag) { printf(" ** The meta file already has a populated statistics structure.\n" " ** If you want to run this program and replace that structure,\n" " ** then use the -overmeta option to do so. If you want to run\n" " ** this program, but don't want to replace the structure, use\n" " ** the -nometa option.\n"); if (logflag) { fprintf(fLog, " ** The meta file already has a populated statistics structure.\n" " ** If you want to run this program and replace that structure,\n" " ** then use the -overmeta option to do so. If you want to run\n" " ** this program, but don't want to replace the structure, use\n" " ** the -nometa option.\n"); } exit(EXIT_FAILURE); } if (fileExists(stat_name) && !overstat_flag && !nostat_flag) { printf(" ** The file, %s, already exists. If you want to\n" " ** overwrite it, then use the -overstat option to do so.\n" " ** If you want to run the progam but don't want to write\n" " ** over the current file, then use the -nostat option.\n", stat_name); if (logflag) { fprintf(fLog, " ** The file, %s, already exists. If you want to\n" " ** overwrite it, then use the -overstat option to do so.\n" " ** If you want to run the progam but don't want to write\n" " ** over the current file, then use the -nostat option.\n", stat_name); } exit(EXIT_FAILURE); } /* Let user know the window in which the stats will be taken */ if ((start_line!=0) || (start_sample!=0) || (window_height!=num_lines) || (window_width!=num_samples)) { if (!quietflag) { printf("Taking statistics on a window with upper left corner (%ld,%ld)\n" " and lower right corner (%ld,%ld)\n", start_sample, start_line, window_width+start_sample, window_height+start_line); } if (logflag && !quietflag) { fprintf(fLog, "Taking statistics on a window with upper left corner (%ld,%ld)\n" " and lower right corner (%ld,%ld)\n", start_sample, start_line, window_width+start_sample, window_height+start_line); } } /* Allocate line buffer */ data_line = (float *)MALLOC(sizeof(float)*num_samples); if (meta->stats) FREE(meta->stats); if (meta->general->band_count <= 0) { printf(" ** Band count in the existing data is missing or less than zero.\nDefaulting to one band.\n"); if (logflag) { fprintf(fLog, " ** Band count in the existing data is missing or less than zero.\nDefaulting to one band.\n"); } meta->general->band_count = 1; } meta->stats = meta_statistics_init(meta->general->band_count); if (!meta->stats) { printf(" ** Cannot allocate memory for statistics data structures.\n"); if (logflag) { fprintf(fLog, " ** Cannot allocate memory for statistics data structures.\n"); } exit(EXIT_FAILURE); } stats = (stat_parameters *)MALLOC(sizeof(stat_parameters) * meta->stats->band_count); if (!stats) { printf(" ** Cannot allocate memory for statistics data structures.\n"); if (logflag) { fprintf(fLog, " ** Cannot allocate memory for statistics data structures.\n"); } exit(EXIT_FAILURE); } int band; long band_offset; for (band = 0; band < meta->stats->band_count; band++) { /* Find min, max, and mean values */ if (!quietflag) printf("\n"); if (logflag && !quietflag) fprintf(fLog,"\n"); min = 100000000; max = -100000000; sum_of_samples=0.0; sum_of_squared_samples=0.0; percent_complete=0; band_offset = band * meta->general->line_count; sar_file = FOPEN(sar_name, "r"); for (line=start_line+band_offset; line<start_line+window_height+band_offset; line++) { if (!quietflag) asfPercentMeter((float)(line-start_line-band_offset)/(float)(window_height-start_line)); get_float_line(sar_file, meta, line, data_line); for (sample=start_sample; sample<start_sample+window_width; sample++) { if ( mask_flag && FLOAT_EQUIVALENT(data_line[sample],mask) ) continue; if (data_line[sample] < min) min=data_line[sample]; if (data_line[sample] > max) max=data_line[sample]; sum_of_samples += data_line[sample]; sum_of_squared_samples += SQR(data_line[sample]); samples_counted++; } } if (!quietflag) asfPercentMeter(1.0); // if (!quietflag) printf("\rFirst data sweep: 100%% complete.\n"); FCLOSE(sar_file); stats[band].min = min; stats[band].max = max; stats[band].upper_left_line = start_line; stats[band].upper_left_samp = start_sample; stats[band].lower_right_line = start_line + window_height; stats[band].lower_right_samp = start_sample + window_width; stats[band].mask = mask; stats[band] = calc_hist(stats[band], sar_name, band, meta, sum_of_samples, samples_counted, mask_flag); /* Remove outliers and trim the histogram by resetting the minimum and and maximum */ if (trim_flag) { register int sum=0, num_pixels, minDex=0, maxDex=255; double overshoot, width; num_pixels = (int)(samples_counted*trim_fraction); minDex = 0; while (sum < num_pixels) sum += stats[band].histogram[minDex++]; if (minDex-1>=0) overshoot = (double)(num_pixels-sum)/stats[band].histogram[minDex-1]; else overshoot = 0; stats[band].min = (minDex-overshoot-stats[band].offset)/stats[band].slope; sum=0; while (sum < num_pixels) sum += stats[band].histogram[maxDex--]; if (maxDex+1<256) overshoot = (double)(num_pixels-sum)/stats[band].histogram[maxDex+1]; else overshoot = 0; stats[band].max = (maxDex+1+overshoot-stats[band].offset)/stats[band].slope; /* Widening the range for better visual effect */ width = (stats[band].max-stats[band].min)*(1/(1.0-2*trim_fraction)-1); stats[band].min -= width/2; stats[band].max += width/2; /* Couple useful corrections borrowed from SARview */ if ((stats[band].max-stats[band].min) < 0.01*(max-min)) { stats[band].max = max; stats[band].min = min; } if (min == 0.0) stats[band].min=0.0; if (stats[band].min == stats[band].max) stats[band].max = stats[band].min + MICRON; stats[band].slope = 255.0/(stats[band].max-stats[band].min); stats[band].offset = -stats[band].slope*stats[band].min; stats[band] = calc_hist(stats[band], sar_name, band, meta, sum_of_samples, samples_counted, mask_flag); } } if(data_line)FREE(data_line); /* Populate meta->stats structure */ char **band_names = NULL; if (meta_is_valid_string(meta->general->bands) && strlen(meta->general->bands) && meta->general->band_count > 0) { band_names = extract_band_names(meta->general->bands, meta->general->band_count); } else { if (meta->general->band_count <= 0) meta->general->band_count = 1; band_names = (char **) MALLOC (meta->general->band_count * sizeof(char *)); int i; for (i=0; i<meta->general->band_count; i++) { band_names[i] = (char *) MALLOC (64 * sizeof(char)); sprintf(band_names[i], "%02d", i); } } int band_no; for (band_no = 0; band_no < meta->stats->band_count; band_no++) { strcpy(meta->stats->band_stats[band_no].band_id, band_names[band_no]); meta->stats->band_stats[band_no].min = stats[band_no].min; meta->stats->band_stats[band_no].max = stats[band_no].max; meta->stats->band_stats[band_no].mean = stats[band_no].mean; meta->stats->band_stats[band_no].rmse = stats[band_no].rmse; meta->stats->band_stats[band_no].std_deviation = stats[band_no].std_deviation; meta->stats->band_stats[band_no].mask = stats[band_no].mask; } if (band_names) { int i; for (i=0; i<meta->general->band_count; i++) { if (band_names[i]) FREE (band_names[i]); } FREE(band_names); } /* Print findings to the screen (and log file if applicable)*/ if (!quietflag) { printf("\n"); printf("Statistics found:\n"); if (mask_flag) { printf("Used mask %-16.11g\n",mask); } printf("Number of bands: %d\n", meta->stats->band_count); for (band=0; band<meta->stats->band_count; band++) { printf("\n\nBand name = \"%s\"\n", meta->stats->band_stats[band].band_id); printf("Minimum = %-16.11g\n",stats[band].min); printf("Maximum = %-16.11g\n",stats[band].max); printf("Mean = %-16.11g\n",stats[band].mean); printf("Root mean squared error = %-16.11g\n", stats[band].rmse); printf("Standard deviation = %-16.11g\n", stats[band].std_deviation); printf("\n"); printf("Data fit to [0..255] using equation: byte = %g * sample + %g\n", stats[band].slope, stats[band].offset); if (trim_flag) printf("Trimming fraction = %.3g\n", trim_fraction); printf("\n"); printf("Histogram:\n"); for (ii=0; ii<256; ii++) { if (ii%8 == 0) { printf("%s%3i-%3i:", (ii==0) ? "" : "\n", ii, ii+7); } printf(" %8i", stats[band].histogram[ii]); } printf("\n"); } } if (logflag && !quietflag) { fprintf(fLog,"Statistics found:\n"); if (mask_flag) { fprintf(fLog,"Used mask %-16.11g\n",mask); } fprintf(fLog,"Number of bands: %d\n", meta->stats->band_count); for (band=0; band<meta->stats->band_count; band++) { fprintf(fLog,"\n\nBand name = \"%s\"\n", meta->stats->band_stats[band].band_id); fprintf(fLog,"Minimum = %-16.11g\n",stats[band].min); fprintf(fLog,"Maximum = %-16.11g\n",stats[band].max); fprintf(fLog,"Mean = %-16.11g\n",stats[band].mean); fprintf(fLog,"Root mean squared error = %-16.11g\n", stats[band].rmse); fprintf(fLog,"Standard deviation = %-16.11g\n", stats[band].std_deviation); fprintf(fLog,"\n"); fprintf(fLog,"Data fit to [0..255] using equation: byte = %g * sample + %g\n", stats[band].slope, stats[band].offset); if (trim_flag) fprintf(fLog,"Trimming fraction = %.3g\n", trim_fraction); fprintf(fLog,"\n"); fprintf(fLog,"Histogram:\n"); for (ii=0; ii<256; ii++) { if (ii%8 == 0) { fprintf(fLog,"%s%3i-%3i:", (ii==0) ? "" : "\n", ii, ii+7); } fprintf(fLog," %8i", stats[band].histogram[ii]); } fprintf(fLog,"\n"); } } /* Write out .meta and .stat files */ if (!nometa_flag) meta_write(meta, meta_name); if (!nostat_flag) stat_write(stats, stat_name, meta->stats->band_count); /* Free the metadata structure */ meta_free(meta); /* Report */ if (!quietflag) { printf("\n"); printf("Statistics taken on image file %s.\n",sar_name); if (!nometa_flag) printf("Statistics written to the stats block in %s.\n", meta_name); if (!nostat_flag) printf("Statistics plus histogram written to %s.\n", stat_name); printf("\n"); } if (logflag && !quietflag) { fprintf(fLog,"\n"); fprintf(fLog,"Statistics taken on image file '%s'\n",sar_name); if (!nometa_flag) fprintf(fLog,"Statistics written to the stats block in %s\n", meta_name); if (!nostat_flag) fprintf(fLog,"Statistics plus histogram written to %s\n", stat_name); fprintf(fLog,"\n"); } if (fLog) FCLOSE(fLog); return 0; }
int main(int argc, char *argv[]) { char inFile[512], outFile[512], *colormap=NULL; char *polsarpro=NULL, *band=NULL, *rgb=NULL; const int pid = getpid(); extern int logflag, quietflag; int reduction = 8; int transparency = 0; int quiet_f; /* log_f is a static global */ int redFlag = FLAG_NOT_SET; // reduction factor flag int transFlag = FLAG_NOT_SET; // level of transparency flag int colorFlag = FLAG_NOT_SET; // colormap flag int rgbFlag = FLAG_NOT_SET; // RGB flag int polFlag = FLAG_NOT_SET; // polarimetry type flag int bandFlag = FLAG_NOT_SET; // band flag logflag = quietflag = FALSE; log_f = quiet_f = FLAG_NOT_SET; // Begin command line parsing *********************************************** if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } get_asf_share_dir_with_argv0(argv[0]); handle_license_and_version_args(argc, argv, ASF_NAME_STRING); // Check which options were provided log_f = checkForOption("-log", argc, argv); quiet_f = checkForOption("-quiet", argc, argv); redFlag = checkForOption("-reduction_factor", argc, argv); transFlag = checkForOption("-transparency", argc, argv); colorFlag = checkForOption("-colormap", argc, argv); rgbFlag = checkForOption("-rgb", argc, argv); polFlag = checkForOption("-polsarpro", argc, argv); bandFlag = checkForOption("-band", argc, argv); // We need to make sure the user specified the proper number of arguments int needed_args = 1 + REQUIRED_ARGS; // command & REQUIRED_ARGS int num_flags = 0; if (log_f != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (quiet_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option if (redFlag != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (transFlag != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (colorFlag != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (rgbFlag != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (polFlag != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (bandFlag != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param // Make sure we have the right number of args if(argc != needed_args) { print_usage(); } // Make sure argument for each flag (that requires an arg) is not another // option flag & is not a required argument if (log_f != FLAG_NOT_SET) { if ( (argv[log_f+1][0]=='-') || (log_f>=(argc-REQUIRED_ARGS)) ) { print_usage(); } } if (redFlag != FLAG_NOT_SET) { if ( (argv[redFlag+1][0]=='-') || (redFlag>=(argc-REQUIRED_ARGS)) ) { print_usage(); } } if (transFlag != FLAG_NOT_SET) { if ( (argv[transFlag+1][0]=='-') || (transFlag>=(argc-REQUIRED_ARGS)) ) { print_usage(); } } if (colorFlag != FLAG_NOT_SET) { if ( (argv[colorFlag+1][0]=='-') || (colorFlag>=(argc-REQUIRED_ARGS)) ) { print_usage(); } } if (rgbFlag != FLAG_NOT_SET) { if ( (argv[rgbFlag+1][0]=='-') || (rgbFlag>=(argc-REQUIRED_ARGS)) ) { print_usage(); } } if (polFlag != FLAG_NOT_SET) { if ( (argv[polFlag+1][0]=='-') || (polFlag>=(argc-REQUIRED_ARGS)) ) { print_usage(); } } if (bandFlag != FLAG_NOT_SET) { if ( (argv[bandFlag+1][0]=='-') || (bandFlag>=(argc-REQUIRED_ARGS)) ) { print_usage(); } } // Make sure all options occur before the config file name argument if (num_flags == 1 && (log_f > 1 || quiet_f > 1 || redFlag > 1 || transFlag > 1 || colorFlag > 1 || rgbFlag > 1 || polFlag > 1 || bandFlag > 1)) { print_usage(); } else if (num_flags > 1 && (log_f >= argc - REQUIRED_ARGS - 1 || quiet_f >= argc - REQUIRED_ARGS - 1 || redFlag >= argc - REQUIRED_ARGS - 1 || transFlag >= argc - REQUIRED_ARGS - 1 || colorFlag >= argc - REQUIRED_ARGS - 1 || rgbFlag >= argc - REQUIRED_ARGS - 1 || polFlag >= argc - REQUIRED_ARGS - 1 || bandFlag >= argc - REQUIRED_ARGS - 1)) { print_usage(); } // Do the actual flagging & such for each flag if (redFlag != FLAG_NOT_SET) { reduction = atoi(argv[redFlag+1]); } if (transFlag != FLAG_NOT_SET) { transparency = atoi(argv[transFlag+1]); } if (colorFlag != FLAG_NOT_SET) { colormap = (char *) MALLOC(sizeof(char)*1024); strcpy(colormap, argv[colorFlag+1]); } if (rgbFlag != FLAG_NOT_SET) { rgb = (char *) MALLOC(sizeof(char)*1024); strcpy(rgb, argv[rgbFlag+1]); } if (polFlag != FLAG_NOT_SET) { polsarpro = (char *) MALLOC(sizeof(char)*1024); strcpy(polsarpro, argv[polFlag+1]); } if (bandFlag != FLAG_NOT_SET) { band = (char *) MALLOC(sizeof(char)*1024); strcpy(band, argv[bandFlag+1]); } if (log_f != FLAG_NOT_SET) { strcpy(logFile, argv[log_f+1]); } else { // default behavior: log to tmp<pid>.log sprintf(logFile, "tmp%i.log", pid); } logflag = TRUE; fLog = FOPEN(logFile, "a"); // Set old school quiet flag (for use in our libraries) quietflag = quiet_f != FLAG_NOT_SET; // Fetch required arguments strcpy(inFile, argv[argc-2]); strcpy(outFile, argv[argc-1]); // Report the command line asfSplashScreen(argc, argv); // No zipping at the moment asfPrintStatus("A system independent zipping function is currently not " "available.\nFor the moment the KML and PNG files need to " "be manually zipped together.\n\n"); kml_overlay_ext(inFile, outFile, reduction, transparency, colormap, rgb, polsarpro, band, FALSE); asfPrintStatus("\nSuccessful completion!\n\n"); FCLOSE(fLog); remove(logFile); return(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { char configFileName[255]; const int pid = getpid(); int createflag; extern int logflag, quietflag; int create_f, quiet_f; /* log_f is a static global */ createflag = logflag = quietflag = FALSE; create_f = log_f = quiet_f = FLAG_NOT_SET; // Begin command line parsing *********************************************** if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } get_asf_share_dir_with_argv0(argv[0]); handle_license_and_version_args(argc, argv, ASF_NAME_STRING); // This is an undocumented option, for internal use (by the GUI) int save_dem = extract_flag_options(&argc, &argv, "-save-dem", "--save-dem", NULL); // Check which options were provided create_f = checkForOption("-create", argc, argv); log_f = checkForOption("-log", argc, argv); quiet_f = checkForOption("-quiet", argc, argv); // We need to make sure the user specified the proper number of arguments int needed_args = 1 + REQUIRED_ARGS; // command & REQUIRED_ARGS int num_flags = 0; if (create_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option if (log_f != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param if (quiet_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option // Make sure we have the right number of args if(argc != needed_args) { print_usage(); } // Make sure argument for each flag (that requires an arg) is not another // option flag & is not a required argument if (log_f != FLAG_NOT_SET) { if ( (argv[log_f+1][0]=='-') || (log_f>=(argc-REQUIRED_ARGS)) ) { print_usage(); } } // Make sure all options occur before the config file name argument if (num_flags == 1 && (create_f > 1 || log_f > 1 || quiet_f > 1)) { print_usage(); } else if (num_flags > 1 && (create_f >= argc - REQUIRED_ARGS - 1 || log_f >= argc - REQUIRED_ARGS - 1 || quiet_f >= argc - REQUIRED_ARGS - 1)) { print_usage(); } // Do the actual flagging & such for each flag if (create_f != FLAG_NOT_SET) { createflag = TRUE; } if (log_f != FLAG_NOT_SET) { strcpy(logFile, argv[log_f+1]); } else { // default behavior: log to tmp<pid>.log sprintf(logFile, "tmp%i.log", pid); } logflag = TRUE; fLog = FOPEN(logFile, "a"); // Set old school quiet flag (for use in our libraries) quietflag = quiet_f != FLAG_NOT_SET; // Fetch required arguments strcpy(configFileName, argv[argc-1]); // Report the command line asfSplashScreen(argc, argv); // End command line parsing ************************************************* asf_convert_ext(createflag, configFileName, save_dem); // remove log file if we created it (leave it if the user asked for it) FCLOSE(fLog); if (log_f == FLAG_NOT_SET) remove(logFile); return(EXIT_SUCCESS); }
// Main program body. int main (int argc, char *argv[]) { int currArg = 1; int NUM_ARGS = 2; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<2) 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,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments. Expected %d, got %d.\n", NUM_ARGS, argc-currArg); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } char *in_file = argv[currArg]; char *out_file = argv[currArg+1]; char *in_img = appendExt(in_file, ".img"); char *out_img = appendExt(out_file, ".img"); char *in_meta = appendExt(in_file, ".meta"); char *out_meta = appendExt(out_file, ".meta"); meta_parameters *meta = meta_read(in_meta); if (!meta) asfPrintError("Failed to read metadata for: %s\n", in_file); FILE *ifp = FOPEN(in_img, "r"); FILE *ofp = FOPEN(out_img, "w"); float *buf = MALLOC(sizeof(float)*meta->general->sample_count); int ii,jj; for (ii=0; ii<meta->general->line_count; ++ii) { get_float_line(ifp, meta, ii, buf); for (jj=0; jj<meta->general->sample_count; ++jj) { if (buf[jj] < 0) { buf[jj] = 0; } else { buf[jj] = sqrt(buf[jj]); } } put_float_line(ofp, meta, ii, buf); asfLineMeter(ii,meta->general->line_count); } FCLOSE(ifp); FCLOSE(ofp); FREE(buf); if (meta->stats) { FREE(meta->stats); meta->stats = NULL; } meta_write(meta, out_meta); meta_free(meta); FREE(in_img); FREE(out_img); FREE(in_meta); FREE(out_meta); asfPrintStatus("Done.\n"); return EXIT_SUCCESS; }
// Main program body. int main (int argc, char *argv[]) { int currArg = 1; int NUM_ARGS = 3; int dbFlag = FALSE; int wh_scaleFlag = FALSE; radiometry_t radiometry; char *inFile, *outFile, *radio; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc >= 2 && strmatches(argv[1],"-help","--help",NULL)) print_help(); if (argc<3) calibrate_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 if (strmatches(key,"-db","--db",NULL)) { dbFlag = TRUE; } else if (strmatches(key,"-wh_scale","--wh_scale",NULL)) { wh_scaleFlag = TRUE; } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments. Expected %d, got %d.\n", NUM_ARGS, argc-currArg); calibrate_usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); calibrate_usage(argv[0]); } radio = argv[currArg]; inFile = argv[currArg+1]; outFile = argv[currArg+2]; if (strcmp_case(radio, "-GAMMA") == 0) { if (dbFlag) radiometry = r_GAMMA_DB; else radiometry = r_GAMMA; } else if (strcmp_case(radio, "-BETA") == 0) { if (dbFlag) radiometry = r_BETA_DB; else radiometry = r_BETA; } else if (strcmp_case(radio, "-SIGMA") == 0) { if (dbFlag) radiometry = r_SIGMA_DB; else radiometry = r_SIGMA; } else asfPrintError("Unknown radiometry (%s)\n", radio); int fail = asf_calibrate(inFile, outFile, radiometry, wh_scaleFlag); int ok = !fail; asfPrintStatus(ok ? "Done.\n" : "Failed.\n"); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char *argv[]) { char configFile[1024], interface[25]; int createflag, unitflag, cleanflag; extern int logflag; int create_f, clean_f, log_f; createflag = unitflag = cleanflag = FALSE; create_f = clean_f, FLAG_NOT_SET; // Begin command line parsing *********************************************** if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } get_asf_share_dir_with_argv0(argv[0]); handle_license_and_version_args(argc, argv, ASF_NAME_STRING); // Check which options were provided create_f = checkForOption("-create", argc, argv); clean_f = checkForOption("-clean", argc, argv); log_f = checkForOption("-log", argc, argv); // We need to make sure the user specified the proper number of arguments int needed_args = 1 + REQUIRED_ARGS; // command & REQUIRED_ARGS int num_flags = 0; if (create_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option if (clean_f != FLAG_NOT_SET) {needed_args += 1; num_flags++;} // option if (log_f != FLAG_NOT_SET) {needed_args += 2; num_flags++;} // option & param // Make sure we have the right number of args if (argc != needed_args) { print_usage(); } // Make sure argument for each flag (that requires an arg) is not another // option flag & is not a required argument if (log_f != FLAG_NOT_SET) { if ((argv[log_f+1][0]=='-') || (log_f>=(argc-REQUIRED_ARGS))) { print_usage(); } } // Make sure all options occur before the config file name argument if (num_flags == 1 && (create_f > 1 || log_f > 1)) { print_usage(); } else if (num_flags > 1 && (create_f >= argc - REQUIRED_ARGS - 1 || log_f >= argc - REQUIRED_ARGS - 1)) { print_usage(); } // Do the actual flagging & such for each flag if (create_f != FLAG_NOT_SET) { createflag = TRUE; } if (clean_f != FLAG_NOT_SET) { cleanflag = TRUE; } if (log_f != FLAG_NOT_SET) { strcpy(logFile, argv[log_f+1]); logflag = TRUE; fLog = FOPEN(logFile, "w"); } // Fetch required arguments strcpy(interface, argv[argc-2]); strcpy(configFile, argv[argc-1]); // Report the command line asfSplashScreen(argc, argv); // End command line parsing ************************************************* // Get test information from configuration file test_config *cfg; char line[1024]; // Creating configuration files if (createflag && !fileExists(configFile)) { init_test_config(configFile); return(EXIT_SUCCESS); } else if (createflag && fileExists(configFile)) { cfg = read_test_config(configFile); check_return(write_test_config(configFile, cfg), "Could not update configuration file"); free_test_config(cfg); return(EXIT_SUCCESS); } else if (!fileExists(configFile)) asfPrintError("Could not find config file (%s)\n", configFile); // Unit tests or single configuration file? if (strcmp_case(interface, "basic") == 0 || strcmp_case(interface, "automated") == 0) unitflag = TRUE; if (unitflag) { extern int quietflag; quietflag = 2; if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error(); int test = FALSE; FILE *fpList = FOPEN(configFile, "r"); while(fgets(line, 1024, fpList)) { if (strcmp_case(trim_spaces(line), "uavsar_metadata") == 0) add_uavsar_metadata_tests(); if (strcmp_case(trim_spaces(line), "uavsar_geotiff") == 0) add_uavsar_geotiff_tests(); if (strcmp_case(trim_spaces(line), "rsat1_map_projections") == 0) add_rsat1_map_projections_tests(); if (strcmp_case(trim_spaces(line), "rsat1_geotiff") == 0) add_rsat1_geotiff_tests(); if (strcmp_case(trim_spaces(line), "alos_browse") == 0) add_alos_browse_tests(); if (strcmp_case(trim_spaces(line), "alos_leader") == 0) add_alos_leader_tests(); if (strcmp_case(trim_spaces(line), "rsat1_overlay") == 0) add_rsat1_overlay_tests(); if (strcmp_case(trim_spaces(line), "alos_calibration") == 0) add_alos_calibration_tests(); test = TRUE; } FCLOSE(fpList); if (test && strcmp_case(interface, "basic") == 0) { asfPrintStatus("Running tests in basic mode ...\n"); CU_basic_set_mode(CU_BRM_VERBOSE); if (CUE_SUCCESS != CU_basic_run_tests()) { CU_cleanup_registry(); return CU_get_error(); } } if (test && strcmp_case(interface, "automated") == 0) { asfPrintStatus("Running tests in automated mode ...\n\n"); CU_set_output_filename("asf_tools"); CU_automated_run_tests(); CU_list_tests_to_file(); } CU_cleanup_registry(); if (cleanflag) cleanup_test_results(configFile); } else { // Configuration file for manual mode cfg = read_test_config(configFile); asfPrintStatus("Running tests in manual mode ...\n\n"); // Run metadata tests if (strcmp_case(cfg->general->type, "metadata") == 0) manual_metadata(configFile); // Run geotiff tests else if (strcmp_case(cfg->general->type, "geotiff") == 0) manual_geotiff(configFile); // Run binary tests else if (strcmp_case(cfg->general->type, "binary") == 0) manual_binary(configFile); // Run library tests else if (strcmp_case(cfg->general->type, "library") == 0) manual_library(configFile); free_test_config(cfg); } return(EXIT_SUCCESS); }
// Main program body. int main (int argc, char *argv[]) { output_format_t format = 0; meta_parameters *md; char *in_base_name, *output_name; char **band_names=NULL; int rgb=0; int true_color; int false_color; int num_bands_found; int ignored[3] = {0, 0, 0}; int num_ignored = 0; in_base_name = (char *) MALLOC(sizeof(char)*255); output_name = (char *) MALLOC(sizeof(char)*255); /**********************BEGIN COMMAND LINE PARSING STUFF**********************/ // Command line input goes in it's own structure. command_line_parameters_t command_line; strcpy (command_line.format, ""); command_line.size = NO_MAXIMUM_OUTPUT_SIZE; strcpy (command_line.in_data_name, ""); strcpy (command_line.in_meta_name, ""); strcpy (command_line.output_name, ""); command_line.verbose = FALSE; command_line.quiet = FALSE; strcpy (command_line.leader_name, ""); strcpy (command_line.cal_params_file, ""); strcpy (command_line.cal_comment, ""); command_line.sample_mapping = 0; strcpy(command_line.red_channel, ""); strcpy(command_line.green_channel, ""); strcpy(command_line.blue_channel, ""); strcpy(command_line.band, ""); strcpy(command_line.look_up_table_name, ""); int formatFlag, logFlag, quietFlag, byteFlag, rgbFlag, bandFlag, lutFlag; int truecolorFlag, falsecolorFlag; int needed_args = 3; //command & argument & argument int ii; char sample_mapping_string[25]; //Check to see which options were specified if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } get_asf_share_dir_with_argv0(argv[0]); handle_license_and_version_args(argc, argv, ASF_NAME_STRING); formatFlag = checkForOption ("-format", argc, argv); logFlag = checkForOption ("-log", argc, argv); quietFlag = checkForOption ("-quiet", argc, argv); byteFlag = checkForOption ("-byte", argc, argv); rgbFlag = checkForOption ("-rgb", argc, argv); bandFlag = checkForOption ("-band", argc, argv); lutFlag = checkForOption ("-lut", argc, argv); truecolorFlag = checkForOption("-truecolor", argc, argv); falsecolorFlag = checkForOption("-falsecolor", argc, argv); if ( formatFlag != FLAG_NOT_SET ) { needed_args += 2; // Option & parameter. } if ( quietFlag != FLAG_NOT_SET ) { needed_args += 1; // Option & parameter. } if ( logFlag != FLAG_NOT_SET ) { needed_args += 2; // Option & parameter. } if ( byteFlag != FLAG_NOT_SET ) { needed_args += 2; // Option & parameter. } if ( rgbFlag != FLAG_NOT_SET ) { needed_args += 4; // Option & 3 parameters. } if ( bandFlag != FLAG_NOT_SET ) { needed_args += 2; // Option & parameter. } if ( lutFlag != FLAG_NOT_SET ) { needed_args += 2; // Option & parameter. } if ( truecolorFlag != FLAG_NOT_SET ) { needed_args += 1; // Option only } if ( falsecolorFlag != FLAG_NOT_SET ) { needed_args += 1; // Option only } if ( argc != needed_args ) { print_usage (); // This exits with a failure. } // We also need to make sure the last three options are close to // what we expect. if ( argv[argc - 1][0] == '-' || argv[argc - 2][0] == '-' ) { print_usage (); // This exits with a failure. } // Make sure any options that have parameters are followed by // parameters (and not other options) Also make sure options' // parameters don't bleed into required arguments. if ( formatFlag != FLAG_NOT_SET ) { if ( argv[formatFlag + 1][0] == '-' || formatFlag >= argc - 3 ) { print_usage (); } } if ( byteFlag != FLAG_NOT_SET ) { if ( argv[byteFlag + 1][0] == '-' || byteFlag >= argc - 3 ) { print_usage (); } } if ( rgbFlag != FLAG_NOT_SET ) { if (( argv[rgbFlag + 1][0] == '-' && argv[rgbFlag + 2][0] == '-' && argv[rgbFlag + 3][0] == '-' ) || rgbFlag >= argc - 5 ) { print_usage (); } } if ( bandFlag != FLAG_NOT_SET ) { if ( argv[bandFlag + 1][0] == '-' || bandFlag >= argc - 3 ) { print_usage (); } } if ( lutFlag != FLAG_NOT_SET ) { if ( argv[lutFlag + 1][0] == '-' || lutFlag >= argc - 3 ) { print_usage (); } } if ( logFlag != FLAG_NOT_SET ) { if ( argv[logFlag + 1][0] == '-' || logFlag >= argc - 3 ) { print_usage (); } } // Make sure there are no flag incompatibilities if ( (rgbFlag != FLAG_NOT_SET && (bandFlag != FLAG_NOT_SET || truecolorFlag != FLAG_NOT_SET || falsecolorFlag != FLAG_NOT_SET)) || (bandFlag != FLAG_NOT_SET && (rgbFlag != FLAG_NOT_SET || truecolorFlag != FLAG_NOT_SET || falsecolorFlag != FLAG_NOT_SET)) || (truecolorFlag != FLAG_NOT_SET && (bandFlag != FLAG_NOT_SET || rgbFlag != FLAG_NOT_SET || falsecolorFlag != FLAG_NOT_SET)) || (falsecolorFlag != FLAG_NOT_SET && (bandFlag != FLAG_NOT_SET || truecolorFlag != FLAG_NOT_SET || rgbFlag != FLAG_NOT_SET)) ) { asfPrintWarning("The following options may only be used one at a time:\n" " %s\n %s\n %s\n %s\n %s\n %s\n", "-rgb", "-truecolor", "-falsecolor", "-band"); print_help(); } if ( (rgbFlag != FLAG_NOT_SET || truecolorFlag != FLAG_NOT_SET || falsecolorFlag != FLAG_NOT_SET) && lutFlag != FLAG_NOT_SET ) asfPrintError("Look up table option can only be used on single-band " "images.\n"); if( logFlag != FLAG_NOT_SET ) { strcpy(logFile, argv[logFlag+1]); } else { sprintf(logFile, "tmp%i.log", (int)getpid()); } logflag = TRUE; // Since we always log, set the old school logflag to true fLog = FOPEN (logFile, "a"); // Set old school quiet flag (for use in our libraries) quietflag = ( quietFlag != FLAG_NOT_SET ) ? TRUE : FALSE; // We're good enough at this point... print the splash screen. asfSplashScreen (argc, argv); // Grab the input and output name strcpy (in_base_name, argv[argc - 2]); strcpy (output_name, argv[argc - 1]); strcpy (command_line.output_name, output_name); // If user added ".img", strip it. char *ext = findExt(in_base_name); if (ext && strcmp(ext, ".img") == 0) *ext = '\0'; // Set default output type if( formatFlag != FLAG_NOT_SET ) { strcpy (command_line.format, argv[formatFlag + 1]); } else { // Default behavior: produce a geotiff. strcpy (command_line.format, "geotiff"); } // Compose input metadata name strcpy (command_line.in_meta_name, in_base_name); strcat (command_line.in_meta_name, ".meta"); // for some validation, need the metadata md = meta_read (command_line.in_meta_name); // Convert the string to upper case. for ( ii = 0 ; ii < strlen (command_line.format) ; ++ii ) { command_line.format[ii] = toupper (command_line.format[ii]); } if (strcmp (command_line.format, "PGM") == 0 && (rgbFlag != FLAG_NOT_SET || truecolorFlag != FLAG_NOT_SET || falsecolorFlag != FLAG_NOT_SET) ) { asfPrintWarning("Greyscale PGM output is not compatible with color options:\n" "(RGB, True Color, False Color, color look-up tables, etc\n)" "...Defaulting to producing separate greyscale PGM files for available band.\n"); rgbFlag = FLAG_NOT_SET; truecolorFlag = FLAG_NOT_SET; falsecolorFlag = FLAG_NOT_SET; } // Set the default byte scaling mechanisms if (md->optical) { // for optical data, default sample mapping is NONE command_line.sample_mapping = NONE; } // for other data, default is based on the output type else if (strcmp (command_line.format, "TIFF") == 0 || strcmp (command_line.format, "TIF") == 0 || strcmp (command_line.format, "JPEG") == 0 || strcmp (command_line.format, "JPG") == 0 || strcmp (command_line.format, "PNG") == 0 || strcmp (command_line.format, "PGM") == 0 || strcmp (command_line.format, "PNG_ALPHA") == 0 || strcmp (command_line.format, "PNG_GE") == 0) { command_line.sample_mapping = SIGMA; } else if (strcmp (command_line.format, "GEOTIFF") == 0) { command_line.sample_mapping = NONE; } if ( quietFlag != FLAG_NOT_SET ) command_line.quiet = TRUE; else command_line.quiet = FALSE; // Set rgb combination if ( rgbFlag != FLAG_NOT_SET ) { int i; for (i=0, num_ignored = 0; i<3; i++) { ignored[i] = strncmp("IGNORE", uc(argv[rgbFlag + i + 1]), 6) == 0 ? 1 : 0; num_ignored += ignored[i] ? 1 : 0; } asfRequire(num_ignored < 3, "Cannot ignore all bands. Exported image would be blank.\n"); strcpy (command_line.red_channel, ignored[0] ? "Ignored" : argv[rgbFlag + 1]); strcpy (command_line.green_channel, ignored[1] ? "Ignored" : argv[rgbFlag + 2]); strcpy (command_line.blue_channel, ignored[2] ? "Ignored" : argv[rgbFlag + 3]); // Check to see if the bands are numeric and in range int r_channel = atoi(command_line.red_channel); int g_channel = atoi(command_line.green_channel); int b_channel = atoi(command_line.blue_channel); /////////// Numeric channel case //////////// // Remove trailing non-numeric characters from the channel number // string and pad front end nicely with a zero if (!ignored[0] && is_numeric(command_line.red_channel) && r_channel >= 1 && r_channel <= MAX_BANDS) { sprintf(command_line.red_channel, "%02d", atoi(command_line.red_channel)); } if (!ignored[1] && is_numeric(command_line.green_channel) && g_channel >= 1 && g_channel <= MAX_BANDS) { sprintf(command_line.green_channel, "%02d", atoi(command_line.green_channel)); } if (!ignored[2] && is_numeric(command_line.blue_channel) && b_channel >= 1 && b_channel <= MAX_BANDS) { sprintf(command_line.blue_channel, "%02d", atoi(command_line.blue_channel)); } } // Set up the bands for true or false color optical data true_color = false_color = 0; int with_sigma = FALSE; if (truecolorFlag != FLAG_NOT_SET || falsecolorFlag != FLAG_NOT_SET) { int ALOS_optical = (md->optical && strncmp(md->general->sensor, "ALOS", 4) == 0) ? 1 : 0; if (md->optical && truecolorFlag != FLAG_NOT_SET) { if (ALOS_optical) { with_sigma = TRUE; strcpy(command_line.red_channel, "03"); strcpy(command_line.green_channel, "02"); strcpy(command_line.blue_channel, "01"); true_color = 1; asfPrintStatus("Applying True Color contrast expansion to following channels:"); } else { char **bands = extract_band_names(md->general->bands, 3); asfRequire(bands != NULL, "-truecolor option specified for non-true color optical image.\n"); asfPrintWarning("Attempting to use the -truecolor option with non-ALOS\n" "optical data.\n"); strcpy(command_line.red_channel, bands[2]); strcpy(command_line.green_channel, bands[1]); strcpy(command_line.blue_channel, bands[0]); int i; for (i=0; i<3; i++) { FREE(bands[i]); } FREE(bands); } } if (md->optical && falsecolorFlag != FLAG_NOT_SET) { if (ALOS_optical) { with_sigma = TRUE; strcpy(command_line.red_channel, "04"); strcpy(command_line.green_channel, "03"); strcpy(command_line.blue_channel, "02"); false_color = 1; asfPrintStatus("Applying False Color contrast expansion to the following channels:"); } else { char **bands = extract_band_names(md->general->bands, 4); asfRequire(bands != NULL, "-falsecolor option specified for an optical image with fewer than 4 bands.\n"); asfPrintWarning("Attempting to use the -falsecolor option with non-ALOS\n" "optical data.\n"); strcpy(command_line.red_channel, bands[3]); strcpy(command_line.green_channel, bands[2]); strcpy(command_line.blue_channel, bands[1]); int i; for (i=0; i<3; i++) { FREE(bands[i]); } FREE(bands); } } if (!ALOS_optical && !md->optical) { asfPrintError("-truecolor or -falsecolor option selected with non-optical data\n"); } } if (rgbFlag != FLAG_NOT_SET || truecolorFlag != FLAG_NOT_SET || falsecolorFlag != FLAG_NOT_SET) { char red_band[16], green_band[16], blue_band[16]; asfPrintStatus("\nRed channel : %s %s\n", command_line.red_channel, sigma_str(with_sigma)); asfPrintStatus("Green channel: %s %s\n", command_line.green_channel, sigma_str(with_sigma)); asfPrintStatus("Blue channel : %s %s\n\n", command_line.blue_channel, sigma_str(with_sigma)); if (is_numeric(command_line.red_channel) && is_numeric(command_line.green_channel) && is_numeric(command_line.blue_channel)) { sprintf(red_band, "%02d", atoi(command_line.red_channel)); sprintf(green_band, "%02d", atoi(command_line.green_channel)); sprintf(blue_band, "%02d", atoi(command_line.blue_channel)); band_names = find_bands(in_base_name, rgbFlag, red_band, green_band, blue_band, &num_bands_found); } else { band_names = find_bands(in_base_name, rgbFlag, command_line.red_channel, command_line.green_channel, command_line.blue_channel, &num_bands_found); } } // Set band if ( bandFlag != FLAG_NOT_SET) { strcpy (command_line.band, argv[bandFlag + 1]); band_names = find_single_band(in_base_name, command_line.band, &num_bands_found); } else if (rgbFlag == FLAG_NOT_SET && truecolorFlag == FLAG_NOT_SET && falsecolorFlag == FLAG_NOT_SET && bandFlag == FLAG_NOT_SET) { bandFlag=1; // For proper messaging to the user strcpy (command_line.band, "all"); band_names = find_single_band(in_base_name, command_line.band, &num_bands_found); } // Read look up table name if ( lutFlag != FLAG_NOT_SET) { strcpy(command_line.look_up_table_name, argv[lutFlag + 1]); rgb = 1; } // Set scaling mechanism if ( byteFlag != FLAG_NOT_SET ) { strcpy (sample_mapping_string, argv[byteFlag + 1]); for ( ii = 0; ii < strlen(sample_mapping_string); ii++) { sample_mapping_string[ii] = toupper (sample_mapping_string[ii]); } if ( strcmp (sample_mapping_string, "TRUNCATE") == 0 ) command_line.sample_mapping = TRUNCATE; else if ( strcmp(sample_mapping_string, "MINMAX") == 0 ) command_line.sample_mapping = MINMAX; else if ( strcmp(sample_mapping_string, "SIGMA") == 0 ) command_line.sample_mapping = SIGMA; else if ( strcmp(sample_mapping_string, "HISTOGRAM_EQUALIZE") == 0 ) command_line.sample_mapping = HISTOGRAM_EQUALIZE; else if ( strcmp(sample_mapping_string, "NONE") == 0 ) { asfPrintWarning("Sample remapping method (-byte option) is set to NONE\n" "which doesn't make sense. Defaulting to TRUNCATE...\n"); command_line.sample_mapping = TRUNCATE; } else asfPrintError("Unrecognized byte scaling method '%s'.\n", sample_mapping_string); } int is_polsarpro = (md->general->bands && strstr(md->general->bands, "POLSARPRO") != NULL) ? 1 : 0; if ( !is_polsarpro && lutFlag != FLAG_NOT_SET && bandFlag == FLAG_NOT_SET && md->general->band_count > 1) { asfPrintError("Look up tables can only be applied to single band" " images\n"); } if ( !is_polsarpro && lutFlag != FLAG_NOT_SET && command_line.sample_mapping == NONE && md->general->data_type != BYTE && md->general->band_count == 1) { asfPrintError("Look up tables can only be applied to byte output" " images\n"); } // Report what is going to happen if (rgbFlag != FLAG_NOT_SET || truecolorFlag != FLAG_NOT_SET || falsecolorFlag != FLAG_NOT_SET) { if (num_bands_found >= 3) { asfPrintStatus("Exporting multiband image ...\n\n"); rgb = 1; } else { asfPrintError("Not all RGB channels found.\n"); } } else if (bandFlag != FLAG_NOT_SET) { if (strcmp_case(command_line.band, "ALL") == 0) { if (multiband(command_line.format, extract_band_names(md->general->bands, md->general->band_count), md->general->band_count)) asfPrintStatus("Exporting multiband image ...\n\n"); else if (num_bands_found > 1) asfPrintStatus("Exporting each band into individual greyscale files ...\n\n"); } else if (num_bands_found == 1) { if (lutFlag != FLAG_NOT_SET) asfPrintStatus("Exporting band '%s' applying look up table ...\n\n", command_line.band); else asfPrintStatus("Exporting band '%s' as greyscale ...\n\n", command_line.band); } else asfPrintError("Band could not be found in the image.\n"); } else if (lutFlag != FLAG_NOT_SET) asfPrintStatus("Exporting applying look up table.\n\n"); else asfPrintStatus("Exporting as greyscale.\n\n"); //If user added ".img", strip it. ext = findExt(in_base_name); if (ext && strcmp(ext, ".img") == 0) *ext = '\0'; meta_free(md); /***********************END COMMAND LINE PARSING STUFF***********************/ if ( strcmp (command_line.format, "ENVI") == 0 ) { format = ENVI; } else if ( strcmp (command_line.format, "ESRI") == 0 ) { format = ESRI; } else if ( strcmp (command_line.format, "GEOTIFF") == 0 || strcmp (command_line.format, "GEOTIF") == 0) { format = GEOTIFF; } else if ( strcmp (command_line.format, "TIFF") == 0 || strcmp (command_line.format, "TIF") == 0) { format = TIF; } else if ( strcmp (command_line.format, "JPEG") == 0 || strcmp (command_line.format, "JPG") == 0) { format = JPEG; } else if ( strcmp (command_line.format, "PGM") == 0 ) { format = PGM; } else if ( strcmp (command_line.format, "PNG") == 0 ) { format = PNG; } else if ( strcmp (command_line.format, "PNG_ALPHA") == 0 ) { format = PNG_ALPHA; } else if ( strcmp (command_line.format, "PNG_GE") == 0 ) { format = PNG_GE; } else if ( strcmp (command_line.format, "KML") == 0 ) { format = KML; } else if ( strcmp (command_line.format, "POLSARPRO") == 0 ) { format = POLSARPRO_HDR; } else if ( strcmp (command_line.format, "HDF5") == 0 ) { format = HDF; } else if ( strcmp (command_line.format, "NETCDF") == 0 ) { format = NC; } else { asfPrintError("Unrecognized output format specified\n"); } /* Complex data generally can't be output into meaningful images, so we refuse to deal with it. */ /* md = meta_read (command_line.in_meta_name); asfRequire ( md->general->data_type == BYTE || md->general->data_type == INTEGER16 || md->general->data_type == INTEGER32 || md->general->data_type == REAL32 || md->general->data_type == REAL64, "Cannot cope with complex data, exiting...\n"); meta_free (md); */ // Do that exporting magic! asf_export_bands(format, command_line.sample_mapping, rgb, true_color, false_color, command_line.look_up_table_name, in_base_name, command_line.output_name, band_names, NULL, NULL); // If the user didn't ask for a log file then nuke the one that's been kept // since everything has finished successfully if (logFlag == FLAG_NOT_SET) { fclose (fLog); remove(logFile); } for (ii = 0; ii<num_bands_found; ii++) { FREE(band_names[ii]); } FREE(band_names); FREE(in_base_name); FREE(output_name); exit (EXIT_SUCCESS); }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *outFile; int currArg = 1; int kernel_size = -1; int NUM_ARGS = 2; handle_license_and_version_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(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else if (strmatches(key,"-kernel-size","--kernel-size","-ks","-k",NULL)) { CHECK_ARG(1); kernel_size = atoi(GET_ARG(1)); } 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 (kernel_size < 0) asfPrintError("No kernel size specified!\n" "Use the option '-kernel-size'.\n"); char *in_base = get_basename(inFile); char *out_base = get_basename(outFile); asfPrintStatus("Smoothing image: %s -> %s\n", in_base, out_base); smooth(inFile, outFile, kernel_size, EDGE_TRUNCATE); asfPrintStatus("Done.\n"); free(in_base); free(out_base); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { dem_config *cfg=NULL; int createFlag = FLAG_NOT_SET; char configFile[255]; // Check for all those little helper options if ( (checkForOption("--help", argc, argv) != FLAG_NOT_SET) || (checkForOption("-h", argc, argv) != FLAG_NOT_SET) || (checkForOption("-help", argc, argv) != FLAG_NOT_SET) ) { print_help(); } handle_license_and_version_args(argc, argv, ASF_NAME_STRING); // Check which options were provided createFlag = checkForOption("-create", argc, argv); // We need to make sure the user specified the proper number of arguments int needed_args = 1 + REQUIRED_ARGS; // command & REQUIRED_ARGS if (createFlag != FLAG_NOT_SET) needed_args += 1; // option // Make sure we have the right number of args if(argc != needed_args) { print_usage(); } if (createFlag != FLAG_NOT_SET) createFlag = 1; else createFlag = 0; // Fetch required arguments strcpy(configFile, argv[argc-1]); // Report the command line asfSplashScreen(argc, argv); // If requested, create a config file and exit (if the file does not exist), // otherwise read it if ( createFlag==TRUE && !fileExists(configFile) ) { init_config(configFile); exit(EXIT_SUCCESS); } // Extend the configuration file if the file already exist else if ( createFlag==TRUE && fileExists(configFile) ) { cfg = read_config(configFile, createFlag); // Assign names for results to be kept sprintf(cfg->igram_coh->igram, "%s_igram", cfg->general->base); sprintf(cfg->igram_coh->coh, "%s_coh.img", cfg->general->base); sprintf(cfg->coreg->master_power, "%s_a_pwr.img", cfg->general->base); sprintf(cfg->coreg->slave_power, "%s_b_pwr.img", cfg->general->base); sprintf(cfg->refine->seeds, "%s.seeds", cfg->general->base); sprintf(cfg->dinsar->igram, "%s_digram.img", cfg->general->base); sprintf(cfg->unwrap->qc, "%s_qc_phase.img", cfg->general->base); sprintf(cfg->elevation->dem, "%s_ht.img", cfg->general->base); sprintf(cfg->elevation->error, "%s_err_ht.img", cfg->general->base); sprintf(cfg->geocode->dem, "%s_dem", cfg->general->base); sprintf(cfg->geocode->amp, "%s_amp", cfg->general->base); sprintf(cfg->geocode->error, "%s_error", cfg->general->base); sprintf(cfg->geocode->coh, "%s_coh", cfg->general->base); asfRequire( 0==write_config(configFile, cfg), "Could not update configuration file"); asfPrintStatus(" Initialized complete configuration file\n\n"); exit(EXIT_SUCCESS); } else if (!fileExists(configFile)) asfPrintError("Configuration file does not exist!\n"); else { cfg = read_config(configFile, createFlag); } /* Setup log file */ sprintf(logFile, "%s.log", cfg->general->base); if (strncmp(cfg->general->status, "new", 3)==0) fLog = FOPEN(logFile, "w"); else fLog = FOPEN(logFile, "a"); if (argc == 3) { sprintf(logbuf, "\nCommand line: ips -c %s\n", configFile); printLog(logbuf); } else { sprintf(logbuf, "\nCommand line: ips %s\n", configFile); printLog(logbuf); } sprintf(logbuf, "Program: ips\n\n"); printLog(logbuf); FCLOSE(fLog); return ips(cfg, configFile, createFlag); }