[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 | |
---|
[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 | |
---|
[84c60fc] | 106 | fprintf(STDERR, m); |
---|
[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> */ |
---|
[b5a3219] | 492 | /* NB order is *month* *day* year */ |
---|
[be97baf] | 493 | get_token(); |
---|
| 494 | get_token(); |
---|
[b5a3219] | 495 | if (ch == ':') { |
---|
[a6301a1] | 496 | struct tm t = {0}; |
---|
[b5a3219] | 497 | |
---|
| 498 | copy_on_write_meta(pcs); |
---|
| 499 | |
---|
| 500 | nextch(); |
---|
| 501 | /* struct tm month uses 0 for Jan */ |
---|
| 502 | t.tm_mon = read_uint() - 1; |
---|
| 503 | t.tm_mday = read_uint(); |
---|
| 504 | /* struct tm uses year - 1900 */ |
---|
| 505 | t.tm_year = read_uint(); |
---|
| 506 | /* Note: Larry says a 2 digit year is always 19XX */ |
---|
| 507 | if (t.tm_year >= 100) t.tm_year -= 1900; |
---|
| 508 | |
---|
| 509 | pcs->meta->date1 = mktime(&t); |
---|
| 510 | pcs->meta->date2 = pcs->meta->date1; |
---|
[a6301a1] | 511 | } else { |
---|
| 512 | pcs->meta->date1 = pcs->meta->date2 = 0; |
---|
[b5a3219] | 513 | } |
---|
[be97baf] | 514 | skipline(); |
---|
| 515 | process_eol(); |
---|
| 516 | /* SURVEY TEAM: */ |
---|
| 517 | get_token(); |
---|
| 518 | get_token(); |
---|
| 519 | skipline(); |
---|
| 520 | process_eol(); |
---|
| 521 | /* <Survey team> */ |
---|
| 522 | nextch(); |
---|
| 523 | skipline(); |
---|
| 524 | process_eol(); |
---|
| 525 | /* DECLINATION: 1.00 FORMAT: DDDDLUDRADLN CORRECTIONS: 2.00 3.00 4.00 */ |
---|
| 526 | get_token(); |
---|
| 527 | nextch(); /* : */ |
---|
| 528 | skipblanks(); |
---|
| 529 | pcs->z[Q_DECLINATION] = -read_numeric(fFalse, NULL); |
---|
| 530 | pcs->z[Q_DECLINATION] *= pcs->units[Q_DECLINATION]; |
---|
| 531 | get_token(); |
---|
| 532 | pcs->ordering = compass_order; |
---|
| 533 | if (strcmp(buffer, "FORMAT") == 0) { |
---|
| 534 | nextch(); /* : */ |
---|
| 535 | get_token(); |
---|
| 536 | if (strlen(buffer) >= 12 && buffer[11] == 'B') { |
---|
| 537 | /* We have backsights for compass and clino */ |
---|
| 538 | pcs->ordering = compass_order_backsights; |
---|
| 539 | } |
---|
| 540 | get_token(); |
---|
[107b8bd] | 541 | } |
---|
[be97baf] | 542 | if (strcmp(buffer, "CORRECTIONS") == 0) { |
---|
| 543 | nextch(); /* : */ |
---|
| 544 | pcs->z[Q_BEARING] = -rad(read_numeric(fFalse, NULL)); |
---|
| 545 | pcs->z[Q_GRADIENT] = -rad(read_numeric(fFalse, NULL)); |
---|
| 546 | pcs->z[Q_LENGTH] = -read_numeric(fFalse, NULL); |
---|
| 547 | } else { |
---|
| 548 | pcs->z[Q_BEARING] = 0; |
---|
| 549 | pcs->z[Q_GRADIENT] = 0; |
---|
| 550 | pcs->z[Q_LENGTH] = 0; |
---|
[a420b49] | 551 | } |
---|
[be97baf] | 552 | skipline(); |
---|
| 553 | process_eol(); |
---|
| 554 | /* BLANK LINE */ |
---|
| 555 | process_bol(); |
---|
| 556 | skipline(); |
---|
| 557 | process_eol(); |
---|
| 558 | /* heading line */ |
---|
| 559 | process_bol(); |
---|
| 560 | skipline(); |
---|
| 561 | process_eol(); |
---|
| 562 | /* BLANK LINE */ |
---|
| 563 | process_bol(); |
---|
| 564 | skipline(); |
---|
| 565 | process_eol(); |
---|
| 566 | while (!feof(file.fh)) { |
---|
| 567 | process_bol(); |
---|
| 568 | if (ch == '\x0c') { |
---|
| 569 | nextch(); |
---|
| 570 | process_eol(); |
---|
| 571 | break; |
---|
| 572 | } |
---|
| 573 | (void)data_normal(); |
---|
| 574 | } |
---|
| 575 | } |
---|
| 576 | { |
---|
| 577 | settings *pcsParent = pcs->next; |
---|
| 578 | SVX_ASSERT(pcsParent); |
---|
| 579 | pcs->ordering = NULL; |
---|
| 580 | free_settings(pcs); |
---|
| 581 | pcs = pcsParent; |
---|
[44bb30d] | 582 | } |
---|
[be97baf] | 583 | } else if (fmt == FMT_MAK) { |
---|
| 584 | nextch_handling_eol(); |
---|
| 585 | while (!feof(file.fh) && !ferror(file.fh)) { |
---|
| 586 | if (ch == '#') { |
---|
| 587 | /* include a file */ |
---|
| 588 | int ch_store; |
---|
[b4fe9fb] | 589 | char *dat_pth = path_from_fnm(file.filename); |
---|
| 590 | char *dat_fnm = NULL; |
---|
| 591 | int dat_fnm_len; |
---|
[be97baf] | 592 | nextch_handling_eol(); |
---|
| 593 | while (ch != ',' && ch != ';' && ch != EOF) { |
---|
| 594 | while (isEol(ch)) process_eol(); |
---|
[63dc4eb] | 595 | s_catchar(&dat_fnm, &dat_fnm_len, (char)ch); |
---|
[be97baf] | 596 | nextch_handling_eol(); |
---|
| 597 | } |
---|
| 598 | while (ch != ';' && ch != EOF) { |
---|
| 599 | prefix *name; |
---|
| 600 | nextch_handling_eol(); |
---|
| 601 | name = read_prefix_stn(fTrue, fFalse); |
---|
| 602 | if (name) { |
---|
| 603 | skipblanks(); |
---|
| 604 | if (ch == '[') { |
---|
| 605 | /* fixed pt */ |
---|
| 606 | node *stn; |
---|
| 607 | real x, y, z; |
---|
| 608 | name->sflags |= BIT(SFLAGS_FIXED); |
---|
| 609 | nextch_handling_eol(); |
---|
| 610 | while (!isdigit(ch) && ch != '+' && ch != '-' && |
---|
| 611 | ch != '.' && ch != ']' && ch != EOF) { |
---|
| 612 | nextch_handling_eol(); |
---|
| 613 | } |
---|
| 614 | x = read_numeric(fFalse, NULL); |
---|
| 615 | while (!isdigit(ch) && ch != '+' && ch != '-' && |
---|
| 616 | ch != '.' && ch != ']' && ch != EOF) { |
---|
| 617 | nextch_handling_eol(); |
---|
| 618 | } |
---|
| 619 | y = read_numeric(fFalse, NULL); |
---|
| 620 | while (!isdigit(ch) && ch != '+' && ch != '-' && |
---|
| 621 | ch != '.' && ch != ']' && ch != EOF) { |
---|
| 622 | nextch_handling_eol(); |
---|
| 623 | } |
---|
| 624 | z = read_numeric(fFalse, NULL); |
---|
| 625 | stn = StnFromPfx(name); |
---|
| 626 | if (!fixed(stn)) { |
---|
| 627 | POS(stn, 0) = x; |
---|
| 628 | POS(stn, 1) = y; |
---|
| 629 | POS(stn, 2) = z; |
---|
| 630 | fix(stn); |
---|
| 631 | } else { |
---|
| 632 | if (x != POS(stn, 0) || y != POS(stn, 1) || |
---|
| 633 | z != POS(stn, 2)) { |
---|
| 634 | compile_error(/*Station already fixed or equated to a fixed point*/46); |
---|
| 635 | } else { |
---|
| 636 | compile_warning(/*Station already fixed at the same coordinates*/55); |
---|
| 637 | } |
---|
| 638 | } |
---|
| 639 | while (ch != ']' && ch != EOF) nextch_handling_eol(); |
---|
| 640 | if (ch == ']') { |
---|
| 641 | nextch_handling_eol(); |
---|
| 642 | skipblanks(); |
---|
| 643 | } |
---|
| 644 | } else { |
---|
| 645 | /* FIXME: link station - ignore for now */ |
---|
| 646 | /* FIXME: perhaps issue warning? */ |
---|
| 647 | } |
---|
| 648 | while (ch != ',' && ch != ';' && ch != EOF) |
---|
| 649 | nextch_handling_eol(); |
---|
| 650 | } |
---|
| 651 | } |
---|
[b4fe9fb] | 652 | if (dat_fnm) { |
---|
[be97baf] | 653 | ch_store = ch; |
---|
[b4fe9fb] | 654 | data_file(dat_pth, dat_fnm); |
---|
[be97baf] | 655 | ch = ch_store; |
---|
[b4fe9fb] | 656 | osfree(dat_fnm); |
---|
[be97baf] | 657 | } |
---|
| 658 | } else { |
---|
| 659 | /* FIXME: also check for % and $ later */ |
---|
| 660 | nextch_handling_eol(); |
---|
| 661 | } |
---|
| 662 | } |
---|
| 663 | { |
---|
| 664 | settings *pcsParent = pcs->next; |
---|
| 665 | SVX_ASSERT(pcsParent); |
---|
| 666 | free_settings(pcs); |
---|
| 667 | pcs = pcsParent; |
---|
[44bb30d] | 668 | } |
---|
[be97baf] | 669 | } else { |
---|
| 670 | while (!feof(file.fh) && !ferror(file.fh)) { |
---|
| 671 | if (!process_non_data_line()) { |
---|
[b4fe9fb] | 672 | volatile int r; |
---|
[be97baf] | 673 | f_export_ok = fFalse; |
---|
| 674 | switch (pcs->style) { |
---|
| 675 | case STYLE_NORMAL: |
---|
| 676 | case STYLE_DIVING: |
---|
| 677 | case STYLE_CYLPOLAR: |
---|
| 678 | r = data_normal(); |
---|
| 679 | break; |
---|
| 680 | case STYLE_CARTESIAN: |
---|
| 681 | r = data_cartesian(); |
---|
| 682 | break; |
---|
[ee05463] | 683 | case STYLE_PASSAGE: |
---|
| 684 | r = data_passage(); |
---|
| 685 | break; |
---|
[be97baf] | 686 | case STYLE_NOSURVEY: |
---|
| 687 | r = data_nosurvey(); |
---|
| 688 | break; |
---|
| 689 | case STYLE_IGNORE: |
---|
| 690 | r = data_ignore(); |
---|
| 691 | break; |
---|
| 692 | default: |
---|
[74a0681] | 693 | r = 0; /* avoid warning */ |
---|
[be97baf] | 694 | BUG("bad style"); |
---|
| 695 | } |
---|
| 696 | /* style function returns 0 => error */ |
---|
| 697 | } |
---|
[647407d] | 698 | } |
---|
[a420b49] | 699 | } |
---|
| 700 | |
---|
[932f7e9] | 701 | /* don't allow *BEGIN at the end of a file, then *EXPORT in the |
---|
| 702 | * including file */ |
---|
| 703 | f_export_ok = fFalse; |
---|
| 704 | |
---|
[a420b49] | 705 | #ifndef NO_PERCENTAGE |
---|
| 706 | if (fPercent) putnl(); |
---|
[4f8285d] | 707 | #endif |
---|
[d1b1380] | 708 | |
---|
[47c7a94] | 709 | if (pcs->begin_lineno) { |
---|
[0e867ba6] | 710 | error_in_file(file.filename, pcs->begin_lineno, |
---|
| 711 | /*BEGIN with no matching END in this file*/23); |
---|
[47c7a94] | 712 | /* Implicitly close any unclosed BEGINs from this file */ |
---|
| 713 | do { |
---|
| 714 | settings *pcsParent = pcs->next; |
---|
[4c07c51] | 715 | SVX_ASSERT(pcsParent); |
---|
[647407d] | 716 | free_settings(pcs); |
---|
[47c7a94] | 717 | pcs = pcsParent; |
---|
| 718 | } while (pcs->begin_lineno); |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | pcs->begin_lineno = begin_lineno_store; |
---|
[cb3d1e2] | 722 | |
---|
[22c9877] | 723 | if (ferror(file.fh)) |
---|
[bfe1242] | 724 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
[cb3d1e2] | 725 | |
---|
[22c9877] | 726 | (void)fclose(file.fh); |
---|
[7f08c83] | 727 | |
---|
[22c9877] | 728 | file = file_store; |
---|
[4d9eecd] | 729 | |
---|
| 730 | /* don't free this - it may be pointed to by prefix.file */ |
---|
| 731 | /* osfree(file.filename); */ |
---|
[a420b49] | 732 | } |
---|
[d1b1380] | 733 | |
---|
[b6de07d] | 734 | static real |
---|
| 735 | mod2pi(real a) |
---|
| 736 | { |
---|
| 737 | return a - floor(a / (2 * M_PI)) * (2 * M_PI); |
---|
| 738 | } |
---|
| 739 | |
---|
[dcec245] | 740 | static real |
---|
[5b7c1b7] | 741 | handle_plumb(clino_type *p_ctype) |
---|
[dcec245] | 742 | { |
---|
| 743 | typedef enum { |
---|
| 744 | CLINO_NULL=-1, CLINO_UP, CLINO_DOWN, CLINO_LEVEL |
---|
| 745 | } clino_tok; |
---|
| 746 | static sztok clino_tab[] = { |
---|
| 747 | {"D", CLINO_DOWN}, |
---|
| 748 | {"DOWN", CLINO_DOWN}, |
---|
| 749 | {"H", CLINO_LEVEL}, |
---|
| 750 | {"LEVEL", CLINO_LEVEL}, |
---|
| 751 | {"U", CLINO_UP}, |
---|
| 752 | {"UP", CLINO_UP}, |
---|
| 753 | {NULL, CLINO_NULL} |
---|
| 754 | }; |
---|
[5b7c1b7] | 755 | static real clinos[] = {(real)M_PI_2, (real)(-M_PI_2), (real)0.0}; |
---|
[dcec245] | 756 | clino_tok tok; |
---|
| 757 | |
---|
| 758 | skipblanks(); |
---|
| 759 | if (isalpha(ch)) { |
---|
[c80bd34] | 760 | filepos fp; |
---|
| 761 | get_pos(&fp); |
---|
[dcec245] | 762 | get_token(); |
---|
| 763 | tok = match_tok(clino_tab, TABSIZE(clino_tab)); |
---|
| 764 | if (tok != CLINO_NULL) { |
---|
[be97baf] | 765 | *p_ctype = (tok == CLINO_LEVEL ? CTYPE_HORIZ : CTYPE_PLUMB); |
---|
[dcec245] | 766 | return clinos[tok]; |
---|
| 767 | } |
---|
[c80bd34] | 768 | set_pos(&fp); |
---|
[dcec245] | 769 | } else if (isSign(ch)) { |
---|
| 770 | int chOld = ch; |
---|
| 771 | nextch(); |
---|
| 772 | if (toupper(ch) == 'V') { |
---|
| 773 | nextch(); |
---|
[fa42426] | 774 | *p_ctype = CTYPE_PLUMB; |
---|
[bceebf4] | 775 | return (!isMinus(chOld) ? M_PI_2 : -M_PI_2); |
---|
[dcec245] | 776 | } |
---|
| 777 | |
---|
[bd1913f] | 778 | if (isOmit(chOld)) { |
---|
[fa42426] | 779 | *p_ctype = CTYPE_OMIT; |
---|
[dcec245] | 780 | /* no clino reading, so assume 0 with large sd */ |
---|
| 781 | return (real)0.0; |
---|
| 782 | } |
---|
[5b7c1b7] | 783 | } else if (isOmit(ch)) { |
---|
| 784 | /* OMIT char may not be a SIGN char too so we need to check here as |
---|
| 785 | * well as above... */ |
---|
| 786 | nextch(); |
---|
[fa42426] | 787 | *p_ctype = CTYPE_OMIT; |
---|
[5b7c1b7] | 788 | /* no clino reading, so assume 0 with large sd */ |
---|
| 789 | return (real)0.0; |
---|
[dcec245] | 790 | } |
---|
| 791 | return HUGE_REAL; |
---|
| 792 | } |
---|
| 793 | |
---|
[b6de07d] | 794 | static void |
---|
[b4fe9fb] | 795 | warn_readings_differ(int msgno, real diff) |
---|
[b6de07d] | 796 | { |
---|
| 797 | char buf[64]; |
---|
| 798 | char *p; |
---|
| 799 | sprintf(buf, "%.2f", deg(fabs(diff))); |
---|
| 800 | p = strchr(buf, '.'); |
---|
| 801 | if (p) { |
---|
| 802 | char *z = p; |
---|
| 803 | while (*++p) { |
---|
| 804 | if (*p != '0') z = p + 1; |
---|
| 805 | } |
---|
| 806 | if (*z) *z = '\0'; |
---|
| 807 | } |
---|
[b4fe9fb] | 808 | compile_warning(msgno, buf); |
---|
[b6de07d] | 809 | } |
---|
| 810 | |
---|
| 811 | static bool |
---|
[21c226e] | 812 | handle_comp_units(void) |
---|
[b6de07d] | 813 | { |
---|
| 814 | bool fNoComp = fTrue; |
---|
[21c226e] | 815 | if (VAL(Comp) != HUGE_REAL) { |
---|
[b6de07d] | 816 | fNoComp = fFalse; |
---|
[21c226e] | 817 | VAL(Comp) *= pcs->units[Q_BEARING]; |
---|
| 818 | if (VAL(Comp) < (real)0.0 || VAL(Comp) - M_PI * 2.0 > EPSILON) { |
---|
[b6de07d] | 819 | compile_warning(/*Suspicious compass reading*/59); |
---|
[21c226e] | 820 | VAL(Comp) = mod2pi(VAL(Comp)); |
---|
[b6de07d] | 821 | } |
---|
| 822 | } |
---|
[21c226e] | 823 | if (VAL(BackComp) != HUGE_REAL) { |
---|
[b6de07d] | 824 | fNoComp = fFalse; |
---|
[21c226e] | 825 | VAL(BackComp) *= pcs->units[Q_BACKBEARING]; |
---|
| 826 | if (VAL(BackComp) < (real)0.0 || VAL(BackComp) - M_PI * 2.0 > EPSILON) { |
---|
[b6de07d] | 827 | /* FIXME: different message for BackComp? */ |
---|
| 828 | compile_warning(/*Suspicious compass reading*/59); |
---|
[21c226e] | 829 | VAL(BackComp) = mod2pi(VAL(BackComp)); |
---|
[b6de07d] | 830 | } |
---|
| 831 | } |
---|
| 832 | return fNoComp; |
---|
| 833 | } |
---|
| 834 | |
---|
| 835 | static real |
---|
[21c226e] | 836 | handle_compass(real *p_var) |
---|
[b6de07d] | 837 | { |
---|
[b4fe9fb] | 838 | real compvar = VAR(Comp); |
---|
[21c226e] | 839 | real comp = VAL(Comp); |
---|
| 840 | real backcomp = VAL(BackComp); |
---|
[b6de07d] | 841 | if (comp != HUGE_REAL) { |
---|
| 842 | comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING]; |
---|
| 843 | comp -= pcs->z[Q_DECLINATION]; |
---|
| 844 | } |
---|
| 845 | if (backcomp != HUGE_REAL) { |
---|
| 846 | backcomp = (backcomp - pcs->z[Q_BACKBEARING]) |
---|
| 847 | * pcs->sc[Q_BACKBEARING]; |
---|
| 848 | backcomp -= pcs->z[Q_DECLINATION]; |
---|
| 849 | backcomp -= M_PI; |
---|
| 850 | if (comp != HUGE_REAL) { |
---|
| 851 | real diff = comp - backcomp; |
---|
| 852 | real adj = fabs(diff) > M_PI ? M_PI : 0; |
---|
| 853 | diff -= floor((diff + M_PI) / (2 * M_PI)) * 2 * M_PI; |
---|
[b4fe9fb] | 854 | if (sqrd(diff / 2.0) > compvar + VAR(Q_BACKBEARING)) { |
---|
[770157e] | 855 | /* fore and back readings differ by more than 2 sds */ |
---|
[fa42426] | 856 | warn_readings_differ(/*Compass reading and back compass reading disagree by %s degrees*/98, diff); |
---|
[b6de07d] | 857 | } |
---|
[b4fe9fb] | 858 | comp = (comp / compvar + backcomp / VAR(BackComp)); |
---|
| 859 | compvar = (compvar + VAR(BackComp)) / 4; |
---|
| 860 | comp *= compvar; |
---|
[b6de07d] | 861 | comp += adj; |
---|
| 862 | } else { |
---|
| 863 | comp = backcomp; |
---|
[b4fe9fb] | 864 | compvar = VAR(BackComp); |
---|
[b6de07d] | 865 | } |
---|
| 866 | } |
---|
[b4fe9fb] | 867 | *p_var = compvar; |
---|
[b6de07d] | 868 | return comp; |
---|
| 869 | } |
---|
| 870 | |
---|
[90bb053f] | 871 | static int |
---|
[21c226e] | 872 | process_normal(prefix *fr, prefix *to, bool fToFirst, |
---|
| 873 | clino_type ctype, clino_type backctype) |
---|
[a420b49] | 874 | { |
---|
[21c226e] | 875 | real tape = VAL(Tape); |
---|
| 876 | real clin = VAL(Clino); |
---|
| 877 | real backclin = VAL(BackClino); |
---|
| 878 | |
---|
[a420b49] | 879 | real dx, dy, dz; |
---|
| 880 | real vx, vy, vz; |
---|
| 881 | #ifndef NO_COVARIANCES |
---|
[cb3d1e2] | 882 | real cxy, cyz, czx; |
---|
[a420b49] | 883 | #endif |
---|
[d1b1380] | 884 | |
---|
[90bb053f] | 885 | bool fNoComp; |
---|
[a420b49] | 886 | |
---|
[107b8bd] | 887 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 888 | if (tape < (real)0.0) { |
---|
| 889 | /* TRANSLATE different message for topofil? */ |
---|
| 890 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
[647407d] | 891 | } |
---|
[d1b1380] | 892 | |
---|
[21c226e] | 893 | fNoComp = handle_comp_units(); |
---|
[d1b1380] | 894 | |
---|
[fa42426] | 895 | if (ctype == CTYPE_READING) { |
---|
[0b71cfc] | 896 | real diff_from_abs90; |
---|
[a420b49] | 897 | clin *= pcs->units[Q_GRADIENT]; |
---|
[fa42426] | 898 | /* percentage scale */ |
---|
| 899 | if (pcs->f_clino_percent) clin = atan(clin); |
---|
[0b71cfc] | 900 | diff_from_abs90 = fabs(clin) - M_PI_2; |
---|
| 901 | if (diff_from_abs90 > EPSILON) { |
---|
[a420b49] | 902 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
[27b8b59] | 903 | } else if (TSTBIT(pcs->infer, INFER_PLUMBS) && |
---|
[be97baf] | 904 | diff_from_abs90 >= -EPSILON) { |
---|
| 905 | ctype = CTYPE_INFERPLUMB; |
---|
[a420b49] | 906 | } |
---|
| 907 | } |
---|
[cb3d1e2] | 908 | |
---|
[fa42426] | 909 | if (backctype == CTYPE_READING) { |
---|
[b14f44f] | 910 | backclin *= pcs->units[Q_BACKGRADIENT]; |
---|
[fa42426] | 911 | /* percentage scale */ |
---|
| 912 | if (pcs->f_backclino_percent) backclin = atan(backclin); |
---|
[be97baf] | 913 | if (ctype != CTYPE_READING) { |
---|
| 914 | real diff_from_abs90 = fabs(backclin) - M_PI_2; |
---|
| 915 | if (diff_from_abs90 > EPSILON) { |
---|
| 916 | /* FIXME: different message for BackClino? */ |
---|
| 917 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
| 918 | } else if (TSTBIT(pcs->infer, INFER_PLUMBS) && |
---|
| 919 | diff_from_abs90 >= -EPSILON) { |
---|
| 920 | backctype = CTYPE_INFERPLUMB; |
---|
| 921 | } |
---|
[0b71cfc] | 922 | } |
---|
| 923 | } |
---|
| 924 | |
---|
[be97baf] | 925 | /* un-infer the plumb if the backsight was just a reading */ |
---|
| 926 | if (ctype == CTYPE_INFERPLUMB && backctype == CTYPE_READING) { |
---|
| 927 | ctype = CTYPE_READING; |
---|
| 928 | } |
---|
| 929 | |
---|
[fa42426] | 930 | if (ctype != CTYPE_OMIT && backctype != CTYPE_OMIT && ctype != backctype) { |
---|
| 931 | compile_error_skip(/*Clino and BackClino readings must be of the same type*/84); |
---|
[b14f44f] | 932 | return 0; |
---|
[0b71cfc] | 933 | } |
---|
| 934 | |
---|
[be97baf] | 935 | if (ctype == CTYPE_PLUMB || ctype == CTYPE_INFERPLUMB || |
---|
| 936 | backctype == CTYPE_PLUMB || backctype == CTYPE_INFERPLUMB) { |
---|
[a420b49] | 937 | /* plumbed */ |
---|
| 938 | if (!fNoComp) { |
---|
[be97baf] | 939 | if (ctype == CTYPE_PLUMB || |
---|
| 940 | (ctype == CTYPE_INFERPLUMB && VAL(Comp) != 0.0) || |
---|
| 941 | backctype == CTYPE_PLUMB || |
---|
| 942 | (backctype == CTYPE_INFERPLUMB && VAL(BackComp) != 0.0)) { |
---|
| 943 | /* FIXME: Different message for BackComp? */ |
---|
| 944 | compile_warning(/*Compass reading given on plumbed leg*/21); |
---|
| 945 | } |
---|
[a420b49] | 946 | } |
---|
| 947 | |
---|
| 948 | dx = dy = (real)0.0; |
---|
[fa42426] | 949 | if (ctype != CTYPE_OMIT) { |
---|
| 950 | if (backctype != CTYPE_OMIT && (clin > 0) == (backclin > 0)) { |
---|
[b14f44f] | 951 | /* We've got two UPs or two DOWNs - FIXME: not ideal message */ |
---|
[fa42426] | 952 | compile_error_skip(/*Clino and BackClino readings must be of the same type*/84); |
---|
[b14f44f] | 953 | return 0; |
---|
[0b71cfc] | 954 | } |
---|
| 955 | dz = (clin > (real)0.0) ? tape : -tape; |
---|
| 956 | } else { |
---|
| 957 | dz = (backclin < (real)0.0) ? tape : -tape; |
---|
| 958 | } |
---|
[a420b49] | 959 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
[21c226e] | 960 | vz = var(Q_POS) / 3.0 + VAR(Tape); |
---|
[4f8285d] | 961 | #ifndef NO_COVARIANCES |
---|
[26a805f] | 962 | /* Correct values - no covariances in this case! */ |
---|
| 963 | cxy = cyz = czx = (real)0.0; |
---|
[4f8285d] | 964 | #endif |
---|
[a420b49] | 965 | } else { |
---|
[fa42426] | 966 | /* Each of ctype and backctype are either CTYPE_READING/CTYPE_HORIZ |
---|
| 967 | * or CTYPE_OMIT */ |
---|
[a420b49] | 968 | /* clino */ |
---|
| 969 | real L2, cosG, LcosG, cosG2, sinB, cosB, dx2, dy2, dz2, v, V; |
---|
[421b7d2] | 970 | if (fNoComp) { |
---|
[fa42426] | 971 | compile_error_skip(/*Compass reading may not be omitted except on plumbed legs*/14); |
---|
[a420b49] | 972 | return 0; |
---|
| 973 | } |
---|
| 974 | if (tape == (real)0.0) { |
---|
| 975 | dx = dy = dz = (real)0.0; |
---|
| 976 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
[4f8285d] | 977 | #ifndef NO_COVARIANCES |
---|
[a420b49] | 978 | cxy = cyz = czx = (real)0.0; |
---|
[4f8285d] | 979 | #endif |
---|
[d1b1380] | 980 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 981 | printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
[d1b1380] | 982 | #endif |
---|
[a420b49] | 983 | } else { |
---|
[dbb4e19] | 984 | real sinGcosG; |
---|
[0b71cfc] | 985 | /* take into account variance in LEVEL case */ |
---|
| 986 | real var_clin = var(Q_LEVEL); |
---|
[b6de07d] | 987 | real var_comp; |
---|
[21c226e] | 988 | real comp = handle_compass(&var_comp); |
---|
[fa42426] | 989 | /* ctype != CTYPE_READING is LEVEL case */ |
---|
| 990 | if (ctype == CTYPE_READING) { |
---|
[a420b49] | 991 | clin = (clin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT]; |
---|
[21c226e] | 992 | var_clin = VAR(Clino); |
---|
[0b71cfc] | 993 | } |
---|
[fa42426] | 994 | if (backctype == CTYPE_READING) { |
---|
[b14f44f] | 995 | backclin = (backclin - pcs->z[Q_BACKGRADIENT]) |
---|
| 996 | * pcs->sc[Q_BACKGRADIENT]; |
---|
[fa42426] | 997 | if (ctype == CTYPE_READING) { |
---|
[be97baf] | 998 | if (sqrd((clin + backclin) / 3.0) > var_clin + VAR(BackClino)) { |
---|
[b14f44f] | 999 | /* fore and back readings differ by more than 3 sds */ |
---|
[fa42426] | 1000 | warn_readings_differ(/*Clino reading and back clino reading disagree by %s degrees*/99, clin + backclin); |
---|
[b14f44f] | 1001 | } |
---|
[21c226e] | 1002 | clin = (clin / var_clin - backclin / VAR(BackClino)); |
---|
| 1003 | var_clin = (var_clin + VAR(BackClino)) / 4; |
---|
[b14f44f] | 1004 | clin *= var_clin; |
---|
[0b71cfc] | 1005 | } else { |
---|
| 1006 | clin = -backclin; |
---|
[21c226e] | 1007 | var_clin = VAR(BackClino); |
---|
[0b71cfc] | 1008 | } |
---|
| 1009 | } |
---|
[d1b1380] | 1010 | |
---|
| 1011 | #if DEBUG_DATAIN |
---|
[a420b49] | 1012 | printf(" %4.2f %4.2f %4.2f\n", tape, comp, clin); |
---|
[d1b1380] | 1013 | #endif |
---|
[a420b49] | 1014 | cosG = cos(clin); |
---|
| 1015 | LcosG = tape * cosG; |
---|
| 1016 | sinB = sin(comp); |
---|
| 1017 | cosB = cos(comp); |
---|
[d1b1380] | 1018 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1019 | printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB, cosG, LcosG); |
---|
[d1b1380] | 1020 | #endif |
---|
[a420b49] | 1021 | dx = LcosG * sinB; |
---|
| 1022 | dy = LcosG * cosB; |
---|
| 1023 | dz = tape * sin(clin); |
---|
[d1b1380] | 1024 | /* printf("%.2f\n",clin); */ |
---|
| 1025 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1026 | printf("dx = %f\ndy = %f\ndz = %f\n", dx, dy, dz); |
---|
[d1b1380] | 1027 | #endif |
---|
[a420b49] | 1028 | dx2 = dx * dx; |
---|
| 1029 | L2 = tape * tape; |
---|
[21c226e] | 1030 | V = VAR(Tape) / L2; |
---|
[a420b49] | 1031 | dy2 = dy * dy; |
---|
| 1032 | cosG2 = cosG * cosG; |
---|
[dbb4e19] | 1033 | sinGcosG = sin(clin) * cosG; |
---|
[a420b49] | 1034 | dz2 = dz * dz; |
---|
[0b71cfc] | 1035 | v = dz2 * var_clin; |
---|
[5b7c1b7] | 1036 | #ifdef NO_COVARIANCES |
---|
[0b71cfc] | 1037 | vx = (var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp + |
---|
[a420b49] | 1038 | (.5 + sinB * sinB * cosG2) * v); |
---|
[0b71cfc] | 1039 | vy = (var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp + |
---|
[a420b49] | 1040 | (.5 + cosB * cosB * cosG2) * 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 | } |
---|
[a420b49] | 1047 | /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */ |
---|
[dbb4e19] | 1048 | #else |
---|
[0b71cfc] | 1049 | vx = var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp + |
---|
[dbb4e19] | 1050 | (sinB * sinB * v); |
---|
[0b71cfc] | 1051 | vy = var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp + |
---|
[dbb4e19] | 1052 | (cosB * cosB * v); |
---|
[fa42426] | 1053 | if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) { |
---|
[5b7c1b7] | 1054 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
[0b71cfc] | 1055 | vz = var(Q_POS) / 3.0 + L2 * (real)0.1; |
---|
[5b7c1b7] | 1056 | } else { |
---|
[0b71cfc] | 1057 | vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin; |
---|
[5b7c1b7] | 1058 | } |
---|
[647407d] | 1059 | /* usual covariance formulae are fine in no clino case since |
---|
[0b71cfc] | 1060 | * dz = 0 so value of var_clin is ignored */ |
---|
[21c226e] | 1061 | cxy = sinB * cosB * (VAR(Tape) * cosG2 + var_clin * dz2) |
---|
[0b71cfc] | 1062 | - var_comp * dx * dy; |
---|
[21c226e] | 1063 | czx = VAR(Tape) * sinB * sinGcosG - var_clin * dx * dz; |
---|
| 1064 | cyz = VAR(Tape) * cosB * sinGcosG - var_clin * dy * dz; |
---|
[dbb4e19] | 1065 | #if 0 |
---|
| 1066 | printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx, vy, vz); |
---|
| 1067 | printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy, cyz, czx); |
---|
| 1068 | #endif |
---|
[4f8285d] | 1069 | #endif |
---|
[d1b1380] | 1070 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1071 | printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
[d1b1380] | 1072 | #endif |
---|
[a420b49] | 1073 | } |
---|
| 1074 | } |
---|
[d1b1380] | 1075 | #if DEBUG_DATAIN_1 |
---|
[a420b49] | 1076 | printf("Just before addleg, vx = %f\n", vx); |
---|
[d1b1380] | 1077 | #endif |
---|
[a420b49] | 1078 | /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/ |
---|
[90bb053f] | 1079 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
[4f8285d] | 1080 | #ifndef NO_COVARIANCES |
---|
[2140502] | 1081 | , cyz, czx, cxy |
---|
[4f8285d] | 1082 | #endif |
---|
[2140502] | 1083 | ); |
---|
[a420b49] | 1084 | return 1; |
---|
[d1b1380] | 1085 | } |
---|
| 1086 | |
---|
[5a38209] | 1087 | static int |
---|
[21c226e] | 1088 | process_diving(prefix *fr, prefix *to, bool fToFirst, bool fDepthChange) |
---|
[a420b49] | 1089 | { |
---|
[21c226e] | 1090 | real tape = VAL(Tape); |
---|
| 1091 | |
---|
[a420b49] | 1092 | real dx, dy, dz; |
---|
| 1093 | real vx, vy, vz; |
---|
[f795df0] | 1094 | #ifndef NO_COVARIANCES |
---|
| 1095 | real cxy = 0, cyz = 0, czx = 0; |
---|
| 1096 | #endif |
---|
[a420b49] | 1097 | |
---|
[21c226e] | 1098 | handle_comp_units(); |
---|
[a420b49] | 1099 | |
---|
[a6d094f] | 1100 | /* depth gauge readings increase upwards with default calibration */ |
---|
[6114207] | 1101 | if (fDepthChange) { |
---|
[21c226e] | 1102 | SVX_ASSERT(VAL(FrDepth) == 0.0); |
---|
| 1103 | dz = VAL(ToDepth) * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]; |
---|
| 1104 | dz *= pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 1105 | } else { |
---|
[21c226e] | 1106 | dz = VAL(ToDepth) - VAL(FrDepth); |
---|
| 1107 | dz *= pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 1108 | } |
---|
[a420b49] | 1109 | |
---|
| 1110 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 1111 | if (tape < (real)0.0) { |
---|
| 1112 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
| 1113 | } |
---|
| 1114 | |
---|
| 1115 | /* check if tape is less than depth change */ |
---|
| 1116 | if (tape < fabs(dz)) { |
---|
[bd1913f] | 1117 | /* FIXME: allow margin of error based on variances? */ |
---|
[a420b49] | 1118 | compile_warning(/*Tape reading is less than change in depth*/62); |
---|
| 1119 | } |
---|
| 1120 | |
---|
[0a208f9] | 1121 | if (tape == (real)0.0 && dz == 0.0) { |
---|
[a420b49] | 1122 | dx = dy = dz = (real)0.0; |
---|
| 1123 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
[21c226e] | 1124 | } else if (VAL(Comp) == HUGE_REAL && |
---|
| 1125 | VAL(BackComp) == HUGE_REAL) { |
---|
[385b703] | 1126 | /* plumb */ |
---|
| 1127 | dx = dy = (real)0.0; |
---|
| 1128 | if (dz < 0) tape = -tape; |
---|
[21c226e] | 1129 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1130 | dz = (dz * VAR(Tape) + tape * 2 * VAR(ToDepth)) |
---|
| 1131 | / (VAR(Tape) * 2 * VAR(ToDepth)); |
---|
[385b703] | 1132 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
[21c226e] | 1133 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1134 | vz = var(Q_POS) / 3.0 + VAR(Tape) * 2 * VAR(ToDepth) |
---|
| 1135 | / (VAR(Tape) + VAR(ToDepth)); |
---|
[a420b49] | 1136 | } else { |
---|
[f795df0] | 1137 | real L2, sinB, cosB, dz2, D2; |
---|
[b6de07d] | 1138 | real var_comp; |
---|
[21c226e] | 1139 | real comp = handle_compass(&var_comp); |
---|
[a420b49] | 1140 | sinB = sin(comp); |
---|
| 1141 | cosB = cos(comp); |
---|
| 1142 | L2 = tape * tape; |
---|
| 1143 | dz2 = dz * dz; |
---|
| 1144 | D2 = L2 - dz2; |
---|
| 1145 | if (D2 <= (real)0.0) { |
---|
[21c226e] | 1146 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1147 | real vsum = VAR(Tape) + 2 * VAR(ToDepth); |
---|
[a420b49] | 1148 | dx = dy = (real)0.0; |
---|
[f795df0] | 1149 | vx = vy = var(Q_POS) / 3.0; |
---|
[21c226e] | 1150 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1151 | vz = var(Q_POS) / 3.0 + VAR(Tape) * 2 * VAR(ToDepth) / vsum; |
---|
[f795df0] | 1152 | if (dz > 0) { |
---|
[21c226e] | 1153 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1154 | dz = (dz * VAR(Tape) + tape * 2 * VAR(ToDepth)) / vsum; |
---|
[f795df0] | 1155 | } else { |
---|
[21c226e] | 1156 | dz = (dz * VAR(Tape) - tape * 2 * VAR(ToDepth)) / vsum; |
---|
[f795df0] | 1157 | } |
---|
[a420b49] | 1158 | } else { |
---|
| 1159 | real D = sqrt(D2); |
---|
[21c226e] | 1160 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1161 | real F = VAR(Tape) * L2 + 2 * VAR(ToDepth) * D2; |
---|
[a420b49] | 1162 | dx = D * sinB; |
---|
| 1163 | dy = D * cosB; |
---|
[f795df0] | 1164 | |
---|
| 1165 | vx = var(Q_POS) / 3.0 + |
---|
[72095d3] | 1166 | sinB * sinB * F / D2 + var_comp * dy * dy; |
---|
[f795df0] | 1167 | vy = var(Q_POS) / 3.0 + |
---|
[72095d3] | 1168 | cosB * cosB * F / D2 + var_comp * dx * dx; |
---|
[21c226e] | 1169 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1170 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
[f795df0] | 1171 | |
---|
| 1172 | #ifndef NO_COVARIANCES |
---|
[72095d3] | 1173 | cxy = sinB * cosB * (F / D2 + var_comp * D2); |
---|
[21c226e] | 1174 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1175 | cyz = -2 * VAR(ToDepth) * dy / D; |
---|
| 1176 | czx = -2 * VAR(ToDepth) * dx / D; |
---|
[f795df0] | 1177 | #endif |
---|
[a420b49] | 1178 | } |
---|
| 1179 | } |
---|
[5a38209] | 1180 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
[2140502] | 1181 | #ifndef NO_COVARIANCES |
---|
[f795df0] | 1182 | , cxy, cyz, czx |
---|
[647407d] | 1183 | #endif |
---|
[2140502] | 1184 | ); |
---|
[647407d] | 1185 | return 1; |
---|
| 1186 | } |
---|
| 1187 | |
---|
[5a38209] | 1188 | static int |
---|
[21c226e] | 1189 | process_cartesian(prefix *fr, prefix *to, bool fToFirst) |
---|
[5a38209] | 1190 | { |
---|
[21c226e] | 1191 | real dx = (VAL(Dx) * pcs->units[Q_DX] - pcs->z[Q_DX]) * pcs->sc[Q_DX]; |
---|
| 1192 | real dy = (VAL(Dy) * pcs->units[Q_DY] - pcs->z[Q_DY]) * pcs->sc[Q_DY]; |
---|
| 1193 | real dz = (VAL(Dz) * pcs->units[Q_DZ] - pcs->z[Q_DZ]) * pcs->sc[Q_DZ]; |
---|
[647407d] | 1194 | |
---|
[21c226e] | 1195 | addlegbyname(fr, to, fToFirst, dx, dy, dz, VAR(Dx), VAR(Dy), VAR(Dz) |
---|
[647407d] | 1196 | #ifndef NO_COVARIANCES |
---|
[c80bd34] | 1197 | , 0, 0, 0 |
---|
[647407d] | 1198 | #endif |
---|
[2140502] | 1199 | ); |
---|
[647407d] | 1200 | return 1; |
---|
| 1201 | } |
---|
| 1202 | |
---|
[ee05463] | 1203 | static int |
---|
[5a38209] | 1204 | data_cartesian(void) |
---|
[647407d] | 1205 | { |
---|
[90bb053f] | 1206 | prefix *fr = NULL, *to = NULL; |
---|
[5a38209] | 1207 | |
---|
| 1208 | bool fMulti = fFalse; |
---|
[647407d] | 1209 | |
---|
[0395657] | 1210 | reading first_stn = End; |
---|
| 1211 | |
---|
| 1212 | reading *ordering; |
---|
[647407d] | 1213 | |
---|
[5a38209] | 1214 | again: |
---|
| 1215 | |
---|
[647407d] | 1216 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
| 1217 | skipblanks(); |
---|
| 1218 | switch (*ordering) { |
---|
[4a6a094] | 1219 | case Fr: |
---|
[21c226e] | 1220 | fr = read_prefix_stn(fFalse, fTrue); |
---|
| 1221 | if (first_stn == End) first_stn = Fr; |
---|
| 1222 | break; |
---|
[4a6a094] | 1223 | case To: |
---|
[21c226e] | 1224 | to = read_prefix_stn(fFalse, fTrue); |
---|
| 1225 | if (first_stn == End) first_stn = To; |
---|
| 1226 | break; |
---|
[5a38209] | 1227 | case Station: |
---|
[21c226e] | 1228 | fr = to; |
---|
| 1229 | to = read_prefix_stn(fFalse, fFalse); |
---|
| 1230 | first_stn = To; |
---|
| 1231 | break; |
---|
| 1232 | case Dx: case Dy: case Dz: |
---|
| 1233 | read_reading(*ordering, fFalse); |
---|
| 1234 | break; |
---|
[647407d] | 1235 | case Ignore: |
---|
| 1236 | skipword(); break; |
---|
[5a38209] | 1237 | case IgnoreAllAndNewLine: |
---|
| 1238 | skipline(); |
---|
| 1239 | /* fall through */ |
---|
| 1240 | case Newline: |
---|
| 1241 | if (fr != NULL) { |
---|
| 1242 | int r; |
---|
[21c226e] | 1243 | r = process_cartesian(fr, to, first_stn == To); |
---|
[5a38209] | 1244 | if (!r) skipline(); |
---|
| 1245 | } |
---|
| 1246 | fMulti = fTrue; |
---|
| 1247 | while (1) { |
---|
| 1248 | process_eol(); |
---|
| 1249 | process_bol(); |
---|
| 1250 | if (isData(ch)) break; |
---|
[ee6a621] | 1251 | if (!isComm(ch)) { |
---|
[993454b] | 1252 | push_back(ch); |
---|
[ee6a621] | 1253 | return 1; |
---|
| 1254 | } |
---|
[5a38209] | 1255 | } |
---|
| 1256 | break; |
---|
[647407d] | 1257 | case IgnoreAll: |
---|
| 1258 | skipline(); |
---|
| 1259 | /* fall through */ |
---|
| 1260 | case End: |
---|
[5a38209] | 1261 | if (!fMulti) { |
---|
[21c226e] | 1262 | int r = process_cartesian(fr, to, first_stn == To); |
---|
[5a38209] | 1263 | process_eol(); |
---|
| 1264 | return r; |
---|
| 1265 | } |
---|
[eef4d8c] | 1266 | do { |
---|
[5a38209] | 1267 | process_eol(); |
---|
| 1268 | process_bol(); |
---|
[eef4d8c] | 1269 | } while (isComm(ch)); |
---|
[5a38209] | 1270 | goto again; |
---|
[0395657] | 1271 | default: BUG("Unknown reading in ordering"); |
---|
[647407d] | 1272 | } |
---|
| 1273 | } |
---|
[5a38209] | 1274 | } |
---|
[cb3d1e2] | 1275 | |
---|
[98a2eec] | 1276 | static int |
---|
[21c226e] | 1277 | process_cylpolar(prefix *fr, prefix *to, bool fToFirst, bool fDepthChange) |
---|
[98a2eec] | 1278 | { |
---|
[21c226e] | 1279 | real tape = VAL(Tape); |
---|
| 1280 | |
---|
[98a2eec] | 1281 | real dx, dy, dz; |
---|
| 1282 | real vx, vy, vz; |
---|
| 1283 | #ifndef NO_COVARIANCES |
---|
| 1284 | real cxy = 0; |
---|
| 1285 | #endif |
---|
| 1286 | |
---|
[21c226e] | 1287 | handle_comp_units(); |
---|
[98a2eec] | 1288 | |
---|
[a6d094f] | 1289 | /* depth gauge readings increase upwards with default calibration */ |
---|
[6114207] | 1290 | if (fDepthChange) { |
---|
[21c226e] | 1291 | SVX_ASSERT(VAL(FrDepth) == 0.0); |
---|
| 1292 | dz = VAL(ToDepth) * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]; |
---|
| 1293 | dz *= pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 1294 | } else { |
---|
[21c226e] | 1295 | dz = VAL(ToDepth) - VAL(FrDepth); |
---|
| 1296 | dz *= pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
[a6d094f] | 1297 | } |
---|
[98a2eec] | 1298 | |
---|
| 1299 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
| 1300 | if (tape < (real)0.0) { |
---|
| 1301 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
| 1302 | } |
---|
| 1303 | |
---|
[21c226e] | 1304 | if (VAL(Comp) == HUGE_REAL && VAL(BackComp) == HUGE_REAL) { |
---|
[98a2eec] | 1305 | /* plumb */ |
---|
| 1306 | dx = dy = (real)0.0; |
---|
| 1307 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
[21c226e] | 1308 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1309 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
[98a2eec] | 1310 | } else { |
---|
| 1311 | real sinB, cosB; |
---|
[b6de07d] | 1312 | real var_comp; |
---|
[21c226e] | 1313 | real comp = handle_compass(&var_comp); |
---|
[98a2eec] | 1314 | sinB = sin(comp); |
---|
| 1315 | cosB = cos(comp); |
---|
| 1316 | |
---|
| 1317 | dx = tape * sinB; |
---|
| 1318 | dy = tape * cosB; |
---|
| 1319 | |
---|
| 1320 | vx = var(Q_POS) / 3.0 + |
---|
[21c226e] | 1321 | VAR(Tape) * sinB * sinB + var_comp * dy * dy; |
---|
[98a2eec] | 1322 | vy = var(Q_POS) / 3.0 + |
---|
[21c226e] | 1323 | VAR(Tape) * cosB * cosB + var_comp * dx * dx; |
---|
| 1324 | /* FIXME: Should use FrDepth sometimes... */ |
---|
| 1325 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
[98a2eec] | 1326 | |
---|
| 1327 | #ifndef NO_COVARIANCES |
---|
[21c226e] | 1328 | cxy = (VAR(Tape) - var_comp * tape * tape) * sinB * cosB; |
---|
[98a2eec] | 1329 | #endif |
---|
| 1330 | } |
---|
| 1331 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
| 1332 | #ifndef NO_COVARIANCES |
---|
| 1333 | , cxy, 0, 0 |
---|
| 1334 | #endif |
---|
| 1335 | ); |
---|
| 1336 | return 1; |
---|
| 1337 | } |
---|
| 1338 | |
---|
[107b8bd] | 1339 | /* Process tape/compass/clino, diving, and cylpolar styles of survey data |
---|
| 1340 | * Also handles topofil (fromcount/tocount or count) in place of tape */ |
---|
[ee05463] | 1341 | static int |
---|
[107b8bd] | 1342 | data_normal(void) |
---|
[54c4612] | 1343 | { |
---|
| 1344 | prefix *fr = NULL, *to = NULL; |
---|
[107b8bd] | 1345 | reading first_stn = End; |
---|
[54c4612] | 1346 | |
---|
[107b8bd] | 1347 | bool fTopofil = fFalse, fMulti = fFalse; |
---|
| 1348 | bool fRev; |
---|
[e217d67] | 1349 | clino_type ctype, backctype; |
---|
[107b8bd] | 1350 | bool fDepthChange; |
---|
[be97baf] | 1351 | unsigned long compass_dat_flags = 0; |
---|
[54c4612] | 1352 | |
---|
| 1353 | reading *ordering; |
---|
| 1354 | |
---|
[21c226e] | 1355 | VAL(Tape) = 0; |
---|
[07442af] | 1356 | VAL(Comp) = VAL(BackComp) = HUGE_REAL; |
---|
[21c226e] | 1357 | VAL(FrCount) = VAL(ToCount) = 0; |
---|
| 1358 | VAL(FrDepth) = VAL(ToDepth) = 0; |
---|
[07442af] | 1359 | VAL(Left) = VAL(Right) = VAL(Up) = VAL(Down) = HUGE_REAL; |
---|
[54c4612] | 1360 | |
---|
| 1361 | fRev = fFalse; |
---|
[fa42426] | 1362 | ctype = backctype = CTYPE_OMIT; |
---|
[6114207] | 1363 | fDepthChange = fFalse; |
---|
[54c4612] | 1364 | |
---|
[107b8bd] | 1365 | /* ordering may omit clino reading, so set up default here */ |
---|
| 1366 | /* this is also used if clino reading is the omit character */ |
---|
[21c226e] | 1367 | VAL(Clino) = VAL(BackClino) = 0; |
---|
| 1368 | |
---|
| 1369 | again: |
---|
[107b8bd] | 1370 | |
---|
[54c4612] | 1371 | for (ordering = pcs->ordering; ; ordering++) { |
---|
| 1372 | skipblanks(); |
---|
| 1373 | switch (*ordering) { |
---|
| 1374 | case Fr: |
---|
[107b8bd] | 1375 | fr = read_prefix_stn(fFalse, fTrue); |
---|
| 1376 | if (first_stn == End) first_stn = Fr; |
---|
| 1377 | break; |
---|
[54c4612] | 1378 | case To: |
---|
[107b8bd] | 1379 | to = read_prefix_stn(fFalse, fTrue); |
---|
| 1380 | if (first_stn == End) first_stn = To; |
---|
| 1381 | break; |
---|
[54c4612] | 1382 | case Station: |
---|
[107b8bd] | 1383 | fr = to; |
---|
| 1384 | to = read_prefix_stn(fFalse, fFalse); |
---|
| 1385 | first_stn = To; |
---|
| 1386 | break; |
---|
[ee1ec59] | 1387 | case Dir: { |
---|
| 1388 | typedef enum { |
---|
| 1389 | DIR_NULL=-1, DIR_FORE, DIR_BACK |
---|
| 1390 | } dir_tok; |
---|
| 1391 | static sztok dir_tab[] = { |
---|
| 1392 | {"B", DIR_BACK}, |
---|
| 1393 | {"F", DIR_FORE}, |
---|
| 1394 | }; |
---|
| 1395 | dir_tok tok; |
---|
| 1396 | get_token(); |
---|
| 1397 | tok = match_tok(dir_tab, TABSIZE(dir_tab)); |
---|
| 1398 | switch (tok) { |
---|
| 1399 | case DIR_FORE: |
---|
[54c4612] | 1400 | break; |
---|
[ee1ec59] | 1401 | case DIR_BACK: |
---|
[54c4612] | 1402 | fRev = fTrue; |
---|
| 1403 | break; |
---|
| 1404 | default: |
---|
[ee1ec59] | 1405 | compile_error_skip(/*Found `%s', expecting `F' or `B'*/131, |
---|
[44bb30d] | 1406 | buffer); |
---|
[54c4612] | 1407 | process_eol(); |
---|
| 1408 | return 0; |
---|
| 1409 | } |
---|
| 1410 | break; |
---|
[ee1ec59] | 1411 | } |
---|
[107b8bd] | 1412 | case Tape: |
---|
[21c226e] | 1413 | read_reading(Tape, fFalse); |
---|
| 1414 | if (VAL(Tape) < (real)0.0) |
---|
| 1415 | compile_warning(/*Negative tape reading*/60); |
---|
[107b8bd] | 1416 | break; |
---|
| 1417 | case Count: |
---|
[21c226e] | 1418 | VAL(FrCount) = VAL(ToCount); |
---|
| 1419 | read_reading(ToCount, fFalse); |
---|
[b4fe9fb] | 1420 | fTopofil = fTrue; |
---|
[107b8bd] | 1421 | break; |
---|
| 1422 | case FrCount: |
---|
[21c226e] | 1423 | read_reading(FrCount, fFalse); |
---|
[107b8bd] | 1424 | break; |
---|
| 1425 | case ToCount: |
---|
[21c226e] | 1426 | read_reading(ToCount, fFalse); |
---|
[107b8bd] | 1427 | fTopofil = fTrue; |
---|
| 1428 | break; |
---|
[07442af] | 1429 | case Comp: case BackComp: |
---|
| 1430 | read_bearing_or_omit(*ordering); |
---|
[5b7c1b7] | 1431 | break; |
---|
[5757725] | 1432 | case Clino: |
---|
[21c226e] | 1433 | read_reading(Clino, fTrue); |
---|
| 1434 | if (VAL(Clino) == HUGE_REAL) { |
---|
| 1435 | VAL(Clino) = handle_plumb(&ctype); |
---|
| 1436 | if (VAL(Clino) != HUGE_REAL) break; |
---|
[107b8bd] | 1437 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
| 1438 | process_eol(); |
---|
| 1439 | return 0; |
---|
| 1440 | } |
---|
[fa42426] | 1441 | ctype = CTYPE_READING; |
---|
[5b7c1b7] | 1442 | break; |
---|
| 1443 | case BackClino: |
---|
[21c226e] | 1444 | read_reading(BackClino, fTrue); |
---|
| 1445 | if (VAL(BackClino) == HUGE_REAL) { |
---|
| 1446 | VAL(BackClino) = handle_plumb(&backctype); |
---|
| 1447 | if (VAL(BackClino) != HUGE_REAL) break; |
---|
[5b7c1b7] | 1448 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
| 1449 | process_eol(); |
---|
| 1450 | return 0; |
---|
| 1451 | } |
---|
[fa42426] | 1452 | backctype = CTYPE_READING; |
---|
[107b8bd] | 1453 | break; |
---|
[07442af] | 1454 | case FrDepth: case ToDepth: |
---|
| 1455 | read_reading(*ordering, fFalse); |
---|
[107b8bd] | 1456 | break; |
---|
[54c4612] | 1457 | case Depth: |
---|
[21c226e] | 1458 | VAL(FrDepth) = VAL(ToDepth); |
---|
| 1459 | read_reading(ToDepth, fFalse); |
---|
[54c4612] | 1460 | break; |
---|
[6114207] | 1461 | case DepthChange: |
---|
| 1462 | fDepthChange = fTrue; |
---|
[21c226e] | 1463 | VAL(FrDepth) = 0; |
---|
| 1464 | read_reading(ToDepth, fFalse); |
---|
[a186573] | 1465 | break; |
---|
[44bb30d] | 1466 | case CompassDATComp: |
---|
| 1467 | read_bearing_or_omit(Comp); |
---|
| 1468 | if (is_compass_NaN(VAL(Comp))) VAL(Comp) = HUGE_REAL; |
---|
| 1469 | break; |
---|
| 1470 | case CompassDATBackComp: |
---|
| 1471 | read_bearing_or_omit(BackComp); |
---|
| 1472 | if (is_compass_NaN(VAL(BackComp))) VAL(BackComp) = HUGE_REAL; |
---|
| 1473 | break; |
---|
| 1474 | case CompassDATClino: |
---|
[07442af] | 1475 | read_reading(Clino, fFalse); |
---|
[44bb30d] | 1476 | if (is_compass_NaN(VAL(Clino))) { |
---|
| 1477 | VAL(Clino) = HUGE_REAL; |
---|
| 1478 | ctype = CTYPE_OMIT; |
---|
[07442af] | 1479 | } else { |
---|
| 1480 | ctype = CTYPE_READING; |
---|
| 1481 | } |
---|
[44bb30d] | 1482 | break; |
---|
| 1483 | case CompassDATBackClino: |
---|
[07442af] | 1484 | read_reading(BackClino, fFalse); |
---|
[44bb30d] | 1485 | if (is_compass_NaN(VAL(BackClino))) { |
---|
| 1486 | VAL(BackClino) = HUGE_REAL; |
---|
| 1487 | backctype = CTYPE_OMIT; |
---|
[07442af] | 1488 | } else { |
---|
| 1489 | backctype = CTYPE_READING; |
---|
| 1490 | } |
---|
| 1491 | break; |
---|
| 1492 | case CompassDATLeft: case CompassDATRight: |
---|
| 1493 | case CompassDATUp: case CompassDATDown: { |
---|
[ee05463] | 1494 | /* FIXME: need to actually make use of these entries! */ |
---|
[07442af] | 1495 | reading actual = Left + (*ordering - CompassDATLeft); |
---|
| 1496 | read_reading(actual, fFalse); |
---|
| 1497 | if (VAL(actual) < 0) VAL(actual) = HUGE_REAL; |
---|
[44bb30d] | 1498 | break; |
---|
[07442af] | 1499 | } |
---|
[be97baf] | 1500 | case CompassDATFlags: |
---|
| 1501 | if (ch == '#') { |
---|
| 1502 | nextch(); |
---|
| 1503 | if (ch == '|') { |
---|
| 1504 | filepos fp; |
---|
| 1505 | get_pos(&fp); |
---|
| 1506 | nextch(); |
---|
| 1507 | while (ch >= 'A' && ch <= 'Z') { |
---|
| 1508 | compass_dat_flags |= BIT(ch - 'A'); |
---|
[0580c6a] | 1509 | /* FIXME: we currently understand X (exclude data) |
---|
| 1510 | * but should also handle at least some of: |
---|
| 1511 | * L exclude from length |
---|
| 1512 | * P no plot |
---|
| 1513 | * C no adjustment |
---|
| 1514 | */ |
---|
[be97baf] | 1515 | nextch(); |
---|
| 1516 | } |
---|
| 1517 | if (ch == '#') { |
---|
| 1518 | nextch(); |
---|
| 1519 | } else { |
---|
| 1520 | compass_dat_flags = 0; |
---|
| 1521 | set_pos(&fp); |
---|
| 1522 | push_back('|'); |
---|
| 1523 | ch = '#'; |
---|
| 1524 | } |
---|
| 1525 | } else { |
---|
| 1526 | push_back(ch); |
---|
| 1527 | ch = '#'; |
---|
| 1528 | } |
---|
| 1529 | } |
---|
[107b8bd] | 1530 | break; |
---|
[be97baf] | 1531 | case Ignore: |
---|
| 1532 | skipword(); break; |
---|
[54c4612] | 1533 | case IgnoreAllAndNewLine: |
---|
[107b8bd] | 1534 | skipline(); |
---|
| 1535 | /* fall through */ |
---|
[54c4612] | 1536 | case Newline: |
---|
[107b8bd] | 1537 | if (fr != NULL) { |
---|
| 1538 | int r; |
---|
[21c226e] | 1539 | if (fTopofil) |
---|
| 1540 | VAL(Tape) = VAL(ToCount) - VAL(FrCount); |
---|
[107b8bd] | 1541 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
| 1542 | * (frdepth always zero, todepth is change of depth) and also |
---|
| 1543 | * works for STYLE_NORMAL (both remain 0) */ |
---|
[44bb30d] | 1544 | if (TSTBIT(pcs->infer, INFER_EQUATES) && |
---|
[27b8b59] | 1545 | VAL(Tape) == (real)0.0 && VAL(FrDepth) == VAL(ToDepth)) { |
---|
[107b8bd] | 1546 | process_equate(fr, to); |
---|
| 1547 | goto inferred_equate; |
---|
| 1548 | } |
---|
[e7576f6] | 1549 | if (fRev) { |
---|
| 1550 | prefix *t = fr; |
---|
[44bb30d] | 1551 | fr = to; |
---|
| 1552 | to = t; |
---|
[e7576f6] | 1553 | } |
---|
[107b8bd] | 1554 | if (fTopofil) { |
---|
[21c226e] | 1555 | VAL(Tape) *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
[107b8bd] | 1556 | } else { |
---|
[21c226e] | 1557 | VAL(Tape) *= pcs->units[Q_LENGTH]; |
---|
| 1558 | VAL(Tape) -= pcs->z[Q_LENGTH]; |
---|
| 1559 | VAL(Tape) *= pcs->sc[Q_LENGTH]; |
---|
[107b8bd] | 1560 | } |
---|
| 1561 | switch (pcs->style) { |
---|
| 1562 | case STYLE_NORMAL: |
---|
[21c226e] | 1563 | r = process_normal(fr, to, (first_stn == To) ^ fRev, |
---|
| 1564 | ctype, backctype); |
---|
[107b8bd] | 1565 | break; |
---|
| 1566 | case STYLE_DIVING: |
---|
[21c226e] | 1567 | r = process_diving(fr, to, (first_stn == To) ^ fRev, |
---|
| 1568 | fDepthChange); |
---|
[107b8bd] | 1569 | break; |
---|
| 1570 | case STYLE_CYLPOLAR: |
---|
[21c226e] | 1571 | r = process_cylpolar(fr, to, (first_stn == To) ^ fRev, |
---|
| 1572 | fDepthChange); |
---|
[107b8bd] | 1573 | break; |
---|
| 1574 | default: |
---|
[74a0681] | 1575 | r = 0; /* avoid warning */ |
---|
[107b8bd] | 1576 | BUG("bad style"); |
---|
| 1577 | } |
---|
| 1578 | if (!r) skipline(); |
---|
[44bb30d] | 1579 | |
---|
[e7576f6] | 1580 | /* Swap fr and to back to how they were for next line */ |
---|
| 1581 | if (fRev) { |
---|
| 1582 | prefix *t = fr; |
---|
| 1583 | fr = to; |
---|
| 1584 | to = t; |
---|
| 1585 | } |
---|
[107b8bd] | 1586 | } |
---|
[21c226e] | 1587 | |
---|
| 1588 | fRev = fFalse; |
---|
| 1589 | ctype = backctype = CTYPE_OMIT; |
---|
| 1590 | fDepthChange = fFalse; |
---|
| 1591 | |
---|
| 1592 | /* ordering may omit clino reading, so set up default here */ |
---|
| 1593 | /* this is also used if clino reading is the omit character */ |
---|
| 1594 | VAL(Clino) = VAL(BackClino) = 0; |
---|
| 1595 | |
---|
[44bb30d] | 1596 | inferred_equate: |
---|
[e7576f6] | 1597 | |
---|
[107b8bd] | 1598 | fMulti = fTrue; |
---|
| 1599 | while (1) { |
---|
| 1600 | process_eol(); |
---|
| 1601 | process_bol(); |
---|
| 1602 | if (isData(ch)) break; |
---|
| 1603 | if (!isComm(ch)) { |
---|
| 1604 | push_back(ch); |
---|
| 1605 | return 1; |
---|
| 1606 | } |
---|
| 1607 | } |
---|
| 1608 | break; |
---|
[54c4612] | 1609 | case IgnoreAll: |
---|
[107b8bd] | 1610 | skipline(); |
---|
| 1611 | /* fall through */ |
---|
[54c4612] | 1612 | case End: |
---|
[107b8bd] | 1613 | if (!fMulti) { |
---|
| 1614 | int r; |
---|
[be97baf] | 1615 | /* Compass ignore flag is 'X' */ |
---|
| 1616 | if ((compass_dat_flags & BIT('X' - 'A'))) { |
---|
| 1617 | process_eol(); |
---|
| 1618 | return 1; |
---|
| 1619 | } |
---|
[107b8bd] | 1620 | if (fRev) { |
---|
| 1621 | prefix *t = fr; |
---|
| 1622 | fr = to; |
---|
| 1623 | to = t; |
---|
| 1624 | } |
---|
[21c226e] | 1625 | if (fTopofil) VAL(Tape) = VAL(ToCount) - VAL(FrCount); |
---|
[107b8bd] | 1626 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
| 1627 | * (frdepth always zero, todepth is change of depth) and also |
---|
| 1628 | * works for STYLE_NORMAL (both remain 0) */ |
---|
[07442af] | 1629 | if (TSTBIT(pcs->infer, INFER_EQUATES) && |
---|
[27b8b59] | 1630 | VAL(Tape) == (real)0.0 && VAL(FrDepth) == VAL(ToDepth)) { |
---|
[107b8bd] | 1631 | process_equate(fr, to); |
---|
| 1632 | process_eol(); |
---|
| 1633 | return 1; |
---|
| 1634 | } |
---|
| 1635 | if (fTopofil) { |
---|
[21c226e] | 1636 | VAL(Tape) *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
[107b8bd] | 1637 | } else { |
---|
[21c226e] | 1638 | VAL(Tape) *= pcs->units[Q_LENGTH]; |
---|
| 1639 | VAL(Tape) -= pcs->z[Q_LENGTH]; |
---|
| 1640 | VAL(Tape) *= pcs->sc[Q_LENGTH]; |
---|
[107b8bd] | 1641 | } |
---|
| 1642 | switch (pcs->style) { |
---|
| 1643 | case STYLE_NORMAL: |
---|
[21c226e] | 1644 | r = process_normal(fr, to, (first_stn == To) ^ fRev, |
---|
| 1645 | ctype, backctype); |
---|
[107b8bd] | 1646 | break; |
---|
| 1647 | case STYLE_DIVING: |
---|
[21c226e] | 1648 | r = process_diving(fr, to, (first_stn == To) ^ fRev, |
---|
| 1649 | fDepthChange); |
---|
[107b8bd] | 1650 | break; |
---|
| 1651 | case STYLE_CYLPOLAR: |
---|
[21c226e] | 1652 | r = process_cylpolar(fr, to, (first_stn == To) ^ fRev, |
---|
| 1653 | fDepthChange); |
---|
[107b8bd] | 1654 | break; |
---|
| 1655 | default: |
---|
[44bb30d] | 1656 | r = 0; /* Suppress compiler warning */; |
---|
[107b8bd] | 1657 | BUG("bad style"); |
---|
| 1658 | } |
---|
[ee05463] | 1659 | |
---|
[107b8bd] | 1660 | process_eol(); |
---|
| 1661 | return r; |
---|
| 1662 | } |
---|
| 1663 | do { |
---|
| 1664 | process_eol(); |
---|
| 1665 | process_bol(); |
---|
| 1666 | } while (isComm(ch)); |
---|
| 1667 | goto again; |
---|
| 1668 | default: |
---|
| 1669 | BUG("Unknown reading in ordering"); |
---|
[54c4612] | 1670 | } |
---|
| 1671 | } |
---|
| 1672 | } |
---|
| 1673 | |
---|
[ee05463] | 1674 | static int |
---|
| 1675 | process_lrud(prefix *stn) |
---|
| 1676 | { |
---|
| 1677 | SVX_ASSERT(next_lrud); |
---|
| 1678 | lrud * xsect = osnew(lrud); |
---|
| 1679 | xsect->stn = stn; |
---|
| 1680 | xsect->l = (VAL(Left) * pcs->units[Q_LEFT] - pcs->z[Q_LEFT]) * pcs->sc[Q_LEFT]; |
---|
| 1681 | xsect->r = (VAL(Right) * pcs->units[Q_RIGHT] - pcs->z[Q_RIGHT]) * pcs->sc[Q_RIGHT]; |
---|
| 1682 | xsect->u = (VAL(Up) * pcs->units[Q_UP] - pcs->z[Q_UP]) * pcs->sc[Q_UP]; |
---|
| 1683 | xsect->d = (VAL(Down) * pcs->units[Q_DOWN] - pcs->z[Q_DOWN]) * pcs->sc[Q_DOWN]; |
---|
[a6301a1] | 1684 | xsect->meta = pcs->meta; |
---|
| 1685 | if (pcs->meta) ++pcs->meta->ref_count; |
---|
[ee05463] | 1686 | xsect->next = NULL; |
---|
| 1687 | *next_lrud = xsect; |
---|
| 1688 | next_lrud = &(xsect->next); |
---|
| 1689 | |
---|
| 1690 | return 1; |
---|
| 1691 | } |
---|
| 1692 | |
---|
| 1693 | static int |
---|
| 1694 | data_passage(void) |
---|
| 1695 | { |
---|
| 1696 | prefix *stn = NULL; |
---|
| 1697 | reading *ordering; |
---|
| 1698 | |
---|
| 1699 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
| 1700 | skipblanks(); |
---|
| 1701 | switch (*ordering) { |
---|
| 1702 | case Station: |
---|
| 1703 | stn = read_prefix_stn(fFalse, fFalse); |
---|
| 1704 | break; |
---|
| 1705 | case Left: case Right: case Up: case Down: |
---|
[89d7d29] | 1706 | read_reading(*ordering, fTrue); |
---|
| 1707 | if (VAL(*ordering) == HUGE_REAL) { |
---|
| 1708 | if (!isOmit(ch)) { |
---|
| 1709 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
| 1710 | } |
---|
[fb94b6a8] | 1711 | nextch(); |
---|
[89d7d29] | 1712 | VAL(*ordering) = -1; |
---|
| 1713 | } |
---|
[ee05463] | 1714 | break; |
---|
| 1715 | case Ignore: |
---|
| 1716 | skipword(); break; |
---|
| 1717 | case IgnoreAll: |
---|
| 1718 | skipline(); |
---|
| 1719 | /* fall through */ |
---|
| 1720 | case End: { |
---|
| 1721 | int r = process_lrud(stn); |
---|
| 1722 | process_eol(); |
---|
| 1723 | return r; |
---|
| 1724 | } |
---|
| 1725 | default: BUG("Unknown reading in ordering"); |
---|
| 1726 | } |
---|
| 1727 | } |
---|
| 1728 | } |
---|
| 1729 | |
---|
[5a38209] | 1730 | static int |
---|
| 1731 | process_nosurvey(prefix *fr, prefix *to, bool fToFirst) |
---|
| 1732 | { |
---|
| 1733 | nosurveylink *link; |
---|
[838a602a] | 1734 | int shape; |
---|
[647407d] | 1735 | |
---|
[838a602a] | 1736 | /* Suppress "unused fixed point" warnings for these stations |
---|
| 1737 | * We do this if it's a 0 or 1 node - 1 node might be an sdfix |
---|
| 1738 | */ |
---|
| 1739 | shape = fr->shape; |
---|
| 1740 | if (shape == 0 || shape == 1) fr->shape = -1 - shape; |
---|
| 1741 | shape = to->shape; |
---|
| 1742 | if (shape == 0 || shape == 1) to->shape = -1 - shape; |
---|
| 1743 | |
---|
[647407d] | 1744 | /* add to linked list which is dealt with after network is solved */ |
---|
| 1745 | link = osnew(nosurveylink); |
---|
[5a38209] | 1746 | if (fToFirst) { |
---|
[90bb053f] | 1747 | link->to = StnFromPfx(to); |
---|
| 1748 | link->fr = StnFromPfx(fr); |
---|
[0395657] | 1749 | } else { |
---|
[90bb053f] | 1750 | link->fr = StnFromPfx(fr); |
---|
| 1751 | link->to = StnFromPfx(to); |
---|
[0395657] | 1752 | } |
---|
[b3bef47] | 1753 | link->flags = pcs->flags; |
---|
[ee05463] | 1754 | link->meta = pcs->meta; |
---|
| 1755 | if (pcs->meta) ++pcs->meta->ref_count; |
---|
[647407d] | 1756 | link->next = nosurveyhead; |
---|
| 1757 | nosurveyhead = link; |
---|
[a420b49] | 1758 | return 1; |
---|
[d1b1380] | 1759 | } |
---|
[50f6901] | 1760 | |
---|
[ee05463] | 1761 | static int |
---|
[5a38209] | 1762 | data_nosurvey(void) |
---|
| 1763 | { |
---|
| 1764 | prefix *fr = NULL, *to = NULL; |
---|
| 1765 | |
---|
| 1766 | bool fMulti = fFalse; |
---|
| 1767 | |
---|
| 1768 | reading first_stn = End; |
---|
| 1769 | |
---|
| 1770 | reading *ordering; |
---|
| 1771 | |
---|
| 1772 | again: |
---|
| 1773 | |
---|
| 1774 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
| 1775 | skipblanks(); |
---|
| 1776 | switch (*ordering) { |
---|
| 1777 | case Fr: |
---|
[84c60fc] | 1778 | fr = read_prefix_stn(fFalse, fTrue); |
---|
[5a38209] | 1779 | if (first_stn == End) first_stn = Fr; |
---|
| 1780 | break; |
---|
| 1781 | case To: |
---|
[84c60fc] | 1782 | to = read_prefix_stn(fFalse, fTrue); |
---|
[5a38209] | 1783 | if (first_stn == End) first_stn = To; |
---|
| 1784 | break; |
---|
| 1785 | case Station: |
---|
| 1786 | fr = to; |
---|
[84c60fc] | 1787 | to = read_prefix_stn(fFalse, fFalse); |
---|
[5a38209] | 1788 | first_stn = To; |
---|
| 1789 | break; |
---|
| 1790 | case Ignore: |
---|
| 1791 | skipword(); break; |
---|
| 1792 | case IgnoreAllAndNewLine: |
---|
| 1793 | skipline(); |
---|
| 1794 | /* fall through */ |
---|
| 1795 | case Newline: |
---|
| 1796 | if (fr != NULL) { |
---|
| 1797 | int r; |
---|
| 1798 | r = process_nosurvey(fr, to, first_stn == To); |
---|
| 1799 | if (!r) skipline(); |
---|
| 1800 | } |
---|
[838a602a] | 1801 | if (ordering[1] == End) { |
---|
| 1802 | do { |
---|
| 1803 | process_eol(); |
---|
| 1804 | process_bol(); |
---|
| 1805 | } while (isComm(ch)); |
---|
[ee6a621] | 1806 | if (!isData(ch)) { |
---|
[993454b] | 1807 | push_back(ch); |
---|
[ee6a621] | 1808 | return 1; |
---|
| 1809 | } |
---|
[838a602a] | 1810 | goto again; |
---|
| 1811 | } |
---|
[5a38209] | 1812 | fMulti = fTrue; |
---|
| 1813 | while (1) { |
---|
| 1814 | process_eol(); |
---|
| 1815 | process_bol(); |
---|
| 1816 | if (isData(ch)) break; |
---|
[ee6a621] | 1817 | if (!isComm(ch)) { |
---|
[993454b] | 1818 | push_back(ch); |
---|
[ee6a621] | 1819 | return 1; |
---|
| 1820 | } |
---|
[5a38209] | 1821 | } |
---|
| 1822 | break; |
---|
| 1823 | case IgnoreAll: |
---|
| 1824 | skipline(); |
---|
| 1825 | /* fall through */ |
---|
| 1826 | case End: |
---|
| 1827 | if (!fMulti) { |
---|
[ee6a621] | 1828 | int r = process_nosurvey(fr, to, first_stn == To); |
---|
[5a38209] | 1829 | process_eol(); |
---|
| 1830 | return r; |
---|
| 1831 | } |
---|
[eef4d8c] | 1832 | do { |
---|
[5a38209] | 1833 | process_eol(); |
---|
| 1834 | process_bol(); |
---|
[eef4d8c] | 1835 | } while (isComm(ch)); |
---|
[5a38209] | 1836 | goto again; |
---|
| 1837 | default: BUG("Unknown reading in ordering"); |
---|
| 1838 | } |
---|
| 1839 | } |
---|
| 1840 | } |
---|
| 1841 | |
---|
[50f6901] | 1842 | /* totally ignore a line of survey data */ |
---|
[ee05463] | 1843 | static int |
---|
[50f6901] | 1844 | data_ignore(void) |
---|
| 1845 | { |
---|
| 1846 | skipline(); |
---|
[ee6a621] | 1847 | process_eol(); |
---|
[570f4bf] | 1848 | return 1; |
---|
[50f6901] | 1849 | } |
---|