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.
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include <grass/G3d.h>
8 /*---------------------------------------------------------------------------*/
24 void G3d_changeType(void *map, const char *nameOut)
25 {
26  void *map2;
27  int x, y, z, saveType;
28  void *data, *data2;
29  G3D_Region region;
30  int tileSize;
31  int tileX, tileY, tileZ, typeIntern, typeIntern2;
32  int tileXsave, tileYsave, tileZsave, nx, ny, nz;
34  saveType = G3d_getFileType();
35  G3d_setFileType(G3d_fileTypeMap(map) == FCELL_TYPE ?
37  G3d_getTileDimension(&tileXsave, &tileYsave, &tileZsave);
38  G3d_getTileDimensionsMap(map, &tileX, &tileY, &tileZ);
39  G3d_setTileDimension(tileX, tileY, tileZ);
41  G3d_getRegionStructMap(map, &region);
42  map2 =
43  G3d_openCellNew(nameOut, FCELL_TYPE, G3D_USE_CACHE_DEFAULT, &region);
45  if (map2 == NULL)
46  G3d_fatalError("G3d_changeType: error in G3d_openCellNew");
48  G3d_setFileType(saveType);
49  G3d_setTileDimension(tileXsave, tileYsave, tileZsave);
51  data = G3d_allocTiles(map, 1);
52  if (data == NULL)
53  G3d_fatalError("G3d_changeType: error in G3d_allocTiles");
54  data2 = G3d_allocTiles(map2, 1);
55  if (data2 == NULL)
56  G3d_fatalError("G3d_changeType: error in G3d_allocTiles");
58  G3d_getNofTilesMap(map2, &nx, &ny, &nz);
59  typeIntern = G3d_tileTypeMap(map);
60  typeIntern2 = G3d_tileTypeMap(map2);
61  tileSize = tileX * tileY * tileZ;
63  for (z = 0; z < nz; z++)
64  for (y = 0; y < ny; y++)
65  for (x = 0; x < nx; x++) {
66  if (!G3d_readTile(map, G3d_tile2tileIndex(map, x, y, z), data,
67  typeIntern))
68  G3d_fatalError("G3d_changeType: error in G3d_readTile");
69  G3d_copyValues(data, 0, typeIntern, data2, 0, typeIntern2,
70  tileSize);
71  if (!G3d_writeTile
72  (map2, G3d_tile2tileIndex(map2, x, y, z), data2,
73  typeIntern2))
74  G3d_fatalError("G3d_changeType: error in G3d_writeTile");
75  }
77  G3d_freeTiles(data);
78  G3d_freeTiles(data2);
79  if (!G3d_closeCell(map2))
80  G3d_fatalError("G3d_changeType: error in G3d_closeCell");
81 }
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_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
int y
Definition: plot.c:34
void G3d_setFileType(int type)
set G3d file type
Definition: g3ddefaults.c:223
void G3d_copyValues(const void *src, int offsSrc, int typeSrc, void *dst, int offsDst, int typeDst, int nElts)
Definition: g3dmisc.c:52
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
void G3d_changeType(void *map, const char *nameOut)
Makes a copy of map with name nameOut in which the cells are of type FCELL_TYPE if they are DCELL_TYP...
Definition: changetype.c:24
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_fileTypeMap(G3D_Map *map)
Returns the type with which tiles of map are stored on file.
Definition: headerinfo.c:178
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