GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-847944e18e
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 
18 int Rast3d_put_float(RASTER3D_Map *map, int x, int y, int z, float value)
19 {
20  int tileIndex, offs;
21  float *tile;
22 
23  if (map->typeIntern == DCELL_TYPE)
24  return (Rast3d_put_double(map, x, y, z, (double)value));
25 
26  Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
27  tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
28  if (tile == NULL) {
29  Rast3d_error("Rast3d_put_float: error in Rast3d_get_tile_ptr");
30  return 0;
31  }
32 
33  tile[offs] = value;
34  return 1;
35 }
36 
37 /*---------------------------------------------------------------------------*/
38 
39 /*!
40  * \brief
41  *
42  * Is equivalent to Rast3d_put_value (map, x, y, z, &value, DCELL_TYPE).
43  *
44  * \param map
45  * \param x
46  * \param y
47  * \param z
48  * \param value
49  * \return 1 ... if successful,
50  * 0 ... otherwise.
51  */
52 
53 int Rast3d_put_double(RASTER3D_Map *map, int x, int y, int z, double value)
54 {
55  int tileIndex, offs;
56  double *tile;
57 
58  if (map->typeIntern == FCELL_TYPE)
59  return (Rast3d_put_float(map, x, y, z, (float)value));
60 
61  Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
62  tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
63  if (tile == NULL) {
64  Rast3d_error("Rast3d_put_double: error in Rast3d_get_tile_ptr");
65  return 0;
66  }
67 
68  tile[offs] = value;
69  return 1;
70 }
71 
72 /*---------------------------------------------------------------------------*/
73 
74 /*!
75  * \brief
76  *
77  * After converting <em>*value</em> of <em>type</em> into the type specified
78  * at the initialization time (i.e. <em>typeIntern</em>) this function writes
79  * the value into the tile buffer corresponding to cell-coordinate <em>(x, y,
80  * z)</em>.
81  *
82  * \param map
83  * \param x
84  * \param y
85  * \param z
86  * \param value
87  * \param type
88  * \return 1 ... if successful,
89  * 0 ... otherwise.
90  */
91 
92 int Rast3d_put_value(RASTER3D_Map *map, int x, int y, int z, const void *value,
93  int type)
94 {
95  if (type == FCELL_TYPE)
96  return (Rast3d_put_float(map, x, y, z, *((float *)value)));
97 
98  return (Rast3d_put_double(map, x, y, z, *((double *)value)));
99 }
#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:79
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:158
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:53
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:92
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:18
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13
int typeIntern
Definition: raster3d.h:150
#define x