GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
xdrdouble.c
Go to the documentation of this file.
1/*!
2 \file lib/db/dbmi_base/xdrdouble.c
3
4 \brief DBMI Library (base) - external data representation (double)
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 double
17
18 \param d
19
20 \return
21 */
22int db__send_double(double 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 double
37
38 \param d
39 */
40int db__recv_double(double *d)
41{
42 int stat = DB_OK;
43
44 if (!db__recv(d, sizeof(*d)))
46
47 if (stat == DB_PROTOCOL_ERR)
49
50 return stat;
51}
52
53/*!
54 \brief Send double array
55
56 \param x
57 \param n
58
59 \return
60 */
61int db__send_double_array(const double *x, int n)
62{
63 int stat = DB_OK;
64
65 if (!db__send(&n, sizeof(n)))
67
68 if (!db__send(x, n * sizeof(*x)))
70
71 if (stat == DB_PROTOCOL_ERR)
73
74 return stat;
75}
76
77/*!
78 \brief Receive double array
79
80 Returns an allocated array of doubles
81 Caller is responsible for free()
82
83 \param x
84 \param n
85
86 \return
87 */
88int db__recv_double_array(double **x, int *n)
89{
90 int stat = DB_OK;
91 int count = 0;
92 double *a = NULL;
93
94 if (!db__recv(&count, sizeof(count)))
96
97 *n = count;
98
99 *x = a = (double *)db_calloc(count, sizeof(*a));
100
101 if (!db__recv(a, count * sizeof(*a)))
103
104 if (stat == DB_PROTOCOL_ERR)
106
107 return stat;
108}
#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__recv_double_array(double **x, int *n)
Receive double array.
Definition xdrdouble.c:88
int db__send_double(double d)
Send double.
Definition xdrdouble.c:22
int db__send_double_array(const double *x, int n)
Send double array.
Definition xdrdouble.c:61
int db__recv_double(double *d)
Receive double.
Definition xdrdouble.c:40
#define x