~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/gpde/N_arrays.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
25
 
/*!
26
 
 * \brief Allocate memory for a N_array_2d data structure. 
27
 
 *
28
 
 * This function allocates memory for an array of type N_array_2d 
29
 
 * and returns the pointer to the new allocated memory.
30
 
 * <br><br>
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.
36
 
 * <br><br>
37
 
 * If the offset is greater then 0, negative indices are possible.
38
 
 * <br><br>
39
 
 *
40
 
 * The data structure of a array with 3 rows and cols and an offset of 1 
41
 
 * will looks like this:
42
 
 * <br><br>
43
 
 *
44
 
 \verbatim
45
 
 0 0 0 0 0
46
 
 0 0 1 2 0
47
 
 0 3 4 5 0
48
 
 0 6 7 8 0
49
 
 0 0 0 0 0
50
 
 \endverbatim
51
 
 *
52
 
 * 0 is the boundary.
53
 
 * <br><br>
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:
57
 
 *
58
 
 \verbatim
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 
60
 
 \endverbatim
61
 
 *
62
 
 * \param cols int 
63
 
 * \param rows int 
64
 
 * \param offset int
65
 
 * \param type int
66
 
 * \return N_array_2d *
67
 
 * 
68
 
 * */
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)
77
 
        G_fatal_error
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
 
 
121
 
/*!
122
 
 * \brief Release the memory of a N_array_2d structure
123
 
 *
124
 
 * \param data N_array_2d * 
125
 
 * \return void
126
 
 * */
127
 
void N_free_array_2d(N_array_2d * data)
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
 
 
153
 
/*!
154
 
 * \brief Return the data type of the N_array_2d struct
155
 
 *
156
 
 * The data type can be CELL_TYPE, FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.
157
 
 *
158
 
 * \param array N_array_2d * 
159
 
 * \return type int
160
 
 * */
161
 
int N_get_array_2d_type(N_array_2d * array)
162
 
{
163
 
    return array->type;
164
 
}
165
 
 
166
 
/*!
167
 
 * \brief Write the value of the N_array_2d struct at position col, row to value
168
 
 *
169
 
 * The value must be from the same type as the array. Otherwise you will risk data losses.  
170
 
 *
171
 
 * \param data N_array_2d * 
172
 
 * \param col int
173
 
 * \param row int
174
 
 * \param value void * - this variable contains the array value at col, row position
175
 
 * \return void
176
 
 * */
177
 
 
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
 
 
216
 
/*!
217
 
 * \brief Returns 1 if the value of N_array_2d struct at postion col, row 
218
 
 * is of type null, otherwise 0 
219
 
 *
220
 
 * This function checks automatically the type of the array and checks for the
221
 
 * data type null value.
222
 
 *
223
 
 * \param data N_array_2d * 
224
 
 * \param col int
225
 
 * \param row int
226
 
 * \return int - 1 = is null, 0 otherwise
227
 
 * */
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
 
 
300
 
/*!
301
 
 * \brief Returns the value of type CELL at position col, row 
302
 
 *
303
 
 * The data array can be of type CELL, FCELL or DCELL, the value will be casted to the CELL type.
304
 
 *
305
 
 * \param data N_array_2d * 
306
 
 * \param col int
307
 
 * \param row int
308
 
 * \return CELL
309
 
 *        
310
 
 * */
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
 
 
332
 
/*!
333
 
 * \brief Returns the value of type FCELL at position col, row 
334
 
 *        
335
 
 * The data array can be of type CELL, FCELL or DCELL, the value will be casted to the FCELL type.
336
 
 *
337
 
 * \param data N_array_2d * 
338
 
 * \param col int
339
 
 * \param row int
340
 
 * \return FCELL
341
 
 
342
 
 * */
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
 
 
364
 
/*!
365
 
 * \brief Returns the value of type DCELL at position col, row 
366
 
 *
367
 
 * The data array can be of type CELL, FCELL or DCELL, the value will be casted to the DCELL type.
368
 
 * 
369
 
 * \param data N_array_2d *
370
 
 * \param col int
371
 
 * \param row int
372
 
 * \return DCELL
373
 
 *        
374
 
 * */
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
 
 
397
 
/*!
398
 
 * \brief Writes a value to the N_array_2d struct at position col, row
399
 
 *
400
 
 * The value will be automatically cast to the array type.
401
 
 *
402
 
 * \param data N_array_2d *
403
 
 * \param col int
404
 
 * \param row int
405
 
 * \param value char *
406
 
 * \return void
407
 
 * */
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
 
 
445
 
/*!
446
 
 * \brief Writes the null value to the N_array_2d struct at position col, row
447
 
 *
448
 
 * The null value will be automatically set to the array data type (CELL, FCELL or DCELL).
449
 
 *
450
 
 * \param data N_array_2d *
451
 
 * \param col int
452
 
 * \param row int
453
 
 * \return void
454
 
 * */
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
 
 
512
 
/*!
513
 
 * \brief Writes a CELL value to the N_array_2d struct at position col, row
514
 
 *
515
 
 * \param data N_array_2d * 
516
 
 * \param col int
517
 
 * \param row int
518
 
 * \param value CELL
519
 
 * \return void
520
 
 * */
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
 
 
542
 
/*!
543
 
 * \brief Writes a FCELL value to the N_array_2d struct at position col, row
544
 
 *
545
 
 * \param data N_array_2d *
546
 
 * \param col int
547
 
 * \param row int
548
 
 * \param value FCELL
549
 
 * \return void
550
 
 * */
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
 
 
572
 
/*!
573
 
 * \brief Writes a DCELL value to the N_array_2d struct at position col, row
574
 
 *
575
 
 * \param data N_array_2d *
576
 
 * \param col int
577
 
 * \param row int
578
 
 * \param value DCELL
579
 
 * \return void
580
 
 * */
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
 
 
602
 
/*!
603
 
 * \brief This function writes the data info of the array data to stdout
604
 
 *
605
 
 * \param data N_array_2d *
606
 
 * \return void
607
 
 * */
608
 
void N_print_array_2d_info(N_array_2d * data)
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
 
 
626
 
/*!
627
 
 * \brief Write info and content of the N_array_2d struct to stdout
628
 
 *
629
 
 * Offsets are ignored
630
 
 *
631
 
 * \param data N_array_2d *
632
 
 * \return void
633
 
 * */
634
 
void N_print_array_2d(N_array_2d * data)
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
 
 
659
 
/*!
660
 
 * \brief Allocate memory for a N_array_3d data structure. 
661
 
 *
662
 
 * This functions allocates an array of type N_array_3d and returns a pointer 
663
 
 * to the new allocated memory.
664
 
 * <br><br>
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.
670
 
 * <br><br>
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:
674
 
 *
675
 
 \verbatim
676
 
 0  0  0  0  0
677
 
 0  0  0  0  0
678
 
 0  0  0  0  0
679
 
 0  0  0  0  0
680
 
 0  0  0  0  0
681
 
 
682
 
 0  0  0  0  0
683
 
 0  0  1  2  0
684
 
 0  3  4  5  0
685
 
 0  6  7  8  0
686
 
 0  0  0  0  0
687
 
 
688
 
 0  0  0  0  0
689
 
 0  9 10 11  0
690
 
 0 12 13 14  0
691
 
 0 15 16 17  0
692
 
 0  0  0  0  0
693
 
 
694
 
 0  0  0  0  0
695
 
 0 18 19 20  0
696
 
 0 21 22 23  0
697
 
 0 24 25 26  0
698
 
 0  0  0  0  0
699
 
 
700
 
 0  0  0  0  0
701
 
 0  0  0  0  0
702
 
 0  0  0  0  0
703
 
 0  0  0  0  0
704
 
 0  0  0  0  0
705
 
 
706
 
 \endverbatim
707
 
 
708
 
 The depth counts from the bottom to the top.
709
 
 
710
 
 * <br><br>
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.
714
 
 *
715
 
 * \param cols int
716
 
 * \param rows int
717
 
 * \param depths int
718
 
 * \param offset int 
719
 
 * \param type int
720
 
 * \return N_array_3d *
721
 
 * 
722
 
 * */
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)
729
 
        G_fatal_error
730
 
            ("N_alloc_array_3d: depths, cols and rows should be > 0");
731
 
 
732
 
    if (type != DCELL_TYPE && type != FCELL_TYPE)
733
 
        G_fatal_error
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
 
 
771
 
/*!
772
 
 * \brief Release the memory of a N_array_3d 
773
 
 *
774
 
 * \param data N_array_3d *
775
 
 * \return void
776
 
 * */
777
 
void N_free_array_3d(N_array_3d * data)
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
 
 
798
 
/*!
799
 
 * \brief Return the data type of the N_array_3d
800
 
 *
801
 
 * The data type can be FCELL_TYPE and DCELL_TYPE accordingly to the raster map data types.
802
 
 *
803
 
 * \param array N_array_3d *
804
 
 * \return type int -- FCELL_TYPE or DCELL_TYPE
805
 
 * */
806
 
int N_get_array_3d_type(N_array_3d * array)
807
 
{
808
 
    return array->type;
809
 
}
810
 
 
811
 
 
812
 
/*!
813
 
 * \brief This function writes the value of N_array_3d data at position col, row, depth
814
 
 *        to the variable value
815
 
 *
816
 
 * The value must be from the same type as the array. Otherwise you will risk data losses.  
817
 
 *
818
 
 * \param data N_array_3d *
819
 
 * \param col int
820
 
 * \param row int
821
 
 * \param depth int
822
 
 * \param value void *
823
 
 * \return void
824
 
 * */
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
 
 
865
 
/*!
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
868
 
 *
869
 
 * This function checks automatically the type of the array and checks for the
870
 
 * data type null value.
871
 
 *
872
 
 * \param data N_array_3d *
873
 
 * \param col int
874
 
 * \param row int
875
 
 * \param depth int
876
 
 * \return void
877
 
 * */
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
 
 
946
 
/*!
947
 
 * \brief This function returns the value of type float at position col, row, depth
948
 
 *
949
 
 * The data type can be FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.
950
 
 *
951
 
 * \param data N_array_3d *
952
 
 * \param col int
953
 
 * \param row int
954
 
 * \param depth int
955
 
 * \return float
956
 
 *
957
 
 * */
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
 
 
975
 
/*!
976
 
 * \brief This function returns the value of type float at position col, row, depth
977
 
 *
978
 
 * The data type can be FCELL_TYPE or DCELL_TYPE accordingly to the raster map data types.
979
 
 *
980
 
 * \param data N_array_3d *
981
 
 * \param col int
982
 
 * \param row int
983
 
 * \param depth int
984
 
 * \return double
985
 
 *
986
 
 * */
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
 
 
1005
 
/*!
1006
 
 * \brief This function writes a value to the N_array_3d data at position col, row, depth
1007
 
 *
1008
 
 * The value will be automatically cast to the array type.
1009
 
 *
1010
 
 * \param data N_array_3d *
1011
 
 * \param col int
1012
 
 * \param row int 
1013
 
 * \param depth int
1014
 
 * \param value cahr *
1015
 
 * \return void
1016
 
 * */
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
 
 
1062
 
/*!
1063
 
 * \brief This function writes a null value to the N_array_3d data at position col, row, depth
1064
 
 *
1065
 
 * The null value will be automatically set to the array type.
1066
 
 *
1067
 
 * \param data N_array_3d *
1068
 
 * \param col int
1069
 
 * \param row int 
1070
 
 * \param depth int
1071
 
 * \return void
1072
 
 * */
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
 
 
1134
 
/*!
1135
 
 * \brief This function writes a float value to the N_array_3d data at position col, row, depth
1136
 
 *
1137
 
 * \param data N_array_3d *
1138
 
 * \param col int
1139
 
 * \param row int
1140
 
 * \param depth int
1141
 
 * \param value float
1142
 
 * \return void
1143
 
 * */
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
 
 
1161
 
/*!
1162
 
 * \brief Writes a double value to the N_array_3d struct at position col, row, depth
1163
 
 *
1164
 
 * \param data N_array_3d *
1165
 
 * \param col int
1166
 
 * \param row int
1167
 
 * \param depth int
1168
 
 * \param value double
1169
 
 * \return void
1170
 
 * */
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
 
 
1188
 
/*!
1189
 
 * \brief Write the info of the array to stdout
1190
 
 *
1191
 
 * \param data N_array_3d *
1192
 
 * \return void
1193
 
 * */
1194
 
void N_print_array_3d_info(N_array_3d * data)
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
 
 
1212
 
/*!
1213
 
 * \brief Write info and content of the array data to stdout
1214
 
 *
1215
 
 * Offsets are ignored
1216
 
 *
1217
 
 * \param data N_array_2d *
1218
 
 * \return void
1219
 
 * */
1220
 
void N_print_array_3d(N_array_3d * data)
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
 
}