Example #1
0
void *Rast3d_open_cell_old_no_header(const char *name, const char *mapset)
{
    RASTER3D_Map *map;
    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];

    Rast3d_init_defaults();

    if (!Rast3d_mask_open_old()) {
	Rast3d_error(_("Rast3d_open_cell_old_no_header: error in Rast3d_mask_open_old"));
	return (void *)NULL;
    }

    map = Rast3d_malloc(sizeof(RASTER3D_Map));
    if (map == NULL) {
	Rast3d_error(_("Rast3d_open_cell_old_no_header: error in Rast3d_malloc"));
	return (void *)NULL;
    }

    G_unqualified_name(name, mapset, xname, xmapset);

    map->fileName = G_store(xname);
    map->mapset = G_store(xmapset);

    map->data_fd = G_open_old_misc(RASTER3D_DIRECTORY, RASTER3D_CELL_ELEMENT, xname, xmapset);
    if (map->data_fd < 0) {
	Rast3d_error(_("Rast3d_open_cell_old_no_header: error in G_open_old"));
	return (void *)NULL;
    }

    Rast3d_range_init(map);
    Rast3d_mask_off(map);

    return map;
}
Example #2
0
File: range.c Project: caomw/grass
/*!
 * \brief Read floating-point range
 *
 * Read the floating point range file <i>drange</i>. This file is
 * written in binary using XDR format.
 *
 * An empty range file indicates that the min, max are undefined. This
 * is a valid case, and the result should be an initialized range
 * struct with no defined min/max.  If the range file is missing and
 * the map is a floating-point map, this function will create a
 * default range by calling G_construct_default_range().
 *
 * \param name map name
 * \param mapset mapset name
 * \param drange pointer to FPRange structure which holds fp range
 *
 * \return 1 on success
 * \return 2 range is empty
 * \return -1 on error
 */
int Rast_read_fp_range(const char *name, const char *mapset,
		       struct FPRange *drange)
{
    struct Range range;
    int fd;
    char xdr_buf[2][XDR_DOUBLE_NBYTES];
    DCELL dcell1, dcell2;

    Rast_init();
    Rast_init_fp_range(drange);

    if (Rast_map_type(name, mapset) == CELL_TYPE) {
	/* if map is integer
	   read integer range and convert it to double */

	if (Rast_read_range(name, mapset, &range) >= 0) {
	    /* if the integer range is empty */
	    if (range.first_time)
		return 2;

	    Rast_update_fp_range((DCELL) range.min, drange);
	    Rast_update_fp_range((DCELL) range.max, drange);
	    return 1;
	}
	return -1;
    }

    fd = -1;

    if (G_find_file2_misc("cell_misc", "f_range", name, mapset)) {
	fd = G_open_old_misc("cell_misc", "f_range", name, mapset);
	if (fd < 0) {
	    G_warning(_("Unable to read fp range file for <%s>"),
		      G_fully_qualified_name(name, mapset));
	    return -1;
	}

	if (read(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
	    /* if the f_range file exists, but empty file, meaning Nulls */
	    close(fd);
	    G_debug(1, "Empty fp range file meaning Nulls for <%s>",
		      G_fully_qualified_name(name, mapset));
	    return 2;
	}

	G_xdr_get_double(&dcell1, xdr_buf[0]);
	G_xdr_get_double(&dcell2, xdr_buf[1]);

	Rast_update_fp_range(dcell1, drange);
	Rast_update_fp_range(dcell2, drange);
	close(fd);
    }

    return 1;
}