2
/*****************************************************************************
4
* MODULE: Grass PDE Numerical Library
5
* AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
6
* soerengebbert <at> gmx <dot> de
8
* PURPOSE: Array managment functions
9
* part of the gpde library
11
* COPYRIGHT: (C) 2000 by the GRASS Development Team
13
* This program is free software under the GNU General Public
14
* License (>=v2). Read the file COPYING that comes with GRASS
17
*****************************************************************************/
19
#include "grass/N_pde.h"
20
#include "grass/glocale.h"
23
/* ******************** 2D ARRAY FUNCTIONS *********************** */
26
* \brief Allocate memory for a N_array_2d data structure.
28
* This function allocates memory for an array of type N_array_2d
29
* and returns the pointer to the new allocated memory.
31
* The data type of this array is set by "type" and must be
32
* CELL_TYPE, FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.
33
* The offset sets the number of boundary cols and rows.
34
* This option is useful to generate homogeneous Neumann boundary conditions around
35
* an array or to establish overlapping boundaries. The array is initialized with 0 by default.
37
* If the offset is greater then 0, negative indices are possible.
40
* The data structure of a array with 3 rows and cols and an offset of 1
41
* will looks like this:
54
* Internal a one dimensional array is allocated to save memory and to speed up the memory access.
55
* To access the one dimensional array with a two dimensional index use the provided
56
* get and put functions. The internal representation of the above data will look like this:
59
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
66
* \return N_array_2d *
69
N_array_2d *N_alloc_array_2d(int cols, int rows, int offset, int type)
71
N_array_2d *data = NULL;
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");
80
data = (N_array_2d *) G_calloc(1, sizeof(N_array_2d));
85
data->offset = offset;
86
data->rows_intern = rows + 2 * offset; /*offset position at booth sides */
87
data->cols_intern = cols + 2 * offset; /*offset position at booth sides */
88
data->cell_array = NULL;
89
data->fcell_array = NULL;
90
data->dcell_array = NULL;
92
if (data->type == CELL_TYPE) {
94
(CELL *) G_calloc(data->rows_intern * data->cols_intern,
97
"N_alloc_array_2d: CELL array allocated rows_intern %i cols_intern %i offset %i",
98
data->rows_intern, data->cols_intern, data->offset = offset);
100
else if (data->type == FCELL_TYPE) {
102
(FCELL *) G_calloc(data->rows_intern * data->cols_intern,
105
"N_alloc_array_2d: FCELL array allocated rows_intern %i cols_intern %i offset %i",
106
data->rows_intern, data->cols_intern, data->offset = offset);
109
else if (data->type == DCELL_TYPE) {
111
(DCELL *) G_calloc(data->rows_intern * data->cols_intern,
114
"N_alloc_array_2d: DCELL array allocated rows_intern %i cols_intern %i offset %i",
115
data->rows_intern, data->cols_intern, data->offset = offset);
122
* \brief Release the memory of a N_array_2d structure
124
* \param data N_array_2d *
127
void N_free_array_2d(N_array_2d * data)
131
G_debug(3, "N_free_array_2d: free N_array_2d");
133
if (data->type == CELL_TYPE && data->cell_array != NULL) {
134
G_free(data->cell_array);
136
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
137
G_free(data->fcell_array);
140
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
141
G_free(data->dcell_array);
154
* \brief Return the data type of the N_array_2d struct
156
* The data type can be CELL_TYPE, FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.
158
* \param array N_array_2d *
161
int N_get_array_2d_type(N_array_2d * array)
167
* \brief Write the value of the N_array_2d struct at position col, row to value
169
* The value must be from the same type as the array. Otherwise you will risk data losses.
171
* \param data N_array_2d *
174
* \param value void * - this variable contains the array value at col, row position
178
void N_get_array_2d_value(N_array_2d * data, int col, int row, void *value)
181
if (data->offset == 0) {
182
if (data->type == CELL_TYPE && data->cell_array != NULL) {
184
data->cell_array[row * data->cols_intern + col];
186
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
188
data->fcell_array[row * data->cols_intern + col];
190
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
192
data->dcell_array[row * data->cols_intern + col];
196
if (data->type == CELL_TYPE && data->cell_array != NULL) {
198
data->cell_array[(row + data->offset) * data->cols_intern +
201
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
203
data->fcell_array[(row + data->offset) * data->cols_intern +
206
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
208
data->dcell_array[(row + data->offset) * data->cols_intern +
217
* \brief Returns 1 if the value of N_array_2d struct at postion col, row
218
* is of type null, otherwise 0
220
* This function checks automatically the type of the array and checks for the
221
* data type null value.
223
* \param data N_array_2d *
226
* \return int - 1 = is null, 0 otherwise
228
int N_is_array_2d_value_null(N_array_2d * data, int col, int row)
231
if (data->offset == 0) {
232
if (data->type == CELL_TYPE && data->cell_array != NULL) {
234
"N_is_array_2d_value_null: null value is of type CELL at pos [%i][%i]",
236
return G_is_null_value((void *)
238
cell_array[row * data->cols_intern +
241
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
243
"N_is_array_2d_value_null: null value is of type FCELL at pos [%i][%i]",
245
return G_is_null_value((void *)
247
fcell_array[row * data->cols_intern +
250
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
252
"N_is_array_2d_value_null: null value is of type DCELL at pos [%i][%i]",
254
return G_is_null_value((void *)
256
dcell_array[row * data->cols_intern +
261
if (data->type == CELL_TYPE && data->cell_array != NULL) {
263
"N_is_array_2d_value_null: null value is of type CELL at pos [%i][%i]",
265
return G_is_null_value((void *)
269
data->cols_intern + col +
270
data->offset]), CELL_TYPE);
272
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
274
"N_is_array_2d_value_null: null value is of type FCELL at pos [%i][%i]",
276
return G_is_null_value((void *)
280
data->cols_intern + col +
281
data->offset]), FCELL_TYPE);
283
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
285
"N_is_array_2d_value_null: null value is of type DCELL at pos [%i][%i]",
287
return G_is_null_value((void *)
291
data->cols_intern + col +
292
data->offset]), DCELL_TYPE);
301
* \brief Returns the value of type CELL at position col, row
303
* The data array can be of type CELL, FCELL or DCELL, the value will be casted to the CELL type.
305
* \param data N_array_2d *
311
CELL N_get_array_2d_c_value(N_array_2d * data, int col, int row)
317
switch (data->type) {
319
N_get_array_2d_value(data, col, row, (void *)&value);
322
N_get_array_2d_value(data, col, row, (void *)&fvalue);
323
return (CELL) fvalue;
325
N_get_array_2d_value(data, col, row, (void *)&dvalue);
326
return (CELL) dvalue;
333
* \brief Returns the value of type FCELL at position col, row
335
* The data array can be of type CELL, FCELL or DCELL, the value will be casted to the FCELL type.
337
* \param data N_array_2d *
343
FCELL N_get_array_2d_f_value(N_array_2d * data, int col, int row)
349
switch (data->type) {
351
N_get_array_2d_value(data, col, row, (void *)&value);
352
return (FCELL) value;
354
N_get_array_2d_value(data, col, row, (void *)&fvalue);
355
return (FCELL) fvalue;
357
N_get_array_2d_value(data, col, row, (void *)&dvalue);
358
return (FCELL) dvalue;
365
* \brief Returns the value of type DCELL at position col, row
367
* The data array can be of type CELL, FCELL or DCELL, the value will be casted to the DCELL type.
369
* \param data N_array_2d *
375
DCELL N_get_array_2d_d_value(N_array_2d * data, int col, int row)
381
switch (data->type) {
383
N_get_array_2d_value(data, col, row, (void *)&value);
384
return (DCELL) value;
386
N_get_array_2d_value(data, col, row, (void *)&fvalue);
387
return (DCELL) fvalue;
389
N_get_array_2d_value(data, col, row, (void *)&dvalue);
390
return (DCELL) dvalue;
398
* \brief Writes a value to the N_array_2d struct at position col, row
400
* The value will be automatically cast to the array type.
402
* \param data N_array_2d *
405
* \param value char *
408
void N_put_array_2d_value(N_array_2d * data, int col, int row, char *value)
411
G_debug(6, "N_put_array_2d_value: put value to array");
413
if (data->offset == 0) {
414
if (data->type == CELL_TYPE && data->cell_array != NULL) {
415
data->cell_array[row * data->cols_intern + col] =
418
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
419
data->fcell_array[row * data->cols_intern + col] =
422
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
423
data->dcell_array[row * data->cols_intern + col] =
428
if (data->type == CELL_TYPE && data->cell_array != NULL) {
429
data->cell_array[(row + data->offset) * data->cols_intern + col +
430
data->offset] = *((CELL *) value);
432
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
433
data->fcell_array[(row + data->offset) * data->cols_intern + col +
434
data->offset] = *((FCELL *) value);
436
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
437
data->dcell_array[(row + data->offset) * data->cols_intern + col +
438
data->offset] = *((DCELL *) value);
446
* \brief Writes the null value to the N_array_2d struct at position col, row
448
* The null value will be automatically set to the array data type (CELL, FCELL or DCELL).
450
* \param data N_array_2d *
455
void N_put_array_2d_value_null(N_array_2d * data, int col, int row)
459
"N_put_array_2d_value_null: put null value to array pos [%i][%i]",
462
if (data->offset == 0) {
463
if (data->type == CELL_TYPE && data->cell_array != NULL) {
464
G_set_c_null_value((void *)
466
cell_array[row * data->cols_intern + col]),
469
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
470
G_set_f_null_value((void *)
472
fcell_array[row * data->cols_intern + col]),
475
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
476
G_set_d_null_value((void *)
478
dcell_array[row * data->cols_intern + col]),
483
if (data->type == CELL_TYPE && data->cell_array != NULL) {
484
G_set_c_null_value((void *)
488
data->cols_intern + col +
491
else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
492
G_set_f_null_value((void *)
496
data->cols_intern + col +
499
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
500
G_set_d_null_value((void *)
504
data->cols_intern + col +
513
* \brief Writes a CELL value to the N_array_2d struct at position col, row
515
* \param data N_array_2d *
521
void N_put_array_2d_c_value(N_array_2d * data, int col, int row, CELL value)
526
switch (data->type) {
528
fvalue = (FCELL) value;
529
N_put_array_2d_value(data, col, row, (char *)&fvalue);
532
dvalue = (DCELL) value;
533
N_put_array_2d_value(data, col, row, (char *)&dvalue);
537
N_put_array_2d_value(data, col, row, (char *)&value);
543
* \brief Writes a FCELL value to the N_array_2d struct at position col, row
545
* \param data N_array_2d *
551
void N_put_array_2d_f_value(N_array_2d * data, int col, int row, FCELL value)
556
switch (data->type) {
558
cvalue = (CELL) value;
559
N_put_array_2d_value(data, col, row, (char *)&cvalue);
562
dvalue = (DCELL) value;
563
N_put_array_2d_value(data, col, row, (char *)&dvalue);
567
N_put_array_2d_value(data, col, row, (char *)&value);
573
* \brief Writes a DCELL value to the N_array_2d struct at position col, row
575
* \param data N_array_2d *
581
void N_put_array_2d_d_value(N_array_2d * data, int col, int row, DCELL value)
586
switch (data->type) {
588
cvalue = (CELL) value;
589
N_put_array_2d_value(data, col, row, (char *)&cvalue);
592
fvalue = (FCELL) value;
593
N_put_array_2d_value(data, col, row, (char *)&fvalue);
597
N_put_array_2d_value(data, col, row, (char *)&value);
603
* \brief This function writes the data info of the array data to stdout
605
* \param data N_array_2d *
608
void N_print_array_2d_info(N_array_2d * data)
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);
627
* \brief Write info and content of the N_array_2d struct to stdout
629
* Offsets are ignored
631
* \param data N_array_2d *
634
void N_print_array_2d(N_array_2d * data)
638
N_print_array_2d_info(data);
640
for (j = 0 - data->offset; j < data->rows + data->offset; j++) {
641
for (i = 0 - data->offset; i < data->cols + data->offset; i++) {
642
if (data->type == CELL_TYPE)
643
fprintf(stdout, "%6d ", N_get_array_2d_c_value(data, i, j));
644
else if (data->type == FCELL_TYPE)
645
fprintf(stdout, "%6.6f ", N_get_array_2d_f_value(data, i, j));
646
else if (data->type == DCELL_TYPE)
647
printf("%6.6f ", N_get_array_2d_d_value(data, i, j));
649
fprintf(stdout, "\n");
651
fprintf(stdout, "\n");
657
/* ******************** 3D ARRAY FUNCTIONS *********************** */
660
* \brief Allocate memory for a N_array_3d data structure.
662
* This functions allocates an array of type N_array_3d and returns a pointer
663
* to the new allocated memory.
665
* The data type of this array set by "type" must be
666
* FCELL_TYPE or DCELL_TYPE accordingly to the raster3d map data types.
667
* The offsets sets the number of boundary cols, rows and depths.
668
* This option is useful to generate homogeneous Neumann boundary conditions around
669
* an array or to establish overlapping boundaries. The arrays are initialized with 0 by default.
671
* If the offset is greater then 0, negative indices are possible.
672
* The data structure of a array with 3 depths, rows and cols and an offset of 1
673
* will looks like this:
708
The depth counts from the bottom to the top.
711
* Internal a one dimensional array is allocated to speed up the memory access.
712
* To access the dimensional array with a three dimensional indexing use the provided
713
* get and put functions.
720
* \return N_array_3d *
723
N_array_3d *N_alloc_array_3d(int cols, int rows, int depths, int offset,
726
N_array_3d *data = NULL;
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");
736
data = (N_array_3d *) G_calloc(1, sizeof(N_array_3d));
740
data->depths = depths;
742
data->offset = offset;
743
data->rows_intern = rows + 2 * offset;
744
data->cols_intern = cols + 2 * offset;
745
data->depths_intern = depths + 2 * offset;
746
data->fcell_array = NULL;
747
data->dcell_array = NULL;
749
if (data->type == FCELL_TYPE) {
751
(float *)G_calloc(data->depths_intern * data->rows_intern *
752
data->cols_intern, sizeof(float));
754
"N_alloc_array_3d: float array allocated rows_intern %i cols_intern %i depths_intern %i offset %i",
755
data->rows_intern, data->cols_intern, data->depths_intern,
756
data->offset = offset);
758
else if (data->type == DCELL_TYPE) {
760
(double *)G_calloc(data->depths_intern * data->rows_intern *
761
data->cols_intern, sizeof(double));
763
"N_alloc_array_3d: double array allocated rows_intern %i cols_intern %i depths_intern %i offset %i",
764
data->rows_intern, data->cols_intern, data->depths_intern,
765
data->offset = offset);
772
* \brief Release the memory of a N_array_3d
774
* \param data N_array_3d *
777
void N_free_array_3d(N_array_3d * data)
781
G_debug(3, "N_free_array_3d: free N_array_3d");
783
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
784
G_free(data->fcell_array);
786
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
787
G_free(data->dcell_array);
799
* \brief Return the data type of the N_array_3d
801
* The data type can be FCELL_TYPE and DCELL_TYPE accordingly to the raster map data types.
803
* \param array N_array_3d *
804
* \return type int -- FCELL_TYPE or DCELL_TYPE
806
int N_get_array_3d_type(N_array_3d * array)
813
* \brief This function writes the value of N_array_3d data at position col, row, depth
814
* to the variable value
816
* The value must be from the same type as the array. Otherwise you will risk data losses.
818
* \param data N_array_3d *
822
* \param value void *
826
N_get_array_3d_value(N_array_3d * data, int col, int row, int depth,
830
if (data->offset == 0) {
831
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
833
data->fcell_array[depth *
834
(data->rows_intern * data->cols_intern) +
835
row * data->cols_intern + col];
837
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
839
data->dcell_array[depth *
840
(data->rows_intern * data->cols_intern) +
841
row * data->cols_intern + col];
845
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
847
data->fcell_array[(depth + data->offset) *
848
(data->rows_intern * data->cols_intern) +
849
(row + data->offset) * data->cols_intern +
850
(col + data->offset)];
853
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
855
data->dcell_array[(depth + data->offset) *
856
(data->rows_intern * data->cols_intern) +
857
(row + data->offset) * data->cols_intern +
858
(col + data->offset)];
866
* \brief This function returns 1 if value of N_array_3d data at position col, row, depth
867
* is of type null, otherwise 0
869
* This function checks automatically the type of the array and checks for the
870
* data type null value.
872
* \param data N_array_3d *
878
int N_is_array_3d_value_null(N_array_3d * data, int col, int row, int depth)
881
if (data->offset == 0) {
882
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
884
"N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
886
return G3d_isNullValueNum((void *)
891
row * data->cols_intern +
894
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
896
"N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
898
return G3d_isNullValueNum((void *)
903
row * data->cols_intern +
908
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
910
"N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
912
return G3d_isNullValueNum((void *)
919
* data->cols_intern +
920
(col + data->offset)]),
924
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
926
"N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
928
return G3d_isNullValueNum((void *)
936
data->cols_intern + (col +
947
* \brief This function returns the value of type float at position col, row, depth
949
* The data type can be FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.
951
* \param data N_array_3d *
958
float N_get_array_3d_f_value(N_array_3d * data, int col, int row, int depth)
963
switch (data->type) {
965
N_get_array_3d_value(data, col, row, depth, (void *)&fvalue);
966
return (float)fvalue;
968
N_get_array_3d_value(data, col, row, depth, (void *)&dvalue);
969
return (float)dvalue;
976
* \brief This function returns the value of type float at position col, row, depth
978
* The data type can be FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.
980
* \param data N_array_3d *
987
double N_get_array_3d_d_value(N_array_3d * data, int col, int row, int depth)
992
switch (data->type) {
995
N_get_array_3d_value(data, col, row, depth, (void *)&fvalue);
996
return (double)fvalue;
998
N_get_array_3d_value(data, col, row, depth, (void *)&dvalue);
999
return (double)dvalue;
1006
* \brief This function writes a value to the N_array_3d data at position col, row, depth
1008
* The value will be automatically cast to the array type.
1010
* \param data N_array_3d *
1014
* \param value cahr *
1018
N_put_array_3d_value(N_array_3d * data, int col, int row, int depth,
1022
G_debug(6, "N_put_array_3d_value: put value to array at pos [%i][%i][%i]",
1025
if (data->offset == 0) {
1026
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
1027
data->fcell_array[depth *
1028
(data->rows_intern * data->cols_intern) +
1029
row * data->cols_intern + col]
1030
= *((float *)value);
1032
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
1034
data->dcell_array[depth *
1035
(data->rows_intern * data->cols_intern) +
1036
row * data->cols_intern + col]
1037
= *((double *)value);
1041
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
1042
data->fcell_array[(depth + data->offset) *
1043
(data->rows_intern * data->cols_intern) + (row +
1046
* data->cols_intern + (col + data->offset)] =
1049
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
1050
data->dcell_array[(depth + data->offset) *
1051
(data->rows_intern * data->cols_intern) + (row +
1054
* data->cols_intern + (col + data->offset)] =
1063
* \brief This function writes a null value to the N_array_3d data at position col, row, depth
1065
* The null value will be automatically set to the array type.
1067
* \param data N_array_3d *
1073
void N_put_array_3d_value_null(N_array_3d * data, int col, int row, int depth)
1077
"N_put_array_3d_value_null: put null value to array at pos [%i][%i][%i]",
1080
if (data->offset == 0) {
1081
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
1082
G3d_setNullValue((void *)
1085
(data->rows_intern *
1086
data->cols_intern) +
1087
row * data->cols_intern + col]), 1,
1090
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
1091
G3d_setNullValue((void *)
1094
(data->rows_intern *
1095
data->cols_intern) +
1096
row * data->cols_intern + col]), 1,
1101
if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
1102
G3d_setNullValue((void *)
1104
fcell_array[(depth +
1106
(data->rows_intern *
1107
data->cols_intern) + (row +
1110
data->cols_intern + (col +
1115
else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
1116
G3d_setNullValue((void *)
1118
dcell_array[(depth +
1120
(data->rows_intern *
1121
data->cols_intern) + (row +
1124
data->cols_intern + (col +
1135
* \brief This function writes a float value to the N_array_3d data at position col, row, depth
1137
* \param data N_array_3d *
1141
* \param value float
1145
N_put_array_3d_f_value(N_array_3d * data, int col, int row, int depth,
1150
if (data->type == DCELL_TYPE) {
1151
dval = (double)value;
1152
N_put_array_3d_value(data, col, row, depth, (void *)&dval);
1155
N_put_array_3d_value(data, col, row, depth, (void *)&value);
1162
* \brief Writes a double value to the N_array_3d struct at position col, row, depth
1164
* \param data N_array_3d *
1168
* \param value double
1172
N_put_array_3d_d_value(N_array_3d * data, int col, int row, int depth,
1177
if (data->type == FCELL_TYPE) {
1178
fval = (double)value;
1179
N_put_array_3d_value(data, col, row, depth, (void *)&fval);
1182
N_put_array_3d_value(data, col, row, depth, (void *)&value);
1189
* \brief Write the info of the array to stdout
1191
* \param data N_array_3d *
1194
void N_print_array_3d_info(N_array_3d * data)
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);
1213
* \brief Write info and content of the array data to stdout
1215
* Offsets are ignored
1217
* \param data N_array_2d *
1220
void N_print_array_3d(N_array_3d * data)
1224
N_print_array_3d_info(data);
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)
1230
printf("%6.6f ", N_get_array_3d_f_value(data, i, j, k));
1231
else if (data->type == DCELL_TYPE)
1232
printf("%6.6f ", N_get_array_3d_d_value(data, i, j, k));