/*! * \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; }
static void cell_values_double(int fd, const unsigned char *data, const COLUMN_MAPPING * cmap, int nbytes, void *cell, int n) { struct fileinfo *fcb = &R__.fileinfo[fd]; const double *work_buf = (const double *) fcb->data; DCELL *c = cell; int i; for (i = 0; i < n; i++) { if (!cmap[i]) { c[i] = 0; continue; } G_xdr_get_double(&c[i], &work_buf[cmap[i]-1]); } }