source: git/src/dump3d.c @ a7f78d4

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since a7f78d4 was a7f78d4, checked in by Olly Betts <olly@…>, 11 years ago

src/dump3d.c: Show dates for XSECT.

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/* dump3d.c */
2/* Show raw contents of .3d file in text form */
3/* Copyright (C) 2001,2002,2006,2011,2012,2013 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <math.h>
28
29#include "cmdline.h"
30#include "date.h"
31#include "debug.h"
32#include "filelist.h"
33#include "img_hosted.h"
34
35static const struct option long_opts[] = {
36   /* const char *name; int has_arg (0 no_argument, 1 required_*, 2 optional_*); int *flag; int val; */
37   {"survey", required_argument, 0, 's'},
38   {"rewind", no_argument, 0, 'r'},
39   {"show-dates", no_argument, 0, 'd'},
40   {"help", no_argument, 0, HLP_HELP},
41   {"version", no_argument, 0, HLP_VERSION},
42   {0, 0, 0, 0}
43};
44
45#define short_opts "rds:"
46
47static struct help_msg help[] = {
48/*                              <-- */
49   {HLP_ENCODELONG(0),        /*only load the sub-survey with this prefix*/199, 0},
50   {HLP_ENCODELONG(1),        /*rewind file and read it a second time*/204, 0},
51   {HLP_ENCODELONG(2),        /*show survey date information (if present)*/396, 0},
52   {0, 0, 0}
53};
54
55int
56main(int argc, char **argv)
57{
58   char *fnm;
59   img *pimg;
60   img_point pt;
61   int code;
62   const char *survey = NULL;
63   bool fRewind = fFalse;
64   bool show_dates = fFalse;
65
66   msg_init(argv);
67
68   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 1, 1);
69   while (1) {
70      int opt = cmdline_getopt();
71      if (opt == EOF) break;
72      if (opt == 's') survey = optarg;
73      if (opt == 'r') fRewind = fTrue;
74      if (opt == 'd') show_dates = fTrue;
75   }
76   fnm = argv[optind];
77
78#if 0
79   pimg = img_open_write("dump3d.3d", "dump3d", 0);
80   if (!pimg) fatalerror(img_error2msg(img_error()), "dump3d.3d");
81   img_write_item(pimg, img_MOVE, 0, NULL, 0, 0, 0);
82   img_write_item(pimg, img_LINE, 0, "161.lostworld.upstream",
83                  36920.120000, 82672.840000, 1528.820000);
84   img_write_item(pimg, img_LINE, 0, "161.keinzimmer",
85                  36918.480000, 82663.360000, 1527.670000);
86   img_write_item(pimg, img_LINE, 0, "161.lostworld.upstream",
87                  36959.760000, 82679.880000, 1537.900000);
88   img_close(pimg);
89#endif
90
91   pimg = img_open_survey(fnm, survey);
92   if (!pimg) fatalerror(img_error2msg(img_error()), fnm);
93
94   printf("TITLE \"%s\"\n", pimg->title);
95   printf("DATE \"%s\"\n", pimg->datestamp);
96   printf("VERSION %d\n", pimg->version);
97   if (pimg->is_extended_elevation)
98      printf("EXTENDED ELEVATION\n");
99   printf("--\n");
100
101   code = img_BAD;
102   do {
103      if (code == img_STOP) {
104         printf("<<< REWIND <<<\n");
105         fRewind = fFalse;
106         if (!img_rewind(pimg)) fatalerror(img_error2msg(img_error()), fnm);
107      }
108
109      do {
110         code = img_read_item(pimg, &pt);
111         switch (code) {
112          case img_MOVE:
113            printf("MOVE %.2f %.2f %.2f\n", pt.x, pt.y, pt.z);
114            break;
115          case img_LINE:
116            printf("LINE %.2f %.2f %.2f [%s]", pt.x, pt.y, pt.z, pimg->label);
117            switch (pimg->style) {
118                case img_STYLE_UNKNOWN:
119                    break;
120                case img_STYLE_NORMAL:
121                    printf(" STYLE=NORMAL");
122                    break;
123                case img_STYLE_DIVING:
124                    printf(" STYLE=DIVING");
125                    break;
126                case img_STYLE_CARTESIAN:
127                    printf(" STYLE=CARTESIAN");
128                    break;
129                case img_STYLE_CYLPOLAR:
130                    printf(" STYLE=CYLPOLAR");
131                    break;
132                case img_STYLE_NOSURVEY:
133                    printf(" STYLE=NOSURVEY");
134                    break;
135            }
136            if (pimg->flags & img_FLAG_SURFACE) printf(" SURFACE");
137            if (pimg->flags & img_FLAG_DUPLICATE) printf(" DUPLICATE");
138            if (pimg->flags & img_FLAG_SPLAY) printf(" SPLAY");
139            if (show_dates && pimg->days1 != -1) {
140                int y, m, d;
141                ymd_from_days_since_1900(pimg->days1, &y, &m, &d);
142                printf(" %04d.%02d.%02d", y, m, d);
143                if (pimg->days1 != pimg->days2) {
144                    ymd_from_days_since_1900(pimg->days2, &y, &m, &d);
145                    printf("-%04d.%02d.%02d", y, m, d);
146                }
147            }
148            printf("\n");
149            break;
150          case img_LABEL:
151            printf("NODE %.2f %.2f %.2f [%s]", pt.x, pt.y, pt.z, pimg->label);
152            if (pimg->flags & img_SFLAG_SURFACE) printf(" SURFACE");
153            if (pimg->flags & img_SFLAG_UNDERGROUND) printf(" UNDERGROUND");
154            if (pimg->flags & img_SFLAG_ENTRANCE) printf(" ENTRANCE");
155            if (pimg->flags & img_SFLAG_EXPORTED) printf(" EXPORTED");
156            if (pimg->flags & img_SFLAG_FIXED) printf(" FIXED");
157            if (pimg->flags & img_SFLAG_ANON) printf(" ANON");
158            printf("\n");
159            break;
160          case img_XSECT:
161            printf("XSECT %.2f %.2f %.2f %.2f [%s]",
162                   pimg->l, pimg->r, pimg->u, pimg->d, pimg->label);
163            if (show_dates && pimg->days1 != -1) {
164                int y, m, d;
165                ymd_from_days_since_1900(pimg->days1, &y, &m, &d);
166                printf(" %04d.%02d.%02d", y, m, d);
167                if (pimg->days1 != pimg->days2) {
168                    ymd_from_days_since_1900(pimg->days2, &y, &m, &d);
169                    printf("-%04d.%02d.%02d", y, m, d);
170                }
171            }
172            printf("\n");
173            break;
174          case img_XSECT_END:
175            printf("XSECT_END\n");
176            break;
177          case img_ERROR_INFO:
178            printf("ERROR_INFO #legs %d, len %.2fm, E %.2f H %.2f V %.2f\n",
179                   pimg->n_legs, pimg->length, pimg->E, pimg->H, pimg->V);
180            break;
181          case img_BAD:
182            img_close(pimg);
183            fatalerror(img_error2msg(img_error()), fnm);
184          case img_STOP:
185            printf("STOP\n");
186            break;
187          default:
188            printf("CODE_0x%02x\n", code);
189         }
190      } while (code != img_STOP);
191   } while (fRewind);
192
193   img_close(pimg);
194
195   return 0;
196}
Note: See TracBrowser for help on using the repository browser.