source: git/src/cavern.c @ 069b3ac

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 069b3ac was 8e8057c, checked in by Olly Betts <olly@…>, 26 years ago

s renamed to str
added --output=

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

  • Property mode set to 100644
File size: 7.6 KB
Line 
1/* > cavern.c
2 * SURVEX Cave surveying software: data reduction main and related functions
3 * Copyright (C) 1991-1999 Olly Betts
4 */
5
6#ifdef HAVE_CONFIG_H
7#include <config.h>
8#endif
9
10#include <time.h>
11
12#include "datain.h"
13#include "debug.h"
14#include "validate.h"
15#include "cavern.h"
16#include "message.h"
17#include "filename.h"
18#include "filelist.h"
19#include "osdepend.h"
20#include "img.h"
21#include "netbits.h"
22#include "commands.h"
23#include "cmdline.h"
24#include "network.h"
25#include "listpos.h"
26#include "out.h"
27#include "str.h"
28
29/* For funcs which want to be immune from messing around with different
30 * calling conventions */
31#ifndef CDECL
32# define CDECL
33#endif
34
35/* Globals */
36node *stnlist = NULL;
37settings *pcs;
38prefix *root;
39long cLegs, cStns;
40long cComponents;
41
42FILE *fhErrStat = NULL;
43img *pimgOut = NULL;
44#ifndef NO_PERCENTAGE
45bool fPercent = fFalse;
46#endif
47bool fAscii = fFalse;
48
49real totadj, total, totplan, totvert;
50real min[3], max[3];
51prefix *pfxHi[3], *pfxLo[3];
52
53char *survey_title = NULL;
54int survey_title_len;
55
56bool fExplicitTitle = fFalse;
57
58char *fnm_output_base = NULL;
59int fnm_output_base_is_dir = 0;
60
61static void do_stats(void);
62
63static const struct option long_opts[] = {
64   /* const char *name; int has_arg (0 no_argument, 1 required_*, 2 optional_*); int *flag; int val; */
65#ifdef NO_PERCENTAGE
66   {"percentage", no_argument, 0, 0},
67   {"no-percentage", no_argument, 0, 0},
68#else
69   {"percentage", no_argument, 0, 'p'},
70   {"no-percentage", no_argument, (int*)&fPercent, 0},
71#endif
72   {"output", required_argument, 0, 'o'},
73   {"help", no_argument, 0, HLP_HELP},
74   {"version", no_argument, 0, HLP_VERSION},
75   {0, 0, 0, 0}
76};
77
78#define short_opts "pao:z:"
79
80/* TRANSLATE: FIXME extract help messages to message file */
81static struct help_msg help[] = {
82/*                              <-- */
83   {HLP_ENCODELONG(0),          "display percentage progress"},
84   {'a',                        "output ascii variant of .3d file"},
85   {HLP_ENCODELONG(2),          "set location for output files"},
86 /*{'z',                        "set optimizations for network reduction"},*/
87   {0, 0}
88};
89
90extern CDECL int
91main(int argc, char **argv)
92{
93   int d;
94   static clock_t tmCPUStart;
95   static time_t tmUserStart;
96   static double tmCPU, tmUser;
97
98   check_fp_ok(); /* check very early on */
99
100   tmUserStart = time(NULL);
101   tmCPUStart = clock();
102   init_screen();
103
104   ReadErrorFile(argv[0]);
105
106   pcs = osnew(settings);
107   pcs->next = NULL;
108   pcs->Translate = ((short*) osmalloc(ossizeof(short) * 257)) + 1;
109
110   /* Set up root of prefix hierarchy */
111   root = osnew(prefix);
112   root->up = root->right = root->down = NULL;
113   root->stn = NULL;
114   root->pos = NULL;
115   root->ident = "\\";
116
117   stnlist = NULL;
118   cLegs = cStns = cComponents = 0;
119   totadj = total = totplan = totvert = 0.0;
120
121   for (d = 0; d <= 2; d++) {
122      min[d] = REAL_BIG;
123      max[d] = -REAL_BIG;
124      pfxHi[d] = pfxLo[d] = NULL;
125   }
126
127   while (1) {
128      int opt = my_getopt_long(argc, argv, short_opts, long_opts, NULL, help, 1);
129      if (opt == EOF) break;
130      switch (opt) {
131       case 'a':
132         fAscii = fTrue;
133         break;
134       case 'p':
135#ifndef NO_PERCENTAGE
136         fPercent = 1;
137#endif
138         break;
139       case 'o': {
140         /* can be a directory (in which case use basename of leaf input)
141          * or a file (in which case just trim the extension off) */
142         if (fDirectory(optarg)) {
143            /* this is a little tricky - we need to note the path here,
144             * and then add the leaf later on (in datain.c) */
145            fnm_output_base = base_from_fnm(optarg);
146            fnm_output_base_is_dir = 1;
147         } else {
148            osfree(fnm_output_base); /* in case of multiple -o options */
149            fnm_output_base = base_from_fnm(optarg);
150         }
151         break;
152       }
153       case 'z': {
154         /* Control which network optimisations are used (development tool) */
155         static int first_opt_z = 1;
156         int ch;
157         if (first_opt_z) {
158            optimize = 0;
159            first_opt_z = 0;
160         }
161         /* Lollipops, Parallel legs, Iterate mx, Delta*, Split stnlist */
162         while ((ch = *optarg++)) if (islower(ch)) optimize |= BITA(ch);
163         break;
164       }
165      }
166   }
167
168   out_puts(PACKAGE" "VERSION);
169   out_puts(COPYRIGHT_MSG);
170   putnl();
171
172   /* end of options, now process data files */
173   while (argv[optind]) {
174      const char *fnm = argv[optind];
175
176      if (!fExplicitTitle) {
177         char *lf;
178         lf = baseleaf_from_fnm(fnm);
179         if (survey_title) s_catchar(&survey_title, &survey_title_len, ' ');
180         s_cat(&survey_title, &survey_title_len, lf);
181         osfree(lf);
182      }
183
184      /* Select defaults settings */
185      default_all(pcs);
186
187      data_file("", fnm); /* first argument is current path */
188     
189      optind++;
190   }
191   
192   validate();
193
194   solve_network(/*stnlist*/); /* Find coordinates of all points */
195   validate();
196#ifdef NEW3DFORMAT
197   cave_close(pimgOut); /* close .3d file */
198#else
199   img_close(pimgOut); /* close .3d file */
200#endif
201   fclose(fhErrStat);
202
203   list_pos(root); /* produce .pos file */
204
205   out_current_action(msg(/*Calculating statistics*/120));
206   do_stats();
207
208   tmCPU = (clock_t)(clock() - tmCPUStart) / (double)CLOCKS_PER_SEC;
209   tmUser = difftime(time(NULL), tmUserStart);
210
211   /* tmCPU is integer, tmUser not - equivalent to (ceil(tmCPU) >= tmUser) */
212   if (tmCPU + 1 > tmUser) {
213      out_printf((msg(/*CPU time used %5.2fs*/140), tmCPU));
214   } else if (tmCPU == 0) {
215      if (tmUser == 0.0) {
216         out_printf((msg(/*Time used %5.2fs*/141), tmUser));
217      } else {
218         out_puts(msg(/*Time used unavailable*/142));
219      }
220   } else {
221      out_printf((msg(/*Time used %5.2fs (%5.2fs CPU time)*/143),
222                  tmUser, tmCPU));
223   }
224
225   out_puts(msg(/*Done.*/144));
226   return error_summary();
227}
228
229static void
230do_range(FILE *fh, int d, int msg1, int msg2, int msg3)
231{
232   char buf [1024];
233   sprintf(buf, msg(msg1), max[d] - min[d]);
234   strcat(buf, sprint_prefix(pfxHi[d]));
235   sprintf(buf + strlen(buf), msg(msg2), max[d]);
236   strcat(buf, sprint_prefix(pfxLo[d]));
237   sprintf(buf + strlen(buf), msg(msg3), min[d]);
238   out_puts(buf);
239   fputsnl(buf, fh);
240}
241
242static void
243do_stats(void)
244{
245   FILE *fh;
246   long cLoops = cComponents + cLegs - cStns;
247   char buf[1024];
248
249   fh = safe_fopen_with_ext(fnm_output_base, EXT_SVX_STAT, "w");
250
251   out_puts("");
252
253   if (cStns == 1)
254      sprintf(buf, msg(/*Survey contains 1 survey station,*/172));
255   else
256      sprintf(buf,
257              msg(/*Survey contains %ld survey stations,*/173), cStns);
258
259   if (cLegs == 1)
260      sprintf(buf + strlen(buf), msg(/* joined by 1 leg.*/174));
261   else
262      sprintf(buf + strlen(buf),
263              msg(/* joined by %ld legs.*/175), cLegs);
264
265   out_puts(buf);
266   fputsnl(buf, fh);
267
268   if (cLoops == 1)
269      sprintf(buf, msg(/*There is 1 loop.*/138));
270   else
271      sprintf(buf, msg(/*There are %ld loops.*/139), cLoops);
272
273   out_puts(buf);
274   fputsnl(buf, fh);
275
276   if (cComponents != 1) {
277      sprintf(buf,
278              msg(/*Survey has %ld connected components.*/178), cComponents);
279      out_puts(buf);
280      fputsnl(buf, fh);
281   }
282
283   sprintf(buf,
284           msg(/*Total length of survey legs = %7.2fm (%7.2fm adjusted)*/132),
285           total, totadj);
286   out_puts(buf);
287   fputsnl(buf, fh);
288
289   sprintf(buf,
290           msg(/*Total plan length of survey legs = %7.2fm*/133), totplan);
291   out_puts(buf);
292   fputsnl(buf, fh);
293
294   sprintf(buf, msg(/*Total vertical length of survey legs = %7.2fm*/134),
295           totvert);
296   out_puts(buf);
297   fputsnl(buf, fh);
298
299   do_range(fh, 2, /*Vertical range = %4.2fm (from */135,
300            /* at %4.2fm to */136, /* at %4.2fm)*/137);
301   do_range(fh, 1, /*North-South range = %4.2fm (from */148,
302            /* at %4.2fm to */196, /* at %4.2fm)*/197);
303   do_range(fh, 0, /*East-West range = %4.2fm (from */149,
304            /* at %4.2fm to */196, /* at %4.2fm)*/197);
305
306   print_node_stats(fh);
307   /* Also, could give:
308    *  # nodes stations (ie have other than two references or are fixed)
309    *  # fixed stations (list of?)
310    */
311
312   fclose(fh);
313}
Note: See TracBrowser for help on using the repository browser.