Example #1
0
int Rast3d_get_standard3d_params(int *useTypeDefault, int *type,
			    int *useCompressionDefault, int *doCompression,
			    int *usePrecisionDefault, int *precision,
			    int *useDimensionDefault, int *tileX, int *tileY,
			    int *tileZ)
{

    *useTypeDefault = *useCompressionDefault = 0;
    *usePrecisionDefault = *useDimensionDefault = 0;

    Rast3d_init_defaults();

    if (strcmp(param->type->answer, "double") == 0)
	*type = DCELL_TYPE;
    else if (strcmp(param->type->answer, "float") == 0)
	*type = FCELL_TYPE;
    else {
	*type = Rast3d_get_file_type();
	*useTypeDefault = 1;
    }

    Rast3d_get_compression_mode(doCompression, precision);

    if (strcmp(param->precision->answer, "default") != 0) {
	if (strcmp(param->precision->answer, "max") == 0)
	    *precision = -1;
	else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
		 (*precision < 0)) {
	    Rast3d_error(_("Rast3d_get_standard3d_params: precision value invalid"));
	    return 0;
	}
	}
	else
	*usePrecisionDefault = 1;


	if (strcmp(param->compression->answer, "default") != 0) {
 		if (strcmp(param->compression->answer, "zip") == 0)
			*doCompression = RASTER3D_COMPRESSION;
		else
			*doCompression = RASTER3D_NO_COMPRESSION;
	} else {
		*useCompressionDefault = 1;
	}

    Rast3d_get_tile_dimension(tileX, tileY, tileZ);
    if (strcmp(param->dimension->answer, "default") != 0) {
	if (sscanf(param->dimension->answer, "%dx%dx%d",
		   tileX, tileY, tileZ) != 3) {
	    Rast3d_error(_("Rast3d_get_standard3d_params: tile dimension value invalid"));
	    return 0;
	}
    }
    else
	*useDimensionDefault = 1;

    Rast3d_free(param);

    return 1;
}
Example #2
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 #3
0
void *Rast3d_get_tile_ptr(RASTER3D_Map * map, int tileIndex)
{
    void *ptr;

    if ((tileIndex >= map->nTiles) || (tileIndex < 0)) {
	Rast3d_error("Rast3d_get_tile_ptr: tileIndex out of range");
	return NULL;
    }

    if (map->useCache) {
	ptr = Rast3d_cache_elt_ptr(map->cache, tileIndex);
	if (ptr == NULL) {
	    Rast3d_error("Rast3d_get_tile_ptr: error in Rast3d_cache_elt_ptr");
	    return NULL;
	}
	return ptr;
    }

    if (map->currentIndex == tileIndex)
	return map->data;

    map->currentIndex = tileIndex;
    if (!Rast3d_read_tile(map, map->currentIndex, map->data, map->typeIntern)) {
	Rast3d_error("Rast3d_get_tile_ptr: error in Rast3d_read_tile");
	return NULL;
    }

    return map->data;
}
Example #4
0
static int cache_remove_elt(RASTER3D_cache * c, int name, int doFlush)
{
    int index;

    index = Rast3d_cache_hash_name2index(c->hash, name);
    if (index == -1) {
	Rast3d_error("Rast3d_cache_deactivate_elt : name not in cache");
	return 0;
    }

    if (IS_NOT_ACTIVE_ELT(index))
	return 1;

    if (IS_IN_QUEUE_ELT(index)) {
	cache_queue_dequeue(c, index);
	LOCK_ELT(index);
    }

    if (doFlush)
	if (!c->eltRemoveFun(name, c->elts + c->eltSize * index,
			     c->eltRemoveFunData)) {
	    Rast3d_error("cache_remove_elt: error in c->eltRemoveFun");
	    return 0;
	}

    cache_queue_preppend(c, index);
    DEACTIVATE_ELT(index);

    Rast3d_cache_hash_remove_name(c->hash, name);

    return 1;
}
Example #5
0
static int
Rast3d_tile2xdrTile(RASTER3D_Map * map, const void *tile, int rows, int cols,
		 int depths, int xRedundant, int yRedundant, int zRedundant,
		 int nofNum, int type)
{
    int y, z;

    if (!Rast3d_init_copy_to_xdr(map, type)) {
	Rast3d_error("Rast3d_tile2xdrTile: error in Rast3d_init_copy_to_xdr");
	return 0;
    }


    if (nofNum == map->tileSize) {
	if (!Rast3d_copy_to_xdr(tile, map->tileSize)) {
	    Rast3d_error("Rast3d_tile2xdrTile: error in Rast3d_copy_to_xdr");
	    return 0;
	}
	return 1;
    }

    if (xRedundant) {
	for (z = 0; z < depths; z++) {
	    for (y = 0; y < rows; y++) {
		if (!Rast3d_copy_to_xdr(tile, cols)) {
		    Rast3d_error("Rast3d_tile2xdrTile: error in Rast3d_copy_to_xdr");
		    return 0;
		}
		tile = G_incr_void_ptr(tile, map->tileX * Rast3d_length(type));
	    }
	    if (yRedundant)
		tile =
		    G_incr_void_ptr(tile,
				    map->tileX * yRedundant *
				    Rast3d_length(type));
	}
	return 1;
    }

    if (yRedundant) {
	for (z = 0; z < depths; z++) {
	    if (!Rast3d_copy_to_xdr(tile, map->tileX * rows)) {
		Rast3d_error("Rast3d_tile2xdrTile: error in Rast3d_copy_to_xdr");
		return 0;
	    }
	    tile = G_incr_void_ptr(tile, map->tileXY * Rast3d_length(type));
	}
	return 1;
    }

    if (!Rast3d_copy_to_xdr(tile, map->tileXY * depths)) {
	Rast3d_error("Rast3d_tile2xdrTile: error in Rast3d_copy_to_xdr");
	return 0;
    }
    return 1;
}
Example #6
0
int Rast3d_flush_index(RASTER3D_Map * map)
{
    int sizeCompressed, indexLength, tileIndex;
    unsigned char *tmp;
    long ldummy;

    if (!map->hasIndex)
	return 1;

    map->indexOffset = lseek(map->data_fd, (long)0, SEEK_END);
    if (map->indexOffset == -1) {
	Rast3d_error("Rast3d_flush_index: can't rewind file");
	return 0;
    }

    map->indexNbytesUsed = Rast3d_long_encode(&(map->indexOffset),
					  (unsigned char *)&ldummy, 1);

    tmp = Rast3d_malloc(sizeof(long) * map->nTiles);
    if (tmp == NULL) {
	Rast3d_error("Rast3d_flush_index: error in Rast3d_malloc");
	return 0;
    }

    for (tileIndex = 0; tileIndex < map->nTiles; tileIndex++)
	if (map->index[tileIndex] == -1)
	    map->index[tileIndex] = 0;

    (void)Rast3d_long_encode(map->index, tmp, map->nTiles);

    sizeCompressed = Rast3d_rle_count_only(tmp, sizeof(long) * map->nTiles, 1);

    if (sizeCompressed >= map->nTiles * sizeof(long)) {
	indexLength = map->nTiles * sizeof(long);
	if (write(map->data_fd, tmp, indexLength) != indexLength) {
	    Rast3d_error("Rast3d_flush_index: can't write file");
	    return 0;
	}
    }
    else {
	indexLength = sizeCompressed;
	Rast3d_rle_encode(tmp, (char *)map->index, sizeof(long) * map->nTiles, 1);
	if (write(map->data_fd, map->index, sizeCompressed) != sizeCompressed) {
	    Rast3d_error("Rast3d_flush_index: can't write file");
	    return 0;
	}
    }

    Rast3d_free(tmp);
    if (!Rast3d_readIndex(map)) {
	Rast3d_error("Rast3d_flush_index: error in Rast3d_readIndex");
	return 0;
    }

    return 1;
}
Example #7
0
int Rast3d_write_tile(RASTER3D_Map * map, int tileIndex, const void *tile, int type)
{
    int rows, cols, depths, xRedundant, yRedundant, zRedundant, nofNum;

    /* valid tileIndex ? */
    if ((tileIndex >= map->nTiles) || (tileIndex < 0))
	Rast3d_fatal_error("Rast3d_write_tile: tileIndex out of range");

    /* already written ? */
    if (map->index[tileIndex] != -1)
	return 2;

    /* save the file position */
    map->index[tileIndex] = lseek(map->data_fd, (long)0, SEEK_END);
    if (map->index[tileIndex] == -1) {
	Rast3d_error("Rast3d_write_tile: can't position file");
	return 0;
    }

    nofNum = Rast3d_compute_clipped_tile_dimensions(map, tileIndex,
					      &rows, &cols, &depths,
					      &xRedundant, &yRedundant,
					      &zRedundant);

    Rast3d_range_update_from_tile(map, tile, rows, cols, depths,
			     xRedundant, yRedundant, zRedundant, nofNum,
			     type);

    if (!Rast3d_tile2xdrTile(map, tile, rows, cols, depths,
			  xRedundant, yRedundant, zRedundant, nofNum, type)) {
	Rast3d_error("Rast3d_writeTileCompressed: error in Rast3d_tile2xdrTile");
	return 0;
    }

    if (map->compression == RASTER3D_NO_COMPRESSION) {
	if (!Rast3d_writeTileUncompressed(map, nofNum)) {
	    Rast3d_error("Rast3d_write_tile: error in Rast3d_writeTileUncompressed");
	    return 0;
	}
    }
    else if (!Rast3d_writeTileCompressed(map, nofNum)) {
	Rast3d_error("Rast3d_write_tile: error in Rast3d_writeTileCompressed");
	return 0;
    }

    /* compute the length */
    map->tileLength[tileIndex] = lseek(map->data_fd, (long)0, SEEK_END) -
	map->index[tileIndex];

    return 1;
}
Example #8
0
void *Rast3d_cache_new(int nofElts, int sizeOfElts, int nofNames,
		    int (*eltRemoveFun) (), void *eltRemoveFunData,
		    int (*eltLoadFun) (), void *eltLoadFunData)
{
    RASTER3D_cache *tmp;
    int i;

    tmp = Rast3d_malloc(sizeof(RASTER3D_cache));
    if (tmp == NULL) {
	Rast3d_error("Rast3d_cache_new: error in Rast3d_malloc");
	return (void *)NULL;
    }

    tmp->hash = NULL;

    tmp->nofElts = nofElts;
    tmp->eltSize = sizeOfElts;
    tmp->elts = Rast3d_malloc(tmp->eltSize * tmp->nofElts);
    tmp->names = Rast3d_malloc(sizeof(int) * tmp->nofElts);
    tmp->locks = Rast3d_malloc(tmp->nofElts);
    tmp->next = Rast3d_malloc(sizeof(int) * tmp->nofElts);
    tmp->prev = Rast3d_malloc(sizeof(int) * tmp->nofElts);

    if ((tmp->elts == NULL) || (tmp->names == NULL) || (tmp->locks == NULL) ||
	(tmp->next == NULL) || (tmp->prev == NULL)) {

	Rast3d_cache_dispose(tmp);
	Rast3d_error("Rast3d_cache_new: error in Rast3d_malloc");
	return (void *)NULL;
    }
    /* Init the cache lock */
    for(i = 0; i < tmp->nofElts; i++)
        tmp->locks[i] = 0;
        
    tmp->eltRemoveFun = eltRemoveFun;
    tmp->eltRemoveFunData = eltRemoveFunData;
    tmp->eltLoadFun = eltLoadFun;
    tmp->eltLoadFunData = eltLoadFunData;

    tmp->hash = Rast3d_cache_hash_new(nofNames);
    if (tmp->hash == NULL) {
	Rast3d_cache_dispose(tmp);
	Rast3d_error("Rast3d_cache_new: error in Rast3d_cache_hash_new");
	return (void *)NULL;
    }

    Rast3d_cache_reset(tmp);

    return tmp;
}
Example #9
0
int Rast3d_init_copy_from_xdr(RASTER3D_Map * map, int dType)
{
    xdrTmp = xdr;
    useXdr = map->useXdr;
    dstType = dType;

    if (useXdr == RASTER3D_USE_XDR) {
	if (!xdr_setpos(&(xdrDecodeStream), 0)) {
	    Rast3d_error("Rast3d_init_copy_from_xdr: positioning xdr failed");
	    return 0;
	}
	xdrs = &(xdrDecodeStream);
    }

    type = map->type;
    isFloat = (type == FCELL_TYPE);
    externLength = Rast3d_extern_length(type);
    eltLength = Rast3d_length(dstType);
    if (isFloat)
	xdrFun = xdr_float;
    else
	xdrFun = xdr_double;
    tmp = &tmpValue;

    return 1;
}
Example #10
0
void *Rast3d_cache_elt_ptr(RASTER3D_cache * c, int name)
{
    int index, oldName, doUnlock;

    index = Rast3d_cache_hash_name2index(c->hash, name);

    if (index != -1) {
	if (c->autoLock)
	    if (IS_UNLOCKED_ELT(index) && (!ONE_UNLOCKED_ELT_ONLY) &&
		(!ARE_MIN_UNLOCKED))
		Rast3d_cache_lock_intern(c, index);

	return c->elts + c->eltSize * index;
    }

    index = c->first;
    if (IS_ACTIVE_ELT(index)) {
	oldName = c->names[index];
	Rast3d_cache_hash_remove_name(c->hash, oldName);
	if (!c->eltRemoveFun(oldName, c->elts + c->eltSize * index,
			     c->eltRemoveFunData)) {
	    Rast3d_error("Rast3d_cache_elt_ptr: error in c->eltRemoveFun");
	    return NULL;
	}
    }

    Rast3d_cache_hash_load_name(c->hash, name, index);

    doUnlock = ((!c->autoLock) || ONE_UNLOCKED_ELT_ONLY || ARE_MIN_UNLOCKED);

    UNLOCK_ELT(index);
    c->names[index] = name;
    Rast3d_cache_lock_intern(c, index);

    if (doUnlock)
	if (!Rast3d_cache_unlock(c, name)) {
	    Rast3d_error("Rast3d_cache_elt_ptr: error in Rast3d_cache_unlock");
	    return NULL;
	}

    if (!c->eltLoadFun(name, c->elts + c->eltSize * index, c->eltLoadFunData)) {
	Rast3d_error("Rast3d_cache_elt_ptr: error in c->eltLoadFun");
	return NULL;
    }

    return c->elts + c->eltSize * index;
}
Example #11
0
int Rast3d_init_fp_xdr(RASTER3D_Map * map, int misuseBytes)



 /* nof addtl bytes allocated for the xdr array so that */
		      /* the array can also be (mis)used for other purposes */
{
    int doAlloc;

    doAlloc = 0;

    if (xdr == NULL) {
	xdrLength = map->tileSize * RASTER3D_MAX(map->numLengthExtern,
					    map->numLengthIntern) +
	    misuseBytes;
	xdr = Rast3d_malloc(xdrLength);
	if (xdr == NULL) {
	    Rast3d_error("Rast3d_init_fp_xdr: error in Rast3d_malloc");
	    return 0;
	}

	doAlloc = 1;
    }
    else if (map->tileSize * RASTER3D_MAX(map->numLengthExtern,
				     map->numLengthIntern) + misuseBytes
	     > xdrLength) {
	xdrLength = map->tileSize * RASTER3D_MAX(map->numLengthExtern,
					    map->numLengthIntern) +
	    misuseBytes;
	xdr = Rast3d_realloc(xdr, xdrLength);
	if (xdr == NULL) {
	    Rast3d_error("Rast3d_init_fp_xdr: error in Rast3d_realloc");
	    return 0;
	}

	doAlloc = 1;
    }

    if (doAlloc) {
	xdrmem_create(&(xdrEncodeStream), xdr, (u_int) xdrLength, XDR_ENCODE);
	xdrmem_create(&(xdrDecodeStream), xdr, (u_int) xdrLength, XDR_DECODE);
    }

    return 1;
}
Example #12
0
int Rast3d_cache_flush(RASTER3D_cache * c, int name)
{
    if (!cache_remove_elt(c, name, 1)) {
	Rast3d_error("Rast3d_cache_flush: error in cache_remove_elt");
	return 0;
    }

    return 1;
}
Example #13
0
int Rast3d_cache_load(RASTER3D_cache * c, int name)
{
    if (Rast3d_cache_elt_ptr(c, name) == NULL) {
	Rast3d_error("Rast3d_cache_load: error in Rast3d_cache_elt_ptr");
	return 0;
    }

    return 1;
}
Example #14
0
int Rast3d_tile_load(RASTER3D_Map * map, int tileIndex)
{
    if (Rast3d_get_tile_ptr(map, tileIndex) == NULL) {
	Rast3d_error("Rast3d_tile_load: error in Rast3d_get_tile_ptr");
	return 0;
    }

    return 1;
}
Example #15
0
int Rast3d_write_tile_double(RASTER3D_Map * map, int tileIndex, const void *tile)
{
    int status;

    if ((status = Rast3d_write_tile(map, tileIndex, tile, DCELL_TYPE)))
	return status;

    Rast3d_error("Rast3d_write_tile_double: error in Rast3d_write_tile");
    return 0;
}
Example #16
0
int Rast3d_copy_from_xdr(int nofNum, void *dst)
{
    int i;

    if (useXdr == RASTER3D_NO_XDR) {
	Rast3d_copy_values(xdrTmp, 0, type, dst, 0, dstType, nofNum);
	xdrTmp = G_incr_void_ptr(xdrTmp, nofNum * Rast3d_extern_length(type));
	return 1;
    }

    for (i = 0; i < nofNum; i++, dst = G_incr_void_ptr(dst, eltLength)) {

	if (Rast3d_is_xdr_null_num(xdrTmp, isFloat)) {
	    Rast3d_set_null_value(dst, 1, dstType);
	    if (!xdr_setpos(xdrs, xdr_getpos(xdrs) + externLength)) {
		Rast3d_error("Rast3d_copy_from_xdr: positioning xdr failed");
		return 0;
	    }
	}
	else {
	    if (type == dstType) {
		if (xdrFun(xdrs, dst) < 0) {
		    Rast3d_error("Rast3d_copy_from_xdr: reading xdr failed");
		    return 0;
		}
	    }
	    else {
		if (xdrFun(xdrs, tmp) < 0) {
		    Rast3d_error("Rast3d_copy_from_xdr: reading xdr failed");
		    return 0;
		}
		if (type == FCELL_TYPE)
		    *((double *)dst) = (double)*((float *)tmp);
		else
		    *((float *)dst) = (float)*((double *)tmp);
	    }
	}

	xdrTmp = G_incr_void_ptr(xdrTmp, externLength);
    }

    return 1;
}
Example #17
0
int Rast3d_copy_to_xdr(const void *src, int nofNum)
{
    int i;

    if (useXdr == RASTER3D_NO_XDR) {
	Rast3d_copy_values(src, 0, srcType, xdrTmp, 0, type, nofNum);
	xdrTmp = G_incr_void_ptr(xdrTmp, nofNum * Rast3d_extern_length(type));
	return 1;
    }

    for (i = 0; i < nofNum; i++, src = G_incr_void_ptr(src, eltLength)) {

	if (Rast3d_is_null_value_num(src, srcType)) {
	    Rast3d_set_xdr_null_num(xdrTmp, isFloat);
	    if (!xdr_setpos(xdrs, xdr_getpos(xdrs) + externLength)) {
		Rast3d_error("Rast3d_copy_to_xdr: positioning xdr failed");
		return 0;
	    }
	}
	else {
	    if (type == srcType) {
		if (xdrFun(xdrs, src) < 0) {
		    Rast3d_error("Rast3d_copy_to_xdr: writing xdr failed");
		    return 0;
		}
	    }
	    else {
		if (type == FCELL_TYPE)
		    *((float *)tmp) = (float)*((double *)src);
		else
		    *((double *)tmp) = (double)*((float *)src);
		if (xdrFun(xdrs, tmp) < 0) {
		    Rast3d_error("Rast3d_copy_to_xdr: writing xdr failed");
		    return 0;
		}
	    }
	}

	xdrTmp = G_incr_void_ptr(xdrTmp, externLength);
    }

    return 1;
}
Example #18
0
static int Rast3d_writeTileUncompressed(RASTER3D_Map * map, int nofNum)
{
    if (write(map->data_fd, xdr, map->numLengthExtern * nofNum) !=
	map->numLengthExtern * nofNum) {
	Rast3d_error("Rast3d_writeTileUncompressed: can't write file.");
	return 0;
    }

    return 1;
}
Example #19
0
int Rast3d_read_window(RASTER3D_Region * window, const char *windowName)
{
    struct Cell_head win;
    struct Key_Value *windowKeys;
    char path[GPATH_MAX];


    if (windowName == NULL) {
	G_get_window(&win);

	window->proj = win.proj;
	window->zone = win.zone;
	window->north = win.north;
	window->south = win.south;
	window->east = win.east;
	window->west = win.west;
	window->top = win.top;
	window->bottom = win.bottom;
	window->rows = win.rows3;
	window->cols = win.cols3;
	window->depths = win.depths;
	window->ns_res = win.ns_res3;
	window->ew_res = win.ew_res3;
	window->tb_res = win.tb_res;
    }
    else {
	Rast3d_getFullWindowPath(path, windowName);

	if (access(path, R_OK) != 0) {
	    G_warning("Rast3d_read_window: unable to find [%s].", path);
	    return 0;
	}

	windowKeys = G_read_key_value_file(path);

	if (!Rast3d_readWriteWindow(windowKeys, 1,
				 &(window->proj), &(window->zone),
				 &(window->north), &(window->south),
				 &(window->east), &(window->west),
				 &(window->top), &(window->bottom),
				 &(window->rows), &(window->cols),
				 &(window->depths), &(window->ew_res),
				 &(window->ns_res), &(window->tb_res))) {
	    Rast3d_error
		("Rast3d_read_window: error extracting window key(s) of file %s",
		 path);
	    return 0;
	}

	G_free_key_value(windowKeys);
    }

    return 1;
}
Example #20
0
void *Rast3d_alloc_tiles(RASTER3D_Map * map, int nofTiles)
{
    void *tiles;

    tiles = Rast3d_alloc_tiles_type(map, nofTiles, map->typeIntern);
    if (tiles == NULL) {
	Rast3d_error("Rast3d_alloc_tiles: error in Rast3d_alloc_tiles_type");
	return NULL;
    }

    return tiles;
}
Example #21
0
void *Rast3d_alloc_tiles_type(RASTER3D_Map * map, int nofTiles, int type)
{
    void *tiles;

    tiles = Rast3d_malloc(map->tileSize * Rast3d_length(type) * nofTiles);
    if (tiles == NULL) {
	Rast3d_error("Rast3d_alloc_tiles_type: error in Rast3d_malloc");
	return NULL;
    }

    return tiles;
}
Example #22
0
int Rast3d__remove_tile(RASTER3D_Map * map, int tileIndex)
{
    if (!map->useCache)
	return 1;

    if (!Rast3d_cache_remove_elt(map->cache, tileIndex)) {
	Rast3d_error("Rast3d_removeTile: error in Rast3d_cache_remove_elt");
	return 0;
    }

    return 1;
}
Example #23
0
static int Rast3d_writeTileCompressed(RASTER3D_Map * map, int nofNum)
{
    if (!Rast3d_fpcompress_write_xdr_nums(map->data_fd, xdr, nofNum, map->precision,
				   tmpCompress, map->type == FCELL_TYPE,
				   map->useRle, map->useLzw)) {
	Rast3d_error
	    ("Rast3d_writeTileCompressed: error in Rast3d_fpcompress_write_xdr_nums");
	return 0;
    }

    return 1;
}
Example #24
0
int Rast3d_write_ints(int fd, int useXdr, const int *i, int nofNum)
{
    char xdrIntBuf[RASTER3D_XDR_INT_LENGTH * 1024];
    unsigned int n;

    if (nofNum <= 0)
	Rast3d_fatal_error("Rast3d_write_ints: nofNum out of range");

    if (useXdr == RASTER3D_NO_XDR) {
	if (write(fd, i, sizeof(int) * nofNum) != sizeof(int) * nofNum) {
	    Rast3d_error("Rast3d_write_ints: writing to file failed");
	    return 0;
	}
	else {
	    return 1;
	}
    }

    do {
	int j;
	n = nofNum % 1024;
	if (n == 0)
	    n = 1024;

	for (j = 0; j < n; j++)
	    G_xdr_put_int(&xdrIntBuf[RASTER3D_XDR_INT_LENGTH * j], i);

	if (write(fd, xdrIntBuf, RASTER3D_XDR_INT_LENGTH * n) !=
	    RASTER3D_XDR_INT_LENGTH * n) {
	    Rast3d_error("Rast3d_write_ints: writing xdr to file failed");
	    return 0;
	}

	nofNum -= n;
	i += n;
    } while (nofNum);

    return 1;
}
Example #25
0
int Rast3d_flush_tile(RASTER3D_Map * map, int tileIndex)
{
    const void *tile;

    tile = Rast3d_get_tile_ptr(map, tileIndex);
    if (tile == NULL) {
	Rast3d_error("Rast3d_flush_tile: error in Rast3d_get_tile_ptr");
	return 0;
    }

    if (!Rast3d_write_tile(map, tileIndex, tile, map->typeIntern)) {
	Rast3d_error("Rast3d_flush_tile: error in Rast3d_write_tile");
	return 0;
    }

    if (!Rast3d__remove_tile(map, tileIndex)) {
	Rast3d_error("Rast3d_flush_tile: error in Rast3d__remove_tile");
	return 0;
    }

    return 1;
}
Example #26
0
int Rast3d_read_ints(int fd, int useXdr, int *i, int nofNum)
{
    char xdrIntBuf[RASTER3D_XDR_INT_LENGTH * 1024];
    unsigned int n;

    if (nofNum <= 0)
	Rast3d_fatal_error("Rast3d_read_ints: nofNum out of range");

    if (useXdr == RASTER3D_NO_XDR) {
	if (read(fd, i, sizeof(int) * nofNum) != sizeof(int) * nofNum) {
	    Rast3d_error("Rast3d_read_ints: reading from file failed");
	    return 0;
	}
	else {
	    return 1;
	}
    }

    do {
	int j;
	n = nofNum % 1024;
	if (n == 0)
	    n = 1024;

	if (read(fd, xdrIntBuf, RASTER3D_XDR_INT_LENGTH * n) !=
	    RASTER3D_XDR_INT_LENGTH * n) {
	    Rast3d_error("Rast3d_read_ints: reading xdr from file failed");
	    return 0;
	}

	for (j = 0; j < n; j++)
	    G_xdr_get_int(i, &xdrIntBuf[RASTER3D_XDR_INT_LENGTH * j]);

	nofNum -= n;
	i += n;
    } while (nofNum);

    return 1;
}
Example #27
0
int Rast3d_cache_flush_all(RASTER3D_cache * c)
{
    int index;

    for (index = 0; index < c->nofElts; index++)
	if (IS_ACTIVE_ELT(index))
	    if (!Rast3d_cache_flush(c, c->names[index])) {
		Rast3d_error("Rast3d_cache_flush_all: error in Rast3d_cache_flush");
		return 0;
	    }

    return 1;
}
Example #28
0
int Rast3d_cache_unlock_all(RASTER3D_cache * c)
{
    int index;

    for (index = 0; index < c->nofElts; index++)
	if (IS_LOCKED_ELT(index))
	    if (!Rast3d_cache_unlock(c, c->names[index])) {
		Rast3d_error("Rast3d_cache_unlock_all: error in Rast3d_cache_unlock");
		return 0;
	    }

    return 1;
}
Example #29
0
int Rast3d_cache_put_elt(RASTER3D_cache * c, int name, const void *src)
{
    void *elt;

    elt = Rast3d_cache_elt_ptr(c, name);
    if (elt == NULL) {
	Rast3d_error("Rast3d_cache_put_elt: error in Rast3d_cache_elt_ptr");
	return 0;
    }

    memcpy(elt, src, c->eltSize);

    return 1;
}
Example #30
0
int Rast3d_cache_get_elt(RASTER3D_cache * c, int name, void *dst)
{
    const void *elt;

    elt = Rast3d_cache_elt_ptr(c, name);
    if (elt == NULL) {
	Rast3d_error("Rast3d_cache_get_elt: error in Rast3d_cache_elt_ptr");
	return 0;
    }

    memcpy(dst, elt, c->eltSize);

    return 1;
}