GRASS 8 Programmer's Manual 8.6.0dev(2026)-5a31d549cc
Loading...
Searching...
No Matches
raster3d/range.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
6#include <grass/gis.h>
7#include <grass/raster.h>
8#include <grass/glocale.h>
9
10#include "raster3d_intern.h"
11
12/*---------------------------------------------------------------------------*/
13
15 int rows, int cols, int depths,
16 int xRedundant, int yRedundant,
17 int zRedundant G_UNUSED, int nofNum,
18 int type)
19{
20 int y, z, cellType;
21 struct FPRange *range;
22
23 range = &(map->range);
25
26 if (nofNum == map->tileSize) {
28 return;
29 }
30
31 if (xRedundant) {
32 for (z = 0; z < depths; z++) {
33 for (y = 0; y < rows; y++) {
36 }
37 if (yRedundant)
39 Rast3d_length(type));
40 }
41 return;
42 }
43
44 if (yRedundant) {
45 for (z = 0; z < depths; z++) {
46 Rast_row_update_fp_range(tile, map->tileX * rows, range, cellType);
48 }
49 return;
50 }
51
52 Rast_row_update_fp_range(tile, map->tileXY * depths, range, cellType);
53}
54
55/*---------------------------------------------------------------------------*/
56
57int Rast3d_read_range(const char *name, const char *mapset,
58 struct FPRange *drange)
59/* adapted from Rast_read_fp_range */
60{
61 int fd;
62 int bytes_read;
65
67
68 fd = -1;
69
71 mapset);
72 if (fd < 0) {
73 G_warning(_("Unable to open range file for [%s in %s]"), name, mapset);
74 return -1;
75 }
76
78
79 /* if the f_range file exists, but empty the range is NULL -> a NULL map */
80 if (bytes_read == 0) {
81 close(fd);
82 return 1;
83 }
84
86 close(fd);
87 G_warning(_("Error reading range file for [%s in %s]"), name, mapset);
88 return 2;
89 }
90
93
96 close(fd);
97 return 1;
98}
99
100/*---------------------------------------------------------------------------*/
101
102/*!
103 * \brief Loads the range into the range structure of <em>map</em>.
104 *
105 * \param map a pointer to a raster 3D map object
106 * \return 1 ... if successful
107 * 0 ... otherwise.
108 */
110{
111 if (map->operation == RASTER3D_WRITE_DATA)
112 return 1;
113 if (Rast3d_read_range(map->fileName, map->mapset, &(map->range)) == -1) {
114 return 0;
115 }
116
117 return 1;
118}
119
120/*---------------------------------------------------------------------------*/
121
122/*!
123 * \brief Returns in <em>min</em> and <em>max</em> the minimum and maximum
124 * values of the range.
125 *
126 * \param map a pointer to a raster 3D map object
127 * \param min a pointer to a double to store minumim
128 * \param max a pointer to a double to store maximum
129 */
130void Rast3d_range_min_max(RASTER3D_Map *map, double *min, double *max)
131{
133}
134
135/*-------------------------------------------------------------------------*/
136
137static int writeRange(const char *name, struct FPRange *range)
138/* adapted from Rast_write_fp_range */
139{
141 int fd;
142
144 if (fd < 0) {
145 G_warning(_("Unable to open range file for <%s>"), name);
146 return -1;
147 }
148
149 if (range->first_time) {
150 /* if range hasn't been updated, write empty file meaning NULLs */
151 close(fd);
152 return 0;
153 }
154
157
160 goto error;
161
162 close(fd);
163 return 0;
164
165error:
166 close(fd);
168 name); /* remove the old file with this name */
169 G_warning("can't write range file for [%s in %s]", name, G_mapset());
170 return -1;
171}
172
173/*---------------------------------------------------------------------------*/
174
175/*!
176 * \brief
177 *
178 * Writes the range which is stored in the range structure of <em>map</em>.
179 * (This function is invoked automatically when a new file is closed).
180 *
181 * \param map
182 * \return 1 ... if successful
183 * 0 ... otherwise.
184 */
186{
187 char path[GPATH_MAX];
188
190 remove(path);
191
192 if (writeRange(map->fileName, &(map->range)) == -1) {
193 Rast3d_error("Rast3d_closeCellNew: error in writeRange");
194 return 0;
195 }
196
197 return 1;
198}
199
200/*---------------------------------------------------------------------------*/
201
203{
204 Rast_init_fp_range(&(map->range));
205 return 0;
206}
void G_warning(const char *,...) __attribute__((format(printf
int G_open_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
Definition open_misc.c:132
int G_remove_misc(const char *, const char *, const char *)
Remove a database misc file.
Definition remove.c:64
void G_xdr_put_double(void *, const double *)
Definition gis/xdr.c:94
void G_xdr_get_double(double *, const void *)
Definition gis/xdr.c:89
#define G_incr_void_ptr(ptr, size)
Definition defs/gis.h:81
int G_open_new_misc(const char *, const char *, const char *)
open a new database misc file
Definition open_misc.c:111
const char * G_mapset(void)
Get current mapset name.
Definition gis/mapset.c:33
int Rast3d_g3d_type2cell_type(int)
void Rast3d_filename(char *, const char *, const char *, const char *)
Definition filename.c:9
int Rast3d_length(int)
void Rast3d_error(const char *,...) __attribute__((format(printf
void Rast_get_fp_range_min_max(const struct FPRange *, DCELL *, DCELL *)
Get minimum and maximum value from fp range.
void Rast_init_fp_range(struct FPRange *)
Initialize fp range.
void Rast_row_update_fp_range(const void *, int, struct FPRange *, RASTER_MAP_TYPE)
Update range structure based on raster row (floating-point)
void Rast_update_fp_range(DCELL, struct FPRange *)
Update range structure (floating-point)
#define min(x, y)
Definition draw2.c:29
#define max(x, y)
Definition draw2.c:30
#define GPATH_MAX
Definition gis.h:199
#define G_UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition gis.h:46
double DCELL
Definition gis.h:635
#define _(str)
Definition glocale.h:10
const char * name
Definition named_colr.c:6
void Rast3d_range_update_from_tile(RASTER3D_Map *map, const void *tile, int rows, int cols, int depths, int xRedundant, int yRedundant, int zRedundant, int nofNum, int type)
void Rast3d_range_min_max(RASTER3D_Map *map, double *min, double *max)
Returns in min and max the minimum and maximum values of the range.
int Rast3d_range_init(RASTER3D_Map *map)
int Rast3d_range_load(RASTER3D_Map *map)
Loads the range into the range structure of map.
int Rast3d_read_range(const char *name, const char *mapset, struct FPRange *drange)
int Rast3d_range_write(RASTER3D_Map *map)
Writes the range which is stored in the range structure of map. (This function is invoked automatical...
#define RASTER3D_DIRECTORY
Definition raster3d.h:31
#define RASTER3D_RANGE_ELEMENT
Definition raster3d.h:34
#define RASTER3D_XDR_DOUBLE_LENGTH
#define RASTER3D_WRITE_DATA
DCELL min
Definition raster.h:219
int first_time
Definition raster.h:221
DCELL max
Definition raster.h:220
char * fileName
Definition raster3d.h:74
struct FPRange range
Definition raster3d.h:168
char * mapset
Definition raster3d.h:76
int operation
Definition raster3d.h:79
Definition path.h:15
#define read
Definition unistd.h:5
#define close
Definition unistd.h:8
#define write
Definition unistd.h:6