GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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  (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 double
19 
20  \param d
21 
22  \return
23 */
24 int db__send_double(double d)
25 {
26  int stat = DB_OK;
27 
28  if (!db__send(&d, sizeof(d)))
29  stat = DB_PROTOCOL_ERR;
30 
31  if (stat == DB_PROTOCOL_ERR)
33 
34  return stat;
35 }
36 
37 /*!
38  \brief Receive double
39 
40  \param d
41 */
42 int db__recv_double(double *d)
43 {
44  int stat = DB_OK;
45 
46  if (!db__recv(d, sizeof(*d)))
47  stat = DB_PROTOCOL_ERR;
48 
49  if (stat == DB_PROTOCOL_ERR)
51 
52  return stat;
53 }
54 
55 /*!
56  \brief Send double array
57 
58  \param x
59  \param n
60 
61  \return
62 */ \
63 int db__send_double_array(const double *x, int n)
64 {
65  int stat = DB_OK;
66 
67  if (!db__send(&n, sizeof(n)))
68  stat = DB_PROTOCOL_ERR;
69 
70  if (!db__send(x, n * sizeof(*x)))
71  stat = DB_PROTOCOL_ERR;
72 
73  if (stat == DB_PROTOCOL_ERR)
75 
76  return stat;
77 }
78 
79 /*!
80  \brief Receive double array
81 
82  Returns an allocated array of doubles
83  Caller is responsible for free()
84 
85  \param x
86  \param n
87 
88  \return
89 */
90 int db__recv_double_array(double **x, int *n)
91 {
92  int stat = DB_OK;
93  int count = 0;
94  double *a = NULL;
95 
96  if (!db__recv(&count, sizeof(count)))
97  stat = DB_PROTOCOL_ERR;
98 
99  *n = count;
100 
101  *x = a = (double *)db_calloc(count, sizeof(*a));
102 
103  if (!db__recv(a, count * sizeof(*a)))
104  stat = DB_PROTOCOL_ERR;
105 
106  if (stat == DB_PROTOCOL_ERR)
108 
109  return stat;
110 }
int db__recv_double_array(double **x, int *n)
Receive double array.
Definition: xdrdouble.c:90
#define DB_PROTOCOL_ERR
Definition: dbmi.h:75
int db__send_double(double d)
Send double.
Definition: xdrdouble.c:24
int count
#define NULL
Definition: ccmath.h:32
#define x
int db__send_double_array(const double *x, int n)
Send double array.
Definition: xdrdouble.c:63
void * db_calloc(int, int)
Allocate memory.
int db__recv(void *buf, size_t size)
void db_protocol_error(void)
Report protocol error.
int db__send(const void *buf, size_t size)
?
int db__recv_double(double *d)
Receive double.
Definition: xdrdouble.c:42
#define DB_OK
Definition: dbmi.h:71