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