source: git/src/cavern.c @ 0087185

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

Fixed all the compiler warnings.

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