2 * Reads in survey files, dealing with special characters, keywords & data
3 * Copyright (C) 1991-2003,2005,2009,2010,2011,2012,2013,2014,2015,2016 Olly Betts
4 * Copyright (C) 2004 Simeon Warner
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
43 #define EPSILON (REAL_EPSILON * 1000)
45 #define var(I) (pcs->Var[(I)])
47 /* true if x is not-a-number value in Compass (999.0 or -999.0) */
48 /* Compass uses 999.0 but understands Karst data which used -999.0 */
49 #define is_compass_NaN(x) ( fabs(fabs(x)-999.0) < EPSILON )
54 CTYPE_OMIT
, CTYPE_READING
, CTYPE_PLUMB
, CTYPE_INFERPLUMB
, CTYPE_HORIZ
57 /* Don't explicitly initialise as we can't set the jmp_buf - this has
58 * static scope so will be initialised like this anyway */
59 parse file
/* = { NULL, NULL, 0, fFalse, NULL } */ ;
63 static real value
[Fr
- 1];
64 #define VAL(N) value[(N)-1]
65 static real variance
[Fr
- 1];
66 #define VAR(N) variance[(N)-1]
67 static long location
[Fr
- 1];
68 #define LOC(N) location[(N)-1]
71 static void data_normal(void);
72 static void data_cartesian(void);
73 static void data_passage(void);
74 static void data_nosurvey(void);
75 static void data_ignore(void);
81 fp
->offset
= ftell(file
.fh
);
83 fatalerror_in_file(file
.filename
, 0, /*Error reading file*/18);
87 set_pos(const filepos
*fp
)
90 if (fseek(file
.fh
, fp
->offset
, SEEK_SET
) == -1)
91 fatalerror_in_file(file
.filename
, 0, /*Error reading file*/18);
97 if (c
!= EOF
&& ungetc(c
, file
.fh
) == EOF
)
98 fatalerror_in_file(file
.filename
, 0, /*Error reading file*/18);
102 report_parent(parse
* p
) {
104 report_parent(p
->parent
);
105 /* Force re-report of include tree for further errors in
107 p
->reported_where
= fFalse
;
108 /* TRANSLATORS: %s is replaced by the filename of the parent file, and %u
109 * by the line number in that file. Your translation should also contain
110 * %s:%u so that automatic parsing of error messages to determine the file
111 * and line number still works. */
112 fprintf(STDERR
, msg(/*In file included from %s:%u:\n*/5), p
->filename
, p
->line
);
116 error_list_parent_files(void)
118 if (!file
.reported_where
&& file
.parent
) {
119 report_parent(file
.parent
);
120 /* Suppress reporting of full include tree for further errors
122 file
.reported_where
= fTrue
;
127 compile_v_report(int severity
, int en
, va_list ap
)
130 error_list_parent_files();
133 if (file
.fh
) col
= ftell(file
.fh
) - file
.lpos
;
135 v_report(severity
, file
.filename
, file
.line
, col
, en
, ap
);
139 compile_error(int en
, ...)
143 compile_v_report(1, en
, ap
);
148 compile_error_skip(int en
, ...)
152 compile_v_report(1, en
, ap
);
158 compile_error_reading(reading r
, int en
, ...)
163 error_list_parent_files();
164 if (LOC(r
) > file
.lpos
) col
= LOC(r
) - file
.lpos
;
165 v_report(1, file
.filename
, file
.line
, col
, en
, ap
);
170 compile_error_reading_skip(reading r
, int en
, ...)
175 error_list_parent_files();
176 if (LOC(r
) > file
.lpos
) col
= LOC(r
) - file
.lpos
;
177 v_report(1, file
.filename
, file
.line
, col
, en
, ap
);
183 compile_error_at(const char * filename
, unsigned line
, int en
, ...)
187 v_report(1, filename
, line
, 0, en
, ap
);
192 compile_error_pfx(const prefix
* pfx
, int en
, ...)
196 v_report(1, pfx
->filename
, pfx
->line
, 0, en
, ap
);
201 compile_error_token(int en
)
206 while (!isBlank(ch
) && !isEol(ch
)) {
207 s_catchar(&p
, &len
, (char)ch
);
210 compile_error(en
, p
? p
: "");
215 compile_warning(int en
, ...)
219 compile_v_report(0, en
, ap
);
224 compile_warning_at(const char * filename
, unsigned line
, int en
, ...)
228 v_report(0, filename
, line
, 0, en
, ap
);
233 compile_warning_pfx(const prefix
* pfx
, int en
, ...)
237 v_report(0, pfx
->filename
, pfx
->line
, 0, en
, ap
);
241 /* This function makes a note where to put output files */
243 using_data_file(const char *fnm
)
245 if (!fnm_output_base
) {
246 /* was: fnm_output_base = base_from_fnm(fnm); */
247 fnm_output_base
= baseleaf_from_fnm(fnm
);
248 } else if (fnm_output_base_is_dir
) {
249 /* --output pointed to directory so use the leaf basename in that dir */
251 lf
= baseleaf_from_fnm(fnm
);
252 p
= use_path(fnm_output_base
, lf
);
254 osfree(fnm_output_base
);
256 fnm_output_base_is_dir
= 0;
263 while (!isBlank(ch
) && !isEol(ch
)) nextch();
269 while (isBlank(ch
)) nextch();
275 while (!isEol(ch
)) nextch();
293 if (!isComm(ch
)) compile_error(-/*End of line not blank*/15);
299 /* skip any different eol characters so we get line counts correct on
300 * DOS text files and similar, but don't count several adjacent blank
304 if (ch
== eolchar
|| !isEol(ch
)) {
308 if (ch
== '\n') eolchar
= ch
;
310 file
.lpos
= ftell(file
.fh
);
314 process_non_data_line(void)
318 if (isData(ch
)) return fFalse
;
331 read_reading(reading r
, bool f_optional
)
336 case Tape
: q
= Q_LENGTH
; break;
337 case BackTape
: q
= Q_BACKLENGTH
; break;
338 case Comp
: q
= Q_BEARING
; break;
339 case BackComp
: q
= Q_BACKBEARING
; break;
340 case Clino
: q
= Q_GRADIENT
; break;
341 case BackClino
: q
= Q_BACKGRADIENT
; break;
342 case FrDepth
: case ToDepth
: q
= Q_DEPTH
; break;
343 case Dx
: q
= Q_DX
; break;
344 case Dy
: q
= Q_DY
; break;
345 case Dz
: q
= Q_DZ
; break;
346 case FrCount
: case ToCount
: q
= Q_COUNT
; break;
347 case Left
: q
= Q_LEFT
; break;
348 case Right
: q
= Q_RIGHT
; break;
349 case Up
: q
= Q_UP
; break;
350 case Down
: q
= Q_DOWN
; break;
352 q
= Q_NULL
; /* Suppress compiler warning */;
353 BUG("Unexpected case");
355 LOC(r
) = ftell(file
.fh
);
356 VAL(r
) = read_numeric_multi(f_optional
, &n_readings
);
358 if (n_readings
> 1) VAR(r
) /= sqrt(n_readings
);
362 read_bearing_or_omit(reading r
)
365 q_quantity q
= Q_NULL
;
366 LOC(r
) = ftell(file
.fh
);
367 VAL(r
) = read_numeric_multi_or_omit(&n_readings
);
369 case Comp
: q
= Q_BEARING
; break;
370 case BackComp
: q
= Q_BACKBEARING
; break;
372 q
= Q_NULL
; /* Suppress compiler warning */;
373 BUG("Unexpected case");
376 if (n_readings
> 1) VAR(r
) /= sqrt(n_readings
);
379 /* For reading Compass MAK files which have a freeform syntax */
381 nextch_handling_eol(void)
384 while (ch
!= EOF
&& isEol(ch
)) {
390 #define LITLEN(S) (sizeof(S"") - 1)
391 #define has_ext(F,L,E) ((L) > LITLEN(E) + 1 &&\
392 (F)[(L) - LITLEN(E) - 1] == FNM_SEP_EXT &&\
393 strcasecmp((F) + (L) - LITLEN(E), E) == 0)
395 data_file(const char *pth
, const char *fnm
)
397 int begin_lineno_store
;
399 volatile enum {FMT_SVX
, FMT_DAT
, FMT_MAK
} fmt
= FMT_SVX
;
407 /* file specified on command line - don't do special translation */
408 fh
= fopenWithPthAndExt(pth
, fnm
, EXT_SVX_DATA
, "rb", &filename
);
410 fh
= fopen_portable(pth
, fnm
, EXT_SVX_DATA
, "rb", &filename
);
414 compile_error(-/*Couldnāt open file ā%sā*/24, fnm
);
418 len
= strlen(filename
);
419 if (has_ext(filename
, len
, "dat")) {
421 } else if (has_ext(filename
, len
, "mak")) {
426 if (file
.fh
) file
.parent
= &file_store
;
428 file
.filename
= filename
;
431 file
.reported_where
= fFalse
;
434 using_data_file(file
.filename
);
436 begin_lineno_store
= pcs
->begin_lineno
;
437 pcs
->begin_lineno
= 0;
439 if (fmt
== FMT_DAT
) {
444 pcsNew
= osnew(settings
);
445 *pcsNew
= *pcs
; /* copy contents */
446 pcsNew
->begin_lineno
= 0;
452 pcs
->style
= STYLE_NORMAL
;
453 pcs
->units
[Q_LENGTH
] = METRES_PER_FOOT
;
454 t
= ((short*)osmalloc(ossizeof(short) * 257)) + 1;
456 t
[EOF
] = SPECIAL_EOL
;
457 memset(t
, 0, sizeof(short) * 33);
458 for (i
= 33; i
< 127; i
++) t
[i
] = SPECIAL_NAMES
;
460 for (i
= 128; i
< 256; i
++) t
[i
] = SPECIAL_NAMES
;
461 t
['\t'] |= SPECIAL_BLANK
;
462 t
[' '] |= SPECIAL_BLANK
;
463 t
['\032'] |= SPECIAL_EOL
; /* Ctrl-Z, so olde DOS text files are handled ok */
464 t
['\n'] |= SPECIAL_EOL
;
465 t
['\r'] |= SPECIAL_EOL
;
466 t
['.'] |= SPECIAL_DECIMAL
;
467 t
['-'] |= SPECIAL_MINUS
;
468 t
['+'] |= SPECIAL_PLUS
;
471 pcs
->Truncate
= INT_MAX
;
472 pcs
->infer
= BIT(INFER_EQUATES
)|BIT(INFER_EXPORTS
)|BIT(INFER_PLUMBS
);
473 } else if (fmt
== FMT_MAK
) {
478 pcsNew
= osnew(settings
);
479 *pcsNew
= *pcs
; /* copy contents */
480 pcsNew
->begin_lineno
= 0;
484 t
= ((short*)osmalloc(ossizeof(short) * 257)) + 1;
486 t
[EOF
] = SPECIAL_EOL
;
487 memset(t
, 0, sizeof(short) * 33);
488 for (i
= 33; i
< 127; i
++) t
[i
] = SPECIAL_NAMES
;
490 for (i
= 128; i
< 256; i
++) t
[i
] = SPECIAL_NAMES
;
491 t
['['] = t
[','] = t
[';'] = 0;
492 t
['\t'] |= SPECIAL_BLANK
;
493 t
[' '] |= SPECIAL_BLANK
;
494 t
['\032'] |= SPECIAL_EOL
; /* Ctrl-Z, so olde DOS text files are handled ok */
495 t
['\n'] |= SPECIAL_EOL
;
496 t
['\r'] |= SPECIAL_EOL
;
497 t
['.'] |= SPECIAL_DECIMAL
;
498 t
['-'] |= SPECIAL_MINUS
;
499 t
['+'] |= SPECIAL_PLUS
;
502 pcs
->Truncate
= INT_MAX
;
506 /* errors in nested functions can longjmp here */
507 if (setjmp(file
.jbSkipLine
)) {
513 if (fmt
== FMT_DAT
) {
514 while (!feof(file
.fh
) && !ferror(file
.fh
)) {
515 static reading compass_order
[] = {
516 Fr
, To
, Tape
, CompassDATComp
, CompassDATClino
,
517 CompassDATLeft
, CompassDATRight
, CompassDATUp
, CompassDATDown
,
518 CompassDATFlags
, IgnoreAll
520 static reading compass_order_backsights
[] = {
521 Fr
, To
, Tape
, CompassDATComp
, CompassDATClino
,
522 CompassDATLeft
, CompassDATRight
, CompassDATUp
, CompassDATDown
,
523 CompassDATBackComp
, CompassDATBackClino
,
524 CompassDATFlags
, IgnoreAll
530 /* SURVEY NAME: <Short name> */
533 /* if (ch != ':') ... */
538 /* SURVEY DATE: 7 10 79 COMMENT:<Long name> */
541 copy_on_write_meta(pcs
);
543 int year
, month
, day
;
547 /* NB order is *month* *day* year */
551 /* Note: Larry says a 2 digit year is always 19XX */
552 if (year
< 100) year
+= 1900;
554 pcs
->meta
->days1
= pcs
->meta
->days2
= days_since_1900(year
, month
, day
);
556 pcs
->meta
->days1
= pcs
->meta
->days2
= -1;
558 pcs
->declination
= HUGE_REAL
;
570 /* DECLINATION: 1.00 FORMAT: DDDDLUDRADLN CORRECTIONS: 2.00 3.00 4.00 */
574 pcs
->z
[Q_DECLINATION
] = -read_numeric(fFalse
);
575 pcs
->z
[Q_DECLINATION
] *= pcs
->units
[Q_DECLINATION
];
577 pcs
->ordering
= compass_order
;
578 if (strcmp(buffer
, "FORMAT") == 0) {
581 if (strlen(buffer
) >= 12 && buffer
[11] == 'B') {
582 /* We have backsights for compass and clino */
583 pcs
->ordering
= compass_order_backsights
;
587 if (strcmp(buffer
, "CORRECTIONS") == 0) {
589 pcs
->z
[Q_BEARING
] = -rad(read_numeric(fFalse
));
590 pcs
->z
[Q_GRADIENT
] = -rad(read_numeric(fFalse
));
591 pcs
->z
[Q_LENGTH
] = -read_numeric(fFalse
);
593 pcs
->z
[Q_BEARING
] = 0;
594 pcs
->z
[Q_GRADIENT
] = 0;
595 pcs
->z
[Q_LENGTH
] = 0;
611 while (!feof(file
.fh
)) {
623 settings
*pcsParent
= pcs
->next
;
624 SVX_ASSERT(pcsParent
);
625 pcs
->ordering
= NULL
;
629 } else if (fmt
== FMT_MAK
) {
630 nextch_handling_eol();
631 while (!feof(file
.fh
) && !ferror(file
.fh
)) {
635 char *dat_pth
= path_from_fnm(file
.filename
);
636 char *dat_fnm
= NULL
;
638 nextch_handling_eol();
639 while (ch
!= ',' && ch
!= ';' && ch
!= EOF
) {
640 while (isEol(ch
)) process_eol();
641 s_catchar(&dat_fnm
, &dat_fnm_len
, (char)ch
);
642 nextch_handling_eol();
644 while (ch
!= ';' && ch
!= EOF
) {
646 nextch_handling_eol();
647 name
= read_prefix(PFX_STATION
|PFX_OPT
);
654 name
->sflags
|= BIT(SFLAGS_FIXED
);
655 nextch_handling_eol();
656 while (!isdigit(ch
) && ch
!= '+' && ch
!= '-' &&
657 ch
!= '.' && ch
!= ']' && ch
!= EOF
) {
658 nextch_handling_eol();
660 x
= read_numeric(fFalse
);
661 while (!isdigit(ch
) && ch
!= '+' && ch
!= '-' &&
662 ch
!= '.' && ch
!= ']' && ch
!= EOF
) {
663 nextch_handling_eol();
665 y
= read_numeric(fFalse
);
666 while (!isdigit(ch
) && ch
!= '+' && ch
!= '-' &&
667 ch
!= '.' && ch
!= ']' && ch
!= EOF
) {
668 nextch_handling_eol();
670 z
= read_numeric(fFalse
);
671 stn
= StnFromPfx(name
);
678 if (x
!= POS(stn
, 0) || y
!= POS(stn
, 1) ||
680 compile_error(/*Station already fixed or equated to a fixed point*/46);
682 compile_warning(/*Station already fixed at the same coordinates*/55);
685 while (ch
!= ']' && ch
!= EOF
) nextch_handling_eol();
687 nextch_handling_eol();
691 /* FIXME: link station - ignore for now */
692 /* FIXME: perhaps issue warning? */
694 while (ch
!= ',' && ch
!= ';' && ch
!= EOF
)
695 nextch_handling_eol();
700 data_file(dat_pth
, dat_fnm
);
705 /* FIXME: also check for % and $ later */
706 nextch_handling_eol();
710 settings
*pcsParent
= pcs
->next
;
711 SVX_ASSERT(pcsParent
);
716 while (!feof(file
.fh
) && !ferror(file
.fh
)) {
717 if (!process_non_data_line()) {
718 f_export_ok
= fFalse
;
719 switch (pcs
->style
) {
725 case STYLE_CARTESIAN
:
745 /* don't allow *BEGIN at the end of a file, then *EXPORT in the
747 f_export_ok
= fFalse
;
749 if (pcs
->begin_lineno
) {
750 error_in_file(file
.filename
, pcs
->begin_lineno
,
751 /*BEGIN with no matching END in this file*/23);
752 /* Implicitly close any unclosed BEGINs from this file */
754 settings
*pcsParent
= pcs
->next
;
755 SVX_ASSERT(pcsParent
);
758 } while (pcs
->begin_lineno
);
761 pcs
->begin_lineno
= begin_lineno_store
;
764 fatalerror_in_file(file
.filename
, 0, /*Error reading file*/18);
766 (void)fclose(file
.fh
);
770 /* don't free this - it may be pointed to by prefix.file */
771 /* osfree(file.filename); */
777 return a
- floor(a
/ (2 * M_PI
)) * (2 * M_PI
);
781 handle_plumb(clino_type
*p_ctype
)
784 CLINO_NULL
=-1, CLINO_UP
, CLINO_DOWN
, CLINO_LEVEL
786 static sztok clino_tab
[] = {
788 {"DOWN", CLINO_DOWN
},
790 {"LEVEL", CLINO_LEVEL
},
795 static real clinos
[] = {(real
)M_PI_2
, (real
)(-M_PI_2
), (real
)0.0};
803 tok
= match_tok(clino_tab
, TABSIZE(clino_tab
));
804 if (tok
!= CLINO_NULL
) {
805 *p_ctype
= (tok
== CLINO_LEVEL
? CTYPE_HORIZ
: CTYPE_PLUMB
);
809 } else if (isSign(ch
)) {
812 if (toupper(ch
) == 'V') {
814 *p_ctype
= CTYPE_PLUMB
;
815 return (!isMinus(chOld
) ? M_PI_2
: -M_PI_2
);
819 *p_ctype
= CTYPE_OMIT
;
820 /* no clino reading, so assume 0 with large sd */
823 } else if (isOmit(ch
)) {
824 /* OMIT char may not be a SIGN char too so we need to check here as
825 * well as above... */
827 *p_ctype
= CTYPE_OMIT
;
828 /* no clino reading, so assume 0 with large sd */
835 warn_readings_differ(int msgno
, real diff
, int units
)
839 diff
/= get_units_factor(units
);
840 sprintf(buf
, "%.2f", fabs(diff
));
841 for (p
= buf
; *p
; ++p
) {
845 if (*p
!= '0') z
= p
+ 1;
851 strcpy(p
, get_units_string(units
));
852 compile_warning(msgno
, buf
);
856 handle_comp_units(void)
858 bool fNoComp
= fTrue
;
859 if (VAL(Comp
) != HUGE_REAL
) {
861 VAL(Comp
) *= pcs
->units
[Q_BEARING
];
862 if (VAL(Comp
) < (real
)0.0 || VAL(Comp
) - M_PI
* 2.0 > EPSILON
) {
863 /* TRANSLATORS: Suspicious means something like 410 degrees or -20
865 compile_warning(/*Suspicious compass reading*/59);
866 VAL(Comp
) = mod2pi(VAL(Comp
));
869 if (VAL(BackComp
) != HUGE_REAL
) {
871 VAL(BackComp
) *= pcs
->units
[Q_BACKBEARING
];
872 if (VAL(BackComp
) < (real
)0.0 || VAL(BackComp
) - M_PI
* 2.0 > EPSILON
) {
873 /* FIXME: different message for BackComp? */
874 compile_warning(/*Suspicious compass reading*/59);
875 VAL(BackComp
) = mod2pi(VAL(BackComp
));
882 handle_compass(real
*p_var
)
884 real compvar
= VAR(Comp
);
885 real comp
= VAL(Comp
);
886 real backcomp
= VAL(BackComp
);
888 if (pcs
->z
[Q_DECLINATION
] != HUGE_REAL
) {
889 declination
= -pcs
->z
[Q_DECLINATION
];
890 } else if (pcs
->declination
!= HUGE_REAL
) {
891 /* Cached value calculated for a previous compass reading taken on the
892 * same date (by the 'else' just below).
894 declination
= pcs
->declination
;
896 if (!pcs
->meta
|| pcs
->meta
->days1
== -1) {
897 compile_warning(/*No survey date specified - using 0 for magnetic declination*/304);
900 int avg_days
= (pcs
->meta
->days1
+ pcs
->meta
->days2
) / 2;
901 double dat
= julian_date_from_days_since_1900(avg_days
);
902 /* thgeomag() takes (lat, lon, h, dat) - i.e. (y, x, z, date). */
903 declination
= thgeomag(pcs
->dec_y
, pcs
->dec_x
, pcs
->dec_z
, dat
);
905 declination
-= pcs
->convergence
;
906 /* We cache the calculated declination as the calculation is relatively
907 * expensive. We also cache an "assumed 0" answer so that we only
908 * warn once per such survey rather than for every line with a compass
910 pcs
->declination
= declination
;
912 if (comp
!= HUGE_REAL
) {
913 comp
= (comp
- pcs
->z
[Q_BEARING
]) * pcs
->sc
[Q_BEARING
];
916 if (backcomp
!= HUGE_REAL
) {
917 backcomp
= (backcomp
- pcs
->z
[Q_BACKBEARING
])
918 * pcs
->sc
[Q_BACKBEARING
];
919 backcomp
+= declination
;
921 if (comp
!= HUGE_REAL
) {
922 real diff
= comp
- backcomp
;
923 real adj
= fabs(diff
) > M_PI
? M_PI
: 0;
924 diff
-= floor((diff
+ M_PI
) / (2 * M_PI
)) * 2 * M_PI
;
925 if (sqrd(diff
/ 3.0) > compvar
+ VAR(BackComp
)) {
926 /* fore and back readings differ by more than 3 sds */
927 /* TRANSLATORS: %s is replaced by the amount the readings disagree
928 * by, e.g. "2.5Ā°" or "3įµ". */
929 warn_readings_differ(/*COMPASS reading and BACKCOMPASS reading disagree by %s*/98,
930 diff
, get_angle_units(Q_BEARING
));
932 comp
= (comp
/ compvar
+ backcomp
/ VAR(BackComp
));
933 compvar
= (compvar
+ VAR(BackComp
)) / 4;
938 compvar
= VAR(BackComp
);
946 process_normal(prefix
*fr
, prefix
*to
, bool fToFirst
,
947 clino_type ctype
, clino_type backctype
)
949 real tape
= VAL(Tape
);
950 real clin
= VAL(Clino
);
951 real backclin
= VAL(BackClino
);
955 #ifndef NO_COVARIANCES
961 /* adjusted tape is negative -- probably the calibration is wrong */
962 if (tape
< (real
)0.0) {
963 /* TRANSLATE different message for topofil? */
964 compile_warning(/*Negative adjusted tape reading*/79);
967 fNoComp
= handle_comp_units();
969 if (ctype
== CTYPE_READING
) {
972 real diff_from_abs90
;
973 clin
*= pcs
->units
[Q_GRADIENT
];
974 /* percentage scale */
975 if (pcs
->f_clino_percent
) clin
= atan(clin
);
976 /* We want to warn if there's a reading which it would be impossible
977 * to have read from the instrument (e.g. on a -90 to 90 degree scale
978 * you can't read "96" (it's probably a typo for "69"). However, the
979 * gradient reading from a topofil is typically in the range 0 to 180,
980 * with 90 being horizontal.
982 * Really we should allow the valid range to be specified, but for now
983 * we infer it from the zero error - if this is within 45 degrees of
984 * 90 then we assume the range is 0 to 180.
986 z
= pcs
->z
[Q_GRADIENT
];
987 range_0_180
= (z
> M_PI_4
&& z
< 3*M_PI_4
);
988 diff_from_abs90
= fabs(clin
) - M_PI_2
;
989 if (diff_from_abs90
> EPSILON
) {
991 int clino_units
= get_angle_units(Q_GRADIENT
);
992 const char * units
= get_units_string(clino_units
);
993 real right_angle
= M_PI_2
/ get_units_factor(clino_units
);
994 /* TRANSLATORS: %.f%s will be replaced with a right angle in the
995 * units currently in use, e.g. "90Ā°" or "100įµ". And "absolute
996 * value" means the reading ignoring the sign (so it might be
997 * < -90Ā° or > 90Ā°. */
998 compile_warning(/*Clino reading over %.f%s (absolute value)*/51,
1001 } else if (TSTBIT(pcs
->infer
, INFER_PLUMBS
) &&
1002 diff_from_abs90
>= -EPSILON
) {
1003 ctype
= CTYPE_INFERPLUMB
;
1005 if (range_0_180
&& ctype
!= CTYPE_INFERPLUMB
) {
1006 /* FIXME: Warning message not ideal... */
1007 if (clin
< 0.0 || clin
- M_PI
> EPSILON
) {
1008 int clino_units
= get_angle_units(Q_GRADIENT
);
1009 const char * units
= get_units_string(clino_units
);
1010 real right_angle
= M_PI_2
/ get_units_factor(clino_units
);
1011 compile_warning(/*Clino reading over %.f%s (absolute value)*/51,
1012 right_angle
, units
);
1017 if (backctype
== CTYPE_READING
) {
1018 backclin
*= pcs
->units
[Q_BACKGRADIENT
];
1019 /* percentage scale */
1020 if (pcs
->f_backclino_percent
) backclin
= atan(backclin
);
1021 /* FIXME: Add range_0_180 handling here too */
1022 if (ctype
!= CTYPE_READING
) {
1023 real diff_from_abs90
= fabs(backclin
) - M_PI_2
;
1024 if (diff_from_abs90
> EPSILON
) {
1025 /* FIXME: different message for BackClino? */
1026 int clino_units
= get_angle_units(Q_BACKGRADIENT
);
1027 const char * units
= get_units_string(clino_units
);
1028 real right_angle
= M_PI_2
/ get_units_factor(clino_units
);
1029 compile_warning(/*Clino reading over %.f%s (absolute value)*/51,
1030 right_angle
, units
);
1031 } else if (TSTBIT(pcs
->infer
, INFER_PLUMBS
) &&
1032 diff_from_abs90
>= -EPSILON
) {
1033 backctype
= CTYPE_INFERPLUMB
;
1038 /* un-infer the plumb if the backsight was just a reading */
1039 if (ctype
== CTYPE_INFERPLUMB
&& backctype
== CTYPE_READING
) {
1040 ctype
= CTYPE_READING
;
1043 if (ctype
!= CTYPE_OMIT
&& backctype
!= CTYPE_OMIT
&& ctype
!= backctype
) {
1044 /* TRANSLATORS: In data with backsights, the user has tried to give a
1045 * plumb for the foresight and a clino reading for the backsight, or
1046 * something similar. */
1047 compile_error_reading_skip(Clino
, /*CLINO and BACKCLINO readings must be of the same type*/84);
1051 if (ctype
== CTYPE_PLUMB
|| ctype
== CTYPE_INFERPLUMB
||
1052 backctype
== CTYPE_PLUMB
|| backctype
== CTYPE_INFERPLUMB
) {
1055 if (ctype
== CTYPE_PLUMB
||
1056 (ctype
== CTYPE_INFERPLUMB
&& VAL(Comp
) != 0.0) ||
1057 backctype
== CTYPE_PLUMB
||
1058 (backctype
== CTYPE_INFERPLUMB
&& VAL(BackComp
) != 0.0)) {
1059 /* FIXME: Different message for BackComp? */
1060 /* TRANSLATORS: A "plumbed leg" is one measured using a plumbline
1061 * (a weight on a string). So the problem here is that the leg is
1062 * vertical, so a compass reading has no meaning! */
1063 compile_warning(/*Compass reading given on plumbed leg*/21);
1067 dx
= dy
= (real
)0.0;
1068 if (ctype
!= CTYPE_OMIT
) {
1069 if (backctype
!= CTYPE_OMIT
&& (clin
> 0) == (backclin
> 0)) {
1070 /* TRANSLATORS: We've been told the foresight and backsight are
1071 * both "UP", or that they're both "DOWN". */
1072 compile_error_reading_skip(Clino
, /*Plumbed CLINO and BACKCLINO readings can't be in the same direction*/92);
1075 dz
= (clin
> (real
)0.0) ? tape
: -tape
;
1077 dz
= (backclin
< (real
)0.0) ? tape
: -tape
;
1079 vx
= vy
= var(Q_POS
) / 3.0 + dz
* dz
* var(Q_PLUMB
);
1080 vz
= var(Q_POS
) / 3.0 + VAR(Tape
);
1081 #ifndef NO_COVARIANCES
1082 /* Correct values - no covariances in this case! */
1083 cxy
= cyz
= czx
= (real
)0.0;
1086 /* Each of ctype and backctype are either CTYPE_READING/CTYPE_HORIZ
1089 real L2
, cosG
, LcosG
, cosG2
, sinB
, cosB
, dx2
, dy2
, dz2
, v
, V
;
1091 /* TRANSLATORS: Here "legs" are survey legs, i.e. measurements between
1092 * survey stations. */
1093 compile_error_reading_skip(Comp
, /*Compass reading may not be omitted except on plumbed legs*/14);
1096 if (tape
== (real
)0.0) {
1097 dx
= dy
= dz
= (real
)0.0;
1098 vx
= vy
= vz
= (real
)(var(Q_POS
) / 3.0); /* Position error only */
1099 #ifndef NO_COVARIANCES
1100 cxy
= cyz
= czx
= (real
)0.0;
1103 printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx
, vy
, vz
);
1107 /* take into account variance in LEVEL case */
1108 real var_clin
= var(Q_LEVEL
);
1110 real comp
= handle_compass(&var_comp
);
1111 /* ctype != CTYPE_READING is LEVEL case */
1112 if (ctype
== CTYPE_READING
) {
1113 clin
= (clin
- pcs
->z
[Q_GRADIENT
]) * pcs
->sc
[Q_GRADIENT
];
1114 var_clin
= VAR(Clino
);
1116 if (backctype
== CTYPE_READING
) {
1117 backclin
= (backclin
- pcs
->z
[Q_BACKGRADIENT
])
1118 * pcs
->sc
[Q_BACKGRADIENT
];
1119 if (ctype
== CTYPE_READING
) {
1120 if (sqrd((clin
+ backclin
) / 3.0) > var_clin
+ VAR(BackClino
)) {
1121 /* fore and back readings differ by more than 3 sds */
1122 /* TRANSLATORS: %s is replaced by the amount the readings disagree
1123 * by, e.g. "2.5Ā°" or "3įµ". */
1124 warn_readings_differ(/*CLINO reading and BACKCLINO reading disagree by %s*/99,
1125 clin
+ backclin
, get_angle_units(Q_GRADIENT
));
1127 clin
= (clin
/ var_clin
- backclin
/ VAR(BackClino
));
1128 var_clin
= (var_clin
+ VAR(BackClino
)) / 4;
1132 var_clin
= VAR(BackClino
);
1137 printf(" %4.2f %4.2f %4.2f\n", tape
, comp
, clin
);
1140 LcosG
= tape
* cosG
;
1144 printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB
, cosG
, LcosG
);
1148 dz
= tape
* sin(clin
);
1149 /* printf("%.2f\n",clin); */
1151 printf("dx = %f\ndy = %f\ndz = %f\n", dx
, dy
, dz
);
1157 cosG2
= cosG
* cosG
;
1158 sinGcosG
= sin(clin
) * cosG
;
1161 #ifdef NO_COVARIANCES
1162 vx
= (var(Q_POS
) / 3.0 + dx2
* V
+ dy2
* var_comp
+
1163 (.5 + sinB
* sinB
* cosG2
) * v
);
1164 vy
= (var(Q_POS
) / 3.0 + dy2
* V
+ dx2
* var_comp
+
1165 (.5 + cosB
* cosB
* cosG2
) * v
);
1166 if (ctype
== CTYPE_OMIT
&& backctype
== CTYPE_OMIT
) {
1167 /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */
1168 vz
= var(Q_POS
) / 3.0 + L2
* (real
)0.1;
1170 vz
= var(Q_POS
) / 3.0 + dz2
* V
+ L2
* cosG2
* var_clin
;
1172 /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */
1174 vx
= var(Q_POS
) / 3.0 + dx2
* V
+ dy2
* var_comp
+
1176 vy
= var(Q_POS
) / 3.0 + dy2
* V
+ dx2
* var_comp
+
1178 if (ctype
== CTYPE_OMIT
&& backctype
== CTYPE_OMIT
) {
1179 /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */
1180 vz
= var(Q_POS
) / 3.0 + L2
* (real
)0.1;
1182 vz
= var(Q_POS
) / 3.0 + dz2
* V
+ L2
* cosG2
* var_clin
;
1184 /* usual covariance formulae are fine in no clino case since
1185 * dz = 0 so value of var_clin is ignored */
1186 cxy
= sinB
* cosB
* (VAR(Tape
) * cosG2
+ var_clin
* dz2
)
1187 - var_comp
* dx
* dy
;
1188 czx
= VAR(Tape
) * sinB
* sinGcosG
- var_clin
* dx
* dz
;
1189 cyz
= VAR(Tape
) * cosB
* sinGcosG
- var_clin
* dy
* dz
;
1191 printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx
, vy
, vz
);
1192 printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy
, cyz
, czx
);
1196 printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx
, vy
, vz
);
1201 printf("Just before addleg, vx = %f\n", vx
);
1203 /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/
1204 addlegbyname(fr
, to
, fToFirst
, dx
, dy
, dz
, vx
, vy
, vz
1205 #ifndef NO_COVARIANCES
1213 process_diving(prefix
*fr
, prefix
*to
, bool fToFirst
, bool fDepthChange
)
1215 real tape
= VAL(Tape
);
1219 #ifndef NO_COVARIANCES
1220 real cxy
= 0, cyz
= 0, czx
= 0;
1223 handle_comp_units();
1225 /* depth gauge readings increase upwards with default calibration */
1227 SVX_ASSERT(VAL(FrDepth
) == 0.0);
1228 dz
= VAL(ToDepth
) * pcs
->units
[Q_DEPTH
] - pcs
->z
[Q_DEPTH
];
1229 dz
*= pcs
->sc
[Q_DEPTH
];
1231 dz
= VAL(ToDepth
) - VAL(FrDepth
);
1232 dz
*= pcs
->units
[Q_DEPTH
] * pcs
->sc
[Q_DEPTH
];
1235 /* adjusted tape is negative -- probably the calibration is wrong */
1236 if (tape
< (real
)0.0) {
1237 compile_warning(/*Negative adjusted tape reading*/79);
1240 /* check if tape is less than depth change */
1241 if (tape
< fabs(dz
)) {
1242 /* FIXME: allow margin of error based on variances? */
1243 /* TRANSLATORS: This means that the data fed in said this.
1245 * It could be a gross error (e.g. the decimal point is missing from the
1246 * depth gauge reading) or it could just be due to random error on a near
1248 compile_warning(/*Tape reading is less than change in depth*/62);
1251 if (tape
== (real
)0.0 && dz
== 0.0) {
1252 dx
= dy
= dz
= (real
)0.0;
1253 vx
= vy
= vz
= (real
)(var(Q_POS
) / 3.0); /* Position error only */
1254 } else if (VAL(Comp
) == HUGE_REAL
&&
1255 VAL(BackComp
) == HUGE_REAL
) {
1257 dx
= dy
= (real
)0.0;
1258 if (dz
< 0) tape
= -tape
;
1259 /* FIXME: Should use FrDepth sometimes... */
1260 dz
= (dz
* VAR(Tape
) + tape
* 2 * VAR(ToDepth
))
1261 / (VAR(Tape
) * 2 * VAR(ToDepth
));
1262 vx
= vy
= var(Q_POS
) / 3.0 + dz
* dz
* var(Q_PLUMB
);
1263 /* FIXME: Should use FrDepth sometimes... */
1264 vz
= var(Q_POS
) / 3.0 + VAR(Tape
) * 2 * VAR(ToDepth
)
1265 / (VAR(Tape
) + VAR(ToDepth
));
1267 real L2
, sinB
, cosB
, dz2
, D2
;
1269 real comp
= handle_compass(&var_comp
);
1275 if (D2
<= (real
)0.0) {
1276 /* FIXME: Should use FrDepth sometimes... */
1277 real vsum
= VAR(Tape
) + 2 * VAR(ToDepth
);
1278 dx
= dy
= (real
)0.0;
1279 vx
= vy
= var(Q_POS
) / 3.0;
1280 /* FIXME: Should use FrDepth sometimes... */
1281 vz
= var(Q_POS
) / 3.0 + VAR(Tape
) * 2 * VAR(ToDepth
) / vsum
;
1283 /* FIXME: Should use FrDepth sometimes... */
1284 dz
= (dz
* VAR(Tape
) + tape
* 2 * VAR(ToDepth
)) / vsum
;
1286 dz
= (dz
* VAR(Tape
) - tape
* 2 * VAR(ToDepth
)) / vsum
;
1290 /* FIXME: Should use FrDepth sometimes... */
1291 real F
= VAR(Tape
) * L2
+ 2 * VAR(ToDepth
) * D2
;
1295 vx
= var(Q_POS
) / 3.0 +
1296 sinB
* sinB
* F
/ D2
+ var_comp
* dy
* dy
;
1297 vy
= var(Q_POS
) / 3.0 +
1298 cosB
* cosB
* F
/ D2
+ var_comp
* dx
* dx
;
1299 /* FIXME: Should use FrDepth sometimes... */
1300 vz
= var(Q_POS
) / 3.0 + 2 * VAR(ToDepth
);
1302 #ifndef NO_COVARIANCES
1303 cxy
= sinB
* cosB
* (F
/ D2
+ var_comp
* D2
);
1304 /* FIXME: Should use FrDepth sometimes... */
1305 cyz
= -2 * VAR(ToDepth
) * dy
/ D
;
1306 czx
= -2 * VAR(ToDepth
) * dx
/ D
;
1309 /* FIXME: If there's a clino reading, check it against the depth reading,
1311 * if (VAL(Clino) != HUGE_REAL || VAL(BackClino) != HUGE_REAL) { ... }
1314 addlegbyname(fr
, to
, fToFirst
, dx
, dy
, dz
, vx
, vy
, vz
1315 #ifndef NO_COVARIANCES
1323 process_cartesian(prefix
*fr
, prefix
*to
, bool fToFirst
)
1325 real dx
= (VAL(Dx
) * pcs
->units
[Q_DX
] - pcs
->z
[Q_DX
]) * pcs
->sc
[Q_DX
];
1326 real dy
= (VAL(Dy
) * pcs
->units
[Q_DY
] - pcs
->z
[Q_DY
]) * pcs
->sc
[Q_DY
];
1327 real dz
= (VAL(Dz
) * pcs
->units
[Q_DZ
] - pcs
->z
[Q_DZ
]) * pcs
->sc
[Q_DZ
];
1329 addlegbyname(fr
, to
, fToFirst
, dx
, dy
, dz
, VAR(Dx
), VAR(Dy
), VAR(Dz
)
1330 #ifndef NO_COVARIANCES
1338 data_cartesian(void)
1340 prefix
*fr
= NULL
, *to
= NULL
;
1342 bool fMulti
= fFalse
;
1344 reading first_stn
= End
;
1350 for (ordering
= pcs
->ordering
; ; ordering
++) {
1352 switch (*ordering
) {
1354 fr
= read_prefix(PFX_STATION
|PFX_ALLOW_ROOT
);
1355 if (first_stn
== End
) first_stn
= Fr
;
1358 to
= read_prefix(PFX_STATION
|PFX_ALLOW_ROOT
);
1359 if (first_stn
== End
) first_stn
= To
;
1363 to
= read_prefix(PFX_STATION
);
1366 case Dx
: case Dy
: case Dz
:
1367 read_reading(*ordering
, fFalse
);
1371 case IgnoreAllAndNewLine
:
1376 if (!process_cartesian(fr
, to
, first_stn
== To
))
1383 if (isData(ch
)) break;
1395 process_cartesian(fr
, to
, first_stn
== To
);
1402 } while (isComm(ch
));
1404 default: BUG("Unknown reading in ordering");
1410 process_cylpolar(prefix
*fr
, prefix
*to
, bool fToFirst
, bool fDepthChange
)
1412 real tape
= VAL(Tape
);
1416 #ifndef NO_COVARIANCES
1420 handle_comp_units();
1422 /* depth gauge readings increase upwards with default calibration */
1424 SVX_ASSERT(VAL(FrDepth
) == 0.0);
1425 dz
= VAL(ToDepth
) * pcs
->units
[Q_DEPTH
] - pcs
->z
[Q_DEPTH
];
1426 dz
*= pcs
->sc
[Q_DEPTH
];
1428 dz
= VAL(ToDepth
) - VAL(FrDepth
);
1429 dz
*= pcs
->units
[Q_DEPTH
] * pcs
->sc
[Q_DEPTH
];
1432 /* adjusted tape is negative -- probably the calibration is wrong */
1433 if (tape
< (real
)0.0) {
1434 compile_warning(/*Negative adjusted tape reading*/79);
1437 if (VAL(Comp
) == HUGE_REAL
&& VAL(BackComp
) == HUGE_REAL
) {
1439 dx
= dy
= (real
)0.0;
1440 vx
= vy
= var(Q_POS
) / 3.0 + dz
* dz
* var(Q_PLUMB
);
1441 /* FIXME: Should use FrDepth sometimes... */
1442 vz
= var(Q_POS
) / 3.0 + 2 * VAR(ToDepth
);
1446 real comp
= handle_compass(&var_comp
);
1453 vx
= var(Q_POS
) / 3.0 +
1454 VAR(Tape
) * sinB
* sinB
+ var_comp
* dy
* dy
;
1455 vy
= var(Q_POS
) / 3.0 +
1456 VAR(Tape
) * cosB
* cosB
+ var_comp
* dx
* dx
;
1457 /* FIXME: Should use FrDepth sometimes... */
1458 vz
= var(Q_POS
) / 3.0 + 2 * VAR(ToDepth
);
1460 #ifndef NO_COVARIANCES
1461 cxy
= (VAR(Tape
) - var_comp
* tape
* tape
) * sinB
* cosB
;
1464 addlegbyname(fr
, to
, fToFirst
, dx
, dy
, dz
, vx
, vy
, vz
1465 #ifndef NO_COVARIANCES
1472 /* Process tape/compass/clino, diving, and cylpolar styles of survey data
1473 * Also handles topofil (fromcount/tocount or count) in place of tape */
1477 prefix
*fr
= NULL
, *to
= NULL
;
1478 reading first_stn
= End
;
1480 bool fTopofil
= fFalse
, fMulti
= fFalse
;
1482 clino_type ctype
, backctype
;
1484 unsigned long compass_dat_flags
= 0;
1488 VAL(Tape
) = VAL(BackTape
) = HUGE_REAL
;
1489 VAL(Comp
) = VAL(BackComp
) = HUGE_REAL
;
1490 VAL(FrCount
) = VAL(ToCount
) = 0;
1491 VAL(FrDepth
) = VAL(ToDepth
) = 0;
1492 VAL(Left
) = VAL(Right
) = VAL(Up
) = VAL(Down
) = HUGE_REAL
;
1495 ctype
= backctype
= CTYPE_OMIT
;
1496 fDepthChange
= fFalse
;
1498 /* ordering may omit clino reading, so set up default here */
1499 /* this is also used if clino reading is the omit character */
1500 VAL(Clino
) = VAL(BackClino
) = 0;
1504 /* We clear these flags in the normal course of events, but if there's an
1505 * error in a reading, we might not, so make sure it has been cleared here.
1507 pcs
->flags
&= ~(BIT(FLAGS_ANON_ONE_END
) | BIT(FLAGS_IMPLICIT_SPLAY
));
1508 for (ordering
= pcs
->ordering
; ; ordering
++) {
1510 switch (*ordering
) {
1512 fr
= read_prefix(PFX_STATION
|PFX_ALLOW_ROOT
|PFX_ANON
);
1513 if (first_stn
== End
) first_stn
= Fr
;
1516 to
= read_prefix(PFX_STATION
|PFX_ALLOW_ROOT
|PFX_ANON
);
1517 if (first_stn
== End
) first_stn
= To
;
1521 to
= read_prefix(PFX_STATION
);
1526 DIR_NULL
=-1, DIR_FORE
, DIR_BACK
1528 static sztok dir_tab
[] = {
1534 tok
= match_tok(dir_tab
, TABSIZE(dir_tab
));
1542 file
.lpos
+= strlen(buffer
);
1543 compile_error_skip(-/*Found ā%sā, expecting āFā or āBā*/131,
1550 case Tape
: case BackTape
: {
1551 reading r
= *ordering
;
1552 read_reading(r
, fTrue
);
1553 if (VAL(r
) == HUGE_REAL
) {
1555 compile_error_token(-/*Expecting numeric field, found ā%sā*/9);
1556 /* Avoid also warning about omitted tape reading. */
1561 } else if (VAL(r
) < (real
)0.0) {
1562 compile_warning(-/*Negative tape reading*/60);
1567 VAL(FrCount
) = VAL(ToCount
);
1568 LOC(FrCount
) = LOC(ToCount
);
1569 read_reading(ToCount
, fFalse
);
1573 read_reading(FrCount
, fFalse
);
1576 read_reading(ToCount
, fFalse
);
1579 case Comp
: case BackComp
:
1580 read_bearing_or_omit(*ordering
);
1582 case Clino
: case BackClino
: {
1583 reading r
= *ordering
;
1584 clino_type
* p_ctype
= (r
== Clino
? &ctype
: &backctype
);
1585 read_reading(r
, fTrue
);
1586 if (VAL(r
) == HUGE_REAL
) {
1587 VAL(r
) = handle_plumb(p_ctype
);
1588 if (VAL(r
) != HUGE_REAL
) break;
1589 compile_error_token(-/*Expecting numeric field, found ā%sā*/9);
1594 *p_ctype
= CTYPE_READING
;
1597 case FrDepth
: case ToDepth
:
1598 read_reading(*ordering
, fFalse
);
1601 VAL(FrDepth
) = VAL(ToDepth
);
1602 LOC(FrDepth
) = LOC(ToDepth
);
1603 read_reading(ToDepth
, fFalse
);
1606 fDepthChange
= fTrue
;
1608 read_reading(ToDepth
, fFalse
);
1610 case CompassDATComp
:
1611 read_bearing_or_omit(Comp
);
1612 if (is_compass_NaN(VAL(Comp
))) VAL(Comp
) = HUGE_REAL
;
1614 case CompassDATBackComp
:
1615 read_bearing_or_omit(BackComp
);
1616 if (is_compass_NaN(VAL(BackComp
))) VAL(BackComp
) = HUGE_REAL
;
1618 case CompassDATClino
: case CompassDATBackClino
: {
1620 clino_type
* p_ctype
;
1621 if (*ordering
== CompassDATClino
) {
1626 p_ctype
= &backctype
;
1628 read_reading(r
, fFalse
);
1629 if (is_compass_NaN(VAL(r
))) {
1631 *p_ctype
= CTYPE_OMIT
;
1633 *p_ctype
= CTYPE_READING
;
1637 case CompassDATLeft
: case CompassDATRight
:
1638 case CompassDATUp
: case CompassDATDown
: {
1639 /* FIXME: need to actually make use of these entries! */
1640 reading actual
= Left
+ (*ordering
- CompassDATLeft
);
1641 read_reading(actual
, fFalse
);
1642 if (VAL(actual
) < 0) VAL(actual
) = HUGE_REAL
;
1645 case CompassDATFlags
:
1652 while (ch
>= 'A' && ch
<= 'Z') {
1653 compass_dat_flags
|= BIT(ch
- 'A');
1654 /* We currently understand:
1655 * L (exclude from length)
1657 * FIXME: but should also handle at least some of:
1658 * C (no adjustment) (set all (co)variances to 0?)
1659 * P (no plot) (new flag in 3d for "hidden by default"?)
1666 compass_dat_flags
= 0;
1679 case IgnoreAllAndNewLine
:
1688 VAL(Tape
) = VAL(ToCount
) - VAL(FrCount
);
1689 LOC(Tape
) = LOC(ToCount
);
1691 /* Note: frdepth == todepth test works regardless of fDepthChange
1692 * (frdepth always zero, todepth is change of depth) and also
1693 * works for STYLE_NORMAL (both remain 0) */
1694 if (TSTBIT(pcs
->infer
, INFER_EQUATES
) &&
1695 (VAL(Tape
) == (real
)0.0 || VAL(Tape
) == HUGE_REAL
) &&
1696 (VAL(BackTape
) == (real
)0.0 || VAL(BackTape
) == HUGE_REAL
) &&
1697 VAL(FrDepth
) == VAL(ToDepth
)) {
1698 process_equate(fr
, to
);
1699 goto inferred_equate
;
1707 VAL(Tape
) *= pcs
->units
[Q_COUNT
] * pcs
->sc
[Q_COUNT
];
1708 } else if (VAL(Tape
) != HUGE_REAL
) {
1709 VAL(Tape
) *= pcs
->units
[Q_LENGTH
];
1710 VAL(Tape
) -= pcs
->z
[Q_LENGTH
];
1711 VAL(Tape
) *= pcs
->sc
[Q_LENGTH
];
1713 if (VAL(BackTape
) != HUGE_REAL
) {
1714 VAL(BackTape
) *= pcs
->units
[Q_BACKLENGTH
];
1715 VAL(BackTape
) -= pcs
->z
[Q_BACKLENGTH
];
1716 VAL(BackTape
) *= pcs
->sc
[Q_BACKLENGTH
];
1717 if (VAL(Tape
) != HUGE_REAL
) {
1718 real diff
= VAL(Tape
) - VAL(BackTape
);
1719 if (sqrd(diff
/ 3.0) > VAR(Tape
) + VAR(BackTape
)) {
1720 /* fore and back readings differ by more than 3 sds */
1721 /* TRANSLATORS: %s is replaced by the amount the readings disagree
1722 * by, e.g. "0.12m" or "0.2ft". */
1723 warn_readings_differ(/*TAPE reading and BACKTAPE reading disagree by %s*/97,
1724 diff
, get_length_units(Q_LENGTH
));
1726 VAL(Tape
) = VAL(Tape
) / VAR(Tape
) + VAL(BackTape
) / VAR(BackTape
);
1727 VAR(Tape
) = (VAR(Tape
) + VAR(BackTape
)) / 4;
1728 VAL(Tape
) *= VAR(Tape
);
1730 VAL(Tape
) = VAL(BackTape
);
1731 VAR(Tape
) = VAR(BackTape
);
1733 } else if (VAL(Tape
) == HUGE_REAL
) {
1734 compile_error_reading(Tape
, /*Tape reading may not be omitted*/94);
1735 goto inferred_equate
;
1737 implicit_splay
= TSTBIT(pcs
->flags
, FLAGS_IMPLICIT_SPLAY
);
1738 pcs
->flags
&= ~(BIT(FLAGS_ANON_ONE_END
) | BIT(FLAGS_IMPLICIT_SPLAY
));
1739 save_flags
= pcs
->flags
;
1740 if (implicit_splay
) {
1741 pcs
->flags
|= BIT(FLAGS_SPLAY
);
1743 switch (pcs
->style
) {
1745 r
= process_normal(fr
, to
, (first_stn
== To
) ^ fRev
,
1749 /* FIXME: Handle any clino readings */
1750 r
= process_diving(fr
, to
, (first_stn
== To
) ^ fRev
,
1753 case STYLE_CYLPOLAR
:
1754 r
= process_cylpolar(fr
, to
, (first_stn
== To
) ^ fRev
,
1758 r
= 0; /* avoid warning */
1761 pcs
->flags
= save_flags
;
1764 /* Swap fr and to back to how they were for next line */
1773 ctype
= backctype
= CTYPE_OMIT
;
1774 fDepthChange
= fFalse
;
1776 /* ordering may omit clino reading, so set up default here */
1777 /* this is also used if clino reading is the omit character */
1778 VAL(Clino
) = VAL(BackClino
) = 0;
1779 LOC(Clino
) = LOC(BackClino
) = -1;
1787 if (isData(ch
)) break;
1801 /* Compass ignore flag is 'X' */
1802 if ((compass_dat_flags
& BIT('X' - 'A'))) {
1812 VAL(Tape
) = VAL(ToCount
) - VAL(FrCount
);
1813 LOC(Tape
) = LOC(ToCount
);
1815 /* Note: frdepth == todepth test works regardless of fDepthChange
1816 * (frdepth always zero, todepth is change of depth) and also
1817 * works for STYLE_NORMAL (both remain 0) */
1818 if (TSTBIT(pcs
->infer
, INFER_EQUATES
) &&
1819 (VAL(Tape
) == (real
)0.0 || VAL(Tape
) == HUGE_REAL
) &&
1820 (VAL(BackTape
) == (real
)0.0 || VAL(BackTape
) == HUGE_REAL
) &&
1821 VAL(FrDepth
) == VAL(ToDepth
)) {
1822 process_equate(fr
, to
);
1827 VAL(Tape
) *= pcs
->units
[Q_COUNT
] * pcs
->sc
[Q_COUNT
];
1828 } else if (VAL(Tape
) != HUGE_REAL
) {
1829 VAL(Tape
) *= pcs
->units
[Q_LENGTH
];
1830 VAL(Tape
) -= pcs
->z
[Q_LENGTH
];
1831 VAL(Tape
) *= pcs
->sc
[Q_LENGTH
];
1833 if (VAL(BackTape
) != HUGE_REAL
) {
1834 VAL(BackTape
) *= pcs
->units
[Q_BACKLENGTH
];
1835 VAL(BackTape
) -= pcs
->z
[Q_BACKLENGTH
];
1836 VAL(BackTape
) *= pcs
->sc
[Q_BACKLENGTH
];
1837 if (VAL(Tape
) != HUGE_REAL
) {
1838 real diff
= VAL(Tape
) - VAL(BackTape
);
1839 if (sqrd(diff
/ 3.0) > VAR(Tape
) + VAR(BackTape
)) {
1840 /* fore and back readings differ by more than 3 sds */
1841 /* TRANSLATORS: %s is replaced by the amount the readings disagree
1842 * by, e.g. "0.12m" or "0.2ft". */
1843 warn_readings_differ(/*TAPE reading and BACKTAPE reading disagree by %s*/97,
1844 diff
, get_length_units(Q_LENGTH
));
1846 VAL(Tape
) = VAL(Tape
) / VAR(Tape
) + VAL(BackTape
) / VAR(BackTape
);
1847 VAR(Tape
) = (VAR(Tape
) + VAR(BackTape
)) / 4;
1848 VAL(Tape
) *= VAR(Tape
);
1850 VAL(Tape
) = VAL(BackTape
);
1851 VAR(Tape
) = VAR(BackTape
);
1853 } else if (VAL(Tape
) == HUGE_REAL
) {
1854 compile_error_reading(Tape
, /*Tape reading may not be omitted*/94);
1858 implicit_splay
= TSTBIT(pcs
->flags
, FLAGS_IMPLICIT_SPLAY
);
1859 pcs
->flags
&= ~(BIT(FLAGS_ANON_ONE_END
) | BIT(FLAGS_IMPLICIT_SPLAY
));
1860 save_flags
= pcs
->flags
;
1861 if (implicit_splay
) {
1862 pcs
->flags
|= BIT(FLAGS_SPLAY
);
1864 if ((compass_dat_flags
& BIT('L' - 'A'))) {
1865 /* 'L' means "exclude from length" - map this to Survex's
1866 * FLAGS_DUPLICATE. */
1867 pcs
->flags
|= BIT(FLAGS_DUPLICATE
);
1869 switch (pcs
->style
) {
1871 process_normal(fr
, to
, (first_stn
== To
) ^ fRev
,
1875 /* FIXME: Handle any clino readings */
1876 process_diving(fr
, to
, (first_stn
== To
) ^ fRev
,
1879 case STYLE_CYLPOLAR
:
1880 process_cylpolar(fr
, to
, (first_stn
== To
) ^ fRev
,
1886 pcs
->flags
= save_flags
;
1894 } while (isComm(ch
));
1897 BUG("Unknown reading in ordering");
1903 process_lrud(prefix
*stn
)
1905 SVX_ASSERT(next_lrud
);
1906 lrud
* xsect
= osnew(lrud
);
1908 xsect
->l
= (VAL(Left
) * pcs
->units
[Q_LEFT
] - pcs
->z
[Q_LEFT
]) * pcs
->sc
[Q_LEFT
];
1909 xsect
->r
= (VAL(Right
) * pcs
->units
[Q_RIGHT
] - pcs
->z
[Q_RIGHT
]) * pcs
->sc
[Q_RIGHT
];
1910 xsect
->u
= (VAL(Up
) * pcs
->units
[Q_UP
] - pcs
->z
[Q_UP
]) * pcs
->sc
[Q_UP
];
1911 xsect
->d
= (VAL(Down
) * pcs
->units
[Q_DOWN
] - pcs
->z
[Q_DOWN
]) * pcs
->sc
[Q_DOWN
];
1912 xsect
->meta
= pcs
->meta
;
1913 if (pcs
->meta
) ++pcs
->meta
->ref_count
;
1916 next_lrud
= &(xsect
->next
);
1927 for (ordering
= pcs
->ordering
; ; ordering
++) {
1929 switch (*ordering
) {
1931 stn
= read_prefix(PFX_STATION
);
1933 case Left
: case Right
: case Up
: case Down
: {
1934 reading r
= *ordering
;
1935 read_reading(r
, fTrue
);
1936 if (VAL(r
) == HUGE_REAL
) {
1938 compile_error_token(-/*Expecting numeric field, found ā%sā*/9);
1956 default: BUG("Unknown reading in ordering");
1962 process_nosurvey(prefix
*fr
, prefix
*to
, bool fToFirst
)
1966 /* Suppress "unused fixed point" warnings for these stations */
1967 fr
->sflags
|= BIT(SFLAGS_USED
);
1968 to
->sflags
|= BIT(SFLAGS_USED
);
1970 /* add to linked list which is dealt with after network is solved */
1971 link
= osnew(nosurveylink
);
1973 link
->to
= StnFromPfx(to
);
1974 link
->fr
= StnFromPfx(fr
);
1976 link
->fr
= StnFromPfx(fr
);
1977 link
->to
= StnFromPfx(to
);
1979 link
->flags
= pcs
->flags
| (STYLE_NOSURVEY
<< FLAGS_STYLE_BIT0
);
1980 link
->meta
= pcs
->meta
;
1981 if (pcs
->meta
) ++pcs
->meta
->ref_count
;
1982 link
->next
= nosurveyhead
;
1983 nosurveyhead
= link
;
1990 prefix
*fr
= NULL
, *to
= NULL
;
1992 bool fMulti
= fFalse
;
1994 reading first_stn
= End
;
2000 for (ordering
= pcs
->ordering
; ; ordering
++) {
2002 switch (*ordering
) {
2004 fr
= read_prefix(PFX_STATION
|PFX_ALLOW_ROOT
);
2005 if (first_stn
== End
) first_stn
= Fr
;
2008 to
= read_prefix(PFX_STATION
|PFX_ALLOW_ROOT
);
2009 if (first_stn
== End
) first_stn
= To
;
2013 to
= read_prefix(PFX_STATION
);
2018 case IgnoreAllAndNewLine
:
2023 if (!process_nosurvey(fr
, to
, first_stn
== To
))
2026 if (ordering
[1] == End
) {
2030 } while (isComm(ch
));
2041 if (isData(ch
)) break;
2053 (void)process_nosurvey(fr
, to
, first_stn
== To
);
2060 } while (isComm(ch
));
2062 default: BUG("Unknown reading in ordering");
2067 /* totally ignore a line of survey data */