18 #include <grass/N_pde.h>
35 G_debug(3,
"N_calc_gradient_field_2d_stats: compute gradient field stats");
50 field->
sum = sumx + sumy;
51 field->
nonull = nonullx + nonully;
117 double dx, dy, p1, p2, r1, r2,
mean, grad, res;
122 "N_compute_gradient_field_2d: the arrays are not of equal size");
126 "N_compute_gradient_field_2d: the arrays are not of equal size");
129 G_fatal_error(
"N_compute_gradient_field_2d: array sizes and geometry "
130 "data are different");
132 G_debug(3,
"N_compute_gradient_field_2d: compute gradient field");
144 G_fatal_error(
"N_compute_gradient_field_2d: gradient field sizes "
145 "and geometry data are different");
148 for (j = 0; j < rows; j++)
149 for (i = 0; i < cols - 1; i++) {
158 grad = (p1 - p2) / dx;
172 for (j = 0; j < rows - 1; j++)
173 for (i = 0; i < cols; i++) {
182 grad = (p1 - p2) / dy;
191 res = -1 *
mean * grad;
259 G_fatal_error(
"N_compute_gradient_components_2d: x array is empty");
261 G_fatal_error(
"N_compute_gradient_components_2d: y array is empty");
267 if (
x->cols != cols ||
x->rows != rows)
268 G_fatal_error(
"N_compute_gradient_components_2d: the size of the x "
269 "array doesn't fit the gradient field size");
270 if (y->
cols != cols || y->
rows != rows)
271 G_fatal_error(
"N_compute_gradient_components_2d: the size of the y "
272 "array doesn't fit the gradient field size");
274 for (j = 0; j < rows; j++)
275 for (i = 0; i < cols; i++) {
279 if (grad.
WC == 0.0 || grad.
EC == 0.0)
280 vx = (grad.
WC + grad.
EC);
282 vx = (grad.
WC + grad.
EC) / 2;
283 if (grad.
NC == 0.0 || grad.
SC == 0.0)
284 vy = (grad.
NC + grad.
SC);
286 vy = (grad.
NC + grad.
SC) / 2;
305 double minx, miny, minz;
307 double maxx, maxy, maxz;
309 double sumx, sumy, sumz;
311 int nonullx, nonully, nonullz;
313 G_debug(3,
"N_calc_gradient_field_3d_stats: compute gradient field stats");
319 if (minx <= minz && minx <= miny)
321 if (miny <= minz && miny <= minx)
323 if (minz <= minx && minz <= miny)
326 if (maxx >= maxz && maxx >= maxy)
328 if (maxy >= maxz && maxy >= maxx)
330 if (maxz >= maxx && maxz >= maxy)
333 field->
sum = sumx + sumy + sumz;
334 field->
nonull = nonullx + nonully + nonullz;
406 int cols, rows, depths;
408 double dx, dy, dz, p1, p2, r1, r2,
mean, grad, res;
415 "N_compute_gradient_field_3d: the arrays are not of equal size");
420 "N_compute_gradient_field_3d: the arrays are not of equal size");
425 "N_compute_gradient_field_3d: the arrays are not of equal size");
429 G_fatal_error(
"N_compute_gradient_field_3d: array sizes and geometry "
430 "data are different");
432 G_debug(3,
"N_compute_gradient_field_3d: compute gradient field");
441 if (gradfield ==
NULL) {
447 G_fatal_error(
"N_compute_gradient_field_3d: gradient field sizes "
448 "and geometry data are different");
451 for (k = 0; k < depths; k++)
452 for (j = 0; j < rows; j++)
453 for (i = 0; i < cols - 1; i++) {
462 grad = (p1 - p2) / dx;
474 "N_compute_gradient_field_3d: X-direction insert value "
475 "%6.5g at %i %i %i ",
481 for (k = 0; k < depths; k++)
482 for (j = 0; j < rows - 1; j++)
483 for (i = 0; i < cols; i++) {
492 grad = (p1 - p2) / dy;
501 res = -1 *
mean * grad;
506 "N_compute_gradient_field_3d: Y-direction insert value "
507 "%6.5g at %i %i %i ",
513 for (k = 0; k < depths - 1; k++)
514 for (j = 0; j < rows; j++)
515 for (i = 0; i < cols; i++) {
524 grad = (p1 - p2) / dz;
536 "N_compute_gradient_field_3d: Z-direction insert value "
537 "%6.5g at %i %i %i ",
602 int rows, cols, depths;
615 G_fatal_error(
"N_compute_gradient_components_3d: x array is empty");
617 G_fatal_error(
"N_compute_gradient_components_3d: y array is empty");
619 G_fatal_error(
"N_compute_gradient_components_3d: z array is empty");
626 if (
x->cols != cols ||
x->rows != rows ||
x->depths != depths)
627 G_fatal_error(
"N_compute_gradient_components_3d: the size of the x "
628 "array doesn't fit the gradient field size");
630 G_fatal_error(
"N_compute_gradient_components_3d: the size of the y "
631 "array doesn't fit the gradient field size");
633 G_fatal_error(
"N_compute_gradient_components_3d: the size of the z "
634 "array doesn't fit the gradient field size");
636 for (k = 0; k < depths; k++)
637 for (j = 0; j < rows; j++)
638 for (i = 0; i < cols; i++) {
641 if (grad.
WC == 0.0 || grad.
EC == 0.0)
642 vx = (grad.
WC + grad.
EC);
644 vx = (grad.
WC + grad.
EC) / 2;
645 if (grad.
NC == 0.0 || grad.
SC == 0.0)
646 vy = (grad.
NC + grad.
SC);
648 vy = (grad.
NC + grad.
SC) / 2;
649 if (grad.
TC == 0.0 || grad.
BC == 0.0)
650 vz = (grad.
TC + grad.
BC);
652 vz = (grad.
TC + grad.
BC) / 2;
double N_calc_harmonic_mean(double a, double b)
Calculate the harmonical mean of values a and b.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
float mean(IClass_statistics *statistics, int band)
Helper function for computing mean.
DCELL N_get_array_2d_d_value(N_array_2d *data, int col, int row)
Returns the value of type DCELL at position col, row.
int N_is_array_3d_value_null(N_array_3d *data, int col, int row, int depth)
This function returns 1 if value of N_array_3d data at position col, row, depth is of type null,...
int N_is_array_2d_value_null(N_array_2d *data, int col, int row)
Returns 1 if the value of N_array_2d struct at position col, row is of type null, otherwise 0.
void N_put_array_3d_d_value(N_array_3d *data, int col, int row, int depth, double value)
Writes a double value to the N_array_3d struct at position col, row, depth.
double N_get_array_3d_d_value(N_array_3d *data, int col, int row, int depth)
This function returns the value of type float at position col, row, depth.
void N_put_array_2d_d_value(N_array_2d *data, int col, int row, DCELL value)
Writes a DCELL value to the N_array_2d struct at position col, row.
void N_calc_array_3d_stats(N_array_3d *a, double *min, double *max, double *sum, int *nonull, int withoffset)
Calculate basic statistics of the N_array_3d struct.
void N_calc_array_2d_stats(N_array_2d *a, double *min, double *max, double *sum, int *nonull, int withoffset)
Calculate basic statistics of the N_array_2d struct.
N_gradient_3d * N_get_gradient_3d(N_gradient_field_3d *field, N_gradient_3d *gradient, int col, int row, int depth)
Return a N_gradient_3d structure calculated from the input gradient field at position [depth][row][co...
N_gradient_field_2d * N_alloc_gradient_field_2d(int cols, int rows)
Allocate a N_gradient_field_2d.
N_gradient_2d * N_get_gradient_2d(N_gradient_field_2d *field, N_gradient_2d *gradient, int col, int row)
Return a N_gradient_2d structure calculated from the input gradient field at position [row][col].
N_gradient_field_3d * N_alloc_gradient_field_3d(int cols, int rows, int depths)
Allocate a N_gradient_field_3d.
void N_compute_gradient_field_components_3d(N_gradient_field_3d *field, N_array_3d *x_comp, N_array_3d *y_comp, N_array_3d *z_comp)
Calculate the x, y and z vector components from a gradient field for each cell and store them in the ...
void N_compute_gradient_field_components_2d(N_gradient_field_2d *field, N_array_2d *x_comp, N_array_2d *y_comp)
Calculate the x and y vector components from a gradient field for each cell and stores them in the pr...
void N_calc_gradient_field_2d_stats(N_gradient_field_2d *field)
Calculate basic statistics of a gradient field.
N_gradient_field_3d * N_compute_gradient_field_3d(N_array_3d *pot, N_array_3d *weight_x, N_array_3d *weight_y, N_array_3d *weight_z, N_geom_data *geom, N_gradient_field_3d *gradfield)
This function computes the gradient based on the input N_array_3d pot (that means potential),...
N_gradient_field_2d * N_compute_gradient_field_2d(N_array_2d *pot, N_array_2d *weight_x, N_array_2d *weight_y, N_geom_data *geom, N_gradient_field_2d *gradfield)
This function computes the gradient based on the input N_array_2d pot (potential),...
void N_calc_gradient_field_3d_stats(N_gradient_field_3d *field)
Calculate basic statistics of a gradient field.
Geometric information about the structured grid.
Gradient between the cells in X and Y direction.
Gradient between the cells in X, Y and Z direction.