19 #include "grass/N_pde.h"
20 #include "grass/glocale.h"
52 (
"N_copy_array_2d: the arrays are not of equal size");
56 (
"N_copy_array_2d: the arrays are not of equal size");
59 "N_copy_array_2d: copy source array to target array size %i",
66 if (source->
type == CELL_TYPE) {
70 if (target->
type == CELL_TYPE) {
73 if (target->
type == FCELL_TYPE) {
79 if (target->
type == DCELL_TYPE) {
87 if (source->
type == FCELL_TYPE) {
91 if (target->
type == CELL_TYPE) {
97 if (target->
type == FCELL_TYPE) {
100 if (target->
type == DCELL_TYPE) {
107 if (source->
type == DCELL_TYPE) {
111 if (target->
type == CELL_TYPE) {
117 if (target->
type == FCELL_TYPE) {
123 if (target->
type == DCELL_TYPE) {
149 double norm = 0.0, tmp = 0.0;
150 double v1 = 0.0, v2 = 0.0;
153 G_fatal_error(
"N_norm_array_2d: the arrays are not of equal size");
156 G_fatal_error(
"N_norm_array_2d: the arrays are not of equal size");
158 G_debug(3,
"N_norm_array_2d: norm of a and b size %i",
165 if (a->
type == CELL_TYPE) {
169 if (a->
type == FCELL_TYPE) {
173 if (a->
type == DCELL_TYPE) {
177 if (b->
type == CELL_TYPE) {
181 if (b->
type == FCELL_TYPE) {
185 if (b->
type == DCELL_TYPE) {
196 norm += fabs(v2 - v1);
218 double *sum,
int *nonull,
int withoffset)
226 if (withoffset == 1) {
253 for (j = 0; j < a->
rows; j++) {
254 for (i = 0; i < a->
cols; i++) {
269 "N_calc_array_2d_stats: compute array stats, min %g, max %g, sum %g, nonull %i",
270 *min, *max, *sum, *nonull);
310 int i, j, setnull = 0;
311 double va = 0.0, vb = 0.0, vc = 0.0;
321 (
"N_math_array_2d: the arrays are not of equal size");
324 (
"N_math_array_2d: the arrays are not of equal size");
327 (
"N_math_array_2d: the arrays have different offsets");
329 G_debug(3,
"N_math_array_2d: mathematical calculations, size: %i",
335 if (a->
type == DCELL_TYPE || b->
type == DCELL_TYPE) {
338 "N_math_array_2d: array of type DCELL_TYPE created");
340 else if (a->
type == FCELL_TYPE || b->
type == FCELL_TYPE) {
343 "N_math_array_2d: array of type FCELL_TYPE created");
348 "N_math_array_2d: array of type CELL_TYPE created");
355 (
"N_math_array_2d: the arrays are not of equal size");
358 (
"N_math_array_2d: the arrays are not of equal size");
361 (
"N_math_array_2d: the arrays have different offsets");
365 #pragma omp for private(va, vb, vc, setnull)
394 if (c->
type == CELL_TYPE) {
400 if (c->
type == FCELL_TYPE) {
406 if (c->
type == DCELL_TYPE) {
434 int i = 0,
count = 0;
436 G_debug(3,
"N_convert_array_2d_null_to_zero: convert array of size %i",
439 if (a->
type == CELL_TYPE)
447 if (a->
type == FCELL_TYPE)
456 if (a->
type == DCELL_TYPE)
465 if (a->
type == CELL_TYPE)
467 "N_convert_array_2d_null_to_zero: %i values of type CELL_TYPE are converted",
469 if (a->
type == FCELL_TYPE)
471 "N_convert_array_2d_null_to_zero: %i valuess of type FCELL_TYPE are converted",
473 if (a->
type == DCELL_TYPE)
475 "N_convert_array_2d_null_to_zero: %i valuess of type DCELL_TYPE are converted",
504 G_fatal_error(
"N_copy_array_3d: the arrays are not of equal size");
507 G_fatal_error(
"N_copy_array_3d: the arrays are not of equal size");
510 G_fatal_error(
"N_copy_array_3d: the arrays are not of equal size");
513 G_debug(3,
"N_copy_array_3d: copy source array to target array size %i",
522 if (source->
type == FCELL_TYPE) {
527 if (target->
type == FCELL_TYPE) {
530 if (target->
type == DCELL_TYPE) {
539 if (source->
type == DCELL_TYPE) {
544 if (target->
type == FCELL_TYPE) {
551 if (target->
type == DCELL_TYPE) {
577 double norm = 0.0, tmp = 0.0;
578 double v1 = 0.0, v2 = 0.0;
581 G_fatal_error(
"N_norm_array_3d: the arrays are not of equal size");
584 G_fatal_error(
"N_norm_array_3d: the arrays are not of equal size");
587 G_fatal_error(
"N_norm_array_3d: the arrays are not of equal size");
589 G_debug(3,
"N_norm_array_3d: norm of a and b size %i",
596 if (a->
type == FCELL_TYPE) {
600 if (a->
type == DCELL_TYPE) {
604 if (b->
type == FCELL_TYPE) {
608 if (b->
type == DCELL_TYPE) {
619 norm += fabs(v2 - v1);
641 double *sum,
int *nonull,
int withoffset)
649 if (withoffset == 1) {
658 for (k = 0 - a->
offset; k < a->depths + a->
offset; k++) {
679 for (k = 0; k < a->
depths; k++) {
680 for (j = 0; j < a->
rows; j++) {
681 for (i = 0; i < a->
cols; i++) {
697 "N_calc_array_3d_stats: compute array stats, min %g, max %g, sum %g, nonull %i",
698 *min, *max, *sum, *nonull);
741 int i, j, k, setnull = 0;
742 double va = 0.0, vb = 0.0, vc = 0.0;
749 G_fatal_error(
"N_math_array_3d: the arrays are not of equal size");
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 have different offsets");
757 G_debug(3,
"N_math_array_3d: mathematical calculations, size: %i",
763 if (a->
type == DCELL_TYPE || b->
type == DCELL_TYPE) {
766 G_debug(3,
"N_math_array_3d: array of type DCELL_TYPE created");
771 G_debug(3,
"N_math_array_3d: array of type FCELL_TYPE created");
778 (
"N_math_array_3d: the arrays are not of equal size");
781 (
"N_math_array_3d: the arrays are not of equal size");
784 (
"N_math_array_3d: the arrays are not of equal size");
787 (
"N_math_array_3d: the arrays have different offsets");
790 for (k = 0 - a->
offset; k < a->depths + a->
offset; k++) {
819 if (c->
type == FCELL_TYPE) {
825 if (c->
type == DCELL_TYPE) {
852 int i = 0,
count = 0;
854 G_debug(3,
"N_convert_array_3d_null_to_zero: convert array of size %i",
857 if (a->
type == FCELL_TYPE)
866 if (a->
type == DCELL_TYPE)
876 if (a->
type == FCELL_TYPE)
878 "N_convert_array_3d_null_to_zero: %i values of type FCELL_TYPE are converted",
881 if (a->
type == DCELL_TYPE)
883 "N_convert_array_3d_null_to_zero: %i values of type DCELL_TYPE are converted",
int G_is_c_null_value(const CELL *cellVal)
Returns 1 if cell is NULL, 0 otherwise. This will test if the value cell is the largest int...
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...
void G3d_setNullValue(void *c, int nofElts, int type)
Fills the vector pointed to by c with nofElts NULL-values of type.
void G_set_d_null_value(DCELL *dcellVals, int numVals)
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.
int G3d_isNullValueNum(const void *n, int type)
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_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.
N_array_2d * N_math_array_2d(N_array_2d *a, N_array_2d *b, N_array_2d *result, int type)
Performe calculations with two input arrays, the result is written to a third array.
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_array_2d * N_alloc_array_2d(int cols, int rows, int offset, int type)
Allocate memory for a N_array_2d data structure.
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.
double N_norm_array_3d(N_array_3d *a, N_array_3d *b, int type)
Calculate the norm of the two input arrays.
int N_convert_array_3d_null_to_zero(N_array_3d *a)
Convert all null values to zero values.
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
int G_is_f_null_value(const FCELL *fcellVal)
Returns 1 if fcell is NULL, 0 otherwise. This will test if the value fcell is a NaN. It isn't good enough to test for a particular NaN bit pattern since the machine code may change this bit pattern to a different NaN. The test will be.
int N_convert_array_2d_null_to_zero(N_array_2d *a)
Convert all null values to zero values.
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_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.
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_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.
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 G_set_f_null_value(FCELL *fcellVals, int numVals)
N_array_3d * N_math_array_3d(N_array_3d *a, N_array_3d *b, N_array_3d *result, int type)
Performe calculations with two input arrays, the result is written to a third array.
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 postion col, row is of type null, otherwise 0...
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.
int G_debug(int level, const char *msg,...)
Print debugging message.
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.
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.
void G_set_c_null_value(CELL *cellVals, int numVals)
double N_norm_array_2d(N_array_2d *a, N_array_2d *b, int type)
Calculate the norm of the two input arrays.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
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.