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

icsm-au / DynAdjust / 4558627370

pending completion
4558627370

Pull #213

github

GitHub
Merge c078a4c77 into 9331be4bf
Pull Request #213: Version 1.2.7 (various fixes and enhancements)

949 of 949 new or added lines in 30 files covered. (100.0%)

30356 of 38394 relevant lines covered (79.06%)

3987.35 hits per line

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

53.37
/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)
47✔
30
{
31
        UINT16 msr_file_count(0);
47✔
32
        stringstream ss;
47✔
33
        ss << "create_msr_input_file_meta(): An error was encountered when creating " << endl <<
47✔
34
                "  the binary measurement file metadata." << endl;
47✔
35

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

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

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

64
        return msr_file_count;
47✔
65
}
47✔
66

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

73
        try {
29✔
74
                // open binary measurements file.  Throws runtime_error on failure.
75
                file_opener(bms_file, bms_filename, ios::in | ios::binary, binary, true);
29✔
76
        }
77
        catch (const runtime_error& e) {
×
78
                ss << e.what();
×
79
                throw boost::enable_current_exception(runtime_error(ss.str()));
×
80
        }
×
81
        catch (...) {
×
82
                throw boost::enable_current_exception(runtime_error(ss.str()));
×
83
        }
×
84
        
85
        ss.str("");
58✔
86
        ss << "load_bms_file(): An error was encountered when reading from " << bms_filename << "." << 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
        }
95
        catch (const ios_base::failure& f) {
×
96
                ss << f.what();
×
97
                throw boost::enable_current_exception(runtime_error(ss.str()));
×
98
        }
×
99
        catch (const runtime_error& e) {
×
100
                ss << e.what();
×
101
                throw boost::enable_current_exception(runtime_error(ss.str()));
×
102
        }
×
103
        catch (...) {
×
104
                throw boost::enable_current_exception(runtime_error(ss.str()));
×
105
        }
×
106
        
107
        bms_file.close();
29✔
108
}
29✔
109
        
110
UINT32 dna_io_bms::load_bms_file(const string& bms_filename, pvmsr_t vbinary_msr, binary_file_meta_t& bms_meta) 
100✔
111
{        
112
        std::ifstream bms_file;
100✔
113
        stringstream ss;
100✔
114
        ss << "load_bms_file(): An error was encountered when opening " << bms_filename << "." << endl;
100✔
115

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

131
        ss.str("");
200✔
132
        ss << "load_bms_file(): An error was encountered when reading from " << bms_filename << "." << endl;
100✔
133

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

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

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

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

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

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

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

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

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

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