예제 #1
0
char *find_in_share(const char * filename)
{
    char * ret = MALLOC(sizeof(char) *
        (strlen(get_asf_share_dir()) + strlen(filename) + 5));
    sprintf(ret, "%s/%s", get_asf_share_dir(), filename);
    return ret;
}
예제 #2
0
static char * projection_directory(int projection)
{
    char * location = NULL, * ret;

    switch (projection)
    {
    case PROJ_UTM:
        location = "utm";
        break;

    case PROJ_PS:
        location = "polar_stereographic";
        break;

    case PROJ_LAMCC:
        location = "lambert_conformal_conic";
        break;

    case PROJ_LAMAZ:
        location = "lambert_azimuthal_equal_area";
        break;

    case PROJ_ALBERS:
        location = "albers_equal_area_conic";
        break;
    }

    ret = (char *) malloc(sizeof(char) *
        (strlen(location) + strlen(get_asf_share_dir()) + 25));

    sprintf(ret, "%s%cprojections%c%s", get_asf_share_dir(),  DIR_SEPARATOR,
        DIR_SEPARATOR, location);

    return ret;
}
예제 #3
0
static char *get_proj_file(char *projFile) 
{
  char location[50], *ret;

  if (strncmp_case(projFile, "ALBERS_EQUAL_AREA_CONIC", 23) == 0)
    strcpy(location, "albers_equal_area_conic");
  else if (strncmp_case(projFile, "EQUIDISTANT", 11) == 0)
    strcpy(location, "equidistant");
  else if (strncmp_case(projFile, "EQUI_RECTANGULAR", 16) == 0)
    strcpy(location, "equi_rectangular");
  else if (strncmp_case(projFile, "LAMBERT_AZIMUTHAL_EQUAL_AREA", 28) == 0)
    strcpy(location, "lambert_azimuthal_equal_area");
  else if (strncmp_case(projFile, "LAMBERT_CONFORMAL_CONIC", 23) == 0)
    strcpy(location, "lambert_conformal_conic");
  else if (strncmp_case(projFile, "MERCATOR", 8) == 0)
    strcpy(location, "mercator");
  else if (strncmp_case(projFile, "POLAR_STEREOGRAPHIC", 19) == 0)
    strcpy(location, "polar_stereographic");
  else if (strncmp_case(projFile, "SINUSOIDAL", 10) == 0)
    strcpy(location, "sinusoidal");
  else if (strncmp_case(projFile, "UTM", 3) == 0)
    strcpy(location, "utm");
  ret = (char *) MALLOC(sizeof(char) *
			(strlen(projFile)*2 + strlen(get_asf_share_dir()) + 5));
  sprintf(ret, "%s%cprojections%c%s%c%s", get_asf_share_dir(), DIR_SEPARATOR,
	  DIR_SEPARATOR, location, DIR_SEPARATOR, projFile);

  return ret;
}
예제 #4
0
const char *get_asf_share_dir_with_argv0(const char *argv0)
{
#ifdef win32
    // "realpath" not available on Windows
    char *argv0_real_path = STRDUP(argv0);
#else
    // handle use of "./mapready" etc
    char *argv0_real_path = realpath(argv0, NULL);
    if (!argv0_real_path) {
        // probably user did not specify a path when running MapReady
        // so, can use the normal method for finding the share dir
        return get_asf_share_dir();
    }
#endif

    // strip off the executable, leaving just the path info
    char *argv0_path = get_dirname(argv0_real_path);

    if (!s_argv0)
        s_argv0 = STRDUP(argv0_path);

#ifndef win32
    // If the user specified a path on the command line, we want to
    // try that directory first, when searching for the share dir.
    // If this doesn't work, in get_asf_share_dir(), called below, we will
    // use the normal path-searching method to find the share dir.  If this
    // does work, then the call below will just return what we've already
    // found.
    if (!s_share_dir) {
        // obtain what needs to be pasted on to the location of the bin dir
        // to get to the share dir (i.e. "share/asf_tools")
        char *share = strstr(ASF_SHARE_DIR, "share");
        if (share) {
            if (argv0_path && strlen(argv0_path) > 0) {
                // a copy for us to change "whatever/bin" to "whatever/share/asf_tools"
                char *buf = MALLOC(sizeof(char)*(strlen(argv0_path) + strlen(share) + strlen(TOOL_SUITE_SHARE_DIR) + 5));
                strcpy(buf, argv0_path);

                // only try this if the binary location ends with 'bin'
                if (strcmp(buf + strlen(buf) - 4, "bin/") == 0) {
                    // strip off "bin" - add "share/asf_tools"
                    *(buf + strlen(buf) - 4) = '\0';
                    strcat(buf, share);
                    strcat(buf, "/");
                    strcat(buf, TOOL_SUITE_SHARE_DIR);
                    if (check_for_known_file_in_share_dir(buf)) {
                        // this is the one!
                        s_share_dir = STRDUP(buf);
                    }
                }
                FREE(buf);
            }
        }
    }
#endif

    FREE(argv0_path);
    FREE(argv0_real_path);
    return get_asf_share_dir();
}
예제 #5
0
meta_parameters *read_asf_meta(const char *meta_name)
{
  meta_parameters *meta = meta_read(meta_name);

  // If the ASF internal format file is a single-band image with RGB color map
  // in the metadata, then store the color map as an ASF style look-up table
  if (meta->colormap) {
    int i;
    meta_colormap *mc = meta->colormap;
    char lut_file[256];
    char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+128));
    sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR);
    sprintf(lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_ASF_COLORMAP_LUT_FILE);
    FILE *lutFP = (FILE *)FOPEN(lut_file, "wt");
    fprintf(lutFP, "# Look up table type: %s\n", mc->look_up_table);
    fprintf(lutFP, "# Originating source: %s\n", meta_name);
    fprintf(lutFP, "# Index   Red   Green   Blue\n");
    for (i=0; i<mc->num_elements; i++) {
      fprintf(lutFP, "%03d    %03d    %03d    %03d\n",
              i, mc->rgb[i].red, mc->rgb[i].green, mc->rgb[i].blue);
    }
    fprintf(lutFP, "\n");
    FCLOSE(lutFP);
  }

  return meta;
}
예제 #6
0
char *
find_in_share(const char * filename)
{
    char * ret = (char *) malloc(sizeof(char) * 
        (strlen(get_asf_share_dir()) + strlen(filename) + 5));
    sprintf(ret, "%s%c%s", get_asf_share_dir(), DIR_SEPARATOR, filename);
    return ret;
}
예제 #7
0
static char *find_in_share(const char * filename)
{
    char * ret = (char *) MALLOC(sizeof(char) *
                                 (strlen(get_asf_share_dir()) + strlen(filename) + 5));
    sprintf(ret, "%s%c%s", get_asf_share_dir(), DIR_SEPARATOR, filename);
    if (fileExists(ret))
        return ret;
    else {
        FREE(ret);
        return NULL;
    }
}
예제 #8
0
파일: c2v.c 프로젝트: rudigens/ASF_MapReady
char *find_in_share(const char * filename)
{
    char * ret = MALLOC(sizeof(char) *
                        (strlen(get_asf_share_dir()) + strlen(filename) + 5));
    sprintf(ret, "%s/%s", get_asf_share_dir(), filename);
    if (fileExists(ret)) {
        return ret;
    } else {
        printf("Trying to find %s file: %s\n", filename, ret);
        free(ret);
        return NULL;
    }
}
double faraday_prediction(int frame_id, double look_angle, int year, int day,
			  int hour, int minute, double clat, double clon, 
			  char *codg_file)
{
  // Determine total electron count for location at given time 
  // at 450 km elevation
  double fHour = (double)hour + (double)minute/60.0;
  int lo_hour = floor(fHour/2) + 1;
  int hi_hour = lo_hour + 1;
  double act_hour = fHour/2 + 1;
  double lo_tec = lookup_tec(codg_file, lo_hour, clat, clon);
  double hi_tec = lookup_tec(codg_file, hi_hour, clat, clon);
  double tec = interpolate(act_hour, hi_hour, hi_tec, lo_hour, lo_tec);
  tec /= 10.0;

  // Determine TEC at 350 km elevation
  char magnetic_field_file[512];
  sprintf(magnetic_field_file, "%s%cx_350.txt", 
	  get_asf_share_dir(), DIR_SEPARATOR);
  double mag_south = lookup_reference(magnetic_field_file, clat, clat);
  mag_south *= -1.0;
  sprintf(magnetic_field_file, "%s%cy_350.txt", 
	  get_asf_share_dir(), DIR_SEPARATOR);
  double mag_east = lookup_reference(magnetic_field_file, clat, clat);
  sprintf(magnetic_field_file, "%s%cz_350.txt", 
	  get_asf_share_dir(), DIR_SEPARATOR);
  double mag_z = lookup_reference(magnetic_field_file, clat, clat);
  mag_z *= -1.0;
  double mag_i, mag_j, mag_k;
  sez2ijk(mag_south, mag_east, mag_z, clat, clon, &mag_i, &mag_j, &mag_k);

  // Determine ALOS pointing angle
  double pt_south, pt_east, pt_z, pt_i, pt_j, pt_k; 
  alos_pointing(frame_id, look_angle, &pt_south, &pt_east, &pt_z);
  sez2ijk(pt_south, pt_east, pt_z, clat, clon, &pt_i, &pt_j, &pt_k);

  // Determine Faraday rotation 
  double nano=1e-9, tecu=1e16, K=2.37e4, frequency=1.27e9;
  double look = look_angle*D2R;
  double dot_mag_pt = mag_i*pt_i + mag_j*pt_j + mag_k*pt_k;
  double norm_mag = sqrt(mag_i*mag_i + mag_j*mag_j + mag_k*mag_k);
  double norm_pt = sqrt(pt_i*pt_i + pt_j*pt_j + pt_k*pt_k); 
  double psi = acos(dot_mag_pt / norm_mag / norm_pt);
  double omega = K/frequency/frequency*tec*tecu*nano;
  omega *= norm_mag*cos(psi)/cos(look)*R2D;
  //printf("omega: %lf\n", omega);

  return omega;
}
예제 #10
0
파일: mdv.c 프로젝트: glshort/MapReady
static char *
find_in_share(const char * filename)
{
    char * escaped_dir = escapify(get_asf_share_dir());
    char * ret = (char *) MALLOC(sizeof(char) *
        (strlen(escaped_dir) + strlen(filename) + 2));
    sprintf(ret, "%s/%s", escaped_dir, filename);
    free(escaped_dir);
    return ret;
}
예제 #11
0
파일: csv.c 프로젝트: rudigens/ASF_MapReady
// try to find a program we can use to view the generated csv files
const char * detect_csv_assoc()
{
    static char *csv_app = NULL;
    if (!csv_app) {
        char *csv_file = find_in_share("asf_view_cfg.csv");

#ifdef win32
        // On Windows, use the file association table to find out what we
        // can do with csv files.
        char path[1024];
        int ret = (int)FindExecutable((LPCTSTR)csv_file,
                                      (LPCTSTR)get_asf_share_dir(), (LPTSTR)path);
        if (ret > 32 && strlen(path) > 0) {
            csv_app = escapify(path);
            printf("Path to CSV Application: %s\n", csv_app);
        } else {
            if (ret==SE_ERR_FNF)
                printf("File not found: %s\n", csv_file);
            else if (ret==SE_ERR_NOASSOC)
                printf("No association for: %s\n", csv_file);
            else if (ret==SE_ERR_OOM)
                printf("Out of resources.\n");
            else
                printf("Unknown error! (return value: %d)\n", ret);

            csv_app = STRDUP("notepad.exe");
            printf("CSV Application not found -- using notepad.\n");
        }
        FREE(csv_file);
#else
        // On Linux, get the app from the configuration file
        FILE *cfg = fopen(csv_file, "r");
        if (cfg) {
            char tmp[1024];
            while (fgets(tmp, 1024, cfg) != NULL) {
                if (strncmp_case(tmp, "CSV,", 4) == 0) {
                    csv_app = trim_whitespace(tmp+4);
                    printf("CSV Application from config file: %s\n", csv_app);
                }
            }
            if (!csv_app)
                csv_app = STRDUP("");
            fclose(cfg);
        } else {
            printf("Failed to open %s: %s\n", csv_file, strerror(errno));
            csv_app = STRDUP("");
            printf("CSV Application not found.\n");
        }
#endif
    }
    return csv_app;
}
예제 #12
0
int share_file_exists(const char *filename)
{
  char * full_name;
  const char * share_dir;

  share_dir = get_asf_share_dir();
  full_name = (char *) MALLOC (sizeof(char) *
                                (strlen(filename) + strlen(share_dir) + 10));

  sprintf(full_name, "%s%c%s", share_dir, DIR_SEPARATOR, filename);

  int exists = fileExists(full_name);
  free(full_name);

  return exists;
}
예제 #13
0
FILE * 
fopen_share_file(const char * filename, const char * mode)
{
  char * full_name;
  const char * share_dir;
  FILE * fp;

  share_dir = get_asf_share_dir();
  full_name = (char *) MALLOC (sizeof(char) *
                                (strlen(filename) + strlen(share_dir) + 10));

  sprintf(full_name, "%s%c%s", share_dir, DIR_SEPARATOR, filename);

  fp = fopen(full_name, mode);
  if (!fp)
    asfPrintWarning("Could not open share file: %s\n", filename);

  free(full_name);
  return fp;
}
예제 #14
0
// Print minimalistic usage info & exit
static void usage(const char *name)
{
  char path[1024];
  struct dirent *dp;
  DIR *dir;

  asfPrintStatus("\n"
      "Usage:\n"
      ASF_USAGE_STRING
      "\n");
  asfPrintStatus("Currently available templates are:\n");
  sprintf(path, "%s/metadata", get_asf_share_dir());
  dir = opendir(path);
  while ((dp = readdir(dir)) != NULL) {
    if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0)
      asfPrintStatus("   %s\n", dp->d_name);
  }
  asfPrintStatus("\n");
  closedir(dir);
  exit(EXIT_FAILURE);
}
예제 #15
0
SIGNAL_CALLBACK void
on_help_button_clicked(GtkWidget *widget)
{
#ifdef win32
    char pdf_dir[1024], pdf_file[128], pdf_viewer[1024];
    snprintf(pdf_dir, 1023, "%s/doc/", get_asf_share_dir());
    strcpy(pdf_file, "mapready_manual.pdf");
    //printf("pdf: %s/%s\n", pdf_dir, pdf_file);

    FindExecutable((LPCTSTR)pdf_file, (LPCTSTR)pdf_dir, (LPTSTR)pdf_viewer);
    printf("Found PDF Viewer: %s\n", pdf_viewer);

    if (strlen(pdf_viewer)) {
      asfSystem_NoWait("\"%s\" \"%s/%s\"", pdf_viewer, pdf_dir, pdf_file);
    } else {
      message_box("Couldn't find path to a PDF Viewer!");
    }
#else
    GtkWidget *help_dialog;
    GtkWidget *help_text;
    GtkTextBuffer * text_buffer;
    FILE * help_file;
    gchar * help_filename;

    help_dialog =
        get_widget_checked("help_dialog");

    help_text =
        get_widget_checked("help_text");

    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(help_text));

    gtk_text_buffer_set_text(text_buffer, "", -1);

    help_filename = "mapready.txt";
    //help_file = fopen(help_filename, "rt");
    help_file = fopen_share_file(help_filename, "rt");
    if (help_file)
    {
        int line_count = 0;
        gchar * buffer = (gchar *) g_malloc(sizeof(gchar) * max_line_len);
        while (!feof(help_file))
        {
            gchar *p = fgets(buffer, max_line_len, help_file);
            if (p)
            {
                if (strlen(p)) line_count++;
                GtkTextIter end;
                gchar * q = strstr(buffer, "$VERSION");

                if (q)
                {
                    gchar * r = g_strdup(q + 8); /* 8 = length of '$VERSION' */

                    strcpy(q, MAPREADY_VERSION_STRING);
                    strcat(buffer, r);
                    g_free(r);
                }

                gtk_text_buffer_get_end_iter(text_buffer, &end);
                gtk_text_buffer_insert(text_buffer, &end, buffer, -1);
            }
        }
        if (!line_count) {
            sprintf(buffer, "\n\n  ERROR: Empty help file (mapready.txt) in share folder\n(%s)\n",
                    get_asf_share_dir());
            GtkTextIter end;
            gtk_text_buffer_get_end_iter(text_buffer, &end);
            gtk_text_buffer_insert(text_buffer, &end, buffer, -1);
        }

        fclose(help_file);
        g_free(buffer);
    }
    else {
        // No help file found
        gchar *buffer = (gchar *) g_malloc(sizeof(gchar) * max_line_len);
        strcpy(buffer, "\n\n  ERROR: Cannot find help file (mapready.txt) in share folder.\n");
        GtkTextIter end;
        gtk_text_buffer_get_end_iter(text_buffer, &end);
        gtk_text_buffer_insert(text_buffer, &end, buffer, -1);
        g_free(buffer);
    }

    gtk_widget_show(help_dialog);
#endif
}
예제 #16
0
파일: asf_view.c 프로젝트: glshort/MapReady
int
main(int argc, char **argv)
{
    if (detect_flag_options(argc, argv, "-help", "--help", NULL))
      help();

    char band[512], lut[512], mask_file_name[512];

    strcpy(band, "");
    strcpy(mask_file_name, "");

    int band_specified = extract_string_options(&argc, &argv, band,
        "-band", "--band", "-b", NULL);
    int lut_specified = extract_string_options(&argc, &argv, lut,
        "-colormap", "--colormap", "-lut", "--lut", NULL);
    int planner_mode = extract_flag_options(&argc, &argv,
        "-plan", "--plan", NULL);
    int mask_specified = extract_string_options(&argc, &argv, mask_file_name,
        "-mask", "--mask", "--layover-mask", "--layover-mask", NULL);
    generic_specified = extract_flag_options(&argc, &argv,
        "-generic", "--generic", NULL);
    if (generic_specified) {
       char type[512];
       if (!extract_int_options(&argc, &argv, &generic_bin_width,
                "-width", "--width", "-cols", "--cols", NULL) ||
           !extract_int_options(&argc, &argv, &generic_bin_height,
                "-height", "--height", "-rows", "--rows", NULL)) {
         asfPrintError("When reading generic data, specify the size "
            "(--width, --height).\n");
       }
       generic_bin_byteswap =
         extract_flag_options(&argc, &argv,
                              "--byteswap", "-byteswap", NULL);
       if (extract_string_options(&argc, &argv, type,
                "-type", "--type", NULL))
       {
         if (strcmp_case(type, "BYTE") == 0 ||
             strcmp_case(type, "INT8") == 0) {
           generic_bin_datatype = BYTE;
         }
         else if (strcmp_case(type, "FLOAT") == 0 ||
                  strcmp_case(type, "REAL32") == 0) {
           generic_bin_datatype = REAL32;
         }
         else {
           asfPrintError("Unknown generic data type: %s\n", type);
         }
       } else {
         asfPrintStatus("Generic binary: assuming REAL32 data.\n");
         generic_bin_datatype = REAL32;
       }
    }

    if (planner_mode) {
      if (detect_flag_options(argc, argv, "-calibrate-reference", NULL)) {
        calibrate_planner_reference();
        exit(EXIT_SUCCESS);
      }
    }

    handle_common_asf_args(&argc, &argv, "ASF View");

    // point to "polygon 0" as the one we initially work on
    g_poly = &g_polys[0];

    // set up image array
    curr = &image_info[0];
    curr->data_name = curr->meta_name = NULL;
    int ii;

    if (argc < 2) {
        curr->filename = STRDUP(find_in_share("startup.jpg"));
    }
    else {
        n_images_loaded = 0;
	for (ii=1; ii<argc; ++ii) {
           if (strlen(argv[ii]) > 0) {
               image_info[n_images_loaded].filename = STRDUP(argv[ii]);
               ++n_images_loaded;
           }
        }    
    }


    if (n_images_loaded == 1) {
        asfPrintStatus("Loading 1 image: %s\n", image_info[0].filename);
    }
    else {
        asfPrintStatus("Loading %d images:\n", n_images_loaded);
        for (ii=0; ii<n_images_loaded; ++ii)
            asfPrintStatus("%d: %s\n", ii+1, image_info[ii].filename);
    }

    if (mask_specified)
        asfPrintStatus("Mask: %s\n", mask_file_name);

    // we could call load_file() here, but don't because this way we can
    // interleave the call to gtk_init() with some of the loading code --
    // which keeps the window from showing up until after it has been loaded,
    // which looks much nicer

    // initialize globals
    reset_globals(TRUE);

    // Get rid of leftover (temporary) colormap luts if they exist, say if asf_view errored out
    // rather than being exited normally
    char embedded_tiff_lut_file[1024];
    char embedded_asf_colormap_file[1024];
    char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+64));
    sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR);
    sprintf(embedded_tiff_lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_TIFF_COLORMAP_LUT_FILE);
    sprintf(embedded_asf_colormap_file,"%s%c%s", lut_loc, DIR_SEPARATOR,
            EMBEDDED_ASF_COLORMAP_LUT_FILE);
    FREE(lut_loc);
    if (fileExists(embedded_tiff_lut_file)) remove(embedded_tiff_lut_file);
    if (fileExists(embedded_asf_colormap_file)) remove(embedded_asf_colormap_file);

    if (mask_specified) {
        curr = mask = &mask_info;
        mask->filename = STRDUP(mask_file_name);

        if (mask->filename[strlen(mask->filename)-1] == '.')
            mask->filename[strlen(mask->filename)-1] = '\0';
        
        read_file(mask->filename, NULL, FALSE, TRUE);
        //set_lut("layover_mask");
    }
    
    // load the image we're going to actually show last
    for (ii=n_images_loaded-1; ii>=0; --ii)
    {
        curr = &image_info[ii];
        
        // strip off any trailing "."
        if (curr->filename[strlen(curr->filename)-1] == '.')
            curr->filename[strlen(curr->filename)-1] = '\0';
        
        read_file(curr->filename, band_specified ? band : NULL, FALSE, TRUE);
        check_for_embedded_tiff_lut(curr->filename, &lut_specified, lut);
        if (lut_specified)
            set_lut(lut);
        
        assert(curr->data_name);
        assert(curr->meta_name);
        
        // we load the thumbnail data before bringing up the window, looks
        // much nicer.  When loading an image within the GUI, we don't need
        // to do get_thumbnail_data() as a separate step.
        ThumbnailData *thumbnail_data = get_thumbnail_data(curr);
        
        // first time through the loop only, set up GTK
        if (ii == n_images_loaded-1) {
            gtk_init(&argc, &argv);
            
            gchar *glade_xml_file = (gchar *)find_in_share("asf_view.glade");
            printf("Found asf_view.glade: %s\n", glade_xml_file);
            glade_xml = glade_xml_new(glade_xml_file, NULL, NULL);
            free(glade_xml_file);
            
            // set up window title, etc
            set_button_images();
            
            // set up the acquisition planner, if we are in that mode
            if (planner_mode) {
                setup_planner();
                
                // getting rid of the info section makes more room for the found
                // acquisitions, and isn't really necessary in the planner
                show_widget("info_hbox", FALSE);
            }
            
            // populate the look up table list, and apply the default
            // look-up-table, if there is one.  In this case, we will need to
            // apply it retroactively to the thumbnail data we already loaded
            // (In new.c, this kludge isn't required - we load/apply in the
            // same pass -- here it is required because we pre-load the thumbnail)
            populate_lut_combo();
            if (check_for_embedded_tiff_lut(curr->filename, &lut_specified, lut)) {
                GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
                gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_tiff_lut_index());
                set_current_index(get_tiff_lut_index());
            }
            else if (is_colormap_ASF_file(curr->filename)) {
                /*
                * lut_specified = 1;
                * strcpy(lut, EMBEDDED_ASF_COLORMAP_LUT);
                * GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
                * gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_asf_lut_index());
                * set_current_index(get_asf_lut_index());
                * check_lut();
                * apply_lut_to_data(thumbnail_data);
                */
            }
        }
        else if (ii == 0) {
            set_title(band_specified, band);
        }

        if (curr->meta && curr->meta->general)  {
            if (set_lut_based_on_image_type(curr->meta->general->image_data_type))
            {
                check_lut();
                // data we loaded needs to be lutted
                apply_lut_to_data(thumbnail_data);
            }
        }
        
        // load the metadata & image data, other setup
        setup_gdk_window_ids();
        setup_small_image_size();
        fill_small_have_data(thumbnail_data, curr);
        fill_big(curr);
        update_pixel_info(curr);
        update_zoom();
        set_font();
        fill_meta_info();
        update_map_settings(curr);
        fill_stats(curr);
        set_mapping_defaults(curr);
        setup_bands_tab(curr->meta);
        disable_meta_button_if_necessary();
        if (lut_specified)
            select_lut(lut);
    }

    if (n_images_loaded>0) {
        asfPrintStatus("Currently displaying %d: %s\n",
                       current_image_info_index, curr->filename);
    }

    glade_xml_signal_autoconnect(glade_xml);
    gtk_main ();

    // If the last viewed file left behind a (temporary) color map lut,
    // then get rid of it
    if (fileExists(embedded_tiff_lut_file))
      remove(embedded_tiff_lut_file);
    if (fileExists(embedded_asf_colormap_file))
      remove(embedded_asf_colormap_file);

    image_info_free(curr);
    free_shapes();
    exit (EXIT_SUCCESS);
}
예제 #17
0
int meta_test_ext(char *in_file, char *spec_file, report_level_t level)
{
  char *filename = NULL, line[1024], param[100], type[25], valid[500], *p;
  char *strValue;
  int nMin, nMax, nValue, err, passed = TRUE;
  double lfMin, lfMax, lfValue;
  
  // First try to find the spec file locally
  FILE *fp = fopen(spec_file, "r");
  if (!fp) {
    filename = appendExt(spec_file, ".specs");
    fp = fopen(filename, "r");
  }

  // Second try the spec file from share directory
  if (!fp) {
    FREE(filename);
    filename = (char *) MALLOC(sizeof(char)*1024);
    sprintf(filename, "%s/meta_test/%s", get_asf_share_dir(), spec_file);
    fp = fopen(filename, "r");
  }
  if (!fp) {
    sprintf(filename, "%s/meta_test/%s.specs", 
	    get_asf_share_dir(), spec_file);
    fp = fopen(filename, "r");
  }
  if (!fp)
    asfPrintError("Could not find spec file (%s)\n", spec_file);
  if (filename)
    FREE(filename);

  // FIXME: Need to implement some pre-checks.
  // For example, map projections will need special treatment. For a given
  // map projection, a set of parameters need are required to define that.
  // We need to be able to ignore some parameters in this context as well.
  // Only for the UAVSAR case, we are good to go.
  
  while(fgets(line, 1024, fp)) {
    // skip comments
    if (strstr(line, "#"))
      continue;
    else
      line[strlen(line)-1] = '\0';

    // parameter out of the metadata structure
    p = strchr(line, ',');
    *p = '\0';
    sprintf(param, "%s", line);
    strcat(param, ":");

    // data type
    sprintf(line, "%s", p+1);
    p = strchr(line, ',');
    if (p)
      *p = '\0';
    sprintf(type, "%s", line);

    // valid
    // If no value is given, we just want to check the parameter is given in
    // the metadata file. If we find quotation marks then assume we have a list
    // of values to check. Otherwise, we assume to find a minimum and a maximum
    // value to check.
    if (p) {
      sprintf(line, "%s", p+1);
      if (line[0] == '\'' && line[strlen(line)-1] == '\'') {
	sprintf(valid, "%s", line+1);
	valid[strlen(valid)-1] = '\0';
	strValue = getString(in_file, param, &err);
	if (err || (strlen(valid) > 0  && strstr(valid, strValue) == NULL)) {
	  asfReport(level, "   %s failed\n", param);
	  passed = FALSE;
	}
      }
      else {
	if (strncmp_case(type, "INT", 3) == 0) {
	  sscanf(line, "%d,%d", &nMin, &nMax);
	  nValue = getInt(in_file, param, &err);
	  if (err || nValue < nMin || nValue > nMax) {
	    asfReport(level, "   %s failed\n", param);
	    passed = FALSE;
	  }
	}
	else if (strncmp_case(type, "DOUBLE", 6) == 0) {
	  sscanf(line, "%lf,%lf", &lfMin, &lfMax);
	  lfValue = getDouble(in_file, param, &err);
	  if (err || lfValue < lfMin || lfValue > lfMax) {
	    asfReport(level, "   %s failed\n", param);
	    passed = FALSE;
	  }
	}
      }
    }
  }
  return passed;
}
예제 #18
0
int main(int argc, char **argv)
{
  char inFormat[25], outFormat[25], configFile[255];
  int currArg = 1, NUM_ARGS = 1, configFlag = FALSE;
  c2v_config *cfg=NULL;

  if (argc < 3) {
    usage(argv[0]);
    exit(1);
  }
    
  // Check for configuration file option first
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key, "-help", "--help", NULL)) {
      usage(argv[0]);
      char format[25], data_dictionary[512];
      CHECK_ARG(1);
      strcpy(format, GET_ARG(1));
      sprintf(data_dictionary, "%s%c%s_data_dictionary.csv", 
        get_asf_share_dir(), DIR_SEPARATOR, format);
      if (fileExists(data_dictionary)) {
        asfPrintStatus("\nFormat defined in %s_data_dictionary.csv\n\n", 
        format);
        catFile(data_dictionary);
        asfPrintStatus("\n\n");
      }
      else
        asfPrintWarning("Could not find a data dictionary for format (%s)!\n\n", 
          format);
      exit(1);
    }
    else if (strmatches(key, "-config", "--config", "-c", NULL)) {
      CHECK_ARG(1);
      strcpy(configFile, GET_ARG(1));
      cfg = read_c2v_config(configFile);
      configFlag = TRUE;
    }
  }
  if (!configFlag) {
    sprintf(configFile, "%s%cconvert2vector.config", 
      get_asf_share_dir(), DIR_SEPARATOR);
    asfPrintStatus("\nReading parameters from default configuration file:\n"
		   "%s\n", configFile);
    cfg = read_c2v_config(configFile);
  }

  // Pick up the rest of the arguments
  currArg = 1;
  NUM_ARGS = 2;
  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key, "-config", "--config", "-c", NULL)) { ; }
    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, "-list", "--list", NULL))
      cfg->list = TRUE;
    else if (strmatches(key, "-nosplit", "--nosplit", "-ns", NULL))
      cfg->nosplit = TRUE;
    else if (strmatches(key, "-input-format", "--input-format", "-i", NULL)) {
      CHECK_ARG(1);
      strcpy(cfg->input_format, GET_ARG(1));
    }
    else if (strmatches(key, "-output-format", "--output-format", "-o", NULL)) {
      CHECK_ARG(1);
      strcpy(cfg->output_format, GET_ARG(1));
    }
    else {
      --currArg;
      break;
    }
  }
  if ((argc-currArg) < NUM_ARGS) {
    printf("Insufficient arguments.\n");
    usage(argv[0]);
  }

  if (!configFlag) {
    sprintf(cfg->input_file, "%s", argv[currArg++]);
    sprintf(cfg->output_file, "%s", argv[currArg]);
  }

  asfSplashScreen (argc, argv);

  sprintf(inFormat, "%s", uc(cfg->input_format));
  sprintf(outFormat, "%s", uc(cfg->output_format));
  
  // Check whether you can find information about the format in the header
  // list file in the share directory
  dbf_header_t *dbf;
  int nCols;
  char shape_type[25];
  if (strcmp_case(inFormat, "CSV") == 0 ||
    read_header_config(inFormat, &dbf, &nCols, shape_type))
    asfPrintStatus("   Converting a %s format file to %s\n", 
      inFormat, outFormat);
  else
    asfPrintError("   Unsupported input format (%s)\n", inFormat);
  
  // Set output directory as the temporary directory -- where all temp files
  // created during import should be put
  char *tmpdir = get_dirname(cfg->output_file);
  if (tmpdir && strlen(tmpdir) > 0)
    set_asf_tmp_dir(tmpdir);

  convert2vector(cfg);

  asfPrintStatus("Done.\n\n");

  return(0);
}
예제 #19
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);
}
예제 #20
0
// Populate both the drop-down on the import tab and within the file browse dialog
void populate_polsarpro_classification_optionmenu()
{
  // Set up the menus (one on the import tab, the other on the input file browse dialog
  GtkWidget *browse_menu = NULL;
  GtkWidget *browse_option_menu = get_widget_checked("browse_select_colormap_optionmenu");
  if (browse_option_menu) {
    browse_menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(browse_option_menu));
    if (browse_menu) {
      gtk_option_menu_remove_menu(GTK_OPTION_MENU(browse_option_menu));
    }
  }
  browse_menu = gtk_menu_new();

  GtkWidget *browse_item = gtk_menu_item_new_with_label("None");
  gtk_menu_append(GTK_MENU(browse_menu), browse_item);
  gtk_widget_show(browse_item);

  browse_item = gtk_separator_menu_item_new();
  gtk_menu_append(GTK_MENU(browse_menu), browse_item);
  gtk_widget_show(browse_item);

  char lut_loc[1024];
  sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR);
  if (g_polsarpro_classification_optionmenu_ht == NULL) {
    g_polsarpro_classification_optionmenu_ht = g_hash_table_new(g_str_hash,g_str_equal);
  }

  // Open up the share dir's look up tables list, populate dropdown
  // from the files in that directory.
  GDir *lut_dir = g_dir_open(lut_loc, 0, NULL);
  if (lut_dir) {
    unsigned int i, n=0;
    char **names = (char**)MALLOC(sizeof(char*)*MAX_LUTS);

    while (1) {
      const char *name = (char*)g_dir_read_name(lut_dir);
      if (name) {
        char *name_dup = STRDUP(name);
        char *p = findExt(name_dup);
        if (p && strcmp(p, ".pal") == 0 && is_jasc_palette_lut(name)) {
          *p = '\0'; // don't show ".pal" extension in menu
          names[n++] = name_dup;
          // quit when we get too many
          if (n > MAX_LUTS)
            break;
        }
      } else
        break;
    }
    g_dir_close(lut_dir);

    // alphabetize
    qsort(names, n, sizeof(char*), my_strcmp);

    // now populate the menus
    for (i=0; i<n; ++i) {
      browse_item = gtk_menu_item_new_with_label(names[i]);
      g_object_set_data(G_OBJECT(browse_item), "file", (gpointer)names[i]);
      g_object_set_data(G_OBJECT(browse_item), "index", GUINT_TO_POINTER(i+2));
      gtk_menu_append(GTK_MENU(browse_menu), browse_item);
      gtk_widget_show(browse_item);
      g_hash_table_insert(g_polsarpro_classification_optionmenu_ht,
                          (gpointer)g_strdup(names[i]),
                           GUINT_TO_POINTER(i+2));
    }
  }

  browse_option_menu = get_widget_checked("browse_select_colormap_optionmenu");

  gtk_option_menu_set_menu(GTK_OPTION_MENU(browse_option_menu), browse_menu);
  gtk_option_menu_set_history(GTK_OPTION_MENU(browse_option_menu), 0);

  gtk_widget_show(browse_menu);
  gtk_widget_show(browse_option_menu);
}
예제 #21
0
파일: help.c 프로젝트: glshort/MapReady
SIGNAL_CALLBACK void
on_help_button_clicked(GtkWidget *widget)
{
#ifdef win32
    char hh[1024];

    // First method, get location of help viewer from the standard registry location
    get_string_from_registry_ex("SOFTWARE\\Classes\\chm.file\\shell\\open\\command", "", hh);

    if (strlen(hh) > 0) {
        char *p = strstr(hh, "%1");
        if (p) *p = '\0';

        char * escaped_share_dir = escapify(get_asf_share_dir());
        strcat(hh, escaped_share_dir);
        strcat(hh, "/mapready.chm");
        FREE(escaped_share_dir);
    }

    // Failed to find location of hh.exe through registry... try the system directory
    char *sr = getenv("SYSTEMROOT");
    if (strlen(sr) > 0) {
        int i, j = 0;
        for (i = 0; i < strlen(sr); ++i) {
            switch(sr[i]) {
                case '\\': hh[j] = '\\'; hh[j+1] = '\\'; ++j; break;
                default:   hh[j] = sr[i]; break;
            }
            ++j;
        }
        hh[j] = '\0';
        strcat(hh, "/hh.exe ");
        char * escaped_share_dir = escapify(get_asf_share_dir());
        strcat(hh, escaped_share_dir);
        strcat(hh, "/mapready.chm");
        FREE(escaped_share_dir);
    }

    if (strlen(hh)>0) {
        static GThreadPool *ttp = NULL;
        GError *err = NULL;

        if (!ttp)
        {
            if (!g_thread_supported ()) g_thread_init (NULL);
            ttp = g_thread_pool_new ((GFunc)help_viewer_thread, NULL,
                                     4, TRUE, &err);
            g_assert(!err);
        }

        g_thread_pool_push (ttp, g_string_new (hh), &err);
        g_assert(!err);
    }
    else {
        // Failed, give up.
        message_box("Couldn't find the help viewer!");
    }
#else
    GtkWidget *help_dialog;
    GtkWidget *help_text;
    GtkTextBuffer * text_buffer;
    FILE * help_file;
    gchar * help_filename;

    help_dialog =
        get_widget_checked("help_dialog");

    help_text =
        get_widget_checked("help_text");

    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(help_text));

    gtk_text_buffer_set_text(text_buffer, "", -1);

    help_filename = "mapready.txt";
    //help_file = fopen(help_filename, "rt");
    help_file = fopen_share_file(help_filename, "rt");
    if (help_file)
    {
        int line_count = 0;
        gchar * buffer = (gchar *) g_malloc(sizeof(gchar) * max_line_len);
        while (!feof(help_file))
        {
            gchar *p = fgets(buffer, max_line_len, help_file);
            if (p)
            {
                if (strlen(p)) line_count++;
                GtkTextIter end;
                gchar * q = strstr(buffer, "$VERSION");

                if (q)
                {
                    gchar * r = g_strdup(q + 8); /* 8 = length of '$VERSION' */

                    strcpy(q, MAPREADY_VERSION_STRING);
                    strcat(buffer, r);
                    g_free(r);
                }

                gtk_text_buffer_get_end_iter(text_buffer, &end);
                gtk_text_buffer_insert(text_buffer, &end, buffer, -1);
            }
        }
        if (!line_count) {
            sprintf(buffer, "\n\n  ERROR: Empty help file (mapready.txt) in share folder\n(%s)\n",
                    get_asf_share_dir());
            GtkTextIter end;
            gtk_text_buffer_get_end_iter(text_buffer, &end);
            gtk_text_buffer_insert(text_buffer, &end, buffer, -1);
        }

        fclose(help_file);
        g_free(buffer);
    }
    else {
        // No help file found
        gchar *buffer = (gchar *) g_malloc(sizeof(gchar) * max_line_len);
        strcpy(buffer, "\n\n  ERROR: Cannot find help file (mapready.txt) in share folder.\n");
        GtkTextIter end;
        gtk_text_buffer_get_end_iter(text_buffer, &end);
        gtk_text_buffer_insert(text_buffer, &end, buffer, -1);
        g_free(buffer);
    }

    gtk_widget_show(help_dialog);
#endif
}
예제 #22
0
파일: new.c 프로젝트: asfadmin/ASF_MapReady
static void load_file_banded_imp(const char *file, const char *band,
                                 int reset_location, int multilook)
{
    char *old_file = NULL;
    if (curr->filename) {
      old_file = STRDUP(curr->filename);
      free(curr->filename);
      curr->filename = NULL;
    }

    reset_globals(reset_location);
    asfPrintStatus("\nLoading: %s\n", file);

    // start loading of the new file
    curr->filename = STRDUP(file);

    // strip off a trailing "."
    if (curr->filename[strlen(curr->filename)-1] == '.')
        curr->filename[strlen(curr->filename)-1] = '\0';

    // Determine if the current file is a new file
    static char *last_file = NULL;
    int new_file = 0;
    if (!last_file) last_file = STRDUP(curr->filename);
    if (last_file && strcmp(last_file, curr->filename) != 0) {
      new_file = 1;
      FREE(last_file);
      last_file = STRDUP(curr->filename);
    }

    if (read_file(curr->filename, band, multilook, FALSE)) {
      int dummy;
      char lut[256];
      static int tiff_lut_exists = 0;
      static int asf_colormap_exists = 0;
      char embedded_tiff_lut_file[1024];
      char embedded_asf_colormap_file[1024];
      char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+128));
      sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR);
      sprintf(embedded_tiff_lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR,
              EMBEDDED_TIFF_COLORMAP_LUT_FILE);
      sprintf(embedded_asf_colormap_file, "%s%c%s", lut_loc, DIR_SEPARATOR,
              EMBEDDED_ASF_COLORMAP_LUT_FILE);
      FREE(lut_loc);
      tiff_lut_exists      = new_file ? 0 : tiff_lut_exists;
      asf_colormap_exists  = new_file ? 0 : asf_colormap_exists;
      tiff_lut_exists     += fileExists(embedded_tiff_lut_file)     ? 1 : 0;
      asf_colormap_exists += fileExists(embedded_asf_colormap_file) ? 1 : 0;
      GtkWidget *om = get_widget_checked("lut_optionmenu");
      int idx = gtk_option_menu_get_history(GTK_OPTION_MENU(om));
      if (tiff_lut_exists <= 1 &&
          check_for_embedded_tiff_lut(curr->filename, &dummy, lut))
      {
        // On first read of a TIFF file, check for embedded colormap and turn it into a
        // look up table if it exists ...then select it
        // (Run this stuff ONCE ...else the embedded lut will keep getting selected, even if changed)
        if (fileExists(embedded_asf_colormap_file)) {
          remove(embedded_asf_colormap_file);
          asf_colormap_exists = 0;
        }

        if (get_tiff_lut_index() == 0) {
            populate_lut_combo();

            GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
            gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_tiff_lut_index());
            set_current_index(get_tiff_lut_index());
            select_lut(lut);
        }
        else {
            set_current_index(idx);
        }
      }
      else if (tiff_lut_exists &&
               !check_for_embedded_tiff_lut(curr->filename, &dummy, lut))
      {
        // If a tiff colormap look up table exists, but the current file being
        // read is not a color map tiff, then delete the existing tiff color map
        // look up table
        remove(embedded_tiff_lut_file);
        tiff_lut_exists = 0;
        populate_lut_combo(); // Re-populate since tiff colormap lut was removed
        GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
        gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), 0); // Default to None
        set_current_index(0);
      }
      if (asf_colormap_exists <= 1 && is_colormap_ASF_file(curr->filename)) {
        // On first read of an ASF file, check for a colormap and turn it into a
        // look up table if it exists ...then select it
        // (Run this stuff ONCE ...else the embedded lut will keep getting selected, even if changed)
        if (fileExists(embedded_tiff_lut_file)) {
          remove(embedded_tiff_lut_file);
          tiff_lut_exists = 0;
        }
        if (get_asf_lut_index() == 0) {
            populate_lut_combo();
            select_lut(EMBEDDED_ASF_COLORMAP_LUT);

            GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
            gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_asf_lut_index());
            set_current_index(get_asf_lut_index());
        }
        else {
            set_current_index(idx);
        }
      }
      else if (asf_colormap_exists && !is_colormap_ASF_file(curr->filename)) {
        // If an ASF colormap look up table exists, but the current file being
        // read does not contain a color map in the metadata, then delete the existing ASF color map
        // look up table
        remove(embedded_asf_colormap_file);
        asf_colormap_exists = 0;
        populate_lut_combo(); // Re-populate since tiff colormap lut was removed
        GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
        gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), 0); // Default to None
        set_current_index(0);
      }
      if (new_file && !tiff_lut_exists && !asf_colormap_exists &&
           reset_location && curr->meta && curr->meta->general)
      {
        // Change LUT selection if necessary
        set_lut_based_on_image_type(curr->meta->general->image_data_type);
      }
      else if (!new_file) {
          // Respect any changes made by the user to the look-up table selection after
          // the file has loaded the first time ...
          set_current_index(idx);
      }
      check_lut();
      set_title(band != NULL, band);

      // load the metadata & image data, other setup
      fill_small_force_reload(curr);
      fill_big(curr);
      update_pixel_info(curr);
      update_zoom();
      fill_meta_info();
      fill_stats(curr);
      setup_bands_tab(curr->meta);

      FREE(old_file);
    }
    else {
      // file failed to load, re-load the old one

      // this is to prevent trying to re-load the old file again & again,
      // if for some reason that fails
      if (strcmp(curr->filename, old_file) == 0) {
          // if this does happen, just quit
          asfPrintError("Failed to load %s.\n", curr->filename);
      }

      asfPrintStatus("Failed to load %s.  Re-loading %s.\n", curr->filename, old_file);
      load_file_banded_imp(old_file, band, reset_location, multilook);

      if (reset_location) {
        center_samp = (double)(curr->ns)/2.;
        center_line = (double)(curr->nl)/2.;
        crosshair_samp = (double)(curr->ns)/2.;
        crosshair_line = (double)(curr->nl)/2.;
      }
    }
}
예제 #23
0
int write_test_config(char *configFile, test_config *cfg)
{
  FILE *fConfig;
  int shortFlag = FALSE, ii;

  if (cfg == NULL)
    check_return(1, "No configuration structure to write.\n");
  if (cfg->general->short_config)
    shortFlag = TRUE;

  fConfig = FOPEN(configFile, "w");

  fprintf(fConfig, "%s\n\n", cfg->comment);

  fprintf(fConfig, "[General]\n");
  // suite
  if (!shortFlag)
    fprintf(fConfig, "\n# This parameter defines the name of the test suite\n\n");
  fprintf(fConfig, "suite = %s\n", cfg->general->suite);
  // type
  if (!shortFlag)
    fprintf(fConfig, "\n# This parameter defines the test type: metadata, binary\n"
	  "# metadata runs checks on .meta file.\n"
	  "# binary run checks on binary data files.\n\n");
  fprintf(fConfig, "type = %s\n", cfg->general->type);
  // short configuration
  if (!shortFlag)
    fprintf(fConfig, "\n# The short configuration file flag allows the experienced "
	  "user to\n# generate configuration files without the verbose "
	  "comments that explain all\n# entries for the parameters in the "
	  "configuration file (1 for a configuration\n# without comments, 0 "
	  "for a configuration file with verbose comments)\n\n");
  fprintf(fConfig, "short configuration file = %d\n", 
	  cfg->general->short_config);
  // status
  if (!shortFlag)
    fprintf(fConfig, "\n# The general status field indicates the progress of the "
	  "testing.\n# Unless the interface is chosen to be 'manual' the tool "
	  "will run all tests\n# regardless of their individual status.\n"
	  "# Values for status: new, passed, failed\n\n");
  fprintf(fConfig, "status = %s\n", cfg->general->status);

  if (!shortFlag)
    fprintf(fConfig, "\n# Each test of the suite has its own section. The name of "
	  "the test is\n# user defined in name of the section [<test name>]"
	  "\n\n");
  for (ii=0; ii<cfg->general->test_count; ii++) {
    fprintf(fConfig, "\n[%s]\n", cfg->test[ii]->test);
    if (strcmp_case(cfg->general->type, "library") == 0) {
      // library
      if (!shortFlag)
	fprintf(fConfig, "\n# This parameter defines the name of the library function to be tested.\n\n");
      fprintf(fConfig, "library function = %s\n", cfg->test[ii]->lib->name);
    }
    else {
      // file
      if (!shortFlag)
	fprintf(fConfig, "\n# This parameters defines the name of the file to be "
		"tested.\n\n");
      fprintf(fConfig, "file = %s\n", cfg->test[ii]->file);
    }
    // specs
    if (!shortFlag)
      fprintf(fConfig, "\n# This parameters defines the name of the specification "
	    "file that contains\n# the metadata parameters that are being "
	    "checked. They can be checked for\n# existence in the file, a value "
	    "within a range (defined by minimum and maximum)\n# and values in a "
	    "predefined list.\n"
	    "# The specification files are located in %s/meta_test.\n\n", 
	    get_asf_share_dir());
    fprintf(fConfig, "specs = %s\n", cfg->test[ii]->specs);
    // status
    if (!shortFlag)
      fprintf(fConfig, "\n# The parameter indicates the status of this test.\n"
	    "# Unless the interface is chosen to be 'manual' the tool "
	    "will run all tests\n# regardless of their individual status.\n"
	    "# Once a test is run, the status is either 'passed' or 'failed'. "
	    "To avoid\n# that a test is executed altogether in manual mode set "
	    "the status to 'skip'\n"
	    "# Values for status: new, passed, failed, skip\n\n");
    fprintf(fConfig, "status = %s\n", cfg->test[ii]->status);
  }

  FCLOSE(fConfig);

  return(0);
}
예제 #24
0
int init_test_config(char *configFile)
{
  FILE *fConfig;

  if ( fileExists(configFile) ) {
    asfPrintError("Cannot create file, %s, because it already exists.\n",
                  configFile);
  }
  fConfig = FOPEN(configFile, "w");

  fprintf(fConfig, "asf_test configuration file\n\n");

  fprintf(fConfig, "[General]\n\n");
  // suite
  fprintf(fConfig, "# This parameter defines the name of the test suite\n\n");
  fprintf(fConfig, "suite = \n\n");
  // type
  fprintf(fConfig, "# This parameter defines the test type: metadata, library, "
	  "binary\n# metadata runs checks on .meta file.\n"
	  "# library run on library functions.\n"
	  "# binary run checks on binary data files.\n\n");
  fprintf(fConfig, "type = metadata\n\n");
  // short configuration
  fprintf(fConfig, "# The short configuration file flag allows the experienced "
	  "user to\n# generate configuration files without the verbose "
	  "comments that explain all\n# entries for the parameters in the "
	  "configuration file (1 for a configuration\n# without comments, 0 "
	  "for a configuration file with verbose comments)\n\n");
  fprintf(fConfig, "short configuration file = 0\n\n");

  // status
  fprintf(fConfig, "# The general status field indicates the progress of the "
	  "testing.\n# Unless the interface is chosen to be 'manual' the tool "
	  "will run all tests\n# regardless of their individual status.\n"
	  "# Values for status: new, passed, failed\n\n");
  fprintf(fConfig, "status = new\n\n");

  fprintf(fConfig, "# Each test of the suite has its own section. The name of "
	  "the test is\n# user defined in name of the section [<test name>]"
	  "\n\n");
  fprintf(fConfig, "[Test]\n\n");
  // file
  fprintf(fConfig, "# This parameters defines the name of the file to be "
	  "tested.\n\n");
  fprintf(fConfig, "file = \n\n");\
  // specs
  fprintf(fConfig, "# This parameters defines the name of the specification "
	  "file that contains\n# the metadata parameters that are being "
	  "checked. They can be checked for\n# existence in the file, a value "
	  "within a range (defined by minimum and maximum)\n# and values in a "
	  "predefined list.\n"
	  "# The specification files are located in %s/meta_test.\n\n", 
	  get_asf_share_dir());
  fprintf(fConfig, "specs = \n\n");
  // status
  fprintf(fConfig, "# The parameter indicates the status of this test.\n"
	  "# Unless the interface is chosen to be 'manual' the tool "
	  "will run all tests\n# regardless of their individual status.\n"
	  "# Once a test is run, the status is either 'passed' or 'failed'. "
	  "To avoid\n# that a test is executed altogether in manual mode set "
	  "the status to 'skip'\n"
	  "# Values for status: new, passed, failed, skip\n\n");
  fprintf(fConfig, "status = new\n\n");

  FCLOSE(fConfig);

  asfPrintStatus("   Initialized test configuration file\n\n");

  return(0);
}
예제 #25
0
int asf_import(radiometry_t radiometry, int db_flag, int complex_flag,
	       int multilook_flag, int azimuth_look_count, int range_look_count,
	       int amp0_flag, input_format_t format_type,
	       char *band_id, char *data_type, char *image_data_type, 
	       char *lutName, char *prcPath, double lowerLat, double upperLat, 
	       double lowerLon, double upperLon, int line, int sample, 
	       int width, int height, int save_intermediates,
	       double *p_range_scale, double *p_azimuth_scale,
	       double *p_correct_y_pixel_size, int apply_ers2_gain_fix,
	       char *inMetaNameOption, char *inBaseName, char *ancillary_file,
	       char *colormapName, char *slave_file, char *interferogram_file,
	       char *coherence_file, char *baseline_file, 
	       int complex_gamma, char *uavsar_type,
	       int metaonly, char *outBaseName)
{
  char outDataName[256], outMetaName[256];

  asfPrintStatus("   Importing: %s\n", inBaseName);

  /*
  printf("\nradiometry: %d\n", radiometry);
  printf("db_flag: %d\n", db_flag);
  printf("complex_flag: %d\n", complex_flag);
  printf("multilook_flag: %d\n", multilook_flag);
  printf("amp0_flag: %d\n", amp0_flag);
  printf("format_type: %d\n", format_type);
  printf("band_id: %s\n", band_id);
  printf("data_type: %s\n", data_type);
  printf("image_data_type: %s\n", image_data_type);
  printf("lutName: %s\n", lutName);
  printf("line: %d\n", line);
  printf("sample: %d\n", sample);
  printf("width: %d\n", width);
  printf("height: %d\n", height);
  printf("p_range_scale: %f\n", &p_range_scale);
  printf("p_azimuth_scale: %f\n", &p_azimuth_scale);
  printf("p_correct_y_pixel_size: %f\n", &p_correct_y_pixel_size);
  printf("apply_ers2_gain_fix: %d\n", apply_ers2_gain_fix);
  printf("inMetaNameOption: %s\n", inMetaNameOption);
  printf("inBaseName: %s\n", inBaseName);
  printf("outBaseName: %s\n\n", outBaseName);
  */

  strcpy(outDataName, outBaseName);
  strcpy(outMetaName, outBaseName);
  strcat(outMetaName, TOOLS_META_EXT);

  if (metaonly) {
    create_xml_meta(inBaseName, outBaseName, format_type);
    return 0;
  }

  if ((radiometry == r_SIGMA ||
       radiometry == r_BETA  ||
       radiometry == r_GAMMA ||
       radiometry == r_POWER)   &&
       !(format_type == CEOS || format_type == STF || format_type == AIRSAR ||
	 format_type == ALOS_MOSAIC || format_type == TERRASAR))
  {
    // A power flag is on, but the input file is not CEOS or STF format
    // so it will be ignored
    asfPrintWarning("Power flags %s%s will be only accepted for the following\n"
		    "data formats since other formats do not indicate what "
                    "type of data is in the file:\n"
		    "CEOS, TERRASAR, STF, AirSAR and ALOS mosaics.\n"
		    "Assuming the input data is an AMPLITUDE image...\n",
                    radiometry == r_SIGMA ? "SIGMA" :
                    radiometry == r_BETA  ? "BETA"  :
                    radiometry == r_GAMMA ? "GAMMA" :
                    radiometry == r_POWER ? "POWER" : "UNKNOWN",
                    db_flag               ? " scaled to DECIBELS" : "");
  }

  // Ingest all sorts of flavors of CEOS data/
  if (format_type == CEOS) {
    asfPrintStatus("   Data format: CEOS\n");
    import_ceos(inBaseName, outBaseName, band_id, lutName,
                p_range_scale, p_azimuth_scale, p_correct_y_pixel_size,
                line, sample, width, height, inMetaNameOption, radiometry,
                db_flag, complex_flag, multilook_flag, azimuth_look_count,
		range_look_count, amp0_flag, apply_ers2_gain_fix);
    // Replace the restituted state vectors that comes with the image data with
    // precision state vectors from Delft
    if (prcPath != NULL && strlen(prcPath) > 0) {
      update_state_vectors(outBaseName, prcPath);
    }
  }
  // Ingest Vexcel Sky Telemetry Format (STF) data
  else if (format_type == STF) {
    asfPrintStatus("   Data format: STF\n");
    int lat_constrained = upperLat != -99 && lowerLat != -99;
    import_stf(inBaseName, outBaseName, radiometry, inMetaNameOption,
               lat_constrained, lowerLat, upperLat, prcPath);
  }
  else if (format_type == GENERIC_GEOTIFF) {
    asfPrintStatus("   Data format: GEOTIFF\n");
    if (band_id != NULL &&
      strlen(band_id) > 0 &&
      strncmp(uc(band_id), "ALL", 3) != 0) {
      asfPrintWarning("The -band option is not supported for data files containing\n"
          "multiple bands within a single file (such as GeoTIFF or TIFF)\n"
          "rather than in individual band files (such as ALOS etc).\n"
          "\nThe import will continue, but all available bands will be\n"
          "imported into a single ASF-format file.  You may select any\n"
          "individual band for export however.\n");
    }

    char *ext = findExt(inBaseName);
    if (ext != NULL) {
      *ext = '\0';
    }
    GString *inGeotiffName = find_geotiff_name (inBaseName);
    if ( inGeotiffName == NULL ) {
      asfPrintError ("Couldn't find a GeoTIFF file (i.e. a file with "
         "extension '.tif', '.tiff',\n'.TIF', or '.TIFF') "
         "corresponding to specified inBaseName:\n"
         "%s\n", inBaseName);
    }
    if (strlen(image_data_type)               &&
        strncmp(image_data_type, MAGIC_UNSET_STRING, strlen(MAGIC_UNSET_STRING)) != 0)
    {
      import_generic_geotiff (inGeotiffName->str, outBaseName, image_data_type);
    }
    else {
      import_generic_geotiff (inGeotiffName->str, outBaseName, NULL);
    }
    g_string_free(inGeotiffName,TRUE);
  }
  else if (format_type == BIL) {
    asfPrintStatus("   Data format: BIL\n");
    import_bil(inBaseName, outBaseName);
  }
  else if (format_type == GRIDFLOAT) {
    asfPrintStatus("   Data format: GRIDFLOAT\n");
    import_gridfloat(inBaseName, outBaseName);
  }
  else if (format_type == AIRSAR) {
    asfPrintStatus("   Data format: AIRSAR\n");
    import_airsar(inBaseName, update(radiometry, db_flag), outBaseName);
  }
  else if (format_type == UAVSAR) {
    asfPrintStatus("   Data format: UAVSAR\n");
    import_uavsar(inBaseName, line, sample, width, height, 
		  update(radiometry, db_flag), uavsar_type, outBaseName);
  }
  else if (format_type == VP) {
    asfPrintStatus("   Data format: VP\n");
    import_vexcel_plain(inBaseName, outBaseName);
  }
  else if (format_type == JAXA_L0) {
      asfPrintStatus("   Data format: JAXA_L0 (ALOS AVNIR-2 Level 0)\n");
      import_jaxa_L0(inBaseName, outBaseName);
  }
  else if (format_type == ALOS_MOSAIC) {
    asfPrintStatus("   Data format: ALOS MOSAIC\n");
    import_alos_mosaic(inBaseName, update(radiometry, db_flag), outBaseName);
  }
  else if (format_type == TERRASAR) {
    asfPrintStatus("   Data format: TERRASAR\n");
    import_terrasar(inBaseName, update(radiometry, db_flag), outBaseName, 0);
  }
  else if (format_type == RADARSAT2) {
    asfPrintStatus("   Data format: RADARSAT2\n");
    import_radarsat2(inBaseName, update(radiometry, db_flag), outBaseName, 0);
  }
  else if (format_type == POLSARPRO) {
    asfPrintStatus("   Data format: POLSARPRO\n");
    import_polsarpro(inBaseName, ancillary_file, colormapName, image_data_type,
		     db_flag, outBaseName);
  }
  else if (format_type == GAMMA) {
    asfPrintStatus("   Data format: GAMMA\n");
    import_gamma(inBaseName, inMetaNameOption, slave_file, interferogram_file,
		 coherence_file, baseline_file, complex_gamma, 
		 outBaseName);
  }
  else if (format_type == ROIPAC) {
    asfPrintStatus("   Data format: ROI_PAC\n");
    import_roipac(inBaseName, outBaseName);
  }
  else if (format_type == SMAP) {
    asfPrintStatus("   Data format: SMAP\n");
    import_smap(inBaseName, outBaseName, 
		upperLat, upperLon, lowerLat, lowerLon);
  }
  // Don't recognize this data format; report & quit
  else {
    asfPrintError("Unrecognized data format: '%d'\n",format_type);
  }
  int num_elements = 0;
  int is_jasc_palette = 0;
  if (format_type == AIRSAR && colormapName != NULL)
    asfPrintError("Colormaps not supported for AirSAR data.\n");
  if (format_type != AIRSAR && format_type != UAVSAR) {
    meta_parameters *meta = meta_read(outMetaName);
    if (meta->colormap) {
      if (!(colormapName != NULL && 
            (meta->general->data_type == ASF_BYTE || is_PolSARpro(inBaseName)))) {
        // Ooops.  Tried to apply a colormap to the wrong type of data
        asfPrintWarning(
          "Color map specified with the -colormap option (%s) not\n"
          "applied during ingest.  Color maps can only be applied to byte or\n"
          "PolSARpro data.  Data was imported as-is.\n", colormapName);
      }
      else {
        // Apply the user-selected color map to the metadata
        FILE *fp = NULL;
        unsigned char * lut_buffer;
        char *lut_basename = STRDUP(colormapName);
        char *ext = findExt(lut_basename);
        if (ext) *ext = '\0';
        
        // Check LUT file validity and allocate appropriately sized buffer
        // to read into
        char magic_str[1024];
        char version_s[1024];
        char num_elements_s[1024];
        char lut_path[1024];
        sprintf(lut_path, "%s%clook_up_tables%c%s.pal", get_asf_share_dir(),
                DIR_SEPARATOR, DIR_SEPARATOR, lut_basename);
        if (fileExists(lut_path)) {
          fp = (FILE*)FOPEN(lut_path, "rt");
          fgets(magic_str, 1024, fp);
          fgets(version_s, 1024, fp);
          fgets(num_elements_s, 1024, fp);
          FCLOSE(fp);
          int version = atoi(version_s);
          num_elements = atoi(num_elements_s);
          is_jasc_palette =
            (strncmp(magic_str, "JASC", 4) == 0 && version == 100) ? 1 : 0;
          if (is_jasc_palette && (num_elements <= 0 || num_elements > 512)) {
            asfPrintWarning(
              "Found invalid JASC-PAL type color map file (%s) ...color map\n"
              "not applied.\n", colormapName);
          }
          if (num_elements > 256) {
            asfPrintWarning(
              "PolSARpro look-up table contains more than 256 elements (%d).\n"
              "Only the first 256 will be read and mapped to data.\n",
              num_elements);
          }
        }
        else {
          sprintf(lut_path, "%s%clook_up_tables%c%s.lut", get_asf_share_dir(),
                  DIR_SEPARATOR, DIR_SEPARATOR, lut_basename);
          if (fileExists(lut_path)) {
            is_jasc_palette = 0; // Assume ASF format
          }
          else {
            strcpy(lut_path, "");
          }
        }
        lut_buffer = MALLOC(sizeof(unsigned char) * 3 * MAX_LUT_DN);
      
        // Read the LUT
        if (strlen(lut_path) > 0) {
          int max_dn = read_lut(lut_path, lut_buffer);
	
          // Populate the metadata colormap
          if (!meta->colormap) meta->colormap = meta_colormap_init();
          if (is_jasc_palette) {
            meta->colormap->num_elements =
              (num_elements <= 256) ? num_elements : 256;
            sprintf(meta->colormap->look_up_table, "%s.pal", lut_basename);
          }
          else {
            num_elements = max_dn + 1;
            meta->colormap->num_elements = num_elements;
            sprintf(meta->colormap->look_up_table, "%s.lut", lut_basename);
          }
          meta->colormap->rgb =
            (meta_rgb*)CALLOC(meta->colormap->num_elements, sizeof(meta_rgb));
          int i;
          for (i = 0; i < meta->colormap->num_elements; i++) {
            meta->colormap->rgb[i].red   = lut_buffer[i*3];
            meta->colormap->rgb[i].green = lut_buffer[i*3+1];
            meta->colormap->rgb[i].blue  = lut_buffer[i*3+2];
          }
        }
        FREE(lut_basename);
        meta_write(meta, outMetaName);
      }
    }
    
    meta_free(meta);
  }

  asfPrintStatus("Import complete.\n\n");
  return 0;
}
예제 #26
0
int open_google_earth()
{
    char *kml_filename = appendExt(curr->filename, ".kml");

    char *basename = get_basename(curr->filename);
    char *dirname = get_dirname(curr->filename);

    char *arg;
    if (strlen(dirname)==0) {
        char *tmpdir = g_get_current_dir();
        dirname = escapify(tmpdir);
        arg = MALLOC(sizeof(char)*(strlen(dirname)+strlen(kml_filename)+20));
        sprintf(arg, "%s/%s", dirname, kml_filename);
        //free(tmpdir);
    }
    else {
        arg = STRDUP(kml_filename);
    }

    char *png_file = appendExt(arg, ".png");

    printf("png file: %s\n", png_file);
    printf("Temporary kml file: %s\n", arg);

    FILE *kml_file = fopen(arg, "w");
    if (!kml_file)
    {
        asfPrintWarning("Couldn't open kml file!\n");        
        return FALSE;
    }

    dbf_header_t *dbf;
    int nAttr, nCoords;
    double *lat, *lon, center_lat, center_lon;
    char configFile[255], *name;
    meta_parameters *meta;

    sprintf(configFile, "%s/convert2vector.config", get_asf_share_dir());
    c2v_config *cfg = read_c2v_config(configFile);

    kml_header(kml_file);

    meta = meta2vector(curr->filename, &dbf, &nAttr, &lat, &lon, &nCoords);
    //meta_parameters *meta = curr->meta;
    if (meta && meta->general &&
        meta_is_valid_double(meta->general->center_latitude) &&
        meta_is_valid_double(meta->general->center_longitude))
    {
        pixbuf2png(pixbuf_small, png_file);
        //kml_entry_with_overlay(kml_file, meta, basename, png_file, dirname);
        name = get_basename(kml_filename);
        center_lat = meta->general->center_latitude;
        center_lon = meta->general->center_longitude;
        write_kml_placemark(kml_file, name, center_lat, center_lon, png_file, 
          dbf, nAttr, lat, lon, nCoords, cfg);
        FREE(lat);
        FREE(lon);
        FREE(dbf);
    }
    else
    {
        asfPrintWarning(
            "Failed, metadata doesn't contain valid lat/lon info.\n");
        return FALSE;
    }

    kml_footer(kml_file);
    fclose(kml_file);

    gchar *ge;

    printf("kml: %s\n", kml_filename);
    printf("dir: %s\n", dirname);

#ifdef win32
    char path[1024];
    FindExecutable((LPCTSTR)kml_filename, (LPCTSTR)dirname, (LPTSTR)path);
    ge = escapify(path);
    printf("Path to google earth: %s\n", ge);
    
    asfSystem("\"%s\" \"%s\"", ge, arg);
#else
    ge = find_in_path("googleearth");
    if (!ge)
    {
       message_box("Couldn't find googleearth! Is it installed?");
       return FALSE;
    }

    int pid = fork();
    if (pid == 0) {
        asfSystem("\"%s\" \"%s\"", ge, arg);
        //unlink(kml_filename);
        exit(EXIT_SUCCESS);
    }
#endif

    free(kml_filename);
    free(basename);
    free(dirname);
    free(arg);

    return TRUE;
}
예제 #27
0
void settings_save(Settings *s)
{
    char *sav_file = find_in_share("req_settings.txt");
    if (sav_file && fileExists(sav_file)) {
        // update an existing file
        printf("Found settings file: %s\n", sav_file);
        char *new_sav_txt = MALLOC(sizeof(char)*1024);
        strcpy(new_sav_txt, "");
        int i,len=2048;
        int wrote_csv=FALSE,
            wrote_output=FALSE,
            wrote_obs_req_num=FALSE,
            wrote_obs_req_id_aadn=FALSE,
            wrote_obs_req_id_tdrs=FALSE,
            wrote_acq_req_num=FALSE,
            wrote_odl0_seq_num=FALSE,
            wrote_odl0_req_id=FALSE,
            wrote_station_code=FALSE;

        int wrote_acq_req_id[MAX_STATIONS];
        int wrote_acq_req_stn_code[MAX_STATIONS];
        for (i=0; i<MAX_STATIONS; ++i) {
            wrote_acq_req_id[i] = FALSE;
            wrote_acq_req_stn_code[i] = FALSE;
        }

        FILE *fp = FOPEN(sav_file, "r");
        if (!fp) {
            message_box("Error opening output file!\n");
            return;
        }

        char buf[1024];
        while (fgets(buf, 1024, fp) != NULL) {
            if (s->csv_dir && matches(buf, csv_dir_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %s\r\n", csv_dir_key, s->csv_dir);
                wrote_csv = TRUE;
            } else if (s->output_dir && matches(buf, output_dir_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %s\r\n", output_dir_key, s->output_dir);
                wrote_output = TRUE;
            } else if (matches(buf, obs_req_num_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", obs_req_num_key, s->obs_req_num);
                wrote_obs_req_num = TRUE;
            } else if (matches(buf, obs_req_id_aadn_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", obs_req_id_aadn_key, s->obs_req_id_aadn);
                wrote_obs_req_id_aadn = TRUE;
            } else if (matches(buf, obs_req_id_tdrs_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", obs_req_id_tdrs_key, s->obs_req_id_tdrs);
                wrote_obs_req_id_tdrs = TRUE;
            } else if (matches(buf, acq_req_num_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", acq_req_num_key, s->acq_req_num);
                wrote_acq_req_num = TRUE;
            } else if (matches(buf, odl0_seq_num_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", odl0_seq_num_key, s->odl0_seq_num);
                wrote_odl0_seq_num = TRUE;
            } else if (matches(buf, odl0_req_id_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", odl0_req_id_key, s->odl0_req_id);
                wrote_odl0_req_id = TRUE;
            } else if (s->station_code && matches(buf, station_code_key)) {
                add_to_text(&new_sav_txt, &len,
                    "%s = %s\r\n", station_code_key, s->station_code);
                wrote_station_code = TRUE;
            } else {
                int found=0;
                for (i=0; i<MAX_STATIONS; ++i) {
                    char id_key[128], stn_code_key[128];
                    snprintf(id_key, 128, "%s %d", acq_req_id_key, i+1);
                    snprintf(stn_code_key, 128, "%s %d", acq_req_stn_code_key, i+1);
                    if (matches(buf, id_key)) {
                        found = TRUE;
                        add_to_text(&new_sav_txt, &len, "%s = %s\r\n",
                            stn_code_key, s->acq_req_stn_codes[i]);
                        wrote_acq_req_stn_code[i] = TRUE;
                    } else if (matches(buf, stn_code_key)) {
                        found = TRUE;
                        add_to_text(&new_sav_txt, &len, "%s = %d\r\n",
                            id_key, s->acq_req_ids[i]);
                        wrote_acq_req_id[i] = TRUE;
                    }
                }
                if (!found)
                    add_to_text(&new_sav_txt, &len, "%s", buf);
            }
        }
        FCLOSE(fp);

        if (s->csv_dir && !wrote_csv)
            add_to_text(&new_sav_txt, &len,
                "%s = %s\r\n", csv_dir_key, s->csv_dir);
        if (s->output_dir && !wrote_output)
            add_to_text(&new_sav_txt, &len,
                "%s = %s\r\n", output_dir_key, s->output_dir);
        if (!wrote_obs_req_num && s->obs_req_num > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", obs_req_num_key, s->obs_req_num);
        if (!wrote_obs_req_id_aadn && s->obs_req_id_aadn > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", obs_req_id_aadn_key, s->obs_req_id_aadn);
        if (!wrote_obs_req_id_tdrs && s->obs_req_id_tdrs > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", obs_req_id_tdrs_key, s->obs_req_id_tdrs);
        if (!wrote_acq_req_num && s->acq_req_num > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", acq_req_num_key, s->acq_req_num);
        if (!wrote_odl0_seq_num && s->odl0_seq_num > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", odl0_seq_num_key, s->odl0_seq_num);
        if (!wrote_odl0_req_id && s->odl0_req_id > 1)
            add_to_text(&new_sav_txt, &len,
                "%s = %d\r\n", s->odl0_req_id);
        if (s->station_code && !wrote_station_code)
            add_to_text(&new_sav_txt, &len,
                "%s = %s\r\n", station_code_key, s->station_code);

        for (i=0; i<MAX_STATIONS; ++i) {
            if (!wrote_acq_req_id[i] && s->acq_req_ids[i] > 0 &&
                !wrote_acq_req_stn_code[i] &&
                strlen(s->acq_req_stn_codes[i]) > 0)
            {
                char id_key[128], stn_code_key[128];
                snprintf(id_key, 128, "%s %d", acq_req_id_key, i+1);
                snprintf(stn_code_key, 128, "%s %d", acq_req_stn_code_key, i+1);
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", stn_code_key, s->acq_req_stn_codes[i]);
                add_to_text(&new_sav_txt, &len,
                    "%s = %d\r\n", id_key, s->acq_req_ids[i]);
            }
        }

        fp = FOPEN(sav_file, "w");
        fprintf(fp, "%s", new_sav_txt);
        FCLOSE(fp);
    } else {
        sav_file = MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+32));
        sprintf(sav_file, "%s/req_settings.txt", get_asf_share_dir());
        // write a new file
        FILE *fp = FOPEN(sav_file, "w");
        if (s->csv_dir)
            fprintf(fp, "%s = %s\r\n", csv_dir_key, s->csv_dir);
        if (s->output_dir)
            fprintf(fp, "%s = %s\r\n", output_dir_key, s->output_dir);
        fprintf(fp, "%s = %d\r\n", obs_req_num_key, s->obs_req_num);
        fprintf(fp, "%s = %d\r\n", obs_req_id_aadn_key, s->obs_req_id_aadn);
        fprintf(fp, "%s = %d\r\n", obs_req_id_tdrs_key, s->obs_req_id_tdrs);
        fprintf(fp, "%s = %d\r\n", acq_req_num_key, s->acq_req_num);
        fprintf(fp, "%s = %d\r\n", odl0_seq_num_key, s->odl0_seq_num);
        fprintf(fp, "%s = %d\r\n", odl0_req_id_key, s->odl0_req_id);

        int i;
        for (i=0; i<MAX_STATIONS; ++i) {
            if (s->acq_req_ids[i] > 0 && strlen(s->acq_req_stn_codes[i]) > 0) {
                char id_key[128], stn_code_key[128];
                snprintf(stn_code_key, 128, "%s %d", acq_req_stn_code_key, i+1);
                fprintf(fp, "%s = %s\r\n", stn_code_key, s->acq_req_stn_codes[i]);
                snprintf(id_key, 128, "%s %d", acq_req_id_key, i+1);
                fprintf(fp, "%s = %d\r\n", id_key, s->acq_req_ids[i]);
            }
        }
        if (s->station_code)
            fprintf(fp, "%s = %s\r\n", station_code_key, s->station_code);
        FCLOSE(fp);
    }
    free(sav_file);
}