20#include <grass/N_pde.h>
21#include <grass/raster.h>
22#include <grass/glocale.h>
47 int x, y, cols, rows, type;
50 struct Cell_head region;
61 map = Rast_open_old(
name,
"");
63 type = Rast_get_map_type(map);
69 if (type == DCELL_TYPE) {
72 if (type == FCELL_TYPE) {
75 if (type == CELL_TYPE) {
81 if (data->cols != cols)
82 G_fatal_error(
"N_read_rast_to_array_2d: the data array size is "
83 "different from the current region settings");
84 if (data->rows != rows)
85 G_fatal_error(
"N_read_rast_to_array_2d: the data array size is "
86 "different from the current region settings");
89 rast = Rast_allocate_buf(type);
93 for (y = 0; y < rows; y++) {
96 Rast_get_row(map, rast, y, type);
98 for (
x = 0, ptr = rast;
x < cols;
100 if (type == CELL_TYPE) {
101 if (Rast_is_c_null_value(ptr)) {
105 if (data->type == CELL_TYPE)
107 (CELL) * (CELL *)ptr);
108 if (data->type == FCELL_TYPE)
110 (FCELL) * (CELL *)ptr);
111 if (data->type == DCELL_TYPE)
113 (DCELL) * (CELL *)ptr);
116 if (type == FCELL_TYPE) {
117 if (Rast_is_f_null_value(ptr)) {
121 if (data->type == CELL_TYPE)
123 (CELL) * (FCELL *)ptr);
124 if (data->type == FCELL_TYPE)
126 (FCELL) * (FCELL *)ptr);
127 if (data->type == DCELL_TYPE)
129 (DCELL) * (FCELL *)ptr);
132 if (type == DCELL_TYPE) {
133 if (Rast_is_d_null_value(ptr)) {
137 if (data->type == CELL_TYPE)
139 (CELL) * (DCELL *)ptr);
140 if (data->type == FCELL_TYPE)
142 (FCELL) * (DCELL *)ptr);
143 if (data->type == DCELL_TYPE)
145 (DCELL) * (DCELL *)ptr);
174 int x, y, cols, rows, type;
178 struct Cell_head region;
191 map = Rast_open_new(
name, type);
193 if (type == CELL_TYPE)
194 rast = Rast_allocate_buf(type);
195 if (type == FCELL_TYPE)
196 frast = Rast_allocate_buf(type);
197 if (type == DCELL_TYPE)
198 drast = Rast_allocate_buf(type);
202 for (y = 0; y < rows; y++) {
204 for (
x = 0;
x < cols;
x++) {
205 if (type == CELL_TYPE)
207 if (type == FCELL_TYPE)
209 if (type == DCELL_TYPE)
212 if (type == CELL_TYPE)
213 Rast_put_c_row(map, rast);
214 if (type == FCELL_TYPE)
215 Rast_put_f_row(map, frast);
216 if (type == DCELL_TYPE)
217 Rast_put_d_row(map, drast);
253 int x, y, z, cols, rows, depths, type;
254 double d1 = 0, f1 = 0;
256 RASTER3D_Region region;
259 Rast3d_get_window(®ion);
263 depths = region.depths;
266 Rast3d_fatal_error(_(
"3D raster map <%s> not found"),
name);
269 map = Rast3d_open_cell_old(
271 RASTER3D_TILE_SAME_AS_FILE, RASTER3D_USE_CACHE_DEFAULT);
274 Rast3d_fatal_error(_(
"Unable to open 3D raster map <%s>"),
name);
276 type = Rast3d_tile_type_map(map);
282 if (type == FCELL_TYPE) {
285 if (type == DCELL_TYPE) {
291 if (data->
cols != cols)
292 G_fatal_error(
"N_read_rast_to_array_3d: the data array size is "
293 "different from the current region settings");
294 if (data->
rows != rows)
295 G_fatal_error(
"N_read_rast_to_array_3d: the data array size is "
296 "different from the current region settings");
297 if (data->
depths != depths)
298 G_fatal_error(
"N_read_rast_to_array_3d: the data array size is "
299 "different from the current region settings");
306 if (Rast3d_mask_file_exists()) {
308 if (Rast3d_mask_is_off(map)) {
315 for (z = 0; z < depths; z++) {
317 for (y = 0; y < rows; y++) {
318 for (
x = 0;
x < cols;
x++) {
319 if (type == FCELL_TYPE) {
320 Rast3d_get_value(map,
x, y, z, &f1, type);
321 if (Rast_is_f_null_value((
void *)&f1)) {
325 if (data->
type == FCELL_TYPE)
327 if (data->
type == DCELL_TYPE)
332 Rast3d_get_value(map,
x, y, z, &d1, type);
333 if (Rast_is_d_null_value((
void *)&d1)) {
337 if (data->
type == FCELL_TYPE)
339 if (data->
type == DCELL_TYPE)
349 if (Rast3d_mask_file_exists())
350 if (Rast3d_mask_is_on(map) && changemask)
351 Rast3d_mask_off(map);
355 if (!Rast3d_close(map))
356 Rast3d_fatal_error(_(
"Error closing g3d file <%s>"),
name);
381 int x, y, z, cols, rows, depths, type;
382 double d1 = 0.0, f1 = 0.0;
384 RASTER3D_Region region;
387 Rast3d_get_window(®ion);
391 depths = region.depths;
395 if (data->
cols != cols)
396 G_fatal_error(
"N_write_array_3d_to_rast3d: the data array size is "
397 "different from the current region settings");
398 if (data->
rows != rows)
399 G_fatal_error(
"N_write_array_3d_to_rast3d: the data array size is "
400 "different from the current region settings");
401 if (data->
depths != depths)
402 G_fatal_error(
"N_write_array_3d_to_rast3d: the data array size is "
403 "different from the current region settings");
406 if (type == DCELL_TYPE)
407 map = Rast3d_open_new_opt_tile_size(
name, RASTER3D_USE_CACHE_XY,
408 ®ion, DCELL_TYPE, 32);
409 else if (type == FCELL_TYPE)
410 map = Rast3d_open_new_opt_tile_size(
name, RASTER3D_USE_CACHE_XY,
411 ®ion, FCELL_TYPE, 32);
414 Rast3d_fatal_error(_(
"Error opening g3d map <%s>"),
name);
420 if (Rast3d_mask_file_exists()) {
422 if (Rast3d_mask_is_off(map)) {
429 for (z = 0; z < depths; z++) {
431 for (y = 0; y < rows; y++) {
432 for (
x = 0;
x < cols;
x++) {
433 if (type == FCELL_TYPE) {
435 Rast3d_put_float(map,
x, y, z, f1);
437 else if (type == DCELL_TYPE) {
439 Rast3d_put_double(map,
x, y, z, d1);
447 if (Rast3d_mask_file_exists())
448 if (Rast3d_mask_is_on(map) && changemask)
449 Rast3d_mask_off(map);
453 if (!Rast3d_flush_all_tiles(map))
454 Rast3d_fatal_error(
"Error flushing tiles with Rast3d_flush_all_tiles");
456 if (!Rast3d_close(map))
457 Rast3d_fatal_error(_(
"Error closing g3d file <%s>"),
name);
void * G_incr_void_ptr(const void *ptr, size_t size)
Advance void pointer.
const char * G_find_raster3d(const char *name, const char *mapset)
Search for a 3D raster map in current search path or in a specified mapset.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void G_message(const char *msg,...)
Print a message to stderr.
void G_get_set_window(struct Cell_head *window)
Get the current working window (region)
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.
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.
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_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.
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.
N_array_2d * N_alloc_array_2d(int cols, int rows, int offset, int type)
Allocate memory for a N_array_2d data structure.
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_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.
void N_write_array_3d_to_rast3d(N_array_3d *array, char *name, int mask)
Write a N_array_3d struct to a volume map.
N_array_2d * N_read_rast_to_array_2d(char *name, N_array_2d *array)
Read a raster map into a N_array_2d structure.
N_array_3d * N_read_rast3d_to_array_3d(char *name, N_array_3d *array, int mask)
Read a volume map into a N_array_3d structure.
void N_write_array_2d_to_rast(N_array_2d *array, char *name)
Write a N_array_2d struct to a raster map.
void G_percent(long n, long d, int s)
Print percent complete messages.