GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
Loading...
Searching...
No Matches
xdrfloat.c
Go to the documentation of this file.
1/*!
2 \file lib/db/dbmi_base/xdrfloat.c
3
4 \brief DBMI Library (base) - external data representation (float)
5
6 (C) 1999-2009, 2011 by the GRASS Development Team
7
8 This program is free software under the GNU General Public License
9 (>=v2). Read the file COPYING that comes with GRASS for details.
10
11 \author Joel Jones (CERL/UIUC), Radim Blazek, Brad Douglas, Markus Neteler
12 \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
13 */
14
15#include "xdr.h"
16
17/*!
18 \brief Send float
19
20 \param d
21
22 \return
23 */
24int db__send_float(float d)
25{
26 int stat = DB_OK;
27
28 if (!db__send(&d, sizeof(d)))
30
31 if (stat == DB_PROTOCOL_ERR)
33
34 return stat;
35}
36
37/*!
38 \brief Receive float
39
40 \param d
41
42 \return
43 */
44int db__recv_float(float *d)
45{
46 int stat = DB_OK;
47
48 if (!db__recv(d, sizeof(*d)))
50
51 if (stat == DB_PROTOCOL_ERR)
53
54 return stat;
55}
56
57/*!
58 \brief Send float array
59
60 \param x
61 \param n
62
63 \return
64 */
65int db__send_float_array(const float *x, int n)
66{
67 int stat = DB_OK;
68
69 if (!db__send(&n, sizeof(n)))
71
72 if (!db__send(x, n * sizeof(*x)))
74
75 if (stat == DB_PROTOCOL_ERR)
77
78 return stat;
79}
80
81/*!
82 \brief Receive float array
83
84 Returns an allocated array of floats
85 Caller is responsible for free()
86
87 \param x
88 \param n
89
90 \return
91 */
92int db__recv_float_array(float **x, int *n)
93{
94 int stat = DB_OK;
95 int count = 0;
96 float *a = NULL;
97
98 if (!db__recv(&count, sizeof(count)))
100
101 *n = count;
102
103 *x = a = (float *)db_calloc(count, sizeof(*a));
104
105 if (!db__recv(a, count * sizeof(*a)))
107
108 if (stat == DB_PROTOCOL_ERR)
110
111 return stat;
112}
#define NULL
Definition ccmath.h:32
int db__recv(void *buf, size_t size)
int db__send(const void *buf, size_t size)
?
#define DB_PROTOCOL_ERR
Definition dbmi.h:75
#define DB_OK
Definition dbmi.h:71
void * db_calloc(int, int)
Allocate memory.
void db_protocol_error(void)
Report protocol error.
int count
int db__send_float_array(const float *x, int n)
Send float array.
Definition xdrfloat.c:65
int db__send_float(float d)
Send float.
Definition xdrfloat.c:24
int db__recv_float(float *d)
Receive float.
Definition xdrfloat.c:44
int db__recv_float_array(float **x, int *n)
Receive float array.
Definition xdrfloat.c:92
#define x