source: git/src/datain.c @ 577f05b

RELEASE/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 577f05b was be97baf, checked in by Olly Betts <olly@…>, 22 years ago

Sync with 1.0 branch.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@2360 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 45.3 KB
RevLine 
[b0d908e]1/* datain.c
[d1b1380]2 * Reads in survey files, dealing with special characters, keywords & data
[107b8bd]3 * Copyright (C) 1991-2002 Olly Betts
[846746e]4 *
[89231c4]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.
[846746e]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
[89231c4]12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
[846746e]14 *
[89231c4]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
[d1b1380]18 */
19
[a420b49]20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
[d1b1380]23
24#include <limits.h>
[a420b49]25#include <stdarg.h>
[d1b1380]26
27#include "debug.h"
[a420b49]28#include "cavern.h"
[07025e3]29#include "filename.h"
30#include "message.h"
[d1b1380]31#include "filelist.h"
32#include "netbits.h"
[5853657]33#include "netskel.h"
[d1b1380]34#include "readval.h"
35#include "datain.h"
36#include "commands.h"
37#include "out.h"
[39fba51]38#include "str.h"
[d1b1380]39
[2b078c4]40#define EPSILON (REAL_EPSILON * 1000)
[d1b1380]41
[58cc1fb]42#define var(I) (pcs->Var[(I)])
[d1b1380]43
[58cc1fb]44int ch;
[d1b1380]45
[be97baf]46typedef enum {
47    CTYPE_OMIT, CTYPE_READING, CTYPE_PLUMB, CTYPE_INFERPLUMB, CTYPE_HORIZ
48} clino_type;
[5b7c1b7]49
[eb18f4d]50/* Don't explicitly initialise as we can't set the jmp_buf - this has
51 * static scope so will be initialised like this anyway */
[b0d908e]52parse file /* = { NULL, NULL, 0, fFalse, NULL } */ ;
[a420b49]53
[932f7e9]54bool f_export_ok;
55
[21c226e]56static real value[Fr - 1];
57#define VAL(N) value[(N)-1]
58static real variance[Fr - 1];
59#define VAR(N) variance[(N)-1]
60
[c7451a9]61void
[c80bd34]62get_pos(filepos *fp)
[c7451a9]63{
[c80bd34]64   fp->ch = ch;
65   fp->offset = ftell(file.fh);
66   if (fp->offset == -1)
[c7451a9]67      fatalerror_in_file(file.filename, 0, /*Error reading file*/18);
68}
69
[c80bd34]70void
71set_pos(const filepos *fp)
[c7451a9]72{
[c80bd34]73   ch = fp->ch;
74   if (fseek(file.fh, fp->offset, SEEK_SET) == -1)
[c7451a9]75      fatalerror_in_file(file.filename, 0, /*Error reading file*/18);
76}
77
[44bf1d9]78static void
[993454b]79push_back(int c)
80{
81   if (c != EOF && ungetc(c, file.fh) == EOF)
82      fatalerror_in_file(file.filename, 0, /*Error reading file*/18);
83}
84
[a420b49]85static void
86error_list_parent_files(void)
87{
[b0d908e]88   if (!file.reported_where && file.parent) {
[421b7d2]89      parse *p = file.parent;
[46cb98f]90      const char *m = msg(/*In file included from*/5);
[84c60fc]91      size_t len = strlen(m);
[b0d908e]92
[84c60fc]93      fprintf(STDERR, m);
[46cb98f]94      m = msg(/*from*/3);
[b0d908e]95
96      /* Suppress reporting of full include tree for further errors
97       * in this file */
98      file.reported_where = fTrue;
99
[a420b49]100      while (p) {
[b0d908e]101         /* Force re-report of include tree for further errors in
102          * parent files */
103         p->reported_where = fFalse;
[46cb98f]104         fprintf(STDERR, " %s:%d", p->filename, p->line);
[a420b49]105         p = p->parent;
[84f3ed6]106         if (p) fprintf(STDERR, ",\n%*s", (int)len, m);
[a420b49]107      }
108      fprintf(STDERR, ":\n");
109   }
110}
111
112void
113compile_error(int en, ...)
114{
115   va_list ap;
116   va_start(ap, en);
117   error_list_parent_files();
118   v_report(1, file.filename, file.line, en, ap);
119   va_end(ap);
120}
121
[fa42426]122void
123compile_error_skip(int en, ...)
124{
125   va_list ap;
126   va_start(ap, en);
127   error_list_parent_files();
128   v_report(1, file.filename, file.line, en, ap);
129   va_end(ap);
130   skipline();
131}
132
[39fba51]133void
134compile_error_token(int en)
135{
136   char *p = NULL;
137   static int len;
138   s_zero(&p);
139   skipblanks();
140   while (!isBlank(ch) && !isEol(ch)) {
141      s_catchar(&p, &len, ch);
142      nextch();
143   }
[fa42426]144   compile_error_skip(en, p ? p : "");
[39fba51]145   osfree(p);
146}
147
[a420b49]148void
149compile_warning(int en, ...)
150{
151   va_list ap;
152   va_start(ap, en);
153   error_list_parent_files();
154   v_report(0, file.filename, file.line, en, ap);
155   va_end(ap);
156}
157
158/* This function makes a note where to put output files */
159static void
160using_data_file(const char *fnm)
161{
162   if (!fnm_output_base) {
[4bab027]163      /* was: fnm_output_base = base_from_fnm(fnm); */
164      fnm_output_base = baseleaf_from_fnm(fnm);
165   } else if (fnm_output_base_is_dir) {
166      /* --output pointed to directory so use the leaf basename in that dir */
167      char *lf, *p;
168      lf = baseleaf_from_fnm(fnm);
169      p = use_path(fnm_output_base, lf);
170      osfree(lf);
171      osfree(fnm_output_base);
172      fnm_output_base = p;
173      fnm_output_base_is_dir = 0;
[58cc1fb]174   }
175}
176
[a420b49]177static void
178skipword(void)
179{
[58cc1fb]180   while (!isBlank(ch) && !isEol(ch)) nextch();
[d1b1380]181}
182
[a420b49]183extern void
184skipblanks(void)
185{
[58cc1fb]186   while (isBlank(ch)) nextch();
[d1b1380]187}
188
[a420b49]189extern void
190skipline(void)
191{
[58cc1fb]192   while (!isEol(ch)) nextch();
[d1b1380]193}
194
[90bb053f]195#ifndef NO_PERCENTAGE
196static long int filelen;
197#endif
198
199static void
200process_bol(void)
201{
202#ifndef NO_PERCENTAGE
203   /* print %age of file done */
[be97baf]204   if (filelen > 0) {
205      filepos fp;
206      get_pos(&fp);
207      printf("%d%%\r", (int)(100 * fp.offset / filelen));
208   }
[90bb053f]209#endif
210
211   nextch();
212   skipblanks();
213}
214
215static void
216process_eol(void)
217{
218   int eolchar;
219
220   skipblanks();
221
222   if (!isEol(ch)) {
[44bf1d9]223      if (!isComm(ch)) compile_error(/*End of line not blank*/15);
[90bb053f]224      skipline();
225   }
226
227   eolchar = ch;
228   file.line++;
229   /* skip any different eol characters so we get line counts correct on
230    * DOS text files and similar, but don't count several adjacent blank
231    * lines as one */
232   while (ch != EOF) {
233      nextch();
234      if (ch == eolchar || !isEol(ch)) {
[993454b]235         push_back(ch);
[90bb053f]236         break;
237      }
238   }
239}
240
241static bool
242process_non_data_line(void)
243{
244   process_bol();
245
246   if (isData(ch)) return fFalse;
247
248   if (isKeywd(ch)) {
249      nextch();
250      handle_command();
251   }
252
253   process_eol();
254
255   return fTrue;
256}
257
[21c226e]258static void
259read_reading(reading r, bool f_optional)
260{
261   int n_readings;
262   q_quantity q;
263   VAL(r) = read_numeric(f_optional, &n_readings);
264   switch (r) {
265      case Tape: q = Q_LENGTH; break;
266      case Comp: q = Q_BEARING; break;
267      case BackComp: q = Q_BACKBEARING; break;
268      case Clino: q = Q_GRADIENT; break;
269      case BackClino: q = Q_BACKGRADIENT; break;
270      case FrDepth: case ToDepth: q = Q_DEPTH; break;
271      case Dx: q = Q_DX; break;
272      case Dy: q = Q_DY; break;
273      case Dz: q = Q_DZ; break;
274      case FrCount: case ToCount: q = Q_COUNT; break;
275      default: BUG("Unexpected case");
276   }
277   VAR(r) = var(q);
278   if (n_readings > 1) VAR(r) /= sqrt(n_readings);
279}
280
281static void
282read_bearing_or_omit(reading r)
283{
284   int n_readings;
285   q_quantity q;
286   VAL(r) = read_numeric_or_omit(&n_readings);
287   switch (r) {
288      case Comp: q = Q_BEARING; break;
289      case BackComp: q = Q_BACKBEARING; break;
290      default: BUG("Unexpected case");
291   }
292   VAR(r) = var(q);
293   if (n_readings > 1) VAR(r) /= sqrt(n_readings);
294}
295
[be97baf]296/* For reading Compass MAK files which have a freeform syntax */
297static void
298nextch_handling_eol(void)
299{
300   nextch();
301   while (ch != EOF && isEol(ch)) {
302      process_eol();
303      nextch();
304   }
305}
306
307#define LITLEN(S) (sizeof(S"") - 1)
308#define has_ext(F,L,E) ((L) > LITLEN(E) + 1 &&\
309                        (F)[(L) - LITLEN(E) - 1] == FNM_SEP_EXT &&\
310                        strcasecmp((F) + (L) - LITLEN(E), E) == 0)
[a420b49]311extern void
312data_file(const char *pth, const char *fnm)
313{
[47c7a94]314   int begin_lineno_store;
[7f08c83]315   parse file_store;
[be97baf]316   enum {FMT_SVX, FMT_DAT, FMT_MAK} fmt = FMT_SVX;
[d1b1380]317
[7f08c83]318   {
319      char *filename;
[f4b609d]320      FILE *fh;
[be97baf]321      size_t len;
322
[f4b609d]323      if (!pth) {
324         /* file specified on command line - don't do special translation */
325         fh = fopenWithPthAndExt(pth, fnm, EXT_SVX_DATA, "rb", &filename);
326      } else {
327         fh = fopen_portable(pth, fnm, EXT_SVX_DATA, "rb", &filename);
328      }
[bd1913f]329
[7f08c83]330      if (fh == NULL) {
[759fb47]331         compile_error(/*Couldn't open data file `%s'*/24, fnm);
[7f08c83]332         return;
333      }
334
[be97baf]335      len = strlen(filename);
336      if (has_ext(filename, len, "dat")) {
337         fmt = FMT_DAT;
338      } else if (has_ext(filename, len, "mak")) {
339         fmt = FMT_MAK;
340      }
341
[7f08c83]342      file_store = file;
343      if (file.fh) file.parent = &file_store;
344      file.fh = fh;
345      file.filename = filename;
346      file.line = 1;
[b0d908e]347      file.reported_where = fFalse;
[a420b49]348   }
[cb3d1e2]349
[5b68ae1]350   if (fPercent) printf("%s:\n", fnm);
[d1b1380]351
[a420b49]352   using_data_file(file.filename);
[d1b1380]353
[47c7a94]354   begin_lineno_store = pcs->begin_lineno;
355   pcs->begin_lineno = 0;
[cb3d1e2]356
[d1b1380]357#ifndef NO_PERCENTAGE
[58cc1fb]358   /* Try to find how long the file is...
359    * However, under ANSI fseek( ..., SEEK_END) may not be supported */
360   filelen = 0;
361   if (fPercent) {
[c80bd34]362      if (fseek(file.fh, 0l, SEEK_END) == 0) {
363         filepos fp;
364         get_pos(&fp);
365         filelen = fp.offset;
366      }
[58cc1fb]367      rewind(file.fh); /* reset file ptr to start & clear any error state */
368   }
[d1b1380]369#endif
370
[be97baf]371   if (fmt == FMT_DAT) {
372      short *t;
373      int i;
374      settings *pcsNew;
375
376      pcsNew = osnew(settings);
377      *pcsNew = *pcs; /* copy contents */
378      pcsNew->begin_lineno = 0;
379      pcsNew->next = pcs;
380      pcs = pcsNew;
381      default_units(pcs);
382      default_calib(pcs);
383
384      pcs->style = STYLE_NORMAL;
385      pcs->units[Q_LENGTH] = METRES_PER_FOOT;
386      t = ((short*)osmalloc(ossizeof(short) * 257)) + 1;
387
388      t[EOF] = SPECIAL_EOL;
389      memset(t, 0, sizeof(short) * 33);
390      for (i = 33; i < 127; i++) t[i] = SPECIAL_NAMES;
391      t[127] = 0;
392      for (i = 128; i < 256; i++) t[i] = SPECIAL_NAMES;
393      t['\t'] |= SPECIAL_BLANK;
394      t[' '] |= SPECIAL_BLANK;
395      t['\032'] |= SPECIAL_EOL; /* Ctrl-Z, so olde DOS text files are handled ok */
396      t['\n'] |= SPECIAL_EOL;
397      t['\r'] |= SPECIAL_EOL;
398      t['.'] |= SPECIAL_DECIMAL;
399      t['-'] |= SPECIAL_MINUS;
400      t['+'] |= SPECIAL_PLUS;
401      pcs->Translate = t;
402      pcs->Case = OFF;
403      pcs->Truncate = INT_MAX;
404      pcs->infer = 7; /* FIXME: BIT(EQUATES)|BIT(EXPORTS)|BIT(PLUMBS); */
405   } else if (fmt == FMT_MAK) {
406      short *t;
407      int i;
408      settings *pcsNew;
409
410      pcsNew = osnew(settings);
411      *pcsNew = *pcs; /* copy contents */
412      pcsNew->begin_lineno = 0;
413      pcsNew->next = pcs;
414      pcs = pcsNew;
415
416      t = ((short*)osmalloc(ossizeof(short) * 257)) + 1;
417     
418      t[EOF] = SPECIAL_EOL;
419      memset(t, 0, sizeof(short) * 33);
420      for (i = 33; i < 127; i++) t[i] = SPECIAL_NAMES;
421      t[127] = 0;
422      for (i = 128; i < 256; i++) t[i] = SPECIAL_NAMES;
423      t['['] = t[','] = t[';'] = 0;
424      t['\t'] |= SPECIAL_BLANK;
425      t[' '] |= SPECIAL_BLANK;
426      t['\032'] |= SPECIAL_EOL; /* Ctrl-Z, so olde DOS text files are handled ok */
427      t['\n'] |= SPECIAL_EOL;
428      t['\r'] |= SPECIAL_EOL;
429      t['.'] |= SPECIAL_DECIMAL;
430      t['-'] |= SPECIAL_MINUS;
431      t['+'] |= SPECIAL_PLUS;
432      pcs->Translate = t;
433      pcs->Case = OFF;
434      pcs->Truncate = INT_MAX;
435   }
436
[7d5f3c0]437#ifdef HAVE_SETJMP_H
[a420b49]438   /* errors in nested functions can longjmp here */
439   if (setjmp(file.jbSkipLine)) {
[076d33d]440      process_eol();
[a420b49]441   }
[d1b1380]442#endif
[cb3d1e2]443
[be97baf]444   if (fmt == FMT_DAT) {
445      while (!feof(file.fh) && !ferror(file.fh)) {
446         static reading compass_order[] = {
447            Fr, To, Tape, Comp, Clino, Ignore, Ignore, Ignore, Ignore,
448            CompassDATFlags, IgnoreAll
449         };
450         static reading compass_order_backsights[] = {
451            Fr, To, Tape, Comp, Clino, Ignore, Ignore, Ignore, Ignore,
452            BackComp, BackClino,
453            CompassDATFlags, IgnoreAll
454         };
455         /* <Cave name> */
456         process_bol();
457         skipline();
458         process_eol();
459         /* SURVEY NAME: <Short name> */
460         get_token();
461         get_token();
462         /* if (ch != ':') ... */
463         nextch();
464         skipblanks();
465         get_token();
466         skipline();
467         process_eol();
468         /* SURVEY DATE: 7 10 79  COMMENT:<Long name> */
469         /* Note: Larry says a 2 digit year is always 19XX */
470         get_token();
471         get_token();
472         /* if (ch != ':') ... */
473         nextch();
474         skipline();
475         process_eol();
476         /* SURVEY TEAM: */
477         get_token();
478         get_token();
479         skipline();
480         process_eol();
481         /* <Survey team> */
482         nextch();
483         skipline();
484         process_eol();
485         /* DECLINATION: 1.00  FORMAT: DDDDLUDRADLN  CORRECTIONS: 2.00 3.00 4.00 */
486         get_token();
487         nextch(); /* : */
488         skipblanks();
489         pcs->z[Q_DECLINATION] = -read_numeric(fFalse, NULL);
490         pcs->z[Q_DECLINATION] *= pcs->units[Q_DECLINATION];
491         get_token();
492         pcs->ordering = compass_order;
493         if (strcmp(buffer, "FORMAT") == 0) {
494            nextch(); /* : */
495            get_token();
496            if (strlen(buffer) >= 12 && buffer[11] == 'B') {
497               /* We have backsights for compass and clino */
498               pcs->ordering = compass_order_backsights;
499            }
500            get_token();
[107b8bd]501         }
[be97baf]502         if (strcmp(buffer, "CORRECTIONS") == 0) {
503            nextch(); /* : */
504            pcs->z[Q_BEARING] = -rad(read_numeric(fFalse, NULL));
505            pcs->z[Q_GRADIENT] = -rad(read_numeric(fFalse, NULL));
506            pcs->z[Q_LENGTH] = -read_numeric(fFalse, NULL);
507         } else {
508            pcs->z[Q_BEARING] = 0;
509            pcs->z[Q_GRADIENT] = 0;
510            pcs->z[Q_LENGTH] = 0;
[a420b49]511         }
[be97baf]512         skipline();
513         process_eol();
514         /* BLANK LINE */
515         process_bol();
516         skipline();
517         process_eol();
518         /* heading line */
519         process_bol();
520         skipline();
521         process_eol();
522         /* BLANK LINE */
523         process_bol();
524         skipline();
525         process_eol();
526         while (!feof(file.fh)) {
527            process_bol();
528            if (ch == '\x0c') {
529               nextch();
530               process_eol();
531               break;
532            }
533            (void)data_normal();
534         }
535      }
536      {
537         settings *pcsParent = pcs->next;
538         SVX_ASSERT(pcsParent);
539         pcs->ordering = NULL;
540         free_settings(pcs);
541         pcs = pcsParent;
542      }                                   
543   } else if (fmt == FMT_MAK) {
544      nextch_handling_eol();
545      while (!feof(file.fh) && !ferror(file.fh)) {
546         if (ch == '#') {
547            /* include a file */
548            int ch_store;
549            char *pth = path_from_fnm(file.filename);
550            char *fnm = NULL;
551            int fnm_len;
552            nextch_handling_eol();
553            while (ch != ',' && ch != ';' && ch != EOF) {
554               while (isEol(ch)) process_eol();
555               s_catchar(&fnm, &fnm_len, ch);
556               nextch_handling_eol();
557            }
558            while (ch != ';' && ch != EOF) {
559               prefix *name;
560               nextch_handling_eol();
561               name = read_prefix_stn(fTrue, fFalse);
562               if (name) {
563                  skipblanks();
564                  if (ch == '[') {
565                     /* fixed pt */
566                     node *stn;
567                     real x, y, z;
568                     name->sflags |= BIT(SFLAGS_FIXED);
569                     nextch_handling_eol();
570                     while (!isdigit(ch) && ch != '+' && ch != '-' &&
571                            ch != '.' && ch != ']' && ch != EOF) {
572                        nextch_handling_eol();
573                     }
574                     x = read_numeric(fFalse, NULL);
575                     while (!isdigit(ch) && ch != '+' && ch != '-' &&
576                            ch != '.' && ch != ']' && ch != EOF) {
577                        nextch_handling_eol();
578                     }
579                     y = read_numeric(fFalse, NULL);
580                     while (!isdigit(ch) && ch != '+' && ch != '-' &&
581                            ch != '.' && ch != ']' && ch != EOF) {
582                        nextch_handling_eol();
583                     }
584                     z = read_numeric(fFalse, NULL);
585                     stn = StnFromPfx(name);
586                     if (!fixed(stn)) {
587                        POS(stn, 0) = x;
588                        POS(stn, 1) = y;
589                        POS(stn, 2) = z;
590                        fix(stn);
591                     } else {
592                        if (x != POS(stn, 0) || y != POS(stn, 1) ||
593                            z != POS(stn, 2)) {
594                           compile_error(/*Station already fixed or equated to a fixed point*/46);
595                        } else {
596                           compile_warning(/*Station already fixed at the same coordinates*/55);
597                        }
598                     }
599                     while (ch != ']' && ch != EOF) nextch_handling_eol();
600                     if (ch == ']') {
601                        nextch_handling_eol();
602                        skipblanks();
603                     }
604                  } else {
605                     /* FIXME: link station - ignore for now */
606                     /* FIXME: perhaps issue warning? */
607                  }
608                  while (ch != ',' && ch != ';' && ch != EOF)
609                     nextch_handling_eol();
610               }
611            }
612            if (fnm) {
613               ch_store = ch;
614               data_file(pth, fnm);
615               ch = ch_store;
616               osfree(fnm);
617            }
618         } else {
619            /* FIXME: also check for % and $ later */
620            nextch_handling_eol();
621         }
622      }
623      {
624         settings *pcsParent = pcs->next;
625         SVX_ASSERT(pcsParent);
626         free_settings(pcs);
627         pcs = pcsParent;
628      }                                   
629   } else {
630      while (!feof(file.fh) && !ferror(file.fh)) {
631         if (!process_non_data_line()) {
632            int r;
633#ifdef CHASM3DX
634            twig *temp = limb;
[21c226e]635#endif
[be97baf]636            f_export_ok = fFalse;
637            switch (pcs->style) {
638             case STYLE_NORMAL:
639             case STYLE_DIVING:
640             case STYLE_CYLPOLAR:
641               r = data_normal();
642               break;
643             case STYLE_CARTESIAN:
644               r = data_cartesian();
645               break;
646             case STYLE_NOSURVEY:
647               r = data_nosurvey();
648               break;
649             case STYLE_IGNORE:
650               r = data_ignore();
651               break;
652             default:
653               BUG("bad style");
654            }
655            /* style function returns 0 => error */
656#ifdef CHASM3DX
657            if (!r && fUseNewFormat) {
658               /* we have just created a very naughty twiglet, and it must be
659                * punished */
660               osfree(limb);
661               limb = temp;
662            }
663#endif
664         }
[647407d]665      }
[a420b49]666   }
667
[932f7e9]668   /* don't allow *BEGIN at the end of a file, then *EXPORT in the
669    * including file */
670   f_export_ok = fFalse;
671
[a420b49]672#ifndef NO_PERCENTAGE
673   if (fPercent) putnl();
[4f8285d]674#endif
[d1b1380]675
[47c7a94]676   if (pcs->begin_lineno) {
[0e867ba6]677      error_in_file(file.filename, pcs->begin_lineno,
678                    /*BEGIN with no matching END in this file*/23);
[47c7a94]679      /* Implicitly close any unclosed BEGINs from this file */
680      do {
681         settings *pcsParent = pcs->next;
[4c07c51]682         SVX_ASSERT(pcsParent);
[647407d]683         free_settings(pcs);
[47c7a94]684         pcs = pcsParent;
685      } while (pcs->begin_lineno);
686   }
687
688   pcs->begin_lineno = begin_lineno_store;
[cb3d1e2]689
[22c9877]690   if (ferror(file.fh))
[bfe1242]691      fatalerror_in_file(file.filename, 0, /*Error reading file*/18);
[cb3d1e2]692
[22c9877]693   (void)fclose(file.fh);
[7f08c83]694
[22c9877]695   file = file_store;
[4d9eecd]696
697   /* don't free this - it may be pointed to by prefix.file */
698   /* osfree(file.filename); */
[a420b49]699}
[d1b1380]700
[b6de07d]701static real
702mod2pi(real a)
703{
704   return a - floor(a / (2 * M_PI)) * (2 * M_PI);
705}
706
[dcec245]707static real
[5b7c1b7]708handle_plumb(clino_type *p_ctype)
[dcec245]709{
710   typedef enum {
711      CLINO_NULL=-1, CLINO_UP, CLINO_DOWN, CLINO_LEVEL
712   } clino_tok;
713   static sztok clino_tab[] = {
714      {"D",     CLINO_DOWN},
715      {"DOWN",  CLINO_DOWN},
716      {"H",     CLINO_LEVEL},
717      {"LEVEL", CLINO_LEVEL},
718      {"U",     CLINO_UP},
719      {"UP",    CLINO_UP},
720      {NULL,    CLINO_NULL}
721   };
[5b7c1b7]722   static real clinos[] = {(real)M_PI_2, (real)(-M_PI_2), (real)0.0};
[dcec245]723   clino_tok tok;
724
725   skipblanks();
726   if (isalpha(ch)) {
[c80bd34]727      filepos fp;
728      get_pos(&fp);
[dcec245]729      get_token();
730      tok = match_tok(clino_tab, TABSIZE(clino_tab));
731      if (tok != CLINO_NULL) {
[be97baf]732         *p_ctype = (tok == CLINO_LEVEL ? CTYPE_HORIZ : CTYPE_PLUMB);
[dcec245]733         return clinos[tok];
734      }
[c80bd34]735      set_pos(&fp);
[dcec245]736   } else if (isSign(ch)) {
737      int chOld = ch;
738      nextch();
739      if (toupper(ch) == 'V') {
740         nextch();
[fa42426]741         *p_ctype = CTYPE_PLUMB;
[bceebf4]742         return (!isMinus(chOld) ? M_PI_2 : -M_PI_2);
[dcec245]743      }
744
[bd1913f]745      if (isOmit(chOld)) {
[fa42426]746         *p_ctype = CTYPE_OMIT;
[dcec245]747         /* no clino reading, so assume 0 with large sd */
748         return (real)0.0;
749      }
[5b7c1b7]750   } else if (isOmit(ch)) {
751      /* OMIT char may not be a SIGN char too so we need to check here as
752       * well as above... */
753      nextch();
[fa42426]754      *p_ctype = CTYPE_OMIT;
[5b7c1b7]755      /* no clino reading, so assume 0 with large sd */
756      return (real)0.0;
[dcec245]757   }
758   return HUGE_REAL;
759}
760
[b6de07d]761static void
762warn_readings_differ(int msg, real diff)
763{
764   char buf[64];
765   char *p;
766   sprintf(buf, "%.2f", deg(fabs(diff)));
767   p = strchr(buf, '.');
768   if (p) {
769      char *z = p;
770      while (*++p) {
771         if (*p != '0') z = p + 1;
772      }
773      if (*z) *z = '\0';
774   }
775   compile_warning(msg, buf);
776}
777
778static bool
[21c226e]779handle_comp_units(void)
[b6de07d]780{
781   bool fNoComp = fTrue;
[21c226e]782   if (VAL(Comp) != HUGE_REAL) {
[b6de07d]783      fNoComp = fFalse;
[21c226e]784      VAL(Comp) *= pcs->units[Q_BEARING];
785      if (VAL(Comp) < (real)0.0 || VAL(Comp) - M_PI * 2.0 > EPSILON) {
[b6de07d]786         compile_warning(/*Suspicious compass reading*/59);
[21c226e]787         VAL(Comp) = mod2pi(VAL(Comp));
[b6de07d]788      }
789   }
[21c226e]790   if (VAL(BackComp) != HUGE_REAL) {
[b6de07d]791      fNoComp = fFalse;
[21c226e]792      VAL(BackComp) *= pcs->units[Q_BACKBEARING];
793      if (VAL(BackComp) < (real)0.0 || VAL(BackComp) - M_PI * 2.0 > EPSILON) {
[b6de07d]794         /* FIXME: different message for BackComp? */
795         compile_warning(/*Suspicious compass reading*/59);
[21c226e]796         VAL(BackComp) = mod2pi(VAL(BackComp));
[b6de07d]797      }
798   }
799   return fNoComp;
800}
801
802static real
[21c226e]803handle_compass(real *p_var)
[b6de07d]804{
[21c226e]805   real var = VAR(Comp);
806   real comp = VAL(Comp);
807   real backcomp = VAL(BackComp);
[b6de07d]808   if (comp != HUGE_REAL) {
809      comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING];
810      comp -= pcs->z[Q_DECLINATION];
811   }
812   if (backcomp != HUGE_REAL) {
813      backcomp = (backcomp - pcs->z[Q_BACKBEARING])
814              * pcs->sc[Q_BACKBEARING];
815      backcomp -= pcs->z[Q_DECLINATION];
816      backcomp -= M_PI;
817      if (comp != HUGE_REAL) {
818         real diff = comp - backcomp;
819         real adj = fabs(diff) > M_PI ? M_PI : 0;
820         diff -= floor((diff + M_PI) / (2 * M_PI)) * 2 * M_PI;
[21c226e]821         if (sqrd(diff / 2.0) > var + VAR(Q_BACKBEARING)) {
[770157e]822            /* fore and back readings differ by more than 2 sds */
[fa42426]823            warn_readings_differ(/*Compass reading and back compass reading disagree by %s degrees*/98, diff);
[b6de07d]824         }
[21c226e]825         comp = (comp / var + backcomp / VAR(BackComp));
826         var = (var + VAR(BackComp)) / 4;
[b6de07d]827         comp *= var;
828         comp += adj;
829      } else {
830         comp = backcomp;
[21c226e]831         var = VAR(BackComp);
[b6de07d]832      }
833   }
834   *p_var = var;
835   return comp;
836}
837
[90bb053f]838static int
[21c226e]839process_normal(prefix *fr, prefix *to, bool fToFirst,
840               clino_type ctype, clino_type backctype)
[a420b49]841{
[21c226e]842   real tape = VAL(Tape);
843   real clin = VAL(Clino);
844   real backclin = VAL(BackClino);
845
[a420b49]846   real dx, dy, dz;
847   real vx, vy, vz;
848#ifndef NO_COVARIANCES
[cb3d1e2]849   real cxy, cyz, czx;
[a420b49]850#endif
[d1b1380]851
[90bb053f]852   bool fNoComp;
[a420b49]853
[107b8bd]854   /* adjusted tape is negative -- probably the calibration is wrong */
855   if (tape < (real)0.0) {
856      /* TRANSLATE different message for topofil? */
857      compile_warning(/*Negative adjusted tape reading*/79);
[647407d]858   }
[d1b1380]859
[21c226e]860   fNoComp = handle_comp_units();
[d1b1380]861
[fa42426]862   if (ctype == CTYPE_READING) {
[0b71cfc]863      real diff_from_abs90;
[a420b49]864      clin *= pcs->units[Q_GRADIENT];
[fa42426]865      /* percentage scale */
866      if (pcs->f_clino_percent) clin = atan(clin);
[0b71cfc]867      diff_from_abs90 = fabs(clin) - M_PI_2;
868      if (diff_from_abs90 > EPSILON) {
[a420b49]869         compile_warning(/*Clino reading over 90 degrees (absolute value)*/51);
[27b8b59]870      } else if (TSTBIT(pcs->infer, INFER_PLUMBS) &&
[be97baf]871                 diff_from_abs90 >= -EPSILON) {
872         ctype = CTYPE_INFERPLUMB;
[a420b49]873      }
874   }
[cb3d1e2]875
[fa42426]876   if (backctype == CTYPE_READING) {
[b14f44f]877      backclin *= pcs->units[Q_BACKGRADIENT];
[fa42426]878      /* percentage scale */
879      if (pcs->f_backclino_percent) backclin = atan(backclin);
[be97baf]880      if (ctype != CTYPE_READING) {
881         real diff_from_abs90 = fabs(backclin) - M_PI_2;
882         if (diff_from_abs90 > EPSILON) {
883            /* FIXME: different message for BackClino? */
884            compile_warning(/*Clino reading over 90 degrees (absolute value)*/51);
885         } else if (TSTBIT(pcs->infer, INFER_PLUMBS) &&
886                    diff_from_abs90 >= -EPSILON) {
887            backctype = CTYPE_INFERPLUMB;
888         }
[0b71cfc]889      }
890   }
891
[be97baf]892   /* un-infer the plumb if the backsight was just a reading */
893   if (ctype == CTYPE_INFERPLUMB && backctype == CTYPE_READING) {
894       ctype = CTYPE_READING;
895   }
896
[fa42426]897   if (ctype != CTYPE_OMIT && backctype != CTYPE_OMIT && ctype != backctype) {
898      compile_error_skip(/*Clino and BackClino readings must be of the same type*/84);
[b14f44f]899      return 0;
[0b71cfc]900   }
901
[be97baf]902   if (ctype == CTYPE_PLUMB || ctype == CTYPE_INFERPLUMB ||
903       backctype == CTYPE_PLUMB || backctype == CTYPE_INFERPLUMB) {
[a420b49]904      /* plumbed */
905      if (!fNoComp) {
[be97baf]906         if (ctype == CTYPE_PLUMB ||
907             (ctype == CTYPE_INFERPLUMB && VAL(Comp) != 0.0) ||
908             backctype == CTYPE_PLUMB ||
909             (backctype == CTYPE_INFERPLUMB && VAL(BackComp) != 0.0)) {
910            /* FIXME: Different message for BackComp? */
911            compile_warning(/*Compass reading given on plumbed leg*/21);
912         }
[a420b49]913      }
914
915      dx = dy = (real)0.0;
[fa42426]916      if (ctype != CTYPE_OMIT) {
917         if (backctype != CTYPE_OMIT && (clin > 0) == (backclin > 0)) {
[b14f44f]918            /* We've got two UPs or two DOWNs - FIXME: not ideal message */
[fa42426]919            compile_error_skip(/*Clino and BackClino readings must be of the same type*/84);
[b14f44f]920            return 0;
[0b71cfc]921         }
922         dz = (clin > (real)0.0) ? tape : -tape;
923      } else {
924         dz = (backclin < (real)0.0) ? tape : -tape;
925      }
[a420b49]926      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
[21c226e]927      vz = var(Q_POS) / 3.0 + VAR(Tape);
[4f8285d]928#ifndef NO_COVARIANCES
[26a805f]929      /* Correct values - no covariances in this case! */
930      cxy = cyz = czx = (real)0.0;
[4f8285d]931#endif
[a420b49]932   } else {
[fa42426]933      /* Each of ctype and backctype are either CTYPE_READING/CTYPE_HORIZ
934       * or CTYPE_OMIT */
[a420b49]935      /* clino */
936      real L2, cosG, LcosG, cosG2, sinB, cosB, dx2, dy2, dz2, v, V;
[421b7d2]937      if (fNoComp) {
[fa42426]938         compile_error_skip(/*Compass reading may not be omitted except on plumbed legs*/14);
[a420b49]939         return 0;
940      }
941      if (tape == (real)0.0) {
942         dx = dy = dz = (real)0.0;
943         vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */
[4f8285d]944#ifndef NO_COVARIANCES
[a420b49]945         cxy = cyz = czx = (real)0.0;
[4f8285d]946#endif
[d1b1380]947#if DEBUG_DATAIN_1
[a420b49]948         printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx, vy, vz);
[d1b1380]949#endif
[a420b49]950      } else {
[dbb4e19]951         real sinGcosG;
[0b71cfc]952         /* take into account variance in LEVEL case */
953         real var_clin = var(Q_LEVEL);
[b6de07d]954         real var_comp;
[21c226e]955         real comp = handle_compass(&var_comp);
[fa42426]956         /* ctype != CTYPE_READING is LEVEL case */
957         if (ctype == CTYPE_READING) {
[a420b49]958            clin = (clin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT];
[21c226e]959            var_clin = VAR(Clino);
[0b71cfc]960         }
[fa42426]961         if (backctype == CTYPE_READING) {
[b14f44f]962            backclin = (backclin - pcs->z[Q_BACKGRADIENT])
963               * pcs->sc[Q_BACKGRADIENT];
[fa42426]964            if (ctype == CTYPE_READING) {
[be97baf]965               if (sqrd((clin + backclin) / 3.0) > var_clin + VAR(BackClino)) {
[b14f44f]966                  /* fore and back readings differ by more than 3 sds */
[fa42426]967                  warn_readings_differ(/*Clino reading and back clino reading disagree by %s degrees*/99, clin + backclin);
[b14f44f]968               }
[21c226e]969               clin = (clin / var_clin - backclin / VAR(BackClino));
970               var_clin = (var_clin + VAR(BackClino)) / 4;
[b14f44f]971               clin *= var_clin;
[0b71cfc]972            } else {
973               clin = -backclin;
[21c226e]974               var_clin = VAR(BackClino);
[0b71cfc]975            }
976         }
[d1b1380]977
978#if DEBUG_DATAIN
[a420b49]979         printf("    %4.2f %4.2f %4.2f\n", tape, comp, clin);
[d1b1380]980#endif
[a420b49]981         cosG = cos(clin);
982         LcosG = tape * cosG;
983         sinB = sin(comp);
984         cosB = cos(comp);
[d1b1380]985#if DEBUG_DATAIN_1
[a420b49]986         printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB, cosG, LcosG);
[d1b1380]987#endif
[a420b49]988         dx = LcosG * sinB;
989         dy = LcosG * cosB;
990         dz = tape * sin(clin);
[d1b1380]991/*      printf("%.2f\n",clin); */
992#if DEBUG_DATAIN_1
[a420b49]993         printf("dx = %f\ndy = %f\ndz = %f\n", dx, dy, dz);
[d1b1380]994#endif
[a420b49]995         dx2 = dx * dx;
996         L2 = tape * tape;
[21c226e]997         V = VAR(Tape) / L2;
[a420b49]998         dy2 = dy * dy;
999         cosG2 = cosG * cosG;
[dbb4e19]1000         sinGcosG = sin(clin) * cosG;
[a420b49]1001         dz2 = dz * dz;
[0b71cfc]1002         v = dz2 * var_clin;
[5b7c1b7]1003#ifdef NO_COVARIANCES
[0b71cfc]1004         vx = (var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp +
[a420b49]1005               (.5 + sinB * sinB * cosG2) * v);
[0b71cfc]1006         vy = (var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp +
[a420b49]1007               (.5 + cosB * cosB * cosG2) * v);
[fa42426]1008         if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) {
[5b7c1b7]1009            /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */
[0b71cfc]1010            vz = var(Q_POS) / 3.0 + L2 * (real)0.1;
[5b7c1b7]1011         } else {
[0b71cfc]1012            vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin;
[5b7c1b7]1013         }
[a420b49]1014         /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */
[dbb4e19]1015#else
[0b71cfc]1016         vx = var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp +
[dbb4e19]1017            (sinB * sinB * v);
[0b71cfc]1018         vy = var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp +
[dbb4e19]1019            (cosB * cosB * v);
[fa42426]1020         if (ctype == CTYPE_OMIT && backctype == CTYPE_OMIT) {
[5b7c1b7]1021            /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */
[0b71cfc]1022            vz = var(Q_POS) / 3.0 + L2 * (real)0.1;
[5b7c1b7]1023         } else {
[0b71cfc]1024            vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin;
[5b7c1b7]1025         }
[647407d]1026         /* usual covariance formulae are fine in no clino case since
[0b71cfc]1027          * dz = 0 so value of var_clin is ignored */
[21c226e]1028         cxy = sinB * cosB * (VAR(Tape) * cosG2 + var_clin * dz2)
[0b71cfc]1029               - var_comp * dx * dy;
[21c226e]1030         czx = VAR(Tape) * sinB * sinGcosG - var_clin * dx * dz;
1031         cyz = VAR(Tape) * cosB * sinGcosG - var_clin * dy * dz;
[dbb4e19]1032#if 0
1033         printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx, vy, vz);
1034         printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy, cyz, czx);
1035#endif
[4f8285d]1036#endif
[d1b1380]1037#if DEBUG_DATAIN_1
[a420b49]1038         printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx, vy, vz);
[d1b1380]1039#endif
[a420b49]1040      }
1041   }
[d1b1380]1042#if DEBUG_DATAIN_1
[a420b49]1043   printf("Just before addleg, vx = %f\n", vx);
[d1b1380]1044#endif
[a420b49]1045   /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/
[90bb053f]1046   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
[4f8285d]1047#ifndef NO_COVARIANCES
[2140502]1048                , cyz, czx, cxy
[4f8285d]1049#endif
[2140502]1050                );
[647407d]1051
[be97baf]1052#ifdef CHASM3DX
[647407d]1053   if (fUseNewFormat) {
[407084d]1054      /* new twiglet and insert into twig tree */
1055      twig *twiglet = osnew(twig);
[90bb053f]1056      twiglet->from = fr;
1057      twiglet->to = to;
[407084d]1058      twiglet->down = twiglet->right = NULL;
1059      twiglet->source = twiglet->drawings
1060        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
1061      twiglet->up = limb->up;
1062      limb->right = twiglet;
1063      limb = twiglet;
1064
1065      /* record pre-fettling deltas */
[647407d]1066      twiglet->delta[0] = dx;
1067      twiglet->delta[1] = dy;
1068      twiglet->delta[2] = dz;
1069   }
1070#endif
[a420b49]1071   return 1;
[d1b1380]1072}
1073
[5a38209]1074static int
[21c226e]1075process_diving(prefix *fr, prefix *to, bool fToFirst, bool fDepthChange)
[a420b49]1076{
[21c226e]1077   real tape = VAL(Tape);
1078
[a420b49]1079   real dx, dy, dz;
1080   real vx, vy, vz;
[f795df0]1081#ifndef NO_COVARIANCES
1082   real cxy = 0, cyz = 0, czx = 0;
1083#endif
[a420b49]1084
[21c226e]1085   handle_comp_units();
[a420b49]1086
[a6d094f]1087   /* depth gauge readings increase upwards with default calibration */
[6114207]1088   if (fDepthChange) {
[21c226e]1089      SVX_ASSERT(VAL(FrDepth) == 0.0);
1090      dz = VAL(ToDepth) * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH];
1091      dz *= pcs->sc[Q_DEPTH];
[a6d094f]1092   } else {
[21c226e]1093      dz = VAL(ToDepth) - VAL(FrDepth);
1094      dz *= pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH];
[a6d094f]1095   }
[a420b49]1096
1097   /* adjusted tape is negative -- probably the calibration is wrong */
1098   if (tape < (real)0.0) {
1099      compile_warning(/*Negative adjusted tape reading*/79);
1100   }
1101
1102   /* check if tape is less than depth change */
1103   if (tape < fabs(dz)) {
[bd1913f]1104      /* FIXME: allow margin of error based on variances? */
[a420b49]1105      compile_warning(/*Tape reading is less than change in depth*/62);
1106   }
1107
[0a208f9]1108   if (tape == (real)0.0 && dz == 0.0) {
[a420b49]1109      dx = dy = dz = (real)0.0;
1110      vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */
[21c226e]1111   } else if (VAL(Comp) == HUGE_REAL &&
1112              VAL(BackComp) == HUGE_REAL) {
[385b703]1113      /* plumb */
1114      dx = dy = (real)0.0;
1115      if (dz < 0) tape = -tape;
[21c226e]1116      /* FIXME: Should use FrDepth sometimes... */
1117      dz = (dz * VAR(Tape) + tape * 2 * VAR(ToDepth))
1118         / (VAR(Tape) * 2 * VAR(ToDepth));
[385b703]1119      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
[21c226e]1120      /* FIXME: Should use FrDepth sometimes... */
1121      vz = var(Q_POS) / 3.0 + VAR(Tape) * 2 * VAR(ToDepth)
1122                              / (VAR(Tape) + VAR(ToDepth));
[a420b49]1123   } else {
[f795df0]1124      real L2, sinB, cosB, dz2, D2;
[b6de07d]1125      real var_comp;
[21c226e]1126      real comp = handle_compass(&var_comp);
[a420b49]1127      sinB = sin(comp);
1128      cosB = cos(comp);
1129      L2 = tape * tape;
1130      dz2 = dz * dz;
1131      D2 = L2 - dz2;
1132      if (D2 <= (real)0.0) {
[21c226e]1133         /* FIXME: Should use FrDepth sometimes... */
1134         real vsum = VAR(Tape) + 2 * VAR(ToDepth);
[a420b49]1135         dx = dy = (real)0.0;
[f795df0]1136         vx = vy = var(Q_POS) / 3.0;
[21c226e]1137         /* FIXME: Should use FrDepth sometimes... */
1138         vz = var(Q_POS) / 3.0 + VAR(Tape) * 2 * VAR(ToDepth) / vsum;
[f795df0]1139         if (dz > 0) {
[21c226e]1140            /* FIXME: Should use FrDepth sometimes... */
1141            dz = (dz * VAR(Tape) + tape * 2 * VAR(ToDepth)) / vsum;
[f795df0]1142         } else {
[21c226e]1143            dz = (dz * VAR(Tape) - tape * 2 * VAR(ToDepth)) / vsum;
[f795df0]1144         }
[a420b49]1145      } else {
1146         real D = sqrt(D2);
[21c226e]1147         /* FIXME: Should use FrDepth sometimes... */
1148         real F = VAR(Tape) * L2 + 2 * VAR(ToDepth) * D2;
[a420b49]1149         dx = D * sinB;
1150         dy = D * cosB;
[f795df0]1151
1152         vx = var(Q_POS) / 3.0 +
[72095d3]1153            sinB * sinB * F / D2 + var_comp * dy * dy;
[f795df0]1154         vy = var(Q_POS) / 3.0 +
[72095d3]1155            cosB * cosB * F / D2 + var_comp * dx * dx;
[21c226e]1156         /* FIXME: Should use FrDepth sometimes... */
1157         vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth);
[f795df0]1158
1159#ifndef NO_COVARIANCES
[72095d3]1160         cxy = sinB * cosB * (F / D2 + var_comp * D2);
[21c226e]1161         /* FIXME: Should use FrDepth sometimes... */
1162         cyz = -2 * VAR(ToDepth) * dy / D;
1163         czx = -2 * VAR(ToDepth) * dx / D;
[f795df0]1164#endif
[a420b49]1165      }
1166   }
[5a38209]1167   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
[2140502]1168#ifndef NO_COVARIANCES
[f795df0]1169                , cxy, cyz, czx
[647407d]1170#endif
[2140502]1171                );
[be97baf]1172#ifdef CHASM3DX
[647407d]1173   if (fUseNewFormat) {
[be97baf]1174      /* new twiglet and insert into twig tree */
[407084d]1175      twig *twiglet = osnew(twig);
[90bb053f]1176      twiglet->from = fr;
1177      twiglet->to = to;
[407084d]1178      twiglet->down = twiglet->right = NULL;
1179      twiglet->source = twiglet->drawings
1180        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
1181      twiglet->up = limb->up;
1182      limb->right = twiglet;
1183      limb = twiglet;
1184
1185      /* record pre-fettling deltas */
[647407d]1186      twiglet->delta[0] = dx;
1187      twiglet->delta[1] = dy;
1188      twiglet->delta[2] = dz;
1189   }
1190#endif
1191
1192   return 1;
1193}
1194
[5a38209]1195static int
[21c226e]1196process_cartesian(prefix *fr, prefix *to, bool fToFirst)
[5a38209]1197{
[21c226e]1198   real dx = (VAL(Dx) * pcs->units[Q_DX] - pcs->z[Q_DX]) * pcs->sc[Q_DX];
1199   real dy = (VAL(Dy) * pcs->units[Q_DY] - pcs->z[Q_DY]) * pcs->sc[Q_DY];
1200   real dz = (VAL(Dz) * pcs->units[Q_DZ] - pcs->z[Q_DZ]) * pcs->sc[Q_DZ];
[647407d]1201
[21c226e]1202   addlegbyname(fr, to, fToFirst, dx, dy, dz, VAR(Dx), VAR(Dy), VAR(Dz)
[647407d]1203#ifndef NO_COVARIANCES
[c80bd34]1204                , 0, 0, 0
[647407d]1205#endif
[2140502]1206                );
[647407d]1207
[be97baf]1208#ifdef CHASM3DX
[647407d]1209   if (fUseNewFormat) {
[407084d]1210      /* new twiglet and insert into twig tree */
1211      twig *twiglet = osnew(twig);
[90bb053f]1212      twiglet->from = fr;
1213      twiglet->to = to;
[407084d]1214      twiglet->down = twiglet->right = NULL;
1215      twiglet->source = twiglet->drawings
1216        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
1217      twiglet->up = limb->up;
1218      limb->right = twiglet;
1219      limb = twiglet;
1220
1221      /* record pre-fettling deltas */
[647407d]1222      twiglet->delta[0] = dx;
1223      twiglet->delta[1] = dy;
1224      twiglet->delta[2] = dz;
1225   }
[4f8285d]1226#endif
[647407d]1227
1228   return 1;
1229}
1230
1231extern int
[5a38209]1232data_cartesian(void)
[647407d]1233{
[90bb053f]1234   prefix *fr = NULL, *to = NULL;
[5a38209]1235
1236   bool fMulti = fFalse;
[647407d]1237
[0395657]1238   reading first_stn = End;
1239
1240   reading *ordering;
[647407d]1241
[5a38209]1242   again:
1243
[647407d]1244   for (ordering = pcs->ordering ; ; ordering++) {
1245      skipblanks();
1246      switch (*ordering) {
[4a6a094]1247       case Fr:
[21c226e]1248         fr = read_prefix_stn(fFalse, fTrue);
1249         if (first_stn == End) first_stn = Fr;
1250         break;
[4a6a094]1251       case To:
[21c226e]1252         to = read_prefix_stn(fFalse, fTrue);
1253         if (first_stn == End) first_stn = To;
1254         break;
[5a38209]1255       case Station:
[21c226e]1256         fr = to;
1257         to = read_prefix_stn(fFalse, fFalse);
1258         first_stn = To;
1259         break;
1260       case Dx: case Dy: case Dz:
1261         read_reading(*ordering, fFalse);
1262         break;
[647407d]1263       case Ignore:
1264         skipword(); break;
[5a38209]1265       case IgnoreAllAndNewLine:
1266         skipline();
1267         /* fall through */
1268       case Newline:
1269         if (fr != NULL) {
1270            int r;
[21c226e]1271            r = process_cartesian(fr, to, first_stn == To);
[5a38209]1272            if (!r) skipline();
1273         }
1274         fMulti = fTrue;
1275         while (1) {
1276            process_eol();
1277            process_bol();
1278            if (isData(ch)) break;
[ee6a621]1279            if (!isComm(ch)) {
[993454b]1280               push_back(ch);
[ee6a621]1281               return 1;
1282            }
[5a38209]1283         }
1284         break;
[647407d]1285       case IgnoreAll:
1286         skipline();
1287         /* fall through */
1288       case End:
[5a38209]1289         if (!fMulti) {
[21c226e]1290            int r = process_cartesian(fr, to, first_stn == To);
[5a38209]1291            process_eol();
1292            return r;
1293         }
[eef4d8c]1294         do {
[5a38209]1295            process_eol();
1296            process_bol();
[eef4d8c]1297         } while (isComm(ch));
[5a38209]1298         goto again;
[0395657]1299       default: BUG("Unknown reading in ordering");
[647407d]1300      }
1301   }
[5a38209]1302}
[cb3d1e2]1303
[98a2eec]1304static int
[21c226e]1305process_cylpolar(prefix *fr, prefix *to, bool fToFirst, bool fDepthChange)
[98a2eec]1306{
[21c226e]1307   real tape = VAL(Tape);
1308   real frdepth = VAL(FrDepth);
1309   real todepth = VAL(ToDepth);
1310
[98a2eec]1311   real dx, dy, dz;
1312   real vx, vy, vz;
1313#ifndef NO_COVARIANCES
1314   real cxy = 0;
1315#endif
1316
[21c226e]1317   handle_comp_units();
[98a2eec]1318
[a6d094f]1319   /* depth gauge readings increase upwards with default calibration */
[6114207]1320   if (fDepthChange) {
[21c226e]1321      SVX_ASSERT(VAL(FrDepth) == 0.0);
1322      dz = VAL(ToDepth) * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH];
1323      dz *= pcs->sc[Q_DEPTH];
[a6d094f]1324   } else {
[21c226e]1325      dz = VAL(ToDepth) - VAL(FrDepth);
1326      dz *= pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH];
[a6d094f]1327   }
[98a2eec]1328
1329   /* adjusted tape is negative -- probably the calibration is wrong */
1330   if (tape < (real)0.0) {
1331      compile_warning(/*Negative adjusted tape reading*/79);
1332   }
1333
[21c226e]1334   if (VAL(Comp) == HUGE_REAL && VAL(BackComp) == HUGE_REAL) {
[98a2eec]1335      /* plumb */
1336      dx = dy = (real)0.0;
1337      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
[21c226e]1338      /* FIXME: Should use FrDepth sometimes... */
1339      vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth);
[98a2eec]1340   } else {
1341      real sinB, cosB;
[b6de07d]1342      real var_comp;
[21c226e]1343      real comp = handle_compass(&var_comp);
[98a2eec]1344      sinB = sin(comp);
1345      cosB = cos(comp);
1346
1347      dx = tape * sinB;
1348      dy = tape * cosB;
1349
1350      vx = var(Q_POS) / 3.0 +
[21c226e]1351         VAR(Tape) * sinB * sinB + var_comp * dy * dy;
[98a2eec]1352      vy = var(Q_POS) / 3.0 +
[21c226e]1353         VAR(Tape) * cosB * cosB + var_comp * dx * dx;
1354      /* FIXME: Should use FrDepth sometimes... */
1355      vz = var(Q_POS) / 3.0 + 2 * VAR(ToDepth);
[98a2eec]1356
1357#ifndef NO_COVARIANCES
[21c226e]1358      cxy = (VAR(Tape) - var_comp * tape * tape) * sinB * cosB;
[98a2eec]1359#endif
1360   }
1361   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
1362#ifndef NO_COVARIANCES
1363                , cxy, 0, 0
1364#endif
1365                );
[be97baf]1366#ifdef CHASM3DX
[98a2eec]1367   if (fUseNewFormat) {
[be97baf]1368      /* new twiglet and insert into twig tree */
[98a2eec]1369      twig *twiglet = osnew(twig);
1370      twiglet->from = fr;
1371      twiglet->to = to;
1372      twiglet->down = twiglet->right = NULL;
1373      twiglet->source = twiglet->drawings
1374        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
1375      twiglet->up = limb->up;
1376      limb->right = twiglet;
1377      limb = twiglet;
1378
1379      /* record pre-fettling deltas */
1380      twiglet->delta[0] = dx;
1381      twiglet->delta[1] = dy;
1382      twiglet->delta[2] = dz;
1383   }
1384#endif
1385
1386   return 1;
1387}
1388
[107b8bd]1389/* Process tape/compass/clino, diving, and cylpolar styles of survey data
1390 * Also handles topofil (fromcount/tocount or count) in place of tape */
[54c4612]1391extern int
[107b8bd]1392data_normal(void)
[54c4612]1393{
1394   prefix *fr = NULL, *to = NULL;
[107b8bd]1395   reading first_stn = End;
[54c4612]1396
[107b8bd]1397   bool fTopofil = fFalse, fMulti = fFalse;
1398   bool fRev;
[e217d67]1399   clino_type ctype, backctype;
[107b8bd]1400   bool fDepthChange;
[be97baf]1401   unsigned long compass_dat_flags = 0;
[54c4612]1402
1403   reading *ordering;
1404
[21c226e]1405   VAL(Tape) = 0;
1406   VAL(Comp) = VAL(BackComp) = HUGE_VAL;
1407   VAL(FrCount) = VAL(ToCount) = 0;
1408   VAL(FrDepth) = VAL(ToDepth) = 0;
[54c4612]1409
1410   fRev = fFalse;
[fa42426]1411   ctype = backctype = CTYPE_OMIT;
[6114207]1412   fDepthChange = fFalse;
[54c4612]1413
[107b8bd]1414   /* ordering may omit clino reading, so set up default here */
1415   /* this is also used if clino reading is the omit character */
[21c226e]1416   VAL(Clino) = VAL(BackClino) = 0;
1417
1418   again:
[107b8bd]1419
[54c4612]1420   for (ordering = pcs->ordering; ; ordering++) {
1421      skipblanks();
1422      switch (*ordering) {
1423       case Fr:
[107b8bd]1424          fr = read_prefix_stn(fFalse, fTrue);
1425          if (first_stn == End) first_stn = Fr;
1426          break;
[54c4612]1427       case To:
[107b8bd]1428          to = read_prefix_stn(fFalse, fTrue);
1429          if (first_stn == End) first_stn = To;
1430          break;
[54c4612]1431       case Station:
[107b8bd]1432          fr = to;
1433          to = read_prefix_stn(fFalse, fFalse);
1434          first_stn = To;
1435          break;
[ee1ec59]1436       case Dir: {
1437          typedef enum {
1438             DIR_NULL=-1, DIR_FORE, DIR_BACK
1439          } dir_tok;
1440          static sztok dir_tab[] = {
1441             {"B",     DIR_BACK},
1442             {"F",     DIR_FORE},
1443          };
1444          dir_tok tok;
1445          get_token();
1446          tok = match_tok(dir_tab, TABSIZE(dir_tab));
1447          switch (tok) {
1448           case DIR_FORE:
[54c4612]1449             break;
[ee1ec59]1450           case DIR_BACK:
[54c4612]1451             fRev = fTrue;
1452             break;
1453           default:
[ee1ec59]1454             compile_error_skip(/*Found `%s', expecting `F' or `B'*/131,
1455                                buffer);
[54c4612]1456             process_eol();
1457             return 0;
1458          }
1459          break;
[ee1ec59]1460       }
[107b8bd]1461       case Tape:
[21c226e]1462          read_reading(Tape, fFalse);
1463          if (VAL(Tape) < (real)0.0)
1464             compile_warning(/*Negative tape reading*/60);
[107b8bd]1465          break;
1466       case Count:
[21c226e]1467          VAL(FrCount) = VAL(ToCount);
1468          read_reading(ToCount, fFalse);
[107b8bd]1469          break;
1470       case FrCount:
[21c226e]1471          read_reading(FrCount, fFalse);
[107b8bd]1472          break;
1473       case ToCount:
[21c226e]1474          read_reading(ToCount, fFalse);
[107b8bd]1475          fTopofil = fTrue;
1476          break;
1477       case Comp:
[21c226e]1478          read_bearing_or_omit(Comp);
[107b8bd]1479          break;
[5b7c1b7]1480       case BackComp:
[21c226e]1481          read_bearing_or_omit(BackComp);
[5b7c1b7]1482          break;
[5757725]1483       case Clino:
[21c226e]1484          read_reading(Clino, fTrue);
1485          if (VAL(Clino) == HUGE_REAL) {
1486             VAL(Clino) = handle_plumb(&ctype);
1487             if (VAL(Clino) != HUGE_REAL) break;
[107b8bd]1488             compile_error_token(/*Expecting numeric field, found `%s'*/9);
1489             process_eol();
1490             return 0;
1491          }
[fa42426]1492          ctype = CTYPE_READING;
[5b7c1b7]1493          break;
1494       case BackClino:
[21c226e]1495          read_reading(BackClino, fTrue);
1496          if (VAL(BackClino) == HUGE_REAL) {
1497             VAL(BackClino) = handle_plumb(&backctype);
1498             if (VAL(BackClino) != HUGE_REAL) break;
[5b7c1b7]1499             compile_error_token(/*Expecting numeric field, found `%s'*/9);
1500             process_eol();
1501             return 0;
1502          }
[fa42426]1503          backctype = CTYPE_READING;
[107b8bd]1504          break;
1505       case FrDepth:
[21c226e]1506          read_reading(FrDepth, fFalse);
[107b8bd]1507          break;
1508       case ToDepth:
[21c226e]1509          read_reading(ToDepth, fFalse);
[107b8bd]1510          break;
[54c4612]1511       case Depth:
[21c226e]1512          VAL(FrDepth) = VAL(ToDepth);
1513          read_reading(ToDepth, fFalse);
[54c4612]1514          break;
[6114207]1515       case DepthChange:
1516          fDepthChange = fTrue;
[21c226e]1517          VAL(FrDepth) = 0;
1518          read_reading(ToDepth, fFalse);
[a186573]1519          break;
[be97baf]1520       case CompassDATFlags:
1521          if (ch == '#') {
1522             nextch();
1523             if (ch == '|') {
1524                filepos fp;
1525                get_pos(&fp);
1526                nextch();
1527                while (ch >= 'A' && ch <= 'Z') {
1528                   compass_dat_flags |= BIT(ch - 'A');
1529                   nextch();
1530                }
1531                if (ch == '#') {
1532                   nextch();
1533                } else {
1534                   compass_dat_flags = 0;
1535                   set_pos(&fp);
1536                   push_back('|');
1537                   ch = '#';
1538                }
1539             } else {
1540                push_back(ch);
1541                ch = '#';
1542             }
1543          }
[107b8bd]1544          break;
[be97baf]1545       case Ignore:
1546          skipword(); break;
[54c4612]1547       case IgnoreAllAndNewLine:
[107b8bd]1548          skipline();
1549          /* fall through */
[54c4612]1550       case Newline:
[107b8bd]1551          if (fr != NULL) {
1552             int r;
[21c226e]1553             if (fTopofil)
1554                VAL(Tape) = VAL(ToCount) - VAL(FrCount);
[107b8bd]1555             /* Note: frdepth == todepth test works regardless of fDepthChange
1556              * (frdepth always zero, todepth is change of depth) and also
1557              * works for STYLE_NORMAL (both remain 0) */
[27b8b59]1558             if (TSTBIT(pcs->infer, INFER_EQUATES) &&
1559                 VAL(Tape) == (real)0.0 && VAL(FrDepth) == VAL(ToDepth)) {
[107b8bd]1560                process_equate(fr, to);
1561                goto inferred_equate;
1562             }
[e7576f6]1563             if (fRev) {
1564                prefix *t = fr;
1565                fr = to;
1566                to = t;
1567             }
[107b8bd]1568             if (fTopofil) {
[21c226e]1569                VAL(Tape) *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT];
[107b8bd]1570             } else {
[21c226e]1571                VAL(Tape) *= pcs->units[Q_LENGTH];
1572                VAL(Tape) -= pcs->z[Q_LENGTH];
1573                VAL(Tape) *= pcs->sc[Q_LENGTH];
[107b8bd]1574             }
1575             switch (pcs->style) {
1576              case STYLE_NORMAL:
[21c226e]1577                r = process_normal(fr, to, (first_stn == To) ^ fRev,
1578                                   ctype, backctype);
[107b8bd]1579                break;
1580              case STYLE_DIVING:
[21c226e]1581                r = process_diving(fr, to, (first_stn == To) ^ fRev,
1582                                   fDepthChange);
[107b8bd]1583                break;
1584              case STYLE_CYLPOLAR:
[21c226e]1585                r = process_cylpolar(fr, to, (first_stn == To) ^ fRev,
1586                                     fDepthChange);
[107b8bd]1587                break;
1588              default:
1589                BUG("bad style");
1590             }
1591             if (!r) skipline();
[e7576f6]1592             
1593             /* Swap fr and to back to how they were for next line */
1594             if (fRev) {
1595                prefix *t = fr;
1596                fr = to;
1597                to = t;
1598             }
[107b8bd]1599          }
[21c226e]1600
1601          fRev = fFalse;
1602          ctype = backctype = CTYPE_OMIT;
1603          fDepthChange = fFalse;
1604
1605          /* ordering may omit clino reading, so set up default here */
1606          /* this is also used if clino reading is the omit character */
1607          VAL(Clino) = VAL(BackClino) = 0;
1608
[107b8bd]1609          inferred_equate:
[e7576f6]1610
[107b8bd]1611          fMulti = fTrue;
1612          while (1) {
1613              process_eol();
1614              process_bol();
1615              if (isData(ch)) break;
1616              if (!isComm(ch)) {
1617                 push_back(ch);
1618                 return 1;
1619              }
1620          }
1621          break;
[54c4612]1622       case IgnoreAll:
[107b8bd]1623          skipline();
1624          /* fall through */
[54c4612]1625       case End:
[107b8bd]1626          if (!fMulti) {
1627             int r;
[be97baf]1628             /* Compass ignore flag is 'X' */
1629             if ((compass_dat_flags & BIT('X' - 'A'))) {
1630                process_eol();
1631                return 1;
1632             }
[107b8bd]1633             if (fRev) {
1634                prefix *t = fr;
1635                fr = to;
1636                to = t;
1637             }
[21c226e]1638             if (fTopofil) VAL(Tape) = VAL(ToCount) - VAL(FrCount);
[107b8bd]1639             /* Note: frdepth == todepth test works regardless of fDepthChange
1640              * (frdepth always zero, todepth is change of depth) and also
1641              * works for STYLE_NORMAL (both remain 0) */
[27b8b59]1642             if (TSTBIT(pcs->infer, INFER_EQUATES) &&
1643                 VAL(Tape) == (real)0.0 && VAL(FrDepth) == VAL(ToDepth)) {
[107b8bd]1644                process_equate(fr, to);
1645                process_eol();
1646                return 1;
1647             }
1648             if (fTopofil) {
[21c226e]1649                VAL(Tape) *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT];
[107b8bd]1650             } else {
[21c226e]1651                VAL(Tape) *= pcs->units[Q_LENGTH];
1652                VAL(Tape) -= pcs->z[Q_LENGTH];
1653                VAL(Tape) *= pcs->sc[Q_LENGTH];
[107b8bd]1654             }
1655             switch (pcs->style) {
1656              case STYLE_NORMAL:
[21c226e]1657                r = process_normal(fr, to, (first_stn == To) ^ fRev,
1658                                   ctype, backctype);
[107b8bd]1659                break;
1660              case STYLE_DIVING:
[21c226e]1661                r = process_diving(fr, to, (first_stn == To) ^ fRev,
1662                                   fDepthChange);
[107b8bd]1663                break;
1664              case STYLE_CYLPOLAR:
[21c226e]1665                r = process_cylpolar(fr, to, (first_stn == To) ^ fRev,
1666                                     fDepthChange);
[107b8bd]1667                break;
1668              default:
1669                BUG("bad style");
1670             }
1671             process_eol();
1672             return r;
1673          }
1674          do {
1675             process_eol();
1676             process_bol();
1677          } while (isComm(ch));
1678          goto again;
1679       default:
1680          BUG("Unknown reading in ordering");
[54c4612]1681      }
1682   }
1683}
1684
[5a38209]1685static int
1686process_nosurvey(prefix *fr, prefix *to, bool fToFirst)
1687{
1688   nosurveylink *link;
[838a602a]1689   int shape;
[647407d]1690
[be97baf]1691#ifdef CHASM3DX
[647407d]1692   if (fUseNewFormat) {
[407084d]1693      /* new twiglet and insert into twig tree */
1694      twig *twiglet = osnew(twig);
[90bb053f]1695      twiglet->from = fr;
1696      twiglet->to = to;
[647407d]1697      twiglet->down = twiglet->right = NULL;
1698      twiglet->source = twiglet->drawings
1699        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
1700      twiglet->up = limb->up;
1701      limb->right = twiglet;
1702      limb = twiglet;
[3bcbcb2]1703      /* delta is only used to calculate error - pass zero and cope
1704       * elsewhere */
[647407d]1705      twiglet->delta[0] = twiglet->delta[1] = twiglet->delta[2] = 0;
1706   }
1707#endif
1708
[838a602a]1709   /* Suppress "unused fixed point" warnings for these stations
1710    * We do this if it's a 0 or 1 node - 1 node might be an sdfix
1711    */
1712   shape = fr->shape;
1713   if (shape == 0 || shape == 1) fr->shape = -1 - shape;
1714   shape = to->shape;
1715   if (shape == 0 || shape == 1) to->shape = -1 - shape;
1716
[647407d]1717   /* add to linked list which is dealt with after network is solved */
1718   link = osnew(nosurveylink);
[5a38209]1719   if (fToFirst) {
[90bb053f]1720      link->to = StnFromPfx(to);
1721      link->fr = StnFromPfx(fr);
[0395657]1722   } else {
[90bb053f]1723      link->fr = StnFromPfx(fr);
1724      link->to = StnFromPfx(to);
[0395657]1725   }
[b3bef47]1726   link->flags = pcs->flags;
[647407d]1727   link->next = nosurveyhead;
1728   nosurveyhead = link;
[a420b49]1729   return 1;
[d1b1380]1730}
[50f6901]1731
[5a38209]1732extern int
1733data_nosurvey(void)
1734{
1735   prefix *fr = NULL, *to = NULL;
1736
1737   bool fMulti = fFalse;
1738
1739   reading first_stn = End;
1740
1741   reading *ordering;
1742
1743   again:
1744
1745   for (ordering = pcs->ordering ; ; ordering++) {
1746      skipblanks();
1747      switch (*ordering) {
1748       case Fr:
[84c60fc]1749          fr = read_prefix_stn(fFalse, fTrue);
[5a38209]1750          if (first_stn == End) first_stn = Fr;
1751          break;
1752       case To:
[84c60fc]1753          to = read_prefix_stn(fFalse, fTrue);
[5a38209]1754          if (first_stn == End) first_stn = To;
1755          break;
1756       case Station:
1757          fr = to;
[84c60fc]1758          to = read_prefix_stn(fFalse, fFalse);
[5a38209]1759          first_stn = To;
1760          break;
1761       case Ignore:
1762         skipword(); break;
1763       case IgnoreAllAndNewLine:
1764         skipline();
1765         /* fall through */
1766       case Newline:
1767         if (fr != NULL) {
1768            int r;
1769            r = process_nosurvey(fr, to, first_stn == To);
1770            if (!r) skipline();
1771         }
[838a602a]1772         if (ordering[1] == End) {
1773            do {
1774               process_eol();
1775               process_bol();
1776            } while (isComm(ch));
[ee6a621]1777            if (!isData(ch)) {
[993454b]1778               push_back(ch);
[ee6a621]1779               return 1;
1780            }
[838a602a]1781            goto again;
1782         }
[5a38209]1783         fMulti = fTrue;
1784         while (1) {
1785            process_eol();
1786            process_bol();
1787            if (isData(ch)) break;
[ee6a621]1788            if (!isComm(ch)) {
[993454b]1789               push_back(ch);
[ee6a621]1790               return 1;
1791            }
[5a38209]1792         }
1793         break;
1794       case IgnoreAll:
1795         skipline();
1796         /* fall through */
1797       case End:
1798         if (!fMulti) {
[ee6a621]1799            int r = process_nosurvey(fr, to, first_stn == To);
[5a38209]1800            process_eol();
1801            return r;
1802         }
[eef4d8c]1803         do {
[5a38209]1804            process_eol();
1805            process_bol();
[eef4d8c]1806         } while (isComm(ch));
[5a38209]1807         goto again;
1808       default: BUG("Unknown reading in ordering");
1809      }
1810   }
1811}
1812
[50f6901]1813/* totally ignore a line of survey data */
1814extern int
1815data_ignore(void)
1816{
1817   skipline();
[ee6a621]1818   process_eol();
[570f4bf]1819   return 1;
[50f6901]1820}
Note: See TracBrowser for help on using the repository browser.