source: git/src/datain.c @ 72095d3

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

BackCompass? now works in DIVING and CYLPOLAR styles.

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

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