source: git/src/cavern.c @ b15eeda

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 b15eeda was cb3d1e2, checked in by Olly Betts <olly@…>, 24 years ago

Trimmed trailing whitespace from source files; updates BUGS, NEWS, TODO;
Added manifest constants for all leg flags.

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

  • Property mode set to 100644
File size: 10.1 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#if (OS==RISCOS)
253         strcpy(startingdir, "@");
254#else
255         getcwd(startingdir, MAXPATHLEN);
256#endif
257      }
258#endif
259      data_file("", fnm); /* first argument is current path */
260
261      optind++;
262   }
263
264   validate();
265
266   solve_network(/*stnlist*/); /* Find coordinates of all points */
267   validate();
268
269#ifdef NEW3DFORMAT
270   if (fUseNewFormat) {
271     cave_close(pimgOut); /* this actually does all the writing */
272   } else {
273#endif
274     img_close(pimgOut); /* close .3d file */
275#ifdef NEW3DFORMAT
276   }
277#endif
278   if (fhErrStat) fclose(fhErrStat);
279
280   if (!fSuppress) list_pos(root); /* produce .pos file */
281
282   out_current_action(msg(/*Calculating statistics*/120));
283   do_stats();
284   if (!fQuiet) {
285      tmCPU = (clock_t)(clock() - tmCPUStart) / (double)CLOCKS_PER_SEC;
286      tmUser = difftime(time(NULL), tmUserStart);
287
288      /* tmCPU is integer, tmUser not - equivalent to (ceil(tmCPU) >= tmUser) */
289      if (tmCPU + 1 > tmUser) {
290         out_printf((msg(/*CPU time used %5.2fs*/140), tmCPU));
291      } else if (tmCPU == 0) {
292         if (tmUser == 0.0) {
293            out_printf((msg(/*Time used %5.2fs*/141), tmUser));
294         } else {
295            out_puts(msg(/*Time used unavailable*/142));
296         }
297      } else {
298         out_printf((msg(/*Time used %5.2fs (%5.2fs CPU time)*/143),
299                    tmUser, tmCPU));
300      }
301
302      out_puts(msg(/*Done.*/144));
303   }
304   return error_summary();
305}
306
307static void
308do_range(FILE *fh, int d, int msg1, int msg2, int msg3)
309{
310   char buf[1024];
311   sprintf(buf, msg(msg1), max[d] - min[d]);
312   strcat(buf, sprint_prefix(pfxHi[d]));
313   sprintf(buf + strlen(buf), msg(msg2), max[d]);
314   strcat(buf, sprint_prefix(pfxLo[d]));
315   sprintf(buf + strlen(buf), msg(msg3), min[d]);
316   if (!fMute) out_puts(buf);
317   if (!fSuppress) fputsnl(buf, fh);
318}
319
320static void
321do_stats(void)
322{
323   FILE *fh;
324   long cLoops = cComponents + cLegs - cStns;
325   char buf[1024];
326
327   if (!fSuppress)
328      fh = safe_fopen_with_ext(fnm_output_base, EXT_SVX_STAT, "w");
329
330   out_puts("");
331
332   if (cStns == 1)
333      sprintf(buf, msg(/*Survey contains 1 survey station,*/172));
334   else
335      sprintf(buf,
336              msg(/*Survey contains %ld survey stations,*/173), cStns);
337
338   if (cLegs == 1)
339      sprintf(buf + strlen(buf), msg(/* joined by 1 leg.*/174));
340   else
341      sprintf(buf + strlen(buf),
342              msg(/* joined by %ld legs.*/175), cLegs);
343
344   if (!fMute) out_puts(buf);
345   if (!fSuppress) fputsnl(buf, fh);
346
347   if (cLoops == 1)
348      sprintf(buf, msg(/*There is 1 loop.*/138));
349   else
350      sprintf(buf, msg(/*There are %ld loops.*/139), cLoops);
351
352   if (!fMute) out_puts(buf);
353   if (!fSuppress) fputsnl(buf, fh);
354
355   if (cComponents != 1) {
356      sprintf(buf,
357              msg(/*Survey has %ld connected components.*/178), cComponents);
358      if (!fMute) out_puts(buf);
359      if (!fSuppress) fputsnl(buf, fh);
360   }
361
362   sprintf(buf,
363           msg(/*Total length of survey legs = %7.2fm (%7.2fm adjusted)*/132),
364           total, totadj);
365   if (!fMute) out_puts(buf);
366   if (!fSuppress) fputsnl(buf, fh);
367
368   sprintf(buf,
369           msg(/*Total plan length of survey legs = %7.2fm*/133), totplan);
370   if (!fMute) out_puts(buf);
371   if (!fSuppress) fputsnl(buf, fh);
372
373   sprintf(buf, msg(/*Total vertical length of survey legs = %7.2fm*/134),
374           totvert);
375   if (!fMute) out_puts(buf);
376   if (!fSuppress) fputsnl(buf, fh);
377
378   do_range(fh, 2, /*Vertical range = %4.2fm (from */135,
379            /* at %4.2fm to */136, /* at %4.2fm)*/137);
380   do_range(fh, 1, /*North-South range = %4.2fm (from */148,
381            /* at %4.2fm to */196, /* at %4.2fm)*/197);
382   do_range(fh, 0, /*East-West range = %4.2fm (from */149,
383            /* at %4.2fm to */196, /* at %4.2fm)*/197);
384
385   print_node_stats(fh);
386   /* Also, could give:
387    *  # nodes stations (ie have other than two references or are fixed)
388    *  # fixed stations (list of?)
389    */
390
391   if (!fSuppress) fclose(fh);
392}
Note: See TracBrowser for help on using the repository browser.