source: git/src/netbits.h @ ed04c55

debug-cidebug-ci-sanitisersfaster-cavernlogwalls-datawalls-data-hanging-as-warning
Last change on this file since ed04c55 was 63d4f07, checked in by Olly Betts <olly@…>, 3 months ago

Use stdbool.h

We've required C99 since 1.4.2.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/* netbits.h
2 * Header file for miscellaneous primitive network routines for Survex
3 * Copyright (C) 1994,1997,1998,2001,2006,2015 Olly Betts
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#include <stdbool.h>
21
22void clear_last_leg(void);
23
24node *StnFromPfx(prefix *name);
25
26linkfor *copy_link(linkfor *leg);
27linkfor *addto_link(linkfor *leg, const linkfor *leg2);
28
29void addlegbyname(prefix *fr_name, prefix *to_name, bool fToFirst,
30                  real dx, real dy, real dz, real vx, real vy, real vz
31#ifndef NO_COVARIANCES
32                  , real cyz, real czx, real cxy
33#endif
34                  );
35
36void process_equate(prefix *name1, prefix *name2);
37
38void addfakeleg(node *fr, node *to,
39                real dx, real dy, real dz, real vx, real vy, real vz
40#ifndef NO_COVARIANCES
41                , real cyz, real czx, real cxy
42#endif
43                );
44
45/* insert at head of double-linked list */
46void add_stn_to_list(node **list, node *stn);
47
48/* remove from double-linked list */
49void remove_stn_from_list(node **list, node *stn);
50
51/* one node must only use leg[0] */
52#define one_node(S) (!(S)->leg[1] && (S)->leg[0])
53
54/* two node must only use leg[0] and leg[1] */
55#define two_node(S) (!(S)->leg[2] && (S)->leg[1])
56
57/* three node iff it uses leg[2] */
58#define three_node(S) ((S)->leg[2])
59
60/* NB FOR_EACH_STN() can't be nested - but it's hard to police as we can't
61 * easily set stn_iter to NULL if the loop is exited with break */
62
63/* Need stn_iter so we can adjust iterator if the stn it points to is deleted */
64extern node *stn_iter;
65#define FOR_EACH_STN(S,L) \
66 for (stn_iter = (L); ((S) = stn_iter) != NULL;\
67 stn_iter = ((S) == stn_iter) ? stn_iter->next : stn_iter)
68
69#define print_prefix(N) fprint_prefix(stdout, (N))
70
71char *sprint_prefix(const prefix *ptr);
72void fprint_prefix(FILE *fh, const prefix *ptr);
73
74/* r = ab ; r,a,b are variance matrices */
75void mulss(var *r, /*const*/ svar *a, /*const*/ svar *b);
76
77#ifdef NO_COVARIANCES
78/* In the NO_COVARIANCES case, v and s are the same so we only need one
79 * version. */
80# define smulvs(R,A,B) mulss(R,A,B)
81#else
82/* r = ab ; r,a,b are variance matrices */
83void smulvs(svar *r, /*const*/ var *a, /*const*/ svar *b);
84#endif
85
86/* r = ab ; r,b delta vectors; a variance matrix */
87void mulsd(delta *r, /*const*/ svar *a, /*const*/ delta *b);
88
89/* r = ca ; r,a variance matrices; c real scaling factor  */
90void mulsc(svar *r, /*const*/ svar *a, real c);
91
92/* r = a + b ; r,a,b delta vectors */
93void adddd(delta *r, /*const*/ delta *a, /*const*/ delta *b);
94
95/* r = a - b ; r,a,b delta vectors */
96void subdd(delta *r, /*const*/ delta *a, /*const*/ delta *b);
97
98/* r = a + b ; r,a,b variance matrices */
99void addss(svar *r, /*const*/ svar *a, /*const*/ svar *b);
100
101/* r = a - b ; r,a,b variance matrices */
102void subss(svar *r, /*const*/ svar *a, /*const*/ svar *b);
103
104/* r = (b^-1)a ; r,a delta vectors; b variance matrix */
105void divds(delta *r, /*const*/ delta *a, /*const*/ svar *b);
106
107/* inv = v^-1 ; inv,v variance matrices */
108int invert_svar(svar *inv, /*const*/ svar *v);
109
110/* Is v zero? */
111bool fZeros(/*const*/ svar *v);
112
113#define PR "%8.6f"
114
115#ifdef NO_COVARIANCES
116# define print_var(V) printf("("PR","PR","PR")\n", (V)[0], (V)[1], (V)[2])
117# define print_svar(V) printf("("PR","PR","PR")\n", (V)[0], (V)[1], (V)[2])
118#else
119# define print_var(V) \
120printf("/"PR","PR","PR"\\\n|"PR","PR","PR"|\n\\"PR","PR","PR"/\n",\
121(V)[0][0], (V)[0][1], (V)[0][2],\
122(V)[1][0], (V)[1][1], (V)[1][2],\
123(V)[2][0], (V)[2][1], (V)[2][2])
124# define print_svar(V) \
125printf("/"PR","PR","PR"\\\n:"PR","PR","PR":\n\\"PR","PR","PR"/\n",\
126(V)[0], (V)[3], (V)[4],\
127(V)[3], (V)[1], (V)[5],\
128(V)[4], (V)[5], (V)[2])
129#endif
130
131#define print_d(D) printf("("PR","PR","PR")", (D)[0], (D)[1], (D)[2])
Note: See TracBrowser for help on using the repository browser.