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