GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
N_arrays_calc.c File Reference
#include "grass/N_pde.h"
#include "grass/glocale.h"
#include <math.h>
Include dependency graph for N_arrays_calc.c:

Go to the source code of this file.

Functions

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. More...
 
double N_norm_array_2d (N_array_2d *a, N_array_2d *b, int type)
 Calculate the norm of the two input arrays. More...
 
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. More...
 
N_array_2dN_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. More...
 
int N_convert_array_2d_null_to_zero (N_array_2d *a)
 Convert all null values to zero values. More...
 
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. More...
 
double N_norm_array_3d (N_array_3d *a, N_array_3d *b, int type)
 Calculate the norm of the two input arrays. More...
 
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. More...
 
N_array_3dN_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. More...
 
int N_convert_array_3d_null_to_zero (N_array_3d *a)
 Convert all null values to zero values. More...
 

Function Documentation

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.

Calculates the minimum, maximum, sum and the number of non null values. The array offset can be included in the calculation.

Parameters
aN_array_2d * - input array
mindouble* - variable to store the computed minimum
maxdouble* - variable to store the computed maximum
sumdouble* - variable to store the computed sum
nonullint* - variable to store the number of non null values
withoffset- if 1 include offset values in statistic calculation, 0 otherwise
Returns
void

Definition at line 217 of file N_arrays_calc.c.

References N_array_2d::cols, dialogs::cols, G_debug(), N_get_array_2d_d_value(), N_is_array_2d_value_null(), N_array_2d::offset, and N_array_2d::rows.

Referenced by N_calc_gradient_field_2d_stats().

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.

Calculates the minimum, maximum, sum and the number of non null values. The array offset can be included in the statistical calculation.

Parameters
aN_array_3d * - input array
mindouble* - variable to store the computed minimum
maxdouble* - variable to store the computed maximum
sumdouble* - variable to store the computed sum
nonullint* - variable to store the number of non null values
withoffset- if 1 include offset values in statistic calculation, 0 otherwise
Returns
void

Definition at line 640 of file N_arrays_calc.c.

References N_array_3d::cols, dialogs::cols, N_array_3d::depths, G_debug(), N_get_array_3d_d_value(), N_is_array_3d_value_null(), N_array_3d::offset, and N_array_3d::rows.

Referenced by N_calc_gradient_field_3d_stats().

int N_convert_array_2d_null_to_zero ( N_array_2d a)

Convert all null values to zero values.

The complete data array inclusively offsets is used. The array data types are automatically recognized.

Parameters
aN_array_2d *
Returns
int - number of replaced values

Definition at line 432 of file N_arrays_calc.c.

References N_array_2d::cell_array, N_array_2d::cols_intern, count, N_array_2d::dcell_array, N_array_2d::fcell_array, G_debug(), G_is_c_null_value(), G_is_d_null_value(), G_is_f_null_value(), N_array_2d::rows_intern, and N_array_2d::type.

int N_convert_array_3d_null_to_zero ( N_array_3d a)

Convert all null values to zero values.

The complete data array inclusively offsets is used.

Parameters
aN_array_3d *
Returns
int - number of replaced null values

Definition at line 850 of file N_arrays_calc.c.

References N_array_3d::cols_intern, count, N_array_3d::dcell_array, N_array_3d::depths_intern, N_array_3d::fcell_array, G3d_isNullValueNum(), G_debug(), N_array_3d::rows_intern, and N_array_3d::type.

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.

The arrays must have the same size and the same offset.

The array types can be mixed, the values are automatically casted and the null values are set accordingly.

If you copy a cell array into a dcell array, the values are casted to dcell and the null values are converted from cell-null to dcell-null

This function can be called in a parallel region defined with OpenMP. The copy loop is parallelize with a openmp for pragma.

Parameters
sourceN_array_2d *
targetN_array_2d *
Returns
void

Definition at line 43 of file N_arrays_calc.c.

References N_array_2d::cell_array, N_array_2d::cols_intern, N_array_2d::dcell_array, N_array_2d::fcell_array, G_debug(), G_fatal_error(), G_is_c_null_value(), G_is_d_null_value(), G_is_f_null_value(), G_set_c_null_value(), G_set_d_null_value(), G_set_f_null_value(), N_array_2d::rows_intern, and N_array_2d::type.

Referenced by N_copy_gradient_field_2d().

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.

The arrays must have the same size and the same offset.

The array data types can be mixed, the values are automatically casted and the null values are set accordingly.

If you copy a float array to a double array, the values are casted to DCELL and the null values are converted from FCELL-null to DCELL-null

Parameters
sourceN_array_3d *
targetN_array_3d *
Returns
void

Definition at line 498 of file N_arrays_calc.c.

References N_array_3d::cols_intern, N_array_3d::dcell_array, N_array_3d::depths_intern, N_array_3d::fcell_array, G3d_isNullValueNum(), G3d_setNullValue(), G_debug(), G_fatal_error(), N_array_3d::rows_intern, and N_array_3d::type.

Referenced by N_copy_gradient_field_3d().

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.

All arrays must have equal sizes and offsets. The complete data array inclusively offsets is used for calucaltions. Only non-null values are computed. If one array value is null, the result array value will be null too.

If a division with zero is detected, the resulting arrays value will set to null and not to NaN.

The result array is optional, if the result arrays points to NULL, a new array will be allocated with the largest arrays data type (CELL, FCELL or DCELL) used by the input arrays.

the array computations can be of the following forms:

  • result = a + b -> N_ARRAY_SUM
  • result = a - b -> N_ARRAY_DIF
  • result = a * b -> N_ARRAY_MUL
  • result = a / b -> N_ARRAY_DIV
Parameters
aN_array_2d * - first input array
bN_array_2d * - second input array
resultN_array_2d * - the optional result array
type- the type of calculation
Returns
N_array_2d * - the pointer to the result array

Definition at line 306 of file N_arrays_calc.c.

References N_array_2d::cols, dialogs::cols, N_array_2d::cols_intern, G_debug(), G_fatal_error(), N_alloc_array_2d(), N_ARRAY_DIF, N_ARRAY_DIV, N_ARRAY_MUL, N_ARRAY_SUM, N_get_array_2d_d_value(), N_is_array_2d_value_null(), N_put_array_2d_c_value(), N_put_array_2d_d_value(), N_put_array_2d_f_value(), N_put_array_2d_value_null(), NULL, N_array_2d::offset, N_array_2d::rows, N_array_2d::rows_intern, and N_array_2d::type.

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.

All arrays must have equal sizes and offsets. The complete data array inclusively offsets is used for calucaltions. Only non-null values are used. If one array value is null, the result array value will be null too.

If a division with zero is detected, the resulting arrays value will set to null and not to NaN.

The result array is optional, if the result arrays points to NULL, a new array will be allocated with the largest arrays data type (FCELL_TYPE or DCELL_TYPE) used by the input arrays.

the calculations are of the following form:

  • result = a + b -> N_ARRAY_SUM
  • result = a - b -> N_ARRAY_DIF
  • result = a * b -> N_ARRAY_MUL
  • result = a / b -> N_ARRAY_DIV
Parameters
aN_array_3d * - first input array
bN_array_3d * - second input array
resultN_array_3d * - the optional result array
type- the type of calculation
Returns
N_array_3d * - the pointer to the result array

Definition at line 737 of file N_arrays_calc.c.

References N_array_3d::cols, dialogs::cols, N_array_3d::cols_intern, N_array_3d::depths, N_array_3d::depths_intern, G_debug(), G_fatal_error(), N_alloc_array_3d(), N_ARRAY_DIF, N_ARRAY_DIV, N_ARRAY_MUL, N_ARRAY_SUM, N_get_array_3d_d_value(), N_is_array_3d_value_null(), N_put_array_3d_d_value(), N_put_array_3d_f_value(), N_put_array_3d_value_null(), NULL, N_array_3d::offset, N_array_3d::rows, N_array_3d::rows_intern, and N_array_3d::type.

double N_norm_array_2d ( N_array_2d a,
N_array_2d b,
int  type 
)

Calculate the norm of the two input arrays.

The norm can be of type N_MAXIMUM_NORM or N_EUKLID_NORM. All arrays must have equal sizes and offsets. The complete data array inclusively offsets is used for norm calucaltion. Only non-null values are used to calcualte the norm.

Parameters
aN_array_2d *
bN_array_2d *
typethe type of the norm -> N_MAXIMUM_NORM, N_EUKLID_NORM
Returns
double the calculated norm

Definition at line 146 of file N_arrays_calc.c.

References N_array_2d::cell_array, N_array_2d::cols_intern, N_array_2d::dcell_array, N_array_2d::fcell_array, G_debug(), G_fatal_error(), G_is_f_null_value(), N_EUKLID_NORM, N_MAXIMUM_NORM, N_array_2d::rows_intern, and N_array_2d::type.

double N_norm_array_3d ( N_array_3d a,
N_array_3d b,
int  type 
)

Calculate the norm of the two input arrays.

The norm can be of type N_MAXIMUM_NORM or N_EUKLID_NORM. All arrays must have equal sizes and offsets. The complete data array inclusively offsets is used for norm calucaltion. Only non-null values are used to calcualte the norm.

Parameters
aN_array_3d *
bN_array_3d *
typethe type of the norm -> N_MAXIMUM_NORM, N_EUKLID_NORM
Returns
double the calculated norm

Definition at line 574 of file N_arrays_calc.c.

References N_array_3d::cols_intern, N_array_3d::dcell_array, N_array_3d::depths_intern, N_array_3d::fcell_array, G3d_isNullValueNum(), G_debug(), G_fatal_error(), N_EUKLID_NORM, N_MAXIMUM_NORM, N_array_3d::rows_intern, and N_array_3d::type.