source: git/src/cavern.c @ d5d89f8

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

*export now works how we want.

git-svn-id: file:///home/survex-svn/survex/trunk@586 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-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;
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->min_export = root->max_export = 0;
155   root->fSuspectTypo = fFalse;
156
157   nosurveyhead = NULL;
158
159   stnlist = NULL;
160   cLegs = cStns = cComponents = 0;
161   totadj = total = totplan = totvert = 0.0;
162
163   for (d = 0; d <= 2; d++) {
164      min[d] = REAL_BIG;
165      max[d] = -REAL_BIG;
166      pfxHi[d] = pfxLo[d] = NULL;
167   }
168
169   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 1, -1);
170   while (1) {
171      /* at least one argument must be given */
172      int opt = cmdline_getopt();
173      if (opt == EOF) break;
174      switch (opt) {
175       case 'a':
176         fAscii = fTrue;
177         break;
178       case 'p':
179#ifndef NO_PERCENTAGE
180         fPercent = 1;
181#endif
182         break;
183       case 'o': {
184         /* can be a directory (in which case use basename of leaf input)
185          * or a file (in which case just trim the extension off) */
186         if (fDirectory(optarg)) {
187            /* this is a little tricky - we need to note the path here,
188             * and then add the leaf later on (in datain.c) */
189            fnm_output_base = base_from_fnm(optarg);
190            fnm_output_base_is_dir = 1;
191         } else {
192            osfree(fnm_output_base); /* in case of multiple -o options */
193            fnm_output_base = base_from_fnm(optarg);
194         }
195         break;
196       }
197#ifdef NEW3DFORMAT
198       case 'x': {
199         fUseNewFormat = 1;
200         break;
201       }
202#endif
203       case 'q':
204         if (fQuiet) fMute = 1;
205         fQuiet = 1;
206         break;
207       case 's':
208         fSuppress = 1;
209         break;
210       case 'z': {
211         /* Control which network optimisations are used (development tool) */
212         static int first_opt_z = 1;
213         char ch;
214         if (first_opt_z) {
215            optimize = 0;
216            first_opt_z = 0;
217         }
218         /* Lollipops, Parallel legs, Iterate mx, Delta* */
219         while ((ch = *optarg++) != '\0')
220             if (islower(ch)) optimize |= BITA(ch);
221         break;
222       }
223      }
224   }
225
226   out_puts(PACKAGE" "VERSION);
227   out_puts(COPYRIGHT_MSG);
228   putnl();
229
230   /* end of options, now process data files */
231   while (argv[optind]) {
232      const char *fnm = argv[optind];
233
234      if (!fExplicitTitle) {
235         char *lf;
236         lf = baseleaf_from_fnm(fnm);
237         if (survey_title) s_catchar(&survey_title, &survey_title_len, ' ');
238         s_cat(&survey_title, &survey_title_len, lf);
239         osfree(lf);
240      }
241
242      /* Select defaults settings */
243      default_all(pcs);
244#ifdef NEW3DFORMAT
245      /* we need to get the filename of the first one for our base_source */
246      /* and also run_file */
247      if (fUseNewFormat) {
248         create_twig(root, fnm);
249         rhizome = root->twig_link;
250         limb = get_twig(root);
251         firstfilename = osstrdup(fnm);
252         startingdir = osmalloc(MAXPATHLEN);
253#if (OS==RISCOS)
254         strcpy(startingdir, "@");
255#else
256         getcwd(startingdir, MAXPATHLEN);
257#endif
258      }
259#endif
260      data_file("", fnm); /* first argument is current path */
261
262      optind++;
263   }
264
265   validate();
266
267   solve_network(/*stnlist*/); /* Find coordinates of all points */
268   validate();
269
270#ifdef NEW3DFORMAT
271   if (fUseNewFormat) {
272     cave_close(pimgOut); /* this actually does all the writing */
273   } else {
274#endif
275     img_close(pimgOut); /* close .3d file */
276#ifdef NEW3DFORMAT
277   }
278#endif
279   if (fhErrStat) fclose(fhErrStat);
280
281   if (!fSuppress) list_pos(root); /* produce .pos file */
282
283   out_current_action(msg(/*Calculating statistics*/120));
284   do_stats();
285   if (!fQuiet) {
286      tmCPU = (clock_t)(clock() - tmCPUStart) / (double)CLOCKS_PER_SEC;
287      tmUser = difftime(time(NULL), tmUserStart);
288
289      /* tmCPU is integer, tmUser not - equivalent to (ceil(tmCPU) >= tmUser) */
290      if (tmCPU + 1 > tmUser) {
291         out_printf((msg(/*CPU time used %5.2fs*/140), tmCPU));
292      } else if (tmCPU == 0) {
293         if (tmUser == 0.0) {
294            out_printf((msg(/*Time used %5.2fs*/141), tmUser));
295         } else {
296            out_puts(msg(/*Time used unavailable*/142));
297         }
298      } else {
299         out_printf((msg(/*Time used %5.2fs (%5.2fs CPU time)*/143),
300                    tmUser, tmCPU));
301      }
302
303      out_puts(msg(/*Done.*/144));
304   }
305   return error_summary();
306}
307
308static void
309do_range(FILE *fh, int d, int msg1, int msg2, int msg3)
310{
311   char buf[1024];
312   sprintf(buf, msg(msg1), max[d] - min[d]);
313   strcat(buf, sprint_prefix(pfxHi[d]));
314   sprintf(buf + strlen(buf), msg(msg2), max[d]);
315   strcat(buf, sprint_prefix(pfxLo[d]));
316   sprintf(buf + strlen(buf), msg(msg3), min[d]);
317   if (!fMute) out_puts(buf);
318   if (!fSuppress) fputsnl(buf, fh);
319}
320
321static void
322do_stats(void)
323{
324   FILE *fh;
325   long cLoops = cComponents + cLegs - cStns;
326   char buf[1024];
327
328   if (!fSuppress)
329      fh = safe_fopen_with_ext(fnm_output_base, EXT_SVX_STAT, "w");
330
331   out_puts("");
332
333   if (cStns == 1)
334      sprintf(buf, msg(/*Survey contains 1 survey station,*/172));
335   else
336      sprintf(buf,
337              msg(/*Survey contains %ld survey stations,*/173), cStns);
338
339   if (cLegs == 1)
340      sprintf(buf + strlen(buf), msg(/* joined by 1 leg.*/174));
341   else
342      sprintf(buf + strlen(buf),
343              msg(/* joined by %ld legs.*/175), cLegs);
344
345   if (!fMute) out_puts(buf);
346   if (!fSuppress) fputsnl(buf, fh);
347
348   if (cLoops == 1)
349      sprintf(buf, msg(/*There is 1 loop.*/138));
350   else
351      sprintf(buf, msg(/*There are %ld loops.*/139), cLoops);
352
353   if (!fMute) out_puts(buf);
354   if (!fSuppress) fputsnl(buf, fh);
355
356   if (cComponents != 1) {
357      sprintf(buf,
358              msg(/*Survey has %ld connected components.*/178), cComponents);
359      if (!fMute) out_puts(buf);
360      if (!fSuppress) fputsnl(buf, fh);
361   }
362
363   sprintf(buf,
364           msg(/*Total length of survey legs = %7.2fm (%7.2fm adjusted)*/132),
365           total, totadj);
366   if (!fMute) out_puts(buf);
367   if (!fSuppress) fputsnl(buf, fh);
368
369   sprintf(buf,
370           msg(/*Total plan length of survey legs = %7.2fm*/133), totplan);
371   if (!fMute) out_puts(buf);
372   if (!fSuppress) fputsnl(buf, fh);
373
374   sprintf(buf, msg(/*Total vertical length of survey legs = %7.2fm*/134),
375           totvert);
376   if (!fMute) out_puts(buf);
377   if (!fSuppress) fputsnl(buf, fh);
378
379   do_range(fh, 2, /*Vertical range = %4.2fm (from */135,
380            /* at %4.2fm to */136, /* at %4.2fm)*/137);
381   do_range(fh, 1, /*North-South range = %4.2fm (from */148,
382            /* at %4.2fm to */196, /* at %4.2fm)*/197);
383   do_range(fh, 0, /*East-West range = %4.2fm (from */149,
384            /* at %4.2fm to */196, /* at %4.2fm)*/197);
385
386   print_node_stats(fh);
387   /* Also, could give:
388    *  # nodes stations (ie have other than two references or are fixed)
389    *  # fixed stations (list of?)
390    */
391
392   if (!fSuppress) fclose(fh);
393}
Note: See TracBrowser for help on using the repository browser.