File: putvalue.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (99 lines) | stat: -rw-r--r-- 2,392 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <grass/raster.h>
#include "raster3d_intern.h"

/*!
 * \brief
 *
 *  Is equivalent to Rast3d_put_value (map, x, y, z, &value, FCELL_TYPE).
 *
 *  \param map
 *  \param x
 *  \param y
 *  \param z
 *  \param value
 *  \return 1 ... if successful,
 *          0 ... otherwise.
 */

int Rast3d_put_float(RASTER3D_Map *map, int x, int y, int z, float value)
{
    int tileIndex, offs;
    float *tile;

    if (map->typeIntern == DCELL_TYPE)
        return (Rast3d_put_double(map, x, y, z, (double)value));

    Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
    tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
    if (tile == NULL) {
        Rast3d_error("Rast3d_put_float: error in Rast3d_get_tile_ptr");
        return 0;
    }

    tile[offs] = value;
    return 1;
}

/*---------------------------------------------------------------------------*/

/*!
 * \brief
 *
 *  Is equivalent to Rast3d_put_value (map, x, y, z, &value, DCELL_TYPE).
 *
 *  \param map
 *  \param x
 *  \param y
 *  \param z
 *  \param value
 *  \return 1 ... if successful,
 *          0 ... otherwise.
 */

int Rast3d_put_double(RASTER3D_Map *map, int x, int y, int z, double value)
{
    int tileIndex, offs;
    double *tile;

    if (map->typeIntern == FCELL_TYPE)
        return (Rast3d_put_float(map, x, y, z, (float)value));

    Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
    tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
    if (tile == NULL) {
        Rast3d_error("Rast3d_put_double: error in Rast3d_get_tile_ptr");
        return 0;
    }

    tile[offs] = value;
    return 1;
}

/*---------------------------------------------------------------------------*/

/*!
 * \brief
 *
 * After converting <em>*value</em> of <em>type</em> into the type specified
 * at the initialization time (i.e. <em>typeIntern</em>) this function writes
 * the value into the tile buffer corresponding to cell-coordinate <em>(x, y,
 * z)</em>.
 *
 *  \param map
 *  \param x
 *  \param y
 *  \param z
 *  \param value
 *  \param type
 *  \return 1 ... if successful,
 *          0 ... otherwise.
 */

int Rast3d_put_value(RASTER3D_Map *map, int x, int y, int z, const void *value,
                     int type)
{
    if (type == FCELL_TYPE)
        return (Rast3d_put_float(map, x, y, z, *((float *)value)));

    return (Rast3d_put_double(map, x, y, z, *((double *)value)));
}