[b0d908e] | 1 | /* datain.c |
---|
[d1b1380] | 2 | * Reads in survey files, dealing with special characters, keywords & data |
---|
[107b8bd] | 3 | * Copyright (C) 1991-2002 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 | |
---|
[a420b49] | 20 | #ifdef HAVE_CONFIG_H |
---|
| 21 | #include <config.h> |
---|
| 22 | #endif |
---|
[d1b1380] | 23 | |
---|
| 24 | #include <limits.h> |
---|
[a420b49] | 25 | #include <stdarg.h> |
---|
[d1b1380] | 26 | |
---|
| 27 | #include "debug.h" |
---|
[a420b49] | 28 | #include "cavern.h" |
---|
[07025e3] | 29 | #include "filename.h" |
---|
| 30 | #include "message.h" |
---|
[d1b1380] | 31 | #include "filelist.h" |
---|
| 32 | #include "netbits.h" |
---|
[5853657] | 33 | #include "netskel.h" |
---|
[d1b1380] | 34 | #include "readval.h" |
---|
| 35 | #include "datain.h" |
---|
| 36 | #include "commands.h" |
---|
| 37 | #include "out.h" |
---|
[39fba51] | 38 | #include "str.h" |
---|
[d1b1380] | 39 | |
---|
[2b078c4] | 40 | #define EPSILON (REAL_EPSILON * 1000) |
---|
[d1b1380] | 41 | |
---|
[58cc1fb] | 42 | #define var(I) (pcs->Var[(I)]) |
---|
[d1b1380] | 43 | |
---|
[58cc1fb] | 44 | int ch; |
---|
[d1b1380] | 45 | |
---|
[fa42426] | 46 | typedef enum {CTYPE_OMIT, CTYPE_READING, CTYPE_PLUMB, CTYPE_HORIZ} clino_type; |
---|
[5b7c1b7] | 47 | |
---|
[eb18f4d] | 48 | /* Don't explicitly initialise as we can't set the jmp_buf - this has |
---|
| 49 | * static scope so will be initialised like this anyway */ |
---|
[b0d908e] | 50 | parse file /* = { NULL, NULL, 0, fFalse, NULL } */ ; |
---|
[a420b49] | 51 | |
---|
[932f7e9] | 52 | bool f_export_ok; |
---|
| 53 | |
---|
[c80bd34] | 54 | static filepos fpLineStart; |
---|
[d1b1380] | 55 | |
---|
[c7451a9] | 56 | void |
---|
[c80bd34] | 57 | get_pos(filepos *fp) |
---|
[c7451a9] | 58 | { |
---|
[c80bd34] | 59 | fp->ch = ch; |
---|
| 60 | fp->offset = ftell(file.fh); |
---|
| 61 | if (fp->offset == -1) |
---|
[c7451a9] | 62 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
| 63 | } |
---|
| 64 | |
---|
[c80bd34] | 65 | void |
---|
| 66 | set_pos(const filepos *fp) |
---|
[c7451a9] | 67 | { |
---|
[c80bd34] | 68 | ch = fp->ch; |
---|
| 69 | if (fseek(file.fh, fp->offset, SEEK_SET) == -1) |
---|
[c7451a9] | 70 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
| 71 | } |
---|
| 72 | |
---|
[44bf1d9] | 73 | static void |
---|
[993454b] | 74 | push_back(int c) |
---|
| 75 | { |
---|
| 76 | if (c != EOF && ungetc(c, file.fh) == EOF) |
---|
| 77 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
| 78 | } |
---|
| 79 | |
---|
[a420b49] | 80 | static void |
---|
| 81 | error_list_parent_files(void) |
---|
| 82 | { |
---|
[b0d908e] | 83 | if (!file.reported_where && file.parent) { |
---|
[421b7d2] | 84 | parse *p = file.parent; |
---|
[46cb98f] | 85 | const char *m = msg(/*In file included from*/5); |
---|
[84c60fc] | 86 | size_t len = strlen(m); |
---|
[b0d908e] | 87 | |
---|
[84c60fc] | 88 | fprintf(STDERR, m); |
---|
[46cb98f] | 89 | m = msg(/*from*/3); |
---|
[b0d908e] | 90 | |
---|
| 91 | /* Suppress reporting of full include tree for further errors |
---|
| 92 | * in this file */ |
---|
| 93 | file.reported_where = fTrue; |
---|
| 94 | |
---|
[a420b49] | 95 | while (p) { |
---|
[b0d908e] | 96 | /* Force re-report of include tree for further errors in |
---|
| 97 | * parent files */ |
---|
| 98 | p->reported_where = fFalse; |
---|
[46cb98f] | 99 | fprintf(STDERR, " %s:%d", p->filename, p->line); |
---|
[a420b49] | 100 | p = p->parent; |
---|
[84f3ed6] | 101 | if (p) fprintf(STDERR, ",\n%*s", (int)len, m); |
---|
[a420b49] | 102 | } |
---|
| 103 | fprintf(STDERR, ":\n"); |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void |
---|
| 108 | compile_error(int en, ...) |
---|
| 109 | { |
---|
| 110 | va_list ap; |
---|
| 111 | va_start(ap, en); |
---|
| 112 | error_list_parent_files(); |
---|
| 113 | v_report(1, file.filename, file.line, en, ap); |
---|
| 114 | va_end(ap); |
---|
| 115 | } |
---|
| 116 | |
---|
[fa42426] | 117 | void |
---|
| 118 | compile_error_skip(int en, ...) |
---|
| 119 | { |
---|
| 120 | va_list ap; |
---|
| 121 | va_start(ap, en); |
---|
| 122 | error_list_parent_files(); |
---|
| 123 | v_report(1, file.filename, file.line, en, ap); |
---|
| 124 | va_end(ap); |
---|
| 125 | skipline(); |
---|
| 126 | } |
---|
| 127 | |
---|
[39fba51] | 128 | void |
---|
| 129 | compile_error_token(int en) |
---|
| 130 | { |
---|
| 131 | char *p = NULL; |
---|
| 132 | static int len; |
---|
| 133 | s_zero(&p); |
---|
| 134 | skipblanks(); |
---|
| 135 | while (!isBlank(ch) && !isEol(ch)) { |
---|
| 136 | s_catchar(&p, &len, ch); |
---|
| 137 | nextch(); |
---|
| 138 | } |
---|
[fa42426] | 139 | compile_error_skip(en, p ? p : ""); |
---|
[39fba51] | 140 | osfree(p); |
---|
| 141 | } |
---|
| 142 | |
---|
[a420b49] | 143 | void |
---|
| 144 | compile_warning(int en, ...) |
---|
| 145 | { |
---|
| 146 | va_list ap; |
---|
| 147 | va_start(ap, en); |
---|
| 148 | error_list_parent_files(); |
---|
| 149 | v_report(0, file.filename, file.line, en, ap); |
---|
| 150 | va_end(ap); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | /* This function makes a note where to put output files */ |
---|
| 154 | static void |
---|
| 155 | using_data_file(const char *fnm) |
---|
| 156 | { |
---|
| 157 | if (!fnm_output_base) { |
---|
[4bab027] | 158 | /* was: fnm_output_base = base_from_fnm(fnm); */ |
---|
| 159 | fnm_output_base = baseleaf_from_fnm(fnm); |
---|
| 160 | } else if (fnm_output_base_is_dir) { |
---|
| 161 | /* --output pointed to directory so use the leaf basename in that dir */ |
---|
| 162 | char *lf, *p; |
---|
| 163 | lf = baseleaf_from_fnm(fnm); |
---|
| 164 | p = use_path(fnm_output_base, lf); |
---|
| 165 | osfree(lf); |
---|
| 166 | osfree(fnm_output_base); |
---|
| 167 | fnm_output_base = p; |
---|
| 168 | fnm_output_base_is_dir = 0; |
---|
[58cc1fb] | 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
[a420b49] | 172 | static void |
---|
| 173 | skipword(void) |
---|
| 174 | { |
---|
[58cc1fb] | 175 | while (!isBlank(ch) && !isEol(ch)) nextch(); |
---|
[d1b1380] | 176 | } |
---|
| 177 | |
---|
[a420b49] | 178 | extern void |
---|
| 179 | skipblanks(void) |
---|
| 180 | { |
---|
[58cc1fb] | 181 | while (isBlank(ch)) nextch(); |
---|
[d1b1380] | 182 | } |
---|
| 183 | |
---|
[a420b49] | 184 | extern void |
---|
| 185 | skipline(void) |
---|
| 186 | { |
---|
[58cc1fb] | 187 | while (!isEol(ch)) nextch(); |
---|
[d1b1380] | 188 | } |
---|
| 189 | |
---|
[90bb053f] | 190 | #ifndef NO_PERCENTAGE |
---|
| 191 | static long int filelen; |
---|
| 192 | #endif |
---|
| 193 | |
---|
| 194 | static void |
---|
| 195 | process_bol(void) |
---|
| 196 | { |
---|
| 197 | /* Note start of line for error reporting */ |
---|
[c80bd34] | 198 | get_pos(&fpLineStart); |
---|
[90bb053f] | 199 | |
---|
| 200 | #ifndef NO_PERCENTAGE |
---|
| 201 | /* print %age of file done */ |
---|
[c80bd34] | 202 | if (filelen > 0) |
---|
| 203 | printf("%d%%\r", (int)(100 * fpLineStart.offset / filelen)); |
---|
[90bb053f] | 204 | #endif |
---|
| 205 | |
---|
| 206 | nextch(); |
---|
| 207 | skipblanks(); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | static void |
---|
| 211 | process_eol(void) |
---|
| 212 | { |
---|
| 213 | int eolchar; |
---|
| 214 | |
---|
| 215 | skipblanks(); |
---|
| 216 | |
---|
| 217 | if (!isEol(ch)) { |
---|
[44bf1d9] | 218 | if (!isComm(ch)) compile_error(/*End of line not blank*/15); |
---|
[90bb053f] | 219 | skipline(); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | eolchar = ch; |
---|
| 223 | file.line++; |
---|
| 224 | /* skip any different eol characters so we get line counts correct on |
---|
| 225 | * DOS text files and similar, but don't count several adjacent blank |
---|
| 226 | * lines as one */ |
---|
| 227 | while (ch != EOF) { |
---|
| 228 | nextch(); |
---|
| 229 | if (ch == eolchar || !isEol(ch)) { |
---|
[993454b] | 230 | push_back(ch); |
---|
[90bb053f] | 231 | break; |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | static bool |
---|
| 237 | process_non_data_line(void) |
---|
| 238 | { |
---|
| 239 | process_bol(); |
---|
| 240 | |
---|
| 241 | if (isData(ch)) return fFalse; |
---|
| 242 | |
---|
| 243 | if (isKeywd(ch)) { |
---|
| 244 | nextch(); |
---|
| 245 | handle_command(); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | process_eol(); |
---|
| 249 | |
---|
| 250 | return fTrue; |
---|
| 251 | } |
---|
| 252 | |
---|
[a420b49] | 253 | extern void |
---|
| 254 | data_file(const char *pth, const char *fnm) |
---|
| 255 | { |
---|
[47c7a94] | 256 | int begin_lineno_store; |
---|
[7f08c83] | 257 | parse file_store; |
---|
[d1b1380] | 258 | |
---|
[7f08c83] | 259 | { |
---|
| 260 | char *filename; |
---|
[f4b609d] | 261 | FILE *fh; |
---|
| 262 | if (!pth) { |
---|
| 263 | /* file specified on command line - don't do special translation */ |
---|
| 264 | fh = fopenWithPthAndExt(pth, fnm, EXT_SVX_DATA, "rb", &filename); |
---|
| 265 | } else { |
---|
| 266 | fh = fopen_portable(pth, fnm, EXT_SVX_DATA, "rb", &filename); |
---|
| 267 | } |
---|
[bd1913f] | 268 | |
---|
[7f08c83] | 269 | if (fh == NULL) { |
---|
[759fb47] | 270 | compile_error(/*Couldn't open data file `%s'*/24, fnm); |
---|
[7f08c83] | 271 | return; |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | file_store = file; |
---|
| 275 | if (file.fh) file.parent = &file_store; |
---|
| 276 | file.fh = fh; |
---|
| 277 | file.filename = filename; |
---|
| 278 | file.line = 1; |
---|
[b0d908e] | 279 | file.reported_where = fFalse; |
---|
[a420b49] | 280 | } |
---|
[cb3d1e2] | 281 | |
---|
[5b68ae1] | 282 | if (fPercent) printf("%s:\n", fnm); |
---|
[d1b1380] | 283 | |
---|
[a420b49] | 284 | using_data_file(file.filename); |
---|
[d1b1380] | 285 | |
---|
[47c7a94] | 286 | begin_lineno_store = pcs->begin_lineno; |
---|
| 287 | pcs->begin_lineno = 0; |
---|
[cb3d1e2] | 288 | |
---|
[d1b1380] | 289 | #ifndef NO_PERCENTAGE |
---|
[58cc1fb] | 290 | /* Try to find how long the file is... |
---|
| 291 | * However, under ANSI fseek( ..., SEEK_END) may not be supported */ |
---|
| 292 | filelen = 0; |
---|
| 293 | if (fPercent) { |
---|
[c80bd34] | 294 | if (fseek(file.fh, 0l, SEEK_END) == 0) { |
---|
| 295 | filepos fp; |
---|
| 296 | get_pos(&fp); |
---|
| 297 | filelen = fp.offset; |
---|
| 298 | } |
---|
[58cc1fb] | 299 | rewind(file.fh); /* reset file ptr to start & clear any error state */ |
---|
| 300 | } |
---|
[d1b1380] | 301 | #endif |
---|
| 302 | |
---|
[7d5f3c0] | 303 | #ifdef HAVE_SETJMP_H |
---|
[a420b49] | 304 | /* errors in nested functions can longjmp here */ |
---|
| 305 | if (setjmp(file.jbSkipLine)) { |
---|
[076d33d] | 306 | process_eol(); |
---|
[a420b49] | 307 | } |
---|
[d1b1380] | 308 | #endif |
---|
[cb3d1e2] | 309 | |
---|
[c7451a9] | 310 | while (!feof(file.fh) && !ferror(file.fh)) { |
---|
[90bb053f] | 311 | if (!process_non_data_line()) { |
---|
[107b8bd] | 312 | int r; |
---|
[647407d] | 313 | #ifdef NEW3DFORMAT |
---|
[407084d] | 314 | twig *temp = limb; |
---|
[647407d] | 315 | #endif |
---|
[407084d] | 316 | f_export_ok = fFalse; |
---|
[107b8bd] | 317 | switch (pcs->style) { |
---|
| 318 | case STYLE_NORMAL: |
---|
| 319 | case STYLE_DIVING: |
---|
| 320 | case STYLE_CYLPOLAR: |
---|
| 321 | r = data_normal(); |
---|
| 322 | break; |
---|
| 323 | case STYLE_CARTESIAN: |
---|
| 324 | r = data_cartesian(); |
---|
| 325 | break; |
---|
| 326 | case STYLE_NOSURVEY: |
---|
| 327 | r = data_nosurvey(); |
---|
| 328 | break; |
---|
| 329 | case STYLE_IGNORE: |
---|
| 330 | r = data_ignore(); |
---|
| 331 | break; |
---|
| 332 | default: |
---|
| 333 | BUG("bad style"); |
---|
| 334 | } |
---|
[90bb053f] | 335 | /* style function returns 0 => error */ |
---|
[107b8bd] | 336 | if (!r) { |
---|
[647407d] | 337 | #ifdef NEW3DFORMAT |
---|
[90bb053f] | 338 | /* we have just created a very naughty twiglet, and it must be |
---|
| 339 | * punished */ |
---|
[647407d] | 340 | osfree(limb); |
---|
| 341 | limb = temp; |
---|
| 342 | #endif |
---|
[a420b49] | 343 | } |
---|
[647407d] | 344 | } |
---|
[a420b49] | 345 | } |
---|
| 346 | |
---|
[932f7e9] | 347 | /* don't allow *BEGIN at the end of a file, then *EXPORT in the |
---|
| 348 | * including file */ |
---|
| 349 | f_export_ok = fFalse; |
---|
| 350 | |
---|
[a420b49] | 351 | #ifndef NO_PERCENTAGE |
---|
| 352 | if (fPercent) putnl(); |
---|
[4f8285d] | 353 | #endif |
---|
[d1b1380] | 354 | |
---|
[47c7a94] | 355 | if (pcs->begin_lineno) { |
---|
[0e867ba6] | 356 | error_in_file(file.filename, pcs->begin_lineno, |
---|
| 357 | /*BEGIN with no matching END in this file*/23); |
---|
[47c7a94] | 358 | /* Implicitly close any unclosed BEGINs from this file */ |
---|
| 359 | do { |
---|
| 360 | settings *pcsParent = pcs->next; |
---|
| 361 | ASSERT(pcsParent); |
---|
[647407d] | 362 | free_settings(pcs); |
---|
[47c7a94] | 363 | pcs = pcsParent; |
---|
| 364 | } while (pcs->begin_lineno); |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | pcs->begin_lineno = begin_lineno_store; |
---|
[cb3d1e2] | 368 | |
---|
[22c9877] | 369 | if (ferror(file.fh)) |
---|
[bfe1242] | 370 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
[cb3d1e2] | 371 | |
---|
[22c9877] | 372 | (void)fclose(file.fh); |
---|
[7f08c83] | 373 | |
---|
[22c9877] | 374 | file = file_store; |
---|
[4d9eecd] | 375 | |
---|
| 376 | /* don't free this - it may be pointed to by prefix.file */ |
---|
| 377 | /* osfree(file.filename); */ |
---|
[a420b49] | 378 | } |
---|
[d1b1380] | 379 | |
---|
[b6de07d] | 380 | static real |
---|
| 381 | mod2pi(real a) |
---|
| 382 | { |
---|
| 383 | return a - floor(a / (2 * M_PI)) * (2 * M_PI); |
---|
| 384 | } |
---|
| 385 | |
---|
[dcec245] | 386 | static real |
---|
[5b7c1b7] | 387 | handle_plumb(clino_type *p_ctype) |
---|
[dcec245] | 388 | { |
---|
| 389 | typedef enum { |
---|
| 390 | CLINO_NULL=-1, CLINO_UP, CLINO_DOWN, CLINO_LEVEL |
---|
| 391 | } clino_tok; |
---|
| 392 | static sztok clino_tab[] = { |
---|
| 393 | {"D", CLINO_DOWN}, |
---|
| 394 | {"DOWN", CLINO_DOWN}, |
---|
| 395 | {"H", CLINO_LEVEL}, |
---|
| 396 | {"LEVEL", CLINO_LEVEL}, |
---|
| 397 | {"U", CLINO_UP}, |
---|
| 398 | {"UP", CLINO_UP}, |
---|
| 399 | {NULL, CLINO_NULL} |
---|
| 400 | }; |
---|
[5b7c1b7] | 401 | static real clinos[] = {(real)M_PI_2, (real)(-M_PI_2), (real)0.0}; |
---|
[dcec245] | 402 | clino_tok tok; |
---|
| 403 | |
---|
| 404 | skipblanks(); |
---|
| 405 | if (isalpha(ch)) { |
---|
[c80bd34] | 406 | filepos fp; |
---|
| 407 | get_pos(&fp); |
---|
[dcec245] | 408 | get_token(); |
---|
| 409 | tok = match_tok(clino_tab, TABSIZE(clino_tab)); |
---|
| 410 | if (tok != CLINO_NULL) { |
---|
[fa42426] | 411 | *p_ctype = (clinos[tok] == CLINO_LEVEL ? CTYPE_HORIZ : CTYPE_PLUMB); |
---|
[dcec245] | 412 | return clinos[tok]; |
---|
| 413 | } |
---|
[c80bd34] | 414 | set_pos(&fp); |
---|
[dcec245] | 415 | } else if (isSign(ch)) { |
---|
| 416 | int chOld = ch; |
---|
| 417 | nextch(); |
---|
| 418 | if (toupper(ch) == 'V') { |
---|
| 419 | nextch(); |
---|
[fa42426] | 420 | *p_ctype = CTYPE_PLUMB; |
---|
[bceebf4] | 421 | return (!isMinus(chOld) ? M_PI_2 : -M_PI_2); |
---|
[dcec245] | 422 | } |
---|
| 423 | |
---|
[bd1913f] | 424 | if (isOmit(chOld)) { |
---|
[fa42426] | 425 | *p_ctype = CTYPE_OMIT; |
---|
[dcec245] | 426 | /* no clino reading, so assume 0 with large sd */ |
---|
| 427 | return (real)0.0; |
---|
| 428 | } |
---|
[5b7c1b7] | 429 | } else if (isOmit(ch)) { |
---|
| 430 | /* OMIT char may not be a SIGN char too so we need to check here as |
---|
| 431 | * well as above... */ |
---|
| 432 | nextch(); |
---|
[fa42426] | 433 | *p_ctype = CTYPE_OMIT; |
---|
[5b7c1b7] | 434 | /* no clino reading, so assume 0 with large sd */ |
---|
| 435 | return (real)0.0; |
---|
[dcec245] | 436 | } |
---|
| 437 | return HUGE_REAL; |
---|
| 438 | } |
---|
| 439 | |
---|
[b6de07d] | 440 | static void |
---|
| 441 | warn_readings_differ(int msg, real diff) |
---|
| 442 | { |
---|
| 443 | char buf[64]; |
---|
| 444 | char *p; |
---|
| 445 | sprintf(buf, "%.2f", deg(fabs(diff))); |
---|
| 446 | p = strchr(buf, '.'); |
---|
| 447 | if (p) { |
---|
| 448 | char *z = p; |
---|
| 449 | while (*++p) { |
---|
| 450 | if (*p != '0') z = p + 1; |
---|
| 451 | } |
---|
| 452 | if (*z) *z = '\0'; |
---|
| 453 | } |
---|
| 454 | compile_warning(msg, buf); |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | static bool |
---|
| 458 | handle_comp_units(real *p_comp, real *p_backcomp) |
---|
| 459 | { |
---|
| 460 | bool fNoComp = fTrue; |
---|
| 461 | if (*p_comp != HUGE_REAL) { |
---|
| 462 | fNoComp = fFalse; |
---|
| 463 | *p_comp *= pcs->units[Q_BEARING]; |
---|
| 464 | if (*p_comp < (real)0.0 || *p_comp - M_PI * 2.0 > EPSILON) { |
---|
| 465 | compile_warning(/*Suspicious compass reading*/59); |
---|
| 466 | *p_comp = mod2pi(*p_comp); |
---|
| 467 | } |
---|
| 468 | } |
---|
| 469 | if (*p_backcomp != HUGE_REAL) { |
---|
| 470 | fNoComp = fFalse; |
---|
| 471 | *p_backcomp *= pcs->units[Q_BACKBEARING]; |
---|
| 472 | if (*p_backcomp < (real)0.0 || *p_backcomp - M_PI * 2.0 > EPSILON) { |
---|
| 473 | /* FIXME: different message for BackComp? */ |
---|
| 474 | compile_warning(/*Suspicious compass reading*/59); |
---|
| 475 | *p_backcomp = mod2pi(*p_backcomp); |
---|
| 476 | } |
---|
| 477 | } |
---|
| 478 | return fNoComp; |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | static real |
---|
| 482 | handle_compass(real *p_var, real comp, real backcomp) |
---|
| 483 | { |
---|
| 484 | real var = var(Q_BEARING); |
---|
| 485 | if (comp != HUGE_REAL) { |
---|
| 486 | comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING]; |
---|
| 487 | comp -= pcs->z[Q_DECLINATION]; |
---|
| 488 | } |
---|
| 489 | if (backcomp != HUGE_REAL) { |
---|
| 490 | backcomp = (backcomp - pcs->z[Q_BACKBEARING]) |
---|
| 491 | * pcs->sc[Q_BACKBEARING]; |
---|
| 492 | backcomp -= pcs->z[Q_DECLINATION]; |
---|
| 493 | backcomp -= M_PI; |
---|
| 494 | if (comp != HUGE_REAL) { |
---|
| 495 | real diff = comp - backcomp; |
---|
| 496 | real adj = fabs(diff) > M_PI ? M_PI : 0; |
---|
| 497 | diff -= floor((diff + M_PI) / (2 * M_PI)) * 2 * M_PI; |
---|
[770157e] | 498 | if (sqrd(diff / 2.0) > var + var(Q_BACKBEARING)) { |
---|
| 499 | /* fore and back readings differ by more than 2 sds */ |
---|
[fa42426] | 500 | warn_readings_differ(/*Compass reading and back compass reading disagree by %s degrees*/98, diff); |
---|
[b6de07d] | 501 | } |
---|
| 502 | comp = (comp / var + backcomp / var(Q_BACKBEARING)); |
---|
| 503 | var = (var + var(Q_BACKBEARING)) / 4; |
---|
| 504 | comp *= var; |
---|
| 505 | comp += adj; |
---|
| 506 | } else { |
---|
| 507 | comp = backcomp; |
---|
| 508 | var = var(Q_BACKBEARING); |
---|
| 509 | } |
---|
| 510 | } |
---|
| 511 | *p_var = var; |
---|
| 512 | return comp; |
---|
| 513 | } |
---|
| 514 | |
---|
[90bb053f] | 515 | static int |
---|
| 516 | process_normal(prefix *fr, prefix *to, real tape, real comp, real clin, |
---|
[0b71cfc] | 517 | real backcomp, real backclin, |
---|
[5b7c1b7] | 518 | bool fToFirst, clino_type ctype, clino_type backctype) |
---|
[a420b49] | 519 | { |
---|
| 520 | real dx, dy, dz; |
---|
| 521 | real vx, vy, vz; |
---|
| 522 | #ifndef NO_COVARIANCES |
---|
[cb3d1e2] | 523 | real cxy, cyz, czx; |
---|
[a420b49] | 524 | #endif |
---|
[d1b1380] | 525 | |
---|
[90bb053f] | 526 | bool fNoComp; |
---|
[a420b49] | 527 | |
---|
[107b8bd] | 528 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 529 | if (tape < (real)0.0) { |
---|
| 530 | /* TRANSLATE different message for topofil? */ |
---|
| 531 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
[647407d] | 532 | } |
---|
[d1b1380] | 533 | |
---|
[b6de07d] | 534 | fNoComp = handle_comp_units(&comp, &backcomp); |
---|
[d1b1380] | 535 | |
---|
[fa42426] | 536 | if (ctype == CTYPE_READING) { |
---|
[0b71cfc] | 537 | real diff_from_abs90; |
---|
[a420b49] | 538 | clin *= pcs->units[Q_GRADIENT]; |
---|
[fa42426] | 539 | /* percentage scale */ |
---|
| 540 | if (pcs->f_clino_percent) clin = atan(clin); |
---|
[0b71cfc] | 541 | diff_from_abs90 = fabs(clin) - M_PI_2; |
---|
| 542 | if (diff_from_abs90 > EPSILON) { |
---|
[a420b49] | 543 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
[0b71cfc] | 544 | } else if (pcs->f90Up && diff_from_abs90 > -EPSILON) { |
---|
[fa42426] | 545 | ctype = CTYPE_PLUMB; |
---|
[a420b49] | 546 | } |
---|
| 547 | } |
---|
[cb3d1e2] | 548 | |
---|
[fa42426] | 549 | if (backctype == CTYPE_READING) { |
---|
[0b71cfc] | 550 | real diff_from_abs90; |
---|
[b14f44f] | 551 | backclin *= pcs->units[Q_BACKGRADIENT]; |
---|
[fa42426] | 552 | /* percentage scale */ |
---|
| 553 | if (pcs->f_backclino_percent) backclin = atan(backclin); |
---|
[0b71cfc] | 554 | diff_from_abs90 = fabs(backclin) - M_PI_2; |
---|
| 555 | if (diff_from_abs90 > EPSILON) { |
---|
| 556 | /* FIXME: different message for BackClino? */ |
---|
| 557 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
| 558 | } else if (pcs->f90Up && diff_from_abs90 > -EPSILON) { |
---|
[fa42426] | 559 | backctype = CTYPE_PLUMB; |
---|
[0b71cfc] | 560 | } |
---|
| 561 | } |
---|
| 562 | |
---|
[fa42426] | 563 | if (ctype != CTYPE_OMIT && backctype != CTYPE_OMIT && ctype != backctype) { |
---|
| 564 | compile_error_skip(/*Clino and BackClino readings must be of the same type*/84); |
---|
[b14f44f] | 565 | return 0; |
---|
[0b71cfc] | 566 | } |
---|
| 567 | |
---|
[fa42426] | 568 | if (ctype == CTYPE_PLUMB || backctype == CTYPE_PLUMB) { |
---|
[a420b49] | 569 | /* plumbed */ |
---|
| 570 | if (!fNoComp) { |
---|
[11e919a] | 571 | /* FIXME: Different message for BackComp? */ |
---|
[a420b49] | 572 | compile_warning(/*Compass reading given on plumbed leg*/21); |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | dx = dy = (real)0.0; |
---|
[fa42426] | 576 | if (ctype != CTYPE_OMIT) { |
---|
| 577 | if (backctype != CTYPE_OMIT && (clin > 0) == (backclin > 0)) { |
---|
[b14f44f] | 578 | /* We've got two UPs or two DOWNs - FIXME: not ideal message */ |
---|
[fa42426] | 579 | compile_error_skip(/*Clino and BackClino readings must be of the same type*/84); |
---|
[b14f44f] | 580 | return 0; |
---|
[0b71cfc] | 581 | } |
---|
| 582 | dz = (clin > (real)0.0) ? tape : -tape; |
---|
| 583 | } else { |
---|
| 584 | dz = (backclin < (real)0.0) ? tape : -tape; |
---|
| 585 | } |
---|
[a420b49] | 586 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
| 587 | vz = var(Q_POS) / 3.0 + var(Q_LENGTH); |
---|
[4f8285d] | 588 | #ifndef NO_COVARIANCES |
---|
[26a805f] | 589 | /* Correct values - no covariances in this case! */ |
---|
| 590 | cxy = cyz = czx = (real)0.0; |
---|
[4f8285d] | 591 | #endif |
---|
[a420b49] | 592 | } else { |
---|
[fa42426] | 593 | /* Each of ctype and backctype are either CTYPE_READING/CTYPE_HORIZ |
---|
| 594 | * or CTYPE_OMIT */ |
---|
[a420b49] | 595 | /* clino */ |
---|
| 596 | real L2, cosG, LcosG, cosG2, sinB, cosB, dx2, dy2, dz2, v, V; |
---|
[421b7d2] | 597 | if (fNoComp) { |
---|
[fa42426] | 598 | compile_error_skip(/*Compass reading may not be omitted except on plumbed legs*/14); |
---|
[a420b49] | 599 | return 0; |
---|
| 600 | } |
---|
| 601 | if (tape == (real)0.0) { |
---|
| 602 | dx = dy = dz = (real)0.0; |
---|
| 603 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
[4f8285d] | 604 | #ifndef NO_COVARIANCES |
---|
[a420b49] | 605 | cxy = cyz = czx = (real)0.0; |
---|
[4f8285d] | 606 | #endif |
---|
[d1b1380] | 607 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 608 | printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
[d1b1380] | 609 | #endif |
---|
[a420b49] | 610 | } else { |
---|
[dbb4e19] | 611 | real sinGcosG; |
---|
[0b71cfc] | 612 | /* take into account variance in LEVEL case */ |
---|
| 613 | real var_clin = var(Q_LEVEL); |
---|
[b6de07d] | 614 | real var_comp; |
---|
| 615 | comp = handle_compass(&var_comp, comp, backcomp); |
---|
[fa42426] | 616 | /* ctype != CTYPE_READING is LEVEL case */ |
---|
| 617 | if (ctype == CTYPE_READING) { |
---|
[a420b49] | 618 | clin = (clin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT]; |
---|
[0b71cfc] | 619 | var_clin = var(Q_GRADIENT); |
---|
| 620 | } |
---|
[fa42426] | 621 | if (backctype == CTYPE_READING) { |
---|
[b14f44f] | 622 | backclin = (backclin - pcs->z[Q_BACKGRADIENT]) |
---|
| 623 | * pcs->sc[Q_BACKGRADIENT]; |
---|
[fa42426] | 624 | if (ctype == CTYPE_READING) { |
---|
[b14f44f] | 625 | if (sqrd((clin + backclin) / 3.0) > |
---|
| 626 | var_clin + var(Q_BACKGRADIENT)) { |
---|
| 627 | /* fore and back readings differ by more than 3 sds */ |
---|
[fa42426] | 628 | warn_readings_differ(/*Clino reading and back clino reading disagree by %s degrees*/99, clin + backclin); |
---|
[b14f44f] | 629 | } |
---|
| 630 | clin = (clin / var_clin - backclin / var(Q_BACKGRADIENT)); |
---|
| 631 | var_clin = (var_clin + var(Q_BACKGRADIENT)) / 4; |
---|
| 632 | clin *= var_clin; |
---|
[0b71cfc] | 633 | } else { |
---|
| 634 | clin = -backclin; |
---|
[b14f44f] | 635 | var_clin = var(Q_BACKGRADIENT); |
---|
[0b71cfc] | 636 | } |
---|
| 637 | } |
---|
[d1b1380] | 638 | |
---|
| 639 | #if DEBUG_DATAIN |
---|
[a420b49] | 640 | printf(" %4.2f %4.2f %4.2f\n", tape, comp, clin); |
---|
[d1b1380] | 641 | #endif |
---|
[a420b49] | 642 | cosG = cos(clin); |
---|
| 643 | LcosG = tape * cosG; |
---|
| 644 | sinB = sin(comp); |
---|
| 645 | cosB = cos(comp); |
---|
[d1b1380] | 646 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 647 | printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB, cosG, LcosG); |
---|
[d1b1380] | 648 | #endif |
---|
[a420b49] | 649 | dx = LcosG * sinB; |
---|
| 650 | dy = LcosG * cosB; |
---|
| 651 | dz = tape * sin(clin); |
---|
[d1b1380] | 652 | /* printf("%.2f\n",clin); */ |
---|
| 653 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 654 | printf("dx = %f\ndy = %f\ndz = %f\n", dx, dy, dz); |
---|
[d1b1380] | 655 | #endif |
---|
[a420b49] | 656 | dx2 = dx * dx; |
---|
| 657 | L2 = tape * tape; |
---|
| 658 | V = var(Q_LENGTH) / L2; |
---|
| 659 | dy2 = dy * dy; |
---|
| 660 | cosG2 = cosG * cosG; |
---|
[dbb4e19] | 661 | sinGcosG = sin(clin) * cosG; |
---|
[a420b49] | 662 | dz2 = dz * dz; |
---|
[0b71cfc] | 663 | v = dz2 * var_clin; |
---|
[5b7c1b7] | 664 | #ifdef NO_COVARIANCES |
---|
[0b71cfc] | 665 | vx = (var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp + |
---|
[a420b49] | 666 | (.5 + sinB * sinB * cosG2) * v); |
---|
[0b71cfc] | 667 | vy = (var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp + |
---|
[a420b49] | 668 | (.5 + cosB * cosB * cosG2) * v); |
---|
[fa42426] | 669 | if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) { |
---|
[5b7c1b7] | 670 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
[0b71cfc] | 671 | vz = var(Q_POS) / 3.0 + L2 * (real)0.1; |
---|
[5b7c1b7] | 672 | } else { |
---|
[0b71cfc] | 673 | vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin; |
---|
[5b7c1b7] | 674 | } |
---|
[a420b49] | 675 | /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */ |
---|
[dbb4e19] | 676 | #else |
---|
[0b71cfc] | 677 | vx = var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp + |
---|
[dbb4e19] | 678 | (sinB * sinB * v); |
---|
[0b71cfc] | 679 | vy = var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp + |
---|
[dbb4e19] | 680 | (cosB * cosB * v); |
---|
[fa42426] | 681 | if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) { |
---|
[5b7c1b7] | 682 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
[0b71cfc] | 683 | vz = var(Q_POS) / 3.0 + L2 * (real)0.1; |
---|
[5b7c1b7] | 684 | } else { |
---|
[0b71cfc] | 685 | vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin; |
---|
[5b7c1b7] | 686 | } |
---|
[647407d] | 687 | /* usual covariance formulae are fine in no clino case since |
---|
[0b71cfc] | 688 | * dz = 0 so value of var_clin is ignored */ |
---|
| 689 | cxy = sinB * cosB * (var(Q_LENGTH) * cosG2 + var_clin * dz2) |
---|
| 690 | - var_comp * dx * dy; |
---|
| 691 | czx = var(Q_LENGTH) * sinB * sinGcosG - var_clin * dx * dz; |
---|
| 692 | cyz = var(Q_LENGTH) * cosB * sinGcosG - var_clin * dy * dz; |
---|
[dbb4e19] | 693 | #if 0 |
---|
| 694 | printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx, vy, vz); |
---|
| 695 | printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy, cyz, czx); |
---|
| 696 | #endif |
---|
[4f8285d] | 697 | #endif |
---|
[d1b1380] | 698 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 699 | printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
[d1b1380] | 700 | #endif |
---|
[a420b49] | 701 | } |
---|
| 702 | } |
---|
[d1b1380] | 703 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 704 | printf("Just before addleg, vx = %f\n", vx); |
---|
[d1b1380] | 705 | #endif |
---|
[a420b49] | 706 | /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/ |
---|
[90bb053f] | 707 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
[4f8285d] | 708 | #ifndef NO_COVARIANCES |
---|
[2140502] | 709 | , cyz, czx, cxy |
---|
[4f8285d] | 710 | #endif |
---|
[2140502] | 711 | ); |
---|
[647407d] | 712 | |
---|
| 713 | #ifdef NEW3DFORMAT |
---|
| 714 | if (fUseNewFormat) { |
---|
[407084d] | 715 | /* new twiglet and insert into twig tree */ |
---|
| 716 | twig *twiglet = osnew(twig); |
---|
[90bb053f] | 717 | twiglet->from = fr; |
---|
| 718 | twiglet->to = to; |
---|
[407084d] | 719 | twiglet->down = twiglet->right = NULL; |
---|
| 720 | twiglet->source = twiglet->drawings |
---|
| 721 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
| 722 | twiglet->up = limb->up; |
---|
| 723 | limb->right = twiglet; |
---|
| 724 | limb = twiglet; |
---|
| 725 | |
---|
| 726 | /* record pre-fettling deltas */ |
---|
[647407d] | 727 | twiglet->delta[0] = dx; |
---|
| 728 | twiglet->delta[1] = dy; |
---|
| 729 | twiglet->delta[2] = dz; |
---|
| 730 | } |
---|
| 731 | #endif |
---|
[a420b49] | 732 | return 1; |
---|
[d1b1380] | 733 | } |
---|
| 734 | |
---|
[5a38209] | 735 | static int |
---|
[72095d3] | 736 | process_diving(prefix *fr, prefix *to, real tape, real comp, real backcomp, |
---|
[6114207] | 737 | real frdepth, real todepth, bool fToFirst, bool fDepthChange) |
---|
[a420b49] | 738 | { |
---|
| 739 | real dx, dy, dz; |
---|
| 740 | real vx, vy, vz; |
---|
[f795df0] | 741 | #ifndef NO_COVARIANCES |
---|
| 742 | real cxy = 0, cyz = 0, czx = 0; |
---|
| 743 | #endif |
---|
[a420b49] | 744 | |
---|
[b6de07d] | 745 | handle_comp_units(&comp, &backcomp); |
---|
[a420b49] | 746 | |
---|
[a6d094f] | 747 | /* depth gauge readings increase upwards with default calibration */ |
---|
[6114207] | 748 | if (fDepthChange) { |
---|
[a6d094f] | 749 | ASSERT(frdepth == 0.0); |
---|
[6114207] | 750 | dz = (todepth * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]) * pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 751 | } else { |
---|
| 752 | dz = (todepth - frdepth) * pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
| 753 | } |
---|
[a420b49] | 754 | |
---|
| 755 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 756 | if (tape < (real)0.0) { |
---|
| 757 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
| 758 | } |
---|
| 759 | |
---|
| 760 | /* check if tape is less than depth change */ |
---|
| 761 | if (tape < fabs(dz)) { |
---|
[bd1913f] | 762 | /* FIXME: allow margin of error based on variances? */ |
---|
[a420b49] | 763 | compile_warning(/*Tape reading is less than change in depth*/62); |
---|
| 764 | } |
---|
| 765 | |
---|
[0a208f9] | 766 | if (tape == (real)0.0 && dz == 0.0) { |
---|
[a420b49] | 767 | dx = dy = dz = (real)0.0; |
---|
| 768 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
[72095d3] | 769 | } else if (comp == HUGE_REAL && backcomp == HUGE_REAL) { |
---|
[385b703] | 770 | /* plumb */ |
---|
| 771 | dx = dy = (real)0.0; |
---|
| 772 | if (dz < 0) tape = -tape; |
---|
| 773 | dz = (dz * var(Q_LENGTH) + tape * 2 * var(Q_DEPTH)) |
---|
[421b7d2] | 774 | / (var(Q_LENGTH) * 2 * var(Q_DEPTH)); |
---|
[385b703] | 775 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
| 776 | vz = var(Q_POS) / 3.0 + var(Q_LENGTH) * 2 * var(Q_DEPTH) |
---|
[421b7d2] | 777 | / (var(Q_LENGTH) + var(Q_DEPTH)); |
---|
[a420b49] | 778 | } else { |
---|
[f795df0] | 779 | real L2, sinB, cosB, dz2, D2; |
---|
[b6de07d] | 780 | real var_comp; |
---|
| 781 | comp = handle_compass(&var_comp, comp, backcomp); |
---|
[a420b49] | 782 | sinB = sin(comp); |
---|
| 783 | cosB = cos(comp); |
---|
| 784 | L2 = tape * tape; |
---|
| 785 | dz2 = dz * dz; |
---|
| 786 | D2 = L2 - dz2; |
---|
| 787 | if (D2 <= (real)0.0) { |
---|
[f795df0] | 788 | real vsum = var(Q_LENGTH) + 2 * var(Q_DEPTH); |
---|
[a420b49] | 789 | dx = dy = (real)0.0; |
---|
[f795df0] | 790 | vx = vy = var(Q_POS) / 3.0; |
---|
| 791 | vz = var(Q_POS) / 3.0 + var(Q_LENGTH) * 2 * var(Q_DEPTH) / vsum; |
---|
| 792 | if (dz > 0) { |
---|
| 793 | dz = (dz * var(Q_LENGTH) + tape * 2 * var(Q_DEPTH)) / vsum; |
---|
| 794 | } else { |
---|
| 795 | dz = (dz * var(Q_LENGTH) - tape * 2 * var(Q_DEPTH)) / vsum; |
---|
| 796 | } |
---|
[a420b49] | 797 | } else { |
---|
| 798 | real D = sqrt(D2); |
---|
[f795df0] | 799 | real F = var(Q_LENGTH) * L2 + 2 * var(Q_DEPTH) * D2; |
---|
[a420b49] | 800 | dx = D * sinB; |
---|
| 801 | dy = D * cosB; |
---|
[f795df0] | 802 | |
---|
| 803 | vx = var(Q_POS) / 3.0 + |
---|
[72095d3] | 804 | sinB * sinB * F / D2 + var_comp * dy * dy; |
---|
[f795df0] | 805 | vy = var(Q_POS) / 3.0 + |
---|
[72095d3] | 806 | cosB * cosB * F / D2 + var_comp * dx * dx; |
---|
[f795df0] | 807 | vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH); |
---|
| 808 | |
---|
| 809 | #ifndef NO_COVARIANCES |
---|
[72095d3] | 810 | cxy = sinB * cosB * (F / D2 + var_comp * D2); |
---|
[f795df0] | 811 | cyz = -2 * var(Q_DEPTH) * dy / D; |
---|
| 812 | czx = -2 * var(Q_DEPTH) * dx / D; |
---|
| 813 | #endif |
---|
[a420b49] | 814 | } |
---|
| 815 | } |
---|
[5a38209] | 816 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
[2140502] | 817 | #ifndef NO_COVARIANCES |
---|
[f795df0] | 818 | , cxy, cyz, czx |
---|
[647407d] | 819 | #endif |
---|
[2140502] | 820 | ); |
---|
[647407d] | 821 | #ifdef NEW3DFORMAT |
---|
| 822 | if (fUseNewFormat) { |
---|
[407084d] | 823 | /*new twiglet and insert into twig tree*/ |
---|
| 824 | twig *twiglet = osnew(twig); |
---|
[90bb053f] | 825 | twiglet->from = fr; |
---|
| 826 | twiglet->to = to; |
---|
[407084d] | 827 | twiglet->down = twiglet->right = NULL; |
---|
| 828 | twiglet->source = twiglet->drawings |
---|
| 829 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
| 830 | twiglet->up = limb->up; |
---|
| 831 | limb->right = twiglet; |
---|
| 832 | limb = twiglet; |
---|
| 833 | |
---|
| 834 | /* record pre-fettling deltas */ |
---|
[647407d] | 835 | twiglet->delta[0] = dx; |
---|
| 836 | twiglet->delta[1] = dy; |
---|
| 837 | twiglet->delta[2] = dz; |
---|
| 838 | } |
---|
| 839 | #endif |
---|
| 840 | |
---|
| 841 | return 1; |
---|
| 842 | } |
---|
| 843 | |
---|
[5a38209] | 844 | static int |
---|
| 845 | process_cartesian(prefix *fr, prefix *to, real dx, real dy, real dz, |
---|
| 846 | bool fToFirst) |
---|
| 847 | { |
---|
[647407d] | 848 | dx = (dx * pcs->units[Q_DX] - pcs->z[Q_DX]) * pcs->sc[Q_DX]; |
---|
| 849 | dy = (dy * pcs->units[Q_DY] - pcs->z[Q_DY]) * pcs->sc[Q_DY]; |
---|
| 850 | dz = (dz * pcs->units[Q_DZ] - pcs->z[Q_DZ]) * pcs->sc[Q_DZ]; |
---|
| 851 | |
---|
[5a38209] | 852 | addlegbyname(fr, to, fToFirst, dx, dy, dz, var(Q_DX), var(Q_DY), var(Q_DZ) |
---|
[647407d] | 853 | #ifndef NO_COVARIANCES |
---|
[c80bd34] | 854 | , 0, 0, 0 |
---|
[647407d] | 855 | #endif |
---|
[2140502] | 856 | ); |
---|
[647407d] | 857 | |
---|
| 858 | #ifdef NEW3DFORMAT |
---|
| 859 | if (fUseNewFormat) { |
---|
[407084d] | 860 | /* new twiglet and insert into twig tree */ |
---|
| 861 | twig *twiglet = osnew(twig); |
---|
[90bb053f] | 862 | twiglet->from = fr; |
---|
| 863 | twiglet->to = to; |
---|
[407084d] | 864 | twiglet->down = twiglet->right = NULL; |
---|
| 865 | twiglet->source = twiglet->drawings |
---|
| 866 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
| 867 | twiglet->up = limb->up; |
---|
| 868 | limb->right = twiglet; |
---|
| 869 | limb = twiglet; |
---|
| 870 | |
---|
| 871 | /* record pre-fettling deltas */ |
---|
[647407d] | 872 | twiglet->delta[0] = dx; |
---|
| 873 | twiglet->delta[1] = dy; |
---|
| 874 | twiglet->delta[2] = dz; |
---|
| 875 | } |
---|
[4f8285d] | 876 | #endif |
---|
[647407d] | 877 | |
---|
| 878 | return 1; |
---|
| 879 | } |
---|
| 880 | |
---|
| 881 | extern int |
---|
[5a38209] | 882 | data_cartesian(void) |
---|
[647407d] | 883 | { |
---|
[90bb053f] | 884 | prefix *fr = NULL, *to = NULL; |
---|
[5a38209] | 885 | real dx = 0, dy = 0, dz = 0; |
---|
| 886 | |
---|
| 887 | bool fMulti = fFalse; |
---|
[647407d] | 888 | |
---|
[0395657] | 889 | reading first_stn = End; |
---|
| 890 | |
---|
| 891 | reading *ordering; |
---|
[647407d] | 892 | |
---|
[5a38209] | 893 | again: |
---|
| 894 | |
---|
[647407d] | 895 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
| 896 | skipblanks(); |
---|
| 897 | switch (*ordering) { |
---|
[4a6a094] | 898 | case Fr: |
---|
[84c60fc] | 899 | fr = read_prefix_stn(fFalse, fTrue); |
---|
[0395657] | 900 | if (first_stn == End) first_stn = Fr; |
---|
[4a6a094] | 901 | break; |
---|
| 902 | case To: |
---|
[84c60fc] | 903 | to = read_prefix_stn(fFalse, fTrue); |
---|
[0395657] | 904 | if (first_stn == End) first_stn = To; |
---|
[4a6a094] | 905 | break; |
---|
[5a38209] | 906 | case Station: |
---|
| 907 | fr = to; |
---|
[84c60fc] | 908 | to = read_prefix_stn(fFalse, fFalse); |
---|
[5a38209] | 909 | first_stn = To; |
---|
| 910 | break; |
---|
| 911 | case Dx: dx = read_numeric(fFalse); break; |
---|
| 912 | case Dy: dy = read_numeric(fFalse); break; |
---|
| 913 | case Dz: dz = read_numeric(fFalse); break; |
---|
[647407d] | 914 | case Ignore: |
---|
| 915 | skipword(); break; |
---|
[5a38209] | 916 | case IgnoreAllAndNewLine: |
---|
| 917 | skipline(); |
---|
| 918 | /* fall through */ |
---|
| 919 | case Newline: |
---|
| 920 | if (fr != NULL) { |
---|
| 921 | int r; |
---|
| 922 | r = process_cartesian(fr, to, dx, dy, dz, first_stn == To); |
---|
| 923 | if (!r) skipline(); |
---|
| 924 | } |
---|
| 925 | fMulti = fTrue; |
---|
| 926 | while (1) { |
---|
| 927 | process_eol(); |
---|
| 928 | process_bol(); |
---|
| 929 | if (isData(ch)) break; |
---|
[ee6a621] | 930 | if (!isComm(ch)) { |
---|
[993454b] | 931 | push_back(ch); |
---|
[ee6a621] | 932 | return 1; |
---|
| 933 | } |
---|
[5a38209] | 934 | } |
---|
| 935 | break; |
---|
[647407d] | 936 | case IgnoreAll: |
---|
| 937 | skipline(); |
---|
| 938 | /* fall through */ |
---|
| 939 | case End: |
---|
[5a38209] | 940 | if (!fMulti) { |
---|
[ee6a621] | 941 | int r = process_cartesian(fr, to, dx, dy, dz, first_stn == To); |
---|
[5a38209] | 942 | process_eol(); |
---|
| 943 | return r; |
---|
| 944 | } |
---|
[eef4d8c] | 945 | do { |
---|
[5a38209] | 946 | process_eol(); |
---|
| 947 | process_bol(); |
---|
[eef4d8c] | 948 | } while (isComm(ch)); |
---|
[5a38209] | 949 | goto again; |
---|
[0395657] | 950 | default: BUG("Unknown reading in ordering"); |
---|
[647407d] | 951 | } |
---|
| 952 | } |
---|
[5a38209] | 953 | } |
---|
[cb3d1e2] | 954 | |
---|
[98a2eec] | 955 | static int |
---|
[72095d3] | 956 | process_cylpolar(prefix *fr, prefix *to, real tape, real comp, real backcomp, |
---|
[6114207] | 957 | real frdepth, real todepth, bool fToFirst, bool fDepthChange) |
---|
[98a2eec] | 958 | { |
---|
| 959 | real dx, dy, dz; |
---|
| 960 | real vx, vy, vz; |
---|
| 961 | #ifndef NO_COVARIANCES |
---|
| 962 | real cxy = 0; |
---|
| 963 | #endif |
---|
| 964 | |
---|
[b6de07d] | 965 | handle_comp_units(&comp, &backcomp); |
---|
[98a2eec] | 966 | |
---|
[a6d094f] | 967 | /* depth gauge readings increase upwards with default calibration */ |
---|
[6114207] | 968 | if (fDepthChange) { |
---|
[a6d094f] | 969 | ASSERT(frdepth == 0.0); |
---|
[6114207] | 970 | dz = (todepth * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]) * pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 971 | } else { |
---|
| 972 | dz = (todepth - frdepth) * pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
| 973 | } |
---|
[98a2eec] | 974 | |
---|
| 975 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 976 | if (tape < (real)0.0) { |
---|
| 977 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
| 978 | } |
---|
| 979 | |
---|
[72095d3] | 980 | if (comp == HUGE_REAL && backcomp == HUGE_REAL) { |
---|
[98a2eec] | 981 | /* plumb */ |
---|
| 982 | dx = dy = (real)0.0; |
---|
| 983 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
| 984 | vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH); |
---|
| 985 | } else { |
---|
| 986 | real sinB, cosB; |
---|
[b6de07d] | 987 | real var_comp; |
---|
| 988 | comp = handle_compass(&var_comp, comp, backcomp); |
---|
[98a2eec] | 989 | sinB = sin(comp); |
---|
| 990 | cosB = cos(comp); |
---|
| 991 | |
---|
| 992 | dx = tape * sinB; |
---|
| 993 | dy = tape * cosB; |
---|
| 994 | |
---|
| 995 | vx = var(Q_POS) / 3.0 + |
---|
[72095d3] | 996 | var(Q_LENGTH) * sinB * sinB + var_comp * dy * dy; |
---|
[98a2eec] | 997 | vy = var(Q_POS) / 3.0 + |
---|
[72095d3] | 998 | var(Q_LENGTH) * cosB * cosB + var_comp * dx * dx; |
---|
[98a2eec] | 999 | vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH); |
---|
| 1000 | |
---|
| 1001 | #ifndef NO_COVARIANCES |
---|
[72095d3] | 1002 | cxy = (var(Q_LENGTH) - var_comp * tape * tape) * sinB * cosB; |
---|
[98a2eec] | 1003 | #endif |
---|
| 1004 | } |
---|
| 1005 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
| 1006 | #ifndef NO_COVARIANCES |
---|
| 1007 | , cxy, 0, 0 |
---|
| 1008 | #endif |
---|
| 1009 | ); |
---|
| 1010 | #ifdef NEW3DFORMAT |
---|
| 1011 | if (fUseNewFormat) { |
---|
| 1012 | /*new twiglet and insert into twig tree*/ |
---|
| 1013 | twig *twiglet = osnew(twig); |
---|
| 1014 | twiglet->from = fr; |
---|
| 1015 | twiglet->to = to; |
---|
| 1016 | twiglet->down = twiglet->right = NULL; |
---|
| 1017 | twiglet->source = twiglet->drawings |
---|
| 1018 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
| 1019 | twiglet->up = limb->up; |
---|
| 1020 | limb->right = twiglet; |
---|
| 1021 | limb = twiglet; |
---|
| 1022 | |
---|
| 1023 | /* record pre-fettling deltas */ |
---|
| 1024 | twiglet->delta[0] = dx; |
---|
| 1025 | twiglet->delta[1] = dy; |
---|
| 1026 | twiglet->delta[2] = dz; |
---|
| 1027 | } |
---|
| 1028 | #endif |
---|
| 1029 | |
---|
| 1030 | return 1; |
---|
| 1031 | } |
---|
| 1032 | |
---|
[107b8bd] | 1033 | /* Process tape/compass/clino, diving, and cylpolar styles of survey data |
---|
| 1034 | * Also handles topofil (fromcount/tocount or count) in place of tape */ |
---|
[54c4612] | 1035 | extern int |
---|
[107b8bd] | 1036 | data_normal(void) |
---|
[54c4612] | 1037 | { |
---|
| 1038 | prefix *fr = NULL, *to = NULL; |
---|
[107b8bd] | 1039 | reading first_stn = End; |
---|
[54c4612] | 1040 | |
---|
[b14f44f] | 1041 | real tape = 0, comp = HUGE_VAL, backcomp = HUGE_VAL, frcount = 0, tocount = 0; |
---|
[5b7c1b7] | 1042 | real clin, backclin; |
---|
[54c4612] | 1043 | real frdepth = 0, todepth = 0; |
---|
| 1044 | |
---|
[107b8bd] | 1045 | bool fTopofil = fFalse, fMulti = fFalse; |
---|
| 1046 | bool fRev; |
---|
[e217d67] | 1047 | clino_type ctype, backctype; |
---|
[107b8bd] | 1048 | bool fDepthChange; |
---|
[54c4612] | 1049 | |
---|
| 1050 | reading *ordering; |
---|
| 1051 | |
---|
| 1052 | again: |
---|
| 1053 | |
---|
| 1054 | fRev = fFalse; |
---|
[fa42426] | 1055 | ctype = backctype = CTYPE_OMIT; |
---|
[6114207] | 1056 | fDepthChange = fFalse; |
---|
[54c4612] | 1057 | |
---|
[107b8bd] | 1058 | /* ordering may omit clino reading, so set up default here */ |
---|
| 1059 | /* this is also used if clino reading is the omit character */ |
---|
[5b7c1b7] | 1060 | backclin = clin = (real)0.0; |
---|
[107b8bd] | 1061 | |
---|
[54c4612] | 1062 | for (ordering = pcs->ordering; ; ordering++) { |
---|
| 1063 | skipblanks(); |
---|
| 1064 | switch (*ordering) { |
---|
| 1065 | case Fr: |
---|
[107b8bd] | 1066 | fr = read_prefix_stn(fFalse, fTrue); |
---|
| 1067 | if (first_stn == End) first_stn = Fr; |
---|
| 1068 | break; |
---|
[54c4612] | 1069 | case To: |
---|
[107b8bd] | 1070 | to = read_prefix_stn(fFalse, fTrue); |
---|
| 1071 | if (first_stn == End) first_stn = To; |
---|
| 1072 | break; |
---|
[54c4612] | 1073 | case Station: |
---|
[107b8bd] | 1074 | fr = to; |
---|
| 1075 | to = read_prefix_stn(fFalse, fFalse); |
---|
| 1076 | first_stn = To; |
---|
| 1077 | break; |
---|
[54c4612] | 1078 | case Dir: |
---|
[f4276af] | 1079 | /* FIXME: use get_token so we can give a better error if the user |
---|
| 1080 | * gives a word rather than "F" or "B" */ |
---|
[54c4612] | 1081 | switch(toupper(ch)) { |
---|
| 1082 | case 'F': |
---|
| 1083 | break; |
---|
| 1084 | case 'B': |
---|
| 1085 | fRev = fTrue; |
---|
| 1086 | break; |
---|
| 1087 | default: |
---|
[fa42426] | 1088 | compile_error_skip(/*Found `%c', expecting `F' or `B'*/131, ch); |
---|
[54c4612] | 1089 | process_eol(); |
---|
| 1090 | return 0; |
---|
| 1091 | } |
---|
[f4276af] | 1092 | nextch(); |
---|
[54c4612] | 1093 | break; |
---|
[107b8bd] | 1094 | case Tape: |
---|
| 1095 | tape = read_numeric(fFalse); |
---|
| 1096 | if (tape < (real)0.0) compile_warning(/*Negative tape reading*/60); |
---|
| 1097 | break; |
---|
| 1098 | case Count: |
---|
| 1099 | frcount = tocount; |
---|
| 1100 | tocount = read_numeric(fFalse); |
---|
| 1101 | break; |
---|
| 1102 | case FrCount: |
---|
| 1103 | frcount = read_numeric(fFalse); |
---|
| 1104 | break; |
---|
| 1105 | case ToCount: |
---|
| 1106 | tocount = read_numeric(fFalse); |
---|
| 1107 | fTopofil = fTrue; |
---|
| 1108 | break; |
---|
| 1109 | case Comp: |
---|
| 1110 | comp = read_numeric_or_omit(); |
---|
| 1111 | break; |
---|
[5b7c1b7] | 1112 | case BackComp: |
---|
| 1113 | backcomp = read_numeric_or_omit(); |
---|
| 1114 | break; |
---|
[5757725] | 1115 | case Clino: |
---|
[107b8bd] | 1116 | clin = read_numeric(fTrue); |
---|
| 1117 | if (clin == HUGE_REAL) { |
---|
[5b7c1b7] | 1118 | clin = handle_plumb(&ctype); |
---|
[107b8bd] | 1119 | if (clin != HUGE_REAL) break; |
---|
| 1120 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
| 1121 | process_eol(); |
---|
| 1122 | return 0; |
---|
| 1123 | } |
---|
[fa42426] | 1124 | ctype = CTYPE_READING; |
---|
[5b7c1b7] | 1125 | break; |
---|
| 1126 | case BackClino: |
---|
| 1127 | backclin = read_numeric(fTrue); |
---|
| 1128 | if (backclin == HUGE_REAL) { |
---|
| 1129 | backclin = handle_plumb(&backctype); |
---|
| 1130 | if (backclin != HUGE_REAL) break; |
---|
| 1131 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
| 1132 | process_eol(); |
---|
| 1133 | return 0; |
---|
| 1134 | } |
---|
[fa42426] | 1135 | backctype = CTYPE_READING; |
---|
[107b8bd] | 1136 | break; |
---|
| 1137 | case FrDepth: |
---|
| 1138 | frdepth = read_numeric(fFalse); |
---|
| 1139 | break; |
---|
| 1140 | case ToDepth: |
---|
| 1141 | todepth = read_numeric(fFalse); |
---|
| 1142 | break; |
---|
[54c4612] | 1143 | case Depth: |
---|
| 1144 | frdepth = todepth; |
---|
| 1145 | todepth = read_numeric(fFalse); |
---|
| 1146 | break; |
---|
[6114207] | 1147 | case DepthChange: |
---|
| 1148 | fDepthChange = fTrue; |
---|
[a186573] | 1149 | frdepth = 0; |
---|
| 1150 | todepth = read_numeric(fFalse); |
---|
| 1151 | break; |
---|
[107b8bd] | 1152 | case Ignore: |
---|
| 1153 | skipword(); |
---|
| 1154 | break; |
---|
[54c4612] | 1155 | case IgnoreAllAndNewLine: |
---|
[107b8bd] | 1156 | skipline(); |
---|
| 1157 | /* fall through */ |
---|
[54c4612] | 1158 | case Newline: |
---|
[107b8bd] | 1159 | if (fr != NULL) { |
---|
| 1160 | int r; |
---|
| 1161 | if (fRev) { |
---|
| 1162 | prefix *t = fr; |
---|
| 1163 | fr = to; |
---|
| 1164 | to = t; |
---|
| 1165 | } |
---|
| 1166 | if (fTopofil) tape = tocount - frcount; |
---|
| 1167 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
| 1168 | * (frdepth always zero, todepth is change of depth) and also |
---|
| 1169 | * works for STYLE_NORMAL (both remain 0) */ |
---|
| 1170 | if (pcs->f0Eq && tape == (real)0.0 && frdepth == todepth) { |
---|
| 1171 | process_equate(fr, to); |
---|
| 1172 | goto inferred_equate; |
---|
| 1173 | } |
---|
| 1174 | if (fTopofil) { |
---|
| 1175 | tape *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
| 1176 | } else { |
---|
| 1177 | tape *= pcs->units[Q_LENGTH]; |
---|
| 1178 | tape = (tape - pcs->z[Q_LENGTH]) * pcs->sc[Q_LENGTH]; |
---|
| 1179 | } |
---|
| 1180 | switch (pcs->style) { |
---|
| 1181 | case STYLE_NORMAL: |
---|
| 1182 | r = process_normal(fr, to, tape, comp, clin, |
---|
[0b71cfc] | 1183 | backcomp, backclin, |
---|
[5b7c1b7] | 1184 | (first_stn == To) ^ fRev, ctype, backctype); |
---|
[107b8bd] | 1185 | break; |
---|
| 1186 | case STYLE_DIVING: |
---|
[72095d3] | 1187 | r = process_diving(fr, to, tape, comp, backcomp, |
---|
| 1188 | frdepth, todepth, |
---|
[107b8bd] | 1189 | (first_stn == To) ^ fRev, fDepthChange); |
---|
| 1190 | break; |
---|
| 1191 | case STYLE_CYLPOLAR: |
---|
[72095d3] | 1192 | r = process_cylpolar(fr, to, tape, comp, backcomp, |
---|
| 1193 | frdepth, todepth, |
---|
[107b8bd] | 1194 | (first_stn == To) ^ fRev, fDepthChange); |
---|
| 1195 | break; |
---|
| 1196 | default: |
---|
| 1197 | BUG("bad style"); |
---|
| 1198 | } |
---|
| 1199 | if (!r) skipline(); |
---|
| 1200 | } |
---|
| 1201 | inferred_equate: |
---|
| 1202 | fMulti = fTrue; |
---|
| 1203 | while (1) { |
---|
| 1204 | process_eol(); |
---|
| 1205 | process_bol(); |
---|
| 1206 | if (isData(ch)) break; |
---|
| 1207 | if (!isComm(ch)) { |
---|
| 1208 | push_back(ch); |
---|
| 1209 | return 1; |
---|
| 1210 | } |
---|
| 1211 | } |
---|
| 1212 | break; |
---|
[54c4612] | 1213 | case IgnoreAll: |
---|
[107b8bd] | 1214 | skipline(); |
---|
| 1215 | /* fall through */ |
---|
[54c4612] | 1216 | case End: |
---|
[107b8bd] | 1217 | if (!fMulti) { |
---|
| 1218 | int r; |
---|
| 1219 | if (fRev) { |
---|
| 1220 | prefix *t = fr; |
---|
| 1221 | fr = to; |
---|
| 1222 | to = t; |
---|
| 1223 | } |
---|
| 1224 | if (fTopofil) tape = tocount - frcount; |
---|
| 1225 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
| 1226 | * (frdepth always zero, todepth is change of depth) and also |
---|
| 1227 | * works for STYLE_NORMAL (both remain 0) */ |
---|
| 1228 | if (pcs->f0Eq && tape == (real)0.0 && frdepth == todepth) { |
---|
| 1229 | process_equate(fr, to); |
---|
| 1230 | process_eol(); |
---|
| 1231 | return 1; |
---|
| 1232 | } |
---|
| 1233 | if (fTopofil) { |
---|
| 1234 | tape *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
| 1235 | } else { |
---|
| 1236 | tape *= pcs->units[Q_LENGTH]; |
---|
| 1237 | tape = (tape - pcs->z[Q_LENGTH]) * pcs->sc[Q_LENGTH]; |
---|
| 1238 | } |
---|
| 1239 | switch (pcs->style) { |
---|
| 1240 | case STYLE_NORMAL: |
---|
| 1241 | r = process_normal(fr, to, tape, comp, clin, |
---|
[0b71cfc] | 1242 | backcomp, backclin, |
---|
[5b7c1b7] | 1243 | (first_stn == To) ^ fRev, ctype, backctype); |
---|
[107b8bd] | 1244 | break; |
---|
| 1245 | case STYLE_DIVING: |
---|
[72095d3] | 1246 | r = process_diving(fr, to, tape, comp, backcomp, |
---|
| 1247 | frdepth, todepth, |
---|
[107b8bd] | 1248 | (first_stn == To) ^ fRev, fDepthChange); |
---|
| 1249 | break; |
---|
| 1250 | case STYLE_CYLPOLAR: |
---|
[72095d3] | 1251 | r = process_cylpolar(fr, to, tape, comp, backcomp, |
---|
| 1252 | frdepth, todepth, |
---|
[107b8bd] | 1253 | (first_stn == To) ^ fRev, fDepthChange); |
---|
| 1254 | break; |
---|
| 1255 | default: |
---|
| 1256 | BUG("bad style"); |
---|
| 1257 | } |
---|
| 1258 | process_eol(); |
---|
| 1259 | return r; |
---|
| 1260 | } |
---|
| 1261 | do { |
---|
| 1262 | process_eol(); |
---|
| 1263 | process_bol(); |
---|
| 1264 | } while (isComm(ch)); |
---|
| 1265 | goto again; |
---|
| 1266 | default: |
---|
| 1267 | BUG("Unknown reading in ordering"); |
---|
[54c4612] | 1268 | } |
---|
| 1269 | } |
---|
| 1270 | } |
---|
| 1271 | |
---|
[5a38209] | 1272 | static int |
---|
| 1273 | process_nosurvey(prefix *fr, prefix *to, bool fToFirst) |
---|
| 1274 | { |
---|
| 1275 | nosurveylink *link; |
---|
[838a602a] | 1276 | int shape; |
---|
[647407d] | 1277 | |
---|
| 1278 | #ifdef NEW3DFORMAT |
---|
| 1279 | if (fUseNewFormat) { |
---|
[407084d] | 1280 | /* new twiglet and insert into twig tree */ |
---|
| 1281 | twig *twiglet = osnew(twig); |
---|
[90bb053f] | 1282 | twiglet->from = fr; |
---|
| 1283 | twiglet->to = to; |
---|
[647407d] | 1284 | twiglet->down = twiglet->right = NULL; |
---|
| 1285 | twiglet->source = twiglet->drawings |
---|
| 1286 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
| 1287 | twiglet->up = limb->up; |
---|
| 1288 | limb->right = twiglet; |
---|
| 1289 | limb = twiglet; |
---|
[3bcbcb2] | 1290 | /* delta is only used to calculate error - pass zero and cope |
---|
| 1291 | * elsewhere */ |
---|
[647407d] | 1292 | twiglet->delta[0] = twiglet->delta[1] = twiglet->delta[2] = 0; |
---|
| 1293 | } |
---|
| 1294 | #endif |
---|
| 1295 | |
---|
[838a602a] | 1296 | /* Suppress "unused fixed point" warnings for these stations |
---|
| 1297 | * We do this if it's a 0 or 1 node - 1 node might be an sdfix |
---|
| 1298 | */ |
---|
| 1299 | shape = fr->shape; |
---|
| 1300 | if (shape == 0 || shape == 1) fr->shape = -1 - shape; |
---|
| 1301 | shape = to->shape; |
---|
| 1302 | if (shape == 0 || shape == 1) to->shape = -1 - shape; |
---|
| 1303 | |
---|
[647407d] | 1304 | /* add to linked list which is dealt with after network is solved */ |
---|
| 1305 | link = osnew(nosurveylink); |
---|
[5a38209] | 1306 | if (fToFirst) { |
---|
[90bb053f] | 1307 | link->to = StnFromPfx(to); |
---|
| 1308 | link->fr = StnFromPfx(fr); |
---|
[0395657] | 1309 | } else { |
---|
[90bb053f] | 1310 | link->fr = StnFromPfx(fr); |
---|
| 1311 | link->to = StnFromPfx(to); |
---|
[0395657] | 1312 | } |
---|
[b3bef47] | 1313 | link->flags = pcs->flags; |
---|
[647407d] | 1314 | link->next = nosurveyhead; |
---|
| 1315 | nosurveyhead = link; |
---|
[a420b49] | 1316 | return 1; |
---|
[d1b1380] | 1317 | } |
---|
[50f6901] | 1318 | |
---|
[5a38209] | 1319 | extern int |
---|
| 1320 | data_nosurvey(void) |
---|
| 1321 | { |
---|
| 1322 | prefix *fr = NULL, *to = NULL; |
---|
| 1323 | |
---|
| 1324 | bool fMulti = fFalse; |
---|
| 1325 | |
---|
| 1326 | reading first_stn = End; |
---|
| 1327 | |
---|
| 1328 | reading *ordering; |
---|
| 1329 | |
---|
| 1330 | again: |
---|
| 1331 | |
---|
| 1332 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
| 1333 | skipblanks(); |
---|
| 1334 | switch (*ordering) { |
---|
| 1335 | case Fr: |
---|
[84c60fc] | 1336 | fr = read_prefix_stn(fFalse, fTrue); |
---|
[5a38209] | 1337 | if (first_stn == End) first_stn = Fr; |
---|
| 1338 | break; |
---|
| 1339 | case To: |
---|
[84c60fc] | 1340 | to = read_prefix_stn(fFalse, fTrue); |
---|
[5a38209] | 1341 | if (first_stn == End) first_stn = To; |
---|
| 1342 | break; |
---|
| 1343 | case Station: |
---|
| 1344 | fr = to; |
---|
[84c60fc] | 1345 | to = read_prefix_stn(fFalse, fFalse); |
---|
[5a38209] | 1346 | first_stn = To; |
---|
| 1347 | break; |
---|
| 1348 | case Ignore: |
---|
| 1349 | skipword(); break; |
---|
| 1350 | case IgnoreAllAndNewLine: |
---|
| 1351 | skipline(); |
---|
| 1352 | /* fall through */ |
---|
| 1353 | case Newline: |
---|
| 1354 | if (fr != NULL) { |
---|
| 1355 | int r; |
---|
| 1356 | r = process_nosurvey(fr, to, first_stn == To); |
---|
| 1357 | if (!r) skipline(); |
---|
| 1358 | } |
---|
[838a602a] | 1359 | if (ordering[1] == End) { |
---|
| 1360 | do { |
---|
| 1361 | process_eol(); |
---|
| 1362 | process_bol(); |
---|
| 1363 | } while (isComm(ch)); |
---|
[ee6a621] | 1364 | if (!isData(ch)) { |
---|
[993454b] | 1365 | push_back(ch); |
---|
[ee6a621] | 1366 | return 1; |
---|
| 1367 | } |
---|
[838a602a] | 1368 | goto again; |
---|
| 1369 | } |
---|
[5a38209] | 1370 | fMulti = fTrue; |
---|
| 1371 | while (1) { |
---|
| 1372 | process_eol(); |
---|
| 1373 | process_bol(); |
---|
| 1374 | if (isData(ch)) break; |
---|
[ee6a621] | 1375 | if (!isComm(ch)) { |
---|
[993454b] | 1376 | push_back(ch); |
---|
[ee6a621] | 1377 | return 1; |
---|
| 1378 | } |
---|
[5a38209] | 1379 | } |
---|
| 1380 | break; |
---|
| 1381 | case IgnoreAll: |
---|
| 1382 | skipline(); |
---|
| 1383 | /* fall through */ |
---|
| 1384 | case End: |
---|
| 1385 | if (!fMulti) { |
---|
[ee6a621] | 1386 | int r = process_nosurvey(fr, to, first_stn == To); |
---|
[5a38209] | 1387 | process_eol(); |
---|
| 1388 | return r; |
---|
| 1389 | } |
---|
[eef4d8c] | 1390 | do { |
---|
[5a38209] | 1391 | process_eol(); |
---|
| 1392 | process_bol(); |
---|
[eef4d8c] | 1393 | } while (isComm(ch)); |
---|
[5a38209] | 1394 | goto again; |
---|
| 1395 | default: BUG("Unknown reading in ordering"); |
---|
| 1396 | } |
---|
| 1397 | } |
---|
| 1398 | } |
---|
| 1399 | |
---|
[50f6901] | 1400 | /* totally ignore a line of survey data */ |
---|
| 1401 | extern int |
---|
| 1402 | data_ignore(void) |
---|
| 1403 | { |
---|
| 1404 | skipline(); |
---|
[ee6a621] | 1405 | process_eol(); |
---|
[570f4bf] | 1406 | return 1; |
---|
[50f6901] | 1407 | } |
---|