GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tileio.c
Go to the documentation of this file.
1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include "G3d_intern.h"
7 
8 /*---------------------------------------------------------------------------*/
9 
10 /*---------------------------------------------------------------------------*/
11 
12  /* EXPORTED FUNCTIONS */
13 
14 /*---------------------------------------------------------------------------*/
15 
16 /*---------------------------------------------------------------------------*/
17 
18 
71 void *G3d_getTilePtr(G3D_Map * map, int tileIndex)
72 {
73  void *ptr;
74 
75  if ((tileIndex >= map->nTiles) || (tileIndex < 0)) {
76  G3d_error("G3d_getTilePtr: tileIndex out of range");
77  return NULL;
78  }
79 
80  if (map->useCache) {
81  ptr = G3d_cache_elt_ptr(map->cache, tileIndex);
82  if (ptr == NULL) {
83  G3d_error("G3d_getTilePtr: error in G3d_cache_elt_ptr");
84  return NULL;
85  }
86  return ptr;
87  }
88 
89  if (map->currentIndex == tileIndex)
90  return map->data;
91 
92  map->currentIndex = tileIndex;
93  if (!G3d_readTile(map, map->currentIndex, map->data, map->typeIntern)) {
94  G3d_error("G3d_getTilePtr: error in G3d_readTile");
95  return NULL;
96  }
97 
98  return map->data;
99 }
100 
101 /*---------------------------------------------------------------------------*/
102 
103 
115 int G3d_tileLoad(G3D_Map * map, int tileIndex)
116 {
117  if (G3d_getTilePtr(map, tileIndex) == NULL) {
118  G3d_error("G3d_tileLoad: error in G3d_getTilePtr");
119  return 0;
120  }
121 
122  return 1;
123 }
124 
125 /*---------------------------------------------------------------------------*/
126 
127 int G3d__removeTile(G3D_Map * map, int tileIndex)
128 {
129  if (!map->useCache)
130  return 1;
131 
132  if (!G3d_cache_remove_elt(map->cache, tileIndex)) {
133  G3d_error("G3d_removeTile: error in G3d_cache_remove_elt");
134  return 0;
135  }
136 
137  return 1;
138 }
139 
140 /*---------------------------------------------------------------------------*/
141 
142 
156 double G3d_getDoubleRegion();
157 
158 
172 float G3d_getFloatRegion(G3D_Map * map, int x, int y, int z)
173 {
174  int tileIndex, offs;
175  float *tile;
176 
177  if (map->typeIntern == DCELL_TYPE)
178  return (float)G3d_getDoubleRegion(map, x, y, z);
179 
180  G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
181  tile = (float *)G3d_getTilePtr(map, tileIndex);
182 
183  if (tile == NULL)
184  G3d_fatalError("G3d_getFloatRegion: error in G3d_getTilePtr");
185 
186  return tile[offs];
187 }
188 
189 /*---------------------------------------------------------------------------*/
190 
191 
205 double G3d_getDoubleRegion(G3D_Map * map, int x, int y, int z)
206 {
207  int tileIndex, offs;
208  double *tile;
209 
210  if (map->typeIntern == FCELL_TYPE)
211  return (double)G3d_getFloatRegion(map, x, y, z);
212 
213  G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs);
214  tile = (double *)G3d_getTilePtr(map, tileIndex);
215 
216  if (tile == NULL)
217  G3d_fatalError("G3d_getDoubleRegion: error in G3d_getTilePtr");
218 
219  return tile[offs];
220 }
221 
222 /*---------------------------------------------------------------------------*/
223 
224 
243 void
244 G3d_getValueRegion(G3D_Map * map, int x, int y, int z, void *value, int type)
245 {
246  if (type == FCELL_TYPE) {
247  *((float *)value) = G3d_getFloatRegion(map, x, y, z);
248  return;
249  }
250 
251  *((double *)value) = G3d_getDoubleRegion(map, x, y, z);
252 }
int G3d__removeTile(G3D_Map *map, int tileIndex)
Definition: tileio.c:127
int G3d_tileLoad(G3D_Map *map, int tileIndex)
Same functionality as G3d_getTilePtr() but does not return the pointer.
Definition: tileio.c:115
void G3d_getValueRegion(G3D_Map *map, int x, int y, int z, void *value, int type)
Returns in *value the cell-value of the cell with region-coordinate (x, y, z). The value returned is ...
Definition: tileio.c:244
void G3d_error(const char *msg,...)
Definition: g3derror.c:75
int y
Definition: plot.c:34
void * G3d_getTilePtr(G3D_Map *map, int tileIndex)
This function returns a pointer to a tile which contains the data for the tile with index tileIndex...
Definition: tileio.c:71
char * value
Definition: env.c:30
double G3d_getDoubleRegion()
Is equivalent to G3d_getValueRegion (map, x, y, z, &amp;value, DCELL_TYPE); return value.
return NULL
Definition: dbfopen.c:1394
void * G3d_cache_elt_ptr(G3D_cache *c, int name)
Definition: cache.c:466
int G3d_readTile(G3D_Map *map, int tileIndex, void *tile, int type)
Reads tile with index tileIndex into the tile buffer. The cells are stored with type type which must ...
Definition: tileread.c:145
int G3d_cache_remove_elt(G3D_cache *c, int name)
Definition: cache.c:409
void G3d_coord2tileIndex(G3D_Map *map, int x, int y, int z, int *tileIndex, int *offset)
Converts cell-coordinates (x, y, z) into tileIndex and the offset of the cell within the tile...
Definition: tilemath.c:167
void G3d_fatalError(const char *,...)
This function prints the error message msg, and terminates the program with an error status...
Definition: g3derror.c:58
float G3d_getFloatRegion(G3D_Map *map, int x, int y, int z)
Is equivalent to G3d_getValueRegion (map, x, y, z, &amp;value, FCELL_TYPE); return value.
Definition: tileio.c:172