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