source: git/src/datain.c @ b14f44f

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 b14f44f was b14f44f, checked in by Olly Betts <olly@…>, 23 years ago

cavern: BackCompass? now works in DIVING and CYLPOLAR styles.

cavern: Tidied up handling of BackCompass? and BackClino? in NORMAL style.

cavern: fixed a bogus warning for any station which was only used in a line
of data which was rejected because of an error; added regression test.

cavern: removed the ill-thought-out and never implemented LENGTHOUTPUT
and ANGLEOUTPUT quantities.

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

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