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 | handle_plumb(clino_type *p_ctype) |
---|
376 | { |
---|
377 | typedef enum { |
---|
378 | CLINO_NULL=-1, CLINO_UP, CLINO_DOWN, CLINO_LEVEL |
---|
379 | } clino_tok; |
---|
380 | static sztok clino_tab[] = { |
---|
381 | {"D", CLINO_DOWN}, |
---|
382 | {"DOWN", CLINO_DOWN}, |
---|
383 | {"H", CLINO_LEVEL}, |
---|
384 | {"LEVEL", CLINO_LEVEL}, |
---|
385 | {"U", CLINO_UP}, |
---|
386 | {"UP", CLINO_UP}, |
---|
387 | {NULL, CLINO_NULL} |
---|
388 | }; |
---|
389 | static real clinos[] = {(real)M_PI_2, (real)(-M_PI_2), (real)0.0}; |
---|
390 | clino_tok tok; |
---|
391 | |
---|
392 | skipblanks(); |
---|
393 | if (isalpha(ch)) { |
---|
394 | filepos fp; |
---|
395 | get_pos(&fp); |
---|
396 | get_token(); |
---|
397 | tok = match_tok(clino_tab, TABSIZE(clino_tab)); |
---|
398 | if (tok != CLINO_NULL) { |
---|
399 | *p_ctype = (clinos[tok] == CLINO_LEVEL ? CLINO_HORIZ : CLINO_PLUMB); |
---|
400 | return clinos[tok]; |
---|
401 | } |
---|
402 | set_pos(&fp); |
---|
403 | } else if (isSign(ch)) { |
---|
404 | int chOld = ch; |
---|
405 | nextch(); |
---|
406 | if (toupper(ch) == 'V') { |
---|
407 | nextch(); |
---|
408 | *p_ctype = CLINO_PLUMB; |
---|
409 | return (!isMinus(chOld) ? M_PI_2 : -M_PI_2); |
---|
410 | } |
---|
411 | |
---|
412 | if (isOmit(chOld)) { |
---|
413 | *p_ctype = CLINO_OMIT; |
---|
414 | /* no clino reading, so assume 0 with large sd */ |
---|
415 | return (real)0.0; |
---|
416 | } |
---|
417 | } else if (isOmit(ch)) { |
---|
418 | /* OMIT char may not be a SIGN char too so we need to check here as |
---|
419 | * well as above... */ |
---|
420 | nextch(); |
---|
421 | *p_ctype = CLINO_OMIT; |
---|
422 | /* no clino reading, so assume 0 with large sd */ |
---|
423 | return (real)0.0; |
---|
424 | } |
---|
425 | return HUGE_REAL; |
---|
426 | } |
---|
427 | |
---|
428 | static int |
---|
429 | process_normal(prefix *fr, prefix *to, real tape, real comp, real clin, |
---|
430 | bool fToFirst, clino_type ctype, clino_type backctype) |
---|
431 | { |
---|
432 | real dx, dy, dz; |
---|
433 | real vx, vy, vz; |
---|
434 | #ifndef NO_COVARIANCES |
---|
435 | real cxy, cyz, czx; |
---|
436 | #endif |
---|
437 | |
---|
438 | bool fNoComp; |
---|
439 | |
---|
440 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
441 | if (tape < (real)0.0) { |
---|
442 | /* TRANSLATE different message for topofil? */ |
---|
443 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
444 | } |
---|
445 | |
---|
446 | fNoComp = (comp == HUGE_REAL); |
---|
447 | if (!fNoComp) { |
---|
448 | comp *= pcs->units[Q_BEARING]; |
---|
449 | if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) { |
---|
450 | compile_warning(/*Suspicious compass reading*/59); |
---|
451 | } |
---|
452 | } |
---|
453 | |
---|
454 | if (ctype == CLINO_READING) { |
---|
455 | clin *= pcs->units[Q_GRADIENT]; |
---|
456 | if (fabs(clin) - M_PI_2 > EPSILON) { |
---|
457 | compile_warning(/*Clino reading over 90 degrees (absolute value)*/51); |
---|
458 | } |
---|
459 | } |
---|
460 | |
---|
461 | if (ctype == CLINO_PLUMB || |
---|
462 | (pcs->f90Up && (fabs(clin - M_PI_2) < EPSILON))) { |
---|
463 | /* plumbed */ |
---|
464 | if (!fNoComp) { |
---|
465 | compile_warning(/*Compass reading given on plumbed leg*/21); |
---|
466 | } |
---|
467 | |
---|
468 | dx = dy = (real)0.0; |
---|
469 | dz = (clin > (real)0.0) ? tape : -tape; |
---|
470 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
471 | vz = var(Q_POS) / 3.0 + var(Q_LENGTH); |
---|
472 | #ifndef NO_COVARIANCES |
---|
473 | /* Correct values - no covariances in this case! */ |
---|
474 | cxy = cyz = czx = (real)0.0; |
---|
475 | #endif |
---|
476 | } else { |
---|
477 | /* clino */ |
---|
478 | real L2, cosG, LcosG, cosG2, sinB, cosB, dx2, dy2, dz2, v, V; |
---|
479 | if (fNoComp) { |
---|
480 | compile_error(/*Compass reading may not be omitted except on plumbed legs*/14); |
---|
481 | skipline(); |
---|
482 | return 0; |
---|
483 | } |
---|
484 | if (tape == (real)0.0) { |
---|
485 | dx = dy = dz = (real)0.0; |
---|
486 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
487 | #ifndef NO_COVARIANCES |
---|
488 | cxy = cyz = czx = (real)0.0; |
---|
489 | #endif |
---|
490 | #if DEBUG_DATAIN_1 |
---|
491 | printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
492 | #endif |
---|
493 | } else { |
---|
494 | real sinGcosG; |
---|
495 | comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING]; |
---|
496 | comp -= pcs->z[Q_DECLINATION]; |
---|
497 | /* LEVEL case */ |
---|
498 | if (ctype == CLINO_READING) |
---|
499 | clin = (clin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT]; |
---|
500 | |
---|
501 | #if DEBUG_DATAIN |
---|
502 | printf(" %4.2f %4.2f %4.2f\n", tape, comp, clin); |
---|
503 | #endif |
---|
504 | cosG = cos(clin); |
---|
505 | LcosG = tape * cosG; |
---|
506 | sinB = sin(comp); |
---|
507 | cosB = cos(comp); |
---|
508 | #if DEBUG_DATAIN_1 |
---|
509 | printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB, cosG, LcosG); |
---|
510 | #endif |
---|
511 | dx = LcosG * sinB; |
---|
512 | dy = LcosG * cosB; |
---|
513 | dz = tape * sin(clin); |
---|
514 | /* printf("%.2f\n",clin); */ |
---|
515 | #if DEBUG_DATAIN_1 |
---|
516 | printf("dx = %f\ndy = %f\ndz = %f\n", dx, dy, dz); |
---|
517 | #endif |
---|
518 | dx2 = dx * dx; |
---|
519 | L2 = tape * tape; |
---|
520 | V = var(Q_LENGTH) / L2; |
---|
521 | dy2 = dy * dy; |
---|
522 | cosG2 = cosG * cosG; |
---|
523 | sinGcosG = sin(clin) * cosG; |
---|
524 | dz2 = dz * dz; |
---|
525 | /* take into account variance in LEVEL case */ |
---|
526 | v = dz2 * var(ctype == CLINO_READING ? Q_GRADIENT : Q_LEVEL); |
---|
527 | #ifdef NO_COVARIANCES |
---|
528 | vx = (var(Q_POS) / 3.0 + dx2 * V + dy2 * var(Q_BEARING) + |
---|
529 | (.5 + sinB * sinB * cosG2) * v); |
---|
530 | vy = (var(Q_POS) / 3.0 + dy2 * V + dx2 * var(Q_BEARING) + |
---|
531 | (.5 + cosB * cosB * cosG2) * v); |
---|
532 | if (ctype == CLINO_OMIT) { |
---|
533 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
534 | vz = (var(Q_POS) / 3.0 + L2 * (real)0.1); |
---|
535 | } else { |
---|
536 | vz = (var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var(Q_GRADIENT)); |
---|
537 | } |
---|
538 | /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */ |
---|
539 | #else |
---|
540 | vx = var(Q_POS) / 3.0 + dx2 * V + dy2 * var(Q_BEARING) + |
---|
541 | (sinB * sinB * v); |
---|
542 | vy = var(Q_POS) / 3.0 + dy2 * V + dx2 * var(Q_BEARING) + |
---|
543 | (cosB * cosB * v); |
---|
544 | if (ctype == CLINO_OMIT) { |
---|
545 | /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */ |
---|
546 | vz = (var(Q_POS) / 3.0 + L2 * (real)0.1); |
---|
547 | } else { |
---|
548 | vz = (var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var(Q_GRADIENT)); |
---|
549 | } |
---|
550 | /* usual covariance formulae are fine in no clino case since |
---|
551 | * dz = 0 so value of var(Q_GRADIENT) is ignored */ |
---|
552 | cxy = sinB * cosB * (var(Q_LENGTH) * cosG2 + var(Q_GRADIENT) * dz2) |
---|
553 | - var(Q_BEARING) * dx * dy; |
---|
554 | czx = var(Q_LENGTH) * sinB * sinGcosG - var(Q_GRADIENT) * dx * dz; |
---|
555 | cyz = var(Q_LENGTH) * cosB * sinGcosG - var(Q_GRADIENT) * dy * dz; |
---|
556 | #if 0 |
---|
557 | printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx, vy, vz); |
---|
558 | printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy, cyz, czx); |
---|
559 | #endif |
---|
560 | #endif |
---|
561 | #if DEBUG_DATAIN_1 |
---|
562 | printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx, vy, vz); |
---|
563 | #endif |
---|
564 | } |
---|
565 | } |
---|
566 | #if DEBUG_DATAIN_1 |
---|
567 | printf("Just before addleg, vx = %f\n", vx); |
---|
568 | #endif |
---|
569 | /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/ |
---|
570 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
571 | #ifndef NO_COVARIANCES |
---|
572 | , cyz, czx, cxy |
---|
573 | #endif |
---|
574 | ); |
---|
575 | |
---|
576 | #ifdef NEW3DFORMAT |
---|
577 | if (fUseNewFormat) { |
---|
578 | /* new twiglet and insert into twig tree */ |
---|
579 | twig *twiglet = osnew(twig); |
---|
580 | twiglet->from = fr; |
---|
581 | twiglet->to = to; |
---|
582 | twiglet->down = twiglet->right = NULL; |
---|
583 | twiglet->source = twiglet->drawings |
---|
584 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
585 | twiglet->up = limb->up; |
---|
586 | limb->right = twiglet; |
---|
587 | limb = twiglet; |
---|
588 | |
---|
589 | /* record pre-fettling deltas */ |
---|
590 | twiglet->delta[0] = dx; |
---|
591 | twiglet->delta[1] = dy; |
---|
592 | twiglet->delta[2] = dz; |
---|
593 | } |
---|
594 | #endif |
---|
595 | return 1; |
---|
596 | } |
---|
597 | |
---|
598 | static int |
---|
599 | process_diving(prefix *fr, prefix *to, real tape, real comp, |
---|
600 | real frdepth, real todepth, bool fToFirst, bool fDepthChange) |
---|
601 | { |
---|
602 | real dx, dy, dz; |
---|
603 | real vx, vy, vz; |
---|
604 | #ifndef NO_COVARIANCES |
---|
605 | real cxy = 0, cyz = 0, czx = 0; |
---|
606 | #endif |
---|
607 | |
---|
608 | if (comp != HUGE_REAL) { |
---|
609 | comp *= pcs->units[Q_BEARING]; |
---|
610 | if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) { |
---|
611 | compile_warning(/*Suspicious compass reading*/59); |
---|
612 | } |
---|
613 | } |
---|
614 | |
---|
615 | /* depth gauge readings increase upwards with default calibration */ |
---|
616 | if (fDepthChange) { |
---|
617 | ASSERT(frdepth == 0.0); |
---|
618 | dz = (todepth * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]) * pcs->sc[Q_DEPTH]; |
---|
619 | } else { |
---|
620 | dz = (todepth - frdepth) * pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
621 | } |
---|
622 | |
---|
623 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
624 | if (tape < (real)0.0) { |
---|
625 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
626 | } |
---|
627 | |
---|
628 | /* check if tape is less than depth change */ |
---|
629 | if (tape < fabs(dz)) { |
---|
630 | /* FIXME: allow margin of error based on variances? */ |
---|
631 | compile_warning(/*Tape reading is less than change in depth*/62); |
---|
632 | } |
---|
633 | |
---|
634 | if (tape == (real)0.0 && dz == 0.0) { |
---|
635 | dx = dy = dz = (real)0.0; |
---|
636 | vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */ |
---|
637 | } else if (comp == HUGE_REAL) { |
---|
638 | /* plumb */ |
---|
639 | dx = dy = (real)0.0; |
---|
640 | if (dz < 0) tape = -tape; |
---|
641 | dz = (dz * var(Q_LENGTH) + tape * 2 * var(Q_DEPTH)) |
---|
642 | / (var(Q_LENGTH) * 2 * var(Q_DEPTH)); |
---|
643 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
644 | vz = var(Q_POS) / 3.0 + var(Q_LENGTH) * 2 * var(Q_DEPTH) |
---|
645 | / (var(Q_LENGTH) + var(Q_DEPTH)); |
---|
646 | } else { |
---|
647 | real L2, sinB, cosB, dz2, D2; |
---|
648 | comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING]; |
---|
649 | comp -= pcs->z[Q_DECLINATION]; |
---|
650 | sinB = sin(comp); |
---|
651 | cosB = cos(comp); |
---|
652 | L2 = tape * tape; |
---|
653 | dz2 = dz * dz; |
---|
654 | D2 = L2 - dz2; |
---|
655 | if (D2 <= (real)0.0) { |
---|
656 | real vsum = var(Q_LENGTH) + 2 * var(Q_DEPTH); |
---|
657 | dx = dy = (real)0.0; |
---|
658 | vx = vy = var(Q_POS) / 3.0; |
---|
659 | vz = var(Q_POS) / 3.0 + var(Q_LENGTH) * 2 * var(Q_DEPTH) / vsum; |
---|
660 | if (dz > 0) { |
---|
661 | dz = (dz * var(Q_LENGTH) + tape * 2 * var(Q_DEPTH)) / vsum; |
---|
662 | } else { |
---|
663 | dz = (dz * var(Q_LENGTH) - tape * 2 * var(Q_DEPTH)) / vsum; |
---|
664 | } |
---|
665 | } else { |
---|
666 | real D = sqrt(D2); |
---|
667 | real F = var(Q_LENGTH) * L2 + 2 * var(Q_DEPTH) * D2; |
---|
668 | dx = D * sinB; |
---|
669 | dy = D * cosB; |
---|
670 | |
---|
671 | vx = var(Q_POS) / 3.0 + |
---|
672 | sinB * sinB * F / D2 + var(Q_BEARING) * dy * dy; |
---|
673 | vy = var(Q_POS) / 3.0 + |
---|
674 | cosB * cosB * F / D2 + var(Q_BEARING) * dx * dx; |
---|
675 | vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH); |
---|
676 | |
---|
677 | #ifndef NO_COVARIANCES |
---|
678 | cxy = sinB * cosB * (F / D2 + var(Q_BEARING) * D2); |
---|
679 | cyz = -2 * var(Q_DEPTH) * dy / D; |
---|
680 | czx = -2 * var(Q_DEPTH) * dx / D; |
---|
681 | #endif |
---|
682 | } |
---|
683 | } |
---|
684 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
685 | #ifndef NO_COVARIANCES |
---|
686 | , cxy, cyz, czx |
---|
687 | #endif |
---|
688 | ); |
---|
689 | #ifdef NEW3DFORMAT |
---|
690 | if (fUseNewFormat) { |
---|
691 | /*new twiglet and insert into twig tree*/ |
---|
692 | twig *twiglet = osnew(twig); |
---|
693 | twiglet->from = fr; |
---|
694 | twiglet->to = to; |
---|
695 | twiglet->down = twiglet->right = NULL; |
---|
696 | twiglet->source = twiglet->drawings |
---|
697 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
698 | twiglet->up = limb->up; |
---|
699 | limb->right = twiglet; |
---|
700 | limb = twiglet; |
---|
701 | |
---|
702 | /* record pre-fettling deltas */ |
---|
703 | twiglet->delta[0] = dx; |
---|
704 | twiglet->delta[1] = dy; |
---|
705 | twiglet->delta[2] = dz; |
---|
706 | } |
---|
707 | #endif |
---|
708 | |
---|
709 | return 1; |
---|
710 | } |
---|
711 | |
---|
712 | static int |
---|
713 | process_cartesian(prefix *fr, prefix *to, real dx, real dy, real dz, |
---|
714 | bool fToFirst) |
---|
715 | { |
---|
716 | dx = (dx * pcs->units[Q_DX] - pcs->z[Q_DX]) * pcs->sc[Q_DX]; |
---|
717 | dy = (dy * pcs->units[Q_DY] - pcs->z[Q_DY]) * pcs->sc[Q_DY]; |
---|
718 | dz = (dz * pcs->units[Q_DZ] - pcs->z[Q_DZ]) * pcs->sc[Q_DZ]; |
---|
719 | |
---|
720 | addlegbyname(fr, to, fToFirst, dx, dy, dz, var(Q_DX), var(Q_DY), var(Q_DZ) |
---|
721 | #ifndef NO_COVARIANCES |
---|
722 | , 0, 0, 0 |
---|
723 | #endif |
---|
724 | ); |
---|
725 | |
---|
726 | #ifdef NEW3DFORMAT |
---|
727 | if (fUseNewFormat) { |
---|
728 | /* new twiglet and insert into twig tree */ |
---|
729 | twig *twiglet = osnew(twig); |
---|
730 | twiglet->from = fr; |
---|
731 | twiglet->to = to; |
---|
732 | twiglet->down = twiglet->right = NULL; |
---|
733 | twiglet->source = twiglet->drawings |
---|
734 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
735 | twiglet->up = limb->up; |
---|
736 | limb->right = twiglet; |
---|
737 | limb = twiglet; |
---|
738 | |
---|
739 | /* record pre-fettling deltas */ |
---|
740 | twiglet->delta[0] = dx; |
---|
741 | twiglet->delta[1] = dy; |
---|
742 | twiglet->delta[2] = dz; |
---|
743 | } |
---|
744 | #endif |
---|
745 | |
---|
746 | return 1; |
---|
747 | } |
---|
748 | |
---|
749 | extern int |
---|
750 | data_cartesian(void) |
---|
751 | { |
---|
752 | prefix *fr = NULL, *to = NULL; |
---|
753 | real dx = 0, dy = 0, dz = 0; |
---|
754 | |
---|
755 | bool fMulti = fFalse; |
---|
756 | |
---|
757 | reading first_stn = End; |
---|
758 | |
---|
759 | reading *ordering; |
---|
760 | |
---|
761 | again: |
---|
762 | |
---|
763 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
764 | skipblanks(); |
---|
765 | switch (*ordering) { |
---|
766 | case Fr: |
---|
767 | fr = read_prefix_stn(fFalse, fTrue); |
---|
768 | if (first_stn == End) first_stn = Fr; |
---|
769 | break; |
---|
770 | case To: |
---|
771 | to = read_prefix_stn(fFalse, fTrue); |
---|
772 | if (first_stn == End) first_stn = To; |
---|
773 | break; |
---|
774 | case Station: |
---|
775 | fr = to; |
---|
776 | to = read_prefix_stn(fFalse, fFalse); |
---|
777 | first_stn = To; |
---|
778 | break; |
---|
779 | case Dx: dx = read_numeric(fFalse); break; |
---|
780 | case Dy: dy = read_numeric(fFalse); break; |
---|
781 | case Dz: dz = read_numeric(fFalse); break; |
---|
782 | case Ignore: |
---|
783 | skipword(); break; |
---|
784 | case IgnoreAllAndNewLine: |
---|
785 | skipline(); |
---|
786 | /* fall through */ |
---|
787 | case Newline: |
---|
788 | if (fr != NULL) { |
---|
789 | int r; |
---|
790 | r = process_cartesian(fr, to, dx, dy, dz, first_stn == To); |
---|
791 | if (!r) skipline(); |
---|
792 | } |
---|
793 | fMulti = fTrue; |
---|
794 | while (1) { |
---|
795 | process_eol(); |
---|
796 | process_bol(); |
---|
797 | if (isData(ch)) break; |
---|
798 | if (!isComm(ch)) { |
---|
799 | push_back(ch); |
---|
800 | return 1; |
---|
801 | } |
---|
802 | } |
---|
803 | break; |
---|
804 | case IgnoreAll: |
---|
805 | skipline(); |
---|
806 | /* fall through */ |
---|
807 | case End: |
---|
808 | if (!fMulti) { |
---|
809 | int r = process_cartesian(fr, to, dx, dy, dz, first_stn == To); |
---|
810 | process_eol(); |
---|
811 | return r; |
---|
812 | } |
---|
813 | do { |
---|
814 | process_eol(); |
---|
815 | process_bol(); |
---|
816 | } while (isComm(ch)); |
---|
817 | goto again; |
---|
818 | default: BUG("Unknown reading in ordering"); |
---|
819 | } |
---|
820 | } |
---|
821 | } |
---|
822 | |
---|
823 | static int |
---|
824 | process_cylpolar(prefix *fr, prefix *to, real tape, real comp, |
---|
825 | real frdepth, real todepth, bool fToFirst, bool fDepthChange) |
---|
826 | { |
---|
827 | real dx, dy, dz; |
---|
828 | real vx, vy, vz; |
---|
829 | #ifndef NO_COVARIANCES |
---|
830 | real cxy = 0; |
---|
831 | #endif |
---|
832 | |
---|
833 | if (comp != HUGE_REAL) { |
---|
834 | comp *= pcs->units[Q_BEARING]; |
---|
835 | if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) { |
---|
836 | compile_warning(/*Suspicious compass reading*/59); |
---|
837 | } |
---|
838 | } |
---|
839 | |
---|
840 | /* depth gauge readings increase upwards with default calibration */ |
---|
841 | if (fDepthChange) { |
---|
842 | ASSERT(frdepth == 0.0); |
---|
843 | dz = (todepth * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]) * pcs->sc[Q_DEPTH]; |
---|
844 | } else { |
---|
845 | dz = (todepth - frdepth) * pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH]; |
---|
846 | } |
---|
847 | |
---|
848 | /* adjusted tape is negative -- probably the calibration is wrong */ |
---|
849 | if (tape < (real)0.0) { |
---|
850 | compile_warning(/*Negative adjusted tape reading*/79); |
---|
851 | } |
---|
852 | |
---|
853 | if (comp == HUGE_REAL) { |
---|
854 | /* plumb */ |
---|
855 | dx = dy = (real)0.0; |
---|
856 | vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB); |
---|
857 | vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH); |
---|
858 | } else { |
---|
859 | real sinB, cosB; |
---|
860 | comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING]; |
---|
861 | comp -= pcs->z[Q_DECLINATION]; |
---|
862 | |
---|
863 | sinB = sin(comp); |
---|
864 | cosB = cos(comp); |
---|
865 | |
---|
866 | dx = tape * sinB; |
---|
867 | dy = tape * cosB; |
---|
868 | |
---|
869 | vx = var(Q_POS) / 3.0 + |
---|
870 | var(Q_LENGTH) * sinB * sinB + var(Q_BEARING) * dy * dy; |
---|
871 | vy = var(Q_POS) / 3.0 + |
---|
872 | var(Q_LENGTH) * cosB * cosB + var(Q_BEARING) * dx * dx; |
---|
873 | vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH); |
---|
874 | |
---|
875 | #ifndef NO_COVARIANCES |
---|
876 | cxy = (var(Q_LENGTH) - var(Q_BEARING) * tape * tape) * sinB * cosB; |
---|
877 | #endif |
---|
878 | } |
---|
879 | addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz |
---|
880 | #ifndef NO_COVARIANCES |
---|
881 | , cxy, 0, 0 |
---|
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 | /* Process tape/compass/clino, diving, and cylpolar styles of survey data |
---|
908 | * Also handles topofil (fromcount/tocount or count) in place of tape */ |
---|
909 | extern int |
---|
910 | data_normal(void) |
---|
911 | { |
---|
912 | prefix *fr = NULL, *to = NULL; |
---|
913 | reading first_stn = End; |
---|
914 | |
---|
915 | real tape = 0, comp = 0, backcomp = 0, frcount = 0, tocount = 0; |
---|
916 | real clin, backclin; |
---|
917 | real frdepth = 0, todepth = 0; |
---|
918 | |
---|
919 | bool fTopofil = fFalse, fMulti = fFalse; |
---|
920 | bool fRev; |
---|
921 | bool ctype, backctype; |
---|
922 | bool fDepthChange; |
---|
923 | |
---|
924 | reading *ordering; |
---|
925 | |
---|
926 | again: |
---|
927 | |
---|
928 | fRev = fFalse; |
---|
929 | ctype = backctype = CLINO_OMIT; |
---|
930 | fDepthChange = fFalse; |
---|
931 | |
---|
932 | /* ordering may omit clino reading, so set up default here */ |
---|
933 | /* this is also used if clino reading is the omit character */ |
---|
934 | backclin = clin = (real)0.0; |
---|
935 | |
---|
936 | for (ordering = pcs->ordering; ; ordering++) { |
---|
937 | skipblanks(); |
---|
938 | switch (*ordering) { |
---|
939 | case Fr: |
---|
940 | fr = read_prefix_stn(fFalse, fTrue); |
---|
941 | if (first_stn == End) first_stn = Fr; |
---|
942 | break; |
---|
943 | case To: |
---|
944 | to = read_prefix_stn(fFalse, fTrue); |
---|
945 | if (first_stn == End) first_stn = To; |
---|
946 | break; |
---|
947 | case Station: |
---|
948 | fr = to; |
---|
949 | to = read_prefix_stn(fFalse, fFalse); |
---|
950 | first_stn = To; |
---|
951 | break; |
---|
952 | case Dir: |
---|
953 | switch(toupper(ch)) { |
---|
954 | case 'F': |
---|
955 | break; |
---|
956 | case 'B': |
---|
957 | fRev = fTrue; |
---|
958 | break; |
---|
959 | default: |
---|
960 | compile_error(/*Found `%c', expecting `F' or `B'*/131, ch); |
---|
961 | skipline(); |
---|
962 | process_eol(); |
---|
963 | return 0; |
---|
964 | } |
---|
965 | break; |
---|
966 | case Tape: |
---|
967 | tape = read_numeric(fFalse); |
---|
968 | if (tape < (real)0.0) compile_warning(/*Negative tape reading*/60); |
---|
969 | break; |
---|
970 | case Count: |
---|
971 | frcount = tocount; |
---|
972 | tocount = read_numeric(fFalse); |
---|
973 | break; |
---|
974 | case FrCount: |
---|
975 | frcount = read_numeric(fFalse); |
---|
976 | break; |
---|
977 | case ToCount: |
---|
978 | tocount = read_numeric(fFalse); |
---|
979 | fTopofil = fTrue; |
---|
980 | break; |
---|
981 | case Comp: |
---|
982 | comp = read_numeric_or_omit(); |
---|
983 | break; |
---|
984 | case BackComp: |
---|
985 | backcomp = read_numeric_or_omit(); |
---|
986 | break; |
---|
987 | case Clino: |
---|
988 | clin = read_numeric(fTrue); |
---|
989 | if (clin == HUGE_REAL) { |
---|
990 | clin = handle_plumb(&ctype); |
---|
991 | if (clin != HUGE_REAL) break; |
---|
992 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
993 | process_eol(); |
---|
994 | return 0; |
---|
995 | } |
---|
996 | ctype = CLINO_READING; |
---|
997 | break; |
---|
998 | case BackClino: |
---|
999 | backclin = read_numeric(fTrue); |
---|
1000 | if (backclin == HUGE_REAL) { |
---|
1001 | /* FIXME: how should special readings for Clino and BackClino |
---|
1002 | * interact? */ |
---|
1003 | backclin = handle_plumb(&backctype); |
---|
1004 | if (backclin != HUGE_REAL) break; |
---|
1005 | compile_error_token(/*Expecting numeric field, found `%s'*/9); |
---|
1006 | process_eol(); |
---|
1007 | return 0; |
---|
1008 | } |
---|
1009 | backctype = CLINO_READING; |
---|
1010 | break; |
---|
1011 | case FrDepth: |
---|
1012 | frdepth = read_numeric(fFalse); |
---|
1013 | break; |
---|
1014 | case ToDepth: |
---|
1015 | todepth = read_numeric(fFalse); |
---|
1016 | break; |
---|
1017 | case Depth: |
---|
1018 | frdepth = todepth; |
---|
1019 | todepth = read_numeric(fFalse); |
---|
1020 | break; |
---|
1021 | case DepthChange: |
---|
1022 | fDepthChange = fTrue; |
---|
1023 | frdepth = 0; |
---|
1024 | todepth = read_numeric(fFalse); |
---|
1025 | break; |
---|
1026 | case Ignore: |
---|
1027 | skipword(); |
---|
1028 | break; |
---|
1029 | case IgnoreAllAndNewLine: |
---|
1030 | skipline(); |
---|
1031 | /* fall through */ |
---|
1032 | case Newline: |
---|
1033 | if (fr != NULL) { |
---|
1034 | int r; |
---|
1035 | if (fRev) { |
---|
1036 | prefix *t = fr; |
---|
1037 | fr = to; |
---|
1038 | to = t; |
---|
1039 | } |
---|
1040 | if (fTopofil) tape = tocount - frcount; |
---|
1041 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
1042 | * (frdepth always zero, todepth is change of depth) and also |
---|
1043 | * works for STYLE_NORMAL (both remain 0) */ |
---|
1044 | if (pcs->f0Eq && tape == (real)0.0 && frdepth == todepth) { |
---|
1045 | process_equate(fr, to); |
---|
1046 | goto inferred_equate; |
---|
1047 | } |
---|
1048 | if (fTopofil) { |
---|
1049 | tape *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
1050 | } else { |
---|
1051 | tape *= pcs->units[Q_LENGTH]; |
---|
1052 | tape = (tape - pcs->z[Q_LENGTH]) * pcs->sc[Q_LENGTH]; |
---|
1053 | } |
---|
1054 | switch (pcs->style) { |
---|
1055 | case STYLE_NORMAL: |
---|
1056 | r = process_normal(fr, to, tape, comp, clin, |
---|
1057 | (first_stn == To) ^ fRev, ctype, backctype); |
---|
1058 | break; |
---|
1059 | case STYLE_DIVING: |
---|
1060 | r = process_diving(fr, to, tape, comp, frdepth, todepth, |
---|
1061 | (first_stn == To) ^ fRev, fDepthChange); |
---|
1062 | break; |
---|
1063 | case STYLE_CYLPOLAR: |
---|
1064 | r = process_cylpolar(fr, to, tape, comp, frdepth, todepth, |
---|
1065 | (first_stn == To) ^ fRev, fDepthChange); |
---|
1066 | break; |
---|
1067 | default: |
---|
1068 | BUG("bad style"); |
---|
1069 | } |
---|
1070 | if (!r) skipline(); |
---|
1071 | } |
---|
1072 | inferred_equate: |
---|
1073 | fMulti = fTrue; |
---|
1074 | while (1) { |
---|
1075 | process_eol(); |
---|
1076 | process_bol(); |
---|
1077 | if (isData(ch)) break; |
---|
1078 | if (!isComm(ch)) { |
---|
1079 | push_back(ch); |
---|
1080 | return 1; |
---|
1081 | } |
---|
1082 | } |
---|
1083 | break; |
---|
1084 | case IgnoreAll: |
---|
1085 | skipline(); |
---|
1086 | /* fall through */ |
---|
1087 | case End: |
---|
1088 | if (!fMulti) { |
---|
1089 | int r; |
---|
1090 | if (fRev) { |
---|
1091 | prefix *t = fr; |
---|
1092 | fr = to; |
---|
1093 | to = t; |
---|
1094 | } |
---|
1095 | if (fTopofil) tape = tocount - frcount; |
---|
1096 | /* Note: frdepth == todepth test works regardless of fDepthChange |
---|
1097 | * (frdepth always zero, todepth is change of depth) and also |
---|
1098 | * works for STYLE_NORMAL (both remain 0) */ |
---|
1099 | if (pcs->f0Eq && tape == (real)0.0 && frdepth == todepth) { |
---|
1100 | process_equate(fr, to); |
---|
1101 | process_eol(); |
---|
1102 | return 1; |
---|
1103 | } |
---|
1104 | if (fTopofil) { |
---|
1105 | tape *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT]; |
---|
1106 | } else { |
---|
1107 | tape *= pcs->units[Q_LENGTH]; |
---|
1108 | tape = (tape - pcs->z[Q_LENGTH]) * pcs->sc[Q_LENGTH]; |
---|
1109 | } |
---|
1110 | switch (pcs->style) { |
---|
1111 | case STYLE_NORMAL: |
---|
1112 | r = process_normal(fr, to, tape, comp, clin, |
---|
1113 | (first_stn == To) ^ fRev, ctype, backctype); |
---|
1114 | break; |
---|
1115 | case STYLE_DIVING: |
---|
1116 | r = process_diving(fr, to, tape, comp, frdepth, todepth, |
---|
1117 | (first_stn == To) ^ fRev, fDepthChange); |
---|
1118 | break; |
---|
1119 | case STYLE_CYLPOLAR: |
---|
1120 | r = process_cylpolar(fr, to, tape, comp, frdepth, todepth, |
---|
1121 | (first_stn == To) ^ fRev, fDepthChange); |
---|
1122 | break; |
---|
1123 | default: |
---|
1124 | BUG("bad style"); |
---|
1125 | } |
---|
1126 | process_eol(); |
---|
1127 | return r; |
---|
1128 | } |
---|
1129 | do { |
---|
1130 | process_eol(); |
---|
1131 | process_bol(); |
---|
1132 | } while (isComm(ch)); |
---|
1133 | goto again; |
---|
1134 | default: |
---|
1135 | BUG("Unknown reading in ordering"); |
---|
1136 | } |
---|
1137 | } |
---|
1138 | } |
---|
1139 | |
---|
1140 | static int |
---|
1141 | process_nosurvey(prefix *fr, prefix *to, bool fToFirst) |
---|
1142 | { |
---|
1143 | nosurveylink *link; |
---|
1144 | int shape; |
---|
1145 | |
---|
1146 | #ifdef NEW3DFORMAT |
---|
1147 | if (fUseNewFormat) { |
---|
1148 | /* new twiglet and insert into twig tree */ |
---|
1149 | twig *twiglet = osnew(twig); |
---|
1150 | twiglet->from = fr; |
---|
1151 | twiglet->to = to; |
---|
1152 | twiglet->down = twiglet->right = NULL; |
---|
1153 | twiglet->source = twiglet->drawings |
---|
1154 | = twiglet->date = twiglet->instruments = twiglet->tape = NULL; |
---|
1155 | twiglet->up = limb->up; |
---|
1156 | limb->right = twiglet; |
---|
1157 | limb = twiglet; |
---|
1158 | /* delta is only used to calculate error - pass zero and cope |
---|
1159 | * elsewhere */ |
---|
1160 | twiglet->delta[0] = twiglet->delta[1] = twiglet->delta[2] = 0; |
---|
1161 | } |
---|
1162 | #endif |
---|
1163 | |
---|
1164 | /* Suppress "unused fixed point" warnings for these stations |
---|
1165 | * We do this if it's a 0 or 1 node - 1 node might be an sdfix |
---|
1166 | */ |
---|
1167 | shape = fr->shape; |
---|
1168 | if (shape == 0 || shape == 1) fr->shape = -1 - shape; |
---|
1169 | shape = to->shape; |
---|
1170 | if (shape == 0 || shape == 1) to->shape = -1 - shape; |
---|
1171 | |
---|
1172 | /* add to linked list which is dealt with after network is solved */ |
---|
1173 | link = osnew(nosurveylink); |
---|
1174 | if (fToFirst) { |
---|
1175 | link->to = StnFromPfx(to); |
---|
1176 | link->fr = StnFromPfx(fr); |
---|
1177 | } else { |
---|
1178 | link->fr = StnFromPfx(fr); |
---|
1179 | link->to = StnFromPfx(to); |
---|
1180 | } |
---|
1181 | link->flags = pcs->flags; |
---|
1182 | link->next = nosurveyhead; |
---|
1183 | nosurveyhead = link; |
---|
1184 | return 1; |
---|
1185 | } |
---|
1186 | |
---|
1187 | extern int |
---|
1188 | data_nosurvey(void) |
---|
1189 | { |
---|
1190 | prefix *fr = NULL, *to = NULL; |
---|
1191 | |
---|
1192 | bool fMulti = fFalse; |
---|
1193 | |
---|
1194 | reading first_stn = End; |
---|
1195 | |
---|
1196 | reading *ordering; |
---|
1197 | |
---|
1198 | again: |
---|
1199 | |
---|
1200 | for (ordering = pcs->ordering ; ; ordering++) { |
---|
1201 | skipblanks(); |
---|
1202 | switch (*ordering) { |
---|
1203 | case Fr: |
---|
1204 | fr = read_prefix_stn(fFalse, fTrue); |
---|
1205 | if (first_stn == End) first_stn = Fr; |
---|
1206 | break; |
---|
1207 | case To: |
---|
1208 | to = read_prefix_stn(fFalse, fTrue); |
---|
1209 | if (first_stn == End) first_stn = To; |
---|
1210 | break; |
---|
1211 | case Station: |
---|
1212 | fr = to; |
---|
1213 | to = read_prefix_stn(fFalse, fFalse); |
---|
1214 | first_stn = To; |
---|
1215 | break; |
---|
1216 | case Ignore: |
---|
1217 | skipword(); break; |
---|
1218 | case IgnoreAllAndNewLine: |
---|
1219 | skipline(); |
---|
1220 | /* fall through */ |
---|
1221 | case Newline: |
---|
1222 | if (fr != NULL) { |
---|
1223 | int r; |
---|
1224 | r = process_nosurvey(fr, to, first_stn == To); |
---|
1225 | if (!r) skipline(); |
---|
1226 | } |
---|
1227 | if (ordering[1] == End) { |
---|
1228 | do { |
---|
1229 | process_eol(); |
---|
1230 | process_bol(); |
---|
1231 | } while (isComm(ch)); |
---|
1232 | if (!isData(ch)) { |
---|
1233 | push_back(ch); |
---|
1234 | return 1; |
---|
1235 | } |
---|
1236 | goto again; |
---|
1237 | } |
---|
1238 | fMulti = fTrue; |
---|
1239 | while (1) { |
---|
1240 | process_eol(); |
---|
1241 | process_bol(); |
---|
1242 | if (isData(ch)) break; |
---|
1243 | if (!isComm(ch)) { |
---|
1244 | push_back(ch); |
---|
1245 | return 1; |
---|
1246 | } |
---|
1247 | } |
---|
1248 | break; |
---|
1249 | case IgnoreAll: |
---|
1250 | skipline(); |
---|
1251 | /* fall through */ |
---|
1252 | case End: |
---|
1253 | if (!fMulti) { |
---|
1254 | int r = process_nosurvey(fr, to, first_stn == To); |
---|
1255 | process_eol(); |
---|
1256 | return r; |
---|
1257 | } |
---|
1258 | do { |
---|
1259 | process_eol(); |
---|
1260 | process_bol(); |
---|
1261 | } while (isComm(ch)); |
---|
1262 | goto again; |
---|
1263 | default: BUG("Unknown reading in ordering"); |
---|
1264 | } |
---|
1265 | } |
---|
1266 | } |
---|
1267 | |
---|
1268 | /* totally ignore a line of survey data */ |
---|
1269 | extern int |
---|
1270 | data_ignore(void) |
---|
1271 | { |
---|
1272 | skipline(); |
---|
1273 | process_eol(); |
---|
1274 | return 1; |
---|
1275 | } |
---|