Пример #1
0
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);
}
Пример #2
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);
}
Пример #3
0
int
main(int argc, char **argv)
{
    GtkWidget *widget;
    gchar *glade_xml_file;

    gtk_init(&argc, &argv);
    set_font();
    get_asf_share_dir_with_argv0(argv[0]);
    set_tiff_warning_handler();

    asfPrintStatus("\nASF MapReady:\n");
    const char *share_dir = get_asf_share_dir();

    if (!share_dir)
      // this actually should never happen with the current implementation
      // of get_asf_share_dir() -- always sets the share dir to something
      // even if it is a bad guess... in which case the next check will fail
      asfPrintError("Could not find the ASF share directory!\n");

    glade_xml_file = (gchar *)find_in_share("mapready.glade");
    if (!glade_xml_file)
      asfPrintError("Could not find the mapready.glade file!\n"
                    "It should be in the share files directory, here:\n"
                    "  %s\n", share_dir);
    glade_xml = glade_xml_new(glade_xml_file, NULL, NULL);
    if (!glade_xml)
      asfPrintError("Could not load the mapready.glade file!\n"
                    "This file may be corrupt. mapready.glade was found in:\n"
                    "  %s\n", share_dir);
    g_free(glade_xml_file);

    asfPrintStatus("Using share files directory: %s\n\n", share_dir);

    /* thumbnails supported in GTK 2.4 or greater */
#ifdef G_THREADS_ENABLED
    use_thumbnails = gtk_major_version >= 2 && gtk_minor_version >= 4;
#else
    use_thumbnails = FALSE;
#endif

#ifdef win32
    // On windows, ensure that our installed sh.exe is the one that is found,
    // by severely restricting the path.
    char pathenv[1024];
    sprintf(pathenv, "PATH=%s", get_asf_bin_dir());
    putenv(pathenv);
#endif

    if (!use_thumbnails)
    {
        printf("GTK Version < 2.4 -- output thumbnails disabled.\n");
    }
    else
    {
        // We will want to load thumbnails in other threads.
        if ( !g_thread_supported () ) {
            g_thread_init (NULL);
        }
    }

    /* allow FOPEN, FREAD, FWRITE to fail without aborting */
    caplib_behavior_on_error = BEHAVIOR_ON_ERROR_CONTINUE;

    /* add version number to window title, request a default size */
    char gtitle [256];
    sprintf (gtitle, "ASF MapReady: Version %s",
             MAPREADY_VERSION_STRING);

    widget = get_widget_checked("asf_convert");
    gtk_window_set_title(GTK_WINDOW(widget), gtitle);
    // commenting this out - now supported within glade
    //gtk_window_resize(GTK_WINDOW(widget), 1000, 700);

    /* select defaults for dropdowns & buttons & labeling */
    widget = get_widget_checked("scaling_method_combobox");
    set_combo_box_item(widget, SCALING_METHOD_SIGMA);

    widget = get_widget_checked("import_checkbutton");
    gtk_widget_set_sensitive(widget, FALSE);

    widget = get_widget_checked("input_data_type_combobox");
    set_combo_box_item(widget, INPUT_TYPE_AMP);

    widget = get_widget_checked("resample_option_menu");
    set_combo_box_item(widget, RESAMPLE_BILINEAR);

    // Populate the colormap drop-downs on both the import tab and in the
    // browse dialog
    populate_polsarpro_classification_optionmenu();
    widget = get_widget_checked("browse_select_colormap_optionmenu");
    gtk_option_menu_set_history(GTK_OPTION_MENU(widget), 0);

    widget = get_widget_checked("output_format_combobox");
    set_combo_box_item(widget, OUTPUT_FORMAT_JPEG);

    widget = get_widget_checked("geocode_checkbutton");
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
    geocode_options_changed();
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);

    widget = get_widget_checked("about_dialog_copyright_label");
    gtk_label_set_text(GTK_LABEL(widget), ASF_COPYRIGHT_STRING);

    // Hide latitude selection stuff until we start supporting
    // swath products (level 0) again
    widget = get_widget_checked("latitude_checkbutton");
    gtk_widget_hide(widget);
    widget = get_widget_checked("latitude_low_label");
    gtk_widget_hide(widget);
    widget = get_widget_checked("latitude_hi_label");
    gtk_widget_hide(widget);
    widget = get_widget_checked("latitude_low_entry");
    gtk_widget_hide(widget);
    widget = get_widget_checked("latitude_hi_entry");
    gtk_widget_hide(widget);

    // For now, do not allow manual offsets
    show_widget("hbox_tc_matching", FALSE);

    // This option is deprecated -- we always apply the fix now
    // and don't give the user the option of turning it off.  Probably
    // we can just delete all code associated with it, but for now we
    // just turn it on, and hide it.
    set_checked("apply_metadata_fix_checkbutton", TRUE);
    widget = get_widget_checked("apply_metadata_fix_checkbutton");
    gtk_widget_hide(widget);

    // Muck with the fonts in the About dialog
    widget = get_widget_checked("about_dialog_mapready_label");
    gchar *str = gtitle;
    gchar *text;
    PangoAttrList *attrs;
    sprintf(gtitle,
                "\n<b>ASF MapReady</b>\n"
                "<i>Remote Sensing Toolkit</i>\n"
                "ver. %s",
                MAPREADY_VERSION_STRING);
    if (strlen(SVN_REV)>0)
        sprintf(gtitle, "%s (build %s)", gtitle, SVN_REV);
    else
        strcat(gtitle, " (custom build)");

    pango_parse_markup(str, -1, 0, &attrs, &text, NULL, NULL);
    gtk_label_set_attributes(GTK_LABEL(widget), attrs);
    gtk_label_set_text(GTK_LABEL(widget), text);
    PangoFontDescription *font_desc =
      pango_font_description_from_string("Sans 12");
    gtk_widget_modify_font(widget, font_desc);

    // Muck with the "Select Processing Steps" label
    widget = get_widget_checked("select_processing_steps_label");
    str = gtitle;
    sprintf(gtitle, "<b><i>  Select Processing Steps:</i></b>");
    pango_parse_markup(str, -1, 0, &attrs, &text, NULL, NULL);
    gtk_label_set_attributes(GTK_LABEL(widget), attrs);
    gtk_label_set_text(GTK_LABEL(widget), text);
    font_desc = pango_font_description_from_string("Sans 12");
    gtk_widget_modify_font(widget, font_desc);

    /* fire handlers for hiding/showing stuff */
    output_format_combobox_changed();
    input_data_type_changed();
    geocode_options_changed();
    load_external_commands();
    external_settings_changed();
    set_toolbar_images();
    show_execute_button(TRUE);

    /* build columns in the files section */
    show_full_paths = FALSE; // Set before setup_files_list(), default to FALSE
    widget = get_widget_checked("show_full_path_names_checkbutton");
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
    setup_files_list();

    /* allow multiple selects */
    widget = get_widget_checked("input_file_selection");
    gtk_file_selection_set_select_multiple(GTK_FILE_SELECTION(widget), TRUE);

    /* drag-n-drop setup */
    setup_dnd();

    /* right-click menu setup */
    setup_popup_menu();

    /* bands dropdown setup*/
    setup_band_comboboxes();

    current_naming_scheme = naming_scheme_default();

    /* set initial vpanel setting */
    //widget = get_widget_checked("vertical_pane");
    //gtk_paned_set_position(GTK_PANED(widget), 240);

    /* Connect signal handlers.  */
    glade_xml_signal_autoconnect (glade_xml);

    /* initial flag settings */
    processing = FALSE;
    settings_on_execute = NULL;

    /* explicit call to the function that refreshes the "summary" */
    /* section when options are changed, so get the settings      */
    /* initially in there                                         */
    input_data_formats_changed();
    input_data_type_combobox_changed();
    default_to_terrcorr_on();
    default_to_keep_temp();
    terrcorr_options_changed();
    init_browse_format_combobox();

    /* For some reason, it did not work to set this via glade        */
    /* So, we have to select our default faraday rotation style here */
    rb_select("rb_fr_global", TRUE);
    polarimetry_settings_changed();

    /* put files on the command-line into the files section */
    populate_files_list(argc, argv);

    /* set up the rgb stuff on the export tab */
    rgb_combo_box_setup();

    /* enters the main GTK loop */
    gtk_main ();

    /* clean up, application has been closed */
    if (settings_on_execute)
        settings_delete(settings_on_execute);

    if (output_directory)
        g_free(output_directory);

    if (current_naming_scheme)
        naming_scheme_delete(current_naming_scheme);

    release_predefined_projections();

    exit (EXIT_SUCCESS);
}
Пример #4
0
// 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);
}
Пример #5
0
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);

}
Пример #6
0
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);
}
Пример #7
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);
}