[7bb8184] | 1 | /* netbits.h |
---|
| 2 | * Header file for miscellaneous primitive network routines for Survex |
---|
| 3 | * Copyright (C) 1994,1997,1998,2001,2006 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 | node *StnFromPfx(prefix *name); |
---|
| 21 | |
---|
| 22 | linkfor *copy_link(linkfor *leg); |
---|
| 23 | linkfor *addto_link(linkfor *leg, const linkfor *leg2); |
---|
| 24 | |
---|
| 25 | void addlegbyname(prefix *fr_name, prefix *to_name, bool fToFirst, |
---|
| 26 | real dx, real dy, real dz, real vx, real vy, real vz |
---|
| 27 | #ifndef NO_COVARIANCES |
---|
| 28 | , real cyz, real czx, real cxy |
---|
| 29 | #endif |
---|
| 30 | ); |
---|
| 31 | |
---|
| 32 | void process_equate(prefix *name1, prefix *name2); |
---|
| 33 | |
---|
| 34 | void addfakeleg(node *fr, node *to, |
---|
| 35 | real dx, real dy, real dz, real vx, real vy, real vz |
---|
| 36 | #ifndef NO_COVARIANCES |
---|
| 37 | , real cyz, real czx, real cxy |
---|
| 38 | #endif |
---|
| 39 | ); |
---|
| 40 | |
---|
| 41 | /* insert at head of double-linked list */ |
---|
| 42 | void add_stn_to_list(node **list, node *stn); |
---|
| 43 | |
---|
| 44 | /* remove from double-linked list */ |
---|
| 45 | void remove_stn_from_list(node **list, node *stn); |
---|
| 46 | |
---|
| 47 | /* one node must only use leg[0] */ |
---|
| 48 | #define one_node(S) (!(S)->leg[1] && (S)->leg[0]) |
---|
| 49 | |
---|
| 50 | /* two node must only use leg[0] and leg[1] */ |
---|
| 51 | #define two_node(S) (!(S)->leg[2] && (S)->leg[1]) |
---|
| 52 | |
---|
| 53 | /* three node iff it uses leg[2] */ |
---|
| 54 | #define three_node(S) ((S)->leg[2]) |
---|
| 55 | |
---|
| 56 | /* NB FOR_EACH_STN() can't be nested - but it's hard to police as we can't |
---|
| 57 | * easily set stn_iter to NULL if the loop is exited with break */ |
---|
| 58 | |
---|
| 59 | /* Need stn_iter so we can adjust iterator if the stn it points to is deleted */ |
---|
| 60 | extern node *stn_iter; |
---|
| 61 | #define FOR_EACH_STN(S,L) \ |
---|
| 62 | for (stn_iter = (L); ((S) = stn_iter) != NULL;\ |
---|
| 63 | stn_iter = ((S) == stn_iter) ? stn_iter->next : stn_iter) |
---|
| 64 | |
---|
| 65 | #define print_prefix(N) fprint_prefix(stdout, (N)) |
---|
| 66 | |
---|
| 67 | char *sprint_prefix(const prefix *ptr); |
---|
| 68 | void fprint_prefix(FILE *fh, const prefix *ptr); |
---|
| 69 | |
---|
| 70 | /* r = ab ; r,a,b are variance matrices */ |
---|
| 71 | void mulss(var *r, /*const*/ svar *a, /*const*/ svar *b); |
---|
| 72 | |
---|
| 73 | #ifdef NO_COVARIANCES |
---|
| 74 | /* In the NO_COVARIANCES case, v and s are the same so we only need one |
---|
| 75 | * version. */ |
---|
| 76 | # define smulvs(R,A,B) mulss(R,A,B) |
---|
| 77 | #else |
---|
| 78 | /* r = ab ; r,a,b are variance matrices */ |
---|
| 79 | void smulvs(svar *r, /*const*/ var *a, /*const*/ svar *b); |
---|
| 80 | #endif |
---|
| 81 | |
---|
| 82 | /* r = ab ; r,b delta vectors; a variance matrix */ |
---|
| 83 | void mulsd(delta *r, /*const*/ svar *a, /*const*/ delta *b); |
---|
| 84 | |
---|
| 85 | /* r = ca ; r,a variance matrices; c real scaling factor */ |
---|
| 86 | void mulsc(svar *r, /*const*/ svar *a, real c); |
---|
| 87 | |
---|
| 88 | /* r = a + b ; r,a,b delta vectors */ |
---|
| 89 | void adddd(delta *r, /*const*/ delta *a, /*const*/ delta *b); |
---|
| 90 | |
---|
| 91 | /* r = a - b ; r,a,b delta vectors */ |
---|
| 92 | void subdd(delta *r, /*const*/ delta *a, /*const*/ delta *b); |
---|
| 93 | |
---|
| 94 | /* r = a + b ; r,a,b variance matrices */ |
---|
| 95 | void addss(svar *r, /*const*/ svar *a, /*const*/ svar *b); |
---|
| 96 | |
---|
| 97 | /* r = a - b ; r,a,b variance matrices */ |
---|
| 98 | void subss(svar *r, /*const*/ svar *a, /*const*/ svar *b); |
---|
| 99 | |
---|
| 100 | /* r = (b^-1)a ; r,a delta vectors; b variance matrix */ |
---|
| 101 | void divds(delta *r, /*const*/ delta *a, /*const*/ svar *b); |
---|
| 102 | |
---|
| 103 | /* inv = v^-1 ; inv,v variance matrices */ |
---|
| 104 | int invert_svar(svar *inv, /*const*/ svar *v); |
---|
| 105 | |
---|
| 106 | /* Is v zero? */ |
---|
| 107 | bool fZeros(/*const*/ svar *v); |
---|
| 108 | |
---|
| 109 | #define PR "%8.6f" |
---|
| 110 | |
---|
| 111 | #ifdef NO_COVARIANCES |
---|
| 112 | # define print_var(V) printf("("PR","PR","PR")\n", (V)[0], (V)[1], (V)[2]) |
---|
| 113 | # define print_svar(V) printf("("PR","PR","PR")\n", (V)[0], (V)[1], (V)[2]) |
---|
| 114 | #else |
---|
| 115 | # define print_var(V) \ |
---|
| 116 | printf("/"PR","PR","PR"\\\n|"PR","PR","PR"|\n\\"PR","PR","PR"/\n",\ |
---|
| 117 | (V)[0][0], (V)[0][1], (V)[0][2],\ |
---|
| 118 | (V)[1][0], (V)[1][1], (V)[1][2],\ |
---|
| 119 | (V)[2][0], (V)[2][1], (V)[2][2]) |
---|
| 120 | # define print_svar(V) \ |
---|
| 121 | printf("/"PR","PR","PR"\\\n:"PR","PR","PR":\n\\"PR","PR","PR"/\n",\ |
---|
| 122 | (V)[0], (V)[3], (V)[4],\ |
---|
| 123 | (V)[3], (V)[1], (V)[5],\ |
---|
| 124 | (V)[4], (V)[5], (V)[2]) |
---|
| 125 | #endif |
---|
| 126 | |
---|
| 127 | #define print_d(D) printf("("PR","PR","PR")", (D)[0], (D)[1], (D)[2]) |
---|