Loading...
Searching...
No Matches
n_arrays.c File Reference
`#include <math.h>`
`#include <grass/N_pde.h>`
`#include <grass/raster.h>`
`#include <grass/glocale.h>`
Include dependency graph for n_arrays.c:

Go to the source code of this file.

## Functions

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_free_array_2d (N_array_2d *data)
| Release the memory of a N_array_2d structure.
int | N_get_array_2d_type (N_array_2d *array)
| Return the data type of the N_array_2d struct.
void | N_get_array_2d_value (N_array_2d *data, int col, int row, void *value)
| Write the value of the N_array_2d struct at position col, row to value.
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.
CELL | N_get_array_2d_c_value (N_array_2d *data, int col, int row)
| Returns the value of type CELL at position col, row.
FCELL | N_get_array_2d_f_value (N_array_2d *data, int col, int row)
| Returns the value of type FCELL at position col, row.
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_2d_value (N_array_2d *data, int col, int row, char *value)
| Writes a value to the N_array_2d struct at position col, row.
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_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_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_print_array_2d_info (N_array_2d *data)
| This function writes the data info of the array data to stdout.
void | N_print_array_2d (N_array_2d *data)
| Write info and content of the N_array_2d struct to stdout.
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.
void | N_free_array_3d (N_array_3d *data)
| Release the memory of a N_array_3d.
int | N_get_array_3d_type (N_array_3d *array)
| Return the data type of the N_array_3d.
void | N_get_array_3d_value (N_array_3d *data, int col, int row, int depth, void *value)
| This function writes the value of N_array_3d data at position col, row, depth to the variable value.
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, otherwise 0.
float | N_get_array_3d_f_value (N_array_3d *data, int col, int row, int depth)
| This function returns the value of type float 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_3d_value (N_array_3d *data, int col, int row, int depth, char *value)
| This function writes a value to the N_array_3d data at position col, row, depth.
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_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_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 | N_print_array_3d_info (N_array_3d *data)
| Write the info of the array to stdout.
void | N_print_array_3d (N_array_3d *data)
| Write info and content of the array data to stdout.

## Function Documentation

## N_alloc_array_2d()

N_array_2d * N_alloc_array_2d | ( | int | cols,
|  | int | rows,
|  | int | offset,
|  | int | type )

Allocate memory for a N_array_2d data structure.

This function allocates memory for an array of type N_array_2d and returns the pointer to the new allocated memory.
The data type of this array is set by "type" and must be CELL_TYPE, FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types. The offset sets the number of boundary cols and rows. This option is useful to generate homogeneous Neumann boundary conditions around an array or to establish overlapping boundaries. The array is initialized with 0 by default.
If the offset is greater then 0, negative indices are possible.

The data structure of a array with 3 rows and cols and an offset of 1 will looks like this:

    0 0 0 0 0
    0 0 1 2 0
    0 3 4 5 0
    0 6 7 8 0
    0 0 0 0 0

0 is the boundary.
Internal a one dimensional array is allocated to save memory and to speed up the memory access. To access the one dimensional array with a two dimensional index use the provided get and put functions. The internal representation of the above data will look like this:

    0 0 0 0 0 0 0 1 2 0 0 3 4 5 0 0 6 7 8 0 0 0 0 0 0

Parameters

  cols | int
  rows | int
  offset | int
  type | int

Returns
  N_array_2d *

Definition at line 75 of file n_arrays.c.

References G_debug(), G_fatal_error(), and NULL.

Referenced by N_alloc_gradient_field_2d(), N_alloc_gwflow_data2d(), N_alloc_gwflow_data3d(), N_alloc_solute_transport_data2d(), N_assemble_les_2d_param(), N_math_array_2d(), and N_read_rast_to_array_2d().

## N_alloc_array_3d()

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.

This functions allocates an array of type N_array_3d and returns a pointer to the new allocated memory.
The data type of this array set by "type" must be FCELL_TYPE or DCELL_TYPE accordingly to the raster3d map data types. The offsets sets the number of boundary cols, rows and depths. This option is useful to generate homogeneous Neumann boundary conditions around an array or to establish overlapping boundaries. The arrays are initialized with 0 by default.
If the offset is greater then 0, negative indices are possible. The data structure of a array with 3 depths, rows and cols and an offset of 1 will looks like this:

    0  0  0  0  0
    0  0  0  0  0
    0  0  0  0  0
    0  0  0  0  0
    0  0  0  0  0

    0  0  0  0  0
    0  0  1  2  0
    0  3  4  5  0
    0  6  7  8  0
    0  0  0  0  0

    0  0  0  0  0
    0  9 10 11  0
    0 12 13 14  0
    0 15 16 17  0
    0  0  0  0  0

    0  0  0  0  0
    0 18 19 20  0
    0 21 22 23  0
    0 24 25 26  0
    0  0  0  0  0

    0  0  0  0  0
    0  0  0  0  0
    0  0  0  0  0
    0  0  0  0  0
    0  0  0  0  0

The depth counts from the bottom to the top.

Internal a one dimensional array is allocated to speed up the memory access. To access the dimensional array with a three dimensional indexing use the provided get and put functions.

Parameters

  cols | int
  rows | int
  depths | int
  offset | int
  type | int

Returns
  N_array_3d *

Definition at line 719 of file n_arrays.c.

References G_debug(), G_fatal_error(), and NULL.

Referenced by N_alloc_gradient_field_3d(), N_alloc_gwflow_data3d(), N_alloc_solute_transport_data3d(), N_assemble_les_3d_param(), N_math_array_3d(), and N_read_rast3d_to_array_3d().

## N_free_array_2d()

void N_free_array_2d | ( | N_array_2d * | data | ) |

Release the memory of a N_array_2d structure.

Parameters

  data | N_array_2d *

Returns
  void

Definition at line 132 of file n_arrays.c.

References G_debug(), G_free(), and NULL.

Referenced by N_assemble_les_2d_param(), N_free_gradient_field_2d(), N_free_gwflow_data2d(), N_free_gwflow_data3d(), and N_free_solute_transport_data2d().

## N_free_array_3d()

void N_free_array_3d | ( | N_array_3d * | data | ) |

Release the memory of a N_array_3d.

Parameters

  data | N_array_3d *

Returns
  void

Definition at line 774 of file n_arrays.c.

References G_debug(), G_free(), and NULL.

Referenced by N_assemble_les_3d_param(), N_free_gradient_field_3d(), N_free_gwflow_data3d(), and N_free_solute_transport_data3d().

## N_get_array_2d_c_value()

CELL N_get_array_2d_c_value | ( | N_array_2d * | data,
|  | int | col,
|  | int | row )

Returns the value of type CELL at position col, row.

The data array can be of type CELL, FCELL or DCELL, the value will be casted to the CELL type.

Parameters

  data | N_array_2d *
  col | int
  row | int

Returns
  CELL

Definition at line 314 of file n_arrays.c.

References N_get_array_2d_value().

Referenced by N_assemble_les_2d_param(), N_gwflow_2d_calc_water_budget(), N_les_integrate_dirichlet_2d(), N_print_array_2d(), and N_write_array_2d_to_rast().

## N_get_array_2d_d_value()

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.

The data array can be of type CELL, FCELL or DCELL, the value will be casted to the DCELL type.

Parameters

  data | N_array_2d *
  col | int
  row | int

Returns
  DCELL

Definition at line 380 of file n_arrays.c.

References N_get_array_2d_value().

Referenced by N_assemble_les_2d_param(), N_calc_array_2d_stats(), N_calc_solute_transport_transmission_2d(), N_callback_gwflow_2d(), N_callback_gwflow_3d(), N_callback_solute_transport_2d(), N_compute_gradient_field_2d(), N_get_gradient_2d(), N_get_gradient_neighbours_2d(), N_gwflow_2d_calc_water_budget(), N_les_integrate_dirichlet_2d(), N_math_array_2d(), N_print_array_2d(), and N_write_array_2d_to_rast().

## N_get_array_2d_f_value()

FCELL N_get_array_2d_f_value | ( | N_array_2d * | data,
|  | int | col,
|  | int | row )

Returns the value of type FCELL at position col, row.

The data array can be of type CELL, FCELL or DCELL, the value will be casted to the FCELL type.

Parameters

  data | N_array_2d *
  col | int
  row | int

Returns
  FCELL

Definition at line 347 of file n_arrays.c.

References N_get_array_2d_value().

Referenced by N_print_array_2d(), and N_write_array_2d_to_rast().

## N_get_array_2d_type()

int N_get_array_2d_type | ( | N_array_2d * | array | ) |

Return the data type of the N_array_2d struct.

The data type can be CELL_TYPE, FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.

Parameters

  array | N_array_2d *

Returns
  type int

Definition at line 164 of file n_arrays.c.

References N_array_2d::type.

## N_get_array_2d_value()

void N_get_array_2d_value | ( | N_array_2d * | data,
|  | int | col,
|  | int | row,
|  | void * | value )

Write the value of the N_array_2d struct at position col, row to value.

The value must be of the same type as the array. Otherwise you will risk data losses.

Parameters

  data | N_array_2d *
  col | int
  row | int
  value | void * - this variable contains the array value at col, row position

Returns
  void

Definition at line 182 of file n_arrays.c.

References NULL.

Referenced by N_get_array_2d_c_value(), N_get_array_2d_d_value(), and N_get_array_2d_f_value().

## N_get_array_3d_d_value()

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.

The data type can be FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.

Parameters

  data | N_array_3d *
  col | int
  row | int
  depth | int

Returns
  double

Definition at line 979 of file n_arrays.c.

References N_get_array_3d_value().

Referenced by N_assemble_les_3d_param(), N_calc_array_3d_stats(), N_callback_gwflow_3d(), N_callback_solute_transport_3d(), N_compute_gradient_field_3d(), N_get_gradient_3d(), N_gwflow_3d_calc_water_budget(), N_les_integrate_dirichlet_3d(), N_math_array_3d(), N_print_array_3d(), and N_write_array_3d_to_rast3d().

## N_get_array_3d_f_value()

float N_get_array_3d_f_value | ( | N_array_3d * | data,
|  | int | col,
|  | int | row,
|  | int | depth )

This function returns the value of type float at position col, row, depth.

The data type can be FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.

Parameters

  data | N_array_3d *
  col | int
  row | int
  depth | int

Returns
  float

Definition at line 948 of file n_arrays.c.

References N_get_array_3d_value().

Referenced by N_print_array_3d(), and N_write_array_3d_to_rast3d().

## N_get_array_3d_type()

int N_get_array_3d_type | ( | N_array_3d * | array | ) |

Return the data type of the N_array_3d.

The data type can be FCELL_TYPE and DCELL_TYPE accordingly to the raster map data types.

Parameters

  array | N_array_3d *

Returns
  type int – FCELL_TYPE or DCELL_TYPE

Definition at line 803 of file n_arrays.c.

References N_array_3d::type.

## N_get_array_3d_value()

void N_get_array_3d_value | ( | N_array_3d * | data,
|  | int | col,
|  | int | row,
|  | int | depth,
|  | void * | value )

This function writes the value of N_array_3d data at position col, row, depth to the variable value.

The value must be from the same type as the array. Otherwise you will risk data losses.

Parameters

  data | N_array_3d *
  col | int
  row | int
  depth | int
  value | void *

Returns
  void

Definition at line 822 of file n_arrays.c.

References NULL.

Referenced by N_get_array_3d_d_value(), and N_get_array_3d_f_value().

## N_is_array_2d_value_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.

This function checks automatically the type of the array and checks for the data type null value.

Parameters

  data | N_array_2d *
  col | int
  row | int

Returns
  int - 1 = is null, 0 otherwise

Definition at line 231 of file n_arrays.c.

References G_debug(), and NULL.

Referenced by N_calc_array_2d_stats(), N_calc_solute_transport_transmission_2d(), N_compute_gradient_field_2d(), and N_math_array_2d().

## N_is_array_3d_value_null()

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, otherwise 0.

This function checks automatically the type of the array and checks for the data type null value.

Parameters

  data | N_array_3d *
  col | int
  row | int
  depth | int

Returns
  void

Definition at line 873 of file n_arrays.c.

References G_debug(), and NULL.

Referenced by N_calc_array_3d_stats(), N_compute_gradient_field_3d(), and N_math_array_3d().

## N_print_array_2d()

void N_print_array_2d | ( | N_array_2d * | data | ) |

Write info and content of the N_array_2d struct to stdout.

Offsets are ignored

Parameters

  data | N_array_2d *

Returns
  void

Definition at line 628 of file n_arrays.c.

References N_get_array_2d_c_value(), N_get_array_2d_d_value(), N_get_array_2d_f_value(), and N_print_array_2d_info().

## N_print_array_2d_info()

void N_print_array_2d_info | ( | N_array_2d * | data | ) |

This function writes the data info of the array data to stdout.

Parameters

  data | N_array_2d *

Returns
  void

Definition at line 603 of file n_arrays.c.

Referenced by N_print_array_2d(), and N_print_gradient_field_2d_info().

## N_print_array_3d()

void N_print_array_3d | ( | N_array_3d * | data | ) |

Write info and content of the array data to stdout.

Offsets are ignored

Parameters

  data | N_array_2d *

Returns
  void

Definition at line 1196 of file n_arrays.c.

References N_get_array_3d_d_value(), N_get_array_3d_f_value(), and N_print_array_3d_info().

## N_print_array_3d_info()

void N_print_array_3d_info | ( | N_array_3d * | data | ) |

Write the info of the array to stdout.

Parameters

  data | N_array_3d *

Returns
  void

Definition at line 1170 of file n_arrays.c.

Referenced by N_print_array_3d(), and N_print_gradient_field_3d_info().

## N_put_array_2d_c_value()

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.

Parameters

  data | N_array_2d *
  col | int
  row | int
  value | CELL

Returns
  void

Definition at line 516 of file n_arrays.c.

References N_put_array_2d_value().

Referenced by N_assemble_les_2d_param(), N_math_array_2d(), and N_read_rast_to_array_2d().

## N_put_array_2d_d_value()

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.

Parameters

  data | N_array_2d *
  col | int
  row | int
  value | DCELL

Returns
  void

Definition at line 576 of file n_arrays.c.

References N_put_array_2d_value().

Referenced by N_calc_solute_transport_disptensor_2d(), N_calc_solute_transport_transmission_2d(), N_compute_gradient_field_2d(), N_compute_gradient_field_components_2d(), N_gwflow_2d_calc_water_budget(), N_math_array_2d(), and N_read_rast_to_array_2d().

## N_put_array_2d_f_value()

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.

Parameters

  data | N_array_2d *
  col | int
  row | int
  value | FCELL

Returns
  void

Definition at line 546 of file n_arrays.c.

References N_put_array_2d_value().

Referenced by N_math_array_2d(), and N_read_rast_to_array_2d().

## N_put_array_2d_value()

void N_put_array_2d_value | ( | N_array_2d * | data,
|  | int | col,
|  | int | row,
|  | char * | value )

Writes a value to the N_array_2d struct at position col, row.

The value will be automatically cast to the array type.

Parameters

  data | N_array_2d *
  col | int
  row | int
  value | char *

Returns
  void

Definition at line 412 of file n_arrays.c.

References G_debug(), and NULL.

Referenced by N_put_array_2d_c_value(), N_put_array_2d_d_value(), and N_put_array_2d_f_value().

## N_put_array_2d_value_null()

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.

The null value will be automatically set to the array data type (CELL, FCELL or DCELL).

Parameters

  data | N_array_2d *
  col | int
  row | int

Returns
  void

Definition at line 459 of file n_arrays.c.

References G_debug(), and NULL.

Referenced by N_math_array_2d(), and N_read_rast_to_array_2d().

## N_put_array_3d_d_value()

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.

Parameters

  data | N_array_3d *
  col | int
  row | int
  depth | int
  value | double

Returns
  void

Definition at line 1148 of file n_arrays.c.

References N_put_array_3d_value().

Referenced by N_assemble_les_3d_param(), N_calc_solute_transport_disptensor_3d(), N_compute_gradient_field_3d(), N_compute_gradient_field_components_3d(), N_gwflow_3d_calc_water_budget(), N_math_array_3d(), and N_read_rast3d_to_array_3d().

## N_put_array_3d_f_value()

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.

Parameters

  data | N_array_3d *
  col | int
  row | int
  depth | int
  value | float

Returns
  void

Definition at line 1121 of file n_arrays.c.

References N_put_array_3d_value().

Referenced by N_math_array_3d(), and N_read_rast3d_to_array_3d().

## N_put_array_3d_value()

void N_put_array_3d_value | ( | N_array_3d * | data,
|  | int | col,
|  | int | row,
|  | int | depth,
|  | char * | value )

This function writes a value to the N_array_3d data at position col, row, depth.

The value will be automatically cast to the array type.

Parameters

  data | N_array_3d *
  col | int
  row | int
  depth | int
  value | char *

Returns
  void

Definition at line 1010 of file n_arrays.c.

References G_debug(), and NULL.

Referenced by N_put_array_3d_d_value(), and N_put_array_3d_f_value().

## N_put_array_3d_value_null()

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.

The null value will be automatically set to the array type.

Parameters

  data | N_array_3d *
  col | int
  row | int
  depth | int

Returns
  void

Definition at line 1060 of file n_arrays.c.

References G_debug(), and NULL.

Referenced by N_math_array_3d(), and N_read_rast3d_to_array_3d().