source: git/src/datain.c @ 4fcd2d19

RELEASE/1.0RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since 4fcd2d19 was 11e919a, checked in by Olly Betts <olly@…>, 23 years ago

Complain is backcompass and backclino differ from their forward friends by
more than 3 sds.

git-svn-id: file:///home/survex-svn/survex/trunk@1922 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 36.8 KB
Line 
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
48int ch;
49
50typedef 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 */
54parse file /* = { NULL, NULL, 0, fFalse, NULL } */ ;
55
56bool f_export_ok;
57
58static filepos fpLineStart;
59
60void
61get_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
69void
70set_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
77static void
78push_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
84static void
85error_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
111void
112compile_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
121void
122compile_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
137void
138compile_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 */
148static void
149using_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
166static void
167skipword(void)
168{
169   while (!isBlank(ch) && !isEol(ch)) nextch();
170}
171
172extern void
173skipblanks(void)
174{
175   while (isBlank(ch)) nextch();
176}
177
178extern void
179skipline(void)
180{
181   while (!isEol(ch)) nextch();
182}
183
184#ifndef NO_PERCENTAGE
185static long int filelen;
186#endif
187
188static void
189process_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
204static void
205process_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
230static bool
231process_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
247extern void
248data_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
374static real
375handle_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
428static int
429process_normal(prefix *fr, prefix *to, real tape, real comp, real clin,
430               real backcomp, real backclin,
431               bool fToFirst, clino_type ctype, clino_type backctype)
432{
433   real dx, dy, dz;
434   real vx, vy, vz;
435#ifndef NO_COVARIANCES
436   real cxy, cyz, czx;
437#endif
438
439   bool fNoComp;
440
441   /* adjusted tape is negative -- probably the calibration is wrong */
442   if (tape < (real)0.0) {
443      /* TRANSLATE different message for topofil? */
444      compile_warning(/*Negative adjusted tape reading*/79);
445   }
446
447   fNoComp = fTrue;
448   if (comp != HUGE_REAL) {
449      fNoComp = fFalse;
450      comp *= pcs->units[Q_BEARING];
451      if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) {
452         compile_warning(/*Suspicious compass reading*/59);
453      }
454   }
455   if (backcomp != HUGE_REAL) {
456      fNoComp = fFalse;
457      backcomp *= pcs->units[Q_BACKBEARING];
458      if (backcomp < (real)0.0 || backcomp - M_PI * 2.0 > EPSILON) {
459         /* FIXME: different message for BackComp? */
460         compile_warning(/*Suspicious compass reading*/59);
461      }
462   }
463
464   if (ctype == CLINO_READING) {
465      real diff_from_abs90;
466      clin *= pcs->units[Q_GRADIENT];
467      diff_from_abs90 = fabs(clin) - M_PI_2;
468      if (diff_from_abs90 > EPSILON) {
469         compile_warning(/*Clino reading over 90 degrees (absolute value)*/51);
470      } else if (pcs->f90Up && diff_from_abs90 > -EPSILON) {
471         ctype = CLINO_PLUMB;
472      }
473   }
474
475   if (backctype == CLINO_READING) {
476      real diff_from_abs90;
477      backclin *= pcs->units[Q_BACKGRADIENT];
478      diff_from_abs90 = fabs(backclin) - M_PI_2;
479      if (diff_from_abs90 > EPSILON) {
480         /* FIXME: different message for BackClino? */
481         compile_warning(/*Clino reading over 90 degrees (absolute value)*/51);
482      } else if (pcs->f90Up && diff_from_abs90 > -EPSILON) {
483         backctype = CLINO_PLUMB;
484      }
485   }
486
487   if (ctype != CLINO_OMIT && backctype != CLINO_OMIT && ctype != backctype) {
488      compile_error(/*Clino and BackClino readings must be of the same type*/84);
489      skipline();
490      return 0;
491   }
492
493   if (ctype == CLINO_PLUMB || backctype == CLINO_PLUMB) {
494      /* plumbed */
495      if (!fNoComp) {
496         /* FIXME: Different message for BackComp? */
497         compile_warning(/*Compass reading given on plumbed leg*/21);
498      }
499
500      dx = dy = (real)0.0;
501      if (ctype != CLINO_OMIT) {
502         if (backctype != CLINO_OMIT && (clin > 0) == (backclin > 0)) {
503            /* We've got two UPs or two DOWNs - FIXME: not ideal message */
504            compile_error(/*Clino and BackClino readings must be of the same type*/84);
505            skipline();
506            return 0;
507         }
508         dz = (clin > (real)0.0) ? tape : -tape;
509      } else {
510         dz = (backclin < (real)0.0) ? tape : -tape;
511      }
512      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
513      vz = var(Q_POS) / 3.0 + var(Q_LENGTH);
514#ifndef NO_COVARIANCES
515      /* Correct values - no covariances in this case! */
516      cxy = cyz = czx = (real)0.0;
517#endif
518   } else {
519      /* Each of ctype and backctype are either CLINO_READING/CLINO_HORIZ
520       * or CLINO_OMIT */
521      /* clino */
522      real L2, cosG, LcosG, cosG2, sinB, cosB, dx2, dy2, dz2, v, V;
523      if (fNoComp) {
524         compile_error(/*Compass reading may not be omitted except on plumbed legs*/14);
525         skipline();
526         return 0;
527      }
528      if (tape == (real)0.0) {
529         dx = dy = dz = (real)0.0;
530         vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */
531#ifndef NO_COVARIANCES
532         cxy = cyz = czx = (real)0.0;
533#endif
534#if DEBUG_DATAIN_1
535         printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx, vy, vz);
536#endif
537      } else {
538         real sinGcosG;
539         real var_comp = var(Q_BEARING);
540         /* take into account variance in LEVEL case */
541         real var_clin = var(Q_LEVEL);
542         if (comp != HUGE_REAL) {
543            comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING];
544            comp -= pcs->z[Q_DECLINATION];
545         }
546         if (backcomp != HUGE_REAL) {
547            backcomp = (backcomp - pcs->z[Q_BACKBEARING])
548                    * pcs->sc[Q_BACKBEARING];
549            backcomp -= pcs->z[Q_DECLINATION];
550            backcomp -= M_PI;
551            if (comp != HUGE_REAL) {
552               real diff = comp - backcomp;
553               diff -= floor((diff + M_PI) / (2 * M_PI)) * 2 * M_PI;
554               if (sqrd(diff / 3.0) > var_comp + var(Q_BACKBEARING)) {
555                  /* fore and back readings differ by more than 3 sds */
556                  char buf[64];
557                  char *p;
558                  sprintf(buf, "%.2f", deg(fabs(diff)));
559                  p = strchr(buf, '.');
560                  if (p) {
561                     char *z = p;
562                     while (*++p) {
563                        if (*p != '0') z = p + 1;
564                     }
565                     if (*z) *z = '\0';
566                  }
567                  compile_warning(/*Compass reading and back compass reading disagree by %s degrees*/325, buf);
568               }
569               comp = (comp / var_comp + backcomp / var(Q_BACKBEARING));
570               var_comp = (var_comp + var(Q_BACKBEARING)) / 4;
571               comp *= var_comp;
572            } else {
573               comp = backcomp;
574               var_comp = var(Q_BACKBEARING);
575            }
576         }
577         /* ctype != CLINO_READING is LEVEL case */
578         if (ctype == CLINO_READING) {
579            clin = (clin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT];
580            var_clin = var(Q_GRADIENT);
581         }
582         if (backctype == CLINO_READING) {
583            backclin = (backclin - pcs->z[Q_BACKGRADIENT])
584               * pcs->sc[Q_BACKGRADIENT];
585            if (ctype == CLINO_READING) {
586               if (sqrd((clin + backclin) / 3.0) >
587                     var_clin + var(Q_BACKGRADIENT)) {
588                  /* fore and back readings differ by more than 3 sds */
589                  char buf[64];
590                  char *p;
591                  sprintf(buf, "%.2f", deg(fabs(clin + backclin)));
592                  p = strchr(buf, '.');
593                  if (p) {
594                     char *z = p;
595                     while (*++p) {
596                        if (*p != '0') z = p + 1;
597                     }
598                     if (*z) *z = '\0';
599                  }
600                  compile_warning(/*Clino reading and back clino reading disagree by %s degrees*/326, buf);
601               }
602               clin = (clin / var_clin - backclin / var(Q_BACKGRADIENT));
603               var_clin = (var_clin + var(Q_BACKGRADIENT)) / 4;
604               clin *= var_clin;
605            } else {
606               clin = -backclin;
607               var_clin = var(Q_BACKGRADIENT);
608            }
609         }
610
611#if DEBUG_DATAIN
612         printf("    %4.2f %4.2f %4.2f\n", tape, comp, clin);
613#endif
614         cosG = cos(clin);
615         LcosG = tape * cosG;
616         sinB = sin(comp);
617         cosB = cos(comp);
618#if DEBUG_DATAIN_1
619         printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB, cosG, LcosG);
620#endif
621         dx = LcosG * sinB;
622         dy = LcosG * cosB;
623         dz = tape * sin(clin);
624/*      printf("%.2f\n",clin); */
625#if DEBUG_DATAIN_1
626         printf("dx = %f\ndy = %f\ndz = %f\n", dx, dy, dz);
627#endif
628         dx2 = dx * dx;
629         L2 = tape * tape;
630         V = var(Q_LENGTH) / L2;
631         dy2 = dy * dy;
632         cosG2 = cosG * cosG;
633         sinGcosG = sin(clin) * cosG;
634         dz2 = dz * dz;
635         v = dz2 * var_clin;
636#ifdef NO_COVARIANCES
637         vx = (var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp +
638               (.5 + sinB * sinB * cosG2) * v);
639         vy = (var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp +
640               (.5 + cosB * cosB * cosG2) * v);
641         if (ctype == CLINO_OMIT && backctype == CLINO_OMIT) {
642            /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */
643            vz = var(Q_POS) / 3.0 + L2 * (real)0.1;
644         } else {
645            vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin;
646         }
647         /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */
648#else
649         vx = var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp +
650            (sinB * sinB * v);
651         vy = var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp +
652            (cosB * cosB * v);
653         if (ctype == CLINO_OMIT && backctype == CLINO_OMIT) {
654            /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */
655            vz = var(Q_POS) / 3.0 + L2 * (real)0.1;
656         } else {
657            vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin;
658         }
659         /* usual covariance formulae are fine in no clino case since
660          * dz = 0 so value of var_clin is ignored */
661         cxy = sinB * cosB * (var(Q_LENGTH) * cosG2 + var_clin * dz2)
662               - var_comp * dx * dy;
663         czx = var(Q_LENGTH) * sinB * sinGcosG - var_clin * dx * dz;
664         cyz = var(Q_LENGTH) * cosB * sinGcosG - var_clin * dy * dz;
665#if 0
666         printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx, vy, vz);
667         printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy, cyz, czx);
668#endif
669#endif
670#if DEBUG_DATAIN_1
671         printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx, vy, vz);
672#endif
673      }
674   }
675#if DEBUG_DATAIN_1
676   printf("Just before addleg, vx = %f\n", vx);
677#endif
678   /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/
679   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
680#ifndef NO_COVARIANCES
681                , cyz, czx, cxy
682#endif
683                );
684
685#ifdef NEW3DFORMAT
686   if (fUseNewFormat) {
687      /* new twiglet and insert into twig tree */
688      twig *twiglet = osnew(twig);
689      twiglet->from = fr;
690      twiglet->to = to;
691      twiglet->down = twiglet->right = NULL;
692      twiglet->source = twiglet->drawings
693        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
694      twiglet->up = limb->up;
695      limb->right = twiglet;
696      limb = twiglet;
697
698      /* record pre-fettling deltas */
699      twiglet->delta[0] = dx;
700      twiglet->delta[1] = dy;
701      twiglet->delta[2] = dz;
702   }
703#endif
704   return 1;
705}
706
707static int
708process_diving(prefix *fr, prefix *to, real tape, real comp, real backcomp,
709               real frdepth, real todepth, bool fToFirst, bool fDepthChange)
710{
711   real dx, dy, dz;
712   real vx, vy, vz;
713#ifndef NO_COVARIANCES
714   real cxy = 0, cyz = 0, czx = 0;
715#endif
716
717   if (comp != HUGE_REAL) {
718      comp *= pcs->units[Q_BEARING];
719      if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) {
720         compile_warning(/*Suspicious compass reading*/59);
721      }
722   }
723   if (backcomp != HUGE_REAL) {
724      backcomp *= pcs->units[Q_BACKBEARING];
725      if (backcomp < (real)0.0 || backcomp - M_PI * 2.0 > EPSILON) {
726         /* FIXME: different message for BackComp? */
727         compile_warning(/*Suspicious compass reading*/59);
728      }
729   }
730
731   /* depth gauge readings increase upwards with default calibration */
732   if (fDepthChange) {
733      ASSERT(frdepth == 0.0);
734      dz = (todepth * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]) * pcs->sc[Q_DEPTH];
735   } else {
736      dz = (todepth - frdepth) * pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH];
737   }
738
739   /* adjusted tape is negative -- probably the calibration is wrong */
740   if (tape < (real)0.0) {
741      compile_warning(/*Negative adjusted tape reading*/79);
742   }
743
744   /* check if tape is less than depth change */
745   if (tape < fabs(dz)) {
746      /* FIXME: allow margin of error based on variances? */
747      compile_warning(/*Tape reading is less than change in depth*/62);
748   }
749
750   if (tape == (real)0.0 && dz == 0.0) {
751      dx = dy = dz = (real)0.0;
752      vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */
753   } else if (comp == HUGE_REAL && backcomp == HUGE_REAL) {
754      /* plumb */
755      dx = dy = (real)0.0;
756      if (dz < 0) tape = -tape;
757      dz = (dz * var(Q_LENGTH) + tape * 2 * var(Q_DEPTH))
758         / (var(Q_LENGTH) * 2 * var(Q_DEPTH));
759      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
760      vz = var(Q_POS) / 3.0 + var(Q_LENGTH) * 2 * var(Q_DEPTH)
761                              / (var(Q_LENGTH) + var(Q_DEPTH));
762   } else {
763      real L2, sinB, cosB, dz2, D2;
764      real var_comp = var(Q_BEARING);
765      if (comp != HUGE_REAL) {
766         comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING];
767         comp -= pcs->z[Q_DECLINATION];
768      }
769      if (backcomp != HUGE_REAL) {
770         backcomp = (backcomp - pcs->z[Q_BACKBEARING]) * pcs->sc[Q_BACKBEARING];
771         backcomp -= pcs->z[Q_DECLINATION];
772         backcomp -= M_PI;
773      }
774      if (comp != HUGE_REAL) {
775         if (backcomp != HUGE_REAL) {
776            real diff = comp - backcomp;
777            diff -= floor((diff + M_PI) / (2 * M_PI)) * 2 * M_PI;
778            if (sqrd(diff / 3.0) > var_comp + var(Q_BACKBEARING)) {
779               /* fore and back readings differ by more than 3 sds */
780               /* FIXME: complain */
781            }
782            comp = (comp / var_comp + backcomp / var(Q_BACKBEARING));
783            var_comp = (var_comp + var(Q_BACKBEARING)) / 4;
784            comp *= var_comp;
785         }
786      } else {
787         comp = backcomp;
788         var_comp = var(Q_BACKBEARING);
789      }
790           
791      sinB = sin(comp);
792      cosB = cos(comp);
793      L2 = tape * tape;
794      dz2 = dz * dz;
795      D2 = L2 - dz2;
796      if (D2 <= (real)0.0) {
797         real vsum = var(Q_LENGTH) + 2 * var(Q_DEPTH);
798         dx = dy = (real)0.0;
799         vx = vy = var(Q_POS) / 3.0;
800         vz = var(Q_POS) / 3.0 + var(Q_LENGTH) * 2 * var(Q_DEPTH) / vsum;
801         if (dz > 0) {
802            dz = (dz * var(Q_LENGTH) + tape * 2 * var(Q_DEPTH)) / vsum;
803         } else {
804            dz = (dz * var(Q_LENGTH) - tape * 2 * var(Q_DEPTH)) / vsum;
805         }
806      } else {
807         real D = sqrt(D2);
808         real F = var(Q_LENGTH) * L2 + 2 * var(Q_DEPTH) * D2;
809         dx = D * sinB;
810         dy = D * cosB;
811
812         vx = var(Q_POS) / 3.0 +
813            sinB * sinB * F / D2 + var_comp * dy * dy;
814         vy = var(Q_POS) / 3.0 +
815            cosB * cosB * F / D2 + var_comp * dx * dx;
816         vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH);
817
818#ifndef NO_COVARIANCES
819         cxy = sinB * cosB * (F / D2 + var_comp * D2);
820         cyz = -2 * var(Q_DEPTH) * dy / D;
821         czx = -2 * var(Q_DEPTH) * dx / D;
822#endif
823      }
824   }
825   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
826#ifndef NO_COVARIANCES
827                , cxy, cyz, czx
828#endif
829                );
830#ifdef NEW3DFORMAT
831   if (fUseNewFormat) {
832      /*new twiglet and insert into twig tree*/
833      twig *twiglet = osnew(twig);
834      twiglet->from = fr;
835      twiglet->to = to;
836      twiglet->down = twiglet->right = NULL;
837      twiglet->source = twiglet->drawings
838        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
839      twiglet->up = limb->up;
840      limb->right = twiglet;
841      limb = twiglet;
842
843      /* record pre-fettling deltas */
844      twiglet->delta[0] = dx;
845      twiglet->delta[1] = dy;
846      twiglet->delta[2] = dz;
847   }
848#endif
849
850   return 1;
851}
852
853static int
854process_cartesian(prefix *fr, prefix *to, real dx, real dy, real dz,
855                  bool fToFirst)
856{
857   dx = (dx * pcs->units[Q_DX] - pcs->z[Q_DX]) * pcs->sc[Q_DX];
858   dy = (dy * pcs->units[Q_DY] - pcs->z[Q_DY]) * pcs->sc[Q_DY];
859   dz = (dz * pcs->units[Q_DZ] - pcs->z[Q_DZ]) * pcs->sc[Q_DZ];
860
861   addlegbyname(fr, to, fToFirst, dx, dy, dz, var(Q_DX), var(Q_DY), var(Q_DZ)
862#ifndef NO_COVARIANCES
863                , 0, 0, 0
864#endif
865                );
866
867#ifdef NEW3DFORMAT
868   if (fUseNewFormat) {
869      /* new twiglet and insert into twig tree */
870      twig *twiglet = osnew(twig);
871      twiglet->from = fr;
872      twiglet->to = to;
873      twiglet->down = twiglet->right = NULL;
874      twiglet->source = twiglet->drawings
875        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
876      twiglet->up = limb->up;
877      limb->right = twiglet;
878      limb = twiglet;
879
880      /* record pre-fettling deltas */
881      twiglet->delta[0] = dx;
882      twiglet->delta[1] = dy;
883      twiglet->delta[2] = dz;
884   }
885#endif
886
887   return 1;
888}
889
890extern int
891data_cartesian(void)
892{
893   prefix *fr = NULL, *to = NULL;
894   real dx = 0, dy = 0, dz = 0;
895
896   bool fMulti = fFalse;
897
898   reading first_stn = End;
899
900   reading *ordering;
901
902   again:
903
904   for (ordering = pcs->ordering ; ; ordering++) {
905      skipblanks();
906      switch (*ordering) {
907       case Fr:
908          fr = read_prefix_stn(fFalse, fTrue);
909          if (first_stn == End) first_stn = Fr;
910          break;
911       case To:
912          to = read_prefix_stn(fFalse, fTrue);
913          if (first_stn == End) first_stn = To;
914          break;
915       case Station:
916          fr = to;
917          to = read_prefix_stn(fFalse, fFalse);
918          first_stn = To;
919          break;
920       case Dx: dx = read_numeric(fFalse); break;
921       case Dy: dy = read_numeric(fFalse); break;
922       case Dz: dz = read_numeric(fFalse); break;
923       case Ignore:
924         skipword(); break;
925       case IgnoreAllAndNewLine:
926         skipline();
927         /* fall through */
928       case Newline:
929         if (fr != NULL) {
930            int r;
931            r = process_cartesian(fr, to, dx, dy, dz, first_stn == To);
932            if (!r) skipline();
933         }
934         fMulti = fTrue;
935         while (1) {
936            process_eol();
937            process_bol();
938            if (isData(ch)) break;
939            if (!isComm(ch)) {
940               push_back(ch);
941               return 1;
942            }
943         }
944         break;
945       case IgnoreAll:
946         skipline();
947         /* fall through */
948       case End:
949         if (!fMulti) {
950            int r = process_cartesian(fr, to, dx, dy, dz, first_stn == To);
951            process_eol();
952            return r;
953         }
954         do {
955            process_eol();
956            process_bol();
957         } while (isComm(ch));
958         goto again;
959       default: BUG("Unknown reading in ordering");
960      }
961   }
962}
963
964static int
965process_cylpolar(prefix *fr, prefix *to, real tape, real comp, real backcomp,
966                 real frdepth, real todepth, bool fToFirst, bool fDepthChange)
967{
968   real dx, dy, dz;
969   real vx, vy, vz;
970#ifndef NO_COVARIANCES
971   real cxy = 0;
972#endif
973
974   if (comp != HUGE_REAL) {
975      comp *= pcs->units[Q_BEARING];
976      if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) {
977         compile_warning(/*Suspicious compass reading*/59);
978      }
979   }
980   if (backcomp != HUGE_REAL) {
981      backcomp *= pcs->units[Q_BACKBEARING];
982      if (backcomp < (real)0.0 || backcomp - M_PI * 2.0 > EPSILON) {
983         /* FIXME: different message for BackComp? */
984         compile_warning(/*Suspicious compass reading*/59);
985      }
986   }
987
988   /* depth gauge readings increase upwards with default calibration */
989   if (fDepthChange) {
990      ASSERT(frdepth == 0.0);
991      dz = (todepth * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]) * pcs->sc[Q_DEPTH];
992   } else {
993      dz = (todepth - frdepth) * pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH];
994   }
995
996   /* adjusted tape is negative -- probably the calibration is wrong */
997   if (tape < (real)0.0) {
998      compile_warning(/*Negative adjusted tape reading*/79);
999   }
1000
1001   if (comp == HUGE_REAL && backcomp == HUGE_REAL) {
1002      /* plumb */
1003      dx = dy = (real)0.0;
1004      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
1005      vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH);
1006   } else {
1007      real sinB, cosB;
1008      real var_comp = var(Q_BEARING);
1009      if (comp != HUGE_REAL) {
1010         comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING];
1011         comp -= pcs->z[Q_DECLINATION];
1012      }
1013      if (backcomp != HUGE_REAL) {
1014         backcomp = (backcomp - pcs->z[Q_BACKBEARING]) * pcs->sc[Q_BACKBEARING];
1015         backcomp -= pcs->z[Q_DECLINATION];
1016         backcomp -= M_PI;
1017      }
1018      if (comp != HUGE_REAL) {
1019         if (backcomp != HUGE_REAL) {
1020            real diff = comp - backcomp;
1021            diff -= floor((diff + M_PI) / (2 * M_PI)) * 2 * M_PI;
1022            if (sqrd(diff / 3.0) > var_comp + var(Q_BACKBEARING)) {
1023               /* fore and back readings differ by more than 3 sds */
1024               /* FIXME: complain */
1025            }
1026            comp = (comp / var_comp + backcomp / var(Q_BACKBEARING));
1027            var_comp = (var_comp + var(Q_BACKBEARING)) / 4;
1028            comp *= var_comp;
1029         }
1030      } else {
1031         comp = backcomp;
1032         var_comp = var(Q_BACKBEARING);
1033      }
1034
1035      sinB = sin(comp);
1036      cosB = cos(comp);
1037
1038      dx = tape * sinB;
1039      dy = tape * cosB;
1040
1041      vx = var(Q_POS) / 3.0 +
1042         var(Q_LENGTH) * sinB * sinB + var_comp * dy * dy;
1043      vy = var(Q_POS) / 3.0 +
1044         var(Q_LENGTH) * cosB * cosB + var_comp * dx * dx;
1045      vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH);
1046
1047#ifndef NO_COVARIANCES
1048      cxy = (var(Q_LENGTH) - var_comp * tape * tape) * sinB * cosB;
1049#endif
1050   }
1051   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
1052#ifndef NO_COVARIANCES
1053                , cxy, 0, 0
1054#endif
1055                );
1056#ifdef NEW3DFORMAT
1057   if (fUseNewFormat) {
1058      /*new twiglet and insert into twig tree*/
1059      twig *twiglet = osnew(twig);
1060      twiglet->from = fr;
1061      twiglet->to = to;
1062      twiglet->down = twiglet->right = NULL;
1063      twiglet->source = twiglet->drawings
1064        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
1065      twiglet->up = limb->up;
1066      limb->right = twiglet;
1067      limb = twiglet;
1068
1069      /* record pre-fettling deltas */
1070      twiglet->delta[0] = dx;
1071      twiglet->delta[1] = dy;
1072      twiglet->delta[2] = dz;
1073   }
1074#endif
1075
1076   return 1;
1077}
1078
1079/* Process tape/compass/clino, diving, and cylpolar styles of survey data
1080 * Also handles topofil (fromcount/tocount or count) in place of tape */
1081extern int
1082data_normal(void)
1083{
1084   prefix *fr = NULL, *to = NULL;
1085   reading first_stn = End;
1086
1087   real tape = 0, comp = HUGE_VAL, backcomp = HUGE_VAL, frcount = 0, tocount = 0;
1088   real clin, backclin;
1089   real frdepth = 0, todepth = 0;
1090
1091   bool fTopofil = fFalse, fMulti = fFalse;
1092   bool fRev;
1093   bool ctype, backctype;
1094   bool fDepthChange;
1095
1096   reading *ordering;
1097
1098   again:
1099
1100   fRev = fFalse;
1101   ctype = backctype = CLINO_OMIT;
1102   fDepthChange = fFalse;
1103
1104   /* ordering may omit clino reading, so set up default here */
1105   /* this is also used if clino reading is the omit character */
1106   backclin = clin = (real)0.0;
1107
1108   for (ordering = pcs->ordering; ; ordering++) {
1109      skipblanks();
1110      switch (*ordering) {
1111       case Fr:
1112          fr = read_prefix_stn(fFalse, fTrue);
1113          if (first_stn == End) first_stn = Fr;
1114          break;
1115       case To:
1116          to = read_prefix_stn(fFalse, fTrue);
1117          if (first_stn == End) first_stn = To;
1118          break;
1119       case Station:
1120          fr = to;
1121          to = read_prefix_stn(fFalse, fFalse);
1122          first_stn = To;
1123          break;
1124       case Dir:
1125          switch(toupper(ch)) {
1126           case 'F':
1127             break;
1128           case 'B':
1129             fRev = fTrue;
1130             break;
1131           default:
1132             compile_error(/*Found `%c', expecting `F' or `B'*/131, ch);
1133             skipline();
1134             process_eol();
1135             return 0;
1136          }
1137          break;
1138       case Tape:
1139          tape = read_numeric(fFalse);
1140          if (tape < (real)0.0) compile_warning(/*Negative tape reading*/60);
1141          break;
1142       case Count:
1143          frcount = tocount;
1144          tocount = read_numeric(fFalse);
1145          break;
1146       case FrCount:
1147          frcount = read_numeric(fFalse);
1148          break;
1149       case ToCount:
1150          tocount = read_numeric(fFalse);
1151          fTopofil = fTrue;
1152          break;
1153       case Comp:
1154          comp = read_numeric_or_omit();
1155          break;
1156       case BackComp:
1157          backcomp = read_numeric_or_omit();
1158          break;
1159       case Clino:
1160          clin = read_numeric(fTrue);
1161          if (clin == HUGE_REAL) {
1162             clin = handle_plumb(&ctype);
1163             if (clin != HUGE_REAL) break;
1164             compile_error_token(/*Expecting numeric field, found `%s'*/9);
1165             process_eol();
1166             return 0;
1167          }
1168          ctype = CLINO_READING;
1169          break;
1170       case BackClino:
1171          backclin = read_numeric(fTrue);
1172          if (backclin == HUGE_REAL) {
1173             backclin = handle_plumb(&backctype);
1174             if (backclin != HUGE_REAL) break;
1175             compile_error_token(/*Expecting numeric field, found `%s'*/9);
1176             process_eol();
1177             return 0;
1178          }
1179          backctype = CLINO_READING;
1180          break;
1181       case FrDepth:
1182          frdepth = read_numeric(fFalse);
1183          break;
1184       case ToDepth:
1185          todepth = read_numeric(fFalse);
1186          break;
1187       case Depth:
1188          frdepth = todepth;
1189          todepth = read_numeric(fFalse);
1190          break;
1191       case DepthChange:
1192          fDepthChange = fTrue;
1193          frdepth = 0;
1194          todepth = read_numeric(fFalse);
1195          break;
1196       case Ignore:
1197          skipword();
1198          break;
1199       case IgnoreAllAndNewLine:
1200          skipline();
1201          /* fall through */
1202       case Newline:
1203          if (fr != NULL) {
1204             int r;
1205             if (fRev) {
1206                prefix *t = fr;
1207                fr = to;
1208                to = t;
1209             }
1210             if (fTopofil) tape = tocount - frcount;
1211             /* Note: frdepth == todepth test works regardless of fDepthChange
1212              * (frdepth always zero, todepth is change of depth) and also
1213              * works for STYLE_NORMAL (both remain 0) */
1214             if (pcs->f0Eq && tape == (real)0.0 && frdepth == todepth) {
1215                process_equate(fr, to);
1216                goto inferred_equate;
1217             }
1218             if (fTopofil) {
1219                tape *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT];
1220             } else {
1221                tape *= pcs->units[Q_LENGTH];
1222                tape = (tape - pcs->z[Q_LENGTH]) * pcs->sc[Q_LENGTH];
1223             }
1224             switch (pcs->style) {
1225              case STYLE_NORMAL:
1226                r = process_normal(fr, to, tape, comp, clin,
1227                                   backcomp, backclin,
1228                                   (first_stn == To) ^ fRev, ctype, backctype);
1229                break;
1230              case STYLE_DIVING:
1231                r = process_diving(fr, to, tape, comp, backcomp,
1232                                   frdepth, todepth,
1233                                   (first_stn == To) ^ fRev, fDepthChange);
1234                break;
1235              case STYLE_CYLPOLAR:
1236                r = process_cylpolar(fr, to, tape, comp, backcomp,
1237                                     frdepth, todepth,
1238                                     (first_stn == To) ^ fRev, fDepthChange);
1239                break;
1240              default:
1241                BUG("bad style");
1242             }
1243             if (!r) skipline();
1244          }
1245          inferred_equate:
1246          fMulti = fTrue;
1247          while (1) {
1248              process_eol();
1249              process_bol();
1250              if (isData(ch)) break;
1251              if (!isComm(ch)) {
1252                 push_back(ch);
1253                 return 1;
1254              }
1255          }
1256          break;
1257       case IgnoreAll:
1258          skipline();
1259          /* fall through */
1260       case End:
1261          if (!fMulti) {
1262             int r;
1263             if (fRev) {
1264                prefix *t = fr;
1265                fr = to;
1266                to = t;
1267             }
1268             if (fTopofil) tape = tocount - frcount;
1269             /* Note: frdepth == todepth test works regardless of fDepthChange
1270              * (frdepth always zero, todepth is change of depth) and also
1271              * works for STYLE_NORMAL (both remain 0) */
1272             if (pcs->f0Eq && tape == (real)0.0 && frdepth == todepth) {
1273                process_equate(fr, to);
1274                process_eol();
1275                return 1;
1276             }
1277             if (fTopofil) {
1278                tape *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT];
1279             } else {
1280                tape *= pcs->units[Q_LENGTH];
1281                tape = (tape - pcs->z[Q_LENGTH]) * pcs->sc[Q_LENGTH];
1282             }
1283             switch (pcs->style) {
1284              case STYLE_NORMAL:
1285                r = process_normal(fr, to, tape, comp, clin,
1286                                   backcomp, backclin,
1287                                   (first_stn == To) ^ fRev, ctype, backctype);
1288                break;
1289              case STYLE_DIVING:
1290                r = process_diving(fr, to, tape, comp, backcomp,
1291                                   frdepth, todepth,
1292                                   (first_stn == To) ^ fRev, fDepthChange);
1293                break;
1294              case STYLE_CYLPOLAR:
1295                r = process_cylpolar(fr, to, tape, comp, backcomp,
1296                                     frdepth, todepth,
1297                                     (first_stn == To) ^ fRev, fDepthChange);
1298                break;
1299              default:
1300                BUG("bad style");
1301             }
1302             process_eol();
1303             return r;
1304          }
1305          do {
1306             process_eol();
1307             process_bol();
1308          } while (isComm(ch));
1309          goto again;
1310       default:
1311          BUG("Unknown reading in ordering");
1312      }
1313   }
1314}
1315
1316static int
1317process_nosurvey(prefix *fr, prefix *to, bool fToFirst)
1318{
1319   nosurveylink *link;
1320   int shape;
1321
1322#ifdef NEW3DFORMAT
1323   if (fUseNewFormat) {
1324      /* new twiglet and insert into twig tree */
1325      twig *twiglet = osnew(twig);
1326      twiglet->from = fr;
1327      twiglet->to = to;
1328      twiglet->down = twiglet->right = NULL;
1329      twiglet->source = twiglet->drawings
1330        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
1331      twiglet->up = limb->up;
1332      limb->right = twiglet;
1333      limb = twiglet;
1334      /* delta is only used to calculate error - pass zero and cope
1335       * elsewhere */
1336      twiglet->delta[0] = twiglet->delta[1] = twiglet->delta[2] = 0;
1337   }
1338#endif
1339
1340   /* Suppress "unused fixed point" warnings for these stations
1341    * We do this if it's a 0 or 1 node - 1 node might be an sdfix
1342    */
1343   shape = fr->shape;
1344   if (shape == 0 || shape == 1) fr->shape = -1 - shape;
1345   shape = to->shape;
1346   if (shape == 0 || shape == 1) to->shape = -1 - shape;
1347
1348   /* add to linked list which is dealt with after network is solved */
1349   link = osnew(nosurveylink);
1350   if (fToFirst) {
1351      link->to = StnFromPfx(to);
1352      link->fr = StnFromPfx(fr);
1353   } else {
1354      link->fr = StnFromPfx(fr);
1355      link->to = StnFromPfx(to);
1356   }
1357   link->flags = pcs->flags;
1358   link->next = nosurveyhead;
1359   nosurveyhead = link;
1360   return 1;
1361}
1362
1363extern int
1364data_nosurvey(void)
1365{
1366   prefix *fr = NULL, *to = NULL;
1367
1368   bool fMulti = fFalse;
1369
1370   reading first_stn = End;
1371
1372   reading *ordering;
1373
1374   again:
1375
1376   for (ordering = pcs->ordering ; ; ordering++) {
1377      skipblanks();
1378      switch (*ordering) {
1379       case Fr:
1380          fr = read_prefix_stn(fFalse, fTrue);
1381          if (first_stn == End) first_stn = Fr;
1382          break;
1383       case To:
1384          to = read_prefix_stn(fFalse, fTrue);
1385          if (first_stn == End) first_stn = To;
1386          break;
1387       case Station:
1388          fr = to;
1389          to = read_prefix_stn(fFalse, fFalse);
1390          first_stn = To;
1391          break;
1392       case Ignore:
1393         skipword(); break;
1394       case IgnoreAllAndNewLine:
1395         skipline();
1396         /* fall through */
1397       case Newline:
1398         if (fr != NULL) {
1399            int r;
1400            r = process_nosurvey(fr, to, first_stn == To);
1401            if (!r) skipline();
1402         }
1403         if (ordering[1] == End) {
1404            do {
1405               process_eol();
1406               process_bol();
1407            } while (isComm(ch));
1408            if (!isData(ch)) {
1409               push_back(ch);
1410               return 1;
1411            }
1412            goto again;
1413         }
1414         fMulti = fTrue;
1415         while (1) {
1416            process_eol();
1417            process_bol();
1418            if (isData(ch)) break;
1419            if (!isComm(ch)) {
1420               push_back(ch);
1421               return 1;
1422            }
1423         }
1424         break;
1425       case IgnoreAll:
1426         skipline();
1427         /* fall through */
1428       case End:
1429         if (!fMulti) {
1430            int r = process_nosurvey(fr, to, first_stn == To);
1431            process_eol();
1432            return r;
1433         }
1434         do {
1435            process_eol();
1436            process_bol();
1437         } while (isComm(ch));
1438         goto again;
1439       default: BUG("Unknown reading in ordering");
1440      }
1441   }
1442}
1443
1444/* totally ignore a line of survey data */
1445extern int
1446data_ignore(void)
1447{
1448   skipline();
1449   process_eol();
1450   return 1;
1451}
Note: See TracBrowser for help on using the repository browser.