GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
raster3d/misc.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <sys/types.h>
5#include <unistd.h>
6
7#include <grass/raster.h>
8
9#include "raster3d_intern.h"
10
11/*---------------------------------------------------------------------------*/
12
14{
15 if (g3dType == FCELL_TYPE)
16 return FCELL_TYPE;
17 return DCELL_TYPE;
18}
19
20/*---------------------------------------------------------------------------*/
21
22void Rast3d_copy_float2Double(const float *src, int offsSrc, double *dst,
23 int offsDst, int nElts)
24{
25 int i;
26
27 src += offsSrc;
28 dst += offsDst;
29
30 for (i = 0; i < nElts; i++)
31 dst[i] = (double)src[i];
32}
33
34/*---------------------------------------------------------------------------*/
35
36void Rast3d_copy_double2Float(const double *src, int offsSrc, float *dst,
37 int offsDst, int nElts)
38{
39 int i;
40
41 src += offsSrc;
42 dst += offsDst;
43
44 for (i = 0; i < nElts; i++)
45 dst[i] = (float)src[i];
46}
47
48/*---------------------------------------------------------------------------*/
49
50void Rast3d_copy_values(const void *src, int offsSrc, int typeSrc, void *dst,
51 int offsDst, int typeDst, int nElts)
52{
53 int eltLength;
54
55 if ((typeSrc == FCELL_TYPE) && (typeDst == DCELL_TYPE)) {
57 return;
58 }
59
60 if ((typeSrc == DCELL_TYPE) && (typeDst == FCELL_TYPE)) {
62 return;
63 }
64
65 eltLength = Rast3d_length(typeSrc);
66
67 src = G_incr_void_ptr(src, eltLength * offsSrc);
68 dst = G_incr_void_ptr(dst, eltLength * offsDst);
69
70 memcpy(dst, src, nElts * eltLength);
71}
72
73/*---------------------------------------------------------------------------*/
74
76{
78 Rast3d_fatal_error("Rast3d_length: invalid type");
79
80 if (t == FCELL_TYPE)
81 return sizeof(FCELL);
82 if (t == DCELL_TYPE)
83 return sizeof(DCELL);
84 return 0;
85}
86
88{
90 Rast3d_fatal_error("Rast3d_extern_length: invalid type");
91
92 if (t == FCELL_TYPE)
94 if (t == DCELL_TYPE)
96 return 0;
97}
#define G_incr_void_ptr(ptr, size)
Definition defs/gis.h:81
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
float FCELL
Definition gis.h:636
double DCELL
Definition gis.h:635
double t
Definition r_raster.c:39
int Rast3d_length(int t)
void Rast3d_copy_float2Double(const float *src, int offsSrc, double *dst, int offsDst, int nElts)
void Rast3d_copy_double2Float(const double *src, int offsSrc, float *dst, int offsDst, int nElts)
int Rast3d_g3d_type2cell_type(int g3dType)
void Rast3d_copy_values(const void *src, int offsSrc, int typeSrc, void *dst, int offsDst, int typeDst, int nElts)
int Rast3d_extern_length(int t)
#define RASTER3D_XDR_DOUBLE_LENGTH
#define RASTER3D_IS_CORRECT_TYPE(t)
#define RASTER3D_XDR_FLOAT_LENGTH
#define FCELL_TYPE
Definition raster.h:12
#define DCELL_TYPE
Definition raster.h:13