[b0d908e] | 1 | /* datain.c |
---|
[d1b1380] | 2 | * Reads in survey files, dealing with special characters, keywords & data |
---|
[5dc0378] | 3 | * Copyright (C) 1991-2003,2005,2009,2010,2011,2012,2013,2014 Olly Betts |
---|
[44bb30d] | 4 | * Copyright (C) 2004 Simeon Warner |
---|
[846746e] | 5 | * |
---|
[89231c4] | 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
[846746e] | 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[89231c4] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
[846746e] | 15 | * |
---|
[89231c4] | 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[ecbc6c18] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[d1b1380] | 19 | */ |
---|
| 20 | |
---|
[a420b49] | 21 | #ifdef HAVE_CONFIG_H |
---|
| 22 | #include <config.h> |
---|
| 23 | #endif |
---|
[d1b1380] | 24 | |
---|
| 25 | #include <limits.h> |
---|
[a420b49] | 26 | #include <stdarg.h> |
---|
[d1b1380] | 27 | |
---|
| 28 | #include "debug.h" |
---|
[a420b49] | 29 | #include "cavern.h" |
---|
[c60cb16] | 30 | #include "date.h" |
---|
[07025e3] | 31 | #include "filename.h" |
---|
| 32 | #include "message.h" |
---|
[d1b1380] | 33 | #include "filelist.h" |
---|
| 34 | #include "netbits.h" |
---|
[5853657] | 35 | #include "netskel.h" |
---|
[d1b1380] | 36 | #include "readval.h" |
---|
| 37 | #include "datain.h" |
---|
| 38 | #include "commands.h" |
---|
| 39 | #include "out.h" |
---|
[39fba51] | 40 | #include "str.h" |
---|
[d1b1380] | 41 | |
---|
[2b078c4] | 42 | #define EPSILON (REAL_EPSILON * 1000) |
---|
[d1b1380] | 43 | |
---|
[58cc1fb] | 44 | #define var(I) (pcs->Var[(I)]) |
---|
[d1b1380] | 45 | |
---|
[44bb30d] | 46 | /* true if x is not-a-number value in Compass (999.0 or -999.0) */ |
---|
| 47 | /* Compass uses 999.0 but understands Karst data which used -999.0 */ |
---|
| 48 | #define is_compass_NaN(x) ( fabs(fabs(x)-999.0) < EPSILON ) |
---|
| 49 | |
---|
[58cc1fb] | 50 | int ch; |
---|
[d1b1380] | 51 | |
---|
[be97baf] | 52 | typedef enum { |
---|
| 53 | CTYPE_OMIT, CTYPE_READING, CTYPE_PLUMB, CTYPE_INFERPLUMB, CTYPE_HORIZ |
---|
| 54 | } clino_type; |
---|
[5b7c1b7] | 55 | |
---|
[eb18f4d] | 56 | /* Don't explicitly initialise as we can't set the jmp_buf - this has |
---|
| 57 | * static scope so will be initialised like this anyway */ |
---|
[b0d908e] | 58 | parse file /* = { NULL, NULL, 0, fFalse, NULL } */ ; |
---|
[a420b49] | 59 | |
---|
[932f7e9] | 60 | bool f_export_ok; |
---|
| 61 | |
---|
[21c226e] | 62 | static real value[Fr - 1]; |
---|
| 63 | #define VAL(N) value[(N)-1] |
---|
| 64 | static real variance[Fr - 1]; |
---|
| 65 | #define VAR(N) variance[(N)-1] |
---|
| 66 | |
---|
[ee05463] | 67 | /* style functions */ |
---|
[e2d48d8] | 68 | static void data_normal(void); |
---|
| 69 | static void data_cartesian(void); |
---|
| 70 | static void data_passage(void); |
---|
| 71 | static void data_nosurvey(void); |
---|
| 72 | static void data_ignore(void); |
---|
[ee05463] | 73 | |
---|
[c7451a9] | 74 | void |
---|
[c80bd34] | 75 | get_pos(filepos *fp) |
---|
[c7451a9] | 76 | { |
---|
[c80bd34] | 77 | fp->ch = ch; |
---|
| 78 | fp->offset = ftell(file.fh); |
---|
| 79 | if (fp->offset == -1) |
---|
[c7451a9] | 80 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
| 81 | } |
---|
| 82 | |
---|
[c80bd34] | 83 | void |
---|
| 84 | set_pos(const filepos *fp) |
---|
[c7451a9] | 85 | { |
---|
[c80bd34] | 86 | ch = fp->ch; |
---|
| 87 | if (fseek(file.fh, fp->offset, SEEK_SET) == -1) |
---|
[c7451a9] | 88 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
| 89 | } |
---|
| 90 | |
---|
[44bf1d9] | 91 | static void |
---|
[993454b] | 92 | push_back(int c) |
---|
| 93 | { |
---|
| 94 | if (c != EOF && ungetc(c, file.fh) == EOF) |
---|
| 95 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
| 96 | } |
---|
| 97 | |
---|
[895f767] | 98 | static void |
---|
| 99 | report_parent(parse * p) { |
---|
| 100 | if (p->parent) |
---|
| 101 | report_parent(p->parent); |
---|
| 102 | /* Force re-report of include tree for further errors in |
---|
| 103 | * parent files */ |
---|
| 104 | p->reported_where = fFalse; |
---|
[736f7df] | 105 | /* TRANSLATORS: %s is replaced by the filename of the parent file, and %u |
---|
| 106 | * by the line number in that file. */ |
---|
[895f767] | 107 | fprintf(STDERR, msg(/*In file included from %s:%u:\n*/5), p->filename, p->line); |
---|
| 108 | } |
---|
| 109 | |
---|
[a420b49] | 110 | static void |
---|
| 111 | error_list_parent_files(void) |
---|
| 112 | { |
---|
[b0d908e] | 113 | if (!file.reported_where && file.parent) { |
---|
[895f767] | 114 | report_parent(file.parent); |
---|
[b0d908e] | 115 | /* Suppress reporting of full include tree for further errors |
---|
| 116 | * in this file */ |
---|
| 117 | file.reported_where = fTrue; |
---|
[a420b49] | 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | void |
---|
| 122 | compile_error(int en, ...) |
---|
| 123 | { |
---|
[da96015] | 124 | int col = 0; |
---|
[a420b49] | 125 | va_list ap; |
---|
| 126 | va_start(ap, en); |
---|
| 127 | error_list_parent_files(); |
---|
[da96015] | 128 | if (en < 0) { |
---|
| 129 | en = -en; |
---|
| 130 | col = ftell(file.fh) - file.lpos; |
---|
| 131 | } |
---|
| 132 | v_report(1, file.filename, file.line, col, en, ap); |
---|
[a420b49] | 133 | va_end(ap); |
---|
| 134 | } |
---|
| 135 | |
---|
[fa42426] | 136 | void |
---|
| 137 | compile_error_skip(int en, ...) |
---|
| 138 | { |
---|
[da96015] | 139 | int col = 0; |
---|
[fa42426] | 140 | va_list ap; |
---|
| 141 | va_start(ap, en); |
---|
| 142 | error_list_parent_files(); |
---|
[da96015] | 143 | if (en < 0) { |
---|
| 144 | en = -en; |
---|
| 145 | col = ftell(file.fh) - file.lpos; |
---|
| 146 | } |
---|
| 147 | v_report(1, file.filename, file.line, col, en, ap); |
---|
[fa42426] | 148 | va_end(ap); |
---|
| 149 | skipline(); |
---|
| 150 | } |
---|
| 151 | |
---|
[39fba51] | 152 | void |
---|
| 153 | compile_error_token(int en) |
---|
| 154 | { |
---|
| 155 | char *p = NULL; |
---|
[8cea1ad] | 156 | int len = 0; |
---|
[39fba51] | 157 | skipblanks(); |
---|
| 158 | while (!isBlank(ch) && !isEol(ch)) { |
---|
[63dc4eb] | 159 | s_catchar(&p, &len, (char)ch); |
---|
[39fba51] | 160 | nextch(); |
---|
| 161 | } |
---|
[4bc4d58] | 162 | compile_error(en, p ? p : ""); |
---|
[39fba51] | 163 | osfree(p); |
---|
| 164 | } |
---|
| 165 | |
---|
[a420b49] | 166 | void |
---|
| 167 | compile_warning(int en, ...) |
---|
| 168 | { |
---|
[da96015] | 169 | int col = 0; |
---|
[a420b49] | 170 | va_list ap; |
---|
| 171 | va_start(ap, en); |
---|
| 172 | error_list_parent_files(); |
---|
[da96015] | 173 | if (en < 0) { |
---|
| 174 | en = -en; |
---|
| 175 | col = ftell(file.fh) - file.lpos; |
---|
| 176 | } |
---|
| 177 | v_report(0, file.filename, file.line, col, en, ap); |
---|
[a420b49] | 178 | va_end(ap); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | /* This function makes a note where to put output files */ |
---|
| 182 | static void |
---|
| 183 | using_data_file(const char *fnm) |
---|
| 184 | { |
---|
| 185 | if (!fnm_output_base) { |
---|
[4bab027] | 186 | /* was: fnm_output_base = base_from_fnm(fnm); */ |
---|
| 187 | fnm_output_base = baseleaf_from_fnm(fnm); |
---|
| 188 | } else if (fnm_output_base_is_dir) { |
---|
| 189 | /* --output pointed to directory so use the leaf basename in that dir */ |
---|
| 190 | char *lf, *p; |
---|
| 191 | lf = baseleaf_from_fnm(fnm); |
---|
| 192 | p = use_path(fnm_output_base, lf); |
---|
| 193 | osfree(lf); |
---|
| 194 | osfree(fnm_output_base); |
---|
| 195 | fnm_output_base = p; |
---|
| 196 | fnm_output_base_is_dir = 0; |
---|
[58cc1fb] | 197 | } |
---|
| 198 | } |
---|
| 199 | |
---|
[a420b49] | 200 | static void |
---|
| 201 | skipword(void) |
---|
| 202 | { |
---|
[58cc1fb] | 203 | while (!isBlank(ch) && !isEol(ch)) nextch(); |
---|
[d1b1380] | 204 | } |
---|
| 205 | |
---|
[a420b49] | 206 | extern void |
---|
| 207 | skipblanks(void) |
---|
| 208 | { |
---|
[58cc1fb] | 209 | while (isBlank(ch)) nextch(); |
---|
[d1b1380] | 210 | } |
---|
| 211 | |
---|
[a420b49] | 212 | extern void |
---|
| 213 | skipline(void) |
---|
| 214 | { |
---|
[58cc1fb] | 215 | while (!isEol(ch)) nextch(); |
---|
[d1b1380] | 216 | } |
---|
| 217 | |
---|
[90bb053f] | 218 | #ifndef NO_PERCENTAGE |
---|
| 219 | static long int filelen; |
---|
| 220 | #endif |
---|
| 221 | |
---|
| 222 | static void |
---|
| 223 | process_bol(void) |
---|
| 224 | { |
---|
| 225 | #ifndef NO_PERCENTAGE |
---|
| 226 | /* print %age of file done */ |
---|
[be97baf] | 227 | if (filelen > 0) { |
---|
| 228 | filepos fp; |
---|
| 229 | get_pos(&fp); |
---|
| 230 | printf("%d%%\r", (int)(100 * fp.offset / filelen)); |
---|
| 231 | } |
---|
[90bb053f] | 232 | #endif |
---|
| 233 | |
---|
| 234 | nextch(); |
---|
| 235 | skipblanks(); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | static void |
---|
| 239 | process_eol(void) |
---|
| 240 | { |
---|
| 241 | int eolchar; |
---|
| 242 | |
---|
| 243 | skipblanks(); |
---|
| 244 | |
---|
| 245 | if (!isEol(ch)) { |
---|
[da96015] | 246 | if (!isComm(ch)) compile_error(-/*End of line not blank*/15); |
---|
[90bb053f] | 247 | skipline(); |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | eolchar = ch; |
---|
| 251 | file.line++; |
---|
| 252 | /* skip any different eol characters so we get line counts correct on |
---|
| 253 | * DOS text files and similar, but don't count several adjacent blank |
---|
| 254 | * lines as one */ |
---|
| 255 | while (ch != EOF) { |
---|
| 256 | nextch(); |
---|
| 257 | if (ch == eolchar || !isEol(ch)) { |
---|
[993454b] | 258 | push_back(ch); |
---|
[90bb053f] | 259 | break; |
---|
| 260 | } |
---|
| 261 | } |
---|
[da96015] | 262 | file.lpos = ftell(file.fh); |
---|
[90bb053f] | 263 | } |
---|
| 264 | |
---|
| 265 | static bool |
---|
| 266 | process_non_data_line(void) |
---|
| 267 | { |
---|
| 268 | process_bol(); |
---|
| 269 | |
---|
| 270 | if (isData(ch)) return fFalse; |
---|
| 271 | |
---|
| 272 | if (isKeywd(ch)) { |
---|
| 273 | nextch(); |
---|
| 274 | handle_command(); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | process_eol(); |
---|
| 278 | |
---|
| 279 | return fTrue; |
---|
| 280 | } |
---|
| 281 | |
---|
[21c226e] | 282 | static void |
---|
| 283 | read_reading(reading r, bool f_optional) |
---|
| 284 | { |
---|
| 285 | int n_readings; |
---|
| 286 | q_quantity q; |
---|
| 287 | switch (r) { |
---|
| 288 | case Tape: q = Q_LENGTH; break; |
---|
| 289 | case Comp: q = Q_BEARING; break; |
---|
| 290 | case BackComp: q = Q_BACKBEARING; break; |
---|
| 291 | case Clino: q = Q_GRADIENT; break; |
---|
| 292 | case BackClino: q = Q_BACKGRADIENT; break; |
---|
| 293 | case FrDepth: case ToDepth: q = Q_DEPTH; break; |
---|
| 294 | case Dx: q = Q_DX; break; |
---|
| 295 | case Dy: q = Q_DY; break; |
---|
| 296 | case Dz: q = Q_DZ; break; |
---|
| 297 | case FrCount: case ToCount: q = Q_COUNT; break; |
---|
[07442af] | 298 | case Left: q = Q_LEFT; break; |
---|
| 299 | case Right: q = Q_RIGHT; break; |
---|
| 300 | case Up: q = Q_UP; break; |
---|
| 301 | case Down: q = Q_DOWN; break; |
---|
[74a0681] | 302 | default: |
---|
[44bb30d] | 303 | q = Q_NULL; /* Suppress compiler warning */; |
---|
[74a0681] | 304 | BUG("Unexpected case"); |
---|
[21c226e] | 305 | } |
---|
[e3b03de] | 306 | VAL(r) = read_numeric(f_optional, &n_readings); |
---|
[21c226e] | 307 | VAR(r) = var(q); |
---|
| 308 | if (n_readings > 1) VAR(r) /= sqrt(n_readings); |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | static void |
---|
| 312 | read_bearing_or_omit(reading r) |
---|
| 313 | { |
---|
| 314 | int n_readings; |
---|
[74a0681] | 315 | q_quantity q = Q_NULL; |
---|
[21c226e] | 316 | VAL(r) = read_numeric_or_omit(&n_readings); |
---|
| 317 | switch (r) { |
---|
| 318 | case Comp: q = Q_BEARING; break; |
---|
| 319 | case BackComp: q = Q_BACKBEARING; break; |
---|
[74a0681] | 320 | default: |
---|
[44bb30d] | 321 | q = Q_NULL; /* Suppress compiler warning */; |
---|
[74a0681] | 322 | BUG("Unexpected case"); |
---|
[21c226e] | 323 | } |
---|
| 324 | VAR(r) = var(q); |
---|
| 325 | if (n_readings > 1) VAR(r) /= sqrt(n_readings); |
---|
| 326 | } |
---|
| 327 | |
---|
[be97baf] | 328 | /* For reading Compass MAK files which have a freeform syntax */ |
---|
| 329 | static void |
---|
| 330 | nextch_handling_eol(void) |
---|
| 331 | { |
---|
| 332 | nextch(); |
---|
| 333 | while (ch != EOF && isEol(ch)) { |
---|
| 334 | process_eol(); |
---|
| 335 | nextch(); |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | #define LITLEN(S) (sizeof(S"") - 1) |
---|
| 340 | #define has_ext(F,L,E) ((L) > LITLEN(E) + 1 &&\ |
---|
| 341 | (F)[(L) - LITLEN(E) - 1] == FNM_SEP_EXT &&\ |
---|
| 342 | strcasecmp((F) + (L) - LITLEN(E), E) == 0) |
---|
[a420b49] | 343 | extern void |
---|
| 344 | data_file(const char *pth, const char *fnm) |
---|
| 345 | { |
---|
[47c7a94] | 346 | int begin_lineno_store; |
---|
[7f08c83] | 347 | parse file_store; |
---|
[b4fe9fb] | 348 | volatile enum {FMT_SVX, FMT_DAT, FMT_MAK} fmt = FMT_SVX; |
---|
[d1b1380] | 349 | |
---|
[7f08c83] | 350 | { |
---|
| 351 | char *filename; |
---|
[f4b609d] | 352 | FILE *fh; |
---|
[be97baf] | 353 | size_t len; |
---|
| 354 | |
---|
[f4b609d] | 355 | if (!pth) { |
---|
| 356 | /* file specified on command line - don't do special translation */ |
---|
| 357 | fh = fopenWithPthAndExt(pth, fnm, EXT_SVX_DATA, "rb", &filename); |
---|
| 358 | } else { |
---|
| 359 | fh = fopen_portable(pth, fnm, EXT_SVX_DATA, "rb", &filename); |
---|
| 360 | } |
---|
[bd1913f] | 361 | |
---|
[7f08c83] | 362 | if (fh == NULL) { |
---|
[ee7511a] | 363 | compile_error(/*Couldn’t open data file “%s”*/24, fnm); |
---|
[7f08c83] | 364 | return; |
---|
| 365 | } |
---|
| 366 | |
---|
[be97baf] | 367 | len = strlen(filename); |
---|
| 368 | if (has_ext(filename, len, "dat")) { |
---|
| 369 | fmt = FMT_DAT; |
---|
| 370 | } else if (has_ext(filename, len, "mak")) { |
---|
| 371 | fmt = FMT_MAK; |
---|
| 372 | } |
---|
| 373 | |
---|
[7f08c83] | 374 | file_store = file; |
---|
| 375 | if (file.fh) file.parent = &file_store; |
---|
| 376 | file.fh = fh; |
---|
| 377 | file.filename = filename; |
---|
| 378 | file.line = 1; |
---|
[da96015] | 379 | file.lpos = 0; |
---|
[b0d908e] | 380 | file.reported_where = fFalse; |
---|
[a420b49] | 381 | } |
---|
[cb3d1e2] | 382 | |
---|
[5b68ae1] | 383 | if (fPercent) printf("%s:\n", fnm); |
---|
[d1b1380] | 384 | |
---|
[a420b49] | 385 | using_data_file(file.filename); |
---|
[d1b1380] | 386 | |
---|
[47c7a94] | 387 | begin_lineno_store = pcs->begin_lineno; |
---|
| 388 | pcs->begin_lineno = 0; |
---|
[cb3d1e2] | 389 | |
---|
[d1b1380] | 390 | #ifndef NO_PERCENTAGE |
---|
[58cc1fb] | 391 | /* Try to find how long the file is... |
---|
| 392 | * However, under ANSI fseek( ..., SEEK_END) may not be supported */ |
---|
| 393 | filelen = 0; |
---|
| 394 | if (fPercent) { |
---|
[c80bd34] | 395 | if (fseek(file.fh, 0l, SEEK_END) == 0) { |
---|
| 396 | filepos fp; |
---|
| 397 | get_pos(&fp); |
---|
| 398 | filelen = fp.offset; |
---|
| 399 | } |
---|
[58cc1fb] | 400 | rewind(file.fh); /* reset file ptr to start & clear any error state */ |
---|
| 401 | } |
---|
[d1b1380] | 402 | #endif |
---|
| 403 | |
---|
[be97baf] | 404 | if (fmt == FMT_DAT) { |
---|
| 405 | short *t; |
---|
| 406 | int i; |
---|
| 407 | settings *pcsNew; |
---|
| 408 | |
---|
| 409 | pcsNew = osnew(settings); |
---|
| 410 | *pcsNew = *pcs; /* copy contents */ |
---|
| 411 | pcsNew->begin_lineno = 0; |
---|
| 412 | pcsNew->next = pcs; |
---|
| 413 | pcs = pcsNew; |
---|
| 414 | default_units(pcs); |
---|
| 415 | default_calib(pcs); |
---|
| 416 | |
---|
| 417 | pcs->style = STYLE_NORMAL; |
---|
| 418 | pcs->units[Q_LENGTH] = METRES_PER_FOOT; |
---|
| 419 | t = ((short*)osmalloc(ossizeof(short) * 257)) + 1; |
---|
| 420 | |
---|
| 421 | t[EOF] = SPECIAL_EOL; |
---|
| 422 | memset(t, 0, sizeof(short) * 33); |
---|
| 423 | for (i = 33; i < 127; i++) t[i] = SPECIAL_NAMES; |
---|
| 424 | t[127] = 0; |
---|
| 425 | for (i = 128; i < 256; i++) t[i] = SPECIAL_NAMES; |
---|
| 426 | t['\t'] |= SPECIAL_BLANK; |
---|
| 427 | t[' '] |= SPECIAL_BLANK; |
---|
| 428 | t['\032'] |= SPECIAL_EOL; /* Ctrl-Z, so olde DOS text files are handled ok */ |
---|
| 429 | t['\n'] |= SPECIAL_EOL; |
---|
| 430 | t['\r'] |= SPECIAL_EOL; |
---|
| 431 | t['.'] |= SPECIAL_DECIMAL; |
---|
| 432 | t['-'] |= SPECIAL_MINUS; |
---|
| 433 | t['+'] |= SPECIAL_PLUS; |
---|
| 434 | pcs->Translate = t; |
---|
| 435 | pcs->Case = OFF; |
---|
| 436 | pcs->Truncate = INT_MAX; |
---|
[e9ea53b] | 437 | pcs->infer = BIT(INFER_EQUATES)|BIT(INFER_EXPORTS)|BIT(INFER_PLUMBS); |
---|
[be97baf] | 438 | } else if (fmt == FMT_MAK) { |
---|
| 439 | short *t; |
---|
| 440 | int i; |
---|
| 441 | settings *pcsNew; |
---|
| 442 | |
---|
| 443 | pcsNew = osnew(settings); |
---|
| 444 | *pcsNew = *pcs; /* copy contents */ |
---|
| 445 | pcsNew->begin_lineno = 0; |
---|
| 446 | pcsNew->next = pcs; |
---|
| 447 | pcs = pcsNew; |
---|
| 448 | |
---|
| 449 | t = ((short*)osmalloc(ossizeof(short) * 257)) + 1; |
---|
[44bb30d] | 450 | |
---|
[be97baf] | 451 | t[EOF] = SPECIAL_EOL; |
---|
| 452 | memset(t, 0, sizeof(short) * 33); |
---|
| 453 | for (i = 33; i < 127; i++) t[i] = SPECIAL_NAMES; |
---|
| 454 | t[127] = 0; |
---|
| 455 | for (i = 128; i < 256; i++) t[i] = SPECIAL_NAMES; |
---|
| 456 | t['['] = t[','] = t[';'] = 0; |
---|
| 457 | t['\t'] |= SPECIAL_BLANK; |
---|
| 458 | t[' '] |= SPECIAL_BLANK; |
---|
| 459 | t['\032'] |= SPECIAL_EOL; /* Ctrl-Z, so olde DOS text files are handled ok */ |
---|
| 460 | t['\n'] |= SPECIAL_EOL; |
---|
| 461 | t['\r'] |= SPECIAL_EOL; |
---|
| 462 | t['.'] |= SPECIAL_DECIMAL; |
---|
| 463 | t['-'] |= SPECIAL_MINUS; |
---|
| 464 | t['+'] |= SPECIAL_PLUS; |
---|
| 465 | pcs->Translate = t; |
---|
| 466 | pcs->Case = OFF; |
---|
| 467 | pcs->Truncate = INT_MAX; |
---|
| 468 | } |
---|
| 469 | |
---|
[7d5f3c0] | 470 | #ifdef HAVE_SETJMP_H |
---|
[a420b49] | 471 | /* errors in nested functions can longjmp here */ |
---|
| 472 | if (setjmp(file.jbSkipLine)) { |
---|
[e363f8b] | 473 | skipline(); |
---|
[076d33d] | 474 | process_eol(); |
---|
[a420b49] | 475 | } |
---|
[d1b1380] | 476 | #endif |
---|
[cb3d1e2] | 477 | |
---|
[be97baf] | 478 | if (fmt == FMT_DAT) { |
---|
| 479 | while (!feof(file.fh) && !ferror(file.fh)) { |
---|
| 480 | static reading compass_order[] = { |
---|
[44bb30d] | 481 | Fr, To, Tape, CompassDATComp, CompassDATClino, |
---|
[07442af] | 482 | CompassDATLeft, CompassDATRight, CompassDATUp, CompassDATDown, |
---|
[be97baf] | 483 | CompassDATFlags, IgnoreAll |
---|
| 484 | }; |
---|
| 485 | static reading compass_order_backsights[] = { |
---|
[44bb30d] | 486 | Fr, To, Tape, CompassDATComp, CompassDATClino, |
---|
[07442af] | 487 | CompassDATLeft, CompassDATRight, CompassDATUp, CompassDATDown, |
---|
[44bb30d] | 488 | CompassDATBackComp, CompassDATBackClino, |
---|
[be97baf] | 489 | CompassDATFlags, IgnoreAll |
---|
| 490 | }; |
---|
| 491 | /* <Cave name> */ |
---|
| 492 | process_bol(); |
---|
| 493 | skipline(); |
---|
| 494 | process_eol(); |
---|
| 495 | /* SURVEY NAME: <Short name> */ |
---|
| 496 | get_token(); |
---|
| 497 | get_token(); |
---|
| 498 | /* if (ch != ':') ... */ |
---|
| 499 | nextch(); |
---|
| 500 | get_token(); |
---|
| 501 | skipline(); |
---|
| 502 | process_eol(); |
---|
| 503 | /* SURVEY DATE: 7 10 79 COMMENT:<Long name> */ |
---|
| 504 | get_token(); |
---|
| 505 | get_token(); |
---|
[5dc0378] | 506 | copy_on_write_meta(pcs); |
---|
[b5a3219] | 507 | if (ch == ':') { |
---|
[1ee204e] | 508 | int year, month, day; |
---|
[b5a3219] | 509 | |
---|
| 510 | nextch(); |
---|
[1ee204e] | 511 | |
---|
[2c39b49] | 512 | /* NB order is *month* *day* year */ |
---|
[1ee204e] | 513 | month = read_uint(); |
---|
| 514 | day = read_uint(); |
---|
| 515 | year = read_uint(); |
---|
[b5a3219] | 516 | /* Note: Larry says a 2 digit year is always 19XX */ |
---|
[1ee204e] | 517 | if (year < 100) year += 1900; |
---|
[b5a3219] | 518 | |
---|
[1ee204e] | 519 | pcs->meta->days1 = pcs->meta->days2 = days_since_1900(year, month, day); |
---|
[a6301a1] | 520 | } else { |
---|
[1ee204e] | 521 | pcs->meta->days1 = pcs->meta->days2 = -1; |
---|
[b5a3219] | 522 | } |
---|
[be97baf] | 523 | skipline(); |
---|
| 524 | process_eol(); |
---|
| 525 | /* SURVEY TEAM: */ |
---|
| 526 | get_token(); |
---|
| 527 | get_token(); |
---|
| 528 | skipline(); |
---|
| 529 | process_eol(); |
---|
| 530 | /* <Survey team> */ |
---|
| 531 | nextch(); |
---|
| 532 | skipline(); |
---|
| 533 | process_eol(); |
---|
| 534 | /* DECLINATION: 1.00 FORMAT: DDDDLUDRADLN CORRECTIONS: 2.00 3.00 4.00 */ |
---|
| 535 | get_token(); |
---|
| 536 | nextch(); /* : */ |
---|
| 537 | skipblanks(); |
---|
| 538 | pcs->z[Q_DECLINATION] = -read_numeric(fFalse, NULL); |
---|
| 539 | pcs->z[Q_DECLINATION] *= pcs->units[Q_DECLINATION]; |
---|
| 540 | get_token(); |
---|
| 541 | pcs->ordering = compass_order; |
---|
| 542 | if (strcmp(buffer, "FORMAT") == 0) { |
---|
| 543 | nextch(); /* : */ |
---|
| 544 | get_token(); |
---|
| 545 | if (strlen(buffer) >= 12 && buffer[11] == 'B') { |
---|
| 546 | /* We have backsights for compass and clino */ |
---|
| 547 | pcs->ordering = compass_order_backsights; |
---|
| 548 | } |
---|
| 549 | get_token(); |
---|
[107b8bd] | 550 | } |
---|
[be97baf] | 551 | if (strcmp(buffer, "CORRECTIONS") == 0) { |
---|
| 552 | nextch(); /* : */ |
---|
| 553 | pcs->z[Q_BEARING] = -rad(read_numeric(fFalse, NULL)); |
---|
| 554 | pcs->z[Q_GRADIENT] = -rad(read_numeric(fFalse, NULL)); |
---|
| 555 | pcs->z[Q_LENGTH] = -read_numeric(fFalse, NULL); |
---|
| 556 | } else { |
---|
| 557 | pcs->z[Q_BEARING] = 0; |
---|
| 558 | pcs->z[Q_GRADIENT] = 0; |
---|
| 559 | pcs->z[Q_LENGTH] = 0; |
---|
[a420b49] | 560 | } |
---|
[be97baf] | 561 | skipline(); |
---|
| 562 | process_eol(); |
---|
| 563 | /* BLANK LINE */ |
---|
| 564 | process_bol(); |
---|
| 565 | skipline(); |
---|
| 566 | process_eol(); |
---|
| 567 | /* heading line */ |
---|
| 568 | process_bol(); |
---|
| 569 | skipline(); |
---|
| 570 | process_eol(); |
---|
| 571 | /* BLANK LINE */ |
---|
| 572 | process_bol(); |
---|
| 573 | skipline(); |
---|
| 574 | process_eol(); |
---|
| 575 | while (!feof(file.fh)) { |
---|
| 576 | process_bol(); |
---|
| 577 | if (ch == '\x0c') { |
---|
| 578 | nextch(); |
---|
| 579 | process_eol(); |
---|
| 580 | break; |
---|
| 581 | } |
---|
[e2d48d8] | 582 | data_normal(); |
---|
[be97baf] | 583 | } |
---|
| 584 | } |
---|
| 585 | { |
---|
| 586 | settings *pcsParent = pcs->next; |
---|
| 587 | SVX_ASSERT(pcsParent); |
---|
| 588 | pcs->ordering = NULL; |
---|
| 589 | free_settings(pcs); |
---|
| 590 | pcs = pcsParent; |
---|
[44bb30d] | 591 | } |
---|
[be97baf] | 592 | } else if (fmt == FMT_MAK) { |
---|
| 593 | nextch_handling_eol(); |
---|
| 594 | while (!feof(file.fh) && !ferror(file.fh)) { |
---|
| 595 | if (ch == '#') { |
---|
| 596 | /* include a file */ |
---|
| 597 | int ch_store; |
---|
[b4fe9fb] | 598 | char *dat_pth = path_from_fnm(file.filename); |
---|
| 599 | char *dat_fnm = NULL; |
---|
| 600 | int dat_fnm_len; |
---|
[be97baf] | 601 | nextch_handling_eol(); |
---|
| 602 | while (ch != ',' && ch != ';' && ch != EOF) { |
---|
| 603 | while (isEol(ch)) process_eol(); |
---|
[63dc4eb] | 604 | s_catchar(&dat_fnm, &dat_fnm_len, (char)ch); |
---|
[be97baf] | 605 | nextch_handling_eol(); |
---|
| 606 | } |
---|
| 607 | while (ch != ';' && ch != EOF) { |
---|
| 608 | prefix *name; |
---|
| 609 | nextch_handling_eol(); |
---|
[c458cf7] | 610 | name = read_prefix(PFX_STATION|PFX_OPT); |
---|
[be97baf] | 611 | if (name) { |
---|
| 612 | skipblanks(); |
---|
| 613 | if (ch == '[') { |
---|
| 614 | /* fixed pt */ |
---|
| 615 | node *stn; |
---|
| 616 | real x, y, z; |
---|
| 617 | name->sflags |= BIT(SFLAGS_FIXED); |
---|
| 618 | nextch_handling_eol(); |
---|
| 619 | while (!isdigit(ch) && ch != '+' && ch != '-' && |
---|
| 620 | ch != '.' && ch != ']' && ch != EOF) { |
---|
| 621 | nextch_handling_eol(); |
---|
| 622 | } |
---|
| 623 | x = read_numeric(fFalse, NULL); |
---|
| 624 | while (!isdigit(ch) && ch != '+' && ch != '-' && |
---|
| 625 | ch != '.' && ch != ']' && ch != EOF) { |
---|
| 626 | nextch_handling_eol(); |
---|
| 627 | } |
---|
| 628 | y = read_numeric(fFalse, NULL); |
---|
| 629 | while (!isdigit(ch) && ch != '+' && ch != '-' && |
---|
| 630 | ch != '.' && ch != ']' && ch != EOF) { |
---|
| 631 | nextch_handling_eol(); |
---|
| 632 | } |
---|
| 633 | z = read_numeric(fFalse, NULL); |
---|
| 634 | stn = StnFromPfx(name); |
---|
| 635 | if (!fixed(stn)) { |
---|
| 636 | POS(stn, 0) = x; |
---|
| 637 | POS(stn, 1) = y; |
---|
| 638 | POS(stn, 2) = z; |
---|
| 639 | fix(stn); |
---|
| 640 | } else { |
---|
| 641 | if (x != POS(stn, 0) || y != POS(stn, 1) || |
---|
| 642 | z != POS(stn, 2)) { |
---|
| 643 | compile_error(/*Station already fixed or equated to a fixed point*/46); |
---|
| 644 | } else { |
---|
| 645 | compile_warning(/*Station already fixed at the same coordinates*/55); |
---|
| 646 | } |
---|
| 647 | } |
---|
| 648 | while (ch != ']' && ch != EOF) nextch_handling_eol(); |
---|
| 649 | if (ch == ']') { |
---|
| 650 | nextch_handling_eol(); |
---|
| 651 | skipblanks(); |
---|
| 652 | } |
---|
| 653 | } else { |
---|
| 654 | /* FIXME: link station - ignore for now */ |
---|
| 655 | /* FIXME: perhaps issue warning? */ |
---|
| 656 | } |
---|
| 657 | while (ch != ',' && ch != ';' && ch != EOF) |
---|
| 658 | nextch_handling_eol(); |
---|
| 659 | } |
---|
| 660 | } |
---|
[b4fe9fb] | 661 | if (dat_fnm) { |
---|
[be97baf] | 662 | ch_store = ch; |
---|
[b4fe9fb] | 663 | data_file(dat_pth, dat_fnm); |
---|
[be97baf] | 664 | ch = ch_store; |
---|
[b4fe9fb] | 665 | osfree(dat_fnm); |
---|
[be97baf] | 666 | } |
---|
| 667 | } else { |
---|
| 668 | /* FIXME: also check for % and $ later */ |
---|
| 669 | nextch_handling_eol(); |
---|
| 670 | } |
---|
| 671 | } |
---|
| 672 | { |
---|
| 673 | settings *pcsParent = pcs->next; |
---|
| 674 | SVX_ASSERT(pcsParent); |
---|
| 675 | free_settings(pcs); |
---|
| 676 | pcs = pcsParent; |
---|
[44bb30d] | 677 | } |
---|
[be97baf] | 678 | } else { |
---|
| 679 | while (!feof(file.fh) && !ferror(file.fh)) { |
---|
| 680 | if (!process_non_data_line()) { |
---|
| 681 | f_export_ok = fFalse; |
---|
| 682 | switch (pcs->style) { |
---|
| 683 | case STYLE_NORMAL: |
---|
| 684 | case STYLE_DIVING: |
---|
| 685 | case STYLE_CYLPOLAR: |
---|
[e2d48d8] | 686 | data_normal(); |
---|
[be97baf] | 687 | break; |
---|
| 688 | case STYLE_CARTESIAN: |
---|
[e2d48d8] | 689 | data_cartesian(); |
---|
[be97baf] | 690 | break; |
---|
[ee05463] | 691 | case STYLE_PASSAGE: |
---|
[e2d48d8] | 692 | data_passage(); |
---|
[ee05463] | 693 | break; |
---|
[be97baf] | 694 | case STYLE_NOSURVEY: |
---|
[e2d48d8] | 695 | data_nosurvey(); |
---|
[be97baf] | 696 | break; |
---|
| 697 | case STYLE_IGNORE: |
---|
[e2d48d8] | 698 | data_ignore(); |
---|
[be97baf] | 699 | break; |
---|
| 700 | default: |
---|
| 701 | BUG("bad style"); |
---|
| 702 | } |
---|
| 703 | } |
---|
[647407d] | 704 | } |
---|
[a420b49] | 705 | } |
---|
| 706 | |
---|
[932f7e9] | 707 | /* don't allow *BEGIN at the end of a file, then *EXPORT in the |
---|
| 708 | * including file */ |
---|
| 709 | f_export_ok = fFalse; |
---|
| 710 | |
---|
[a420b49] | 711 | #ifndef NO_PERCENTAGE |
---|
| 712 | if (fPercent) putnl(); |
---|
[4f8285d] | 713 | #endif |
---|
[d1b1380] | 714 | |
---|
[47c7a94] | 715 | if (pcs->begin_lineno) { |
---|
[0e867ba6] | 716 | error_in_file(file.filename, pcs->begin_lineno, |
---|
| 717 | /*BEGIN with no matching END in this file*/23); |
---|
[47c7a94] | 718 | /* Implicitly close any unclosed BEGINs from this file */ |
---|
| 719 | do { |
---|
| 720 | settings *pcsParent = pcs->next; |
---|
[4c07c51] | 721 | SVX_ASSERT(pcsParent); |
---|
[647407d] | 722 | free_settings(pcs); |
---|
[47c7a94] | 723 | pcs = pcsParent; |
---|
| 724 | } while (pcs->begin_lineno); |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | pcs->begin_lineno = begin_lineno_store; |
---|
[cb3d1e2] | 728 | |
---|
[22c9877] | 729 | if (ferror(file.fh)) |
---|
[bfe1242] | 730 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
[cb3d1e2] | 731 | |
---|
[22c9877] | 732 | (void)fclose(file.fh); |
---|
[7f08c83] | 733 | |
---|
[22c9877] | 734 | file = file_store; |
---|
[4d9eecd] | 735 | |
---|
| 736 | /* don't free this - it may be pointed to by prefix.file */ |
---|
| 737 | /* osfree(file.filename); */ |
---|
[a420b49] | 738 | } |
---|
[d1b1380] | 739 | |
---|
[b6de07d] | 740 | static real |
---|
| 741 | mod2pi(real a) |
---|
| 742 | { |
---|
| 743 | return a - floor(a / (2 * M_PI)) * (2 * M_PI); |
---|
| 744 | } |
---|
| 745 | |
---|
[dcec245] | 746 | static real |
---|
[5b7c1b7] | 747 | handle_plumb(clino_type *p_ctype) |
---|
[dcec245] | 748 | { |
---|
| 749 | typedef enum { |
---|
| 750 | CLINO_NULL=-1, CLINO_UP, CLINO_DOWN, CLINO_LEVEL |
---|
| 751 | } clino_tok; |
---|
| 752 | static sztok clino_tab[] = { |
---|
| 753 | {"D", CLINO_DOWN}, |
---|
| 754 | {"DOWN", CLINO_DOWN}, |
---|
| 755 | {"H", CLINO_LEVEL}, |
---|
| 756 | {"LEVEL", CLINO_LEVEL}, |
---|
| 757 | {"U", CLINO_UP}, |
---|
| 758 | {"UP", CLINO_UP}, |
---|
| 759 | {NULL, CLINO_NULL} |
---|
| 760 | }; |
---|
[5b7c1b7] | 761 | static real clinos[] = {(real)M_PI_2, (real)(-M_PI_2), (real)0.0}; |
---|
[dcec245] | 762 | clino_tok tok; |
---|
| 763 | |
---|
| 764 | skipblanks(); |
---|
| 765 | if (isalpha(ch)) { |
---|
[c80bd34] | 766 | filepos fp; |
---|
| 767 | get_pos(&fp); |
---|
[dcec245] | 768 | get_token(); |
---|
| 769 | tok = match_tok(clino_tab, TABSIZE(clino_tab)); |
---|
| 770 | if (tok != CLINO_NULL) { |
---|
[be97baf] | 771 | *p_ctype = (tok == CLINO_LEVEL ? CTYPE_HORIZ : CTYPE_PLUMB); |
---|
[dcec245] | 772 | return clinos[tok]; |
---|
| 773 | } |
---|
[c80bd34] | 774 | set_pos(&fp); |
---|
[dcec245] | 775 | } else if (isSign(ch)) { |
---|
| 776 | int chOld = ch; |
---|
| 777 | nextch(); |
---|
| 778 | if (toupper(ch) == 'V') { |
---|
| 779 | nextch(); |
---|
[fa42426] | 780 | *p_ctype = CTYPE_PLUMB; |
---|
[bceebf4] | 781 | return (!isMinus(chOld) ? M_PI_2 : -M_PI_2); |
---|
[dcec245] | 782 | } |
---|
| 783 | |
---|
[bd1913f] | 784 | if (isOmit(chOld)) { |
---|
[fa42426] | 785 | *p_ctype = CTYPE_OMIT; |
---|
[dcec245] | 786 | /* no clino reading, so assume 0 with large sd */ |
---|
| 787 | return (real)0.0; |
---|
| 788 | } |
---|
[5b7c1b7] | 789 | } else if (isOmit(ch)) { |
---|
| 790 | /* OMIT char may not be a SIGN char too so we need to check here as |
---|
| 791 | * well as above... */ |
---|
| 792 | nextch(); |
---|
[fa42426] | 793 | *p_ctype = CTYPE_OMIT; |
---|
[5b7c1b7] | 794 | /* no clino reading, so assume 0 with large sd */ |
---|
| 795 | return (real)0.0; |
---|
[dcec245] | 796 | } |
---|
| 797 | return HUGE_REAL; |
---|
| 798 | } |
---|
| 799 | |
---|
[b6de07d] | 800 | static void |
---|
[b4fe9fb] | 801 | warn_readings_differ(int msgno, real diff) |
---|
[b6de07d] | 802 | { |
---|
| 803 | char buf[64]; |
---|
| 804 | char *p; |
---|
| 805 | sprintf(buf, "%.2f", deg(fabs(diff))); |
---|
| 806 | p = strchr(buf, '.'); |
---|
| 807 | if (p) { |
---|
| 808 | char *z = p; |
---|
| 809 | while (*++p) { |
---|
| 810 | if (*p != '0') z = p + 1; |
---|
| 811 | } |
---|
| 812 | if (*z) *z = '\0'; |
---|
| 813 | } |
---|
[b4fe9fb] | 814 | compile_warning(msgno, buf); |
---|
[b6de07d] | 815 | } |
---|
| 816 | |
---|
| 817 | static bool |
---|
[21c226e] | 818 | handle_comp_units(void) |
---|
[b6de07d] | 819 | { |
---|
| 820 | bool fNoComp = fTrue; |
---|
[21c226e] | 821 | if (VAL(Comp) != HUGE_REAL) { |
---|
[b6de07d] | 822 | fNoComp = fFalse; |
---|
[21c226e] | 823 | VAL(Comp) *= pcs->units[Q_BEARING]; |
---|
| 824 | if (VAL(Comp) < (real)0.0 || VAL(Comp) - M_PI * 2.0 > EPSILON) { |
---|
[736f7df] | 825 | /* TRANSLATORS: Suspicious means something like 410 degrees or -20 |
---|
| 826 | * degrees */ |
---|
[b6de07d] | 827 | compile_warning(/*Suspicious compass reading*/59); |
---|
[21c226e] | 828 | VAL(Comp) = mod2pi(VAL(Comp)); |
---|
[b6de07d] | 829 | } |
---|
| 830 | } |
---|
[21c226e] | 831 | if (VAL(BackComp) != HUGE_REAL) { |
---|
[b6de07d] | 832 | fNoComp = fFalse; |
---|
[21c226e] | 833 | VAL(BackComp) *= pcs->units[Q_BACKBEARING]; |
---|
| 834 | if (VAL(BackComp) < (real)0.0 || VAL(BackComp) - M_PI * 2.0 > EPSILON) { |
---|
[b6de07d] | 835 | /* FIXME: different message for BackComp? */ |
---|
| 836 | compile_warning(/*Suspicious compass reading*/59); |
---|
[21c226e] | 837 | VAL(BackComp) = mod2pi(VAL(BackComp)); |
---|
[b6de07d] | 838 | } |
---|
| 839 | } |
---|
| 840 | return fNoComp; |
---|
| 841 | } |
---|
| 842 | |
---|
| 843 | static real |
---|
[21c226e] | 844 | handle_compass(real *p_var) |
---|
[b6de07d] | 845 | { |
---|
[b4fe9fb] | 846 | real compvar = VAR(Comp); |
---|
[21c226e] | 847 | real comp = VAL(Comp); |
---|
| 848 | real backcomp = VAL(BackComp); |
---|
[b6de07d] | 849 | if (comp != HUGE_REAL) { |
---|
| 850 | comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING]; |
---|
| 851 | comp -= pcs->z[Q_DECLINATION]; |
---|
| 852 | } |
---|
| 853 | if (backcomp != HUGE_REAL) { |
---|
| 854 | backcomp = (backcomp - pcs->z[Q_BACKBEARING]) |
---|
| 855 | * pcs->sc[Q_BACKBEARING]; |
---|
| 856 | backcomp -= pcs->z[Q_DECLINATION]; |
---|
| 857 | backcomp -= M_PI; |
---|
| 858 | if (comp != HUGE_REAL) { |
---|
| 859 | real diff = comp - backcomp; |
---|
| 860 | real adj = fabs(diff) > M_PI ? M_PI : 0; |
---|
| 861 | diff -= floor((diff + M_PI) / (2 * M_PI)) * 2 * M_PI; |
---|
[b4fe9fb] | 862 | if (sqrd(diff / 2.0) > compvar + VAR(Q_BACKBEARING)) { |
---|
[770157e] | 863 | /* fore and back readings differ by more than 2 sds */ |
---|
[736f7df] | 864 | /* TRANSLATORS: Degrees are the angular measurement where there are |
---|
| 865 | * 360 in a full circle. */ |
---|
[ee7511a] | 866 | warn_readings_differ(/*COMPASS reading and BACKCOMPASS reading disagree by %s degrees*/98, diff); |
---|
[b6de07d] | 867 | } |
---|
[b4fe9fb] | 868 | comp = (comp / compvar + backcomp / VAR(BackComp)); |
---|
| 869 | compvar = (compvar + VAR(BackComp)) / 4; |
---|
| 870 | comp *= compvar; |
---|
[b6de07d] | 871 | comp += adj; |
---|
| 872 | } else { |
---|
| 873 | comp = backcomp; |
---|
[b4fe9fb] | 874 | compvar = VAR(BackComp); |
---|
[b6de07d] | 875 | } |
---|
| 876 | } |
---|
[b4fe9fb] | 877 | *p_var = compvar; |
---|
[b6de07d] | 878 | return comp; |
---|
| 879 | } |
---|
| 880 | |
---|
[90bb053f] | 881 | static int |
---|
[21c226e] | 882 | process_normal(prefix *fr, prefix *to, bool fToFirst, |
---|
| 883 | clino_type ctype, clino_type backctype) |
---|
[a420b49] | 884 | { |
---|
[21c226e] | 885 | real tape = VAL(Tape); |
---|
| 886 | real clin = VAL(Clino); |
---|
| 887 | real backclin = VAL(BackClino); |
---|
| 888 | |
---|
[a420b49] | 889 | real dx, dy, dz; |
---|
| 890 | real vx, vy, vz; |
---|
| 891 | #ifndef NO_COVARIANCES |
---|
[cb3d1e2] | 892 | real cxy, cyz, czx; |
---|
[a420b49] | 893 | #endif |
---|
[d1b1380] | 894 | |
---|
[90bb053f] | 895 | bool fNoComp; |
---|
[a420b49] | 896 | |
---|
[107b8bd] | 897 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 898 | if (tape < (real)0.0) { |
---|
| 899 | /* TRANSLATE different message for topofil? */ |
---|
| 900 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
[647407d] | 901 | } |
---|
[d1b1380] | 902 | |
---|
[21c226e] | 903 | fNoComp = handle_comp_units(); |
---|
[d1b1380] | 904 | |
---|
[fa42426] | 905 | if (ctype == CTYPE_READING) { |
---|
[93935c7] | 906 | bool range_0_180; |
---|
| 907 | real z; |
---|
[0b71cfc] | 908 | real diff_from_abs90; |
---|
[a420b49] | 909 | clin *= pcs->units[Q_GRADIENT]; |
---|
[fa42426] | 910 | /* percentage scale */ |
---|
| 911 | if (pcs->f_clino_percent) clin = atan(clin); |
---|
[93935c7] | 912 | /* We want to warn if there's a reading which it would be impossible |
---|
| 913 | * to have read from the instrument (e.g. on a -90 to 90 degree scale |
---|
| 914 | * you can't read "96" (it's probably a typo for "69"). However, the |
---|
| 915 | * gradient reading from a topofil is typically in the range 0 to 180, |
---|
| 916 | * with 90 being horizontal. |
---|
| 917 | * |
---|
| 918 | * Really we should allow the valid range to be specified, but for now |
---|
| 919 | * we infer it from the zero error - if this is within 45 degrees of |
---|
| 920 | * 90 then we assume the range is 0 to 180. |
---|
| 921 | */ |
---|
| 922 | z = pcs->z[Q_GRADIENT]; |
---|
| 923 | range_0_180 = (z > M_PI_4 && z < 3*M_PI_4); |
---|
[0b71cfc] | 924 | diff_from_abs90 = fabs(clin) - M_PI_2; |
---|
| 925 | if (diff_from_abs90 > EPSILON) { |
---|
[93935c7] | 926 | if (!range_0_180) |
---|
[736f7df] | 927 | /* TRANSLATORS: Degrees are the angular measurement where there are |
---|
| 928 | * 360 in a full circle. */ |
---|
[93935c7] | 929 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
[27b8b59] | 930 | } else if (TSTBIT(pcs->infer, INFER_PLUMBS) && |
---|
[be97baf] | 931 | diff_from_abs90 >= -EPSILON) { |
---|
| 932 | ctype = CTYPE_INFERPLUMB; |
---|
[a420b49] | 933 | } |
---|
[93935c7] | 934 | if (range_0_180 && ctype != CTYPE_INFERPLUMB) { |
---|
| 935 | /* FIXME: Warning message not ideal... */ |
---|
| 936 | if (clin < 0.0 || clin - M_PI > EPSILON) |
---|
| 937 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
| 938 | } |
---|
[a420b49] | 939 | } |
---|
[cb3d1e2] | 940 | |
---|
[fa42426] | 941 | if (backctype == CTYPE_READING) { |
---|
[b14f44f] | 942 | backclin *= pcs->units[Q_BACKGRADIENT]; |
---|
[fa42426] | 943 | /* percentage scale */ |
---|
| 944 | if (pcs->f_backclino_percent) backclin = atan(backclin); |
---|
[be97baf] | 945 | if (ctype != CTYPE_READING) { |
---|
| 946 | real diff_from_abs90 = fabs(backclin) - M_PI_2; |
---|
| 947 | if (diff_from_abs90 > EPSILON) { |
---|
| 948 | /* FIXME: different message for BackClino? */ |
---|
| 949 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
| 950 | } else if (TSTBIT(pcs->infer, INFER_PLUMBS) && |
---|
| 951 | diff_from_abs90 >= -EPSILON) { |
---|
| 952 | backctype = CTYPE_INFERPLUMB; |
---|
| 953 | } |
---|
[0b71cfc] | 954 | } |
---|
| 955 | } |
---|
| 956 | |
---|
[be97baf] | 957 | /* un-infer the plumb if the backsight was just a reading */ |
---|
| 958 | if (ctype == CTYPE_INFERPLUMB && backctype == CTYPE_READING) { |
---|
| 959 | ctype = CTYPE_READING; |
---|
| 960 | } |
---|
| 961 | |
---|
[fa42426] | 962 | if (ctype != CTYPE_OMIT && backctype != CTYPE_OMIT && ctype != backctype) { |
---|
[736f7df] | 963 | /* TRANSLATORS: In data with backsights, the user has tried to give a |
---|
| 964 | * plumb for the foresight and a clino reading for the backsight, or |
---|
| 965 | * something similar. */ |
---|
[ee7511a] | 966 | compile_error_skip(/*CLINO and BACKCLINO readings must be of the same type*/84); |
---|
[b14f44f] | 967 | return 0; |
---|
[0b71cfc] | 968 | } |
---|
| 969 | |
---|
[be97baf] | 970 | if (ctype == CTYPE_PLUMB || ctype == CTYPE_INFERPLUMB || |
---|
| 971 | backctype == CTYPE_PLUMB || backctype == CTYPE_INFERPLUMB) { |
---|
[a420b49] | 972 | /* plumbed */ |
---|
| 973 | if (!fNoComp) { |
---|
[be97baf] | 974 | if (ctype == CTYPE_PLUMB || |
---|
| 975 | (ctype == CTYPE_INFERPLUMB && VAL(Comp) != 0.0) || |
---|
| 976 | backctype == CTYPE_PLUMB || |
---|
| 977 | (backctype == CTYPE_INFERPLUMB && VAL(BackComp) != 0.0)) { |
---|
| 978 | /* FIXME: Different message for BackComp? */ |
---|
[736f7df] | 979 | /* TRANSLATORS: A "plumbed leg" is one measured using a plumbline |
---|
| 980 | * (a weight on a string). So the problem here is that the leg is |
---|
| 981 | * vertical, so a compass reading has no meaning! */ |
---|
[be97baf] | 982 | compile_warning(/*Compass reading given on plumbed leg*/21); |
---|
| 983 | } |
---|
[a420b49] | 984 | } |
---|
| 985 | |
---|
| 986 | dx = dy = (real)0.0; |
---|
[fa42426] | 987 | if (ctype != CTYPE_OMIT) { |
---|
| 988 | if (backctype != CTYPE_OMIT && (clin > 0) == (backclin > 0)) { |
---|
[b14f44f] | 989 | /* We've got two UPs or two DOWNs - FIXME: not ideal message */ |
---|
[ee7511a] | 990 | compile_error_skip(/*CLINO and BACKCLINO readings must be of the same type*/84); |
---|
[b14f44f] | 991 | return 0; |
---|
[0b71cfc] | 992 | } |
---|
| 993 | dz = (clin > (real)0.0) ? tape : -tape; |
---|
| 994 | } else { |
---|
| 995 | dz = (backclin < (real)0.0) ? tape : -tape; |
---|
| 996 | } |
---|
[a420b49] | 997 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
[21c226e] | 998 | vz = var(Q_POS) / 3.0 + VAR(Tape); |
---|
[4f8285d] | 999 | #ifndef NO_COVARIANCES |
---|
[26a805f] | 1000 | /* Correct values - no covariances in this case! */ |
---|
| 1001 | cxy = cyz = czx = (real)0.0; |
---|
[4f8285d] | 1002 | #endif |
---|
[a420b49] | 1003 | } else { |
---|
[fa42426] | 1004 | /* Each of ctype and backctype are either CTYPE_READING/CTYPE_HORIZ |
---|
| 1005 | * or CTYPE_OMIT */ |
---|
[a420b49] | 1006 | /* clino */ |
---|
| 1007 | real L2, cosG, LcosG, cosG2, sinB, cosB, dx2, dy2, dz2, v, V; |
---|
[421b7d2] | 1008 | if (fNoComp) { |
---|
[736f7df] | 1009 | /* TRANSLATORS: Here "legs" are survey legs, i.e. measurements between |
---|
| 1010 | * survey stations. */ |
---|
[fa42426] | 1011 | compile_error_skip(/*Compass reading may not be omitted except on plumbed legs*/14); |
---|
[a420b49] | 1012 | return 0; |
---|
| 1013 | } |
---|
| 1014 | if (tape == (real)0.0) { |
---|
| 1015 | dx = dy = dz = (real)0.0; |
---|
| 1016 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
[4f8285d] | 1017 | #ifndef NO_COVARIANCES |
---|
[a420b49] | 1018 | cxy = cyz = czx = (real)0.0; |
---|
[4f8285d] | 1019 | #endif |
---|
[d1b1380] | 1020 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1021 | printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
[d1b1380] | 1022 | #endif |
---|
[a420b49] | 1023 | } else { |
---|
[dbb4e19] | 1024 | real sinGcosG; |
---|
[0b71cfc] | 1025 | /* take into account variance in LEVEL case */ |
---|
| 1026 | real var_clin = var(Q_LEVEL); |
---|
[b6de07d] | 1027 | real var_comp; |
---|
[21c226e] | 1028 | real comp = handle_compass(&var_comp); |
---|
[fa42426] | 1029 | /* ctype != CTYPE_READING is LEVEL case */ |
---|
| 1030 | if (ctype == CTYPE_READING) { |
---|
[a420b49] | 1031 | clin = (clin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT]; |
---|
[21c226e] | 1032 | var_clin = VAR(Clino); |
---|
[0b71cfc] | 1033 | } |
---|
[fa42426] | 1034 | if (backctype == CTYPE_READING) { |
---|
[b14f44f] | 1035 | backclin = (backclin - pcs->z[Q_BACKGRADIENT]) |
---|
| 1036 | * pcs->sc[Q_BACKGRADIENT]; |
---|
[fa42426] | 1037 | if (ctype == CTYPE_READING) { |
---|
[be97baf] | 1038 | if (sqrd((clin + backclin) / 3.0) > var_clin + VAR(BackClino)) { |
---|
[b14f44f] | 1039 | /* fore and back readings differ by more than 3 sds */ |
---|
[736f7df] | 1040 | /* TRANSLATORS: Degrees are the angular measurement where |
---|
| 1041 | * there are 360 in a full circle. */ |
---|
[ee7511a] | 1042 | warn_readings_differ(/*CLINO reading and BACKCLINO reading disagree by %s degrees*/99, clin + backclin); |
---|
[b14f44f] | 1043 | } |
---|
[21c226e] | 1044 | clin = (clin / var_clin - backclin / VAR(BackClino)); |
---|
| 1045 | var_clin = (var_clin + VAR(BackClino)) / 4; |
---|
[b14f44f] | 1046 | clin *= var_clin; |
---|
[0b71cfc] | 1047 | } else { |
---|
| 1048 | clin = -backclin; |
---|
[21c226e] | 1049 | var_clin = VAR(BackClino); |
---|
[0b71cfc] | 1050 | } |
---|
| 1051 | } |
---|
[d1b1380] | 1052 | |
---|
| 1053 | #if DEBUG_DATAIN |
---|
[a420b49] | 1054 | printf(" %4.2f %4.2f %4.2f\n", tape, comp, clin); |
---|
[d1b1380] | 1055 | #endif |
---|
[a420b49] | 1056 | cosG = cos(clin); |
---|
| 1057 | LcosG = tape * cosG; |
---|
| 1058 | sinB = sin(comp); |
---|
| 1059 | cosB = cos(comp); |
---|
[d1b1380] | 1060 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1061 | printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB, cosG, LcosG); |
---|
[d1b1380] | 1062 | #endif |
---|
[a420b49] | 1063 | dx = LcosG * sinB; |
---|
| 1064 | dy = LcosG * cosB; |
---|
| 1065 | dz = tape * sin(clin); |
---|
[d1b1380] | 1066 | /* printf("%.2f\n",clin); */ |
---|
| 1067 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1068 | printf("dx = %f\ndy = %f\ndz = %f\n", dx, dy, dz); |
---|
[d1b1380] | 1069 | #endif |
---|
[a420b49] | 1070 | dx2 = dx * dx; |
---|
| 1071 | L2 = tape * tape; |
---|
[21c226e] | 1072 | V = VAR(Tape) / L2; |
---|
[a420b49] | 1073 | dy2 = dy * dy; |
---|
| 1074 | cosG2 = cosG * cosG; |
---|
[dbb4e19] | 1075 | sinGcosG = sin(clin) * cosG; |
---|
[a420b49] | 1076 | dz2 = dz * dz; |
---|
[0b71cfc] | 1077 | v = dz2 * var_clin; |
---|
[5b7c1b7] | 1078 | #ifdef NO_COVARIANCES |
---|
[0b71cfc] | 1079 | vx = (var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp + |
---|
[a420b49] | 1080 | (.5 + sinB * sinB * cosG2) * v); |
---|
[0b71cfc] | 1081 | vy = (var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp + |
---|
[a420b49] | 1082 | (.5 + cosB * cosB * cosG2) * v); |
---|
[fa42426] | 1083 | if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) { |
---|
[5b7c1b7] | 1084 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
[0b71cfc] | 1085 | vz = var(Q_POS) / 3.0 + L2 * (real)0.1; |
---|
[5b7c1b7] | 1086 | } else { |
---|
[0b71cfc] | 1087 | vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin; |
---|
[5b7c1b7] | 1088 | } |
---|
[a420b49] | 1089 | /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */ |
---|
[dbb4e19] | 1090 | #else |
---|
[0b71cfc] | 1091 | vx = var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp + |
---|
[dbb4e19] | 1092 | (sinB * sinB * v); |
---|
[0b71cfc] | 1093 | vy = var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp + |
---|
[dbb4e19] | 1094 | (cosB * cosB * v); |
---|
[fa42426] | 1095 | if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) { |
---|
[5b7c1b7] | 1096 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
[0b71cfc] | 1097 | vz = var(Q_POS) / 3.0 + L2 * (real)0.1; |
---|
[5b7c1b7] | 1098 | } else { |
---|
[0b71cfc] | 1099 | vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin; |
---|
[5b7c1b7] | 1100 | } |
---|
[647407d] | 1101 | /* usual covariance formulae are fine in no clino case since |
---|
[0b71cfc] | 1102 | * dz = 0 so value of var_clin is ignored */ |
---|
[21c226e] | 1103 | cxy = sinB * cosB * (VAR(Tape) * cosG2 + var_clin * dz2) |
---|
[0b71cfc] | 1104 | - var_comp * dx * dy; |
---|
[21c226e] | 1105 | czx = VAR(Tape) * sinB * sinGcosG - var_clin * dx * dz; |
---|
| 1106 | cyz = VAR(Tape) * cosB * sinGcosG - var_clin * dy * dz; |
---|
[dbb4e19] | 1107 | #if 0 |
---|
| 1108 | printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx, vy, vz); |
---|
| 1109 | printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy, cyz, czx); |
---|
| 1110 | #endif |
---|
[4f8285d] | 1111 | #endif |
---|
[d1b1380] | 1112 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1113 | printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
[d1b1380] | 1114 | #endif |
---|
[a420b49] | 1115 | } |
---|
| 1116 | } |
---|
[d1b1380] | 1117 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1118 | printf("Just before addleg, vx = %f\n", vx); |
---|
[d1b1380] | 1119 | #endif |
---|
[a420b49] | 1120 | /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/ |
---|
[90bb053f] | 1121 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
[4f8285d] | 1122 | #ifndef NO_COVARIANCES |
---|
[2140502] | 1123 | , cyz, czx, cxy |
---|
[4f8285d] | 1124 | #endif |
---|
[2140502] | 1125 | ); |
---|
[a420b49] | 1126 | return 1; |
---|
[d1b1380] | 1127 | } |
---|
| 1128 | |
---|
[5a38209] | 1129 | static int |
---|
[21c226e] | 1130 | process_diving(prefix *fr, prefix *to, bool fToFirst, bool fDepthChange) |
---|
[a420b49] | 1131 | { |
---|
[21c226e] | 1132 | real tape = VAL(Tape); |
---|
| 1133 | |
---|
[a420b49] | 1134 | real dx, dy, dz; |
---|
| 1135 | real vx, vy, vz; |
---|
[f795df0] | 1136 | #ifndef NO_COVARIANCES |
---|
| 1137 | real cxy = 0, cyz = 0, czx = 0; |
---|
| 1138 | #endif |
---|
[a420b49] | 1139 | |
---|
[21c226e] | 1140 | handle_comp_units(); |
---|
[a420b49] | 1141 | |
---|
[a6d094f] | 1142 | /* depth gauge readings increase upwards with default calibration */ |
---|
[6114207] | 1143 | if (fDepthChange) { |
---|
[21c226e] | 1144 | SVX_ASSERT(VAL(FrDepth) == 0.0); |
---|
| 1145 | dz = VAL(ToDepth) * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]; |
---|
| 1146 | dz *= pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 1147 | } else { |
---|
[21c226e] | 1148 | dz = VAL(ToDepth) - VAL(FrDepth); |
---|
| 1149 | dz *= pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 1150 | } |
---|
[a420b49] | 1151 | |
---|
| 1152 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 1153 | if (tape < (real)0.0) { |
---|
| 1154 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
| 1155 | } |
---|
| 1156 | |
---|
| 1157 | /* check if tape is less than depth change */ |
---|
| 1158 | if (tape < fabs(dz)) { |
---|
[bd1913f] | 1159 | /* FIXME: allow margin of error based on variances? */ |
---|
[736f7df] | 1160 | /* TRANSLATORS: This means that the data fed in said this. |
---|
| 1161 | * |
---|
| 1162 | * It could be a gross error (e.g. the decimal point is missing from the |
---|
| 1163 | * depth gauge reading) or it could just be due to random error on a near |
---|
| 1164 | * vertical leg */ |
---|
[a420b49] | 1165 | compile_warning(/*Tape reading is less than change in depth*/62); |
---|
| 1166 | } |
---|
| 1167 | |
---|
[0a208f9] | 1168 | if (tape == (real)0.0 && dz == 0.0) { |
---|
[a420b49] | 1169 | dx = dy = dz = (real)0.0; |
---|
| 1170 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
[21c226e] | 1171 | } else if (VAL(Comp) == HUGE_REAL && |
---|
| 1172 | VAL(BackComp) == HUGE_REAL) { |
---|
[385b703] | 1173 | /* plumb */ |
---|
| 1174 | dx = dy = (real)0.0; |
---|
| 1175 | if (dz < 0) tape = -tape; |
---|
[21c226e] | 1176 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1177 | dz = (dz * VAR(Tape) + tape * 2 * VAR(ToDepth)) |
---|
| 1178 | / (VAR(Tape) * 2 * VAR(ToDepth)); |
---|
[385b703] | 1179 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
[21c226e] | 1180 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1181 | vz = var(Q_POS) / 3.0 + VAR(Tape) * 2 * VAR(ToDepth) |
---|
| 1182 | / (VAR(Tape) + VAR(ToDepth)); |
---|
[a420b49] | 1183 | } else { |
---|
[f795df0] | 1184 | real L2, sinB, cosB, dz2, D2; |
---|
[b6de07d] | 1185 | real var_comp; |
---|
[21c226e] | 1186 | real comp = handle_compass(&var_comp); |
---|
[a420b49] | 1187 | sinB = sin(comp); |
---|
| 1188 | cosB = cos(comp); |
---|
| 1189 | L2 = tape * tape; |
---|
| 1190 | dz2 = dz * dz; |
---|
| 1191 | D2 = L2 - dz2; |
---|
| 1192 | if (D2 <= (real)0.0) { |
---|
[21c226e] | 1193 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1194 | real vsum = VAR(Tape) + 2 * VAR(ToDepth); |
---|
[a420b49] | 1195 | dx = dy = (real)0.0; |
---|
[f795df0] | 1196 | vx = vy = var(Q_POS) / 3.0; |
---|
[21c226e] | 1197 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1198 | vz = var(Q_POS) / 3.0 + VAR(Tape) * 2 * VAR(ToDepth) / vsum; |
---|
[f795df0] | 1199 | if (dz > 0) { |
---|
[21c226e] | 1200 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1201 | dz = (dz * VAR(Tape) + tape * 2 * VAR(ToDepth)) / vsum; |
---|
[f795df0] | 1202 | } else { |
---|
[21c226e] | 1203 | dz = (dz * VAR(Tape) - tape * 2 * VAR(ToDepth)) / vsum; |
---|
[f795df0] | 1204 | } |
---|
[a420b49] | 1205 | } else { |
---|
| 1206 | real D = sqrt(D2); |
---|
[21c226e] | 1207 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1208 | real F = VAR(Tape) * L2 + 2 * VAR(ToDepth) * D2; |
---|
[a420b49] | 1209 | dx = D * sinB; |
---|
| 1210 | dy = D * cosB; |
---|
[f795df0] | 1211 | |
---|
| 1212 | vx = var(Q_POS) / 3.0 + |
---|
[72095d3] | 1213 | sinB * sinB * F / D2 + var_comp * dy * dy; |
---|
[f795df0] | 1214 | vy = var(Q_POS) / 3.0 + |
---|
[72095d3] | 1215 | cosB * cosB * F / D2 + var_comp * dx * dx; |
---|
[21c226e] | 1216 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1217 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
[f795df0] | 1218 | |
---|
| 1219 | #ifndef NO_COVARIANCES |
---|
[72095d3] | 1220 | cxy = sinB * cosB * (F / D2 + var_comp * D2); |
---|
[21c226e] | 1221 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1222 | cyz = -2 * VAR(ToDepth) * dy / D; |
---|
| 1223 | czx = -2 * VAR(ToDepth) * dx / D; |
---|
[f795df0] | 1224 | #endif |
---|
[a420b49] | 1225 | } |
---|
| 1226 | } |
---|
[5a38209] | 1227 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
[2140502] | 1228 | #ifndef NO_COVARIANCES |
---|
[f795df0] | 1229 | , cxy, cyz, czx |
---|
[647407d] | 1230 | #endif |
---|
[2140502] | 1231 | ); |
---|
[647407d] | 1232 | return 1; |
---|
| 1233 | } |
---|
| 1234 | |
---|
[5a38209] | 1235 | static int |
---|
[21c226e] | 1236 | process_cartesian(prefix *fr, prefix *to, bool fToFirst) |
---|
[5a38209] | 1237 | { |
---|
[21c226e] | 1238 | real dx = (VAL(Dx) * pcs->units[Q_DX] - pcs->z[Q_DX]) * pcs->sc[Q_DX]; |
---|
| 1239 | real dy = (VAL(Dy) * pcs->units[Q_DY] - pcs->z[Q_DY]) * pcs->sc[Q_DY]; |
---|
| 1240 | real dz = (VAL(Dz) * pcs->units[Q_DZ] - pcs->z[Q_DZ]) * pcs->sc[Q_DZ]; |
---|
[647407d] | 1241 | |
---|
[21c226e] | 1242 | addlegbyname(fr, to, fToFirst, dx, dy, dz, VAR(Dx), VAR(Dy), VAR(Dz) |
---|
[647407d] | 1243 | #ifndef NO_COVARIANCES |
---|
[c80bd34] | 1244 | , 0, 0, 0 |
---|
[647407d] | 1245 | #endif |
---|
[2140502] | 1246 | ); |
---|
[647407d] | 1247 | return 1; |
---|
| 1248 | } |
---|
| 1249 | |
---|
[e2d48d8] | 1250 | static void |
---|
[5a38209] | 1251 | data_cartesian(void) |
---|
[647407d] | 1252 | { |
---|
[90bb053f] | 1253 | prefix *fr = NULL, *to = NULL; |
---|
[5a38209] | 1254 | |
---|
| 1255 | bool fMulti = fFalse; |
---|
[647407d] | 1256 | |
---|
[0395657] | 1257 | reading first_stn = End; |
---|
| 1258 | |
---|
| 1259 | reading *ordering; |
---|
[647407d] | 1260 | |
---|
[5a38209] | 1261 | again: |
---|
| 1262 | |
---|
[647407d] | 1263 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
| 1264 | skipblanks(); |
---|
| 1265 | switch (*ordering) { |
---|
[4a6a094] | 1266 | case Fr: |
---|
[c458cf7] | 1267 | fr = read_prefix(PFX_STATION|PFX_ALLOW_ROOT); |
---|
[21c226e] | 1268 | if (first_stn == End) first_stn = Fr; |
---|
| 1269 | break; |
---|
[4a6a094] | 1270 | case To: |
---|
[c458cf7] | 1271 | to = read_prefix(PFX_STATION|PFX_ALLOW_ROOT); |
---|
[21c226e] | 1272 | if (first_stn == End) first_stn = To; |
---|
| 1273 | break; |
---|
[5a38209] | 1274 | case Station: |
---|
[21c226e] | 1275 | fr = to; |
---|
[c458cf7] | 1276 | to = read_prefix(PFX_STATION); |
---|
[21c226e] | 1277 | first_stn = To; |
---|
| 1278 | break; |
---|
| 1279 | case Dx: case Dy: case Dz: |
---|
| 1280 | read_reading(*ordering, fFalse); |
---|
| 1281 | break; |
---|
[647407d] | 1282 | case Ignore: |
---|
| 1283 | skipword(); break; |
---|
[5a38209] | 1284 | case IgnoreAllAndNewLine: |
---|
| 1285 | skipline(); |
---|
| 1286 | /* fall through */ |
---|
| 1287 | case Newline: |
---|
| 1288 | if (fr != NULL) { |
---|
[e2d48d8] | 1289 | if (!process_cartesian(fr, to, first_stn == To)) |
---|
| 1290 | skipline(); |
---|
[5a38209] | 1291 | } |
---|
| 1292 | fMulti = fTrue; |
---|
| 1293 | while (1) { |
---|
| 1294 | process_eol(); |
---|
| 1295 | process_bol(); |
---|
| 1296 | if (isData(ch)) break; |
---|
[ee6a621] | 1297 | if (!isComm(ch)) { |
---|
[993454b] | 1298 | push_back(ch); |
---|
[e2d48d8] | 1299 | return; |
---|
[ee6a621] | 1300 | } |
---|
[5a38209] | 1301 | } |
---|
| 1302 | break; |
---|
[647407d] | 1303 | case IgnoreAll: |
---|
| 1304 | skipline(); |
---|
| 1305 | /* fall through */ |
---|
| 1306 | case End: |
---|
[5a38209] | 1307 | if (!fMulti) { |
---|
[e2d48d8] | 1308 | process_cartesian(fr, to, first_stn == To); |
---|
[5a38209] | 1309 | process_eol(); |
---|
[e2d48d8] | 1310 | return; |
---|
[5a38209] | 1311 | } |
---|
[eef4d8c] | 1312 | do { |
---|
[5a38209] | 1313 | process_eol(); |
---|
| 1314 | process_bol(); |
---|
[eef4d8c] | 1315 | } while (isComm(ch)); |
---|
[5a38209] | 1316 | goto again; |
---|
[0395657] | 1317 | default: BUG("Unknown reading in ordering"); |
---|
[647407d] | 1318 | } |
---|
| 1319 | } |
---|
[5a38209] | 1320 | } |
---|
[cb3d1e2] | 1321 | |
---|
[98a2eec] | 1322 | static int |
---|
[21c226e] | 1323 | process_cylpolar(prefix *fr, prefix *to, bool fToFirst, bool fDepthChange) |
---|
[98a2eec] | 1324 | { |
---|
[21c226e] | 1325 | real tape = VAL(Tape); |
---|
| 1326 | |
---|
[98a2eec] | 1327 | real dx, dy, dz; |
---|
| 1328 | real vx, vy, vz; |
---|
| 1329 | #ifndef NO_COVARIANCES |
---|
| 1330 | real cxy = 0; |
---|
| 1331 | #endif |
---|
| 1332 | |
---|
[21c226e] | 1333 | handle_comp_units(); |
---|
[98a2eec] | 1334 | |
---|
[a6d094f] | 1335 | /* depth gauge readings increase upwards with default calibration */ |
---|
[6114207] | 1336 | if (fDepthChange) { |
---|
[21c226e] | 1337 | SVX_ASSERT(VAL(FrDepth) == 0.0); |
---|
| 1338 | dz = VAL(ToDepth) * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]; |
---|
| 1339 | dz *= pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 1340 | } else { |
---|
[21c226e] | 1341 | dz = VAL(ToDepth) - VAL(FrDepth); |
---|
| 1342 | dz *= pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 1343 | } |
---|
[98a2eec] | 1344 | |
---|
| 1345 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 1346 | if (tape < (real)0.0) { |
---|
| 1347 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
| 1348 | } |
---|
| 1349 | |
---|
[21c226e] | 1350 | if (VAL(Comp) == HUGE_REAL && VAL(BackComp) == HUGE_REAL) { |
---|
[98a2eec] | 1351 | /* plumb */ |
---|
| 1352 | dx = dy = (real)0.0; |
---|
| 1353 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
[21c226e] | 1354 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1355 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
[98a2eec] | 1356 | } else { |
---|
| 1357 | real sinB, cosB; |
---|
[b6de07d] | 1358 | real var_comp; |
---|
[21c226e] | 1359 | real comp = handle_compass(&var_comp); |
---|
[98a2eec] | 1360 | sinB = sin(comp); |
---|
| 1361 | cosB = cos(comp); |
---|
| 1362 | |
---|
| 1363 | dx = tape * sinB; |
---|
| 1364 | dy = tape * cosB; |
---|
| 1365 | |
---|
| 1366 | vx = var(Q_POS) / 3.0 + |
---|
[21c226e] | 1367 | VAR(Tape) * sinB * sinB + var_comp * dy * dy; |
---|
[98a2eec] | 1368 | vy = var(Q_POS) / 3.0 + |
---|
[21c226e] | 1369 | VAR(Tape) * cosB * cosB + var_comp * dx * dx; |
---|
| 1370 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1371 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
[98a2eec] | 1372 | |
---|
| 1373 | #ifndef NO_COVARIANCES |
---|
[21c226e] | 1374 | cxy = (VAR(Tape) - var_comp * tape * tape) * sinB * cosB; |
---|
[98a2eec] | 1375 | #endif |
---|
| 1376 | } |
---|
| 1377 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
| 1378 | #ifndef NO_COVARIANCES |
---|
| 1379 | , cxy, 0, 0 |
---|
| 1380 | #endif |
---|
| 1381 | ); |
---|
| 1382 | return 1; |
---|
| 1383 | } |
---|
| 1384 | |
---|
[107b8bd] | 1385 | /* Process tape/compass/clino, diving, and cylpolar styles of survey data |
---|
| 1386 | * Also handles topofil (fromcount/tocount or count) in place of tape */ |
---|
[e2d48d8] | 1387 | static void |
---|
[107b8bd] | 1388 | data_normal(void) |
---|
[54c4612] | 1389 | { |
---|
| 1390 | prefix *fr = NULL, *to = NULL; |
---|
[107b8bd] | 1391 | reading first_stn = End; |
---|
[54c4612] | 1392 | |
---|
[107b8bd] | 1393 | bool fTopofil = fFalse, fMulti = fFalse; |
---|
| 1394 | bool fRev; |
---|
[e217d67] | 1395 | clino_type ctype, backctype; |
---|
[107b8bd] | 1396 | bool fDepthChange; |
---|
[be97baf] | 1397 | unsigned long compass_dat_flags = 0; |
---|
[54c4612] | 1398 | |
---|
| 1399 | reading *ordering; |
---|
| 1400 | |
---|
[21c226e] | 1401 | VAL(Tape) = 0; |
---|
[07442af] | 1402 | VAL(Comp) = VAL(BackComp) = HUGE_REAL; |
---|
[21c226e] | 1403 | VAL(FrCount) = VAL(ToCount) = 0; |
---|
| 1404 | VAL(FrDepth) = VAL(ToDepth) = 0; |
---|
[07442af] | 1405 | VAL(Left) = VAL(Right) = VAL(Up) = VAL(Down) = HUGE_REAL; |
---|
[54c4612] | 1406 | |
---|
| 1407 | fRev = fFalse; |
---|
[fa42426] | 1408 | ctype = backctype = CTYPE_OMIT; |
---|
[6114207] | 1409 | fDepthChange = fFalse; |
---|
[54c4612] | 1410 | |
---|
[107b8bd] | 1411 | /* ordering may omit clino reading, so set up default here */ |
---|
| 1412 | /* this is also used if clino reading is the omit character */ |
---|
[21c226e] | 1413 | VAL(Clino) = VAL(BackClino) = 0; |
---|
| 1414 | |
---|
| 1415 | again: |
---|
[107b8bd] | 1416 | |
---|
[dcbcae0] | 1417 | /* We clear these flags in the normal course of events, but if there's an |
---|
| 1418 | * error in a reading, we might not, so make sure it has been cleared here. |
---|
[710ecc1] | 1419 | */ |
---|
[dcbcae0] | 1420 | pcs->flags &= ~(BIT(FLAGS_ANON_ONE_END) | BIT(FLAGS_IMPLICIT_SPLAY)); |
---|
[54c4612] | 1421 | for (ordering = pcs->ordering; ; ordering++) { |
---|
| 1422 | skipblanks(); |
---|
| 1423 | switch (*ordering) { |
---|
| 1424 | case Fr: |
---|
[710ecc1] | 1425 | fr = read_prefix(PFX_STATION|PFX_ALLOW_ROOT|PFX_ANON); |
---|
[107b8bd] | 1426 | if (first_stn == End) first_stn = Fr; |
---|
| 1427 | break; |
---|
[54c4612] | 1428 | case To: |
---|
[710ecc1] | 1429 | to = read_prefix(PFX_STATION|PFX_ALLOW_ROOT|PFX_ANON); |
---|
[107b8bd] | 1430 | if (first_stn == End) first_stn = To; |
---|
| 1431 | break; |
---|
[54c4612] | 1432 | case Station: |
---|
[107b8bd] | 1433 | fr = to; |
---|
[c458cf7] | 1434 | to = read_prefix(PFX_STATION); |
---|
[107b8bd] | 1435 | first_stn = To; |
---|
| 1436 | break; |
---|
[ee1ec59] | 1437 | case Dir: { |
---|
| 1438 | typedef enum { |
---|
| 1439 | DIR_NULL=-1, DIR_FORE, DIR_BACK |
---|
| 1440 | } dir_tok; |
---|
| 1441 | static sztok dir_tab[] = { |
---|
| 1442 | {"B", DIR_BACK}, |
---|
| 1443 | {"F", DIR_FORE}, |
---|
| 1444 | }; |
---|
| 1445 | dir_tok tok; |
---|
| 1446 | get_token(); |
---|
| 1447 | tok = match_tok(dir_tab, TABSIZE(dir_tab)); |
---|
| 1448 | switch (tok) { |
---|
| 1449 | case DIR_FORE: |
---|
[54c4612] | 1450 | break; |
---|
[ee1ec59] | 1451 | case DIR_BACK: |
---|
[54c4612] | 1452 | fRev = fTrue; |
---|
| 1453 | break; |
---|
| 1454 | default: |
---|
[da96015] | 1455 | file.lpos += strlen(buffer); |
---|
| 1456 | compile_error_skip(-/*Found “%s”, expecting “F” or “B”*/131, |
---|
[44bb30d] | 1457 | buffer); |
---|
[54c4612] | 1458 | process_eol(); |
---|
[e2d48d8] | 1459 | return; |
---|
[54c4612] | 1460 | } |
---|
| 1461 | break; |
---|
[ee1ec59] | 1462 | } |
---|
[107b8bd] | 1463 | case Tape: |
---|
[21c226e] | 1464 | read_reading(Tape, fFalse); |
---|
| 1465 | if (VAL(Tape) < (real)0.0) |
---|
[da96015] | 1466 | compile_warning(-/*Negative tape reading*/60); |
---|
[107b8bd] | 1467 | break; |
---|
| 1468 | case Count: |
---|
[21c226e] | 1469 | VAL(FrCount) = VAL(ToCount); |
---|
| 1470 | read_reading(ToCount, fFalse); |
---|
[b4fe9fb] | 1471 | fTopofil = fTrue; |
---|
[107b8bd] | 1472 | break; |
---|
| 1473 | case FrCount: |
---|
[21c226e] | 1474 | read_reading(FrCount, fFalse); |
---|
[107b8bd] | 1475 | break; |
---|
| 1476 | case ToCount: |
---|
[21c226e] | 1477 | read_reading(ToCount, fFalse); |
---|
[107b8bd] | 1478 | fTopofil = fTrue; |
---|
| 1479 | break; |
---|
[07442af] | 1480 | case Comp: case BackComp: |
---|
| 1481 | read_bearing_or_omit(*ordering); |
---|
[5b7c1b7] | 1482 | break; |
---|
[0a158bc] | 1483 | case Clino: case BackClino: { |
---|
| 1484 | reading r = *ordering; |
---|
| 1485 | clino_type * p_ctype = (r == Clino ? &ctype : &backctype); |
---|
| 1486 | read_reading(r, fTrue); |
---|
| 1487 | if (VAL(r) == HUGE_REAL) { |
---|
| 1488 | VAL(r) = handle_plumb(p_ctype); |
---|
| 1489 | if (VAL(r) != HUGE_REAL) break; |
---|
[da96015] | 1490 | compile_error_token(-/*Expecting numeric field, found “%s”*/9); |
---|
[4bc4d58] | 1491 | skipline(); |
---|
[107b8bd] | 1492 | process_eol(); |
---|
[e2d48d8] | 1493 | return; |
---|
[107b8bd] | 1494 | } |
---|
[0a158bc] | 1495 | *p_ctype = CTYPE_READING; |
---|
[107b8bd] | 1496 | break; |
---|
[0a158bc] | 1497 | } |
---|
[07442af] | 1498 | case FrDepth: case ToDepth: |
---|
| 1499 | read_reading(*ordering, fFalse); |
---|
[107b8bd] | 1500 | break; |
---|
[54c4612] | 1501 | case Depth: |
---|
[21c226e] | 1502 | VAL(FrDepth) = VAL(ToDepth); |
---|
| 1503 | read_reading(ToDepth, fFalse); |
---|
[54c4612] | 1504 | break; |
---|
[6114207] | 1505 | case DepthChange: |
---|
| 1506 | fDepthChange = fTrue; |
---|
[21c226e] | 1507 | VAL(FrDepth) = 0; |
---|
| 1508 | read_reading(ToDepth, fFalse); |
---|
[a186573] | 1509 | break; |
---|
[44bb30d] | 1510 | case CompassDATComp: |
---|
| 1511 | read_bearing_or_omit(Comp); |
---|
| 1512 | if (is_compass_NaN(VAL(Comp))) VAL(Comp) = HUGE_REAL; |
---|
| 1513 | break; |
---|
| 1514 | case CompassDATBackComp: |
---|
| 1515 | read_bearing_or_omit(BackComp); |
---|
| 1516 | if (is_compass_NaN(VAL(BackComp))) VAL(BackComp) = HUGE_REAL; |
---|
| 1517 | break; |
---|
[0a158bc] | 1518 | case CompassDATClino: case CompassDATBackClino: { |
---|
| 1519 | reading r; |
---|
| 1520 | clino_type * p_ctype; |
---|
| 1521 | if (*ordering == CompassDATClino) { |
---|
| 1522 | r = Clino; |
---|
| 1523 | p_ctype = &ctype; |
---|
[07442af] | 1524 | } else { |
---|
[0a158bc] | 1525 | r = BackClino; |
---|
| 1526 | p_ctype = &backctype; |
---|
[07442af] | 1527 | } |
---|
[0a158bc] | 1528 | read_reading(r, fFalse); |
---|
| 1529 | if (is_compass_NaN(VAL(r))) { |
---|
| 1530 | VAL(r) = HUGE_REAL; |
---|
| 1531 | *p_ctype = CTYPE_OMIT; |
---|
[07442af] | 1532 | } else { |
---|
[0a158bc] | 1533 | *p_ctype = CTYPE_READING; |
---|
[07442af] | 1534 | } |
---|
| 1535 | break; |
---|
[0a158bc] | 1536 | } |
---|
[07442af] | 1537 | case CompassDATLeft: case CompassDATRight: |
---|
| 1538 | case CompassDATUp: case CompassDATDown: { |
---|
[ee05463] | 1539 | /* FIXME: need to actually make use of these entries! */ |
---|
[07442af] | 1540 | reading actual = Left + (*ordering - CompassDATLeft); |
---|
| 1541 | read_reading(actual, fFalse); |
---|
| 1542 | if (VAL(actual) < 0) VAL(actual) = HUGE_REAL; |
---|
[44bb30d] | 1543 | break; |
---|
[07442af] | 1544 | } |
---|
[be97baf] | 1545 | case CompassDATFlags: |
---|
| 1546 | if (ch == '#') { |
---|
| 1547 | nextch(); |
---|
| 1548 | if (ch == '|') { |
---|
| 1549 | filepos fp; |
---|
| 1550 | get_pos(&fp); |
---|
| 1551 | nextch(); |
---|
| 1552 | while (ch >= 'A' && ch <= 'Z') { |
---|
| 1553 | compass_dat_flags |= BIT(ch - 'A'); |
---|
[850fdc4] | 1554 | /* FIXME: we currently understand: |
---|
| 1555 | * L (exclude from length) |
---|
| 1556 | * X (exclude data) |
---|
[0580c6a] | 1557 | * but should also handle at least some of: |
---|
[850fdc4] | 1558 | * C (no adjustment) |
---|
| 1559 | * P (no plot) |
---|
[0580c6a] | 1560 | */ |
---|
[be97baf] | 1561 | nextch(); |
---|
| 1562 | } |
---|
| 1563 | if (ch == '#') { |
---|
| 1564 | nextch(); |
---|
| 1565 | } else { |
---|
| 1566 | compass_dat_flags = 0; |
---|
| 1567 | set_pos(&fp); |
---|
| 1568 | push_back('|'); |
---|
| 1569 | ch = '#'; |
---|
| 1570 | } |
---|
| 1571 | } else { |
---|
| 1572 | push_back(ch); |
---|
| 1573 | ch = '#'; |
---|
| 1574 | } |
---|
| 1575 | } |
---|
[107b8bd] | 1576 | break; |
---|
[be97baf] | 1577 | case Ignore: |
---|
| 1578 | skipword(); break; |
---|
[54c4612] | 1579 | case IgnoreAllAndNewLine: |
---|
[107b8bd] | 1580 | skipline(); |
---|
| 1581 | /* fall through */ |
---|
[54c4612] | 1582 | case Newline: |
---|
[107b8bd] | 1583 | if (fr != NULL) { |
---|
| 1584 | int r; |
---|
[710ecc1] | 1585 | int save_flags; |
---|
[dcbcae0] | 1586 | int implicit_splay; |
---|
[21c226e] | 1587 | if (fTopofil) |
---|
| 1588 | VAL(Tape) = VAL(ToCount) - VAL(FrCount); |
---|
[107b8bd] | 1589 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
| 1590 | * (frdepth always zero, todepth is change of depth) and also |
---|
| 1591 | * works for STYLE_NORMAL (both remain 0) */ |
---|
[44bb30d] | 1592 | if (TSTBIT(pcs->infer, INFER_EQUATES) && |
---|
[27b8b59] | 1593 | VAL(Tape) == (real)0.0 && VAL(FrDepth) == VAL(ToDepth)) { |
---|
[107b8bd] | 1594 | process_equate(fr, to); |
---|
| 1595 | goto inferred_equate; |
---|
| 1596 | } |
---|
[e7576f6] | 1597 | if (fRev) { |
---|
| 1598 | prefix *t = fr; |
---|
[44bb30d] | 1599 | fr = to; |
---|
| 1600 | to = t; |
---|
[e7576f6] | 1601 | } |
---|
[107b8bd] | 1602 | if (fTopofil) { |
---|
[21c226e] | 1603 | VAL(Tape) *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
[107b8bd] | 1604 | } else { |
---|
[21c226e] | 1605 | VAL(Tape) *= pcs->units[Q_LENGTH]; |
---|
| 1606 | VAL(Tape) -= pcs->z[Q_LENGTH]; |
---|
| 1607 | VAL(Tape) *= pcs->sc[Q_LENGTH]; |
---|
[107b8bd] | 1608 | } |
---|
[dcbcae0] | 1609 | implicit_splay = TSTBIT(pcs->flags, FLAGS_IMPLICIT_SPLAY); |
---|
| 1610 | pcs->flags &= ~(BIT(FLAGS_ANON_ONE_END) | BIT(FLAGS_IMPLICIT_SPLAY)); |
---|
| 1611 | save_flags = pcs->flags; |
---|
| 1612 | if (implicit_splay) { |
---|
[710ecc1] | 1613 | pcs->flags |= BIT(FLAGS_SPLAY); |
---|
| 1614 | } |
---|
[107b8bd] | 1615 | switch (pcs->style) { |
---|
| 1616 | case STYLE_NORMAL: |
---|
[21c226e] | 1617 | r = process_normal(fr, to, (first_stn == To) ^ fRev, |
---|
| 1618 | ctype, backctype); |
---|
[107b8bd] | 1619 | break; |
---|
| 1620 | case STYLE_DIVING: |
---|
[21c226e] | 1621 | r = process_diving(fr, to, (first_stn == To) ^ fRev, |
---|
| 1622 | fDepthChange); |
---|
[107b8bd] | 1623 | break; |
---|
| 1624 | case STYLE_CYLPOLAR: |
---|
[21c226e] | 1625 | r = process_cylpolar(fr, to, (first_stn == To) ^ fRev, |
---|
| 1626 | fDepthChange); |
---|
[107b8bd] | 1627 | break; |
---|
| 1628 | default: |
---|
[74a0681] | 1629 | r = 0; /* avoid warning */ |
---|
[107b8bd] | 1630 | BUG("bad style"); |
---|
| 1631 | } |
---|
[710ecc1] | 1632 | pcs->flags = save_flags; |
---|
[107b8bd] | 1633 | if (!r) skipline(); |
---|
[44bb30d] | 1634 | |
---|
[e7576f6] | 1635 | /* Swap fr and to back to how they were for next line */ |
---|
| 1636 | if (fRev) { |
---|
| 1637 | prefix *t = fr; |
---|
| 1638 | fr = to; |
---|
| 1639 | to = t; |
---|
| 1640 | } |
---|
[107b8bd] | 1641 | } |
---|
[21c226e] | 1642 | |
---|
| 1643 | fRev = fFalse; |
---|
| 1644 | ctype = backctype = CTYPE_OMIT; |
---|
| 1645 | fDepthChange = fFalse; |
---|
| 1646 | |
---|
| 1647 | /* ordering may omit clino reading, so set up default here */ |
---|
| 1648 | /* this is also used if clino reading is the omit character */ |
---|
| 1649 | VAL(Clino) = VAL(BackClino) = 0; |
---|
| 1650 | |
---|
[44bb30d] | 1651 | inferred_equate: |
---|
[e7576f6] | 1652 | |
---|
[107b8bd] | 1653 | fMulti = fTrue; |
---|
| 1654 | while (1) { |
---|
| 1655 | process_eol(); |
---|
| 1656 | process_bol(); |
---|
| 1657 | if (isData(ch)) break; |
---|
| 1658 | if (!isComm(ch)) { |
---|
| 1659 | push_back(ch); |
---|
[e2d48d8] | 1660 | return; |
---|
[107b8bd] | 1661 | } |
---|
| 1662 | } |
---|
| 1663 | break; |
---|
[54c4612] | 1664 | case IgnoreAll: |
---|
[107b8bd] | 1665 | skipline(); |
---|
| 1666 | /* fall through */ |
---|
[54c4612] | 1667 | case End: |
---|
[107b8bd] | 1668 | if (!fMulti) { |
---|
[710ecc1] | 1669 | int save_flags; |
---|
[dcbcae0] | 1670 | int implicit_splay; |
---|
[be97baf] | 1671 | /* Compass ignore flag is 'X' */ |
---|
| 1672 | if ((compass_dat_flags & BIT('X' - 'A'))) { |
---|
| 1673 | process_eol(); |
---|
[e2d48d8] | 1674 | return; |
---|
[be97baf] | 1675 | } |
---|
[107b8bd] | 1676 | if (fRev) { |
---|
| 1677 | prefix *t = fr; |
---|
| 1678 | fr = to; |
---|
| 1679 | to = t; |
---|
| 1680 | } |
---|
[21c226e] | 1681 | if (fTopofil) VAL(Tape) = VAL(ToCount) - VAL(FrCount); |
---|
[107b8bd] | 1682 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
| 1683 | * (frdepth always zero, todepth is change of depth) and also |
---|
| 1684 | * works for STYLE_NORMAL (both remain 0) */ |
---|
[07442af] | 1685 | if (TSTBIT(pcs->infer, INFER_EQUATES) && |
---|
[27b8b59] | 1686 | VAL(Tape) == (real)0.0 && VAL(FrDepth) == VAL(ToDepth)) { |
---|
[107b8bd] | 1687 | process_equate(fr, to); |
---|
| 1688 | process_eol(); |
---|
[e2d48d8] | 1689 | return; |
---|
[107b8bd] | 1690 | } |
---|
| 1691 | if (fTopofil) { |
---|
[21c226e] | 1692 | VAL(Tape) *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
[107b8bd] | 1693 | } else { |
---|
[21c226e] | 1694 | VAL(Tape) *= pcs->units[Q_LENGTH]; |
---|
| 1695 | VAL(Tape) -= pcs->z[Q_LENGTH]; |
---|
| 1696 | VAL(Tape) *= pcs->sc[Q_LENGTH]; |
---|
[107b8bd] | 1697 | } |
---|
[dcbcae0] | 1698 | implicit_splay = TSTBIT(pcs->flags, FLAGS_IMPLICIT_SPLAY); |
---|
| 1699 | pcs->flags &= ~(BIT(FLAGS_ANON_ONE_END) | BIT(FLAGS_IMPLICIT_SPLAY)); |
---|
[710ecc1] | 1700 | save_flags = pcs->flags; |
---|
[dcbcae0] | 1701 | if (implicit_splay) { |
---|
[710ecc1] | 1702 | pcs->flags |= BIT(FLAGS_SPLAY); |
---|
| 1703 | } |
---|
[850fdc4] | 1704 | if ((compass_dat_flags & BIT('L' - 'A'))) { |
---|
| 1705 | /* 'L' means "exclude from length" - map this to Survex's |
---|
| 1706 | * FLAGS_DUPLICATE. */ |
---|
| 1707 | pcs->flags |= BIT(FLAGS_DUPLICATE); |
---|
| 1708 | } |
---|
[107b8bd] | 1709 | switch (pcs->style) { |
---|
| 1710 | case STYLE_NORMAL: |
---|
[e2d48d8] | 1711 | process_normal(fr, to, (first_stn == To) ^ fRev, |
---|
| 1712 | ctype, backctype); |
---|
[107b8bd] | 1713 | break; |
---|
| 1714 | case STYLE_DIVING: |
---|
[e2d48d8] | 1715 | process_diving(fr, to, (first_stn == To) ^ fRev, |
---|
| 1716 | fDepthChange); |
---|
[107b8bd] | 1717 | break; |
---|
| 1718 | case STYLE_CYLPOLAR: |
---|
[e2d48d8] | 1719 | process_cylpolar(fr, to, (first_stn == To) ^ fRev, |
---|
| 1720 | fDepthChange); |
---|
[107b8bd] | 1721 | break; |
---|
| 1722 | default: |
---|
| 1723 | BUG("bad style"); |
---|
| 1724 | } |
---|
[710ecc1] | 1725 | pcs->flags = save_flags; |
---|
[ee05463] | 1726 | |
---|
[107b8bd] | 1727 | process_eol(); |
---|
[e2d48d8] | 1728 | return; |
---|
[107b8bd] | 1729 | } |
---|
| 1730 | do { |
---|
| 1731 | process_eol(); |
---|
| 1732 | process_bol(); |
---|
| 1733 | } while (isComm(ch)); |
---|
| 1734 | goto again; |
---|
| 1735 | default: |
---|
| 1736 | BUG("Unknown reading in ordering"); |
---|
[54c4612] | 1737 | } |
---|
| 1738 | } |
---|
| 1739 | } |
---|
| 1740 | |
---|
[ee05463] | 1741 | static int |
---|
| 1742 | process_lrud(prefix *stn) |
---|
| 1743 | { |
---|
| 1744 | SVX_ASSERT(next_lrud); |
---|
| 1745 | lrud * xsect = osnew(lrud); |
---|
| 1746 | xsect->stn = stn; |
---|
| 1747 | xsect->l = (VAL(Left) * pcs->units[Q_LEFT] - pcs->z[Q_LEFT]) * pcs->sc[Q_LEFT]; |
---|
| 1748 | xsect->r = (VAL(Right) * pcs->units[Q_RIGHT] - pcs->z[Q_RIGHT]) * pcs->sc[Q_RIGHT]; |
---|
| 1749 | xsect->u = (VAL(Up) * pcs->units[Q_UP] - pcs->z[Q_UP]) * pcs->sc[Q_UP]; |
---|
| 1750 | xsect->d = (VAL(Down) * pcs->units[Q_DOWN] - pcs->z[Q_DOWN]) * pcs->sc[Q_DOWN]; |
---|
[a6301a1] | 1751 | xsect->meta = pcs->meta; |
---|
| 1752 | if (pcs->meta) ++pcs->meta->ref_count; |
---|
[ee05463] | 1753 | xsect->next = NULL; |
---|
| 1754 | *next_lrud = xsect; |
---|
| 1755 | next_lrud = &(xsect->next); |
---|
| 1756 | |
---|
| 1757 | return 1; |
---|
| 1758 | } |
---|
| 1759 | |
---|
[e2d48d8] | 1760 | static void |
---|
[ee05463] | 1761 | data_passage(void) |
---|
| 1762 | { |
---|
| 1763 | prefix *stn = NULL; |
---|
| 1764 | reading *ordering; |
---|
| 1765 | |
---|
| 1766 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
| 1767 | skipblanks(); |
---|
| 1768 | switch (*ordering) { |
---|
| 1769 | case Station: |
---|
[c458cf7] | 1770 | stn = read_prefix(PFX_STATION); |
---|
[ee05463] | 1771 | break; |
---|
| 1772 | case Left: case Right: case Up: case Down: |
---|
[89d7d29] | 1773 | read_reading(*ordering, fTrue); |
---|
| 1774 | if (VAL(*ordering) == HUGE_REAL) { |
---|
| 1775 | if (!isOmit(ch)) { |
---|
[da96015] | 1776 | compile_error_token(-/*Expecting numeric field, found “%s”*/9); |
---|
[4bc4d58] | 1777 | } else { |
---|
| 1778 | nextch(); |
---|
[89d7d29] | 1779 | } |
---|
| 1780 | VAL(*ordering) = -1; |
---|
| 1781 | } |
---|
[ee05463] | 1782 | break; |
---|
| 1783 | case Ignore: |
---|
| 1784 | skipword(); break; |
---|
| 1785 | case IgnoreAll: |
---|
| 1786 | skipline(); |
---|
| 1787 | /* fall through */ |
---|
| 1788 | case End: { |
---|
[e2d48d8] | 1789 | process_lrud(stn); |
---|
[ee05463] | 1790 | process_eol(); |
---|
[e2d48d8] | 1791 | return; |
---|
[ee05463] | 1792 | } |
---|
| 1793 | default: BUG("Unknown reading in ordering"); |
---|
| 1794 | } |
---|
| 1795 | } |
---|
| 1796 | } |
---|
| 1797 | |
---|
[5a38209] | 1798 | static int |
---|
| 1799 | process_nosurvey(prefix *fr, prefix *to, bool fToFirst) |
---|
| 1800 | { |
---|
| 1801 | nosurveylink *link; |
---|
[647407d] | 1802 | |
---|
[f15cde77] | 1803 | /* Suppress "unused fixed point" warnings for these stations */ |
---|
| 1804 | fr->sflags |= BIT(SFLAGS_USED); |
---|
| 1805 | to->sflags |= BIT(SFLAGS_USED); |
---|
[838a602a] | 1806 | |
---|
[647407d] | 1807 | /* add to linked list which is dealt with after network is solved */ |
---|
| 1808 | link = osnew(nosurveylink); |
---|
[5a38209] | 1809 | if (fToFirst) { |
---|
[90bb053f] | 1810 | link->to = StnFromPfx(to); |
---|
| 1811 | link->fr = StnFromPfx(fr); |
---|
[0395657] | 1812 | } else { |
---|
[90bb053f] | 1813 | link->fr = StnFromPfx(fr); |
---|
| 1814 | link->to = StnFromPfx(to); |
---|
[0395657] | 1815 | } |
---|
[eb5aea0] | 1816 | link->flags = pcs->flags | (STYLE_NOSURVEY << FLAGS_STYLE_BIT0); |
---|
[ee05463] | 1817 | link->meta = pcs->meta; |
---|
| 1818 | if (pcs->meta) ++pcs->meta->ref_count; |
---|
[647407d] | 1819 | link->next = nosurveyhead; |
---|
| 1820 | nosurveyhead = link; |
---|
[a420b49] | 1821 | return 1; |
---|
[d1b1380] | 1822 | } |
---|
[50f6901] | 1823 | |
---|
[e2d48d8] | 1824 | static void |
---|
[5a38209] | 1825 | data_nosurvey(void) |
---|
| 1826 | { |
---|
| 1827 | prefix *fr = NULL, *to = NULL; |
---|
| 1828 | |
---|
| 1829 | bool fMulti = fFalse; |
---|
| 1830 | |
---|
| 1831 | reading first_stn = End; |
---|
| 1832 | |
---|
| 1833 | reading *ordering; |
---|
| 1834 | |
---|
| 1835 | again: |
---|
| 1836 | |
---|
| 1837 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
| 1838 | skipblanks(); |
---|
| 1839 | switch (*ordering) { |
---|
| 1840 | case Fr: |
---|
[c458cf7] | 1841 | fr = read_prefix(PFX_STATION|PFX_ALLOW_ROOT); |
---|
[5a38209] | 1842 | if (first_stn == End) first_stn = Fr; |
---|
| 1843 | break; |
---|
| 1844 | case To: |
---|
[c458cf7] | 1845 | to = read_prefix(PFX_STATION|PFX_ALLOW_ROOT); |
---|
[5a38209] | 1846 | if (first_stn == End) first_stn = To; |
---|
| 1847 | break; |
---|
| 1848 | case Station: |
---|
| 1849 | fr = to; |
---|
[c458cf7] | 1850 | to = read_prefix(PFX_STATION); |
---|
[5a38209] | 1851 | first_stn = To; |
---|
| 1852 | break; |
---|
| 1853 | case Ignore: |
---|
| 1854 | skipword(); break; |
---|
| 1855 | case IgnoreAllAndNewLine: |
---|
| 1856 | skipline(); |
---|
| 1857 | /* fall through */ |
---|
| 1858 | case Newline: |
---|
| 1859 | if (fr != NULL) { |
---|
[e2d48d8] | 1860 | if (!process_nosurvey(fr, to, first_stn == To)) |
---|
| 1861 | skipline(); |
---|
[5a38209] | 1862 | } |
---|
[838a602a] | 1863 | if (ordering[1] == End) { |
---|
| 1864 | do { |
---|
| 1865 | process_eol(); |
---|
| 1866 | process_bol(); |
---|
| 1867 | } while (isComm(ch)); |
---|
[ee6a621] | 1868 | if (!isData(ch)) { |
---|
[993454b] | 1869 | push_back(ch); |
---|
[e2d48d8] | 1870 | return; |
---|
[ee6a621] | 1871 | } |
---|
[838a602a] | 1872 | goto again; |
---|
| 1873 | } |
---|
[5a38209] | 1874 | fMulti = fTrue; |
---|
| 1875 | while (1) { |
---|
| 1876 | process_eol(); |
---|
| 1877 | process_bol(); |
---|
| 1878 | if (isData(ch)) break; |
---|
[ee6a621] | 1879 | if (!isComm(ch)) { |
---|
[993454b] | 1880 | push_back(ch); |
---|
[e2d48d8] | 1881 | return; |
---|
[ee6a621] | 1882 | } |
---|
[5a38209] | 1883 | } |
---|
| 1884 | break; |
---|
| 1885 | case IgnoreAll: |
---|
| 1886 | skipline(); |
---|
| 1887 | /* fall through */ |
---|
| 1888 | case End: |
---|
| 1889 | if (!fMulti) { |
---|
[e2d48d8] | 1890 | (void)process_nosurvey(fr, to, first_stn == To); |
---|
[5a38209] | 1891 | process_eol(); |
---|
[e2d48d8] | 1892 | return; |
---|
[5a38209] | 1893 | } |
---|
[eef4d8c] | 1894 | do { |
---|
[5a38209] | 1895 | process_eol(); |
---|
| 1896 | process_bol(); |
---|
[eef4d8c] | 1897 | } while (isComm(ch)); |
---|
[5a38209] | 1898 | goto again; |
---|
| 1899 | default: BUG("Unknown reading in ordering"); |
---|
| 1900 | } |
---|
| 1901 | } |
---|
| 1902 | } |
---|
| 1903 | |
---|
[50f6901] | 1904 | /* totally ignore a line of survey data */ |
---|
[e2d48d8] | 1905 | static void |
---|
[50f6901] | 1906 | data_ignore(void) |
---|
| 1907 | { |
---|
| 1908 | skipline(); |
---|
[ee6a621] | 1909 | process_eol(); |
---|
[50f6901] | 1910 | } |
---|