source: git/src/datain.c @ 5fa68cc5

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

*infer plumbs wasn't inferring -90 to be DOWN - fixed.

BackClino? and BackCompass? now partially work with NORMAL data style.

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

  • Property mode set to 100644
File size: 33.9 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
42#define MAX_KEYWORD_LEN 16
43
44#define PRINT_COMMENT 0
45
[58cc1fb]46#define var(I) (pcs->Var[(I)])
[d1b1380]47
[58cc1fb]48int ch;
[d1b1380]49
[5b7c1b7]50typedef enum {CLINO_OMIT, CLINO_READING, CLINO_PLUMB, CLINO_HORIZ} clino_type;
51
[eb18f4d]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 */
[b0d908e]54parse file /* = { NULL, NULL, 0, fFalse, NULL } */ ;
[a420b49]55
[932f7e9]56bool f_export_ok;
57
[c80bd34]58static filepos fpLineStart;
[d1b1380]59
[c7451a9]60void
[c80bd34]61get_pos(filepos *fp)
[c7451a9]62{
[c80bd34]63   fp->ch = ch;
64   fp->offset = ftell(file.fh);
65   if (fp->offset == -1)
[c7451a9]66      fatalerror_in_file(file.filename, 0, /*Error reading file*/18);
67}
68
[c80bd34]69void
70set_pos(const filepos *fp)
[c7451a9]71{
[c80bd34]72   ch = fp->ch;
73   if (fseek(file.fh, fp->offset, SEEK_SET) == -1)
[c7451a9]74      fatalerror_in_file(file.filename, 0, /*Error reading file*/18);
75}
76
[44bf1d9]77static void
[993454b]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
[a420b49]84static void
85error_list_parent_files(void)
86{
[b0d908e]87   if (!file.reported_where && file.parent) {
[421b7d2]88      parse *p = file.parent;
[46cb98f]89      const char *m = msg(/*In file included from*/5);
[84c60fc]90      size_t len = strlen(m);
[b0d908e]91
[84c60fc]92      fprintf(STDERR, m);
[46cb98f]93      m = msg(/*from*/3);
[b0d908e]94
95      /* Suppress reporting of full include tree for further errors
96       * in this file */
97      file.reported_where = fTrue;
98
[a420b49]99      while (p) {
[b0d908e]100         /* Force re-report of include tree for further errors in
101          * parent files */
102         p->reported_where = fFalse;
[46cb98f]103         fprintf(STDERR, " %s:%d", p->filename, p->line);
[a420b49]104         p = p->parent;
[84f3ed6]105         if (p) fprintf(STDERR, ",\n%*s", (int)len, m);
[a420b49]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
[39fba51]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   }
[029cc3f]132   compile_error(en, p ? p : "");
[39fba51]133   osfree(p);
134   skipline();
135}
136
[a420b49]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) {
[4bab027]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;
[58cc1fb]163   }
164}
165
[a420b49]166static void
167skipword(void)
168{
[58cc1fb]169   while (!isBlank(ch) && !isEol(ch)) nextch();
[d1b1380]170}
171
[a420b49]172extern void
173skipblanks(void)
174{
[58cc1fb]175   while (isBlank(ch)) nextch();
[d1b1380]176}
177
[a420b49]178extern void
179skipline(void)
180{
[58cc1fb]181   while (!isEol(ch)) nextch();
[d1b1380]182}
183
[90bb053f]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 */
[c80bd34]192   get_pos(&fpLineStart);
[90bb053f]193
194#ifndef NO_PERCENTAGE
195   /* print %age of file done */
[c80bd34]196   if (filelen > 0)
197      printf("%d%%\r", (int)(100 * fpLineStart.offset / filelen));
[90bb053f]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)) {
[44bf1d9]212      if (!isComm(ch)) compile_error(/*End of line not blank*/15);
[90bb053f]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)) {
[993454b]224         push_back(ch);
[90bb053f]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
[a420b49]247extern void
248data_file(const char *pth, const char *fnm)
249{
[47c7a94]250   int begin_lineno_store;
[7f08c83]251   parse file_store;
[d1b1380]252
[7f08c83]253   {
254      char *filename;
[f4b609d]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      }
[bd1913f]262
[7f08c83]263      if (fh == NULL) {
[759fb47]264         compile_error(/*Couldn't open data file `%s'*/24, fnm);
[7f08c83]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;
[b0d908e]273      file.reported_where = fFalse;
[a420b49]274   }
[cb3d1e2]275
[5b68ae1]276   if (fPercent) printf("%s:\n", fnm);
[d1b1380]277
[a420b49]278   using_data_file(file.filename);
[d1b1380]279
[47c7a94]280   begin_lineno_store = pcs->begin_lineno;
281   pcs->begin_lineno = 0;
[cb3d1e2]282
[d1b1380]283#ifndef NO_PERCENTAGE
[58cc1fb]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) {
[c80bd34]288      if (fseek(file.fh, 0l, SEEK_END) == 0) {
289         filepos fp;
290         get_pos(&fp);
291         filelen = fp.offset;
292      }
[58cc1fb]293      rewind(file.fh); /* reset file ptr to start & clear any error state */
294   }
[d1b1380]295#endif
296
[7d5f3c0]297#ifdef HAVE_SETJMP_H
[a420b49]298   /* errors in nested functions can longjmp here */
299   if (setjmp(file.jbSkipLine)) {
[076d33d]300      process_eol();
[a420b49]301   }
[d1b1380]302#endif
[cb3d1e2]303
[c7451a9]304   while (!feof(file.fh) && !ferror(file.fh)) {
[90bb053f]305      if (!process_non_data_line()) {
[107b8bd]306         int r;
[647407d]307#ifdef NEW3DFORMAT
[407084d]308         twig *temp = limb;
[647407d]309#endif
[407084d]310         f_export_ok = fFalse;
[107b8bd]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         }
[90bb053f]329         /* style function returns 0 => error */
[107b8bd]330         if (!r) {
[647407d]331#ifdef NEW3DFORMAT
[90bb053f]332            /* we have just created a very naughty twiglet, and it must be
333             * punished */
[647407d]334            osfree(limb);
335            limb = temp;
336#endif
[a420b49]337         }
[647407d]338      }
[a420b49]339   }
340
[932f7e9]341   /* don't allow *BEGIN at the end of a file, then *EXPORT in the
342    * including file */
343   f_export_ok = fFalse;
344
[a420b49]345#ifndef NO_PERCENTAGE
346   if (fPercent) putnl();
[4f8285d]347#endif
[d1b1380]348
[47c7a94]349   if (pcs->begin_lineno) {
[0e867ba6]350      error_in_file(file.filename, pcs->begin_lineno,
351                    /*BEGIN with no matching END in this file*/23);
[47c7a94]352      /* Implicitly close any unclosed BEGINs from this file */
353      do {
354         settings *pcsParent = pcs->next;
355         ASSERT(pcsParent);
[647407d]356         free_settings(pcs);
[47c7a94]357         pcs = pcsParent;
358      } while (pcs->begin_lineno);
359   }
360
361   pcs->begin_lineno = begin_lineno_store;
[cb3d1e2]362
[22c9877]363   if (ferror(file.fh))
[bfe1242]364      fatalerror_in_file(file.filename, 0, /*Error reading file*/18);
[cb3d1e2]365
[22c9877]366   (void)fclose(file.fh);
[7f08c83]367
[22c9877]368   file = file_store;
[4d9eecd]369
370   /* don't free this - it may be pointed to by prefix.file */
371   /* osfree(file.filename); */
[a420b49]372}
[d1b1380]373
[dcec245]374static real
[5b7c1b7]375handle_plumb(clino_type *p_ctype)
[dcec245]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   };
[5b7c1b7]389   static real clinos[] = {(real)M_PI_2, (real)(-M_PI_2), (real)0.0};
[dcec245]390   clino_tok tok;
391
392   skipblanks();
393   if (isalpha(ch)) {
[c80bd34]394      filepos fp;
395      get_pos(&fp);
[dcec245]396      get_token();
397      tok = match_tok(clino_tab, TABSIZE(clino_tab));
398      if (tok != CLINO_NULL) {
[5b7c1b7]399         *p_ctype = (clinos[tok] == CLINO_LEVEL ? CLINO_HORIZ : CLINO_PLUMB);
[dcec245]400         return clinos[tok];
401      }
[c80bd34]402      set_pos(&fp);
[dcec245]403   } else if (isSign(ch)) {
404      int chOld = ch;
405      nextch();
406      if (toupper(ch) == 'V') {
407         nextch();
[5b7c1b7]408         *p_ctype = CLINO_PLUMB;
[bceebf4]409         return (!isMinus(chOld) ? M_PI_2 : -M_PI_2);
[dcec245]410      }
411
[bd1913f]412      if (isOmit(chOld)) {
[5b7c1b7]413         *p_ctype = CLINO_OMIT;
[dcec245]414         /* no clino reading, so assume 0 with large sd */
415         return (real)0.0;
416      }
[5b7c1b7]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;
[dcec245]424   }
425   return HUGE_REAL;
426}
427
[90bb053f]428static int
429process_normal(prefix *fr, prefix *to, real tape, real comp, real clin,
[0b71cfc]430               real backcomp, real backclin,
[5b7c1b7]431               bool fToFirst, clino_type ctype, clino_type backctype)
[a420b49]432{
433   real dx, dy, dz;
434   real vx, vy, vz;
435#ifndef NO_COVARIANCES
[cb3d1e2]436   real cxy, cyz, czx;
[a420b49]437#endif
[d1b1380]438
[90bb053f]439   bool fNoComp;
[a420b49]440
[107b8bd]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);
[647407d]445   }
[d1b1380]446
[0b71cfc]447   fNoComp = fTrue;
448   if (comp != HUGE_REAL) {
449      fNoComp = fFalse;
[a420b49]450      comp *= pcs->units[Q_BEARING];
[3e784b5]451      if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) {
[a420b49]452         compile_warning(/*Suspicious compass reading*/59);
453      }
454   }
[0b71cfc]455   if (backcomp != HUGE_REAL) {
456      fNoComp = fFalse;
457      /* FIXME: different units for BackComp? */
458      backcomp *= pcs->units[Q_BEARING];
459      if (backcomp < (real)0.0 || backcomp - M_PI * 2.0 > EPSILON) {
460         /* FIXME: different message for BackComp? */
461         compile_warning(/*Suspicious compass reading*/59);
462      }
463   }
[d1b1380]464
[5b7c1b7]465   if (ctype == CLINO_READING) {
[0b71cfc]466      real diff_from_abs90;
[a420b49]467      clin *= pcs->units[Q_GRADIENT];
[0b71cfc]468      diff_from_abs90 = fabs(clin) - M_PI_2;
469      if (diff_from_abs90 > EPSILON) {
[a420b49]470         compile_warning(/*Clino reading over 90 degrees (absolute value)*/51);
[0b71cfc]471      } else if (pcs->f90Up && diff_from_abs90 > -EPSILON) {
472         ctype = CLINO_PLUMB;
[a420b49]473      }
474   }
[cb3d1e2]475
[0b71cfc]476   if (backctype == CLINO_READING) {
477      real diff_from_abs90;
478      /* FIXME: different units for BackClino? */
479      backclin *= pcs->units[Q_GRADIENT];
480      diff_from_abs90 = fabs(backclin) - M_PI_2;
481      if (diff_from_abs90 > EPSILON) {
482         /* FIXME: different message for BackClino? */
483         compile_warning(/*Clino reading over 90 degrees (absolute value)*/51);
484      } else if (pcs->f90Up && diff_from_abs90 > -EPSILON) {
485         backctype = CLINO_PLUMB;
486      }
487   }
488
489   if (ctype != CLINO_OMIT && backctype != CLINO_OMIT && ctype != backctype) {
490      /* Bad combinations */
491      compile_error(21/*FIXME*/);
492   }
493
494   if (ctype == CLINO_PLUMB || backctype == CLINO_PLUMB) {
[a420b49]495      /* plumbed */
496      if (!fNoComp) {
[0b71cfc]497         /* FIXME: Different message for BackCompass */
[a420b49]498         compile_warning(/*Compass reading given on plumbed leg*/21);
499      }
500
501      dx = dy = (real)0.0;
[0b71cfc]502      if (ctype != CLINO_OMIT) {
503         if (backctype != CLINO_OMIT && (clin > 0) == (backclin > 0)) {
504            compile_error(/*FIXME*/21);
505         }
506         dz = (clin > (real)0.0) ? tape : -tape;
507      } else {
508         dz = (backclin < (real)0.0) ? tape : -tape;
509      }
[a420b49]510      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
511      vz = var(Q_POS) / 3.0 + var(Q_LENGTH);
[4f8285d]512#ifndef NO_COVARIANCES
[26a805f]513      /* Correct values - no covariances in this case! */
514      cxy = cyz = czx = (real)0.0;
[4f8285d]515#endif
[a420b49]516   } else {
[0b71cfc]517      /* Each of ctype and backctype are either CLINO_READING/CLINO_HORIZ
518       * or CLINO_OMIT */
[a420b49]519      /* clino */
520      real L2, cosG, LcosG, cosG2, sinB, cosB, dx2, dy2, dz2, v, V;
[421b7d2]521      if (fNoComp) {
[39fba51]522         compile_error(/*Compass reading may not be omitted except on plumbed legs*/14);
523         skipline();
[a420b49]524         return 0;
525      }
526      if (tape == (real)0.0) {
527         dx = dy = dz = (real)0.0;
528         vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */
[4f8285d]529#ifndef NO_COVARIANCES
[a420b49]530         cxy = cyz = czx = (real)0.0;
[4f8285d]531#endif
[d1b1380]532#if DEBUG_DATAIN_1
[a420b49]533         printf("Zero length leg: vx = %f, vy = %f, vz = %f\n", vx, vy, vz);
[d1b1380]534#endif
[a420b49]535      } else {
[dbb4e19]536         real sinGcosG;
[0b71cfc]537         real var_comp = var(Q_BEARING);
538         /* take into account variance in LEVEL case */
539         real var_clin = var(Q_LEVEL);
540         if (comp != HUGE_REAL) {
541            comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING];
542            comp -= pcs->z[Q_DECLINATION];
543         }
544         if (backcomp != HUGE_REAL) {
545            /* FIXME: different calibration? */
546            backcomp = (backcomp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING];
547            backcomp -= pcs->z[Q_DECLINATION];
548            if (comp != HUGE_REAL) {
549               /* FIXME: complain if fabs(comp - backcomp + M_PI) (mod (M_PI*2))
550                * is too large */
551               /* FIXME: weighted averages if variances can be different */
552               comp = (comp + backcomp - M_PI) / 2.0;
553               var_comp /= 2;
554            } else {
555               /* FIXME: if variances can be different
556                * set var_comp to back variance */
557               comp = backcomp - M_PI;
558            }
559         }
560         /* ctype != CLINO_READING is LEVEL case */
561         if (ctype == CLINO_READING) {
[a420b49]562            clin = (clin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT];
[0b71cfc]563            var_clin = var(Q_GRADIENT);
564         }
565         /* FIXME: Separate units and calib for BackClino? */
566         if (backctype == CLINO_READING) {
567            backclin = (backclin - pcs->z[Q_GRADIENT]) * pcs->sc[Q_GRADIENT];
568            if (ctype == CLINO_READING) {
569               /* FIXME: complain if fabs(clin + backclin) is too large */
570               /* FIXME: weighted averages if variances can be different */
571               clin = (clin - backclin) / 2;
572               var_clin /= 2;
573            } else {
574               clin = -backclin;
575               /* FIXME: if backclin var can differ... */
576               var_clin = var(Q_GRADIENT);
577            }
578         }
[d1b1380]579
580#if DEBUG_DATAIN
[a420b49]581         printf("    %4.2f %4.2f %4.2f\n", tape, comp, clin);
[d1b1380]582#endif
[a420b49]583         cosG = cos(clin);
584         LcosG = tape * cosG;
585         sinB = sin(comp);
586         cosB = cos(comp);
[d1b1380]587#if DEBUG_DATAIN_1
[a420b49]588         printf("sinB = %f, cosG = %f, LcosG = %f\n", sinB, cosG, LcosG);
[d1b1380]589#endif
[a420b49]590         dx = LcosG * sinB;
591         dy = LcosG * cosB;
592         dz = tape * sin(clin);
[d1b1380]593/*      printf("%.2f\n",clin); */
594#if DEBUG_DATAIN_1
[a420b49]595         printf("dx = %f\ndy = %f\ndz = %f\n", dx, dy, dz);
[d1b1380]596#endif
[a420b49]597         dx2 = dx * dx;
598         L2 = tape * tape;
599         V = var(Q_LENGTH) / L2;
600         dy2 = dy * dy;
601         cosG2 = cosG * cosG;
[dbb4e19]602         sinGcosG = sin(clin) * cosG;
[a420b49]603         dz2 = dz * dz;
[0b71cfc]604         v = dz2 * var_clin;
[5b7c1b7]605#ifdef NO_COVARIANCES
[0b71cfc]606         vx = (var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp +
[a420b49]607               (.5 + sinB * sinB * cosG2) * v);
[0b71cfc]608         vy = (var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp +
[a420b49]609               (.5 + cosB * cosB * cosG2) * v);
[0b71cfc]610         if (ctype == CLINO_OMIT && backctype == CLINO_OMIT) {
[5b7c1b7]611            /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */
[0b71cfc]612            vz = var(Q_POS) / 3.0 + L2 * (real)0.1;
[5b7c1b7]613         } else {
[0b71cfc]614            vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin;
[5b7c1b7]615         }
[a420b49]616         /* for Surveyor87 errors: vx=vy=vz=var(Q_POS)/3.0; */
[dbb4e19]617#else
[0b71cfc]618         vx = var(Q_POS) / 3.0 + dx2 * V + dy2 * var_comp +
[dbb4e19]619            (sinB * sinB * v);
[0b71cfc]620         vy = var(Q_POS) / 3.0 + dy2 * V + dx2 * var_comp +
[dbb4e19]621            (cosB * cosB * v);
[0b71cfc]622         if (ctype == CLINO_OMIT && backctype == CLINO_OMIT) {
[5b7c1b7]623            /* if no clino, assume sd=tape/sqrt(10) so 3sds = .95*tape */
[0b71cfc]624            vz = var(Q_POS) / 3.0 + L2 * (real)0.1;
[5b7c1b7]625         } else {
[0b71cfc]626            vz = var(Q_POS) / 3.0 + dz2 * V + L2 * cosG2 * var_clin;
[5b7c1b7]627         }
[647407d]628         /* usual covariance formulae are fine in no clino case since
[0b71cfc]629          * dz = 0 so value of var_clin is ignored */
630         cxy = sinB * cosB * (var(Q_LENGTH) * cosG2 + var_clin * dz2)
631               - var_comp * dx * dy;
632         czx = var(Q_LENGTH) * sinB * sinGcosG - var_clin * dx * dz;
633         cyz = var(Q_LENGTH) * cosB * sinGcosG - var_clin * dy * dz;
[dbb4e19]634#if 0
635         printf("vx = %6.3f, vy = %6.3f, vz = %6.3f\n", vx, vy, vz);
636         printf("cxy = %6.3f, cyz = %6.3f, czx = %6.3f\n", cxy, cyz, czx);
637#endif
[4f8285d]638#endif
[d1b1380]639#if DEBUG_DATAIN_1
[a420b49]640         printf("In DATAIN.C, vx = %f, vy = %f, vz = %f\n", vx, vy, vz);
[d1b1380]641#endif
[a420b49]642      }
643   }
[d1b1380]644#if DEBUG_DATAIN_1
[a420b49]645   printf("Just before addleg, vx = %f\n", vx);
[d1b1380]646#endif
[a420b49]647   /*printf("dx,dy,dz = %.2f %.2f %.2f\n\n", dx, dy, dz);*/
[90bb053f]648   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
[4f8285d]649#ifndef NO_COVARIANCES
[2140502]650                , cyz, czx, cxy
[4f8285d]651#endif
[2140502]652                );
[647407d]653
654#ifdef NEW3DFORMAT
655   if (fUseNewFormat) {
[407084d]656      /* new twiglet and insert into twig tree */
657      twig *twiglet = osnew(twig);
[90bb053f]658      twiglet->from = fr;
659      twiglet->to = to;
[407084d]660      twiglet->down = twiglet->right = NULL;
661      twiglet->source = twiglet->drawings
662        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
663      twiglet->up = limb->up;
664      limb->right = twiglet;
665      limb = twiglet;
666
667      /* record pre-fettling deltas */
[647407d]668      twiglet->delta[0] = dx;
669      twiglet->delta[1] = dy;
670      twiglet->delta[2] = dz;
671   }
672#endif
[a420b49]673   return 1;
[d1b1380]674}
675
[5a38209]676static int
677process_diving(prefix *fr, prefix *to, real tape, real comp,
[6114207]678               real frdepth, real todepth, bool fToFirst, bool fDepthChange)
[a420b49]679{
680   real dx, dy, dz;
681   real vx, vy, vz;
[f795df0]682#ifndef NO_COVARIANCES
683   real cxy = 0, cyz = 0, czx = 0;
684#endif
[a420b49]685
[385b703]686   if (comp != HUGE_REAL) {
687      comp *= pcs->units[Q_BEARING];
[3e784b5]688      if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) {
[421b7d2]689         compile_warning(/*Suspicious compass reading*/59);
[385b703]690      }
[a420b49]691   }
692
[a6d094f]693   /* depth gauge readings increase upwards with default calibration */
[6114207]694   if (fDepthChange) {
[a6d094f]695      ASSERT(frdepth == 0.0);
[6114207]696      dz = (todepth * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]) * pcs->sc[Q_DEPTH];
[a6d094f]697   } else {
698      dz = (todepth - frdepth) * pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH];
699   }
[a420b49]700
701   /* adjusted tape is negative -- probably the calibration is wrong */
702   if (tape < (real)0.0) {
703      compile_warning(/*Negative adjusted tape reading*/79);
704   }
705
706   /* check if tape is less than depth change */
707   if (tape < fabs(dz)) {
[bd1913f]708      /* FIXME: allow margin of error based on variances? */
[a420b49]709      compile_warning(/*Tape reading is less than change in depth*/62);
710   }
711
[0a208f9]712   if (tape == (real)0.0 && dz == 0.0) {
[a420b49]713      dx = dy = dz = (real)0.0;
714      vx = vy = vz = (real)(var(Q_POS) / 3.0); /* Position error only */
[385b703]715   } else if (comp == HUGE_REAL) {
716      /* plumb */
717      dx = dy = (real)0.0;
718      if (dz < 0) tape = -tape;
719      dz = (dz * var(Q_LENGTH) + tape * 2 * var(Q_DEPTH))
[421b7d2]720         / (var(Q_LENGTH) * 2 * var(Q_DEPTH));
[385b703]721      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
722      vz = var(Q_POS) / 3.0 + var(Q_LENGTH) * 2 * var(Q_DEPTH)
[421b7d2]723                              / (var(Q_LENGTH) + var(Q_DEPTH));
[a420b49]724   } else {
[f795df0]725      real L2, sinB, cosB, dz2, D2;
[a420b49]726      comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING];
727      comp -= pcs->z[Q_DECLINATION];
728      sinB = sin(comp);
729      cosB = cos(comp);
730      L2 = tape * tape;
731      dz2 = dz * dz;
732      D2 = L2 - dz2;
733      if (D2 <= (real)0.0) {
[f795df0]734         real vsum = var(Q_LENGTH) + 2 * var(Q_DEPTH);
[a420b49]735         dx = dy = (real)0.0;
[f795df0]736         vx = vy = var(Q_POS) / 3.0;
737         vz = var(Q_POS) / 3.0 + var(Q_LENGTH) * 2 * var(Q_DEPTH) / vsum;
738         if (dz > 0) {
739            dz = (dz * var(Q_LENGTH) + tape * 2 * var(Q_DEPTH)) / vsum;
740         } else {
741            dz = (dz * var(Q_LENGTH) - tape * 2 * var(Q_DEPTH)) / vsum;
742         }
[a420b49]743      } else {
744         real D = sqrt(D2);
[f795df0]745         real F = var(Q_LENGTH) * L2 + 2 * var(Q_DEPTH) * D2;
[a420b49]746         dx = D * sinB;
747         dy = D * cosB;
[f795df0]748
749         vx = var(Q_POS) / 3.0 +
750            sinB * sinB * F / D2 + var(Q_BEARING) * dy * dy;
751         vy = var(Q_POS) / 3.0 +
752            cosB * cosB * F / D2 + var(Q_BEARING) * dx * dx;
753         vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH);
754
755#ifndef NO_COVARIANCES
756         cxy = sinB * cosB * (F / D2 + var(Q_BEARING) * D2);
757         cyz = -2 * var(Q_DEPTH) * dy / D;
758         czx = -2 * var(Q_DEPTH) * dx / D;
759#endif
[a420b49]760      }
761   }
[5a38209]762   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
[2140502]763#ifndef NO_COVARIANCES
[f795df0]764                , cxy, cyz, czx
[647407d]765#endif
[2140502]766                );
[647407d]767#ifdef NEW3DFORMAT
768   if (fUseNewFormat) {
[407084d]769      /*new twiglet and insert into twig tree*/
770      twig *twiglet = osnew(twig);
[90bb053f]771      twiglet->from = fr;
772      twiglet->to = to;
[407084d]773      twiglet->down = twiglet->right = NULL;
774      twiglet->source = twiglet->drawings
775        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
776      twiglet->up = limb->up;
777      limb->right = twiglet;
778      limb = twiglet;
779
780      /* record pre-fettling deltas */
[647407d]781      twiglet->delta[0] = dx;
782      twiglet->delta[1] = dy;
783      twiglet->delta[2] = dz;
784   }
785#endif
786
787   return 1;
788}
789
[5a38209]790static int
791process_cartesian(prefix *fr, prefix *to, real dx, real dy, real dz,
792                  bool fToFirst)
793{
[647407d]794   dx = (dx * pcs->units[Q_DX] - pcs->z[Q_DX]) * pcs->sc[Q_DX];
795   dy = (dy * pcs->units[Q_DY] - pcs->z[Q_DY]) * pcs->sc[Q_DY];
796   dz = (dz * pcs->units[Q_DZ] - pcs->z[Q_DZ]) * pcs->sc[Q_DZ];
797
[5a38209]798   addlegbyname(fr, to, fToFirst, dx, dy, dz, var(Q_DX), var(Q_DY), var(Q_DZ)
[647407d]799#ifndef NO_COVARIANCES
[c80bd34]800                , 0, 0, 0
[647407d]801#endif
[2140502]802                );
[647407d]803
804#ifdef NEW3DFORMAT
805   if (fUseNewFormat) {
[407084d]806      /* new twiglet and insert into twig tree */
807      twig *twiglet = osnew(twig);
[90bb053f]808      twiglet->from = fr;
809      twiglet->to = to;
[407084d]810      twiglet->down = twiglet->right = NULL;
811      twiglet->source = twiglet->drawings
812        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
813      twiglet->up = limb->up;
814      limb->right = twiglet;
815      limb = twiglet;
816
817      /* record pre-fettling deltas */
[647407d]818      twiglet->delta[0] = dx;
819      twiglet->delta[1] = dy;
820      twiglet->delta[2] = dz;
821   }
[4f8285d]822#endif
[647407d]823
824   return 1;
825}
826
827extern int
[5a38209]828data_cartesian(void)
[647407d]829{
[90bb053f]830   prefix *fr = NULL, *to = NULL;
[5a38209]831   real dx = 0, dy = 0, dz = 0;
832
833   bool fMulti = fFalse;
[647407d]834
[0395657]835   reading first_stn = End;
836
837   reading *ordering;
[647407d]838
[5a38209]839   again:
840
[647407d]841   for (ordering = pcs->ordering ; ; ordering++) {
842      skipblanks();
843      switch (*ordering) {
[4a6a094]844       case Fr:
[84c60fc]845          fr = read_prefix_stn(fFalse, fTrue);
[0395657]846          if (first_stn == End) first_stn = Fr;
[4a6a094]847          break;
848       case To:
[84c60fc]849          to = read_prefix_stn(fFalse, fTrue);
[0395657]850          if (first_stn == End) first_stn = To;
[4a6a094]851          break;
[5a38209]852       case Station:
853          fr = to;
[84c60fc]854          to = read_prefix_stn(fFalse, fFalse);
[5a38209]855          first_stn = To;
856          break;
857       case Dx: dx = read_numeric(fFalse); break;
858       case Dy: dy = read_numeric(fFalse); break;
859       case Dz: dz = read_numeric(fFalse); break;
[647407d]860       case Ignore:
861         skipword(); break;
[5a38209]862       case IgnoreAllAndNewLine:
863         skipline();
864         /* fall through */
865       case Newline:
866         if (fr != NULL) {
867            int r;
868            r = process_cartesian(fr, to, dx, dy, dz, first_stn == To);
869            if (!r) skipline();
870         }
871         fMulti = fTrue;
872         while (1) {
873            process_eol();
874            process_bol();
875            if (isData(ch)) break;
[ee6a621]876            if (!isComm(ch)) {
[993454b]877               push_back(ch);
[ee6a621]878               return 1;
879            }
[5a38209]880         }
881         break;
[647407d]882       case IgnoreAll:
883         skipline();
884         /* fall through */
885       case End:
[5a38209]886         if (!fMulti) {
[ee6a621]887            int r = process_cartesian(fr, to, dx, dy, dz, first_stn == To);
[5a38209]888            process_eol();
889            return r;
890         }
[eef4d8c]891         do {
[5a38209]892            process_eol();
893            process_bol();
[eef4d8c]894         } while (isComm(ch));
[5a38209]895         goto again;
[0395657]896       default: BUG("Unknown reading in ordering");
[647407d]897      }
898   }
[5a38209]899}
[cb3d1e2]900
[98a2eec]901static int
902process_cylpolar(prefix *fr, prefix *to, real tape, real comp,
[6114207]903                 real frdepth, real todepth, bool fToFirst, bool fDepthChange)
[98a2eec]904{
905   real dx, dy, dz;
906   real vx, vy, vz;
907#ifndef NO_COVARIANCES
908   real cxy = 0;
909#endif
910
911   if (comp != HUGE_REAL) {
912      comp *= pcs->units[Q_BEARING];
[3e784b5]913      if (comp < (real)0.0 || comp - M_PI * 2.0 > EPSILON) {
[421b7d2]914         compile_warning(/*Suspicious compass reading*/59);
[98a2eec]915      }
916   }
917
[a6d094f]918   /* depth gauge readings increase upwards with default calibration */
[6114207]919   if (fDepthChange) {
[a6d094f]920      ASSERT(frdepth == 0.0);
[6114207]921      dz = (todepth * pcs->units[Q_DEPTH] - pcs->z[Q_DEPTH]) * pcs->sc[Q_DEPTH];
[a6d094f]922   } else {
923      dz = (todepth - frdepth) * pcs->units[Q_DEPTH] * pcs->sc[Q_DEPTH];
924   }
[98a2eec]925
926   /* adjusted tape is negative -- probably the calibration is wrong */
927   if (tape < (real)0.0) {
928      compile_warning(/*Negative adjusted tape reading*/79);
929   }
930
931   if (comp == HUGE_REAL) {
932      /* plumb */
933      dx = dy = (real)0.0;
934      vx = vy = var(Q_POS) / 3.0 + dz * dz * var(Q_PLUMB);
935      vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH);
936   } else {
937      real sinB, cosB;
938      comp = (comp - pcs->z[Q_BEARING]) * pcs->sc[Q_BEARING];
939      comp -= pcs->z[Q_DECLINATION];
940
941      sinB = sin(comp);
942      cosB = cos(comp);
943
944      dx = tape * sinB;
945      dy = tape * cosB;
946
947      vx = var(Q_POS) / 3.0 +
948         var(Q_LENGTH) * sinB * sinB + var(Q_BEARING) * dy * dy;
949      vy = var(Q_POS) / 3.0 +
950         var(Q_LENGTH) * cosB * cosB + var(Q_BEARING) * dx * dx;
951      vz = var(Q_POS) / 3.0 + 2 * var(Q_DEPTH);
952
953#ifndef NO_COVARIANCES
954      cxy = (var(Q_LENGTH) - var(Q_BEARING) * tape * tape) * sinB * cosB;
955#endif
956   }
957   addlegbyname(fr, to, fToFirst, dx, dy, dz, vx, vy, vz
958#ifndef NO_COVARIANCES
959                , cxy, 0, 0
960#endif
961                );
962#ifdef NEW3DFORMAT
963   if (fUseNewFormat) {
964      /*new twiglet and insert into twig tree*/
965      twig *twiglet = osnew(twig);
966      twiglet->from = fr;
967      twiglet->to = to;
968      twiglet->down = twiglet->right = NULL;
969      twiglet->source = twiglet->drawings
970        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
971      twiglet->up = limb->up;
972      limb->right = twiglet;
973      limb = twiglet;
974
975      /* record pre-fettling deltas */
976      twiglet->delta[0] = dx;
977      twiglet->delta[1] = dy;
978      twiglet->delta[2] = dz;
979   }
980#endif
981
982   return 1;
983}
984
[107b8bd]985/* Process tape/compass/clino, diving, and cylpolar styles of survey data
986 * Also handles topofil (fromcount/tocount or count) in place of tape */
[54c4612]987extern int
[107b8bd]988data_normal(void)
[54c4612]989{
990   prefix *fr = NULL, *to = NULL;
[107b8bd]991   reading first_stn = End;
[54c4612]992
[5b7c1b7]993   real tape = 0, comp = 0, backcomp = 0, frcount = 0, tocount = 0;
994   real clin, backclin;
[54c4612]995   real frdepth = 0, todepth = 0;
996
[107b8bd]997   bool fTopofil = fFalse, fMulti = fFalse;
998   bool fRev;
[5b7c1b7]999   bool ctype, backctype;
[107b8bd]1000   bool fDepthChange;
[54c4612]1001
1002   reading *ordering;
1003
1004   again:
1005
1006   fRev = fFalse;
[5b7c1b7]1007   ctype = backctype = CLINO_OMIT;
[6114207]1008   fDepthChange = fFalse;
[54c4612]1009
[107b8bd]1010   /* ordering may omit clino reading, so set up default here */
1011   /* this is also used if clino reading is the omit character */
[5b7c1b7]1012   backclin = clin = (real)0.0;
[107b8bd]1013
[54c4612]1014   for (ordering = pcs->ordering; ; ordering++) {
1015      skipblanks();
1016      switch (*ordering) {
1017       case Fr:
[107b8bd]1018          fr = read_prefix_stn(fFalse, fTrue);
1019          if (first_stn == End) first_stn = Fr;
1020          break;
[54c4612]1021       case To:
[107b8bd]1022          to = read_prefix_stn(fFalse, fTrue);
1023          if (first_stn == End) first_stn = To;
1024          break;
[54c4612]1025       case Station:
[107b8bd]1026          fr = to;
1027          to = read_prefix_stn(fFalse, fFalse);
1028          first_stn = To;
1029          break;
[54c4612]1030       case Dir:
1031          switch(toupper(ch)) {
1032           case 'F':
1033             break;
1034           case 'B':
1035             fRev = fTrue;
1036             break;
1037           default:
1038             compile_error(/*Found `%c', expecting `F' or `B'*/131, ch);
1039             skipline();
1040             process_eol();
1041             return 0;
1042          }
1043          break;
[107b8bd]1044       case Tape:
1045          tape = read_numeric(fFalse);
1046          if (tape < (real)0.0) compile_warning(/*Negative tape reading*/60);
1047          break;
1048       case Count:
1049          frcount = tocount;
1050          tocount = read_numeric(fFalse);
1051          break;
1052       case FrCount:
1053          frcount = read_numeric(fFalse);
1054          break;
1055       case ToCount:
1056          tocount = read_numeric(fFalse);
1057          fTopofil = fTrue;
1058          break;
1059       case Comp:
1060          comp = read_numeric_or_omit();
1061          break;
[5b7c1b7]1062       case BackComp:
1063          backcomp = read_numeric_or_omit();
1064          break;
[5757725]1065       case Clino:
[107b8bd]1066          clin = read_numeric(fTrue);
1067          if (clin == HUGE_REAL) {
[5b7c1b7]1068             clin = handle_plumb(&ctype);
[107b8bd]1069             if (clin != HUGE_REAL) break;
1070             compile_error_token(/*Expecting numeric field, found `%s'*/9);
1071             process_eol();
1072             return 0;
1073          }
[5b7c1b7]1074          ctype = CLINO_READING;
1075          break;
1076       case BackClino:
1077          backclin = read_numeric(fTrue);
1078          if (backclin == HUGE_REAL) {
1079             /* FIXME: how should special readings for Clino and BackClino
1080              * interact? */
1081             backclin = handle_plumb(&backctype);
1082             if (backclin != HUGE_REAL) break;
1083             compile_error_token(/*Expecting numeric field, found `%s'*/9);
1084             process_eol();
1085             return 0;
1086          }
1087          backctype = CLINO_READING;
[107b8bd]1088          break;
1089       case FrDepth:
1090          frdepth = read_numeric(fFalse);
1091          break;
1092       case ToDepth:
1093          todepth = read_numeric(fFalse);
1094          break;
[54c4612]1095       case Depth:
1096          frdepth = todepth;
1097          todepth = read_numeric(fFalse);
1098          break;
[6114207]1099       case DepthChange:
1100          fDepthChange = fTrue;
[a186573]1101          frdepth = 0;
1102          todepth = read_numeric(fFalse);
1103          break;
[107b8bd]1104       case Ignore:
1105          skipword();
1106          break;
[54c4612]1107       case IgnoreAllAndNewLine:
[107b8bd]1108          skipline();
1109          /* fall through */
[54c4612]1110       case Newline:
[107b8bd]1111          if (fr != NULL) {
1112             int r;
1113             if (fRev) {
1114                prefix *t = fr;
1115                fr = to;
1116                to = t;
1117             }
1118             if (fTopofil) tape = tocount - frcount;
1119             /* Note: frdepth == todepth test works regardless of fDepthChange
1120              * (frdepth always zero, todepth is change of depth) and also
1121              * works for STYLE_NORMAL (both remain 0) */
1122             if (pcs->f0Eq && tape == (real)0.0 && frdepth == todepth) {
1123                process_equate(fr, to);
1124                goto inferred_equate;
1125             }
1126             if (fTopofil) {
1127                tape *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT];
1128             } else {
1129                tape *= pcs->units[Q_LENGTH];
1130                tape = (tape - pcs->z[Q_LENGTH]) * pcs->sc[Q_LENGTH];
1131             }
1132             switch (pcs->style) {
1133              case STYLE_NORMAL:
1134                r = process_normal(fr, to, tape, comp, clin,
[0b71cfc]1135                                   backcomp, backclin,
[5b7c1b7]1136                                   (first_stn == To) ^ fRev, ctype, backctype);
[107b8bd]1137                break;
1138              case STYLE_DIVING:
1139                r = process_diving(fr, to, tape, comp, frdepth, todepth,
1140                                   (first_stn == To) ^ fRev, fDepthChange);
1141                break;
1142              case STYLE_CYLPOLAR:
1143                r = process_cylpolar(fr, to, tape, comp, frdepth, todepth,
1144                                     (first_stn == To) ^ fRev, fDepthChange);
1145                break;
1146              default:
1147                BUG("bad style");
1148             }
1149             if (!r) skipline();
1150          }
1151          inferred_equate:
1152          fMulti = fTrue;
1153          while (1) {
1154              process_eol();
1155              process_bol();
1156              if (isData(ch)) break;
1157              if (!isComm(ch)) {
1158                 push_back(ch);
1159                 return 1;
1160              }
1161          }
1162          break;
[54c4612]1163       case IgnoreAll:
[107b8bd]1164          skipline();
1165          /* fall through */
[54c4612]1166       case End:
[107b8bd]1167          if (!fMulti) {
1168             int r;
1169             if (fRev) {
1170                prefix *t = fr;
1171                fr = to;
1172                to = t;
1173             }
1174             if (fTopofil) tape = tocount - frcount;
1175             /* Note: frdepth == todepth test works regardless of fDepthChange
1176              * (frdepth always zero, todepth is change of depth) and also
1177              * works for STYLE_NORMAL (both remain 0) */
1178             if (pcs->f0Eq && tape == (real)0.0 && frdepth == todepth) {
1179                process_equate(fr, to);
1180                process_eol();
1181                return 1;
1182             }
1183             if (fTopofil) {
1184                tape *= pcs->units[Q_COUNT] * pcs->sc[Q_COUNT];
1185             } else {
1186                tape *= pcs->units[Q_LENGTH];
1187                tape = (tape - pcs->z[Q_LENGTH]) * pcs->sc[Q_LENGTH];
1188             }
1189             switch (pcs->style) {
1190              case STYLE_NORMAL:
1191                r = process_normal(fr, to, tape, comp, clin,
[0b71cfc]1192                                   backcomp, backclin,
[5b7c1b7]1193                                   (first_stn == To) ^ fRev, ctype, backctype);
[107b8bd]1194                break;
1195              case STYLE_DIVING:
1196                r = process_diving(fr, to, tape, comp, frdepth, todepth,
1197                                   (first_stn == To) ^ fRev, fDepthChange);
1198                break;
1199              case STYLE_CYLPOLAR:
1200                r = process_cylpolar(fr, to, tape, comp, frdepth, todepth,
1201                                     (first_stn == To) ^ fRev, fDepthChange);
1202                break;
1203              default:
1204                BUG("bad style");
1205             }
1206             process_eol();
1207             return r;
1208          }
1209          do {
1210             process_eol();
1211             process_bol();
1212          } while (isComm(ch));
1213          goto again;
1214       default:
1215          BUG("Unknown reading in ordering");
[54c4612]1216      }
1217   }
1218}
1219
[5a38209]1220static int
1221process_nosurvey(prefix *fr, prefix *to, bool fToFirst)
1222{
1223   nosurveylink *link;
[838a602a]1224   int shape;
[647407d]1225
1226#ifdef NEW3DFORMAT
1227   if (fUseNewFormat) {
[407084d]1228      /* new twiglet and insert into twig tree */
1229      twig *twiglet = osnew(twig);
[90bb053f]1230      twiglet->from = fr;
1231      twiglet->to = to;
[647407d]1232      twiglet->down = twiglet->right = NULL;
1233      twiglet->source = twiglet->drawings
1234        = twiglet->date = twiglet->instruments = twiglet->tape = NULL;
1235      twiglet->up = limb->up;
1236      limb->right = twiglet;
1237      limb = twiglet;
[3bcbcb2]1238      /* delta is only used to calculate error - pass zero and cope
1239       * elsewhere */
[647407d]1240      twiglet->delta[0] = twiglet->delta[1] = twiglet->delta[2] = 0;
1241   }
1242#endif
1243
[838a602a]1244   /* Suppress "unused fixed point" warnings for these stations
1245    * We do this if it's a 0 or 1 node - 1 node might be an sdfix
1246    */
1247   shape = fr->shape;
1248   if (shape == 0 || shape == 1) fr->shape = -1 - shape;
1249   shape = to->shape;
1250   if (shape == 0 || shape == 1) to->shape = -1 - shape;
1251
[647407d]1252   /* add to linked list which is dealt with after network is solved */
1253   link = osnew(nosurveylink);
[5a38209]1254   if (fToFirst) {
[90bb053f]1255      link->to = StnFromPfx(to);
1256      link->fr = StnFromPfx(fr);
[0395657]1257   } else {
[90bb053f]1258      link->fr = StnFromPfx(fr);
1259      link->to = StnFromPfx(to);
[0395657]1260   }
[b3bef47]1261   link->flags = pcs->flags;
[647407d]1262   link->next = nosurveyhead;
1263   nosurveyhead = link;
[a420b49]1264   return 1;
[d1b1380]1265}
[50f6901]1266
[5a38209]1267extern int
1268data_nosurvey(void)
1269{
1270   prefix *fr = NULL, *to = NULL;
1271
1272   bool fMulti = fFalse;
1273
1274   reading first_stn = End;
1275
1276   reading *ordering;
1277
1278   again:
1279
1280   for (ordering = pcs->ordering ; ; ordering++) {
1281      skipblanks();
1282      switch (*ordering) {
1283       case Fr:
[84c60fc]1284          fr = read_prefix_stn(fFalse, fTrue);
[5a38209]1285          if (first_stn == End) first_stn = Fr;
1286          break;
1287       case To:
[84c60fc]1288          to = read_prefix_stn(fFalse, fTrue);
[5a38209]1289          if (first_stn == End) first_stn = To;
1290          break;
1291       case Station:
1292          fr = to;
[84c60fc]1293          to = read_prefix_stn(fFalse, fFalse);
[5a38209]1294          first_stn = To;
1295          break;
1296       case Ignore:
1297         skipword(); break;
1298       case IgnoreAllAndNewLine:
1299         skipline();
1300         /* fall through */
1301       case Newline:
1302         if (fr != NULL) {
1303            int r;
1304            r = process_nosurvey(fr, to, first_stn == To);
1305            if (!r) skipline();
1306         }
[838a602a]1307         if (ordering[1] == End) {
1308            do {
1309               process_eol();
1310               process_bol();
1311            } while (isComm(ch));
[ee6a621]1312            if (!isData(ch)) {
[993454b]1313               push_back(ch);
[ee6a621]1314               return 1;
1315            }
[838a602a]1316            goto again;
1317         }
[5a38209]1318         fMulti = fTrue;
1319         while (1) {
1320            process_eol();
1321            process_bol();
1322            if (isData(ch)) break;
[ee6a621]1323            if (!isComm(ch)) {
[993454b]1324               push_back(ch);
[ee6a621]1325               return 1;
1326            }
[5a38209]1327         }
1328         break;
1329       case IgnoreAll:
1330         skipline();
1331         /* fall through */
1332       case End:
1333         if (!fMulti) {
[ee6a621]1334            int r = process_nosurvey(fr, to, first_stn == To);
[5a38209]1335            process_eol();
1336            return r;
1337         }
[eef4d8c]1338         do {
[5a38209]1339            process_eol();
1340            process_bol();
[eef4d8c]1341         } while (isComm(ch));
[5a38209]1342         goto again;
1343       default: BUG("Unknown reading in ordering");
1344      }
1345   }
1346}
1347
[50f6901]1348/* totally ignore a line of survey data */
1349extern int
1350data_ignore(void)
1351{
1352   skipline();
[ee6a621]1353   process_eol();
[570f4bf]1354   return 1;
[50f6901]1355}
Note: See TracBrowser for help on using the repository browser.