source: git/src/cavern.c @ e4eefff

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 e4eefff was 89231c4, checked in by Olly Betts <olly@…>, 26 years ago

Updated GPL info (now has correct address for FSF)

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

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