source: git/src/cavern.c @ 70d428e

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

To avoid breaking all existing datasets, only check exports if *export is
used somewhere in the dataset.

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

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