21 #include <grass/N_pde.h>
22 #include <grass/raster.h>
23 #include <grass/glocale.h>
76 if (rows < 1 || cols < 1)
77 G_fatal_error(
"N_alloc_array_2d: cols and rows should be > 0");
79 if (type != CELL_TYPE && type != FCELL_TYPE && type != DCELL_TYPE)
81 (
"N_alloc_array_2d: Wrong data type, should be CELL_TYPE, FCELL_TYPE or DCELL_TYPE");
95 if (data->
type == CELL_TYPE) {
100 "N_alloc_array_2d: CELL array allocated rows_intern %i cols_intern %i offset %i",
103 else if (data->
type == FCELL_TYPE) {
108 "N_alloc_array_2d: FCELL array allocated rows_intern %i cols_intern %i offset %i",
112 else if (data->
type == DCELL_TYPE) {
117 "N_alloc_array_2d: DCELL array allocated rows_intern %i cols_intern %i offset %i",
134 G_debug(3,
"N_free_array_2d: free N_array_2d");
237 "N_is_array_2d_value_null: null value is of type CELL at pos [%i][%i]",
239 return Rast_is_null_value((
void *)
246 "N_is_array_2d_value_null: null value is of type FCELL at pos [%i][%i]",
248 return Rast_is_null_value((
void *)
255 "N_is_array_2d_value_null: null value is of type DCELL at pos [%i][%i]",
257 return Rast_is_null_value((
void *)
266 "N_is_array_2d_value_null: null value is of type CELL at pos [%i][%i]",
268 return Rast_is_null_value((
void *)
273 data->
offset]), CELL_TYPE);
277 "N_is_array_2d_value_null: null value is of type FCELL at pos [%i][%i]",
279 return Rast_is_null_value((
void *)
284 data->
offset]), FCELL_TYPE);
288 "N_is_array_2d_value_null: null value is of type DCELL at pos [%i][%i]",
290 return Rast_is_null_value((
void *)
295 data->
offset]), DCELL_TYPE);
320 switch (data->
type) {
326 return (CELL) fvalue;
329 return (CELL) dvalue;
352 switch (data->
type) {
355 return (FCELL) value;
358 return (FCELL) fvalue;
361 return (FCELL) dvalue;
384 switch (data->
type) {
387 return (DCELL) value;
390 return (DCELL) fvalue;
393 return (DCELL) dvalue;
414 G_debug(6,
"N_put_array_2d_value: put value to array");
433 data->
offset] = *((CELL *) value);
437 data->
offset] = *((FCELL *) value);
441 data->
offset] = *((DCELL *) value);
462 "N_put_array_2d_value_null: put null value to array pos [%i][%i]",
467 Rast_set_c_null_value((
void *)
473 Rast_set_f_null_value((
void *)
479 Rast_set_d_null_value((
void *)
487 Rast_set_c_null_value((
void *)
495 Rast_set_f_null_value((
void *)
503 Rast_set_d_null_value((
void *)
529 switch (data->
type) {
531 fvalue = (FCELL) value;
535 dvalue = (DCELL) value;
559 switch (data->
type) {
561 cvalue = (CELL) value;
565 dvalue = (DCELL) value;
589 switch (data->
type) {
591 cvalue = (CELL) value;
595 fvalue = (FCELL) value;
614 fprintf(stdout,
"N_array_2d \n");
615 fprintf(stdout,
"Cols %i\n", data->
cols);
616 fprintf(stdout,
"Rows: %i\n", data->
rows);
617 fprintf(stdout,
"Array type: %i\n", data->
type);
618 fprintf(stdout,
"Offset: %i\n", data->
offset);
619 fprintf(stdout,
"Internal cols: %i\n", data->
cols_intern);
620 fprintf(stdout,
"Internal rows: %i\n", data->
rows_intern);
621 fprintf(stdout,
"CELL array pointer: %p\n", data->
cell_array);
622 fprintf(stdout,
"FCELL array pointer: %p\n", data->
fcell_array);
623 fprintf(stdout,
"DCELL array pointer: %p\n", data->
dcell_array);
643 for (j = 0 - data->
offset; j < data->rows + data->
offset; j++) {
644 for (i = 0 - data->
offset; i < data->cols + data->
offset; i++) {
645 if (data->
type == CELL_TYPE)
647 else if (data->
type == FCELL_TYPE)
649 else if (data->
type == DCELL_TYPE)
652 fprintf(stdout,
"\n");
654 fprintf(stdout,
"\n");
731 if (rows < 1 || cols < 1 || depths < 1)
733 (
"N_alloc_array_3d: depths, cols and rows should be > 0");
735 if (type != DCELL_TYPE && type != FCELL_TYPE)
737 (
"N_alloc_array_3d: Wrong data type, should be FCELL_TYPE or DCELL_TYPE");
752 if (data->
type == FCELL_TYPE) {
757 "N_alloc_array_3d: float array allocated rows_intern %i cols_intern %i depths_intern %i offset %i",
761 else if (data->
type == DCELL_TYPE) {
766 "N_alloc_array_3d: double array allocated rows_intern %i cols_intern %i depths_intern %i offset %i",
784 G_debug(3,
"N_free_array_3d: free N_array_3d");
887 "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
889 return Rast3d_is_null_value_num((
void *)
899 "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
901 return Rast3d_is_null_value_num((
void *)
913 "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
915 return Rast3d_is_null_value_num((
void *)
929 "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
931 return Rast3d_is_null_value_num((
void *)
966 switch (data->
type) {
969 return (
float)fvalue;
972 return (
float)dvalue;
995 switch (data->
type) {
999 return (
double)fvalue;
1002 return (
double)dvalue;
1025 G_debug(6,
"N_put_array_3d_value: put value to array at pos [%i][%i][%i]",
1033 = *((
float *)value);
1040 = *((
double *)value);
1080 "N_put_array_3d_value_null: put null value to array at pos [%i][%i][%i]",
1085 Rast3d_set_null_value((
void *)
1094 Rast3d_set_null_value((
void *)
1105 Rast3d_set_null_value((
void *)
1107 fcell_array[(depth +
1119 Rast3d_set_null_value((
void *)
1121 dcell_array[(depth +
1153 if (data->
type == DCELL_TYPE) {
1154 dval = (double)value;
1180 if (data->
type == FCELL_TYPE) {
1181 fval = (double)value;
1200 fprintf(stdout,
"N_array_3d \n");
1201 fprintf(stdout,
"Cols %i\n", data->
cols);
1202 fprintf(stdout,
"Rows: %i\n", data->
rows);
1203 fprintf(stdout,
"Depths: %i\n", data->
depths);
1204 fprintf(stdout,
"Array type: %i\n", data->
type);
1205 fprintf(stdout,
"Offset: %i\n", data->
offset);
1206 fprintf(stdout,
"Internal cols: %i\n", data->
cols_intern);
1207 fprintf(stdout,
"Internal rows: %i\n", data->
rows_intern);
1208 fprintf(stdout,
"Internal depths: %i\n", data->
depths_intern);
1209 fprintf(stdout,
"FCELL array pointer: %p\n", data->
fcell_array);
1210 fprintf(stdout,
"DCELL array pointer: %p\n", data->
dcell_array);
1229 for (k = 0; k < data->
depths; k++) {
1230 for (j = 0; j < data->
rows; j++) {
1231 for (i = 0; i < data->
cols; i++) {
1232 if (data->
type == FCELL_TYPE)
1234 else if (data->
type == DCELL_TYPE)
void G_free(void *buf)
Free allocated memory.
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.
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.
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_print_array_3d_info(N_array_3d *data)
Write the info of the array to stdout.
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.
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.
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_free_array_3d(N_array_3d *data)
Release the memory of a N_array_3d.
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.
int N_get_array_2d_type(N_array_2d *array)
Return the data type of the N_array_2d struct.
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.
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(N_array_2d *data)
Write info and content of the N_array_2d struct to stdout.
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_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.
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_print_array_2d_info(N_array_2d *data)
This function writes the data info of the array data to stdout.
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_free_array_2d(N_array_2d *data)
Release the memory of a N_array_2d 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_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 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_get_array_3d_type(N_array_3d *array)
Return the data type of the N_array_3d.
void N_print_array_3d(N_array_3d *data)
Write info and content of the array data to stdout.