• 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

53.99
/dynadjust/include/io/dnaiobms.cpp
1
//============================================================================
2
// Name         : dnaiobms.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 binary measurement file io operations
21
//============================================================================
22

23
#include <include/io/dnaiobms.hpp>
24
#include <include/functions/dnaiostreamfuncs.hpp>
25

26
namespace dynadjust { 
27
namespace iostreams {
28

29
UINT16 dna_io_bms::create_msr_input_file_meta(vifm_t& vinput_file_meta, input_file_meta_t** input_file_meta)
80✔
30
{
31
        UINT16 msr_file_count(0);
80✔
32
        std::stringstream ss;
80✔
33
        ss << "create_msr_input_file_meta(): An error was encountered when creating " << std::endl <<
80✔
34
                "  the binary measurement file metadata." << std::endl;
80✔
35

36
        // Determine how many measurement files were supplied
37
        try {
80✔
38
                for_each(vinput_file_meta.begin(), vinput_file_meta.end(),
80✔
39
                        [&msr_file_count] (input_file_meta_t& ifm) { 
172✔
40
                                if (ifm.datatype == msr_data || ifm.datatype == stn_msr_data)
172✔
41
                                        msr_file_count++;
93✔
42
                });
43

44
                if (*input_file_meta != NULL)
80✔
45
                        delete [] *input_file_meta;
5✔
46
        
47
                (*input_file_meta) = new input_file_meta_t[msr_file_count];
80✔
48

49
                msr_file_count = 0;
80✔
50
                for_each(vinput_file_meta.begin(), vinput_file_meta.end(),
80✔
51
                        [&msr_file_count, &input_file_meta] (input_file_meta_t& ifm) { 
172✔
52
                                if (ifm.datatype == msr_data || ifm.datatype == stn_msr_data)
172✔
53
                                {
54
                                        (*input_file_meta)[msr_file_count] = ifm;
93✔
55
                                        msr_file_count++;
93✔
56
                                }
57
                });
172✔
58
        
59
        }
60
        catch (...) {
×
NEW
61
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
62
        }
×
63

64
        return msr_file_count;
80✔
65
}
80✔
66

67
void dna_io_bms::load_bms_file_meta(const std::string& bms_filename, binary_file_meta_t& bms_meta) 
29✔
68
{
69
        std::ifstream bms_file;
29✔
70
        std::stringstream ss;
29✔
71
        ss << "load_bms_file(): An error was encountered when opening " << bms_filename << "." << std::endl;
29✔
72

73
        try {
29✔
74
                // open binary measurements file.  Throws runtime_error on failure.
75
                file_opener(bms_file, bms_filename, std::ios::in | std::ios::binary, binary, true);
29✔
76
        }
NEW
77
        catch (const std::runtime_error& e) {
×
78
                ss << e.what();
×
NEW
79
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
80
        }
×
81
        catch (...) {
×
NEW
82
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
83
        }
×
84
        
85
        ss.str("");
87✔
86
        ss << "load_bms_file(): An error was encountered when reading from " << bms_filename << "." << std::endl;
29✔
87

88
        try {
29✔
89
                // read the file information
90
                readFileInfo(bms_file);
29✔
91
                
92
                // read the metadata
93
                readFileMetadata(bms_file, bms_meta);
29✔
94
        }
NEW
95
        catch (const std::ios_base::failure& f) {
×
96
                ss << f.what();
×
NEW
97
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
98
        }
×
NEW
99
        catch (const std::runtime_error& e) {
×
100
                ss << e.what();
×
NEW
101
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
102
        }
×
103
        catch (...) {
×
NEW
104
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
105
        }
×
106
        
107
        bms_file.close();
29✔
108
}
29✔
109
        
110
UINT32 dna_io_bms::load_bms_file(const std::string& bms_filename, pvmsr_t vbinary_msr, binary_file_meta_t& bms_meta) 
546✔
111
{        
112
        std::ifstream bms_file;
546✔
113
        std::stringstream ss;
546✔
114
        ss << "load_bms_file(): An error was encountered when opening " << bms_filename << "." << std::endl;
546✔
115

116
        try {
546✔
117
                // open binary measurements file.  Throws runtime_error on failure.
118
                file_opener(bms_file, bms_filename, std::ios::in | std::ios::binary, binary, true);
546✔
119
        }
NEW
120
        catch (const std::runtime_error& e) {
×
121
                ss << e.what();
×
NEW
122
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
123
        }
×
124
        catch (...) {
×
NEW
125
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
126
        }
×
127
        
128
        measurement_t measRecord;
546✔
129
        UINT32 msr;
546✔
130

131
        ss.str("");
1,638✔
132
        ss << "load_bms_file(): An error was encountered when reading from " << bms_filename << "." << std::endl;
546✔
133

134
        try {
546✔
135
                // read the file information 
136
                readFileInfo(bms_file);
546✔
137
                
138
                // read the metadata
139
                readFileMetadata(bms_file, bms_meta);
546✔
140

141
                // read the bms data
142
                vbinary_msr->reserve(bms_meta.binCount);
546✔
143
                for (msr=0; msr<bms_meta.binCount; msr++)
416,247✔
144
                {
145
                        bms_file.read(reinterpret_cast<char *>(&measRecord), sizeof(measurement_t));
415,701✔
146
                        vbinary_msr->push_back(measRecord);
415,701✔
147
                }
148
        }
NEW
149
        catch (const std::ios_base::failure& f) {
×
150
                ss << f.what();
×
NEW
151
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
152
        }
×
NEW
153
        catch (const std::runtime_error& e) {
×
154
                ss << e.what();
×
NEW
155
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
156
        }
×
157
        catch (...) {
×
NEW
158
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
159
        }
×
160
        
161
        bms_file.close();
546✔
162

163
        return bms_meta.binCount;
546✔
164
}
546✔
165

166
void dna_io_bms::write_bms_file(const std::string& bms_filename, pvmsr_t vbinary_msr, binary_file_meta_t& bms_meta)
477✔
167
{
168
        std::ofstream bms_file;
477✔
169
        std::stringstream ss;
477✔
170
        ss << "write_bms_file(): An error was encountered when opening " << bms_filename << "." << std::endl;
477✔
171

172
        try {
477✔
173
                // open binary measurements file.  Throws runtime_error on failure.
174
                file_opener(bms_file, bms_filename,
477✔
175
                        std::ios::out | std::ios::binary, binary);
176
        }
NEW
177
        catch (const std::runtime_error& e) {
×
178
                ss << e.what();
×
NEW
179
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
180
        }
×
181
        catch (...) {
×
NEW
182
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
183
        }
×
184
        
185
        ss.str("");
1,431✔
186
        ss << "write_bms_file(): An error was encountered when writing to " << bms_filename << "." << std::endl;
477✔
187

188
        try {
477✔
189
                // write the file information
190
                writeFileInfo(bms_file);
477✔
191
                
192
                // write the metadata
193
                writeFileMetadata(bms_file, bms_meta);
477✔
194
                
195
                // write the bms data
196
                it_vmsr_t _it_msr(vbinary_msr->begin());                
477✔
197
                for (_it_msr=vbinary_msr->begin(); _it_msr!=vbinary_msr->end(); ++_it_msr)
246,774✔
198
                        bms_file.write(reinterpret_cast<char *>(&(*_it_msr)), sizeof(measurement_t));
246,297✔
199
        }
NEW
200
        catch (const std::ios_base::failure& f) {
×
201
                ss << f.what();
×
NEW
202
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
203
        }
×
NEW
204
        catch (const std::runtime_error& e) {
×
205
                ss << e.what();
×
NEW
206
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
207
        }
×
208
        catch (...) {
×
NEW
209
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
210
        }
×
211
        
212
        bms_file.close();
477✔
213
}
477✔
214

215
void dna_io_bms::write_bms_file(const std::string& bms_filename, vdnaMsrPtr* vMeasurements, binary_file_meta_t& bms_meta)
80✔
216
{
217
        std::ofstream bms_file;
80✔
218
        std::stringstream ss;
80✔
219
        ss << "write_bms_file(): An error was encountered when opening " << bms_filename << "." << std::endl;
80✔
220

221
        try {
80✔
222
                // open binary measurements file.  Throws runtime_error on failure.
223
                file_opener(bms_file, bms_filename,
80✔
224
                        std::ios::out | std::ios::binary, binary);
225
        }
NEW
226
        catch (const std::runtime_error& e) {
×
227
                ss << e.what();
×
NEW
228
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
229
        }
×
230
        catch (...) {
×
NEW
231
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
232
        }
×
233
        
234
        ss.str("");
240✔
235
        ss << "write_bms_file(): An error was encountered when writing to " << bms_filename << "." << std::endl;
80✔
236

237
        _it_vdnamsrptr _it_msr;
80✔
238
        UINT32 msrIndex(0);
80✔
239

240
        try {
80✔
241
                // write the file information
242
                writeFileInfo(bms_file);
80✔
243
                
244
                // write the metadata
245
                writeFileMetadata(bms_file, bms_meta);
80✔
246
                
247
                // write the bms data
248
                for (_it_msr=vMeasurements->begin(); _it_msr!=vMeasurements->end(); ++_it_msr)
47,026✔
249
                        _it_msr->get()->WriteBinaryMsr(&bms_file, &msrIndex);
46,946✔
250
        }
NEW
251
        catch (const std::ios_base::failure& f) {
×
252
                ss << f.what();
×
NEW
253
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
254
        }
×
NEW
255
        catch (const std::runtime_error& e) {
×
256
                ss << e.what();
×
NEW
257
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
258
        }
×
259
        catch (...) {
×
NEW
260
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
261
        }
×
262
        
263
        bms_file.close();
80✔
264
}
80✔
265

266
} // dnaiostreams
267
} // dynadjust
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