• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

icsm-au / DynAdjust / 13494567994

24 Feb 2025 09:15AM UTC coverage: 81.168% (+2.0%) from 79.161%
13494567994

push

github

web-flow
Merge pull request #234 from icsm-au/1.2.8

Version 1.2.8 (fixes, ehnacements, improved datum management)

6131 of 8137 new or added lines in 90 files covered. (75.35%)

162 existing lines in 33 files now uncovered.

32214 of 39688 relevant lines covered (81.17%)

11775.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.72
/dynadjust/dynadjust/dynadjust/dynadjust.cpp
1
// dynadjust.cpp : Defines the entry point for the console application.
2
//
3
#include <iostream>
4
#include <fstream>
5
#include <algorithm>
6
#include <iomanip>
7
#include <sstream>
8
#include <string>
9
#include <time.h>
10

11
#include <boost/timer/timer.hpp>
12
#include <boost/date_time/posix_time/posix_time.hpp>
13
#include <boost/thread.hpp>
14
#include <boost/thread/mutex.hpp>
15
#include <boost/shared_ptr.hpp>
16
#include <boost/program_options/options_description.hpp>
17
#include <boost/program_options/parsers.hpp>
18
#include <boost/program_options/variables_map.hpp>
19
#include <boost/filesystem.hpp>
20
#include <boost/algorithm/string/predicate.hpp>
21

22
boost::mutex cout_mutex;
23

24
#include <include/config/dnaversion.hpp>
25
#include <include/config/dnaconsts.hpp>
26
#include <include/config/dnaoptions.hpp>
27
#include <include/config/dnaoptions-interface.hpp>
28

29
#include <include/functions/dnastringfuncs.hpp>
30
#include <include/functions/dnaprocessfuncs.hpp>
31
#include <include/functions/dnaiostreamfuncs.hpp>
32
#include <include/functions/dnafilepathfuncs.hpp>
33
#include <include/functions/dnafilepathfuncs.hpp>
34
#include <include/functions/dnatemplatedatetimefuncs.hpp>
35
#include <include/functions/dnastrmanipfuncs.hpp>
36

37
#include <include/config/dnaprojectfile.hpp>
38

39
using namespace dynadjust;
40

41
int CloseLogandReturn(std::ofstream& os, const int status, const std::string& output_file="")
1✔
42
{
43
        if (status == EXIT_FAILURE)
1✔
44
        {
NEW
45
                os << std::setw(25) << std::left << formattedDateTimeString<std::string>() << 
×
NEW
46
                        "Failed. " << std::endl << std::endl << 
×
UNCOV
47
                        "+ DynAdjust ended prematurely. ";
×
48

49
                if (!output_file.empty())
×
50
                {
51
                        std::ifstream f(output_file);
×
NEW
52
                        os << " Contents of last output file:" << std::endl << std::endl << f.rdbuf();
×
53
                }
×
54
                else
NEW
55
                         os << std::endl;
×
56
        }
57
        else
58
                os << std::endl << std::endl << "+ DynAdjust finished successfully." << std::endl;
1✔
59

60
        os.close();
1✔
61
        return status;
1✔
62
}
63

64
void PrintAppStartTimeMessage(std::ofstream& os, std::string&& app)
5✔
65
{
66
        // App start time
67
        os << std::setw(15) << std::left << std::string("+ " + app) << std::setw(25) << 
5✔
68
                formattedDateTimeString<std::string>();
15✔
69
}
5✔
70

71
void PrintSuccessStatusMessage(std::ofstream& os)
5✔
72
{
73
        // end time
74
        os << std::setw(25) << std::left << formattedDateTimeString<std::string>() << 
5✔
75
                "Ended successfully." << std::endl;
5✔
76
}
5✔
77

78
int main(int argc, char* argv[])
12✔
79
{
80
        std::stringstream ss;
12✔
81

82
        std::string cmd_line_banner;
12✔
83
        fileproc_help_header(&cmd_line_banner);
12✔
84

85
        project_settings p;
12✔
86
        boost::program_options::variables_map vm;
12✔
87
        boost::program_options::positional_options_description positional_options;
12✔
88

89
        boost::program_options::options_description standard_options("+ " + std::string(ALL_MODULE_STDOPT), PROGRAM_OPTIONS_LINE_LENGTH);
36✔
90
        boost::program_options::options_description generic_options("+ " + std::string(ALL_MODULE_GENERIC), PROGRAM_OPTIONS_LINE_LENGTH);
36✔
91

92
        std::string cmd_line_usage("+ ");
12✔
93
        cmd_line_usage.append(__BINARY_NAME__).append(" usage:  ").append(__BINARY_NAME__).append(" ").append(" [options]");
12✔
94
        boost::program_options::options_description allowable_options(cmd_line_usage, PROGRAM_OPTIONS_LINE_LENGTH);
12✔
95

96
        try {
12✔
97
                standard_options.add_options()
12✔
98
                        (PROJECT_FILE_P, boost::program_options::value<std::string>(&p.g.project_file),
12✔
99
                                "Project file containing all user options for import, segment, geoid, reftran, adjust and plot.")
100
                        (NETWORK_NAME_N, boost::program_options::value<std::string>(&p.g.network_name),
12✔
101
                                "Network name. User defined name for all input and output files. Default is \"network#\".")
102
                        (RUN_IMPORT,
12✔
103
                                "Run import - DynAdjust file exchange software.")
104
                        (RUN_GEOID,
12✔
105
                                "Run geoid - geoid model interpolation software to determine geoid-ellipsoid separation and deflection values.")
106
                        (RUN_REFTRAN,
12✔
107
                                "Run reftran - reference frame transformation software to transform stations and measurements.")
108
                        (RUN_SEGMENT,
12✔
109
                                "Run segment - automated segmentation software to partition a geodetic network into smaller sized blocks.")
110
                        (RUN_ADJUST,
12✔
111
                                "Run adjust - geodetic network adjustment software.")
112
                        ;
113

114
                generic_options.add_options()
12✔
115
                        (VERBOSE, boost::program_options::value<UINT16>(&p.g.verbose),
12✔
116
                                std::string("Give detailed information about what ").append(__BINARY_NAME__).append(" is doing.\n  0: No information (default)\n  1: Helpful information\n  2: Extended information\n  3: Debug level information").c_str())
24✔
117
                        (QUIET,
12✔
118
                                std::string("Suppresses all explanation of what ").append(__BINARY_NAME__).append(" is doing unless an error occurs.").c_str())
24✔
119
                        (VERSION_V, "Display the current program version.")
12✔
120
                        (HELP_H, "Show this help message.")
12✔
121
                        (HELP_MODULE_H, boost::program_options::value<std::string>(),
12✔
122
                                "Provide help for a specific help category.")
123
                        ;
124

125
                allowable_options.add(standard_options).add(generic_options);
12✔
126

127
                // add "positional options" to handle command line tokens which have no option name
128
                positional_options.add(NETWORK_NAME, -1);
12✔
129
                
130
                boost::program_options::command_line_parser parser(argc, argv);
12✔
131
                store(parser.options(allowable_options).positional(positional_options).run(), vm);
12✔
132
                notify(vm);
11✔
133
        } 
1✔
134
        catch (const std::exception& e) {
1✔
135
                cout_mutex.lock();
1✔
136
                std::cout << "- Error: " << e.what() << std::endl;
1✔
137
                std::cout << cmd_line_banner << allowable_options << std::endl;
1✔
138
                cout_mutex.unlock();
1✔
139
                return EXIT_FAILURE;
1✔
140
        }
1✔
141
        
142
        if (argc < 2)
11✔
143
        {
144
                std::cout << std::endl << "- Nothing to do - no options provided. " << std::endl << std::endl;  
1✔
145
                std::cout << cmd_line_banner << allowable_options << std::endl;
1✔
146
                return EXIT_FAILURE;
147
        }
148

149
        if (vm.count(VERSION))
20✔
150
        {
151
                std::cout << cmd_line_banner << std::endl;
1✔
152
                return EXIT_SUCCESS;
153
        }
154

155
        if (vm.count(HELP))
18✔
156
        {
157
                std::cout << cmd_line_banner << allowable_options << std::endl;
1✔
158
                return EXIT_SUCCESS;
159
        }
160

161
        if (vm.count(HELP_MODULE))
16✔
162
        {
163
                std::cout << cmd_line_banner;
3✔
164
                std::string original_text = vm[HELP_MODULE].as<std::string>();
9✔
165
                std::string help_text = str_upper<std::string>(original_text);
3✔
166

167
                if (str_upper<std::string, char>(ALL_MODULE_STDOPT).find(help_text) != std::string::npos) {
9✔
168
                        std::cout << standard_options << std::endl;
1✔
169
                }
170
                else if (str_upper<std::string, char>(ALL_MODULE_GENERIC).find(help_text) != std::string::npos) {
6✔
171
                        std::cout << generic_options << std::endl;
1✔
172
                }
173
                else {
174
                        std::cout << std::endl << "- Error: Help module '" <<
1✔
175
                                original_text << "' is not in the list of options." << std::endl;
3✔
176
                        return EXIT_FAILURE;
177
                }
178

179
                return EXIT_SUCCESS;
2✔
180
        }
6✔
181

182
        if (vm.count(QUIET))
10✔
183
                p.g.quiet = 1;
×
184
        else
185
                std::cout << std::endl << cmd_line_banner;
5✔
186

187
        if (!vm.count(PROJECT_FILE) && !vm.count(NETWORK_NAME))
13✔
188
        {
189
                std::cout << std::endl << "- Nothing to do - no project file or network name specified. " << std::endl << std::endl;  
1✔
190
                return EXIT_FAILURE;
191
        }
192

193
        if (!vm.count(RUN_IMPORT) && 
11✔
194
                !vm.count(RUN_GEOID) && 
13✔
195
                !vm.count(RUN_REFTRAN) && 
13✔
196
                !vm.count(RUN_SEGMENT) && 
21✔
197
                !vm.count(RUN_ADJUST))
10✔
198
        {
199
                std::cout << std::endl << "- Nothing to do - no programs were specified. " << std::endl << std::endl;  
3✔
200
                return EXIT_FAILURE;
201
        }
202

203
        if (vm.count(PROJECT_FILE) && vm.count(NETWORK_NAME))
2✔
204
        {
NEW
205
                if (boost::equals(boost::filesystem::path(p.g.project_file).stem().string(), p.g.network_name))
×
206
                {
NEW
207
                        std::cout << std::endl << "- Error: project file name doesn't match network name.  Provide" << std::endl;  
×
NEW
208
                        std::cout << std::endl << "         either a project file path or the network name. " << std::endl << std::endl;  
×
209
                        return EXIT_FAILURE;
210
                }
211
        }
212
        
213
        // If a name was supplied, form full file path for project file using the current folder
214
        if (vm.count(NETWORK_NAME))
2✔
215
                p.g.project_file = formPath<std::string>(".", p.g.network_name, "dnaproj");
4✔
216
        
217
        if (!boost::filesystem::exists(p.g.project_file))
2✔
218
        {
NEW
219
                std::cout << std::endl << 
×
220
                        "- Error: Project file  " << p.g.project_file <<
NEW
221
                                "  does not exist. " << std::endl << std::endl;  
×
222
                return EXIT_FAILURE;
223
        }
224

225
        // Load project file, obtain output folder and form log file path
226
        CDnaProjectFile projectFile;
1✔
227
        projectFile.LoadProjectFile(p.g.project_file);
1✔
228
        p = projectFile.GetSettings();
1✔
229
        
230
        std::string dynadjustLogFilePath(formPath<std::string>(p.g.output_folder, "dynadjust", "log"));
3✔
231
        
232
        p.g.log_file = dynadjustLogFilePath;
1✔
233
        projectFile.UpdateSettingsGeneral(p.g);
1✔
234
        projectFile.PrintProjectFile();
1✔
235

236
        std::ofstream dynadjust_log;
1✔
237

238
        ss << "- Error: Could not open dynadjust.log for writing." << std::endl;
1✔
239
        try {
1✔
240
                // Create dynadjust log file.  Exit failure.
241
                file_opener(dynadjust_log, dynadjustLogFilePath);
1✔
242
        }
NEW
243
        catch (const std::runtime_error& e) {
×
244
                ss << e.what();
×
NEW
245
                std::cout << std::endl << ss.str() << std::endl << std::endl;
×
246
                return EXIT_FAILURE;
×
247
        }
×
248
        catch (...) {
×
NEW
249
                std::cout << std::endl << ss.str() << std::endl << std::endl;
×
250
                return EXIT_FAILURE;
×
251
        }
×
252

253
        dynadjust_log << cmd_line_banner << std::endl;
1✔
254

255
        dynadjust_log << std::left << std::setw(15) << "+ Executable" << 
1✔
256
                std::setw(25) << "Start date and time" << 
257
                std::setw(25) << "End date and time" << 
258
                std::setw(25) << "Exit status" << std::endl;
1✔
259

260
        for (UINT32 d=0, linelen(15+25+25+25); d<linelen; ++d)
91✔
261
                dynadjust_log << "-";
90✔
262
        dynadjust_log << std::endl;
1✔
263
        
264
        // Run import (optional)
265
        if (vm.count(RUN_IMPORT))
2✔
266
        {
267
                std::stringstream cmd;
1✔
268
                cmd << __import_app_name__ << " -p " << p.g.project_file;
1✔
269
                
270
                if (p.g.quiet)
1✔
271
                        cmd << " --quiet";
×
272
                
273
                // start time
274
                PrintAppStartTimeMessage(dynadjust_log, __import_app_name__);
2✔
275
                
276
                if (!run_command(cmd.str().c_str()), p.g.quiet)
3✔
277
                {
NEW
278
                        p.i.imp_file = formPath<std::string>(p.g.output_folder, p.g.network_name, "imp");
×
279
                        return CloseLogandReturn(dynadjust_log, EXIT_FAILURE, p.i.imp_file);
×
280
                }
281
                
282
                // end time
283
                PrintSuccessStatusMessage(dynadjust_log);
1✔
284

285
                boost::this_thread::sleep(boost::posix_time::milliseconds(40));
1✔
286
        }
1✔
287
        
288
        // Run reftran (optional)
289
        if (vm.count(RUN_REFTRAN))
2✔
290
        {
291
                std::stringstream cmd;
1✔
292
                cmd << __reftran_app_name__ << " -p " << p.g.project_file;
1✔
293
                
294
                if (p.g.quiet)
1✔
295
                        cmd << " --quiet";
×
296
                
297
                // start time
298
                PrintAppStartTimeMessage(dynadjust_log, __reftran_app_name__);
2✔
299
                
300
                if (!run_command(cmd.str().c_str()), p.g.quiet)
3✔
301
                        return CloseLogandReturn(dynadjust_log, EXIT_FAILURE);
×
302
                
303
                // end time
304
                PrintSuccessStatusMessage(dynadjust_log);
1✔
305

306
                boost::this_thread::sleep(boost::posix_time::milliseconds(40));
1✔
307
        }
1✔
308
        
309
        // Run geoid (optional)
310
        if (vm.count(RUN_GEOID))
2✔
311
        {
312
                std::stringstream cmd;
1✔
313
                cmd << __geoid_app_name__ << " -p " << p.g.project_file;
1✔
314
                
315
                if (p.g.quiet)
1✔
316
                        cmd << " --quiet";
×
317
                
318
                // start time
319
                PrintAppStartTimeMessage(dynadjust_log, __geoid_app_name__);
2✔
320
                
321
                if (!run_command(cmd.str().c_str()), p.g.quiet)
3✔
322
                        return CloseLogandReturn(dynadjust_log, EXIT_FAILURE);
×
323
        
324
                // end time
325
                PrintSuccessStatusMessage(dynadjust_log);
1✔
326

327
                boost::this_thread::sleep(boost::posix_time::milliseconds(40));
1✔
328
        }
1✔
329
                
330
        // Run segment (optional)
331
        if (vm.count(RUN_SEGMENT))
2✔
332
        {
333
                std::stringstream cmd;
1✔
334
                cmd << __segment_app_name__ << " -p " << p.g.project_file;
1✔
335
                
336
                if (p.g.quiet)
1✔
337
                        cmd << " --quiet";
×
338
                
339
                // start time
340
                PrintAppStartTimeMessage(dynadjust_log, __segment_app_name__);
2✔
341
                
342
                if (!run_command(cmd.str().c_str()), p.g.quiet)
3✔
343
                        return CloseLogandReturn(dynadjust_log, EXIT_FAILURE);
×
344
        
345
                // end time
346
                PrintSuccessStatusMessage(dynadjust_log);
1✔
347

348
                boost::this_thread::sleep(boost::posix_time::milliseconds(40));
1✔
349
        }
1✔
350
        
351
        // Run adjust (optional)
352
        if (vm.count(RUN_ADJUST))
2✔
353
        {                
354
                std::stringstream cmd;
1✔
355
                cmd << __adjust_app_name__ << " -p " << p.g.project_file;
1✔
356
                
357
                if (p.g.quiet)
1✔
358
                        cmd << " --quiet";
×
359
                
360
                // start time
361
                PrintAppStartTimeMessage(dynadjust_log, __adjust_app_name__);
2✔
362
                
363
                if (!run_command(cmd.str().c_str()), p.g.quiet)
3✔
364
                        return CloseLogandReturn(dynadjust_log, EXIT_FAILURE);
×
365

366
                // end time
367
                PrintSuccessStatusMessage(dynadjust_log);
1✔
368

369
                boost::this_thread::sleep(boost::posix_time::milliseconds(40));
1✔
370
        }
1✔
371

372
        return CloseLogandReturn(dynadjust_log, EXIT_SUCCESS);
2✔
373
}
37✔
374

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc