• 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

55.88
/dynadjust/include/io/dnaiobst.cpp
1
//============================================================================
2
// Name         : dnaiobst.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 station file io operations
21
//============================================================================
22

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

26
namespace dynadjust { 
27
namespace iostreams {
28

29
UINT16 dna_io_bst::create_stn_input_file_meta(vifm_t& vinput_file_meta, input_file_meta_t** input_file_meta)
82✔
30
{
31
        UINT16 stn_file_count(0);
82✔
32
        std::stringstream ss;
82✔
33
        ss << "create_stn_input_file_meta(): An error was encountered when creating " << std::endl <<
82✔
34
                "  the binary station file metadata." << std::endl;
82✔
35

36
        // Determine how many station files were supplied
37
        try {
82✔
38
                for_each(vinput_file_meta.begin(), vinput_file_meta.end(),
82✔
39
                        [&stn_file_count] (input_file_meta_t& ifm) { 
175✔
40
                                if (ifm.datatype == stn_data || ifm.datatype == stn_msr_data)
175✔
41
                                        stn_file_count++;
88✔
42
                });
43

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

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

64
        return stn_file_count;
82✔
65
}
82✔
66

67
void dna_io_bst::load_bst_file_meta(const std::string& bst_filename, binary_file_meta_t& bst_meta) 
53✔
68
{
69
        std::ifstream bst_file;
53✔
70
        std::stringstream ss;
53✔
71
        ss << "load_bst_file(): An error was encountered when opening " << bst_filename << "." << std::endl;
53✔
72

73
        try {
53✔
74
                // open binary stations file.  Throws runtime_error on failure.
75
                file_opener(bst_file, bst_filename, std::ios::in | std::ios::binary, binary, true);
53✔
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("");
159✔
86
        ss << "load_bst_file(): An error was encountered when reading from " << bst_filename << "." << std::endl;
53✔
87

88
        try {
53✔
89
                // read the file information
90
                readFileInfo(bst_file);
53✔
91
                
92
                // read the metadata
93
                readFileMetadata(bst_file, bst_meta);
53✔
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
        bst_file.close();
53✔
108
}
53✔
109
        
110

111
UINT32 dna_io_bst::load_bst_file(const std::string& bst_filename, pvstn_t vbinary_stn, binary_file_meta_t& bst_meta) 
552✔
112
{        
113
        std::ifstream bst_file;
552✔
114
        std::stringstream ss;
552✔
115
        ss << "load_bst_file(): An error was encountered when opening " << bst_filename << "." << std::endl;
552✔
116

117
        try {
552✔
118
                // open binary stations file.  Throws runtime_error on failure.
119
                file_opener(bst_file, bst_filename, std::ios::in | std::ios::binary, binary, true);
552✔
120
        }
NEW
121
        catch (const std::runtime_error& e) {
×
122
                ss << e.what();
×
NEW
123
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
124
        }
×
125
        catch (...) {
×
NEW
126
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
127
        }
×
128
        
129
        station_t stationRecord;
552✔
130
        UINT32 stn;
552✔
131

132
        ss.str("");
1,656✔
133
        ss << "load_bst_file(): An error was encountered when reading from " << bst_filename << "." << std::endl;
552✔
134

135
        try {
552✔
136
                // read the file information
137
                readFileInfo(bst_file);
552✔
138
                
139
                // read the metadata
140
                readFileMetadata(bst_file, bst_meta);
552✔
141
                
142
                // read the bms data
143
                vbinary_stn->reserve(bst_meta.binCount);
552✔
144
                for (stn=0; stn<bst_meta.binCount; stn++)
32,535✔
145
                {
146
                        bst_file.read(reinterpret_cast<char *>(&stationRecord), sizeof(station_t));
31,983✔
147
                        vbinary_stn->push_back(stationRecord);
31,983✔
148
                }
149
        }
NEW
150
        catch (const std::ios_base::failure& f) {
×
151
                ss << f.what();
×
NEW
152
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
153
        }
×
NEW
154
        catch (const std::runtime_error& e) {
×
155
                ss << e.what();
×
NEW
156
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
157
        }
×
158
        catch (...) {
×
NEW
159
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
160
        }
×
161
        
162
        bst_file.close();
552✔
163

164
        return bst_meta.binCount;
552✔
165
}
552✔
166

167
void dna_io_bst::write_bst_file(const std::string& bst_filename, pvstn_t vbinary_stn, binary_file_meta_t& bst_meta)
486✔
168
{
169
        std::ofstream bst_file;
486✔
170
        std::stringstream ss;
486✔
171
        ss << "write_bst_file(): An error was encountered when opening " << bst_filename << "." << std::endl;
486✔
172

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

189
        try {
486✔
190
                // write version
191
                writeFileInfo(bst_file);
486✔
192
                
193
                // write the metadata
194
                writeFileMetadata(bst_file, bst_meta);
486✔
195
                
196
                // write the bst data
197
                it_vstn_t _it_stn(vbinary_stn->begin());                
486✔
198
                for (; _it_stn!=vbinary_stn->end(); ++_it_stn)
23,890✔
199
                        bst_file.write(reinterpret_cast<char *>(&(*_it_stn)), sizeof(station_t));
23,404✔
200
        }
NEW
201
        catch (const std::ios_base::failure& f) {
×
202
                ss << f.what();
×
NEW
203
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
204
        }
×
NEW
205
        catch (const std::runtime_error& e) {
×
206
                ss << e.what();
×
NEW
207
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
208
        }
×
209
        catch (...) {
×
NEW
210
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
211
        }
×
212
        
213
        bst_file.close();
486✔
214
}
486✔
215

216
bool dna_io_bst::write_bst_file(const std::string& bst_filename, vdnaStnPtr* vStations, pvstring vUnusedStns, binary_file_meta_t& bst_meta, bool flagUnused)
82✔
217
{
218
        std::ofstream bst_file;
82✔
219
        std::stringstream ss;
82✔
220
        ss << "write_bst_file(): An error was encountered when opening " << bst_filename << "." << std::endl;
82✔
221

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

238
        _it_vdnastnptr _it_stn;
82✔
239
        
240
        try {
82✔
241
                // write version
242
                writeFileInfo(bst_file);                
82✔
243
                
244
                // write the metadata
245
                writeFileMetadata(bst_file, bst_meta);
82✔
246
                
247
                // write the bst data
248
                if (flagUnused)
82✔
249
                {
250
                        std::sort(vUnusedStns->begin(), vUnusedStns->end());
15✔
251
                        for (_it_stn=vStations->begin(); _it_stn!=vStations->end(); _it_stn++)
825✔
252
                        {
253
                                if (binary_search(vUnusedStns->begin(), vUnusedStns->end(), _it_stn->get()->GetName()))
1,620✔
254
                                {
255
                                        _it_stn->get()->SetStationUnused();
29✔
256
                                        _it_stn->get()->WriteBinaryStn(&bst_file, TRUE);
29✔
257
                                }
258
                                else
259
                                        _it_stn->get()->WriteBinaryStn(&bst_file);
781✔
260
                        }
261
                }
262
                else
263
                        for (_it_stn=vStations->begin(); _it_stn!=vStations->end(); _it_stn++)
6,149✔
264
                                _it_stn->get()->WriteBinaryStn(&bst_file);
6,082✔
265
        }
NEW
266
        catch (const std::ios_base::failure& f) {
×
267
                ss << f.what();
×
NEW
268
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
269
        }
×
NEW
270
        catch (const std::runtime_error& e) {
×
271
                ss << e.what();
×
NEW
272
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
273
        }
×
274
        catch (...) {
×
NEW
275
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
276
        }
×
277
        
278
        bst_file.close();
82✔
279
        return true;
82✔
280
}
82✔
281

282

283
} // dnaiostreams
284
} // dynadjust
285

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