2 * Convert a processed survey data file to another format.
5 /* Copyright (C) 1994-2004,2008,2010,2011,2013,2014,2018 Olly Betts
6 * Copyright (C) 2004 John Pybus (SVG Output code)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 #include "img_hosted.h"
43 #define FMT_DEFAULT FMT_DXF
46 main(int argc
, char **argv
)
51 bool format_set
= false;
53 const char *survey
= NULL
;
54 double grid
= 0.0; /* grid spacing (or 0 for no grid) */
55 double text_height
= DEFAULT_TEXT_HEIGHT
; /* for station labels */
56 double marker_size
= DEFAULT_MARKER_SIZE
; /* for station markers */
66 static const struct option long_opts
[] = {
67 /* const char *name; int has_arg (0 no_argument, 1 required, 2 options_*); int *flag; int val */
68 {"survey", required_argument
, 0, 's'},
69 {"no-crosses", no_argument
, 0, 'c'},
70 {"no-station-names", no_argument
, 0, 'n'},
71 {"no-legs", no_argument
, 0, 'l'},
72 {"grid", optional_argument
, 0, 'g'},
73 {"text-height", required_argument
, 0, 't'},
74 {"marker-size", required_argument
, 0, 'm'},
75 {"elevation", required_argument
, 0, 'e'},
76 {"reduction", required_argument
, 0, 'r'},
77 {"dxf", no_argument
, 0, 'D'},
78 {"skencil", no_argument
, 0, 'S'},
79 {"plt", no_argument
, 0, 'P'},
80 {"svg", no_argument
, 0, 'V'},
81 {"help", no_argument
, 0, HLP_HELP
},
82 {"version", no_argument
, 0, HLP_VERSION
},
83 /* Old name for --skencil: */
84 {"sketch", no_argument
, 0, 'S'},
88 #define short_opts "s:cnlg::t:m:e:r:DSPV"
91 static struct help_msg help
[] = {
93 {HLP_ENCODELONG(0), /*only load the sub-survey with this prefix*/199, 0},
94 {HLP_ENCODELONG(1), /*do not generate station markers*/100, 0},
95 {HLP_ENCODELONG(2), /*do not generate station labels*/101, 0},
96 {HLP_ENCODELONG(3), /*do not generate survey legs*/102, 0},
97 {HLP_ENCODELONG(4), /*generate grid (default %sm)*/148, STRING(DEFAULT_GRID_SPACING
)},
98 {HLP_ENCODELONG(5), /*station labels text height (default %s)*/149, STRING(DEFAULT_TEXT_HEIGHT
)},
99 {HLP_ENCODELONG(6), /*station marker size (default %s)*/152, STRING(DEFAULT_MARKER_SIZE
)},
100 {HLP_ENCODELONG(7), /*produce an elevation view*/103, 0},
101 {HLP_ENCODELONG(8), /*factor to scale down by (default %s)*/155, "500"},
102 {HLP_ENCODELONG(9), /*produce DXF output*/156, 0},
103 /* TRANSLATORS: "Skencil" is the name of a software package, so should not be
105 {HLP_ENCODELONG(10), /*produce Skencil output*/158, 0},
106 /* TRANSLATORS: "Compass" and "Carto" are the names of software packages,
107 * so should not be translated. */
108 {HLP_ENCODELONG(11), /*produce Compass PLT output for Carto*/159, 0},
109 {HLP_ENCODELONG(12), /*produce SVG output*/160, 0},
115 cmdline_init(argc
, argv
, short_opts
, long_opts
, NULL
, help
, 1, 2);
117 int opt
= cmdline_getopt();
118 if (opt
== EOF
) break;
120 case 'e': /* Elevation */
121 tilt
= cmdline_double_arg();
123 case 'c': /* Crosses */
126 case 'n': /* Labels */
127 show_mask
&= ~LABELS
;
134 grid
= cmdline_double_arg();
136 grid
= (double)DEFAULT_GRID_SPACING
;
139 case 'r': /* Reduction factor */
140 scale
= cmdline_double_arg();
142 case 't': /* Text height */
143 text_height
= cmdline_double_arg();
145 case 'm': /* Marker size */
146 marker_size
= cmdline_double_arg();
170 const char* fnm_in
= argv
[optind
++];
171 const char* fnm_out
= argv
[optind
];
175 size_t len
= strlen(fnm_out
);
176 format
= FMT_DEFAULT
;
177 for (i
= 0; i
< FMT_MAX_PLUS_ONE_
; ++i
) {
178 size_t l
= strlen(extension
[i
]);
180 strcasecmp(fnm_out
+ len
- l
, extension
[i
]) == 0) {
181 format
= export_format(i
);
187 char *baseleaf
= baseleaf_from_fnm(fnm_in
);
188 if (!format_set
) format
= FMT_DEFAULT
;
189 /* note : memory allocated by fnm_out gets leaked in this case... */
190 fnm_out
= add_ext(baseleaf
, extension
[format
]);
195 int err
= model
.Load(fnm_in
, survey
);
196 if (err
) fatalerror(err
, fnm_in
);
198 if (!Export(fnm_out
, model
.GetSurveyTitle(),
199 model
.GetDateString(),
201 pan
, tilt
, show_mask
, format
,
203 grid
, text_height
, marker_size
,
205 fatalerror(/*Couldn’t write file “%s”*/402, fnm_out
);