14 #include <grass/gis.h>
15 #include <grass/glocale.h>
41 if (cellhd->ns_res <= 0)
45 if (cellhd->rows <= 0)
49 if (cellhd->ew_res <= 0)
53 if (cellhd->cols <= 0)
58 if (cellhd->proj == PROJECTION_LL) {
59 double epsilon_ns, epsilon_ew;
62 epsilon_ns = 1. / cellhd->rows * 0.001;
65 G_debug(3,
"G_adjust_Cell_head: epsilon_ns: %g, epsilon_ew: %g",
66 epsilon_ns, epsilon_ew);
71 if (cellhd->north > 90.0) {
72 if (((cellhd->north - 90.0) < epsilon_ns) &&
73 ((cellhd->north - 90.0) > GRASS_EPSILON)) {
74 G_warning(_(
"Fixing subtle input data rounding error of north boundary (%g>%g)"),
75 cellhd->north - 90.0, epsilon_ns);
82 if (cellhd->south < -90.0) {
83 if (((cellhd->south + 90.0) < epsilon_ns) &&
84 ((cellhd->south + 90.0) < GRASS_EPSILON)) {
85 G_warning(_(
"Fixing subtle input data rounding error of south boundary (%g>%g)"),
86 cellhd->south + 90.0, epsilon_ns);
87 cellhd->south = -90.0;
97 "G_adjust_Cell_head() cellhd->west: %f, devi: %g, eps: %g",
98 cellhd->west, cellhd->west + 180.0, epsilon_ew);
100 if ((cellhd->west < -180.0) && ((cellhd->west + 180.0) < epsilon_ew)
101 && ((cellhd->west + 180.0) < GRASS_EPSILON)) {
102 G_warning(_(
"Fixing subtle input data rounding error of west boundary (%g>%g)"),
103 cellhd->west + 180.0, epsilon_ew);
104 cellhd->west = -180.0;
108 "G_adjust_Cell_head() cellhd->east: %f, devi: %g, eps: %g",
109 cellhd->east, cellhd->east - 180.0, epsilon_ew);
111 if ((cellhd->east > 180.0) && ((cellhd->east - 180.0) > epsilon_ew)
112 && ((cellhd->east - 180.0) > GRASS_EPSILON)) {
113 G_warning(_(
"Fixing subtle input data rounding error of east boundary (%g>%g)"),
114 cellhd->east - 180.0, epsilon_ew);
115 cellhd->east = 180.0;
119 while (cellhd->east <= cellhd->west)
120 cellhd->east += 360.0;
124 if (cellhd->north <= cellhd->south) {
125 if (cellhd->proj == PROJECTION_LL)
130 if (cellhd->east <= cellhd->west)
136 (cellhd->north - cellhd->south +
137 cellhd->ns_res / 2.0) / cellhd->ns_res;
138 if (cellhd->rows == 0)
143 (cellhd->east - cellhd->west +
144 cellhd->ew_res / 2.0) / cellhd->ew_res;
145 if (cellhd->cols == 0)
149 if (cellhd->cols < 0 || cellhd->rows < 0) {
155 cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
156 cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
187 int col_flag,
int depth_flag)
190 if (cellhd->ns_res <= 0)
192 if (cellhd->ns_res3 <= 0)
196 if (cellhd->rows <= 0)
198 if (cellhd->rows3 <= 0)
202 if (cellhd->ew_res <= 0)
204 if (cellhd->ew_res3 <= 0)
208 if (cellhd->cols <= 0)
210 if (cellhd->cols3 <= 0)
214 if (cellhd->tb_res <= 0)
218 if (cellhd->depths <= 0)
223 if (cellhd->proj == PROJECTION_LL) {
224 double epsilon_ns, epsilon_ew;
227 epsilon_ns = 1. / cellhd->rows * 0.001;
228 epsilon_ew = .000001;
230 G_debug(3,
"G_adjust_Cell_head: epsilon_ns: %g, epsilon_ew: %g",
231 epsilon_ns, epsilon_ew);
236 if (cellhd->north > 90.0) {
237 if (((cellhd->north - 90.0) < epsilon_ns) &&
238 ((cellhd->north - 90.0) > GRASS_EPSILON)) {
239 G_warning(_(
"Fixing subtle input data rounding error of north boundary (%g>%g)"),
240 cellhd->north - 90.0, epsilon_ns);
241 cellhd->north = 90.0;
247 if (cellhd->south < -90.0) {
248 if (((cellhd->south + 90.0) < epsilon_ns) &&
249 ((cellhd->south + 90.0) < GRASS_EPSILON)) {
250 G_warning(_(
"Fixing subtle input data rounding error of south boundary (%g>%g)"),
251 cellhd->south + 90.0, epsilon_ns);
252 cellhd->south = -90.0;
262 "G_adjust_Cell_head3() cellhd->west: %f, devi: %g, eps: %g",
263 cellhd->west, cellhd->west + 180.0, epsilon_ew);
265 if ((cellhd->west < -180.0) && ((cellhd->west + 180.0) < epsilon_ew)
266 && ((cellhd->west + 180.0) < GRASS_EPSILON)) {
267 G_warning(_(
"Fixing subtle input data rounding error of west boundary (%g>%g)"),
268 cellhd->west + 180.0, epsilon_ew);
269 cellhd->west = -180.0;
273 "G_adjust_Cell_head3() cellhd->east: %f, devi: %g, eps: %g",
274 cellhd->east, cellhd->east - 180.0, epsilon_ew);
276 if ((cellhd->east > 180.0) && ((cellhd->east - 180.0) > epsilon_ew)
277 && ((cellhd->east - 180.0) > GRASS_EPSILON)) {
278 G_warning(_(
"Fixing subtle input data rounding error of east boundary (%g>%g)"),
279 cellhd->east - 180.0, epsilon_ew);
280 cellhd->east = 180.0;
284 while (cellhd->east <= cellhd->west)
285 cellhd->east += 360.0;
289 if (cellhd->north <= cellhd->south) {
290 if (cellhd->proj == PROJECTION_LL)
295 if (cellhd->east <= cellhd->west)
298 if (cellhd->top <= cellhd->bottom)
304 (cellhd->north - cellhd->south +
305 cellhd->ns_res / 2.0) / cellhd->ns_res;
306 if (cellhd->rows == 0)
310 (cellhd->north - cellhd->south +
311 cellhd->ns_res3 / 2.0) / cellhd->ns_res3;
312 if (cellhd->rows3 == 0)
317 (cellhd->east - cellhd->west +
318 cellhd->ew_res / 2.0) / cellhd->ew_res;
319 if (cellhd->cols == 0)
323 (cellhd->east - cellhd->west +
324 cellhd->ew_res3 / 2.0) / cellhd->ew_res3;
325 if (cellhd->cols3 == 0)
331 (cellhd->top - cellhd->bottom +
332 cellhd->tb_res / 2.0) / cellhd->tb_res;
333 if (cellhd->depths == 0)
338 if (cellhd->cols < 0 || cellhd->rows < 0 || cellhd->cols3 < 0 ||
339 cellhd->rows3 < 0 || cellhd->depths < 0) {
344 cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
345 cellhd->ns_res3 = (cellhd->north - cellhd->south) / cellhd->rows3;
346 cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
347 cellhd->ew_res3 = (cellhd->east - cellhd->west) / cellhd->cols3;
348 cellhd->tb_res = (cellhd->top - cellhd->bottom) / cellhd->depths;
void G_adjust_Cell_head3(struct Cell_head *cellhd, int row_flag, int col_flag, int depth_flag)
Adjust cell header for 3D values.
void G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G_debug(int level, const char *msg,...)
Print debugging message.
void G_warning(const char *msg,...)
Print a warning message to stderr.