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