GRASS Programmer's Manual  6.5.svn(2014)-r66266
N_arrays.c
Go to the documentation of this file.
1
2 /*****************************************************************************
3 *
4 * MODULE: Grass PDE Numerical Library
5 * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
6 * soerengebbert <at> gmx <dot> de
7 *
8 * PURPOSE: Array managment functions
9 * part of the gpde library
10 *
11 * COPYRIGHT: (C) 2000 by the GRASS Development Team
12 *
13 * This program is free software under the GNU General Public
14 * License (>=v2). Read the file COPYING that comes with GRASS
15 * for details.
16 *
17 *****************************************************************************/
18
19 #include "grass/N_pde.h"
20 #include "grass/glocale.h"
21 #include <math.h>
22
23 /* ******************** 2D ARRAY FUNCTIONS *********************** */
24
69 N_array_2d *N_alloc_array_2d(int cols, int rows, int offset, int type)
70 {
71  N_array_2d *data = NULL;
72
73  if (rows < 1 || cols < 1)
74  G_fatal_error("N_alloc_array_2d: cols and rows should be > 0");
75
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");
79
80  data = (N_array_2d *) G_calloc(1, sizeof(N_array_2d));
81
82  data->cols = cols;
83  data->rows = rows;
84  data->type = type;
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;
91
92  if (data->type == CELL_TYPE) {
93  data->cell_array =
94  (CELL *) G_calloc(data->rows_intern * data->cols_intern,
95  sizeof(CELL));
96  G_debug(3,
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);
99  }
100  else if (data->type == FCELL_TYPE) {
101  data->fcell_array =
102  (FCELL *) G_calloc(data->rows_intern * data->cols_intern,
103  sizeof(FCELL));
104  G_debug(3,
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);
107
108  }
109  else if (data->type == DCELL_TYPE) {
110  data->dcell_array =
111  (DCELL *) G_calloc(data->rows_intern * data->cols_intern,
112  sizeof(DCELL));
113  G_debug(3,
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);
116  }
117
118  return data;
119 }
120
128 {
129
130  if (data != NULL) {
131  G_debug(3, "N_free_array_2d: free N_array_2d");
132
133  if (data->type == CELL_TYPE && data->cell_array != NULL) {
134  G_free(data->cell_array);
135  }
136  else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
137  G_free(data->fcell_array);
138
139  }
140  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
141  G_free(data->dcell_array);
142  }
143
144  G_free(data);
145  data = NULL;
146
147  }
148
149  return;
150 }
151
152
162 {
163  return array->type;
164 }
165
178 void N_get_array_2d_value(N_array_2d * data, int col, int row, void *value)
179 {
180
181  if (data->offset == 0) {
182  if (data->type == CELL_TYPE && data->cell_array != NULL) {
183  *((CELL *) value) =
184  data->cell_array[row * data->cols_intern + col];
185  }
186  else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
187  *((FCELL *) value) =
188  data->fcell_array[row * data->cols_intern + col];
189  }
190  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
191  *((DCELL *) value) =
192  data->dcell_array[row * data->cols_intern + col];
193  }
194  }
195  else {
196  if (data->type == CELL_TYPE && data->cell_array != NULL) {
197  *((CELL *) value) =
198  data->cell_array[(row + data->offset) * data->cols_intern +
199  col + data->offset];
200  }
201  else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
202  *((FCELL *) value) =
203  data->fcell_array[(row + data->offset) * data->cols_intern +
204  col + data->offset];
205  }
206  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
207  *((DCELL *) value) =
208  data->dcell_array[(row + data->offset) * data->cols_intern +
209  col + data->offset];
210  }
211  }
212
213  return;
214 }
215
228 int N_is_array_2d_value_null(N_array_2d * data, int col, int row)
229 {
230
231  if (data->offset == 0) {
232  if (data->type == CELL_TYPE && data->cell_array != NULL) {
233  G_debug(6,
234  "N_is_array_2d_value_null: null value is of type CELL at pos [%i][%i]",
235  col, row);
236  return G_is_null_value((void *)
237  &(data->
238  cell_array[row * data->cols_intern +
239  col]), CELL_TYPE);
240  }
241  else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
242  G_debug(6,
243  "N_is_array_2d_value_null: null value is of type FCELL at pos [%i][%i]",
244  col, row);
245  return G_is_null_value((void *)
246  &(data->
247  fcell_array[row * data->cols_intern +
248  col]), FCELL_TYPE);
249  }
250  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
251  G_debug(6,
252  "N_is_array_2d_value_null: null value is of type DCELL at pos [%i][%i]",
253  col, row);
254  return G_is_null_value((void *)
255  &(data->
256  dcell_array[row * data->cols_intern +
257  col]), DCELL_TYPE);
258  }
259  }
260  else {
261  if (data->type == CELL_TYPE && data->cell_array != NULL) {
262  G_debug(6,
263  "N_is_array_2d_value_null: null value is of type CELL at pos [%i][%i]",
264  col, row);
265  return G_is_null_value((void *)
266  &(data->
267  cell_array[(row +
268  data->offset) *
269  data->cols_intern + col +
270  data->offset]), CELL_TYPE);
271  }
272  else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
273  G_debug(6,
274  "N_is_array_2d_value_null: null value is of type FCELL at pos [%i][%i]",
275  col, row);
276  return G_is_null_value((void *)
277  &(data->
278  fcell_array[(row +
279  data->offset) *
280  data->cols_intern + col +
281  data->offset]), FCELL_TYPE);
282  }
283  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
284  G_debug(6,
285  "N_is_array_2d_value_null: null value is of type DCELL at pos [%i][%i]",
286  col, row);
287  return G_is_null_value((void *)
288  &(data->
289  dcell_array[(row +
290  data->offset) *
291  data->cols_intern + col +
292  data->offset]), DCELL_TYPE);
293  }
294  }
295
296  return 0;
297 }
298
299
311 CELL N_get_array_2d_c_value(N_array_2d * data, int col, int row)
312 {
313  CELL value = 0;
314  FCELL fvalue = 0.0;
315  DCELL dvalue = 0.0;
316
317  switch (data->type) {
318  case CELL_TYPE:
319  N_get_array_2d_value(data, col, row, (void *)&value);
320  return (CELL) value;
321  case FCELL_TYPE:
322  N_get_array_2d_value(data, col, row, (void *)&fvalue);
323  return (CELL) fvalue;
324  case DCELL_TYPE:
325  N_get_array_2d_value(data, col, row, (void *)&dvalue);
326  return (CELL) dvalue;
327  }
328
329  return value;
330 }
331
343 FCELL N_get_array_2d_f_value(N_array_2d * data, int col, int row)
344 {
345  CELL value = 0;
346  FCELL fvalue = 0.0;
347  DCELL dvalue = 0.0;
348
349  switch (data->type) {
350  case CELL_TYPE:
351  N_get_array_2d_value(data, col, row, (void *)&value);
352  return (FCELL) value;
353  case FCELL_TYPE:
354  N_get_array_2d_value(data, col, row, (void *)&fvalue);
355  return (FCELL) fvalue;
356  case DCELL_TYPE:
357  N_get_array_2d_value(data, col, row, (void *)&dvalue);
358  return (FCELL) dvalue;
359  }
360
361  return fvalue;
362 }
363
375 DCELL N_get_array_2d_d_value(N_array_2d * data, int col, int row)
376 {
377  CELL value = 0;
378  FCELL fvalue = 0.0;
379  DCELL dvalue = 0.0;
380
381  switch (data->type) {
382  case CELL_TYPE:
383  N_get_array_2d_value(data, col, row, (void *)&value);
384  return (DCELL) value;
385  case FCELL_TYPE:
386  N_get_array_2d_value(data, col, row, (void *)&fvalue);
387  return (DCELL) fvalue;
388  case DCELL_TYPE:
389  N_get_array_2d_value(data, col, row, (void *)&dvalue);
390  return (DCELL) dvalue;
391  }
392
393  return dvalue;
394
395 }
396
408 void N_put_array_2d_value(N_array_2d * data, int col, int row, char *value)
409 {
410
411  G_debug(6, "N_put_array_2d_value: put value to array");
412
413  if (data->offset == 0) {
414  if (data->type == CELL_TYPE && data->cell_array != NULL) {
415  data->cell_array[row * data->cols_intern + col] =
416  *((CELL *) value);
417  }
418  else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
419  data->fcell_array[row * data->cols_intern + col] =
420  *((FCELL *) value);
421  }
422  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
423  data->dcell_array[row * data->cols_intern + col] =
424  *((DCELL *) value);
425  }
426  }
427  else {
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);
431  }
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);
435  }
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);
439  }
440  }
441
442  return;
443 }
444
455 void N_put_array_2d_value_null(N_array_2d * data, int col, int row)
456 {
457
458  G_debug(6,
459  "N_put_array_2d_value_null: put null value to array pos [%i][%i]",
460  col, row);
461
462  if (data->offset == 0) {
463  if (data->type == CELL_TYPE && data->cell_array != NULL) {
464  G_set_c_null_value((void *)
465  &(data->
466  cell_array[row * data->cols_intern + col]),
467  1);
468  }
469  else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
470  G_set_f_null_value((void *)
471  &(data->
472  fcell_array[row * data->cols_intern + col]),
473  1);
474  }
475  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
476  G_set_d_null_value((void *)
477  &(data->
478  dcell_array[row * data->cols_intern + col]),
479  1);
480  }
481  }
482  else {
483  if (data->type == CELL_TYPE && data->cell_array != NULL) {
484  G_set_c_null_value((void *)
485  &(data->
486  cell_array[(row +
487  data->offset) *
488  data->cols_intern + col +
489  data->offset]), 1);
490  }
491  else if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
492  G_set_f_null_value((void *)
493  &(data->
494  fcell_array[(row +
495  data->offset) *
496  data->cols_intern + col +
497  data->offset]), 1);
498  }
499  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
500  G_set_d_null_value((void *)
501  &(data->
502  dcell_array[(row +
503  data->offset) *
504  data->cols_intern + col +
505  data->offset]), 1);
506  }
507  }
508
509  return;
510 }
511
521 void N_put_array_2d_c_value(N_array_2d * data, int col, int row, CELL value)
522 {
523  FCELL fvalue;
524  DCELL dvalue;
525
526  switch (data->type) {
527  case FCELL_TYPE:
528  fvalue = (FCELL) value;
529  N_put_array_2d_value(data, col, row, (char *)&fvalue);
530  return;
531  case DCELL_TYPE:
532  dvalue = (DCELL) value;
533  N_put_array_2d_value(data, col, row, (char *)&dvalue);
534  return;
535  }
536
537  N_put_array_2d_value(data, col, row, (char *)&value);
538
539  return;
540 }
541
551 void N_put_array_2d_f_value(N_array_2d * data, int col, int row, FCELL value)
552 {
553  CELL cvalue;
554  DCELL dvalue;
555
556  switch (data->type) {
557  case CELL_TYPE:
558  cvalue = (CELL) value;
559  N_put_array_2d_value(data, col, row, (char *)&cvalue);
560  return;
561  case DCELL_TYPE:
562  dvalue = (DCELL) value;
563  N_put_array_2d_value(data, col, row, (char *)&dvalue);
564  return;
565  }
566
567  N_put_array_2d_value(data, col, row, (char *)&value);
568
569  return;
570 }
571
581 void N_put_array_2d_d_value(N_array_2d * data, int col, int row, DCELL value)
582 {
583  CELL cvalue;
584  FCELL fvalue;
585
586  switch (data->type) {
587  case CELL_TYPE:
588  cvalue = (CELL) value;
589  N_put_array_2d_value(data, col, row, (char *)&cvalue);
590  return;
591  case FCELL_TYPE:
592  fvalue = (FCELL) value;
593  N_put_array_2d_value(data, col, row, (char *)&fvalue);
594  return;
595  }
596
597  N_put_array_2d_value(data, col, row, (char *)&value);
598
599  return;
600 }
601
609 {
610
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);
621
622
623  return;
624 }
625
635 {
636  int i, j;
637
638  N_print_array_2d_info(data);
639
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));
648  }
649  fprintf(stdout, "\n");
650  }
651  fprintf(stdout, "\n");
652
653  return;
654 }
655
656
657 /* ******************** 3D ARRAY FUNCTIONS *********************** */
658
723 N_array_3d *N_alloc_array_3d(int cols, int rows, int depths, int offset,
724  int type)
725 {
726  N_array_3d *data = NULL;
727
728  if (rows < 1 || cols < 1 || depths < 1)
730  ("N_alloc_array_3d: depths, cols and rows should be > 0");
731
732  if (type != DCELL_TYPE && type != FCELL_TYPE)
734  ("N_alloc_array_3d: Wrong data type, should be FCELL_TYPE or DCELL_TYPE");
735
736  data = (N_array_3d *) G_calloc(1, sizeof(N_array_3d));
737
738  data->cols = cols;
739  data->rows = rows;
740  data->depths = depths;
741  data->type = type;
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;
748
749  if (data->type == FCELL_TYPE) {
750  data->fcell_array =
751  (float *)G_calloc(data->depths_intern * data->rows_intern *
752  data->cols_intern, sizeof(float));
753  G_debug(3,
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);
757  }
758  else if (data->type == DCELL_TYPE) {
759  data->dcell_array =
760  (double *)G_calloc(data->depths_intern * data->rows_intern *
761  data->cols_intern, sizeof(double));
762  G_debug(3,
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);
766  }
767
768  return data;
769 }
770
778 {
779
780  if (data != NULL) {
781  G_debug(3, "N_free_array_3d: free N_array_3d");
782
783  if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
784  G_free(data->fcell_array);
785  }
786  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
787  G_free(data->dcell_array);
788  }
789
790  G_free(data);
791  data = NULL;
792
793  }
794
795  return;
796 }
797
807 {
808  return array->type;
809 }
810
811
825 void
826 N_get_array_3d_value(N_array_3d * data, int col, int row, int depth,
827  void *value)
828 {
829
830  if (data->offset == 0) {
831  if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
832  *((float *)value) =
833  data->fcell_array[depth *
834  (data->rows_intern * data->cols_intern) +
835  row * data->cols_intern + col];
836  }
837  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
838  *((double *)value) =
839  data->dcell_array[depth *
840  (data->rows_intern * data->cols_intern) +
841  row * data->cols_intern + col];
842  }
843  }
844  else {
845  if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
846  *((float *)value) =
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)];
851
852  }
853  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
854  *((double *)value) =
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)];
859  }
860  }
861
862  return;
863 }
864
878 int N_is_array_3d_value_null(N_array_3d * data, int col, int row, int depth)
879 {
880
881  if (data->offset == 0) {
882  if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
883  G_debug(6,
884  "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
885  depth, row, col);
886  return G3d_isNullValueNum((void *)
887  &(data->
888  fcell_array[depth *
889  (data->rows_intern *
890  data->cols_intern) +
891  row * data->cols_intern +
892  col]), FCELL_TYPE);
893  }
894  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
895  G_debug(6,
896  "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
897  depth, row, col);
898  return G3d_isNullValueNum((void *)
899  &(data->
900  dcell_array[depth *
901  (data->rows_intern *
902  data->cols_intern) +
903  row * data->cols_intern +
904  col]), DCELL_TYPE);
905  }
906  }
907  else {
908  if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
909  G_debug(6,
910  "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
911  depth, row, col);
912  return G3d_isNullValueNum((void *)
913  &(data->
914  fcell_array[(depth +
915  data->offset) *
916  (data->rows_intern *
917  data->cols_intern) +
918  (row + data->offset)
919  * data->cols_intern +
920  (col + data->offset)]),
921  FCELL_TYPE);
922
923  }
924  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
925  G_debug(6,
926  "N_is_array_3d_value_null: null value is of type DCELL_TYPE at pos [%i][%i][%i]",
927  depth, row, col);
928  return G3d_isNullValueNum((void *)
929  &(data->
930  dcell_array[(depth +
931  data->offset) *
932  (data->rows_intern *
933  data->cols_intern) +
934  (row +
935  data->offset) *
936  data->cols_intern + (col +
937  data->
938  offset)]),
939  DCELL_TYPE);
940  }
941  }
942
943  return 0;
944 }
945
958 float N_get_array_3d_f_value(N_array_3d * data, int col, int row, int depth)
959 {
960  float fvalue = 0.0;
961  double dvalue = 0.0;
962
963  switch (data->type) {
964  case FCELL_TYPE:
965  N_get_array_3d_value(data, col, row, depth, (void *)&fvalue);
966  return (float)fvalue;
967  case DCELL_TYPE:
968  N_get_array_3d_value(data, col, row, depth, (void *)&dvalue);
969  return (float)dvalue;
970  }
971
972  return fvalue;
973 }
974
987 double N_get_array_3d_d_value(N_array_3d * data, int col, int row, int depth)
988 {
989  float fvalue = 0.0;
990  double dvalue = 0.0;
991
992  switch (data->type) {
993
994  case FCELL_TYPE:
995  N_get_array_3d_value(data, col, row, depth, (void *)&fvalue);
996  return (double)fvalue;
997  case DCELL_TYPE:
998  N_get_array_3d_value(data, col, row, depth, (void *)&dvalue);
999  return (double)dvalue;
1000  }
1001
1002  return dvalue;
1003 }
1004
1017 void
1018 N_put_array_3d_value(N_array_3d * data, int col, int row, int depth,
1019  char *value)
1020 {
1021
1022  G_debug(6, "N_put_array_3d_value: put value to array at pos [%i][%i][%i]",
1023  depth, row, col);
1024
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);
1031  }
1032  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
1033
1034  data->dcell_array[depth *
1035  (data->rows_intern * data->cols_intern) +
1036  row * data->cols_intern + col]
1037  = *((double *)value);
1038  }
1039  }
1040  else {
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 +
1044  data->
1045  offset)
1046  * data->cols_intern + (col + data->offset)] =
1047  *((float *)value);
1048  }
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 +
1052  data->
1053  offset)
1054  * data->cols_intern + (col + data->offset)] =
1055  *((double *)value);
1056  }
1057  }
1058
1059  return;
1060 }
1061
1073 void N_put_array_3d_value_null(N_array_3d * data, int col, int row, int depth)
1074 {
1075
1076  G_debug(6,
1077  "N_put_array_3d_value_null: put null value to array at pos [%i][%i][%i]",
1078  depth, row, col);
1079
1080  if (data->offset == 0) {
1081  if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
1082  G3d_setNullValue((void *)
1083  &(data->
1084  fcell_array[depth *
1085  (data->rows_intern *
1086  data->cols_intern) +
1087  row * data->cols_intern + col]), 1,
1088  FCELL_TYPE);
1089  }
1090  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
1091  G3d_setNullValue((void *)
1092  &(data->
1093  dcell_array[depth *
1094  (data->rows_intern *
1095  data->cols_intern) +
1096  row * data->cols_intern + col]), 1,
1097  DCELL_TYPE);
1098  }
1099  }
1100  else {
1101  if (data->type == FCELL_TYPE && data->fcell_array != NULL) {
1102  G3d_setNullValue((void *)
1103  &(data->
1104  fcell_array[(depth +
1105  data->offset) *
1106  (data->rows_intern *
1107  data->cols_intern) + (row +
1108  data->
1109  offset) *
1110  data->cols_intern + (col +
1111  data->
1112  offset)]), 1,
1113  FCELL_TYPE);
1114  }
1115  else if (data->type == DCELL_TYPE && data->dcell_array != NULL) {
1116  G3d_setNullValue((void *)
1117  &(data->
1118  dcell_array[(depth +
1119  data->offset) *
1120  (data->rows_intern *
1121  data->cols_intern) + (row +
1122  data->
1123  offset) *
1124  data->cols_intern + (col +
1125  data->
1126  offset)]), 1,
1127  DCELL_TYPE);
1128  }
1129  }
1130
1131  return;
1132 }
1133
1144 void
1145 N_put_array_3d_f_value(N_array_3d * data, int col, int row, int depth,
1146  float value)
1147 {
1148  double dval;
1149
1150  if (data->type == DCELL_TYPE) {
1151  dval = (double)value;
1152  N_put_array_3d_value(data, col, row, depth, (void *)&dval);
1153  }
1154  else {
1155  N_put_array_3d_value(data, col, row, depth, (void *)&value);
1156  }
1157
1158  return;
1159 }
1160
1171 void
1172 N_put_array_3d_d_value(N_array_3d * data, int col, int row, int depth,
1173  double value)
1174 {
1175  float fval;
1176
1177  if (data->type == FCELL_TYPE) {
1178  fval = (double)value;
1179  N_put_array_3d_value(data, col, row, depth, (void *)&fval);
1180  }
1181  else {
1182  N_put_array_3d_value(data, col, row, depth, (void *)&value);
1183  }
1184
1185  return;
1186 }
1187
1195 {
1196
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);
1208
1209  return;
1210 }
1211
1221 {
1222  int i, j, k;
1223
1224  N_print_array_3d_info(data);
1225
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));
1233  }
1234  printf("\n");
1235  }
1236  printf("\n");
1237  }
1238  printf("\n");
1239
1240  return;
1241 }
void N_free_array_2d(N_array_2d *data)
Release the memory of a N_array_2d structure.
Definition: N_arrays.c:127
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
int depths_intern
Definition: N_pde.h:219
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...
Definition: N_arrays.c:878
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...
Definition: N_arrays.c:826
int rows
Definition: N_pde.h:162
void G3d_setNullValue(void *c, int nofElts, int type)
Fills the vector pointed to by c with nofElts NULL-values of type.
Definition: g3dnull.c:32
void N_free_array_3d(N_array_3d *data)
Release the memory of a N_array_3d.
Definition: N_arrays.c:777
void G_set_d_null_value(DCELL *dcellVals, int numVals)
Definition: null_val.c:176
int depths
Definition: N_pde.h:218
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.
Definition: N_arrays.c:1073
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.
Definition: N_arrays.c:343
int G3d_isNullValueNum(const void *n, int type)
Definition: g3dnull.c:9
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.
Definition: N_arrays.c:581
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.
Definition: N_arrays.c:551
int cols
Definition: N_pde.h:162
N_array_2d * N_alloc_array_2d(int cols, int rows, int offset, int type)
Allocate memory for a N_array_2d data structure.
Definition: N_arrays.c:69
int offset
Definition: N_pde.h:220
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.
Definition: N_arrays.c:723
int offset
Definition: N_pde.h:164
void N_print_array_2d_info(N_array_2d *data)
This function writes the data info of the array data to stdout.
Definition: N_arrays.c:608
CELL * cell_array
Definition: N_pde.h:165
int cols_intern
Definition: N_pde.h:219
tuple data
void N_print_array_3d_info(N_array_3d *data)
Write the info of the array to stdout.
Definition: N_arrays.c:1194
int cols
Definition: N_pde.h:218
FCELL * fcell_array
Definition: N_pde.h:166
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.
Definition: N_arrays.c:455
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.
Definition: N_arrays.c:521
char * value
Definition: env.c:30
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.
Definition: N_arrays.c:958
DCELL * dcell_array
Definition: N_pde.h:167
void N_print_array_2d(N_array_2d *data)
Write info and content of the N_array_2d struct to stdout.
Definition: N_arrays.c:634
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.
Definition: N_arrays.c:1145
void N_print_array_3d(N_array_3d *data)
Write info and content of the array data to stdout.
Definition: N_arrays.c:1220
float * fcell_array
Definition: N_pde.h:221
void G_set_f_null_value(FCELL *fcellVals, int numVals)
Definition: null_val.c:158
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.
Definition: N_arrays.c:178
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...
Definition: N_arrays.c:228
double * dcell_array
Definition: N_pde.h:222
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.
Definition: N_arrays.c:987
int type
Definition: N_pde.h:161
return NULL
Definition: dbfopen.c:1394
tuple cols
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.
Definition: N_arrays.c:408
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
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.
Definition: N_arrays.c:375
int cols_intern
Definition: N_pde.h:163
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.
Definition: N_arrays.c:1172
int N_get_array_3d_type(N_array_3d *array)
Return the data type of the N_array_3d.
Definition: N_arrays.c:806
int N_get_array_2d_type(N_array_2d *array)
Return the data type of the N_array_2d struct.
Definition: N_arrays.c:161
void G_set_c_null_value(CELL *cellVals, int numVals)
Definition: null_val.c:142
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.
Definition: N_arrays.c:311
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.
Definition: N_arrays.c:1018
int type
Definition: N_pde.h:217
int rows_intern
Definition: N_pde.h:219
int rows
Definition: N_pde.h:218
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...
Definition: null_val.c:207
int rows_intern
Definition: N_pde.h:163