source: git/src/cavern.c @ 9163cb5

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 9163cb5 was 647407d, checked in by Olly Betts <olly@…>, 25 years ago

Lots of fixes from CUCC 2000 Expo:

  • cavern: *fix with error values (one for same all round, two for horizontal and vertical, three for x, y, z)
  • Fixed RISC OS not treating "foo." as a directory
  • Improved behaviour when sgmltools not installed
  • cavern: Merged patches for generating .3dx files for chasm
  • Miscellaneous code tidying
  • Moved unresolvable issues from BUGS to ZOMBIES
  • cavern: Fixed articulation code bug (handling of some cases of components with multiple fixed points); added regression test
  • cavern: "*begin" / "*end foo" now gives more explicit error
  • cavern: More work on gross error detection
  • xcaverot: you can now set environmental variables XCAVEROT_FONTNAME, XCAVEROT_INDICATOR_RADIUS
  • extend: now starts from highest station with only one leg. If no such station exists then revert to the previous behaviour of starting from the highest station (but complain if we have no legs at all).
  • cavern: line numbers now correct for .svx files with Mac style lineends
  • cavern: improved error reporting in several cases
  • caverot: on RISC OS now fall back to using 2 or even just one screen bank if we can't find a mode where we can create 3 banks [FIXME: need to test this works]
  • cavern: added data styles "TOPOFIL" (like tape/compass/clino but with a counter instead of the tape), "CARTESIAN" (dx, dy, dz), and "NOSURVEY" (for unsurveyed connections between surveys)
  • cavern: can now suppress "unused fixed point" error on a station by station basis by using: "*fix <station> reference <coords>"
  • cavern: new command "*require <version>" to allow survey data to specify the minimum survex version required to process it
  • print*: now search multiple print.ini files so you can override settings in the shipped file rather than having to modify it. Search order is: ~/.survex/print.ini (unix only), $SURVEXHOME/myprint.ini, $SURVEXHOME/print.ini
  • Changed xcaverot rotation/zoom to be the same way round as caverot
  • diffpos, extend, xcaverot, caverot: Now use cmdline library to parse command line arguments and so support --help, --version, etc.
  • hto2svx, svx2hto, and survex wrapper now all support --help and --version
  • `configure --disable-aven' now disables building of aven
  • caverot: on RISC OS fall back to using 2 or just 1 screen bank if there's not enough video memory allocated for 3.
  • Documentation brought more up to date.
  • If a station is only referenced once, and that reference is in a *equate and with an explicit prefix (e.g. "*equate 1 possibletypo.6"), a warning is issued.
  • configure now autoprobes compiler for 16 and 32 bit types so osdepend.h no longer needs to list them for each platform.
  • Removed pointless check for floating point support - it was only implemented for RISC OS and without FP the program falls over during initialisation and never gets to the check.
  • Rearranged caverot sources to make use of cvrotimg from other programs cleaner.
  • Minor enhancements to cmdline library.
  • Strings read by get_token now reported with original case in error messages.
  • Handle LANG=C (Mandrake Linux) and LANG=en_US (RedHat? 6.1).

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

  • Property mode set to 100644
File size: 10.0 KB
Line 
1/* > cavern.c
2 * SURVEX Cave surveying software: data reduction main and related functions
3 * Copyright (C) 1991-2000 Olly Betts
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24#include <time.h>
25
26#include "cavern.h"
27#include "cmdline.h"
28#include "commands.h"
29#include "datain.h"
30#include "debug.h"
31#include "message.h"
32#include "filename.h"
33#include "filelist.h"
34#include "img.h"
35#include "listpos.h"
36#include "netbits.h"
37#include "netskel.h"
38#include "osdepend.h"
39#include "out.h"
40#include "str.h"
41#include "validate.h"
42
43#ifdef NEW3DFORMAT
44#include "new3dout.h"
45#ifndef MAXPATHLEN
46#define MAXPATHLEN 1024
47#endif
48#endif
49
50/* For funcs which want to be immune from messing around with different
51 * calling conventions */
52#ifndef CDECL
53# define CDECL
54#endif
55
56/* Globals */
57node *stnlist = NULL;
58settings *pcs;
59prefix *root;
60long cLegs, cStns;
61long cComponents;
62
63FILE *fhErrStat = NULL;
64img *pimgOut = NULL;
65#ifndef NO_PERCENTAGE
66bool fPercent = fFalse;
67#endif
68bool fAscii = fFalse;
69bool fQuiet = fFalse; /* just show brief summary + errors */
70bool fMute = fFalse; /* just show errors */
71bool fSuppress = fFalse; /* only output 3d(3dx) file */
72
73nosurveylink *nosurveyhead;
74
75real totadj, total, totplan, totvert;
76real min[3], max[3];
77prefix *pfxHi[3], *pfxLo[3];
78
79char *survey_title = NULL;
80int survey_title_len;
81
82bool fExplicitTitle = fFalse;
83
84char *fnm_output_base = NULL;
85int fnm_output_base_is_dir = 0;
86
87static void do_stats(void);
88
89static const struct option long_opts[] = {
90   /* const char *name; int has_arg (0 no_argument, 1 required_*, 2 optional_*); int *flag; int val; */
91#ifdef NO_PERCENTAGE
92   {"percentage", no_argument, 0, 0},
93   {"no-percentage", no_argument, 0, 0},
94#else
95   {"percentage", no_argument, 0, 'p'},
96   {"no-percentage", no_argument, (int*)&fPercent, 0},
97#endif
98   {"output", required_argument, 0, 'o'},
99   {"quiet", no_argument, 0, 'q'},
100   {"no-auxiliary-files", no_argument, 0, 's'},
101#ifdef NEW3DFORMAT
102   {"new-format", no_argument, 0, 'x'},
103#endif
104   {"help", no_argument, 0, HLP_HELP},
105   {"version", no_argument, 0, HLP_VERSION},
106   {0, 0, 0, 0}
107};
108
109#ifdef NEW3DFORMAT
110#define short_opts "pxao:qsz:"
111#else
112#define short_opts "pao:qsz:"
113#endif
114
115/* TRANSLATE extract help messages to message file */
116static struct help_msg help[] = {
117/*                              <-- */
118   {HLP_ENCODELONG(0),          "display percentage progress"},
119   {'a',                        "output ascii variant of .3d file"},
120   {HLP_ENCODELONG(2),          "set location for output files"},
121   {HLP_ENCODELONG(3),          "only show brief summary (-qq for errors only)"},
122   {HLP_ENCODELONG(4),          "do not create .pos, .inf, or .err files"},
123#ifdef NEW3DFORMAT
124   {HLP_ENCODELONG(5),          "output data in 3dx format"},
125#endif
126 /*{'z',                        "set optimizations for network reduction"},*/
127   {0, 0}
128};
129
130extern CDECL int
131main(int argc, char **argv)
132{
133   int d;
134   static clock_t tmCPUStart;
135   static time_t tmUserStart;
136   static double tmCPU, tmUser;
137
138   tmUserStart = time(NULL);
139   tmCPUStart = clock();
140   init_screen();
141
142   msg_init(argv[0]);
143
144   pcs = osnew(settings);
145   pcs->next = NULL;
146   pcs->Translate = ((short*) osmalloc(ossizeof(short) * 257)) + 1;
147
148   /* Set up root of prefix hierarchy */
149   root = osnew(prefix);
150   root->up = root->right = root->down = NULL;
151   root->stn = NULL;
152   root->pos = NULL;
153   root->ident = "\\";
154   root->fSuspectTypo = fFalse;
155
156   nosurveyhead = NULL;
157
158   stnlist = NULL;
159   cLegs = cStns = cComponents = 0;
160   totadj = total = totplan = totvert = 0.0;
161
162   for (d = 0; d <= 2; d++) {
163      min[d] = REAL_BIG;
164      max[d] = -REAL_BIG;
165      pfxHi[d] = pfxLo[d] = NULL;
166   }
167
168   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 1, -1);
169   while (1) {
170      /* at least one argument must be given */
171      int opt = cmdline_getopt();
172      if (opt == EOF) break;
173      switch (opt) {
174       case 'a':
175         fAscii = fTrue;
176         break;
177       case 'p':
178#ifndef NO_PERCENTAGE
179         fPercent = 1;
180#endif
181         break;
182       case 'o': {
183         /* can be a directory (in which case use basename of leaf input)
184          * or a file (in which case just trim the extension off) */
185         if (fDirectory(optarg)) {
186            /* this is a little tricky - we need to note the path here,
187             * and then add the leaf later on (in datain.c) */
188            fnm_output_base = base_from_fnm(optarg);
189            fnm_output_base_is_dir = 1;
190         } else {
191            osfree(fnm_output_base); /* in case of multiple -o options */
192            fnm_output_base = base_from_fnm(optarg);
193         }
194         break;
195       }
196#ifdef NEW3DFORMAT
197       case 'x': {
198         fUseNewFormat = 1;
199         break;
200       }
201#endif
202       case 'q':
203         if (fQuiet) fMute = 1;
204         fQuiet = 1;
205         break;
206       case 's':
207         fSuppress = 1;
208         break;
209       case 'z': {
210         /* Control which network optimisations are used (development tool) */
211         static int first_opt_z = 1;
212         char ch;
213         if (first_opt_z) {
214            optimize = 0;
215            first_opt_z = 0;
216         }
217         /* Lollipops, Parallel legs, Iterate mx, Delta* */
218         while ((ch = *optarg++) != '\0')
219             if (islower(ch)) optimize |= BITA(ch);
220         break;
221       }
222      }
223   }
224
225   out_puts(PACKAGE" "VERSION);
226   out_puts(COPYRIGHT_MSG);
227   putnl();
228
229   /* end of options, now process data files */
230   while (argv[optind]) {
231      const char *fnm = argv[optind];
232
233      if (!fExplicitTitle) {
234         char *lf;
235         lf = baseleaf_from_fnm(fnm);
236         if (survey_title) s_catchar(&survey_title, &survey_title_len, ' ');
237         s_cat(&survey_title, &survey_title_len, lf);
238         osfree(lf);
239      }
240
241      /* Select defaults settings */
242      default_all(pcs);
243#ifdef NEW3DFORMAT
244      /* we need to get the filename of the first one for our base_source */
245      /* and also run_file */
246      if (fUseNewFormat) {
247         create_twig(root, fnm);
248         rhizome = root->twig_link;
249         limb = get_twig(root);
250         firstfilename = osstrdup(fnm);
251         startingdir = osmalloc(MAXPATHLEN);
252         getcwd(startingdir, MAXPATHLEN);
253      }
254#endif
255      data_file("", fnm); /* first argument is current path */
256     
257      optind++;
258   }
259   
260   validate();
261
262   solve_network(/*stnlist*/); /* Find coordinates of all points */
263   validate();
264
265#ifdef NEW3DFORMAT
266   if (fUseNewFormat) {
267     cave_close(pimgOut); /* this actually does all the writing */
268   } else {
269#endif
270     img_close(pimgOut); /* close .3d file */
271#ifdef NEW3DFORMAT
272   }
273#endif
274   if (fhErrStat) fclose(fhErrStat);
275
276   if (!fSuppress) list_pos(root); /* produce .pos file */
277
278   out_current_action(msg(/*Calculating statistics*/120));
279   do_stats();
280   if (!fQuiet) {
281      tmCPU = (clock_t)(clock() - tmCPUStart) / (double)CLOCKS_PER_SEC;
282      tmUser = difftime(time(NULL), tmUserStart);
283
284      /* tmCPU is integer, tmUser not - equivalent to (ceil(tmCPU) >= tmUser) */
285      if (tmCPU + 1 > tmUser) {
286         out_printf((msg(/*CPU time used %5.2fs*/140), tmCPU));
287      } else if (tmCPU == 0) {
288         if (tmUser == 0.0) {
289            out_printf((msg(/*Time used %5.2fs*/141), tmUser));
290         } else {
291            out_puts(msg(/*Time used unavailable*/142));
292         }
293      } else {
294         out_printf((msg(/*Time used %5.2fs (%5.2fs CPU time)*/143),
295                    tmUser, tmCPU));
296      }
297
298      out_puts(msg(/*Done.*/144));
299   }
300   return error_summary();
301}
302
303static void
304do_range(FILE *fh, int d, int msg1, int msg2, int msg3)
305{
306   char buf[1024];
307   sprintf(buf, msg(msg1), max[d] - min[d]);
308   strcat(buf, sprint_prefix(pfxHi[d]));
309   sprintf(buf + strlen(buf), msg(msg2), max[d]);
310   strcat(buf, sprint_prefix(pfxLo[d]));
311   sprintf(buf + strlen(buf), msg(msg3), min[d]);
312   if (!fMute) out_puts(buf);
313   if (!fSuppress) fputsnl(buf, fh);
314}
315
316static void
317do_stats(void)
318{
319   FILE *fh;
320   long cLoops = cComponents + cLegs - cStns;
321   char buf[1024];
322
323   if (!fSuppress)
324      fh = safe_fopen_with_ext(fnm_output_base, EXT_SVX_STAT, "w");
325
326   out_puts("");
327
328   if (cStns == 1)
329      sprintf(buf, msg(/*Survey contains 1 survey station,*/172));
330   else
331      sprintf(buf,
332              msg(/*Survey contains %ld survey stations,*/173), cStns);
333
334   if (cLegs == 1)
335      sprintf(buf + strlen(buf), msg(/* joined by 1 leg.*/174));
336   else
337      sprintf(buf + strlen(buf),
338              msg(/* joined by %ld legs.*/175), cLegs);
339
340   if (!fMute) out_puts(buf);
341   if (!fSuppress) fputsnl(buf, fh);
342
343   if (cLoops == 1)
344      sprintf(buf, msg(/*There is 1 loop.*/138));
345   else
346      sprintf(buf, msg(/*There are %ld loops.*/139), cLoops);
347
348   if (!fMute) out_puts(buf);
349   if (!fSuppress) fputsnl(buf, fh);
350
351   if (cComponents != 1) {
352      sprintf(buf,
353              msg(/*Survey has %ld connected components.*/178), cComponents);
354      if (!fMute) out_puts(buf);
355      if (!fSuppress) fputsnl(buf, fh);
356   }
357
358   sprintf(buf,
359           msg(/*Total length of survey legs = %7.2fm (%7.2fm adjusted)*/132),
360           total, totadj);
361   if (!fMute) out_puts(buf);
362   if (!fSuppress) fputsnl(buf, fh);
363
364   sprintf(buf,
365           msg(/*Total plan length of survey legs = %7.2fm*/133), totplan);
366   if (!fMute) out_puts(buf);
367   if (!fSuppress) fputsnl(buf, fh);
368
369   sprintf(buf, msg(/*Total vertical length of survey legs = %7.2fm*/134),
370           totvert);
371   if (!fMute) out_puts(buf);
372   if (!fSuppress) fputsnl(buf, fh);
373
374   do_range(fh, 2, /*Vertical range = %4.2fm (from */135,
375            /* at %4.2fm to */136, /* at %4.2fm)*/137);
376   do_range(fh, 1, /*North-South range = %4.2fm (from */148,
377            /* at %4.2fm to */196, /* at %4.2fm)*/197);
378   do_range(fh, 0, /*East-West range = %4.2fm (from */149,
379            /* at %4.2fm to */196, /* at %4.2fm)*/197);
380
381   print_node_stats(fh);
382   /* Also, could give:
383    *  # nodes stations (ie have other than two references or are fixed)
384    *  # fixed stations (list of?)
385    */
386
387   if (!fSuppress) fclose(fh);
388}
Note: See TracBrowser for help on using the repository browser.