GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
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 UNUSED, int nofNum, int type)
18{
19 int y, z, cellType;
20 struct FPRange *range;
21
22 range = &(map->range);
24
25 if (nofNum == map->tileSize) {
27 return;
28 }
29
30 if (xRedundant) {
31 for (z = 0; z < depths; z++) {
32 for (y = 0; y < rows; y++) {
35 }
36 if (yRedundant)
38 Rast3d_length(type));
39 }
40 return;
41 }
42
43 if (yRedundant) {
44 for (z = 0; z < depths; z++) {
45 Rast_row_update_fp_range(tile, map->tileX * rows, range, cellType);
47 }
48 return;
49 }
50
51 Rast_row_update_fp_range(tile, map->tileXY * depths, range, cellType);
52}
53
54/*---------------------------------------------------------------------------*/
55
56int Rast3d_read_range(const char *name, const char *mapset,
57 struct FPRange *drange)
58/* adapted from Rast_read_fp_range */
59{
60 int fd;
61 int bytes_read;
64
66
67 fd = -1;
68
70 mapset);
71 if (fd < 0) {
72 G_warning(_("Unable to open range file for [%s in %s]"), name, mapset);
73 return -1;
74 }
75
77
78 /* if the f_range file exists, but empty the range is NULL -> a NULL map */
79 if (bytes_read == 0) {
80 close(fd);
81 return 1;
82 }
83
85 close(fd);
86 G_warning(_("Error reading range file for [%s in %s]"), name, mapset);
87 return 2;
88 }
89
92
95 close(fd);
96 return 1;
97}
98
99/*---------------------------------------------------------------------------*/
100
101/*!
102 * \brief Loads the range into the range structure of <em>map</em>.
103 *
104 * \param map a pointer to a raster 3D map object
105 * \return 1 ... if successful
106 * 0 ... otherwise.
107 */
109{
110 if (map->operation == RASTER3D_WRITE_DATA)
111 return 1;
112 if (Rast3d_read_range(map->fileName, map->mapset, &(map->range)) == -1) {
113 return 0;
114 }
115
116 return 1;
117}
118
119/*---------------------------------------------------------------------------*/
120
121/*!
122 * \brief Returns in <em>min</em> and <em>max</em> the minimum and maximum
123 * values of the range.
124 *
125 * \param map a pointer to a raster 3D map object
126 * \param min a pointer to a double to store minumim
127 * \param max a pointer to a double to store maximum
128 */
129void Rast3d_range_min_max(RASTER3D_Map *map, double *min, double *max)
130{
132}
133
134/*-------------------------------------------------------------------------*/
135
136static int writeRange(const char *name, struct FPRange *range)
137/* adapted from Rast_write_fp_range */
138{
140 int fd;
141
143 if (fd < 0) {
144 G_warning(_("Unable to open range file for <%s>"), name);
145 return -1;
146 }
147
148 if (range->first_time) {
149 /* if range hasn't been updated, write empty file meaning NULLs */
150 close(fd);
151 return 0;
152 }
153
156
159 goto error;
160
161 close(fd);
162 return 0;
163
164error:
165 close(fd);
167 name); /* remove the old file with this name */
168 G_warning("can't write range file for [%s in %s]", name, G_mapset());
169 return -1;
170}
171
172/*---------------------------------------------------------------------------*/
173
174/*!
175 * \brief
176 *
177 * Writes the range which is stored in the range structure of <em>map</em>.
178 * (This function is invoked automatically when a new file is closed).
179 *
180 * \param map
181 * \return 1 ... if successful
182 * 0 ... otherwise.
183 */
185{
186 char path[GPATH_MAX];
187
189 remove(path);
190
191 if (writeRange(map->fileName, &(map->range)) == -1) {
192 Rast3d_error("Rast3d_closeCellNew: error in writeRange");
193 return 0;
194 }
195
196 return 1;
197}
198
199/*---------------------------------------------------------------------------*/
200
202{
203 Rast_init_fp_range(&(map->range));
204 return 0;
205}
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
double DCELL
Definition gis.h:635
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition gis.h:46
#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