1 | /* datain.c |
---|
2 | * Reads in survey files, dealing with special characters, keywords & data |
---|
3 | * Copyright (C) 1991-2002 Olly Betts |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation; either version 2 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | */ |
---|
19 | |
---|
20 | #ifdef HAVE_CONFIG_H |
---|
21 | #include <config.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <limits.h> |
---|
25 | #include <stdarg.h> |
---|
26 | |
---|
27 | #include "debug.h" |
---|
28 | #include "cavern.h" |
---|
29 | #include "filename.h" |
---|
30 | #include "message.h" |
---|
31 | #include "filelist.h" |
---|
32 | #include "netbits.h" |
---|
33 | #include "netskel.h" |
---|
34 | #include "readval.h" |
---|
35 | #include "datain.h" |
---|
36 | #include "commands.h" |
---|
37 | #include "out.h" |
---|
38 | #include "str.h" |
---|
39 | |
---|
40 | #define EPSILON (REAL_EPSILON * 1000) |
---|
41 | |
---|
42 | #define var(I) (pcs->Var[(I)]) |
---|
43 | |
---|
44 | int ch; |
---|
45 | |
---|
46 | typedef enum {CTYPE_OMIT, CTYPE_READING, CTYPE_PLUMB, CTYPE_HORIZ} clino_type; |
---|
47 | |
---|
48 | /* Don't explicitly initialise as we can't set the jmp_buf - this has |
---|
49 | * static scope so will be initialised like this anyway */ |
---|
50 | parse file /* = { NULL, NULL, 0, fFalse, NULL } */ ; |
---|
51 | |
---|
52 | bool f_export_ok; |
---|
53 | |
---|
54 | static real value[Fr - 1]; |
---|
55 | #define VAL(N) value[(N)-1] |
---|
56 | static real variance[Fr - 1]; |
---|
57 | #define VAR(N) variance[(N)-1] |
---|
58 | |
---|
59 | static filepos fpLineStart; |
---|
60 | |
---|
61 | void |
---|
62 | get_pos(filepos *fp) |
---|
63 | { |
---|
64 | fp->ch = ch; |
---|
65 | fp->offset = ftell(file.fh); |
---|
66 | if (fp->offset == -1) |
---|
67 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
68 | } |
---|
69 | |
---|
70 | void |
---|
71 | set_pos(const filepos *fp) |
---|
72 | { |
---|
73 | ch = fp->ch; |
---|
74 | if (fseek(file.fh, fp->offset, SEEK_SET) == -1) |
---|
75 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
76 | } |
---|
77 | |
---|
78 | static void |
---|
79 | push_back(int c) |
---|
80 | { |
---|
81 | if (c != EOF && ungetc(c, file.fh) == EOF) |
---|
82 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
83 | } |
---|
84 | |
---|
85 | static void |
---|
86 | error_list_parent_files(void) |
---|
87 | { |
---|
88 | if (!file.reported_where && file.parent) { |
---|
89 | parse *p = file.parent; |
---|
90 | const char *m = msg(/*In file included from*/5); |
---|
91 | size_t len = strlen(m); |
---|
92 | |
---|
93 | fprintf(STDERR, m); |
---|
94 | m = msg(/*from*/3); |
---|
95 | |
---|
96 | /* Suppress reporting of full include tree for further errors |
---|
97 | * in this file */ |
---|
98 | file.reported_where = fTrue; |
---|
99 | |
---|
100 | while (p) { |
---|
101 | /* Force re-report of include tree for further errors in |
---|
102 | * parent files */ |
---|
103 | p->reported_where = fFalse; |
---|
104 | fprintf(STDERR, " %s:%d", p->filename, p->line); |
---|
105 | p = p->parent; |
---|
106 | if (p) fprintf(STDERR, ",\n%*s", (int)len, m); |
---|
107 | } |
---|
108 | fprintf(STDERR, ":\n"); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | void |
---|
113 | compile_error(int en, ...) |
---|
114 | { |
---|
115 | va_list ap; |
---|
116 | va_start(ap, en); |
---|
117 | error_list_parent_files(); |
---|
118 | v_report(1, file.filename, file.line, en, ap); |
---|
119 | va_end(ap); |
---|
120 | } |
---|
121 | |
---|
122 | void |
---|
123 | compile_error_skip(int en, ...) |
---|
124 | { |
---|
125 | va_list ap; |
---|
126 | va_start(ap, en); |
---|
127 | error_list_parent_files(); |
---|
128 | v_report(1, file.filename, file.line, en, ap); |
---|
129 | va_end(ap); |
---|
130 | skipline(); |
---|
131 | } |
---|
132 | |
---|
133 | void |
---|
134 | compile_error_token(int en) |
---|
135 | { |
---|
136 | char *p = NULL; |
---|
137 | static int len; |
---|
138 | s_zero(&p); |
---|
139 | skipblanks(); |
---|
140 | while (!isBlank(ch) && !isEol(ch)) { |
---|
141 | s_catchar(&p, &len, ch); |
---|
142 | nextch(); |
---|
143 | } |
---|
144 | compile_error_skip(en, p ? p : ""); |
---|
145 | osfree(p); |
---|
146 | } |
---|
147 | |
---|
148 | void |
---|
149 | compile_warning(int en, ...) |
---|
150 | { |
---|
151 | va_list ap; |
---|
152 | va_start(ap, en); |
---|
153 | error_list_parent_files(); |
---|
154 | v_report(0, file.filename, file.line, en, ap); |
---|
155 | va_end(ap); |
---|
156 | } |
---|
157 | |
---|
158 | /* This function makes a note where to put output files */ |
---|
159 | static void |
---|
160 | using_data_file(const char *fnm) |
---|
161 | { |
---|
162 | if (!fnm_output_base) { |
---|
163 | /* was: fnm_output_base = base_from_fnm(fnm); */ |
---|
164 | fnm_output_base = baseleaf_from_fnm(fnm); |
---|
165 | } else if (fnm_output_base_is_dir) { |
---|
166 | /* --output pointed to directory so use the leaf basename in that dir */ |
---|
167 | char *lf, *p; |
---|
168 | lf = baseleaf_from_fnm(fnm); |
---|
169 | p = use_path(fnm_output_base, lf); |
---|
170 | osfree(lf); |
---|
171 | osfree(fnm_output_base); |
---|
172 | fnm_output_base = p; |
---|
173 | fnm_output_base_is_dir = 0; |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | static void |
---|
178 | skipword(void) |
---|
179 | { |
---|
180 | while (!isBlank(ch) && !isEol(ch)) nextch(); |
---|
181 | } |
---|
182 | |
---|
183 | extern void |
---|
184 | skipblanks(void) |
---|
185 | { |
---|
186 | while (isBlank(ch)) nextch(); |
---|
187 | } |
---|
188 | |
---|
189 | extern void |
---|
190 | skipline(void) |
---|
191 | { |
---|
192 | while (!isEol(ch)) nextch(); |
---|
193 | } |
---|
194 | |
---|
195 | #ifndef NO_PERCENTAGE |
---|
196 | static long int filelen; |
---|
197 | #endif |
---|
198 | |
---|
199 | static void |
---|
200 | process_bol(void) |
---|
201 | { |
---|
202 | /* Note start of line for error reporting */ |
---|
203 | get_pos(&fpLineStart); |
---|
204 | |
---|
205 | #ifndef NO_PERCENTAGE |
---|
206 | /* print %age of file done */ |
---|
207 | if (filelen > 0) |
---|
208 | printf("%d%%\r", (int)(100 * fpLineStart.offset / filelen)); |
---|
209 | #endif |
---|
210 | |
---|
211 | nextch(); |
---|
212 | skipblanks(); |
---|
213 | } |
---|
214 | |
---|
215 | static void |
---|
216 | process_eol(void) |
---|
217 | { |
---|
218 | int eolchar; |
---|
219 | |
---|
220 | skipblanks(); |
---|
221 | |
---|
222 | if (!isEol(ch)) { |
---|
223 | if (!isComm(ch)) compile_error(/*End of line not blank*/15); |
---|
224 | skipline(); |
---|
225 | } |
---|
226 | |
---|
227 | eolchar = ch; |
---|
228 | file.line++; |
---|
229 | /* skip any different eol characters so we get line counts correct on |
---|
230 | * DOS text files and similar, but don't count several adjacent blank |
---|
231 | * lines as one */ |
---|
232 | while (ch != EOF) { |
---|
233 | nextch(); |
---|
234 | if (ch == eolchar || !isEol(ch)) { |
---|
235 | push_back(ch); |
---|
236 | break; |
---|
237 | } |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | static bool |
---|
242 | process_non_data_line(void) |
---|
243 | { |
---|
244 | process_bol(); |
---|
245 | |
---|
246 | if (isData(ch)) return fFalse; |
---|
247 | |
---|
248 | if (isKeywd(ch)) { |
---|
249 | nextch(); |
---|
250 | handle_command(); |
---|
251 | } |
---|
252 | |
---|
253 | process_eol(); |
---|
254 | |
---|
255 | return fTrue; |
---|
256 | } |
---|
257 | |
---|
258 | static void |
---|
259 | read_reading(reading r, bool f_optional) |
---|
260 | { |
---|
261 | int n_readings; |
---|
262 | q_quantity q; |
---|
263 | VAL(r) = read_numeric(f_optional, &n_readings); |
---|
264 | switch (r) { |
---|
265 | case Tape: q = Q_LENGTH; break; |
---|
266 | case Comp: q = Q_BEARING; break; |
---|
267 | case BackComp: q = Q_BACKBEARING; break; |
---|
268 | case Clino: q = Q_GRADIENT; break; |
---|
269 | case BackClino: q = Q_BACKGRADIENT; break; |
---|
270 | case FrDepth: case ToDepth: q = Q_DEPTH; break; |
---|
271 | case Dx: q = Q_DX; break; |
---|
272 | case Dy: q = Q_DY; break; |
---|
273 | case Dz: q = Q_DZ; break; |
---|
274 | case FrCount: case ToCount: q = Q_COUNT; break; |
---|
275 | default: BUG("Unexpected case"); |
---|
276 | } |
---|
277 | VAR(r) = var(q); |
---|
278 | if (n_readings > 1) VAR(r) /= sqrt(n_readings); |
---|
279 | } |
---|
280 | |
---|
281 | static void |
---|
282 | read_bearing_or_omit(reading r) |
---|
283 | { |
---|
284 | int n_readings; |
---|
285 | q_quantity q; |
---|
286 | VAL(r) = read_numeric_or_omit(&n_readings); |
---|
287 | switch (r) { |
---|
288 | case Comp: q = Q_BEARING; break; |
---|
289 | case BackComp: q = Q_BACKBEARING; break; |
---|
290 | default: BUG("Unexpected case"); |
---|
291 | } |
---|
292 | VAR(r) = var(q); |
---|
293 | if (n_readings > 1) VAR(r) /= sqrt(n_readings); |
---|
294 | } |
---|
295 | |
---|
296 | extern void |
---|
297 | data_file(const char *pth, const char *fnm) |
---|
298 | { |
---|
299 | int begin_lineno_store; |
---|
300 | parse file_store; |
---|
301 | |
---|
302 | { |
---|
303 | char *filename; |
---|
304 | FILE *fh; |
---|
305 | if (!pth) { |
---|
306 | /* file specified on command line - don't do special translation */ |
---|
307 | fh = fopenWithPthAndExt(pth, fnm, EXT_SVX_DATA, "rb", &filename); |
---|
308 | } else { |
---|
309 | fh = fopen_portable(pth, fnm, EXT_SVX_DATA, "rb", &filename); |
---|
310 | } |
---|
311 | |
---|
312 | if (fh == NULL) { |
---|
313 | compile_error(/*Couldn't open data file `%s'*/24, fnm); |
---|
314 | return; |
---|
315 | } |
---|
316 | |
---|
317 | file_store = file; |
---|
318 | if (file.fh) file.parent = &file_store; |
---|
319 | file.fh = fh; |
---|
320 | file.filename = filename; |
---|
321 | file.line = 1; |
---|
322 | file.reported_where = fFalse; |
---|
323 | } |
---|
324 | |
---|
325 | if (fPercent) printf("%s:\n", fnm); |
---|
326 | |
---|
327 | using_data_file(file.filename); |
---|
328 | |
---|
329 | begin_lineno_store = pcs->begin_lineno; |
---|
330 | pcs->begin_lineno = 0; |
---|
331 | |
---|
332 | #ifndef NO_PERCENTAGE |
---|
333 | /* Try to find how long the file is... |
---|
334 | * However, under ANSI fseek( ..., SEEK_END) may not be supported */ |
---|
335 | filelen = 0; |
---|
336 | if (fPercent) { |
---|
337 | if (fseek(file.fh, 0l, SEEK_END) == 0) { |
---|
338 | filepos fp; |
---|
339 | get_pos(&fp); |
---|
340 | filelen = fp.offset; |
---|
341 | } |
---|
342 | rewind(file.fh); /* reset file ptr to start & clear any error state */ |
---|
343 | } |
---|
344 | #endif |
---|
345 | |
---|
346 | #ifdef HAVE_SETJMP_H |
---|
347 | /* errors in nested functions can longjmp here */ |
---|
348 | if (setjmp(file.jbSkipLine)) { |
---|
349 | process_eol(); |
---|
350 | } |
---|
351 | #endif |
---|
352 | |
---|
353 | while (!feof(file.fh) && !ferror(file.fh)) { |
---|
354 | if (!process_non_data_line()) { |
---|
355 | int r; |
---|
356 | #ifdef NEW3DFORMAT |
---|
357 | twig *temp = limb; |
---|
358 | #endif |
---|
359 | f_export_ok = fFalse; |
---|
360 | switch (pcs->style) { |
---|
361 | case STYLE_NORMAL: |
---|
362 | case STYLE_DIVING: |
---|
363 | case STYLE_CYLPOLAR: |
---|
364 | r = data_normal(); |
---|
365 | break; |
---|
366 | case STYLE_CARTESIAN: |
---|
367 | r = data_cartesian(); |
---|
368 | break; |
---|
369 | case STYLE_NOSURVEY: |
---|
370 | r = data_nosurvey(); |
---|
371 | break; |
---|
372 | case STYLE_IGNORE: |
---|
373 | r = data_ignore(); |
---|
374 | break; |
---|
375 | default: |
---|
376 | BUG("bad style"); |
---|
377 | } |
---|
378 | /* style function returns 0 => error */ |
---|
379 | #ifdef NEW3DFORMAT |
---|
380 | if (!r) { |
---|
381 | /* we have just created a very naughty twiglet, and it must be |
---|
382 | * punished */ |
---|
383 | osfree(limb); |
---|
384 | limb = temp; |
---|
385 | } |
---|
386 | #endif |
---|
387 | } |
---|
388 | } |
---|
389 | |
---|
390 | /* don't allow *BEGIN at the end of a file, then *EXPORT in the |
---|
391 | * including file */ |
---|
392 | f_export_ok = fFalse; |
---|
393 | |
---|
394 | #ifndef NO_PERCENTAGE |
---|
395 | if (fPercent) putnl(); |
---|
396 | #endif |
---|
397 | |
---|
398 | if (pcs->begin_lineno) { |
---|
399 | error_in_file(file.filename, pcs->begin_lineno, |
---|
400 | /*BEGIN with no matching END in this file*/23); |
---|
401 | /* Implicitly close any unclosed BEGINs from this file */ |
---|
402 | do { |
---|
403 | settings *pcsParent = pcs->next; |
---|
404 | SVX_ASSERT(pcsParent); |
---|
405 | free_settings(pcs); |
---|
406 | pcs = pcsParent; |
---|
407 | } while (pcs->begin_lineno); |
---|
408 | } |
---|
409 | |
---|
410 | pcs->begin_lineno = begin_lineno_store; |
---|
411 | |
---|
412 | if (ferror(file.fh)) |
---|
413 | fatalerror_in_file(file.filename, 0, /*Error reading file*/18); |
---|
414 | |
---|
415 | (void)fclose(file.fh); |
---|
416 | |
---|
417 | file = file_store; |
---|
418 | |
---|
419 | /* don't free this - it may be pointed to by prefix.file */ |
---|
420 | /* osfree(file.filename); */ |
---|
421 | } |
---|
422 | |
---|
423 | static real |
---|
424 | mod2pi(real a) |
---|
425 | { |
---|
426 | return a - floor(a / (2 * M_PI)) * (2 * M_PI); |
---|
427 | } |
---|
428 | |
---|
429 | static real |
---|
430 | handle_plumb(clino_type *p_ctype) |
---|
431 | { |
---|
432 | typedef enum { |
---|
433 | CLINO_NULL=-1, CLINO_UP, CLINO_DOWN, CLINO_LEVEL |
---|
434 | } clino_tok; |
---|
435 | static sztok clino_tab[] = { |
---|
436 | {"D", CLINO_DOWN}, |
---|
437 | {"DOWN", CLINO_DOWN}, |
---|
438 | {"H", CLINO_LEVEL}, |
---|
439 | {"LEVEL", CLINO_LEVEL}, |
---|
440 | {"U", CLINO_UP}, |
---|
441 | {"UP", CLINO_UP}, |
---|
442 | {NULL, CLINO_NULL} |
---|
443 | }; |
---|
444 | static real clinos[] = {(real)M_PI_2, (real)(-M_PI_2), (real)0.0}; |
---|
445 | clino_tok tok; |
---|
446 | |
---|
447 | skipblanks(); |
---|
448 | if (isalpha(ch)) { |
---|
449 | filepos fp; |
---|
450 | get_pos(&fp); |
---|
451 | get_token(); |
---|
452 | tok = match_tok(clino_tab, TABSIZE(clino_tab)); |
---|
453 | if (tok != CLINO_NULL) { |
---|
454 | *p_ctype = (clinos[tok] == CLINO_LEVEL ? CTYPE_HORIZ : CTYPE_PLUMB); |
---|
455 | return clinos[tok]; |
---|
456 | } |
---|
457 | set_pos(&fp); |
---|
458 | } else if (isSign(ch)) { |
---|
459 | int chOld = ch; |
---|
460 | nextch(); |
---|
461 | if (toupper(ch) == 'V') { |
---|
462 | nextch(); |
---|
463 | *p_ctype = CTYPE_PLUMB; |
---|
464 | return (!isMinus(chOld) ? M_PI_2 : -M_PI_2); |
---|
465 | } |
---|
466 | |
---|
467 | if (isOmit(chOld)) { |
---|
468 | *p_ctype = CTYPE_OMIT; |
---|
469 | /* no clino reading, so assume 0 with large sd */ |
---|
470 | return (real)0.0; |
---|
471 | } |
---|
472 | } else if (isOmit(ch)) { |
---|
473 | /* OMIT char may not be a SIGN char too so we need to check here as |
---|
474 | * well as above... */ |
---|
475 | nextch(); |
---|
476 | *p_ctype = CTYPE_OMIT; |
---|
477 | /* no clino reading, so assume 0 with large sd */ |
---|
478 | return (real)0.0; |
---|
479 | } |
---|
480 | return HUGE_REAL; |
---|
481 | } |
---|
482 | |
---|
483 | static void |
---|
484 | warn_readings_differ(int msg, real diff) |
---|
485 | { |
---|
486 | char buf[64]; |
---|
487 | char *p; |
---|
488 | sprintf(buf, "%.2f", deg(fabs(diff))); |
---|
489 | p = strchr(buf, '.'); |
---|
490 | if (p) { |
---|
491 | char *z = p; |
---|
492 | while (*++p) { |
---|
493 | if (*p != '0') z = p + 1; |
---|
494 | } |
---|
495 | if (*z) *z = '\0'; |
---|
496 | } |
---|
497 | compile_warning(msg, buf); |
---|
498 | } |
---|
499 | |
---|
500 | static bool |
---|
501 | handle_comp_units(void) |
---|
502 | { |
---|
503 | bool fNoComp = fTrue; |
---|
504 | if (VAL(Comp) != HUGE_REAL) { |
---|
505 | fNoComp = fFalse; |
---|
506 | VAL(Comp) *= pcs->units[Q_BEARING]; |
---|
507 | if (VAL(Comp) < (real)0.0 || VAL(Comp) - M_PI * 2.0 > EPSILON) { |
---|
508 | compile_warning(/*Suspicious compass reading*/59); |
---|
509 | VAL(Comp) = mod2pi(VAL(Comp)); |
---|
510 | } |
---|
511 | } |
---|
512 | if (VAL(BackComp) != HUGE_REAL) { |
---|
513 | fNoComp = fFalse; |
---|
514 | VAL(BackComp) *= pcs->units[Q_BACKBEARING]; |
---|
515 | if (VAL(BackComp) < (real)0.0 || VAL(BackComp) - M_PI * 2.0 > EPSILON) { |
---|
516 | /* FIXME: different message for BackComp? */ |
---|
517 | compile_warning(/*Suspicious compass reading*/59); |
---|
518 | VAL(BackComp) = mod2pi(VAL(BackComp)); |
---|
519 | } |
---|
520 | } |
---|
521 | return fNoComp; |
---|
522 | } |
---|
523 | |
---|
524 | static real |
---|
525 | handle_compass(real *p_var) |
---|
526 | { |
---|
527 | real var = VAR(Comp); |
---|
528 | real comp = VAL(Comp); |
---|
529 | real backcomp = VAL(BackComp); |
---|
530 | if (comp != HUGE_REAL) { |
---|
531 | comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING]; |
---|
532 | comp -= pcs->z[Q_DECLINATION]; |
---|
533 | } |
---|
534 | if (backcomp != HUGE_REAL) { |
---|
535 | backcomp = (backcomp - pcs->z[Q_BACKBEARING]) |
---|
536 | * pcs->sc[Q_BACKBEARING]; |
---|
537 | backcomp -= pcs->z[Q_DECLINATION]; |
---|
538 | backcomp -= M_PI; |
---|
539 | if (comp != HUGE_REAL) { |
---|
540 | real diff = comp - backcomp; |
---|
541 | real adj = fabs(diff) > M_PI ? M_PI : 0; |
---|
542 | diff -= floor((diff + M_PI) / (2 * M_PI)) * 2 * M_PI; |
---|
543 | if (sqrd(diff / 2.0) > var + VAR(Q_BACKBEARING)) { |
---|
544 | /* fore and back readings differ by more than 2 sds */ |
---|
545 | warn_readings_differ(/*Compass reading and back compass reading disagree by %s degrees*/98, diff); |
---|
546 | } |
---|
547 | comp = (comp / var + backcomp / VAR(BackComp)); |
---|
548 | var = (var + VAR(BackComp)) / 4; |
---|
549 | comp *= var; |
---|
550 | comp += adj; |
---|
551 | } else { |
---|
552 | comp = backcomp; |
---|
553 | var = VAR(BackComp); |
---|
554 | } |
---|
555 | } |
---|
556 | *p_var = var; |
---|
557 | return comp; |
---|
558 | } |
---|
559 | |
---|
560 | static int |
---|
561 | process_normal(prefix *fr, prefix *to, bool fToFirst, |
---|
562 | clino_type ctype, clino_type backctype) |
---|
563 | { |
---|
564 | real tape = VAL(Tape); |
---|
565 | real comp = VAL(Comp); |
---|
566 | real clin = VAL(Clino); |
---|
567 | real backclin = VAL(BackClino); |
---|
568 | |
---|
569 | real dx, dy, dz; |
---|
570 | real vx, vy, vz; |
---|
571 | #ifndef NO_COVARIANCES |
---|
572 | real cxy, cyz, czx; |
---|
573 | #endif |
---|
574 | |
---|
575 | bool fNoComp; |
---|
576 | |
---|
577 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
578 | if (tape < (real)0.0) { |
---|
579 | /* TRANSLATE different message for topofil? */ |
---|
580 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
581 | } |
---|
582 | |
---|
583 | fNoComp = handle_comp_units(); |
---|
584 | |
---|
585 | if (ctype == CTYPE_READING) { |
---|
586 | real diff_from_abs90; |
---|
587 | clin *= pcs->units[Q_GRADIENT]; |
---|
588 | /* percentage scale */ |
---|
589 | if (pcs->f_clino_percent) clin = atan(clin); |
---|
590 | diff_from_abs90 = fabs(clin) - M_PI_2; |
---|
591 | if (diff_from_abs90 > EPSILON) { |
---|
592 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
593 | } else if (TSTBIT(pcs->infer, INFER_PLUMBS) && |
---|
594 | diff_from_abs90 > -EPSILON) { |
---|
595 | ctype = CTYPE_PLUMB; |
---|
596 | } |
---|
597 | } |
---|
598 | |
---|
599 | if (backctype == CTYPE_READING) { |
---|
600 | real diff_from_abs90; |
---|
601 | backclin *= pcs->units[Q_BACKGRADIENT]; |
---|
602 | /* percentage scale */ |
---|
603 | if (pcs->f_backclino_percent) backclin = atan(backclin); |
---|
604 | diff_from_abs90 = fabs(backclin) - M_PI_2; |
---|
605 | if (diff_from_abs90 > EPSILON) { |
---|
606 | /* FIXME: different message for BackClino? */ |
---|
607 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
608 | } else if (TSTBIT(pcs->infer, INFER_PLUMBS) && |
---|
609 | diff_from_abs90 > -EPSILON) { |
---|
610 | backctype = CTYPE_PLUMB; |
---|
611 | } |
---|
612 | } |
---|
613 | |
---|
614 | if (ctype != CTYPE_OMIT && backctype != CTYPE_OMIT && ctype != backctype) { |
---|
615 | compile_error_skip(/*Clino and BackClino readings must be of the same type*/84); |
---|
616 | return 0; |
---|
617 | } |
---|
618 | |
---|
619 | if (ctype == CTYPE_PLUMB || backctype == CTYPE_PLUMB) { |
---|
620 | /* plumbed */ |
---|
621 | if (!fNoComp) { |
---|
622 | /* FIXME: Different message for BackComp? */ |
---|
623 | compile_warning(/*Compass reading given on plumbed leg*/21); |
---|
624 | } |
---|
625 | |
---|
626 | dx = dy = (real)0.0; |
---|
627 | if (ctype != CTYPE_OMIT) { |
---|
628 | if (backctype != CTYPE_OMIT && (clin > 0) == (backclin > 0)) { |
---|
629 | /* We've got two UPs or two DOWNs - FIXME: not ideal message */ |
---|
630 | compile_error_skip(/*Clino and BackClino readings must be of the same type*/84); |
---|
631 | return 0; |
---|
632 | } |
---|
633 | dz = (clin > (real)0.0) ? tape : -tape; |
---|
634 | } else { |
---|
635 | dz = (backclin < (real)0.0) ? tape : -tape; |
---|
636 | } |
---|
637 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
638 | vz = var(Q_POS) / 3.0 + VAR(Tape); |
---|
639 | #ifndef NO_COVARIANCES |
---|
640 | /* Correct values - no covariances in this case! */ |
---|
641 | cxy = cyz = czx = (real)0.0; |
---|
642 | #endif |
---|
643 | } else { |
---|
644 | /* Each of ctype and backctype are either CTYPE_READING/CTYPE_HORIZ |
---|
645 | * or CTYPE_OMIT */ |
---|
646 | /* clino */ |
---|
647 | real L2, cosG, LcosG, cosG2, sinB, cosB, dx2, dy2, dz2, v, V; |
---|
648 | if (fNoComp) { |
---|
649 | compile_error_skip(/*Compass reading may not be omitted except on plumbed legs*/14); |
---|
650 | return 0; |
---|
651 | } |
---|
652 | if (tape == (real)0.0) { |
---|
653 | dx = dy = dz = (real)0.0; |
---|
654 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
655 | #ifndef NO_COVARIANCES |
---|
656 | cxy = cyz = czx = (real)0.0; |
---|
657 | #endif |
---|
658 | #if DEBUG_DATAIN_1 |
---|
659 | printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
660 | #endif |
---|
661 | } else { |
---|
662 | real sinGcosG; |
---|
663 | /* take into account variance in LEVEL case */ |
---|
664 | real var_clin = var(Q_LEVEL); |
---|
665 | real var_comp; |
---|
666 | real comp = handle_compass(&var_comp); |
---|
667 | /* ctype != CTYPE_READING is LEVEL case */ |
---|
668 | if (ctype == CTYPE_READING) { |
---|
669 | clin = (clin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT]; |
---|
670 | var_clin = VAR(Clino); |
---|
671 | } |
---|
672 | if (backctype == CTYPE_READING) { |
---|
673 | backclin = (backclin - pcs->z[Q_BACKGRADIENT]) |
---|
674 | * pcs->sc[Q_BACKGRADIENT]; |
---|
675 | if (ctype == CTYPE_READING) { |
---|
676 | if (sqrd((clin + backclin) / 3.0) > |
---|
677 | var_clin + VAR(BackClino)) { |
---|
678 | /* fore and back readings differ by more than 3 sds */ |
---|
679 | warn_readings_differ(/*Clino reading and back clino reading disagree by %s degrees*/99, clin + backclin); |
---|
680 | } |
---|
681 | clin = (clin / var_clin - backclin / VAR(BackClino)); |
---|
682 | var_clin = (var_clin + VAR(BackClino)) / 4; |
---|
683 | clin *= var_clin; |
---|
684 | } else { |
---|
685 | clin = -backclin; |
---|
686 | var_clin = VAR(BackClino); |
---|
687 | } |
---|
688 | } |
---|
689 | |
---|
690 | #if DEBUG_DATAIN |
---|
691 | printf(" %4.2f %4.2f %4.2f\n", tape, comp, clin); |
---|
692 | #endif |
---|
693 | cosG = cos(clin); |
---|
694 | LcosG = tape * cosG; |
---|
695 | sinB = sin(comp); |
---|
696 | cosB = cos(comp); |
---|
697 | #if DEBUG_DATAIN_1 |
---|
698 | printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB, cosG, LcosG); |
---|
699 | #endif |
---|
700 | dx = LcosG * sinB; |
---|
701 | dy = LcosG * cosB; |
---|
702 | dz = tape * sin(clin); |
---|
703 | /* printf("%.2f\n",clin); */ |
---|
704 | #if DEBUG_DATAIN_1 |
---|
705 | printf("dx = %f\ndy = %f\ndz = %f\n", dx, dy, dz); |
---|
706 | #endif |
---|
707 | dx2 = dx * dx; |
---|
708 | L2 = tape * tape; |
---|
709 | V = VAR(Tape) / L2; |
---|
710 | dy2 = dy * dy; |
---|
711 | cosG2 = cosG * cosG; |
---|
712 | sinGcosG = sin(clin) * cosG; |
---|
713 | dz2 = dz * dz; |
---|
714 | v = dz2 * var_clin; |
---|
715 | #ifdef NO_COVARIANCES |
---|
716 | vx = (var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp + |
---|
717 | (.5 + sinB * sinB * cosG2) * v); |
---|
718 | vy = (var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp + |
---|
719 | (.5 + cosB * cosB * cosG2) * v); |
---|
720 | if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) { |
---|
721 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
722 | vz = var(Q_POS) / 3.0 + L2 * (real)0.1; |
---|
723 | } else { |
---|
724 | vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin; |
---|
725 | } |
---|
726 | /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */ |
---|
727 | #else |
---|
728 | vx = var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp + |
---|
729 | (sinB * sinB * v); |
---|
730 | vy = var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp + |
---|
731 | (cosB * cosB * v); |
---|
732 | if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) { |
---|
733 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
734 | vz = var(Q_POS) / 3.0 + L2 * (real)0.1; |
---|
735 | } else { |
---|
736 | vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin; |
---|
737 | } |
---|
738 | /* usual covariance formulae are fine in no clino case since |
---|
739 | * dz = 0 so value of var_clin is ignored */ |
---|
740 | cxy = sinB * cosB * (VAR(Tape) * cosG2 + var_clin * dz2) |
---|
741 | - var_comp * dx * dy; |
---|
742 | czx = VAR(Tape) * sinB * sinGcosG - var_clin * dx * dz; |
---|
743 | cyz = VAR(Tape) * cosB * sinGcosG - var_clin * dy * dz; |
---|
744 | #if 0 |
---|
745 | printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx, vy, vz); |
---|
746 | printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy, cyz, czx); |
---|
747 | #endif |
---|
748 | #endif |
---|
749 | #if DEBUG_DATAIN_1 |
---|
750 | printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
751 | #endif |
---|
752 | } |
---|
753 | } |
---|
754 | #if DEBUG_DATAIN_1 |
---|
755 | printf("Just before addleg, vx = %f\n", vx); |
---|
756 | #endif |
---|
757 | /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/ |
---|
758 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
759 | #ifndef NO_COVARIANCES |
---|
760 | , cyz, czx, cxy |
---|
761 | #endif |
---|
762 | ); |
---|
763 | |
---|
764 | #ifdef NEW3DFORMAT |
---|
765 | if (fUseNewFormat) { |
---|
766 | /* new twiglet and insert into twig tree */ |
---|
767 | twig *twiglet = osnew(twig); |
---|
768 | twiglet->from = fr; |
---|
769 | twiglet->to = to; |
---|
770 | twiglet->down = twiglet->right = NULL; |
---|
771 | twiglet->source = twiglet->drawings |
---|
772 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
773 | twiglet->up = limb->up; |
---|
774 | limb->right = twiglet; |
---|
775 | limb = twiglet; |
---|
776 | |
---|
777 | /* record pre-fettling deltas */ |
---|
778 | twiglet->delta[0] = dx; |
---|
779 | twiglet->delta[1] = dy; |
---|
780 | twiglet->delta[2] = dz; |
---|
781 | } |
---|
782 | #endif |
---|
783 | return 1; |
---|
784 | } |
---|
785 | |
---|
786 | static int |
---|
787 | process_diving(prefix *fr, prefix *to, bool fToFirst, bool fDepthChange) |
---|
788 | { |
---|
789 | real tape = VAL(Tape); |
---|
790 | |
---|
791 | real dx, dy, dz; |
---|
792 | real vx, vy, vz; |
---|
793 | #ifndef NO_COVARIANCES |
---|
794 | real cxy = 0, cyz = 0, czx = 0; |
---|
795 | #endif |
---|
796 | |
---|
797 | handle_comp_units(); |
---|
798 | |
---|
799 | /* depth gauge readings increase upwards with default calibration */ |
---|
800 | if (fDepthChange) { |
---|
801 | SVX_ASSERT(VAL(FrDepth) == 0.0); |
---|
802 | dz = VAL(ToDepth) * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]; |
---|
803 | dz *= pcs->sc[Q_DEPTH]; |
---|
804 | } else { |
---|
805 | dz = VAL(ToDepth) - VAL(FrDepth); |
---|
806 | dz *= pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
807 | } |
---|
808 | |
---|
809 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
810 | if (tape < (real)0.0) { |
---|
811 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
812 | } |
---|
813 | |
---|
814 | /* check if tape is less than depth change */ |
---|
815 | if (tape < fabs(dz)) { |
---|
816 | /* FIXME: allow margin of error based on variances? */ |
---|
817 | compile_warning(/*Tape reading is less than change in depth*/62); |
---|
818 | } |
---|
819 | |
---|
820 | if (tape == (real)0.0 && dz == 0.0) { |
---|
821 | dx = dy = dz = (real)0.0; |
---|
822 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
823 | } else if (VAL(Comp) == HUGE_REAL && |
---|
824 | VAL(BackComp) == HUGE_REAL) { |
---|
825 | /* plumb */ |
---|
826 | dx = dy = (real)0.0; |
---|
827 | if (dz < 0) tape = -tape; |
---|
828 | /* FIXME: Should use FrDepth sometimes... */ |
---|
829 | dz = (dz * VAR(Tape) + tape * 2 * VAR(ToDepth)) |
---|
830 | / (VAR(Tape) * 2 * VAR(ToDepth)); |
---|
831 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
832 | /* FIXME: Should use FrDepth sometimes... */ |
---|
833 | vz = var(Q_POS) / 3.0 + VAR(Tape) * 2 * VAR(ToDepth) |
---|
834 | / (VAR(Tape) + VAR(ToDepth)); |
---|
835 | } else { |
---|
836 | real L2, sinB, cosB, dz2, D2; |
---|
837 | real var_comp; |
---|
838 | real comp = handle_compass(&var_comp); |
---|
839 | sinB = sin(comp); |
---|
840 | cosB = cos(comp); |
---|
841 | L2 = tape * tape; |
---|
842 | dz2 = dz * dz; |
---|
843 | D2 = L2 - dz2; |
---|
844 | if (D2 <= (real)0.0) { |
---|
845 | /* FIXME: Should use FrDepth sometimes... */ |
---|
846 | real vsum = VAR(Tape) + 2 * VAR(ToDepth); |
---|
847 | dx = dy = (real)0.0; |
---|
848 | vx = vy = var(Q_POS) / 3.0; |
---|
849 | /* FIXME: Should use FrDepth sometimes... */ |
---|
850 | vz = var(Q_POS) / 3.0 + VAR(Tape) * 2 * VAR(ToDepth) / vsum; |
---|
851 | if (dz > 0) { |
---|
852 | /* FIXME: Should use FrDepth sometimes... */ |
---|
853 | dz = (dz * VAR(Tape) + tape * 2 * VAR(ToDepth)) / vsum; |
---|
854 | } else { |
---|
855 | dz = (dz * VAR(Tape) - tape * 2 * VAR(ToDepth)) / vsum; |
---|
856 | } |
---|
857 | } else { |
---|
858 | real D = sqrt(D2); |
---|
859 | /* FIXME: Should use FrDepth sometimes... */ |
---|
860 | real F = VAR(Tape) * L2 + 2 * VAR(ToDepth) * D2; |
---|
861 | dx = D * sinB; |
---|
862 | dy = D * cosB; |
---|
863 | |
---|
864 | vx = var(Q_POS) / 3.0 + |
---|
865 | sinB * sinB * F / D2 + var_comp * dy * dy; |
---|
866 | vy = var(Q_POS) / 3.0 + |
---|
867 | cosB * cosB * F / D2 + var_comp * dx * dx; |
---|
868 | /* FIXME: Should use FrDepth sometimes... */ |
---|
869 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
870 | |
---|
871 | #ifndef NO_COVARIANCES |
---|
872 | cxy = sinB * cosB * (F / D2 + var_comp * D2); |
---|
873 | /* FIXME: Should use FrDepth sometimes... */ |
---|
874 | cyz = -2 * VAR(ToDepth) * dy / D; |
---|
875 | czx = -2 * VAR(ToDepth) * dx / D; |
---|
876 | #endif |
---|
877 | } |
---|
878 | } |
---|
879 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
880 | #ifndef NO_COVARIANCES |
---|
881 | , cxy, cyz, czx |
---|
882 | #endif |
---|
883 | ); |
---|
884 | #ifdef NEW3DFORMAT |
---|
885 | if (fUseNewFormat) { |
---|
886 | /*new twiglet and insert into twig tree*/ |
---|
887 | twig *twiglet = osnew(twig); |
---|
888 | twiglet->from = fr; |
---|
889 | twiglet->to = to; |
---|
890 | twiglet->down = twiglet->right = NULL; |
---|
891 | twiglet->source = twiglet->drawings |
---|
892 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
893 | twiglet->up = limb->up; |
---|
894 | limb->right = twiglet; |
---|
895 | limb = twiglet; |
---|
896 | |
---|
897 | /* record pre-fettling deltas */ |
---|
898 | twiglet->delta[0] = dx; |
---|
899 | twiglet->delta[1] = dy; |
---|
900 | twiglet->delta[2] = dz; |
---|
901 | } |
---|
902 | #endif |
---|
903 | |
---|
904 | return 1; |
---|
905 | } |
---|
906 | |
---|
907 | static int |
---|
908 | process_cartesian(prefix *fr, prefix *to, bool fToFirst) |
---|
909 | { |
---|
910 | real dx = (VAL(Dx) * pcs->units[Q_DX] - pcs->z[Q_DX]) * pcs->sc[Q_DX]; |
---|
911 | real dy = (VAL(Dy) * pcs->units[Q_DY] - pcs->z[Q_DY]) * pcs->sc[Q_DY]; |
---|
912 | real dz = (VAL(Dz) * pcs->units[Q_DZ] - pcs->z[Q_DZ]) * pcs->sc[Q_DZ]; |
---|
913 | |
---|
914 | addlegbyname(fr, to, fToFirst, dx, dy, dz, VAR(Dx), VAR(Dy), VAR(Dz) |
---|
915 | #ifndef NO_COVARIANCES |
---|
916 | , 0, 0, 0 |
---|
917 | #endif |
---|
918 | ); |
---|
919 | |
---|
920 | #ifdef NEW3DFORMAT |
---|
921 | if (fUseNewFormat) { |
---|
922 | /* new twiglet and insert into twig tree */ |
---|
923 | twig *twiglet = osnew(twig); |
---|
924 | twiglet->from = fr; |
---|
925 | twiglet->to = to; |
---|
926 | twiglet->down = twiglet->right = NULL; |
---|
927 | twiglet->source = twiglet->drawings |
---|
928 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
929 | twiglet->up = limb->up; |
---|
930 | limb->right = twiglet; |
---|
931 | limb = twiglet; |
---|
932 | |
---|
933 | /* record pre-fettling deltas */ |
---|
934 | twiglet->delta[0] = dx; |
---|
935 | twiglet->delta[1] = dy; |
---|
936 | twiglet->delta[2] = dz; |
---|
937 | } |
---|
938 | #endif |
---|
939 | |
---|
940 | return 1; |
---|
941 | } |
---|
942 | |
---|
943 | extern int |
---|
944 | data_cartesian(void) |
---|
945 | { |
---|
946 | prefix *fr = NULL, *to = NULL; |
---|
947 | |
---|
948 | bool fMulti = fFalse; |
---|
949 | |
---|
950 | reading first_stn = End; |
---|
951 | |
---|
952 | reading *ordering; |
---|
953 | |
---|
954 | again: |
---|
955 | |
---|
956 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
957 | skipblanks(); |
---|
958 | switch (*ordering) { |
---|
959 | case Fr: |
---|
960 | fr = read_prefix_stn(fFalse, fTrue); |
---|
961 | if (first_stn == End) first_stn = Fr; |
---|
962 | break; |
---|
963 | case To: |
---|
964 | to = read_prefix_stn(fFalse, fTrue); |
---|
965 | if (first_stn == End) first_stn = To; |
---|
966 | break; |
---|
967 | case Station: |
---|
968 | fr = to; |
---|
969 | to = read_prefix_stn(fFalse, fFalse); |
---|
970 | first_stn = To; |
---|
971 | break; |
---|
972 | case Dx: case Dy: case Dz: |
---|
973 | read_reading(*ordering, fFalse); |
---|
974 | break; |
---|
975 | case Ignore: |
---|
976 | skipword(); break; |
---|
977 | case IgnoreAllAndNewLine: |
---|
978 | skipline(); |
---|
979 | /* fall through */ |
---|
980 | case Newline: |
---|
981 | if (fr != NULL) { |
---|
982 | int r; |
---|
983 | r = process_cartesian(fr, to, first_stn == To); |
---|
984 | if (!r) skipline(); |
---|
985 | } |
---|
986 | fMulti = fTrue; |
---|
987 | while (1) { |
---|
988 | process_eol(); |
---|
989 | process_bol(); |
---|
990 | if (isData(ch)) break; |
---|
991 | if (!isComm(ch)) { |
---|
992 | push_back(ch); |
---|
993 | return 1; |
---|
994 | } |
---|
995 | } |
---|
996 | break; |
---|
997 | case IgnoreAll: |
---|
998 | skipline(); |
---|
999 | /* fall through */ |
---|
1000 | case End: |
---|
1001 | if (!fMulti) { |
---|
1002 | int r = process_cartesian(fr, to, first_stn == To); |
---|
1003 | process_eol(); |
---|
1004 | return r; |
---|
1005 | } |
---|
1006 | do { |
---|
1007 | process_eol(); |
---|
1008 | process_bol(); |
---|
1009 | } while (isComm(ch)); |
---|
1010 | goto again; |
---|
1011 | default: BUG("Unknown reading in ordering"); |
---|
1012 | } |
---|
1013 | } |
---|
1014 | } |
---|
1015 | |
---|
1016 | static int |
---|
1017 | process_cylpolar(prefix *fr, prefix *to, bool fToFirst, bool fDepthChange) |
---|
1018 | { |
---|
1019 | real tape = VAL(Tape); |
---|
1020 | real frdepth = VAL(FrDepth); |
---|
1021 | real todepth = VAL(ToDepth); |
---|
1022 | |
---|
1023 | real dx, dy, dz; |
---|
1024 | real vx, vy, vz; |
---|
1025 | #ifndef NO_COVARIANCES |
---|
1026 | real cxy = 0; |
---|
1027 | #endif |
---|
1028 | |
---|
1029 | handle_comp_units(); |
---|
1030 | |
---|
1031 | /* depth gauge readings increase upwards with default calibration */ |
---|
1032 | if (fDepthChange) { |
---|
1033 | SVX_ASSERT(VAL(FrDepth) == 0.0); |
---|
1034 | dz = VAL(ToDepth) * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]; |
---|
1035 | dz *= pcs->sc[Q_DEPTH]; |
---|
1036 | } else { |
---|
1037 | dz = VAL(ToDepth) - VAL(FrDepth); |
---|
1038 | dz *= pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
1039 | } |
---|
1040 | |
---|
1041 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
1042 | if (tape < (real)0.0) { |
---|
1043 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
1044 | } |
---|
1045 | |
---|
1046 | if (VAL(Comp) == HUGE_REAL && VAL(BackComp) == HUGE_REAL) { |
---|
1047 | /* plumb */ |
---|
1048 | dx = dy = (real)0.0; |
---|
1049 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
1050 | /* FIXME: Should use FrDepth sometimes... */ |
---|
1051 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
1052 | } else { |
---|
1053 | real sinB, cosB; |
---|
1054 | real var_comp; |
---|
1055 | real comp = handle_compass(&var_comp); |
---|
1056 | sinB = sin(comp); |
---|
1057 | cosB = cos(comp); |
---|
1058 | |
---|
1059 | dx = tape * sinB; |
---|
1060 | dy = tape * cosB; |
---|
1061 | |
---|
1062 | vx = var(Q_POS) / 3.0 + |
---|
1063 | VAR(Tape) * sinB * sinB + var_comp * dy * dy; |
---|
1064 | vy = var(Q_POS) / 3.0 + |
---|
1065 | VAR(Tape) * cosB * cosB + var_comp * dx * dx; |
---|
1066 | /* FIXME: Should use FrDepth sometimes... */ |
---|
1067 | vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth); |
---|
1068 | |
---|
1069 | #ifndef NO_COVARIANCES |
---|
1070 | cxy = (VAR(Tape) - var_comp * tape * tape) * sinB * cosB; |
---|
1071 | #endif |
---|
1072 | } |
---|
1073 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
1074 | #ifndef NO_COVARIANCES |
---|
1075 | , cxy, 0, 0 |
---|
1076 | #endif |
---|
1077 | ); |
---|
1078 | #ifdef NEW3DFORMAT |
---|
1079 | if (fUseNewFormat) { |
---|
1080 | /*new twiglet and insert into twig tree*/ |
---|
1081 | twig *twiglet = osnew(twig); |
---|
1082 | twiglet->from = fr; |
---|
1083 | twiglet->to = to; |
---|
1084 | twiglet->down = twiglet->right = NULL; |
---|
1085 | twiglet->source = twiglet->drawings |
---|
1086 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
1087 | twiglet->up = limb->up; |
---|
1088 | limb->right = twiglet; |
---|
1089 | limb = twiglet; |
---|
1090 | |
---|
1091 | /* record pre-fettling deltas */ |
---|
1092 | twiglet->delta[0] = dx; |
---|
1093 | twiglet->delta[1] = dy; |
---|
1094 | twiglet->delta[2] = dz; |
---|
1095 | } |
---|
1096 | #endif |
---|
1097 | |
---|
1098 | return 1; |
---|
1099 | } |
---|
1100 | |
---|
1101 | /* Process tape/compass/clino, diving, and cylpolar styles of survey data |
---|
1102 | * Also handles topofil (fromcount/tocount or count) in place of tape */ |
---|
1103 | extern int |
---|
1104 | data_normal(void) |
---|
1105 | { |
---|
1106 | prefix *fr = NULL, *to = NULL; |
---|
1107 | reading first_stn = End; |
---|
1108 | |
---|
1109 | bool fTopofil = fFalse, fMulti = fFalse; |
---|
1110 | bool fRev; |
---|
1111 | clino_type ctype, backctype; |
---|
1112 | bool fDepthChange; |
---|
1113 | |
---|
1114 | reading *ordering; |
---|
1115 | |
---|
1116 | VAL(Tape) = 0; |
---|
1117 | VAL(Comp) = VAL(BackComp) = HUGE_VAL; |
---|
1118 | VAL(FrCount) = VAL(ToCount) = 0; |
---|
1119 | VAL(FrDepth) = VAL(ToDepth) = 0; |
---|
1120 | |
---|
1121 | fRev = fFalse; |
---|
1122 | ctype = backctype = CTYPE_OMIT; |
---|
1123 | fDepthChange = fFalse; |
---|
1124 | |
---|
1125 | /* ordering may omit clino reading, so set up default here */ |
---|
1126 | /* this is also used if clino reading is the omit character */ |
---|
1127 | VAL(Clino) = VAL(BackClino) = 0; |
---|
1128 | |
---|
1129 | again: |
---|
1130 | |
---|
1131 | for (ordering = pcs->ordering; ; ordering++) { |
---|
1132 | skipblanks(); |
---|
1133 | switch (*ordering) { |
---|
1134 | case Fr: |
---|
1135 | fr = read_prefix_stn(fFalse, fTrue); |
---|
1136 | if (first_stn == End) first_stn = Fr; |
---|
1137 | break; |
---|
1138 | case To: |
---|
1139 | to = read_prefix_stn(fFalse, fTrue); |
---|
1140 | if (first_stn == End) first_stn = To; |
---|
1141 | break; |
---|
1142 | case Station: |
---|
1143 | fr = to; |
---|
1144 | to = read_prefix_stn(fFalse, fFalse); |
---|
1145 | first_stn = To; |
---|
1146 | break; |
---|
1147 | case Dir: { |
---|
1148 | typedef enum { |
---|
1149 | DIR_NULL=-1, DIR_FORE, DIR_BACK |
---|
1150 | } dir_tok; |
---|
1151 | static sztok dir_tab[] = { |
---|
1152 | {"B", DIR_BACK}, |
---|
1153 | {"F", DIR_FORE}, |
---|
1154 | }; |
---|
1155 | dir_tok tok; |
---|
1156 | get_token(); |
---|
1157 | tok = match_tok(dir_tab, TABSIZE(dir_tab)); |
---|
1158 | switch (tok) { |
---|
1159 | case DIR_FORE: |
---|
1160 | break; |
---|
1161 | case DIR_BACK: |
---|
1162 | fRev = fTrue; |
---|
1163 | break; |
---|
1164 | default: |
---|
1165 | compile_error_skip(/*Found `%s', expecting `F' or `B'*/131, |
---|
1166 | buffer); |
---|
1167 | process_eol(); |
---|
1168 | return 0; |
---|
1169 | } |
---|
1170 | break; |
---|
1171 | } |
---|
1172 | case Tape: |
---|
1173 | read_reading(Tape, fFalse); |
---|
1174 | if (VAL(Tape) < (real)0.0) |
---|
1175 | compile_warning(/*Negative tape reading*/60); |
---|
1176 | break; |
---|
1177 | case Count: |
---|
1178 | VAL(FrCount) = VAL(ToCount); |
---|
1179 | read_reading(ToCount, fFalse); |
---|
1180 | break; |
---|
1181 | case FrCount: |
---|
1182 | read_reading(FrCount, fFalse); |
---|
1183 | break; |
---|
1184 | case ToCount: |
---|
1185 | read_reading(ToCount, fFalse); |
---|
1186 | fTopofil = fTrue; |
---|
1187 | break; |
---|
1188 | case Comp: |
---|
1189 | read_bearing_or_omit(Comp); |
---|
1190 | break; |
---|
1191 | case BackComp: |
---|
1192 | read_bearing_or_omit(BackComp); |
---|
1193 | break; |
---|
1194 | case Clino: |
---|
1195 | read_reading(Clino, fTrue); |
---|
1196 | if (VAL(Clino) == HUGE_REAL) { |
---|
1197 | VAL(Clino) = handle_plumb(&ctype); |
---|
1198 | if (VAL(Clino) != HUGE_REAL) break; |
---|
1199 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
1200 | process_eol(); |
---|
1201 | return 0; |
---|
1202 | } |
---|
1203 | ctype = CTYPE_READING; |
---|
1204 | break; |
---|
1205 | case BackClino: |
---|
1206 | read_reading(BackClino, fTrue); |
---|
1207 | if (VAL(BackClino) == HUGE_REAL) { |
---|
1208 | VAL(BackClino) = handle_plumb(&backctype); |
---|
1209 | if (VAL(BackClino) != HUGE_REAL) break; |
---|
1210 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
1211 | process_eol(); |
---|
1212 | return 0; |
---|
1213 | } |
---|
1214 | backctype = CTYPE_READING; |
---|
1215 | break; |
---|
1216 | case FrDepth: |
---|
1217 | read_reading(FrDepth, fFalse); |
---|
1218 | break; |
---|
1219 | case ToDepth: |
---|
1220 | read_reading(ToDepth, fFalse); |
---|
1221 | break; |
---|
1222 | case Depth: |
---|
1223 | VAL(FrDepth) = VAL(ToDepth); |
---|
1224 | read_reading(ToDepth, fFalse); |
---|
1225 | break; |
---|
1226 | case DepthChange: |
---|
1227 | fDepthChange = fTrue; |
---|
1228 | VAL(FrDepth) = 0; |
---|
1229 | read_reading(ToDepth, fFalse); |
---|
1230 | break; |
---|
1231 | case Ignore: |
---|
1232 | skipword(); |
---|
1233 | break; |
---|
1234 | case IgnoreAllAndNewLine: |
---|
1235 | skipline(); |
---|
1236 | /* fall through */ |
---|
1237 | case Newline: |
---|
1238 | if (fr != NULL) { |
---|
1239 | int r; |
---|
1240 | if (fTopofil) |
---|
1241 | VAL(Tape) = VAL(ToCount) - VAL(FrCount); |
---|
1242 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
1243 | * (frdepth always zero, todepth is change of depth) and also |
---|
1244 | * works for STYLE_NORMAL (both remain 0) */ |
---|
1245 | if (TSTBIT(pcs->infer, INFER_EQUATES) && |
---|
1246 | VAL(Tape) == (real)0.0 && VAL(FrDepth) == VAL(ToDepth)) { |
---|
1247 | process_equate(fr, to); |
---|
1248 | goto inferred_equate; |
---|
1249 | } |
---|
1250 | if (fRev) { |
---|
1251 | prefix *t = fr; |
---|
1252 | fr = to; |
---|
1253 | to = t; |
---|
1254 | } |
---|
1255 | if (fTopofil) { |
---|
1256 | VAL(Tape) *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
1257 | } else { |
---|
1258 | VAL(Tape) *= pcs->units[Q_LENGTH]; |
---|
1259 | VAL(Tape) -= pcs->z[Q_LENGTH]; |
---|
1260 | VAL(Tape) *= pcs->sc[Q_LENGTH]; |
---|
1261 | } |
---|
1262 | switch (pcs->style) { |
---|
1263 | case STYLE_NORMAL: |
---|
1264 | r = process_normal(fr, to, (first_stn == To) ^ fRev, |
---|
1265 | ctype, backctype); |
---|
1266 | break; |
---|
1267 | case STYLE_DIVING: |
---|
1268 | r = process_diving(fr, to, (first_stn == To) ^ fRev, |
---|
1269 | fDepthChange); |
---|
1270 | break; |
---|
1271 | case STYLE_CYLPOLAR: |
---|
1272 | r = process_cylpolar(fr, to, (first_stn == To) ^ fRev, |
---|
1273 | fDepthChange); |
---|
1274 | break; |
---|
1275 | default: |
---|
1276 | BUG("bad style"); |
---|
1277 | } |
---|
1278 | if (!r) skipline(); |
---|
1279 | |
---|
1280 | /* Swap fr and to back to how they were for next line */ |
---|
1281 | if (fRev) { |
---|
1282 | prefix *t = fr; |
---|
1283 | fr = to; |
---|
1284 | to = t; |
---|
1285 | } |
---|
1286 | } |
---|
1287 | |
---|
1288 | fRev = fFalse; |
---|
1289 | ctype = backctype = CTYPE_OMIT; |
---|
1290 | fDepthChange = fFalse; |
---|
1291 | |
---|
1292 | /* ordering may omit clino reading, so set up default here */ |
---|
1293 | /* this is also used if clino reading is the omit character */ |
---|
1294 | VAL(Clino) = VAL(BackClino) = 0; |
---|
1295 | |
---|
1296 | inferred_equate: |
---|
1297 | |
---|
1298 | fMulti = fTrue; |
---|
1299 | while (1) { |
---|
1300 | process_eol(); |
---|
1301 | process_bol(); |
---|
1302 | if (isData(ch)) break; |
---|
1303 | if (!isComm(ch)) { |
---|
1304 | push_back(ch); |
---|
1305 | return 1; |
---|
1306 | } |
---|
1307 | } |
---|
1308 | break; |
---|
1309 | case IgnoreAll: |
---|
1310 | skipline(); |
---|
1311 | /* fall through */ |
---|
1312 | case End: |
---|
1313 | if (!fMulti) { |
---|
1314 | int r; |
---|
1315 | if (fRev) { |
---|
1316 | prefix *t = fr; |
---|
1317 | fr = to; |
---|
1318 | to = t; |
---|
1319 | } |
---|
1320 | if (fTopofil) VAL(Tape) = VAL(ToCount) - VAL(FrCount); |
---|
1321 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
1322 | * (frdepth always zero, todepth is change of depth) and also |
---|
1323 | * works for STYLE_NORMAL (both remain 0) */ |
---|
1324 | if (TSTBIT(pcs->infer, INFER_EQUATES) && |
---|
1325 | VAL(Tape) == (real)0.0 && VAL(FrDepth) == VAL(ToDepth)) { |
---|
1326 | process_equate(fr, to); |
---|
1327 | process_eol(); |
---|
1328 | return 1; |
---|
1329 | } |
---|
1330 | if (fTopofil) { |
---|
1331 | VAL(Tape) *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
1332 | } else { |
---|
1333 | VAL(Tape) *= pcs->units[Q_LENGTH]; |
---|
1334 | VAL(Tape) -= pcs->z[Q_LENGTH]; |
---|
1335 | VAL(Tape) *= pcs->sc[Q_LENGTH]; |
---|
1336 | } |
---|
1337 | switch (pcs->style) { |
---|
1338 | case STYLE_NORMAL: |
---|
1339 | r = process_normal(fr, to, (first_stn == To) ^ fRev, |
---|
1340 | ctype, backctype); |
---|
1341 | break; |
---|
1342 | case STYLE_DIVING: |
---|
1343 | r = process_diving(fr, to, (first_stn == To) ^ fRev, |
---|
1344 | fDepthChange); |
---|
1345 | break; |
---|
1346 | case STYLE_CYLPOLAR: |
---|
1347 | r = process_cylpolar(fr, to, (first_stn == To) ^ fRev, |
---|
1348 | fDepthChange); |
---|
1349 | break; |
---|
1350 | default: |
---|
1351 | BUG("bad style"); |
---|
1352 | } |
---|
1353 | process_eol(); |
---|
1354 | return r; |
---|
1355 | } |
---|
1356 | do { |
---|
1357 | process_eol(); |
---|
1358 | process_bol(); |
---|
1359 | } while (isComm(ch)); |
---|
1360 | goto again; |
---|
1361 | default: |
---|
1362 | BUG("Unknown reading in ordering"); |
---|
1363 | } |
---|
1364 | } |
---|
1365 | } |
---|
1366 | |
---|
1367 | static int |
---|
1368 | process_nosurvey(prefix *fr, prefix *to, bool fToFirst) |
---|
1369 | { |
---|
1370 | nosurveylink *link; |
---|
1371 | int shape; |
---|
1372 | |
---|
1373 | #ifdef NEW3DFORMAT |
---|
1374 | if (fUseNewFormat) { |
---|
1375 | /* new twiglet and insert into twig tree */ |
---|
1376 | twig *twiglet = osnew(twig); |
---|
1377 | twiglet->from = fr; |
---|
1378 | twiglet->to = to; |
---|
1379 | twiglet->down = twiglet->right = NULL; |
---|
1380 | twiglet->source = twiglet->drawings |
---|
1381 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
1382 | twiglet->up = limb->up; |
---|
1383 | limb->right = twiglet; |
---|
1384 | limb = twiglet; |
---|
1385 | /* delta is only used to calculate error - pass zero and cope |
---|
1386 | * elsewhere */ |
---|
1387 | twiglet->delta[0] = twiglet->delta[1] = twiglet->delta[2] = 0; |
---|
1388 | } |
---|
1389 | #endif |
---|
1390 | |
---|
1391 | /* Suppress "unused fixed point" warnings for these stations |
---|
1392 | * We do this if it's a 0 or 1 node - 1 node might be an sdfix |
---|
1393 | */ |
---|
1394 | shape = fr->shape; |
---|
1395 | if (shape == 0 || shape == 1) fr->shape = -1 - shape; |
---|
1396 | shape = to->shape; |
---|
1397 | if (shape == 0 || shape == 1) to->shape = -1 - shape; |
---|
1398 | |
---|
1399 | /* add to linked list which is dealt with after network is solved */ |
---|
1400 | link = osnew(nosurveylink); |
---|
1401 | if (fToFirst) { |
---|
1402 | link->to = StnFromPfx(to); |
---|
1403 | link->fr = StnFromPfx(fr); |
---|
1404 | } else { |
---|
1405 | link->fr = StnFromPfx(fr); |
---|
1406 | link->to = StnFromPfx(to); |
---|
1407 | } |
---|
1408 | link->flags = pcs->flags; |
---|
1409 | link->next = nosurveyhead; |
---|
1410 | nosurveyhead = link; |
---|
1411 | return 1; |
---|
1412 | } |
---|
1413 | |
---|
1414 | extern int |
---|
1415 | data_nosurvey(void) |
---|
1416 | { |
---|
1417 | prefix *fr = NULL, *to = NULL; |
---|
1418 | |
---|
1419 | bool fMulti = fFalse; |
---|
1420 | |
---|
1421 | reading first_stn = End; |
---|
1422 | |
---|
1423 | reading *ordering; |
---|
1424 | |
---|
1425 | again: |
---|
1426 | |
---|
1427 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
1428 | skipblanks(); |
---|
1429 | switch (*ordering) { |
---|
1430 | case Fr: |
---|
1431 | fr = read_prefix_stn(fFalse, fTrue); |
---|
1432 | if (first_stn == End) first_stn = Fr; |
---|
1433 | break; |
---|
1434 | case To: |
---|
1435 | to = read_prefix_stn(fFalse, fTrue); |
---|
1436 | if (first_stn == End) first_stn = To; |
---|
1437 | break; |
---|
1438 | case Station: |
---|
1439 | fr = to; |
---|
1440 | to = read_prefix_stn(fFalse, fFalse); |
---|
1441 | first_stn = To; |
---|
1442 | break; |
---|
1443 | case Ignore: |
---|
1444 | skipword(); break; |
---|
1445 | case IgnoreAllAndNewLine: |
---|
1446 | skipline(); |
---|
1447 | /* fall through */ |
---|
1448 | case Newline: |
---|
1449 | if (fr != NULL) { |
---|
1450 | int r; |
---|
1451 | r = process_nosurvey(fr, to, first_stn == To); |
---|
1452 | if (!r) skipline(); |
---|
1453 | } |
---|
1454 | if (ordering[1] == End) { |
---|
1455 | do { |
---|
1456 | process_eol(); |
---|
1457 | process_bol(); |
---|
1458 | } while (isComm(ch)); |
---|
1459 | if (!isData(ch)) { |
---|
1460 | push_back(ch); |
---|
1461 | return 1; |
---|
1462 | } |
---|
1463 | goto again; |
---|
1464 | } |
---|
1465 | fMulti = fTrue; |
---|
1466 | while (1) { |
---|
1467 | process_eol(); |
---|
1468 | process_bol(); |
---|
1469 | if (isData(ch)) break; |
---|
1470 | if (!isComm(ch)) { |
---|
1471 | push_back(ch); |
---|
1472 | return 1; |
---|
1473 | } |
---|
1474 | } |
---|
1475 | break; |
---|
1476 | case IgnoreAll: |
---|
1477 | skipline(); |
---|
1478 | /* fall through */ |
---|
1479 | case End: |
---|
1480 | if (!fMulti) { |
---|
1481 | int r = process_nosurvey(fr, to, first_stn == To); |
---|
1482 | process_eol(); |
---|
1483 | return r; |
---|
1484 | } |
---|
1485 | do { |
---|
1486 | process_eol(); |
---|
1487 | process_bol(); |
---|
1488 | } while (isComm(ch)); |
---|
1489 | goto again; |
---|
1490 | default: BUG("Unknown reading in ordering"); |
---|
1491 | } |
---|
1492 | } |
---|
1493 | } |
---|
1494 | |
---|
1495 | /* totally ignore a line of survey data */ |
---|
1496 | extern int |
---|
1497 | data_ignore(void) |
---|
1498 | { |
---|
1499 | skipline(); |
---|
1500 | process_eol(); |
---|
1501 | return 1; |
---|
1502 | } |
---|