• 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

79.7
/dynadjust/dynadjust/dnareftranwrapper/dnareftranwrapper.cpp
1
//============================================================================
2
// Name         : dnareftranwrapper.cpp
3
// Author       : Roger Fraser
4
// Contributors :
5
// Version      : 1.00
6
// Copyright    : Copyright 2017 Geoscience Australia
7
//
8
//                Licensed under the Apache License, Version 2.0 (the "License");
9
//                you may not use this file except in compliance with the License.
10
//                You may obtain a copy of the License at
11
//               
12
//                http ://www.apache.org/licenses/LICENSE-2.0
13
//               
14
//                Unless required by applicable law or agreed to in writing, software
15
//                distributed under the License is distributed on an "AS IS" BASIS,
16
//                WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
//                See the License for the specific language governing permissions and
18
//                limitations under the License.
19
//
20
// Description  : Reference Frame Transformation Executable
21
//============================================================================
22

23
#include <dynadjust/dnareftranwrapper/dnareftranwrapper.hpp>
24

25
using namespace dynadjust;
26

27
void PrintOutputFileHeaderInfo(std::ofstream* f_out, const std::string& out_file, project_settings* p, const std::string& header, UINT32& epsgCode, bool userSuppliedFrame, bool userSuppliedEpoch)
458✔
28
{
29
        // Print formatted header
30
        print_file_header(*f_out, header);
458✔
31

32
        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << boost::filesystem::system_complete(out_file).string() << std::endl << std::endl;
916✔
33
        
34
        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Command line arguments: ";
458✔
35
        *f_out << p->r.command_line_arguments << std::endl << std::endl;
458✔
36

37
        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Network name:" <<  p->g.network_name << std::endl;
458✔
38
        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Input folder: " << boost::filesystem::system_complete(p->g.input_folder).string() << std::endl;
916✔
39
        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Output folder: " << boost::filesystem::system_complete(p->g.output_folder).string() << std::endl;
916✔
40
        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << boost::filesystem::system_complete(p->r.bst_file).string() << std::endl;
916✔
41
        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << boost::filesystem::system_complete(p->r.bms_file).string() << std::endl;
916✔
42
        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Target reference frame:" << p->r.reference_frame;
458✔
43

44
        if (userSuppliedFrame)
458✔
45
                *f_out << " (user supplied)" << std::endl;
440✔
46
        else
47
                *f_out << " (project reference frame)" << std::endl;
18✔
48

49
        if (!p->r.epoch.empty())
458✔
50
        {
51
                // Has the user supplied the year only?
52
                if (p->r.epoch.rfind(".") == std::string::npos)
458✔
53
                        p->r.epoch.insert(0, "01.01.");
×
54

55
                *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Target epoch: " << p->r.epoch;
458✔
56
                if (isEpsgDatumStatic(epsgCode))
458✔
57
                        *f_out << " (adopted reference epoch of " << p->r.reference_frame << ")";
62✔
58
                else
59
                {
60
                        if (userSuppliedEpoch)
396✔
61
                                *f_out << " (user supplied)" << std::endl;
7✔
62
                        else
63
                        {
64
                                if (userSuppliedFrame)
389✔
65
                                        *f_out << " (adopted reference epoch of " << p->r.reference_frame << ")" << std::endl;
374✔
66
                                else
67
                                        *f_out << " (project epoch)" << std::endl;
15✔
68
                        }
69
                }
70
                *f_out << std::endl;
458✔
71
        }
72
        
73
        if (p->r.plate_model_option > 0)
458✔
74
        {
75
                *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Plate boundaries file: " << p->r.tpb_file << std::endl;
20✔
76
                *f_out << std::setw(PRINT_VAR_PAD) << std::left << "Plate pole parameter file: " << p->r.tpp_file << std::endl;
20✔
77
        }
78
        
79
        if (p->i.export_dynaml)
458✔
80
        {
81
                if (p->i.export_single_xml_file)
5✔
82
                        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "DynaML output file: " << p->i.xml_outfile << std::endl;
2✔
83
                else
84
                {
85
                        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "DynaML station file: " << p->i.xml_stnfile << std::endl;
3✔
86
                        *f_out << std::setw(PRINT_VAR_PAD) << std::left << "DynaML measurement file: " << p->i.xml_msrfile << std::endl;
3✔
87
                }                                
88
        }
89
        if (p->i.export_dna_files)
458✔
90
        {
91
                *f_out << std::setw(PRINT_VAR_PAD) << std::left << "DNA station file: " << p->i.dna_stnfile << std::endl;
5✔
92
                *f_out << std::setw(PRINT_VAR_PAD) << std::left << "DNA measurement file: " << p->i.dna_msrfile << std::endl;
5✔
93
        }
94

95
//        if (p->o._export_snx_file)
96
//                *f_out << std::setw(PRINT_VAR_PAD) << std::left << "SINEX file: " << p->o._snx_file << std::endl;
97

98

99
        *f_out << OUTPUTLINE << std::endl << std::endl;
458✔
100
}
458✔
101

102

103
int ParseCommandLineOptions(const int& argc, char* argv[], const boost::program_options::variables_map& vm, project_settings& p, UINT32& epsgCode)
463✔
104
{
105
        // capture command line arguments
106
        for (int cmd_arg(0); cmd_arg<argc; ++cmd_arg)
2,474✔
107
        {
108
                 p.r.command_line_arguments += argv[cmd_arg];
2,011✔
109
                 p.r.command_line_arguments += " ";
2,011✔
110
        }
111

112
        if (vm.count(PROJECT_FILE))
926✔
113
        {
114
                if (boost::filesystem::exists(p.g.project_file))
4✔
115
                {
116
                        try {
1✔
117
                                CDnaProjectFile projectFile(p.g.project_file, reftranSetting);
1✔
118
                                p = projectFile.GetSettings();
1✔
119
                        }
×
NEW
120
                        catch (const std::runtime_error& e) {
×
NEW
121
                                std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
122
                                return EXIT_FAILURE;
×
123
                        }
×
124
                        
125
                        return EXIT_SUCCESS;
1✔
126
                }
127

128
                std::cout << std::endl << "- Error: project file " << p.g.project_file << " does not exist." << std::endl << std::endl;
1✔
129
                return EXIT_FAILURE;
1✔
130
        }
131

132
        if (!vm.count(NETWORK_NAME))
922✔
133
        {
134
                std::cout << std::endl << "- Nothing to do - no network name specified. " << std::endl << std::endl;  
1✔
135
                return EXIT_FAILURE;
1✔
136
        }
137
        
138
        p.g.project_file = formPath<std::string>(p.g.output_folder, p.g.network_name, "dnaproj");
1,380✔
139
        p.r.rft_file = formPath<std::string>(p.g.output_folder, p.g.network_name, "rft");
1,380✔
140

141
        bool frameSupplied(true);
460✔
142
        project_settings tmp;
460✔
143

144
        if (!vm.count(REFERENCE_FRAME))
920✔
145
        {
146
                if (boost::filesystem::exists(p.g.project_file))
34✔
147
                {
148
                        try {
17✔
149
                                CDnaProjectFile projectFile(p.g.project_file, reftranSetting);
17✔
150
                                tmp = projectFile.GetSettings();
17✔
151
                                p.r.reference_frame = tmp.r.reference_frame;
17✔
152
                                frameSupplied = false;
17✔
153
                        }
17✔
NEW
154
                        catch (const std::runtime_error& e) {
×
NEW
155
                                std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
NEW
156
                                return EXIT_FAILURE;
×
NEW
157
                        }
×
158
                }
159

160
                //cout << std::endl << "- Reference frame was not supplied.  Using project default (" << p.r.reference_frame << ")" << std::endl << std::endl;
161
                
162
                try
17✔
163
                {
164
                        // Okay, no frame supplied, set the frame epsg code from the project settings.
165
                        // The following throws an exception if the frame is unknown
166
                        epsgCode = epsgCodeFromName<UINT32>(p.r.reference_frame);
17✔
167
                }
NEW
168
                catch (const std::runtime_error& e) {
×
NEW
169
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
NEW
170
                        return EXIT_FAILURE;
×
NEW
171
                }                
×
172
        }
173

174
        if (vm.count(EPOCH))
920✔
175
        {
176
                // Get today's date?
177
                if (boost::iequals(p.r.epoch, "today"))
7✔
NEW
178
                        p.r.epoch = stringFromToday<boost::gregorian::date>();
×
179
                // Has the user supplied the year only?
180
                else if (p.r.epoch.rfind(".") == std::string::npos)
7✔
181
                        p.r.epoch.insert(0, "01.01.");
1✔
182

183
                if (p.r.epoch.length() < 10)
7✔
184
                        p.r.epoch = FormatDateString(p.r.epoch);
2✔
185
        }
186
        else
187
        {
188
                try
453✔
189
                {
190
                        if (frameSupplied)
453✔
191
                                // Okay, frame supplied, but no epoch supplied.
192
                                // Set the epoch to be the reference epoch of the supplied reference frame
193
                                p.r.epoch = referenceepochFromEpsgCode<UINT32>(epsgCodeFromName<UINT32, std::string>(p.r.reference_frame));
872✔
194
                        else
195
                                // Take the epoch from the project file
196
                                p.r.epoch = tmp.r.epoch;
17✔
197
                }
NEW
198
                catch (const std::runtime_error& e) {
×
NEW
199
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
UNCOV
200
                        return EXIT_FAILURE;
×
UNCOV
201
                }
×
202
        }
203

204
        if (vm.count(TECTONIC_PLATE_BDY_FILE))
920✔
205
        {
206
                if (!boost::filesystem::exists(p.r.tpb_file))
42✔
207
                {
208
                        std::cout << std::endl << "- Error: ";
1✔
209
                        std::cout << std::endl << "tectonic plate boundary file " << std::endl << "               ";
1✔
210
                        std::cout << p.r.tpb_file << " does not exist." << std::endl << std::endl;
1✔
211
                        return EXIT_FAILURE;
212
                }
213
        }
214

215
        if (vm.count(TECTONIC_PLATE_POLE_FILE))
918✔
216
        {
217
                if (!boost::filesystem::exists(p.r.tpp_file))
42✔
218
                {
219
                        std::cout << std::endl << "- Error: ";
1✔
220
                        std::cout << std::endl << "Euler pole parameters file " << std::endl << "               ";
1✔
221
                        std::cout << p.r.tpp_file << " does not exist." << std::endl << std::endl;
1✔
222
                        return EXIT_FAILURE;
223
                }
224
        }
225

226
        // binary station file location (input)
227
        if (vm.count(BIN_STN_FILE))
916✔
NEW
228
                p.r.bst_file = formPath<std::string>(p.g.input_folder, p.r.bst_file);
×
229
        else
230
                p.r.bst_file = formPath<std::string>(p.g.output_folder, p.g.network_name, "bst");
1,374✔
231

232
        // binary station file location (input)
233
        if (vm.count(BIN_MSR_FILE))
916✔
NEW
234
                p.r.bms_file = formPath<std::string>(p.g.input_folder, p.r.bms_file);
×
235
        else
236
                p.r.bms_file = formPath<std::string>(p.g.output_folder, p.g.network_name, "bms");
1,374✔
237

238
        if (!boost::filesystem::exists(p.r.bst_file) || !boost::filesystem::exists(p.r.bms_file))
1,373✔
239
        {
240
                std::cout << std::endl << "- Nothing to do: ";  
1✔
241
                        
242
                if (p.g.network_name.empty())
1✔
NEW
243
                        std::cout << std::endl << "network name has not been specified specified, and " << std::endl << "               ";  
×
244
                std::cout << p.r.bst_file << " and " << p.r.bms_file << " do not exist." << std::endl << std::endl;  
1✔
245
                return EXIT_FAILURE;
246
        }
247

248
        // convert to upper case
249
        str_toupper<int>(p.r.reference_frame);
457✔
250

251
        //////////////////////////////////////////////////////////////////////////////
252
        // Export options
253
        
254
        // Create file name based on the provided block
255
        std::string fileName(p.g.network_name);
457✔
256
        fileName.append(".").append(p.r.reference_frame);
457✔
257

258
        if (!isEpsgDatumStatic(epsgCode))
457✔
259
        {
260
                if (boost::iequals(p.r.epoch, "today"))
396✔
NEW
261
                        p.r.epoch = stringFromToday<boost::gregorian::date>();
×
262
                fileName.append(".").append(p.r.epoch);
396✔
263
        }
264

265
        // Export to dynaml?
266
        if (vm.count(EXPORT_XML_FILES))
914✔
267
        {
268
                p.i.export_dynaml = 1;
4✔
269
        
270
                // single file for both stations and measurements
271
                if (vm.count(EXPORT_SINGLE_XML_FILE))
8✔
272
                {
273
                        p.i.export_single_xml_file = 1;
2✔
274
                        p.i.xml_outfile = formPath<std::string>(p.g.output_folder, 
6✔
275
                                fileName, "xml");
2✔
276
                }
277
                // unique files for stations and measurements
278
                else
279
                {
280
                        p.i.export_single_xml_file = 0;
2✔
281
                        p.i.xml_stnfile = formPath<std::string>(p.g.output_folder, 
8✔
282
                                fileName + "stn", "xml");
6✔
283
                        p.i.xml_msrfile = formPath<std::string>(p.g.output_folder, 
8✔
284
                                fileName + "msr", "xml");
6✔
285
                }
286
        }
287

288
        // Export dna files
289
        if (vm.count(EXPORT_DNA_FILES))
914✔
290
        {
291
                p.i.export_dna_files = 1;                
4✔
292
                p.i.dna_stnfile = formPath<std::string>(p.g.output_folder, 
12✔
293
                        fileName, "stn");
4✔
294
                p.i.dna_msrfile = formPath<std::string>(p.g.output_folder, 
12✔
295
                        fileName, "msr");
4✔
296
        }
297

298
//        // Export dna files
299
//        if (vm.count(EXPORT_SNX_FILE))
300
//        {
301
//                p.o._export_snx_file = 1;                
302
//                p.o._snx_file = formPath<std::string>(p.g.output_folder, 
303
//                        fileName, "snx");
304
//        }
305

306
        return EXIT_SUCCESS;
457✔
307
}
460✔
308

309
int main(int argc, char* argv[])
474✔
310
{        
311
        // create banner message
312
        std::string cmd_line_banner;
474✔
313
        fileproc_help_header(&cmd_line_banner);
474✔
314

315
        project_settings p;
474✔
316

317
        boost::program_options::variables_map vm;
474✔
318
        boost::program_options::positional_options_description positional_options;
474✔
319
        
320
        boost::program_options::options_description standard_options("+ " + std::string(ALL_MODULE_STDOPT), PROGRAM_OPTIONS_LINE_LENGTH);
1,422✔
321
        boost::program_options::options_description transformation_options("+ " + std::string(REFTRAN_MODULE_TRANSFORM), PROGRAM_OPTIONS_LINE_LENGTH);
1,422✔
322
        boost::program_options::options_description export_options("+ " + std::string(ALL_MODULE_EXPORT), PROGRAM_OPTIONS_LINE_LENGTH);
1,422✔
323
        boost::program_options::options_description generic_options("+ " + std::string(ALL_MODULE_GENERIC), PROGRAM_OPTIONS_LINE_LENGTH);
1,422✔
324

325
        std::string cmd_line_usage("+ ");
474✔
326
        cmd_line_usage.append(__BINARY_NAME__).append(" usage:  ").append(__BINARY_NAME__).append(" ").append(NETWORK_NAME).append(" [options]");
474✔
327
        boost::program_options::options_description allowable_options(cmd_line_usage, PROGRAM_OPTIONS_LINE_LENGTH);
474✔
328

329
        try {
474✔
330
                // Declare a group of options that will be 
331
                // allowed only on command line                
332
                standard_options.add_options()
474✔
333
                        (PROJECT_FILE_P, boost::program_options::value<std::string>(&p.g.project_file),
474✔
334
                                "Project file name. Full path to project file. If none specified, a new file is created using input-folder and network-name.")
335
                        (NETWORK_NAME_N, boost::program_options::value<std::string>(&p.g.network_name), 
474✔
336
                                "Network name. User defined name for all output files. Default is \"network#\".")
337
                        (INPUT_FOLDER_I, boost::program_options::value<std::string>(&p.g.input_folder),
474✔
338
                                "Path containing all input files")
339
                        (OUTPUT_FOLDER_O, boost::program_options::value<std::string>(&p.g.output_folder),                // default is ./,
474✔
340
                                "Path for all output files")
341
                        (BIN_STN_FILE, boost::program_options::value<std::string>(&p.r.bst_file),
474✔
342
                                "Binary station file name. Overrides network name.")
343
                        (BIN_MSR_FILE, boost::program_options::value<std::string>(&p.r.bms_file),
474✔
344
                                "Binary measurement file name. Overrides network name.")
345
                        ;
346

347
                transformation_options.add_options()
474✔
348
                        (REFERENCE_FRAME_R, boost::program_options::value<std::string>(&p.r.reference_frame), 
474✔
349
                                "Target reference frame for all stations and datum-dependent measurements.")
350
                        (EPOCH_E, boost::program_options::value<std::string>(&p.r.epoch),
474✔
351
                                "Projected date for the transformed stations and measurements. arg is a dot delimited string \"dd.mm.yyyy\", or \"today\" if today's date is required. If no date is supplied, the reference epoch of the supplied reference frame will be used.")
352
                        (TECTONIC_PLATE_MODEL_OPTION, boost::program_options::value<UINT16>(&p.r.plate_model_option),
474✔
353
                                std::string("Plate motion model option.\n"
948✔
354
                                        "  0: Assume all stations are on the Australian plate (default)\n"
355
                                        "  1: Interpolate plate motion model parameters from a defined\n"
356
                                        "     set of global tectonic plates. For this option, a global\n"
357
                                        "     tectonic plate boundary file and corresponding Euler\n"
358
                                        "     pole parameters file must be provided.").c_str())
359
                        (TECTONIC_PLATE_BDY_FILE_B, boost::program_options::value<std::string>(&p.r.tpb_file),
474✔
360
                                std::string("Global tectonic plate boundaries.").c_str())
948✔
361
                        (TECTONIC_PLATE_POLE_FILE_M, boost::program_options::value<std::string>(&p.r.tpp_file), 
474✔
362
                                std::string("Euler pole parameters corresponding to the global tectonic plate boundaries supplied with option --" +
1,896✔
363
                                        StringFromT(TECTONIC_PLATE_BDY_FILE) +
948✔
364
                                        ".").c_str())
365
                        ;
366

367
                export_options.add_options()
474✔
368
                        (EXPORT_XML_FILES,
474✔
369
                                "Export transformed stations and measurements to DynaML (DynAdjust XML) format.")
370
                        (EXPORT_SINGLE_XML_FILE,
474✔
371
                                "Create a single DynaML file for stations and measurements.")
372
                        (EXPORT_DNA_FILES,
474✔
373
                                "Export transformed stations and measurements to DNA STN and MSR format.")
374
                        //(EXPORT_SNX_FILE,
375
                        //        "Export transformed station coordinates and full variance matrix to SINEX file.")
376
                        ;
377

378
                generic_options.add_options()
474✔
379
                        (VERBOSE, boost::program_options::value<UINT16>(&p.g.verbose),
474✔
380
                                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())
948✔
381
                        (QUIET,
474✔
382
                                std::string("Suppresses all explanation of what ").append(__BINARY_NAME__).append(" is doing unless an error occurs").c_str())
948✔
383
                        (VERSION_V, "Display the current program version")
474✔
384
                        (HELP_H, "Show this help message")
474✔
385
                        (HELP_MODULE_H, boost::program_options::value<std::string>(),
474✔
386
                                "Provide help for a specific help category.")
387
                        ;
388

389
                allowable_options.add(standard_options).add(transformation_options).add(export_options).add(generic_options);
474✔
390

391
                // add "positional options" to handle command line tokens which have no option name
392
                positional_options.add(NETWORK_NAME, -1);
474✔
393
                
394
                boost::program_options::command_line_parser parser(argc, argv);
474✔
395
                store(parser.options(allowable_options).positional(positional_options).run(), vm);
474✔
396
                notify(vm);
472✔
397
        } 
2✔
398
        catch (const std::exception& e) {
2✔
399
                std::cout << "- Error: " << e.what() << std::endl;
2✔
400
                std::cout << cmd_line_banner << allowable_options << std::endl;
2✔
401
                return EXIT_FAILURE;
2✔
402
        }
2✔
403
        catch (...) 
×
404
        {
NEW
405
                std::cout << "+ Exception of unknown type!\n";
×
406
                return EXIT_FAILURE;
×
407
        }
×
408

409
        if (argc < 2)
472✔
410
        {
411
                std::cout << std::endl << "- Nothing to do - no options provided. " << std::endl << std::endl;  
1✔
412
                std::cout << cmd_line_banner << allowable_options << std::endl;
1✔
413
                return EXIT_FAILURE;
414
        }
415

416
        if (vm.count(VERSION))
942✔
417
        {
418
                std::cout << cmd_line_banner << std::endl;
1✔
419
                return EXIT_SUCCESS;
420
        }
421

422
        if (vm.count(HELP))
940✔
423
        {
424
                std::cout << cmd_line_banner << allowable_options << std::endl;
1✔
425
                return EXIT_SUCCESS;
426
        }
427

428
        if (vm.count(HELP_MODULE))
938✔
429
        {
430
                std::cout << cmd_line_banner;
5✔
431
                std::string original_text = vm[HELP_MODULE].as<std::string>();
15✔
432
                std::string help_text = str_upper<std::string>(original_text);
5✔
433

434
                if (str_upper<std::string, char>(ALL_MODULE_STDOPT).find(help_text) != std::string::npos) {
15✔
435
                        std::cout << standard_options << std::endl;
1✔
436
                }
437
                else if (str_upper<std::string, char>(REFTRAN_MODULE_TRANSFORM).find(help_text) != std::string::npos) {
12✔
438
                        std::cout << transformation_options << std::endl;
1✔
439
                }
440
                else if (str_upper<std::string, char>(ALL_MODULE_EXPORT).find(help_text) != std::string::npos) {
9✔
441
                        std::cout << export_options << std::endl;
1✔
442
                }
443
                else if (str_upper<std::string, char>(ALL_MODULE_GENERIC).find(help_text) != std::string::npos) {
6✔
444
                        std::cout << generic_options << std::endl;
1✔
445
                }
446
                else {
447
                        std::cout << std::endl << "- Error: Help module '" <<
1✔
448
                                original_text << "' is not in the list of options." << std::endl;
5✔
449
                        return EXIT_FAILURE;
450
                }
451

452
                return EXIT_SUCCESS;
4✔
453
        }
10✔
454

455
        if (vm.count(TECTONIC_PLATE_MODEL_OPTION))
928✔
456
        {
457
                if (!vm.count(TECTONIC_PLATE_BDY_FILE))
40✔
458
                {
NEW
459
                        std::cout << std::endl << "- Error: A plate boundary file must be supplied in order to interpolate plate motion model parameters. See command line help for further information." << std::endl;
×
460
                        return EXIT_FAILURE;
461
                }
462

463
                if (!vm.count(TECTONIC_PLATE_POLE_FILE))
40✔
464
                {
NEW
465
                        std::cout << std::endl << "- Error: A Euler pole parameters file must be supplied in order to interpolate plate motion model parameters. See command line help for further information." << std::endl;
×
466
                        return EXIT_FAILURE;
467
                }
468
        }
469

470
        // Test for a valid reference frame label
471
        UINT32 epsgCode;
464✔
472
        try {
464✔
473
                epsgCode = epsgCodeFromName<UINT32>(p.r.reference_frame);
464✔
474
        }
475
        catch (const std::runtime_error& e) {
1✔
476
                std::cout << std::endl << cmd_line_banner;
1✔
477
                
478
                std::cout << "- Error: " << e.what() << std::endl;
1✔
479
                return EXIT_FAILURE;
1✔
480
        }
1✔
481

482
        if (ParseCommandLineOptions(argc, argv, vm, p, epsgCode) != EXIT_SUCCESS)
463✔
483
                return EXIT_FAILURE;
484

485
        // If the reference frame supplied is static, then force the epoch
486
        // to be the reference epoch
487
        if (isEpsgDatumStatic(epsgCode))
458✔
488
                p.r.epoch = referenceepochFromEpsgCode<UINT32>(epsgCode);
124✔
489

490
        std::ofstream rft_file;
458✔
491
        try {
458✔
492
                // Create import log file.  Throws runtime_error on failure.
493
                file_opener(rft_file, p.r.rft_file);
458✔
494
        }
NEW
495
        catch (const std::runtime_error& e) {
×
NEW
496
                std::stringstream ss;
×
NEW
497
                ss << "- Error: Could not open " << p.r.rft_file << ". \n  Check that the file exists and that the file is not already opened." << std::endl;
×
NEW
498
                std::cout << ss.str() << e.what() << std::endl;
×
499
                return EXIT_FAILURE;
×
500
        }
×
501

502

503

504
        if (vm.count(QUIET))
916✔
505
                p.g.quiet = 1;
×
506

507
        if (!p.g.quiet)
458✔
508
        {
509
                std::cout << std::endl << cmd_line_banner;
458✔
510
        
511
                std::cout << "+ Options:" << std::endl; 
458✔
512
                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Network name: " <<  p.g.network_name << std::endl;
458✔
513
                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Input folder: " << p.g.input_folder << std::endl;
458✔
514
                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Output folder: " << p.g.output_folder << std::endl;
458✔
515
                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Binary station file: " << p.r.bst_file << std::endl;
458✔
516
                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Binary measurement file: " << p.r.bms_file << std::endl;
458✔
517
                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Target reference frame: " << p.r.reference_frame;
458✔
518
                if (vm.count(REFERENCE_FRAME))
916✔
519
                        std::cout << " (user supplied)" << std::endl;
440✔
520
                else
521
                        std::cout << " (project reference frame)" << std::endl;
18✔
522

523
                // try to parse user supplied string.  If this fails, then there's not much point in attempting
524
                // to transform stations and measurements
525
                try 
458✔
526
                {
527
                        if (!p.r.epoch.empty())
458✔
528
                        {        
529
                                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Target epoch: " << p.r.epoch;
458✔
530
                                if (isEpsgDatumStatic(epsgCode))
458✔
531
                                        std::cout << " (adopted reference epoch of " << p.r.reference_frame << ")";
62✔
532
                                else
533
                                {
534
                                        if (vm.count(EPOCH))
792✔
535
                                                std::cout << " (user supplied)" << std::endl;
7✔
536
                                        else
537
                                        {
538
                                                if (vm.count(REFERENCE_FRAME))
778✔
539
                                                        std::cout << " (adopted reference epoch of " << p.r.reference_frame << ")" << std::endl;
374✔
540
                                                else
541
                                                        std::cout << " (project epoch)" << std::endl;
15✔
542
                                        }
543
                                }
544
                                std::cout << std::endl;                                
458✔
545
                        }
546
                }
NEW
547
                catch (const std::runtime_error& e) {
×
NEW
548
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
UNCOV
549
                        rft_file.close();
×
UNCOV
550
                        return EXIT_FAILURE;
×
UNCOV
551
                }
×
552
                catch (const RefTranException& e) {
×
NEW
553
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
554
                        rft_file.close();
×
555
                        return EXIT_FAILURE;
×
556
                }
×
557
                catch (...) {
×
NEW
558
                        std::cout << std::endl << "- Error: Unknown error." << std::endl;
×
559
                        rft_file.close();
×
560
                        return EXIT_FAILURE;
×
561
                }
×
562

563
                if (p.r.plate_model_option > 0)
458✔
564
                {
565
                        std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Plate boundaries file: " << p.r.tpb_file << std::endl;
20✔
566
                        std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  Plate pole parameter file: " << p.r.tpp_file << std::endl;
20✔
567
                }
568

569
                // Export options
570
                if (p.i.export_dynaml)
458✔
571
                {
572
                        if (p.i.export_single_xml_file)
5✔
573
                                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  DynaML output file: " << p.i.xml_outfile << std::endl;
2✔
574
                        else
575
                        {
576
                                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  DynaML station file: " << p.i.xml_stnfile << std::endl;
3✔
577
                                std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  DynaML measurement file: " << p.i.xml_msrfile << std::endl;
3✔
578
                        }                                
579
                }
580
                if (p.i.export_dna_files)
458✔
581
                {
582
                        std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  DNA station file: " << p.i.dna_stnfile << std::endl;
5✔
583
                        std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  DNA measurement file: " << p.i.dna_msrfile << std::endl;
5✔
584
                }
585

586
//                if (p.o._export_snx_file)
587
//                        std::cout << std::setw(PRINT_VAR_PAD) << std::left << "  SINEX file: " << p.o._snx_file << std::endl;
588

589
                std::cout << std::endl;
458✔
590
        }
591

592
        PrintOutputFileHeaderInfo(&rft_file, p.r.rft_file, &p, "DYNADJUST REFTRAN LOG FILE", epsgCode, vm.count(REFERENCE_FRAME), vm.count(EPOCH));
1,832✔
593

594
        dna_reftran refTran(p, &rft_file);
458✔
595
        std::stringstream ss_msg;
458✔
596

597
        // Load plate boundary and euler pole information
598
        if (vm.count(TECTONIC_PLATE_MODEL_OPTION))
916✔
599
        {
600
                ss_msg << "+ Loading global tectonic plate boundaries and plate motion information... ";
20✔
601

602
                if (!p.g.quiet)
20✔
603
                        std::cout << ss_msg.str();                
40✔
604
                rft_file << ss_msg.str();
20✔
605
        
606
                try
20✔
607
                {
608
                        refTran.LoadTectonicPlateParameters(p.r.tpb_file, p.r.tpp_file);
20✔
609
                }
NEW
610
                catch (const std::runtime_error& e) {
×
NEW
611
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
NEW
612
                        rft_file << std::endl << "- Error: " << e.what() << std::endl;
×
613
                        rft_file.close();
×
614
                        return EXIT_FAILURE;
×
615
                }
×
616

617
                if (!p.g.quiet)
20✔
618
                        std::cout << "done." << std::endl;
20✔
619

620
                if (p.g.verbose == 0)
20✔
NEW
621
                        rft_file << "done." << std::endl;
×
622
                else
623
                        rft_file << std::endl << "+ Done." << std::endl << std::endl;
20✔
624
        }
625

626
        ss_msg.str("");
1,374✔
627
        ss_msg << "+ Transforming stations and measurements... ";
458✔
628
        if (!p.g.quiet)
458✔
629
                std::cout << ss_msg.str();                
916✔
630
        rft_file << ss_msg.str();
458✔
631

632
        ss_msg.str("");
1,374✔
633

634
        try
458✔
635
        {
636
                // Transform binary station file
637
                refTran.TransformBinaryFiles(p.r.bst_file, p.r.bms_file,
458✔
638
                        p.r.reference_frame, p.r.epoch);
639
        }
640
        catch (const std::runtime_error& e) {
1✔
641
                std::cout << std::endl << "- Error: " << e.what() << std::endl;
1✔
642
                rft_file << std::endl << "- Error: " << e.what() << std::endl;
1✔
643
                rft_file.close();
1✔
644
                return EXIT_FAILURE;
1✔
645
        }
1✔
646
        catch (const RefTranException& e) {
×
647
                switch (e.exception_type())
×
648
                {
UNCOV
649
                case REFTRAN_WGS84_TRANS_UNSUPPORTED:
×
UNCOV
650
                        break;
×
651
                }
NEW
652
                std::cout << std::endl << std::endl << "- Error: " << e.what() << std::endl;
×
NEW
653
                rft_file << std::endl << std::endl << "- Error: " << e.what() << std::endl;
×
654
                rft_file.close();
×
655
                return EXIT_FAILURE;
×
656
        }
×
657
        catch (...) {
×
NEW
658
                std::cout << std::endl << "- Error: Unknown error." << std::endl;
×
NEW
659
                rft_file << std::endl << "- Error: Unknown error." << std::endl;
×
660
                rft_file.close();
×
661
                return EXIT_FAILURE;
×
662
        }
×
663
        
664
        if (!p.g.quiet)
457✔
665
                std::cout << "done." << std::endl;
457✔
666

667
        if (p.g.verbose == 0)
457✔
668
                rft_file << "done." << std::endl;
432✔
669
        else
670
                rft_file << std::endl << "+ Done." << std::endl << std::endl;
25✔
671
        
672
        ss_msg.str("");
1,371✔
673

674
        // Station summary
675
        if (refTran.StationsTransformed())
457✔
676
        {
677
                ss_msg << "+ Transformed " << refTran.StationsTransformed();
455✔
678
        
679
                if (refTran.StationsTransformed() == 1)
455✔
NEW
680
                        ss_msg << " station." << std::endl;
×
681
                else
682
                        ss_msg << " stations." << std::endl;
455✔
683
        }
684
        else
685
                ss_msg << "+ No stations were transformed." << std::endl;
2✔
686
        
687
        if (!p.g.quiet)
457✔
688
                std::cout << ss_msg.str();
914✔
689
        rft_file << ss_msg.str();
457✔
690

691
        ss_msg.str("");
1,371✔
692

693
        if (refTran.StationsNotTransformed() > 0)
457✔
694
        {
695
                if (refTran.StationsTransformed())
2✔
696
                        ss_msg << "+ Note: ";
×
697
                else
698
                        ss_msg << "  ";
2✔
699

700
                ss_msg << refTran.StationsNotTransformed();
2✔
701
                if (refTran.StationsNotTransformed() == 1)
2✔
702
                        ss_msg << " station was";
×
703
                else
704
                        ss_msg << " stations were";
2✔
705

706
                ss_msg << " already referenced to " << p.r.reference_frame;
2✔
707
                if (!isEpsgDatumStatic(epsgCode))
2✔
708
                {
NEW
709
                        if (!p.r.epoch.empty())
×
NEW
710
                                ss_msg << ", epoch " << p.r.epoch;
×
711
                }
712
                ss_msg << std::endl;
2✔
713
        }
714

715
        if (!p.g.quiet)
457✔
716
                std::cout << ss_msg.str();
914✔
717
        rft_file << ss_msg.str();
457✔
718

719
        ss_msg.str("");
1,371✔
720

721
        // Measurement summary
722
        if (refTran.MeasurementsTransformed())
457✔
723
        {
724
                ss_msg << "+ Transformed " << refTran.MeasurementsTransformed();
456✔
725
        
726
                if (refTran.MeasurementsTransformed() == 1)
456✔
NEW
727
                        ss_msg << " measurement." << std::endl;
×
728
                else
729
                        ss_msg << " measurements." << std::endl;
456✔
730
        }
731
        else
732
                ss_msg << "+ No measurements were transformed." << std::endl;
1✔
733

734
        if (!p.g.quiet)
457✔
735
                std::cout << ss_msg.str();
914✔
736
        rft_file << ss_msg.str();
457✔
737

738
        ss_msg.str("");
1,371✔
739

740
        if (refTran.MeasurementsNotTransformed() > 0)
457✔
741
        {
742
                if (refTran.MeasurementsTransformed())
2✔
743
                        ss_msg << "+ Note: ";
1✔
744
                else
745
                        ss_msg << "  ";
1✔
746

747
                ss_msg << refTran.MeasurementsNotTransformed();
2✔
748
                if (refTran.MeasurementsNotTransformed() == 1)
2✔
749
                        ss_msg << " measurement was";
×
750
                else
751
                        ss_msg << " measurements were";
2✔
752

753
                ss_msg << " already referenced to " << p.r.reference_frame;
2✔
754
                if (!isEpsgDatumStatic(epsgCode))
2✔
755
                {
NEW
756
                        if (!p.r.epoch.empty())
×
NEW
757
                                ss_msg << ", epoch " << p.r.epoch;
×
758
                }
759
                ss_msg << std::endl;
2✔
760
        }
761
        
762
        if (!p.g.quiet)
457✔
763
                std::cout << ss_msg.str() << std::endl;
914✔
764
        rft_file << ss_msg.str() << std::endl;
457✔
765

766
        ss_msg.str("");
1,371✔
767

768
        if (p.i.export_dynaml) 
457✔
769
        {
770
                try {
5✔
771
                        
772
                        if (p.i.export_single_xml_file)
5✔
773
                        {
774
                                // Single output file
775
                                if (!p.g.quiet)
2✔
776
                                {
777
                                        std::cout << "+ Exporting stations and measurements to " << leafStr<std::string>(p.i.xml_outfile) << "... ";
4✔
778
                                        std::cout.flush();
2✔
779
                                        rft_file << "+ Exporting stations and measurements to " << leafStr<std::string>(p.i.xml_outfile) << "... ";
6✔
780
                                }
781
                                refTran.SerialiseDynaML(
2✔
782
                                        p.i.xml_outfile, 
783
                                        (p.i.flag_unused_stn ? true : false));        
2✔
784
                        }
785
                        else
786
                        {
787
                                // Separate output files (default)
788
                                if (!p.g.quiet)
3✔
789
                                {
790
                                        std::cout << "+ Exporting stations and measurements to:" << std::endl << 
3✔
791
                                                "  - " << leafStr<std::string>(p.i.xml_stnfile) << std::endl <<
6✔
792
                                                "  - " << leafStr<std::string>(p.i.xml_msrfile) << "... ";
9✔
793
                                        std::cout.flush();
3✔
794
                                        rft_file << "+ Exporting stations and measurements to:" << std::endl <<
3✔
795
                                                "  - " << leafStr<std::string>(p.i.xml_stnfile) << std::endl <<
9✔
796
                                                "  - " << leafStr<std::string>(p.i.xml_msrfile) << "... ";
9✔
797
                                }
798
                                refTran.SerialiseDynaML(
3✔
799
                                        p.i.xml_stnfile, p.i.xml_msrfile, 
800
                                        (p.i.flag_unused_stn ? true : false));        
3✔
801
                        }
802

803
                        if (!p.g.quiet)
5✔
804
                        {
805
                                std::cout << "done." << std::endl;
5✔
806
                                std::cout.flush();
5✔
807
                        }
808

809
                        rft_file << "done." << std::endl;
5✔
810
                        
811
                }
812
                catch (const XMLInteropException& e) {
×
NEW
813
                        std::cout.flush();
×
NEW
814
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
NEW
815
                        rft_file << std::endl << "- Error: " << e.what() << std::endl;
×
816
                        rft_file.close();
×
817
                        return EXIT_FAILURE;
×
818
                }
×
819
        }
820

821
        if (p.i.export_dna_files) 
457✔
822
        {
823
                try {
5✔
824
                        // Separate output files (default)
825
                        if (!p.g.quiet)
5✔
826
                        {
827
                                std::cout << "+ Exporting stations and measurements to:" << std::endl <<
5✔
828
                                        "  - " << leafStr<std::string>(p.i.dna_stnfile) << std::endl <<
10✔
829
                                        "  - " << leafStr<std::string>(p.i.dna_msrfile) << "... ";
15✔
830
                                std::cout.flush();
5✔
831
                        }
832
                        rft_file << "+ Exporting stations and measurements to:" << std::endl <<
5✔
833
                                "  - " << leafStr<std::string>(p.i.dna_stnfile) << std::endl <<
10✔
834
                                "  - " << leafStr<std::string>(p.i.dna_msrfile) << "... ";
15✔
835
                                
836
                        refTran.SerialiseDNA(
5✔
837
                                p.i.dna_stnfile, p.i.dna_msrfile, 
838
                                (p.i.flag_unused_stn ? true : false));
5✔
839
                        
840
                        if (!p.g.quiet)
5✔
841
                                std::cout << "Done." << std::endl;
5✔
842
                        rft_file << "Done." << std::endl;
5✔
843
                }
844
                catch (const XMLInteropException& e) {
×
NEW
845
                        std::cout.flush();
×
NEW
846
                        std::cout << std::endl << "- Error: " << e.what() << std::endl;
×
NEW
847
                        rft_file << std::endl << "- Error: " << e.what() << std::endl;
×
848
                        rft_file.close();
×
849
                        return EXIT_FAILURE;
×
850
                }
×
851
        }
852

853
//        // Print adjusted stations and measurements to SINEX
854
//        if (p.o._export_snx_file)
855
//        {
856
//                // Export to SINEX
857
//                if (!p.g.quiet)
858
//                        std::cout << "+ Exporting stations and measurements to " << 
859
//                                leafStr<std::string>(p.o._snx_file) << "... ";
860
//                std::cout.flush();
861
//                rft_file << "+ Exporting stations and measurements to " << 
862
//                        leafStr<std::string>(p.o._snx_file) << "... ";
863
//
864
//                bool success(refTran.PrintTransformedStationCoordinatestoSNX());
865
//
866
//                // SomeFunc()
867
//                if (!p.g.quiet)
868
//                        std::cout << " done." << std::endl;
869
//                rft_file << " done." << std::endl;
870
//
871
//                ss_msg.str("");
872
//
873
//                if (!success)
874
//                {
875
//                        ss_msg << "- Warning: The SINEX export process produced some warnings." << std::endl;
876
//                        ss_msg << "  See " << p.g.network_name << "*.snx.err for details." << std::endl; 
877
//                }
878
//                std::cout << ss_msg.str();
879
//                rft_file << ss_msg.str();
880
//        }
881

882
        if (!p.g.quiet)
457✔
883
        {
884
                std::cout << std::endl;
457✔
885
        }
886

887
        // Look for a project file.  If it exists, open and load it.
888
        // Update the import settings.
889
        // Print the project file. If it doesn't exist, it will be created.
890
        CDnaProjectFile projectFile;
914✔
891
        if (boost::filesystem::exists(p.g.project_file))
914✔
892
                projectFile.LoadProjectFile(p.g.project_file);
457✔
893
        
894
        projectFile.UpdateSettingsReftran(p);
457✔
895
        projectFile.PrintProjectFile();
457✔
896

897
        rft_file.close();
457✔
898
        return REFTRAN_SUCCESS;
457✔
899
}
1,422✔
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