[421b7d2] | 1 | /* netbits.h |
---|
[d1b1380] | 2 | * Header file for miscellaneous primitive network routines for Survex |
---|
[bd1913f] | 3 | * Copyright (C) 1994,1997,1998,2001 Olly Betts |
---|
[846746e] | 4 | * |
---|
[89231c4] | 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. |
---|
[846746e] | 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 |
---|
[89231c4] | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
[846746e] | 14 | * |
---|
[89231c4] | 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[d1b1380] | 18 | */ |
---|
| 19 | |
---|
[a9f5117] | 20 | node *StnFromPfx(prefix *name); |
---|
[d1b1380] | 21 | |
---|
[a9f5117] | 22 | linkfor *copy_link(linkfor *leg); |
---|
| 23 | linkfor *addto_link(linkfor *leg, const linkfor *leg2); |
---|
[d1b1380] | 24 | |
---|
[a9f5117] | 25 | char freeleg(node **stnptr); |
---|
[d1b1380] | 26 | |
---|
[2140502] | 27 | void addlegbyname(prefix *fr_name, prefix *to_name, bool fToFirst, |
---|
| 28 | real dx, real dy, real dz, real vx, real vy, real vz |
---|
| 29 | #ifndef NO_COVARIANCES |
---|
| 30 | , real cyz, real czx, real cxy |
---|
| 31 | #endif |
---|
| 32 | ); |
---|
| 33 | |
---|
[be374fc] | 34 | void process_equate(prefix *name1, prefix *name2); |
---|
[d1b1380] | 35 | |
---|
[a9f5117] | 36 | void addfakeleg(node *fr, node *to, |
---|
| 37 | real dx, real dy, real dz, real vx, real vy, real vz |
---|
[233fbf7] | 38 | #ifndef NO_COVARIANCES |
---|
[a9f5117] | 39 | , real cyz, real czx, real cxy |
---|
[233fbf7] | 40 | #endif |
---|
[a9f5117] | 41 | ); |
---|
[d1b1380] | 42 | |
---|
[564f471] | 43 | /* insert at head of double-linked list */ |
---|
| 44 | void add_stn_to_list(node **list, node *stn); |
---|
| 45 | |
---|
| 46 | /* remove from double-linked list */ |
---|
| 47 | void remove_stn_from_list(node **list, node *stn); |
---|
| 48 | |
---|
| 49 | /* one node must only use leg[0] */ |
---|
| 50 | #define one_node(S) (!(S)->leg[1] && (S)->leg[0]) |
---|
| 51 | |
---|
| 52 | /* two node must only use leg[0] and leg[1] */ |
---|
| 53 | #define two_node(S) (!(S)->leg[2] && (S)->leg[1]) |
---|
| 54 | |
---|
| 55 | /* three node iff it uses leg[2] */ |
---|
| 56 | #define three_node(S) ((S)->leg[2]) |
---|
| 57 | |
---|
| 58 | /* NB FOR_EACH_STN() can't be nested - but it's hard to police as we can't |
---|
| 59 | * easily set stn_iter to NULL if the loop is exited with break */ |
---|
| 60 | |
---|
| 61 | /* Need stn_iter so we can adjust iterator if the stn it points to is deleted */ |
---|
| 62 | extern node *stn_iter; |
---|
| 63 | #define FOR_EACH_STN(S,L) \ |
---|
[e917a13] | 64 | for (stn_iter = (L); ((S) = stn_iter) != NULL;\ |
---|
[564f471] | 65 | stn_iter = ((S) == stn_iter) ? stn_iter->next : stn_iter) |
---|
| 66 | |
---|
[a420b49] | 67 | #define print_prefix(N) fprint_prefix(stdout, (N)) |
---|
[d1b1380] | 68 | |
---|
[a7217d0] | 69 | char *sprint_prefix(const prefix *ptr); |
---|
| 70 | void fprint_prefix(FILE *fh, const prefix *ptr); |
---|
[d1b1380] | 71 | |
---|
| 72 | /* r = ab ; r,a,b are variance matrices */ |
---|
[407084d] | 73 | void mulvv(var *r, /*const*/ var *a, /*const*/ var *b); |
---|
[d1b1380] | 74 | |
---|
[59f2dbb] | 75 | /* r = ab ; r,a,b are variance matrices */ |
---|
| 76 | void mulss(var *r, /*const*/ svar *a, /*const*/ svar *b); |
---|
| 77 | |
---|
| 78 | /* r = ab ; r,a,b are variance matrices */ |
---|
| 79 | void smulvs(svar *r, /*const*/ var *a, /*const*/ svar *b); |
---|
| 80 | |
---|
[d1b1380] | 81 | /* r = ab ; r,b delta vectors; a variance matrix */ |
---|
[eb18f4d] | 82 | void mulvd(delta *r, /*const*/ var *a, /*const*/ delta *b); |
---|
[a7217d0] | 83 | |
---|
[59f2dbb] | 84 | /* r = ab ; r,b delta vectors; a variance matrix */ |
---|
| 85 | void mulsd(delta *r, /*const*/ svar *a, /*const*/ delta *b); |
---|
| 86 | |
---|
[a7217d0] | 87 | /* r = ca ; r,a variance matrices; c real scaling factor */ |
---|
[407084d] | 88 | void mulvc(var *r, /*const*/ var *a, real c); |
---|
[d1b1380] | 89 | |
---|
[59f2dbb] | 90 | /* r = ca ; r,a variance matrices; c real scaling factor */ |
---|
| 91 | void mulsc(svar *r, /*const*/ svar *a, real c); |
---|
| 92 | |
---|
[c13e2f6] | 93 | /* r = ca ; r,a delta vectors; c real scaling factor */ |
---|
[eb18f4d] | 94 | void muldc(delta *r, /*const*/ delta *a, real c); |
---|
[c13e2f6] | 95 | |
---|
[d1b1380] | 96 | /* r = a + b ; r,a,b delta vectors */ |
---|
[eb18f4d] | 97 | void adddd(delta *r, /*const*/ delta *a, /*const*/ delta *b); |
---|
[d1b1380] | 98 | |
---|
| 99 | /* r = a - b ; r,a,b delta vectors */ |
---|
[eb18f4d] | 100 | void subdd(delta *r, /*const*/ delta *a, /*const*/ delta *b); |
---|
[d1b1380] | 101 | |
---|
| 102 | /* r = a + b ; r,a,b variance matrices */ |
---|
[407084d] | 103 | void addvv(var *r, /*const*/ var *a, /*const*/ var *b); |
---|
[d1b1380] | 104 | |
---|
[59f2dbb] | 105 | /* r = a + b ; r,a,b variance matrices */ |
---|
| 106 | void addss(svar *r, /*const*/ svar *a, /*const*/ svar *b); |
---|
| 107 | |
---|
[233fbf7] | 108 | /* r = a - b ; r,a,b variance matrices */ |
---|
[407084d] | 109 | void subvv(var *r, /*const*/ var *a, /*const*/ var *b); |
---|
[233fbf7] | 110 | |
---|
[59f2dbb] | 111 | /* r = a - b ; r,a,b variance matrices */ |
---|
| 112 | void subss(svar *r, /*const*/ svar *a, /*const*/ svar *b); |
---|
| 113 | |
---|
[a7217d0] | 114 | /* r = (b^-1)a ; r,a delta vectors; b variance matrix */ |
---|
[eb18f4d] | 115 | void divdv(delta *r, /*const*/ delta *a, /*const*/ var *b); |
---|
[d1b1380] | 116 | |
---|
[59f2dbb] | 117 | /* r = (b^-1)a ; r,a delta vectors; b variance matrix */ |
---|
| 118 | void divds(delta *r, /*const*/ delta *a, /*const*/ svar *b); |
---|
| 119 | |
---|
[d1b1380] | 120 | /* r = a(b^-1) ; r,a,b variance matrices */ |
---|
[407084d] | 121 | void divvv(var *r, /*const*/ var *a, /*const*/ var *b); |
---|
[d1b1380] | 122 | |
---|
[233fbf7] | 123 | /* inv = v^-1 ; inv,v variance matrices */ |
---|
[407084d] | 124 | int invert_var(var *inv, /*const*/ var *v); |
---|
[233fbf7] | 125 | |
---|
[59f2dbb] | 126 | /* inv = v^-1 ; inv,v variance matrices */ |
---|
[dac18d8] | 127 | int invert_svar(svar *inv, /*const*/ svar *v); |
---|
[6ed08fb] | 128 | |
---|
[59f2dbb] | 129 | /* Is v zero? */ |
---|
| 130 | bool fZeros(/*const*/ svar *v); |
---|
| 131 | |
---|
| 132 | #ifdef NO_COVARIANCES |
---|
| 133 | #define mulss mulvv |
---|
| 134 | #define smulvs mulvv |
---|
| 135 | #define mulsd mulvd |
---|
| 136 | #define mulsc mulvc |
---|
| 137 | #define addss addvv |
---|
| 138 | #define subss subvv |
---|
| 139 | #define divds divdv |
---|
| 140 | #define invert_svar invert_var |
---|
| 141 | #endif |
---|
| 142 | |
---|
[bd1913f] | 143 | #define PR "%8.6f" |
---|
[9aed2cc] | 144 | |
---|
[6ed08fb] | 145 | #ifdef NO_COVARIANCES |
---|
[bd1913f] | 146 | # define print_var(V) printf("("PR","PR","PR")\n", (V)[0], (V)[1], (V)[2]) |
---|
[59f2dbb] | 147 | # define print_svar(V) printf("("PR","PR","PR")\n", (V)[0], (V)[1], (V)[2]) |
---|
[6ed08fb] | 148 | #else |
---|
| 149 | # define print_var(V) \ |
---|
[bd1913f] | 150 | printf("/"PR","PR","PR"\\\n|"PR","PR","PR"|\n\\"PR","PR","PR"/\n",\ |
---|
[6ed08fb] | 151 | (V)[0][0], (V)[0][1], (V)[0][2],\ |
---|
| 152 | (V)[1][0], (V)[1][1], (V)[1][2],\ |
---|
| 153 | (V)[2][0], (V)[2][1], (V)[2][2]) |
---|
[59f2dbb] | 154 | # define print_svar(V) \ |
---|
| 155 | printf("/"PR","PR","PR"\\\n:"PR","PR","PR":\n\\"PR","PR","PR"/\n",\ |
---|
| 156 | (V)[0], (V)[3], (V)[4],\ |
---|
| 157 | (V)[3], (V)[1], (V)[5],\ |
---|
| 158 | (V)[4], (V)[5], (V)[2]) |
---|
[6ed08fb] | 159 | #endif |
---|
[71cd713] | 160 | |
---|
[bd1913f] | 161 | #define print_d(D) printf("("PR","PR","PR")", (D)[0], (D)[1], (D)[2]) |
---|