• 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

75.84
/dynadjust/include/io/dnaioaml.cpp
1
//============================================================================
2
// Name         : dnaioaml.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  : DynAdjust associated measurement file io operations
21
//============================================================================
22

23
#include <include/io/dnaioaml.hpp>
24
#include <include/functions/dnatemplatestnmsrfuncs.hpp>
25
#include <include/functions/dnaiostreamfuncs.hpp>
26

27
namespace dynadjust { 
28
namespace iostreams {
29

30
void dna_io_aml::load_aml_file(const std::string& aml_filename, v_aml_pair* vbinary_aml, pvmsr_t bmsRecords)
23✔
31
{        
32
        std::ifstream aml_file;
23✔
33
        std::stringstream ss;
23✔
34
        ss << "load_aml_file(): An error was encountered when opening " << aml_filename << "." << std::endl;
23✔
35

36
        try {
23✔
37
                // open stations aml file.  Throws runtime_error on failure.
38
                file_opener(aml_file, aml_filename, std::ios::in | std::ios::binary, binary, true);
23✔
39
        }
NEW
40
        catch (const std::runtime_error& e) {
×
41
                ss << e.what();
×
NEW
42
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
43
        }
×
44
        catch (...) {
×
NEW
45
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
46
        }
×
47
        
48
        ss.str("");
69✔
49
        ss << "load_aml_file(): An error was encountered when reading from " << aml_filename << "." << std::endl;
23✔
50

51
        UINT32 msrValue;
23✔
52
        
53
        try {
23✔
54
                // read the file information
55
                readFileInfo(aml_file);
23✔
56
                
57
                // Get number of records and resize AML vector
58
                aml_file.read(reinterpret_cast<char *>(&msrValue), sizeof(UINT32));
23✔
59
                
60
                vbinary_aml->clear();
23✔
61
                vbinary_aml->resize(msrValue);
23✔
62

63
                it_aml_pair _it_aml;
23✔
64

65
                for (_it_aml = vbinary_aml->begin(); 
18,852✔
66
                        _it_aml != vbinary_aml->end();
18,852✔
67
                        ++_it_aml)
18,829✔
68
                {
69
                        aml_file.read(reinterpret_cast<char *>(&msrValue), sizeof(UINT32));
18,829✔
70
                        // Ignored measurements are retained in the AML, so consume them!
71
                        _it_aml->bmsr_index = msrValue;
18,829✔
72
                        if (bmsRecords->at(msrValue).ignore)
18,829✔
73
                                _it_aml->consume();
664✔
74
                }
75

76
        }
NEW
77
        catch (const std::ios_base::failure& f) {
×
78
                ss << f.what();
×
NEW
79
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
80
        }
×
NEW
81
        catch (const std::runtime_error& e) {
×
82
                ss << e.what();
×
NEW
83
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
84
        }
×
85
        catch (...) {
×
NEW
86
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
87
        }
×
88

89
        aml_file.close();
23✔
90
}
23✔
91

92
void dna_io_aml::write_aml_file(const std::string& aml_filename, pvUINT32 vbinary_aml) 
80✔
93
{        
94
        std::ofstream aml_file;
80✔
95
        std::stringstream ss;
80✔
96
        ss << "write_aml_file(): An error was encountered when opening " << aml_filename << "." << std::endl;
80✔
97

98
        try {
80✔
99
                // create binary aml file.  Throws runtime_error on failure.
100
                file_opener(aml_file, aml_filename,
80✔
101
                        std::ios::out | std::ios::binary, binary);
102
        }
NEW
103
        catch (const std::runtime_error& e) {
×
104
                ss << e.what();
×
NEW
105
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
106
        }
×
107
        catch (...) {
×
NEW
108
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
109
        }
×
110
        
111
        ss.str("");
240✔
112
        ss << "write_aml_file(): An error was encountered when writing to " << aml_filename << "." << std::endl;
80✔
113

114
        // Calculate number of measurement records and write to binary file
115
        UINT32 amlCount(static_cast<UINT32>(vbinary_aml->size()));
80✔
116
        it_vUINT32 _it_aml;
80✔
117
        
118
        try {
80✔
119
                // write the file information
120
                writeFileInfo(aml_file);
80✔
121
                
122
                // write the data
123
                aml_file.write(reinterpret_cast<char *>(&amlCount), sizeof(UINT32));
80✔
124
                for (_it_aml = vbinary_aml->begin(); 
104,507✔
125
                        _it_aml != vbinary_aml->end();
104,507✔
126
                        ++_it_aml)
104,427✔
127
                {
128
                        aml_file.write(reinterpret_cast<char *>(&(*_it_aml)), sizeof(UINT32));
104,427✔
129
                }
130
        }
NEW
131
        catch (const std::ios_base::failure& f) {
×
132
                ss << f.what();
×
NEW
133
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
134
        }
×
NEW
135
        catch (const std::runtime_error& e) {
×
136
                ss << e.what();
×
NEW
137
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
138
        }
×
139
        catch (...) {
×
NEW
140
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
141
        }
×
142
        
143
        aml_file.close();
80✔
144
}
80✔
145

146
void dna_io_aml::create_msr_to_stn_tally(const pvASLPtr vAssocStnList, v_aml_pair& vAssocMsrList, 
6✔
147
        vmsrtally& stnmsrTally, vmsr_t& bmsBinaryRecords)
148
{        
149
        stnmsrTally.clear();
6✔
150
        stnmsrTally.resize(vAssocStnList->size());
6✔
151

152
        vASLPtr::iterator _it_asl;
6✔
153
        UINT32 i, m, amlIndex, msrCount;
6✔
154

155
        for (_it_asl=vAssocStnList->begin(), i=0; _it_asl!=vAssocStnList->end(); ++_it_asl, ++i)
447✔
156
        {
157
                msrCount = _it_asl->get()->GetAssocMsrCount();
441✔
158

159
                for (m=0; m<msrCount; ++m)
6,282✔
160
                {
161
                        amlIndex = _it_asl->get()->GetAMLStnIndex() + m;
5,841✔
162

163
                        if (bmsBinaryRecords.at(vAssocMsrList.at(amlIndex).bmsr_index).ignore)
5,841✔
164
                                continue;
74✔
165

166
                        stnmsrTally.at(i).IncrementMsrType(bmsBinaryRecords.at(vAssocMsrList.at(amlIndex).bmsr_index).measType);
5,767✔
167
                }
168

169
                stnmsrTally.at(i).TotalCount();
441✔
170
        }
171
}
6✔
172
        
173
        
174
void dna_io_aml::write_msr_to_stn(std::ostream &os, pvstn_t bstBinaryRecords, 
6✔
175
        pvUINT32 vStationList, vmsrtally& v_stnmsrTally, MsrTally* parsemsrTally)
176
{
177
        // Print measurement to station summary header
178
        std::string header("MEASUREMENT TO STATIONS ");
6✔
179
        MsrToStnSummaryHeader(os, header);
6✔
180

181
        it_vUINT32 _it_stn(vStationList->begin());
6✔
182

183
        UINT32 msrRedundancies(0);
6✔
184
        vstring stationRedundantMsrs;
6✔
185

186
        // Print measurements to each station and the total count for each station
187
        for (_it_stn=vStationList->begin(); _it_stn != vStationList->end(); ++_it_stn)
447✔
188
        {
189
                v_stnmsrTally.at(*_it_stn).coutSummaryMsrToStn(os, bstBinaryRecords->at(*_it_stn).stationName);
882✔
190

191
                // Test for possible redundancies
192
                if ((v_stnmsrTally.at(*_it_stn).MeasurementCount('G') ||
715✔
193
                        v_stnmsrTally.at(*_it_stn).MeasurementCount('X') ||
543✔
194
                        v_stnmsrTally.at(*_it_stn).MeasurementCount('Y')) 
269✔
195
                        &&
616✔
196
                        (v_stnmsrTally.at(*_it_stn).MeasurementCount('P') ||
349✔
197
                        v_stnmsrTally.at(*_it_stn).MeasurementCount('Q') ||
348✔
198
                        v_stnmsrTally.at(*_it_stn).MeasurementCount('R') ||
348✔
199
                        v_stnmsrTally.at(*_it_stn).MeasurementCount('H') ||
345✔
200
                        v_stnmsrTally.at(*_it_stn).MeasurementCount('I') ||
342✔
201
                        v_stnmsrTally.at(*_it_stn).MeasurementCount('J')))
608✔
202
                {
203
                        msrRedundancies++;
4✔
204
                        stationRedundantMsrs.push_back(bstBinaryRecords->at(*_it_stn).stationName);
12✔
205
                }
206
        }
207
        
208
        // Print "the bottom line"
209
        MsrToStnSummaryHeaderLine(os);
6✔
210
        
211
        // Print the total count per measurement        
212
        parsemsrTally->coutSummaryMsrToStn(os, "Totals");
12✔
213

214
        os << std::endl << std::endl;
6✔
215

216
        if (msrRedundancies > 0)
6✔
217
        {
218
                os << "WARNING: " << msrRedundancies;
3✔
219
                if (msrRedundancies == 1)
3✔
220
                        os << " station was";
2✔
221
                else
222
                        os << " stations were";
1✔
223

224
                os << " found to have GNSS measurements and absolute terrestrial measurements:" << std::endl << std::endl;
3✔
225
                
226
                // Print header
227
                os << std::setw(STATION) << std::left << "Station" << std::setw(30) << "Measurement types" << "Count" << std::endl;
3✔
228
                os << "------------------------------------------------------------" << std::endl;
3✔
229

230
                // Print measurements to each station and the total count for each station
231
                for (_it_stn=vStationList->begin(); _it_stn != vStationList->end(); ++_it_stn)
315✔
232
                {
233
                        // Test for possible redundancies
234
                        if ((v_stnmsrTally.at(*_it_stn).MeasurementCount('G') ||
586✔
235
                                v_stnmsrTally.at(*_it_stn).MeasurementCount('X') ||
543✔
236
                                v_stnmsrTally.at(*_it_stn).MeasurementCount('Y')) 
269✔
237
                                &&
358✔
238
                                (v_stnmsrTally.at(*_it_stn).MeasurementCount('P') ||
91✔
239
                                v_stnmsrTally.at(*_it_stn).MeasurementCount('Q') ||
90✔
240
                                v_stnmsrTally.at(*_it_stn).MeasurementCount('R') ||
90✔
241
                                v_stnmsrTally.at(*_it_stn).MeasurementCount('H') ||
87✔
242
                                v_stnmsrTally.at(*_it_stn).MeasurementCount('I') ||
84✔
243
                                v_stnmsrTally.at(*_it_stn).MeasurementCount('J')))
350✔
244
                        {
245
                                v_stnmsrTally.at(*_it_stn).coutSummaryMsrToStn_Compressed(os, bstBinaryRecords->at(*_it_stn).stationName);
8✔
246
                        }
247
                }        
248
        }
249
}
12✔
250
        
251

252
void dna_io_aml::write_aml_file_txt(const std::string& bms_filename, const std::string& aml_filename, pvUINT32 vbinary_aml, const pvASLPtr vAssocStnList, vdnaStnPtr* vStations)
5✔
253
{        
254
        vmsr_t binaryMsrRecords;
5✔
255
        std::stringstream ss;
5✔
256
        ss << "write_aml_file(): An error was encountered when opening " << bms_filename << "." << std::endl;
5✔
257

258
        binary_file_meta_t bms_meta;
5✔
259
        try {
5✔
260
                dna_io_bms bms;
5✔
261
                // Load binary stations data.  Throws runtime_error on failure.
262
                bms.load_bms_file(bms_filename, &binaryMsrRecords, bms_meta);
5✔
263
        }
×
NEW
264
        catch (const std::runtime_error& e) {
×
265
                ss << e.what();
×
NEW
266
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
267
        }
×
268
        catch (...) {
×
NEW
269
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
270
        }
×
271

272
        std::ofstream aml_file;
5✔
273
        ss.str("");
15✔
274
        ss << "write_aml_file(): An error was encountered when opening " << aml_filename << "." << std::endl;
5✔
275

276
        try {
5✔
277
                // create binary aml file.  Throws runtime_error on failure.
278
                file_opener(aml_file, aml_filename,
5✔
279
                        std::ios::out | std::ios::binary, binary);
280
        }
NEW
281
        catch (const std::runtime_error& e) {
×
282
                ss << e.what();
×
NEW
283
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
284
        }
×
285
        catch (...) {
×
NEW
286
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
287
        }
×
288
        
289
        ss.str("");
15✔
290
        ss << "write_aml_file(): An error was encountered when writing to " << aml_filename << "." << std::endl;
5✔
291

292
        // Write number of measurement records to file
293
        std::stringstream ss_aml;
5✔
294
        ss_aml << vbinary_aml->size() << " records";
5✔
295
        aml_file << std::left << std::setw(HEADER_18) << ss_aml.str();
5✔
296
        aml_file << std::left << std::setw(MSR) << "Msr index";
5✔
297
        aml_file << std::left << std::setw(MSR) << "Msr type";
5✔
298
        aml_file << std::left << std::setw(MSR) << "Cluster";
5✔
299
        aml_file << std::left << std::setw(MSR) << "Ignored msr?" << std::endl;
5✔
300

301
        it_vUINT32_const _it_aml(vbinary_aml->begin());
5✔
302
        
303
        UINT32 stn_index(0);
5✔
304

305
        UINT32 nextAMLStationIndex(vAssocStnList->at(stn_index)->GetAMLStnIndex() + vAssocStnList->at(stn_index)->GetAssocMsrCount());
5✔
306
        UINT32 currAMLStationIndex(0);
5✔
307
        vUINT32 msrIndices;
5✔
308

309
        it_vUINT32 _it_msr;
5✔
310
        
311
        try {
5,916✔
312
                do
5,916✔
313
                {
314
                        if (stn_index >= vAssocStnList->size())
5,916✔
315
                                break;
316

317
                        if (_it_aml >= vbinary_aml->end())
5,916✔
318
                                break;
319

320
                        // Is the curent station not connected to any measurements?
321
                        if (vAssocStnList->at(stn_index)->GetAssocMsrCount() == 0)
5,916✔
322
                        {
323
                                // Get the index of the next station in the AML
324
                                ++stn_index;
×
325
                                nextAMLStationIndex = vAssocStnList->at(stn_index)->GetAMLStnIndex() + vAssocStnList->at(stn_index)->GetAssocMsrCount();
×
326
                                continue;
×
327
                        }
328

329
                        // Has a new station index been reached?
330
                        if (currAMLStationIndex == nextAMLStationIndex)
5,916✔
331
                        {
332
                                // Get the index of the next station in the AML
333
                                ++stn_index;
382✔
334
                                nextAMLStationIndex = vAssocStnList->at(stn_index)->GetAMLStnIndex() + vAssocStnList->at(stn_index)->GetAssocMsrCount();
382✔
335
                                continue;
382✔
336
                        }
337

338
                        // At this point, the current station is connected to measurements.
339
                        // However, such measurements may be ignored, in which case a station
340
                        // may be unused.
341

342
                        // Print station name
343
                        aml_file << std::setw(HEADER_18) << std::left << vStations->at(stn_index)->GetName();
5,534✔
344
                        
345
                        // print the bmsr index
346
                        // For clusters, this will be the index of the first binary element 
347
                        aml_file <<        std::setw(MSR) << std::left << *_it_aml;
5,534✔
348

349
                        GetMsrIndices<UINT32>(binaryMsrRecords, *_it_aml, msrIndices);
5,534✔
350

351
                        ss_aml.str("");
16,602✔
352
                        ss_aml << binaryMsrRecords.at(*_it_aml).measType;
5,534✔
353

354
                        for (_it_msr=msrIndices.begin(); _it_msr!=msrIndices.end(); ++_it_msr)
11,188✔
355
                        {
356
                                if (stn_index == binaryMsrRecords.at(*_it_msr).station1)
5,654✔
357
                                {
358
                                        // All measurements have a first station
359
                                        ss_aml << std::left << " (First)";
2,535✔
360
                                        aml_file << std::setw(MSR) << std::left << ss_aml.str();
2,535✔
361
                                        ss_aml.str("");
7,605✔
362
                                        switch (binaryMsrRecords.at(*_it_msr).measType)
2,535✔
363
                                        {
364
                                        case 'D': // Direction set
36✔
365
                                        case 'X': // GPS Baseline cluster
36✔
366
                                        case 'Y': // GPS point cluster
36✔
367
                                                ss_aml << std::setw(MSR) << std::left << binaryMsrRecords.at(*_it_msr).clusterID;
36✔
368
                                                break;
369
                                        default:
2,499✔
370
                                                ss_aml << std::setw(MSR) << std::left << " ";
2,499✔
371
                                                break;
372
                                        }
373
                                        continue;
2,535✔
374
                                }
375

376
                                if (MsrTally::Stations(binaryMsrRecords.at(*_it_msr).measType) >= TWO_STATION)
3,119✔
377
                                {
378
                                        // Measurements which have a second or third station
379
                                        switch (binaryMsrRecords.at(*_it_msr).measType)
3,035✔
380
                                        {
381
                                        case 'D': // Direction set
4✔
382
                                                if (stn_index == binaryMsrRecords.at(*_it_msr).station2)
4✔
383
                                                {
384
                                                        if (binaryMsrRecords.at(*_it_msr).vectorCount1 > 0)
2✔
385
                                                                ss_aml << std::left << " (Second)";
1✔
386
                                                        else
387
                                                                ss_aml << std::left << " (Target)";
1✔
388
                                                }
389
                                                aml_file << std::setw(MSR) << std::left << ss_aml.str();
4✔
390
                                                ss_aml.str("");
12✔
391
                                                ss_aml << std::setw(MSR) << std::left << binaryMsrRecords.at(*_it_msr).clusterID;
4✔
392
                                                break;
393
                                        case 'B': // Geodetic azimuth
1,988✔
394
                                        case 'C': // Chord dist
1,988✔
395
                                        case 'E': // Ellipsoid arc
1,988✔
396
                                        case 'G': // GPS Baseline (treat as single-baseline cluster)
1,988✔
397
                                        case 'K': // Astronomic azimuth
1,988✔
398
                                        case 'L': // Level difference
1,988✔
399
                                        case 'M': // MSL arc
1,988✔
400
                                        case 'S': // Slope distance
1,988✔
401
                                        case 'V': // Zenith distance
1,988✔
402
                                        case 'Z': // Vertical angle
1,988✔
403
                                                if (stn_index == binaryMsrRecords.at(*_it_msr).station2)
1,988✔
404
                                                        ss_aml << std::left << " (Second)";
1,988✔
405
                                                aml_file << std::setw(MSR) << std::left << ss_aml.str();
1,988✔
406
                                                ss_aml.str("");
5,964✔
407
                                                ss_aml << std::setw(MSR) << std::left << " ";
1,988✔
408
                                                break;        
409
                                        case 'X': // GPS Baseline cluster
37✔
410
                                                if (stn_index == binaryMsrRecords.at(*_it_msr).station2)
37✔
411
                                                        ss_aml << std::left << " (Second)";
11✔
412
                                                aml_file << std::setw(MSR) << std::left << ss_aml.str();
37✔
413
                                                ss_aml.str("");
111✔
414
                                                ss_aml << std::setw(MSR) << std::left << binaryMsrRecords.at(*_it_msr).clusterID;
5,654✔
415
                                                break;        
416
                                        case 'A': // Horizontal angle
1,006✔
417
                                                if (stn_index == binaryMsrRecords.at(*_it_msr).station2)
1,006✔
418
                                                        ss_aml << std::left << " (Second)";
503✔
419
                                                else if (stn_index == binaryMsrRecords.at(*_it_msr).station3)
503✔
420
                                                        ss_aml << std::left << " (Third)";
503✔
421
                                                aml_file << std::setw(MSR) << std::left << ss_aml.str();
1,006✔
422
                                                ss_aml.str("");
3,018✔
423
                                                ss_aml << std::setw(MSR) << std::left << " ";
1,006✔
424
                                                break;
425
                                        }
426
                                }
427
                        }                        
428

429
                        aml_file << std::setw(MSR) << std::left << ss_aml.str();
5,534✔
430

431
                        if (binaryMsrRecords.at(*_it_aml).ignore)
5,534✔
432
                                aml_file << std::setw(MSR) << std::left << "*" << std::endl;        // Ignored
74✔
433
                        else
434
                                aml_file << std::setw(MSR) << std::left << " " << std::endl;
5,460✔
435
                        
436
                        // Move to the next AML record
437
                        if (++_it_aml == vbinary_aml->end())
5,534✔
438
                                break;
439

440
                        ++currAMLStationIndex;
5,529✔
441

442
                // has the end of the AML been reached?
443
                } while (_it_aml != vbinary_aml->end());
5,911✔
444

445
        }
NEW
446
        catch (const std::ios_base::failure& f) {
×
447
                ss << f.what();
×
NEW
448
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
449
        }
×
NEW
450
        catch (const std::runtime_error& e) {
×
451
                ss << e.what();
×
NEW
452
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
453
        }
×
454
        catch (...) {
×
NEW
455
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
456
        }
×
457
        
458
        aml_file.close();
5✔
459
}
10✔
460

461
} // dnaiostreams
462
} // dynadjust
463

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