GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
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 SPDX-FileCopyrightText: 1999-2009, 2011 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Joel Jones (CERL/UIUC), Radim Blazek, Brad Douglas, Markus Neteler
10 \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
11 */
12
13#include "xdr.h"
14
15/*!
16 \brief Send float
17
18 \param d
19
20 \return
21 */
22int db__send_float(float d)
23{
24 int stat = DB_OK;
25
26 if (!db__send(&d, sizeof(d)))
28
29 if (stat == DB_PROTOCOL_ERR)
31
32 return stat;
33}
34
35/*!
36 \brief Receive float
37
38 \param d
39
40 \return
41 */
42int db__recv_float(float *d)
43{
44 int stat = DB_OK;
45
46 if (!db__recv(d, sizeof(*d)))
48
49 if (stat == DB_PROTOCOL_ERR)
51
52 return stat;
53}
54
55/*!
56 \brief Send float array
57
58 \param x
59 \param n
60
61 \return
62 */
63int db__send_float_array(const float *x, int n)
64{
65 int stat = DB_OK;
66
67 if (!db__send(&n, sizeof(n)))
69
70 if (!db__send(x, n * sizeof(*x)))
72
73 if (stat == DB_PROTOCOL_ERR)
75
76 return stat;
77}
78
79/*!
80 \brief Receive float array
81
82 Returns an allocated array of floats
83 Caller is responsible for free()
84
85 \param x
86 \param n
87
88 \return
89 */
90int db__recv_float_array(float **x, int *n)
91{
92 int stat = DB_OK;
93 int count = 0;
94 float *a = NULL;
95
96 if (!db__recv(&count, sizeof(count)))
98
99 *n = count;
100
101 *x = a = (float *)db_calloc(count, sizeof(*a));
102
103 if (!db__recv(a, count * sizeof(*a)))
105
106 if (stat == DB_PROTOCOL_ERR)
108
109 return stat;
110}
#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:73
#define DB_OK
Definition dbmi.h:69
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:63
int db__send_float(float d)
Send float.
Definition xdrfloat.c:22
int db__recv_float(float *d)
Receive float.
Definition xdrfloat.c:42
int db__recv_float_array(float **x, int *n)
Receive float array.
Definition xdrfloat.c:90
#define x