GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
tilealloc.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include "raster3d_intern.h"
6 
7 /*---------------------------------------------------------------------------*/
8 
9 
10 /*!
11  * \brief
12  *
13  * Allocates a vector of <em>nofTiles</em> tiles with the same dimensions
14  * as the tiles of <em>map</em> and large enough to store cell-values of
15  * <em>type</em>.
16  *
17  * \param map
18  * \param nofTiles
19  * \param type
20  * \return void * : a pointer to the vector ... if successful,
21  * NULL ... otherwise.
22  */
23 
24 void *Rast3d_alloc_tiles_type(RASTER3D_Map * map, int nofTiles, int type)
25 {
26  void *tiles;
27 
28  tiles = Rast3d_malloc(map->tileSize * Rast3d_length(type) * nofTiles);
29  if (tiles == NULL) {
30  Rast3d_error("Rast3d_alloc_tiles_type: error in Rast3d_malloc");
31  return NULL;
32  }
33 
34  return tiles;
35 }
36 
37 /*---------------------------------------------------------------------------*/
38 
39 
40 /*!
41  * \brief
42  *
43  * Is equivalent to Rast3d_alloc_tiles_type (map, nofTiles, Rast3d_file_type_map (map)).
44  *
45  * \param map
46  * \param nofTiles
47  * \return void *
48  */
49 
50 void *Rast3d_alloc_tiles(RASTER3D_Map * map, int nofTiles)
51 {
52  void *tiles;
53 
54  tiles = Rast3d_alloc_tiles_type(map, nofTiles, map->typeIntern);
55  if (tiles == NULL) {
56  Rast3d_error("Rast3d_alloc_tiles: error in Rast3d_alloc_tiles_type");
57  return NULL;
58  }
59 
60  return tiles;
61 }
62 
63 /*---------------------------------------------------------------------------*/
64 
65 
66 /*!
67  * \brief
68  *
69  * Is equivalent to <tt>Rast3d_free (tiles);</tt>
70  *
71  * \param tiles
72  * \return void
73  */
74 
75 void Rast3d_free_tiles(void *tiles)
76 {
77  Rast3d_free(tiles);
78 }
void * Rast3d_alloc_tiles(RASTER3D_Map *map, int nofTiles)
Is equivalent to Rast3d_alloc_tiles_type (map, nofTiles, Rast3d_file_type_map (map)).
Definition: tilealloc.c:50
void * Rast3d_malloc(int)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.
int typeIntern
Definition: raster3d.h:149
void Rast3d_free_tiles(void *tiles)
Is equivalent to Rast3d_free (tiles);
Definition: tilealloc.c:75
#define NULL
Definition: ccmath.h:32
void Rast3d_error(const char *,...) __attribute__((format(printf
int tileSize
Definition: raster3d.h:179
void * Rast3d_alloc_tiles_type(RASTER3D_Map *map, int nofTiles, int type)
Allocates a vector of nofTiles tiles with the same dimensions as the tiles of map and large enough to...
Definition: tilealloc.c:24
int Rast3d_length(int)
Definition: raster3d/misc.c:78
void Rast3d_free(void *)
Same as free (ptr).