GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
putvalue.c
Go to the documentation of this file.
1 #include <grass/raster.h>
2 #include "raster3d_intern.h"
3 
4 /*!
5  * \brief
6  *
7  * Is equivalent to Rast3d_put_value (map, x, y, z, &value, FCELL_TYPE).
8  *
9  * \param map
10  * \param x
11  * \param y
12  * \param z
13  * \param value
14  * \return 1 ... if successful,
15  * 0 ... otherwise.
16  */
17 int Rast3d_put_float(RASTER3D_Map *map, int x, int y, int z, float value)
18 {
19  int tileIndex, offs;
20  float *tile;
21 
22  if (map->typeIntern == DCELL_TYPE)
23  return (Rast3d_put_double(map, x, y, z, (double)value));
24 
25  Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
26  tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
27  if (tile == NULL) {
28  Rast3d_error("Rast3d_put_float: error in Rast3d_get_tile_ptr");
29  return 0;
30  }
31 
32  tile[offs] = value;
33  return 1;
34 }
35 
36 /*---------------------------------------------------------------------------*/
37 
38 /*!
39  * \brief
40  *
41  * Is equivalent to Rast3d_put_value (map, x, y, z, &value, DCELL_TYPE).
42  *
43  * \param map
44  * \param x
45  * \param y
46  * \param z
47  * \param value
48  * \return 1 ... if successful,
49  * 0 ... otherwise.
50  */
51 int Rast3d_put_double(RASTER3D_Map *map, int x, int y, int z, double value)
52 {
53  int tileIndex, offs;
54  double *tile;
55 
56  if (map->typeIntern == FCELL_TYPE)
57  return (Rast3d_put_float(map, x, y, z, (float)value));
58 
59  Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
60  tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
61  if (tile == NULL) {
62  Rast3d_error("Rast3d_put_double: error in Rast3d_get_tile_ptr");
63  return 0;
64  }
65 
66  tile[offs] = value;
67  return 1;
68 }
69 
70 /*---------------------------------------------------------------------------*/
71 
72 /*!
73  * \brief
74  *
75  * After converting <em>*value</em> of <em>type</em> into the type specified
76  * at the initialization time (i.e. <em>typeIntern</em>) this function writes
77  * the value into the tile buffer corresponding to cell-coordinate <em>(x, y,
78  * z)</em>.
79  *
80  * \param map
81  * \param x
82  * \param y
83  * \param z
84  * \param value
85  * \param type
86  * \return 1 ... if successful,
87  * 0 ... otherwise.
88  */
89 int Rast3d_put_value(RASTER3D_Map *map, int x, int y, int z, const void *value,
90  int type)
91 {
92  if (type == FCELL_TYPE)
93  return (Rast3d_put_float(map, x, y, z, *((float *)value)));
94 
95  return (Rast3d_put_double(map, x, y, z, *((double *)value)));
96 }
#define NULL
Definition: ccmath.h:32
void * Rast3d_get_tile_ptr(RASTER3D_Map *, int)
This function returns a pointer to a tile which contains the data for the tile with index tileIndex....
Definition: tileio.c:78
void Rast3d_error(const char *,...) __attribute__((format(printf
void Rast3d_coord2tile_index(RASTER3D_Map *, int, int, int, int *, int *)
Converts cell-coordinates (x, y, z) into tileIndex and the offset of the cell within the tile.
Definition: tilemath.c:152
int Rast3d_put_double(RASTER3D_Map *map, int x, int y, int z, double value)
Is equivalent to Rast3d_put_value (map, x, y, z, &value, DCELL_TYPE).
Definition: putvalue.c:51
int Rast3d_put_value(RASTER3D_Map *map, int x, int y, int z, const void *value, int type)
After converting *value of type into the type specified at the initialization time (i....
Definition: putvalue.c:89
int Rast3d_put_float(RASTER3D_Map *map, int x, int y, int z, float value)
Is equivalent to Rast3d_put_value (map, x, y, z, &value, FCELL_TYPE).
Definition: putvalue.c:17
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
int typeIntern
Definition: raster3d.h:150
#define x