Exemplo n.º 1
0
int handle_brs_file(const char *filename, char *meta_name, char *data_name,
                    char **err)
{
    char *ext = findExt(filename);
    int has_ext = ext && strlen(ext) > 0;
    int has_brs_ext = has_ext && strcmp_case(ext,".brs")==0;
    char *file;

    if (!has_ext) {
        has_brs_ext = try_ext(filename, ".brs");
        if (!has_brs_ext) {
            has_brs_ext = try_ext(filename, ".BRS");
            if (has_brs_ext)
                file = appendExt(filename, ".BRS");
        }
        else {
            file = appendExt(filename, ".brs");
        }
    }
    else
        file = STRDUP(filename);

    if (has_brs_ext)
    {
        strcpy(meta_name, file);
        strcpy(data_name, file);

        int ret;
        if (!fileExists(data_name)) {
            // I don't think this will actually ever run
            int l = sizeof(char)*strlen(filename)+255;
            *err = MALLOC(l);
            snprintf(*err, l, "Error opening BRS file: %s\n", data_name);
            ret = FALSE;
        }
        else
            ret = TRUE;

        free(file);
        return ret;
    }
    else {
        int l = sizeof(char)*strlen(filename)+255;
        *err = MALLOC(l);
        snprintf(*err, l, "Failed to open %s as a BRS File.\n", filename);
        free(file);
        return FALSE;
    }

    // not reached
    assert(FALSE);
    return FALSE;
}
Exemplo n.º 2
0
int handle_asf_file(const char *filename, char *meta_name, char *data_name,
                    char **err)
{
    char *ext = findExt(filename);
    int has_ext = ext && strlen(ext) > 0;
    int has_asf_ext = has_ext &&
        (strcmp_case(ext,".img")==0 || strcmp_case(ext,".meta")==0);

    // either they gave us an ASF Internal extension, or we try adding it
    // to a user-provided basename, and that file does exist
    if (has_asf_ext || try_ext(filename, ".img"))
    {
        char *m = appendExt(filename, ".meta");
        char *d = appendExt(filename, ".img");

        strcpy(meta_name, m);
        strcpy(data_name, d);

        int ret;
        if (!fileExists(meta_name) || !fileExists(data_name)) {
            int l = sizeof(char)*strlen(filename)*2+255;
            *err = MALLOC(l);
            snprintf(*err, l,
                "Error opening ASF Internal Format file.\n"
                "  Metadata file: %s - %s\n"
                "      Data file: %s - %s\n",
                m, fileExists(m) ? "Found" : "NOT FOUND",
                d, fileExists(d) ? "Found" : "NOT FOUND");

            ret = FALSE;
        }
        else
            ret = TRUE;

        free(m);
        free(d);

        return ret;
    }
    else {
        // in theory this shouldn't happen, if try_ext is working
        assert(!try_ext(filename, ".img"));
        int l = sizeof(char)*strlen(filename)*2+255;
        *err = MALLOC(l);
        snprintf(*err, l,
            "Failed to open %s as an ASF Internal Format File.\n", filename);
        return FALSE;
    }

    // not reached
    assert(FALSE);
    return FALSE;
}
Exemplo n.º 3
0
int handle_png_file(const char *filename, char *meta_name, char *data_name,
                    char **err)
{
    char *ext = findExt(filename);
    int has_ext = ext && strlen(ext) > 0;
    int has_png_ext = has_ext && strcmp_case(ext,".png")==0;

    if (!has_ext) {
        has_png_ext = try_ext(filename, ".png");
    }

    if (has_png_ext)
    {
        char *d=NULL;
        if (has_ext)
            d = STRDUP(filename);
        else if (has_png_ext)
            d = appendExt(filename, ".png");
        assert(d);

        strcpy(meta_name, d);
        strcpy(data_name, d);
        free(d);

        int ret;
        if (!fileExists(data_name)) {
            // I don't think this will actually ever run
            int l = sizeof(char)*strlen(filename)+255;
            *err = MALLOC(l);
            snprintf(*err, l, "Error opening PNG file: %s\n", data_name);
            ret = FALSE;
        }
        else
            ret = TRUE;

        return ret;
    }
    else {
        // in theory this shouldn't happen, if try_ext is working
        assert(!try_ext(filename, ".png"));
        int l = sizeof(char)*strlen(filename)+255;
        *err = MALLOC(l);
        snprintf(*err, l, "Failed to open %s as a PNG File.\n", filename);
        return FALSE;
    }

    // not reached
    assert(FALSE);
    return FALSE;
}
Exemplo n.º 4
0
int try_brs(const char *filename, int try_extensions)
{
    char *ext = findExt(filename);

    if (ext && strlen(ext) > 0) {
        return strcmp_case(ext, ".brs") == 0;
    } else if (try_extensions) {
        int ret = try_ext(filename, ".brs");
        if (!ret)
            ret = try_ext(filename, ".BRS");
        return ret;
    }
    return FALSE;
}
Exemplo n.º 5
0
static int	verif(char *file)
{
	if (try_ext(file) == 0)
		return (0);
	if (try_file(file) == 0)
		return (0);
	return (1);
}
Exemplo n.º 6
0
int try_png(const char *filename, int try_extensions)
{
    char *ext = findExt(filename);

    if (ext && strlen(ext) > 0) {
      return strcmp_case(ext, ".png") == 0;
    } else if (try_extensions) {
      return try_ext(filename, ".png");
    }
    return FALSE;
}
Exemplo n.º 7
0
int try_asf(const char *filename, int try_extensions)
{
    char *ext = findExt(filename);

    if (ext && strlen(ext) > 0) {
        return strcmp_case(ext, ".img") == 0 ||
               strcmp_case(ext, ".meta") == 0;
    } else if (try_extensions) {
        return try_ext(filename, ".img");
    } else {
        return FALSE;
    }
}
Exemplo n.º 8
0
// External entry point
//  --> meta: SAR metadata
//  --> dem_cla_arg: either (1) a DEM, (2) a directory with DEMs,
//                   (3) a file containing directories of DEMs.
// In case (1), nothing is done, return value is dem_cla_arg.
// In case (2), the directory is scanned and a DEM is built from
//              the DEMs found in that directory.
// In case (3), All of the directories are scanned, and a DEM is
//              built from the DEMs in all of the directories.
char *build_dem(meta_parameters *meta, const char *dem_cla_arg,
                const char *dir_for_tmp_dem)
{
    char *ext = findExt(dem_cla_arg);
    if (ext) {
        // check against known DEM extensions
        if (strcmp_case(ext, ".img") == 0 ||
            strcmp_case(ext, ".tif") == 0 ||
            strcmp_case(ext, ".tiff") == 0)
        {
            asfPrintStatus("%s: DEM.\n", dem_cla_arg);
            // presumably, this is a DEM -- case (1) above.
            return STRDUP(dem_cla_arg);
        }
    }
    else {
        // no extension -- user may have just provided the basename
        if (try_ext(dem_cla_arg, ".img")) {
            asfPrintStatus("%s: DEM.\n", dem_cla_arg);
            return STRDUP(dem_cla_arg);
        } else if (try_ext(dem_cla_arg, ".tiff")) {
            asfPrintStatus("%s: DEM.\n", dem_cla_arg);
            return STRDUP(dem_cla_arg);
        } else if (try_ext(dem_cla_arg, ".tif")) {
            asfPrintStatus("%s: DEM.\n", dem_cla_arg);
            return STRDUP(dem_cla_arg);
        }
    }

    char **list_of_dems = NULL;
    // Eliminated case (1) -- try case (2)
    if (is_dir_s(dem_cla_arg)) {
        asfPrintStatus("%s: directory containing DEMs.\n", dem_cla_arg);
        int n;
        list_of_dems =
            find_overlapping_dems_dir(meta, dem_cla_arg, &n);
    }
    else {
        // this is case (3)
        asfPrintStatus("%s: file containing directories of DEMs.\n", dem_cla_arg);
        if (fileExists(dem_cla_arg)) {
            int n;
            list_of_dems =
                find_overlapping_dems(meta, dem_cla_arg, &n);
        }
    }

    if (list_of_dems) {
        // form a bounding box
        double lat_lo, lat_hi, lon_lo, lon_hi;
        get_bounding_box_latlon(meta, &lat_lo, &lat_hi, &lon_lo, &lon_hi);

        // hard-coded name of the built dem
        char *built_dem;
        if (strlen(dir_for_tmp_dem) > 0) {
            built_dem = MALLOC(sizeof(char)*(strlen(dir_for_tmp_dem)+10));
            sprintf(built_dem, "%s/built_dem", dir_for_tmp_dem);
        } else
            built_dem = STRDUP("built_dem");

        // always geocode to utm -- we may wish change this to use the
        // user's preferred projection...
        asf_mosaic_utm(list_of_dems, built_dem,
            utm_zone(meta->general->center_longitude), lat_lo, lat_hi,
            lon_lo, lon_hi, meta->general->no_data);

        asfPrintStatus("Constructed DEM: %s\n", built_dem);
        return built_dem;
    }
    else {
        asfPrintError("DEM not found: %s\n", dem_cla_arg);
        return NULL; // not reached
    }
}