GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 <grass/G3d.h>
7 /*---------------------------------------------------------------------------*/
23 void G3d_changePrecision(void *map, int precision, const char *nameOut)
24 {
25  void *map2;
26  int x, y, z, savePrecision, saveCompression, saveLzw, saveRle;
27  char *data;
28  G3D_Region region;
29  int typeIntern;
30  int nx, ny, nz;
31  int tileXsave, tileYsave, tileZsave, tileX, tileY, tileZ, saveType;
33  saveType = G3d_getFileType();
34  /* G3d_setFileType (G3d_fileTypeMap (map)); */
35  G3d_getCompressionMode(&saveCompression, &saveLzw, &saveRle,
36  &savePrecision);
37  G3d_setCompressionMode(G3D_COMPRESSION, saveLzw, saveRle, precision);
38  G3d_getTileDimension(&tileXsave, &tileYsave, &tileZsave);
39  G3d_getTileDimensionsMap(map, &tileX, &tileY, &tileZ);
40  G3d_setTileDimension(tileX, tileY, tileZ);
42  typeIntern = G3d_tileTypeMap(map);
43  G3d_getRegionStructMap(map, &region);
45  map2 =
46  G3d_openCellNew(nameOut, typeIntern, G3D_USE_CACHE_DEFAULT, &region);
47  if (map2 == NULL)
48  G3d_fatalError("G3d_changePrecision: error in G3d_openCellNew");
50  G3d_setFileType(saveType);
51  G3d_setCompressionMode(saveCompression, saveLzw, saveRle, savePrecision);
52  G3d_setTileDimension(tileXsave, tileYsave, tileZsave);
54  data = G3d_allocTiles(map, 1);
55  if (data == NULL)
56  G3d_fatalError("G3d_changePrecision: error in G3d_allocTiles");
57  G3d_getNofTilesMap(map2, &nx, &ny, &nz);
59  for (z = 0; z < nz; z++)
60  for (y = 0; y < ny; y++)
61  for (x = 0; x < nx; x++) {
62  if (!G3d_readTile(map, G3d_tile2tileIndex(map, x, y, z), data,
63  typeIntern))
65  ("G3d_changePrecision: error in G3d_readTile");
66  if (!G3d_writeTile
67  (map2, G3d_tile2tileIndex(map2, x, y, z), data,
68  typeIntern))
70  ("G3d_changePrecision: error in G3d_writeTile");
71  }
73  G3d_freeTiles(data);
74  if (!G3d_closeCell(map2))
75  G3d_fatalError("G3d_changePrecision: error in G3d_closeCell");
76 }
int G3d_writeTile(G3D_Map *map, int tileIndex, const void *tile, int type)
Writes tile with index tileIndex to the file corresponding to map. It is assumed that the cells in ti...
Definition: tilewrite.c:128
void G3d_changePrecision(void *map, int precision, const char *nameOut)
Makes a copy of map with name nameOut which is written with precision. The source code can be found i...
void G3d_getTileDimensionsMap(G3D_Map *map, int *x, int *y, int *z)
Returns the tile dimensions used for map.
Definition: headerinfo.c:142
void G3d_getRegionStructMap(G3D_Map *map, G3D_Region *region)
Returns in region the region of map.
Definition: headerinfo.c:115
void * G3d_allocTiles(G3D_Map *map, int nofTiles)
Is equivalent to G3d_allocTilesType (map, nofTiles, G3d_fileTypeMap (map)).
Definition: tilealloc.c:52
void G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle, int *precision)
Definition: g3ddefaults.c:125
void G3d_setCompressionMode(int doCompress, int doLzw, int doRle, int precision)
doCompress should be one of G3D_NO_COMPRESSION and G3D_COMPRESSION, doRle should be either G3D_NO_RLE...
Definition: g3ddefaults.c:85
int y
Definition: plot.c:34
void G3d_setFileType(int type)
set G3d file type
Definition: g3ddefaults.c:223
void G3d_getNofTilesMap(G3D_Map *map, int *nx, int *ny, int *nz)
Returns the dimensions of the tile-cube used to tile the region of map. These numbers include partial...
Definition: headerinfo.c:51
tuple data
void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
get Tile Dimension
Definition: g3ddefaults.c:291
int G3d_closeCell(G3D_Map *map)
Closes g3d-file. If map is new and cache-mode is used for map then every tile which is not flushed be...
Definition: g3dclose.c:144
return NULL
Definition: dbfopen.c:1394
void G3d_freeTiles(void *tiles)
Is equivalent to G3d_free (tiles);
Definition: tilealloc.c:77
void G3d_setTileDimension(int tileX, int tileY, int tileZ)
set Tile Dimension
Definition: g3ddefaults.c:262
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_tile2tileIndex(G3D_Map *map, int xTile, int yTile, int zTile)
Returns tile-index corresponding to tile-coordinates (xTile, yTile, zTile).
Definition: tilemath.c:52
int G3d_tileTypeMap(G3D_Map *map)
Returns the type in which tiles of map are stored in memory.
Definition: headerinfo.c:161
void G3d_fatalError(const char *,...)
This function prints the error message msg, and terminates the program with an error status...
Definition: g3derror.c:58
void * G3d_openCellNew(const char *name, int typeIntern, int cache, G3D_Region *region)
Opens new g3d-file with name in the current mapset. Tiles are stored in memory with type which must b...
Definition: g3dopen.c:213
int G3d_getFileType()
get G3d file type
Definition: g3ddefaults.c:243