19 #include "grass/N_pde.h"
20 #include "grass/glocale.h"
73 if (rows < 1 || cols < 1)
74 G_fatal_error(
"N_alloc_array_2d: cols and rows should be > 0");
76 if (type != CELL_TYPE && type != FCELL_TYPE && type != DCELL_TYPE)
78 (
"N_alloc_array_2d: Wrong data type, should be CELL_TYPE, FCELL_TYPE or DCELL_TYPE");
92 if (data->
type == CELL_TYPE) {
97 "N_alloc_array_2d: CELL array allocated rows_intern %i cols_intern %i offset %i",
100 else if (data->
type == FCELL_TYPE) {
105 "N_alloc_array_2d: FCELL array allocated rows_intern %i cols_intern %i offset %i",
109 else if (data->
type == DCELL_TYPE) {
114 "N_alloc_array_2d: DCELL array allocated rows_intern %i cols_intern %i offset %i",
131 G_debug(3,
"N_free_array_2d: free N_array_2d");
234 "N_is_array_2d_value_null: null value is of type CELL at pos [%i][%i]",
243 "N_is_array_2d_value_null: null value is of type FCELL at pos [%i][%i]",
252 "N_is_array_2d_value_null: null value is of type DCELL at pos [%i][%i]",
263 "N_is_array_2d_value_null: null value is of type CELL at pos [%i][%i]",
270 data->
offset]), CELL_TYPE);
274 "N_is_array_2d_value_null: null value is of type FCELL at pos [%i][%i]",
281 data->
offset]), FCELL_TYPE);
285 "N_is_array_2d_value_null: null value is of type DCELL at pos [%i][%i]",
292 data->
offset]), DCELL_TYPE);
317 switch (data->
type) {
323 return (CELL) fvalue;
326 return (CELL) dvalue;
349 switch (data->
type) {
352 return (FCELL)
value;
355 return (FCELL) fvalue;
358 return (FCELL) dvalue;
381 switch (data->
type) {
384 return (DCELL)
value;
387 return (DCELL) fvalue;
390 return (DCELL) dvalue;
411 G_debug(6,
"N_put_array_2d_value: put value to array");
459 "N_put_array_2d_value_null: put null value to array pos [%i][%i]",
526 switch (data->
type) {
528 fvalue = (FCELL) value;
532 dvalue = (DCELL) value;
556 switch (data->
type) {
558 cvalue = (CELL) value;
562 dvalue = (DCELL) value;
586 switch (data->
type) {
588 cvalue = (CELL) value;
592 fvalue = (FCELL) value;
611 fprintf(stdout,
"N_array_2d \n");
612 fprintf(stdout,
"Cols %i\n", data->
cols);
613 fprintf(stdout,
"Rows: %i\n", data->
rows);
614 fprintf(stdout,
"Array type: %i\n", data->
type);
615 fprintf(stdout,
"Offset: %i\n", data->
offset);
616 fprintf(stdout,
"Internal cols: %i\n", data->
cols_intern);
617 fprintf(stdout,
"Internal rows: %i\n", data->
rows_intern);
618 fprintf(stdout,
"CELL array pointer: %p\n", data->
cell_array);
619 fprintf(stdout,
"FCELL array pointer: %p\n", data->
fcell_array);
620 fprintf(stdout,
"DCELL array pointer: %p\n", data->
dcell_array);
640 for (j = 0 - data->
offset; j < data->rows + data->
offset; j++) {
642 if (data->
type == CELL_TYPE)
644 else if (data->
type == FCELL_TYPE)
646 else if (data->
type == DCELL_TYPE)
649 fprintf(stdout,
"\n");
651 fprintf(stdout,
"\n");
728 if (rows < 1 || cols < 1 || depths < 1)
730 (
"N_alloc_array_3d: depths, cols and rows should be > 0");
732 if (type != DCELL_TYPE && type != FCELL_TYPE)
734 (
"N_alloc_array_3d: Wrong data type, should be FCELL_TYPE or DCELL_TYPE");
749 if (data->
type == FCELL_TYPE) {
754 "N_alloc_array_3d: float array allocated rows_intern %i cols_intern %i depths_intern %i offset %i",
758 else if (data->
type == DCELL_TYPE) {
763 "N_alloc_array_3d: double array allocated rows_intern %i cols_intern %i depths_intern %i offset %i",
781 G_debug(3,
"N_free_array_3d: free N_array_3d");
884 "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
896 "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
910 "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
926 "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
963 switch (data->
type) {
966 return (
float)fvalue;
969 return (
float)dvalue;
992 switch (data->
type) {
996 return (
double)fvalue;
999 return (
double)dvalue;
1022 G_debug(6,
"N_put_array_3d_value: put value to array at pos [%i][%i][%i]",
1030 = *((
float *)
value);
1037 = *((
double *)
value);
1077 "N_put_array_3d_value_null: put null value to array at pos [%i][%i][%i]",
1104 fcell_array[(depth +
1118 dcell_array[(depth +
1150 if (data->
type == DCELL_TYPE) {
1151 dval = (double)value;
1177 if (data->
type == FCELL_TYPE) {
1178 fval = (double)value;
1197 fprintf(stdout,
"N_array_3d \n");
1198 fprintf(stdout,
"Cols %i\n", data->
cols);
1199 fprintf(stdout,
"Rows: %i\n", data->
rows);
1200 fprintf(stdout,
"Depths: %i\n", data->
depths);
1201 fprintf(stdout,
"Array type: %i\n", data->
type);
1202 fprintf(stdout,
"Offset: %i\n", data->
offset);
1203 fprintf(stdout,
"Internal cols: %i\n", data->
cols_intern);
1204 fprintf(stdout,
"Internal rows: %i\n", data->
rows_intern);
1205 fprintf(stdout,
"Internal depths: %i\n", data->
depths_intern);
1206 fprintf(stdout,
"FCELL array pointer: %p\n", data->
fcell_array);
1207 fprintf(stdout,
"DCELL array pointer: %p\n", data->
dcell_array);
1226 for (k = 0; k < data->
depths; k++) {
1227 for (j = 0; j < data->
rows; j++) {
1228 for (i = 0; i < data->
cols; i++) {
1229 if (data->
type == FCELL_TYPE)
1231 else if (data->
type == DCELL_TYPE)
void N_free_array_2d(N_array_2d *data)
Release the memory of a N_array_2d structure.
void G_free(void *buf)
Free allocated memory.
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 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...
void G3d_setNullValue(void *c, int nofElts, int type)
Fills the vector pointed to by c with nofElts NULL-values of type.
void N_free_array_3d(N_array_3d *data)
Release the memory of a N_array_3d.
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.
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.
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_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.
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_3d_info(N_array_3d *data)
Write the info of the array to stdout.
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.
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.
void N_print_array_2d(N_array_2d *data)
Write info and content of the N_array_2d struct to stdout.
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_print_array_3d(N_array_3d *data)
Write info and content of the array data to stdout.
void G_set_f_null_value(FCELL *fcellVals, int numVals)
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 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.
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.
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.
int N_get_array_3d_type(N_array_3d *array)
Return the data type of the N_array_3d.
int N_get_array_2d_type(N_array_2d *array)
Return the data type of the N_array_2d struct.
void G_set_c_null_value(CELL *cellVals, int numVals)
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.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
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.
int G_is_null_value(const void *rast, RASTER_MAP_TYPE data_type)
If the data_type is CELL_TYPE, calls G_is_c_null_value ((CELL *) rast); If the data_type is FCELL_TYP...