source: git/src/datain.c @ b14f44f

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

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

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

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

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

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

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