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