7 #include <grass/glocale.h>
20 G3d_error(_(
"G3d_openCellOldNoHeader: error in G3d_maskOpenOld"));
26 G3d_error(_(
"G3d_openCellOldNoHeader: error in G3d_malloc"));
31 sprintf(buf,
"%s/%s", G3D_DIRECTORY, xname);
32 sprintf(buf2,
"%s@%s", G3D_CELL_ELEMENT, xmapset);
36 sprintf(buf,
"%s/%s", G3D_DIRECTORY, name);
37 sprintf(buf2,
"%s", G3D_CELL_ELEMENT);
44 if (map->data_fd < 0) {
45 G3d_error(_(
"G3d_openCellOldNoHeader: error in G_open_old"));
86 G3D_Region *
window,
int typeIntern,
int cache)
91 int rows,
cols, depths, precision;
92 double ew_res, ns_res, tb_res;
93 int nofHeaderBytes, dataOffset, useXdr, hasIndex;
95 double north, south, east, west, top, bottom;
99 G3d_error(_(
"G3d_openCellOld: error in G3d_openCellOldNoHeader"));
103 if (lseek(map->data_fd, (
long)0, SEEK_SET) == -1) {
104 G3d_error(_(
"G3d_openCellOld: can't rewind file"));
110 &north, &south, &east, &west, &top, &bottom,
111 &rows, &cols, &depths,
112 &ew_res, &ns_res, &tb_res,
113 &tileX, &tileY, &tileZ,
114 &type, &compression, &useRle, &useLzw,
115 &precision, &dataOffset, &useXdr, &hasIndex, &unit)) {
116 G3d_error(_(
"G3d_openCellOld: error in G3d_readHeader"));
120 if (window == G3D_DEFAULT_WINDOW)
123 if (proj != window->proj) {
124 G3d_error(_(
"G3d_openCellOld: projection does not match window projection"));
127 if (zone != window->zone) {
128 G3d_error(_(
"G3d_openCellOld: zone does not match window zone"));
132 map->useXdr = useXdr;
137 &(map->indexLongNbytes), 1)) ||
139 &(map->indexNbytesUsed), 1))) {
140 G3d_error(_(
"G3d_openCellOld: can't read header"));
145 if (map->indexNbytesUsed >
sizeof(
long))
146 G3d_fatalError(_(
"G3d_openCellOld: index does not fit into long"));
150 G3d_error(_(
"G3d_openCellOld: error in G3d_malloc"));
155 if (read(map->data_fd, ltmp, map->indexLongNbytes) !=
156 map->indexLongNbytes) {
157 G3d_error(_(
"G3d_openCellOld: can't read header"));
160 G3d_longDecode(ltmp, &(map->indexOffset), 1, map->indexLongNbytes);
164 nofHeaderBytes = dataOffset;
166 if (typeIntern == G3D_TILE_SAME_AS_FILE)
170 type, precision, cache,
171 hasIndex, map->useXdr, typeIntern,
172 nofHeaderBytes, tileX, tileY, tileZ,
174 north, south, east, west, top, bottom,
175 rows, cols, depths, ew_res, ns_res, tb_res, unit)) {
176 G3d_error(_(
"G3d_openCellOld: error in G3d_fillHeader"));
217 int nofHeaderBytes, dummy = 0,
compression, precision;
223 G3d_error(_(
"G3d_openCellNew: error in G3d_maskOpenOld"));
232 G3d_error(_(
"G3d_openCellNew: error in G3d_malloc"));
237 map->fileName =
G_store(xname);
243 map->data_fd = open(map->tempName, O_RDWR | O_CREAT | O_TRUNC, 0666);
244 if (map->data_fd < 0) {
245 G3d_error(_(
"G3d_openCellNew: could not open file"));
256 else if (precision < -1)
259 else if (precision > 52)
261 else if (precision < -1)
265 if ((typeIntern == FCELL_TYPE) && (
g3d_file_type == DCELL_TYPE)) {
269 precision =
G3D_MIN(precision, 23);
273 precision = G3D_MAX_PRECISION;
278 map->indexLongNbytes =
sizeof(long);
288 &(map->indexLongNbytes), 1)) ||
290 G3d_error(_(
"G3d_openCellNew: can't write header"));
293 if (write(map->data_fd, &ldummy, map->indexLongNbytes) !=
294 map->indexLongNbytes) {
295 G3d_error(_(
"G3d_openCellNew: can't write header"));
301 nofHeaderBytes = lseek(map->data_fd, (
long)0, SEEK_CUR);
309 map->useXdr, typeIntern, nofHeaderBytes,
312 region->proj, region->zone,
313 region->north, region->south, region->east,
314 region->west, region->top, region->bottom,
315 region->rows, region->cols, region->depths,
316 region->ew_res, region->ns_res, region->tb_res,
318 G3d_error(_(
"G3d_openCellNew: error in G3d_fillHeader"));
char * G_mapset(void)
current mapset name
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int g3d_do_rle_compression
int G3d_range_init(G3D_Map *map)
unsigned short compression
G3D_Region * G3d_windowPtr()
void G3d_maskOff(G3D_Map *map)
Turns off the mask for map. This is the default. Do not invoke this function after the first tile has...
char * G_store(const char *s)
Copy string to allocated memory.
void G3d_makeMapsetMapDirectory(const char *mapName)
void G3d_free(void *buf)
Same as free (ptr).
void G3d_error(const char *msg,...)
char * G_tempfile(void)
Returns a temporary file name.
void G3d_getNearestNeighborFunPtr(void(**nnFunPtr)())
Returns in nnFunPtr a pointer to G3d_nearestNeighbor () (cf.{g3d:G3d.nearestNeighbor}).
int G3d_writeInts(int fd, int useXdr, const int *i, int nofNum)
int g3d_tile_dimension[3]
int g3d_do_lzw_compression
void * G3d_openCellOldNoHeader(const char *name, const char *mapset)
int G_open_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
void * G3d_malloc(int nBytes)
Same as malloc (nBytes), except that in case of error G3d_error() is invoked.
void G3d_initDefaults(void)
Initializes the default values described in G3D Defaults. Applications have to use this function only...
void * G3d_openCellOld(const char *name, const char *mapset, G3D_Region *window, int typeIntern, int cache)
Opens existing g3d-file name in mapset. Tiles are stored in memory with type which must be any of FCE...
void G3d_adjustRegion(G3D_Region *region)
Computes an adjusts the resolutions in the region structure from the region boundaries and number of ...
void G3d_regionCopy(G3D_Region *regionDest, G3D_Region *regionSrc)
Copies the values of regionSrc into regionDst. (The unfortunate order of parameters was chosen in ord...
void G3d_longDecode(unsigned char *source, long *dst, int nofNums, int longNbytes)
void G3d_fatalError(const char *,...)
This function prints the error message msg, and terminates the program with an error status...
int G3d_readInts(int fd, int useXdr, int *i, int nofNum)
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...
int G__name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)