GRASS Programmer's Manual  6.4.2(2012)
N_arrays_calc.c
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * MODULE:       Grass PDE Numerical Library
00005 * AUTHOR(S):    Soeren Gebbert, Berlin (GER) Dec 2006
00006 *               soerengebbert <at> gmx <dot> de
00007 *               
00008 * PURPOSE:      Higher level array managment functions 
00009 *               part of the gpde library
00010 *
00011 * COPYRIGHT:    (C) 2000 by the GRASS Development Team
00012 *
00013 *               This program is free software under the GNU General Public
00014 *               License (>=v2). Read the file COPYING that comes with GRASS
00015 *               for details.
00016 *
00017 *****************************************************************************/
00018 
00019 #include "grass/N_pde.h"
00020 #include "grass/glocale.h"
00021 #include <math.h>
00022 
00023 /* ******************** 2D ARRAY FUNCTIONS *********************** */
00024 
00043 void N_copy_array_2d(N_array_2d * source, N_array_2d * target)
00044 {
00045     int i;
00046     int null = 0;
00047 
00048 #pragma omp single
00049     {
00050         if (source->cols_intern != target->cols_intern)
00051             G_fatal_error
00052                 ("N_copy_array_2d: the arrays are not of equal size");
00053 
00054         if (source->rows_intern != target->rows_intern)
00055             G_fatal_error
00056                 ("N_copy_array_2d: the arrays are not of equal size");
00057 
00058         G_debug(3,
00059                 "N_copy_array_2d: copy source array to target array size %i",
00060                 source->cols_intern * source->rows_intern);
00061     }
00062 
00063 #pragma omp for
00064     for (i = 0; i < source->cols_intern * source->rows_intern; i++) {
00065         null = 0;
00066         if (source->type == CELL_TYPE) {
00067             if (G_is_c_null_value((void *)&source->cell_array[i]))
00068                 null = 1;
00069 
00070             if (target->type == CELL_TYPE) {
00071                 target->cell_array[i] = source->cell_array[i];
00072             }
00073             if (target->type == FCELL_TYPE) {
00074                 if (null)
00075                     G_set_f_null_value((void *)&(target->fcell_array[i]), 1);
00076                 else
00077                     target->fcell_array[i] = (FCELL) source->cell_array[i];
00078             }
00079             if (target->type == DCELL_TYPE) {
00080                 if (null)
00081                     G_set_d_null_value((void *)&(target->dcell_array[i]), 1);
00082                 else
00083                     target->dcell_array[i] = (DCELL) source->cell_array[i];
00084             }
00085 
00086         }
00087         if (source->type == FCELL_TYPE) {
00088             if (G_is_f_null_value((void *)&source->fcell_array[i]))
00089                 null = 1;
00090 
00091             if (target->type == CELL_TYPE) {
00092                 if (null)
00093                     G_set_c_null_value((void *)&(target->cell_array[i]), 1);
00094                 else
00095                     target->cell_array[i] = (CELL) source->fcell_array[i];
00096             }
00097             if (target->type == FCELL_TYPE) {
00098                 target->fcell_array[i] = source->fcell_array[i];
00099             }
00100             if (target->type == DCELL_TYPE) {
00101                 if (null)
00102                     G_set_d_null_value((void *)&(target->dcell_array[i]), 1);
00103                 else
00104                     target->dcell_array[i] = (DCELL) source->fcell_array[i];
00105             }
00106         }
00107         if (source->type == DCELL_TYPE) {
00108             if (G_is_d_null_value((void *)&source->dcell_array[i]))
00109                 null = 1;
00110 
00111             if (target->type == CELL_TYPE) {
00112                 if (null)
00113                     G_set_c_null_value((void *)&(target->cell_array[i]), 1);
00114                 else
00115                     target->cell_array[i] = (CELL) source->dcell_array[i];
00116             }
00117             if (target->type == FCELL_TYPE) {
00118                 if (null)
00119                     G_set_f_null_value((void *)&(target->fcell_array[i]), 1);
00120                 else
00121                     target->fcell_array[i] = (FCELL) source->dcell_array[i];
00122             }
00123             if (target->type == DCELL_TYPE) {
00124                 target->dcell_array[i] = source->dcell_array[i];
00125             }
00126         }
00127     }
00128 
00129     return;
00130 }
00131 
00146 double N_norm_array_2d(N_array_2d * a, N_array_2d * b, int type)
00147 {
00148     int i = 0;
00149     double norm = 0.0, tmp = 0.0;
00150     double v1 = 0.0, v2 = 0.0;
00151 
00152     if (a->cols_intern != b->cols_intern)
00153         G_fatal_error("N_norm_array_2d: the arrays are not of equal size");
00154 
00155     if (a->rows_intern != b->rows_intern)
00156         G_fatal_error("N_norm_array_2d: the arrays are not of equal size");
00157 
00158     G_debug(3, "N_norm_array_2d: norm of a and b size %i",
00159             a->cols_intern * a->rows_intern);
00160 
00161     for (i = 0; i < a->cols_intern * a->rows_intern; i++) {
00162         v1 = 0.0;
00163         v2 = 0.0;
00164 
00165         if (a->type == CELL_TYPE) {
00166             if (!G_is_f_null_value((void *)&(a->cell_array[i])))
00167                 v1 = (double)a->cell_array[i];
00168         }
00169         if (a->type == FCELL_TYPE) {
00170             if (!G_is_f_null_value((void *)&(a->fcell_array[i])))
00171                 v1 = (double)a->fcell_array[i];
00172         }
00173         if (a->type == DCELL_TYPE) {
00174             if (!G_is_f_null_value((void *)&(a->dcell_array[i])))
00175                 v1 = (double)a->dcell_array[i];
00176         }
00177         if (b->type == CELL_TYPE) {
00178             if (!G_is_f_null_value((void *)&(b->cell_array[i])))
00179                 v2 = (double)b->cell_array[i];
00180         }
00181         if (b->type == FCELL_TYPE) {
00182             if (!G_is_f_null_value((void *)&(b->fcell_array[i])))
00183                 v2 = (double)b->fcell_array[i];
00184         }
00185         if (b->type == DCELL_TYPE) {
00186             if (!G_is_f_null_value((void *)&(b->dcell_array[i])))
00187                 v2 = (double)b->dcell_array[i];
00188         }
00189 
00190         if (type == N_MAXIMUM_NORM) {
00191             tmp = fabs(v2 - v1);
00192             if ((tmp > norm))
00193                 norm = tmp;
00194         }
00195         if (type == N_EUKLID_NORM) {
00196             norm += fabs(v2 - v1);
00197         }
00198     }
00199 
00200     return norm;
00201 }
00202 
00217 void N_calc_array_2d_stats(N_array_2d * a, double *min, double *max,
00218                            double *sum, int *nonull, int withoffset)
00219 {
00220     int i, j;
00221     double val;
00222 
00223     *sum = 0.0;
00224     *nonull = 0;
00225 
00226     if (withoffset == 1) {
00227 
00228         *min =
00229             (double)N_get_array_2d_d_value(a, 0 - a->offset, 0 - a->offset);
00230         *max =
00231             (double)N_get_array_2d_d_value(a, 0 - a->offset, 0 - a->offset);
00232 
00233         for (j = 0 - a->offset; j < a->rows + a->offset; j++) {
00234             for (i = 0 - a->offset; i < a->cols + a->offset; i++) {
00235                 if (!N_is_array_2d_value_null(a, i, j)) {
00236                     val = (double)N_get_array_2d_d_value(a, i, j);
00237                     if (*min > val)
00238                         *min = val;
00239                     if (*max < val)
00240                         *max = val;
00241                     *sum += val;
00242                     (*nonull)++;
00243                 }
00244             }
00245         }
00246     }
00247     else {
00248 
00249         *min = (double)N_get_array_2d_d_value(a, 0, 0);
00250         *max = (double)N_get_array_2d_d_value(a, 0, 0);
00251 
00252 
00253         for (j = 0; j < a->rows; j++) {
00254             for (i = 0; i < a->cols; i++) {
00255                 if (!N_is_array_2d_value_null(a, i, j)) {
00256                     val = (double)N_get_array_2d_d_value(a, i, j);
00257                     if (*min > val)
00258                         *min = val;
00259                     if (*max < val)
00260                         *max = val;
00261                     *sum += val;
00262                     (*nonull)++;
00263                 }
00264             }
00265         }
00266     }
00267 
00268     G_debug(3,
00269             "N_calc_array_2d_stats: compute array stats, min %g, max %g, sum %g, nonull %i",
00270             *min, *max, *sum, *nonull);
00271     return;
00272 }
00273 
00274 
00306 N_array_2d *N_math_array_2d(N_array_2d * a, N_array_2d * b,
00307                             N_array_2d * result, int type)
00308 {
00309     N_array_2d *c;
00310     int i, j, setnull = 0;
00311     double va = 0.0, vb = 0.0, vc = 0.0;        /*variables used for calculation */
00312 
00313     /*Set the pointer */
00314     c = result;
00315 
00316 #pragma omp single
00317     {
00318         /*Check the array sizes */
00319         if (a->cols_intern != b->cols_intern)
00320             G_fatal_error
00321                 ("N_math_array_2d: the arrays are not of equal size");
00322         if (a->rows_intern != b->rows_intern)
00323             G_fatal_error
00324                 ("N_math_array_2d: the arrays are not of equal size");
00325         if (a->offset != b->offset)
00326             G_fatal_error
00327                 ("N_math_array_2d: the arrays have different offsets");
00328 
00329         G_debug(3, "N_math_array_2d: mathematical calculations, size: %i",
00330                 a->cols_intern * a->rows_intern);
00331 
00332         /*if the result array is null, allocate a new one, use the 
00333          * largest data type of the input arrays*/
00334         if (c == NULL) {
00335             if (a->type == DCELL_TYPE || b->type == DCELL_TYPE) {
00336                 c = N_alloc_array_2d(a->cols, a->rows, a->offset, DCELL_TYPE);
00337                 G_debug(3,
00338                         "N_math_array_2d: array of type DCELL_TYPE created");
00339             }
00340             else if (a->type == FCELL_TYPE || b->type == FCELL_TYPE) {
00341                 c = N_alloc_array_2d(a->cols, a->rows, a->offset, FCELL_TYPE);
00342                 G_debug(3,
00343                         "N_math_array_2d: array of type FCELL_TYPE created");
00344             }
00345             else {
00346                 c = N_alloc_array_2d(a->cols, a->rows, a->offset, CELL_TYPE);
00347                 G_debug(3,
00348                         "N_math_array_2d: array of type CELL_TYPE created");
00349             }
00350         }
00351         else {
00352             /*Check the array sizes */
00353             if (a->cols_intern != c->cols_intern)
00354                 G_fatal_error
00355                     ("N_math_array_2d: the arrays are not of equal size");
00356             if (a->rows_intern != c->rows_intern)
00357                 G_fatal_error
00358                     ("N_math_array_2d: the arrays are not of equal size");
00359             if (a->offset != c->offset)
00360                 G_fatal_error
00361                     ("N_math_array_2d: the arrays have different offsets");
00362         }
00363     }
00364 
00365 #pragma omp for private(va, vb, vc, setnull)
00366     for (j = 0 - a->offset; j < a->rows + a->offset; j++) {
00367         for (i = 0 - a->offset; i < a->cols + a->offset; i++) {
00368             if (!N_is_array_2d_value_null(a, i, j) &&
00369                 !N_is_array_2d_value_null(b, i, j)) {
00370                 /*we always calulate internally with double values */
00371                 va = (double)N_get_array_2d_d_value(a, i, j);
00372                 vb = (double)N_get_array_2d_d_value(b, i, j);
00373                 vc = 0;
00374                 setnull = 0;
00375 
00376                 switch (type) {
00377                 case N_ARRAY_SUM:
00378                     vc = va + vb;
00379                     break;
00380                 case N_ARRAY_DIF:
00381                     vc = va - vb;
00382                     break;
00383                 case N_ARRAY_MUL:
00384                     vc = va * vb;
00385                     break;
00386                 case N_ARRAY_DIV:
00387                     if (vb != 0)
00388                         vc = va / vb;
00389                     else
00390                         setnull = 1;
00391                     break;
00392                 }
00393 
00394                 if (c->type == CELL_TYPE) {
00395                     if (setnull)
00396                         N_put_array_2d_value_null(c, i, j);
00397                     else
00398                         N_put_array_2d_c_value(c, i, j, (CELL) vc);
00399                 }
00400                 if (c->type == FCELL_TYPE) {
00401                     if (setnull)
00402                         N_put_array_2d_value_null(c, i, j);
00403                     else
00404                         N_put_array_2d_f_value(c, i, j, (FCELL) vc);
00405                 }
00406                 if (c->type == DCELL_TYPE) {
00407                     if (setnull)
00408                         N_put_array_2d_value_null(c, i, j);
00409                     else
00410                         N_put_array_2d_d_value(c, i, j, (DCELL) vc);
00411                 }
00412 
00413             }
00414             else {
00415                 N_put_array_2d_value_null(c, i, j);
00416             }
00417         }
00418     }
00419 
00420     return c;
00421 }
00422 
00432 int N_convert_array_2d_null_to_zero(N_array_2d * a)
00433 {
00434     int i = 0, count = 0;
00435 
00436     G_debug(3, "N_convert_array_2d_null_to_zero: convert array of size %i",
00437             a->cols_intern * a->rows_intern);
00438 
00439     if (a->type == CELL_TYPE)
00440         for (i = 0; i < a->cols_intern * a->rows_intern; i++) {
00441             if (G_is_c_null_value((void *)&(a->cell_array[i]))) {
00442                 a->cell_array[i] = 0;
00443                 count++;
00444             }
00445         }
00446 
00447     if (a->type == FCELL_TYPE)
00448         for (i = 0; i < a->cols_intern * a->rows_intern; i++) {
00449             if (G_is_f_null_value((void *)&(a->fcell_array[i]))) {
00450                 a->fcell_array[i] = 0.0;
00451                 count++;
00452             }
00453         }
00454 
00455 
00456     if (a->type == DCELL_TYPE)
00457         for (i = 0; i < a->cols_intern * a->rows_intern; i++) {
00458             if (G_is_d_null_value((void *)&(a->dcell_array[i]))) {
00459                 a->dcell_array[i] = 0.0;
00460                 count++;
00461             }
00462         }
00463 
00464 
00465     if (a->type == CELL_TYPE)
00466         G_debug(2,
00467                 "N_convert_array_2d_null_to_zero: %i values of type CELL_TYPE are converted",
00468                 count);
00469     if (a->type == FCELL_TYPE)
00470         G_debug(2,
00471                 "N_convert_array_2d_null_to_zero: %i valuess of type FCELL_TYPE are converted",
00472                 count);
00473     if (a->type == DCELL_TYPE)
00474         G_debug(2,
00475                 "N_convert_array_2d_null_to_zero: %i valuess of type DCELL_TYPE are converted",
00476                 count);
00477 
00478     return count;
00479 }
00480 
00481 /* ******************** 3D ARRAY FUNCTIONS *********************** */
00482 
00498 void N_copy_array_3d(N_array_3d * source, N_array_3d * target)
00499 {
00500     int i;
00501     int null;
00502 
00503     if (source->cols_intern != target->cols_intern)
00504         G_fatal_error("N_copy_array_3d: the arrays are not of equal size");
00505 
00506     if (source->rows_intern != target->rows_intern)
00507         G_fatal_error("N_copy_array_3d: the arrays are not of equal size");
00508 
00509     if (source->depths_intern != target->depths_intern)
00510         G_fatal_error("N_copy_array_3d: the arrays are not of equal size");
00511 
00512 
00513     G_debug(3, "N_copy_array_3d: copy source array to target array size %i",
00514             source->cols_intern * source->rows_intern *
00515             source->depths_intern);
00516 
00517     for (i = 0;
00518          i <
00519          source->cols_intern * source->rows_intern * source->depths_intern;
00520          i++) {
00521         null = 0;
00522         if (source->type == FCELL_TYPE) {
00523             if (G3d_isNullValueNum
00524                 ((void *)&(source->fcell_array[i]), FCELL_TYPE))
00525                 null = 1;
00526 
00527             if (target->type == FCELL_TYPE) {
00528                 target->fcell_array[i] = source->fcell_array[i];
00529             }
00530             if (target->type == DCELL_TYPE) {
00531                 if (null)
00532                     G3d_setNullValue((void *)&(target->dcell_array[i]), 1,
00533                                      DCELL_TYPE);
00534                 else
00535                     target->dcell_array[i] = (double)source->fcell_array[i];
00536             }
00537 
00538         }
00539         if (source->type == DCELL_TYPE) {
00540             if (G3d_isNullValueNum
00541                 ((void *)&(source->dcell_array[i]), DCELL_TYPE))
00542                 null = 1;
00543 
00544             if (target->type == FCELL_TYPE) {
00545                 if (null)
00546                     G3d_setNullValue((void *)&(target->fcell_array[i]), 1,
00547                                      FCELL_TYPE);
00548                 else
00549                     target->fcell_array[i] = (float)source->dcell_array[i];
00550             }
00551             if (target->type == DCELL_TYPE) {
00552                 target->dcell_array[i] = source->dcell_array[i];
00553             }
00554         }
00555     }
00556 
00557     return;
00558 }
00559 
00560 
00574 double N_norm_array_3d(N_array_3d * a, N_array_3d * b, int type)
00575 {
00576     int i = 0;
00577     double norm = 0.0, tmp = 0.0;
00578     double v1 = 0.0, v2 = 0.0;
00579 
00580     if (a->cols_intern != b->cols_intern)
00581         G_fatal_error("N_norm_array_3d: the arrays are not of equal size");
00582 
00583     if (a->rows_intern != b->rows_intern)
00584         G_fatal_error("N_norm_array_3d: the arrays are not of equal size");
00585 
00586     if (a->depths_intern != b->depths_intern)
00587         G_fatal_error("N_norm_array_3d: the arrays are not of equal size");
00588 
00589     G_debug(3, "N_norm_array_3d: norm of a and b size %i",
00590             a->cols_intern * a->rows_intern * a->depths_intern);
00591 
00592     for (i = 0; i < a->cols_intern * a->rows_intern * a->depths_intern; i++) {
00593         v1 = 0.0;
00594         v2 = 0.0;
00595 
00596         if (a->type == FCELL_TYPE) {
00597             if (!G3d_isNullValueNum((void *)&(a->fcell_array[i]), FCELL_TYPE))
00598                 v1 = (double)a->fcell_array[i];
00599         }
00600         if (a->type == DCELL_TYPE) {
00601             if (!G3d_isNullValueNum((void *)&(a->dcell_array[i]), DCELL_TYPE))
00602                 v1 = (double)a->dcell_array[i];
00603         }
00604         if (b->type == FCELL_TYPE) {
00605             if (!G3d_isNullValueNum((void *)&(b->fcell_array[i]), FCELL_TYPE))
00606                 v2 = (double)b->fcell_array[i];
00607         }
00608         if (b->type == DCELL_TYPE) {
00609             if (!G3d_isNullValueNum((void *)&(b->dcell_array[i]), DCELL_TYPE))
00610                 v2 = (double)b->dcell_array[i];
00611         }
00612 
00613         if (type == N_MAXIMUM_NORM) {
00614             tmp = fabs(v2 - v1);
00615             if ((tmp > norm))
00616                 norm = tmp;
00617         }
00618         if (type == N_EUKLID_NORM) {
00619             norm += fabs(v2 - v1);
00620         }
00621     }
00622 
00623     return norm;
00624 }
00625 
00640 void N_calc_array_3d_stats(N_array_3d * a, double *min, double *max,
00641                            double *sum, int *nonull, int withoffset)
00642 {
00643     int i, j, k;
00644     double val;
00645 
00646     *sum = 0.0;
00647     *nonull = 0;
00648 
00649     if (withoffset == 1) {
00650 
00651         *min =
00652             (double)N_get_array_3d_d_value(a, 0 - a->offset, 0 - a->offset,
00653                                            0 - a->offset);
00654         *max =
00655             (double)N_get_array_3d_d_value(a, 0 - a->offset, 0 - a->offset,
00656                                            0 - a->offset);
00657 
00658         for (k = 0 - a->offset; k < a->depths + a->offset; k++) {
00659             for (j = 0 - a->offset; j < a->rows + a->offset; j++) {
00660                 for (i = 0 - a->offset; i < a->cols + a->offset; i++) {
00661                     if (!N_is_array_3d_value_null(a, i, j, k)) {
00662                         val = (double)N_get_array_3d_d_value(a, i, j, k);
00663                         if (*min > val)
00664                             *min = val;
00665                         if (*max < val)
00666                             *max = val;
00667                         *sum += val;
00668                         (*nonull)++;
00669                     }
00670                 }
00671             }
00672         }
00673     }
00674     else {
00675 
00676         *min = (double)N_get_array_3d_d_value(a, 0, 0, 0);
00677         *max = (double)N_get_array_3d_d_value(a, 0, 0, 0);
00678 
00679         for (k = 0; k < a->depths; k++) {
00680             for (j = 0; j < a->rows; j++) {
00681                 for (i = 0; i < a->cols; i++) {
00682                     if (!N_is_array_3d_value_null(a, i, j, k)) {
00683                         val = (double)N_get_array_3d_d_value(a, i, j, k);
00684                         if (*min > val)
00685                             *min = val;
00686                         if (*max < val)
00687                             *max = val;
00688                         *sum += val;
00689                         (*nonull)++;
00690                     }
00691                 }
00692             }
00693         }
00694     }
00695 
00696     G_debug(3,
00697             "N_calc_array_3d_stats: compute array stats, min %g, max %g, sum %g, nonull %i",
00698             *min, *max, *sum, *nonull);
00699 
00700     return;
00701 }
00702 
00737 N_array_3d *N_math_array_3d(N_array_3d * a, N_array_3d * b,
00738                             N_array_3d * result, int type)
00739 {
00740     N_array_3d *c;
00741     int i, j, k, setnull = 0;
00742     double va = 0.0, vb = 0.0, vc = 0.0;        /*variables used for calculation */
00743 
00744     /*Set the pointer */
00745     c = result;
00746 
00747     /*Check the array sizes */
00748     if (a->cols_intern != b->cols_intern)
00749         G_fatal_error("N_math_array_3d: the arrays are not of equal size");
00750     if (a->rows_intern != b->rows_intern)
00751         G_fatal_error("N_math_array_3d: the arrays are not of equal size");
00752     if (a->depths_intern != b->depths_intern)
00753         G_fatal_error("N_math_array_3d: the arrays are not of equal size");
00754     if (a->offset != b->offset)
00755         G_fatal_error("N_math_array_3d: the arrays have different offsets");
00756 
00757     G_debug(3, "N_math_array_3d: mathematical calculations, size: %i",
00758             a->cols_intern * a->rows_intern * a->depths_intern);
00759 
00760     /*if the result array is null, allocate a new one, use the 
00761      * largest data type of the input arrays*/
00762     if (c == NULL) {
00763         if (a->type == DCELL_TYPE || b->type == DCELL_TYPE) {
00764             c = N_alloc_array_3d(a->cols, a->rows, a->depths, a->offset,
00765                                  DCELL_TYPE);
00766             G_debug(3, "N_math_array_3d: array of type DCELL_TYPE created");
00767         }
00768         else {
00769             c = N_alloc_array_3d(a->cols, a->rows, a->depths, a->offset,
00770                                  FCELL_TYPE);
00771             G_debug(3, "N_math_array_3d: array of type FCELL_TYPE created");
00772         }
00773     }
00774     else {
00775         /*Check the array sizes */
00776         if (a->cols_intern != c->cols_intern)
00777             G_fatal_error
00778                 ("N_math_array_3d: the arrays are not of equal size");
00779         if (a->rows_intern != c->rows_intern)
00780             G_fatal_error
00781                 ("N_math_array_3d: the arrays are not of equal size");
00782         if (a->depths_intern != c->depths_intern)
00783             G_fatal_error
00784                 ("N_math_array_3d: the arrays are not of equal size");
00785         if (a->offset != c->offset)
00786             G_fatal_error
00787                 ("N_math_array_3d: the arrays have different offsets");
00788     }
00789 
00790     for (k = 0 - a->offset; k < a->depths + a->offset; k++) {
00791         for (j = 0 - a->offset; j < a->rows + a->offset; j++) {
00792             for (i = 0 - a->offset; i < a->cols + a->offset; i++) {
00793                 if (!N_is_array_3d_value_null(a, i, j, k) &&
00794                     !N_is_array_3d_value_null(a, i, j, k)) {
00795                     /*we always calulate internally with double values */
00796                     va = (double)N_get_array_3d_d_value(a, i, j, k);
00797                     vb = (double)N_get_array_3d_d_value(b, i, j, k);
00798                     vc = 0;
00799                     setnull = 0;
00800 
00801                     switch (type) {
00802                     case N_ARRAY_SUM:
00803                         vc = va + vb;
00804                         break;
00805                     case N_ARRAY_DIF:
00806                         vc = va - vb;
00807                         break;
00808                     case N_ARRAY_MUL:
00809                         vc = va * vb;
00810                         break;
00811                     case N_ARRAY_DIV:
00812                         if (vb != 0)
00813                             vc = va / vb;
00814                         else
00815                             setnull = 1;
00816                         break;
00817                     }
00818 
00819                     if (c->type == FCELL_TYPE) {
00820                         if (setnull)
00821                             N_put_array_3d_value_null(c, i, j, k);
00822                         else
00823                             N_put_array_3d_f_value(c, i, j, k, (float)vc);
00824                     }
00825                     if (c->type == DCELL_TYPE) {
00826                         if (setnull)
00827                             N_put_array_3d_value_null(c, i, j, k);
00828                         else
00829                             N_put_array_3d_d_value(c, i, j, k, vc);
00830                     }
00831                 }
00832                 else {
00833                     N_put_array_3d_value_null(c, i, j, k);
00834                 }
00835             }
00836         }
00837     }
00838 
00839     return c;
00840 }
00841 
00850 int N_convert_array_3d_null_to_zero(N_array_3d * a)
00851 {
00852     int i = 0, count = 0;
00853 
00854     G_debug(3, "N_convert_array_3d_null_to_zero: convert array of size %i",
00855             a->cols_intern * a->rows_intern * a->depths_intern);
00856 
00857     if (a->type == FCELL_TYPE)
00858         for (i = 0; i < a->cols_intern * a->rows_intern * a->depths_intern;
00859              i++) {
00860             if (G3d_isNullValueNum((void *)&(a->fcell_array[i]), FCELL_TYPE)) {
00861                 a->fcell_array[i] = 0.0;
00862                 count++;
00863             }
00864         }
00865 
00866     if (a->type == DCELL_TYPE)
00867         for (i = 0; i < a->cols_intern * a->rows_intern * a->depths_intern;
00868              i++) {
00869             if (G3d_isNullValueNum((void *)&(a->dcell_array[i]), DCELL_TYPE)) {
00870                 a->dcell_array[i] = 0.0;
00871                 count++;
00872             }
00873         }
00874 
00875 
00876     if (a->type == FCELL_TYPE)
00877         G_debug(3,
00878                 "N_convert_array_3d_null_to_zero: %i values of type FCELL_TYPE are converted",
00879                 count);
00880 
00881     if (a->type == DCELL_TYPE)
00882         G_debug(3,
00883                 "N_convert_array_3d_null_to_zero: %i values of type DCELL_TYPE are converted",
00884                 count);
00885 
00886     return count;
00887 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines