20 #include <grass/N_pde.h>
21 #include <grass/raster.h>
22 #include <grass/glocale.h>
54 (
"N_copy_array_2d: the arrays are not of equal size");
58 (
"N_copy_array_2d: the arrays are not of equal size");
61 "N_copy_array_2d: copy source array to target array size %i",
66 for (i = 0; i <
source->cols_intern *
source->rows_intern; i++) {
68 if (
source->type == CELL_TYPE) {
69 if (Rast_is_c_null_value((
void *)&
source->cell_array[i]))
72 if (target->
type == CELL_TYPE) {
75 if (target->
type == FCELL_TYPE) {
77 Rast_set_f_null_value((
void *)&(target->
fcell_array[i]), 1);
81 if (target->
type == DCELL_TYPE) {
83 Rast_set_d_null_value((
void *)&(target->
dcell_array[i]), 1);
89 if (
source->type == FCELL_TYPE) {
90 if (Rast_is_f_null_value((
void *)&
source->fcell_array[i]))
93 if (target->
type == CELL_TYPE) {
95 Rast_set_c_null_value((
void *)&(target->
cell_array[i]), 1);
99 if (target->
type == FCELL_TYPE) {
102 if (target->
type == DCELL_TYPE) {
104 Rast_set_d_null_value((
void *)&(target->
dcell_array[i]), 1);
109 if (
source->type == DCELL_TYPE) {
110 if (Rast_is_d_null_value((
void *)&
source->dcell_array[i]))
113 if (target->
type == CELL_TYPE) {
115 Rast_set_c_null_value((
void *)&(target->
cell_array[i]), 1);
119 if (target->
type == FCELL_TYPE) {
121 Rast_set_f_null_value((
void *)&(target->
fcell_array[i]), 1);
125 if (target->
type == DCELL_TYPE) {
151 double norm = 0.0, tmp = 0.0;
152 double v1 = 0.0, v2 = 0.0;
155 G_fatal_error(
"N_norm_array_2d: the arrays are not of equal size");
158 G_fatal_error(
"N_norm_array_2d: the arrays are not of equal size");
160 G_debug(3,
"N_norm_array_2d: norm of a and b size %i",
167 if (a->
type == CELL_TYPE) {
168 if (!Rast_is_f_null_value((
void *)&(a->
cell_array[i])))
171 if (a->
type == FCELL_TYPE) {
172 if (!Rast_is_f_null_value((
void *)&(a->
fcell_array[i])))
175 if (a->
type == DCELL_TYPE) {
176 if (!Rast_is_f_null_value((
void *)&(a->
dcell_array[i])))
179 if (
b->type == CELL_TYPE) {
180 if (!Rast_is_f_null_value((
void *)&(
b->cell_array[i])))
181 v2 = (
double)
b->cell_array[i];
183 if (
b->type == FCELL_TYPE) {
184 if (!Rast_is_f_null_value((
void *)&(
b->fcell_array[i])))
185 v2 = (
double)
b->fcell_array[i];
187 if (
b->type == DCELL_TYPE) {
188 if (!Rast_is_f_null_value((
void *)&(
b->dcell_array[i])))
189 v2 = (
double)
b->dcell_array[i];
198 norm += fabs(v2 - v1);
220 double *sum,
int *nonull,
int withoffset)
228 if (withoffset == 1) {
255 for (j = 0; j < a->
rows; j++) {
256 for (i = 0; i < a->
cols; i++) {
271 "N_calc_array_2d_stats: compute array stats, min %g, max %g, sum %g, nonull %i",
272 *
min, *
max, *sum, *nonull);
312 int i, j, setnull = 0;
313 double va = 0.0, vb = 0.0, vc = 0.0;
323 (
"N_math_array_2d: the arrays are not of equal size");
326 (
"N_math_array_2d: the arrays are not of equal size");
329 (
"N_math_array_2d: the arrays have different offsets");
331 G_debug(3,
"N_math_array_2d: mathematical calculations, size: %i",
337 if (a->
type == DCELL_TYPE ||
b->type == DCELL_TYPE) {
340 "N_math_array_2d: array of type DCELL_TYPE created");
342 else if (a->
type == FCELL_TYPE ||
b->type == FCELL_TYPE) {
345 "N_math_array_2d: array of type FCELL_TYPE created");
350 "N_math_array_2d: array of type CELL_TYPE created");
357 (
"N_math_array_2d: the arrays are not of equal size");
360 (
"N_math_array_2d: the arrays are not of equal size");
363 (
"N_math_array_2d: the arrays have different offsets");
367 #pragma omp for private(va, vb, vc, setnull)
396 if (c->
type == CELL_TYPE) {
402 if (c->
type == FCELL_TYPE) {
408 if (c->
type == DCELL_TYPE) {
436 int i = 0,
count = 0;
438 G_debug(3,
"N_convert_array_2d_null_to_zero: convert array of size %i",
441 if (a->
type == CELL_TYPE)
443 if (Rast_is_c_null_value((
void *)&(a->
cell_array[i]))) {
449 if (a->
type == FCELL_TYPE)
451 if (Rast_is_f_null_value((
void *)&(a->
fcell_array[i]))) {
458 if (a->
type == DCELL_TYPE)
460 if (Rast_is_d_null_value((
void *)&(a->
dcell_array[i]))) {
467 if (a->
type == CELL_TYPE)
469 "N_convert_array_2d_null_to_zero: %i values of type CELL_TYPE are converted",
471 if (a->
type == FCELL_TYPE)
473 "N_convert_array_2d_null_to_zero: %i valuess of type FCELL_TYPE are converted",
475 if (a->
type == DCELL_TYPE)
477 "N_convert_array_2d_null_to_zero: %i valuess of type DCELL_TYPE are converted",
506 G_fatal_error(
"N_copy_array_3d: the arrays are not of equal size");
509 G_fatal_error(
"N_copy_array_3d: the arrays are not of equal size");
512 G_fatal_error(
"N_copy_array_3d: the arrays are not of equal size");
515 G_debug(3,
"N_copy_array_3d: copy source array to target array size %i",
524 if (
source->type == FCELL_TYPE) {
525 if (Rast3d_is_null_value_num
526 ((
void *)&(
source->fcell_array[i]), FCELL_TYPE))
529 if (target->
type == FCELL_TYPE) {
532 if (target->
type == DCELL_TYPE) {
534 Rast3d_set_null_value((
void *)&(target->
dcell_array[i]), 1,
541 if (
source->type == DCELL_TYPE) {
542 if (Rast3d_is_null_value_num
543 ((
void *)&(
source->dcell_array[i]), DCELL_TYPE))
546 if (target->
type == FCELL_TYPE) {
548 Rast3d_set_null_value((
void *)&(target->
fcell_array[i]), 1,
553 if (target->
type == DCELL_TYPE) {
579 double norm = 0.0, tmp = 0.0;
580 double v1 = 0.0, v2 = 0.0;
583 G_fatal_error(
"N_norm_array_3d: the arrays are not of equal size");
586 G_fatal_error(
"N_norm_array_3d: the arrays are not of equal size");
589 G_fatal_error(
"N_norm_array_3d: the arrays are not of equal size");
591 G_debug(3,
"N_norm_array_3d: norm of a and b size %i",
598 if (a->
type == FCELL_TYPE) {
599 if (!Rast3d_is_null_value_num((
void *)&(a->
fcell_array[i]), FCELL_TYPE))
602 if (a->
type == DCELL_TYPE) {
603 if (!Rast3d_is_null_value_num((
void *)&(a->
dcell_array[i]), DCELL_TYPE))
606 if (
b->type == FCELL_TYPE) {
607 if (!Rast3d_is_null_value_num((
void *)&(
b->fcell_array[i]), FCELL_TYPE))
608 v2 = (
double)
b->fcell_array[i];
610 if (
b->type == DCELL_TYPE) {
611 if (!Rast3d_is_null_value_num((
void *)&(
b->dcell_array[i]), DCELL_TYPE))
612 v2 = (
double)
b->dcell_array[i];
621 norm += fabs(v2 - v1);
643 double *sum,
int *nonull,
int withoffset)
651 if (withoffset == 1) {
660 for (k = 0 - a->
offset; k < a->depths + a->
offset; k++) {
681 for (k = 0; k < a->
depths; k++) {
682 for (j = 0; j < a->
rows; j++) {
683 for (i = 0; i < a->
cols; i++) {
699 "N_calc_array_3d_stats: compute array stats, min %g, max %g, sum %g, nonull %i",
700 *
min, *
max, *sum, *nonull);
743 int i, j, k, setnull = 0;
744 double va = 0.0, vb = 0.0, vc = 0.0;
751 G_fatal_error(
"N_math_array_3d: the arrays are not of equal size");
753 G_fatal_error(
"N_math_array_3d: the arrays are not of equal size");
755 G_fatal_error(
"N_math_array_3d: the arrays are not of equal size");
757 G_fatal_error(
"N_math_array_3d: the arrays have different offsets");
759 G_debug(3,
"N_math_array_3d: mathematical calculations, size: %i",
765 if (a->
type == DCELL_TYPE ||
b->type == DCELL_TYPE) {
768 G_debug(3,
"N_math_array_3d: array of type DCELL_TYPE created");
773 G_debug(3,
"N_math_array_3d: array of type FCELL_TYPE created");
780 (
"N_math_array_3d: the arrays are not of equal size");
783 (
"N_math_array_3d: the arrays are not of equal size");
786 (
"N_math_array_3d: the arrays are not of equal size");
789 (
"N_math_array_3d: the arrays have different offsets");
792 for (k = 0 - a->
offset; k < a->depths + a->
offset; k++) {
821 if (c->
type == FCELL_TYPE) {
827 if (c->
type == DCELL_TYPE) {
854 int i = 0,
count = 0;
856 G_debug(3,
"N_convert_array_3d_null_to_zero: convert array of size %i",
859 if (a->
type == FCELL_TYPE)
862 if (Rast3d_is_null_value_num((
void *)&(a->
fcell_array[i]), FCELL_TYPE)) {
868 if (a->
type == DCELL_TYPE)
871 if (Rast3d_is_null_value_num((
void *)&(a->
dcell_array[i]), DCELL_TYPE)) {
878 if (a->
type == FCELL_TYPE)
880 "N_convert_array_3d_null_to_zero: %i values of type FCELL_TYPE are converted",
883 if (a->
type == DCELL_TYPE)
885 "N_convert_array_3d_null_to_zero: %i values of type DCELL_TYPE are converted",
int G_debug(int level, const char *msg,...)
Print debugging message.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void N_put_array_3d_value_null(N_array_3d *data, int col, int row, int depth)
This function writes a null value to the N_array_3d data at position col, row, depth.
void N_put_array_2d_f_value(N_array_2d *data, int col, int row, FCELL value)
Writes a FCELL value to the N_array_2d struct at position col, row.
void N_put_array_3d_f_value(N_array_3d *data, int col, int row, int depth, float value)
This function writes a float value to the N_array_3d data at position col, row, depth.
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.
N_array_3d * N_alloc_array_3d(int cols, int rows, int depths, int offset, int type)
Allocate memory for a N_array_3d data structure.
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.
N_array_2d * N_alloc_array_2d(int cols, int rows, int offset, int type)
Allocate memory for a N_array_2d data structure.
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_value_null(N_array_2d *data, int col, int row)
Writes the null value to the N_array_2d struct at position col, row.
void N_put_array_2d_c_value(N_array_2d *data, int col, int row, CELL value)
Writes a CELL value to the N_array_2d struct at position col, row.
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.
int N_convert_array_3d_null_to_zero(N_array_3d *a)
Convert all null values to zero values.
int N_convert_array_2d_null_to_zero(N_array_2d *a)
Convert all null values to zero values.
double N_norm_array_3d(N_array_3d *a, N_array_3d *b, int type)
Calculate the norm of the two input arrays.
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.
void N_copy_array_3d(N_array_3d *source, N_array_3d *target)
Copy the source N_array_3d struct to the target N_array_3d struct.
void N_copy_array_2d(N_array_2d *source, N_array_2d *target)
Copy the source N_array_2d struct to the target N_array_2d struct.
N_array_3d * N_math_array_3d(N_array_3d *a, N_array_3d *b, N_array_3d *result, int type)
Perform calculations with two input arrays, the result is written to a third array.
N_array_2d * N_math_array_2d(N_array_2d *a, N_array_2d *b, N_array_2d *result, int type)
Perform calculations with two input arrays, the result is written to a third array.
double N_norm_array_2d(N_array_2d *a, N_array_2d *b, int type)
Calculate the norm of the two input arrays.